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
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"
47 static TEXT buf_dead
[BUFSIZE
];
48 static TEXT buf_subsys
[BUFSIZE
];
49 static TEXT buf_general
[BUFSIZE
];
50 static TEXT buf_spec
[BUFSIZE
];
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
)
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);
83 static void InitLocale(STRPTR catname
, ULONG version
)
85 LocaleBase
= (struct LocaleBase
*)OpenLibrary("locale.library", 39);
88 catalog
= OpenCatalog(NULL
, catname
, OC_Version
, version
,
94 static void CleanupLocale(void)
96 if (catalog
) CloseCatalog(catalog
);
97 if (LocaleBase
) CloseLibrary((struct Library
*)LocaleBase
);
101 static CONST_STRPTR
MSG(ULONG id
)
105 // we have defined message IDs in the *.cd file, so we must first search
106 // for the ID in the array
110 arridx
< sizeof (CatCompArray
) / sizeof (struct CatCompArrayType
) - 1;
114 if (CatCompArray
[arridx
].cca_ID
== id
)
121 return GetCatalogStr(catalog
, id
, CatCompArray
[arridx
].cca_Str
);
123 return CatCompArray
[arridx
].cca_Str
;
129 InitLocale(CATALOG_NAME
, CATALOG_VERSION
);
133 IPTR args
[ARG_COUNT
] = {0};
135 rda
= (struct RDArgs
*)AllocDosObject(DOS_RDARGS
, NULL
);
138 rda
->RDA_ExtHelp
= (STRPTR
)MSG(MSG_GURU_HELP
);
140 if (ReadArgs(ARG_TEMPLATE
, args
, rda
))
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
),
168 PutStr(MSG(MSG_GURU_BADCODE
));
172 FreeDosObject(DOS_RDARGS
, rda
);