int isInstruction(char *line) { line = cleanLine(line); if(line[0] == '@') return 1; unsigned short comp; unsigned char dest, jump; parseCType(line, &comp, &dest, &jump); return comp != KERR; }
void P_insertItemByIndexPTblLst(void) { UINT32 buffer[PTBL_MAX_SIZE]; UINT32 index; static UINT32 counter = 0; UINT32 temp_value; clearPTblLst(&g_point_node); memset((void *)buffer, 0, (size_t)PTBL_MAX_SIZE); srand(time(0)); for (index = 0; index != PTBL_MAX_SIZE; ++index) { temp_value = rand() % 100; fprintf(stdout, "[%d]\n", temp_value); if ( 1 != buffer[temp_value]) { if ( TRUE != insertItemByIndexPTblLst(&g_point_node, temp_value, counter)) { fprintf(stdout, "[X] <%s> : in %d => Insert item by index fail\n", __FILE__, __LINE__); return ; } buffer[temp_value] = 1; counter++; } } counter = 0; while (counter < PTBL_MAX_SIZE) { if (buffer[counter++]) { fprintf(stdout, "[%d]\t", counter); } } putchar('\n'); P_traversePTblLst(); fprintf(stdout, "Enter a number to be inserted 10: "); scanf("%d", &temp_value); cleanLine(); if ( TRUE != insertItemByIndexPTblLst(&g_point_node, 100, temp_value)) { fprintf(stdout, "[X] Insert by user enter error: %s %d\n", __FILE__, __LINE__); return ; } P_traversePTblLst(); }
instruction *parseInstruction(char *line) { line = cleanLine(line); if(strlen(line) == 0) return NULL; if(line[0] == '(') return NULL; if(line[0] == '@') { //A-type if(line[1] <= '9' && line[1] >= '0') { instruction* result = malloc(sizeof(instruction)); result->type = A; int imm; if(sscanf(line, "@%d", &imm) == 0) { fprintf(stderr, "Syntax error: %s\n", line); abort(); } if(imm >= 1 << 15) { fprintf(stderr, "Error, address out of bounds %d\n", imm); } result->literal = imm; return result; } }else{ unsigned short comp; unsigned char dest, jump; parseCType(line, &comp, &dest, &jump); if(dest == KNF) dest = 0; if(jump == KNF) jump = 0; if(comp == KERR || dest == KERR || jump == KERR) { /* TODO: make a better error message parseCType adds some \0s to line so it won't be the full command anymore */ fprintf(stderr, "Syntax error: %s\n", line); abort(); } instruction *result = malloc(sizeof(instruction)); result->type = C; result->comp = comp; result->dest = dest; result->jump = jump; return result; } fprintf(stderr, "Syntax error %s\n", line); abort(); }
bool Config::read (string filename) { ifstream cfg (filename.c_str ()); if (!cfg.is_open ()) { return false; } string line; while (cfg.good ()) { getline (cfg, line); cleanLine (line); parseLine (line); } cfg.close (); return true; }
void Parameters::parseLine(string line) { line = cleanLine(line); // check for include directive string directive("include "); if (line.substr(0,directive.size())==directive) { parseSettingsFile(line.substr(directive.size(),string::npos)); return; } // what's left has to have a space as separator string::size_type space = line.find(' '); if (space == string::npos) return; string key(line,0,space); string val(line,space+1); cout << key << "=" << val << endl; set(key,val); }
int main(int argc, char **argv){ FILE *f = NULL, *fout = NULL; char line[1024]; char *tmp, *fName; char foutname[100]; int i; char first; int pending = 0, files; fprintf(stderr, "\nHelpPC Reference Library to HTML converter. Ver 1.02\n" "Copyleft (l) Stanislav Sokolov\n\n"); if(argc == 1){ fprintf(stderr, "Usage:\n %s [file.txt [file2.txt [...]]]\n" "or\n %s *.txt\n\n", argv[0], argv[0]); return 10; } mkdir(BASE_PATH, 0777); /* Build conversion table */ fprintf(stderr, "Building conversion table and index files...\n"); i = buildConv(argc, argv); fprintf(stderr, "Found %d keywords corresponding to %d unique entries.\n", i >> 16, i & 0xFFFF); /* Parse the files */ for(files = 1; files < argc; files++){ //For all files given to function if((f = fopen(argv[files], "r")) == NULL){ fprintf(stderr, "Error opening %s\n", argv[files]); exit(100); } fprintf(stderr, "\nParsing %s...\n", argv[files]); while(fgets(line, 200, f) != NULL){ cleanLine(line); line[strlen(line) - 1] = '\0'; first = line[0]; if(first == '@'){ /* do nothing */ } else if(first == ':'){ /*Make new html file*/ if(pending){ fprintf(fout, "</PRE>\n\n</BODY>\n</HTML>"); fclose(fout); } pending = 1; rmFirst(line); tmp = strtok(line, ":"); fName = makeFName(tmp); sprintf(foutname, "%s/%s", BASE_PATH, fName); if((fout = fopen(foutname, "w+")) == NULL){ convError("Cannot open for writing!"); convError(foutname); return 3; } free(fName); fprintf(fout, "<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n</HEAD>\n\n<BODY><PRE>", tmp); } else if(first == '^'){ /* Make H2 */ rmFirst(line); fprintf(fout, "</PRE>\n\n<H2 ALIGN=Center>%s</H2>\n\n<PRE>\n", line); continue; } else if(first == '%'){ /* Make Bold */ rmFirst(line); fprintf(fout, "<B>%s</B>\n", line); } else { if(line[0] != '\0'){ parseLine(line); } fprintf(fout, "%s\n", line); } }/* while */ fclose(f); }/* for */ fprintf(stderr, "\nAll done.\n"); if(pending){ fprintf(fout, "</PRE>\n\n</BODY>\n</HTML>"); fclose(fout); } fclose(f); freeTable(c_head); return 0; }
int buildConv(int argc, char **argv){ int files, count = 0, i, entry = 0; FILE *f, *fidx, *idx; char index[45]; char fidxname[100]; char line[200]; char *tmp, *fName = NULL, *x1, *x2; struct conv *conv = NULL; struct conv c_list[2000]; int c_list_len; /* Start main index */ sprintf(line, "%s/index.html", BASE_PATH); if((idx = fopen(line, "w+")) == NULL){ convError("Error writing main index!"); exit(100); } fprintf(idx, "<HTML>\n<HEAD>\n <TITLE>HelpPC Reference Library</TITLE>\n" "</HEAD>\n\n<BODY>\n<CENTER>\n<H1>HelpPC Reference Library</H1>\n" "David Jurgens<BR>\n</CENTER>\n<HR WIDTH=140>\n" "<BR>\n\nTopics:<UL>\n"); for(files = 1; files < argc; files++){ //For all files given to function if((f = fopen(argv[files], "r")) == NULL){ fprintf(stderr, "Error opening %s\n", argv[files]); exit(100); } /* Get index title */ fprintf(stderr, " Getting index title of %s:\n\t", argv[files]); fgets(index, 45, f); cleanLine(index); if(index[0] != '@'){ convError("Not a valid help file!"); exit(1); } rmFirst(index); x1 = strdup(index); tmp = strtok(x1, " /,"); x2 = makeFName(tmp); free(x1); fprintf(stderr, "%s\n\n", index); fprintf(idx, " <LI><A HREF=\"idx_%s\">%s</A>\n", x2, index); sprintf(fidxname, "%s/idx_%s", BASE_PATH, x2); if((fidx = fopen(fidxname, "w+")) == NULL){ convError("Error writing topic index!"); convError(x2); free(x2); exit(100); } free(x2); fprintf(fidx, "<HTML>\n<HEAD>\n <TITLE>%s</TITLE>\n</HEAD>\n\n<BODY>\n", index); fprintf(fidx, "<H1 ALIGN=Center>%s</H1>\n\n", index); fprintf(fidx, "<TABLE BORDER=0>\n<TR>\n"); c_list_len = 0; while(fgets(line, 200, f) != NULL){ cleanLine(line); line[strlen(line) - 1] = '\0'; if(line[0] == ':'){ rmFirst(line); /* Make file name */ tmp = strtok(line, ":"); if(tmp != NULL){ fName = makeFName(tmp); entry++; } while(tmp != NULL){ count++; c_list[c_list_len].file = malloc(strlen(fName) + 1); c_list[c_list_len].orig = malloc(strlen(tmp) + 1); strcpy(c_list[c_list_len].file, fName); strcpy(c_list[c_list_len].orig, tmp); c_list_len++; conv = malloc(sizeof(struct conv)); conv->file = malloc(strlen(fName) + 1); conv->orig = malloc(strlen(tmp) + 1); conv->next = c_head; c_head = conv; strlowr(tmp); strcpy(conv->orig, tmp); strcpy(conv->file, fName); tmp = strtok(NULL, ":"); } free(fName); }/* if */ }/* while */ idxSortWrt(c_list, c_list_len, fidx); for(i = 0; i < c_list_len; i++){ free(c_list[i].file); free(c_list[i].orig); } fprintf(fidx, "\n</TR>\n</TABLE>\n</BODY>\n</HTML>"); fclose(f); fclose(fidx); } /* for */ fprintf(idx, "</UL>\n<HR>Converted to HTML by <A HREF=\"mailto:[email protected]\">Stanislav" " Sokolov</A>.<BR>\n</BODY>\n</HTML>"); fclose(idx); return (count << 16) | (entry & 0xFFFF); }
void sqlimport::process_line(QString sqlLine) { QString lineData; lineData = cleanLine(sqlLine); if (!lineData.isEmpty()) { if ((lineData.left(13) == "CREATE TABLE") || (lineData.left(12) == "CREATE TABLE")) { SQLStatement.clear(); collectSQL = false; if (lineData.lastIndexOf(";") >= 0) { SQLStatement << lineData; if (isSemiColonInsideSingleQuote() == false) { collectSQL = false; processSQL(SQLStatement); SQLStatement.clear(); } else { collectSQL = true; } } else { SQLStatement << lineData; collectSQL = true; } } else { if ((lineData.left(12) == "INSERT INTO") || (lineData.left(11) == "INSERT INTO")) { //qDebug() << lineData.left(11); SQLStatement.clear(); collectSQL = false; if (lineData.lastIndexOf(";") >= 0) { SQLStatement << lineData; if (isSemiColonInsideSingleQuote() == false) { collectSQL = false; processSQL(SQLStatement); SQLStatement.clear(); } else { collectSQL = true; } } else { SQLStatement << lineData; collectSQL = true; } } else { if (lineData.lastIndexOf(";") >= 0) { SQLStatement << lineData; if (isSemiColonInsideSingleQuote() == false) { collectSQL = false; processSQL(SQLStatement); SQLStatement.clear(); } else { //qDebug() << "Why!"; collectSQL = true; } } else { if (collectSQL) { SQLStatement << lineData; } else { lineData = lineData + "\n"; //outfile.write(lineData.toAscii()); writeToFile(lineData.toAscii()); //outStream << lineData; } } } } } }
void TrailingWhitespaceCleaner::cleanRange (juce::StringArray& lines, const int start, const int end) { for (int i = start; i < end; ++i) cleanLine (lines.getReference (i)); }