static void generate_enum( FILE *ofp2) { MYDATA *p; static const char *const table_1[] = { "enum option_enum {", 0 }; static const char *const table_2[] = { "\tSIGNAL_HANDLER };", "", "#define LAST_OPT SIGNAL_HANDLER - 1", 0 }; /* generate enumerated type */ write_it(ofp2, table_1); for (p = all_data; p != 0; p = p->link) { if (p->name[0] == '#') fprintf(ofp2, "%s\n", p->name); else { char *s = p->name; fprintf(ofp2, "\tOPT_"); while (*s != '\0') { fprintf(ofp2, "%c", isalpha ((unsigned char)*s) && islower((unsigned char)*s) ? toupper ((unsigned char)*s) : *s); s++; } fprintf(ofp2, ",\n"); } } write_it(ofp2, table_2); }
rtems_task Init( rtems_task_argument argument ) { TEST_BEGIN(); pppasyncattach(); open_it(); set_wakeups(); set_discipline(); write_it(); ioctl_it(); read_it(); close_it(); TEST_END(); rtems_test_exit(0); }
static void makecfg( FILE *ifp, FILE *ofp, FILE *ofp2) { char buffer[BUFSIZ]; MYDATA *p, *q; static const char *const table_1[] = { "/* This file is generated by MAKECFG */" ,"" ,"#ifndef TINCFG_H" ,"#define TINCFG_H 1" ,"" ,"/* Macros for defining symbolic offsets that can be ifdef'd */" ,"#undef OINX" ,"#undef OVAL" ,"#undef OEND" ,"#undef OTYP" ,"" ,"#ifdef lint" ,"#\tdefine OINX(T, M) 0 /* 'lint -c' cannot be appeased */" ,"#\tdefine OVAL(T, M) char M;" ,"#\tdefine OEND(T, M) char M;" ,"#\tdefine OTYP struct" ,"#else" ,"#\tifdef CPP_DOES_CONCAT" ,"#\t\tdefine OINX(T, M) T ## M" ,"#\t\tdefine OVAL(T, M) T ## M," ,"#\t\tdefine OEND(T, M) T ## M" ,"#\t\tdefine OTYP enum" ,"#\telse" ,"#\t\tdefine OINX(T, M) \\" ,"\t\t\t(((int)&(((T*)0)->M))/ \\" ,"\t\t\t ((int)&(((T*)0)->Q1) - (int)&(((T*)0)->s_MAX)))" ,"#\t\tdefine OVAL(T, M) char M;" ,"#\t\tdefine OEND(T, M) char M;" ,"#\t\tdefine OTYP struct" ,"#\tendif /* CPP_DOES_CONCAT */" ,"#endif /* lint */" ,0 }; static const char *const table_2[] = { "" ,"/* We needed these only to make the table compile */" ,"#undef OINX" ,"#undef OVAL" ,"#undef OEND" ,"#undef OTYP" ,"" ,"#endif /* TINCFG_H */" ,0 }; static const char *const table_3[] = { "/* This file is generated by MAKECFG */", "", "#ifndef OPTIONS_MENU_H", "#define OPTIONS_MENU_H 1", "", 0 }; static const char *const table_4[] = { "", "#endif /* OPTIONS_MENU_H */", 0 }; /* * Process the input file. */ line_no = 0; while (fgets(buffer, sizeof(buffer) - 1, ifp)) parse_tbl(buffer); fclose(ifp); /* * Generate the output file */ write_it(ofp, table_1); /* * For each type used in the table, generate a list of pointers to * that type. */ for (p = all_data; p != 0; p = p->link) { int found = FALSE; if (p->name[0] == '#') continue; if (type_is_int(p) || is_title(p)) continue; for (q = all_data; p != q; q = q->link) { if (!strcmp(p->type, q->type)) { found = TRUE; break; } } if (!found && !strncmp(p->type, "OPT_", 4)) { generate_ptr (ofp, p->type, typename_of(p), 0); generate_ptr (ofp, p->type, typename_of(p), 1); generate_ptr (ofp, p->type, typename_of(p), 2); } } generate_tbl(ofp); write_it(ofp, table_2); fclose(ofp); if (ofp2) { write_it(ofp2, table_3); generate_enum(ofp2); write_it(ofp2, table_4); fclose(ofp2); } }
static void generate_tbl( FILE *ofp) { static const char *const table_1[] = { "" ,"#define OPT_TITLE 0" ,"#define OPT_ON_OFF 1" ,"#define OPT_LIST 2" ,"#define OPT_STRING 3" ,"#define OPT_NUM 4" ,"#define OPT_CHAR 5" ,"" ,"struct t_option option_table[]={" ,0 }; static const char *const table_2[] = { "};" ,0 }; static const char prefix[] = " { "; static const char suffix[] = "},"; MYDATA *p; char temp[BUFSIZ]; /* generate the access table */ write_it(ofp, table_1); for (p = all_data; p != 0; p = p->link) { if (p->name[0] == '#') fprintf(ofp, "%s\n", p->name); else { int is_opt = !strncmp(p->type, "OPT_", 4); int is_int = type_is_int(p); char *dft_name = p->name; /* TODO: is this still necessary? */ /* shorten message-variable names */ if (!strncmp(dft_name, "default_", 8)) dft_name += 8; else if (!strncmp(dft_name, "attrib_", 7)) dft_name += 7; fprintf(ofp, "%s", prefix); sprintf(temp, "%s,", is_opt ? p->type : "OPT_LIST"); fprintf(ofp, "%-13s", temp); if (is_title(p)) { fprintf(ofp, "0, NULL, "); } else if (!is_int) { fprintf(ofp, "OINX_%s, 0, ", p->name); } else { fprintf(ofp, "0, &tinrc.%s, ", p->name); } if (is_opt) fprintf(ofp, "NULL, "); else fprintf(ofp, "%s, ", p->type); fprintf(ofp, "&txt_%s ", dft_name); fprintf(ofp, "%s\n", suffix); } } write_it(ofp, table_2); }