Exemplo n.º 1
0
Arquivo: dir.c Projeto: 8l/vlink
char *read_dir(char *d)
/* get next file name from opened directory, NULL if no more entries */
{
  if (ExNext(((struct Dir *)d)->lock,&(((struct Dir *)d)->fib)))
    return ((struct Dir *)d)->fib.fib_FileName;
  if (IoErr() != ERROR_NO_MORE_ENTRIES)
    error(10,((struct Dir *)d)->name);
  return NULL;
}
Exemplo n.º 2
0
static void * simulated_readdir(SIMULATED_DIR * dirstream) {
  BOOL ok;
  SIMULATED_DIR *result = NULL;

  ok = (ExNext(dirstream->lock, dirstream->info) != DOSFALSE);

  if (ok) {
    result = dirstream;
  }
  return (void *) result;
}
Exemplo n.º 3
0
void ReadAll(BPTR lock)
{
  struct FileInfoBlock * FIB = AllocVec(sizeof(struct FileInfoBlock), MEMF_CLEAR);
  BOOL success;
  int count = 1;

  success = Examine(lock, FIB);
  if (FIB->fib_DirEntryType < 0)
    success = FALSE;
  if (success)
    success = ExNext(lock, FIB);
  while (success)
  {
    printf("%s",FIB->fib_FileName);
    if (FIB->fib_DirEntryType > 0)
    {
      printf(" (Dir)\n");
      count++;
      if (count > 1)
      {
        char * name = AllocVec(1024,0);
        BPTR tmplock;
        NameFromLock(lock,name,1024);
        AddPart(name,FIB->fib_FileName,1024);
        printf("Entering %s\n",name);
        tmplock = Lock(name , ACCESS_READ);
        ReadAll(tmplock);
        NameFromLock(lock,name,1024);
        printf("Returning to %s\n",name);
        UnLock(tmplock);
        FreeVec(name);
      }
    }
    else
    {
      printf("\n");
    }
    success = ExNext(lock,FIB);
  }
  FreeVec(FIB);
}
Exemplo n.º 4
0
/* return next dir entry */
int my_readdir (struct my_opendir_s *mod, TCHAR *name) {

  if(ExNext(mod->lock, mod->h)) {
    strcpy(name, (TCHAR *) mod->h->fib_FileName);
    DebOut("name: %s\n", name);

    return TRUE;
  }

  DebOut("no more files/error!\n");

  /* no more entries */
  return FALSE;
}
Exemplo n.º 5
0
struct List *LoadBlankerEntries( STRPTR Path )
{
    struct FileInfoBlock *Blk;
    struct List *Entries = 0L;
    BlankerEntry *New;
    BPTR DirLock;
	
    if(!( Entries = AllocVec( sizeof( struct List ), MEMF_CLEAR )))
        return 0L;
    else
        NewList( Entries );
	
    NumBlankEntries = 0;
    
    if( DirLock = Lock( Path, ACCESS_READ ))
    {
        if(( Blk = AllocDosObject( DOS_FIB, 0L ))&&( Examine( DirLock, Blk )))
        {
            while( ExNext( DirLock, Blk ))
            {
                if(( Blk->fib_FileName )&&
                   ( FileIsModule( Path, Blk->fib_FileName )))
                {
                    if( New = NewBlankerEntry( Path, Blk->fib_FileName,
											  Blk->fib_Comment ))
                    {
                        New->be_Node.ln_Pri = 128 - ( New->be_Name[0] - 'a' );
                        Enqueue( Entries, ( struct Node * )New );
                        NumBlankEntries++;
                    }
                }
            }
            FreeDosObject( DOS_FIB, Blk );
        }
        UnLock( DirLock );
    }
    
    if( New = NewBlankerEntry( ":", "Random", "" ))
        AddTail( Entries, ( struct Node * )New );
	
