added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / c / SetDate.c
blob65867ea2e75a75efee499f126b9326f73f83dfa0
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: SetDate CLI command
6 Lang: English
7 */
9 /******************
10 NAME
12 SetDate
14 FORMAT
16 SetDate (file | pattern) [(weekday)] [(date)] [(time)] [ALL]
18 SYNOPSIS
20 FILE/A,WEEKDAY,DATE,TIME,ALL/S
22 LOCATION
24 Sys:c
26 FUNCTION
28 Changes the the date and time of the creation or last change of a
29 file or directory. With option ALL, it changes the date and time of
30 all files and directories (and files and subdirectories to those)
31 matching the specified pattern.
32 You may use the output from Date as input to SetDate.
34 INPUTS
36 FILE -- File (or pattern) to change the date of.
38 WEEKDAY -- Specification of the day of the date. This is locale
39 sensitive, and you may use standard keywords as
40 'Tomorrow' and 'Yesterday' (in the language used, of
41 course).
43 DATE -- A date described according to the locale specification
44 of the currently used language.
46 TIME -- Time string in localized format.
48 ALL -- Recurse through subdirectories.
50 RESULT
52 Standard DOS return codes
54 NOTES
56 EXAMPLE
58 SetDate #? `Date` ALL
60 Sets the date for all files and directories in the current directory
61 and its subdirectories to the current date.
63 BUGS
65 SEE ALSO
67 Date
69 INTERNALS
71 HISTORY
73 26.12.99 SDuvan implemented
76 #include <dos/datetime.h>
77 #include <proto/dos.h>
78 #include <dos/rdargs.h>
79 #include <dos/dosasl.h>
81 enum { ARG_FILE = 0, ARG_WEEKDAY, ARG_DATE, ARG_TIME, ARG_ALL };
83 int __nocommandline;
85 int main(void)
87 struct AnchorPath aPath;
88 struct RDArgs *rda;
89 IPTR args[5] = { NULL, NULL, NULL, NULL, FALSE };
90 struct DateTime dt;
91 LONG error = 0;
92 BPTR oldCurDir;
93 LONG retval = RETURN_OK;
94 BOOL timeError = FALSE; /* Error in time/date specification? */
96 rda = ReadArgs("FILE/A,WEEKDAY,DATE,TIME,ALL/S", args, NULL);
98 if(rda == NULL)
100 PrintFault(IoErr(), "SetDate");
101 return RETURN_FAIL;
104 /* Use the current time as default (if no DATE, TIME or WEEKDAY is
105 defined) */
106 DateStamp(&dt.dat_Stamp);
108 dt.dat_Flags = DTF_FUTURE;
109 dt.dat_Format = FORMAT_DEF;
110 dt.dat_StrDate = (UBYTE *)args[ARG_DATE];
111 dt.dat_StrTime = (UBYTE *)args[ARG_TIME];
113 /* Change the defaults according to the user's specifications */
114 if(StrToDate(&dt) == DOSTRUE)
116 dt.dat_StrDate = (UBYTE *)args[ARG_WEEKDAY];
118 if(StrToDate(&dt) == DOSFALSE)
119 timeError = TRUE;
121 else
122 timeError = TRUE;
124 if(timeError)
126 PutStr("SetDate: Illegal DATE or TIME string\n");
127 return RETURN_FAIL;
131 aPath.ap_Flags = (BOOL)args[ARG_ALL] ? APF_DOWILD : 0;
132 aPath.ap_BreakBits = SIGBREAKF_CTRL_C;
133 aPath.ap_Strlen = 0;
135 /* Save the current dir */
136 oldCurDir = CurrentDir(NULL);
137 CurrentDir(oldCurDir);
139 error = MatchFirst((STRPTR)args[ARG_FILE], &aPath);
141 while(error == 0)
143 CurrentDir(aPath.ap_Current->an_Lock);
145 // VPrintf("%s", (IPTR *)&aPath.ap_Info.fib_FileName);
147 SetFileDate(aPath.ap_Info.fib_FileName, &dt.dat_Stamp);
149 error = MatchNext(&aPath);
152 MatchEnd(&aPath);
154 /* Restore the current dir */
155 CurrentDir(oldCurDir);
157 FreeArgs(rda);
159 if(error != ERROR_NO_MORE_ENTRIES)
161 if(error == ERROR_BREAK)
162 retval = RETURN_WARN;
163 else
164 retval = RETURN_FAIL;
166 PrintFault(IoErr(), "SetDate");
169 return retval;