Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    r36de20d r67bfc50  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 16 23:05:59 2020
    13 // Update Count     : 447
     12// Last Modified On : Thu Aug 13 17:22:02 2020
     13// Update Count     : 435
    1414//
    1515
    1616#include <iostream>
    17 #include <cstdio>                                                                               // perror
    18 #include <cstdlib>                                                                              // putenv, exit
    19 #include <climits>                                                                              // PATH_MAX
    20 #include <string>                                                                               // STL version
    21 #include <algorithm>                                                                    // find
    22 
    23 #include <unistd.h>                                                                             // execvp
     17#include <cstdio>      // perror
     18#include <cstdlib>     // putenv, exit
     19#include <climits>     // PATH_MAX
     20#include <unistd.h>    // execvp
     21#include <string>      // STL version
     22#include <string.h>    // strcmp
     23#include <algorithm>   // find
     24
    2425#include <sys/types.h>
    2526#include <sys/stat.h>
     
    3334using std::to_string;
    3435
    35 //#define __DEBUG_H__
    36 
    37 #define xstr(s) str(s)
    38 #define str(s) #s
    39 
    40 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "__CFA_FLAG__=" suffix
    41 
    42 static void Putenv( char * argv[], string arg ) {
     36// #define __DEBUG_H__
     37
     38// "N__=" suffix
     39static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );
     40
     41void Putenv( char * argv[], string arg ) {
    4342        // environment variables must have unique names
    4443        static int flags = 0;
     
    5049} // Putenv
    5150
    52 static bool prefix( const string & arg, const string & pre ) { // check if string has prefix
     51// check if string has prefix
     52bool prefix( const string & arg, const string & pre ) {
    5353        return arg.substr( 0, pre.size() ) == pre;
    5454} // prefix
    5555
    56 static inline bool ends_with(const string & str, const string & sfix) {
     56inline bool ends_with(const string & str, const string & sfix) {
    5757        if (sfix.size() > str.size()) return false;
    5858        return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend());
     
    6060
    6161// check if string has suffix
    62 static bool suffix( const string & arg ) {
     62bool suffix( const string & arg ) {
    6363        enum { NumSuffixes = 3 };
    6464        static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
     
    7070} // suffix
    7171
     72
    7273static inline bool dirExists( const string & path ) {   // check if directory exists
    7374    struct stat info;
     
    7879static inline string dir(const string & path) {
    7980        return path.substr(0, path.find_last_of('/'));
    80 } // dir
     81}
    8182
    8283// Different path modes
     
    117118}
    118119
     120
     121#define xstr(s) str(s)
     122#define str(s) #s
    119123
    120124int main( int argc, char * argv[] ) {
     
    154158        PathMode path = FromProc();
    155159
    156         const char * args[argc + 100];                                          // cfa command line values, plus some space for additional flags
     160        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
    157161        int sargs = 1;                                                                          // starting location for arguments in args list
    158162        int nargs = sargs;                                                                      // number of arguments in args list; 0 => command name
    159163
    160         const char * libs[argc + 20];                                           // non-user libraries must come separately, plus some added libraries and flags
     164        const char *libs[argc + 20];                                            // non-user libraries must come separately, plus some added libraries and flags
    161165        int nlibs = 0;
    162166
     
    181185                                args[nargs++] = argv[i];                                // pass argument along
    182186                                if ( arg == "-o" ) o_file = i;                  // remember file
    183 
    184                                 // CFA specific arguments
    185 
    186187                        } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through
    187188                                if ( arg.size() == 5 ) {
     
    202203                        } else if ( arg == "-nodebug" ) {
    203204                                debug = false;                                                  // strip the nodebug flag
     205                        } else if ( arg == "-nolib" ) {
     206                                nolib = true;                                                   // strip the nodebug flag
    204207                        } else if ( arg == "-quiet" ) {
    205208                                quiet = true;                                                   // strip the quiet flag
    206209                        } else if ( arg == "-noquiet" ) {
    207210                                quiet = false;                                                  // strip the noquiet flag
    208                         } else if ( arg == "-no-include-stdhdr" ) {
    209                                 noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    210                         } else if ( arg == "-nolib" ) {
    211                                 nolib = true;                                                   // strip the nolib flag
    212211                        } else if ( arg == "-help" ) {
    213212                                help = true;                                                    // strip the help flag
    214213                        } else if ( arg == "-nohelp" ) {
    215214                                help = false;                                                   // strip the nohelp flag
     215                        } else if ( arg == "-no-include-stdhdr" ) {
     216                                noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    216217                        } else if ( arg == "-cfalib") {
    217218                                compiling_libs = true;
     
    335336        string libbase;
    336337        switch(path) {
    337           case Installed:
     338        case Installed:
    338339                args[nargs++] = "-I" CFA_INCDIR;
    339340                // do not use during build
     
    345346                libbase = CFA_LIBDIR;
    346347                break;
    347           case BuildTree:
    348           case Distributed:
     348        case BuildTree:
     349        case Distributed:
    349350                args[nargs++] = "-I" TOP_SRCDIR "libcfa/src";
    350351                // do not use during build
     
    380381        string libdir = libbase + arch + "-" + config;
    381382
    382         if ( path != Distributed ) {
     383        if (path != Distributed) {
    383384                if ( ! nolib && ! dirExists( libdir ) ) {
    384385                        cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     
    400401        string preludedir;
    401402        switch(path) {
    402           case Installed   : preludedir = libdir; break;
    403           case BuildTree   : preludedir = libdir + "/prelude"; break;
    404           case Distributed : preludedir = dir(argv[0]); break;
    405         } // switch
     403        case Installed   : preludedir = libdir; break;
     404        case BuildTree   : preludedir = libdir + "/prelude"; break;
     405        case Distributed : preludedir = dir(argv[0]); break;
     406        }
    406407
    407408        Putenv( argv, "--prelude-dir=" + preludedir );
     
    475476        if ( bprefix.length() == 0 ) {
    476477                switch(path) {
    477                   case Installed   : bprefix = installlibdir; break;
    478                   case BuildTree   : bprefix = srcdriverdir ; break;
    479                   case Distributed : bprefix = dir(argv[0]) ; break;
    480                 } // switch
    481         } // if
    482         if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
    483         Putenv( argv, string("-B=") + bprefix );
     478                case Installed   : bprefix = installlibdir; break;
     479                case BuildTree   : bprefix = srcdriverdir ; break;
     480                case Distributed : bprefix = dir(argv[0]) ; break;
     481                }
     482                if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
     483                Putenv( argv, string("-B=") + bprefix );
     484        } // if
    484485
    485486        args[nargs++] = "-Xlinker";                                                     // used by backtrace
     
    503504                args[nargs++] = "-Wno-cast-function-type";
    504505                #endif // HAVE_CAST_FUNCTION_TYPE
    505                 if ( ! std_flag && ! x_flag ) {
    506                         args[nargs++] = "-std=gnu11";                           // default c11, if none specified
     506                if ( ! std_flag ) {                                                             // default c11, if none specified
     507                        args[nargs++] = "-std=gnu11";
    507508                } // if
    508509                args[nargs++] = "-fgnu89-inline";
     
    554555        // execute the command and return the result
    555556
    556         execvp( args[0], (char * const *)args );                        // should not return
     557        execvp( args[0], (char *const *)args );                         // should not return
    557558        perror( "CFA Translator error: execvp" );
    558559        exit( EXIT_FAILURE );
Note: See TracChangeset for help on using the changeset viewer.