Пример #1
0
const char *DoWildCard( const char *base )
/***********************************************/
{
    PGROUP          pg;
    struct dirent   *entry;

    if( base != NULL ) {
        /* clean up from previous invocation */
        DoWildCardClose();

        if( strpbrk( base, WILD_METAS ) == NULL ) {
            return( base );
        }
        // create directory name and pattern
        path = MallocSafe( _MAX_PATH );
        pattern = MallocSafe( _MAX_PATH );
        strcpy( path, base );
        FixName( path );
        _splitpath2( path, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext );
        _makepath( path, pg.drive, pg.dir, ".", NULL );
        // create file name pattern
        _makepath( pattern, NULL, NULL, pg.fname, pg.ext );

        parent = opendir( path );
        if( parent == NULL ) {
            DoWildCardClose();
            return( base );
        }
    }

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

    assert( path != NULL && parent != NULL );

    while( (entry = readdir( parent )) != NULL ) {
#ifndef __UNIX__
        if( ( entry->d_attr & IGNORE_MASK ) == 0 ) {
#endif
            if( __fnmatch( pattern, entry->d_name ) ) {
                break;
            }
#ifndef __UNIX__
        }
#endif
    }
    if( entry == NULL ) {
        DoWildCardClose();
        return( base );
    }

    _splitpath2( path, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext );
    _makepath( path, pg.drive, pg.dir, entry->d_name, NULL );

    return( path );
}
Пример #2
0
STATIC char *getDirBuf( void )
/****************************/
{
    if( dirBuf == NULL ) {
        dirBuf = MallocSafe( _MAX_PATH );
    }
    return( dirBuf );
}
Пример #3
0
void OSLoadDLL( char *cmd_name, char *dll_name, char *ent_name )
/**************************************************************/
{
    DLL_CMD     *n;

    // we want newer !loaddlls to take precedence
    n = MallocSafe( sizeof( *n ) );
    n->cmd_name = StrDupSafe( cmd_name );
    n->next = dllCommandList;
    dllCommandList = n;
    IdeDrvInit( &n->inf, StrDupSafe( dll_name ),
                (ent_name == NULL) ? NULL : StrDupSafe( ent_name ) );
}
Пример #4
0
STATIC void pushFH( SENT *sent, int fh )
/***************************************
 * given an open file handle, this routine allocates a buffer, and pushes a
 * SENT onto the stack
 */
{
    assert( sent != NULL );

    sent->data.file.fh = fh;
    sent->data.file.buf = MallocSafe( FILE_BUFFER_SIZE );
    sent->data.file.cur = sent->data.file.buf;
    sent->data.file.max = sent->data.file.buf;
    sent->data.file.line = 1;
    sent->data.file.nestLevel = -1;
}
Пример #5
0
STATIC SENT *getSENT( STYPE_T type )
/***********************************
 * get a free sent, and push it into stack.  Determines next char of input.
 */
{
    SENT    *d;

    if( freeSent != NULL ) {    /* check if any free SENTs lying around */
        d = freeSent;
        freeSent = freeSent->next;
    } else {
        d = MallocSafe( sizeof( *d ) );
    }
    d->type = type;
    d->next = headSent;
    headSent = d;
    return( d );
}
Пример #6
0
void StreamInit( void )
/****************************/
{
    int     count;
    SENT    *sent;

    /* preallocate storage to speed things up, and reduce fragmentation */

    freeSent = NULL;
    for( count = 0; count < STREAM_ALLOC_SENT; count++ ) {
        sent = MallocSafe( sizeof( *sent ) );
        sent->next = freeSent;
        freeSent = sent;
    }

#ifdef USE_SCARCE
    IfMemScarce( streamScarce );
#endif
}
Пример #7
0
STATIC RET_T imply( TARGET *targ, const char *drive, const char *dir,
    const char *fname, const char *ext, bool must )
