2 Copyright © 1995-2013, 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} 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
;
179 fprintf(stderr
, "Unrecognized argument \"%s\"\n%s", argv
[optind
], usage
);
183 cfg
->modulename
= argv
[optind
+1];
184 cfg
->modulenameupper
= strdup(cfg
->modulename
);
185 for (s
=cfg
->modulenameupper
; *s
!='\0'; *s
= toupper(*s
), s
++) {
186 if (!isalnum(*s
)) *s
= '_';
189 if (strcmp(argv
[optind
+2],"library")==0)
191 cfg
->modtype
= LIBRARY
;
192 cfg
->moddir
= "Libs";
194 else if (strcmp(argv
[optind
+2],"mcc")==0)
197 cfg
->moddir
= "Classes/Zune";
199 else if (strcmp(argv
[optind
+2],"mui")==0)
202 cfg
->moddir
= "Classes/Zune";
204 else if (strcmp(argv
[optind
+2],"mcp")==0)
207 cfg
->moddir
= "Classes/Zune";
209 else if (strcmp(argv
[optind
+2], "device")==0)
211 cfg
->modtype
= DEVICE
;
212 cfg
->moddir
= "Devs";
214 else if (strcmp(argv
[optind
+2], "resource")==0)
216 cfg
->modtype
= RESOURCE
;
217 cfg
->moddir
= "Devs";
219 else if (strcmp(argv
[optind
+2], "gadget")==0)
221 cfg
->modtype
= GADGET
;
222 cfg
->moddir
= "Classes/Gadgets";
224 else if (strcmp(argv
[optind
+2], "datatype")==0)
226 cfg
->modtype
= DATATYPE
;
227 cfg
->moddir
= "Classes/DataTypes";
229 else if (strcmp(argv
[optind
+2], "usbclass")==0)
231 cfg
->modtype
= USBCLASS
;
232 cfg
->moddir
= "Classes/USB";
235 cfg
->suffix
= "class";
239 else if (strcmp(argv
[optind
+2], "hidd")==0)
242 cfg
->moddir
= "Devs/Drivers";
244 else if (strcmp(argv
[optind
+2], "handler")==0)
246 cfg
->modtype
= HANDLER
;
247 cfg
->moddir
= "$(AROS_DIR_FS)";
249 else if (strcmp(argv
[optind
+2], "hook")==0)
251 cfg
->modtype
= HANDLER
;
252 cfg
->moddir
= "Devs";
256 fprintf(stderr
, "Unknown modtype \"%s\" specified for second argument\n", argv
[optind
+2]);
259 cfg
->modtypestr
= argv
[optind
+2];
262 cfg
->suffix
= argv
[optind
+2];
264 /* Fill fields with default value if not specified on the command line */
268 if (cfg
->conffile
== NULL
)
270 snprintf(tmpbuf
, sizeof(tmpbuf
), "%s.conf", cfg
->modulename
);
271 cfg
->conffile
= strdup(tmpbuf
);
274 if (cfg
->gendir
== NULL
)
280 /* For a device add the functions given in beginiofunc and abortiofunc to the functionlist
281 * if they are provided
283 if (cfg
->beginiofunc
!= NULL
)
285 struct functionhead
*funchead
;
287 cfg
->intcfg
|= CFG_NOREADFUNCS
;
289 /* Add beginio_func to the list of functions */
290 funchead
= newfunctionhead(cfg
->beginiofunc
, REGISTERMACRO
);
291 funchead
->type
= strdup("void");
293 funcaddarg(funchead
, "struct IORequest *ioreq", "A1");
295 funchead
->next
= cfg
->funclist
;
296 cfg
->funclist
= funchead
;
298 /* Add abortio_func to the list of functions */
299 funchead
= newfunctionhead(cfg
->abortiofunc
, REGISTERMACRO
);
300 funchead
->type
= strdup("LONG");
302 funcaddarg(funchead
, "struct IORequest *ioreq", "A1");
304 funchead
->next
= cfg
->funclist
->next
;
305 cfg
->funclist
->next
= funchead
;
307 else if (cfg
->modtype
== DEVICE
&& cfg
->intcfg
& CFG_NOREADFUNCS
)
312 "beginio_func and abortio_func missing for a device with a non empty function list\n"
317 /* See if we have any stackcall options */
319 struct functionhead
*funchead
;
321 for (funchead
= cfg
->funclist
; funchead
; funchead
= funchead
->next
) {
322 if (funchead
->libcall
== STACK
) {
323 cfg
->options
|= OPTION_STACKCALL
;
329 /* Provide default version for functions that didnt have it */
331 struct functionhead
*funchead
;
332 int defversion
= cfg
->majorversion
; /* Assume library version is default */
334 for (funchead
= cfg
->funclist
; funchead
; funchead
= funchead
->next
) {
335 if (funchead
->version
> -1) {
336 /* There was at least one .version tag. Assume 0 is default */
342 for (funchead
= cfg
->funclist
; funchead
; funchead
= funchead
->next
) {
343 if (funchead
->version
== -1) {
344 funchead
->version
= defversion
;
349 /* Verify that a handler has a handler */
350 if (cfg
->modtype
== HANDLER
) {
351 if (cfg
->handlerfunc
== NULL
) {
352 fprintf(stderr
, "handler modules require a 'handler_func' ##config option\n");
355 cfg
->options
|= OPTION_NOAUTOLIB
| OPTION_NOEXPUNGE
| OPTION_NOOPENCLOSE
;
361 /* Functions to read configuration from the configuration file */
363 #include "fileread.h"
365 static char *readsections(struct config
*, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
);
366 static void readsectionconfig(struct config
*, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
);
367 static void readsectioncdef(struct config
*);
368 static void readsectioncdefprivate(struct config
*);
369 static void readsectionstartup(struct config
*);
370 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
, enum libcall def_libcall
);
371 static void readsectionclass_methodlist(struct classinfo
*);
372 static void readsectionclass(struct config
*);
373 static void readsectionhandler(struct config
*);
374 static void readsectioninterface(struct config
*);
376 static void readconfig(struct config
*cfg
)
378 struct classinfo
*mainclass
= NULL
;
380 /* Create a classinfo structure if this module is a class */
381 switch (cfg
->modtype
)
396 mainclass
= newclass(cfg
);
397 mainclass
->classtype
= cfg
->modtype
;
401 fprintf(stderr
, "Internal error: unsupported modtype for classinfo creation\n");
405 switch (cfg
->modtype
)
418 mainclass
->boopsimprefix
= muimprefix
;
426 mainclass
->boopsimprefix
= gadgetmprefix
;
430 mainclass
->boopsimprefix
= dtmprefix
;
434 /* FIXME: need boopsimprefix ? */
437 fprintf(stderr
, "Internal error: unsupported modtype for firstlvo\n");
441 if (!fileopen(cfg
->conffile
))
443 fprintf(stderr
, "In readconfig: Could not open %s\n", cfg
->conffile
);
447 /* Read all sections and see that we are at the end of the file */
448 if (readsections(cfg
, mainclass
, NULL
, 0) != NULL
)
449 exitfileerror(20, "Syntax error");
454 /* readsections will scan through all the sections in the config file.
456 * struct config *cfg: The module config data which may be updated by
457 * the information in the sections
458 * struct classinfo *cl: The classdata to be filled with data from the sections.
459 * This may be NULL if this is the main part of the configuration file and the
460 * type of the module is not a class
461 * int inclass: Boolean to indicate if we are in a class part. If not we are in the main
462 * part of the config file.
464 static char *readsections(struct config
*cfg
, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
)
469 while ((line
=readline())!=NULL
)
471 if (strncmp(line
, "##", 2)==0)
473 static char *parts
[] =
475 "config", "cdefprivate", "cdef", "startup", "functionlist", "methodlist", "class", "handler", "interface", "attributelist", "cfunctionlist"
477 const unsigned int nums
= sizeof(parts
)/sizeof(char *);
478 unsigned int partnum
;
482 while (isspace(*s
)) s
++;
484 if (strncmp(s
, "begin", 5)!=0)
489 exitfileerror(20, "space after begin expected\n");
490 while (isspace(*s
)) s
++;
492 for (i
= 0, partnum
= 0; partnum
==0 && i
<nums
; i
++)
494 if (strncmp(s
, parts
[i
], strlen(parts
[i
]))==0)
497 s
+= strlen(parts
[i
]);
498 while (isspace(*s
)) s
++;
500 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
504 exitfileerror(20, "unknown start of section\n");
508 readsectionconfig(cfg
, cl
, in
, inclass
);
512 case 2: /* cdefprivate */
514 exitfileerror(20, "cdefprivate section not allowed in class section\n");
515 readsectioncdefprivate(cfg
);
520 exitfileerror(20, "cdef section not allowed in class section\n");
521 readsectioncdef(cfg
);
524 case 4: /* startup */
526 exitfileerror(20, "startup section not allowed in class section\n");
527 readsectionstartup(cfg
);
530 case 5: /* functionlist */
532 exitfileerror(20, "functionlist section not allow in class section\n");
533 if (cfg
->basename
==NULL
)
534 exitfileerror(20, "section functionlist has to come after section config\n");
536 readsectionfunctionlist("functionlist", &cfg
->funclist
, cfg
->firstlvo
, 0, REGISTERMACRO
);
537 cfg
->intcfg
|= CFG_NOREADFUNCS
;
540 case 6: /* methodlist */
541 if (cl
== NULL
&& in
== NULL
)
542 exitfileerror(20, "methodlist section when not in a class or interface\n");
544 readsectionclass_methodlist(cl
);
546 readsectionfunctionlist("methodlist", &in
->methodlist
, 0, 0, REGISTERMACRO
);
547 cfg
->intcfg
|= CFG_NOREADFUNCS
;
552 exitfileerror(20, "class section may not be in nested\n");
553 readsectionclass(cfg
);
555 case 8: /* handler */
556 readsectionhandler(cfg
);
558 case 9: /* interface */
560 exitfileerror(20, "interface section may not be nested\n");
561 readsectioninterface(cfg
);
563 case 10: /* attributelist */
565 exitfileerror(20, "attributelist only valid in interface sections\n");
566 readsectionfunctionlist("attributelist", &in
->attributelist
, 0, 1, INVALID
);
568 case 11: /* cfunctionlist */
570 exitfileerror(20, "cfunctionlist section not allow in class section\n");
571 if (cfg
->basename
==NULL
)
572 exitfileerror(20, "section cfunctionlist has to come after section config\n");
574 readsectionfunctionlist("cfunctionlist", &cfg
->funclist
, cfg
->firstlvo
, 0, REGISTER
);
575 cfg
->intcfg
|= CFG_NOREADFUNCS
;
579 else if (strlen(line
)!=0)
580 filewarning("warning line outside section ignored\n");
586 exitfileerror(20, "No config section in conffile\n");
588 /* If no indication was given for generating includes or not
589 decide on module type and if there are functions
591 if(!((cfg
->options
& OPTION_INCLUDES
) || (cfg
->options
& OPTION_NOINCLUDES
)))
593 switch (cfg
->modtype
)
597 cfg
->options
|= OPTION_INCLUDES
;
605 cfg
->options
|= OPTION_NOINCLUDES
;
610 (cfg
->funclist
!= NULL
)
611 || (cfg
->cdeflines
!= NULL
)
612 || strcmp(cfg
->libbasetypeptrextern
, "struct Device *") != 0
613 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
620 (cfg
->funclist
!= NULL
)
621 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
625 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for includes\n");
631 /* If no indication was given for not generating stubs only generate them if
632 * the module has functions
634 if(!((cfg
->options
& OPTION_STUBS
) || (cfg
->options
& OPTION_NOSTUBS
)))
636 switch (cfg
->modtype
)
639 cfg
->options
|= (cfg
->funclist
!= NULL
) ? OPTION_STUBS
: OPTION_NOSTUBS
;
652 cfg
->options
|= OPTION_NOSTUBS
;
656 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for stubs\n");
662 /* If no indication was given for generating autoinit code or not
663 decide on module type
665 if(!((cfg
->options
& OPTION_AUTOINIT
) || (cfg
->options
& OPTION_NOAUTOINIT
)))
667 switch (cfg
->modtype
)
670 cfg
->options
|= OPTION_AUTOINIT
;
683 cfg
->options
|= OPTION_NOAUTOINIT
;
687 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for autoinit\n");
693 if ((cfg
->modtype
== RESOURCE
) || (cfg
->modtype
== HANDLER
))
694 /* Enforce noopenclose for resources and handlers */
695 cfg
->options
|= OPTION_NOOPENCLOSE
;
696 else if (!(cfg
->options
& OPTION_SELFINIT
))
697 /* Enforce using RTF_AUTOINIT for everything except resources */
698 cfg
->options
|= OPTION_RESAUTOINIT
;
704 static void readsectionconfig(struct config
*cfg
, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
)
707 char *line
, *s
, *s2
, *libbasetypeextern
= NULL
;
714 exitfileerror(20, "unexpected end of file in section config\n");
716 if (strncmp(line
, "##", 2)!=0)
718 const char *names
[] =
720 "basename", "libbase", "libbasetype", "libbasetypeextern",
721 "version", "date", "copyright", "libcall", "forcebase", "superclass",
722 "superclass_field", "residentpri", "options", "sysbase_field",
723 "seglist_field", "rootbase_field", "classptr_field", "classptr_var",
724 "classid", "classdatatype", "beginio_func", "abortio_func", "dispatcher",
725 "initpri", "type", "addromtag", "oopbase_field",
726 "rellib", "interfaceid", "interfacename",
727 "methodstub", "methodbase", "attributebase", "handler_func"
729 const unsigned int namenums
= sizeof(names
)/sizeof(char *);
730 unsigned int namenum
;
732 for (i
= 0, namenum
= 0; namenum
==0 && i
<namenums
; i
++)
736 strncmp(line
, names
[i
], strlen(names
[i
]))==0
737 && isspace(*(line
+strlen(names
[i
])))
742 exitfileerror(20, "unrecognized configuration option\n");
744 s
= line
+ strlen(names
[namenum
-1]);
746 exitfileerror(20, "space character expected after \"%s\"\n", names
[namenum
-1]);
748 while (isspace(*s
)) s
++;
750 exitfileerror(20, "unexpected end of line\n");
753 while (isspace(*(s2
-1))) s2
--;
758 case 1: /* basename */
760 cfg
->basename
= strdup(s
);
762 cl
->basename
= strdup(s
);
764 exitfileerror(20, "basename not valid config option when in a interface section\n");
767 case 2: /* libbase */
769 exitfileerror(20, "libbase not valid config option when in a class section\n");
770 cfg
->libbase
= strdup(s
);
773 case 3: /* libbasetype */
775 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
776 cfg
->libbasetype
= strdup(s
);
779 case 4: /* libbasetypeextern */
781 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
782 libbasetypeextern
= strdup(s
);
785 case 5: /* version */
787 exitfileerror(20, "version not valid config option when in a class section\n");
788 if (sscanf(s
, "%u.%u", &cfg
->majorversion
, &cfg
->minorversion
)!=2)
789 exitfileerror(20, "wrong version string \"%s\"\n", s
);
794 exitfileerror(20, "date not valid config option when in a class section\n");
796 if (strptime(s
, "%e.%m.%Y", &date
) == NULL
)
798 exitfileerror(20, "date string has to have d.m.yyyy format\n");
801 cfg
->datestring
= strdup(s
);
804 case 7: /* copyright */
806 exitfileerror(20, "copyright not valid config option when in a class section\n");
807 cfg
->copyright
= strdup(s
);
810 case 8: /* libcall */
811 fprintf(stderr
, "libcall specification is deprecated and ignored\n");
814 case 9: /* forcebase */
816 exitfileerror(20, "forcebase not valid config option when in a class section\n");
817 slist_append(&cfg
->forcelist
, s
);
820 case 10: /* superclass */
822 exitfileerror(20, "superclass specified when not a BOOPSI class\n");
823 cl
->superclass
= strdup(s
);
826 case 11: /* superclass_field */
828 exitfileerror(20, "superclass_field specified when not a BOOPSI class\n");
829 cl
->superclass_field
= strdup(s
);
832 case 12: /* residentpri */
838 count
= sscanf(s
, "%d%c", &cfg
->residentpri
, &dummy
);
840 cfg
->residentpri
< -128 || cfg
->residentpri
> 127
843 exitfileerror(20, "residentpri number format error\n");
847 exitfileerror(20, "residentpri not valid config option when in a class section\n");
850 case 13: /* options */
853 static const char *optionnames
[] =
855 "noautolib", "noexpunge", "noresident", "peropenerbase",
856 "pertaskbase", "includes", "noincludes", "nostubs",
857 "autoinit", "noautoinit", "resautoinit", "noopenclose",
860 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
865 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
867 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
870 s
+= strlen(optionnames
[i
]);
871 while (isspace(*s
)) s
++;
875 exitfileerror(20, "Unrecognized option\n");
879 exitfileerror(20, "Unrecognized option\n");
882 case 1: /* noautolib */
883 cfg
->options
|= OPTION_NOAUTOLIB
;
885 case 2: /* noexpunge */
886 cfg
->options
|= OPTION_NOEXPUNGE
;
888 case 3: /* noresident */
889 cfg
->options
|= OPTION_NORESIDENT
;
892 case 5: /* pertaskbase */
893 cfg
->options
|= OPTION_PERTASKBASE
;
895 case 4: /* peropenerbase */
896 if (cfg
->options
& OPTION_DUPBASE
)
897 exitfileerror(20, "Only one option peropenerbase or pertaskbase allowed\n");
898 cfg
->options
|= OPTION_DUPBASE
;
900 case 6: /* includes */
901 if (cfg
->options
& OPTION_NOINCLUDES
)
902 exitfileerror(20, "option includes and noincludes are incompatible\n");
903 cfg
->options
|= OPTION_INCLUDES
;
905 case 7: /* noincludes */
906 if (cfg
->options
& OPTION_INCLUDES
)
907 exitfileerror(20, "option includes and noincludes are incompatible\n");
908 cfg
->options
|= OPTION_NOINCLUDES
;
910 case 8: /* nostubs */
911 cfg
->options
|= OPTION_NOSTUBS
;
913 case 9: /* autoinit */
914 if (cfg
->options
& OPTION_NOAUTOINIT
)
915 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
916 cfg
->options
|= OPTION_AUTOINIT
;
918 case 10: /* noautoinit */
919 if (cfg
->options
& OPTION_AUTOINIT
)
920 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
921 cfg
->options
|= OPTION_NOAUTOINIT
;
923 case 11: /* resautoinit */
924 if (cfg
->options
& OPTION_SELFINIT
)
925 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
926 cfg
->options
|= OPTION_RESAUTOINIT
;
929 cfg
->options
|= OPTION_NOOPENCLOSE
;
931 case 13: /* noresautoinit */
932 if (cfg
->options
& OPTION_RESAUTOINIT
)
933 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
934 cfg
->options
|= OPTION_SELFINIT
;
937 while (isspace(*s
)) s
++;
942 static const char *optionnames
[] =
946 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
951 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
953 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
956 s
+= strlen(optionnames
[i
]);
957 while (isspace(*s
)) s
++;
961 exitfileerror(20, "Unrecognized option\n");
965 exitfileerror(20, "Unrecognized option\n");
968 case 1: /* private */
969 cl
->options
|= COPTION_PRIVATE
;
972 while (isspace(*s
)) s
++;
977 case 14: /* sysbase_field */
979 exitfileerror(20, "sysbase_field not valid config option when in a class section\n");
980 cfg
->sysbase_field
= strdup(s
);
983 case 15: /* seglist_field */
985 exitfileerror(20, "seglist_field not valid config option when in a class section\n");
986 cfg
->seglist_field
= strdup(s
);
989 case 16: /* rootbase_field */
991 exitfileerror(20, "rootbase_field not valid config option when in a class section\n");
992 cfg
->rootbase_field
= strdup(s
);
995 case 17: /* classptr_field */
1001 "classptr_field specified when not a BOOPSI class\n"
1004 cl
->classptr_field
= strdup(s
);
1007 case 18: /* classptr_var */
1013 "classptr_var specified when not a BOOPSI class\n"
1016 cl
->classptr_var
= strdup(s
);
1019 case 19: /* classid */
1021 exitfileerror(20, "classid specified when not a BOOPSI class\n");
1022 if (cl
->classid
!= NULL
)
1023 exitfileerror(20, "classid specified twice\n");
1024 cl
->classid
= strdup(s
);
1025 if (strcmp(cl
->classid
, "NULL") == 0)
1026 cl
->options
|= COPTION_PRIVATE
;
1029 case 20: /* classdatatype */
1031 exitfileerror(20, "classdatatype specified when not a BOOPSI class\n");
1032 cl
->classdatatype
= strdup(s
);
1035 case 21: /* beginio_func */
1037 exitfileerror(20, "beginio_func not valid config option when in a class section\n");
1038 if (cfg
->modtype
!= DEVICE
)
1039 exitfileerror(20, "beginio_func specified when not a device\n");
1040 cfg
->beginiofunc
= strdup(s
);
1043 case 22: /* abortio_func */
1045 exitfileerror(20, "abortio_func not valid config option when in a class section\n");
1046 if (cfg
->modtype
!= DEVICE
)
1047 exitfileerror(20, "abortio_func specified when not a device\n");
1048 cfg
->abortiofunc
= strdup(s
);
1051 case 23: /* dispatcher */
1053 exitfileerror(20, "dispatcher specified when not a BOOPSI class\n");
1054 cl
->dispatcher
= strdup(s
);
1055 /* function references are not needed when dispatcher is specified */
1056 cfg
->intcfg
|= CFG_NOREADFUNCS
;
1059 case 24: /* initpri */
1065 count
= sscanf(s
, "%d%c", &cl
->initpri
, &dummy
);
1067 cl
->initpri
< -128 || cl
->initpri
> 127
1070 exitfileerror(20, "initpri number format error\n");
1074 exitfileerror(20, "initpri only valid config option for a BOOPSI class\n");
1079 exitfileerror(20, "type only valid config option in a class section\n");
1080 if (strcmp(s
,"mcc")==0)
1081 cl
->classtype
= MCC
;
1082 else if (strcmp(s
,"mui")==0)
1083 cl
->classtype
= MUI
;
1084 else if (strcmp(s
,"mcp")==0)
1085 cl
->classtype
= MCP
;
1086 else if (strcmp(s
, "image")==0)
1087 cl
->classtype
= IMAGE
;
1088 else if (strcmp(s
, "gadget")==0)
1089 cl
->classtype
= GADGET
;
1090 else if (strcmp(s
, "datatype")==0)
1091 cl
->classtype
= DATATYPE
;
1092 else if (strcmp(s
, "usbclass")==0)
1093 cl
->classtype
= USBCLASS
;
1094 else if (strcmp(s
, "class")==0)
1095 cl
->classtype
= CLASS
;
1096 else if (strcmp(s
, "hidd")==0)
1097 cl
->classtype
= HIDD
;
1100 fprintf(stderr
, "Unknown type \"%s\" specified\n", s
);
1105 case 26: /* addromtag */
1106 cfg
->addromtag
= strdup(s
);
1109 case 27: /* oopbase_field */
1110 cfg
->oopbase_field
= strdup(s
);
1112 case 28: /* rellib */
1113 slist_append(&cfg
->rellibs
, s
);
1115 case 29: /* interfaceid */
1117 exitfileerror(20, "interfaceid only valid config option for an interface\n");
1118 in
->interfaceid
= strdup(s
);
1120 case 30: /* interfacename */
1122 exitfileerror(20, "interfacename only valid config option for an interface\n");
1123 in
->interfacename
= strdup(s
);
1125 case 31: /* methodstub */
1127 exitfileerror(20, "methodstub only valid config option for an interface\n");
1128 in
->methodstub
= strdup(s
);
1130 case 32: /* methodbase */
1132 exitfileerror(20, "methodbase only valid config option for an interface\n");
1133 in
->methodbase
= strdup(s
);
1135 case 33: /* attributebase */
1137 exitfileerror(20, "attributebase only valid config option for an interface\n");
1138 in
->attributebase
= strdup(s
);
1140 case 34: /* handler_func */
1141 if (cfg
->modtype
!= HANDLER
)
1142 exitfileerror(20, "handler specified when not a handler\n");
1143 cfg
->handlerfunc
= strdup(s
);
1147 else /* Line starts with ## */
1150 while (isspace(*s
)) s
++;
1151 if (strncmp(s
, "end", 3)!=0)
1152 exitfileerror(20, "\"##end config\" expected\n");
1156 exitfileerror(20, "\"##end config\" expected\n");
1158 while (isspace(*s
)) s
++;
1159 if (strncmp(s
, "config", 6)!=0)
1160 exitfileerror(20, "\"##end config\" expected\n");
1163 while (isspace(*s
)) s
++;
1165 exitfileerror(20, "\"##end config\" expected\n");
1171 /* When not in a class section fill in default values for fields in cfg */
1174 if (cfg
->basename
==NULL
)
1176 cfg
->basename
= strdup(cfg
->modulename
);
1177 *cfg
->basename
= toupper(*cfg
->basename
);
1179 if (cfg
->libbase
==NULL
)
1181 unsigned int len
= strlen(cfg
->basename
)+5;
1182 cfg
->libbase
= malloc(len
);
1183 snprintf(cfg
->libbase
, len
, "%sBase", cfg
->basename
);
1185 if (cfg
->libbasetype
== NULL
&& libbasetypeextern
!= NULL
)
1186 cfg
->libbasetype
= strdup(libbasetypeextern
);
1187 if (cfg
->sysbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1188 exitfileerror(20, "sysbase_field specified when no libbasetype is given\n");
1189 if (cfg
->seglist_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1190 exitfileerror(20, "seglist_field specified when no libbasetype is given\n");
1191 if (cfg
->oopbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1192 exitfileerror(20, "oopbase_field specified when no libbasetype is given\n");
1193 /* rootbase_field only allowed when duplicating base */
1194 if (cfg
->rootbase_field
!= NULL
&& !(cfg
->options
& OPTION_DUPBASE
))
1195 exitfileerror(20, "rootbasefield only valid for option peropenerbase or pertaskbase\n");
1197 /* Set default date to current date */
1198 if (cfg
->datestring
== NULL
)
1201 time_t now
= time(NULL
);
1202 struct tm
*ltime
= localtime(&now
);
1204 snprintf(tmpbuf
, sizeof(tmpbuf
), "%u.%u.%u",
1205 ltime
->tm_mday
, 1 + ltime
->tm_mon
, 1900 + ltime
->tm_year
);
1207 cfg
->datestring
= strdup(tmpbuf
);
1210 if (cfg
->copyright
== NULL
)
1211 cfg
->copyright
= "";
1213 if ( (cfg
->beginiofunc
!= NULL
&& cfg
->abortiofunc
== NULL
)
1214 || (cfg
->beginiofunc
== NULL
&& cfg
->abortiofunc
!= NULL
)
1216 exitfileerror(20, "please specify both beginio_func and abortio_func\n");
1218 if (libbasetypeextern
==NULL
)
1220 switch (cfg
->modtype
)
1223 cfg
->libbasetypeptrextern
= "struct Device *";
1227 cfg
->libbasetypeptrextern
= "APTR ";
1237 cfg
->libbasetypeptrextern
= "struct Library *";
1240 fprintf(stderr
, "Internal error: Unsupported modtype for libbasetypeptrextern\n");
1246 cfg
->libbasetypeptrextern
= malloc(strlen(libbasetypeextern
)+3);
1247 strcpy(cfg
->libbasetypeptrextern
, libbasetypeextern
);
1248 strcat(cfg
->libbasetypeptrextern
, " *");
1249 free(libbasetypeextern
);
1253 /* When class was given too fill in some defaults when not specified */
1256 if (cl
->classtype
== UNSPECIFIED
)
1257 cl
->classtype
= CLASS
;
1259 if (cl
->basename
== NULL
)
1262 cl
->basename
= cfg
->basename
;
1264 exitfileerror(20, "basename has to be specified in the config section inside of a class section\n");
1267 /* MUI classes are always private */
1268 if (cl
->classtype
== MUI
|| cl
->classtype
== MCC
|| cl
->classtype
== MCP
)
1269 cl
->options
|= COPTION_PRIVATE
;
1271 if (cl
->classid
== NULL
1272 && (cl
->classtype
!= MUI
&& cl
->classtype
!= MCC
&& cl
->classtype
!= MCP
)
1275 if (cl
->classtype
== HIDD
)
1277 cl
->options
&= !COPTION_PRIVATE
;
1279 else if (cl
->options
& COPTION_PRIVATE
)
1281 cl
->classid
= "NULL";
1287 if (cl
->classtype
== GADGET
|| cl
->classtype
== IMAGE
|| cl
->classtype
== CLASS
|| cl
->classtype
== USBCLASS
)
1289 sprintf(s
, "\"%sclass\"", inclass
? cl
->basename
: cfg
->modulename
);
1291 else if (cl
->classtype
== DATATYPE
)
1293 sprintf(s
, "\"%s.datatype\"", inclass
? cl
->basename
: cfg
->modulename
);
1295 cl
->classid
= strdup(s
);
1299 /* Only specify superclass or superclass_field */
1300 if (cl
->superclass
!= NULL
&& cl
->superclass_field
!= NULL
)
1301 exitfileerror(20, "Only specify one of superclass or superclass_field in config section\n");
1303 /* Give default value to superclass if it is not specified */
1304 if (cl
->superclass
== NULL
&& cl
->superclass
== NULL
)
1306 switch (cl
->classtype
)
1310 cl
->superclass
= "MUIC_Area";
1313 cl
->superclass
= "MUIC_Mccprefs";
1316 cl
->superclass
= "IMAGECLASS";
1319 cl
->superclass
= "GADGETCLASS";
1322 cl
->superclass
= "DATATYPESCLASS";
1325 cl
->superclass
= "ROOTCLASS";
1328 cl
->superclass
= "CLID_Root";
1331 exitfileerror(20, "Internal error: unhandled classtype in readsectionconfig\n");
1338 static void readsectioncdef(struct config
*cfg
)
1347 exitfileerror(20, "unexptected end of file in section cdef\n");
1349 if (strncmp(line
, "##", 2)!=0)
1351 slist_append(&cfg
->cdeflines
, line
);
1356 while (isspace(*s
)) s
++;
1357 if (strncmp(s
, "end", 3)!=0)
1358 exitfileerror(20, "\"##end cdef\" expected\n");
1361 while (isspace(*s
)) s
++;
1362 if (strncmp(s
, "cdef", 4)!=0)
1363 exitfileerror(20, "\"##end cdef\" expected\n");
1366 while (isspace(*s
)) s
++;
1368 exitfileerror(20, "unexpected character at position %d\n");
1375 static void readsectioncdefprivate(struct config
*cfg
)
1384 exitfileerror(20, "unexptected end of file in section cdef\n");
1386 if (strncmp(line
, "##", 2)!=0)
1388 slist_append(&cfg
->cdefprivatelines
, line
);
1393 while (isspace(*s
)) s
++;
1394 if (strncmp(s
, "end", 3)!=0)
1395 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1398 while (isspace(*s
)) s
++;
1399 if (strncmp(s
, "cdefprivate", 11)!=0)
1400 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1403 while (isspace(*s
)) s
++;
1405 exitfileerror(20, "unexpected character at position %d\n");
1412 static void readsectionstartup(struct config
*cfg
)
1421 exitfileerror(20, "unexptected end of file in section startup\n");
1423 if (strncmp(line
, "##", 2)!=0)
1425 slist_append(&cfg
->startuplines
, line
);
1430 while (isspace(*s
)) s
++;
1431 if (strncmp(s
, "end", 3)!=0)
1432 exitfileerror(20, "\"##end startup\" expected\n");
1435 while (isspace(*s
)) s
++;
1436 if (strncmp(s
, "startup", 7)!=0)
1437 exitfileerror(20, "\"##end startup\" expected\n");
1440 while (isspace(*s
)) s
++;
1442 exitfileerror(20, "unexpected character at position %d\n");
1449 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
, enum libcall def_libcall
)
1452 char *line
, *s
, *s2
;
1453 unsigned int lvo
= firstlvo
;
1454 int minversion
= -1;
1460 exitfileerror(20, "unexpected EOF in functionlist section\n");
1461 if (strlen(line
)==0)
1463 if (*funclistptr
!= NULL
)
1464 funclistptr
= &((*funclistptr
)->next
);
1467 else if (isspace(*line
))
1470 while (isspace(*s
)) s
++;
1473 if (*funclistptr
!= NULL
)
1474 funclistptr
= &((*funclistptr
)->next
);
1478 exitfileerror(20, "no space allowed before functionname\n");
1480 else if (strncmp(line
, "##", 2)==0)
1483 while (isspace(*s
)) s
++;
1484 if (strncmp(s
, "end", 3)!=0)
1485 exitfileerror(20, "\"##end %s\" expected\n", type
);
1488 while (isspace(*s
)) s
++;
1489 if (strncmp(s
, type
, strlen(type
))!=0)
1490 exitfileerror(20, "\"##end %s\" expected\n", type
);
1493 while (isspace(*s
)) s
++;
1495 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1499 else if (*line
=='.')
1502 if (strncmp(s
, "skip", 4)==0)
1508 exitfileerror(20, "syntax is '.skip n'\n");
1510 n
=strtol(s
, &s2
, 10);
1512 exitfileerror(20, "positive number expected\n");
1514 while (isspace(*s2
)) s2
++;
1515 if ((*s2
!= '\0') && (*s2
!= '#'))
1516 exitfileerror(20, "syntax is '.skip n'\n");
1517 if (*funclistptr
!= NULL
)
1518 funclistptr
= &((*funclistptr
)->next
);
1521 else if (strncmp(s
, "alias", 5)==0)
1526 exitfileerror(20, "syntax is '.alias name'\n");
1528 while (isspace(*s
)) s
++;
1529 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1530 exitfileerror(20, "syntax is '.alias name'\n");
1534 while (isalnum(*s
) || *s
== '_') s
++;
1541 } while (isspace(*s
));
1545 exitfileerror(20, "syntax is '.alias name'\n");
1547 if (*funclistptr
== NULL
)
1548 exitfileerror(20, ".alias has to come after a function declaration\n");
1550 slist_append(&(*funclistptr
)->aliases
, s2
);
1552 else if (strncmp(s
, "function", 8) == 0)
1557 exitfileerror(20, "Syntax error\n");
1559 while (isspace(*s
)) s
++;
1560 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1561 exitfileerror(20, "syntax is '.function name'\n");
1565 while (isalnum(*s
) || *s
== '_') s
++;
1572 } while (isspace(*s
));
1576 exitfileerror(20, "syntax is '.function name'\n");
1578 if (*funclistptr
== NULL
)
1579 exitfileerror(20, ".function has to come after a function declaration\n");
1581 funcsetinternalname(*funclistptr
, s2
);
1583 else if (strncmp(s
, "cfunction", 9)==0)
1585 if (*funclistptr
== NULL
)
1586 exitfileerror(20, ".cfunction has to come after a function declaration\n");
1588 (*funclistptr
)->libcall
= REGISTER
;
1590 else if (strncmp(s
, "private", 7)==0)
1592 if (*funclistptr
== NULL
)
1593 exitfileerror(20, ".private has to come after a function declaration\n");
1595 (*funclistptr
)->priv
= 1;
1597 else if (strncmp(s
, "novararg", 8)==0)
1599 if (*funclistptr
== NULL
)
1600 exitfileerror(20, ".novararg has to come after a function declaration\n");
1602 (*funclistptr
)->novararg
= 1;
1604 else if (strncmp(s
, "version", 7) == 0)
1606 /* Mark version number for the following
1607 * functions, so that the automatic OpenLibrary()
1608 * will know what version to use.
1615 while (isspace(*s
)) s
++;
1616 ver
= (int)strtol(s
, &tmp
, 0);
1619 exitfileerror(20, ".version expects an integer\n");
1622 while (isspace(*s
)) s
++;
1624 if (*s
&& *s
!= '#')
1625 exitfileerror(20, ".version has junk after the version number\n");
1629 else if (strncmp(s
, "unusedlibbase", 13) == 0)
1631 if (*funclistptr
== NULL
)
1632 exitfileerror(20, ".unusedlibbase has to come after a function declaration\n");
1633 (*funclistptr
)->unusedlibbase
= 1;
1636 exitfileerror(20, "Syntax error");
1638 else if (*line
!='#') /* Ignore line that is a comment, e.g. that starts with a # */
1640 /* The line is a function or attribute prototype.
1641 * A function can have one of two syntaxes:
1642 * type funcname(argproto1, argproto2, ...)
1643 * type funcname(argproto1, argproto2, ...) (reg1, reg2, ...)
1644 * The former is for C type function argument passing, the latter for
1645 * register argument passing.
1646 * An attribute has the following syntax:
1649 char c
, *args
[64], *regs
[64], *funcname
, *cp
;
1650 int len
, argcount
= 0, regcount
= 0, brcount
= 0;
1652 cp
= strchr(line
,'#');
1656 /* Parse 'type functionname' at the beginning of the line */
1658 s
= line
+ strlen(line
);
1660 s
= strchr(line
, '(');
1662 exitfileerror(20, "( expected at position %d\n", strlen(line
) + 1);
1666 while (isspace(*(s2
-1)))
1670 while (s2
> line
&& !isspace(*(s2
-1)) && !(*(s2
-1) == '*'))
1674 exitfileerror(20, "No type specifier before %s name\n", isattribute
? "attribute" : "function");
1676 if (*funclistptr
!= NULL
)
1677 funclistptr
= &((*funclistptr
)->next
);
1678 *funclistptr
= newfunctionhead(s2
, STACK
);
1681 (*funclistptr
)->comment
= strdup(cp
);
1683 (*funclistptr
)->comment
= NULL
;
1685 while (isspace(*(s2
-1)))
1688 (*funclistptr
)->type
= strdup(line
);
1689 (*funclistptr
)->lvo
= lvo
;
1690 (*funclistptr
)->version
= minversion
;
1696 /* Parse function prototype */
1713 && !(brcount
== 0 && (*s
== ',' || *s
== ')'))
1723 exitfileerror(20, "Unexected ')' at position %d\n", s
-line
+1);
1730 exitfileerror(20, "'(' without ')'");
1733 while (isspace(*(s2
-1)))
1737 if (!(s2
> args
[argcount
- 1]))
1738 exitfileerror(20, "Syntax error in function prototype\n");
1744 while (*s
!= '\0' && isspace(*s
))
1749 /* Parse registers specifications if available otherwise this prototype for C type argument passing */
1751 /* There may be no register specified with () so be sure then c is == ')' */
1766 if (memchr("AD",s
[0],2)!=NULL
&& memchr("01234567",s
[1],8)!=NULL
)
1773 if (s
[0] == s
[-3] && s
[1] == s
[-2] + 1)
1780 "wrong register specification \"%s\" for argument %u\n",
1781 regs
[regcount
-1], regcount
1785 exitfileerror(20, "maximum four arguments passed in two registers allowed (%d, %s) \n", regcount
, regs
[regcount
-1]);
1791 "wrong register \"%s\" for argument %u\n",
1792 regs
[regcount
-1], regcount
1801 exitfileerror(20, "'(' without ')'\n");
1802 if (c
!= ',' && c
!= ')')
1803 exitfileerror(20, "',' or ')' expected at position %d\n", s
-line
+1);
1809 while (isspace(*s
)) s
++;
1811 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1813 if (argcount
!= regcount
)
1814 exitfileerror(20, "Number of arguments (%d) and registers (%d) mismatch\n",
1818 (*funclistptr
)->libcall
= def_libcall
;
1819 for (i
= 0; i
< argcount
; i
++)
1820 funcaddarg(*funclistptr
, args
[i
], regs
[i
]);
1822 else if (*s
== '\0')
1823 { /* No registers specified */
1824 for (i
= 0; i
< argcount
; i
++)
1825 funcaddarg(*funclistptr
, args
[i
], NULL
);
1828 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1833 static void readsectionclass_methodlist(struct classinfo
*cl
)
1836 char *line
, *s
, *s2
;
1837 struct functionhead
**methlistptr
= &cl
->methlist
;
1838 struct stringlist
*interface
= NULL
;
1840 if (cl
->basename
==NULL
)
1841 exitfileerror(20, "section methodlist has to come after section config\n");
1847 exitfileerror(20, "unexptected EOF in methodlist section\n");
1849 /* Ignore empty lines or lines that qre a comment, e.g. that starts with a # */
1850 if (strlen(line
)==0 || (line
[0] == '#' && line
[1] != '#'))
1854 exitfileerror(20, "No space allowed at start of the line\n");
1856 if (strncmp(line
, "##", 2)==0) /* Is this the end ? */
1859 while (isspace(*s
)) s
++;
1860 if (strncmp(s
, "end", 3)!=0)
1861 exitfileerror(20, "\"##end methodlist\" expected\n");
1864 while (isspace(*s
)) s
++;
1865 if (strncmp(s
, "methodlist", 10)!=0)
1866 exitfileerror(20, "\"##end methodlist\" expected\n");
1869 while (isspace(*s
)) s
++;
1871 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1881 if (strncmp(s
, "alias", 5)==0)
1886 exitfileerror(20, "syntax is '.alias name'\n");
1888 while (isspace(*s
)) s
++;
1889 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1890 exitfileerror(20, "syntax is '.alias name'\n");
1894 while (isalnum(*s
) || *s
== '_') s
++;
1901 } while (isspace(*s
));
1905 exitfileerror(20, "syntax is '.alias name'\n");
1907 if (*methlistptr
== NULL
)
1908 exitfileerror(20, ".alias has to come after a function declaration\n");
1910 slist_append(&(*methlistptr
)->aliases
, s2
);
1912 else if (strncmp(s
, "function", 8) == 0)
1917 exitfileerror(20, "Syntax error\n");
1919 while (isspace(*s
)) s
++;
1920 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1921 exitfileerror(20, "syntax is '.function name'\n");
1925 while (isalnum(*s
) || *s
== '_') s
++;
1932 } while (isspace(*s
));
1936 exitfileerror(20, "syntax is '.function name'\n");
1938 if (*methlistptr
== NULL
)
1939 exitfileerror(20, ".function has to come after a function declaration\n");
1941 funcsetinternalname(*methlistptr
, s2
);
1943 else if (strncmp(s
, "interface", 9) == 0)
1945 if (cl
->classtype
!= HIDD
)
1946 exitfileerror(20, "interface only valid for a HIDD\n");
1951 exitfileerror(20, "Syntax error\n");
1953 while (isspace(*s
)) s
++;
1954 if (*s
== '\0' || !isalpha(*s
))
1955 exitfileerror(20, "syntax is '.interface name'\n");
1959 while (isalnum(*s
) || *s
== '_') s
++;
1966 } while (isspace(*s
));
1970 exitfileerror(20, "syntax is '.interface name'\n");
1972 interface
= slist_append(&cl
->interfaces
, s2
);
1975 exitfileerror(20, "Syntax error");
1977 else if (isalpha(*line
))
1981 for (s
= line
+ 1; isalnum(*s
) || *s
== '_'; s
++)
1984 if (cl
->classtype
== HIDD
&& interface
== NULL
)
1985 exitfileerror(20, "For a HIDD the first method has to come after an .interface line\n");
1988 exitfileerror(20, "Only letters, digits and an underscore allowed in a methodname\n");
1990 if (*methlistptr
!= NULL
)
1991 methlistptr
= &((*methlistptr
)->next
);
1992 if (cl
->classtype
!= HIDD
)
1994 if (snprintf(stmp
, 256, "%s__%s", cl
->basename
, line
) >= 256)
1995 exitfileerror(20, "Method name too large\n");
1997 *methlistptr
= newfunctionhead(stmp
, STACK
);
1998 (*methlistptr
)->type
= "IPTR";
1999 funcaddarg(*methlistptr
, "Class *cl", NULL
);
2000 funcaddarg(*methlistptr
, "Object *o", NULL
);
2001 funcaddarg(*methlistptr
, "Msg msg", NULL
);
2005 if (snprintf(stmp
, 256, "%s__%s__%s", cl
->basename
, interface
->s
, line
) >= 256)
2006 exitfileerror(20, "Method name too large\n");
2008 *methlistptr
= newfunctionhead(stmp
, STACK
);
2009 (*methlistptr
)->type
= "IPTR";
2010 funcaddarg(*methlistptr
, "OOP_Class *cl", NULL
);
2011 funcaddarg(*methlistptr
, "OOP_Object *o", NULL
);
2012 funcaddarg(*methlistptr
, "OOP_Msg msg", NULL
);
2013 (*methlistptr
)->interface
= interface
;
2014 if (snprintf(stmp
, 256, "mo%s_%s", interface
->s
, line
) >= 256)
2015 exitfileerror(20, "Method name too large\n");
2016 (*methlistptr
)->method
= strdup(stmp
);
2018 slist_append(&(*methlistptr
)->aliases
, line
);
2021 exitfileerror(20, "Methodname has to begin with a letter\n");
2026 readsectioninterface(struct config
*cfg
)
2029 struct interfaceinfo
*in
;
2031 in
= newinterface(cfg
);
2032 s
= readsections(cfg
, NULL
, in
, 1);
2034 exitfileerror(20, "Unexpected end of file\n");
2036 if (strncmp(s
, "##", 2) != 0)
2037 exitfileerror(20, "'##end interface' expected\n");
2040 while (isspace(*s
)) s
++;
2042 if (strncmp(s
, "end", 3) != 0)
2043 exitfileerror(20, "'##end interface' expected\n");
2047 exitfileerror(20, "'##end interface' expected\n");
2048 while (isspace(*s
)) s
++;
2050 if (strncmp(s
, "interface", 9) != 0)
2051 exitfileerror(20, "'##end interface' expected\n");
2054 while (isspace(*s
)) s
++;
2056 exitfileerror(20, "'##end interface' expected\n");
2058 if (!in
->interfaceid
)
2059 exitfileerror(20, "interface has no 'interfaceid' defined!\n");
2061 if (!in
->interfacename
)
2062 exitfileerror(20, "interface has no 'interfacename' defined!\n");
2064 if (!in
->methodstub
)
2065 in
->methodstub
= strdup(in
->interfacename
);
2067 if (!in
->methodbase
) {
2068 int len
= strlen(in
->interfacename
);
2069 in
->methodbase
= malloc(len
+ 4 + 1);
2070 strcpy(in
->methodbase
, in
->interfacename
);
2071 strcat(in
->methodbase
, "Base");
2074 if (!in
->attributebase
) {
2075 int len
= strlen(in
->interfacename
);
2076 in
->attributebase
= malloc(len
+ 4 + 4 + 1);
2077 strcpy(in
->attributebase
, in
->interfacename
);
2078 strcat(in
->attributebase
, "AttrBase");
2083 readsectionclass(struct config
*cfg
)
2086 struct classinfo
*cl
;
2089 s
= readsections(cfg
, cl
, NULL
, 1);
2091 exitfileerror(20, "Unexpected end of file\n");
2093 if (strncmp(s
, "##", 2) != 0)
2094 exitfileerror(20, "'##end class' expected\n");
2097 while (isspace(*s
)) s
++;
2099 if (strncmp(s
, "end", 3) != 0)
2100 exitfileerror(20, "'##end class' expected\n");
2104 exitfileerror(20, "'##end class' expected\n");
2105 while (isspace(*s
)) s
++;
2107 if (strncmp(s
, "class", 5) != 0)
2108 exitfileerror(20, "'##end class' expected\n");
2111 while (isspace(*s
)) s
++;
2113 exitfileerror(20, "'##end class' expected\n");
2116 static struct classinfo
*newclass(struct config
*cfg
)
2118 struct classinfo
*cl
, *classlistit
;
2120 cl
= malloc(sizeof(struct classinfo
));
2123 fprintf(stderr
, "Out of memory\n");
2126 memset(cl
, 0, sizeof(struct classinfo
));
2128 /* By default the classes are initialized with a priority of 1 so they
2129 * are initialized before any user added initialization with priority 1
2133 if (cfg
->classlist
== NULL
)
2134 cfg
->classlist
= cl
;
2139 classlistit
= cfg
->classlist
;
2140 classlistit
->next
!= NULL
;
2141 classlistit
= classlistit
->next
2144 classlistit
->next
= cl
;
2150 static struct handlerinfo
*newhandler(struct config
*cfg
)
2152 struct handlerinfo
*hl
;
2154 hl
= calloc(1,sizeof(*hl
));
2155 hl
->next
= cfg
->handlerlist
;
2156 cfg
->handlerlist
= hl
;
2160 static struct interfaceinfo
*newinterface(struct config
*cfg
)
2162 struct interfaceinfo
*in
, *interfacelistit
;
2164 in
= malloc(sizeof(struct interfaceinfo
));
2167 fprintf(stderr
, "Out of memory\n");
2170 memset(in
, 0, sizeof(struct interfaceinfo
));
2172 if (cfg
->interfacelist
== NULL
)
2173 cfg
->interfacelist
= in
;
2178 interfacelistit
= cfg
->interfacelist
;
2179 interfacelistit
->next
!= NULL
;
2180 interfacelistit
= interfacelistit
->next
2183 interfacelistit
->next
= in
;
2190 static int getdirective(char *s
, const char *directive
, int range_min
, int range_max
, int *val
)
2195 if (strncmp(s
, directive
, strlen(directive
)) != 0)
2198 s
+= strlen(directive
);
2199 if (*s
&& !isspace(*s
))
2200 exitfileerror(20, "Unrecognized directive \".%s\"\n", directive
);
2202 while (isspace(*s
)) s
++;
2204 exitfileerror(20, "No .%s value specified\n", directive
);
2206 newval
= strtol(s
, &tmp
, 0);
2207 if (s
== tmp
|| !(newval
>= range_min
&& newval
<= range_max
)) {
2209 while (*tmp
&& !isspace(*tmp
)) tmp
++;
2210 exitfileerror(20, "Invalid .%s value of %.*s\n", directive
, tmp
- s
, s
);
2218 readsectionhandler(struct config
*cfg
)
2220 char *line
= NULL
, *s
;
2221 struct handlerinfo
*hl
;
2222 unsigned char autolevel
= 0;
2223 unsigned int stacksize
= 0;
2227 int has_filesystem
= 0;
2235 s
= line
= readline();
2238 exitfileerror(20, "unexpected end of file in section hanlder\n");
2240 if (strncmp(s
, "##", 2)==0)
2243 /* Ignore comments */
2244 if (strncmp(s
, "#", 1)==0)
2247 /* Skip ahead to function name */
2248 while (*s
&& isspace(*s
)) s
++;
2250 /* Permit blank lines */
2258 if (getdirective(s
, "autodetect", 0, 127, &val
)) {
2260 } else if (getdirective(s
, "stacksize", 0, INT_MAX
, &val
)) {
2262 } else if (getdirective(s
, "priority", -128, 127, &val
)) {
2264 } else if (getdirective(s
, "bootpri", -128, 127, &val
)) {
2266 } else if (getdirective(s
, "startup", INT_MIN
, INT_MAX
, &val
)) {
2269 exitfileerror(20, "Unrecognized directive \"%s\"\n", line
);
2275 unsigned int id
= 0;
2277 if (strncasecmp(s
,"resident=",9)==0) {
2280 s
= strchr(s
, '=') + 1;
2282 while (*s
&& !isspace(*s
)) s
++;
2284 exitfileerror(20, "Empty resident= is not permitted\n");
2289 hl
= newhandler(cfg
);
2290 hl
->type
= HANDLER_RESIDENT
;
2292 hl
->name
= strdup(res
);
2293 hl
->autodetect
= autolevel
--;
2294 hl
->stacksize
= stacksize
;
2295 hl
->priority
= priority
;
2296 hl
->startup
= startup
;
2297 } else if (strncasecmp(s
,"dosnode=",8)==0) {
2300 s
= strchr(s
, '=') + 1;
2302 while (*s
&& !isspace(*s
)) s
++;
2304 exitfileerror(20, "Empty dosnode= is not permitted\n");
2309 hl
= newhandler(cfg
);
2310 hl
->type
= HANDLER_DOSNODE
;
2312 hl
->name
= strdup(dev
);
2313 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2314 hl
->stacksize
= stacksize
;
2315 hl
->priority
= priority
;
2316 hl
->startup
= startup
;
2317 hl
->bootpri
= bootpri
;
2318 } else if (strncasecmp(s
,"dostype=",8) == 0) {
2319 s
= strchr(s
, '=') + 1;
2321 id
= (unsigned int)strtoul(s
, &tmp
, 0);
2324 while (*tmp
&& !isspace(*tmp
))
2326 exitfileerror(20, "\"%.*s\" is not a numerical DOS ID\n", (tmp
-s
), s
);
2330 if (id
== 0 || id
== ~0) {
2331 exitfileerror(20, "DOS ID 0x%08x is not permitted\n", id
);
2334 hl
= newhandler(cfg
);
2335 hl
->type
= HANDLER_DOSTYPE
;
2338 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2339 hl
->stacksize
= stacksize
;
2340 hl
->priority
= priority
;
2341 hl
->startup
= startup
;
2343 for (tmp
= s
; !isspace(*tmp
); tmp
++);
2344 exitfileerror(20, "Unknown option \"%.*s\"\n", tmp
- s
, s
);
2347 /* Advance to next ID */
2348 while (*s
&& isspace(*s
)) s
++;
2354 exitfileerror(20, "Unexpected end of file\n");
2356 if (strncmp(s
, "##", 2) != 0)
2357 exitfileerror(20, "'##end handler' expected\n");
2360 while (isspace(*s
)) s
++;
2362 if (strncmp(s
, "end", 3) != 0)
2363 exitfileerror(20, "'##end handler' expected\n");
2366 while (isspace(*s
)) s
++;
2368 if (strncmp(s
, "handler", 7) != 0)
2369 exitfileerror(20, "'##end handler' expected\n");
2372 while (isspace(*s
)) s
++;
2374 exitfileerror(20, "'##end handler' expected\n");