00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 # include "incls/_precompiled.incl"
00025 # include "incls/_arguments.cpp.incl"
00026 # include <ctype.h>
00027
00028
00029
00030
00031
00032
00033 char* boot_filename = SYSTEM_NAME ".bst";
00034 char* rc_filename = "." SYSTEM_NAME "rc";
00035
00036 static void set_bool_flag(char* name, bool value) {
00037 bool s = value;
00038 if (!debugFlags::boolAtPut(name, &s))
00039 fprintf(stderr, "Boolean flag %s unknown.\n", name);
00040 }
00041
00042 static void set_int_flag(char* name, int value) {
00043 int v = value;
00044 if (!debugFlags::intAtPut(name, &v))
00045 fprintf(stderr, "Integer flag %s unknown.\n", name);
00046 }
00047
00048 static void process_token(char* token) {
00049 if (token[0] == '-') set_bool_flag(&token[1], false);
00050 else if (token[0] == '+') set_bool_flag(&token[1], true);
00051 else {
00052 char name[100];
00053 int value;
00054 if (sscanf(token, "%[a-zA-Z]=%d", name, &value) == 2) {
00055 set_int_flag(name, value);
00056 }
00057 }
00058 }
00059
00060 void process_settings_file(char* file_name, bool quiet) {
00061 FILE* stream = fopen(file_name, "rb");
00062 if (stream == NULL) {
00063 if (quiet) return;
00064 fprintf(stderr, "Could not open %s\n", file_name);
00065 exit(-1);
00066 }
00067
00068 char token[1024];
00069 int pos = 0;
00070
00071 bool in_white_space = true;
00072 bool in_comment = false;
00073
00074 int c = getc(stream);
00075 while(c != EOF) {
00076 if (in_white_space) {
00077 if (in_comment) {
00078 if (c == '\n') in_comment = false;
00079 } else {
00080 if (c == '#') in_comment = true;
00081 else if (!isspace(c)) {
00082 in_white_space = false;
00083 token[pos++] = c;
00084 }
00085 }
00086 } else {
00087 if (isspace(c)) {
00088 token[pos] = '\0';
00089 process_token(token);
00090 pos = 0;
00091 in_white_space = true;
00092 } else {
00093 token[pos++] = c;
00094 }
00095 }
00096 c = getc(stream);
00097 }
00098 if (pos>0) {
00099 token[pos] = '\0';
00100 process_token(token);
00101 }
00102 fclose(stream);
00103 }
00104
00105 void print_credits() {
00106
00107
00108 const char credits[] = "\
00109 \x11\x5a\x04\x1e\x7a\x76\x08\x38\x0b\x6e\x5b\x50\x1e\x04\x2e\x34\x6b\x21\x47\x2e\
00110 \x73\x57\x41\x7b\x65\x18\x3c\x54\x03\x2e\x79\x0e\x1a\x49\x17\x1f\x2f\x44\x45\x73\
00111 \x75\x21\x7e\x5c\x00\x11\x6a\x53\x5b\x3a\x43\x3e\x7e\x5b\x08\x29\x1a\x4c\x1d\x53\
00112 \x13\x22\x73\x0e\x1a\x49\x1f\x1e\x2d\x5b\x05\x37\x0b\x6e\x49\x4b\x01\x45\x02\x7b\
00113 \x4c\x3f\x5c\x21\x7e\x3c\
00114 ";
00115 int mask = 0xa729b65d;
00116 for (int i = 0; i < sizeof(credits) - 1; i++) {
00117 fputc((credits[i] ^ mask) & 0x7f, stdout);
00118 mask = (mask << 1) | (mask >> 31) & 1;
00119 }
00120 }
00121
00122 void parse_arguments(int argc, char* argv[]) {
00123 bool parse_files = true;
00124
00125 if (argc > 1 && strcmp(argv[1], "-t") == 0) {
00126 fprintf(stdout, "Timers turned off, flags file and -f arguments are ignored.\n");
00127 UseTimers = false;
00128 EnableTasks = false;
00129 parse_files = false;
00130 }
00131
00132 if (parse_files) {
00133 process_settings_file(rc_filename, true);
00134 }
00135
00136 for (int index = parse_files ? 1 : 2; index < argc; index++) {
00137 if (strcmp(argv[index], "-?") == 0) {
00138 debugFlags::printFlags();
00139 exit(0);
00140 } else if (strcmp(argv[index], "-credits") == 0) {
00141 print_credits();
00142 exit(0);
00143 } else if (strcmp(argv[index], "-b") == 0) {
00144 index++;
00145 if (index >= argc) {
00146 fprintf(stderr, "file name expected after '-b'\n");
00147 exit(-1);
00148 }
00149 boot_filename = argv[index];
00150 } else if (strcmp(argv[index], "-f") == 0) {
00151 index++;
00152 if (index >= argc) {
00153 fprintf(stderr, "file name expected after '-f'\n");
00154 exit(-1);
00155 }
00156 if (parse_files) {
00157 process_settings_file(argv[index]);
00158 }
00159 } else process_token(argv[index]);
00160 }
00161 }