Example #1
0
void main()
{
char choice;
while(1)
{
clrscr();
printf("\n\n ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("================ telephone directory database =================");
printf("\n\n");
printf("\n 1     : add record in the database ");
printf("\n 2     : find record from the database ");
printf("\n 3     : read all record in the database ");
printf("\n 4     : quit from this software");
printf("\n\n      enter your choice");
fflush(stdin);
choice=getchar();
switch(choice)
{
case     '1'    :   appenddata();
break;
case     '2'    : finddata();
break;
case '3' : showalldata();
break;
case '4' : quit();
case '23' : exit(1);
}
}
}
Example #2
0
int
markblock(ulong from, ulong fromval, Block *b)
{
	Data *d;
	ulong top;
	Block *nb;

USED(from, fromval);
//print("trace 0x%.8lux from 0x%.8lux (%d)\n", b->addr, from, b->mark);
	if(b->free){
	//	fprint(2, "possible dangling pointer *0x%.8lux = 0x%.8lux\n", from, fromval);
		return 0;
	}
	if(b->mark)
		return 0;
	b->mark = 1;
	nmark++;

	if(d = finddata(b->addr)) {
		assert(d->addr >= b->addr);
		b->d = d;
		top = b->addr+b->size;
		for(; d < edata && d->addr < top; d++) {
			assert(d->b == 0);
			d->b = b;
			if((nb = findblock(d->val-8)) || (nb = findblock(d->val-8-8)))
				markblock(d->addr, d->val, nb);
		}
		return 1;
	}
	return 0;
}
Example #3
0
void convert(FILE *D_in, FILE *D_out)
{
/* Buffers utilizados por la rutina */
  float   *fvertbuf;		 // Valores en coma flotante de los v‚rtices
  float   *nbuf;		 // Buffer de normales (averaged)
  long    *vertbuf;		 // Vertices en modo fixed
  WORD    *facebuf, *list;	 // Lista de caras... ; Lista de normales que converge...
  char    *filebuf;		 // Buffer del fichero cargado en memoria...

/* Datos varios */
  float   ftemp;
  long    ltemp;
  short   itemp;
  long    len;
  char    number[255];
  long    i=0, j=0, k=0, np=0, p=0;
  BYTE    col=0;
  float   scalar;
  char    *inmem = { "\n\rInsuficient memory!!!\n" };
  char    *errorv = { "\n\rError in Vertex %d:%c" };
  char    *errorf = { "\n\rError in Face %d:%c ; Value: %s" };
  char    *errord = { "\n\n\r Hey men, where are the %ss definitions?" };
  char    *abort = { "\n\n\r Too many errors!\n\r Aborted.\n" };
  long    error = 0;
  dot3d   normal;
  float   max, opt;


  len = filesize(D_in);

// Read the file into memory
  if((filebuf = (char *) malloc(len)) == NULL) {
    cprintf("\r\nERROR: Insuficient memory for file buffer (¨¨Comorllll??)\n");
    exit(0);
  }

  fread(filebuf, 1, (size_t)len, D_in);


// Initalize the struct
  shape.ident = 0x3DEF;
  shape.atrib = 0;

// Extract the number of vertx
  if((pos = finddata(filebuf, data_table[0])) == NULL) {
    cprintf("\n\r ERROR: Vertices not defined!");
    exit(0);
  }

  getns(filebuf, strtemp);
  shape.numverts = atoi(strtemp);
  cprintf("\n\r  Number of vertices: %d", shape.numverts);

// Now with the faces...
  if((pos = finddata(filebuf, data_table[1])) == NULL) {
    cprintf("\n\rERROR: Faces not defined!\n");
    exit(0);
  }

  getns(filebuf, strtemp);
  shape.numfaces = atoi(strtemp);
  cprintf("\n\r  Number of faces: %d", shape.numfaces);


// ¨Maped?
  getns(filebuf, strtemp);
  if((strcmp(strtemp, data_table[16])) == NULL) {
    cprintf("\n\r  Mesh Mapped.");
    shape.atrib |= 1;
    SizeVertex = 32 / 4;
  } else {
    SizeVertex = (32-8) / 4;
  }

// Here is the memory allocation
  if((vertbuf = (long *) malloc(shape.numverts * (SizeVertex*4))) == NULL) {
    cprintf(inmem);
    exit(0);
  }

  if((fvertbuf = (float *) malloc(shape.numverts * sizeof(dot3d))) == NULL) {
    cprintf(inmem);
    exit(0);
  }

  if((facebuf = (WORD *) malloc(shape.numfaces * 14)) == NULL) {
    cprintf(inmem);
    exit(0);
  }

  if((nbuf = (float *) malloc(shape.numfaces * sizeof(dot3d))) == NULL) {
    cprintf(inmem);
    exit(0);
  }

  if((list = (WORD *) malloc(shape.numfaces * 2)) == NULL) {
    cprintf(inmem);
    exit(0);
  }

/* Proceso de extracci¢n de v‚rtices */
  cprintf("\n\r  Converting Vertices.");
  pos = finddata(filebuf, data_table[5]);

  if(pos == -1) {
    cprintf(errord, data_table[5]);
    exit(-1);
  }

  for(i = 0; i < shape.numverts; i++) {
    if(error > MAX_ERRORS) {
      cprintf(abort);
      exit(-1);
    }

    if((i % 32) == 0) cprintf(".");
    do {
      getns(filebuf, strtemp);
    } while((strcmp(strtemp, data_table[13])) != NULL);


    getns(filebuf, strtemp);

    getns(filebuf, strtemp);
    if((strtemp[0] == 'X')) { 
      getns(filebuf, strtemp);
      scalar = atof(strtemp);
      fvertbuf[k++] = scalar * SCALE;
      vertbuf[j++] = (long)(scalar * 65536 * SCALE);
    } else {
      error++;
      cprintf(errorv, i, 'X');
    }

    getns(filebuf, strtemp);
    if((strtemp[0] == 'Y')) { 
      getns(filebuf, strtemp);
      scalar = atof(strtemp);
      fvertbuf[k++] = scalar * SCALE;
      vertbuf[j++] = (long)(scalar * 65536 * SCALE);
    } else {
      error++;
      cprintf(errorv, i, 'Y');
    }

    getns(filebuf, strtemp);
    if((strtemp[0] == 'Z')) { 
      getns(filebuf, strtemp);
      scalar = atof(strtemp);
      fvertbuf[k++] = scalar * SCALE;
      vertbuf[j++] = (long)(scalar * 65536 * SCALE);
    } else {
      error++;
      cprintf(errorv, i, 'Z');
    }


/* Xchg order of coordinates */
    ltemp        = -vertbuf[j-2];
    vertbuf[j-2] = -vertbuf[j-1];
    vertbuf[j-1] = ltemp;

    ftemp         = -fvertbuf[k-2];
    fvertbuf[k-2] = -fvertbuf[k-1];
    fvertbuf[k-1] = ftemp;

/* Take space for the normal's calculation */
    j += 3;

/* Read texture-map coordinates, if exists... */
    if((shape.atrib & 1) != 0) {
      getns(filebuf, strtemp);
      if((strtemp[0] == 'U')) { 
        getns(filebuf, strtemp);
        scalar = atof(strtemp);
        vertbuf[j++] = (long)(scalar * 65536 * U_TEXT);
      } else {
        error++;
        cprintf(errorv, i, 'U');
      }
    
      getns(filebuf, strtemp);
      if((strtemp[0] == 'V')) { 
        getns(filebuf, strtemp);
        scalar = atof(strtemp);
        vertbuf[j++] = (long)(scalar * 65536 * V_TEXT);
      } else {
        error++;
        cprintf(errorv, i, 'V');
      }

    }

/*
  In total, every [mapped] vertex is :

  3 ³ Dwords for the point
  3 ³ Dwords for the VERTEX normal
 [2 ³ Dwords for the mapping coordinates]
 ÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
  8 ³ DWORDS (32 bytes) [No map = 24]
*/

  }

// Here we start with the polys...
  cprintf("\n\r  Extracting Faces.");
  pos = finddata(filebuf, data_table[6]);

  if(pos == -1) {
    cprintf(errord, data_table[6]);
    exit(-1);
  }


  for(i = 0, np=0; i < shape.numfaces; i++) {

    if(error > MAX_ERRORS) {
      cprintf(abort);
      exit(-1);
    }

    j = i * 4;
    if((i % 32) == 0) cprintf(".");
    do {
      getns(filebuf, strtemp);
    } while((strcmp(strtemp, data_table[11])) != NULL);

    getns(filebuf, strtemp);

    getns(filebuf, strtemp);
    if(strtemp[0] == 'A') {
      getns(filebuf, strtemp);
      facebuf[j++] = atoi(strtemp);
    } else {
      error++;
      cprintf(errorf, i, 'A', strtemp);
    }

    getns(filebuf, strtemp);
    if(strtemp[0] == 'B') {
      getns(filebuf, strtemp);
      facebuf[j++] = atoi(strtemp);
    } else {
      error++;
      cprintf(errorf, i, 'B', strtemp);
    }

    getns(filebuf, strtemp);
    if(strtemp[0] == 'C') {
      getns(filebuf, strtemp);
      facebuf[j++] = atoi(strtemp);
    } else {
      error++;
      cprintf(errorf, i, 'C', strtemp);
    }

    itemp = facebuf[j-1];
    facebuf[j-1] = facebuf[j-3];
    facebuf[j-3] = itemp;


    GetNormal(facebuf[j-3], facebuf[j-2], facebuf[j-1], fvertbuf, &nbuf[np]);
    np += 3;
/*
    do {
     getns(filebuf, strtemp);
    } while((strcmp(strtemp, data_table[17])) != NULL);

    getns(filebuf, strtemp);
    for(col=0;strtemp[col]!= NULL;col++);
    strtemp[col-1] = NULL;


    for(col=0;col<=8;col++) {
       if((strcmp(&strtemp[1], mat_table[col])) == NULL) break;
    }

    facebuf[j++] = col;
    cprintf("\n\r Material: %s; %d", mat_table[col], col);
*/

    facebuf[j++] = 1;

  }	    

// Average the normal dots that converge
  cprintf("\n\r  Averaging Normals.");
  for(i = 0; i < shape.numverts; i++) {
    if((i % 32) == 0) cprintf(".");
    Average_Dot(facebuf, i, vertbuf, nbuf, list);
  }


// Save the results:
  cprintf("\n\r  Written to disk...");
  fwrite((void *)&shape, 1, sizeof(SHPfile), D_out);

  fwrite(vertbuf, 1, shape.numverts*(SizeVertex*4), D_out);
  fwrite(facebuf, 1, shape.numfaces*4*2, D_out);
  cprintf("\n\rConversion finished.\n");
}
Example #4
0
 int  ScanFilesEx ( CTEXTSTR base
           , CTEXTSTR mask
           , void **pInfo
           , void CPROC Process( uintptr_t psvUser, CTEXTSTR name, int flags )
           , int flags 
           , uintptr_t psvUser 
		   , LOGICAL begin_sub_path 
		   , struct file_system_mounted_interface *mount
		   )
{
	PMFD pDataCurrent = (PMFD)(pInfo);
	PMFD pData = (PMFD)(*pInfo);
	TEXTSTR tmp_base = NULL;
	int sendflags;
	int processed = 0;
#ifndef WIN32
	struct dirent *de;
#endif
	if( begin_sub_path )
	{
		pInfo = (void**)&(pDataCurrent->current);
	}
	else
		pDataCurrent = NULL;

	//lprintf( "Search in %s for %s   %d %d", base?base:"(NULL)", mask?mask:"(*)", (*pInfo)?((PMFD)*pInfo)->scanning_mount:0, (*pInfo)?((PMFD)*pInfo)->single_mount:0 );
	if( !*pInfo || begin_sub_path || ((PMFD)*pInfo)->new_mount )
	{
		TEXTCHAR findmask[256];
		pData = (PMFD)(*pInfo);
		if( !pData )
		{
			*pInfo = Allocate( sizeof( MFD ) );
			pData = (PMFD)(*pInfo);
			if( !( pData->scanning_mount = mount ) )
			{
				if( !winfile_local )
					SimpleRegisterAndCreateGlobal( winfile_local );

				//lprintf( "... %p", winfile_local );
				pData->single_mount = FALSE;
				pData->scanning_mount = (*winfile_local).mounted_file_systems;
			}
			else
				pData->single_mount = TRUE;

			if( !pData->scanning_mount )
			{
				Deallocate( PMFD, pData );
				if( tmp_base )
					Release( tmp_base );
				return 0;
			}
			if( pData->scanning_mount->fsi )
			{
				//lprintf( "create cursor" );
				tmp_base = ExpandPathEx( base, pData->scanning_mount->fsi );
				pData->cursor = pData->scanning_mount->fsi->find_create_cursor( pData->scanning_mount->psvInstance, CStrDup( tmp_base ), CStrDup( mask ) );
			}
			else
			{
				//lprintf( "no cursor" );
				pData->cursor = NULL;
			}
		}
		else
		{
			if( pData->new_mount )
			{
				if( pData->scanning_mount->fsi )
				{
					//lprintf( "create cursor (new mount)" );
					tmp_base = ExpandPathEx( base, pData->scanning_mount->fsi );
					pData->cursor = pData->scanning_mount->fsi->find_create_cursor( pData->scanning_mount->psvInstance, CStrDup( tmp_base ), CStrDup( mask ) );
				}
				else
					pData->cursor = NULL;
			}
		}
		pData->new_mount = FALSE;
		pData->current = NULL;
		pData->prior = pDataCurrent;

		if( pDataCurrent )
		{
			pData->root_info = pDataCurrent->root_info;
			pInfo = (void**)pData->root_info;
		}
		else
		{
			pData->root_info = (struct myfinddata**)pInfo;
		}

		(*pData->root_info) = pData;
		if( base )
		{
			TEXTSTR tmp;
			StrCpyEx( findbasename(pInfo), tmp = ExpandPathEx( base, pData->scanning_mount?pData->scanning_mount->fsi:NULL ), MAX_PATH_NAME );
			Release( tmp );
			StrCpyEx( findmask(pInfo), mask, MAX_PATH_NAME );
		}
		else
		{
			CTEXTSTR p = pathrchr( mask );
			if( p )
			{
				StrCpyEx( findbasename(pInfo), mask, p - mask + 1 );
				StrCpyEx( findmask(pInfo), p + 1, MAX_PATH_NAME );
				//mask = p + 1;
			}
			else
			{
				StrCpyEx( findbasename(pInfo), WIDE(""), 2 );
				StrCpyEx( findmask(pInfo), mask, MAX_PATH_NAME );
			}
		}
		if( findbasename(pInfo)[0] )
			tnprintf( findmask, sizeof(findmask), WIDE("%s/*"), findbasename(pInfo) );
		else
			tnprintf( findmask, sizeof( findmask ), WIDE( "*" ) );
		if( pData->scanning_mount?pData->scanning_mount->fsi:NULL )
			if( pData->scanning_mount->fsi->find_first( findcursor(pInfo) ) )
				findhandle(pInfo) = 0;
			else
				findhandle(pInfo) = (HANDLECAST)-1;
		else
		{
#if WIN32
			findhandle(pInfo) = findfirst( findmask, finddata(pInfo) );
#else
			//lprintf( "opendir %s", findbasename(pInfo) );
			findhandle( pInfo ) = opendir( findbasename(pInfo) );
			if( !findhandle(pInfo ) )
				findhandle(pInfo) = (HANDLECAST)-1;
			else
				de = readdir( (DIR*)findhandle( pInfo ) );
#endif
		}
		if( findhandle(pInfo) == (HANDLECAST)-1 )
		{
			PMFD prior = pData->prior;
			//lprintf( "first use of cursor or first open of directoy failed..." );
			if( pData->scanning_mount && pData->scanning_mount->fsi )
				pData->scanning_mount->fsi->find_close( (struct find_cursor*)findcursor(pInfo) );
			else
			{
#ifdef WIN32
				findclose( findhandle(pInfo) );
#else
				// but it failed... so ... don't close
				//closedir( findhandle( pInfo ) );
#endif
			}
			pData->scanning_mount = NextThing( pData->scanning_mount );
			if( !pData->scanning_mount || pData->single_mount )
			{
				(*pData->root_info) = pData->prior;
				if( !begin_sub_path ) {
					Release( pData ); pInfo[0] = NULL;
				}
				//lprintf( WIDE( "%p %d" ), prior, processed );
				if( tmp_base )
					Release( tmp_base );
				return prior?processed:0;
			}
			pData->new_mount = TRUE;
				if( tmp_base )
					Release( tmp_base );
			return 1;
		}
	}
	else
	{
		int r;
getnext:
		//lprintf( "returning customer..." );
		if( pData->scanning_mount?pData->scanning_mount->fsi:NULL )
			r = !pData->scanning_mount->fsi->find_next( findcursor( pInfo ) );
		else
		{
#ifdef _WIN32
			r = findnext( findhandle(pInfo), finddata( pInfo ) );
#else
			de = readdir( (DIR*)findhandle( pInfo ) );
			//lprintf( "using %p got %p", findhandle( pInfo ), de );
			r = (de == NULL);
#endif
		}
		if( r )
		{
			PMFD prior = pData->prior;
			//lprintf( "nothing left to find..." );
			if( pData->scanning_mount->fsi )
				pData->scanning_mount->fsi->find_close( findcursor(pInfo) );
			else
			{
#ifdef WIN32
				findclose( findhandle(pInfo) );
#else
				closedir( (DIR*)findhandle(pInfo));
#endif
			}
			pData->scanning_mount = NextThing( pData->scanning_mount );
			//lprintf( "Step mount... %p %d", pData->scanning_mount, pData->single_mount );
			if( !pData->scanning_mount || pData->single_mount )
			{
				//lprintf( "done with mounts?" );
				(*pData->root_info) = pData->prior;
				Release( pData );
				if( prior )
					prior->current = NULL;
				if( !processed && !begin_sub_path )
				{
					//pInfo = (void**)&(prior->prior->current);
					pData = prior;
					if( pData )
						goto getnext;
				}
				if( tmp_base )
					Release( tmp_base );
				return (*pInfo)?processed:0;
			}
			pData->new_mount = TRUE;
			if( tmp_base )
				Release( tmp_base );
			return 1;
		}
	}
	if( pData->scanning_mount?pData->scanning_mount->fsi:NULL )
	{
		char * path = pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) );
		//lprintf( "... %s", path );
		if( !strcmp( ".", path ) ||
		    !strcmp( "..", path ) )
		goto getnext;
	}
	else
	{
#if WIN32 
		//lprintf( "... %s", finddata(pInfo)->name );
#  ifdef UNDER_CE
		if( !StrCmp( WIDE("."), finddata(pInfo)->cFileName ) ||
		    !StrCmp( WIDE(".."), finddata(pInfo)->cFileName ) )
#  else
		if( !StrCmp( WIDE("."), finddata(pInfo)->name ) ||
		    !StrCmp( WIDE(".."), finddata(pInfo)->name ) )
#  endif
#else
		if( !StrCmp( WIDE("."), de->d_name ) ||
		    !StrCmp( WIDE(".."), de->d_name ) )
#endif
			goto getnext;
	}
	if( !(flags & SFF_NAMEONLY) ) // if nameonly - have to rebuild the correct name.
	{
		if( pData->scanning_mount?pData->scanning_mount->fsi:NULL )
		{
			tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE("%s"), pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) ) );
			if( findbasename( pInfo )[0] )
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s/%s"), findbasename(pInfo), pData->file_buffer );
			else
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE( "%s" ), pData->file_buffer );
		}
		else
		{
#ifdef WIN32
#  ifdef UNDER_CE
			tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE( "%s" ), finddata( pInfo )->cFileName );
			tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s/%s"), findbasename(pInfo), finddata(pInfo)->cFileName );
