2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
5 Code to parse the command line options and the module config file for
17 #include "functionhead.h"
20 const static char bannertemplate
[] =
22 " *** Automatically generated from '%s'. Edits will be lost. ***\n"
23 " Copyright © 1995-%4u, The AROS Development Team. All rights reserved.\n"
27 getBanner(struct config
* config
)
29 static unsigned currentyear
= 0;
31 int bannerlength
= strlen(config
->conffile
) + strlen(bannertemplate
);
32 // No additional bytes needed because
33 // + 1 (NUL) + 4 (4 digit year) - strlen("%s") - strlen("%4u) = 0
35 char * banner
= malloc(bannerlength
);
41 struct tm
*utctm
= gmtime(&rawtime
);
42 currentyear
= utctm
->tm_year
+ 1900;
45 snprintf (banner
, bannerlength
, bannertemplate
, config
->conffile
, currentyear
);
51 freeBanner(char *banner
)
56 const static char usage
[] =
58 "Usage: genmodule [-c conffile] [-s suffix] [-d gendir] [-v versionextra]\n"
59 " {writefiles|writemakefile|writeincludes|writelibdefs|writefunclist|writefd|writeskel|writethunk} modname modtype\n"
62 static void readconfig(struct config
*);
63 static struct classinfo
*newclass(struct config
*);
64 static struct handlerinfo
*newhandler(struct config
*);
65 static struct interfaceinfo
*newinterface(struct config
*);
67 /* the method prefices for the supported classes */
68 static const char *muimprefix
[] =
74 static const char *gadgetmprefix
[] =
81 static const char *dtmprefix
[] =
90 /* Create a config struct. Initialize with the values from the programs command
91 * line arguments and the contents of the modules .conf file
93 struct config
*initconfig(int argc
, char **argv
)
96 char *s
, **argvit
= argv
+ 1;
99 cfg
= malloc(sizeof(struct config
));
102 fprintf(stderr
, "Out of memory\n");
106 memset(cfg
, 0, sizeof(struct config
));
108 while ((c
= getopt(argc
, argv
, ":c:s:d:v:")) != -1)
112 fprintf(stderr
, "Option -%c needs an argument\n",optopt
);
119 cfg
->conffile
= optarg
;
123 cfg
->suffix
= optarg
;
128 /* Remove / at end if present */
129 if ((optarg
)[strlen(*argvit
)-1]=='/') (optarg
)[strlen(optarg
)-1]='\0';
130 cfg
->gendir
= optarg
;
134 cfg
->versionextra
= optarg
;
138 fprintf(stderr
, "Internal error: Unhandled option\n");
143 if (optind
+ 3 != argc
)
145 fprintf(stderr
, "Wrong number of arguments.\n%s", usage
);
149 if (strcmp(argv
[optind
], "writefiles") == 0)
151 cfg
->command
= FILES
;
153 else if (strcmp(argv
[optind
], "writemakefile") == 0)
155 cfg
->command
= MAKEFILE
;
157 else if (strcmp(argv
[optind
], "writeincludes") == 0)
159 cfg
->command
= INCLUDES
;
161 else if (strcmp(argv
[optind
], "writelibdefs") == 0)
163 cfg
->command
= LIBDEFS
;
165 else if (strcmp(argv
[optind
], "writefunclist") == 0)
167 cfg
->command
= WRITEFUNCLIST
;
169 else if (strcmp(argv
[optind
], "writefd") == 0)
171 cfg
->command
= WRITEFD
;
173 else if (strcmp(argv
[optind
], "writeskel") == 0)
175 cfg
->command
= WRITESKEL
;
177 else if (strcmp(argv
[optind
], "writethunk") == 0)
179 cfg
->command
= WRITETHUNK
;
183 fprintf(stderr
, "Unrecognized argument \"%s\"\n%s", argv
[optind
], usage
);
187 cfg
->modulename
= argv
[optind
+1];
188 cfg
->modulenameupper
= strdup(cfg
->modulename
);
189 for (s
=cfg
->modulenameupper
; *s
!='\0'; *s
= toupper(*s
), s
++) {
190 if (!isalnum(*s
)) *s
= '_';
193 if (strcmp(argv
[optind
+2],"library")==0)
195 cfg
->modtype
= LIBRARY
;
196 cfg
->moddir
= "Libs";
198 else if (strcmp(argv
[optind
+2],"mcc")==0)
201 cfg
->moddir
= "Classes/Zune";
203 else if (strcmp(argv
[optind
+2],"mui")==0)
206 cfg
->moddir
= "Classes/Zune";
208 else if (strcmp(argv
[optind
+2],"mcp")==0)
211 cfg
->moddir
= "Classes/Zune";
213 else if (strcmp(argv
[optind
+2], "device")==0)
215 cfg
->modtype
= DEVICE
;
216 cfg
->moddir
= "Devs";
218 else if (strcmp(argv
[optind
+2], "resource")==0)
220 cfg
->modtype
= RESOURCE
;
221 cfg
->moddir
= "Devs";
223 else if (strcmp(argv
[optind
+2], "gadget")==0)
225 cfg
->modtype
= GADGET
;
226 cfg
->moddir
= "Classes/Gadgets";
228 else if (strcmp(argv
[optind
+2], "datatype")==0)
230 cfg
->modtype
= DATATYPE
;
231 cfg
->moddir
= "Classes/DataTypes";
233 else if (strcmp(argv
[optind
+2], "usbclass")==0)
235 cfg
->modtype
= USBCLASS
;
236 cfg
->moddir
= "Classes/USB";
239 cfg
->suffix
= "class";
243 else if (strcmp(argv
[optind
+2], "hidd")==0)
246 cfg
->moddir
= "Devs/Drivers";
248 else if (strcmp(argv
[optind
+2], "handler")==0)
250 cfg
->modtype
= HANDLER
;
251 cfg
->moddir
= "$(AROS_DIR_FS)";
253 else if (strcmp(argv
[optind
+2], "hook")==0)
255 cfg
->modtype
= HANDLER
;
256 cfg
->moddir
= "Devs";
260 fprintf(stderr
, "Unknown modtype \"%s\" specified for second argument\n", argv
[optind
+2]);
263 cfg
->modtypestr
= argv
[optind
+2];
266 cfg
->suffix
= argv
[optind
+2];
268 /* Fill fields with default value if not specified on the command line */
272 if (cfg
->conffile
== NULL
)
274 snprintf(tmpbuf
, sizeof(tmpbuf
), "%s.conf", cfg
->modulename
);
275 cfg
->conffile
= strdup(tmpbuf
);
278 if (cfg
->gendir
== NULL
)
284 /* For a device add the functions given in beginiofunc and abortiofunc to the functionlist
285 * if they are provided
287 if (cfg
->beginiofunc
!= NULL
)
289 struct functionhead
*funchead
;
291 cfg
->intcfg
|= CFG_NOREADFUNCS
;
293 /* Add beginio_func to the list of functions */
294 funchead
= newfunctionhead(cfg
->beginiofunc
, REGISTERMACRO
);
295 funchead
->type
= strdup("void");
297 funcaddarg(funchead
, "struct IORequest *ioreq", "A1");
299 funchead
->next
= cfg
->funclist
;
300 cfg
->funclist
= funchead
;
302 /* Add abortio_func to the list of functions */
303 funchead
= newfunctionhead(cfg
->abortiofunc
, REGISTERMACRO
);
304 funchead
->type
= strdup("LONG");
306 funcaddarg(funchead
, "struct IORequest *ioreq", "A1");
308 funchead
->next
= cfg
->funclist
->next
;
309 cfg
->funclist
->next
= funchead
;
311 else if (cfg
->modtype
== DEVICE
&& cfg
->intcfg
& CFG_NOREADFUNCS
)
316 "beginio_func and abortio_func missing for a device with a non empty function list\n"
321 /* See if we have any stackcall options */
323 struct functionhead
*funchead
;
325 for (funchead
= cfg
->funclist
; funchead
; funchead
= funchead
->next
) {
326 if (funchead
->libcall
== STACK
) {
327 cfg
->options
|= OPTION_STACKCALL
;
333 /* Provide default version for functions that didnt have it */
335 struct functionhead
*funchead
;
336 int defversion
= cfg
->majorversion
; /* Assume library version is default */
338 for (funchead
= cfg
->funclist
; funchead
; funchead
= funchead
->next
) {
339 if (funchead
->version
> -1) {
340 /* There was at least one .version tag. Assume 0 is default */
346 for (funchead
= cfg
->funclist
; funchead
; funchead
= funchead
->next
) {
347 if (funchead
->version
== -1) {
348 funchead
->version
= defversion
;
353 /* Verify that a handler has a handler */
354 if (cfg
->modtype
== HANDLER
) {
355 if (cfg
->handlerfunc
== NULL
) {
356 fprintf(stderr
, "handler modules require a 'handler_func' ##config option\n");
359 cfg
->options
|= OPTION_NOAUTOLIB
| OPTION_NOEXPUNGE
| OPTION_NOOPENCLOSE
;
365 /* Functions to read configuration from the configuration file */
367 #include "fileread.h"
369 static char *readsections(struct config
*, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
);
370 static void readsectionconfig(struct config
*, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
);
371 static void readsectioncdef(struct config
*);
372 static void readsectioncdefprivate(struct config
*);
373 static void readsectionstubprivate(struct config
*);
374 static void readsectionstartup(struct config
*);
375 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
, enum libcall def_libcall
);
376 static void readsectionclass_methodlist(struct classinfo
*);
377 static void readsectionclass(struct config
*);
378 static void readsectionhandler(struct config
*);
379 static void readsectioninterface(struct config
*);
381 static void readconfig(struct config
*cfg
)
383 struct classinfo
*mainclass
= NULL
;
385 /* Create a classinfo structure if this module is a class */
386 switch (cfg
->modtype
)
401 mainclass
= newclass(cfg
);
402 mainclass
->classtype
= cfg
->modtype
;
406 fprintf(stderr
, "Internal error: unsupported modtype for classinfo creation\n");
410 switch (cfg
->modtype
)
423 mainclass
->boopsimprefix
= muimprefix
;
431 mainclass
->boopsimprefix
= gadgetmprefix
;
435 mainclass
->boopsimprefix
= dtmprefix
;
439 /* FIXME: need boopsimprefix ? */
442 fprintf(stderr
, "Internal error: unsupported modtype for firstlvo\n");
446 if (!fileopen(cfg
->conffile
))
448 fprintf(stderr
, "In readconfig: Could not open %s\n", cfg
->conffile
);
452 /* Read all sections and see that we are at the end of the file */
453 if (readsections(cfg
, mainclass
, NULL
, 0) != NULL
)
454 exitfileerror(20, "Syntax error");
459 /* readsections will scan through all the sections in the config file.
461 * struct config *cfg: The module config data which may be updated by
462 * the information in the sections
463 * struct classinfo *cl: The classdata to be filled with data from the sections.
464 * This may be NULL if this is the main part of the configuration file and the
465 * type of the module is not a class
466 * int inclass: Boolean to indicate if we are in a class part. If not we are in the main
467 * part of the config file.
469 static char *readsections(struct config
*cfg
, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
)
474 while ((line
=readline())!=NULL
)
476 if (strncmp(line
, "##", 2)==0)
478 static char *parts
[] =
480 "config", "cdefprivate", "cdef", "stubprivate", "startup", "functionlist", "methodlist", "class", "handler", "interface", "attributelist", "cfunctionlist"
482 const unsigned int nums
= sizeof(parts
)/sizeof(char *);
483 unsigned int partnum
;
487 while (isspace(*s
)) s
++;
489 if (strncmp(s
, "begin", 5)!=0)
494 exitfileerror(20, "space after begin expected\n");
495 while (isspace(*s
)) s
++;
497 for (i
= 0, partnum
= 0; partnum
==0 && i
<nums
; i
++)
499 if (strncmp(s
, parts
[i
], strlen(parts
[i
]))==0)
502 s
+= strlen(parts
[i
]);
503 while (isspace(*s
)) s
++;
505 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
509 exitfileerror(20, "unknown start of section\n");
513 readsectionconfig(cfg
, cl
, in
, inclass
);
517 case 2: /* cdefprivate */
519 exitfileerror(20, "cdefprivate section not allowed in class section\n");
520 readsectioncdefprivate(cfg
);
525 exitfileerror(20, "cdef section not allowed in class section\n");
526 readsectioncdef(cfg
);
529 case 4: /* stubprivate */
531 exitfileerror(20, "stubprivate section not allowed in class section\n");
532 readsectionstubprivate(cfg
);
535 case 5: /* startup */
537 exitfileerror(20, "startup section not allowed in class section\n");
538 readsectionstartup(cfg
);
541 case 6: /* functionlist */
543 exitfileerror(20, "functionlist section not allow in class section\n");
544 if (cfg
->basename
==NULL
)
545 exitfileerror(20, "section functionlist has to come after section config\n");
547 readsectionfunctionlist("functionlist", &cfg
->funclist
, cfg
->firstlvo
, 0, REGISTERMACRO
);
548 cfg
->intcfg
|= CFG_NOREADFUNCS
;
551 case 7: /* methodlist */
552 if (cl
== NULL
&& in
== NULL
)
553 exitfileerror(20, "methodlist section when not in a class or interface\n");
555 readsectionclass_methodlist(cl
);
557 readsectionfunctionlist("methodlist", &in
->methodlist
, 0, 0, REGISTERMACRO
);
558 cfg
->intcfg
|= CFG_NOREADFUNCS
;
563 exitfileerror(20, "class section may not be in nested\n");
564 readsectionclass(cfg
);
567 case 9: /* handler */
568 readsectionhandler(cfg
);
571 case 10: /* interface */
573 exitfileerror(20, "interface section may not be nested\n");
574 readsectioninterface(cfg
);
577 case 11: /* attributelist */
579 exitfileerror(20, "attributelist only valid in interface sections\n");
580 readsectionfunctionlist("attributelist", &in
->attributelist
, 0, 1, INVALID
);
583 case 12: /* cfunctionlist */
585 exitfileerror(20, "cfunctionlist section not allow in class section\n");
586 if (cfg
->basename
==NULL
)
587 exitfileerror(20, "section cfunctionlist has to come after section config\n");
589 readsectionfunctionlist("cfunctionlist", &cfg
->funclist
, cfg
->firstlvo
, 0, REGISTER
);
590 cfg
->intcfg
|= CFG_NOREADFUNCS
;
594 else if (strlen(line
)!=0)
595 filewarning("warning line outside section ignored\n");
601 exitfileerror(20, "No config section in conffile\n");
603 /* If no indication was given for generating includes or not
604 decide on module type and if there are functions
606 if(!((cfg
->options
& OPTION_INCLUDES
) || (cfg
->options
& OPTION_NOINCLUDES
)))
608 switch (cfg
->modtype
)
612 cfg
->options
|= OPTION_INCLUDES
;
620 cfg
->options
|= OPTION_NOINCLUDES
;
625 (cfg
->funclist
!= NULL
)
626 || (cfg
->cdeflines
!= NULL
)
627 || strcmp(cfg
->libbasetypeptrextern
, "struct Device *") != 0
628 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
635 (cfg
->funclist
!= NULL
)
636 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
640 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for includes\n");
646 /* If no indication was given for not generating stubs only generate them if
647 * the module has functions
649 if(!((cfg
->options
& OPTION_STUBS
) || (cfg
->options
& OPTION_NOSTUBS
)))
651 switch (cfg
->modtype
)
654 cfg
->options
|= (cfg
->funclist
!= NULL
) ? OPTION_STUBS
: OPTION_NOSTUBS
;
667 cfg
->options
|= OPTION_NOSTUBS
;
671 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for stubs\n");
677 /* If no indication was given for generating autoinit code or not
678 decide on module type
680 if(!((cfg
->options
& OPTION_AUTOINIT
) || (cfg
->options
& OPTION_NOAUTOINIT
)))
682 switch (cfg
->modtype
)
685 cfg
->options
|= OPTION_AUTOINIT
;
698 cfg
->options
|= OPTION_NOAUTOINIT
;
702 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for autoinit\n");
708 if ((cfg
->modtype
== RESOURCE
) || (cfg
->modtype
== HANDLER
))
709 /* Enforce noopenclose for resources and handlers */
710 cfg
->options
|= OPTION_NOOPENCLOSE
;
711 else if (!(cfg
->options
& OPTION_SELFINIT
))
712 /* Enforce using RTF_AUTOINIT for everything except resources */
713 cfg
->options
|= OPTION_RESAUTOINIT
;
719 static void readsectionconfig(struct config
*cfg
, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
)
722 char *line
, *s
, *s2
, *libbasetypeextern
= NULL
;
729 exitfileerror(20, "unexpected end of file in section config\n");
731 if (strncmp(line
, "##", 2)!=0)
733 const char *names
[] =
735 "basename", "libbase", "libbasetype", "libbasetypeextern",
736 "version", "date", "copyright", "libcall", "forcebase", "superclass",
737 "superclass_field", "residentpri", "options", "sysbase_field",
738 "seglist_field", "rootbase_field", "classptr_field", "classptr_var",
739 "classid", "classdatatype", "beginio_func", "abortio_func", "dispatcher",
740 "initpri", "type", "addromtag", "oopbase_field",
741 "rellib", "interfaceid", "interfacename",
742 "methodstub", "methodbase", "attributebase", "handler_func",
745 const unsigned int namenums
= sizeof(names
)/sizeof(char *);
746 unsigned int namenum
;
748 for (i
= 0, namenum
= 0; namenum
==0 && i
<namenums
; i
++)
752 strncmp(line
, names
[i
], strlen(names
[i
]))==0
753 && isspace(*(line
+strlen(names
[i
])))
758 exitfileerror(20, "unrecognized configuration option\n");
760 s
= line
+ strlen(names
[namenum
-1]);
762 exitfileerror(20, "space character expected after \"%s\"\n", names
[namenum
-1]);
764 while (isspace(*s
)) s
++;
766 exitfileerror(20, "unexpected end of line\n");
769 while (isspace(*(s2
-1))) s2
--;
774 case 1: /* basename */
776 cfg
->basename
= strdup(s
);
778 cl
->basename
= strdup(s
);
780 exitfileerror(20, "basename not valid config option when in an interface section\n");
783 case 2: /* libbase */
785 exitfileerror(20, "libbase not valid config option when in a class section\n");
786 cfg
->libbase
= strdup(s
);
789 case 3: /* libbasetype */
791 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
792 cfg
->libbasetype
= strdup(s
);
795 case 4: /* libbasetypeextern */
797 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
798 libbasetypeextern
= strdup(s
);
801 case 5: /* version */
803 exitfileerror(20, "version not valid config option when in a class section\n");
804 if (sscanf(s
, "%u.%u", &cfg
->majorversion
, &cfg
->minorversion
)!=2)
805 exitfileerror(20, "wrong version string \"%s\"\n", s
);
810 exitfileerror(20, "date not valid config option when in a class section\n");
812 if (strptime(s
, "%e.%m.%Y", &date
) == NULL
)
814 exitfileerror(20, "date string has to have d.m.yyyy format\n");
817 cfg
->datestring
= strdup(s
);
820 case 7: /* copyright */
822 exitfileerror(20, "copyright not valid config option when in a class section\n");
823 cfg
->copyright
= strdup(s
);
826 case 8: /* libcall */
827 fprintf(stderr
, "libcall specification is deprecated and ignored\n");
830 case 9: /* forcebase */
832 exitfileerror(20, "forcebase not valid config option when in a class section\n");
833 slist_append(&cfg
->forcelist
, s
);
836 case 10: /* superclass */
838 exitfileerror(20, "superclass specified when not a BOOPSI class\n");
839 cl
->superclass
= strdup(s
);
842 case 11: /* superclass_field */
844 exitfileerror(20, "superclass_field specified when not a BOOPSI class\n");
845 cl
->superclass_field
= strdup(s
);
848 case 12: /* residentpri */
854 count
= sscanf(s
, "%d%c", &cfg
->residentpri
, &dummy
);
856 cfg
->residentpri
< -128 || cfg
->residentpri
> 127
859 exitfileerror(20, "residentpri number format error\n");
863 exitfileerror(20, "residentpri not valid config option when in a class section\n");
866 case 13: /* options */
869 static const char *optionnames
[] =
871 "noautolib", "noexpunge", "noresident", "peropenerbase",
872 "pertaskbase", "includes", "noincludes", "nostubs",
873 "autoinit", "noautoinit", "resautoinit", "noopenclose",
876 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
881 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
883 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
886 s
+= strlen(optionnames
[i
]);
887 while (isspace(*s
)) s
++;
891 exitfileerror(20, "Unrecognized option\n");
895 exitfileerror(20, "Unrecognized option\n");
898 case 1: /* noautolib */
899 cfg
->options
|= OPTION_NOAUTOLIB
;
901 case 2: /* noexpunge */
902 cfg
->options
|= OPTION_NOEXPUNGE
;
904 case 3: /* noresident */
905 cfg
->options
|= OPTION_NORESIDENT
;
908 case 5: /* pertaskbase */
909 cfg
->options
|= OPTION_PERTASKBASE
;
911 case 4: /* peropenerbase */
912 if (cfg
->options
& OPTION_DUPBASE
)
913 exitfileerror(20, "Only one option peropenerbase or pertaskbase allowed\n");
914 cfg
->options
|= OPTION_DUPBASE
;
916 case 6: /* includes */
917 if (cfg
->options
& OPTION_NOINCLUDES
)
918 exitfileerror(20, "option includes and noincludes are incompatible\n");
919 cfg
->options
|= OPTION_INCLUDES
;
921 case 7: /* noincludes */
922 if (cfg
->options
& OPTION_INCLUDES
)
923 exitfileerror(20, "option includes and noincludes are incompatible\n");
924 cfg
->options
|= OPTION_NOINCLUDES
;
926 case 8: /* nostubs */
927 cfg
->options
|= OPTION_NOSTUBS
;
929 case 9: /* autoinit */
930 if (cfg
->options
& OPTION_NOAUTOINIT
)
931 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
932 cfg
->options
|= OPTION_AUTOINIT
;
934 case 10: /* noautoinit */
935 if (cfg
->options
& OPTION_AUTOINIT
)
936 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
937 cfg
->options
|= OPTION_NOAUTOINIT
;
939 case 11: /* resautoinit */
940 if (cfg
->options
& OPTION_SELFINIT
)
941 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
942 cfg
->options
|= OPTION_RESAUTOINIT
;
945 cfg
->options
|= OPTION_NOOPENCLOSE
;
947 case 13: /* noresautoinit */
948 if (cfg
->options
& OPTION_RESAUTOINIT
)
949 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
950 cfg
->options
|= OPTION_SELFINIT
;
953 while (isspace(*s
)) s
++;
958 static const char *optionnames
[] =
962 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
967 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
969 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
972 s
+= strlen(optionnames
[i
]);
973 while (isspace(*s
)) s
++;
977 exitfileerror(20, "Unrecognized option\n");
981 exitfileerror(20, "Unrecognized option\n");
984 case 1: /* private */
985 cl
->options
|= COPTION_PRIVATE
;
988 while (isspace(*s
)) s
++;
993 case 14: /* sysbase_field */
995 exitfileerror(20, "sysbase_field not valid config option when in a class section\n");
996 cfg
->sysbase_field
= strdup(s
);
999 case 15: /* seglist_field */
1001 exitfileerror(20, "seglist_field not valid config option when in a class section\n");
1002 cfg
->seglist_field
= strdup(s
);
1005 case 16: /* rootbase_field */
1007 exitfileerror(20, "rootbase_field not valid config option when in a class section\n");
1008 cfg
->rootbase_field
= strdup(s
);
1011 case 17: /* classptr_field */
1017 "classptr_field specified when not a BOOPSI class\n"
1020 cl
->classptr_field
= strdup(s
);
1023 case 18: /* classptr_var */
1029 "classptr_var specified when not a BOOPSI class\n"
1032 cl
->classptr_var
= strdup(s
);
1035 case 19: /* classid */
1037 exitfileerror(20, "classid specified when not a BOOPSI class\n");
1038 if (cl
->classid
!= NULL
)
1039 exitfileerror(20, "classid specified twice\n");
1040 cl
->classid
= strdup(s
);
1041 if (strcmp(cl
->classid
, "NULL") == 0)
1042 cl
->options
|= COPTION_PRIVATE
;
1045 case 20: /* classdatatype */
1047 exitfileerror(20, "classdatatype specified when not a BOOPSI class\n");
1048 cl
->classdatatype
= strdup(s
);
1051 case 21: /* beginio_func */
1053 exitfileerror(20, "beginio_func not valid config option when in a class section\n");
1054 if (cfg
->modtype
!= DEVICE
)
1055 exitfileerror(20, "beginio_func specified when not a device\n");
1056 cfg
->beginiofunc
= strdup(s
);
1059 case 22: /* abortio_func */
1061 exitfileerror(20, "abortio_func not valid config option when in a class section\n");
1062 if (cfg
->modtype
!= DEVICE
)
1063 exitfileerror(20, "abortio_func specified when not a device\n");
1064 cfg
->abortiofunc
= strdup(s
);
1067 case 23: /* dispatcher */
1069 exitfileerror(20, "dispatcher specified when not a BOOPSI class\n");
1070 cl
->dispatcher
= strdup(s
);
1071 /* function references are not needed when dispatcher is specified */
1072 cfg
->intcfg
|= CFG_NOREADFUNCS
;
1075 case 24: /* initpri */
1081 count
= sscanf(s
, "%d%c", &cl
->initpri
, &dummy
);
1083 cl
->initpri
< -128 || cl
->initpri
> 127
1086 exitfileerror(20, "initpri number format error\n");
1090 exitfileerror(20, "initpri only valid config option for a BOOPSI class\n");
1095 exitfileerror(20, "type only valid config option in a class section\n");
1096 if (strcmp(s
,"mcc")==0)
1097 cl
->classtype
= MCC
;
1098 else if (strcmp(s
,"mui")==0)
1099 cl
->classtype
= MUI
;
1100 else if (strcmp(s
,"mcp")==0)
1101 cl
->classtype
= MCP
;
1102 else if (strcmp(s
, "image")==0)
1103 cl
->classtype
= IMAGE
;
1104 else if (strcmp(s
, "gadget")==0)
1105 cl
->classtype
= GADGET
;
1106 else if (strcmp(s
, "datatype")==0)
1107 cl
->classtype
= DATATYPE
;
1108 else if (strcmp(s
, "usbclass")==0)
1109 cl
->classtype
= USBCLASS
;
1110 else if (strcmp(s
, "class")==0)
1111 cl
->classtype
= CLASS
;
1112 else if (strcmp(s
, "hidd")==0)
1113 cl
->classtype
= HIDD
;
1116 fprintf(stderr
, "Unknown type \"%s\" specified\n", s
);
1121 case 26: /* addromtag */
1122 cfg
->addromtag
= strdup(s
);
1125 case 27: /* oopbase_field */
1126 cfg
->oopbase_field
= strdup(s
);
1128 case 28: /* rellib */
1129 slist_append(&cfg
->rellibs
, s
);
1131 case 29: /* interfaceid */
1133 exitfileerror(20, "interfaceid only valid config option for an interface\n");
1134 in
->interfaceid
= strdup(s
);
1136 case 30: /* interfacename */
1138 exitfileerror(20, "interfacename only valid config option for an interface\n");
1139 in
->interfacename
= strdup(s
);
1141 case 31: /* methodstub */
1143 exitfileerror(20, "methodstub only valid config option for an interface\n");
1144 in
->methodstub
= strdup(s
);
1146 case 32: /* methodbase */
1148 exitfileerror(20, "methodbase only valid config option for an interface\n");
1149 in
->methodbase
= strdup(s
);
1151 case 33: /* attributebase */
1153 exitfileerror(20, "attributebase only valid config option for an interface\n");
1154 in
->attributebase
= strdup(s
);
1156 case 34: /* handler_func */
1157 if (cfg
->modtype
!= HANDLER
)
1158 exitfileerror(20, "handler specified when not a handler\n");
1159 cfg
->handlerfunc
= strdup(s
);
1161 case 35: /* includename */
1163 exitfileerror(20, "includename not valid config option"
1164 " when in a class section\n");
1165 cfg
->includename
= strdup(s
);
1169 else /* Line starts with ## */
1172 while (isspace(*s
)) s
++;
1173 if (strncmp(s
, "end", 3)!=0)
1174 exitfileerror(20, "\"##end config\" expected\n");
1178 exitfileerror(20, "\"##end config\" expected\n");
1180 while (isspace(*s
)) s
++;
1181 if (strncmp(s
, "config", 6)!=0)
1182 exitfileerror(20, "\"##end config\" expected\n");
1185 while (isspace(*s
)) s
++;
1187 exitfileerror(20, "\"##end config\" expected\n");
1193 /* When not in a class section fill in default values for fields in cfg */
1196 if (cfg
->basename
==NULL
)
1198 cfg
->basename
= strdup(cfg
->modulename
);
1199 *cfg
->basename
= toupper(*cfg
->basename
);
1201 if (cfg
->libbase
==NULL
)
1203 unsigned int len
= strlen(cfg
->basename
)+5;
1204 cfg
->libbase
= malloc(len
);
1205 snprintf(cfg
->libbase
, len
, "%sBase", cfg
->basename
);
1207 if (cfg
->libbasetype
== NULL
&& libbasetypeextern
!= NULL
)
1208 cfg
->libbasetype
= strdup(libbasetypeextern
);
1209 if (cfg
->sysbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1210 exitfileerror(20, "sysbase_field specified when no libbasetype is given\n");
1211 if (cfg
->seglist_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1212 exitfileerror(20, "seglist_field specified when no libbasetype is given\n");
1213 if (cfg
->oopbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1214 exitfileerror(20, "oopbase_field specified when no libbasetype is given\n");
1215 /* rootbase_field only allowed when duplicating base */
1216 if (cfg
->rootbase_field
!= NULL
&& !(cfg
->options
& OPTION_DUPBASE
))
1217 exitfileerror(20, "rootbasefield only valid for option peropenerbase or pertaskbase\n");
1219 /* Set default date to current date */
1220 if (cfg
->datestring
== NULL
)
1223 time_t now
= time(NULL
);
1224 struct tm
*ltime
= localtime(&now
);
1226 snprintf(tmpbuf
, sizeof(tmpbuf
), "%u.%u.%u",
1227 ltime
->tm_mday
, 1 + ltime
->tm_mon
, 1900 + ltime
->tm_year
);
1229 cfg
->datestring
= strdup(tmpbuf
);
1232 if (cfg
->copyright
== NULL
)
1233 cfg
->copyright
= "";
1235 if ( (cfg
->beginiofunc
!= NULL
&& cfg
->abortiofunc
== NULL
)
1236 || (cfg
->beginiofunc
== NULL
&& cfg
->abortiofunc
!= NULL
)
1238 exitfileerror(20, "please specify both beginio_func and abortio_func\n");
1240 if (libbasetypeextern
==NULL
)
1242 switch (cfg
->modtype
)
1245 cfg
->libbasetypeptrextern
= "struct Device *";
1249 cfg
->libbasetypeptrextern
= "APTR ";
1259 cfg
->libbasetypeptrextern
= "struct Library *";
1262 fprintf(stderr
, "Internal error: Unsupported modtype for libbasetypeptrextern\n");
1268 cfg
->libbasetypeptrextern
= malloc(strlen(libbasetypeextern
)+3);
1269 strcpy(cfg
->libbasetypeptrextern
, libbasetypeextern
);
1270 strcat(cfg
->libbasetypeptrextern
, " *");
1271 free(libbasetypeextern
);
1274 if (cfg
->includename
== NULL
)
1275 cfg
->includename
= cfg
->modulename
;
1276 cfg
->includenameupper
= strdup(cfg
->includename
);
1277 for (s
=cfg
->includenameupper
; *s
!='\0'; *s
= toupper(*s
), s
++)
1278 if (!isalnum(*s
)) *s
= '_';
1281 /* When class was given too fill in some defaults when not specified */
1284 if (cl
->classtype
== UNSPECIFIED
)
1285 cl
->classtype
= CLASS
;
1287 if (cl
->basename
== NULL
)
1290 cl
->basename
= cfg
->basename
;
1292 exitfileerror(20, "basename has to be specified in the config section inside of a class section\n");
1295 /* MUI classes are always private */
1296 if (cl
->classtype
== MUI
|| cl
->classtype
== MCC
|| cl
->classtype
== MCP
)
1297 cl
->options
|= COPTION_PRIVATE
;
1299 if (cl
->classid
== NULL
1300 && (cl
->classtype
!= MUI
&& cl
->classtype
!= MCC
&& cl
->classtype
!= MCP
)
1303 if (cl
->classtype
== HIDD
)
1305 cl
->options
&= !COPTION_PRIVATE
;
1307 else if (cl
->options
& COPTION_PRIVATE
)
1309 cl
->classid
= "NULL";
1315 if (cl
->classtype
== GADGET
|| cl
->classtype
== IMAGE
|| cl
->classtype
== CLASS
|| cl
->classtype
== USBCLASS
)
1317 sprintf(s
, "\"%sclass\"", inclass
? cl
->basename
: cfg
->modulename
);
1319 else if (cl
->classtype
== DATATYPE
)
1321 sprintf(s
, "\"%s.datatype\"", inclass
? cl
->basename
: cfg
->modulename
);
1323 cl
->classid
= strdup(s
);
1327 /* Only specify superclass or superclass_field */
1328 if (cl
->superclass
!= NULL
&& cl
->superclass_field
!= NULL
)
1329 exitfileerror(20, "Only specify one of superclass or superclass_field in config section\n");
1331 /* Give default value to superclass if it is not specified */
1332 if (cl
->superclass
== NULL
&& cl
->superclass
== NULL
)
1334 switch (cl
->classtype
)
1338 cl
->superclass
= "MUIC_Area";
1341 cl
->superclass
= "MUIC_Mccprefs";
1344 cl
->superclass
= "IMAGECLASS";
1347 cl
->superclass
= "GADGETCLASS";
1350 cl
->superclass
= "DATATYPESCLASS";
1353 cl
->superclass
= "ROOTCLASS";
1356 cl
->superclass
= "CLID_Root";
1359 exitfileerror(20, "Internal error: unhandled classtype in readsectionconfig\n");
1366 static void readsectioncdef(struct config
*cfg
)
1375 exitfileerror(20, "unexptected end of file in section cdef\n");
1377 if (strncmp(line
, "##", 2)!=0)
1379 slist_append(&cfg
->cdeflines
, line
);
1384 while (isspace(*s
)) s
++;
1385 if (strncmp(s
, "end", 3)!=0)
1386 exitfileerror(20, "\"##end cdef\" expected\n");
1389 while (isspace(*s
)) s
++;
1390 if (strncmp(s
, "cdef", 4)!=0)
1391 exitfileerror(20, "\"##end cdef\" expected\n");
1394 while (isspace(*s
)) s
++;
1396 exitfileerror(20, "unexpected character at position %d\n");
1404 static void readsectionstubprivate(struct config
*cfg
)
1413 exitfileerror(20, "unexptected end of file in section stubprivate\n");
1415 if (strncmp(line
, "##", 2)!=0)
1417 slist_append(&cfg
->stubprivatelines
, line
);
1422 while (isspace(*s
)) s
++;
1423 if (strncmp(s
, "end", 3)!=0)
1424 exitfileerror(20, "\"##end stubprivate\" expected\n");
1427 while (isspace(*s
)) s
++;
1428 if (strncmp(s
, "stubprivate", 11)!=0)
1429 exitfileerror(20, "\"##end stubprivate\" expected\n");
1432 while (isspace(*s
)) s
++;
1434 exitfileerror(20, "unexpected character at position %d\n");
1441 static void readsectioncdefprivate(struct config
*cfg
)
1450 exitfileerror(20, "unexptected end of file in section cdefprivate\n");
1452 if (strncmp(line
, "##", 2)!=0)
1454 slist_append(&cfg
->cdefprivatelines
, line
);
1459 while (isspace(*s
)) s
++;
1460 if (strncmp(s
, "end", 3)!=0)
1461 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1464 while (isspace(*s
)) s
++;
1465 if (strncmp(s
, "cdefprivate", 11)!=0)
1466 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1469 while (isspace(*s
)) s
++;
1471 exitfileerror(20, "unexpected character at position %d\n");
1478 static void readsectionstartup(struct config
*cfg
)
1487 exitfileerror(20, "unexptected end of file in section startup\n");
1489 if (strncmp(line
, "##", 2)!=0)
1491 slist_append(&cfg
->startuplines
, line
);
1496 while (isspace(*s
)) s
++;
1497 if (strncmp(s
, "end", 3)!=0)
1498 exitfileerror(20, "\"##end startup\" expected\n");
1501 while (isspace(*s
)) s
++;
1502 if (strncmp(s
, "startup", 7)!=0)
1503 exitfileerror(20, "\"##end startup\" expected\n");
1506 while (isspace(*s
)) s
++;
1508 exitfileerror(20, "unexpected character at position %d\n");
1515 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
, enum libcall def_libcall
)
1518 char *line
, *s
, *s2
;
1519 unsigned int lvo
= firstlvo
;
1520 int minversion
= -1;
1526 exitfileerror(20, "unexpected EOF in functionlist section\n");
1527 if (strlen(line
)==0)
1529 if (*funclistptr
!= NULL
)
1530 funclistptr
= &((*funclistptr
)->next
);
1533 else if (isspace(*line
))
1536 while (isspace(*s
)) s
++;
1539 if (*funclistptr
!= NULL
)
1540 funclistptr
= &((*funclistptr
)->next
);
1544 exitfileerror(20, "no space allowed before functionname\n");
1546 else if (strncmp(line
, "##", 2)==0)
1549 while (isspace(*s
)) s
++;
1550 if (strncmp(s
, "end", 3)!=0)
1551 exitfileerror(20, "\"##end %s\" expected\n", type
);
1554 while (isspace(*s
)) s
++;
1555 if (strncmp(s
, type
, strlen(type
))!=0)
1556 exitfileerror(20, "\"##end %s\" expected\n", type
);
1559 while (isspace(*s
)) s
++;
1561 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1565 else if (*line
=='.')
1568 if (strncmp(s
, "skip", 4)==0)
1574 exitfileerror(20, "syntax is '.skip n'\n");
1576 n
=strtol(s
, &s2
, 10);
1578 exitfileerror(20, "positive number expected\n");
1580 while (isspace(*s2
)) s2
++;
1581 if ((*s2
!= '\0') && (*s2
!= '#'))
1582 exitfileerror(20, "syntax is '.skip n'\n");
1583 if (*funclistptr
!= NULL
)
1584 funclistptr
= &((*funclistptr
)->next
);
1587 else if (strncmp(s
, "alias", 5)==0)
1592 exitfileerror(20, "syntax is '.alias name'\n");
1594 while (isspace(*s
)) s
++;
1595 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1596 exitfileerror(20, "syntax is '.alias name'\n");
1600 while (isalnum(*s
) || *s
== '_') s
++;
1607 } while (isspace(*s
));
1611 exitfileerror(20, "syntax is '.alias name'\n");
1613 if (*funclistptr
== NULL
)
1614 exitfileerror(20, ".alias has to come after a function declaration\n");
1616 slist_append(&(*funclistptr
)->aliases
, s2
);
1618 else if (strncmp(s
, "function", 8) == 0)
1623 exitfileerror(20, "Syntax error\n");
1625 while (isspace(*s
)) s
++;
1626 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1627 exitfileerror(20, "syntax is '.function name'\n");
1631 while (isalnum(*s
) || *s
== '_') s
++;
1638 } while (isspace(*s
));
1642 exitfileerror(20, "syntax is '.function name'\n");
1644 if (*funclistptr
== NULL
)
1645 exitfileerror(20, ".function has to come after a function declaration\n");
1647 funcsetinternalname(*funclistptr
, s2
);
1649 else if (strncmp(s
, "cfunction", 9)==0)
1651 if (*funclistptr
== NULL
)
1652 exitfileerror(20, ".cfunction has to come after a function declaration\n");
1654 (*funclistptr
)->libcall
= REGISTER
;
1656 else if (strncmp(s
, "private", 7)==0)
1658 if (*funclistptr
== NULL
)
1659 exitfileerror(20, ".private has to come after a function declaration\n");
1661 (*funclistptr
)->priv
= 1;
1663 else if (strncmp(s
, "novararg", 8)==0)
1665 if (*funclistptr
== NULL
)
1666 exitfileerror(20, ".novararg has to come after a function declaration\n");
1668 (*funclistptr
)->novararg
= 1;
1670 else if (strncmp(s
, "version", 7) == 0)
1672 /* Mark version number for the following
1673 * functions, so that the automatic OpenLibrary()
1674 * will know what version to use.
1681 while (isspace(*s
)) s
++;
1682 ver
= (int)strtol(s
, &tmp
, 0);
1685 exitfileerror(20, ".version expects an integer\n");
1688 while (isspace(*s
)) s
++;
1690 if (*s
&& *s
!= '#')
1691 exitfileerror(20, ".version has junk after the version number\n");
1695 else if (strncmp(s
, "unusedlibbase", 13) == 0)
1697 if (*funclistptr
== NULL
)
1698 exitfileerror(20, ".unusedlibbase has to come after a function declaration\n");
1699 (*funclistptr
)->unusedlibbase
= 1;
1702 exitfileerror(20, "Syntax error");
1704 else if (*line
!='#') /* Ignore line that is a comment, e.g. that starts with a # */
1706 /* The line is a function or attribute prototype.
1707 * A function can have one of two syntaxes:
1708 * type funcname(argproto1, argproto2, ...)
1709 * type funcname(argproto1, argproto2, ...) (reg1, reg2, ...)
1710 * The former is for C type function argument passing, the latter for
1711 * register argument passing.
1712 * An attribute has the following syntax:
1715 char c
, *args
[64], *regs
[64], *funcname
, *cp
;
1716 int len
, argcount
= 0, regcount
= 0, brcount
= 0;
1718 cp
= strchr(line
,'#');
1722 /* Parse 'type functionname' at the beginning of the line */
1724 s
= line
+ strlen(line
);
1726 s
= strchr(line
, '(');
1728 exitfileerror(20, "( expected at position %d\n", strlen(line
) + 1);
1732 while (isspace(*(s2
-1)))
1736 while (s2
> line
&& !isspace(*(s2
-1)) && !(*(s2
-1) == '*'))
1740 exitfileerror(20, "No type specifier before %s name\n", isattribute
? "attribute" : "function");
1742 if (*funclistptr
!= NULL
)
1743 funclistptr
= &((*funclistptr
)->next
);
1744 *funclistptr
= newfunctionhead(s2
, STACK
);
1747 (*funclistptr
)->comment
= strdup(cp
);
1749 (*funclistptr
)->comment
= NULL
;
1751 while (isspace(*(s2
-1)))
1754 (*funclistptr
)->type
= strdup(line
);
1755 (*funclistptr
)->lvo
= lvo
;
1756 (*funclistptr
)->version
= minversion
;
1762 /* Parse function prototype */
1779 && !(brcount
== 0 && (*s
== ',' || *s
== ')'))
1789 exitfileerror(20, "Unexected ')' at position %d\n", s
-line
+1);
1796 exitfileerror(20, "'(' without ')'");
1799 while (isspace(*(s2
-1)))
1803 if (!(s2
> args
[argcount
- 1]))
1804 exitfileerror(20, "Syntax error in function prototype\n");
1810 while (*s
!= '\0' && isspace(*s
))
1815 /* Parse registers specifications if available otherwise this prototype for C type argument passing */
1817 /* There may be no register specified with () so be sure then c is == ')' */
1832 if (memchr("AD",s
[0],2)!=NULL
&& memchr("01234567",s
[1],8)!=NULL
)
1839 if (s
[0] == s
[-3] && s
[1] == s
[-2] + 1)
1846 "wrong register specification \"%s\" for argument %u\n",
1847 regs
[regcount
-1], regcount
1851 exitfileerror(20, "maximum four arguments passed in two registers allowed (%d, %s) \n", regcount
, regs
[regcount
-1]);
1857 "wrong register \"%s\" for argument %u\n",
1858 regs
[regcount
-1], regcount
1867 exitfileerror(20, "'(' without ')'\n");
1868 if (c
!= ',' && c
!= ')')
1869 exitfileerror(20, "',' or ')' expected at position %d\n", s
-line
+1);
1875 while (isspace(*s
)) s
++;
1877 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1879 if (argcount
!= regcount
)
1880 exitfileerror(20, "Number of arguments (%d) and registers (%d) mismatch\n",
1884 (*funclistptr
)->libcall
= def_libcall
;
1885 for (i
= 0; i
< argcount
; i
++)
1886 funcaddarg(*funclistptr
, args
[i
], regs
[i
]);
1888 else if (*s
== '\0')
1889 { /* No registers specified */
1890 for (i
= 0; i
< argcount
; i
++)
1891 funcaddarg(*funclistptr
, args
[i
], NULL
);
1894 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1899 static void readsectionclass_methodlist(struct classinfo
*cl
)
1902 char *line
, *s
, *s2
;
1903 struct functionhead
**methlistptr
= &cl
->methlist
;
1904 struct stringlist
*interface
= NULL
;
1906 if (cl
->basename
==NULL
)
1907 exitfileerror(20, "section methodlist has to come after section config\n");
1913 exitfileerror(20, "unexptected EOF in methodlist section\n");
1915 /* Ignore empty lines or lines that qre a comment, e.g. that starts with a # */
1916 if (strlen(line
)==0 || (line
[0] == '#' && line
[1] != '#'))
1920 exitfileerror(20, "No space allowed at start of the line\n");
1922 if (strncmp(line
, "##", 2)==0) /* Is this the end ? */
1925 while (isspace(*s
)) s
++;
1926 if (strncmp(s
, "end", 3)!=0)
1927 exitfileerror(20, "\"##end methodlist\" expected\n");
1930 while (isspace(*s
)) s
++;
1931 if (strncmp(s
, "methodlist", 10)!=0)
1932 exitfileerror(20, "\"##end methodlist\" expected\n");
1935 while (isspace(*s
)) s
++;
1937 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1947 if (strncmp(s
, "alias", 5)==0)
1952 exitfileerror(20, "syntax is '.alias name'\n");
1954 while (isspace(*s
)) s
++;
1955 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1956 exitfileerror(20, "syntax is '.alias name'\n");
1960 while (isalnum(*s
) || *s
== '_') s
++;
1967 } while (isspace(*s
));
1971 exitfileerror(20, "syntax is '.alias name'\n");
1973 if (*methlistptr
== NULL
)
1974 exitfileerror(20, ".alias has to come after a function declaration\n");
1976 slist_append(&(*methlistptr
)->aliases
, s2
);
1978 else if (strncmp(s
, "function", 8) == 0)
1983 exitfileerror(20, "Syntax error\n");
1985 while (isspace(*s
)) s
++;
1986 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1987 exitfileerror(20, "syntax is '.function name'\n");
1991 while (isalnum(*s
) || *s
== '_') s
++;
1998 } while (isspace(*s
));
2002 exitfileerror(20, "syntax is '.function name'\n");
2004 if (*methlistptr
== NULL
)
2005 exitfileerror(20, ".function has to come after a function declaration\n");
2007 funcsetinternalname(*methlistptr
, s2
);
2009 else if (strncmp(s
, "interface", 9) == 0)
2011 if (cl
->classtype
!= HIDD
)
2012 exitfileerror(20, "interface only valid for a HIDD\n");
2017 exitfileerror(20, "Syntax error\n");
2019 while (isspace(*s
)) s
++;
2020 if (*s
== '\0' || !isalpha(*s
))
2021 exitfileerror(20, "syntax is '.interface name'\n");
2025 while (isalnum(*s
) || *s
== '_') s
++;
2032 } while (isspace(*s
));
2036 exitfileerror(20, "syntax is '.interface name'\n");
2038 interface
= slist_append(&cl
->interfaces
, s2
);
2041 exitfileerror(20, "Syntax error");
2043 else if (isalpha(*line
))
2047 for (s
= line
+ 1; isalnum(*s
) || *s
== '_'; s
++)
2050 if (cl
->classtype
== HIDD
&& interface
== NULL
)
2051 exitfileerror(20, "For a HIDD the first method has to come after an .interface line\n");
2054 exitfileerror(20, "Only letters, digits and an underscore allowed in a methodname\n");
2056 if (*methlistptr
!= NULL
)
2057 methlistptr
= &((*methlistptr
)->next
);
2058 if (cl
->classtype
!= HIDD
)
2060 if (snprintf(stmp
, 256, "%s__%s", cl
->basename
, line
) >= 256)
2061 exitfileerror(20, "Method name too large\n");
2063 *methlistptr
= newfunctionhead(stmp
, STACK
);
2064 (*methlistptr
)->type
= "IPTR";
2065 funcaddarg(*methlistptr
, "Class *cl", NULL
);
2066 funcaddarg(*methlistptr
, "Object *o", NULL
);
2067 funcaddarg(*methlistptr
, "Msg msg", NULL
);
2071 if (snprintf(stmp
, 256, "%s__%s__%s", cl
->basename
, interface
->s
, line
) >= 256)
2072 exitfileerror(20, "Method name too large\n");
2074 *methlistptr
= newfunctionhead(stmp
, STACK
);
2075 (*methlistptr
)->type
= "IPTR";
2076 funcaddarg(*methlistptr
, "OOP_Class *cl", NULL
);
2077 funcaddarg(*methlistptr
, "OOP_Object *o", NULL
);
2078 funcaddarg(*methlistptr
, "OOP_Msg msg", NULL
);
2079 (*methlistptr
)->interface
= interface
;
2080 if (snprintf(stmp
, 256, "mo%s_%s", interface
->s
, line
) >= 256)
2081 exitfileerror(20, "Method name too large\n");
2082 (*methlistptr
)->method
= strdup(stmp
);
2084 slist_append(&(*methlistptr
)->aliases
, line
);
2087 exitfileerror(20, "Methodname has to begin with a letter\n");
2092 readsectioninterface(struct config
*cfg
)
2095 struct interfaceinfo
*in
;
2097 in
= newinterface(cfg
);
2098 s
= readsections(cfg
, NULL
, in
, 1);
2100 exitfileerror(20, "Unexpected end of file\n");
2102 if (strncmp(s
, "##", 2) != 0)
2103 exitfileerror(20, "'##end interface' expected\n");
2106 while (isspace(*s
)) s
++;
2108 if (strncmp(s
, "end", 3) != 0)
2109 exitfileerror(20, "'##end interface' expected\n");
2113 exitfileerror(20, "'##end interface' expected\n");
2114 while (isspace(*s
)) s
++;
2116 if (strncmp(s
, "interface", 9) != 0)
2117 exitfileerror(20, "'##end interface' expected\n");
2120 while (isspace(*s
)) s
++;
2122 exitfileerror(20, "'##end interface' expected\n");
2124 if (!in
->interfaceid
)
2125 exitfileerror(20, "interface has no 'interfaceid' defined!\n");
2127 if (!in
->interfacename
)
2128 exitfileerror(20, "interface has no 'interfacename' defined!\n");
2130 if (!in
->methodstub
)
2131 in
->methodstub
= strdup(in
->interfacename
);
2133 if (!in
->methodbase
) {
2134 int len
= strlen(in
->interfacename
);
2135 in
->methodbase
= malloc(len
+ 4 + 1);
2136 strcpy(in
->methodbase
, in
->interfacename
);
2137 strcat(in
->methodbase
, "Base");
2140 if (!in
->attributebase
) {
2141 int len
= strlen(in
->interfacename
);
2142 in
->attributebase
= malloc(len
+ 4 + 4 + 1);
2143 strcpy(in
->attributebase
, in
->interfacename
);
2144 strcat(in
->attributebase
, "AttrBase");
2149 readsectionclass(struct config
*cfg
)
2152 struct classinfo
*cl
;
2155 s
= readsections(cfg
, cl
, NULL
, 1);
2157 exitfileerror(20, "Unexpected end of file\n");
2159 if (strncmp(s
, "##", 2) != 0)
2160 exitfileerror(20, "'##end class' expected\n");
2163 while (isspace(*s
)) s
++;
2165 if (strncmp(s
, "end", 3) != 0)
2166 exitfileerror(20, "'##end class' expected\n");
2170 exitfileerror(20, "'##end class' expected\n");
2171 while (isspace(*s
)) s
++;
2173 if (strncmp(s
, "class", 5) != 0)
2174 exitfileerror(20, "'##end class' expected\n");
2177 while (isspace(*s
)) s
++;
2179 exitfileerror(20, "'##end class' expected\n");
2182 static struct classinfo
*newclass(struct config
*cfg
)
2184 struct classinfo
*cl
, *classlistit
;
2186 cl
= malloc(sizeof(struct classinfo
));
2189 fprintf(stderr
, "Out of memory\n");
2192 memset(cl
, 0, sizeof(struct classinfo
));
2194 /* By default the classes are initialized with a priority of 1 so they
2195 * are initialized before any user added initialization with priority 1
2199 if (cfg
->classlist
== NULL
)
2200 cfg
->classlist
= cl
;
2205 classlistit
= cfg
->classlist
;
2206 classlistit
->next
!= NULL
;
2207 classlistit
= classlistit
->next
2210 classlistit
->next
= cl
;
2216 static struct handlerinfo
*newhandler(struct config
*cfg
)
2218 struct handlerinfo
*hl
;
2220 hl
= calloc(1,sizeof(*hl
));
2221 hl
->next
= cfg
->handlerlist
;
2222 cfg
->handlerlist
= hl
;
2226 static struct interfaceinfo
*newinterface(struct config
*cfg
)
2228 struct interfaceinfo
*in
, *interfacelistit
;
2230 in
= malloc(sizeof(struct interfaceinfo
));
2233 fprintf(stderr
, "Out of memory\n");
2236 memset(in
, 0, sizeof(struct interfaceinfo
));
2238 if (cfg
->interfacelist
== NULL
)
2239 cfg
->interfacelist
= in
;
2244 interfacelistit
= cfg
->interfacelist
;
2245 interfacelistit
->next
!= NULL
;
2246 interfacelistit
= interfacelistit
->next
2249 interfacelistit
->next
= in
;
2256 static int getdirective(char *s
, const char *directive
, int range_min
, int range_max
, int *val
)
2261 if (strncmp(s
, directive
, strlen(directive
)) != 0)
2264 s
+= strlen(directive
);
2265 if (*s
&& !isspace(*s
))
2266 exitfileerror(20, "Unrecognized directive \".%s\"\n", directive
);
2268 while (isspace(*s
)) s
++;
2270 exitfileerror(20, "No .%s value specified\n", directive
);
2272 newval
= strtol(s
, &tmp
, 0);
2273 if (s
== tmp
|| !(newval
>= range_min
&& newval
<= range_max
)) {
2275 while (*tmp
&& !isspace(*tmp
)) tmp
++;
2276 exitfileerror(20, "Invalid .%s value of %.*s\n", directive
, tmp
- s
, s
);
2284 readsectionhandler(struct config
*cfg
)
2286 char *line
= NULL
, *s
;
2287 struct handlerinfo
*hl
;
2288 unsigned char autolevel
= 0;
2289 unsigned int stacksize
= 0;
2293 int has_filesystem
= 0;
2301 s
= line
= readline();
2304 exitfileerror(20, "unexpected end of file in section hanlder\n");
2306 if (strncmp(s
, "##", 2)==0)
2309 /* Ignore comments */
2310 if (strncmp(s
, "#", 1)==0)
2313 /* Skip ahead to function name */
2314 while (*s
&& isspace(*s
)) s
++;
2316 /* Permit blank lines */
2324 if (getdirective(s
, "autodetect", 0, 127, &val
)) {
2326 } else if (getdirective(s
, "stacksize", 0, INT_MAX
, &val
)) {
2328 } else if (getdirective(s
, "priority", -128, 127, &val
)) {
2330 } else if (getdirective(s
, "bootpri", -128, 127, &val
)) {
2332 } else if (getdirective(s
, "startup", INT_MIN
, INT_MAX
, &val
)) {
2335 exitfileerror(20, "Unrecognized directive \"%s\"\n", line
);
2341 unsigned int id
= 0;
2343 if (strncasecmp(s
,"resident=",9)==0) {
2346 s
= strchr(s
, '=') + 1;
2348 while (*s
&& !isspace(*s
)) s
++;
2350 exitfileerror(20, "Empty resident= is not permitted\n");
2355 hl
= newhandler(cfg
);
2356 hl
->type
= HANDLER_RESIDENT
;
2358 hl
->name
= strdup(res
);
2359 hl
->autodetect
= autolevel
--;
2360 hl
->stacksize
= stacksize
;
2361 hl
->priority
= priority
;
2362 hl
->startup
= startup
;
2363 } else if (strncasecmp(s
,"dosnode=",8)==0) {
2366 s
= strchr(s
, '=') + 1;
2368 while (*s
&& !isspace(*s
)) s
++;
2370 exitfileerror(20, "Empty dosnode= is not permitted\n");
2375 hl
= newhandler(cfg
);
2376 hl
->type
= HANDLER_DOSNODE
;
2378 hl
->name
= strdup(dev
);
2379 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2380 hl
->stacksize
= stacksize
;
2381 hl
->priority
= priority
;
2382 hl
->startup
= startup
;
2383 hl
->bootpri
= bootpri
;
2384 } else if (strncasecmp(s
,"dostype=",8) == 0) {
2385 s
= strchr(s
, '=') + 1;
2387 id
= (unsigned int)strtoul(s
, &tmp
, 0);
2390 while (*tmp
&& !isspace(*tmp
))
2392 exitfileerror(20, "\"%.*s\" is not a numerical DOS ID\n", (tmp
-s
), s
);
2396 if (id
== 0 || id
== ~0) {
2397 exitfileerror(20, "DOS ID 0x%08x is not permitted\n", id
);
2400 hl
= newhandler(cfg
);
2401 hl
->type
= HANDLER_DOSTYPE
;
2404 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2405 hl
->stacksize
= stacksize
;
2406 hl
->priority
= priority
;
2407 hl
->startup
= startup
;
2409 for (tmp
= s
; !isspace(*tmp
); tmp
++);
2410 exitfileerror(20, "Unknown option \"%.*s\"\n", tmp
- s
, s
);
2413 /* Advance to next ID */
2414 while (*s
&& isspace(*s
)) s
++;
2420 exitfileerror(20, "Unexpected end of file\n");
2422 if (strncmp(s
, "##", 2) != 0)
2423 exitfileerror(20, "'##end handler' expected\n");
2426 while (isspace(*s
)) s
++;
2428 if (strncmp(s
, "end", 3) != 0)
2429 exitfileerror(20, "'##end handler' expected\n");
2432 while (isspace(*s
)) s
++;
2434 if (strncmp(s
, "handler", 7) != 0)
2435 exitfileerror(20, "'##end handler' expected\n");
2438 while (isspace(*s
)) s
++;
2440 exitfileerror(20, "'##end handler' expected\n");