    return Entries;
}
Exemplo n.º 6
0
static int findFirstMatch( char * pFileName, char * wpName )
{
static BOOL isfirst=TRUE;
BPTR dirlock;
struct Node * newnode;
/* char * onefname; */
char * point;
unsigned len;

/* printf("Called findFirstMatch: %s %s\n", pFileName, wpName); */

if(isfirst)
	{
	isfirst=FALSE;

	NewListPPC(&filelist);

	fib = AllocDosObject(DOS_FIB, NULL);

	strcpy(filepart, FilePart(pFileName));

	if((point=PathPart(pFileName)) == pFileName) /* Current directory */
		{
		dirlock=DupLock(((struct Process *)FindTask(NULL))->pr_CurrentDir);
		*pathpart=0;
		}
	else
		{
		len =(unsigned) (point-pFileName);
		strncpy(pathpart, pFileName, len);
		pathpart[len]=0;

		dirlock=Lock(pathpart, ACCESS_READ);
		}

	if(dirlock)
		{
		if(Examine(dirlock, fib))
			{
			while(ExNext(dirlock, fib))
				{
				if(fib->fib_DirEntryType == ST_FILE || fib->fib_DirEntryType == ST_LINKFILE)
					{
					/* printf("%s\n", fib->fib_FileName); */

					newnode=malloc(sizeof(struct Node));

					newnode->ln_Type = NT_USER;
					newnode->ln_Name=malloc(strlen(fib->fib_FileName)+1);
					strcpy(newnode->ln_Name, fib->fib_FileName);

					AddTailPPC(&filelist, newnode);

					}
				}
			}

		UnLock(dirlock);

		FreeDosObject(DOS_FIB, fib);
		}
	else	return FALSE;
	}

if(ParsePatternNoCase(filepart, parsebuf, PARSEBUFLEN))
	{
	for(currentnode = filelist.lh_Head; currentnode->ln_Succ; currentnode = currentnode->ln_Succ)
		{
		/* printf("Match %s %s\n", parsebuf, currentnode->ln_Name); */
		if(MatchPatternNoCase(parsebuf, currentnode->ln_Name))
			{
			/* printf("Trovato %s\n", currentnode->ln_Name); */
			strcpy(wpName, pathpart);
			AddPart(wpName, currentnode->ln_Name, MAX_NAMELEN);
			currentnode = currentnode->ln_Succ;
			return TRUE;
			}
		}
/*	return FALSE; */
	}
return FALSE;
}
Exemplo n.º 7
0
int __stat_from_path(const char *path, struct stat *sb)
{
    int                  len;
    char                 *mypath;
    int                  cwdsize = FILENAME_MAX;
    char                 *cwd = NULL;
    char                 *abspath = NULL;
    char                 *filepart = NULL;
    char                 *split;
    struct FileInfoBlock *fib = NULL;
    BPTR                 lock = BNULL;
    BPTR                 cwdlock;
    int                  fallback_to_defaults = 0;
    BOOL                 loop;
    int                  res = -1;

    /* copy path and strip trailing slash */
    len = strlen(path);
    if (!(mypath = AllocVec(len + 1, MEMF_ANY)))
    {
        errno = ENOMEM;
        goto out;
    }
    strcpy(mypath, path);
    if (len && mypath[len-1] == '/')
        mypath[len-1] = '\0';

    /* do we have an absolute path */
    if (!strchr(mypath, ':'))
    {
        /* no, then create one */
        cwdlock = CurrentDir(BNULL);
        CurrentDir(cwdlock);
        do
        {
            if (!(cwd = AllocVec(cwdsize, MEMF_ANY)))
            {
                errno = ENOMEM;
                goto out;
            }

            if (NameFromLock(cwdlock, cwd, cwdsize))
                break;
            else if (IoErr() != ERROR_LINE_TOO_LONG)
            {
                errno = __stdc_ioerr2errno(IoErr());
                goto out;
            }

            FreeVec(cwd);
            cwdsize *= 2;
        }
        while (TRUE);

        /* get memory for current dir + '/' + input path + zero byte */
        len = strlen(cwd) + 1 + len + 1;
        abspath = AllocVec(len, MEMF_ANY);
        if (!abspath)
        {
            errno = ENOMEM;
            goto out;
        }

        strcpy(abspath, cwd);
        AddPart(abspath, mypath, len);
        FreeVec(mypath);
    }
    else
        abspath = mypath;

    /* split into path part and file part */
    split = FilePart(abspath);
    filepart = AllocVec(strlen(split) + 1, MEMF_ANY);
    if (!filepart)
    {
        errno = ENOMEM;
        goto out;
    }
    strcpy(filepart, split);
    *split = '\0';

    if (   !(fib = AllocDosObject(DOS_FIB, NULL))
        || !(lock = Lock(abspath, SHARED_LOCK)))
    {
        errno = __stdc_ioerr2errno(IoErr());
        goto out;
    }

    /* examine parent directory of object to stat */
    if (!Examine(lock, fib))
    {
        if (IoErr() == ERROR_NOT_IMPLEMENTED ||
            IoErr() == ERROR_ACTION_NOT_KNOWN)
            fallback_to_defaults = 1;
        else
        {
            errno = __stdc_ioerr2errno(IoErr());
            goto out;
        }
    }

    if (*filepart == '\0' || fallback_to_defaults)
        __fill_statbuffer(sb, abspath, fib, fallback_to_defaults, lock);
    else
        /* examine entries of parent directory until we find the object to stat */
        do
        {
            loop = ExNext(lock, fib);

            if (loop)
            {
                if (stricmp(fib->fib_FileName, filepart) == 0)
                {
                    __fill_statbuffer(sb, abspath, fib, 0, lock);
                    res = 0;
                    break;
                }

                continue;
            }

            if (IoErr() != ERROR_NO_MORE_ENTRIES)
                errno = __stdc_ioerr2errno(IoErr());
            else
                /* nothing found to stat */
                errno = ENOENT;
        }
        while (loop);

out:
    if (lock)
        UnLock(lock);

    FreeVec(cwd);

    /* if we had absolute path as input, mypath is free'd here */
    FreeVec(abspath);

    FreeVec(filepart);

    if (fib)
        FreeDosObject(DOS_FIB, fib);

    return res;
}
Exemplo n.º 8
0
void readTextInfo(void) {  
  struct FileInfoBlock *fib;
  BPTR lock, fh;
  ULONG high=0, low=-1L, nr;
  char filename[40];
  struct Header readhead;

  if(!(fib=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),
                                            MEMF_CLEAR))) {
    cleanup(EXIT_ERROR, "Couldn't allocate a FileInfoBlock");
  }
  if(!(lock=Lock("NiKom:Moten",ACCESS_READ))) {
    FreeMem(fib,sizeof(struct FileInfoBlock));
    cleanup(EXIT_ERROR, "Couldn't lock NiKom:Moten.");
  }
  if(!Examine(lock,fib)) {
    FreeMem(fib,sizeof(struct FileInfoBlock));
    UnLock(lock);
    cleanup(EXIT_ERROR, "Couldn't Examine() NiKom:Moten.");
  }
  while(ExNext(lock, fib)) {
    if(strncmp(fib->fib_FileName, "Head", 4)) {
      continue;
    }
    nr = atoi(&fib->fib_FileName[4]);
    if(nr > high) {
      high = nr;
    }
    if(nr < low) {
      low=nr;
    }
  }
  UnLock(lock);
  FreeMem(fib,sizeof(struct FileInfoBlock));
  
  if(low == -1L) {
    printf("No Head.dat files found. Assuming system has no texts yet.\n");
    Servermem->info.hightext = -1L;
    Servermem->info.lowtext = 0L;
    return;
  }

  sprintf(filename, "NiKom:Moten/Head%d.dat", low);
  if(!(fh = Open(filename, MODE_OLDFILE))) {
    printf("Can't open %s.\n", filename);
    cleanup(EXIT_ERROR, "Couldn't get lowest textnumber.");
  }
  if(Seek(fh,0,OFFSET_BEGINNING) == -1) {
    Close(fh);
    cleanup(EXIT_ERROR, "Couldn't Seek() in Head.dat (1)");
  }
  if(Read(fh, &readhead, sizeof(struct Header)) != sizeof(struct Header)) {
    Close(fh);
    cleanup(EXIT_ERROR, "Couldn't read Head.dat (1)");
  }
  Servermem->info.lowtext = readhead.nummer;
  Close(fh);
  
  sprintf(filename,"NiKom:Moten/Head%d.dat", high);
  if(!(fh = Open(filename,MODE_OLDFILE))) {
    printf("Can't open %s.\n", filename);
    cleanup(EXIT_ERROR, "Couldn't get highest textnumber.");
  }
  if(Seek(fh, -sizeof(struct Header), OFFSET_END) == -1) {
    Close(fh);
    cleanup(EXIT_ERROR, "Couldn't Seek() in Head.dat (2)");
  }
  if(Read(fh, &readhead, sizeof(struct Header)) != sizeof(struct Header)) {
    Close(fh);
    cleanup(EXIT_ERROR, "Couldn't read Head.dat (2)");
  }
  Servermem->info.hightext = readhead.nummer;
  Close(fh);
  printf("Lowtext: %d  Hightext: %d\n",
         Servermem->info.lowtext, Servermem->info.hightext);
}
Exemplo n.º 9
0
ULONG
LoadModeFile( UBYTE*          name,
              struct AHIBase* AHIBase )
{
  ULONG rc=FALSE;
  struct FileInfoBlock  *fib;
  BPTR  lock,thisdir;

