File

File Commit Details

Date:2010-12-05 22:24:34 (7 years 11 months ago)
Author:Michael Baudin
Commit:15
Parents: 14
Message:Cosmetic.
Changes:
M/tests/unit_tests/normalize.tst
M/macros/file_normalize.sci
M/macros/file_touch.sci

File differences

tests/unit_tests/normalize.tst
5353
5454
5555
56
57
58
5659
57
58
59
60
61
62
6063
6164
6265
expected = "/foo/bla/myfile.txt";
assert_equal ( path , expected );
//
path = file_normalize("\foo\bla\myfile.txt");
expected_Windows = "/foo/bla/myfile.txt";
expected_Linux = pwd()+"/\foo\bla\myfile.txt";
if ( getos()=="Windows") then
path = file_normalize("\foo\bla\myfile.txt");
expected = "/foo/bla/myfile.txt";
assert_equal ( path , expected );
assert_equal ( path , expected_Windows );
else
assert_equal ( path , expected_Linux );
end
//
// Check "."
macros/file_touch.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (C) 2010 - DIGITEO - Michael Baudin
// Copyright (c) 2008 - Michael Baudin
// Copyright (c) 2008 - Arjen Markus
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
function file_touch ( name )
// Alter the atime and mtime of the specified files.
//
// Calling Sequence
// file_touch ( name )
//
// Parameters
// name : a 1-by-1 matrix of strings
//
// Description
// Creates the file if it does not exist.
// Alter the atime and mtime of the specified files.
// TODO : test this under Linux
//
// Examples
// name = file_tempfile ( )
// file_touch ( name )
// x = fileinfo ( name );
// mprintf("Last modification: %d\n",x(6))
// //
// // Wait for 1 second
// realtimeinit(1);//sets time unit to half a second
// realtime(0);//sets current date to 0
// realtime(1);
// //
// // Touch it again
// file_touch ( name )
// x = fileinfo ( name );
// mprintf("Last modification: %d\n",x(6))
//
//
// Authors
// Copyright (C) 2010 - DIGITEO - Michael Baudin
// Copyright (c) 2008 - Michael Baudin
// Copyright (c) 2008 - Arjen Markus
if ( fileinfo(name) <> [] ) then
method = 3
if ( method == 1 ) then
tmpfile = file_tempfile ( )
//
// Copy the file.
[status,message] = copyfile(name,tmpfile)
if ( status == 0 ) then
error(msprintf("%s: Failed to copy file %s into %s: %s","file_touch",name,tmpfile,message))
end
f = deletefile(name)
if ( ~f ) then
error(msprintf("%s: Failed to delete file %s","file_touch",name))
end
[status,message] = copyfile(tmpfile,name)
if ( status == 0 ) then
error(msprintf("%s: Failed to copy file %s into %s: %s","file_touch",tmpfile,name,message))
end
f = deletefile(tmpfile)
if ( ~f ) then
error(msprintf("%s: Failed to delete file %s","file_touch",tmpfile))
end
elseif ( method == 2 ) then
fd=mopen(name,"a");
mclose(fd);
else
os = getos()
if ( os=="Windows" ) then
dos("copy /b "+name+" +,, "+name)
else
unix_g("touch "+name)
end
end
else
// If the file does not exist, create it as an empty file
[fd,err]=mopen(name,"w")
if ( err <> 0 ) then
error(msprintf("%s: Failed to open file %s","file_touch",name))
end
err=mclose(fd)
if ( err <> 0 ) then
error(msprintf("%s: Failed to close file %s","file_touch",name))
end
end
endfunction
// Copyright (C) 2010 - DIGITEO - Michael Baudin
// Copyright (c) 2008 - Michael Baudin
// Copyright (c) 2008 - Arjen Markus
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
function file_touch ( name )
// Alter the atime and mtime of the specified files.
//
// Calling Sequence
// file_touch ( name )
//
// Parameters
// name : a 1-by-1 matrix of strings
//
// Description
// Creates the file if it does not exist.
// Alter the atime and mtime of the specified files.
//
// Examples
// name = file_tempfile ( )
// file_touch ( name )
// x = fileinfo ( name );
// mprintf("Last modification: %d\n",x(6))
// //
// // Wait for 1 second
// realtimeinit(1);//sets time unit to half a second
// realtime(0);//sets current date to 0
// realtime(1);
// //
// // Touch it again
// file_touch ( name )
// x = fileinfo ( name );
// mprintf("Last modification: %d\n",x(6))
//
//
// Authors
// Copyright (C) 2010 - DIGITEO - Michael Baudin
// Copyright (c) 2008 - Michael Baudin
// Copyright (c) 2008 - Arjen Markus
if ( fileinfo(name) <> [] ) then
os = getos()
if ( os=="Windows" ) then
dos("copy /b "+name+" +,, "+name)
else
unix_g("touch "+name)
end
else
// If the file does not exist, create it as an empty file
[fd,err]=mopen(name,"w")
if ( err <> 0 ) then
error(msprintf("%s: Failed to open file %s","file_touch",name))
end
err=mclose(fd)
if ( err <> 0 ) then
error(msprintf("%s: Failed to close file %s","file_touch",name))
end
end
endfunction
macros/file_normalize.sci
3333
3434
3535
36
36
37
3738
3839
3940
// expected = "/foo/bla/myfile.txt";
// //
// file_normalize ( "\foo\myfile.txt" )
// expected = "/foo/bla/myfile.txt";
// expected_Windows = "/foo/bla/myfile.txt"
// expected_Linux = pwd()+"/\foo\bla\myfile.txt"
// //
// file_normalize ( "." )
// expected = pwd()

Archive Download the corresponding diff file

Revision: 15