Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / c / SetDate.c
blob5b5830c294df2fc7615af104f5df49830457a04d
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: SetDate CLI command
6 Lang: English
7 */
9 /*************************************************************************
11 NAME
13 SetDate
15 FORMAT
17 SetDate (file | pattern) [(weekday)] [(date)] [(time)] [ALL]
19 SYNOPSIS
21 FILE/A,WEEKDAY,DATE,TIME,ALL/S
23 LOCATION
27 FUNCTION
29 Changes the date and time of the creation or last change of a file or
30 directory. With option ALL, it also changes the date and time of all
31 files and subdirectories within directories matching the specified
32 pattern. If either the date or time is unspecified, the current date
33 or time is used.
35 INPUTS
37 FILE -- File (or pattern) to change the date of.
39 WEEKDAY -- Specification of the day of the date. This is locale
40 sensitive, and you may use standard keywords such as
41 'Tomorrow' and 'Yesterday' (in the language used, of
42 course).
44 DATE -- A date in the format DD-MMM-YY.
45 MMM is either the number or the first 3 letters of the
46 month in English.
48 TIME -- Time string in the format HH:MM:SS or HH:MM.
50 ALL -- Recurse through subdirectories.
52 RESULT
54 Standard DOS return codes
56 NOTES
58 EXAMPLE
60 SetDate #? ALL
62 Sets the date for all files and directories in the current directory
63 and its subdirectories to the current date.
65 BUGS
67 ALL flag does not work.
69 SEE ALSO
71 Date
73 INTERNALS
75 *************************************************************************/
78 #include <dos/datetime.h>
79 #include <proto/dos.h>
80 #include <dos/rdargs.h>
81 #include <dos/dosasl.h>
83 enum { ARG_FILE = 0, ARG_WEEKDAY, ARG_DATE, ARG_TIME, ARG_ALL };
85 int __nocommandline;
87 int main(void)
89 struct AnchorPath aPath;
90 struct RDArgs *rda;
91 IPTR args[5] = { NULL, NULL, NULL, NULL, FALSE };
92 struct DateTime dt;
93 LONG error = 0;
94 BPTR oldCurDir;
95 LONG retval = RETURN_OK;
96 BOOL timeError = FALSE; /* Error in time/date specification? */
98 rda = ReadArgs("FILE/A,WEEKDAY,DATE,TIME,ALL/S", args, NULL);
100 if(rda == NULL)
102 PrintFault(IoErr(), "SetDate");
103 return RETURN_FAIL;
106 /* Use the current time as default (if no DATE, TIME or WEEKDAY is
107 defined) */
108 DateStamp(&dt.dat_Stamp);
110 dt.dat_Flags = DTF_FUTURE;
111 dt.dat_Format = FORMAT_DOS;
112 dt.dat_StrDate = (TEXT *)args[ARG_DATE];
113 dt.dat_StrTime = (TEXT *)args[ARG_TIME];
115 /* Change the defaults according to the user's specifications */
116 if(StrToDate(&dt))
118 dt.dat_StrDate = (TEXT *)args[ARG_WEEKDAY];
120 if(!StrToDate(&dt))
121 timeError = TRUE;
123 else
124 timeError = TRUE;
126 if(timeError)
128 PutStr("SetDate: Illegal DATE or TIME string\n");
129 return RETURN_FAIL;
133 aPath.ap_Flags = (BOOL)args[ARG_ALL] ? APF_DOWILD : 0;
134 aPath.ap_BreakBits = SIGBREAKF_CTRL_C;
135 aPath.ap_Strlen = 0;
137 /* Save the current dir */
138 oldCurDir = CurrentDir(NULL);
139 CurrentDir(oldCurDir);
141 error = MatchFirst((STRPTR)args[ARG_FILE], &aPath);
143 while(error == 0)
145 CurrentDir(aPath.ap_Current->an_Lock);
147 // VPrintf("%s", (IPTR *)&aPath.ap_Info.fib_FileName);
149 SetFileDate(aPath.ap_Info.fib_FileName, &dt.dat_Stamp);
151 error = MatchNext(&aPath);
154 MatchEnd(&aPath);
156 /* Restore the current dir */
157 CurrentDir(oldCurDir);
159 FreeArgs(rda);
161 if(error != ERROR_NO_MORE_ENTRIES)
163 if(error == ERROR_BREAK)
164 retval = RETURN_WARN;
165 else
166 retval = RETURN_FAIL;
168 PrintFault(IoErr(), "SetDate");
171 return retval;