2 Copyright © 2004-2016, 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 PROG_NAME "Identify"
71 static const TEXT prog_name
[] = PROG_NAME
;
73 const TEXT version_string
[] = "$VER: " PROG_NAME
" 41.2 (14.7.2016)";
74 static const TEXT
template[] = "FILE/M/A,VERBOSE/S";
83 /*** Prototypes *************************************************************/
84 static LONG
identify(CONST_STRPTR filename
, BOOL verbose
);
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(), prog_name
);
116 static LONG
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
;
127 CONST_STRPTR gid_str
= GetDTString(dth
->dth_GroupID
);
131 Printf("%s:\t%s/%s\n", filename
, gid_str
, dth
->dth_Name
);
135 ULONG gid
= AROS_LONG2BE(dth
->dth_GroupID
),
136 id
= AROS_LONG2BE(dth
->dth_ID
);
141 "Type: %s/%s\t(GID: %.4s, ID: %.4s)\n"
142 "DT Basename: %s\n\n",
143 filename
, gid_str
, dth
->dth_Name
,
144 (CONST_STRPTR
) &gid
, (CONST_STRPTR
) &id
,
153 FPrintf(ErrorOutput(),
154 PROG_NAME
": Could not obtain datatype for file.\n");
162 PrintFault(IoErr(), prog_name
);