2 Copyright © 2004, 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-sequenceS:startup-sequence
41 (This will identify the startup-sequence as a text file.)
53 ******************************************************************************/
55 #include <proto/dos.h>
56 #include <proto/datatypes.h>
57 #include <datatypes/datatypes.h>
68 #define ERROR_HEADER "Identify"
70 /*** Prototypes *************************************************************/
71 int identify(CONST_STRPTR filename
, BOOL verbose
);
72 CONST_STRPTR
gid2string(ULONG gid
);
74 /*** Functions **************************************************************/
78 struct RDArgs
*rdargs
= NULL
;
79 IPTR args
[ARG_COUNT
] = { 0 };
81 if ((rdargs
= ReadArgs("FILE/M/A,VERBOSE/S", args
, NULL
)) != NULL
)
83 CONST_STRPTR
*files
= (CONST_STRPTR
*) args
[ARG_FILE
], file
;
85 while ((file
= *files
++) != NULL
)
87 if (identify(file
, args
[ARG_VERBOSE
]) != RETURN_OK
)
97 PrintFault(IoErr(), ERROR_HEADER
);
104 int identify(CONST_STRPTR filename
, BOOL verbose
)
107 BPTR lock
= Lock(filename
, ACCESS_READ
);
111 struct DataType
*dt
= ObtainDataType(DTST_FILE
, lock
, TAG_DONE
);
114 struct DataTypeHeader
*dth
= dt
->dtn_Header
;
121 filename
, gid2string(dth
->dth_GroupID
), dth
->dth_Name
126 ULONG gid
= AROS_LONG2BE(dth
->dth_GroupID
),
127 id
= AROS_LONG2BE(dth
->dth_ID
);
132 "Type: %s/%s\t(GID: %.4s, ID: %.4s)\n"
133 "DT Basename: %s\n\n",
134 filename
, gid2string(dth
->dth_GroupID
), dth
->dth_Name
,
135 (CONST_STRPTR
) &gid
, (CONST_STRPTR
) &id
,
142 FPrintf(Error(), ERROR_HEADER
": Could not obtain datatype for file.\n");
150 PrintFault(IoErr(), ERROR_HEADER
);
157 CONST_STRPTR
gid2string(ULONG gid
)
161 case GID_SYSTEM
: return "System";
162 case GID_TEXT
: return "Text";
163 case GID_DOCUMENT
: return "Document";
164 case GID_SOUND
: return "Sound";
165 case GID_INSTRUMENT
: return "Instrument";
166 case GID_MUSIC
: return "Music";
167 case GID_PICTURE
: return "Picture";
168 case GID_ANIMATION
: return "Animation";
169 case GID_MOVIE
: return "Movie";
170 default: return NULL
;