1 # Creates C files with function prototypes from FD and clib/*_proto.h files.
5 # Required directory structure:
6 # amiga/include/fd/mylib_lib.fd
7 # amiga/include/clib/mylib_protos.h
9 # Usage: awk -f cint2.awk mylib
19 RTYPES
["long"]=
"LONG";
20 RTYPES
["unsigned long"]=
"ULONG";
21 RTYPES
["short"]=
"WORD";
22 RTYPES
["unsigned short"]=
"UWORD";
23 RTYPES
["char"]=
"BYTE";
24 RTYPES
["unsigned char"]=
"UBYTE";
55 KEYWORDS
["switch"]=
10;
58 KEYWORDS
["continue"]=
10;
62 KEYWORDS
["typedef"]=
1;
64 KEYWORDS
["unsigned"]=
3;
72 SpecialStructs
["exec"]=
"ExecBase";
73 SpecialStructs
["graphics"]=
"GfxBase";
74 SpecialStructs
["dos"]=
"DosLibrary";
75 SpecialStructs
["intuition"]=
"IntuitionBase";
81 for (arg=
1; arg
<ARGC; arg
++)
84 Part_name=
toupper(substr(part_name
,1,1)) substr(part_name
,2);
86 if (part_name in SpecialStructs
)
87 struct_name=SpecialStructs
[part_name
];
89 struct_name=
"Library";
91 print "Working on " part_name
"..."
93 dir=
"amiga/" part_name
;
97 INPUT=
"amiga/include/fd/" part_name
"_lib.fd"
102 while ((getline line
< INPUT
) > 0)
104 if (substr(line
,1,6) ==
"##bias")
105 offset = int
(substr(line
,7))/6;
106 else if (substr(line
,1,6) ==
"##base")
108 match(line
,"[A-Za-z_][A-Za-z0-9_]*$");
109 Base =
substr(line
,RSTART+1,RLENGTH-1);
111 else if (!
match (line
,/[*#]/))
113 match(line
,"[A-Za-z_][A-Za-z0-9_]*");
114 fname=
substr(line
,RSTART,RLENGTH);
115 line=
substr(line
,RSTART+RLENGTH);
116 if (match(line
,"[(][^)]*[)]"))
119 fargs=
substr(line
,RSTART+1,RLENGTH-2);
125 line=
substr(line
,RSTART+RLENGTH);
126 if (match(line
,"[(][^)]*[)]"))
129 fregs=
substr(line
,RSTART+1,RLENGTH-2);
135 #print fname " (" fargs ") (" fregs ") " offset
138 LVO_regs
[fname
] =
toupper(fregs
);
142 INPUT=
"amiga/include/clib/" part_name
"_protos.h"
148 #if (!match(FILENAME,"\/.*_"))
150 # print "Can't find libname"
153 #dir=substr(FILENAME,RSTART+1,RLENGTH-2);
157 # system("mkdir " dir);
162 while ((token=yylex
()) != "EOF")
164 #print "0 -" token "-" yyval "-"
165 if ((token==
"keyword" && KEYWORDS
[yyval
]<10) || token==
"typedef")
168 token=read_type
(token
);
178 ret=rt_type
" " rt_ptr
;
197 token=read_type
(token
);
210 # while((token==yylex())!=")" || plevel!=1)
215 # else if (token==")")
217 # name=name " " yyval;
222 par_type
[npar
]=rt_type
;
223 par_ptr
[npar
]=rt_ptr
;
225 #print "npar " npar "-" rt_type "-" rt_ptr "-" name
229 print "Processing "fname
"..."
231 file=dir
tolower(fname
) ".c"
236 regs=LVO_regs
[fname
];
244 printf ("/*\n") > file
;
245 print " Copyright © 2010, The AROS Development Team. All rights reserved." >> file
246 printf (" %sId$\n", "$") >> file
;
247 printf ("\n") >> file
;
248 printf (" Desc:\n") >> file
;
249 printf (" Lang: english\n") >> file
;
250 printf ("*/\n") >> file
;
251 printf ("#include \"%s_intern.h\"\n\n", part_name
) >> file
;
252 print "/*****************************************************************************\n" >> file
253 print " NAME */" >>file
254 print "#include <proto/" part_name
".h>\n">>file
258 if (npar==
1 && par_type
[1]==
"void" && par_ptr
[1] ==
"" &&
260 print "\tAROS_LH0("ret
", "fname
",\n" >>file
262 print "\tAROS_LH"npar
"("ret
", "fname
",\n" >>file
263 print "/* SYNOPSIS */" >>file
265 if (npar==
1 && par_type
[1]==
"void" && par_ptr
[1] ==
"" &&
268 print "\t/* void */" >>file
273 for (t=
1; t
<=npar
; t
++)
276 len=
length(par_type
[t
]);
277 len2=
length(par_ptr
[t
]);
278 len
+=len2 ? len2
+1 : 0;
283 for (t=
1; t
<=npar
; t
++)
286 len=
length(par_type
[t
]);
287 len2=
length(par_ptr
[t
]);
289 printf("\tAROS_LHA(%s", par_type
[t
])>>file
;
290 printf("%s", substr(spaces
,1,maxlen
-len
-len2
))>>file
;
291 printf("%s, %s, %s),\n",par_ptr
[t
],par_name
[t
],
292 substr(regs
,1,2))>>file
;
299 print "\n/* LOCATION */\n\tstruct "struct_name
" *, "Base
", "offset
", "Part_name
")">>file
303 print "\t"ret
" "fname
" (\n" >>file
304 print "/* SYNOPSIS */" >>file
306 if (npar==
1 && par_type
[1]==
"void" && par_ptr
[1] ==
"" &&
309 print "\tvoid)" >>file
314 for (t=
1; t
<=npar
; t
++)
317 len=
length(par_type
[t
]);
318 len2=
length(par_ptr
[t
]);
319 len
+=len2 ? len2
+1 : 0;
324 for (t=
1; t
<=npar
; t
++)
327 len=
length(par_type
[t
]);
328 len2=
length(par_ptr
[t
]);
330 printf("\t%s", par_type
[t
])>>file
;
331 printf("%s", substr(spaces
,1,maxlen
-len
-len2
))>>file
;
332 printf("%s %s",par_ptr
[t
],par_name
[t
])>>file
;
340 print "\n/* FUNCTION\n\n INPUTS\n\n RESULT\n\n NOTES\n">>file
341 print " EXAMPLE\n\n BUGS\n\n SEE ALSO\n\n INTERNALS\n">>file
342 print " HISTORY\n\n">>file
;
343 print "*****************************************************************************/" > file
345 print " AROS_LIBFUNC_INIT\n">>file
;
346 print " extern void aros_print_not_implemented (char *);">>file
;
347 print " aros_print_not_implemented (\"" fname
"\");\n">>file
;
348 print " AROS_LIBFUNC_EXIT">>file
;
349 print "} /* " fname
" */">>file
;
353 } # while token != EOF
357 function read_type
(pretoken
,token
) {
359 #print "token3 " token "-" yyval
362 while ((token==
"keyword" && KEYWORDS
[yyval
]<10) || token==
"typedef" ||
366 rt_type=rt_type
" " yyval
;
367 if (KEYWORDS
[yyval
]==
2)
370 rt_type=rt_type
" " yyval
;
373 #print "token2 " token
375 rt_type=
substr(rt_type
,2);
376 #print "type " rt_type
377 if (rt_type in RTYPES
)
378 rt_type = RTYPES
[rt_type
];
381 while (token==
"*" || token==
"(")
388 #print "token1 " token
395 function yyinit
(str
) {
401 for (yyagain=
1; yyagain
; )
404 if (yyrest==
"" || match(yyrest
,/^
[ \t\014\r]+/))
410 if ((getline yyrest
< INPUT
) != 1)
412 #print "1 -" yyrest "-"
413 if (substr(yyrest
,1,1) ==
"#")
416 if (!
match(yyrest
,"^[ \t\014\r]+"))
418 yyrest=
substr(yyrest
,RSTART+RLENGTH);
421 if (match(yyrest
,/^\
/\
*/))
423 yyrest=
substr(yyrest
,3);
424 while (!
match(yyrest
,"\*\/"))
426 if ((getline yyrest
< INPUT
) != 1)
428 #print "2 -" yyrest "-"
430 yyrest=
substr(yyrest
,RSTART+RLENGTH);
434 if (match(yyrest
,"^[a-zA-Z_][a-zA-Z0-9_]*"))
436 yyval=
substr(yyrest
,RSTART,RLENGTH);
437 yyrest=
substr(yyrest
,RSTART+RLENGTH);
441 else if (yyval in KEYWORDS
)
446 if (match(yyrest
,"^0[xX][0-9a-f]+[lL]?"))
448 yyval=
substr(yyrest
,RSTART,RLENGTH);
449 yyrest=
substr(yyrest
,RSTART+RLENGTH);
452 if (match(yyrest
,/^
([0-9]*\.
[0-9]+|[0-9]+\.
[0-9]*)([eE
][0-9]+)?
[fF
]?
/))
454 yyval=
substr(yyrest
,RSTART,RLENGTH);
455 yyrest=
substr(yyrest
,RSTART+RLENGTH);
456 return "float_const";
458 if (match(yyrest
,"^0[0-7]+[lL]?"))
460 yyval=
substr(yyrest
,RSTART,RLENGTH);
461 yyrest=
substr(yyrest
,RSTART+RLENGTH);
464 if (match(yyrest
,"^[1-9][0-9]*[lL]?"))
466 yyval=
substr(yyrest
,RSTART,RLENGTH);
467 yyrest=
substr(yyrest
,RSTART+RLENGTH);
470 if (match(yyrest
,"^\""))
472 if (match(yyrest
,"^\"(\\\"|[^\"])*\""))
474 yyval=
substr(yyrest
,RSTART,RLENGTH);
475 yyrest=
substr(yyrest
,RSTART+RLENGTH);
480 yyval=
substr(yyrest
,1,length(yyrest
)-1);
483 if ((getline yyrest
< INPUT
) != 1)
485 if (match(yyrest
,"^(\\\"|[^\"])*\""))
487 yyval=yyval
substr(yyrest
,1,length(yyrest
)-1);
489 yyval=yyval
substr(yyrest
,RSTART,RLENGTH);
490 yyrest=
substr(yyrest
,RSTART+RLENGTH);
494 if (substr(yyrest
,1,3)==
"...")
497 yyrest=
substr(yyrest
,4);
500 yyval=
substr(yyrest
,1,1);
501 yyrest=
substr(yyrest
,2);