/********************************************************************
 * targ     is the target to be implied
 * drive    is the drive of the target
 * dir      is the path of the target
 * fname    is the portion of targ's name without the extension
 * ext      is the extension of targ's name
 * must     must we make this target?
 *
 * RET_SUCCESS - performed cmds,
 * RET_WARN unable to imply,
 * RET_ERROR - perform failed
 */
{
    SUFFIX      *srcsuf;
    CREATOR     *cur;
    SUFFIX      *cursuf;
    TARGET      *imptarg = NULL;
    RET_T       ret;
    bool        newtarg;
    UINT32      startcount;
    char        *buf;
    SLIST       *curslist;
    SLIST       *slist;     // Slist chosen for sufsuf
    SLIST       *slistDef;  // Slist that has dependent path = ""
    SLIST       *slistEmptyTargDepPath;
    bool        UseDefaultSList;
    int         slistCount;

    srcsuf = FindSuffix( ext );
    if( srcsuf == NULL || srcsuf->creator == NULL ) {
        PrtMsg( DBG | INF | IMP_ENV_M, targ->node.name, M_HAS_NO_IMPLICIT );
        return( RET_WARN );
    }
    PrtMsg( DBG | INF | IMP_ENV_M, targ->node.name, M_CHECKING_IMPLICIT );
    startcount = cListCount;

    for( cur = srcsuf->creator; cur != NULL; cur = cur->next ) {
        cursuf = cur->suffix;

        /* allocate a buffer */
        buf = MallocSafe( _MAX_PATH );
        slist = NULL;
        slistDef = NULL;
        slistEmptyTargDepPath = NULL;

        ret = RET_ERROR;

        UseDefaultSList = true;
        /* find path in SLIST */
        slistCount = 0;
        for( curslist = cur->slist; curslist != NULL && ret != RET_SUCCESS; curslist = curslist->next ) {
            _makepath( buf, drive, dir, NULL, NULL );
            FixName( buf );
            /*
             * note the path of the current target must match the
             * path as specified in the slist
             */
            if( stricmp( buf, curslist->targ_path ) == 0 ) {
                /* build filename for implied target */
                _makepath( buf, NULL, curslist->dep_path, fname, cursuf->node.name );
                /* try to find this file on path or in targets */
                ret = TrySufPath( buf, buf, &imptarg, false );
                if( ret == RET_SUCCESS ) {
                    slist = curslist;
                    /* later on we need to check if implied target does not */
                    /* exist we need to create it on the first directory we */
                    /* see on the SLIST since                               */
                    /* the first on the list is the one that was defined    */
                    /* last in the makefile                                 */
                } else if( slistDef == NULL ) {
                    slistDef = curslist;
                }
            }
            if( *curslist->targ_path == NULLCHAR && *curslist->dep_path == NULLCHAR ) {
                slistEmptyTargDepPath = curslist;
            }

            if( slistCount > 0 && slistEmptyTargDepPath != NULL ) {
                UseDefaultSList = false;
            }
            ++slistCount;
        }

        if( UseDefaultSList && slist == NULL && !Glob.compat_nmake ) {
            _makepath( buf, NULL, NULL, fname, cursuf->node.name );
            /* try to find this file on path or in targets */
            ret = TrySufPath( buf, buf, &imptarg, false );
            switch( ret ) {
            case RET_WARN:
                break;
            case RET_ERROR:
                if( !Glob.compat_nmake ) {
                    slistDef = slistEmptyTargDepPath;
                }
                break;
            case RET_SUCCESS:
                slist = slistEmptyTargDepPath;
                break;
            }
        }

        if( ret == RET_ERROR && slistDef == NULL ) {
            /*
             * No Default Slist found so must continue and find
             * another slist
             */
            FreeSafe( buf );
            continue;
        }

        if( (ret == RET_SUCCESS && imptarg == NULL) || ret == RET_ERROR ) {
            /* Either file doesn't exist, or it exists and we don't already
             * have a target for it.  Either way, we create a new target.
             */
            if( ret == RET_ERROR ) {
                slist = slistDef;
                /* file doesn't exist, assume in directory */
                /* pointed to by the slistDef              */
                _makepath( buf, NULL, slist->dep_path, fname, cursuf->node.name );

            }
            newtarg = true;
            imptarg = NewTarget( buf );
            FreeSafe( buf );        /* don't need any more */
            getStats( imptarg );
            imptarg->busy = true;   /* protect against recursion */
            if( imply( imptarg, NULL, slist->dep_path, fname, cursuf->node.name, false ) == RET_ERROR ) {
                imptarg->error = true;
            }
            if( startcount != cListCount && (Glob.noexec || Glob.query) ) {
                imptarg->touched = true;
                imptarg->executed = true;
            }
            imptarg->updated = true;
            imptarg->busy = false;
        } else {
            /* We already know about imptarg, so just update it */
            assert( imptarg != NULL );
            FreeSafe( buf );        /* don't need any more */
            newtarg = false;        /* this isn't a new target */
            Update( imptarg );
        }

        /* We've tried our best to make the imptarg, check if it exists
         * after our efforts.
         */
        if( targExists( imptarg ) ) {
            /* it exists - now we perform the implicit cmd list, and return */
            ret = implyMaybePerform( targ, imptarg, slist->cretarg, must );
            if( newtarg && !Glob.noexec ) {
                /* destroy the implied target, because the info in the target
                 * structure is nicely stored on disk (unless Glob.noexec)
                 */
                KillTarget( imptarg->node.name );
            }
            implyDebugInfo( targ, startcount );
            return( ret );
        } else if( newtarg ) {
            /* we created an unsuccessful target - so destroy it */
            KillTarget( imptarg->node.name );
        }

        /* We couldn't imply with this suffix... try next one */
    }
    implyDebugInfo( targ, startcount );
    return( RET_WARN );
}