Example #1
0
const char *procPath( const char *fullpath )
/**************************************************
 * process fullpath according to the form qualifier in CurAttr.num
 * returns: pointer to a static buffer
 */
{
    PGROUP  pg;
    char    *p;

    if( fullpath == NULL ) {
        return( NULL );
    }

    getDirBuf();

    _splitpath2( fullpath, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext );

    switch( CurAttr.u.form ) {
    case FORM_FULL:
        _makepath( dirBuf, pg.drive, pg.dir, pg.fname, pg.ext );
        break;
    case FORM_NOEXT:
        _makepath( dirBuf, pg.drive, pg.dir, pg.fname, NULL );
        break;
    case FORM_NOEXT_NOPATH:
        _makepath( dirBuf, NULL, NULL, pg.fname, NULL );
        break;
    case FORM_NOPATH:
        _makepath( dirBuf, NULL, NULL, pg.fname, pg.ext );
        break;
    case FORM_PATH:
        _makepath( dirBuf, pg.drive, pg.dir, NULL, NULL );
        if( Glob.compat_nmake ) {
            if( dirBuf[0] == NULLCHAR ) {
                dirBuf[0] = '.';
                dirBuf[1] = NULLCHAR;
            } else {
                p = dirBuf;
                while( *p != NULLCHAR ) {
                    ++p;
                }
                if( *(p - 1) == '\\' ) {
                    *(p - 1) = NULLCHAR;
                }
            }
        }
        break;
    case FORM_EXT:
        _makepath( dirBuf, NULL, NULL, NULL, pg.ext );
        break;
    default:
        dirBuf[0] = NULLCHAR;
    }

    massageDollarOctothorpe( dirBuf );
    return( dirBuf );
}
Example #2
0
STATIC const char *GetMacroValueProcess( const char *name )
/**********************************************************
 * returns: pointer to text of macro (incl. environment vars)
 */
{
    char    macro[MAX_MAC_NAME];
    MACRO   *cur;
    char    *env;
    BOOLEAN cdrive;
    BOOLEAN cwd;
    BOOLEAN ctime;
    char    *p;
    int     pos;

    makeMacroName( macro, name ); // Does assert( IsMacroName( name ) );

    if( *macro == ENVVAR ) {
        env = getenv( macro + 1 );
        if( env != NULL ) {
            return( env );
        }
        cdrive = strcmp( macro + 1, "CDRIVE" ) == 0 ||
                 strcmp( macro + 1, "__CDRIVE__" ) == 0;
        cwd    = strcmp( macro + 1, "CWD" ) == 0 ||
                 strcmp( macro + 1, "__CWD__" ) == 0;
        ctime  = strcmp( macro + 1, "__CTIME__" ) == 0;
        if( cdrive || cwd ) {
            if( getcwd( getDirBuf(), _MAX_PATH ) == NULL ) {
                return( NULL );
            }
            p = strchr( dirBuf, ':' );
            if( cdrive ) {
                if( p != NULL ) {
                    *p = NULLCHAR;
                } else {
                    dirBuf[0] = NULLCHAR;
                }
            } else {    /* cwd */
                if( p != NULL ) {
                    return( p + 1 );
                }
            }
            return( dirBuf );
        } else if( ctime ) {
            time_t      timex;
            struct tm   *tm;

            time( &timex );
            tm = localtime( &timex );
            FmtStr( getDirBuf(), "%D:%D:%D", tm->tm_hour, tm->tm_min, tm->tm_sec );
            return( dirBuf );
        }
        return( NULL );
    }

    cur = getMacroNode( macro );
    if( cur != NULL ) {
        return( cur->value );
    }

    // If not defined as a macro then get it as a Environment variable
    if( Glob.compat_nmake || Glob.compat_posix ) {
        // Check if macro is all caps in NMAKE mode
        if( Glob.compat_nmake ) {
            for( pos = 0; macro[pos] != NULLCHAR; ++pos ) {
                if( macro[pos] != toupper( macro[pos] ) ) {
                    return( NULL );
                }
            }
        }
        env = getenv( macro );
        if( env != NULL ) {
            return( env );
        }
    }

    return( NULL );
}