some fixes to accented characters
[tangerine.git] / scripts / cint2.awk
blob3fd24a694bb535af2e532ac301b7104ab64163e1
1 BEGIN {
2 date="27-11-96";
4 RTYPES["long"]="LONG";
5 RTYPES["unsigned long"]="ULONG";
6 RTYPES["short"]="WORD";
7 RTYPES["unsigned short"]="UWORD";
8 RTYPES["char"]="BYTE";
9 RTYPES["unsigned char"]="UBYTE";
11 TYPES["ULONG"]=1;
12 TYPES["LONG"]=1;
13 TYPES["UBYTE"]=1;
14 TYPES["BYTE"]=1;
15 TYPES["UWORD"]=1;
16 TYPES["WORD"]=1;
17 TYPES["APTR"]=1;
18 TYPES["BPTR"]=1;
19 TYPES["STRPTR"]=1;
20 TYPES["BSTR"]=1;
21 TYPES["BOOL"]=1;
22 TYPES["Tag"]=1;
23 TYPES["FLOAT"]=1;
24 TYPES["DOUBLE"]=1;
25 TYPES[""]=1;
26 TYPES[""]=1;
28 # 1- types
29 # 2- commands
30 KEYWORDS["struct"]=2;
31 KEYWORDS["int"]=1;
32 KEYWORDS["char"]=1;
33 KEYWORDS["double"]=1;
34 KEYWORDS["float"]=1;
35 KEYWORDS["for"]=10;
36 KEYWORDS["if"]=10;
37 KEYWORDS["else"]=10;
38 KEYWORDS["do"]=10;
39 KEYWORDS["while"]=10;
40 KEYWORDS["switch"]=10;
41 KEYWORDS["case"]=10;
42 KEYWORDS["break"]=10;
43 KEYWORDS["continue"]=10;
44 KEYWORDS["goto"]=10;
45 KEYWORDS["union"]=2;
46 KEYWORDS["enum"]=2;
47 KEYWORDS["typedef"]=1;
48 KEYWORDS["void"]=1;
49 KEYWORDS["unsigned"]=3;
50 KEYWORDS["signed"]=3;
51 KEYWORDS["const"]=3;
52 KEYWORDS["long"]=3;
53 KEYWORDS["short"]=3;
54 KEYWORDS[""]=0;
55 KEYWORDS[""]=0;
57 SpecialStructs["exec"]="ExecBase";
58 SpecialStructs["graphics"]="GfxBase";
59 SpecialStructs["dos"]="DosLibrary";
60 SpecialStructs["intuition"]="IntuitionBase";
62 spaces=" ";
63 for (t=0; t<10; t++)
64 spaces=spaces spaces;
66 for (arg=1; arg<ARGC; arg++)
68 part_name=ARGV[arg];
69 Part_name=toupper(substr(part_name,1,1)) substr(part_name,2);
71 if (part_name in SpecialStructs)
72 struct_name=SpecialStructs[part_name];
73 else
74 struct_name="Library";
76 print "Working on " part_name "..."
78 dir="amiga/" part_name;
79 system("mkdir " dir);
80 print dir;
81 dir=dir"/";
82 INPUT="amiga/include/fd/" part_name "_lib.fd"
83 print INPUT
85 # Read LVO
86 delete LVO
87 while ((getline line < INPUT) > 0)
89 if (substr(line,1,6) == "##bias")
90 offset = int(substr(line,7))/6;
91 else if (substr(line,1,6) == "##base")
93 match(line,"[A-Za-z_][A-Za-z0-9_]*$");
94 Base = substr(line,RSTART+1,RLENGTH-1);
96 else if (!match (line,/[*#]/))
98 match(line,"[A-Za-z_][A-Za-z0-9_]*");
99 fname=substr(line,RSTART,RLENGTH);
100 line=substr(line,RSTART+RLENGTH);
101 if (match(line,"[(][^)]*[)]"))
103 if (RLENGTH!=2)
104 fargs=substr(line,RSTART+1,RLENGTH-2);
105 else
106 fargs="";
108 else
109 fargs="";
110 line=substr(line,RSTART+RLENGTH);
111 if (match(line,"[(][^)]*[)]"))
113 if (RLENGTH!=2)
114 fregs=substr(line,RSTART+1,RLENGTH-2);
115 else
116 fregs="";
118 else
119 fregs="";
120 #print fname " (" fargs ") (" fregs ") " offset
121 LVO[fname] = offset;
122 offset ++;
123 LVO_regs[fname] = toupper(fregs);
127 INPUT="amiga/include/clib/" part_name "_protos.h"
128 #print INPUT
129 getline line < INPUT
130 yyinit(line);
131 rt_type="";
133 #if (!match(FILENAME,"\/.*_"))
135 # print "Can't find libname"
136 # exit (10);
138 #dir=substr(FILENAME,RSTART+1,RLENGTH-2);
140 #if (dir!="")
142 # system("mkdir " dir);
143 # part_name=dir;
144 # dir=dir "/";
147 while ((token=yylex()) != "EOF")
149 #print "0 -" token "-" yyval "-"
150 if ((token=="keyword" && KEYWORDS[yyval]<10) || token=="typedef")
152 plevel=0;
153 token=read_type(token);
154 fname = yyval;
155 token=yylex();
157 if (token=="(")
159 plevel ++;
160 token=yylex();
162 if (rt_ptr!="")
163 ret=rt_type " " rt_ptr;
164 else
165 ret=rt_type;
167 if (token==")")
169 npar=1;
170 par_type[1]="void";
171 par_ptr[1]="";
172 par_name[1]="";
174 else
176 npar=0;
177 while (token!=")")
179 #print 1
180 if (token==",")
181 token=yylex();
182 token=read_type(token);
183 if (token=="ident")
185 name=yyval;
186 token=yylex();
188 else
189 name="";
191 # if (plevel != 1)
193 # plevel --;
194 # name=name ") "
195 # while((token==yylex())!=")" || plevel!=1)
197 #print 2
198 # if (token=="(")
199 # plevel ++;
200 # else if (token==")")
201 # plevel --;
202 # name=name " " yyval;
206 npar++;
207 par_type[npar]=rt_type;
208 par_ptr[npar]=rt_ptr;
209 par_name[npar]=name;
210 #print "npar " npar "-" rt_type "-" rt_ptr "-" name
214 print "Processing "fname"..."
215 #file="/dev/stdout"
216 file=dir tolower(fname) ".c"
218 if (fname in LVO)
220 offset=LVO[fname];
221 regs=LVO_regs[fname];
223 else
225 offset=-1;
226 regs="";
229 printf ("/*\n") > file;
230 print " Copyright © 1995-2001, The AROS Development Team. All rights reserved." >> file
231 printf (" %sId$\n", "$") >> file;
232 printf ("\n") >> file;
233 printf (" Desc:\n") >> file;
234 printf (" Lang: english\n") >> file;
235 printf ("*/\n") >> file;
236 printf ("#include \"%s_intern.h\"\n\n", part_name) >> file;
237 print "/*****************************************************************************\n" >> file
238 print " NAME */" >>file
239 print "#include <clib/" part_name "_protos.h>\n">>file
241 if (offset!=-1)
243 if (npar==1 && par_type[1]=="void" && par_ptr[1] == "" &&
244 par_name[1]=="")
245 print "\tAROS_LH0("ret", "fname",\n" >>file
246 else
247 print "\tAROS_LH"npar"("ret", "fname",\n" >>file
248 print "/* SYNOPSIS */" >>file
250 if (npar==1 && par_type[1]=="void" && par_ptr[1] == "" &&
251 par_name[1]=="")
253 print "\t/* void */" >>file
255 else
257 maxlen=0;
258 for (t=1; t<=npar; t++)
260 #print 3
261 len=length(par_type[t]);
262 len2=length(par_ptr[t]);
263 len+=len2 ? len2+1 : 0;
264 if (len > maxlen)
265 maxlen = len;
268 for (t=1; t<=npar; t++)
270 #print 4
271 len=length(par_type[t]);
272 len2=length(par_ptr[t]);
274 printf("\tAROS_LHA(%s", par_type[t])>>file;
275 printf("%s", substr(spaces,1,maxlen-len-len2))>>file;
276 printf("%s, %s, %s),\n",par_ptr[t],par_name[t],
277 substr(regs,1,2))>>file;
278 if (regs!="")
280 regs=substr(regs,4);
284 print "\n/* LOCATION */\n\tstruct "struct_name" *, "Base", "offset", "Part_name")">>file
286 else
288 print "\t"ret" "fname" (\n" >>file
289 print "/* SYNOPSIS */" >>file
291 if (npar==1 && par_type[1]=="void" && par_ptr[1] == "" &&
292 par_name[1]=="")
294 print "\tvoid)" >>file
296 else
298 maxlen=0;
299 for (t=1; t<=npar; t++)
301 #print 3
302 len=length(par_type[t]);
303 len2=length(par_ptr[t]);
304 len+=len2 ? len2+1 : 0;
305 if (len > maxlen)
306 maxlen = len;
309 for (t=1; t<=npar; t++)
311 #print 4
312 len=length(par_type[t]);
313 len2=length(par_ptr[t]);
315 printf("\t%s", par_type[t])>>file;
316 printf("%s", substr(spaces,1,maxlen-len-len2))>>file;
317 printf("%s %s",par_ptr[t],par_name[t])>>file;
318 if (t==npar)
319 printf(")\n")>>file;
320 else
321 printf(",\n")>>file;
325 print "\n/* FUNCTION\n\n INPUTS\n\n RESULT\n\n NOTES\n">>file
326 print " EXAMPLE\n\n BUGS\n\n SEE ALSO\n\n INTERNALS\n">>file
327 print " HISTORY\n\t" date " digulla automatically created from">>file
328 print "\t\t\t "part_name"_lib.fd and clib/"part_name"_protos.h\n">>file;
329 print "*****************************************************************************/" > file
330 print "{">>file;
331 print " AROS_LIBFUNC_INIT">>file;
332 if (Base!="")
333 print " AROS_LIBBASE_EXT_DECL(struct "struct_name" *,"Base")">>file;
334 print " extern void aros_print_not_implemented (char *);\n">>file;
335 print " aros_print_not_implemented (\"" fname "\");\n">>file;
336 print " AROS_LIBFUNC_EXIT">>file;
337 print "} /* " fname " */">>file;
338 fclose (file);
339 } # found "("
340 } # found keyword
341 } # while token != EOF
342 } # for all args
343 } # BEGIN
345 function read_type(pretoken ,token) {
346 token=pretoken;
347 #print "token3 " token "-" yyval
349 rt_type="";
350 while ((token=="keyword" && KEYWORDS[yyval]<10) || token=="typedef" ||
351 token=="...")
353 #print 5
354 rt_type=rt_type " " yyval;
355 if (KEYWORDS[yyval]==2)
357 token=yylex();
358 rt_type=rt_type " " yyval;
360 token=yylex();
361 #print "token2 " token
363 rt_type=substr(rt_type,2);
364 #print "type " rt_type
365 if (rt_type in RTYPES)
366 rt_type = RTYPES[rt_type];
368 rt_ptr="";
369 while (token=="*" || token=="(")
371 #print 6
372 rt_ptr=rt_ptr yyval;
373 if (token=="(")
374 plevel++;
375 token=yylex();
376 #print "token1 " token
378 #print "ptr " rt_ptr
380 return token;
383 function yyinit(str) {
384 yyrest=str;
387 function yylex() {
388 #print yylex
389 for (yyagain=1; yyagain; )
391 yyagain=0;
392 if (yyrest=="" || match(yyrest,/^[ \t\014\r]+/))
394 while (1)
396 while (yyrest=="")
398 if ((getline yyrest < INPUT) != 1)
399 return "EOF";
400 #print "1 -" yyrest "-"
401 if (substr(yyrest,1,1) == "#")
402 yyrest="";
404 if (!match(yyrest,"^[ \t\014\r]+"))
405 break;
406 yyrest=substr(yyrest,RSTART+RLENGTH);
409 if (match(yyrest,/^\/\*/))
411 yyrest=substr(yyrest,3);
412 while (!match(yyrest,"\*\/"))
414 if ((getline yyrest < INPUT) != 1)
415 return "EOF";
416 #print "2 -" yyrest "-"
418 yyrest=substr(yyrest,RSTART+RLENGTH);
419 yyagain=1;
422 if (match(yyrest,"^[a-zA-Z_][a-zA-Z0-9_]*"))
424 yyval=substr(yyrest,RSTART,RLENGTH);
425 yyrest=substr(yyrest,RSTART+RLENGTH);
427 if (yyval in TYPES)
428 return "typedef";
429 else if (yyval in KEYWORDS)
430 return "keyword";
431 else
432 return "ident";
434 if (match(yyrest,"^0[xX][0-9a-f]+[lL]?"))
436 yyval=substr(yyrest,RSTART,RLENGTH);
437 yyrest=substr(yyrest,RSTART+RLENGTH);
438 return "int_const";
440 if (match(yyrest,/^([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)([eE][0-9]+)?[fF]?/))
442 yyval=substr(yyrest,RSTART,RLENGTH);
443 yyrest=substr(yyrest,RSTART+RLENGTH);
444 return "float_const";
446 if (match(yyrest,"^0[0-7]+[lL]?"))
448 yyval=substr(yyrest,RSTART,RLENGTH);
449 yyrest=substr(yyrest,RSTART+RLENGTH);
450 return "int_const";
452 if (match(yyrest,"^[1-9][0-9]*[lL]?"))
454 yyval=substr(yyrest,RSTART,RLENGTH);
455 yyrest=substr(yyrest,RSTART+RLENGTH);
456 return "int_const";
458 if (match(yyrest,"^\""))
460 if (match(yyrest,"^\"(\\\"|[^\"])*\""))
462 yyval=substr(yyrest,RSTART,RLENGTH);
463 yyrest=substr(yyrest,RSTART+RLENGTH);
464 return "str_const";
466 else
468 yyval=substr(yyrest,1,length(yyrest)-1);
469 while (1)
471 if ((getline yyrest < INPUT) != 1)
472 return "EOF";
473 if (match(yyrest,"^(\\\"|[^\"])*\""))
474 break;
475 yyval=yyval substr(yyrest,1,length(yyrest)-1);
477 yyval=yyval substr(yyrest,RSTART,RLENGTH);
478 yyrest=substr(yyrest,RSTART+RLENGTH);
479 return "str_const";
482 if (substr(yyrest,1,3)=="...")
484 yyval="...";
485 yyrest=substr(yyrest,4);
486 return yyval;
488 yyval=substr(yyrest,1,1);
489 yyrest=substr(yyrest,2);
490 return yyval;