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] [-n]\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
);
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"
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);
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);
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);
550 else if (strlen(line
)!=0)
551 filewarning("warning line outside section ignored\n");
557 exitfileerror(20, "No config section in conffile\n");
559 /* If no indication was given for generating includes or not
560 decide on module type and if there are functions
562 if(!((cfg
->options
& OPTION_INCLUDES
) || (cfg
->options
& OPTION_NOINCLUDES
)))
564 switch (cfg
->modtype
)
568 cfg
->options
|= OPTION_INCLUDES
;
576 cfg
->options
|= OPTION_NOINCLUDES
;
581 (cfg
->funclist
!= NULL
)
582 || (cfg
->cdeflines
!= NULL
)
583 || strcmp(cfg
->libbasetypeptrextern
, "struct Device *") != 0
584 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
591 (cfg
->funclist
!= NULL
)
592 ) ? OPTION_INCLUDES
: OPTION_NOINCLUDES
;
596 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for includes\n");
602 /* If no indication was given for not generating stubs only generate them if
603 * the module has functions
605 if(!((cfg
->options
& OPTION_STUBS
) || (cfg
->options
& OPTION_NOSTUBS
)))
607 switch (cfg
->modtype
)
610 cfg
->options
|= (cfg
->funclist
!= NULL
) ? OPTION_STUBS
: OPTION_NOSTUBS
;
623 cfg
->options
|= OPTION_NOSTUBS
;
627 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for stubs\n");
633 /* If no indication was given for generating autoinit code or not
634 decide on module type
636 if(!((cfg
->options
& OPTION_AUTOINIT
) || (cfg
->options
& OPTION_NOAUTOINIT
)))
638 switch (cfg
->modtype
)
641 cfg
->options
|= OPTION_AUTOINIT
;
654 cfg
->options
|= OPTION_NOAUTOINIT
;
658 fprintf(stderr
, "Internal error writemakefile: unhandled modtype for autoinit\n");
664 if ((cfg
->modtype
== RESOURCE
) || (cfg
->modtype
== HANDLER
))
665 /* Enforce noopenclose for resources and handlers */
666 cfg
->options
|= OPTION_NOOPENCLOSE
;
667 else if (!(cfg
->options
& OPTION_SELFINIT
))
668 /* Enforce using RTF_AUTOINIT for everything except resources */
669 cfg
->options
|= OPTION_RESAUTOINIT
;
675 static void readsectionconfig(struct config
*cfg
, struct classinfo
*cl
, struct interfaceinfo
*in
, int inclass
)
678 char *line
, *s
, *s2
, *libbasetypeextern
= NULL
;
685 exitfileerror(20, "unexpected end of file in section config\n");
687 if (strncmp(line
, "##", 2)!=0)
689 const char *names
[] =
691 "basename", "libbase", "libbasetype", "libbasetypeextern",
692 "version", "date", "copyright", "libcall", "forcebase", "superclass",
693 "superclass_field", "residentpri", "options", "sysbase_field",
694 "seglist_field", "rootbase_field", "classptr_field", "classptr_var",
695 "classid", "classdatatype", "beginio_func", "abortio_func", "dispatcher",
696 "initpri", "type", "addromtag", "oopbase_field",
697 "rellib", "interfaceid", "interfacename",
698 "methodstub", "methodbase", "attributebase", "handler_func"
700 const unsigned int namenums
= sizeof(names
)/sizeof(char *);
701 unsigned int namenum
;
703 for (i
= 0, namenum
= 0; namenum
==0 && i
<namenums
; i
++)
707 strncmp(line
, names
[i
], strlen(names
[i
]))==0
708 && isspace(*(line
+strlen(names
[i
])))
713 exitfileerror(20, "unrecognized configuration option\n");
715 s
= line
+ strlen(names
[namenum
-1]);
717 exitfileerror(20, "space character expected after \"%s\"\n", names
[namenum
-1]);
719 while (isspace(*s
)) s
++;
721 exitfileerror(20, "unexpected end of line\n");
724 while (isspace(*(s2
-1))) s2
--;
729 case 1: /* basename */
731 cfg
->basename
= strdup(s
);
733 cl
->basename
= strdup(s
);
735 exitfileerror(20, "basename not valid config option when in a interface section\n");
738 case 2: /* libbase */
740 exitfileerror(20, "libbase not valid config option when in a class section\n");
741 cfg
->libbase
= strdup(s
);
744 case 3: /* libbasetype */
746 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
747 cfg
->libbasetype
= strdup(s
);
750 case 4: /* libbasetypeextern */
752 exitfileerror(20, "libbasetype not valid config option when in a class section\n");
753 libbasetypeextern
= strdup(s
);
756 case 5: /* version */
758 exitfileerror(20, "version not valid config option when in a class section\n");
759 if (sscanf(s
, "%u.%u", &cfg
->majorversion
, &cfg
->minorversion
)!=2)
760 exitfileerror(20, "wrong version string \"%s\"\n", s
);
765 exitfileerror(20, "date not valid config option when in a class section\n");
767 if (strptime(s
, "%e.%m.%Y", &date
) == NULL
)
769 exitfileerror(20, "date string has to have d.m.yyyy format\n");
772 cfg
->datestring
= strdup(s
);
775 case 7: /* copyright */
777 exitfileerror(20, "copyright not valid config option when in a class section\n");
778 cfg
->copyright
= strdup(s
);
781 case 8: /* libcall */
782 fprintf(stderr
, "libcall specification is deprecated and ignored\n");
785 case 9: /* forcebase */
787 exitfileerror(20, "forcebase not valid config option when in a class section\n");
788 slist_append(&cfg
->forcelist
, s
);
791 case 10: /* superclass */
793 exitfileerror(20, "superclass specified when not a BOOPSI class\n");
794 cl
->superclass
= strdup(s
);
797 case 11: /* superclass_field */
799 exitfileerror(20, "superclass_field specified when not a BOOPSI class\n");
800 cl
->superclass_field
= strdup(s
);
803 case 12: /* residentpri */
809 count
= sscanf(s
, "%d%c", &cfg
->residentpri
, &dummy
);
811 cfg
->residentpri
< -128 || cfg
->residentpri
> 127
814 exitfileerror(20, "residentpri number format error\n");
818 exitfileerror(20, "residentpri not valid config option when in a class section\n");
821 case 13: /* options */
824 static const char *optionnames
[] =
826 "noautolib", "noexpunge", "noresident", "peropenerbase",
827 "pertaskbase", "includes", "noincludes", "nostubs",
828 "autoinit", "noautoinit", "resautoinit", "noopenclose",
831 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
836 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
838 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
841 s
+= strlen(optionnames
[i
]);
842 while (isspace(*s
)) s
++;
846 exitfileerror(20, "Unrecognized option\n");
850 exitfileerror(20, "Unrecognized option\n");
853 case 1: /* noautolib */
854 cfg
->options
|= OPTION_NOAUTOLIB
;
856 case 2: /* noexpunge */
857 cfg
->options
|= OPTION_NOEXPUNGE
;
859 case 3: /* noresident */
860 cfg
->options
|= OPTION_NORESIDENT
;
863 case 5: /* pertaskbase */
864 cfg
->options
|= OPTION_PERTASKBASE
;
866 case 4: /* peropenerbase */
867 if (cfg
->options
& OPTION_DUPBASE
)
868 exitfileerror(20, "Only one option peropenerbase or pertaskbase allowed\n");
869 cfg
->options
|= OPTION_DUPBASE
;
871 case 6: /* includes */
872 if (cfg
->options
& OPTION_NOINCLUDES
)
873 exitfileerror(20, "option includes and noincludes are incompatible\n");
874 cfg
->options
|= OPTION_INCLUDES
;
876 case 7: /* noincludes */
877 if (cfg
->options
& OPTION_INCLUDES
)
878 exitfileerror(20, "option includes and noincludes are incompatible\n");
879 cfg
->options
|= OPTION_NOINCLUDES
;
881 case 8: /* nostubs */
882 cfg
->options
|= OPTION_NOSTUBS
;
884 case 9: /* autoinit */
885 if (cfg
->options
& OPTION_NOAUTOINIT
)
886 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
887 cfg
->options
|= OPTION_AUTOINIT
;
889 case 10: /* noautoinit */
890 if (cfg
->options
& OPTION_AUTOINIT
)
891 exitfileerror(20, "option autoinit and noautoinit are incompatible\n");
892 cfg
->options
|= OPTION_NOAUTOINIT
;
894 case 11: /* resautoinit */
895 if (cfg
->options
& OPTION_SELFINIT
)
896 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
897 cfg
->options
|= OPTION_RESAUTOINIT
;
900 cfg
->options
|= OPTION_NOOPENCLOSE
;
902 case 13: /* noresautoinit */
903 if (cfg
->options
& OPTION_RESAUTOINIT
)
904 exitfileerror(20, "option resautoinit and selfinit are incompatible\n");
905 cfg
->options
|= OPTION_SELFINIT
;
908 while (isspace(*s
)) s
++;
913 static const char *optionnames
[] =
917 const unsigned int optionnums
= sizeof(optionnames
)/sizeof(char *);
922 for (i
= 0, optionnum
= 0; optionnum
==0 && i
<optionnums
; i
++)
924 if (strncmp(s
, optionnames
[i
], strlen(optionnames
[i
]))==0)
927 s
+= strlen(optionnames
[i
]);
928 while (isspace(*s
)) s
++;
932 exitfileerror(20, "Unrecognized option\n");
936 exitfileerror(20, "Unrecognized option\n");
939 case 1: /* private */
940 cl
->options
|= COPTION_PRIVATE
;
943 while (isspace(*s
)) s
++;
948 case 14: /* sysbase_field */
950 exitfileerror(20, "sysbase_field not valid config option when in a class section\n");
951 cfg
->sysbase_field
= strdup(s
);
954 case 15: /* seglist_field */
956 exitfileerror(20, "seglist_field not valid config option when in a class section\n");
957 cfg
->seglist_field
= strdup(s
);
960 case 16: /* rootbase_field */
962 exitfileerror(20, "rootbase_field not valid config option when in a class section\n");
963 cfg
->rootbase_field
= strdup(s
);
966 case 17: /* classptr_field */
972 "classptr_field specified when not a BOOPSI class\n"
975 cl
->classptr_field
= strdup(s
);
978 case 18: /* classptr_var */
984 "classptr_var specified when not a BOOPSI class\n"
987 cl
->classptr_var
= strdup(s
);
990 case 19: /* classid */
992 exitfileerror(20, "classid specified when not a BOOPSI class\n");
993 if (cl
->classid
!= NULL
)
994 exitfileerror(20, "classid specified twice\n");
995 cl
->classid
= strdup(s
);
996 if (strcmp(cl
->classid
, "NULL") == 0)
997 cl
->options
|= COPTION_PRIVATE
;
1000 case 20: /* classdatatype */
1002 exitfileerror(20, "classdatatype specified when not a BOOPSI class\n");
1003 cl
->classdatatype
= strdup(s
);
1006 case 21: /* beginio_func */
1008 exitfileerror(20, "beginio_func not valid config option when in a class section\n");
1009 if (cfg
->modtype
!= DEVICE
)
1010 exitfileerror(20, "beginio_func specified when not a device\n");
1011 cfg
->beginiofunc
= strdup(s
);
1014 case 22: /* abortio_func */
1016 exitfileerror(20, "abortio_func not valid config option when in a class section\n");
1017 if (cfg
->modtype
!= DEVICE
)
1018 exitfileerror(20, "abortio_func specified when not a device\n");
1019 cfg
->abortiofunc
= strdup(s
);
1022 case 23: /* dispatcher */
1024 exitfileerror(20, "dispatcher specified when not a BOOPSI class\n");
1025 cl
->dispatcher
= strdup(s
);
1026 /* function references are not needed when dispatcher is specified */
1027 cfg
->intcfg
|= CFG_NOREADFUNCS
;
1030 case 24: /* initpri */
1036 count
= sscanf(s
, "%d%c", &cl
->initpri
, &dummy
);
1038 cl
->initpri
< -128 || cl
->initpri
> 127
1041 exitfileerror(20, "initpri number format error\n");
1045 exitfileerror(20, "initpri only valid config option for a BOOPSI class\n");
1050 exitfileerror(20, "type only valid config option in a class section\n");
1051 if (strcmp(s
,"mcc")==0)
1052 cl
->classtype
= MCC
;
1053 else if (strcmp(s
,"mui")==0)
1054 cl
->classtype
= MUI
;
1055 else if (strcmp(s
,"mcp")==0)
1056 cl
->classtype
= MCP
;
1057 else if (strcmp(s
, "image")==0)
1058 cl
->classtype
= IMAGE
;
1059 else if (strcmp(s
, "gadget")==0)
1060 cl
->classtype
= GADGET
;
1061 else if (strcmp(s
, "datatype")==0)
1062 cl
->classtype
= DATATYPE
;
1063 else if (strcmp(s
, "usbclass")==0)
1064 cl
->classtype
= USBCLASS
;
1065 else if (strcmp(s
, "class")==0)
1066 cl
->classtype
= CLASS
;
1067 else if (strcmp(s
, "hidd")==0)
1068 cl
->classtype
= HIDD
;
1071 fprintf(stderr
, "Unknown type \"%s\" specified\n", s
);
1076 case 26: /* addromtag */
1077 cfg
->addromtag
= strdup(s
);
1080 case 27: /* oopbase_field */
1081 cfg
->oopbase_field
= strdup(s
);
1083 case 28: /* rellib */
1084 slist_append(&cfg
->rellibs
, s
);
1086 case 29: /* interfaceid */
1088 exitfileerror(20, "interfaceid only valid config option for an interface\n");
1089 in
->interfaceid
= strdup(s
);
1091 case 30: /* interfacename */
1093 exitfileerror(20, "interfacename only valid config option for an interface\n");
1094 in
->interfacename
= strdup(s
);
1096 case 31: /* methodstub */
1098 exitfileerror(20, "methodstub only valid config option for an interface\n");
1099 in
->methodstub
= strdup(s
);
1101 case 32: /* methodbase */
1103 exitfileerror(20, "methodbase only valid config option for an interface\n");
1104 in
->methodbase
= strdup(s
);
1106 case 33: /* attributebase */
1108 exitfileerror(20, "attributebase only valid config option for an interface\n");
1109 in
->attributebase
= strdup(s
);
1111 case 34: /* handler_func */
1112 if (cfg
->modtype
!= HANDLER
)
1113 exitfileerror(20, "handler specified when not a handler\n");
1114 cfg
->handlerfunc
= strdup(s
);
1118 else /* Line starts with ## */
1121 while (isspace(*s
)) s
++;
1122 if (strncmp(s
, "end", 3)!=0)
1123 exitfileerror(20, "\"##end config\" expected\n");
1127 exitfileerror(20, "\"##end config\" expected\n");
1129 while (isspace(*s
)) s
++;
1130 if (strncmp(s
, "config", 6)!=0)
1131 exitfileerror(20, "\"##end config\" expected\n");
1134 while (isspace(*s
)) s
++;
1136 exitfileerror(20, "\"##end config\" expected\n");
1142 /* When not in a class section fill in default values for fields in cfg */
1145 if (cfg
->basename
==NULL
)
1147 cfg
->basename
= strdup(cfg
->modulename
);
1148 *cfg
->basename
= toupper(*cfg
->basename
);
1150 if (cfg
->libbase
==NULL
)
1152 unsigned int len
= strlen(cfg
->basename
)+5;
1153 cfg
->libbase
= malloc(len
);
1154 snprintf(cfg
->libbase
, len
, "%sBase", cfg
->basename
);
1156 if (cfg
->libbasetype
== NULL
&& libbasetypeextern
!= NULL
)
1157 cfg
->libbasetype
= strdup(libbasetypeextern
);
1158 if (cfg
->sysbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1159 exitfileerror(20, "sysbase_field specified when no libbasetype is given\n");
1160 if (cfg
->seglist_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1161 exitfileerror(20, "seglist_field specified when no libbasetype is given\n");
1162 if (cfg
->oopbase_field
!= NULL
&& cfg
->libbasetype
== NULL
)
1163 exitfileerror(20, "oopbase_field specified when no libbasetype is given\n");
1164 /* rootbase_field only allowed when duplicating base */
1165 if (cfg
->rootbase_field
!= NULL
&& !(cfg
->options
& OPTION_DUPBASE
))
1166 exitfileerror(20, "rootbasefield only valid for option peropenerbase or pertaskbase\n");
1168 /* Set default date to current date */
1169 if (cfg
->datestring
== NULL
)
1172 time_t now
= time(NULL
);
1173 struct tm
*ltime
= localtime(&now
);
1175 snprintf(tmpbuf
, sizeof(tmpbuf
), "%u.%u.%u",
1176 ltime
->tm_mday
, 1 + ltime
->tm_mon
, 1900 + ltime
->tm_year
);
1178 cfg
->datestring
= strdup(tmpbuf
);
1181 if (cfg
->copyright
== NULL
)
1182 cfg
->copyright
= "";
1184 if ( (cfg
->beginiofunc
!= NULL
&& cfg
->abortiofunc
== NULL
)
1185 || (cfg
->beginiofunc
== NULL
&& cfg
->abortiofunc
!= NULL
)
1187 exitfileerror(20, "please specify both beginio_func and abortio_func\n");
1189 if (libbasetypeextern
==NULL
)
1191 switch (cfg
->modtype
)
1194 cfg
->libbasetypeptrextern
= "struct Device *";
1198 cfg
->libbasetypeptrextern
= "APTR ";
1208 cfg
->libbasetypeptrextern
= "struct Library *";
1211 fprintf(stderr
, "Internal error: Unsupported modtype for libbasetypeptrextern\n");
1217 cfg
->libbasetypeptrextern
= malloc(strlen(libbasetypeextern
)+3);
1218 strcpy(cfg
->libbasetypeptrextern
, libbasetypeextern
);
1219 strcat(cfg
->libbasetypeptrextern
, " *");
1220 free(libbasetypeextern
);
1224 /* When class was given too fill in some defaults when not specified */
1227 if (cl
->classtype
== UNSPECIFIED
)
1228 cl
->classtype
= CLASS
;
1230 if (cl
->basename
== NULL
)
1233 cl
->basename
= cfg
->basename
;
1235 exitfileerror(20, "basename has to be specified in the config section inside of a class section\n");
1238 /* MUI classes are always private */
1239 if (cl
->classtype
== MUI
|| cl
->classtype
== MCC
|| cl
->classtype
== MCP
)
1240 cl
->options
|= COPTION_PRIVATE
;
1242 if (cl
->classid
== NULL
1243 && (cl
->classtype
!= MUI
&& cl
->classtype
!= MCC
&& cl
->classtype
!= MCP
)
1246 if (cl
->classtype
== HIDD
)
1248 cl
->options
&= !COPTION_PRIVATE
;
1250 else if (cl
->options
& COPTION_PRIVATE
)
1252 cl
->classid
= "NULL";
1258 if (cl
->classtype
== GADGET
|| cl
->classtype
== IMAGE
|| cl
->classtype
== CLASS
|| cl
->classtype
== USBCLASS
)
1260 sprintf(s
, "\"%sclass\"", inclass
? cl
->basename
: cfg
->modulename
);
1262 else if (cl
->classtype
== DATATYPE
)
1264 sprintf(s
, "\"%s.datatype\"", inclass
? cl
->basename
: cfg
->modulename
);
1266 cl
->classid
= strdup(s
);
1270 /* Only specify superclass or superclass_field */
1271 if (cl
->superclass
!= NULL
&& cl
->superclass_field
!= NULL
)
1272 exitfileerror(20, "Only specify one of superclass or superclass_field in config section\n");
1274 /* Give default value to superclass if it is not specified */
1275 if (cl
->superclass
== NULL
&& cl
->superclass
== NULL
)
1277 switch (cl
->classtype
)
1281 cl
->superclass
= "MUIC_Area";
1284 cl
->superclass
= "MUIC_Mccprefs";
1287 cl
->superclass
= "IMAGECLASS";
1290 cl
->superclass
= "GADGETCLASS";
1293 cl
->superclass
= "DATATYPESCLASS";
1296 cl
->superclass
= "ROOTCLASS";
1299 cl
->superclass
= "CLID_Root";
1302 exitfileerror(20, "Internal error: unhandled classtype in readsectionconfig\n");
1309 static void readsectioncdef(struct config
*cfg
)
1318 exitfileerror(20, "unexptected end of file in section cdef\n");
1320 if (strncmp(line
, "##", 2)!=0)
1322 slist_append(&cfg
->cdeflines
, line
);
1327 while (isspace(*s
)) s
++;
1328 if (strncmp(s
, "end", 3)!=0)
1329 exitfileerror(20, "\"##end cdef\" expected\n");
1332 while (isspace(*s
)) s
++;
1333 if (strncmp(s
, "cdef", 4)!=0)
1334 exitfileerror(20, "\"##end cdef\" expected\n");
1337 while (isspace(*s
)) s
++;
1339 exitfileerror(20, "unexpected character at position %d\n");
1346 static void readsectioncdefprivate(struct config
*cfg
)
1355 exitfileerror(20, "unexptected end of file in section cdef\n");
1357 if (strncmp(line
, "##", 2)!=0)
1359 slist_append(&cfg
->cdefprivatelines
, line
);
1364 while (isspace(*s
)) s
++;
1365 if (strncmp(s
, "end", 3)!=0)
1366 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1369 while (isspace(*s
)) s
++;
1370 if (strncmp(s
, "cdefprivate", 11)!=0)
1371 exitfileerror(20, "\"##end cdefprivate\" expected\n");
1374 while (isspace(*s
)) s
++;
1376 exitfileerror(20, "unexpected character at position %d\n");
1383 static void readsectionstartup(struct config
*cfg
)
1392 exitfileerror(20, "unexptected end of file in section startup\n");
1394 if (strncmp(line
, "##", 2)!=0)
1396 slist_append(&cfg
->startuplines
, line
);
1401 while (isspace(*s
)) s
++;
1402 if (strncmp(s
, "end", 3)!=0)
1403 exitfileerror(20, "\"##end startup\" expected\n");
1406 while (isspace(*s
)) s
++;
1407 if (strncmp(s
, "startup", 7)!=0)
1408 exitfileerror(20, "\"##end startup\" expected\n");
1411 while (isspace(*s
)) s
++;
1413 exitfileerror(20, "unexpected character at position %d\n");
1420 static void readsectionfunctionlist(const char *type
, struct functionhead
**funclistptr
, unsigned int firstlvo
, int isattribute
)
1423 char *line
, *s
, *s2
;
1424 unsigned int lvo
= firstlvo
;
1431 exitfileerror(20, "unexpected EOF in functionlist section\n");
1432 if (strlen(line
)==0)
1434 if (*funclistptr
!= NULL
)
1435 funclistptr
= &((*funclistptr
)->next
);
1438 else if (isspace(*line
))
1441 while (isspace(*s
)) s
++;
1444 if (*funclistptr
!= NULL
)
1445 funclistptr
= &((*funclistptr
)->next
);
1449 exitfileerror(20, "no space allowed before functionname\n");
1451 else if (strncmp(line
, "##", 2)==0)
1454 while (isspace(*s
)) s
++;
1455 if (strncmp(s
, "end", 3)!=0)
1456 exitfileerror(20, "\"##end %s\" expected\n", type
);
1459 while (isspace(*s
)) s
++;
1460 if (strncmp(s
, type
, strlen(type
))!=0)
1461 exitfileerror(20, "\"##end %s\" expected\n", type
);
1464 while (isspace(*s
)) s
++;
1466 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1470 else if (*line
=='.')
1473 if (strncmp(s
, "skip", 4)==0)
1479 exitfileerror(20, "syntax is '.skip n'\n");
1481 n
=strtol(s
, &s2
, 10);
1483 exitfileerror(20, "positive number expected\n");
1485 while (isspace(*s2
)) s2
++;
1486 if ((*s2
!= '\0') && (*s2
!= '#'))
1487 exitfileerror(20, "syntax is '.skip n'\n");
1488 if (*funclistptr
!= NULL
)
1489 funclistptr
= &((*funclistptr
)->next
);
1492 else if (strncmp(s
, "alias", 5)==0)
1497 exitfileerror(20, "syntax is '.alias name'\n");
1499 while (isspace(*s
)) s
++;
1500 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1501 exitfileerror(20, "syntax is '.alias name'\n");
1505 while (isalnum(*s
) || *s
== '_') s
++;
1512 } while (isspace(*s
));
1516 exitfileerror(20, "syntax is '.alias name'\n");
1518 if (*funclistptr
== NULL
)
1519 exitfileerror(20, ".alias has to come after a function declaration\n");
1521 slist_append(&(*funclistptr
)->aliases
, s2
);
1523 else if (strncmp(s
, "function", 8) == 0)
1528 exitfileerror(20, "Syntax error\n");
1530 while (isspace(*s
)) s
++;
1531 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1532 exitfileerror(20, "syntax is '.function name'\n");
1536 while (isalnum(*s
) || *s
== '_') s
++;
1543 } while (isspace(*s
));
1547 exitfileerror(20, "syntax is '.function name'\n");
1549 if (*funclistptr
== NULL
)
1550 exitfileerror(20, ".function has to come after a function declaration\n");
1552 funcsetinternalname(*funclistptr
, s2
);
1554 else if (strncmp(s
, "cfunction", 9)==0)
1556 if (*funclistptr
== NULL
)
1557 exitfileerror(20, ".cfunction has to come after a function declaration\n");
1559 (*funclistptr
)->libcall
= REGISTER
;
1561 else if (strncmp(s
, "private", 7)==0)
1563 if (*funclistptr
== NULL
)
1564 exitfileerror(20, ".private has to come after a function declaration\n");
1566 (*funclistptr
)->priv
= 1;
1568 else if (strncmp(s
, "novararg", 8)==0)
1570 if (*funclistptr
== NULL
)
1571 exitfileerror(20, ".novararg has to come after a function declaration\n");
1573 (*funclistptr
)->novararg
= 1;
1575 else if (strncmp(s
, "version", 7) == 0)
1577 /* Mark version number for the following
1578 * functions, so that the automatic OpenLibrary()
1579 * will know what version to use.
1586 while (isspace(*s
)) s
++;
1587 ver
= (int)strtol(s
, &tmp
, 0);
1590 exitfileerror(20, ".version expects an integer\n");
1593 while (isspace(*s
)) s
++;
1595 if (*s
&& *s
!= '#')
1596 exitfileerror(20, ".version has junk after the version number\n");
1600 else if (strncmp(s
, "unusedlibbase", 13) == 0)
1602 if (*funclistptr
== NULL
)
1603 exitfileerror(20, ".unusedlibbase has to come after a function declaration\n");
1604 (*funclistptr
)->unusedlibbase
= 1;
1607 exitfileerror(20, "Syntax error");
1609 else if (*line
!='#') /* Ignore line that is a comment, e.g. that starts with a # */
1611 /* The line is a function or attribute prototype.
1612 * A function can have one of two syntaxes:
1613 * type funcname(argproto1, argproto2, ...)
1614 * type funcname(argproto1, argproto2, ...) (reg1, reg2, ...)
1615 * The former is for C type function argument passing, the latter for
1616 * register argument passing.
1617 * An attribute has the following syntax:
1620 char c
, *args
[64], *regs
[64], *funcname
, *cp
;
1621 int len
, argcount
= 0, regcount
= 0, brcount
= 0;
1623 cp
= strchr(line
,'#');
1627 /* Parse 'type functionname' at the beginning of the line */
1629 s
= line
+ strlen(line
);
1631 s
= strchr(line
, '(');
1633 exitfileerror(20, "( expected at position %d\n", strlen(line
) + 1);
1637 while (isspace(*(s2
-1)))
1641 while (s2
> line
&& !isspace(*(s2
-1)) && !(*(s2
-1) == '*'))
1645 exitfileerror(20, "No type specifier before %s name\n", isattribute
? "attribute" : "function");
1647 if (*funclistptr
!= NULL
)
1648 funclistptr
= &((*funclistptr
)->next
);
1649 *funclistptr
= newfunctionhead(s2
, STACK
);
1652 (*funclistptr
)->comment
= strdup(cp
);
1654 (*funclistptr
)->comment
= NULL
;
1656 while (isspace(*(s2
-1)))
1659 (*funclistptr
)->type
= strdup(line
);
1660 (*funclistptr
)->lvo
= lvo
;
1661 (*funclistptr
)->version
= minversion
;
1667 /* Parse function prototype */
1684 && !(brcount
== 0 && (*s
== ',' || *s
== ')'))
1694 exitfileerror(20, "Unexected ')' at position %d\n", s
-line
+1);
1701 exitfileerror(20, "'(' without ')'");
1704 while (isspace(*(s2
-1)))
1708 if (!(s2
> args
[argcount
- 1]))
1709 exitfileerror(20, "Syntax error in function prototype\n");
1715 while (*s
!= '\0' && isspace(*s
))
1720 /* Parse registers specifications if available otherwise this prototype for C type argument passing */
1722 /* There may be no register specified with () so be sure then c is == ')' */
1737 if (memchr("AD",s
[0],2)!=NULL
&& memchr("01234567",s
[1],8)!=NULL
)
1744 if (s
[0] == s
[-3] && s
[1] == s
[-2] + 1)
1751 "wrong register specification \"%s\" for argument %u\n",
1752 regs
[regcount
-1], regcount
1756 exitfileerror(20, "maximum four arguments passed in two registers allowed (%d, %s) \n", regcount
, regs
[regcount
-1]);
1762 "wrong register \"%s\" for argument %u\n",
1763 regs
[regcount
-1], regcount
1772 exitfileerror(20, "'(' without ')'\n");
1773 if (c
!= ',' && c
!= ')')
1774 exitfileerror(20, "',' or ')' expected at position %d\n", s
-line
+1);
1780 while (isspace(*s
)) s
++;
1782 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1784 if (argcount
!= regcount
)
1785 exitfileerror(20, "Number of arguments (%d) and registers (%d) mismatch\n",
1789 (*funclistptr
)->libcall
= REGISTERMACRO
;
1790 for (i
= 0; i
< argcount
; i
++)
1791 funcaddarg(*funclistptr
, args
[i
], regs
[i
]);
1793 else if (*s
== '\0')
1794 { /* No registers specified */
1795 for (i
= 0; i
< argcount
; i
++)
1796 funcaddarg(*funclistptr
, args
[i
], NULL
);
1799 exitfileerror(20, "wrong char '%c' at position %d\n", *s
, (int)(s
-line
) + 1);
1804 static void readsectionclass_methodlist(struct classinfo
*cl
)
1807 char *line
, *s
, *s2
;
1808 struct functionhead
**methlistptr
= &cl
->methlist
;
1809 struct stringlist
*interface
= NULL
;
1811 if (cl
->basename
==NULL
)
1812 exitfileerror(20, "section methodlist has to come after section config\n");
1818 exitfileerror(20, "unexptected EOF in methodlist section\n");
1820 /* Ignore empty lines or lines that qre a comment, e.g. that starts with a # */
1821 if (strlen(line
)==0 || (line
[0] == '#' && line
[1] != '#'))
1825 exitfileerror(20, "No space allowed at start of the line\n");
1827 if (strncmp(line
, "##", 2)==0) /* Is this the end ? */
1830 while (isspace(*s
)) s
++;
1831 if (strncmp(s
, "end", 3)!=0)
1832 exitfileerror(20, "\"##end methodlist\" expected\n");
1835 while (isspace(*s
)) s
++;
1836 if (strncmp(s
, "methodlist", 10)!=0)
1837 exitfileerror(20, "\"##end methodlist\" expected\n");
1840 while (isspace(*s
)) s
++;
1842 exitfileerror(20, "unexpected character on position %d\n", s
-line
);
1852 if (strncmp(s
, "alias", 5)==0)
1857 exitfileerror(20, "syntax is '.alias name'\n");
1859 while (isspace(*s
)) s
++;
1860 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1861 exitfileerror(20, "syntax is '.alias name'\n");
1865 while (isalnum(*s
) || *s
== '_') s
++;
1872 } while (isspace(*s
));
1876 exitfileerror(20, "syntax is '.alias name'\n");
1878 if (*methlistptr
== NULL
)
1879 exitfileerror(20, ".alias has to come after a function declaration\n");
1881 slist_append(&(*methlistptr
)->aliases
, s2
);
1883 else if (strncmp(s
, "function", 8) == 0)
1888 exitfileerror(20, "Syntax error\n");
1890 while (isspace(*s
)) s
++;
1891 if (*s
== '\0' || !(isalpha(*s
) || *s
== '_'))
1892 exitfileerror(20, "syntax is '.function name'\n");
1896 while (isalnum(*s
) || *s
== '_') s
++;
1903 } while (isspace(*s
));
1907 exitfileerror(20, "syntax is '.function name'\n");
1909 if (*methlistptr
== NULL
)
1910 exitfileerror(20, ".function has to come after a function declaration\n");
1912 funcsetinternalname(*methlistptr
, s2
);
1914 else if (strncmp(s
, "interface", 9) == 0)
1916 if (cl
->classtype
!= HIDD
)
1917 exitfileerror(20, "interface only valid for a HIDD\n");
1922 exitfileerror(20, "Syntax error\n");
1924 while (isspace(*s
)) s
++;
1925 if (*s
== '\0' || !isalpha(*s
))
1926 exitfileerror(20, "syntax is '.interface name'\n");
1930 while (isalnum(*s
) || *s
== '_') s
++;
1937 } while (isspace(*s
));
1941 exitfileerror(20, "syntax is '.interface name'\n");
1943 interface
= slist_append(&cl
->interfaces
, s2
);
1946 exitfileerror(20, "Syntax error");
1948 else if (isalpha(*line
))
1952 for (s
= line
+ 1; isalnum(*s
) || *s
== '_'; s
++)
1955 if (cl
->classtype
== HIDD
&& interface
== NULL
)
1956 exitfileerror(20, "For a HIDD the first method has to come after an .interface line\n");
1959 exitfileerror(20, "Only letters, digits and an underscore allowed in a methodname\n");
1961 if (*methlistptr
!= NULL
)
1962 methlistptr
= &((*methlistptr
)->next
);
1963 if (cl
->classtype
!= HIDD
)
1965 if (snprintf(stmp
, 256, "%s__%s", cl
->basename
, line
) >= 256)
1966 exitfileerror(20, "Method name too large\n");
1968 *methlistptr
= newfunctionhead(stmp
, STACK
);
1969 (*methlistptr
)->type
= "IPTR";
1970 funcaddarg(*methlistptr
, "Class *cl", NULL
);
1971 funcaddarg(*methlistptr
, "Object *o", NULL
);
1972 funcaddarg(*methlistptr
, "Msg msg", NULL
);
1976 if (snprintf(stmp
, 256, "%s__%s__%s", cl
->basename
, interface
->s
, line
) >= 256)
1977 exitfileerror(20, "Method name too large\n");
1979 *methlistptr
= newfunctionhead(stmp
, STACK
);
1980 (*methlistptr
)->type
= "IPTR";
1981 funcaddarg(*methlistptr
, "OOP_Class *cl", NULL
);
1982 funcaddarg(*methlistptr
, "OOP_Object *o", NULL
);
1983 funcaddarg(*methlistptr
, "OOP_Msg msg", NULL
);
1984 (*methlistptr
)->interface
= interface
;
1985 if (snprintf(stmp
, 256, "mo%s_%s", interface
->s
, line
) >= 256)
1986 exitfileerror(20, "Method name too large\n");
1987 (*methlistptr
)->method
= strdup(stmp
);
1989 slist_append(&(*methlistptr
)->aliases
, line
);
1992 exitfileerror(20, "Methodname has to begin with a letter\n");
1997 readsectioninterface(struct config
*cfg
)
2000 struct interfaceinfo
*in
;
2002 in
= newinterface(cfg
);
2003 s
= readsections(cfg
, NULL
, in
, 1);
2005 exitfileerror(20, "Unexpected end of file\n");
2007 if (strncmp(s
, "##", 2) != 0)
2008 exitfileerror(20, "'##end interface' expected\n");
2011 while (isspace(*s
)) s
++;
2013 if (strncmp(s
, "end", 3) != 0)
2014 exitfileerror(20, "'##end interface' expected\n");
2018 exitfileerror(20, "'##end interface' expected\n");
2019 while (isspace(*s
)) s
++;
2021 if (strncmp(s
, "interface", 9) != 0)
2022 exitfileerror(20, "'##end interface' expected\n");
2025 while (isspace(*s
)) s
++;
2027 exitfileerror(20, "'##end interface' expected\n");
2029 if (!in
->interfaceid
)
2030 exitfileerror(20, "interface has no 'interfaceid' defined!\n");
2032 if (!in
->interfacename
)
2033 exitfileerror(20, "interface has no 'interfacename' defined!\n");
2035 if (!in
->methodstub
)
2036 in
->methodstub
= strdup(in
->interfacename
);
2038 if (!in
->methodbase
) {
2039 int len
= strlen(in
->interfacename
);
2040 in
->methodbase
= malloc(len
+ 4 + 1);
2041 strcpy(in
->methodbase
, in
->interfacename
);
2042 strcat(in
->methodbase
, "Base");
2045 if (!in
->attributebase
) {
2046 int len
= strlen(in
->interfacename
);
2047 in
->attributebase
= malloc(len
+ 4 + 4 + 1);
2048 strcpy(in
->attributebase
, in
->interfacename
);
2049 strcat(in
->attributebase
, "AttrBase");
2054 readsectionclass(struct config
*cfg
)
2057 struct classinfo
*cl
;
2060 s
= readsections(cfg
, cl
, NULL
, 1);
2062 exitfileerror(20, "Unexpected end of file\n");
2064 if (strncmp(s
, "##", 2) != 0)
2065 exitfileerror(20, "'##end class' expected\n");
2068 while (isspace(*s
)) s
++;
2070 if (strncmp(s
, "end", 3) != 0)
2071 exitfileerror(20, "'##end class' expected\n");
2075 exitfileerror(20, "'##end class' expected\n");
2076 while (isspace(*s
)) s
++;
2078 if (strncmp(s
, "class", 5) != 0)
2079 exitfileerror(20, "'##end class' expected\n");
2082 while (isspace(*s
)) s
++;
2084 exitfileerror(20, "'##end class' expected\n");
2087 static struct classinfo
*newclass(struct config
*cfg
)
2089 struct classinfo
*cl
, *classlistit
;
2091 cl
= malloc(sizeof(struct classinfo
));
2094 fprintf(stderr
, "Out of memory\n");
2097 memset(cl
, 0, sizeof(struct classinfo
));
2099 /* By default the classes are initialized with a priority of 1 so they
2100 * are initialized before any user added initialization with priority 1
2104 if (cfg
->classlist
== NULL
)
2105 cfg
->classlist
= cl
;
2110 classlistit
= cfg
->classlist
;
2111 classlistit
->next
!= NULL
;
2112 classlistit
= classlistit
->next
2115 classlistit
->next
= cl
;
2121 static struct handlerinfo
*newhandler(struct config
*cfg
)
2123 struct handlerinfo
*hl
;
2125 hl
= calloc(1,sizeof(*hl
));
2126 hl
->next
= cfg
->handlerlist
;
2127 cfg
->handlerlist
= hl
;
2131 static struct interfaceinfo
*newinterface(struct config
*cfg
)
2133 struct interfaceinfo
*in
, *interfacelistit
;
2135 in
= malloc(sizeof(struct interfaceinfo
));
2138 fprintf(stderr
, "Out of memory\n");
2141 memset(in
, 0, sizeof(struct interfaceinfo
));
2143 if (cfg
->interfacelist
== NULL
)
2144 cfg
->interfacelist
= in
;
2149 interfacelistit
= cfg
->interfacelist
;
2150 interfacelistit
->next
!= NULL
;
2151 interfacelistit
= interfacelistit
->next
2154 interfacelistit
->next
= in
;
2161 static int getdirective(char *s
, const char *directive
, int range_min
, int range_max
, int *val
)
2166 if (strncmp(s
, directive
, strlen(directive
)) != 0)
2169 s
+= strlen(directive
);
2170 if (*s
&& !isspace(*s
))
2171 exitfileerror(20, "Unrecognized directive \".%s\"\n", directive
);
2173 while (isspace(*s
)) s
++;
2175 exitfileerror(20, "No .%s value specified\n", directive
);
2177 newval
= strtol(s
, &tmp
, 0);
2178 if (s
== tmp
|| !(newval
>= range_min
&& newval
<= range_max
)) {
2180 while (*tmp
&& !isspace(*tmp
)) tmp
++;
2181 exitfileerror(20, "Invalid .%s value of %.*s\n", directive
, tmp
- s
, s
);
2189 readsectionhandler(struct config
*cfg
)
2191 char *line
= NULL
, *s
;
2192 struct handlerinfo
*hl
;
2193 unsigned char autolevel
= 0;
2194 unsigned int stacksize
= 0;
2198 int has_filesystem
= 0;
2206 s
= line
= readline();
2209 exitfileerror(20, "unexpected end of file in section hanlder\n");
2211 if (strncmp(s
, "##", 2)==0)
2214 /* Ignore comments */
2215 if (strncmp(s
, "#", 1)==0)
2218 /* Skip ahead to function name */
2219 while (*s
&& isspace(*s
)) s
++;
2221 /* Permit blank lines */
2229 if (getdirective(s
, "autodetect", 0, 127, &val
)) {
2231 } else if (getdirective(s
, "stacksize", 0, INT_MAX
, &val
)) {
2233 } else if (getdirective(s
, "priority", -128, 127, &val
)) {
2235 } else if (getdirective(s
, "bootpri", -128, 127, &val
)) {
2237 } else if (getdirective(s
, "startup", INT_MIN
, INT_MAX
, &val
)) {
2240 exitfileerror(20, "Unrecognized directive \"%s\"\n", line
);
2246 unsigned int id
= 0;
2248 if (strncasecmp(s
,"resident=",9)==0) {
2251 s
= strchr(s
, '=') + 1;
2253 while (*s
&& !isspace(*s
)) s
++;
2255 exitfileerror(20, "Empty resident= is not permitted\n");
2260 hl
= newhandler(cfg
);
2261 hl
->type
= HANDLER_RESIDENT
;
2263 hl
->name
= strdup(res
);
2264 hl
->autodetect
= autolevel
--;
2265 hl
->stacksize
= stacksize
;
2266 hl
->priority
= priority
;
2267 hl
->startup
= startup
;
2268 } else if (strncasecmp(s
,"dosnode=",8)==0) {
2271 s
= strchr(s
, '=') + 1;
2273 while (*s
&& !isspace(*s
)) s
++;
2275 exitfileerror(20, "Empty dosnode= is not permitted\n");
2280 hl
= newhandler(cfg
);
2281 hl
->type
= HANDLER_DOSNODE
;
2283 hl
->name
= strdup(dev
);
2284 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2285 hl
->stacksize
= stacksize
;
2286 hl
->priority
= priority
;
2287 hl
->startup
= startup
;
2288 hl
->bootpri
= bootpri
;
2289 } else if (strncasecmp(s
,"dostype=",8) == 0) {
2290 s
= strchr(s
, '=') + 1;
2292 id
= (unsigned int)strtoul(s
, &tmp
, 0);
2295 while (*tmp
&& !isspace(*tmp
))
2297 exitfileerror(20, "\"%.*s\" is not a numerical DOS ID\n", (tmp
-s
), s
);
2301 if (id
== 0 || id
== ~0) {
2302 exitfileerror(20, "DOS ID 0x%08x is not permitted\n", id
);
2305 hl
= newhandler(cfg
);
2306 hl
->type
= HANDLER_DOSTYPE
;
2309 hl
->autodetect
= autolevel
? autolevel
-- : 0;
2310 hl
->stacksize
= stacksize
;
2311 hl
->priority
= priority
;
2312 hl
->startup
= startup
;
2314 for (tmp
= s
; !isspace(*tmp
); tmp
++);
2315 exitfileerror(20, "Unknown option \"%.*s\"\n", tmp
- s
, s
);
2318 /* Advance to next ID */
2319 while (*s
&& isspace(*s
)) s
++;
2325 exitfileerror(20, "Unexpected end of file\n");
2327 if (strncmp(s
, "##", 2) != 0)
2328 exitfileerror(20, "'##end handler' expected\n");
2331 while (isspace(*s
)) s
++;
2333 if (strncmp(s
, "end", 3) != 0)
2334 exitfileerror(20, "'##end handler' expected\n");
2337 while (isspace(*s
)) s
++;
2339 if (strncmp(s
, "handler", 7) != 0)
2340 exitfileerror(20, "'##end handler' expected\n");
2343 while (isspace(*s
)) s
++;
2345 exitfileerror(20, "'##end handler' expected\n");