void process_token(char *tok, struct program *prog){ if(check_comment(tok, prog)){ process_comment(tok); } else{ // must be a variable process_definition(tok, prog); } }
static void jdfits_append_comment (char *buf, char *comment) { unsigned int comment_len; unsigned int buf_len = strlen (buf); char *b, *bmax; b = buf + buf_len; if (comment != NULL) { int slash_ok; unsigned int space; slash_ok = 0; space = JDFITS_CARD_SIZE - buf_len; if (space > 2) { slash_ok = 1; space -= 2; } if (*comment == '/') comment++; comment_len = check_comment (comment, space); if (comment_len) { if (comment_len + 30 < JDFITS_CARD_SIZE) { bmax = buf + 30; while (b < bmax) *b++ = ' '; } if (slash_ok) { *b++ = ' '; *b++ = '/'; } strncpy (b, comment, comment_len); } b += comment_len; } bmax = buf + JDFITS_CARD_SIZE; while (b < bmax) *b++ = ' '; }
bool Config::load_(const std::string &filename) { ScopedLock lock(map_mutex_); map_.clear(); std::ifstream ifs; ifs.open(filename.c_str(), std::ios::in); if (!ifs) { return false; } while(!ifs.eof()) { std::string l; getline(ifs, l); l = chomp(l); if (check_comment(l)) continue; set_key_value_(l); } return true; }
/* move from newpred.cpp */ void CNewPredEncoder::load_ref_ind() { int i, j; FILE *read_file; char buf[256]; char *dtp; int count=0; int line=0; int err_flag = 0; int int_dt; int frameNo; int first = 1; memset(m_pNewPredControl->ref_tbl, 0x00, 0x800*MAX_NumGOB*sizeof(int)); if( (read_file = fopen(refname,"r")) == NULL ) { fprintf( stdout, "Unable to open Ref_Indication_file: %s\n", refname); exit( -1 ); } while( !feof(read_file) ) { line++; if( first ) { if( fgets(buf,256,read_file) == 0 ) { fprintf( stderr, "Read error!! : %s\n", refname ); exit( -1 ); } first = 0; } check_comment( buf ); if( check_space(buf)!=0 ) { fgets( buf,256,read_file ); continue; } i = 0, j = 0; dtp = strtok( buf, " \t\n" ); frameNo = atoi( dtp ); while( (dtp = strtok(NULL, " \t\n")) != NULL ) { int_dt = atoi( dtp ); if( int_dt < 0 || int_dt > count + 1 ) { err_flag = 1; } if(int_dt > (int)~(0xffffffff<<m_iNumBitsVopID)) { err_flag = 1; } m_pNewPredControl->ref_tbl[count][i++] = int_dt; if( i >= MAX_NumGOB ) break; } if( err_flag != 0 || i > (m_iHeight/MB_SIZE) ) { fprintf( stdout, "Error reference frame table: %s(%d Line)\n", refname, line ); exit( -1 ); } count++; if( count >= 0x800 ) break; fgets( buf, 256, read_file ); } fclose( read_file ); first = 1; }
/** * Given the first token to an input line, will attempt to parse it and * process the related instruction. * * @param tok The first token on the input line, this is expected to be * a clean (non-whitespace) token. * @param program Contains all current program information gathered so far, * primarily used for error reporting. */ void process_token(char *tok, struct program *program){ // check for comments if(check_comment(tok, program)){ process_comment(program); return; } // process constant definitions else if(check_const_def(tok, program)){ process_const_def(tok, program); return; } // Function definitions else if(check_func_def(tok, program)){ process_func_def(tok, program); return; } // check if we have a label else if(check_label_def(tok, program)){ process_label_def(tok, program); return; } // the first token should contain our instruction else if(!strcmp(tok, "HALT")){ process_instruction(program, HALT, HALT_F , 0); } else if(!strcmp(tok, "NOT")){ process_instruction(program, NOT, NOT_F, 0); } else if(!strcmp(tok, "SHL")){ process_instruction(program, SHL, SHL_F, 0); } else if(!strcmp(tok, "SHR")){ process_instruction(program, SHR, SHR_F, 0); } else if(!strcmp(tok, "OR")){ process_instruction(program, OR, OR_F, 0); } else if(!strcmp(tok, "AND")){ process_instruction(program, AND, AND_F, 0); } else if(!strcmp(tok, "ADD")){ process_instruction(program, ADD, ADD_F, 0); } else if(!strcmp(tok, "SW")){ process_instruction(program, SW, SW_F, 0); } else if(!strcmp(tok, "SI")){ process_instruction(program, SI, SI_F, 0); } else if(!strcmp(tok, "LW")){ process_instruction(program, LW, LW_F, 0); } else if(!strcmp(tok, "LI")){ process_instruction(program, LI, LI_F, 0); } else if(!strcmp(tok, "BEZ")){ process_instruction(program, BEZ, BEZ_F, 0); } else if(!strcmp(tok, "ROT")){ process_instruction(program, ROT, ROT_F, 0); } else if(!strcmp(tok, "ROT1")){ process_instruction(program, ROT1, ROT1_F, 0); } else if(!strcmp(tok, "JMP")){ process_instruction(program, JMP, JMP_F, 0); } else if(!strcmp(tok, "NOP")){ process_instruction(program, NOP, NOP_F, 0); } else if(!strcmp(tok, "LFSJ")){ process_instruction(program, LFSJ, LFSJ_F, 0); } else if(!strcmp(tok, "STJ")){ process_instruction(program, STJ, STJ_F, 0); } // looks like a bad opcode else{ #ifdef DEBUG fprintf(stderr, "BAD CODE '%s'\n", tok); #endif print_unexpected_ident(tok, program); } }
int do_read_file(char *buf, FILE *f, int repl) { int bal = -1; char tmp[LINEBUFSIZ]; char *p; int i = 0; int bl = 0; int ind; /* * This loops as long as there * are unclosed parentheses */ while (bal) { /* * If in interactive mode, * handle prompts/autoindent */ if (repl) { /* * If i = 0, print a new logical-line prompt * (This counts the number of UNIX lines * in this logical line, so far) */ if (!i++) printf("]=> "); else { /* * The logical-line is incomplete; print * a "..." prompt then auto-indent */ printf("... "); if (bal > 0) { for (ind = 0; ind < bal; ++ind) { printf(" "); /* * Transcribe the auto-indentation * to the logfile if logging is enabled */ if (save_mode) fprintf(save_file, " "); } } } /* * Flush out the prompt/autoindent to make sure * it appears -- it's not newline-terminated, * because the rest of the line is the user's code */ fflush(stdout); } /* * Read in a line of input. exit the routine * in various ways if this fails. */ if (!fgets(tmp, LINEBUFSIZ, f)) { printf("\n"); /* ???? */ if (repl) { return 0; } else break; } /* * Transcribe the line input to the logfile, * if logging and interactive (repl) mode * are enabled */ if (save_mode && repl && *tmp != '\n') { fflush(save_file); fprintf(save_file, "%s", tmp); } /* Check if the line is a comment */ if (check_comment(tmp)) { /* * If a comment was written on a "]=>" prompt, * write another "]=>" prompt afterwards, not * a "..." */ if (i == 1) i = 0; /* * Go on to the next line of input; * do not add the comment to the buffer */ continue; } /* Skip empty lines, parser hates them */ if (*tmp == '\n') { if (repl) { /* * An empty line given on a "]=>" prompt * leads to a new "]=>" prompt afterwards, * not a "..." prompt. */ if (i == 1) --i; /* * In interactive (repl) mode, blank * lines cause the CLI reader to autocomplete * missing closing parentheses. This loop * is ugly because it has to transcribe these * parentheses to the buffer, to stdout, and * also to the logfile if logging is enabled. */ if (++bl > 0 && bal > 0) { printf ("... "); for (ind = 0; ind < bal; ++ind) { printf(")"); strcat(buf, ")"); if (save_file) fprintf(save_file, ")"); } if (save_file) { fflush(save_file); fprintf(save_file, "\n"); } fflush(stdout); printf("\n"); break; } } continue; } else bl = 0; /* Trim the newline from the input line */ for (p = tmp; *p; ++p) { if (*p == '\n' || *p == EOF) { *p = 0; break; } } /* Add the input line to the logical-line buffer */ strcat(buf, tmp); strcat(buf, " "); /* Check parentheses balance */ bal = 0; for (p = buf; *p; ++p) { if (*p == '(') ++bal; else if (*p == ')') --bal; } /* Abort on negative parenthesis-nest */ if (bal < 0) { error_msg("terrible syntax"); code_error(); } } return 1; }