/* * Append system-specific directories to the include directory list. * Called only when cpp is started. */ void setincdirs() { #ifdef CPP_INCLUDE *incend++ = CPP_INCLUDE; #define IS_INCLUDE 1 #else #define IS_INCLUDE 0 #endif #if HOST == SYS_UNIX *incend++ = "/usr/include"; #define MAXINCLUDE (NINCLUDE - 1 - IS_INCLUDE) #endif #if HOST == SYS_UNKNOWN /* * Kontext: GenMake * Unter DOS wird nun auch die Environment-Variable INCLUDE ausgewetet. * Es kommt erschwerend hinzu, dass alle Eintraege, die mit ';' getrennt * sind, mit in die Liste aufenommen werden muessen. * Dies wird mit der Funktion strtok() realisiert. * Vorsicht bei der Benutzung von malloc !!! * In savestring wird naemlich getmem() verwendet. Vermutlich kommen sich * die beiden Funktion in die Quere. Als ich malloc statt savestring * verwendete knallte es in strcpy() ! */ #if !defined( WNT ) && ! defined UNX extern char* getenv( char *pStr ); /* BP */ #endif char* pIncGetEnv = NULL; /* Pointer auf INCLUDE */ if ( ( pIncGetEnv = getenv("INCLUDE") ) != NULL ) AddInclude( pIncGetEnv ); #define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE) #endif }
// Parse //------------------------------------------------------------------------------ bool CIncludeParser::ParseMSCL_Output( const char * compilerOutput, size_t compilerOutputSize ) { // we require null terminated input ASSERT( compilerOutput[ compilerOutputSize ] == 0 ); (void)compilerOutputSize; const char * pos = compilerOutput; //const char * end = pos + compilerOutputSize; for (;;) { // find next include note const char * token = strstr( pos, "\nNote: including file: " ); if ( !token ) { break; } pos = token + 23; // skip whitespace (alwways spaces) while ( *pos == ' ' ) { ++pos; } const char * lineStart = pos; // find end of line pos = strchr( pos, '\r' ); if ( !pos ) { return false; } const char * lineEnd = pos; AddInclude( lineStart, lineEnd ); } return true; }
Bool_t Compile(const char* script=0, Option_t* option="g") { if (!script || script[0] == '\0') { std::cerr << "No script to compile!" << std::endl; return kFALSE; } gSystem->Load("libANALYSIS"); gSystem->Load("libANALYSISalice"); gSystem->Load("libFMDutil"); TString macroPath(gROOT->GetMacroPath()); macroPath.Append(":${ALICE_ROOT}/FMD/scripts"); gROOT->SetMacroPath(macroPath.Data()); AddInclude("-I`root-config --incdir`"); AddInclude("-I${ALICE_ROOT}"); AddInclude("-I${ALICE_ROOT}/include"); AddInclude("-I${ALICE_ROOT}/FMD"); AddInclude("-I${ALICE_ROOT}/geant3/TGeant3"); AddInclude("-I${ALICE_ROOT}/../master-src"); AddInclude("-I${ALICE_ROOT}/../master-src/FMD"); AddInclude("-I${ALICE_ROOT}/../master-src/RAW"); Long_t ret = gROOT->ProcessLine(Form(".L %s+%s", script, option)); return ret == 0; }
// Parse //------------------------------------------------------------------------------ bool CIncludeParser::ParseMSCL_Output( const char * compilerOutput, size_t compilerOutputSize ) { // we require null terminated input ASSERT( compilerOutput[ compilerOutputSize ] == 0 ); (void)compilerOutputSize; const char * pos = compilerOutput; //const char * end = pos + compilerOutputSize; for (;;) { const char * lineStart = pos; // find end of the line pos = strchr( pos, '\r' ); if ( !pos ) { break; // end of output } const char * lineEnd = pos; ASSERT( *pos == '\r' ); ++pos; // skip \r for next line const char * ch = lineStart; // count colons in the line const char * colon1 = nullptr; for ( ; ch < lineEnd ; ++ch ) { if ( *ch == ':' ) { if ( colon1 == nullptr ) { colon1 = ch; } else { break; } } } // check that we have two colons separated by at least one char if ( colon1 == nullptr || colon1 == lineStart || *ch != ':' || (ch - colon1) < 2 ) { continue; // next line } ASSERT( *ch == ':' ); const char * colon2 = ch; // skip whitespace (always spaces) do { ++ch; } while ( *ch == ' ' ); // must have whitespaces if ( ch == colon2 ) { continue; // next line } const char * includeStart = ch; const char * includeEnd = lineEnd; // validates the windows path bool validated = ( includeStart < includeEnd ); size_t colonCount( 0 ); for ( ; validated && ( ch < includeEnd ); ++ch ) { switch ( *ch ) { // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx case '<': case '>': case '"': case '|': case '?': case '*': { validated = false; break; } case ':': { // This logic handles warnings which might otherwise appear as valid paths ++colonCount; if ( colonCount > 1 ) { validated = false; } break; } default: break; } } if ( validated ) { const char c1 = includeStart[ 0 ]; const bool driveLetter = ( ( ( c1 >= 'A' ) && ( c1 <= 'Z' ) ) || ( ( c1 >= 'a' ) && ( c1 <= 'z' ) ) ); const bool validPath = driveLetter && ( includeStart[ 1 ] == ':' ); if ( validPath ) { AddInclude( includeStart, includeEnd ); } } } return true; }
// Parse //------------------------------------------------------------------------------ bool CIncludeParser::ParseGCC_Preprocessed( const char * compilerOutput, size_t compilerOutputSize ) { // we require null terminated input ASSERT( compilerOutput[ compilerOutputSize ] == 0 ); (void)compilerOutputSize; const char * pos = compilerOutput; // special case for include on first line // (out of loop to keep loop logic simple) if ( pos[ 0 ] == '#' ) { ++pos; goto possibleInclude; } for (;;) { pos = strstr( pos, "\n#" ); if ( !pos ) { break; } pos += 2; possibleInclude: if ( *pos == ' ' ) { ++pos; goto foundInclude; } if ( strncmp( pos, "line ", 5 ) == 0 ) { pos += 5; goto foundInclude; } continue; // some other directive we don't care about foundInclude: // skip number for ( ;; ) { char c = * pos; if ( ( c >= '0' ) && ( c <= '9' ) ) { pos++; continue; } break; // non numeric } // single space if ( *pos != ' ' ) { continue; } pos++; // opening quote if ( *pos != '"' ) { continue; } pos++; // ignore special case GCC "<built-in>" and "<command line>" if ( *pos == '<' ) { continue; } const char * lineStart = pos; // find end of line pos = strchr( pos, '"' ); if ( !pos ) { return false; // corrupt input } const char * lineEnd = pos; // ignore GCC paths const char lastChar( lineEnd[ -1 ] ); if ( ( lastChar == NATIVE_SLASH ) || ( lastChar == OTHER_SLASH ) ) { continue; } AddInclude( lineStart, lineEnd ); } return true; }
// Parse //------------------------------------------------------------------------------ bool CIncludeParser::ParseMSCL_Preprocessed( const char * compilerOutput, size_t compilerOutputSize ) { // we require null terminated input ASSERT( compilerOutput[ compilerOutputSize ] == 0 ); (void)compilerOutputSize; const char * pos = compilerOutput; for (;;) { pos = strstr( pos, "#line 1 " ); if ( !pos ) { break; } const char * lineStart = pos; pos += 8; // search backwards for start of line searchForLineStart: // special case for first line (prevent buffer underread) if ( lineStart == compilerOutput ) { goto foundInclude; } // skip whitespace --lineStart; if ( ( *lineStart == ' ' ) || ( *lineStart == '\t' ) ) { goto searchForLineStart; } // wrapped to previous line? if ( *lineStart == '\n' ) { goto foundInclude; } // hit some non-whitespace before the #line continue; // look for another #line foundInclude: // go to opening quote pos = strchr( pos, '"' ); if ( !pos ) { return false; } pos++; const char * incStart = pos; // find end of line pos = strchr( pos, '"' ); if ( !pos ) { return false; } const char * incEnd = pos; AddInclude( incStart, incEnd ); } return true; }
void setincdirs() /* * Append system-specific directories to the include directory list. * Called only when cpp is started. */ { #ifdef CPP_INCLUDE *incend++ = CPP_INCLUDE; #define IS_INCLUDE 1 #else #define IS_INCLUDE 0 #endif #if HOST == SYS_UNIX *incend++ = "/usr/include"; #define MAXINCLUDE (NINCLUDE - 1 - IS_INCLUDE) #endif #if HOST == SYS_VMS extern char *getenv(); if (getenv("C$LIBRARY") != NULL) *incend++ = "C$LIBRARY:"; *incend++ = "SYS$LIBRARY:"; #define MAXINCLUDE (NINCLUDE - 2 - IS_INCLUDE) #endif #if HOST == SYS_RSX extern int $$rsts; /* TRUE on RSTS/E */ extern int $$pos; /* TRUE on PRO-350 P/OS */ extern int $$vms; /* TRUE on VMS compat. */ if ($$pos) { /* P/OS? */ *incend++ = "SY:[ZZDECUSC]"; /* C #includes */ *incend++ = "LB:[1,5]"; /* RSX library */ } else if ($$rsts) { /* RSTS/E? */ *incend++ = "SY:@"; /* User-defined account */ *incend++ = "C:"; /* Decus-C library */ *incend++ = "LB:[1,1]"; /* RSX library */ } else if ($$vms) { /* VMS compatibility? */ *incend++ = "C:"; } else { /* Plain old RSX/IAS */ *incend++ = "LB:[1,1]"; } #define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE) #endif #if HOST == SYS_RT11 extern int $$rsts; /* RSTS/E emulation? */ if ($$rsts) *incend++ = "SY:@"; /* User-defined account */ *incend++ = "C:"; /* Decus-C library disk */ *incend++ = "SY:"; /* System (boot) disk */ #define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE) #endif #if HOST == SYS_UNKNOWN /* * Kontext: GenMake * Unter DOS wird nun auch die Environment-Variable INCLUDE ausgewetet. * Es kommt erschwerend hinzu, dass alle Eintraege, die mit ';' getrennt * sind, mit in die Liste aufenommen werden muessen. * Dies wird mit der Funktion strtok() realisiert. * Vorsicht bei der Benutzung von malloc !!! * In savestring wird naemlich getmem() verwendet. Vermutlich kommen sich * die beiden Funktion in die Quere. Als ich malloc statt savestring * verwendete knallte es in strcpy() ! */ #if !defined( WNT ) && ! defined UNX extern char *getenv( char *pStr ); /* BP */ #endif char *pIncGetEnv = NULL; /* Pointer auf INCLUDE */ if ( ( pIncGetEnv = getenv("INCLUDE") ) != NULL ) AddInclude( pIncGetEnv ); #define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE) #endif }
int dooptions(int argc, char** argv) /* * dooptions is called to process command line arguments (-Detc). * It is called only at cpp startup. */ { register char *ap; register DEFBUF *dp; register int c; int i, j; char *arg; SIZES *sizp; /* For -S */ int size; /* For -S */ int isdatum; /* FALSE for -S* */ int endtest; /* For -S */ for (i = j = 1; i < argc; i++) { arg = ap = argv[i]; if (*ap++ != '-' || *ap == EOS) { argv[j++] = argv[i]; } else { c = *ap++; /* Option byte */ if (islower(c)) /* Normalize case */ c = toupper(c); switch (c) { /* Command character */ case 'C': /* Keep comments */ cflag = TRUE; keepcomments = TRUE; break; case 'D': /* Define symbol */ /* * If the option is just "-Dfoo", make it -Dfoo=1 */ while (*ap != EOS && *ap != '=') ap++; if (*ap == EOS) ap = "1"; else *ap++ = EOS; /* * Now, save the word and its definition. */ dp = defendel(argv[i] + 2, FALSE); dp->repl = savestring(ap); dp->nargs = DEF_NOARGS; break; case 'E': /* Ignore non-fatal */ eflag = TRUE; /* errors. */ break; case 'I': /* Include directory */ AddInclude( ap ); /* BP, 11.09.91 */ break; case 'N': /* No predefineds */ nflag++; /* Repeat to undefine */ break; /* __LINE__, etc. */ case 'S': sizp = size_table; if (0 != (isdatum = (*ap != '*'))) /* If it's just -S, */ endtest = T_FPTR; /* Stop here */ else { /* But if it's -S* */ ap++; /* Step over '*' */ endtest = 0; /* Stop at end marker */ } while (sizp->bits != endtest && *ap != EOS) { if (!isdigit(*ap)) { /* Skip to next digit */ ap++; continue; } size = 0; /* Compile the value */ while (isdigit(*ap)) { size *= 10; size += (*ap++ - '0'); } if (isdatum) sizp->size = size; /* Datum size */ else sizp->psize = size; /* Pointer size */ sizp++; } if (sizp->bits != endtest) cwarn("-S, too few values specified in %s", argv[i]); else if (*ap != EOS) cwarn("-S, too many values, \"%s\" unused", ap); break; case 'U': /* Undefine symbol */ if (defendel(ap, TRUE) == NULL) cwarn("\"%s\" wasn't defined", ap); break; #if OSL_DEBUG_LEVEL > 1 case 'X': /* Debug */ debug = (isdigit(*ap)) ? atoi(ap) : 1; #if (HOST == SYS_VMS || HOST == SYS_UNIX) signal(SIGINT, (void (*)(int)) abort); /* Trap "interrupt" */ #endif fprintf(stderr, "Debug set to %d\n", debug); break; #endif #if OSL_DEBUG_LEVEL > 1 case 'P': /* #define's dump */ bDumpDefs = 1; fprintf(stderr, "Dump #define's is on\n"); break; #endif default: /* What is this one? */ cwarn("Unknown option \"%s\"", arg); fprintf(stderr, "The following options are valid:\n\ -C\t\t\tWrite source file comments to output\n\ -Dsymbol=value\tDefine a symbol with the given (optional) value\n\ -Idirectory\t\tAdd a directory to the #include search list\n\ -N\t\t\tDon't predefine target-specific names\n\ -Stext\t\tSpecify sizes for #if sizeof\n\ -Usymbol\t\tUndefine symbol\n"); #if OSL_DEBUG_LEVEL > 1 fprintf(stderr, " -Xvalue\t\tSet internal debug flag\n"); fprintf(stderr, " -P\t\t\tdump #define's\n"); #endif break; } /* Switch on all options */ } /* If it's a -option */ } /* For all arguments */ #if OSL_DEBUG_LEVEL > 1 if ( (bDumpDefs ? j > 4 : j > 3) ) { #else if (j > 3) { #endif cerror( "Too many file arguments. Usage: cpp [input [output]]", NULLST); } return (j); /* Return new argc */ } int readoptions(char* filename, char*** pfargv) { FILE *fp; int c; int bInQuotes = 0; char optbuff[1024], *poptbuff; int fargc=0, back; char *fargv[PARALIMIT], **pfa; pfa=*pfargv=malloc(sizeof(fargv)); poptbuff=&optbuff[0]; filename++; if ((fp = fopen(filename, "r")) == NULL) { #if OSL_DEBUG_LEVEL > 1 if ( debug || !bDumpDefs ) perror(filename); #endif return (FALSE); } do { /* * #i27914# double ticks '"' now have a duplicate function: * 1. they define a string ( e.g. -DFOO="baz" ) * 2. a string can contain spaces, so -DFOO="baz zum" defines one * argument no two ! */ c=fgetc(fp); if ( c != ' ' && c != CR && c != NL && c != HT && c != EOF) { *poptbuff++=(char)c; if( c == '"' ) bInQuotes = ~bInQuotes; } else { if( c != EOF && bInQuotes ) *poptbuff++=(char)c; else { *poptbuff=EOS; if (strlen(optbuff)>0) { pfa[fargc+1]=malloc(strlen(optbuff)+1); strcpy(pfa[fargc+1],optbuff); fargc++; pfa[fargc+1]=0; poptbuff=&optbuff[0]; } } } } while ( c != EOF ); fclose(fp); back=dooptions(fargc+1,pfa); return (back); }
void ProjectSettingsWindow::MessageReceived(BMessage* message) { switch (message->what) { case M_SHOW_ADD_PATH: { fFilePanel->Show(); break; } case M_DROP_PATH: { BString path; if (message->FindString("path",&path) == B_OK) fProject->AddLocalInclude(path.String()); break; } case M_ADD_PATH: { entry_ref ref; int32 i = 0; while (message->FindRef("refs", i++, &ref) == B_OK) { fDirty = true; AddInclude(ref); } break; } case M_REMOVE_PATH: { int32 selection = fIncludeList->CurrentSelection(); if (selection < 0) break; fDirty = true; for (int32 i = fIncludeList->CountItems() - 1; i >= 0; i--) { BStringItem* item = (BStringItem*)fIncludeList->ItemAt(i); if (item->IsSelected()) { fIncludeList->RemoveItem(item); fProject->RemoveLocalInclude(item->Text()); delete item; } } break; } case M_TARGET_NAME_CHANGED: { if (fTargetText->Text() && strlen(fTargetText->Text()) > 0) fProject->SetTargetName(fTargetText->Text()); fDirty = true; } case M_TOGGLE_DEBUG: { if (fDebugBox->Value() == B_CONTROL_ON) { fProject->SetDebug(true); fOpField->SetEnabled(false); fOpSizeBox->SetEnabled(false); } else { fProject->SetDebug(false); fOpField->SetEnabled(true); fOpSizeBox->SetEnabled(true); } fDirty = true; break; } case M_TOGGLE_PROFILE: { if (fProfileBox->Value() == B_CONTROL_ON) fProject->SetProfiling(true); else fProject->SetProfiling(false); fDirty = true; break; } case M_TOGGLE_OPSIZE: { if (fOpSizeBox->Value() == B_CONTROL_ON) fProject->SetOpForSize(true); else fProject->SetOpForSize(false); fDirty = true; break; } case M_SET_OP_VALUE: { BMenuItem *item = fOpField->Menu()->FindMarked(); if (item) fProject->SetOpLevel(fOpField->Menu()->IndexOf(item)); fDirty = true; break; } case M_SET_TARGET_TYPE: { BMenuItem *item = fTypeField->Menu()->FindMarked(); if (item) fProject->SetTargetType(fTypeField->Menu()->IndexOf(item)); fDirty = true; break; } case M_CCOPTS_CHANGED: { fProject->SetExtraCompilerOptions(fCompileText->Text()); fDirty = true; break; } case M_LDOPTS_CHANGED: { fProject->SetExtraLinkerOptions(fLinkText->Text()); fDirty = true; break; } default: BWindow::MessageReceived(message); } }
/* * dooptions is called to process command line arguments (-Detc). * It is called only at cpp startup. */ int dooptions(int argc, char** argv) { char* ap; DEFBUF* dp; int c; int i, j; char* arg; SIZES* sizp; /* For -S */ int size; /* For -S */ int isdatum; /* FALSE for -S* */ int endtest; /* For -S */ for (i = j = 1; i < argc; i++) { arg = ap = argv[i]; if (*ap++ != '-' || *ap == EOS) { argv[j++] = argv[i]; } else { c = *ap++; /* Option byte */ if (islower(c)) /* Normalize case */ c = toupper(c); switch (c) /* Command character */ { case 'C': /* Keep comments */ cflag = TRUE; keepcomments = TRUE; break; case 'D': /* Define symbol */ /* * If the option is just "-Dfoo", make it -Dfoo=1 */ while (*ap != EOS && *ap != '=') ap++; if (*ap == EOS) ap = "1"; else *ap++ = EOS; /* * Now, save the word and its definition. */ dp = defendel(argv[i] + 2, FALSE); dp->repl = savestring(ap); dp->nargs = DEF_NOARGS; break; case 'E': /* Ignore non-fatal */ eflag = TRUE; /* errors. */ break; case 'I': /* Include directory */ AddInclude( ap ); /* BP, 11.09.91 */ break; case 'N': /* No predefineds */ nflag++; /* Repeat to undefine */ break; /* __LINE__, etc. */ case 'S': sizp = size_table; if (0 != (isdatum = (*ap != '*'))) /* If it's just -S, */ endtest = T_FPTR; /* Stop here */ else /* But if it's -S* */ { ap++; /* Step over '*' */ endtest = 0; /* Stop at end marker */ } while (sizp->bits != endtest && *ap != EOS) { if (!isdigit(*ap)) /* Skip to next digit */ { ap++; continue; } size = 0; /* Compile the value */ while (isdigit(*ap)) { size *= 10; size += (*ap++ - '0'); } if (isdatum) sizp->size = size; /* Datum size */ else sizp->psize = size; /* Pointer size */ sizp++; } if (sizp->bits != endtest) cwarn("-S, too few values specified in %s", argv[i]); else if (*ap != EOS) cwarn("-S, too many values, \"%s\" unused", ap); break; case 'U': /* Undefine symbol */ if (defendel(ap, TRUE) == NULL) cwarn("\"%s\" wasn't defined", ap); break; #if OSL_DEBUG_LEVEL > 1 case 'X': /* Debug */ debug = (isdigit(*ap)) ? atoi(ap) : 1; #if (HOST == SYS_UNIX) signal(SIGINT, (void (*)(int)) abort); /* Trap "interrupt" */ #endif fprintf(stderr, "Debug set to %d\n", debug); break; #endif #if OSL_DEBUG_LEVEL > 1 case 'P': /* #define's dump */ bDumpDefs = 1; fprintf(stderr, "Dump #define's is on\n"); break; #endif default: /* What is this one? */ cwarn("Unknown option \"%s\"", arg); fprintf(stderr, "The following options are valid:\n\ -C\t\t\tWrite source file comments to output\n\ -Dsymbol=value\tDefine a symbol with the given (optional) value\n\ -Idirectory\t\tAdd a directory to the #include search list\n\ -N\t\t\tDon't predefine target-specific names\n\ -Stext\t\tSpecify sizes for #if sizeof\n\ -Usymbol\t\tUndefine symbol\n"); #if OSL_DEBUG_LEVEL > 1 fprintf(stderr, " -Xvalue\t\tSet internal debug flag\n"); fprintf(stderr, " -P\t\t\tdump #define's\n"); #endif break; } /* Switch on all options */ } /* If it's a -option */ } /* For all arguments */ #if OSL_DEBUG_LEVEL > 1 if ( (bDumpDefs ? j > 4 : j > 3) ) #else if (j > 3) #endif { cerror( "Too many file arguments. Usage: cpp [input [output]]", NULLST); } return (j); /* Return new argc */ }