コード例 #1
0
ファイル: wfilenam.cpp プロジェクト: ABratovic/open-watcom-v2
static bool setdrive( const char* drive, unsigned* olddrive )
{
    if( strlen( drive ) > 0 ) {
        _dos_getdrive( olddrive );
        unsigned drv = toupper( drive[0]) - 'A' + 1;    //1='A'; 2='B'; ...
        if( *olddrive != drv ) {
            unsigned total; _dos_setdrive( drv, &total );
            unsigned newdrive; _dos_getdrive( &newdrive );
            if( drv != newdrive ) {
                return( false );
            }
        }
    }
    return( true );
}
コード例 #2
0
ファイル: QF.C プロジェクト: rbieber/quickfind
/******************************************************************************
 *
 *          Name:   splitfilespec
 *      Synopsis:   void splitfilespec(szFileName, file, drive);
 *                  PSTR szFileName,          szFileName to split
 *                          *file;              variable to hold filename.ext
 *                  int     drive;              variable to store new drive #
 *
 *   Description:   parses szFileName and returns the drive number and filename
 *
 *****************************************************************************/
void PASCAL splitfilespec(const PSTR szFileSpec, PSTR szFile, unsigned *piDrive)
{
   char szDrive[_MAX_DRIVE],
       szDir[_MAX_DIR], szFName[_MAX_FNAME], szExt[_MAX_EXT];

   _splitpath(szFileSpec, szDrive, szDir, szFName, szExt);

   if (*szDir && *(szDir + 1))
      printf("\nIgnoring path:  %s\n", szDir);

   if (strlen(szDrive) > 1)
      *piDrive = *szDrive - 64;
   else
      _dos_getdrive(piDrive);

   if (!*szFName) {
      *szFName = '*';
      *(szFName + 1) = 0;
   }

   if (!*szExt) {
      *szExt = '.';
      *(szExt + 1) = '*';
      *(szExt + 2) = 0;
   }

   sprintf(szFile, "%s%s", szFName, szExt);
}
コード例 #3
0
ファイル: cdir.c プロジェクト: Eric-Schnipke/snippets
 drive_t getdisk(void)
 {
       drive_t drive;

       _dos_getdrive(&drive);
       return drive - 1;
 }
コード例 #4
0
/*--------------------------------------------------------------------------*

Name            getdisk - gets current drive

Usage           int getdisk(void);

Prototype in    dir.h

Description     gets the current drive.

Return value    0 = A:, 1 = B:, 2 = C:; etc.

*---------------------------------------------------------------------------*/
int getdisk(void)
{
    unsigned drive;

    _dos_getdrive(&drive);
    return ((int)drive - 1);
}
コード例 #5
0
ファイル: getdrive.c プロジェクト: guolilong2012/study
void main (void)
 {
   unsigned drive_number;

   _dos_getdrive(&drive_number);

   printf("The current drive is %c\n", drive_number - 1 + 'A');
 }
コード例 #6
0
int LocalGetDrv( void )
/*********************/
{
    unsigned    drive;

    _dos_getdrive( &drive );
    return( drive - 1 );
}
コード例 #7
0
_WCRTLINK CHAR_TYPE *__F_NAME(_getdcwd,_wgetdcwd)( int drive, CHAR_TYPE *buffer, size_t maxlen )
{
    unsigned            olddrive, tmpdrive;

    /*** Change drive if necessary ***/
    if( drive != 0 ) {
        _dos_getdrive( &olddrive );
        _dos_setdrive( drive, &tmpdrive );
        _dos_getdrive( &tmpdrive );
        if( drive != tmpdrive ) {
            _RWD_errno = ENODEV;
            return( NULL );
        }
    }
    buffer = __F_NAME(getcwd,_wgetcwd)( buffer, maxlen );
    if( drive != 0 )  _dos_setdrive( olddrive, &tmpdrive );
    return( buffer );
}
コード例 #8
0
static int __getcwd (char drive, char *buffer, int buffersize)
{
  unsigned int old_drive, num_drives;
  _dos_getdrive (&old_drive);
  _dos_setdrive (drive, &num_drives);
  getcwd (buffer, buffersize);
  _dos_setdrive (old_drive, &num_drives);
  return strlen (buffer);
}
コード例 #9
0
ファイル: text_gui.c プロジェクト: spippolatore/abuse
long K_avail(char *path)
{
  unsigned drive=0;
  if (path[1]==':') drive=toupper(path[0])-'A'+1;
  else _dos_getdrive(&drive);

  struct diskfree_t f;
  _dos_getdiskfree(drive,&f);
  
  return (long)((long)f.sectors_per_cluster*(long)f.bytes_per_sector/1024)*(long)f.avail_clusters;
}
コード例 #10
0
ファイル: text_gui.c プロジェクト: spippolatore/abuse
int change_dir(char *path)
{
#ifdef __WATCOMC__
  unsigned cur_drive;
  _dos_getdrive(&cur_drive);
  if (path[1]==':')
  {
    unsigned total;
    _dos_setdrive(toupper(path[0])-'A'+1,&total);


    unsigned new_drive;
    _dos_getdrive(&new_drive);

    if (new_drive!=toupper(path[0])-'A'+1)
    {
      return 0;
    }

    path+=2;
  }
  
  int er=chdir(path);
  if (er)
  {
    unsigned total;
    _dos_setdrive(cur_drive,&total);
  }
  return !er;
#else
  int ret;    // weird, used to include =chdir(path)
#ifdef __MAC__
  ret=chdir(macify_name(path));
#else
  ret=chdir(path);
#endif
  return ret==0;
#endif  
}
コード例 #11
0
ファイル: dossys.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * PushDirectory
 */
void PushDirectory( char *orig )
{
    unsigned    c;

    oldPath[0] = 0;
    _dos_getdrive( &c );
    oldDrive = (char) c;
    if( orig[1] == ':' ) {
        ChangeDrive( orig[0] );
    }
    GetCWD2( oldPath, _MAX_PATH );

} /* PushDirectory */
コード例 #12
0
ファイル: label.c プロジェクト: ErisBlastar/osfree
void GetDrive()
{
    unsigned driveno;

#ifdef __TURBOC__
    driveno = getdisk(); /* get current drive */
    Drive[0] = 'A' + driveno;
#else
    _dos_getdrive(&driveno);
    Drive[0] = (char) driveno + 'A' - 1;
#endif
    valid_drive(Drive);

} /* end GetDrive. */
コード例 #13
0
ファイル: savelbox.c プロジェクト: jossk/open-watcom-v2
/*
 * relToAbs - converts a relative path to an absolute path based on the
 *            current working directory
 *          - assumes that the path given is valid
 */
static void relToAbs( char *path, char *out )
{
    char        *cwd;
    unsigned    old_dir;
    unsigned    tot;
    char        dir[_MAX_DIR];
    char        drive[_MAX_DRIVE];
    char        fname[_MAX_FNAME];
    char        ext[_MAX_EXT];
    char        *ptr;

    cwd = getcwd( NULL, 0 );
    _dos_getdrive( &old_dir );
    _splitpath( path, drive, dir, fname, ext );
    if( strcmp( dir, "\\" ) != 0 ) {
        if( *dir != '\0' ) {
            ptr = dir;
            while( *ptr ) {
                ptr++;
            }
            ptr--;
            *ptr = '\0';
        }
    }
    _dos_setdrive( toupper( drive[0] ) - 'A' + 1, &tot );
    chdir( dir );
    getcwd( out, _MAX_PATH );
    _dos_setdrive( old_dir, &tot );
    chdir( cwd );
    free( cwd );
    ptr = out;
    /*
     * Make sure _splitpath doesn't mistake the last directory spec as a
     * filename.
     */
    while( *ptr ) {
        ptr++;
    }
    if( *(ptr - 1) != '\\' ) {
        ptr[0] = '\\';
        ptr++;
    }
    strcpy( ptr, "a" );
    strupr( fname );
    strupr( ext );
    _splitpath( out, drive, dir, NULL, NULL );
    _makepath( out, drive, dir, fname, ext );

} /* relToAbs */
コード例 #14
0
ファイル: dossys.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * ChangeDrive - change the working drive
 */
