2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Filenote CLI command
9 /*****************************************************************************
17 FILE/A,COMMENT,ALL/S,QUIET/S
25 Add a comment to a file or directory.
27 Filenote allows a recursive scan of all directories adding comments
28 to each file/directory it finds that matches the file pattern
33 FILE - Always has to be specified. Can be either a filename with
34 a full path or a file pattern that is to be matched.
36 COMMENT - The ASCII string that is to be added as a comment to the
37 file(s)/dir(s) specified.
39 To provide a comment that has embedded quotation marks,
40 precede each quote with an asterisk.
42 i.e. Filenote FILE=RAM:test.txt COMMENT=*"hello*"
44 ALL - Boolean switch. If specified, Filenote scans the directories
45 that match the pattern specified, recursively.
47 QUIET - Boolean switch. If specified, no diagnostic text will be
52 Standard DOS return codes.
56 Output from AROS' Filenote is more neat and structured than the
57 standard Filenote command.
59 Does not yet support multi-assigns.
63 Filenote ram: hello all
65 Recurses through each directory in RAM: adding "hello" as a
66 filenote to each file/directory.
72 dos.library/SetComment()
78 27-Jul-1997 laguest Initial inclusion into the AROS tree
80 ******************************************************************************/
82 #include <proto/arossupport.h>
83 #include <proto/dos.h>
84 #include <proto/exec.h>
87 #include <dos/dosasl.h>
88 #include <dos/dosextens.h>
89 #include <dos/rdargs.h>
90 #include <exec/memory.h>
91 #include <utility/utility.h>
97 #define ERROR_HEADER "Filenote"
99 #define ARG_TEMPLATE "FILE/A,COMMENT,ALL/S,QUIET/S"
101 #define ARG_COMMENT 1
106 /* To define whether a command line switch was set or not.
110 #define MAX_PATH_LEN 512
112 static const char version
[] = "$VER: Filenote 41.1 (29.08.1998)\n";
114 int Do_Filenote(struct AnchorPath
*, STRPTR
, STRPTR
, LONG
, LONG
);
121 struct AnchorPath
* apath
;
122 IPTR args
[TOTAL_ARGS
] = { NULL
, NULL
, NULL
, NULL
};
127 Return_Value
= RETURN_OK
;
129 apath
= AllocVec(sizeof(struct AnchorPath
) + MAX_PATH_LEN
,
130 MEMF_ANY
| MEMF_CLEAR
);
133 /* Make sure DOS knows the buffer size.
135 apath
->ap_Flags
= APF_DOWILD
| APF_FollowHLinks
;
136 apath
->ap_Strlen
= MAX_PATH_LEN
;
137 apath
->ap_BreakBits
= 0;
138 apath
->ap_FoundBreak
= 0;
140 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
143 Return_Value
= Do_Filenote(apath
,
144 (STRPTR
)args
[ARG_FILE
],
145 (STRPTR
)args
[ARG_COMMENT
],
147 (LONG
)args
[ARG_QUIET
]
153 PrintFault(IoErr(), ERROR_HEADER
);
155 Return_Value
= RETURN_ERROR
;
160 Return_Value
= RETURN_FAIL
;
167 return (Return_Value
);
172 /* Defines whether MatchFirst(), etc has matched a file.
174 #define MATCHED_FILE 0
176 void PrintFileName(struct AnchorPath
*, LONG
);
177 int SafeSetFileComment(struct AnchorPath
*, char *);
179 int Do_Filenote(struct AnchorPath
*a
,
189 Return_Value
= RETURN_OK
;
192 /* Looks to see if the user has given a volume name as a pattern
193 * without the all switch set. If so, we fail.
198 IsDosEntryA((char *)File
, LDF_VOLUMES
| LDF_DEVICES
) == TRUE
203 PrintFault(ERROR_OBJECT_WRONG_TYPE
, ERROR_HEADER
);
204 Return_Value
= RETURN_FAIL
;
208 if (Return_Value
!= RETURN_FAIL
)
210 Result
= MatchFirst(File
, a
);
212 if (Result
== MATCHED_FILE
)
218 Return_Value
= SafeSetFileComment(a
, Comment
);
220 if (Quiet
== NOT_SET
)
222 PrintFileName(a
, TabValue
);
227 /* Allow a recursive scan.
230 if (a
->ap_Info
.fib_DirEntryType
> 0)
234 if (!(a
->ap_Flags
& APF_DIDDIR
))
236 a
->ap_Flags
|= APF_DODIR
;
238 Return_Value
= SafeSetFileComment(a
, Comment
);
240 if (Quiet
== NOT_SET
)
242 PrintFileName(a
, TabValue
);
250 a
->ap_Flags
&= ~APF_DIDDIR
;
256 Return_Value
= SafeSetFileComment(a
, Comment
);
258 if (Quiet
== NOT_SET
)
260 PrintFileName(a
, TabValue
);
267 ((Result
= MatchNext(a
)) == MATCHED_FILE
)
269 Return_Value
!= RETURN_FAIL
274 PrintFault(IoErr(), ERROR_HEADER
);
275 Return_Value
= RETURN_FAIL
;
282 return (Return_Value
);
287 void PrintFileName(struct AnchorPath
*a
, LONG t
)
292 args
[0] = (IPTR
)FilePart(&a
->ap_Buf
[0]);
293 args
[1] = (IPTR
)NULL
;
297 for (i
= 0; i
!= t
; i
++)
304 if (a
->ap_Info
.fib_DirEntryType
> 0)
306 VPrintf(" (dir)", NULL
);
309 VPrintf("...Done\n", NULL
);
311 } /* PrintFileName */
314 int SafeSetFileComment(struct AnchorPath
*a
, char *c
)
318 Return_Value
= RETURN_OK
;
320 if (!SetComment(a
->ap_Buf
, c
))
322 Return_Value
= RETURN_WARN
;
325 return(Return_Value
);
327 } /* SafeSetFileComment */