forwarding a radium compilation fix.
[AROS-Contrib.git] / fish / touch / touch.c
blobd67d87d476b08fdf1ba6baba9f476a726b583104
1 #include <dos/rdargs.h>
2 #include <dos/dosasl.h>
4 /************************************************************************/
5 /* Touch V1.01 */
6 /* Written and Copyright ©1993 by Dave Schreiber. All Rights Reserved. */
7 /* */
8 /* This is an Amigaized version of the Unix utility with the same name. */
9 /* Usage: */
10 /* Touch FILE/A/M */
11 /* */
12 /* Touch sets the date/time of all specified files to the current date */
13 /* and time. This uses Workbench 2.0 wildcard pattern-matching, so all */
14 /* 2.0 wildcards are valid. */
15 /* */
16 /* To compile (SAS/C V6.0): */
17 /* smake */
18 /* */
19 /* Version history: */
20 /* 1.01 - Fixed an enforcer hit */
21 /* July 17, 1993 */
22 /* 1.00 - Initial Release. */
23 /* July 17, 1993 */
24 /************************************************************************/
26 #include <exec/types.h>
27 #include <dos/dos.h>
28 #include <exec/memory.h>
30 #include <proto/dos.h>
31 #include <proto/exec.h>
33 void touchFiles(char *pattern);
35 char trashBuf[512];
37 struct RDArgs ra=
39 {NULL,0,0},
41 trashBuf,
42 512,
43 "FILE/A/M"
46 char *version="$VER: Touch V1.01 (17.7.93)";
48 char *copyright="Copyright 1993 by Dave Schreiber. All Rights Reserved";
50 int main(int argc, char **argv)
52 IPTR args[2];
53 char **filenames;
54 int c;
56 /*Get the list of filenames/patterns*/
57 args[0]=0;
58 ReadArgs("FILE/A/M",args,&ra);
59 filenames=(char **)args[0];
61 /*Update the date and time of each name matching any given pattern*/
62 if(filenames!=NULL)
63 for(c=0;filenames[c]!=NULL;c++)
64 touchFiles(filenames[c]);
66 /*Free resources allocated by ReadArgs()*/
67 FreeArgs(&ra);
69 return 0;
72 void touchFiles(char *pattern)
74 struct AnchorPath *anchor;
75 struct DateStamp currentDate;
76 BPTR origDir;
78 /*Allocate a structure required by MatchFirst()*/
79 anchor=(struct AnchorPath *)AllocMem(sizeof(struct AnchorPath),MEMF_CLEAR);
80 if(anchor==NULL)
81 return;
83 /*Get first file*/
84 if(MatchFirst(pattern,anchor)==0)
86 /*Update date/time*/
87 origDir=CurrentDir(anchor->ap_Current->an_Lock);
88 DateStamp(&currentDate);
89 SetFileDate(anchor->ap_Info.fib_FileName,&currentDate);
90 CurrentDir(origDir);
92 /*Update the rest of the files*/
93 while(MatchNext(anchor)==0)
95 origDir=CurrentDir(anchor->ap_Current->an_Lock);
96 DateStamp(&currentDate);
97 SetFileDate(anchor->ap_Info.fib_FileName,&currentDate);
98 CurrentDir(origDir);
102 /*All done*/
103 MatchEnd(anchor);
104 FreeMem(anchor,sizeof(struct AnchorPath));
106 return;