Ejemplo n.º 1
0
int test_get_absolute__add_include_dir()
{
    static const size_t sz = SCRATCH_SZ;
    int errors = 0;
    char scratch[SCRATCH_SZ];

    strcpy( scratch, "path_utils_test.c" );
    if ( get_absolute( scratch, sz ) != -1 )
    {
        LOG("get_absolute: file should not have been found ['%s']'\n", scratch);
        ++errors;
    }

    add_include_dir(".");
    if ( get_absolute( scratch, sz ) != 0 )
    {
        LOG("get_absolute: file not found ['%s']' in './'\n", scratch);
        ++errors;
    }

    strcpy( scratch, "non-existent-file.c" );
    if ( get_absolute( scratch, sz ) != -1 )
    {
        LOG("get_absolute: file should not have been found ['%s']' in './'\n", scratch);
        ++errors;
    }

    if ( get_absolute( scratch, 5 ) != 1 )
    {
        LOG("get_absolute: buffer should have been too small for '%s'\n", scratch);
        ++errors;
    }

    return errors;
}
Ejemplo n.º 2
0
static int
do_test (void)
{
  void *ref = (void *) 0;
  void *ptr;

  ptr = get_absolute ();
  if (ptr != ref)
    FAIL_EXIT1 ("Got %p, expected %p\n", ptr, ref);

  return 0;
}
Ejemplo n.º 3
0
/*
// InitSourceFile
//
// Initializes all the fields in SOURCEFILE, and attempts to to open the
// file.
//
// Returns 1 on success, 0 on error
*/
SOURCEFILE *InitSourceFile( SOURCEFILE *pParent, char *filename,
                            int use_include_path )
{
    SOURCEFILE *ps;
    int i;
    char SourceName[SOURCE_NAME];
    char SourceBaseDir[SOURCE_BASE_DIR];

    /* Put a reasonable cap on #include depth */
    if( OpenFiles==15 )
    {
        Report(pParent,REP_FATAL,"Too many open files");
        return(0);
    }

    if ( use_include_path )
        if ( !is_definite(filename) )
        {
            switch ( get_absolute( filename, SOURCE_BASE_DIR ) )
            {
                case -1:
                  Report(pParent,REP_FATAL,
                         "Could not find '%s' in include paths",filename);
                  goto FILEOP_ERROR;
                case 1:
                  Report(pParent,REP_FATAL,
                         "Absolute pathname too long in [include-dirs]/'%s'",
                         filename);
                  goto FILEOP_ERROR;
            }
        }
    /* I don't imagine these test should ever fail at this point, but... */
    if ( get_dirname(filename, SourceBaseDir, SOURCE_BASE_DIR) )
    {
        Report(pParent,REP_FATAL,"Dirname too long in '%s'",filename);
        goto FILEOP_ERROR;
    }
    if ( get_basename(filename, SourceName, SOURCE_NAME) )
    {
        Report(pParent,REP_FATAL,"base filename too long in '%s'",filename);
        goto FILEOP_ERROR;
    }

    if( Options & OPTION_DEBUG )
        printf("Base source directory: '%s'\n",SourceBaseDir);

    /*
    // See if this file was used before, or allocate a new record
    */
    for( i=0; i<(int)sfIndex; i++ )
    {
        if( !sfArray[i].InUse &&
            !strcmp(SourceName, sfArray[i].SourceName) &&
            !strcmp(SourceBaseDir, sfArray[i].SourceBaseDir) )
            break;
    }

    if( i<(int)sfIndex )
        ps = &sfArray[i];
    else
    {
        /* Allocate a new file */
        if( sfIndex==SOURCEFILE_MAX )
            { Report(pParent,REP_FATAL,"Max source files exceeded"); return(0); }

        ps = &sfArray[sfIndex];
        i = sfIndex++;
    }

    /*
    // Fill in file record
    */
    memset( ps, 0, sizeof(SOURCEFILE) );

    if( Options & OPTION_DEBUG )
        printf("New source file: '%s'\n",filename);

    /* Init the base fields */
    ps->pParent       = 0;
    ps->LastChar      = 0;
    ps->CurrentLine   = 1;
    ps->CurrentColumn = 1;
    ps->ccDepthIn     = ccDepth;
    ps->InUse         = 1;
    ps->FileIndex     = i;

    strcpy( ps->SourceName, SourceName );
    strcpy( ps->SourceBaseDir, SourceBaseDir );


    /* Open the file */
    ps->FilePtr = fopen(filename,"rb");
    if (!ps->FilePtr)
    {
        Report(pParent,REP_FATAL,"Can't open source file '%s'",filename);
        goto FILEOP_ERROR;
    }
    OpenFiles++;
    if( OpenFiles > 10 )
        Report(pParent,REP_WARN1,"%d open files - possible #include recursion",OpenFiles);
    return(ps);

FILEOP_ERROR:
    return(0);
}