void *main_thread(void *) { #ifdef SIMU_EXCEPTIONS signal(SIGFPE, sig); signal(SIGSEGV, sig); try { #endif eeReadAll(); //load general setup and selected model if (main_thread_running == 1) { checkMem(); //enough eeprom free? checkTHR(); checkSwitches(); //must be last } chainMenu(menuProc0); //call evt_entry while (main_thread_running) { perMain(); sleep(1/*ms*/); } #ifdef SIMU_EXCEPTIONS } catch (...) { main_thread_running = 0; } #endif return NULL; }
int main(int argc, char *argv[]) { char line[MAXLINE]; //create an array that keeps track of where switches are //initialize it with values of -1 int isSwitch[argc]; for (int i = 0; i < argc; i++) { isSwitch[i] = -1; } isSwitch[0] = 1; //if one of the arguments is --help, print the help page and exit for (int i = 1; i < argc; i++) { if (strcmp("--help", argv[i]) ==0 ) { FILE *help; if ((help = fopen("help.txt", "r")) != NULL ) { for (;;) { fgets(line, sizeof(line), help); if(feof(help)) { break; } printf("%s", line); } fclose(help); } return 0; } } //if there is only one input, then just take standard input if (argc == 1) { fgets(line, sizeof(line), stdin); while (!feof(stdin)) { takeInput(line); fgets(line, sizeof(line), stdin); } return 0; } //call the function that finds switches checkSwitches(argv, isSwitch, argc); //check for any errors if (error == 1) return 1; //check for a bad mapfile if (badMap == 1) { printf("Error: invalid map file. The map file a list of characters."); printf(" Each character must be separated by a space.\n"); return 1; } //if there are only switches, take standard input if (allSwitches(isSwitch, argc) == 1) { fgets(line, sizeof(line), stdin); while (!feof(stdin)) { generateOutput(line); fgets(line, sizeof(line), stdin); } return 0; } /* Now we know there is more than one argument, so we'll go through the arguments */ int z = 1; while (z < argc ) { //make sure that the argument we're on is not a switch if ( isSwitch[z] != 1) { //check if the argument is a hypen or if there are no arguments // except switches, meaning we stop and collect terminal output if (argv[z][0] == '-' ) { fgets(line, sizeof(line), stdin); while (!feof(stdin)) { generateOutput(line); fgets(line, sizeof(line), stdin); } } //if the argument is not a hyphen, it's a file else if ((fp = fopen( argv[z], "r")) != NULL ) { for (;;) { fgets(line, sizeof(line), fp); if(feof(fp)) { break; } generateOutput(line); } fclose(fp); } //otherwise, the argument is an invalid file else { printf("Error: No such file %s\n", argv[z]); break; } } z++; } return 0; }