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} 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",
730 const unsigned int namenums
= sizeof(names
)/sizeof(char *);
731 unsigned int namenum
;
733 for (i
= 0, namenum
= 0; namenum
==0 && i
<namenums
; i
++)
737 strncmp(line
, names
[i
], strlen(names
[i
]))==0
738 && isspace(*(line
+strlen(names
[i
])))
743 exitfileerror(20, "unrecognized configuration option\n");
745 s
= line
+ strlen(names
[namenum
-1]);
747 exitfileerror(20, "space character expected after \"%s\"\n", names
[namenum
-1]);
749 while (isspace(*s
)) s
++;
751 exitfileerror(20, "unexpected end of line\n");
754 while (isspace(*(s2
-1))) s2
--;
759 case 1: /* basename */
761 cfg
->basename
= strdup(s
);
763 cl
->basename
= strdup(s
);
765 exitfileerror(20, "basename not valid config option when in an interface section\n");
768 case 2: /* libbase */
770 exitfileerror(20, "libbase not valid config option when in a class section\n");
771 cfg
->libbase
= strdup(s
);
774 case 3: /* libbasetype */
776 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
777 cfg
->libbasetype
= strdup(s
);
780 case 4: /* libbasetypeextern */
782 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
783 libbasetypeextern
= strdup(s
);
786 case 5: /* version */
788 exitfileerror(20, "version not valid config option when in a class section\n");
789 if (sscanf(s
, "%u.%u", &cfg
->majorversion
, &cfg
->minorversion
)!=2)
790 exitfileerror(20, "wrong version string \"%s\"\n", s
);
795 exitfileerror(20, "date not valid config option when in a class section\n");
797 if (strptime(s
, "%e.%m.%Y", &date
) == NULL
)
799 exitfileerror(20, "date string has to have d.m.yyyy format\n");
802 cfg
->datestring
= strdup(s
);
805 case 7: /* copyright */
807 exitfileerror(20, "copyright not valid config option when in a class section\n");
808 cfg
->copyright
= strdup(s
);
811 case 8: /* libcall */
812 fprintf(stderr
, "libcall specification is deprecated and ignored\n");
815 case 9: /* forcebase */
817 exitfileerror(20, "forcebase not valid config option when in a class section\n");
818 slist_append(&cfg
->forcelist
, s
);
821 case 10: /* superclass */
823 exitfileerror(20, "superclass specified when not a BOOPSI class\n");
824 cl
->superclass
= strdup(s
);
827 case 11: /* superclass_field */
829 exitfileerror(20, "superclass_field specified when not a BOOPSI class\n");
830 cl
->superclass_field
= strdup(s
);
833 case 12: /* residentpri */
839 count
= sscanf(s
, "%d%c", &cfg
->residentpri
, &dummy
);
841 cfg
->residentpri
< -128 || cfg
->residentpri
> 127
844 exitfileerror(20, "residentpri number format error\n");
848 exitfileerror(20, "residentpri not valid config option when in a class section\n");
851 case 13: /* options */
854 static const char *optionnames
[] =
856 "noautolib", "noexpunge", "noresident", "peropenerbase",
857 "pertaskbase", "includes", "noincludes", "nostubs",
858 "autoinit", "noautoinit", "resautoinit", "noopenclose",
861 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
866 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
868 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
871 s
+= strlen(optionnames
[i
]);
872 while (isspace(*s
)) s
++;
876 exitfileerror(20, "Unrecognized option\n");
880 exitfileerror(20, "Unrecognized option\n");
883 case 1: /* noautolib */
884 cfg
->options
|= OPTION_NOAUTOLIB
;
886 case 2: /* noexpunge */
887 cfg
->options
|= OPTION_NOEXPUNGE
;
889 case 3: /* noresident */
890 cfg
->options
|= OPTION_NORESIDENT
;
893 case 5: /* pertaskbase */
894 cfg
->options
|= OPTION_PERTASKBASE
;
896 case 4: /* peropenerbase */
897 if (cfg
->options
& OPTION_DUPBASE
)
898 exitfileerror(20, "Only one option peropenerbase or pertaskbase allowed\n");
899 cfg
->options
|= OPTION_DUPBASE
;
901 case 6: /* includes */
902 if (cfg
->options
& OPTION_NOINCLUDES
)
903 exitfileerror(20, "option includes and noincludes are incompatible\n");
904 cfg
->options
|= OPTION_INCLUDES
;
906 case 7: /* noincludes */
907 if (cfg
->options
& OPTION_INCLUDES
)
908 exitfileerror(20, "option includes and noincludes are incompatible\n");
909 cfg
->options
|= OPTION_NOINCLUDES
;
911 case 8: /* nostubs */
912 cfg
->options
|= OPTION_NOSTUBS
;
914 case 9: /* autoinit */
915 if (cfg
->options
& OPTION_NOAUTOINIT
)
916 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
917 cfg
->options
|= OPTION_AUTOINIT
;
919 case 10: /* noautoinit */
920 if (cfg
->options
& OPTION_AUTOINIT
)
921 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
922 cfg
->options
|= OPTION_NOAUTOINIT
;
924 case 11: /* resautoinit */
925 if (cfg
->options
& OPTION_SELFINIT
)
926 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
927 cfg
->options
|= OPTION_RESAUTOINIT
;
930 cfg
->options
|= OPTION_NOOPENCLOSE
;
932 case 13: /* noresautoinit */
933 if (cfg
->options
& OPTION_RESAUTOINIT
)
934 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
935 cfg
->options
|= OPTION_SELFINIT
;
938 while (isspace(*s
)) s
++;
943 static const char *optionnames
[] =
947 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
952 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
954 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
957 s
+= strlen(optionnames
[i
]);
958 while (isspace(*s
)) s
++;
962 exitfileerror(20, "Unrecognized option\n");
966 exitfileerror(20, "Unrecognized option\n");
969 case 1: /* private */
970 cl
->options
|= COPTION_PRIVATE
;
973 while (isspace(*s
)) s
++;
978 case 14: /* sysbase_field */
980 exitfileerror(20, "sysbase_field not valid config option when in a class section\n");
981 cfg
->sysbase_field
= strdup(s
);
984 case 15: /* seglist_field */
986 exitfileerror(20, "seglist_field not valid config option when in a class section\n");
987 cfg
->seglist_field
= strdup(s
);
990 case 16: /* rootbase_field */
992 exitfileerror(20, "rootbase_field not valid config option when in a class section\n");
993 cfg
->rootbase_field
= strdup(s
);
996 case 17: /* classptr_field */
1002 "classptr_field specified when not a BOOPSI class\n"
1005 cl
->classptr_field
= strdup(s
);
1008 case 18: /* classptr_var */
1014 "classptr_var specified when not a BOOPSI class\n"
1017 cl
->classptr_var
= strdup(s
);
1020 case 19: /* classid */
1022 exitfileerror(20, "classid specified when not a BOOPSI class\n");
1023 if (cl
->classid
!= NULL
)
1024 exitfileerror(20, "classid specified twice\n");
1025 cl
->classid
= strdup(s
);
1026 if (strcmp(cl
->classid
, "NULL") == 0)
1027 cl
->options
|= COPTION_PRIVATE
;
1030 case 20: /* classdatatype */
1032 exitfileerror(20, "classdatatype specified when not a BOOPSI class\n");
1033 cl
->classdatatype
= strdup(s
);
1036 case 21: /* beginio_func */
1038 exitfileerror(20, "beginio_func not valid config option when in a class section\n");
1039 if (cfg
->modtype
!= DEVICE
)
1040 exitfileerror(20, "beginio_func specified when not a device\n");
1041 cfg
->beginiofunc
= strdup(s
);
1044 case 22: /* abortio_func */
1046 exitfileerror(20, "abortio_func not valid config option when in a class section\n");
1047 if (cfg
->modtype
!= DEVICE
)
1048 exitfileerror(20, "abortio_func specified when not a device\n");
1049 cfg
->abortiofunc
= strdup(s
);
1052 case 23: /* dispatcher */
1054 exitfileerror(20, "dispatcher specified when not a BOOPSI class\n");
1055 cl
->dispatcher
= strdup(s
);
1056 /* function references are not needed when dispatcher is specified */
1057 cfg
->intcfg
|= CFG_NOREADFUNCS
;
1060 case 24: /* initpri */
1066 count
= sscanf(s
, "%d%c", &cl
->initpri
, &dummy
);
1068 cl
->initpri
< -128 || cl
->initpri
> 127
1071 exitfileerror(20, "initpri number format error\n");
1075 exitfileerror(20, "initpri only valid config option for a BOOPSI class\n");
1080 exitfileerror(20, "type only valid config option in a class section\n");
1081 if (strcmp(s
,"mcc")==0)
1082 cl
->classtype
= MCC
;
1083 else if (strcmp(s
,"mui")==0)
1084 cl
->classtype
= MUI
;
1085 else if (strcmp(s
,"mcp")==0)
1086 cl
->classtype
= MCP
;
1087 else if (strcmp(s
, "image")==0)
1088 cl
->classtype
= IMAGE
;
1089 else if (strcmp(s
, "gadget")==0)
1090 cl
->classtype
= GADGET
;
1091 else if (strcmp(s
, "datatype")==0)
1092 cl
->classtype
= DATATYPE
;
1093 else if (strcmp(s
, "usbclass")==0)
1094 cl
->classtype
= USBCLASS
;
1095 else if (strcmp(s
, "class")==0)
1096 cl
->classtype
= CLASS
;
1097 else if (strcmp(s
, "hidd")==0)
1098 cl
->classtype
= HIDD
;
1101 fprintf(stderr
, "Unknown type \"%s\" specified\n", s
);
1106 case 26: /* addromtag */
1107 cfg
->addromtag
= strdup(s
);
1110 case 27: /* oopbase_field */
1111 cfg
->oopbase_field
= strdup(s
);
1113 case 28: /* rellib */
1114 slist_append(&cfg
->rellibs
, s
);
1116 case 29: /* interfaceid */
1118 exitfileerror(20, "interfaceid only valid config option for an interface\n");
1119 in
->interfaceid
= strdup(s
);
1121 case 30: /* interfacename */
1123 exitfileerror(20, "interfacename only valid config option for an interface\n");
1124 in
->interfacename
= strdup(s
);
1126 case 31: /* methodstub */
1128 exitfileerror(20, "methodstub only valid config option for an interface\n");
1129 in
->methodstub
= strdup(s
);
1131 case 32: /* methodbase */
1133 exitfileerror(20, "methodbase only valid config option for an interface\n");
1134 in
->methodbase
= strdup(s
);
1136 case 33: /* attributebase */
1138 exitfileerror(20, "attributebase only valid config option for an interface\n");
1139 in
->attributebase
= strdup(s
);
1141 case 34: /* handler_func */
1142 if (cfg
->modtype
!= HANDLER
)
1143 exitfileerror(20, "handler specified when not a handler\n");
1144 cfg
->handlerfunc
= strdup(s
);
1146 case 35: /* includename */
1148 exitfileerror(20, "includename not valid config option"
1149 " when in a class section\n");
1150 cfg
->includename
= strdup(s
);
1154 else /* Line starts with ## */
1157 while (isspace(*s
)) s
++;
1158 if (strncmp(s
, "end", 3)!=0)
1159 exitfileerror(20, "\"##end config\" expected\n");
1163 exitfileerror(20, "\"##end config\" expected\n");
1165 while (isspace(*s
)) s
++;
1166 if (strncmp(s
, "config", 6)!=0)
1167 exitfileerror(20, "\"##end config\" expected\n");
1170 while (isspace(*s
)) s
++;
1172 exitfileerror(20, "\"##end config\" expected\n");
1178 /* When not in a class section fill in default values for fields in cfg */
1181 if (cfg
->basename
==NULL
)
1183 cfg
->basename
= strdup(cfg
->modulename
);
1184 *cfg
->basename
= toupper(*cfg
->basename
);
1186 if (cfg
->libbase
==NULL
)
1188 unsigned int len
= strlen(cfg
->basename
)+5;
1189 cfg
->libbase
= malloc(len
);
1190 snprintf(cfg
->libbase
, len
, "%sBase", cfg
->basename
);
1192 if (cfg
->libbasetype
== NULL
&& libbasetypeextern
!= NULL
)
1193 cfg
->libbasetype
= strdup(libbasetypeextern
);
1194 if (cfg
->sysbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1195 exitfileerror(20, "sysbase_field specified when no libbasetype is given\n");
1196 if (cfg
->seglist_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1197 exitfileerror(20, "seglist_field specified when no libbasetype is given\n");
1198 if (cfg
->oopbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1199 exitfileerror(20, "oopbase_field specified when no libbasetype is given\n");
1200 /* rootbase_field only allowed when duplicating base */
1201 if (cfg
->rootbase_field
!= NULL
&& !(cfg
->options
& OPTION_DUPBASE
))
1202 exitfileerror(20, "rootbasefield only valid for option peropenerbase or pertaskbase\n");
1204 /* Set default date to current date */
1205 if (cfg
->datestring
== NULL
)
1208 time_t now
= time(NULL
);
1209 struct tm
*ltime
= localtime(&now
);
1211 snprintf(tmpbuf
, sizeof(tmpbuf
), "%u.%u.%u",
1212 ltime
->tm_mday
, 1 + ltime
->tm_mon
, 1900 + ltime
->tm_year
);
1214 cfg
->datestring
= strdup(tmpbuf
);
1217 if (cfg
->copyright
== NULL
)
1218 cfg
->copyright
= "";
1220 if ( (cfg
->beginiofunc
!= NULL
&& cfg
->abortiofunc
== NULL
)
1221 || (cfg
->beginiofunc
== NULL
&& cfg
->abortiofunc
!= NULL
)
1223 exitfileerror(20, "please specify both beginio_func and abortio_func\n");
1225 if (libbasetypeextern
==NULL
)
1227 switch (cfg
->modtype
)
1230 cfg
->libbasetypeptrextern
= "struct Device *";
1234 cfg
->libbasetypeptrextern
= "APTR ";
1244 cfg
->libbasetypeptrextern
= "struct Library *";
1247 fprintf(stderr
, "Internal error: Unsupported modtype for libbasetypeptrextern\n");
1253 cfg
->libbasetypeptrextern
= malloc(strlen(libbasetypeextern
)+3);
1254 strcpy(cfg
->libbasetypeptrextern
, libbasetypeextern
);
1255 strcat(cfg
->libbasetypeptrextern
, " *");
1256 free(libbasetypeextern
);
1259 if (cfg
->includename
== NULL
)
1260 cfg
->includename
= cfg
->modulename
;
1261 cfg
->includenameupper
= strdup(cfg
->includename
);
1262 for (s
=cfg
->includenameupper
; *s
!='\0'; *s
= toupper(*s
), s
++)
1263 if (!isalnum(*s
)) *s
= '_';
1266 /* When class was given too fill in some defaults when not specified */
1269 if (cl
->classtype
== UNSPECIFIED
)
1270 cl
->classtype
= CLASS
;
1272 if (cl
->basename
== NULL
)
1275 cl
->basename
= cfg
->basename
;
1277 exitfileerror(20, "basename has to be specified in the config section inside of a class section\n");
1280 /* MUI classes are always private */
1281 if (cl
->classtype
== MUI
|| cl
->classtype
== MCC
|| cl
->classtype
== MCP
)
1282 cl
->options
|= COPTION_PRIVATE
;
1284 if (cl
->classid
== NULL
1285 && (cl
->classtype
!= MUI
&& cl
->classtype
!= MCC
&& cl
->classtype
!= MCP
)
1288 if (cl
->classtype
== HIDD
)
1290 cl
->options
&= !COPTION_PRIVATE
;
1292 else if (cl
->options
& COPTION_PRIVATE
)
1294 cl
->classid
= "NULL";
1300 if (cl
->classtype
== GADGET
|| cl
->classtype
== IMAGE
|| cl
->classtype
== CLASS
|| cl
->classtype
== USBCLASS
)
1302 sprintf(s
, "\"%sclass\"", inclass
? cl
->basename
: cfg
->modulename
);
1304 else if (cl
->classtype
== DATATYPE
)
1306 sprintf(s
, "\"%s.datatype\"", inclass
? cl
->basename
: cfg
->modulename
);
1308 cl
->classid
= strdup(s
);
1312 /* Only specify superclass or superclass_field */
1313 if (cl
->superclass
!= NULL
&& cl
->superclass_field
!= NULL
)
1314 exitfileerror(20, "Only specify one of superclass or superclass_field in config section\n");
1316 /* Give default value to superclass if it is not specified */
1317 if (cl
->superclass
== NULL
&& cl
->superclass
== NULL
)
1319 switch (cl
->classtype
)
1323 cl
->superclass
= "MUIC_Area";
1326 cl
->superclass
= "MUIC_Mccprefs";
1329 cl
->superclass
= "IMAGECLASS";
1332 cl
->superclass
= "GADGETCLASS";
1335 cl
->superclass
= "DATATYPESCLASS";
1338 cl
->superclass
= "ROOTCLASS";
1341 cl
->superclass
= "CLID_Root";
1344 exitfileerror(20, "Internal error: unhandled classtype in readsectionconfig\n");
1351 static void readsectioncdef(struct config
*cfg
)
1360 exitfileerror(20, "unexptected end of file in section cdef\n");
1362 if (strncmp(line
, "##", 2)!=0)
1364 slist_append(&cfg
->cdeflines
, line
);
1369 while (isspace(*s
)) s
++;
1370 if (strncmp(s
, "end", 3)!=0)
1371 exitfileerror(20, "\"##end cdef\" expected\n");
1374 while (isspace(*s
)) s
++;
1375 if (strncmp(s
, "cdef", 4)!=0)
1376 exitfileerror(20, "\"##end cdef\" expected\n");
1379 while (isspace(*s
)) s
++;
1381 exitfileerror(20, "unexpected character at position %d\n");
1388 static void readsectioncdefprivate(struct config
*cfg
)
1397 exitfileerror(20, "unexptected end of file in section cdef\n");
1399 if (strncmp(line
, "##", 2)!=0)
1401 slist_append(&cfg
->cdefprivatelines
, line
);
1406 while (isspace(*s
)) s
++;
1407 if (strncmp(s
, "end", 3)!=0)
1408 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1411 while (isspace(*s
)) s
++;
1412 if (strncmp(s
, "cdefprivate", 11)!=0)
1413 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1416 while (isspace(*s
)) s
++;
1418 exitfileerror(20, "unexpected character at position %d\n");
1425 static void readsectionstartup(struct config
*cfg
)
1434 exitfileerror(20, "unexptected end of file in section startup\n");
1436 if (strncmp(line
, "##", 2)!=0)
1438 slist_append(&cfg
->startuplines
, line
);
1443 while (isspace(*s
)) s
++;
1444 if (strncmp(s
, "end", 3)!=0)
1445 exitfileerror(20, "\"##end startup\" expected\n");
1448 while (isspace(*s
)) s
++;
1449 if (strncmp(s
, "startup", 7)!=0)
1450 exitfileerror(20, "\"##end startup\" expected\n");
1453 while (isspace(*s
)) s
++;
1455 exitfileerror(20, "unexpected character at position %d\n");
1462 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
, enum libcall def_libcall
)
1465 char *line
, *s
, *s2
;
1466 unsigned int lvo
= firstlvo
;
1467 int minversion
= -1;
1473 exitfileerror(20, "unexpected EOF in functionlist section\n");
1474 if (strlen(line
)==0)
1476 if (*funclistptr
!= NULL
)
1477 funclistptr
= &((*funclistptr
)->next
);
1480 else if (isspace(*line
))
1483 while (isspace(*s
)) s
++;
1486 if (*funclistptr
!= NULL
)
1487 funclistptr
= &((*funclistptr
)->next
);
1491 exitfileerror(20, "no space allowed before functionname\n");
1493 else if (strncmp(line
, "##", 2)==0)
1496 while (isspace(*s
)) s
++;
1497 if (strncmp(s
, "end", 3)!=0)
1498 exitfileerror(20, "\"##end %s\" expected\n", type
);
1501 while (isspace(*s
)) s
++;
1502 if (strncmp(s
, type
, strlen(type
))!=0)
1503 exitfileerror(20, "\"##end %s\" expected\n", type
);
1506 while (isspace(*s
)) s
++;
1508 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1512 else if (*line
=='.')
1515 if (strncmp(s
, "skip", 4)==0)
1521 exitfileerror(20, "syntax is '.skip n'\n");
1523 n
=strtol(s
, &s2
, 10);
1525 exitfileerror(20, "positive number expected\n");
1527 while (isspace(*s2
)) s2
++;
1528 if ((*s2
!= '\0') && (*s2
!= '#'))
1529 exitfileerror(20, "syntax is '.skip n'\n");
1530 if (*funclistptr
!= NULL
)
1531 funclistptr
= &((*funclistptr
)->next
);
1534 else if (strncmp(s
, "alias", 5)==0)
1539 exitfileerror(20, "syntax is '.alias name'\n");
1541 while (isspace(*s
)) s
++;
1542 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1543 exitfileerror(20, "syntax is '.alias name'\n");
1547 while (isalnum(*s
) || *s
== '_') s
++;
1554 } while (isspace(*s
));
1558 exitfileerror(20, "syntax is '.alias name'\n");
1560 if (*funclistptr
== NULL
)
1561 exitfileerror(20, ".alias has to come after a function declaration\n");
1563 slist_append(&(*funclistptr
)->aliases
, s2
);
1565 else if (strncmp(s
, "function", 8) == 0)
1570 exitfileerror(20, "Syntax error\n");
1572 while (isspace(*s
)) s
++;
1573 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1574 exitfileerror(20, "syntax is '.function name'\n");
1578 while (isalnum(*s
) || *s
== '_') s
++;
1585 } while (isspace(*s
));
1589 exitfileerror(20, "syntax is '.function name'\n");
1591 if (*funclistptr
== NULL
)
1592 exitfileerror(20, ".function has to come after a function declaration\n");
1594 funcsetinternalname(*funclistptr
, s2
);
1596 else if (strncmp(s
, "cfunction", 9)==0)
1598 if (*funclistptr
== NULL
)
1599 exitfileerror(20, ".cfunction has to come after a function declaration\n");
1601 (*funclistptr
)->libcall
= REGISTER
;
1603 else if (strncmp(s
, "private", 7)==0)
1605 if (*funclistptr
== NULL
)
1606 exitfileerror(20, ".private has to come after a function declaration\n");
1608 (*funclistptr
)->priv
= 1;
1610 else if (strncmp(s
, "novararg", 8)==0)
1612 if (*funclistptr
== NULL
)
1613 exitfileerror(20, ".novararg has to come after a function declaration\n");
1615 (*funclistptr
)->novararg
= 1;
1617 else if (strncmp(s
, "version", 7) == 0)
1619 /* Mark version number for the following
1620 * functions, so that the automatic OpenLibrary()
1621 * will know what version to use.
1628 while (isspace(*s
)) s
++;
1629 ver
= (int)strtol(s
, &tmp
, 0);
1632 exitfileerror(20, ".version expects an integer\n");
1635 while (isspace(*s
)) s
++;
1637 if (*s
&& *s
!= '#')
1638 exitfileerror(20, ".version has junk after the version number\n");
1642 else if (strncmp(s
, "unusedlibbase", 13) == 0)
1644 if (*funclistptr
== NULL
)
1645 exitfileerror(20, ".unusedlibbase has to come after a function declaration\n");
1646 (*funclistptr
)->unusedlibbase
= 1;
1649 exitfileerror(20, "Syntax error");
1651 else if (*line
!='#') /* Ignore line that is a comment, e.g. that starts with a # */
1653 /* The line is a function or attribute prototype.
1654 * A function can have one of two syntaxes:
1655 * type funcname(argproto1, argproto2, ...)
1656 * type funcname(argproto1, argproto2, ...) (reg1, reg2, ...)
1657 * The former is for C type function argument passing, the latter for
1658 * register argument passing.
1659 * An attribute has the following syntax:
1662 char c
, *args
[64], *regs
[64], *funcname
, *cp
;
1663 int len
, argcount
= 0, regcount
= 0, brcount
= 0;
1665 cp
= strchr(line
,'#');
1669 /* Parse 'type functionname' at the beginning of the line */
1671 s
= line
+ strlen(line
);
1673 s
= strchr(line
, '(');
1675 exitfileerror(20, "( expected at position %d\n", strlen(line
) + 1);
1679 while (isspace(*(s2
-1)))
1683 while (s2
> line
&& !isspace(*(s2
-1)) && !(*(s2
-1) == '*'))
1687 exitfileerror(20, "No type specifier before %s name\n", isattribute
? "attribute" : "function");
1689 if (*funclistptr
!= NULL
)
1690 funclistptr
= &((*funclistptr
)->next
);
1691 *funclistptr
= newfunctionhead(s2
, STACK
);
1694 (*funclistptr
)->comment
= strdup(cp
);
1696 (*funclistptr
)->comment
= NULL
;
1698 while (isspace(*(s2
-1)))
1701 (*funclistptr
)->type
= strdup(line
);
1702 (*funclistptr
)->lvo
= lvo
;
1703 (*funclistptr
)->version
= minversion
;
1709 /* Parse function prototype */
1726 && !(brcount
== 0 && (*s
== ',' || *s
== ')'))
1736 exitfileerror(20, "Unexected ')' at position %d\n", s
-line
+1);
1743 exitfileerror(20, "'(' without ')'");
1746 while (isspace(*(s2
-1)))
1750 if (!(s2
> args
[argcount
- 1]))
1751 exitfileerror(20, "Syntax error in function prototype\n");
1757 while (*s
!= '\0' && isspace(*s
))
1762 /* Parse registers specifications if available otherwise this prototype for C type argument passing */
1764 /* There may be no register specified with () so be sure then c is == ')' */
1779 if (memchr("AD",s
[0],2)!=NULL
&& memchr("01234567",s
[1],8)!=NULL
)
1786 if (s
[0] == s
[-3] && s
[1] == s
[-2] + 1)
1793 "wrong register specification \"%s\" for argument %u\n",
1794 regs
[regcount
-1], regcount
1798 exitfileerror(20, "maximum four arguments passed in two registers allowed (%d, %s) \n", regcount
, regs
[regcount
-1]);
1804 "wrong register \"%s\" for argument %u\n",
1805 regs
[regcount
-1], regcount
1814 exitfileerror(20, "'(' without ')'\n");
1815 if (c
!= ',' && c
!= ')')
1816 exitfileerror(20, "',' or ')' expected at position %d\n", s
-line
+1);
1822 while (isspace(*s
)) s
++;
1824 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1826 if (argcount
!= regcount
)
1827 exitfileerror(20, "Number of arguments (%d) and registers (%d) mismatch\n",
1831 (*funclistptr
)->libcall
= def_libcall
;
1832 for (i
= 0; i
< argcount
; i
++)
1833 funcaddarg(*funclistptr
, args
[i
], regs
[i
]);
1835 else if (*s
== '\0')
1836 { /* No registers specified */
1837 for (i
= 0; i
< argcount
; i
++)
1838 funcaddarg(*funclistptr
, args
[i
], NULL
);
1841 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1846 static void readsectionclass_methodlist(struct classinfo
*cl
)
1849 char *line
, *s
, *s2
;
1850 struct functionhead
**methlistptr
= &cl
->methlist
;
1851 struct stringlist
*interface
= NULL
;
1853 if (cl
->basename
==NULL
)
1854 exitfileerror(20, "section methodlist has to come after section config\n");
1860 exitfileerror(20, "unexptected EOF in methodlist section\n");
1862 /* Ignore empty lines or lines that qre a comment, e.g. that starts with a # */
1863 if (strlen(line
)==0 || (line
[0] == '#' && line
[1] != '#'))
1867 exitfileerror(20, "No space allowed at start of the line\n");
1869 if (strncmp(line
, "##", 2)==0) /* Is this the end ? */
1872 while (isspace(*s
)) s
++;
1873 if (strncmp(s
, "end", 3)!=0)
1874 exitfileerror(20, "\"##end methodlist\" expected\n");
1877 while (isspace(*s
)) s
++;
1878 if (strncmp(s
, "methodlist", 10)!=0)
1879 exitfileerror(20, "\"##end methodlist\" expected\n");
1882 while (isspace(*s
)) s
++;
1884 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1894 if (strncmp(s
, "alias", 5)==0)
1899 exitfileerror(20, "syntax is '.alias name'\n");
1901 while (isspace(*s
)) s
++;
1902 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1903 exitfileerror(20, "syntax is '.alias name'\n");
1907 while (isalnum(*s
) || *s
== '_') s
++;
1914 } while (isspace(*s
));
1918 exitfileerror(20, "syntax is '.alias name'\n");
1920 if (*methlistptr
== NULL
)
1921 exitfileerror(20, ".alias has to come after a function declaration\n");
1923 slist_append(&(*methlistptr
)->aliases
, s2
);
1925 else if (strncmp(s
, "function", 8) == 0)
1930 exitfileerror(20, "Syntax error\n");
1932 while (isspace(*s
)) s
++;
1933 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1934 exitfileerror(20, "syntax is '.function name'\n");
1938 while (isalnum(*s
) || *s
== '_') s
++;
1945 } while (isspace(*s
));
1949 exitfileerror(20, "syntax is '.function name'\n");
1951 if (*methlistptr
== NULL
)
1952 exitfileerror(20, ".function has to come after a function declaration\n");
1954 funcsetinternalname(*methlistptr
, s2
);
1956 else if (strncmp(s
, "interface", 9) == 0)
1958 if (cl
->classtype
!= HIDD
)
1959 exitfileerror(20, "interface only valid for a HIDD\n");
1964 exitfileerror(20, "Syntax error\n");
1966 while (isspace(*s
)) s
++;
1967 if (*s
== '\0' || !isalpha(*s
))
1968 exitfileerror(20, "syntax is '.interface name'\n");
1972 while (isalnum(*s
) || *s
== '_') s
++;
1979 } while (isspace(*s
));
1983 exitfileerror(20, "syntax is '.interface name'\n");
1985 interface
= slist_append(&cl
->interfaces
, s2
);
1988 exitfileerror(20, "Syntax error");
1990 else if (isalpha(*line
))
1994 for (s
= line
+ 1; isalnum(*s
) || *s
== '_'; s
++)
1997 if (cl
->classtype
== HIDD
&& interface
== NULL
)
1998 exitfileerror(20, "For a HIDD the first method has to come after an .interface line\n");
2001 exitfileerror(20, "Only letters, digits and an underscore allowed in a methodname\n");
2003 if (*methlistptr
!= NULL
)
2004 methlistptr
= &((*methlistptr
)->next
);
2005 if (cl
->classtype
!= HIDD
)
2007 if (snprintf(stmp
, 256, "%s__%s", cl
->basename
, line
) >= 256)
2008 exitfileerror(20, "Method name too large\n");
2010 *methlistptr
= newfunctionhead(stmp
, STACK
);
2011 (*methlistptr
)->type
= "IPTR";
2012 funcaddarg(*methlistptr
, "Class *cl", NULL
);
2013 funcaddarg(*methlistptr
, "Object *o", NULL
);
2014 funcaddarg(*methlistptr
, "Msg msg", NULL
);
2018 if (snprintf(stmp
, 256, "%s__%s__%s", cl
->basename
, interface
->s
, line
) >= 256)
2019 exitfileerror(20, "Method name too large\n");
2021 *methlistptr
= newfunctionhead(stmp
, STACK
);
2022 (*methlistptr
)->type
= "IPTR";
2023 funcaddarg(*methlistptr
, "OOP_Class *cl", NULL
);
2024 funcaddarg(*methlistptr
, "OOP_Object *o", NULL
);
2025 funcaddarg(*methlistptr
, "OOP_Msg msg", NULL
);
2026 (*methlistptr
)->interface
= interface
;
2027 if (snprintf(stmp
, 256, "mo%s_%s", interface
->s
, line
) >= 256)
2028 exitfileerror(20, "Method name too large\n");
2029 (*methlistptr
)->method
= strdup(stmp
);
2031 slist_append(&(*methlistptr
)->aliases
, line
);
2034 exitfileerror(20, "Methodname has to begin with a letter\n");
2039 readsectioninterface(struct config
*cfg
)
2042 struct interfaceinfo
*in
;
2044 in
= newinterface(cfg
);
2045 s
= readsections(cfg
, NULL
, in
, 1);
2047 exitfileerror(20, "Unexpected end of file\n");
2049 if (strncmp(s
, "##", 2) != 0)
2050 exitfileerror(20, "'##end interface' expected\n");
2053 while (isspace(*s
)) s
++;
2055 if (strncmp(s
, "end", 3) != 0)
2056 exitfileerror(20, "'##end interface' expected\n");
2060 exitfileerror(20, "'##end interface' expected\n");
2061 while (isspace(*s
)) s
++;
2063 if (strncmp(s
, "interface", 9) != 0)
2064 exitfileerror(20, "'##end interface' expected\n");
2067 while (isspace(*s
)) s
++;
2069 exitfileerror(20, "'##end interface' expected\n");
2071 if (!in
->interfaceid
)
2072 exitfileerror(20, "interface has no 'interfaceid' defined!\n");
2074 if (!in
->interfacename
)
2075 exitfileerror(20, "interface has no 'interfacename' defined!\n");
2077 if (!in
->methodstub
)
2078 in
->methodstub
= strdup(in
->interfacename
);
2080 if (!in
->methodbase
) {
2081 int len
= strlen(in
->interfacename
);
2082 in
->methodbase
= malloc(len
+ 4 + 1);
2083 strcpy(in
->methodbase
, in
->interfacename
);
2084 strcat(in
->methodbase
, "Base");
2087 if (!in
->attributebase
) {
2088 int len
= strlen(in
->interfacename
);
2089 in
->attributebase
= malloc(len
+ 4 + 4 + 1);
2090 strcpy(in
->attributebase
, in
->interfacename
);
2091 strcat(in
->attributebase
, "AttrBase");
2096 readsectionclass(struct config
*cfg
)
2099 struct classinfo
*cl
;
2102 s
= readsections(cfg
, cl
, NULL
, 1);
2104 exitfileerror(20, "Unexpected end of file\n");
2106 if (strncmp(s
, "##", 2) != 0)
2107 exitfileerror(20, "'##end class' expected\n");
2110 while (isspace(*s
)) s
++;
2112 if (strncmp(s
, "end", 3) != 0)
2113 exitfileerror(20, "'##end class' expected\n");
2117 exitfileerror(20, "'##end class' expected\n");
2118 while (isspace(*s
)) s
++;
2120 if (strncmp(s
, "class", 5) != 0)
2121 exitfileerror(20, "'##end class' expected\n");
2124 while (isspace(*s
)) s
++;
2126 exitfileerror(20, "'##end class' expected\n");
2129 static struct classinfo
*newclass(struct config
*cfg
)
2131 struct classinfo
*cl
, *classlistit
;
2133 cl
= malloc(sizeof(struct classinfo
));
2136 fprintf(stderr
, "Out of memory\n");
2139 memset(cl
, 0, sizeof(struct classinfo
));
2141 /* By default the classes are initialized with a priority of 1 so they
2142 * are initialized before any user added initialization with priority 1
2146 if (cfg
->classlist
== NULL
)
2147 cfg
->classlist
= cl
;
2152 classlistit
= cfg
->classlist
;
2153 classlistit
->next
!= NULL
;
2154 classlistit
= classlistit
->next
2157 classlistit
->next
= cl
;
2163 static struct handlerinfo
*newhandler(struct config
*cfg
)
2165 struct handlerinfo
*hl
;
2167 hl
= calloc(1,sizeof(*hl
));
2168 hl
->next
= cfg
->handlerlist
;
2169 cfg
->handlerlist
= hl
;
2173 static struct interfaceinfo
*newinterface(struct config
*cfg
)
2175 struct interfaceinfo
*in
, *interfacelistit
;
2177 in
= malloc(sizeof(struct interfaceinfo
));
2180 fprintf(stderr
, "Out of memory\n");
2183 memset(in
, 0, sizeof(struct interfaceinfo
));
2185 if (cfg
->interfacelist
== NULL
)
2186 cfg
->interfacelist
= in
;
2191 interfacelistit
= cfg
->interfacelist
;
2192 interfacelistit
->next
!= NULL
;
2193 interfacelistit
= interfacelistit
->next
2196 interfacelistit
->next
= in
;
2203 static int getdirective(char *s
, const char *directive
, int range_min
, int range_max
, int *val
)
2208 if (strncmp(s
, directive
, strlen(directive
)) != 0)
2211 s
+= strlen(directive
);
2212 if (*s
&& !isspace(*s
))
2213 exitfileerror(20, "Unrecognized directive \".%s\"\n", directive
);
2215 while (isspace(*s
)) s
++;
2217 exitfileerror(20, "No .%s value specified\n", directive
);
2219 newval
= strtol(s
, &tmp
, 0);
2220 if (s
== tmp
|| !(newval
>= range_min
&& newval
<= range_max
)) {
2222 while (*tmp
&& !isspace(*tmp
)) tmp
++;
2223 exitfileerror(20, "Invalid .%s value of %.*s\n", directive
, tmp
- s
, s
);
2231 readsectionhandler(struct config
*cfg
)
2233 char *line
= NULL
, *s
;
2234 struct handlerinfo
*hl
;
2235 unsigned char autolevel
= 0;
2236 unsigned int stacksize
= 0;
2240 int has_filesystem
= 0;
2248 s
= line
= readline();
2251 exitfileerror(20, "unexpected end of file in section hanlder\n");
2253 if (strncmp(s
, "##", 2)==0)
2256 /* Ignore comments */
2257 if (strncmp(s
, "#", 1)==0)
2260 /* Skip ahead to function name */
2261 while (*s
&& isspace(*s
)) s
++;
2263 /* Permit blank lines */
2271 if (getdirective(s
, "autodetect", 0, 127, &val
)) {
2273 } else if (getdirective(s
, "stacksize", 0, INT_MAX
, &val
)) {
2275 } else if (getdirective(s
, "priority", -128, 127, &val
)) {
2277 } else if (getdirective(s
, "bootpri", -128, 127, &val
)) {
2279 } else if (getdirective(s
, "startup", INT_MIN
, INT_MAX
, &val
)) {
2282 exitfileerror(20, "Unrecognized directive \"%s\"\n", line
);
2288 unsigned int id
= 0;
2290 if (strncasecmp(s
,"resident=",9)==0) {
2293 s
= strchr(s
, '=') + 1;
2295 while (*s
&& !isspace(*s
)) s
++;
2297 exitfileerror(20, "Empty resident= is not permitted\n");
2302 hl
= newhandler(cfg
);
2303 hl
->type
= HANDLER_RESIDENT
;
2305 hl
->name
= strdup(res
);
2306 hl
->autodetect
= autolevel
--;
2307 hl
->stacksize
= stacksize
;
2308 hl
->priority
= priority
;
2309 hl
->startup
= startup
;
2310 } else if (strncasecmp(s
,"dosnode=",8)==0) {
2313 s
= strchr(s
, '=') + 1;
2315 while (*s
&& !isspace(*s
)) s
++;
2317 exitfileerror(20, "Empty dosnode= is not permitted\n");
2322 hl
= newhandler(cfg
);
2323 hl
->type
= HANDLER_DOSNODE
;
2325 hl
->name
= strdup(dev
);
2326 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2327 hl
->stacksize
= stacksize
;
2328 hl
->priority
= priority
;
2329 hl
->startup
= startup
;
2330 hl
->bootpri
= bootpri
;
2331 } else if (strncasecmp(s
,"dostype=",8) == 0) {
2332 s
= strchr(s
, '=') + 1;
2334 id
= (unsigned int)strtoul(s
, &tmp
, 0);
2337 while (*tmp
&& !isspace(*tmp
))
2339 exitfileerror(20, "\"%.*s\" is not a numerical DOS ID\n", (tmp
-s
), s
);
2343 if (id
== 0 || id
== ~0) {
2344 exitfileerror(20, "DOS ID 0x%08x is not permitted\n", id
);
2347 hl
= newhandler(cfg
);
2348 hl
->type
= HANDLER_DOSTYPE
;
2351 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2352 hl
->stacksize
= stacksize
;
2353 hl
->priority
= priority
;
2354 hl
->startup
= startup
;
2356 for (tmp
= s
; !isspace(*tmp
); tmp
++);
2357 exitfileerror(20, "Unknown option \"%.*s\"\n", tmp
- s
, s
);
2360 /* Advance to next ID */
2361 while (*s
&& isspace(*s
)) s
++;
2367 exitfileerror(20, "Unexpected end of file\n");
2369 if (strncmp(s
, "##", 2) != 0)
2370 exitfileerror(20, "'##end handler' expected\n");
2373 while (isspace(*s
)) s
++;
2375 if (strncmp(s
, "end", 3) != 0)
2376 exitfileerror(20, "'##end handler' expected\n");
2379 while (isspace(*s
)) s
++;
2381 if (strncmp(s
, "handler", 7) != 0)
2382 exitfileerror(20, "'##end handler' expected\n");
2385 while (isspace(*s
)) s
++;
2387 exitfileerror(20, "'##end handler' expected\n");