int main(int argc, char **argv) { if (argc == 2) { if (init_scanner(argv[1])) return EOF; } else { if (init_scanner(NULL)) return EOF; } int ret; do { ret = get_token(); #ifdef SCANNER_DEBUG if (token.type == TT_VALUE_INT) printf("\n%d Typ: %s %d\n", ret, token_name[token.type], token.value_int); else if (token.type == TT_VALUE_DOUBLE) printf("\n%d Typ: %s %lf\n", ret, token_name[token.type], token.value_double); else printf("\n%d Typ: %s %s\n", ret, token_name[token.type], strGetStr(buffer)); #endif // DEBUG } while (ret != ERR_SCANNER && ret != EOF); if(clean_scanner()) return EOF; return 0; }
int main(int argc, char **argv) { if (argc != 2) { // argv[0] == interpret // argv[1] == filename // and nothing else! fprintf(stderr, "Wrong number of arguments\n"); return ERR_INTERPRET; } // try to open file if (init_scanner(argv[1]) != OK) { fprintf(stderr, "Cannot open file\n"); return ERR_INTERPRET; } int err; err = initialize_global_symbol_table(); if (err != OK) return err; err = init_tac(); if (err != OK) return err; err = parse(); if (err == OK) { err = every_func_defined(); if (err == OK) { Tglobal_sym_tab_node *m = get_func("main"); err = run_tac(m->func_start, m->var_count); } else { fprintf(stderr, "Undefined function\n"); } } else if (err == ERR_PARSER) { fprintf(stderr, "Syntax error: line %d, column before %d\n", row+1, col); } else if (err == ERR_SCANNER) { // Lexikalni vypisuje scanner sam // fprintf(stderr, "Lexical error: line %d, column before %d\n", row+1, col); } else if (err == ERR_SEMANTIC || err == ERR_UNDEF || err == ERR_TYPE || err == ERR_AUTO) { fprintf(stderr, "Semantic error: line %d, column before %d\n", row+1, col); } else if (err == ERR_NUMBER || err == ERR_VARINIT || err == ERR_ZERODIV || err == ERR_RUN) { fprintf(stderr, "Runtime error: line %d, column before %d\n", row+1, col); } else if (err == ERR_INTERPRET) { fprintf(stderr, "Internal error: line %d, column before %d\n", row+1, col); } else { fprintf(stderr, "Unknown error: line %d, column before %d\n", row+1, col); } free_tac(); free_global_symbol_table(); clean_scanner(); //fprintf(stderr, "%d\n", err); return err; }
*/ RefParseContext::RefParseContext( Trick::MemoryManager *in_mem_mgr, std::istream* in_is = &std::cin ) { // Set verif input and echo input flags. verify_input = 0; echo_input = 1; // Initialize the scanner init_scanner(); this->is = in_is; this->mem_mgr = in_mem_mgr; }
int SickTimCommon::init() { int result = init_device(); if(result != 0) { ROS_FATAL("Failed to init device: %d", result); return result; } result = init_scanner(); if(result != 0) { ROS_FATAL("Failed to init scanner: %d", result); } return result; }
static void update_db(FILE *db, FILE *temp_db, FILE *new_file, char *addname, char *fullname, int fresh) { char *fname; int c, file_there = 0, mtime; if (fresh) { add_new_pages(db, new_file, addname, fullname); return; } if (db == NULL) { add_new_pages(temp_db, new_file, addname, fullname); return; } init_scanner(); cfile = db; c = get_char(); do { if (c == '\t') { get_filename(); fname = alloc_string(token.id); get_token(); mtime = atoi(token.id); if (strcmp(fname, addname) == 0) { save_scanner_state(); add_new_pages(temp_db, new_file, addname, fullname); restore_scanner_state(); file_there = 1; while ((c = get_char()) != EOF) { if (c == '\t') break; } } else { fprintf(temp_db, "\t%s %d", fname, mtime); while ((c = get_char()) != EOF) { if (c == '\t') break; putc(c, temp_db); } } free(fname); } else c = get_char(); } while (c != EOF); if (!file_there) { add_new_pages(temp_db, new_file, addname, fullname); } }
int main() { int token = 1; init_scanner(); while(token != -1) { token = getSymbol(); printf("Token: %s (%d)\n", get_token_name(token), token); //if(token == IDENTIFIER) printf("\t'%s'\n", intstr_to_charstr(identifier)); //if(token == INTEGER) printf("\t%d\n", integer); } return EXIT_SUCCESS; }
SCANNER* new_scanner( char *spr ) { SCANNER *scanner; scanner = (SCANNER *) malloc( sizeof(SCANNER) ); if (scanner != NULL) { if (!init_scanner(scanner, spr)) { free(scanner); scanner = NULL; } } return scanner; }
int main(int argc, const char * argv[]) { char token; char source_name[MAX_FILE_NAME_LENGTH]; char date[DATE_STRING_LENGTH]; FILE *source_file = init_lister(argv[1], source_name, date); init_scanner(source_file, source_name, date); do { token = get_token(); } while (token != '.'); //loop ends when a period is found returning the char 0 return 0; }
static void add_new_pages(FILE *temp_db, FILE *new_file, char *addname, char *fullname) { char type[15]; int pos; int present_type; int pages = 0; struct stat fstats; stat(fullname, &fstats); fprintf(temp_db, "\t%s %d\n", addname, (int)fstats.st_mtime); cfile = new_file; init_scanner(); while (get_token() != EOF) { if (Special(token.type)) { ptype(type, token.id); present_type = token.type; pos = keyword_fpos; get_token(); if (token.type != Lbrace) { fprintf(stderr, "missing left brace after a page, macro or patch \ declaration\n"); fprintf(stderr, "In the file %s on line %d\n", fullname, line_number); exit(-1); } get_token(); if (present_type == Page && token.type != Word) { fprintf(stderr, "missing page name after \\begin{page}\n"); fprintf(stderr, "In the file %s on line %d\n", fullname, line_number); exit(-1); } else if (present_type == Macro && token.type != Macro) { fprintf(stderr, "Expected a \\macro name after newcommand, got %s\n", token.id); fprintf(stderr, "In the file %s on line %d\n", fullname, line_number); exit(-1); } else if (present_type == Patch && token.type != Word) { fprintf(stderr, "Missing patch name after a \\begin{patch}\n"); fprintf(stderr, "In the file %s on line %d\n", fullname, line_number); exit(-1); } fprintf(temp_db, "\\%s %s %d %d\n", type, token.id, pos, line_number); pages++; }
/** Constructor */ ChkPtParseContext::ChkPtParseContext( Trick::MemoryManager *mem_mgr, std::istream* is = &std::cin ) { // Set verif input and echo input flags. verify_input = 0; echo_input = 0; // Initialize the scanner init_scanner(); this->buf = (char*)calloc( 0xffff, sizeof(char)); this->bad_declaration_count = 0; this->bad_assignment_count = 0; this->is = is; this->mem_mgr = mem_mgr; }
int main(int argc, const char * argv[]) { Token *token; Token *token_list; //This needs to be implemented as a linked list in scanner.h. char source_name[MAX_FILE_NAME_LENGTH]; char date[DATE_STRING_LENGTH]; FILE *source_file = init_lister(argv[1], source_name, date); init_scanner(source_file, source_name, date); do { token = get_token(); add_token_to_list(token_list, token); print_token(token); } while (???);//What is the sentinal value that ends this loop? quit_scanner(source_file, token_list); return 0; }
int main(int argc, const char *argv[]) { Token *token; // Token *token_list; //This needs to be implemented as a linked list in scanner.h. char source_name[MAX_FILE_NAME_LENGTH]; char date[DATE_STRING_LENGTH]; FILE *source_file; source_file = init_lister(argv[1], source_name, date); init_scanner(source_file, source_name, date); do { token = get_token(); // add_token_to_list(token_list, token); print_token(token); } while ((* token).tCode != END_OF_FILE); //quit_scanner(source_file, token_list); return 0; }
int main(int argc, const char * argv[]) { Token *token; Token *token_list; char source_name[MAX_FILE_NAME_LENGTH]; char date[DATE_STRING_LENGTH]; FILE *source_file = init_lister(argv[1], source_name, date); init_scanner(source_file, source_name, date); init_scanner2(source_name, date); token_list = malloc(sizeof(Token)); token_list->nextptr = NULL; do { token = get_token(); add_token_to_list(token_list, token); print_token(token); } while (token->token_string[0] != '.'); quit_scanner(source_file, token_list); return 0; }
void test_parse_rcp(void) { GScanner *scan; FILE *fp; GTokenType tok; fp = fopen("test.rcp", "r"); if (fp == NULL) { err_printf("cannot open test.rcp\n"); return; } scan = init_scanner(); g_scanner_input_file(scan, fileno(fp)); do { tok = g_scanner_get_next_token(scan); print_token(scan, tok); } while (tok != G_TOKEN_EOF); g_scanner_destroy(scan); }
PHP_context::PHP_context(std::istream& input, String* filename) : stream (input) { init_scanner(NULL); php_script = NULL; current_method = new String(""); current_class = new String(""); this->filename = filename; source_line = 1; mt_index = 0; mt_count = 0; last_commented_node = NULL; hash_bang = NULL; attach_to_previous = false; after_arrow = false; starts_line = true; heredoc_attr = NULL; }
static void load_patch(PatchStore *patch) { long start_fpos; int size = 0; int limsize; char *trace; save_scanner_state(); cfile = find_fp(patch->fpos); init_scanner(); /** First thing I should do is make sure that the name is correct ***/ start_fpos = fpos; get_expected_token(openaxiom_Patch_token); get_expected_token(openaxiom_Lbrace_token); get_expected_token(openaxiom_Word_token); if (strcmp(token.id, patch->name)) { /** WOW, Somehow I had the location of the wrong macro **/ fprintf(stderr, "(HyperDoc) Expected patch name %s: got instead %s in load_patch\n", patch->name, token.id); jump(); } get_expected_token(openaxiom_Rbrace_token); scan_HyperDoc(); fseek(cfile, patch->fpos.pos + start_fpos, 0); limsize = fpos - start_fpos + 1; patch->string = (char *) halloc((limsize + 1) * sizeof(char), "Patch String"); for (size = 1, trace = patch->string; size < limsize; size++) *trace++ = getc(cfile); *trace = '\0'; patch->loaded = 1; restore_scanner_state(); }
void get_new_window() { int val; char buf[128]; int frame; Window wid; HDWindow *htw; HyperDocPage *hpage; /* * If I am going to try and start a new window, then I should make sure I * have a coonection to listen on * * BUT This code is entered when a socket selects * * if (spad_socket == NULL) { spad_socket = * connect_to_local_server(SpadServer, MenuServer, 10); if (spad_socket * == NULL) { fprintf(stderr, "Get_new_window: Couldn't Connect to * SpadServer\n"); return -1; } } * */ frame = get_int(spad_socket); val = get_int(spad_socket); switch (val) { case StartPage: init_top_window(NULL); val = get_int(spad_socket); init_scanner(); input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); gWindow->fAxiomFrame = frame; XFlush(gXDisplay); break; case LinkToPage: get_string_buf(spad_socket, buf, 128); if (init_top_window(buf) == -1) { fprintf(stderr, "get_new_window: Did not find page %s\n", buf); /* return -1; */ } gWindow->fAxiomFrame = frame; break; case PopUpPage: val = get_int(spad_socket); init_form_window(NULL, val); send_int(spad_socket, gWindow->fMainWindow); init_scanner(); input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); compute_form_page(gWindow->page); XMapWindow(gXDisplay, gWindow->fMainWindow); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; gWindow->fAxiomFrame = frame; XFlush(gXDisplay); break; case PopUpNamedPage: val = get_int(spad_socket); get_string_buf(spad_socket, buf, 128); if (init_form_window(buf, val) == -1) { send_int(spad_socket, -1); break; } load_page(gWindow->page); compute_form_page(gWindow->page); XMapWindow(gXDisplay, gWindow->fMainWindow); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; gWindow->fAxiomFrame = frame; XFlush(gXDisplay); send_int(spad_socket, gWindow->fMainWindow); /* fprintf(stderr, "Window Id was %d\n", gWindow->fMainWindow); */ break; case ReplaceNamedPage: wid = (Window) get_int(spad_socket); get_string_buf(spad_socket, buf, 128); htw = (HDWindow *) hash_find(&gSessionHashTable,(char *)&wid); if (htw == NULL) break; hpage = (HyperDocPage *) hash_find(gWindow->fPageHashTable, buf); if (hpage == NULL) break; gWindow = htw; gWindow->page = hpage; display_page(gWindow->page); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; clear_exposures(gWindow->fMainWindow); clear_exposures(gWindow->fScrollWindow); XFlush(gXDisplay); break; case ReplacePage: wid = (Window) get_int(spad_socket); set_window(wid); init_scanner(); input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); display_page(gWindow->page); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; clear_exposures(gWindow->fMainWindow); clear_exposures(gWindow->fScrollWindow); XFlush(gXDisplay); break; case KillPage: /* Here the user wishes to kill the page */ wid = (Window) get_int(spad_socket); htw = (HDWindow *) hash_find(&gSessionHashTable,(char *)&wid); if (htw !=NULL) { gWindow = htw; exitHyperDoc(); break; } break; } }
/* * Log message callback function. * * Arguments: log_level is the level to log, message is the message to log. */ static void log_message(int log_level, char *message) { int status = 0; char *response = NULL; if (log_level <= _log_level) { pam_syslog(_pam_handle, log_level, "%s", message); } if (log_level == LOG_NOTICE && _silent_operation == FALSE) { const struct pam_message info_message = { .msg_style = PAM_TEXT_INFO, .msg = message, }; const struct pam_message *message_pointer = &info_message; struct pam_response pam_response = { .resp = response, .resp_retcode = 0, }; struct pam_response *response_pointer = &pam_response; const struct pam_conv *pam_conversation = NULL; status = pam_get_item(_pam_handle, PAM_CONV, (const void **)&pam_conversation); if (status != PAM_SUCCESS || !pam_conversation || !pam_conversation->conv) { pam_syslog(_pam_handle, LOG_NOTICE, "error getting PAM conversation handle: %s", pam_strerror(_pam_handle, status)); } else { status = pam_conversation->conv(1, &message_pointer, &response_pointer, pam_conversation->appdata_ptr); if (status != PAM_SUCCESS) pam_syslog(_pam_handle, LOG_NOTICE, "error encountered sending message to user: %s", pam_strerror(_pam_handle, status)); } if(pam_response.resp != NULL) free((void *)pam_response.resp); //to satisfy splint: message shouldn't ever change. if(info_message.msg != message) free((void *)info_message.msg); } } PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) { const char *rhost = NULL; char *rfid_code = NULL; int pam_function_result = PAM_SUCCESS; int scan_result = 0; char buffer[9] = "........"; //set some configuration defaults unsigned int timeout = 10; unsigned int sleep_increment = 1; //sanity checks pam_function_result = pam_get_item(pamh, PAM_RHOST, (const void **)&rhost); if(pam_function_result != PAM_SUCCESS) { pam_syslog(_pam_handle, LOG_ERR, "failed to obtain remote host information during sanity check: %s", pam_strerror(_pam_handle, pam_function_result)); return pam_function_result; } if (rhost != NULL && strlen(rhost) > 0) { //remote login (e.g. over SSH) pam_syslog(_pam_handle, LOG_INFO, "remote login--aborting."); return PAM_AUTHINFO_UNAVAIL; } _pam_handle = pamh; //process module arguments for ( ; argc-- > 0; ++argv) { if(strcmp(*argv, "debug") == 0) { _log_level = LOG_DEBUG; } else if(strcmp(*argv, "silent") == 0 || (flags & PAM_SILENT) == PAM_SILENT) { _silent_operation = TRUE; } else if (strcmp(strncpy(buffer, *argv, 8), "timeout=") == 0) { unsigned int val = (unsigned int)atoi(*argv + 8); if (val == 0) { pam_syslog(_pam_handle, LOG_ERR, "invalid timeout specified: %s", *argv + 8); } else { timeout = val; } } else { pam_syslog(_pam_handle, LOG_ERR, "unrecognized argument: %s", *argv); } } //let's get to it if (init_scanner(&log_message, 1) != 0) { pam_syslog(_pam_handle, LOG_NOTICE, "no scanner detected, exiting."); return PAM_AUTHINFO_UNAVAIL; } scan_result = scan_tag(&rfid_code, timeout, sleep_increment); close_scanner(); //process scan results if(scan_result == 1 && rfid_code != NULL) { pam_syslog(_pam_handle, LOG_NOTICE, "authentication token acquired."); pam_function_result = pam_set_item(pamh, PAM_AUTHTOK, (void *)rfid_code); if(pam_function_result != PAM_SUCCESS) { pam_syslog(_pam_handle, LOG_ERR, "error while setting PAM auth token to scanned RFID code: %s", pam_strerror(_pam_handle, pam_function_result)); return pam_function_result; } pam_syslog(_pam_handle, LOG_DEBUG, "authentication token passed to PAM."); free(rfid_code); return PAM_IGNORE; } else { pam_syslog(_pam_handle, LOG_NOTICE, "authentication failed."); return PAM_AUTHINFO_UNAVAIL; } } PAM_EXTERN int pam_sm_setcred(/*@unused@*/pam_handle_t *pamh, /*@unused@*/int flags, /*@unused@*/int argc, /*@unused@*/const char **argv) { //Phidget scanner doesn't support re-programming of RFID tags, //and we don't have any way of changing the down-stream authentication schemes return PAM_SUCCESS; }
/* read a star file frame (one s-expression) from the given file pointer, and return the stf of the root node */ struct stf *stf_read_frame(FILE *fp) { GScanner *scan; GTokenType tok; int level = 0; int minus = 0; GList *sl; struct stf *ret = NULL; struct stf *lstf[STF_MAX_DEPTH]; struct stf *stf=NULL, *nstf = NULL; lstf[0] = NULL; scan = init_scanner(); g_scanner_input_file(scan, fileno(fp)); do { tok = g_scanner_get_next_token(scan); // d3_printf("level %d ", level); // print_token(scan, tok); if (level == 0 && tok != '(') continue; if (level == 1 && tok == ')') { ret = lstf[0]; break; } if (minus) minus --; switch(tok) { case '(': if (level >= STF_MAX_DEPTH - 1) break; nstf = stf_new(); lstf[level] = nstf; if (level > 0) { stf->next = nstf; STF_SET_LIST(nstf, stf_new()); stf = STF_LIST(nstf); } else { stf = nstf; } level ++; break; case ')': stf = lstf[level-1]; level --; break; case G_TOKEN_SYMBOL: if (!STF_IS_NIL(stf)) { nstf = stf_new(); stf->next = nstf; stf = nstf; } STF_SET_SYMBOL(stf, intval(scan)); if (intval(scan) == SYM_STARS) { sl = read_star_list(scan); if (sl == NULL) break; nstf = stf_new(); stf->next = nstf; stf = nstf; STF_SET_GLIST(stf, sl); } break; case '-': minus = 2; break; case G_TOKEN_FLOAT: if (!STF_IS_NIL(stf)) { nstf = stf_new(); stf->next = nstf; stf = nstf; } STF_SET_DOUBLE(stf, minus?-floatval(scan):floatval(scan)); break; case G_TOKEN_STRING: if (!STF_IS_NIL(stf)) { nstf = stf_new(); stf->next = nstf; stf = nstf; } STF_SET_STRING(stf, strdup(stringval(scan))); break; case G_TOKEN_IDENTIFIER: err_printf("unexpected identifier: %s\n", stringval(scan)); // if (!STF_IS_NIL(stf)) { // nstf = stf_new(); // stf->next = nstf; // stf = nstf; // } // STF_SET_IDENT(stf, strdup(stringval(scan))); // break; default: err_printf("unexected token %d\n", tok); break; } } while (tok != G_TOKEN_EOF); g_scanner_sync_file_offset(scan); g_scanner_destroy(scan); return ret; }
// ----------------------------------------------------------------------- // Invoke yyparse, set hsGlobal structure for each column group. // ----------------------------------------------------------------------- Lng32 HSFuncParseStmt() { HSGlobalsClass *hs_globals = GetHSContext(); Lng32 retcode; HSColGroupStruct *mgroup = NULL; void* scanner; init_scanner (scanner); HSFuncResetLexer(scanner); retcode = yyparse(scanner); HSHandleError(retcode); destroy_scanner (scanner); // The parser does not always return immediately following an error, so that // it can report as many errors as possible. This can result in a nonzero // return code being overwritten. To detect this case, we check the diagnostics // area and return with the appropriate sqlcode if necessary. retcode = hs_globals->getRetcodeFromDiags(); HSHandleError(retcode); hs_globals->parserError = HSGlobalsClass::ERROR_SEMANTICS; // We are done here if it is the showstats command if (hs_globals->optFlags & SHOWSTATS_OPT) return 0; // Automatically generate single-column histograms for all multi-column // histograms requested. This is required to calculate UEC counts for // multi-column histograms. // However, do not generate them when the CLEAR option is requested, unless // ON EVERY COLUMN or ON EVERY KEY is also specified. if (NOT (hs_globals->optFlags & CLEAR_OPT) || hs_globals->optFlags & EVERYCOL_OPT || hs_globals->optFlags & EVERYKEY_OPT) { mgroup = hs_globals->multiGroup; while (mgroup != NULL) { for (Int32 i=0; i<mgroup->colCount; i++) { HSColumnStruct &col = mgroup->colSet[i]; if (NOT ColumnExists(col.colnum)) { retcode = AddSingleColumn(col.colnum); HSHandleError(retcode); } } mgroup = mgroup->next; } } // ---------------------------------------------------------------------- // Construct statistics time in the format: YYYY-MM-DD:HH:MM:SS. // We use GMT time. // ---------------------------------------------------------------------- time_t t; time(&t); char pt[30]; strftime(pt, 30, "%Y-%m-%d:%H:%M:%S", gmtime(&t)); *hs_globals->statstime = pt; // Also store a numerical timestamp with 10 digits MMDDHHMMSS. hs_globals->statsTimeInt = (pt[5] - '0') * 1000000000 + (pt[6] - '0') * 100000000 + (pt[8] - '0') * 10000000 + (pt[9] - '0') * 1000000 + (pt[11] - '0') * 100000 + (pt[12] - '0') * 10000 + (pt[14] - '0') * 1000 + (pt[15] - '0') * 100 + (pt[17] - '0') * 10 + (pt[18] - '0'); return 0; }
static char * load_macro(MacroStore *macro) { int ret_val; long start_fpos; int size = 0; char *trace; char *macro_buff; save_scanner_state(); cfile = find_fp(macro->fpos); init_scanner(); /** First thing I should do is make sure that the name is correct ***/ get_expected_token(NewCommand); get_expected_token(Lbrace); get_expected_token(Macro); if (strcmp(token.id, macro->name)) { /** WOW, Somehow I had the location of the wrong macro **/ fprintf(stderr, "Expected macro name %s got insted %s in load_macro\n", macro->name, token.id); longjmp(jmpbuf, 1); } get_expected_token(Rbrace); /** Next I should check to see if I have any parameters **/ get_token(); if (token.type == Lsquarebrace) { /** The person is telling me the number of macros he is going to use **/ get_expected_token(Word); if (!number(token.id)) { fprintf(stderr, "load_macro: Expected A Value Instead Got %s\n", token.id); longjmp(jmpbuf, 1); } /** if it is a number, then I should store it in the parameter number member of the macro structure **/ macro->number_parameters = atoi(token.id); #ifdef DEBUG fprintf(stderr, "The number of parameters is %d\n", macro->number_parameters); #endif get_expected_token(Rsquarebrace); get_token(); } else macro->number_parameters = 0; /*** Now I should be able to check the token, and insure that I have read a leftbrace, then the string will follow ****/ if (token.type != Lbrace) { /** The macro is not in a group, uh oh **/ fprintf(stderr, "load_macro:Expected a Left Brace got type %d\n", token.type); longjmp(jmpbuf, 1); } start_fpos = fpos; scan_HyperDoc(); ret_val = fseek(cfile, macro->fpos.pos + start_fpos, 0); size = fpos - start_fpos; macro_buff = (char *) halloc((size + 1) * sizeof(char), "Macro_buf"); for (size = 0, trace = macro_buff; size < fpos - (start_fpos) - 1; size++) *trace++ = getc(cfile); *trace = '\0'; macro->loaded = 1; restore_scanner_state(); return macro_buff; }
time_t parsetime(int argc, char **argv) { /* Do the argument parsing, die if necessary, and return the time the job * should be run. */ time_t nowtimer, runtimer; struct tm nowtime, runtime; int hr = 0; /* this MUST be initialized to zero for midnight/noon/teatime */ nowtimer = time(NULL); nowtime = *localtime(&nowtimer); runtime = nowtime; runtime.tm_sec = 0; runtime.tm_isdst = 0; if (argc <= optind) usage(); init_scanner(argc-optind, argv+optind); switch (token()) { case NOW: if (scc < 1) { return nowtimer; } /* now is optional prefix for PLUS tree */ expect(PLUS); case PLUS: plus(&runtime); break; case NUMBER: tod(&runtime); month(&runtime); break; /* evil coding for TEATIME|NOON|MIDNIGHT - we've initialised * hr to zero up above, then fall into this case in such a * way so we add +12 +4 hours to it for teatime, +12 hours * to it for noon, and nothing at all for midnight, then * set our runtime to that hour before leaping into the * month scanner */ case TEATIME: hr += 4; case NOON: hr += 12; case MIDNIGHT: if (runtime.tm_hour >= hr) { runtime.tm_mday++; runtime.tm_wday++; } runtime.tm_hour = hr; runtime.tm_min = 0; token(); /* FALLTHROUGH to month setting */ default: month(&runtime); break; } /* ugly case statement */ expect(EOF); /* convert back to time_t */ runtime.tm_isdst = -1; runtimer = mktime(&runtime); if (runtimer < 0) panic("garbled time"); if (nowtimer > runtimer) panic("trying to travel back in time"); return runtimer; } /* parsetime */