int ChangeDrive( int drive )
{
    char        a;
    unsigned    b;
    unsigned    total, c;

    a = (char) tolower( drive ) - (char) 'a';
    b = a + 1;
    _dos_setdrive( b, &total );
    _dos_getdrive( &c );
    if( b != c ) {
        return( ERR_NO_SUCH_DRIVE );
    }
    return( ERR_NO_ERR );

}/* ChangeDrive */
コード例 #15
0
int getcurdir(int __drive, char *buffer) {
#define MAXPATHLEN MAXPATH
   long size=MAXPATHLEN;
   char tmp[MAXPATHLEN+1];
   tmp[0]='\\';
#if 1
   unsigned int old, dummy;
   _dos_getdrive(&old);
   _dos_setdrive(__drive,&dummy);
   if (getcwd(tmp, size) == 0) {  // getcwd returns a leading backslash
      _dos_setdrive(old,&dummy);
      return 0;
   }
   _dos_setdrive(old,&dummy);
   strcpy(buffer,&tmp[3]);
   return 1;
#endif  // 1
#if 0
#if defined(__OS2__)
   size_t len;
   char *p;
   unsigned long l = MAXPATHLEN;
   if (DosQueryCurrentDir(__drive,tmp+1,&l)) return NULL;
   len = strlen(tmp) + 2;
   if (buffer == NULL) {
      if (size < len) size = len;
      buffer = new char[size];
   }
   if (buffer == NULL) {
      errno = ENOMEM;
      return (0);
   }
   for (p = tmp; *p != 0; ++p) // no forward slashes please.
      if (*p == '/') *p = '\\';
   strcpy(buffer, tmp+1);
   return 1;
#endif  // __OS2__
#endif  // 0
}
コード例 #16
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);
}
コード例 #17
0
ファイル: sys.c プロジェクト: TijmenW/FreeDOS
int main(int argc, char **argv)
{
  COUNT drive;                  /* destination drive */
  COUNT drivearg = 0;           /* drive argument position */
  BYTE *bsFile = NULL;          /* user specified destination boot sector */
  unsigned srcDrive;            /* source drive */
  BYTE srcPath[SYS_MAXPATH];    /* user specified source drive and/or path */
  BYTE rootPath[4];             /* alternate source path to try if not '\0' */
  WORD slen;

  printf("FreeDOS System Installer " SYS_VERSION "\n\n");

  if (argc > 1 && memicmp(argv[1], "CONFIG", 6) == 0)
  {
    exit(FDKrnConfigMain(argc, argv));
  }

  srcPath[0] = '\0';
  if (argc > 1 && argv[1][1] == ':' && argv[1][2] == '\0')
    drivearg = 1;

  if (argc > 2 && argv[2][1] == ':' && argv[2][2] == '\0')
  {
    drivearg = 2;
    strncpy(srcPath, argv[1], SYS_MAXPATH - 12);
    /* leave room for COMMAND.COM\0 */
    srcPath[SYS_MAXPATH - 13] = '\0';
    /* make sure srcPath + "file" is a valid path */
    slen = strlen(srcPath);
    if ((srcPath[slen - 1] != ':') &&
        ((srcPath[slen - 1] != '\\') || (srcPath[slen - 1] != '/')))
    {
      srcPath[slen] = '\\';
      slen++;
      srcPath[slen] = '\0';
    }
  }

  if (drivearg == 0)
  {
    printf("Usage: %s [source] drive: [bootsect [BOTH|BOOTONLY]]\n", pgm);
    printf
        ("  source   = A:,B:,C:\\KERNEL\\BIN\\,etc., or current directory if not given\n");
    printf("  drive    = A,B,etc.\n");
    printf
        ("  bootsect = name of 512-byte boot sector file image for drive:\n");
    printf("             to write to *instead* of real boot sector\n");
    printf
        ("  BOTH     : write to *both* the real boot sector and the image file\n");
    printf
        ("  BOOTONLY : do *not* copy kernel / shell, only update boot sector or image\n");
    printf("%s CONFIG /help\n", pgm);
    exit(1);
  }
  drive = toupper(argv[drivearg][0]) - 'A';

  if (drive < 0 || drive >= 26)
  {
    printf("%s: drive %c must be A:..Z:\n", pgm,
           *argv[(argc == 3 ? 2 : 1)]);
    exit(1);
  }

  /* Get source drive */
  if ((strlen(srcPath) > 1) && (srcPath[1] == ':'))     /* src specifies drive */
    srcDrive = toupper(*srcPath) - 'A';
  else                          /* src doesn't specify drive, so assume current drive */
  {
#ifdef __TURBOC__
    srcDrive = (unsigned) getdisk();
#else
    _dos_getdrive(&srcDrive);
    srcDrive--;
#endif
  }

  /* Don't try root if src==dst drive or source path given */
  if ((drive == srcDrive)
      || (*srcPath
          && ((srcPath[1] != ':') || ((srcPath[1] == ':') && srcPath[2]))))
    *rootPath = '\0';
  else
    sprintf(rootPath, "%c:\\", 'A' + srcDrive);

  if ((argc <= drivearg + 2)
      || (memicmp(argv[drivearg + 2], "BOOTONLY", 8) != 0))
  {
    if (!check_space(drive, oldboot))
    {
      printf("%s: Not enough space to transfer system files\n", pgm);
      exit(1);
    }

    printf("\nCopying KERNEL.SYS...\n");
    if (!copy(drive, srcPath, rootPath, "KERNEL.SYS"))
    {
      printf("\n%s: cannot copy \"KERNEL.SYS\"\n", pgm);
      exit(1);
    }
  } /* copy kernel */

  if (argc > drivearg + 1)
    bsFile = argv[drivearg + 1];
    
  printf("\nWriting boot sector...\n");
  put_boot(drive, bsFile,
           (argc > drivearg + 2)
           && memicmp(argv[drivearg + 2], "BOTH", 4) == 0);

  if ((argc <= drivearg + 2)
      || (memicmp(argv[drivearg + 2], "BOOTONLY", 8) != 0))
  {
    printf("\nCopying COMMAND.COM...\n");
    if (!copy(drive, srcPath, rootPath, "COMMAND.COM"))
    {
      char *comspec = getenv("COMSPEC");
      if (comspec != NULL)
      {
        printf("%s: Trying \"%s\"\n", pgm, comspec);
        if (!copy(drive, comspec, NULL, "COMMAND.COM"))
          comspec = NULL;
      }
      if (comspec == NULL)
      {
        printf("\n%s: cannot copy \"COMMAND.COM\"\n", pgm);      
        exit(1);
      }
    }
  } /* copy shell */

  printf("\nSystem transferred.\n");
  return 0;
}
コード例 #18
0
ファイル: guifdlg.c プロジェクト: pavanvunnava/open-watcom-v2
int GUIGetFileName( gui_window *wnd, open_file_name *ofn )
{
  #ifdef _M_I86
    wnd = wnd;
    ofn = ofn;
  #else
    FILEDLG             fdlg;
    int                 str_index;
    int                 rc;
    ULONG               i;
    ULONG               slen, flen;
    unsigned            drive;
    unsigned            old_drive;
    unsigned            drives;
    char                initial_path[_MAX_PATH];
    char                old_path[_MAX_PATH];
    char                fname[_MAX_FNAME + _MAX_EXT];
    char                *cwd;

    old_path[0] = '\0';
    fname[0] = '\0';
    cwd = getcwd( initial_path, _MAX_PATH );
    if( cwd ) {
        _splitpath( cwd, NULL, old_path, NULL, NULL );
    }

    drive = 0;
    initial_path[0] = '\0';
    if( ofn->initial_dir != NULL && ofn->initial_dir[0] != '\0' ) {
        if( ofn->initial_dir[1] == ':' ) {
            drive = ofn->initial_dir[0];
        }
        _splitpath( ofn->initial_dir, NULL, initial_path, NULL, NULL );
    }

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

    fdlg.cbSize = sizeof( fdlg );

    fdlg.fl = FDS_CENTER | FDS_ENABLEFILELB;
    if( ofn->flags & OFN_ISSAVE ) {
        fdlg.fl |= FDS_SAVEAS_DIALOG;
        fdlg.pszOKButton = (PSZ)LIT( FDlg_Save_Text );
    } else {
        fdlg.fl |= FDS_OPEN_DIALOG;
        fdlg.pszOKButton = (PSZ)LIT( FDlg_Open_Text );
    }
    if( ofn->flags & OFN_ALLOWMULTISELECT ) {
        fdlg.fl |= FDS_MULTIPLESEL;
    }

    fdlg.pszTitle = ofn->title;

    if( ofn->file_name ) {
        strncpy( fdlg.szFullFile, ofn->file_name, CCHMAXPATH );
        fdlg.szFullFile[CCHMAXPATH-1] = '\0';
    }

    if( ( !ofn->file_name || !*ofn->file_name ) && ofn->filter_index >= 0 ) {
        str_index = 0;
        for( i=0; ;i++ ) {
            if( ofn->filter_list[i] == '\0' ) {
                if( ofn->filter_list[i+1] == '\0' ) {
                    break;
                }
                str_index++;
                if( str_index == ofn->filter_index * 2 - 1 ) {
                    i++;
                    break;
                }
            }
        }
        if( ofn->filter_list[i] != '\0' ) {
            strncpy( fdlg.szFullFile, ofn->filter_list + i, CCHMAXPATH );
            fdlg.szFullFile[CCHMAXPATH-1] = '\0';
        }
    }

  #if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_getdrive( &old_drive );
        _dos_setdrive( tolower( drive ) - 'a' + 1, &drives );
        if( *initial_path && *old_path ) {
            chdir( initial_path );
        }
    }
  #endif

    rc = (int)WinFileDlg( HWND_DESKTOP, GUIGetParentFrameHWND( wnd ), &fdlg );

    if( fdlg.papszFQFilename ) {
        ofn->file_name[0] = '\0';
        slen = 0;
        for( i=0; i<fdlg.ulFQFCount; i++ ) {
            flen = strlen( fdlg.papszFQFilename[0][i] );
            if( ( slen + flen + 2 ) > ofn->max_file_name ) {
                return( OFN_RC_FAILED_TO_INITIALIZE );
            }
            if( slen ) {
                ofn->file_name[slen++] = ' ';
            }
            memcpy( &ofn->file_name[slen], fdlg.papszFQFilename[0][i], flen + 1);
            slen += flen;
        }
        WinFreeFileDlgList( fdlg.papszFQFilename );
        if( ofn->base_file_name  != NULL ) {
            ofn->base_file_name[0] = '\0';
        }
    } else {
        if( strlen( fdlg.szFullFile ) > ( ofn->max_file_name - 1 ) ) {
            return( OFN_RC_FAILED_TO_INITIALIZE );
        } else {
            strcpy( ofn->file_name, fdlg.szFullFile );
            _splitpath( fdlg.szFullFile, NULL, NULL, fname, NULL );
            _splitpath( fdlg.szFullFile, NULL, NULL, NULL, fname+strlen(fname) );
        }
        if( ofn->base_file_name  != NULL ) {
            ofn->base_file_name[0] = '\0';
            if( strlen( fname ) <= ofn->max_base_file_name ) {
                strcpy( ofn->base_file_name, fname );
            }
        }
    }

  #if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_setdrive( old_drive, &drives );
        if( *initial_path && *old_path ) {
            chdir( old_path );
        }
    }
  #endif

    if( fdlg.lReturn == DID_CANCEL ) {
        return( OFN_RC_NO_FILE_SELECTED );
    }

    if( rc ) {
        return( OFN_RC_FILE_SELECTED );
    }
  #endif
    return( OFN_RC_FAILED_TO_INITIALIZE );
} /* GUIGetFileName */
コード例 #19
0
ファイル: guifdlg.c プロジェクト: pavanvunnava/open-watcom-v2
int GUIGetFileName( gui_window *wnd, open_file_name *ofn )
{
    OPENFILENAME        wofn;
    bool                issave;
    int                 rc;
    unsigned            drive;
#if defined(HAVE_DRIVES)
    unsigned            old_drive;
    unsigned            drives;
#endif

    LastPath = NULL;
    if( ofn->initial_dir != NULL && ofn->initial_dir[0] != '\0' && ofn->initial_dir[1] == ':' ) {
        drive = ofn->initial_dir[0];
        memmove( ofn->initial_dir, ofn->initial_dir+2, strlen( ofn->initial_dir+2 ) + 1 );
    } else {
        drive = 0;
    }

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

    if( ofn->flags & OFN_ISSAVE ) {
        issave = true;
    } else {
        issave = false;
    }

    wofn.Flags = 0;
    if( hookFileDlg ) {
        wofn.Flags |= OFN_ENABLEHOOK;
    }
    if( !(ofn->flags & OFN_CHANGEDIR) ) {
        wofn.Flags |= OFN_NOCHANGEDIR;
    }

    if( ofn->flags & OFN_OVERWRITEPROMPT ) {
        wofn.Flags |= OFN_OVERWRITEPROMPT;
    }
    if( ofn->flags & OFN_HIDEREADONLY ) {
        wofn.Flags |= OFN_HIDEREADONLY;
    }
    if( ofn->flags & OFN_FILEMUSTEXIST ) {
        wofn.Flags |= OFN_FILEMUSTEXIST;
    }
    if( ofn->flags & OFN_PATHMUSTEXIST ) {
        wofn.Flags |= OFN_PATHMUSTEXIST;
    }
    if( ofn->flags & OFN_ALLOWMULTISELECT ) {
        wofn.Flags |= OFN_ALLOWMULTISELECT;
    }
    wofn.hwndOwner = GUIGetParentFrameHWND( wnd );
    wofn.hInstance = GUIMainHInst;
    wofn.lStructSize = sizeof( wofn );
    wofn.lpstrFilter = ofn->filter_list;
    wofn.nFilterIndex = ofn->filter_index;
    wofn.lpstrFile = ofn->file_name;
    wofn.nMaxFile = ofn->max_file_name;
    wofn.lpstrFileTitle = ofn->base_file_name;
    wofn.nMaxFileTitle = ofn->max_base_file_name;
    wofn.lpstrTitle = ofn->title;
    wofn.lpstrInitialDir = ofn->initial_dir;
    wofn.lpfnHook = (LPOFNHOOKPROC)NULL;
    if( hookFileDlg ) {
        wofn.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( OpenHook, GUIMainHInst );
    }

#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_getdrive( &old_drive );
        _dos_setdrive( tolower( drive ) - 'a' + 1, &drives );
    }
