Don't call InvertPixelArray with negative width and/or height.
[tangerine.git] / workbench / c / Identify / main.c
blob84f5fa80859bfaefb5368bb26eaf031a3ccfaf99
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 */
5 #include <proto/dos.h>
6 #include <proto/datatypes.h>
7 #include <datatypes/datatypes.h>
9 #include <stdio.h>
11 enum
13 ARG_FILE,
14 ARG_VERBOSE,
15 ARG_COUNT
18 #define ERROR_HEADER "Identify"
20 /*** Prototypes *************************************************************/
21 int identify(CONST_STRPTR filename, BOOL verbose);
22 CONST_STRPTR gid2string(ULONG gid);
24 /*** Functions **************************************************************/
25 int main(void)
27 int rc = RETURN_OK;
28 struct RDArgs *rdargs = NULL;
29 IPTR args[ARG_COUNT] = { 0 };
31 if ((rdargs = ReadArgs("FILE/M/A,VERBOSE/S", args, NULL)) != NULL)
33 CONST_STRPTR *files = (CONST_STRPTR *) args[ARG_FILE], file;
35 while ((file = *files++) != NULL)
37 if (identify(file, args[ARG_VERBOSE]) != RETURN_OK)
39 rc = RETURN_WARN;
43 FreeArgs(rdargs);
45 else
47 PrintFault(IoErr(), ERROR_HEADER);
48 rc = RETURN_FAIL;
51 return rc;
54 int identify(CONST_STRPTR filename, BOOL verbose)
56 int rc = RETURN_OK;
57 BPTR lock = Lock(filename, ACCESS_READ);
59 if (lock != NULL)
61 struct DataType *dt = ObtainDataType(DTST_FILE, lock, TAG_DONE);
62 if (dt != NULL)
64 struct DataTypeHeader *dth = dt->dtn_Header;
66 if (!verbose)
68 Printf
70 "%s:\t%s/%s\n",
71 filename, gid2string(dth->dth_GroupID), dth->dth_Name
74 else
76 ULONG gid = AROS_LONG2BE(dth->dth_GroupID),
77 id = AROS_LONG2BE(dth->dth_ID);
79 Printf
81 "File: %s\n"
82 "Type: %s/%s\t(GID: %.4s, ID: %.4s)\n"
83 "DT Basename: %s\n\n",
84 filename, gid2string(dth->dth_GroupID), dth->dth_Name,
85 (CONST_STRPTR) &gid, (CONST_STRPTR) &id,
86 dth->dth_BaseName
90 else
92 FPrintf(Error(), ERROR_HEADER": Could not obtain datatype for file.\n");
93 rc = RETURN_FAIL;
96 UnLock(lock);
98 else
100 PrintFault(IoErr(), ERROR_HEADER);
101 rc = RETURN_FAIL;
104 return rc;
107 CONST_STRPTR gid2string(ULONG gid)
109 switch (gid)
111 case GID_SYSTEM: return "System";
112 case GID_TEXT: return "Text";
113 case GID_DOCUMENT: return "Document";
114 case GID_SOUND: return "Sound";
115 case GID_INSTRUMENT: return "Instrument";
116 case GID_MUSIC: return "Music";
117 case GID_PICTURE: return "Picture";
118 case GID_ANIMATION: return "Animation";
119 case GID_MOVIE: return "Movie";
120 default: return NULL;