Don't call InvertPixelArray with negative width and/or height.
[tangerine.git] / workbench / c / Filenote.c
blob12fa3249e941947cb4a401b25bec327df026d18d
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Filenote CLI command
6 Lang: english
7 */
9 /*****************************************************************************
11 NAME
13 Filenote
15 SYNOPSIS
17 FILE/A,COMMENT,ALL/S,QUIET/S
19 LOCATION
21 Workbench:c
23 FUNCTION
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
29 specified.
31 INPUTS
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
48 displayed to stdout.
50 RESULT
52 Standard DOS return codes.
54 NOTES
56 Output from AROS' Filenote is more neat and structured than the
57 standard Filenote command.
59 Does not yet support multi-assigns.
61 EXAMPLE
63 Filenote ram: hello all
65 Recurses through each directory in RAM: adding "hello" as a
66 filenote to each file/directory.
68 BUGS
70 SEE ALSO
72 dos.library/SetComment()
74 INTERNALS
76 HISTORY
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>
86 #include <dos/dos.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>
93 #include <ctype.h>
95 #include <aros/rt.h>
97 #define ERROR_HEADER "Filenote"
99 #define ARG_TEMPLATE "FILE/A,COMMENT,ALL/S,QUIET/S"
100 #define ARG_FILE 0
101 #define ARG_COMMENT 1
102 #define ARG_ALL 2
103 #define ARG_QUIET 3
104 #define TOTAL_ARGS 4
106 /* To define whether a command line switch was set or not.
108 #define NOT_SET 0
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);
116 int __nocommandline;
118 int main(void)
120 struct RDArgs * rda;
121 struct AnchorPath * apath;
122 IPTR args[TOTAL_ARGS] = { NULL, NULL, NULL, NULL};
123 int Return_Value;
125 RT_Init();
127 Return_Value = RETURN_OK;
129 apath = AllocVec(sizeof(struct AnchorPath) + MAX_PATH_LEN,
130 MEMF_ANY | MEMF_CLEAR);
131 if (apath)
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);
141 if (rda)
143 Return_Value = Do_Filenote(apath,
144 (STRPTR)args[ARG_FILE],
145 (STRPTR)args[ARG_COMMENT],
146 (LONG)args[ARG_ALL],
147 (LONG)args[ARG_QUIET]
149 FreeArgs(rda);
151 else
153 PrintFault(IoErr(), ERROR_HEADER);
155 Return_Value = RETURN_ERROR;
158 else
160 Return_Value = RETURN_FAIL;
163 FreeVec(apath);
165 RT_Exit();
167 return (Return_Value);
169 } /* main */
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,
180 STRPTR File,
181 STRPTR Comment,
182 LONG All,
183 LONG Quiet)
185 LONG Result,
186 TabValue;
187 int Return_Value;
189 Return_Value = RETURN_OK;
190 TabValue = 0L;
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
200 All == NOT_SET
203 PrintFault(ERROR_OBJECT_WRONG_TYPE, ERROR_HEADER);
204 Return_Value = RETURN_FAIL;
206 else
208 if (Return_Value != RETURN_FAIL)
210 Result = MatchFirst(File, a);
212 if (Result == MATCHED_FILE)
216 if (All == NOT_SET)
218 Return_Value = SafeSetFileComment(a, Comment);
220 if (Quiet == NOT_SET)
222 PrintFileName(a, TabValue);
225 else
227 /* Allow a recursive scan.
230 if (a->ap_Info.fib_DirEntryType > 0)
232 /* Enter directory.
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);
244 TabValue++;
246 else
248 /* Leave directory.
250 a->ap_Flags &= ~APF_DIDDIR;
251 TabValue--;
254 else
256 Return_Value = SafeSetFileComment(a, Comment);
258 if (Quiet == NOT_SET)
260 PrintFileName(a, TabValue);
265 while
267 ((Result = MatchNext(a)) == MATCHED_FILE)
269 Return_Value != RETURN_FAIL
272 else
274 PrintFault(IoErr(), ERROR_HEADER);
275 Return_Value = RETURN_FAIL;
278 MatchEnd(a);
282 return (Return_Value);
284 } /* Do_Filenote */
287 void PrintFileName(struct AnchorPath *a, LONG t)
289 int i;
290 IPTR args[2];
292 args[0] = (IPTR)FilePart(&a->ap_Buf[0]);
293 args[1] = (IPTR)NULL;
295 VPrintf(" ", NULL);
297 for (i = 0; i != t; i++)
299 VPrintf(" ", NULL);
302 VPrintf("%s", args);
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)
316 int Return_Value;
318 Return_Value = RETURN_OK;
320 if (!SetComment(a->ap_Buf, c))
322 Return_Value = RETURN_WARN;
325 return(Return_Value);
327 } /* SafeSetFileComment */