Added locale item (sysmon.cd)
[AROS.git] / workbench / c / Identify / main.c
bloba4fe2d864c456a10294243bbfa83cbe9b8b1619f
1 /*
2 Copyright © 2004-2016, 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 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";
76 enum
78 ARG_FILE,
79 ARG_VERBOSE,
80 ARG_COUNT
83 /*** Prototypes *************************************************************/
84 static LONG identify(CONST_STRPTR filename, BOOL verbose);
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(), prog_name);
110 rc = RETURN_FAIL;
113 return rc;
116 static LONG 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;
127 CONST_STRPTR gid_str = GetDTString(dth->dth_GroupID);
129 if (!verbose)
131 Printf("%s:\t%s/%s\n", filename, gid_str, dth->dth_Name);
133 else
135 ULONG gid = AROS_LONG2BE(dth->dth_GroupID),
136 id = AROS_LONG2BE(dth->dth_ID);
138 Printf
140 "File: %s\n"
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,
145 dth->dth_BaseName
149 ReleaseDataType(dt);
151 else
153 FPrintf(ErrorOutput(),
154 PROG_NAME ": Could not obtain datatype for file.\n");
155 rc = RETURN_FAIL;
158 UnLock(lock);
160 else
162 PrintFault(IoErr(), prog_name);
163 rc = RETURN_FAIL;
166 return rc;