Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / identify / tools / Guru.c
blobc7b8dbd2a2af0063b0ea96178e7f9622a998d450
1 /*
2 * Copyright (c) 2010-2011 Matthias Rustler
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
22 * $Id$
25 #include <libraries/identify.h>
27 #include <proto/identify.h>
28 #include <proto/exec.h>
29 #include <proto/dos.h>
30 #include <proto/locale.h>
33 #define ARG_TEMPLATE "GURU,L=LASTALERT/S"
35 enum
37 ARG_GURU,
38 ARG_LAST,
39 ARG_COUNT
42 struct RDArgs *rda;
45 #define BUFSIZE (50)
47 static TEXT buf_dead[BUFSIZE];
48 static TEXT buf_subsys[BUFSIZE];
49 static TEXT buf_general[BUFSIZE];
50 static TEXT buf_spec[BUFSIZE];
53 #define CATCOMP_ARRAY
54 #include "strings.h"
56 #define CATALOG_NAME "System/C/IdentifyTools.catalog"
57 #define CATALOG_VERSION 1
59 static struct Catalog *catalog;
62 const char *ver = "$VER: Guru 2.0 (31.5.2011)";
64 static ULONG htoi(const char *ptr)
66 ULONG value = 0;
67 char ch = *ptr;
69 for (;;)
71 if (ch >= '0' && ch <= '9')
72 value = (value << 4) + (ch - '0');
73 else if (ch >= 'A' && ch <= 'F')
74 value = (value << 4) + (ch - 'A' + 10);
75 else if (ch >= 'a' && ch <= 'f')
76 value = (value << 4) + (ch - 'a' + 10);
77 else
78 return value;
79 ch = *(++ptr);
83 static void InitLocale(STRPTR catname, ULONG version)
85 LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library", 39);
86 if (LocaleBase)
88 catalog = OpenCatalog(NULL, catname, OC_Version, version,
89 TAG_DONE);
94 static void CleanupLocale(void)
96 if (catalog) CloseCatalog(catalog);
97 if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
101 static CONST_STRPTR MSG(ULONG id)
103 ULONG arridx;
105 // we have defined message IDs in the *.cd file, so we must first search
106 // for the ID in the array
109 arridx = 0;
110 arridx < sizeof (CatCompArray) / sizeof (struct CatCompArrayType) - 1;
111 arridx++
114 if (CatCompArray[arridx].cca_ID == id)
116 break;
119 if (catalog != NULL)
121 return GetCatalogStr(catalog, id, CatCompArray[arridx].cca_Str);
123 return CatCompArray[arridx].cca_Str;
127 int main(void)
129 InitLocale(CATALOG_NAME, CATALOG_VERSION);
131 ULONG guru = 0;
133 IPTR args[ARG_COUNT] = {0};
135 rda = (struct RDArgs *)AllocDosObject(DOS_RDARGS, NULL);
136 if (rda)
138 rda->RDA_ExtHelp = (STRPTR)MSG(MSG_GURU_HELP);
140 if (ReadArgs(ARG_TEMPLATE, args, rda))
142 if (args[ARG_LAST])
144 guru = IdHardwareNum(IDHW_LASTALERT, NULL);
146 else if (args[ARG_GURU])
148 guru = htoi((STRPTR)args[ARG_GURU]);
151 if (IdAlertTags(guru,
152 IDTAG_DeadStr, buf_dead,
153 IDTAG_SubsysStr, buf_subsys,
154 IDTAG_GeneralStr, buf_general,
155 IDTAG_SpecStr, buf_spec,
156 IDTAG_StrLength, BUFSIZE,
157 TAG_DONE) == IDERR_OKAY)
159 Printf(MSG(MSG_GURU_RESULT),
160 guru,
161 buf_dead,
162 buf_subsys,
163 buf_general,
164 buf_spec);
166 else
168 PutStr(MSG(MSG_GURU_BADCODE));
170 FreeArgs(rda);
172 FreeDosObject(DOS_RDARGS, rda);
174 CleanupLocale();
176 return 0;