#  else
			tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->name );
			tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s"), findbasename(pInfo), findbasename( pInfo )[0]?"/":"", pData->file_buffer );
#  endif
#else
			tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE("%s"), de->d_name );
			tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s/%s"), findbasename(pInfo), de->d_name );
#endif
		}
	}
	else
	{
		if( flags & SFF_SUBCURSE )
		{
			if( pData->scanning_mount?pData->scanning_mount->fsi:NULL )
			{
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s")
					  , pData->prior?pData->prior->buffer:WIDE( "" )
					  , pData->prior?WIDE( "/" ):WIDE( "" )
					, pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) ) 
					);
			}
			else
			{
#if WIN32
#  ifdef UNDER_CE
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s")
						  , pData->prior?pData->prior->buffer:WIDE( "" )
						  , pData->prior?WIDE( "/" ):WIDE( "" )
						  , finddata(pInfo)->cFileName );
#  else
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s")
						  , pData->prior?pData->prior->buffer:WIDE( "" )
						  , pData->prior?WIDE( "/" ):WIDE( "" )
						  , finddata(pInfo)->name );
#  endif
#else
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s")
					  , pData->prior?pData->prior->buffer:WIDE( "" )
					  , pData->prior?WIDE( "/" ):WIDE( "" )
					  , de->d_name );
					  lprintf( "resulting is %s", pData->buffer );
