コード例 #1
0
ファイル: P230.CPP プロジェクト: agudeloandres/C_Struct_Files
void main() {	/*  0 = defecto: 1 = a:  2 = b: 3 = c: */
	char *q,a[100];
	int i;

	i = getdisk();
	if (getcurdir (0,a) == -1) {   		/* Por defecto */
		q = _strerror ("Error en getcur dir()");
		PRS(q);
		getch(); exit(1);
	}
	printf ("Directorio actual en %c: = %s\n",i + 'a',a);


	/* Determina el directorio actual en a: */


	if (getcurdir (1,a) == -1) {   		/* Unidad a: */
		q = _strerror ("Error en getcur dir()");
		PRS(q);
		getch(); exit(1);
	}
	printf ("Directorio actual en a: = %s\n",a);
	getch();

}
コード例 #2
0
ファイル: CME.C プロジェクト: krattai/flosh
void main(void)
{
	char *oldpath,*curpath;

	clrscr();
	strcpy(oldpath,"\\");
	getcurdir(0,oldpath+1);
	printf("C:%s>",oldpath);
	while(getch() != ESC)
	{
		getcurdir(0,oldpath+1);
		printf("\nC:%s>",oldpath);
	}
}
コード例 #3
0
ファイル: braille_Win32.c プロジェクト: AdamJHowell/Braille
char *current_directory(char *path)
{
	strcpy(path, "X:\\");		// fill string with form of response: X:\
	path[0] = 'A' + getdisk();	// replace X with current drive letter
	getcurdir(0, path+3);		// fill rest of string with current directory
	return(path);
}
コード例 #4
0
//&<<&void PutCurDir(FILE *f){   // prints current drive & directory into FILE *f
void PutCurDir(FILE *f){
  char *cd=getcurdir();                        // current disk
  int lcd=strlen(cd);
  if(lcd>3 && cd[lcd-1]=='/') cd[--lcd]=0;
  fprintf(f,"cd %s\n",cd);
  delete cd;
}
コード例 #5
0
/// get current directory of active process (string is malloc-ed)
char* _std getcurdir_dyn(void) {
   spstr cd;
   if (!getcurdir(cd)) return 0;
   char *rc = strdup(cd());
   __set_shared_block_info(rc, "getcurdir()", 0);
   return rc;
}
コード例 #6
0
ファイル: 4-11.c プロジェクト: Huericiz/C_lg_small_examples
main()
{
   char curdir[MAXPATH];
   strcpy(curdir,"a:\\");
   curdir[0]='A'+getdisk();
   getcurdir(0,curdir+3);
   printf("\nThe current directory is:%s",curdir);
   getch();
}
コード例 #7
0
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   sectors = new sector[20];
    mainfile = new AnsiString;
    *mainfile = "C:\\";
    char temp2[1024];

// Setup Current directory
    getcurdir(3, temp2);
    AnsiString tempstring = temp2;
    directoryname = "C:\\" + tempstring + "\\";

//set up name of hpt file
    *mainfile += temp2;
    *mainfile += "\\niseclist.hpt";


    currentsector = 0;
    currentobject = 0;
    sectorupdn->Position = (short)currentsector;

   //load info from file using memory mapped files
 filehandle = CreateFile((*mainfile).c_str(),GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
 filemaphandle = CreateFileMapping(filehandle,NULL,PAGE_READONLY,0,0,NULL);
 filepointer = MapViewOfFile(filemaphandle,FILE_MAP_READ,0,0,0);
 void* tempfilepntr = filepointer;
 if(filepointer != NULL)
 {
    for(int count = 0;count < 20;count++)
    {
        numobjpersec[count] = *((int*)tempfilepntr);
        sectors[count].readinfo(tempfilepntr);
    }
  }
 else
 {
   //no memory mapped file exist so set to default setup
   for(int count = 0;count < 20;count++)
    {
        numobjpersec[count] = 1;
    }
    for(int count = 0;count < 20;count++)
    {
      sectors[count].addobject();
     }
 }
 UnmapViewOfFile(filepointer);
 CloseHandle(filemaphandle);
 CloseHandle(filehandle);
 

   objectnumberupdn->Max = (short)(numobjpersec[currentsector] - 1);
   resetobjparams();
}
コード例 #8
0
ファイル: xfer.c プロジェクト: crtc-demos/mode-infinity
/* Get file names from BBC which match pattern, and create linked list of
   file information. *INFO is used to get the filenames, because OSGBPB 8
   only returns files in current directory, and there is no easy way of 
   finding all of the DFS/DNFS single-character directories. If the
   directories argument is true, then all single character directories will
   be listed using "*INFO *.*", otherwise "*INFO *" will be used. Pattern
   can contain * and ? to match strings or characters. */