#endif
    if( issave ) {
        rc = GetSaveFileName( &wofn );
    } else {
        rc = GetOpenFileName( &wofn );
    }

    if( hookFileDlg ) {
        (void)FreeProcInstance( (FARPROC)wofn.lpfnHook );
    }

    if( LastPath && ( !rc || !( ofn->flags & OFN_WANT_LAST_PATH ) ) ) {
        GUIMemFree( LastPath );
        LastPath = NULL;
    }
    ofn->last_path = LastPath;
#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_setdrive( old_drive, &drives );
    }
#endif
    if( rc ) {
        return( OFN_RC_FILE_SELECTED );
    }
    if( !CommDlgExtendedError() ) {
        return( OFN_RC_NO_FILE_SELECTED );
    }
    return( OFN_RC_FAILED_TO_INITIALIZE );
} /* _GUIGetFileName */
コード例 #20
0
int getdisk(void) {
   unsigned int mydrive;
   _dos_getdrive(&mydrive);
   return mydrive-1;
}
コード例 #21
0
ファイル: stat.c プロジェクト: doniexun/OrangeC
int _RTL_FUNC _stat(char *path, struct _stat *__statbuf)
{
	int fd, rv, rootdir;
	char pbuf[265];
	memset(__statbuf, 0, sizeof(__statbuf));
	if (!strcmp(path,"."))
		path = getcwd(pbuf, 265);
	rootdir = ((path[1] == ':' &&
			(path[2] == '\\' || path[2] == '/') &&
			(path[3] == '.' || path[3] == '\0')) ||
			((path[0] == '\\' || path[0] == '/') &&
			(path[1] == '.' || path[1] == '\0')));
	if (!rootdir)
	{
		int l = strlen(path);
		if ((path[l-1] == '/' || path[l-1] == '\\'))
		{
			path = strcpy(pbuf, path);
			path[l-1] = '\0';
		}
	}
	rv = __ll_namedstat(path, __statbuf);   
	if (rv == -1)
	{
		if (rootdir)
		{
			memset(__statbuf, 0, sizeof(*__statbuf));
			__statbuf->st_atime = __statbuf->st_ctime = __statbuf->st_mtime =
					(10 * 365 + 2) * 60 * 60 * 24 - _timezone ;
			__statbuf->st_mode = S_IFDIR ;
			rv = 0;
		}
		else
		{
			fd = open(path, O_RDONLY, 0);
			if (fd != -1)
			{
				if (__ll_isatty(__uihandles[fd]))
				{
					__statbuf->st_mode |= S_IFREG | S_IREAD | S_IWRITE;
					rv = 0;
				}
				close(fd);
			}
		}
	}
        if (rv == 0)
	{
		int drive;
		if (path[1] == ':')
		{
			drive = toupper(path[0]) - 'A';
		}
		else
		{
			_dos_getdrive(&drive);
			drive--;
		}
		__statbuf->st_ino = 0 ;
		__statbuf->st_uid = 0 ;
		__statbuf->st_nlink = 1;
		__statbuf->st_rdev = __statbuf->st_dev = drive;
	}
        if (rv == -1)
                errno = ENOENT;
	return rv;
}
コード例 #22
0
void Burger::Filename::SetFromNative(const char *pInput)
{
	Clear();

	Regs16 Regs;		// Used for DOS calls

	// Parse out the C: (Drive number)
	// Assume no drive is found
	Word uDriveNum = static_cast<Word>(-1);

	// Get the possible drive letter
	WordPtr uInputLength = Burger::StringLength(pInput);
	if (uInputLength>=2) {
		Word uTemp = reinterpret_cast<const Word8*>(pInput)[0];
		uTemp = (uTemp&0xDF)-'A';		// Upper case
		// Could this be a drive letter?
		if ((uTemp<26) && (reinterpret_cast<const Word8*>(pInput)[1]==':')) {
			uDriveNum = uTemp;
			pInput += 2;				// Accept the drive letter
			uInputLength -= 2;			// Shrink the input string
		}
	}
	
	// If not a network name, (//), query MSDOS for the current drive
	
	if (uDriveNum==static_cast<Word>(-1)) {
		if ((uInputLength<2) ||
			(reinterpret_cast<const Word8*>(pInput)[0]!='\\') ||
			(reinterpret_cast<const Word8*>(pInput)[1]!='\\')) {
			// Get the default drive number
			_dos_getdrive(&uDriveNum);
			--uDriveNum;
		} else {
			pInput+=2;
			uInputLength-=2;	// Parse past the volume slashes
		}
	}

	WordPtr uWorkingDirectoryLength = 0;
	const Word8 *pWorkingDirectory = NULL;
	
	// Obtain the current working directory for the current drive
	
	if (uInputLength && (uDriveNum!=static_cast<Word>(-1))) {
		if (reinterpret_cast<const Word8*>(pInput)[0] != '\\') {
			Regs.dx = static_cast<Word16>(uDriveNum+1);	// Requested drive
			Word32 DosBuffer = GetRealBufferPtr();		// Get real memory buffer
			Regs.ds = static_cast<Word16>(DosBuffer>>16U);	// Pass to Dos call
			Regs.si = static_cast<Word16>(DosBuffer&0xFFFFU);
			Regs.ax = 0x7147;				// First try long version
			Int86x(0x21,&Regs,&Regs);		// Call DOS
			if (Regs.flags&1) {				// Carry set??
				Regs.ax = 0x4700;			// Try DOS 2.0 version
				Int86x(0x21,&Regs,&Regs);	// Get the working directory
			}
			// If carry is clear, then one of the preceeding calls succeeded
			if (!(Regs.flags&1)) {
				// Convert to my pointer
				pWorkingDirectory = static_cast<Word8 *>(RealToProtectedPtr(DosBuffer));
				uWorkingDirectoryLength = Burger::StringLength(reinterpret_cast<const char *>(pWorkingDirectory));
			}
		} else {
			--uInputLength;
コード例 #23
0
ファイル: getdisk.c プロジェクト: NoSuchProcess/OrangeC
int _RTL_FUNC         getdisk( void )
{
    int drv;
    _dos_getdrive(&drv);
    return drv-1;
}
コード例 #24
0
ファイル: my_getwd.c プロジェクト: Miguel-J/eneboo-core
int my_setwd(const char *dir, myf MyFlags)
{
  int res;
  size_s length;
  my_string start,pos;
#if defined(VMS) || defined(MSDOS) || defined(OS2)
  char buff[FN_REFLEN];
#endif
  DBUG_ENTER("my_setwd");
  DBUG_PRINT("my",("dir: '%s'  MyFlags %d", dir, MyFlags));

  start=(my_string) dir;
#if defined(MSDOS) || defined(OS2) /* OS2/MSDOS chdir can't change drive */
#if !defined(_DDL) && !defined(WIN32)
  if ((pos=(char*) strchr(dir,FN_DEVCHAR)) != 0)
  {
    uint drive,drives;

    pos++;				/* Skip FN_DEVCHAR */
    drive=(uint) (my_toupper(&my_charset_latin1,dir[0])-'A'+1);
    drives= (uint) -1;
    if ((pos-(byte*) dir) == 2 && drive > 0 && drive < 32)
    {
#ifdef OS2
      _chdrive(drive);
      drives = _getdrive();
#else
      _dos_setdrive(drive,&drives);
      _dos_getdrive(&drives);
#endif
    }
    if (drive != drives)
    {
      *pos='\0';			/* Dir is now only drive */
      my_errno=errno;
      my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT);
      DBUG_RETURN(-1);
    }
    dir=pos;				/* drive changed, change now path */
  }
#endif
  if (*((pos=strend(dir)-1)) == FN_LIBCHAR && pos != dir)
  {
    strmov(buff,dir)[-1]=0;			/* Remove last '/' */
    dir=buff;
  }
#endif /* MSDOS*/
  if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0))
    dir=FN_ROOTDIR;
#ifdef VMS
  {
    pos=strmov(buff,dir);
    if (pos[-1] != FN_LIBCHAR)
    {
      pos[0]=FN_LIBCHAR;		/* Mark as directory */
      pos[1]=0;
    }
    system_filename(buff,buff);		/* Change to VMS format */
    dir=buff;
  }
#endif /* VMS */
  if ((res=chdir((char*) dir)) != 0)
  {
    my_errno=errno;
    if (MyFlags & MY_WME)
      my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno);
  }
  else
  {
    if (test_if_hard_path(start))
    {						/* Hard pathname */
      pos=strmake(&curr_dir[0],start,(size_s) FN_REFLEN-1);
      if (pos[-1] != FN_LIBCHAR)
      {
	length=(uint) (pos-(char*) curr_dir);
	curr_dir[length]=FN_LIBCHAR;		/* must end with '/' */
	curr_dir[length+1]='\0';
      }
    }
    else
      curr_dir[0]='\0';				/* Don't save name */
  }
  DBUG_RETURN(res);
} /* my_setwd */
コード例 #25
0
ファイル: QF.C プロジェクト: rbieber/quickfind
//*****************************************************************************
//
// Main Program
//
//*****************************************************************************
int main(int argc, const char **argv)
{
   int iDrive = 0;
   unsigned int iNumDrives;

   PSTR pchTemp = NULL;

#ifdef _DOS
   setvbuf(stdout, NULL, _IONBF, 0);
#endif

   usFirstDisk = fSwitches = 0;

   DisplayMessage(IDS_EGOLINE, VERSION);

   ParseEnvironmentOptions("QF_OPT");

   if (!(parms(&argc, (const PPSTR) argv + 1) - 1))
      usage(TRUE);
   else
      argv++;

#ifndef _WINDOWS
   signal(SIGINT, c_break);     // set ctrl-break handler
#endif

#if !defined(_WINDOWS) && !defined(__OS2__) && !defined(WIN32)
   _harderr(handler);           // set hardware error handler
#endif

   // get original drive and directory ...
   _dos_getdrive(&usFirstDisk);
   getcwd(szOriginalPath, sizeof(szOriginalPath));

   _dos_setdrive(usFirstDisk, (unsigned int *) &iNumDrives);
   splitfilespec((char *) strupr((char *) *argv), szFileName, (unsigned int *) &iDrive);

   if (!isvalid(iDrive) || bError)  // invalid drive specified.
   {
      BELL();
      DisplayMessage(IDS_INVALIDDRIVE);
      exit(1);
   }

   if ((fSwitches & DELETEFILE) && (fSwitches & NOPROMPT))
      if (!ShowNoPromptMessage(iDrive, szFileName))
         c_break(0);

   if (fSwitches & ALLDRIVES) {
      for (iDrive = 1; iDrive <= floppies(); iDrive++) {
         if (isvalid(iDrive) && !bError) {
            _dos_setdrive(iDrive, &iNumDrives);
            walkdirs("\\", 0, filefind);
         }

         if (bError)
            bError = FALSE;
      }

      for (floppies() + 1; iDrive <= iNumDrives; iDrive++) {
         if (isvalid(iDrive) && !bError) {
            _dos_setdrive(iDrive, &iNumDrives);
            getcwd(curdir, sizeof(curdir));  // save current directory on
            walkdirs("\\", 0, filefind);  // alternate drives
            chdir(curdir);
         }

         if (bError)
            bError = FALSE;
      }
   } else {
      _dos_setdrive(iDrive, &iNumDrives);
      getcwd(curdir, sizeof(curdir));  //  save current directory on alternate drives

      if (fSwitches & FROM_CURDIR)  //  Only search current directory and subdirs
         walkdirs(szOriginalPath, 1, filefind);
      else
         walkdirs("\\", 0, filefind);

      chdir(curdir);
   }

   _dos_setdrive(usFirstDisk, &iNumDrives);
   chdir(szOriginalPath);

   // print totals

   if (!(fSwitches & NOFILEINFO)) {
      if (fSwitches & SUBDIRTOT) {
         if (ulDirs || ulTotal) {
            PSTR pchNumFiles = NULL;

            printf("\n   ================ ===========\n");

            pchTemp = LongToString(ulTotalFileSize, pchTemp, 11, LTS_PADLEFT);
            pchNumFiles = LongToString(ulTotal + ulDirs, NULL, 16, LTS_PADLEFT);

            printf
                ("   %s %s total files/bytes in all directories\n",
                 pchNumFiles, pchTemp);

            if (pchNumFiles)
               free(pchNumFiles);

            usLineCount += 3;
         }
      }

      if (ulDirs || ulTotal) {
         printf("\n");

         if (ulDirs) {
            pchTemp = LongToString(ulDirs, pchTemp, 11, LTS_PADLEFT);
            printf(" %s directory(s) found.\n", pchTemp);
         }

         pchTemp = LongToString(ulTotal, pchTemp, 11, LTS_PADLEFT);
         printf(" %s file(s) found.\n", pchTemp);
      } else
         printf("\nNo files found.\n");

      if ((fSwitches & DELETEFILE) && ulTotal) {
         pchTemp = LongToString((LONG) nDeleted, pchTemp, 11, LTS_PADLEFT);
         printf(" %s file(s) deleted.\n", pchTemp);
      }

      if (fSwitches & LOG) {
         unassign();
         printf(" done.");
      }
   }
   // free the memory that MIGHT have been allocated by LongToString.
   if (pchTemp)
      free(pchTemp);

   return (0);
}
コード例 #26
0
ファイル: adplay.cpp プロジェクト: adplug/adplay-dos
int main(int argc, char *argv[])
{
  char          inkey=0, *prgdir, *curdir, *program_name;
  bool          ext, validcfg, quit = false, bkgply = false, batchply = false;
  unsigned int	opt, prgdrive, i;
  CWindow       *focus;

#ifdef DEBUG
  f_log = fopen(DEBUG_FILE,"wt");
#endif

  std::cout << ADPLAYVERS << ", Copyright (c) 2000 - 2006 Simon Peter <*****@*****.**>" << std::endl << std::endl;

  // check that no other instance is running
  {
    char *adplayenv = getenv("ADPLAY");

    if(adplayenv && !strcmp(adplayenv,"S")) {
      std::cout << "AdPlay already running!" << std::endl;
      exit(EXIT_FAILURE);
    } else
      setenv("ADPLAY","S",1); // flag our instance
  }

  // Build program executable name
  program_name = strrchr(argv[0], '\\') ? strrchr(argv[0], '\\') + 1 : argv[0];

  CAdPlug::debug_output("debug.log"); // Redirect AdPlug's debug to file
  // Build path to default configuration file (in program's directory)
  SPLITPATH(argv[0],configfile,configfile+2,NULL,NULL);
  strcat(configfile,CONFIGFILE);

  loadconfig(configfile,DEFCONFIG);       // load default configuration

  // parse commandline for general options
  while((opt = getopt(argc,argv)))
    switch(opt) {
    case 1:	// display help
    case 2:
      std::cout << "Usage: " << program_name << " [options]" << std::endl << std::endl;
      std::cout << "Options can be set with '-' or '/' respectively." << std::endl << std::endl;
      std::cout << " -?, -h      Display commandline help" << std::endl <<
	" -p port     Set OPL2 port" << std::endl <<
	" -o          Force OPL2 port" << std::endl <<
	" -f file     Use alternate configuration file" << std::endl <<
	" -c section  Load another configuration section" << std::endl <<
	" -b file     Immediate background playback using " <<
	"specified file" << std::endl <<
	" -q files    Immediate (batch mode) playback using " <<
	"specified files" << std::endl;
      showcursor();
      exit(EXIT_SUCCESS);
    case 3:	// set OPL2 port
      opl.setport(atoi(argv[myoptind++]));
      break;
    case 4: // force OPL2 port
      oplforce = true;
      break;
    case 7:	// background playback
      bkgply = true;
      break;
    case 8: // batch mode playback
      batchply = true;
      break;
    }

  // Bail out if OPL2 not detected and not force
  if(!opl.detect() && !oplforce) {
    std::cout << "No OPL2 detected!" << std::endl;
    showcursor();
    exit(EXIT_FAILURE);
  }

  // Hand our database to AdPlug
  CAdPlug::set_database(&mydb);

  /*** Background playback mode ***/
  if(bkgply)
    if(!(p = CAdPlug::factory(argv[myoptind],&opl))) {
      std::cout << "[" << argv[myoptind] << "]: unsupported file type!" << std::endl;
      exit(EXIT_FAILURE);
    } else {
      std::cout << "Background playback... (type EXIT to stop)" << std::endl;
#ifdef HAVE_WCC_TIMER_H
      tmInit(poll_player,0xffff,DEFSTACK);
#elif defined HAVE_GCC_TIMER_H
      timer_init(poll_player);
#endif
      dopoll = true;
#ifdef __WATCOMC__
      _heapshrink();
#endif
      system(getenv("COMSPEC"));
#ifdef HAVE_WCC_TIMER_H
      tmClose();
#elif defined HAVE_GCC_TIMER_H
      timer_deinit();
#endif
      stop();
      exit(EXIT_SUCCESS);
    }

  /*** Batch playback mode ***/
  if(batchply) {
#ifdef HAVE_WCC_TIMER_H
    tmInit(poll_player,0xffff,DEFSTACK);
#elif defined HAVE_GCC_TIMER_H
    timer_init(poll_player);
#endif

    for(i = myoptind; i < argc; i++)
      if(!(p = CAdPlug::factory(argv[i],&opl))) {
	std::cout << "[" << argv[i] << "]: unsupported file type!" << std::endl;
#ifdef HAVE_WCC_TIMER_H
	tmClose();
#elif defined HAVE_GCC_TIMER_H
	timer_deinit();
#endif
	exit(EXIT_FAILURE);
      } else {
	dopoll = firsttime = true;
	std::cout << "Playing [" << argv[i] << "] ..." << std::endl;
	while(firsttime) ;	// busy waiting
	stop();
	dopoll = false;
      }

#ifdef HAVE_WCC_TIMER_H
    tmClose();
#elif defined HAVE_GCC_TIMER_H
    timer_deinit();
#endif
    exit(EXIT_SUCCESS);
  }

  /*** interactive (GUI) mode ***/
  getvideoinfo(&dosvideo);        // Save previous video state

  // register our windows with the window manager
  wnds.reg(titlebar); wnds.reg(filesel); wnds.reg(songwnd);
  wnds.reg(instwnd); wnds.reg(volbars); wnds.reg(mastervol);
  wnds.reg(infownd);

  // load default GUI layout
  validcfg = loadcolors(configfile,DEFCONFIG);

  // reparse commandline for GUI options
  myoptind = 1;     // reset option parser
  while((opt = getopt(argc,argv)))
    switch(opt) {
    case 5:	// set config file
      strcpy(configfile,argv[myoptind++]);
      if(loadcolors(configfile,DEFCONFIG))
	validcfg = true;
      break;
    case 6:	// load config section
      loadcolors(configfile,argv[myoptind++]);
      break;
    }

  // bail out if no configfile could be loaded
  if(!validcfg) {
    std::cout << "No valid default GUI layout could be loaded!" << std::endl;
    exit(EXIT_FAILURE);
  }

  // init GUI
  if((tmpfn = TEMPNAM(getenv("TEMP"),"_AP")))
#ifdef __WATCOMC__
    mkdir(tmpfn);
#else
  mkdir(tmpfn, S_IWUSR);
#endif
  prgdir = getcwd(NULL, PATH_MAX); _dos_getdrive(&prgdrive);
  setadplugvideo();
#ifdef HAVE_WCC_TIMER_H
  tmInit(poll_player,0xffff,DEFSTACK);
#elif defined HAVE_GCC_TIMER_H
  timer_init(poll_player);
#endif
  songwnd.setcaption("Song Info"); volbars.setcaption("VBars");
  titlebar.setcaption(ADPLAYVERS); filesel.setcaption("Directory");
  mastervol.setcaption("Vol"); filesel.refresh(); mastervol.set(63);
  display_help(infownd); filesel.setfocus(); reset_windows();

  // main loop
  do {
    if(p) {	// auto-update windows
      //                        wait_retrace();
      idle_ms(1000/70);
      refresh_songinfo(songwnd);
      refresh_volbars(volbars,opl);

      if(onsongend && !firsttime) {	// song ended
	switch(onsongend) {
	case 1:	// auto-rewind
	  dopoll = false; while(inpoll) ;	// critical section...
	  p->rewind(subsong);
	  last_ms = time_ms = 0.0f;
	  dopoll = true;	// ...End critical section
	  break;
	case 2:	// stop playback
	  stop();
	  reset_windows();
	  break;
	}
      }
    }

    // Check for keypress and read in, if any
    if(kbhit()) {
      if(!(inkey = toupper(getch()))) {
	ext = true;
	inkey = toupper(getch());
      } else
	ext = false;

      focus = CWindow::getfocus(); // cache focused window
      dbg_printf("main(): Key pressed: %d %s\n",
		 inkey, ext ? "(Ext)" : "(Norm)");
    } else
      inkey = 0;

    if(ext)	// handle all extended keys
      switch(inkey) {
      case 15:        // [Shift]+[TAB] - Back cycle windows
	window_cycle(true);
	break;
      case 59:	// [F1] - display help
	display_help(infownd);
	infownd.setfocus();
	wnds.update();
	break;
      case 60:	// [F2] - change screen layout
	curdir = getcwd(NULL, PATH_MAX);
	chdir(prgdir);
	select_colors();
	chdir(curdir);
	free(curdir);
	clearscreen(backcol);
	filesel.refresh();
	wnds.update();
	break;
      case 72:        // [Up Arrow] - scroll up
	if(focus == &filesel) {
	  filesel.select_prev();
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_up();
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_up();
	  instwnd.update();
	}
	break;
      case 80:        // [Down Arrow] - scroll down
	if(focus == &filesel) {
	  filesel.select_next();
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_down();
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_down();
	  instwnd.update();
	}
	break;
      case 75:	// [Left Arrow] - previous subsong
	if(p && subsong) {
	  subsong--;
	  dopoll = false; while(inpoll) ;	// critical section...
	  totaltime = p->songlength(subsong);
	  p->rewind(subsong);
	  last_ms = time_ms = 0.0f;
	  dopoll = true;	// ...End critical section
	}
	break;
      case 77:	// [Right Arrow] - next subsong
	if(p && subsong < p->getsubsongs()-1) {
	  subsong++;
	  dopoll = false; while(inpoll) ;	// critical section...
	  totaltime = p->songlength(subsong);
	  p->rewind(subsong);
	  last_ms = time_ms = 0.0f;
	  dopoll = true;	// ...End critical section
	}
	break;
      case 73:        // [Page Up] - scroll up half window
	if(focus == &filesel) {
	  filesel.select_prev(filesel.getsizey() / 2);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_up(infownd.getsizey() / 2);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_up(instwnd.getsizey() / 2);
	  instwnd.update();
	}
	break;
      case 81:        // [Page Down] - scroll down half window
	if(focus == &filesel) {
	  filesel.select_next(filesel.getsizey() / 2);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_down(infownd.getsizey() / 2);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_down(instwnd.getsizey() / 2);
	  instwnd.update();
	}
	break;
      case 71:        // [Home] - scroll to start
	if(focus == &filesel) {
	  filesel.setselection(0);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_set(0);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_set(0);
	  instwnd.update();
	}
	break;
      case 79:        // [End] - scroll to end
	if(focus == &filesel) {
	  filesel.setselection(0xffff);
	  filesel.update();
	} else if(focus == &infownd) {
	  infownd.scroll_set(0xffff);
	  infownd.update();
	} else if(focus == &instwnd) {
	  instwnd.scroll_set(0xffff);
	  instwnd.update();
	}
	break;
      }
    else		// handle all normal keys
      switch(inkey) {
      case 9:         // [TAB] - Cycle through windows
	window_cycle();
	break;
      case 13:        // [Return] - Activate
	if(focus == &filesel)
	  activate();
	break;
      case 27:        // [ESC] - Stop music / Exit to DOS
	if(p) {
	  stop();
	  reset_windows();
	} else
	  quit = true;
	break;
      case ' ':	// [Space] - fast forward
	fast_forward(FF_MSEC);
	break;
      case 'M':	// refresh song info
	refresh_songdesc(infownd);
	break;
      case 'D':	// shell to DOS
	dosshell(getenv("COMSPEC"));
	filesel.refresh(); wnds.update();
	break;
      case '+':       // [+] - Increase volume
	adjust_volume(-1);
	break;
      case '-':       // [-] - Decrease volume
	adjust_volume(+1);
	break;
      }
  } while(!quit);

  // deinit
#ifdef HAVE_WCC_TIMER_H
    tmClose();
#elif defined HAVE_GCC_TIMER_H
    timer_deinit();
#endif
  stop();
  setvideoinfo(&dosvideo);
  {
    unsigned int dummy;
    _dos_setdrive(prgdrive, &dummy);
  }
  chdir(prgdir);
  free(prgdir);
  if(tmpfn) { rmdir(tmpfn); free(tmpfn); }
#ifdef DEBUG
  dbg_printf("main(): clean shutdown.\n");
  fclose(f_log);
#endif
  return EXIT_SUCCESS;
}
コード例 #27
0
ファイル: os2.cpp プロジェクト: J0anJosep/OpenTTD
void FiosGetDrives(FileList &file_list)
{
    uint disk, disk2, save, total;

#ifndef __INNOTEK_LIBC__
    _dos_getdrive(&save); // save original drive
#else
    save = _getdrive(); // save original drive
    char wd[MAX_PATH];
    getcwd(wd, MAX_PATH);
    total = 'z';
#endif

    /* get an available drive letter */
#ifndef __INNOTEK_LIBC__
    for (disk = 1;; disk++) {
        _dos_setdrive(disk, &total);
#else
    for (disk = 'A';; disk++) {
        _chdrive(disk);
#endif
        if (disk >= total)  break;

#ifndef __INNOTEK_LIBC__
        _dos_getdrive(&disk2);
#else
        disk2 = _getdrive();
#endif

        if (disk == disk2) {
            FiosItem *fios = file_list.Append();
            fios->type = FIOS_TYPE_DRIVE;
            fios->mtime = 0;
#ifndef __INNOTEK_LIBC__
            snprintf(fios->name, lengthof(fios->name),  "%c:", 'A' + disk - 1);
#else
            snprintf(fios->name, lengthof(fios->name),  "%c:", disk);
#endif
            strecpy(fios->title, fios->name, lastof(fios->title));
        }
    }

    /* Restore the original drive */
#ifndef __INNOTEK_LIBC__
    _dos_setdrive(save, &total);
#else
    chdir(wd);
#endif
}

bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
{
#ifndef __INNOTEK_LIBC__
    struct diskfree_t free;
    char drive = path[0] - 'A' + 1;

    if (tot != NULL && _getdiskfree(drive, &free) == 0) {
        *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector;
        return true;
    }

    return false;
#else
    uint64 free = 0;

#ifdef HAS_STATVFS
    {
        struct statvfs s;

        if (statvfs(path, &s) != 0) return false;
        free = (uint64)s.f_frsize * s.f_bavail;
    }
#endif
    if (tot != NULL) *tot = free;
    return true;
#endif
}

bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
{
    char filename[MAX_PATH];

    snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
    return stat(filename, sb) == 0;
}
コード例 #28
0
ファイル: tuifs.c プロジェクト: AreaScout/vice
/* FIXME: documentation.  */
char *tui_file_selector(const char *title, const char *directory,
                        const char *pattern, const char *default_item,
                        read_contents_func_type contents_func,
                        char **browse_file_return,
                        unsigned int *browse_file_number_return)
{
    static char *return_path = NULL;
    struct file_list *fl;
    int curr_item, first_item, need_update;
    int x, y, width, height, num_cols, num_lines, field_width;
    int num_files;
    char str[0x100];
    int str_len = 0;
    tui_area_t backing_store = NULL;

    if (contents_func != NULL) {
        *browse_file_return = NULL;
    }

    if (browse_file_number_return != NULL) {
        *browse_file_number_return = 0;
    }

    if (directory != NULL) {
        return_path = lib_stralloc(directory);
    } else {
        return_path = ioutil_current_dir();
    }

    slashize_path(&return_path);

    fl = file_list_read(return_path, pattern);
    if (fl == NULL) {
        return NULL;
    }

    first_item = curr_item = 0;
    num_cols = 4;
    field_width = 18;
    num_lines = 17;
    height = num_lines + 2;
    width = field_width * num_cols + 4;
    num_files = num_cols * num_lines;

    if (default_item != NULL && *default_item) {
        int i;

        for (i = 0; i < fl->num_items; i++) {
            if (!strcasecmp(default_item, fl->items[i].name)) {
                curr_item = i;
                while (curr_item - first_item >= num_files) {
                    first_item += num_lines;
                }
                break;
            }
        }
    }

    x = CENTER_X(width);
    y = CENTER_Y(height);

    need_update = 1;

    tui_area_get(&backing_store, x, y, width + 2, height + 1);

    tui_display_window(x, y, width, height, MENU_BORDER, MENU_BACK, title, NULL);

    while (1) {
        int key;

        tui_set_attr(MENU_FORE, MENU_BACK, 0);
        if (need_update) {
            file_selector_display_path(return_path, x + 1, y + height - 1, width - 2);
            file_selector_update(fl, first_item, x + 2, y + 1, field_width, num_lines, num_cols);
            tui_set_attr(FIRST_LINE_FORE, FIRST_LINE_BACK, 0);
            tui_display(0, tui_num_lines() - 1, tui_num_cols(), "\030\031\033\032: Move  <Enter>: Select  %s<Alt>-<letter>: Change drive", contents_func != NULL ? "<Space>: Preview  " : "");
            need_update = 0;
        }
        tui_set_attr(MENU_FORE, MENU_HIGHLIGHT, 0);
        file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1, field_width, num_lines, num_cols);
        key = getkey();
        tui_set_attr(MENU_FORE, MENU_BACK, 0);
        file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1, field_width, num_lines, num_cols);

        switch (key) {
            case K_Escape:
                tui_area_put(backing_store, x, y);
                tui_area_free(backing_store);
                return NULL;
            case K_Left:
                str_len = 0;
                if (curr_item - num_lines >= 0) {
                    curr_item -= num_lines;
                    if (curr_item < first_item) {
                        if (first_item >= num_lines) {
                            first_item -= num_lines;
                            need_update = 1;
                        } else {
                            curr_item += num_lines;
                        }
                    }
                }
                break;
            case K_Up:
                str_len = 0;
                if (curr_item > 0) {
                    curr_item--;
                    if (curr_item < first_item) {
                        first_item = curr_item;
                        need_update = 1;
                    }
                }
                break;
            case K_Right:
                str_len = 0;
                if (curr_item + num_lines < fl->num_used_items) {
                    curr_item += num_lines;
                    if (curr_item - first_item >= num_files) {
                        first_item += num_lines;
                        need_update = 1;
                    }
                }
                break;
            case K_Down:
                str_len = 0;
                if (curr_item < fl->num_used_items - 1) {
                    curr_item++;
                    if (curr_item == first_item + num_files) {
                        first_item++;
                        need_update = 1;
                    }
                }
                break;
            case K_PageDown:
                str_len = 0;
                if (curr_item + num_files < fl->num_used_items) {
                    curr_item += num_files;
                    first_item += num_files;
                }
                need_update = 1;
                break;
            case K_PageUp:
                str_len = 0;
                if (curr_item - num_files >= 0) {
                    curr_item -= num_files;
                    first_item -= num_files;
                    if (first_item < 0) {
                        first_item = 0;
                    }
                    need_update = 1;
                }
                break;
            case K_Home:
                str_len = 0;
                curr_item = 0;
                if (first_item != 0) {
                    first_item = 0;
                    need_update = 1;
                }
                break;
            case K_End:
                str_len = 0;
                curr_item = fl->num_used_items - 1;
                first_item = curr_item - num_files + 1;
                if (first_item < 0) {
                    first_item = 0;
                }
                need_update = 1;
                break;
            case K_Return:
                str_len = 0;
                if (fl->items[curr_item].type == FT_DIR) {
                    struct file_list *new_fl;
                    char *new_path;

                    new_path = change_path(fl, return_path, curr_item);

                    new_fl = file_list_read(new_path, pattern);

                    if (new_fl != NULL) {
                        file_list_free(fl);
                        fl = new_fl;
                        first_item = curr_item = 0;
                        lib_free(return_path);
                        return_path = new_path;
                        need_update = 1;
                        ioutil_chdir(return_path);
                    } else {
                        lib_free(new_path);
                    }
                } else {
                    char *p = util_concat(return_path, fl->items[curr_item].name, NULL);

                    lib_free(return_path);
                    return_path = p;
                    tui_area_put(backing_store, x, y);
                    tui_area_free(backing_store);
                    return return_path;
                }
                break;
            case K_BackSpace:
                if (str_len > 1) {
                    int n;
                    str_len--;
                    n = file_list_find(fl, str, str_len);
                    if (n >= 0) {
                        curr_item = n;
                        if (curr_item < first_item) {
                            first_item = curr_item;
                            need_update = 1;
                        } else if (first_item + num_files <= curr_item) {
                            first_item = curr_item - num_files + 1;
                            need_update = 1;
                        }
                    }
                } else {
                    str_len = 0;
                    curr_item = 0;
                    if (first_item != 0) {
                        first_item = 0;
                        need_update = 1;
                    }
                }
                break;
            case ' ':
                if (contents_func != NULL && fl->items[curr_item].type != FT_DIR && browse_file_return != NULL) {
                    tui_display(0, tui_num_lines() - 1, tui_num_cols(), "");
                    *browse_file_return = tui_image_browser(fl->items[curr_item].name, contents_func, browse_file_number_return);
                    if (*browse_file_return != NULL) {
                        char *p = util_concat(return_path, fl->items[curr_item].name, NULL);

                        lib_free(return_path);
                        return_path = p;
                        tui_area_put(backing_store, x, y);
                        tui_area_free(backing_store);
                        return return_path;
                    }
                    need_update = 1;
                    break;
                } else {
                    tui_beep();
                }
            default:
                {
                    int drive_num;

                    drive_num = alt_key_to_drive_num(key);

                    if (drive_num > 0) {
                        /* `A-a' ... `A-z' change the current drive.  */
                        int num_available_drives;
                        int current_drive;

                        _dos_getdrive(&current_drive);
                        _dos_setdrive(current_drive, &num_available_drives);
                        if (drive_num <= num_available_drives) {
                            char *new_path;

                            /* FIXME: This is a hack...  Maybe there is a cleaner
                               way to do it, but for now I just don't know.  */
                            _dos_setdrive(drive_num, &num_available_drives);
                            new_path = ioutil_current_dir();
                            if (new_path != NULL) {
                                slashize_path(&new_path);
                                _dos_setdrive(current_drive, &num_available_drives);
                                if (new_path != NULL) {
                                    struct file_list *new_fl;

                                    new_fl = file_list_read(new_path, pattern);
                                    if (new_fl != NULL) {
                                        file_list_free(fl);
                                        fl = new_fl;
                                        first_item = curr_item = 0;
                                        lib_free(return_path);
                                        return_path = new_path;
                                        need_update = 1;
                                        ioutil_chdir(return_path);
                                    } else {
                                        lib_free(new_path);
                                    }
                                }
                            } else {
                                _dos_setdrive(current_drive, &num_available_drives);
                                tui_beep();
                            }
                        } else {
                            tui_beep();
                        }
                    } else if (isprint(key) && str_len < 0x100) {
                        int n;

                        str[str_len] = key;
                        n = file_list_find(fl, str, str_len + 1);
                        if (n < 0) {
                            tui_beep();
                        } else {
                            str_len++;
                            curr_item = n;
                            if (curr_item < first_item) {
                                first_item = curr_item;
                                need_update = 1;
                            } else if (first_item + num_files <= curr_item) {
                                first_item = curr_item - num_files + 1;
                                need_update = 1;
                            }
                        }
                    }
                }
                break;
        }
    }
}
コード例 #29
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);
}