2 Copyright © 2004-2012, The AROS Development Team. All rights reserved.
5 Desc: File Identifier/starter
8 /******************************************************************************
25 Identifies the file type or directory
29 FILE -- file to be recognized
30 VERBOSE -- activates verbose output
38 > Identify S:Startup-Sequence
39 S:Startup-Sequence: Text/ascii
41 (This will identify the startup-sequence as a text file.)
53 ******************************************************************************/
56 typedef unsigned long IPTR
;
58 #include <proto/alib.h>
60 #include <proto/dos.h>
61 #include <proto/datatypes.h>
62 #include <datatypes/datatypes.h>
67 #define ErrorOutput() Output()
70 #define ERROR_HEADER "Identify"
72 const TEXT version_string
[] = "$VER: " ERROR_HEADER
" 41.1 (02.02.2012)";
73 const TEXT
template[] = "FILE/M/A,VERBOSE/S";
82 /*** Prototypes *************************************************************/
83 int identify(CONST_STRPTR filename
, BOOL verbose
);
84 CONST_STRPTR
gid2string(ULONG gid
);
86 /*** Functions **************************************************************/
90 struct RDArgs
*rdargs
= NULL
;
91 IPTR args
[ARG_COUNT
] = { 0 };
93 if ((rdargs
= ReadArgs(template, args
, NULL
)) != NULL
)
95 CONST_STRPTR
*files
= (CONST_STRPTR
*) args
[ARG_FILE
], file
;
97 while ((file
= *files
++) != NULL
)
99 if (identify(file
, args
[ARG_VERBOSE
]) != RETURN_OK
)
109 PrintFault(IoErr(), ERROR_HEADER
);
116 int identify(CONST_STRPTR filename
, BOOL verbose
)
119 BPTR lock
= Lock(filename
, ACCESS_READ
);
123 struct DataType
*dt
= ObtainDataType(DTST_FILE
, (APTR
)lock
, TAG_DONE
);
126 struct DataTypeHeader
*dth
= dt
->dtn_Header
;
133 filename
, gid2string(dth
->dth_GroupID
), dth
->dth_Name
138 ULONG gid
= AROS_LONG2BE(dth
->dth_GroupID
),
139 id
= AROS_LONG2BE(dth
->dth_ID
);
144 "Type: %s/%s\t(GID: %.4s, ID: %.4s)\n"
145 "DT Basename: %s\n\n",
146 filename
, gid2string(dth
->dth_GroupID
), dth
->dth_Name
,
147 (CONST_STRPTR
) &gid
, (CONST_STRPTR
) &id
,
154 FPrintf(ErrorOutput(), ERROR_HEADER
": Could not obtain datatype for file.\n");
162 PrintFault(IoErr(), ERROR_HEADER
);
169 CONST_STRPTR
gid2string(ULONG gid
)
173 case GID_SYSTEM
: return "System";
174 case GID_TEXT
: return "Text";
175 case GID_DOCUMENT
: return "Document";
176 case GID_SOUND
: return "Sound";
177 case GID_INSTRUMENT
: return "Instrument";
178 case GID_MUSIC
: return "Music";
179 case GID_PICTURE
: return "Picture";
180 case GID_ANIMATION
: return "Animation";
181 case GID_MOVIE
: return "Movie";
182 default: return NULL
;