revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / identify / idformatstring.c
blob9ce90b432896492b7e3c1cd443fe95db17d56bec
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
15 * OR 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 <aros/debug.h>
27 #include <string.h>
29 #include "identify_intern.h"
31 static CONST_STRPTR commands[] =
33 "SYSTEM$",
34 "CPU$",
35 "FPU$",
36 "MMU$",
37 "OSVER$",
38 "EXECVER$",
39 "WBVER$",
40 "ROMSIZE$",
41 "CHIPSET$",
42 "GFXSYS$",
43 "CHIPRAM$",
44 "FASTRAM$",
45 "RAM$",
46 "SETPATCHVER$",
47 "AUDIOSYS$",
48 "OSNR$",
49 "VMMCHIPRAM$",
50 "VMMFASTRAM$",
51 "VMMRAM$",
52 "PLNCHIPRAM$",
53 "PLNFASTRAM$",
54 "PLNRAM$",
55 "VBR$",
56 "LASTALERT$",
57 "VBLANKFREQ$",
58 "POWERFREQ$",
59 "ECLOCK$",
60 "SLOWRAM$",
61 "GARY$",
62 "RAMSEY$",
63 "BATTCLOCK$",
64 "CHUNKYPLANAR$",
65 "POWERPC$",
66 "PPCCLOCK$",
67 "CPUREV$",
68 "CPUCLOCK$",
69 "FPUCLOCK$",
70 "RAMACCESS$",
71 "RAMWIDTH$",
72 "RAMCAS$",
73 "RAMBANDWIDTH$",
74 "TCPIP$",
75 "PPCOS$",
76 "AGNUS$",
77 "AGNUSMODE$",
78 "DENISE$",
79 "DENISEREV$",
80 "BOINGBAG$",
81 "EMULATED$",
82 "XLVERSION$",
83 "HOSTOS$",
84 "HOSTVERS$",
85 "HOSTMACHINE$",
86 "HOSTCPU$",
87 "HOSTSPEED$"
90 static LONG findcommand(TEXT *);
92 /*****************************************************************************
94 NAME */
95 #include <proto/identify.h>
97 AROS_LH4(ULONG, IdFormatString,
99 /* SYNOPSIS */
100 AROS_LHA(STRPTR , string, A0),
101 AROS_LHA(STRPTR , buffer, A1),
102 AROS_LHA(ULONG , len , D0),
103 AROS_LHA(struct TagItem *, tags , A2),
105 /* LOCATION */
106 struct IdentifyBaseIntern *, IdentifyBase, 11, Identify)
108 /* FUNCTION
109 The buffer will be filled with the format string until
110 the format string terminates or the buffer size is reached.
112 The format string may contain format tags, which are
113 surrounded by dollar signs. Doing so, the printf formattings
114 are kept for a following printf.
116 Format tags are case sensitive!
118 If you want to write a dollar sign, then double it: '$$'.
120 These format tags are known:
122 $SYSTEM$
123 $CPU$
124 $FPU$
125 $MMU$
126 $OSVER$
127 $EXECVER$
128 $WBVER$
129 $ROMSIZE$
130 $CHIPSET$
131 $GFXSYS$
132 $CHIPRAM$
133 $FASTRAM$
134 $RAM$
135 $SETPATCHVER$
136 $AUDIOSYS$
137 $OSNR$
138 $VMMCHIPRAM$
139 $VMMFASTRAM$
140 $VMMRAM$
141 $PLNCHIPRAM$
142 $PLNFASTRAM$
143 $PLNRAM$
144 $VBR$
145 $LASTALERT$
146 $VBLANKFREQ$
147 $POWERFREQ$
148 $ECLOCK$
149 $SLOWRAM$
150 $GARY$
151 $RAMSEY$
152 $BATTCLOCK$
153 $CHUNKYPLANAR$
154 $POWERPC$
155 $PPCCLOCK$
156 $CPUREV$
157 $CPUCLOCK$
158 $FPUCLOCK$
159 $RAMACCESS$
160 $RAMWIDTH$
161 $RAMCAS$
162 $RAMBANDWIDTH$
163 $TCPIP$
164 $PPCOS$
165 $AGNUS$
166 $AGNUSMODE$
167 $DENISE$
168 $DENISEREV$
169 $EMULATED$
170 $XLVERSION$
171 $HOSTOS$
172 $HOSTVERS$
173 $HOSTMACHINE$
174 $HOSTCPU$
175 $HOSTSPEED$
177 For their meanings, see the include file.
179 INPUTS
180 String -- (STRPTR) Format string
182 Buffer -- (STRPTR) Buffer to be filled with the result
183 until the format string terminates or the buffer
184 size is reached.
186 Length -- (ULONG) Length of the buffer, including the
187 null termination.
189 Tags -- (struct TagItem *) For future compatibility.
190 You must provide NULL or a pointer to TAG_DONE.
192 TAGS
194 RESULT
195 Length -- (ULONG) Length of the buffer that really
196 has been used.
198 NOTES
199 Remember that, unlike RawDoFmt(), the format tags must be
200 surrounded, i.e. started and ended, by a dollar sign '$'.
202 EXAMPLE
203 "Your CPU is a $CPU$ with $CPUCLOCK$ MHz"
205 BUGS
207 SEE ALSO
208 IdHardware(), IdEstimateFormatSize()
210 INTERNALS
212 HISTORY
215 *****************************************************************************/
217 AROS_LIBFUNC_INIT
219 // no tags
221 TEXT *from = string;
222 TEXT *to = buffer;
223 ULONG size = len;
224 LONG commandindex;
225 CONST_STRPTR toinsert;
226 ULONG cpycnt;
228 if (from == NULL || to == NULL || len < 1)
230 return 0;
233 len--; // for '\0'
235 while (len > 0 && *from)
237 if (*from == '$')
239 from++;
240 if (*from == '$')
242 *to++ = '$';
243 from++;
244 len--;
246 else if ((commandindex = findcommand(from)) != -1)
248 toinsert = IdHardware(commandindex, NULL);
249 cpycnt = strlen(toinsert);
250 if (cpycnt > len)
252 cpycnt = len;
254 memcpy(to, toinsert, cpycnt);
255 from += strlen(commands[commandindex]);
256 to += cpycnt;
257 len -= cpycnt;
260 else
262 *to++ = *from++;
263 len--;
266 *to = '\0';
268 return size - len;
270 AROS_LIBFUNC_EXIT
271 } /* IdFormatString */
274 static LONG findcommand(TEXT *t)
276 int i;
278 for (i = 0; i < sizeof commands / sizeof (STRPTR); i++)
280 if (strncmp(t, commands[i], strlen(commands[i])) == 0)
282 return i;
285 return -1;