#endif
			}
		}
		else
		{
			if( pData->scanning_mount?pData->scanning_mount->fsi:NULL )
			{
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) ) );
			}
			else
			{
#if WIN32
#  ifdef UNDER_CE
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->cFileName );
#  else
#    ifdef UNICODE
				snwprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->name );
#    else
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->name );
#    endif
#  endif
#else
				tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), de->d_name );
#endif
			}
		}
	}
	pData->buffer[MAX_PATH_NAME-1] = 0; // force nul termination...
#ifdef UNICODE
	{
		char *pDataBuffer = CStrDup( pData->buffer );
#else
#  define pDataBuffer pData->buffer
#endif
	//lprintf( "Check if %s is a directory...", pData->buffer );
	if( (flags & (SFF_DIRECTORIES | SFF_SUBCURSE))
		&& (pData->scanning_mount && pData->scanning_mount->fsi
			&& (pData->scanning_mount->fsi->is_directory
				&& pData->scanning_mount->fsi->is_directory( pDataBuffer )))
		|| (!(pData->scanning_mount ? pData->scanning_mount->fsi : NULL)
#ifdef WIN32
#  ifdef UNDER_CE
			&& (finddata( pInfo )->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
#  else
			&& (finddata( pInfo )->attrib & _A_SUBDIR)
#  endif
#else
			&& IsPath( pData->buffer )
#endif
			) )
	{
#ifdef UNICODE
		Deallocate( char *, pDataBuffer );
#else 
#  undef pDataBuffer
#endif
		//lprintf( "... it is?" );
		if( flags & SFF_DIRECTORIES )
		{
			if( Process != NULL )
			{
				//lprintf( "Send %s", pData->buffer );
				Process( psvUser, pData->buffer, SFF_DIRECTORY );
				processed = 1;
			}
			//return 1;
		}
		if( flags & SFF_SUBCURSE )
		{
			void *data = NULL;
			int ofs = 0;
			TEXTCHAR tmpbuf[MAX_PATH_NAME];
			if( flags & SFF_NAMEONLY )
			{
				// even in name only - need to have this full buffer for subcurse.
				if( pData->scanning_mount && pData->scanning_mount->fsi )
				{
					ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), pData->scanning_mount->fsi->find_get_name( findcursor( pInfo ) ) );
				}
				else
				{
#ifdef WIN32
#  ifdef UNDER_CE
					ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), finddata( pInfo )->cFileName );
#  else
#    ifdef UNICODE
					ofs = snwprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), finddata( pInfo )->name );
