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 /* Verify that a handler has a handler */
330 if (cfg
->modtype
== HANDLER
) {
331 if (cfg
->handlerfunc
== NULL
) {
332 fprintf(stderr
, "handler modules require a 'handler_func' ##config option\n");
335 cfg
->options
|= OPTION_NOAUTOLIB
| OPTION_NOEXPUNGE
| OPTION_NOOPENCLOSE
;
341 /* Functions to read configuration from the configuration file */
343 #include "fileread.h"
345 static char *readsections(struct config
*, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
);
346 static void readsectionconfig(struct config
*, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
);
347 static void readsectioncdef(struct config
*);
348 static void readsectioncdefprivate(struct config
*);
349 static void readsectionstartup(struct config
*);
350 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
, enum libcall def_libcall
);
351 static void readsectionclass_methodlist(struct classinfo
*);
352 static void readsectionclass(struct config
*);
353 static void readsectionhandler(struct config
*);
354 static void readsectioninterface(struct config
*);
356 static void readconfig(struct config
*cfg
)
358 struct classinfo
*mainclass
= NULL
;
360 /* Create a classinfo structure if this module is a class */
361 switch (cfg
->modtype
)
376 mainclass
= newclass(cfg
);
377 mainclass
->classtype
= cfg
->modtype
;
381 fprintf(stderr
, "Internal error: unsupported modtype for classinfo creation\n");
385 switch (cfg
->modtype
)
398 mainclass
->boopsimprefix
= muimprefix
;
406 mainclass
->boopsimprefix
= gadgetmprefix
;
410 mainclass
->boopsimprefix
= dtmprefix
;
414 /* FIXME: need boopsimprefix ? */
417 fprintf(stderr
, "Internal error: unsupported modtype for firstlvo\n");
421 if (!fileopen(cfg
->conffile
))
423 fprintf(stderr
, "In readconfig: Could not open %s\n", cfg
->conffile
);
427 /* Read all sections and see that we are at the end of the file */
428 if (readsections(cfg
, mainclass
, NULL
, 0) != NULL
)
429 exitfileerror(20, "Syntax error");
434 /* readsections will scan through all the sections in the config file.
436 * struct config *cfg: The module config data which may be updated by
437 * the information in the sections
438 * struct classinfo *cl: The classdata to be filled with data from the sections.
439 * This may be NULL if this is the main part of the configuration file and the
440 * type of the module is not a class
441 * int inclass: Boolean to indicate if we are in a class part. If not we are in the main
442 * part of the config file.
444 static char *readsections(struct config
*cfg
, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
)
449 while ((line
=readline())!=NULL
)
451 if (strncmp(line
, "##", 2)==0)
453 static char *parts
[] =
455 "config", "cdefprivate", "cdef", "startup", "functionlist", "methodlist", "class", "handler", "interface", "attributelist", "cfunctionlist"
457 const unsigned int nums
= sizeof(parts
)/sizeof(char *);
458 unsigned int partnum
;
462 while (isspace(*s
)) s
++;
464 if (strncmp(s
, "begin", 5)!=0)
469 exitfileerror(20, "space after begin expected\n");
470 while (isspace(*s
)) s
++;
472 for (i
= 0, partnum
= 0; partnum
==0 && i
<nums
; i
++)
474 if (strncmp(s
, parts
[i
], strlen(parts
[i
]))==0)
477 s
+= strlen(parts
[i
]);
478 while (isspace(*s
)) s
++;
480 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
484 exitfileerror(20, "unknown start of section\n");
488 readsectionconfig(cfg
, cl
, in
, inclass
);
492 case 2: /* cdefprivate */
494 exitfileerror(20, "cdefprivate section not allowed in class section\n");
495 readsectioncdefprivate(cfg
);
500 exitfileerror(20, "cdef section not allowed in class section\n");
501 readsectioncdef(cfg
);
504 case 4: /* startup */
506 exitfileerror(20, "startup section not allowed in class section\n");
507 readsectionstartup(cfg
);
510 case 5: /* functionlist */
512 exitfileerror(20, "functionlist section not allow in class section\n");
513 if (cfg
->basename
==NULL
)
514 exitfileerror(20, "section functionlist has to come after section config\n");
516 readsectionfunctionlist("functionlist", &cfg
->funclist
, cfg
->firstlvo
, 0, REGISTERMACRO
);
517 cfg
->intcfg
|= CFG_NOREADFUNCS
;
520 case 6: /* methodlist */
521 if (cl
== NULL
&& in
== NULL
)
522 exitfileerror(20, "methodlist section when not in a class or interface\n");
524 readsectionclass_methodlist(cl
);
526 readsectionfunctionlist("methodlist", &in
->methodlist
, 0, 0, REGISTERMACRO
);
527 cfg
->intcfg
|= CFG_NOREADFUNCS
;
532 exitfileerror(20, "class section may not be in nested\n");
533 readsectionclass(cfg
);
535 case 8: /* handler */
536 readsectionhandler(cfg
);
538 case 9: /* interface */
540 exitfileerror(20, "interface section may not be nested\n");
541 readsectioninterface(cfg
);
543 case 10: /* attributelist */
545 exitfileerror(20, "attributelist only valid in interface sections\n");
546 readsectionfunctionlist("attributelist", &in
->attributelist
, 0, 1, INVALID
);
548 case 11: /* cfunctionlist */
550 exitfileerror(20, "cfunctionlist section not allow in class section\n");
551 if (cfg
->basename
==NULL
)
552 exitfileerror(20, "section cfunctionlist has to come after section config\n");
554 readsectionfunctionlist("cfunctionlist", &cfg
->funclist
, cfg
->firstlvo
, 0, REGISTER
);
555 cfg
->intcfg
|= CFG_NOREADFUNCS
;
559 else if (strlen(line
)!=0)
560 filewarning("warning line outside section ignored\n");
566 exitfileerror(20, "No config section in conffile\n");
568 /* If no indication was given for generating includes or not
569 decide on module type and if there are functions
571 if(!((cfg
->options
& OPTION_INCLUDES
) || (cfg
->options
& OPTION_NOINCLUDES
)))
573 switch (cfg
->modtype
)
577 cfg
->options
|= OPTION_INCLUDES
;
585 cfg
->options
|= OPTION_NOINCLUDES
;
590 (cfg
->funclist
!= NULL
)
591 || (cfg
->cdeflines
!= NULL
)
592 || strcmp(cfg
->libbasetypeptrextern
, "struct Device *") != 0
593 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
600 (cfg
->funclist
!= NULL
)
601 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
605 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for includes\n");
611 /* If no indication was given for not generating stubs only generate them if
612 * the module has functions
614 if(!((cfg
->options
& OPTION_STUBS
) || (cfg
->options
& OPTION_NOSTUBS
)))
616 switch (cfg
->modtype
)
619 cfg
->options
|= (cfg
->funclist
!= NULL
) ? OPTION_STUBS
: OPTION_NOSTUBS
;
632 cfg
->options
|= OPTION_NOSTUBS
;
636 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for stubs\n");
642 /* If no indication was given for generating autoinit code or not
643 decide on module type
645 if(!((cfg
->options
& OPTION_AUTOINIT
) || (cfg
->options
& OPTION_NOAUTOINIT
)))
647 switch (cfg
->modtype
)
650 cfg
->options
|= OPTION_AUTOINIT
;
663 cfg
->options
|= OPTION_NOAUTOINIT
;
667 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for autoinit\n");
673 if ((cfg
->modtype
== RESOURCE
) || (cfg
->modtype
== HANDLER
))
674 /* Enforce noopenclose for resources and handlers */
675 cfg
->options
|= OPTION_NOOPENCLOSE
;
676 else if (!(cfg
->options
& OPTION_SELFINIT
))
677 /* Enforce using RTF_AUTOINIT for everything except resources */
678 cfg
->options
|= OPTION_RESAUTOINIT
;
684 static void readsectionconfig(struct config
*cfg
, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
)
687 char *line
, *s
, *s2
, *libbasetypeextern
= NULL
;
694 exitfileerror(20, "unexpected end of file in section config\n");
696 if (strncmp(line
, "##", 2)!=0)
698 const char *names
[] =
700 "basename", "libbase", "libbasetype", "libbasetypeextern",
701 "version", "date", "copyright", "libcall", "forcebase", "superclass",
702 "superclass_field", "residentpri", "options", "sysbase_field",
703 "seglist_field", "rootbase_field", "classptr_field", "classptr_var",
704 "classid", "classdatatype", "beginio_func", "abortio_func", "dispatcher",
705 "initpri", "type", "addromtag", "oopbase_field",
706 "rellib", "interfaceid", "interfacename",
707 "methodstub", "methodbase", "attributebase", "handler_func"
709 const unsigned int namenums
= sizeof(names
)/sizeof(char *);
710 unsigned int namenum
;
712 for (i
= 0, namenum
= 0; namenum
==0 && i
<namenums
; i
++)
716 strncmp(line
, names
[i
], strlen(names
[i
]))==0
717 && isspace(*(line
+strlen(names
[i
])))
722 exitfileerror(20, "unrecognized configuration option\n");
724 s
= line
+ strlen(names
[namenum
-1]);
726 exitfileerror(20, "space character expected after \"%s\"\n", names
[namenum
-1]);
728 while (isspace(*s
)) s
++;
730 exitfileerror(20, "unexpected end of line\n");
733 while (isspace(*(s2
-1))) s2
--;
738 case 1: /* basename */
740 cfg
->basename
= strdup(s
);
742 cl
->basename
= strdup(s
);
744 exitfileerror(20, "basename not valid config option when in a interface section\n");
747 case 2: /* libbase */
749 exitfileerror(20, "libbase not valid config option when in a class section\n");
750 cfg
->libbase
= strdup(s
);
753 case 3: /* libbasetype */
755 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
756 cfg
->libbasetype
= strdup(s
);
759 case 4: /* libbasetypeextern */
761 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
762 libbasetypeextern
= strdup(s
);
765 case 5: /* version */
767 exitfileerror(20, "version not valid config option when in a class section\n");
768 if (sscanf(s
, "%u.%u", &cfg
->majorversion
, &cfg
->minorversion
)!=2)
769 exitfileerror(20, "wrong version string \"%s\"\n", s
);
774 exitfileerror(20, "date not valid config option when in a class section\n");
776 if (strptime(s
, "%e.%m.%Y", &date
) == NULL
)
778 exitfileerror(20, "date string has to have d.m.yyyy format\n");
781 cfg
->datestring
= strdup(s
);
784 case 7: /* copyright */
786 exitfileerror(20, "copyright not valid config option when in a class section\n");
787 cfg
->copyright
= strdup(s
);
790 case 8: /* libcall */
791 fprintf(stderr
, "libcall specification is deprecated and ignored\n");
794 case 9: /* forcebase */
796 exitfileerror(20, "forcebase not valid config option when in a class section\n");
797 slist_append(&cfg
->forcelist
, s
);
800 case 10: /* superclass */
802 exitfileerror(20, "superclass specified when not a BOOPSI class\n");
803 cl
->superclass
= strdup(s
);
806 case 11: /* superclass_field */
808 exitfileerror(20, "superclass_field specified when not a BOOPSI class\n");
809 cl
->superclass_field
= strdup(s
);
812 case 12: /* residentpri */
818 count
= sscanf(s
, "%d%c", &cfg
->residentpri
, &dummy
);
820 cfg
->residentpri
< -128 || cfg
->residentpri
> 127
823 exitfileerror(20, "residentpri number format error\n");
827 exitfileerror(20, "residentpri not valid config option when in a class section\n");
830 case 13: /* options */
833 static const char *optionnames
[] =
835 "noautolib", "noexpunge", "noresident", "peropenerbase",
836 "pertaskbase", "includes", "noincludes", "nostubs",
837 "autoinit", "noautoinit", "resautoinit", "noopenclose",
840 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
845 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
847 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
850 s
+= strlen(optionnames
[i
]);
851 while (isspace(*s
)) s
++;
855 exitfileerror(20, "Unrecognized option\n");
859 exitfileerror(20, "Unrecognized option\n");
862 case 1: /* noautolib */
863 cfg
->options
|= OPTION_NOAUTOLIB
;
865 case 2: /* noexpunge */
866 cfg
->options
|= OPTION_NOEXPUNGE
;
868 case 3: /* noresident */
869 cfg
->options
|= OPTION_NORESIDENT
;
872 case 5: /* pertaskbase */
873 cfg
->options
|= OPTION_PERTASKBASE
;
875 case 4: /* peropenerbase */
876 if (cfg
->options
& OPTION_DUPBASE
)
877 exitfileerror(20, "Only one option peropenerbase or pertaskbase allowed\n");
878 cfg
->options
|= OPTION_DUPBASE
;
880 case 6: /* includes */
881 if (cfg
->options
& OPTION_NOINCLUDES
)
882 exitfileerror(20, "option includes and noincludes are incompatible\n");
883 cfg
->options
|= OPTION_INCLUDES
;
885 case 7: /* noincludes */
886 if (cfg
->options
& OPTION_INCLUDES
)
887 exitfileerror(20, "option includes and noincludes are incompatible\n");
888 cfg
->options
|= OPTION_NOINCLUDES
;
890 case 8: /* nostubs */
891 cfg
->options
|= OPTION_NOSTUBS
;
893 case 9: /* autoinit */
894 if (cfg
->options
& OPTION_NOAUTOINIT
)
895 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
896 cfg
->options
|= OPTION_AUTOINIT
;
898 case 10: /* noautoinit */
899 if (cfg
->options
& OPTION_AUTOINIT
)
900 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
901 cfg
->options
|= OPTION_NOAUTOINIT
;
903 case 11: /* resautoinit */
904 if (cfg
->options
& OPTION_SELFINIT
)
905 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
906 cfg
->options
|= OPTION_RESAUTOINIT
;
909 cfg
->options
|= OPTION_NOOPENCLOSE
;
911 case 13: /* noresautoinit */
912 if (cfg
->options
& OPTION_RESAUTOINIT
)
913 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
914 cfg
->options
|= OPTION_SELFINIT
;
917 while (isspace(*s
)) s
++;
922 static const char *optionnames
[] =
926 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
931 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
933 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
936 s
+= strlen(optionnames
[i
]);
937 while (isspace(*s
)) s
++;
941 exitfileerror(20, "Unrecognized option\n");
945 exitfileerror(20, "Unrecognized option\n");
948 case 1: /* private */
949 cl
->options
|= COPTION_PRIVATE
;
952 while (isspace(*s
)) s
++;
957 case 14: /* sysbase_field */
959 exitfileerror(20, "sysbase_field not valid config option when in a class section\n");
960 cfg
->sysbase_field
= strdup(s
);
963 case 15: /* seglist_field */
965 exitfileerror(20, "seglist_field not valid config option when in a class section\n");
966 cfg
->seglist_field
= strdup(s
);
969 case 16: /* rootbase_field */
971 exitfileerror(20, "rootbase_field not valid config option when in a class section\n");
972 cfg
->rootbase_field
= strdup(s
);
975 case 17: /* classptr_field */
981 "classptr_field specified when not a BOOPSI class\n"
984 cl
->classptr_field
= strdup(s
);
987 case 18: /* classptr_var */
993 "classptr_var specified when not a BOOPSI class\n"
996 cl
->classptr_var
= strdup(s
);
999 case 19: /* classid */
1001 exitfileerror(20, "classid specified when not a BOOPSI class\n");
1002 if (cl
->classid
!= NULL
)
1003 exitfileerror(20, "classid specified twice\n");
1004 cl
->classid
= strdup(s
);
1005 if (strcmp(cl
->classid
, "NULL") == 0)
1006 cl
->options
|= COPTION_PRIVATE
;
1009 case 20: /* classdatatype */
1011 exitfileerror(20, "classdatatype specified when not a BOOPSI class\n");
1012 cl
->classdatatype
= strdup(s
);
1015 case 21: /* beginio_func */
1017 exitfileerror(20, "beginio_func not valid config option when in a class section\n");
1018 if (cfg
->modtype
!= DEVICE
)
1019 exitfileerror(20, "beginio_func specified when not a device\n");
1020 cfg
->beginiofunc
= strdup(s
);
1023 case 22: /* abortio_func */
1025 exitfileerror(20, "abortio_func not valid config option when in a class section\n");
1026 if (cfg
->modtype
!= DEVICE
)
1027 exitfileerror(20, "abortio_func specified when not a device\n");
1028 cfg
->abortiofunc
= strdup(s
);
1031 case 23: /* dispatcher */
1033 exitfileerror(20, "dispatcher specified when not a BOOPSI class\n");
1034 cl
->dispatcher
= strdup(s
);
1035 /* function references are not needed when dispatcher is specified */
1036 cfg
->intcfg
|= CFG_NOREADFUNCS
;
1039 case 24: /* initpri */
1045 count
= sscanf(s
, "%d%c", &cl
->initpri
, &dummy
);
1047 cl
->initpri
< -128 || cl
->initpri
> 127
1050 exitfileerror(20, "initpri number format error\n");
1054 exitfileerror(20, "initpri only valid config option for a BOOPSI class\n");
1059 exitfileerror(20, "type only valid config option in a class section\n");
1060 if (strcmp(s
,"mcc")==0)
1061 cl
->classtype
= MCC
;
1062 else if (strcmp(s
,"mui")==0)
1063 cl
->classtype
= MUI
;
1064 else if (strcmp(s
,"mcp")==0)
1065 cl
->classtype
= MCP
;
1066 else if (strcmp(s
, "image")==0)
1067 cl
->classtype
= IMAGE
;
1068 else if (strcmp(s
, "gadget")==0)
1069 cl
->classtype
= GADGET
;
1070 else if (strcmp(s
, "datatype")==0)
1071 cl
->classtype
= DATATYPE
;
1072 else if (strcmp(s
, "usbclass")==0)
1073 cl
->classtype
= USBCLASS
;
1074 else if (strcmp(s
, "class")==0)
1075 cl
->classtype
= CLASS
;
1076 else if (strcmp(s
, "hidd")==0)
1077 cl
->classtype
= HIDD
;
1080 fprintf(stderr
, "Unknown type \"%s\" specified\n", s
);
1085 case 26: /* addromtag */
1086 cfg
->addromtag
= strdup(s
);
1089 case 27: /* oopbase_field */
1090 cfg
->oopbase_field
= strdup(s
);
1092 case 28: /* rellib */
1093 slist_append(&cfg
->rellibs
, s
);
1095 case 29: /* interfaceid */
1097 exitfileerror(20, "interfaceid only valid config option for an interface\n");
1098 in
->interfaceid
= strdup(s
);
1100 case 30: /* interfacename */
1102 exitfileerror(20, "interfacename only valid config option for an interface\n");
1103 in
->interfacename
= strdup(s
);
1105 case 31: /* methodstub */
1107 exitfileerror(20, "methodstub only valid config option for an interface\n");
1108 in
->methodstub
= strdup(s
);
1110 case 32: /* methodbase */
1112 exitfileerror(20, "methodbase only valid config option for an interface\n");
1113 in
->methodbase
= strdup(s
);
1115 case 33: /* attributebase */
1117 exitfileerror(20, "attributebase only valid config option for an interface\n");
1118 in
->attributebase
= strdup(s
);
1120 case 34: /* handler_func */
1121 if (cfg
->modtype
!= HANDLER
)
1122 exitfileerror(20, "handler specified when not a handler\n");
1123 cfg
->handlerfunc
= strdup(s
);
1127 else /* Line starts with ## */
1130 while (isspace(*s
)) s
++;
1131 if (strncmp(s
, "end", 3)!=0)
1132 exitfileerror(20, "\"##end config\" expected\n");
1136 exitfileerror(20, "\"##end config\" expected\n");
1138 while (isspace(*s
)) s
++;
1139 if (strncmp(s
, "config", 6)!=0)
1140 exitfileerror(20, "\"##end config\" expected\n");
1143 while (isspace(*s
)) s
++;
1145 exitfileerror(20, "\"##end config\" expected\n");
1151 /* When not in a class section fill in default values for fields in cfg */
1154 if (cfg
->basename
==NULL
)
1156 cfg
->basename
= strdup(cfg
->modulename
);
1157 *cfg
->basename
= toupper(*cfg
->basename
);
1159 if (cfg
->libbase
==NULL
)
1161 unsigned int len
= strlen(cfg
->basename
)+5;
1162 cfg
->libbase
= malloc(len
);
1163 snprintf(cfg
->libbase
, len
, "%sBase", cfg
->basename
);
1165 if (cfg
->libbasetype
== NULL
&& libbasetypeextern
!= NULL
)
1166 cfg
->libbasetype
= strdup(libbasetypeextern
);
1167 if (cfg
->sysbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1168 exitfileerror(20, "sysbase_field specified when no libbasetype is given\n");
1169 if (cfg
->seglist_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1170 exitfileerror(20, "seglist_field specified when no libbasetype is given\n");
1171 if (cfg
->oopbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1172 exitfileerror(20, "oopbase_field specified when no libbasetype is given\n");
1173 /* rootbase_field only allowed when duplicating base */
1174 if (cfg
->rootbase_field
!= NULL
&& !(cfg
->options
& OPTION_DUPBASE
))
1175 exitfileerror(20, "rootbasefield only valid for option peropenerbase or pertaskbase\n");
1177 /* Set default date to current date */
1178 if (cfg
->datestring
== NULL
)
1181 time_t now
= time(NULL
);
1182 struct tm
*ltime
= localtime(&now
);
1184 snprintf(tmpbuf
, sizeof(tmpbuf
), "%u.%u.%u",
1185 ltime
->tm_mday
, 1 + ltime
->tm_mon
, 1900 + ltime
->tm_year
);
1187 cfg
->datestring
= strdup(tmpbuf
);
1190 if (cfg
->copyright
== NULL
)
1191 cfg
->copyright
= "";
1193 if ( (cfg
->beginiofunc
!= NULL
&& cfg
->abortiofunc
== NULL
)
1194 || (cfg
->beginiofunc
== NULL
&& cfg
->abortiofunc
!= NULL
)
1196 exitfileerror(20, "please specify both beginio_func and abortio_func\n");
1198 if (libbasetypeextern
==NULL
)
1200 switch (cfg
->modtype
)
1203 cfg
->libbasetypeptrextern
= "struct Device *";
1207 cfg
->libbasetypeptrextern
= "APTR ";
1217 cfg
->libbasetypeptrextern
= "struct Library *";
1220 fprintf(stderr
, "Internal error: Unsupported modtype for libbasetypeptrextern\n");
1226 cfg
->libbasetypeptrextern
= malloc(strlen(libbasetypeextern
)+3);
1227 strcpy(cfg
->libbasetypeptrextern
, libbasetypeextern
);
1228 strcat(cfg
->libbasetypeptrextern
, " *");
1229 free(libbasetypeextern
);
1233 /* When class was given too fill in some defaults when not specified */
1236 if (cl
->classtype
== UNSPECIFIED
)
1237 cl
->classtype
= CLASS
;
1239 if (cl
->basename
== NULL
)
1242 cl
->basename
= cfg
->basename
;
1244 exitfileerror(20, "basename has to be specified in the config section inside of a class section\n");
1247 /* MUI classes are always private */
1248 if (cl
->classtype
== MUI
|| cl
->classtype
== MCC
|| cl
->classtype
== MCP
)
1249 cl
->options
|= COPTION_PRIVATE
;
1251 if (cl
->classid
== NULL
1252 && (cl
->classtype
!= MUI
&& cl
->classtype
!= MCC
&& cl
->classtype
!= MCP
)
1255 if (cl
->classtype
== HIDD
)
1257 cl
->options
&= !COPTION_PRIVATE
;
1259 else if (cl
->options
& COPTION_PRIVATE
)
1261 cl
->classid
= "NULL";
1267 if (cl
->classtype
== GADGET
|| cl
->classtype
== IMAGE
|| cl
->classtype
== CLASS
|| cl
->classtype
== USBCLASS
)
1269 sprintf(s
, "\"%sclass\"", inclass
? cl
->basename
: cfg
->modulename
);
1271 else if (cl
->classtype
== DATATYPE
)
1273 sprintf(s
, "\"%s.datatype\"", inclass
? cl
->basename
: cfg
->modulename
);
1275 cl
->classid
= strdup(s
);
1279 /* Only specify superclass or superclass_field */
1280 if (cl
->superclass
!= NULL
&& cl
->superclass_field
!= NULL
)
1281 exitfileerror(20, "Only specify one of superclass or superclass_field in config section\n");
1283 /* Give default value to superclass if it is not specified */
1284 if (cl
->superclass
== NULL
&& cl
->superclass
== NULL
)
1286 switch (cl
->classtype
)
1290 cl
->superclass
= "MUIC_Area";
1293 cl
->superclass
= "MUIC_Mccprefs";
1296 cl
->superclass
= "IMAGECLASS";
1299 cl
->superclass
= "GADGETCLASS";
1302 cl
->superclass
= "DATATYPESCLASS";
1305 cl
->superclass
= "ROOTCLASS";
1308 cl
->superclass
= "CLID_Root";
1311 exitfileerror(20, "Internal error: unhandled classtype in readsectionconfig\n");
1318 static void readsectioncdef(struct config
*cfg
)
1327 exitfileerror(20, "unexptected end of file in section cdef\n");
1329 if (strncmp(line
, "##", 2)!=0)
1331 slist_append(&cfg
->cdeflines
, line
);
1336 while (isspace(*s
)) s
++;
1337 if (strncmp(s
, "end", 3)!=0)
1338 exitfileerror(20, "\"##end cdef\" expected\n");
1341 while (isspace(*s
)) s
++;
1342 if (strncmp(s
, "cdef", 4)!=0)
1343 exitfileerror(20, "\"##end cdef\" expected\n");
1346 while (isspace(*s
)) s
++;
1348 exitfileerror(20, "unexpected character at position %d\n");
1355 static void readsectioncdefprivate(struct config
*cfg
)
1364 exitfileerror(20, "unexptected end of file in section cdef\n");
1366 if (strncmp(line
, "##", 2)!=0)
1368 slist_append(&cfg
->cdefprivatelines
, line
);
1373 while (isspace(*s
)) s
++;
1374 if (strncmp(s
, "end", 3)!=0)
1375 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1378 while (isspace(*s
)) s
++;
1379 if (strncmp(s
, "cdefprivate", 11)!=0)
1380 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1383 while (isspace(*s
)) s
++;
1385 exitfileerror(20, "unexpected character at position %d\n");
1392 static void readsectionstartup(struct config
*cfg
)
1401 exitfileerror(20, "unexptected end of file in section startup\n");
1403 if (strncmp(line
, "##", 2)!=0)
1405 slist_append(&cfg
->startuplines
, line
);
1410 while (isspace(*s
)) s
++;
1411 if (strncmp(s
, "end", 3)!=0)
1412 exitfileerror(20, "\"##end startup\" expected\n");
1415 while (isspace(*s
)) s
++;
1416 if (strncmp(s
, "startup", 7)!=0)
1417 exitfileerror(20, "\"##end startup\" expected\n");
1420 while (isspace(*s
)) s
++;
1422 exitfileerror(20, "unexpected character at position %d\n");
1429 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
, enum libcall def_libcall
)
1432 char *line
, *s
, *s2
;
1433 unsigned int lvo
= firstlvo
;
1440 exitfileerror(20, "unexpected EOF in functionlist section\n");
1441 if (strlen(line
)==0)
1443 if (*funclistptr
!= NULL
)
1444 funclistptr
= &((*funclistptr
)->next
);
1447 else if (isspace(*line
))
1450 while (isspace(*s
)) s
++;
1453 if (*funclistptr
!= NULL
)
1454 funclistptr
= &((*funclistptr
)->next
);
1458 exitfileerror(20, "no space allowed before functionname\n");
1460 else if (strncmp(line
, "##", 2)==0)
1463 while (isspace(*s
)) s
++;
1464 if (strncmp(s
, "end", 3)!=0)
1465 exitfileerror(20, "\"##end %s\" expected\n", type
);
1468 while (isspace(*s
)) s
++;
1469 if (strncmp(s
, type
, strlen(type
))!=0)
1470 exitfileerror(20, "\"##end %s\" expected\n", type
);
1473 while (isspace(*s
)) s
++;
1475 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1479 else if (*line
=='.')
1482 if (strncmp(s
, "skip", 4)==0)
1488 exitfileerror(20, "syntax is '.skip n'\n");
1490 n
=strtol(s
, &s2
, 10);
1492 exitfileerror(20, "positive number expected\n");
1494 while (isspace(*s2
)) s2
++;
1495 if ((*s2
!= '\0') && (*s2
!= '#'))
1496 exitfileerror(20, "syntax is '.skip n'\n");
1497 if (*funclistptr
!= NULL
)
1498 funclistptr
= &((*funclistptr
)->next
);
1501 else if (strncmp(s
, "alias", 5)==0)
1506 exitfileerror(20, "syntax is '.alias name'\n");
1508 while (isspace(*s
)) s
++;
1509 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1510 exitfileerror(20, "syntax is '.alias name'\n");
1514 while (isalnum(*s
) || *s
== '_') s
++;
1521 } while (isspace(*s
));
1525 exitfileerror(20, "syntax is '.alias name'\n");
1527 if (*funclistptr
== NULL
)
1528 exitfileerror(20, ".alias has to come after a function declaration\n");
1530 slist_append(&(*funclistptr
)->aliases
, s2
);
1532 else if (strncmp(s
, "function", 8) == 0)
1537 exitfileerror(20, "Syntax error\n");
1539 while (isspace(*s
)) s
++;
1540 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1541 exitfileerror(20, "syntax is '.function name'\n");
1545 while (isalnum(*s
) || *s
== '_') s
++;
1552 } while (isspace(*s
));
1556 exitfileerror(20, "syntax is '.function name'\n");
1558 if (*funclistptr
== NULL
)
1559 exitfileerror(20, ".function has to come after a function declaration\n");
1561 funcsetinternalname(*funclistptr
, s2
);
1563 else if (strncmp(s
, "cfunction", 9)==0)
1565 if (*funclistptr
== NULL
)
1566 exitfileerror(20, ".cfunction has to come after a function declaration\n");
1568 (*funclistptr
)->libcall
= REGISTER
;
1570 else if (strncmp(s
, "private", 7)==0)
1572 if (*funclistptr
== NULL
)
1573 exitfileerror(20, ".private has to come after a function declaration\n");
1575 (*funclistptr
)->priv
= 1;
1577 else if (strncmp(s
, "novararg", 8)==0)
1579 if (*funclistptr
== NULL
)
1580 exitfileerror(20, ".novararg has to come after a function declaration\n");
1582 (*funclistptr
)->novararg
= 1;
1584 else if (strncmp(s
, "version", 7) == 0)
1586 /* Mark version number for the following
1587 * functions, so that the automatic OpenLibrary()
1588 * will know what version to use.
1595 while (isspace(*s
)) s
++;
1596 ver
= (int)strtol(s
, &tmp
, 0);
1599 exitfileerror(20, ".version expects an integer\n");
1602 while (isspace(*s
)) s
++;
1604 if (*s
&& *s
!= '#')
1605 exitfileerror(20, ".version has junk after the version number\n");
1609 else if (strncmp(s
, "unusedlibbase", 13) == 0)
1611 if (*funclistptr
== NULL
)
1612 exitfileerror(20, ".unusedlibbase has to come after a function declaration\n");
1613 (*funclistptr
)->unusedlibbase
= 1;
1616 exitfileerror(20, "Syntax error");
1618 else if (*line
!='#') /* Ignore line that is a comment, e.g. that starts with a # */
1620 /* The line is a function or attribute prototype.
1621 * A function can have one of two syntaxes:
1622 * type funcname(argproto1, argproto2, ...)
1623 * type funcname(argproto1, argproto2, ...) (reg1, reg2, ...)
1624 * The former is for C type function argument passing, the latter for
1625 * register argument passing.
1626 * An attribute has the following syntax:
1629 char c
, *args
[64], *regs
[64], *funcname
, *cp
;
1630 int len
, argcount
= 0, regcount
= 0, brcount
= 0;
1632 cp
= strchr(line
,'#');
1636 /* Parse 'type functionname' at the beginning of the line */
1638 s
= line
+ strlen(line
);
1640 s
= strchr(line
, '(');
1642 exitfileerror(20, "( expected at position %d\n", strlen(line
) + 1);
1646 while (isspace(*(s2
-1)))
1650 while (s2
> line
&& !isspace(*(s2
-1)) && !(*(s2
-1) == '*'))
1654 exitfileerror(20, "No type specifier before %s name\n", isattribute
? "attribute" : "function");
1656 if (*funclistptr
!= NULL
)
1657 funclistptr
= &((*funclistptr
)->next
);
1658 *funclistptr
= newfunctionhead(s2
, STACK
);
1661 (*funclistptr
)->comment
= strdup(cp
);
1663 (*funclistptr
)->comment
= NULL
;
1665 while (isspace(*(s2
-1)))
1668 (*funclistptr
)->type
= strdup(line
);
1669 (*funclistptr
)->lvo
= lvo
;
1670 (*funclistptr
)->version
= minversion
;
1676 /* Parse function prototype */
1693 && !(brcount
== 0 && (*s
== ',' || *s
== ')'))
1703 exitfileerror(20, "Unexected ')' at position %d\n", s
-line
+1);
1710 exitfileerror(20, "'(' without ')'");
1713 while (isspace(*(s2
-1)))
1717 if (!(s2
> args
[argcount
- 1]))
1718 exitfileerror(20, "Syntax error in function prototype\n");
1724 while (*s
!= '\0' && isspace(*s
))
1729 /* Parse registers specifications if available otherwise this prototype for C type argument passing */
1731 /* There may be no register specified with () so be sure then c is == ')' */
1746 if (memchr("AD",s
[0],2)!=NULL
&& memchr("01234567",s
[1],8)!=NULL
)
1753 if (s
[0] == s
[-3] && s
[1] == s
[-2] + 1)
1760 "wrong register specification \"%s\" for argument %u\n",
1761 regs
[regcount
-1], regcount
1765 exitfileerror(20, "maximum four arguments passed in two registers allowed (%d, %s) \n", regcount
, regs
[regcount
-1]);
1771 "wrong register \"%s\" for argument %u\n",
1772 regs
[regcount
-1], regcount
1781 exitfileerror(20, "'(' without ')'\n");
1782 if (c
!= ',' && c
!= ')')
1783 exitfileerror(20, "',' or ')' expected at position %d\n", s
-line
+1);
1789 while (isspace(*s
)) s
++;
1791 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1793 if (argcount
!= regcount
)
1794 exitfileerror(20, "Number of arguments (%d) and registers (%d) mismatch\n",
1798 (*funclistptr
)->libcall
= def_libcall
;
1799 for (i
= 0; i
< argcount
; i
++)
1800 funcaddarg(*funclistptr
, args
[i
], regs
[i
]);
1802 else if (*s
== '\0')
1803 { /* No registers specified */
1804 for (i
= 0; i
< argcount
; i
++)
1805 funcaddarg(*funclistptr
, args
[i
], NULL
);
1808 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1813 static void readsectionclass_methodlist(struct classinfo
*cl
)
1816 char *line
, *s
, *s2
;
1817 struct functionhead
**methlistptr
= &cl
->methlist
;
1818 struct stringlist
*interface
= NULL
;
1820 if (cl
->basename
==NULL
)
1821 exitfileerror(20, "section methodlist has to come after section config\n");
1827 exitfileerror(20, "unexptected EOF in methodlist section\n");
1829 /* Ignore empty lines or lines that qre a comment, e.g. that starts with a # */
1830 if (strlen(line
)==0 || (line
[0] == '#' && line
[1] != '#'))
1834 exitfileerror(20, "No space allowed at start of the line\n");
1836 if (strncmp(line
, "##", 2)==0) /* Is this the end ? */
1839 while (isspace(*s
)) s
++;
1840 if (strncmp(s
, "end", 3)!=0)
1841 exitfileerror(20, "\"##end methodlist\" expected\n");
1844 while (isspace(*s
)) s
++;
1845 if (strncmp(s
, "methodlist", 10)!=0)
1846 exitfileerror(20, "\"##end methodlist\" expected\n");
1849 while (isspace(*s
)) s
++;
1851 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1861 if (strncmp(s
, "alias", 5)==0)
1866 exitfileerror(20, "syntax is '.alias name'\n");
1868 while (isspace(*s
)) s
++;
1869 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1870 exitfileerror(20, "syntax is '.alias name'\n");
1874 while (isalnum(*s
) || *s
== '_') s
++;
1881 } while (isspace(*s
));
1885 exitfileerror(20, "syntax is '.alias name'\n");
1887 if (*methlistptr
== NULL
)
1888 exitfileerror(20, ".alias has to come after a function declaration\n");
1890 slist_append(&(*methlistptr
)->aliases
, s2
);
1892 else if (strncmp(s
, "function", 8) == 0)
1897 exitfileerror(20, "Syntax error\n");
1899 while (isspace(*s
)) s
++;
1900 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1901 exitfileerror(20, "syntax is '.function name'\n");
1905 while (isalnum(*s
) || *s
== '_') s
++;
1912 } while (isspace(*s
));
1916 exitfileerror(20, "syntax is '.function name'\n");
1918 if (*methlistptr
== NULL
)
1919 exitfileerror(20, ".function has to come after a function declaration\n");
1921 funcsetinternalname(*methlistptr
, s2
);
1923 else if (strncmp(s
, "interface", 9) == 0)
1925 if (cl
->classtype
!= HIDD
)
1926 exitfileerror(20, "interface only valid for a HIDD\n");
1931 exitfileerror(20, "Syntax error\n");
1933 while (isspace(*s
)) s
++;
1934 if (*s
== '\0' || !isalpha(*s
))
1935 exitfileerror(20, "syntax is '.interface name'\n");
1939 while (isalnum(*s
) || *s
== '_') s
++;
1946 } while (isspace(*s
));
1950 exitfileerror(20, "syntax is '.interface name'\n");
1952 interface
= slist_append(&cl
->interfaces
, s2
);
1955 exitfileerror(20, "Syntax error");
1957 else if (isalpha(*line
))
1961 for (s
= line
+ 1; isalnum(*s
) || *s
== '_'; s
++)
1964 if (cl
->classtype
== HIDD
&& interface
== NULL
)
1965 exitfileerror(20, "For a HIDD the first method has to come after an .interface line\n");
1968 exitfileerror(20, "Only letters, digits and an underscore allowed in a methodname\n");
1970 if (*methlistptr
!= NULL
)
1971 methlistptr
= &((*methlistptr
)->next
);
1972 if (cl
->classtype
!= HIDD
)
1974 if (snprintf(stmp
, 256, "%s__%s", cl
->basename
, line
) >= 256)
1975 exitfileerror(20, "Method name too large\n");
1977 *methlistptr
= newfunctionhead(stmp
, STACK
);
1978 (*methlistptr
)->type
= "IPTR";
1979 funcaddarg(*methlistptr
, "Class *cl", NULL
);
1980 funcaddarg(*methlistptr
, "Object *o", NULL
);
1981 funcaddarg(*methlistptr
, "Msg msg", NULL
);
1985 if (snprintf(stmp
, 256, "%s__%s__%s", cl
->basename
, interface
->s
, line
) >= 256)
1986 exitfileerror(20, "Method name too large\n");
1988 *methlistptr
= newfunctionhead(stmp
, STACK
);
1989 (*methlistptr
)->type
= "IPTR";
1990 funcaddarg(*methlistptr
, "OOP_Class *cl", NULL
);
1991 funcaddarg(*methlistptr
, "OOP_Object *o", NULL
);
1992 funcaddarg(*methlistptr
, "OOP_Msg msg", NULL
);
1993 (*methlistptr
)->interface
= interface
;
1994 if (snprintf(stmp
, 256, "mo%s_%s", interface
->s
, line
) >= 256)
1995 exitfileerror(20, "Method name too large\n");
1996 (*methlistptr
)->method
= strdup(stmp
);
1998 slist_append(&(*methlistptr
)->aliases
, line
);
2001 exitfileerror(20, "Methodname has to begin with a letter\n");
2006 readsectioninterface(struct config
*cfg
)
2009 struct interfaceinfo
*in
;
2011 in
= newinterface(cfg
);
2012 s
= readsections(cfg
, NULL
, in
, 1);
2014 exitfileerror(20, "Unexpected end of file\n");
2016 if (strncmp(s
, "##", 2) != 0)
2017 exitfileerror(20, "'##end interface' expected\n");
2020 while (isspace(*s
)) s
++;
2022 if (strncmp(s
, "end", 3) != 0)
2023 exitfileerror(20, "'##end interface' expected\n");
2027 exitfileerror(20, "'##end interface' expected\n");
2028 while (isspace(*s
)) s
++;
2030 if (strncmp(s
, "interface", 9) != 0)
2031 exitfileerror(20, "'##end interface' expected\n");
2034 while (isspace(*s
)) s
++;
2036 exitfileerror(20, "'##end interface' expected\n");
2038 if (!in
->interfaceid
)
2039 exitfileerror(20, "interface has no 'interfaceid' defined!\n");
2041 if (!in
->interfacename
)
2042 exitfileerror(20, "interface has no 'interfacename' defined!\n");
2044 if (!in
->methodstub
)
2045 in
->methodstub
= strdup(in
->interfacename
);
2047 if (!in
->methodbase
) {
2048 int len
= strlen(in
->interfacename
);
2049 in
->methodbase
= malloc(len
+ 4 + 1);
2050 strcpy(in
->methodbase
, in
->interfacename
);
2051 strcat(in
->methodbase
, "Base");
2054 if (!in
->attributebase
) {
2055 int len
= strlen(in
->interfacename
);
2056 in
->attributebase
= malloc(len
+ 4 + 4 + 1);
2057 strcpy(in
->attributebase
, in
->interfacename
);
2058 strcat(in
->attributebase
, "AttrBase");
2063 readsectionclass(struct config
*cfg
)
2066 struct classinfo
*cl
;
2069 s
= readsections(cfg
, cl
, NULL
, 1);
2071 exitfileerror(20, "Unexpected end of file\n");
2073 if (strncmp(s
, "##", 2) != 0)
2074 exitfileerror(20, "'##end class' expected\n");
2077 while (isspace(*s
)) s
++;
2079 if (strncmp(s
, "end", 3) != 0)
2080 exitfileerror(20, "'##end class' expected\n");
2084 exitfileerror(20, "'##end class' expected\n");
2085 while (isspace(*s
)) s
++;
2087 if (strncmp(s
, "class", 5) != 0)
2088 exitfileerror(20, "'##end class' expected\n");
2091 while (isspace(*s
)) s
++;
2093 exitfileerror(20, "'##end class' expected\n");
2096 static struct classinfo
*newclass(struct config
*cfg
)
2098 struct classinfo
*cl
, *classlistit
;
2100 cl
= malloc(sizeof(struct classinfo
));
2103 fprintf(stderr
, "Out of memory\n");
2106 memset(cl
, 0, sizeof(struct classinfo
));
2108 /* By default the classes are initialized with a priority of 1 so they
2109 * are initialized before any user added initialization with priority 1
2113 if (cfg
->classlist
== NULL
)
2114 cfg
->classlist
= cl
;
2119 classlistit
= cfg
->classlist
;
2120 classlistit
->next
!= NULL
;
2121 classlistit
= classlistit
->next
2124 classlistit
->next
= cl
;
2130 static struct handlerinfo
*newhandler(struct config
*cfg
)
2132 struct handlerinfo
*hl
;
2134 hl
= calloc(1,sizeof(*hl
));
2135 hl
->next
= cfg
->handlerlist
;
2136 cfg
->handlerlist
= hl
;
2140 static struct interfaceinfo
*newinterface(struct config
*cfg
)
2142 struct interfaceinfo
*in
, *interfacelistit
;
2144 in
= malloc(sizeof(struct interfaceinfo
));
2147 fprintf(stderr
, "Out of memory\n");
2150 memset(in
, 0, sizeof(struct interfaceinfo
));
2152 if (cfg
->interfacelist
== NULL
)
2153 cfg
->interfacelist
= in
;
2158 interfacelistit
= cfg
->interfacelist
;
2159 interfacelistit
->next
!= NULL
;
2160 interfacelistit
= interfacelistit
->next
2163 interfacelistit
->next
= in
;
2170 static int getdirective(char *s
, const char *directive
, int range_min
, int range_max
, int *val
)
2175 if (strncmp(s
, directive
, strlen(directive
)) != 0)
2178 s
+= strlen(directive
);
2179 if (*s
&& !isspace(*s
))
2180 exitfileerror(20, "Unrecognized directive \".%s\"\n", directive
);
2182 while (isspace(*s
)) s
++;
2184 exitfileerror(20, "No .%s value specified\n", directive
);
2186 newval
= strtol(s
, &tmp
, 0);
2187 if (s
== tmp
|| !(newval
>= range_min
&& newval
<= range_max
)) {
2189 while (*tmp
&& !isspace(*tmp
)) tmp
++;
2190 exitfileerror(20, "Invalid .%s value of %.*s\n", directive
, tmp
- s
, s
);
2198 readsectionhandler(struct config
*cfg
)
2200 char *line
= NULL
, *s
;
2201 struct handlerinfo
*hl
;
2202 unsigned char autolevel
= 0;
2203 unsigned int stacksize
= 0;
2207 int has_filesystem
= 0;
2215 s
= line
= readline();
2218 exitfileerror(20, "unexpected end of file in section hanlder\n");
2220 if (strncmp(s
, "##", 2)==0)
2223 /* Ignore comments */
2224 if (strncmp(s
, "#", 1)==0)
2227 /* Skip ahead to function name */
2228 while (*s
&& isspace(*s
)) s
++;
2230 /* Permit blank lines */
2238 if (getdirective(s
, "autodetect", 0, 127, &val
)) {
2240 } else if (getdirective(s
, "stacksize", 0, INT_MAX
, &val
)) {
2242 } else if (getdirective(s
, "priority", -128, 127, &val
)) {
2244 } else if (getdirective(s
, "bootpri", -128, 127, &val
)) {
2246 } else if (getdirective(s
, "startup", INT_MIN
, INT_MAX
, &val
)) {
2249 exitfileerror(20, "Unrecognized directive \"%s\"\n", line
);
2255 unsigned int id
= 0;
2257 if (strncasecmp(s
,"resident=",9)==0) {
2260 s
= strchr(s
, '=') + 1;
2262 while (*s
&& !isspace(*s
)) s
++;
2264 exitfileerror(20, "Empty resident= is not permitted\n");
2269 hl
= newhandler(cfg
);
2270 hl
->type
= HANDLER_RESIDENT
;
2272 hl
->name
= strdup(res
);
2273 hl
->autodetect
= autolevel
--;
2274 hl
->stacksize
= stacksize
;
2275 hl
->priority
= priority
;
2276 hl
->startup
= startup
;
2277 } else if (strncasecmp(s
,"dosnode=",8)==0) {
2280 s
= strchr(s
, '=') + 1;
2282 while (*s
&& !isspace(*s
)) s
++;
2284 exitfileerror(20, "Empty dosnode= is not permitted\n");
2289 hl
= newhandler(cfg
);
2290 hl
->type
= HANDLER_DOSNODE
;
2292 hl
->name
= strdup(dev
);
2293 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2294 hl
->stacksize
= stacksize
;
2295 hl
->priority
= priority
;
2296 hl
->startup
= startup
;
2297 hl
->bootpri
= bootpri
;
2298 } else if (strncasecmp(s
,"dostype=",8) == 0) {
2299 s
= strchr(s
, '=') + 1;
2301 id
= (unsigned int)strtoul(s
, &tmp
, 0);
2304 while (*tmp
&& !isspace(*tmp
))
2306 exitfileerror(20, "\"%.*s\" is not a numerical DOS ID\n", (tmp
-s
), s
);
2310 if (id
== 0 || id
== ~0) {
2311 exitfileerror(20, "DOS ID 0x%08x is not permitted\n", id
);
2314 hl
= newhandler(cfg
);
2315 hl
->type
= HANDLER_DOSTYPE
;
2318 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2319 hl
->stacksize
= stacksize
;
2320 hl
->priority
= priority
;
2321 hl
->startup
= startup
;
2323 for (tmp
= s
; !isspace(*tmp
); tmp
++);
2324 exitfileerror(20, "Unknown option \"%.*s\"\n", tmp
- s
, s
);
2327 /* Advance to next ID */
2328 while (*s
&& isspace(*s
)) s
++;
2334 exitfileerror(20, "Unexpected end of file\n");
2336 if (strncmp(s
, "##", 2) != 0)
2337 exitfileerror(20, "'##end handler' expected\n");
2340 while (isspace(*s
)) s
++;
2342 if (strncmp(s
, "end", 3) != 0)
2343 exitfileerror(20, "'##end handler' expected\n");
2346 while (isspace(*s
)) s
++;
2348 if (strncmp(s
, "handler", 7) != 0)
2349 exitfileerror(20, "'##end handler' expected\n");
2352 while (isspace(*s
)) s
++;
2354 exitfileerror(20, "'##end handler' expected\n");