  if(AHIBase->ahib_DebugLevel >= AHI_DEBUG_HIGH)
  {
    Debug_LoadModeFile(name);
  }

  SetIoErr(NULL);

  fib = AllocDosObject(DOS_FIB, TAG_DONE);

  if(fib != NULL)
  {
    lock = Lock(name, ACCESS_READ);

    if(lock != NULL)
    {
      if(Examine(lock,fib))
      {
        if(fib->fib_DirEntryType>0) // Directory?
        {
          thisdir = CurrentDir(lock);

          while(ExNext(lock, fib))
          {
            if(fib->fib_DirEntryType>0)
            {
              continue;     // AHI_LoadModeFile(fib->fib_FileName); for recursion
            }
            else
            {
              rc = AddModeFile(fib->fib_FileName);

              if(!rc)
              {
                break;
              }
            }
          }
          if(IoErr() == ERROR_NO_MORE_ENTRIES)
          {
            SetIoErr(NULL);
          }

          CurrentDir(thisdir);
        }
        else  // Plain file
        {
          rc = AddModeFile(name);
        }
      }

      UnLock(lock);
    }

    FreeDosObject(DOS_FIB,fib);
  }

  if(AHIBase->ahib_DebugLevel >= AHI_DEBUG_HIGH)
  {
    KPrintF("=>%ld\n",rc);
  }

  return rc;
}