#    else
					ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), finddata( pInfo )->name );
#    endif
#  endif
#else	
					ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), de->d_name );
#endif
				}
				//lprintf( "process sub... %s %s", tmpbuf, findmask(pInfo)  );
				processed |= ScanFilesEx( tmpbuf, findmask( pInfo ), (POINTER*)pData, Process, flags, psvUser, TRUE, pData->scanning_mount );
			}
			else
			{
				//lprintf( "process sub..." );
				processed |= ScanFilesEx( pData->buffer, findmask( pInfo ), (POINTER*)pData, Process, flags, psvUser, TRUE, pData->scanning_mount );
			}
		}
		if( !processed )
			goto getnext;
		if( tmp_base )
			Release( tmp_base );
		return (*pInfo) ? 1 : 0;
	}
#ifdef UNICODE
	Deallocate( char *, pDataBuffer );
	}
#else 
#  undef pDataBuffer
#endif
	if( ( sendflags = SFF_DIRECTORY, ( ( flags & SFF_DIRECTORIES )
#ifdef WIN32
#  ifdef UNDER_CE
												 && ( finddata(pInfo)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
#  else
												 && ( finddata(pInfo)->attrib & _A_SUBDIR )
#  endif
#else
												 && ( IsPath( pData->buffer ) )

#endif
												) ) || ( sendflags = 0, CompareMask( findmask( pInfo )
#ifdef WIN32
#  ifdef UNDER_CE
																							  , finddata(pInfo)->cFileName
#  else
																							  , pData->file_buffer
#  endif
#else
																							  , de->d_name
#endif
																								// yes this is silly - but it's correct...
																							  , (flags & SFF_IGNORECASE)?0:0 ) ) )
	{
		//lprintf( "Send %s", pData->buffer );
		if( Process != NULL )
			Process( psvUser, pData->buffer, sendflags );
		if( tmp_base )
			Release( tmp_base );
		return (*pInfo)?1:0;
	}
	if( tmp_base )
		Release( tmp_base );
	return (*pInfo)?1:0;
}
Example #5
0
int ScanFiles( char *base
             , char *mask
             , void **pInfo
             , void Process( char *name, int flags )
             , int flags
             )
{
    int sendflags;
    struct stat st;
    if( !*pInfo )
    {
        char findmask[256];
        sprintf( findmask, "%s/*", base );
        *pInfo = malloc( sizeof( MFD ) );
        findhandle(pInfo) = opendir( base );
        if( findhandle(pInfo) == NULL )
        {
            free( *pInfo );
            *pInfo = NULL;
            return 0;
        }
    }
    else
    {
    getnext:
        if( ( finddata( pInfo ) = readdir( findhandle(pInfo) ) ) == NULL )
        {
            closedir( findhandle(pInfo) );
            free( *pInfo );
            *pInfo = NULL;
            return 0;
        }
    }
    if( !strcmp( ".", finddata(pInfo)->d_name ) ||
         !strcmp( "..", finddata(pInfo)->d_name ) )
        goto getnext;
    if( flags & SFF_NAMEONLY )
        strncpy( findbuffer( pInfo ), finddata(pInfo)->d_name, MAX_PATH_NAME );
    else
        snprintf( findbuffer( pInfo ), MAX_PATH_NAME, "%s/%s", base, finddata(pInfo)->d_name );
    findbuffer( pInfo )[MAX_PATH_NAME-1] = 0; // force nul termination...
    stat( findbuffer( pInfo ), &st );
    if( ( flags & (SFF_DIRECTORIES|SFF_SUBCURSE) )
         && S_ISDIR(st.st_mode) )
    {
        if( flags & SFF_SUBCURSE  )
        {
            void *data = NULL;
            if( flags & SFF_DIRECTORIES )
                if( Process )
                    Process( findbuffer( pInfo ), SFF_DIRECTORY );
            if( flags & SFF_NAMEONLY ) // if nameonly - have to rebuild the correct name.
                snprintf( findbuffer( pInfo ), MAX_PATH_NAME, "%s/%s", base, finddata(pInfo)->d_name );
            while( ScanFiles( findbuffer(pInfo), mask, &data, Process, flags ) );
        }
        goto getnext;
    }

    if( ( sendflags = SFF_DIRECTORY, ( ( flags & SFF_DIRECTORIES )
            && ( S_ISDIR( st.st_mode ) ) ) )
         || ( sendflags = 0, CompareMask( mask, finddata(pInfo)->d_name, 0 ) ) )
    {
        if( Process )
            Process( findbuffer( pInfo ), sendflags );
        return 1;
    }
    return 1;
}