int Store::open(const char *name) { int i; STORE_ASSERT(m_state==Init); if (m_file) return 0; // already open m_file = portable_fopen(name,"w+b"); if (m_file==0) return -1; // first block serves as header, so offset=0 can be used as the end of the list. for (i=0;i<BLOCK_SIZE/8;i++) { fputc('D',m_file); fputc('O',m_file); fputc('X',m_file); fputc('Y',m_file); fputc('G',m_file); fputc('E',m_file); fputc('N',m_file); fputc(0,m_file); } m_front = BLOCK_SIZE; m_cur = BLOCK_SIZE; m_head = 0; m_state = Reading; return 0; }
void initWarningFormat() { // int filePos = Config_getString("WARN_FORMAT").find("$file"); // int linePos = Config_getString("WARN_FORMAT").find("$line"); // int textPos = Config_getString("WARN_FORMAT").find("$text"); // // // sort items on position (there are 6 cases) // warnFormatOrder = 1; // if (filePos>linePos && filePos>textPos) // { // if (linePos>textPos) // $text,$line,$file // { // warnFormatOrder = 2; // } // else // $line,$text,$file // { // warnFormatOrder = 3; // } // } // else if (filePos<linePos && filePos<textPos) // { // if (linePos>textPos) // $file,$text,$line // { // warnFormatOrder = 4; // } // } // else if (filePos<linePos && filePos>textPos) // $text,$file,$line // { // warnFormatOrder = 5; // } // else // $line,$file,$text // { // warnFormatOrder = 6; // } // outputFormat = // substitute( // substitute( // substitute( // Config_getString("WARN_FORMAT"), // "$file","%s" // ), // "$text","%s" // ), // "$line","%d" // )+'\n'; // replace(QRegExp("\\$file"),"%s"). // replace(QRegExp("\\$text"),"%s"). // replace(QRegExp("\\$line"),"%d")+ // '\n'; outputFormat = Config_getString("WARN_FORMAT"); if (!Config_getString("WARN_LOGFILE").isEmpty()) { warnFile = portable_fopen(Config_getString("WARN_LOGFILE"),"w"); } if (!warnFile) // point it to something valid, because warn() relies on it { warnFile = stderr; } }
/*! Reads a fragment of code from file \a fileName starting at * line \a startLine and ending at line \a endLine (inclusive). The fragment is * stored in \a result. If FALSE is returned the code fragment could not be * found. * * The file is scanned for a opening bracket ('{') from \a startLine onward * The line actually containing the bracket is returned via startLine. * The file is scanned for a closing bracket ('}') from \a endLine backward. * The line actually containing the bracket is returned via endLine. * Note that for VHDL code the bracket search is not done. */ static bool readCodeFragment(const char *fileName, int &startLine,int &endLine,QCString &result) { static bool vhdlOpt = Config_getBool("OPTIMIZE_OUTPUT_VHDL"); static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES"); //printf("readCodeFragment(%s,%d,%d)\n",fileName,startLine,endLine); if (fileName==0 || fileName[0]==0) return FALSE; // not a valid file name QCString filter = getFileFilter(fileName,TRUE); FILE *f=0; bool usePipe = !filter.isEmpty() && filterSourceFiles; if (!usePipe) // no filter given or wanted { f = portable_fopen(fileName,"r"); } else // use filter { QCString cmd=filter+" \""+fileName+"\""; Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",cmd.data()); f = portable_popen(cmd,"r"); } bool found=vhdlOpt; // for VHDL no bracket search is possible if (f) { int c=0; int col=0; int lineNr=1; // skip until the startLine has reached while (lineNr<startLine && !feof(f)) { while ((c=fgetc(f))!='\n' && c!=EOF) /* skip */; lineNr++; } if (!feof(f)) { // skip until the opening bracket or lonely : is found char cn=0; while (lineNr<=endLine && !feof(f) && !found) { int pc=0; while ((c=fgetc(f))!='{' && c!=':' && c!=EOF) { //printf("parsing char `%c'\n",c); if (c=='\n') { lineNr++,col=0; } else if (c=='\t') { col+=Config_getInt("TAB_SIZE") - (col%Config_getInt("TAB_SIZE")); } else if (pc=='/' && c=='/') // skip single line comment { while ((c=fgetc(f))!='\n' && c!=EOF) pc=c; if (c=='\n') lineNr++,col=0; } else if (pc=='/' && c=='*') // skip C style comment { while (((c=fgetc(f))!='/' || pc!='*') && c!=EOF) { if (c=='\n') lineNr++,col=0; pc=c; } } else { col++; } pc = c; } if (c==':') { cn=fgetc(f); if (cn!=':') found=TRUE; } else if (c=='{') { found=TRUE; } } //printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr); if (found) { // For code with more than one line, // fill the line with spaces until we are at the right column // so that the opening brace lines up with the closing brace if (endLine!=startLine) { QCString spaces; spaces.fill(' ',col); result+=spaces; } // copy until end of line result+=c; if (c==':') { result+=cn; if (cn=='\n') lineNr++; } startLine=lineNr; const int maxLineLength=4096; char lineStr[maxLineLength]; do { //printf("reading line %d in range %d-%d\n",lineNr,startLine,endLine); int size_read; do { // read up to maxLineLength-1 bytes, the last byte being zero char *p = fgets(lineStr, maxLineLength,f); //printf(" read %s",p); if (p) { size_read=qstrlen(p); } else // nothing read { size_read=-1; lineStr[0]='\0'; } result+=lineStr; } while (size_read == (maxLineLength-1)); lineNr++; } while (lineNr<=endLine && !feof(f)); // strip stuff after closing bracket int newLineIndex = result.findRev('\n'); int braceIndex = result.findRev('}'); if (braceIndex > newLineIndex) { result.truncate(braceIndex+1); } endLine=lineNr-1; } } if (usePipe) { portable_pclose(f); } else { fclose(f); } } result = transcodeCharacterStringToUTF8(result); return found; }