static bbc_status_t getfilenames(serial_h com, char *pattern, filelist **names,
                                 bool directories)
{
  char buffer[MAXLINELEN] ;
  bbc_status_t result ;
  int nnames = 0 ;

  /* If we allow directories, check that its not a multi-format DFS which
     is in a subdirectory */
  if ( directories ) {
    if ( (result = getcurdir(com, buffer, MAXLINELEN)) != BBC_OK )
      return result ;
    if ( strlen(buffer) != 1 )
      directories = false ;
  }

  *names = NULL ;

  serial_printf(com, directories ? "*INFO *.*\r" : "*INFO *\r") ;
  while ( (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_OK ) {
    char *start, *end ;

    for ( start = buffer ; *start && isspace(*start) ; ++start) ;
    for ( end = start ; *end && !isspace(*end) ; ++end) ;

    if ( start == end ) {
      printf("Empty name returned by *INFO, skipping %s\n", buffer) ;
      continue ;
    }

    *end = '\0' ;

    if ( !match(pattern, start) ) /* Doesn't match pattern */
      continue ;

    if ( (*names = (filelist *)malloc(sizeof(filelist))) == NULL )
      error("Out of memory storing file info for %s", start) ;

    strcpy((*names)->name, start) ;
    (*names)->next = NULL ;
    names = &(*names)->next ;
    ++nnames ;
  }

  return result ;
}
コード例 #9
0
ファイル: getcwd.c プロジェクト: NoSuchProcess/OrangeC
char  *_RTL_FUNC      getcwd( char  *__buf, int __buflen )
{
    int drv,rv;
    char ibuf[265];
    drv = getdisk() ;
    rv = getcurdir(0,ibuf+3);
    ibuf[0] = drv + 'A';
    ibuf[1] = ':';
    ibuf[2] = '\\';
    if (!__buf)
        __buf = strdup(ibuf) ;
    else {
        memcpy(__buf,ibuf,__buflen);
        __buf[__buflen-1] = 0;
    }
   return __buf;
}
コード例 #10
0
ファイル: disk_io.cpp プロジェクト: FarGroup/FarManager
CONSTSTR MYRTLEXP GetCurDir( void )
  {  static char path[ MAX_PATH_SIZE+1 ];

#if defined(__GNUC__) || defined(__QNX__)
    getcwd( path,MAX_PATH_SIZE );
#else
#if defined(__HDOS__) || defined(__HWIN16__)
   strcpy(path, "X:\\");      /* fill string with form of response: X:\ */
   path[0] = 'A' + getdisk();    /* replace X with current drive letter */
   getcurdir(0, path+3);  /* fill rest of string with current directory */
#else
#if defined(__HWIN__)
   GetCurrentDirectory( sizeof(path),path );
#else
#error ERR_PLATFORM
#endif
#endif
#endif
 return AddLastSlash( path );
}
コード例 #11
0
ファイル: TDIRCOLL.cpp プロジェクト: gdobra/tvision
void getCurDir( char *dir )
{
    getcurdir(dir);
    if( strlen( dir ) > 3 )
        strcat( dir, "\\" );
}
コード例 #12
0
ファイル: main.c プロジェクト: Wuzzy2/instead
void wince_init(char *path)
{
	unix_path(path);
	strcpy(game_cwd, getcurdir(path));
}
コード例 #13
0
ファイル: xfer.c プロジェクト: crtc-demos/mode-infinity
static bbc_status_t retrieve_file(serial_h com, filelist *file)
{
  bbc_status_t result ;

  file->type = 0 ;

  if ( (result = getfileinfo(com, file)) == BBC_OK ) {
    char pcname[MAXLINELEN] ;
    FILE *pcfile ;
    bool fileerr = false ;

    if ( file->type == 0 ) { /* OSFILE returned 0 */
      printf("File %s does not exist on BBC, skipping\n", file->name) ;
      return BBC_OK ;
    }

    strcpy(pcname, file->name) ;

    /* Check if PC name is used */
    if ( !check_pcname(file->type == 2 ? "Directory" : "File",
                       pcname, MAXLINELEN) )
      return BBC_OK ;

    if ( file->type == 1 ) { /* OSFILE indicates it's a file */
      char buffer[BBCTRACKSIZE] ;
      int fhandle, size ;

      if ( (pcfile = fopen(pcname, "wb")) == NULL ) {
        printf("Can't open PC file %s to retrieve %s, skipping\n",
               pcname, file->name) ;
        return BBC_OK ;
      }

      printf("Retrieving file %s %x %x %x %c%c%c%c to %s\n",
             file->name, file->load, file->exec, file->length,
             (file->attrs & FILE_Not_R) ? ' ' : 'R',
             (file->attrs & FILE_Not_W) ? ' ' : 'W',
             (file->attrs & FILE_Not_X) ? ' ' : 'X',
             (file->attrs & FILE_Not_D) ? 'L' : ' ',
             pcname) ;

      serial_printf(com, "S%s\r", file->name) ;

      if ( (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_SYNC &&
           (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_OK &&
           sscanf(buffer, "%d", &fhandle) == 1 &&
           fhandle != 0 &&
           (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_OK &&
           sscanf(buffer, "%d", &size) == 1 ) {
        int remaining = size, nbytes = 0 ;
        unsigned int crc = 0;

        while ( remaining > 0 ) {
          int rbytes = remaining > BBCTRACKSIZE ? BBCTRACKSIZE : remaining ;

          if ( (result = bbc_read(com, buffer, &rbytes)) == BBC_OK ) {
            if ( !fileerr &&
                 (int)fwrite(buffer, sizeof(char), rbytes, pcfile) != rbytes )
              fileerr = true ;
            remaining -= rbytes ;
            nbytes += rbytes ;
            crccalc(buffer, rbytes, &crc) ;
            printf("\rRead %d bytes of %d", nbytes, size) ;
            fflush(stdout) ;
          } else /* Error reading bytes */
            break ;
        }

        putchar('\n') ;

        if ( result == BBC_OK ) {
          unsigned int bbccrc = 0 ;

          if ( (result = bbc_readline(com, buffer, MAXLINELEN)) != BBC_OK ||
               sscanf(buffer, "%u", &bbccrc) != 1 ) {
            printf("Problem retrieving CRC for %s from BBC\n", file->name) ;
            fileerr = true ;
          } else if ( bbccrc != crc ) {
            printf("CRC error for %s (%x not equal to %x)\n",
                   file->name, crc, bbccrc) ;
            fileerr = true ;
          }
        }
      } else {
        printf("Problem opening %s on BBC, skipping\n", file->name) ;
        fileerr = true ;
      }

      fclose(pcfile) ;
    } else if ( file->type == 2 ) { /* OSFILE indicates it's a directory */
      char pcdir[MAXLINELEN], bbcdir[MAXLINELEN] ;
      filelist *subfiles = NULL ;

      printf("Retrieving directory %s %x %x %x %c%c%c%c to %s\n",
             file->name, file->load, file->exec, file->length,
             (file->attrs & FILE_Not_R) ? ' ' : 'R',
             (file->attrs & FILE_Not_W) ? ' ' : 'W',
             (file->attrs & FILE_Not_X) ? ' ' : 'X',
             (file->attrs & FILE_Not_D) ? 'L' : ' ',
             pcname) ;
      (void)mkdir(pcname, 0755) ;
      if ( getcwd(pcdir, MAXLINELEN) &&
           (result = getcurdir(com, bbcdir, MAXLINELEN)) == BBC_OK ) {
        if ( chdir(pcname) == 0 ) {
          if ( (result = setcurdir(com, file->name)) == BBC_SYNC ) {
            if ( (result = getfilenames(com, "*", &subfiles, false)) == BBC_SYNC ) {
              result = BBC_OK ;

              while ( subfiles && !interrupted(false) ) {
                filelist *next = subfiles->next ;

                if ( (result = retrieve_file(com, subfiles)) != BBC_OK ) {
                  printf("Error retrieving file %s, skipping\n",
                         subfiles->name) ;
                  free(subfiles) ;
                  subfiles = next ;
                  fileerr = true ;
                  break ;
                }

                free(subfiles) ;
                subfiles = next ;
              }

              while ( subfiles ) {
                filelist *next = subfiles->next ;
                printf("Skipping file %s because of previous error\n",
                       subfiles->name) ;
                free(subfiles) ;
                subfiles = next ;
              }

              if ( interrupted(true) )
                fileerr = true ;
            }

            if ( result == BBC_OK &&
                 (result = setcurdir(com, bbcdir)) == BBC_SYNC )
              result = BBC_OK ;
          }
          (void)chdir(pcdir) ;
        }
      }
    } else {
      printf("File %s has unknown OSFILE type %d, skipping\n",
             file->name, file->type) ;
      return BBC_OK ;
    }

    if ( result == BBC_OK && !fileerr ) { /* Write .inf file */
      char *basename ;

      strcat(pcname, ".inf") ;

      /* Get basename to compare against; if !boot, get boot option */
      if ( (basename = strrchr(file->name, '.')) != NULL )
        ++basename ;
      else
        basename = file->name ;

      if ( (pcfile = fopen(pcname, "w")) != NULL ) {
        fprintf(pcfile, "%s %06x %06x %06x%s",
                file->name, file->load, file->exec, file->length,
                (file->attrs & FILE_Not_D) ? " Locked" : "") ;
        /* Use qmatch to use case-insensitive comparison */
        if ( qmatch("!boot", basename, -1) ) {
          char buffer[MAXLINELEN] ;

          if ( (result = getbootopt(com, buffer, MAXLINELEN)) == BBC_OK )
            fprintf(pcfile, " OPT4=%s", buffer) ;
        }
        fprintf(pcfile, " ATTR=%x TYPE=%d\n", file->attrs, file->type) ;
        fclose(pcfile) ;
      } else { /* Can't open .inf name, delete downloaded file */
        printf("Problem creating info file %s.inf, skipping\n", file->name) ;
        pcname[strlen(pcname) - 4] = '\0' ;
        remove(pcname) ;
      }
    } else { /* If download failed, remove file */
      remove(pcname) ;
    }
  }

  return result ;
}
コード例 #14
0
ファイル: OPENFILC.C プロジェクト: Inzaghi2012/EZP
static unsigned long FileNameList(HWND Window,HMSG Message,long Param1,long Param2)
{
  int hlist;

  switch (Message)
  {
    case DIRCHANGE:
         MessageGo(Window,WINDOWINIT,0,0);
         hlist = WindowList(Window);
         MessageGo(Window,WMPAINT,0,ListGetHeight(hlist)*CHARHEIGHT);
         break;

    case ITEMSELECT:
         MessageGo(WindowGetFather(Window),FILECHANGE,Param1,Param2);
         break;

    case LISTBOXCONFIRM:
         hlist=WindowGetUserData(Window);
         strcpy(NowOpenFile->filename,ListGetItem(hlist,ListGetCurrent(hlist)));
         MessageGo(WindowGetFather(Window),DIALOGBOXOK,0l,0l);
         break;

    case WINDOWINIT:
         {
           char  *filename=NowOpenFile->filename;
           char  *dirs=NowOpenFile->dirs;
           char  *drive=NowOpenFile->drive;
           char  fn[128];
           int   r;

           #ifdef _TURBOC_
              struct ffblk opffblk;
           #else
              struct find_t opffblk;
           #endif

           MessageGo(Window,LISTSETITEMHEIGHT,16,0);
           MessageGo(Window,LISTSETITEMLENGTH,13,0);

           /*------ ByHance, 96,3.25 ----
           hlist = WindowList(Window);
           ListSetTotal(hlist,0);
           ListSetCurrent(hlist,0);
           ListSetTop(hlist,0);
           --------------------*/
           MessageGo(Window,LISTDELETEALL,0L,0L);

     //      _harderr(handler);

           if( !dirs[0] ) {
              #ifdef __TURBOC__
                 getcurdir((int)(*drive-'A'+1), dirs);
              #else
                 unsigned total,old;
                 _dos_getdrive(&old);
                 if(old!=*drive-'A'+1)
                    _dos_setdrive( *drive-'A'+1, &total );
                 getcwd(dirs, 64);
                 memmove(dirs,dirs+3,61);       // cancel "C:\"
                 if(!dirs[0])
                     strcpy(dirs,"\\");
                 if(old!=*drive-'A'+1)
                    _dos_setdrive( old, &total );
              #endif
           }

           memset(&opffblk, 0, sizeof(opffblk));

           strcpy(fn,drive);
           //strcat(fn,"\\");
           //if( strcmp(dirs,"\\") && strcmp(dirs,"/") )
           //{
           //    strcat(fn,dirs);
           //    strcat(fn,"\\");
           //}
           if(dirs[0])
           {
                  char ch;
                  int len;

                  ch=dirs[0];
                  if(ch!='\\' && ch!='/')
                       strcat(fn,"\\");

                  strcat(fn,dirs);
                  len=strlen(fn);
                  ch=fn[len-1];
                  if(ch!='\\' && ch!='/')
                       strcat(fn,"\\");
           }

           strcat(fn,filename);

           r = findfirst(fn, &opffblk, _A_NORMAL);

           if (!r)              // found at least 1 file
              strcpy(NowOpenFile->filename, opffblk.ff_name);

           while (!r)
           {
              MessageGo(Window, LISTINSERTITEMSORTED, FP2LONG(opffblk.ff_name), 0L);
              r = findnext(&opffblk);
           }

           //MessageGo(Window,WMPAINT,0,ListGetHeight(hlist)*CHARHEIGHT);
           //   ByHance, 95,12.11
             MessageInsert(Window,REDRAWMESSAGE,0L,
               MAKELONG(WindowGetWidth(Window),WindowGetHeight(Window)) );
         }
         break;
    default:
         return(ListBoxDefaultProcedure(Window,Message,Param1,Param2));
  }
  return(TRUE);
}
コード例 #15
0
ファイル: fixpath.c プロジェクト: idispatch/tvision
/* Takes as input an arbitrary path.  Fixes up the path by:
 1. Removing consecutive slashes
 2. Removing trailing slashes
 3. Making the path absolute if it wasn't already
 4. Removing "." in the path
 5. Removing ".." entries in the path (and the directory above them)
 */
void _fixpath(const char *in, char *out) {
    const char *ip = in;
    char *op = out;

    /* Convert ~ to the HOME environment variable */
    if (*ip == '~' && (is_slash(ip[1]) || !ip[1])) {
        const char *home = getenv("HOME");
        if (home) {
            strcpy(op, home);
            op += strlen(op);
            ip++;
            if (!*ip)
                return;
        }
    }

    /* Convert relative path to absolute */
    if (!is_slash(*ip)) {
        getcurdir(0, op);
        op += strlen(op);
    }

#if defined(TVOSf_QNX4)
    /* Skip the first slashes, which are a node number part */
    /* Full QNX4 pathname is //node/dirpath/filename        */
    if ((ip==in) && (is_slash(*ip)) && (is_slash(*(ip+1))))
    {
        *op=*ip;
        ip++;
        op++;
    }
#endif // TVOSf_QNX4
    /* Step through the input path */
    while (*ip) {
        /* Skip input slashes */
        if (is_slash(*ip)) {
            ip++;
            continue;
        }

        /* Skip "." and output nothing */
        if (*ip == '.' && is_term(*(ip + 1))) {
            ip++;
            continue;
        }

        /* Skip ".." and remove previous output directory */
        if (*ip == '.' && *(ip + 1) == '.' && is_term(*(ip + 2))) {
            ip += 2;
            /* Don't back up over root '/' */
            if (op > out)
                /* This requires "/" to follow drive spec */
                while (!is_slash(*--op))
                    ;
            continue;
        }

        /* Copy path component from in to out */
        *op++ = '/';
        while (!is_term(*ip))
            *op++ = *ip++;
    }

    /* If root directory, insert trailing slash */
    if (op == out)
        *op++ = '/';

    /* Null terminate the output */
    *op = '\0';

}
コード例 #16
0
SaveDir::SaveDir()
{
    drive = getdisk();
    path[0] = '\\';
    getcurdir( 0, path+1 );
}
コード例 #17
0
ファイル: FCTOOLS.C プロジェクト: FDOS/fc
/* ************************************************************************ */
char* FullPath(char* Buffer, char *Path, int BufferSize)
{
  struct REGPACK r;
  char Drive;
  int Work;
  char* WorkPointer = Buffer;

  *Buffer = END_OF_STRING;
  if (BufferSize < MAXPATHLFN) return Buffer;

  if (isalpha(Path[0]) && (Path[1] == ':'))    /* Drive specified */
  {
    Drive = WorkPointer[0] = Path[0];
    Path += 2;
  }
  else					 /* Default drive */
    Drive = WorkPointer[0] = getdisk() + 'A';
  WorkPointer[1] = ':';
  WorkPointer += 2; BufferSize -= 2;

  if (islower(Drive)) Drive = _toupper (Drive); /* Upper case drive */
  Drive = Drive - 'A' + 1;

  *WorkPointer = '\\';
  WorkPointer++; BufferSize -= 1;
  if (*Path == '\\')
    Path++;			/* Absolute path */
  else
  {				/* Relative path */
    r.r_ax = 0x7147;		/* Get current directory (LFN) */
    r.r_dx = Drive;
    r.r_ds = FP_SEG(WorkPointer);  r.r_si = FP_OFF(WorkPointer);
    r.r_flags = CARRY;	/* Set carry to prepare for failure */
    intr(DOS, &r);
    if ((r.r_flags & CARRY) != 0)	/* Carry -> Not ok */
      getcurdir(Drive, WorkPointer);	/* Use the SFN function */

    if (*WorkPointer != END_OF_STRING)
    {
      Work = strlen(WorkPointer);
      WorkPointer += Work;
      *WorkPointer = '\\';
      WorkPointer++;
      BufferSize -= Work + 1;
    }
  }

  strncpy(WorkPointer, Path, BufferSize);  /* Add the rest of the path */

  WorkPointer = Buffer;		/* Expand the "." directories */
  do
  {
    WorkPointer = strchr(WorkPointer, '.');
    if (WorkPointer == NULL) break;

    switch (WorkPointer[1])
    {
      case '\\':                        /* ".\" */
	stpcpy(WorkPointer, WorkPointer + 2);
	break;

      case END_OF_STRING:		/* Terminal '.' */
	if (WorkPointer[-1] == '\\')    /* "\." */
	  *WorkPointer = END_OF_STRING;
	else
	  WorkPointer++;		/* "FOO." */
	break;

      case '.':
	if (WorkPointer[-1] == '\\')    /* "\.." */
	{
	  Path = WorkPointer + 1;
	  do { Path++; } while (*Path == '.');

	  if ((*Path != '\\') && (*Path != END_OF_STRING))
	    WorkPointer = Path;
	  else
	  {
	    Work = (int)(Path - WorkPointer - 1);
	    do
	    {
	      WorkPointer--;
	      do
	      {
		WorkPointer--;
		/* Handle the case (absurd) C:\.. */
		if (*WorkPointer == ':')
		{
		  *Buffer = END_OF_STRING;
		  return Buffer;
		}
	      } while (*WorkPointer != '\\');
	      Work--;
	    } while (Work > 0);
	    stpcpy(WorkPointer, Path);
	  }
	}
	break;

      default:
	WorkPointer++;
    }
  } while (TRUE);

  /* Remove the last '\' if not the root directory */
  Work = strlen(Buffer) - 1;
  if ((Work > 3) && (Buffer[Work] == '\\')) Buffer[Work] = END_OF_STRING;

  return Buffer;
}
コード例 #18
0
ファイル: fixpath.c プロジェクト: idispatch/tvision
// getcurdir is provided by the compatibility layer ;-)
static char* __fp_getcurdir(char* out, int drive)
{
    if (!getcurdir(drive + 1, out))
        out += strlen(out);
    return out;
}
コード例 #19
0
ファイル: path.c プロジェクト: doniexun/OrangeC
char *_RTL_FUNC _fullpath(char *absPath, const char *relPath, size_t len)
{
	char result[MAXPATH], *p;
	int disk = getdisk();
	result[0] = disk + 'A';
	result[1] = ':';
	result[2] = '\\';
	if (getcurdir(disk+1, result + 3) < 0)
	{
		errno = ENOENT;
		return NULL;
	}
	if (relPath && *relPath)
	{
		if (relPath[1] == ':')
		{
			disk = toupper(relPath[0]) - 'A';
			result[0] = disk + 'A';
			relPath += 2;
			if (getcurdir(disk+1, result + 3) < 0)
			{
				errno = ENOENT;
				return NULL;
			}
		}
		if (*relPath == '\\' || *relPath == '/')
		{
			relPath++;
			p = result+2;
		}
		else
		{
			p = result + strlen(result) - 1;
			if (*p != '\\')
				*++p = '\\';
		}
		while (*relPath)
		{
			if (relPath[0] == '.' && (relPath[1] == '\\' || relPath[1] == '/'))
				relPath+=2;
			else if (relPath[0] == '.' && relPath[1] == '.' && 
					(relPath[2] == '\\' || relPath[2] == '/'))
			{
				relPath += 3;
				p--; /* won't get here if p isn't pointing to a '\\' */
				while (*p != '\\' && *p != ':')
					p--;
				if (*p == ':')
					return NULL;
			}
			else
			{
				while (*relPath && *relPath != '\\' && *relPath != '/')
					*++p = *relPath++;
				if (*relPath)
				{
					*++p = '\\';
					relPath++;
				}
			}
		}
		*++p = 0;
	}
	if (!absPath)
	{
		if (!(absPath = strdup(result)))
		{
			errno = ENOMEM;
			return NULL;
		}
	}
	else if (strlen(result) > len-1)
	{
		errno = ERANGE;
		return NULL;
	}
	else strcpy(absPath, result);
	return absPath;
}
コード例 #20
0
ファイル: OPENFILC.C プロジェクト: Inzaghi2012/EZP
static unsigned long DirectoryList(HWND Window,HMSG Message,long Param1,long Param2)
{
  int hlist;

  switch (Message)
  {
    case WINDOWINIT:
         {
           //int   i,j;
           char  *dirs=NowOpenFile->dirs;
           char  *drive=NowOpenFile->drive;
           #ifdef _TURBOC_
              struct ffblk opffblk;
           #else
              struct find_t opffblk;
           #endif

           char  fn[128];
           int   r;

           MessageGo(Window,LISTSETITEMHEIGHT,16,0);
           MessageGo(Window,LISTSETITEMLENGTH,13,0);

           /*------ ByHance, 96,3.25 ----
           hlist = WindowList(Window);
           ListSetTotal(hlist,0);
           ListSetCurrent(hlist,0);
           ListSetTop(hlist,0);
           --------------------*/
           MessageGo(Window,LISTDELETEALL,0L,0L);

//           _harderr(handler);
           if( ! drive[0] )
            {
 //             *drive     = (char)getdisk()+'A';
             *drive     = (char)getdisk()+'A'-1;
             *(drive+1) = ':';
             *(drive+2) = 0;
            }

           if( !dirs[0] ) {
              #ifdef __TURBOC__
                 getcurdir((int)(*drive-'A'+1), dirs);
              #else
                 unsigned total,old;
                 _dos_getdrive(&old);
                 if(old!=*drive-'A'+1)
                    _dos_setdrive( *drive-'A'+1 , &total );
                 getcwd(dirs, 64);
                 memmove(dirs,dirs+3,61);       // cancel "C:\"
                 if(!dirs[0])
                     strcpy(dirs,"\\");
                 if(old!=*drive-'A'+1)
                    _dos_setdrive( old, &total );
              #endif
           }

           memset(&opffblk, 0, sizeof(opffblk));
           strcpy(fn,drive);

           //if( strcmp(dirs,"\\") && strcmp(dirs,"/") )
           //{
           //    strcat(fn,dirs);
           //    strcat(fn,"\\");
           //}
           if(dirs[0])
           {
                  char ch;
                  int len;

                  ch=dirs[0];
                  if(ch!='\\' && ch!='/')
                       strcat(fn,"\\");

                  strcat(fn,dirs);
                  len=strlen(fn);
                  ch=fn[len-1];
                  if(ch!='\\' && ch!='/')
                       strcat(fn,"\\");
           }

           strcat(fn,"*.*");

           r = findfirst(fn, &opffblk, FA_DIREC);
           while (!r)
           {
            if((opffblk.ff_attrib & FA_DIREC) && strcmp(opffblk.ff_name,"."))
              MessageGo(Window, LISTINSERTITEMSORTED, FP2LONG(opffblk.ff_name), 0L);
            r = findnext(&opffblk);
           }

           //MessageGo(Window,WMPAINT,0,ListGetHeight(hlist)*CHARHEIGHT);
           //   ByHance, 95,12.11
           MessageInsert(Window,REDRAWMESSAGE,0L,
               MAKELONG(WindowGetWidth(Window),WindowGetHeight(Window)) );

           {    /*--- display directory's name ----*/
              #define max_n  (304/ASC16WIDTH)
                 int x,y,w,h;
                 unsigned total,old;
                 int len;
                 int SaveColor;
                 struct viewporttype TmpViewPort;
                 char disk[20],dirs[64],file[14],ext[5];

                 strupr(fn);
                 _splitpath(fn,disk,dirs,file,ext);

                 _dos_getdrive(&old);
                 if(old!=disk[0]-'A'+1)
                    _dos_setdrive( disk[0]-'A'+1 , &total );
                 len=strlen(dirs);
                 if(len>1)
                 {
                   char ch=dirs[len-1];
                   if(ch=='\\' || ch=='/') dirs[len-1]=0;
                 }

                 chdir(dirs);
                 getcwd(dirs, 64);
                 _dos_setdrive( old, &total );

                 MouseHidden();
                 SaveColor=getcolor();
                 getviewsettings(&TmpViewPort);
                 setviewport(0,0,getmaxx(),getmaxy(),1);

                 WindowGetRealRect(Window,&x,&y,&w,&h);
                 y-=26;

                 len=strlen(dirs);
                 if(len>max_n)
                 {
                    int i;
                    i=len-1;
                    while(dirs[i]!='\\' && dirs[i]!='/' && i>max_n-12) i--;
                    strcpy(dirs,"...");
                    strcat(dirs,&dirs[i]);
                 }

                 // WaitMessageEmpty();
                 setfillstyle(1,EGA_LIGHTGRAY);
                 bar(x,y,x+304,y+25);            /*--- clear old area --*/
                 DisplayString(dirs,x,y,EGA_BLACK,EGA_LIGHTGRAY);

                 setviewport(TmpViewPort.left,TmpViewPort.top,TmpViewPort.right,
                             TmpViewPort.bottom,TmpViewPort.clip);
                 setcolor(SaveColor);
                 MouseShow();
              #undef max_n
            }
         }
         break;

    case LISTBOXCONFIRM:{
         char dir[20];
         char path[40];

         hlist = WindowList(Window);
         strcpy(dir,ListGetItem(hlist,ListGetCurrent(hlist)));
         strcpy(path,NowOpenFile->drive);
         strcat(path,dir);
         chdir(path);
         #ifdef __TURBOC__
            getcurdir(path[0]-'A'+1,NowOpenFile->dirs);
         #else
         {
            unsigned total,old;
            _dos_getdrive(&old);
            if(old!=path[0]-'A'+1)
               _dos_setdrive( path[0]-'A'+1 , &total );
            getcwd(NowOpenFile->dirs, 64);
            memmove(NowOpenFile->dirs,NowOpenFile->dirs+3,61); // cancel "C:\"
            if(old!=path[0]-'A'+1)
               _dos_setdrive( old, &total );
         }
         #endif

         MessageGo(Window,WINDOWINIT,0,0);
         MessageGo(Window,WMPAINT,0,ListGetHeight(hlist)*CHARHEIGHT);
         ListSetTop(hlist,0);
         ListSetCurrent(hlist,0);
         MessageGo(WindowGetFather(Window),DIRCHANGE,0L,0L);
         }
         break;
    default:
         return(ListBoxDefaultProcedure(Window,Message,Param1,Param2));
  }
  return(TRUE);
}