Metatarget for copying of testfile fixed.
[AROS.git] / workbench / c / Identify / main.c
blobb92af6bc7d0003ac6d3c87f8a6c69d0886c5a601
1 /*
2 Copyright © 2004-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: File Identifier/starter
6 Lang: English
7 */
8 /******************************************************************************
11 NAME
13 Identify
15 SYNOPSIS
17 FILE/M/A, VERBOSE/S
19 LOCATION
23 FUNCTION
25 Identifies the file type or directory
27 INPUTS
29 FILE -- file to be recognized
30 VERBOSE -- activates verbose output
32 RESULT
34 NOTES
36 EXAMPLE
38 > Identify S:Startup-Sequence
39 S:Startup-Sequence: Text/ascii
41 (This will identify the startup-sequence as a text file.)
43 BUGS
45 SEE ALSO
47 AddDatatypes
49 INTERNALS
51 HISTORY
53 ******************************************************************************/
55 #ifdef __VBCC__
56 typedef unsigned long IPTR;
57 #else
58 #include <proto/alib.h>
59 #endif
60 #include <proto/dos.h>
61 #include <proto/datatypes.h>
62 #include <datatypes/datatypes.h>
64 #ifndef BNULL
65 #define BNULL NULL
66 #define AROS_LONG2BE
67 #define ErrorOutput() Output()
68 #endif
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";
75 enum
77 ARG_FILE,
78 ARG_VERBOSE,
79 ARG_COUNT
82 /*** Prototypes *************************************************************/
83 int identify(CONST_STRPTR filename, BOOL verbose);
84 CONST_STRPTR gid2string(ULONG gid);
86 /*** Functions **************************************************************/
87 int main(void)
89 int rc = RETURN_OK;
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)
101 rc = RETURN_WARN;
105 FreeArgs(rdargs);
107 else
109 PrintFault(IoErr(), ERROR_HEADER);
110 rc = RETURN_FAIL;
113 return rc;
116 int identify(CONST_STRPTR filename, BOOL verbose)
118 int rc = RETURN_OK;
119 BPTR lock = Lock(filename, ACCESS_READ);
121 if (lock != BNULL)
123 struct DataType *dt = ObtainDataType(DTST_FILE, (APTR)lock, TAG_DONE);
124 if (dt != NULL)
126 struct DataTypeHeader *dth = dt->dtn_Header;
128 if (!verbose)
130 Printf
132 "%s:\t%s/%s\n",
133 filename, gid2string(dth->dth_GroupID), dth->dth_Name
136 else
138 ULONG gid = AROS_LONG2BE(dth->dth_GroupID),
139 id = AROS_LONG2BE(dth->dth_ID);
141 Printf
143 "File: %s\n"
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,
148 dth->dth_BaseName
152 else
154 FPrintf(ErrorOutput(), ERROR_HEADER": Could not obtain datatype for file.\n");
155 rc = RETURN_FAIL;
158 UnLock(lock);
160 else
162 PrintFault(IoErr(), ERROR_HEADER);
163 rc = RETURN_FAIL;
166 return rc;
169 CONST_STRPTR gid2string(ULONG gid)
171 switch (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;