Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
LONG DiskType(CHAR *dst)
 {
  ULONG type=NO_DRIVE;
  SHORT disk;
  unsigned ulCurDisk,totaldrives;
  //UCHAR j,len,*vol_ptr;
  //struct ffblk ffblk;

  //CountHDD=peekb(0x0040,0x0075);
//  type
//IDI_FLOPPY_12
//IDI_FLOPPY_144;
//IDI_LOCAL1;
//IDI_CD
//IDI_NET_ON
  ulCurDisk=_getdrive();
  if((dst[1]==':')&&(strlen(dst)<=3)&&((dst[2]==0)||(dst[2]=='\\')))
   {
    disk=(CHAR)(toupper(dst[0])-'A');
    if((disk==0)||(disk==1)) //a или б
     {
      if(GetDriveType((BYTE)disk))
       //if(CheckForRemote((BYTE)disk))
         type=IDI_FLOPPY_144;//Disk[i]|=DISK_REMOTE;
     }
    else
     {
      _dos_setdrive(disk+1,&totaldrives);
      if(_getdrive()==(disk+1))
       {
        type=IDI_LOCAL1;//DISK_HDD;
        if(CheckForRemote((BYTE)disk))
         type=IDI_NET_ON;//DISK_REMOTE;
       }
      //if(Disk[i]&DISK_HDD&&!findfirst("*.*",&ffblk,FA_LABEL))
      // {
      //  vol_ptr=VolumeLabel[i-2];
      //  len=strlen(ffblk.ff_name);
      //  for(j=0;j<=len;j++)
      //  if(*(ffblk.ff_name+j)!='.')
      //   {
      //    *vol_ptr=*(ffblk.ff_name+j);
      //    vol_ptr++;
      //   }
      // }
      //else *VolumeLabel[i-2]=0;
     }
   }
  else type=IDI_FOLD_CLOSE;

  _dos_setdrive(ulCurDisk,&totaldrives);
  return type;
 }
Ejemplo n.º 3
0
/*
 * 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 */
Ejemplo n.º 4
0
 drive_t setdisk(drive_t drive)
 {
       drive_t max_drives;

       _dos_setdrive(drive + 1, &max_drives);
       return max_drives - 1;
 }
Ejemplo n.º 5
0
static void set_path(char *p)
{
  unsigned old;
  if (!p[0]) return;
  if (p[1]==':') _dos_setdrive((p[0]|0x20)-'a'+1,&old);
  chdir(p);
}
/*--------------------------------------------------------------------------*

Name            setdisk - sets current drive

Usage           int setdisk(int drive);

Prototype in    dir.h

Description     sets the current drive.
                0 = A:, 1 = B:, 2 = C:; etc.

Return value    the total number of drives available.

*---------------------------------------------------------------------------*/
int setdisk(int drive)
{
    unsigned ndrives;

    _dos_setdrive(drive+1,&ndrives);
    return ((int)ndrives);
}
Ejemplo n.º 7
0
void main (void)
 {
   unsigned drive_count;

   _dos_setdrive(3, &drive_count);
   printf("The number of available drives is %d\n", 
     drive_count);
 }
Ejemplo n.º 8
0
error_handle LocalSetDrv( int drv )
/*********************************/
{
    unsigned    total;

    _dos_setdrive( drv - 1, &total );
    return( 0 );
}
Ejemplo n.º 9
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 );
}
Ejemplo n.º 10
0
/*
 * goToDir - go to a specified directory
 */
static bool goToDir( gui_window *gui, char *dir )
{
    char        drive[_MAX_DRIVE];
    unsigned    total;
    bool        removed_end;
    size_t      len;
    int         rc;

    gui = gui;
    if( dir == NULL ) {
        return( false );
    }

    if( dir[0] == 0 ) {
        return( true );
    }

    if( !(dir[1] == ':' && dir[2] == 0) ) {
        len = strlen( dir );
        removed_end = false;
        if( dir[len - 1] == FILE_SEP_CHAR ) {
            if( len > 1 && dir[len - 2] != ':' ) {
                dir[len - 1] = 0;
                removed_end = true;
            }
        }

#ifdef __OS2__
        /* prevent hard error popup */
        DosError( 1 );
#endif
        rc = chdir( dir );
#ifdef __OS2__
        /* allow hard error popup: Grrr can't restore to original state */
        DosError( 0 );
#endif
        if( removed_end ) {
            dir[len - 1] = FILE_SEP_CHAR;
        }
        if( rc ) {
            return( false );
        }
    }

    splitPath( dir, drive, NULL, NULL, NULL );
    if( drive[0] != 0 ) {
#if defined( __UNIX__ ) || defined( __NETWARE__ )
        total = 1;
#else
        _dos_setdrive( toupper( drive[0] ) - 'A' + 1, &total );
#endif
    }
    return( true );

} /* goToDir */
Ejemplo n.º 11
0
/*
 * PopDirectory
 */
void PopDirectory( void )
{
    unsigned    total;

    if( oldPath[0] != 0 ) {
        ChangeDirectory( oldPath );
    }
    _dos_setdrive( oldDrive, &total );
    ChangeDirectory( CurrentDirectory );

} /* PopDirectory */
Ejemplo n.º 12
0
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  
}
Ejemplo n.º 13
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
}
Ejemplo n.º 14
0
bool WEXPORT WFileName::makeDir() const
{
    splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext, PATHSEP_STR );
    if( strlen( _x.dir ) > 0 ) {
        unsigned olddrive;
        if( setdrive( _x.drive, &olddrive ) ) {
            int ret = mkdir( _x.dir );
            unsigned total;
            _dos_setdrive( olddrive, &total );
            return( ret == 0 );
        }
        return( false );
    }
    return( true );
}
Ejemplo n.º 15
0
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 );
}
Ejemplo n.º 16
0
/*
 * 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 */
Ejemplo n.º 17
0
/******************************************************************************
 *
 *          szFName:   c_break
 *      Synopsis:   void cbreak(void);
 *
 *   Description:   Control Break interrupt handler
 *
 *****************************************************************************/
void c_break(int c)
{
   unsigned int iTemp;

#ifndef _WINDOWS
   if (fSwitches & LOG)
      unassign();
#endif

   chdir(curdir);
   _dos_setdrive(usFirstDisk, &iTemp);

   if (chdir(szOriginalPath))
      DisplayMessage(IDS_CANTCHANGEDIRECTORY, szOriginalPath);

   exit(3);
}
Ejemplo n.º 18
0
bool WEXPORT WFileName::setCWD() const
{
    splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext, PATHSEP_STR );
    unsigned olddrive;
    if( setdrive( _x.drive, &olddrive ) ) {
        if( strlen( _x.dir ) > 0 ) {
            int ret = chdir( _x.dir );
            if( ret == 0 ) {
                return TRUE;
            }
            unsigned total;
            _dos_setdrive( olddrive, &total );
            return FALSE;
        }
        return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 19
0
int _RTL_FUNC         setdisk( int __drive )
{
    int nd ;
    return _dos_setdrive(__drive,&nd);
}
Ejemplo n.º 20
0
void GetProg( char *cmd, char *eoc )
{
    char        save;
    char        prog_name[_MAX_PATH];
    char        buff1[_MAX_PATH2];
    char        buff2[_MAX_PATH2];
    char        *drive;
    char        *dir;
    char        *fname;
    char        *ext;
    char        *sfname;
#ifdef __WINDOWS__
    unsigned    a,b;
    char        **drivep;
    char        **dirp;
    char        buff3[_MAX_DRIVE+MAX_PATH+5];
#endif

    save = *eoc;
    *eoc = '\0';
    _splitpath2( (char *)cmd, (char *)buff1,
        (char **)&drive, (char **)&dir, (char **)&fname, (char **)&ext );
    *eoc = save;
#ifdef __NETWARE__
    if( ext[0] == '\0' )
        ext = ".nlm";
#elif defined( __DOS__ ) && defined( _PLS )
    if( ext[0] == '\0' )
        ext = ".exp";
#elif !defined( __UNIX__ )
    if( ext[0] == '\0' )
        ext = ".exe";
#endif
    _makepath( (char *)prog_name, (char *)drive, (char *)dir, (char *)fname, (char *)ext );

    if( drive[0] == '\0' && dir[0] == '\0' ) {
        _searchenv( (char *)prog_name, "PATH", ExeName );
    } else if( access( (char *)prog_name, R_OK ) == 0 ) {
        strcpy( ExeName, (char *)prog_name );
    }

    if( ExeName[0] == '\0' ) {
        Output( MsgArray[MSG_PROGRAM - ERR_FIRST_MESSAGE] );
        Output( (char *)prog_name );
        Output( "\r\n" );
        fatal();
    }

#ifdef __WINDOWS__
    /*
     * for windows, we need to make our current directory the
     * same as that for the EXE, since windows moves our current directory
     * to that of the sampler
     */
    _splitpath2( ExeName, buff2, &drive, &dir, NULL, NULL );
    a = tolower( drive[0] ) - 'a' + 1;
    _dos_setdrive( a, &b );
    dir[strlen( dir ) - 1] = '\0';
    chdir( dir );
#endif

    _splitpath2( SampName, (char *)buff2,
        (char **)&drive, (char **)&dir, (char **)&sfname, (char **)&ext );

    /*
     * for windows, we need to give the sample file an absolute
     * path name so that both threads of the sampler can write
     * to the sample file
     */
#ifdef __WINDOWS__
    drivep = (drive[0] == '\0') ? &drive : NULL;
    dirp   = (dir[0]   == '\0') ? &dir   : NULL;
    if( drivep != NULL || dirp != NULL ) {
        _splitpath2( ExeName, buff3, drivep, dirp, NULL, NULL );
    }
#endif

    _makepath( SampName, (char *)drive, (char *)dir, (char *)(sfname[0] == '\0' ? fname : sfname),
               ext[0] == '\0' ? (char *)"smp" : (char *)ext );

#ifdef __WINDOWS__
    _fstrcpy( SharedMemory->SampName, SampName );
#endif
}
Ejemplo n.º 21
0
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;
}
Ejemplo n.º 22
0
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 */
Ejemplo n.º 23
0
/*
 * AccLoadProg
 *
 * To load a app, we do the following:
 *
 *  Case 1: debugging an existing task
 *      - Find its current CS:IP.
 *      - Plant a breakpoint at the current CS:IP
 *
 *  Case 2: starting a task from scratch
 *      - Look up the start address from the .EXE
 *      - WinExec the app
 *      - Wait for the STARTASK notification for the app
 *      - Plant a breakpoint at its start address
 *
 *  - Wait for the app to hit the breakpoint
 *  - Check if the app is a 32-bit app (look for "DEADBEEF" in code seg).
 *     If it is a 32-bit app:
 *      - Flip the "DEADBEEF" to "BEEFDEAD".  If the extender see's the
 *        "BEEFDEAD", it executes a breakpoint right before it jumps to
 *        the 32-bit code
 *      - Let the app run until a breakpoint is hit
 *      - Trace one instruction. This leaves you at the first instruction
 *        of the 32-bit code
 */
unsigned ReqProg_load( void )
{
    char                exe_name[_MAX_PATH];
    char                drive[_MAX_DRIVE],directory[_MAX_DIR];
    char                buff[256];
    lm_parms            loadp;
    word_struct         cmdshow;
    char                *parm;
    char                *src;
    char                *dst;
    char                ch;
    unsigned            a,b;
    private_msg         pmsg;
    char                sig[sizeof(DWORD)];
    HTASK               tid;
    DWORD               csip;
    prog_load_req       *acc;
    prog_load_ret       *ret;
    char                *end;

    acc = GetInPtr( 0 );
    ret = GetOutPtr( 0 );
    ret->flags = LD_FLAG_IS_PROT | LD_FLAG_HAVE_RUNTIME_DLLS;
    parm = GetInPtr( sizeof( *acc ) );

    /*
     * reset flags
     */
    OutPos = 0;
    WasStarted = FALSE;
    LoadingDebugee = TRUE;
    Debugging32BitApp = FALSE;
    AddAllCurrentModules();

    /*
     * check for task id
     */
    tid = 0;
    src = parm;
    if( *src == '#' ) {
        src++;
        tid = (HTASK)strtol( src, NULL, 16 );
    } else {
        while( *src != 0 ) {
            if( !isdigit( *src ) ) {
                break;
            }
            src++;
        }
        if( *src == 0 && src != parm ) {
            tid = (HTASK)atoi( parm );
        }
    }
    if( tid != 0 ) {
        csip = GetRealCSIP( tid, &DebugeeModule );
        if( csip == 0 ) {
            tid = 0;
        } else {
            DebugeeTask = tid;
            StopNewTask.loc.segment = FP_SEG( (LPVOID) csip );
            StopNewTask.loc.offset = FP_OFF( (LPVOID) csip );
            ReadMem( StopNewTask.loc.segment, StopNewTask.loc.offset,
                    &StopNewTask.value, 1 );
            ch = 0xcc;
            WriteMem( StopNewTask.loc.segment, StopNewTask.loc.offset, &ch, 1 );
        }
    } else {
        tid = 0;
    }

    /*
     * get the file to execute
     */
    if( tid == 0 ) {
        if( TINY_ERROR( FindFilePath( parm, exe_name, ExtensionList ) ) ) {
            exe_name[0] = 0;
        } else {
            _splitpath( exe_name, drive, directory, NULL, NULL );
            a = tolower( drive[0] ) - 'a' + 1;
            _dos_setdrive( a, &b );
            directory[ strlen( directory ) - 1 ] = 0;
            chdir( directory );
        }

        /*
         * get the parm list
         */

        src = parm;
        while( *src != 0 )
            ++src;
        ++src;
        end = GetInPtr( GetTotalSize() - 1 );
        dst = &buff[1];
        for( ;; ) {
            if( src > end )
                break;
            ch = *src;
            if( ch == 0 )
                ch = ' ';
            *dst = ch;
            ++dst;
            ++src;
        }
        if( dst > &buff[1] )
            --dst;
        *dst = '\0';
        buff[0] = dst-buff-1;

        /*
         * get starting point in task
         */
        if( !GetStartAddress( exe_name, &StopNewTask.loc ) ) {
            Out((OUT_ERR,"Could not get starting address"));
            ret->err = WINERR_NOSTART;
            LoadingDebugee = FALSE;
            return( sizeof( *ret ) );
        }
        StopNewTask.segment_number = StopNewTask.loc.segment;
        Out((OUT_LOAD,"Loading %s, cs:ip = %04x:%04lx", exe_name, StopNewTask.loc.segment,
                            StopNewTask.loc.offset ));

        /*
         * load the task
         */
        loadp.cmdshow = &cmdshow;
        loadp.wEnvSeg = 0;
        loadp.lpCmdLine = (LPSTR) buff;
        loadp.cmdshow->mustbe2 = 2;
        loadp.cmdshow->cmdshow = SW_NORMAL;
        loadp.reserved = 0L;
        DebuggerState = LOADING_DEBUGEE;
        DebugeeInstance = LoadModule( exe_name, (LPVOID) &loadp );
        if( (UINT)DebugeeInstance < 32 ) {
            Out((OUT_ERR,"Debugee did not load %d", DebugeeInstance));
            ret->err = WINERR_NOLOAD;
            LoadingDebugee = FALSE;
            return( sizeof( *ret ) );
        }
        DebuggerWaitForMessage( WAITING_FOR_TASK_LOAD, NULL, RESTART_APP );
    }
    AddDebugeeModule();
    pmsg = DebuggerWaitForMessage( WAITING_FOR_BREAKPOINT, DebugeeTask, RESTART_APP );
    if( pmsg == START_BP_HIT ) {

        ret->err = 0;
        ret->task_id = (unsigned_32)DebugeeTask;

        /*
         * look for 32-bit windows application
         */
        ReadMem( IntResult.CS, SIG_OFF, sig, sizeof( DWORD ) );
        if( !StopOnExtender && (!memcmp( sig, win386sig, 4 ) ||
                !memcmp( sig, win386sig2, 4 )) ) {
            Out((OUT_LOAD,"Is Win32App" ));
            Debugging32BitApp = TRUE;
            /*
             * make sure that WDEBUG.386 is installed
             */
            if( !WDebug386 ) {
                ret->err = WINERR_NODEBUG32; /* Can't debug 32 bit app */
                LoadingDebugee = FALSE;
                return( sizeof( *ret ) );
            }
            ret->flags |= LD_FLAG_IS_32;
            if( tid == 0 ) {
                WriteMem( IntResult.CS, SIG_OFF, win386sig2, sizeof( DWORD ) );
                pmsg = DebuggerWaitForMessage( GOING_TO_32BIT_START,
                                DebugeeTask, RESTART_APP );
                if( pmsg == FAULT_HIT && IntResult.InterruptNumber == INT_3 ) {
                    IntResult.EIP++;
                    SingleStepMode();
                    pmsg = DebuggerWaitForMessage( GOING_TO_32BIT_START,
                                DebugeeTask, RESTART_APP );
                    if( pmsg != FAULT_HIT || IntResult.InterruptNumber != INT_1 ) {
                        Out((OUT_ERR,"Expected INT_1 not found"));
                        ret->err = WINERR_NOINT1;
                    }
                } else {
                    Out((OUT_ERR,"Expected INT_3 not found"));
                    ret->err = WINERR_NOINT3;
                }
            }
        }
        if( tid != 0 ) {
            ret->flags |= LD_FLAG_IS_STARTED;
            WasStarted = TRUE;
        }
    } else {
        Out((OUT_ERR,"Starting breakpoint not found, pmsg=%d", pmsg ));
        ret->err = WINERR_STARTNOTFOUND;
    }
#if 0
    if( DebugeeTask != NULL ) {
        InitASynchHook();
    }
#endif
    LoadingDebugee = FALSE;
    CurrentModule = 1;
    ret->mod_handle = 0;
    return( sizeof( *ret ) );
}
Ejemplo n.º 24
0
static unsigned long DriverList(HWND Window,HMSG Message,long Param1,long Param2)
{
  switch (Message)
  {
    case WINDOWINIT:
         {
           unsigned save,disk,total,UnusedDisk;
           char diskn[3];
           char *dri=diskn;

           diskn[1] = ':';
           diskn[2] = '\0';

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

               /* save original drive */
           save = getdisk();
//           diskn[0] = save+'A';
           diskn[0] = save+'A'-1;
//           _harderr(handler);
           MessageGo(Window,SETLINEBUFFER,FP2LONG(dri),0L);
           MessageGo(Window,LISTDELETEALL,0L,0L);

       /*------------
           for (disk = 1;disk < 26;++disk) {
                 setdisk(disk);
                 if (disk == getdisk()) {
                      setdisk(save);
       ------------*/

           disk = 1;            // from diskette A:
           UnusedDisk=0;
           {                         // ByHance, for diskette error
                 char *p=(char *)0x410;           // equipment list
                 total=*p;
                 if(total&1) {          // diskette present, count how many
                    total=(total>>6)&0x3;
                    if(!total) UnusedDisk=2;    // if only 1, can not use B:
                 } else disk=3;         // no diskette present, so, from C:
           }
           for (; disk<26; ++disk) {
                 if(disk==UnusedDisk) continue;
                 _dos_setdrive(disk,&total);
                 if (disk == getdisk()) {
                      _dos_setdrive(save,&total);
                      if(first && disk==save) {           // ByHance
                          HWND MidWindow=ComboFindListBox(Window);
                          if (MidWindow)
                               ListSetCurrent(WindowList(MidWindow),
                                        ListGetTotal(WindowList(MidWindow)) );
                          first=0;
                      }
                      diskn[0] = disk+'A'-1;
                      MessageGo(Window,LISTAPPENDITEM,FP2LONG(dri),0L);
                 }
           }

       /*---------
           setdisk(save);
           diskn[0] = save+'A';
        ----------*/
           _dos_setdrive(save,&total);
           diskn[0] = save+'A'-1;

           strcpy(NowOpenFile->drive,diskn);
         }
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
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);
}
Ejemplo n.º 27
0
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 */
Ejemplo n.º 28
0
//*****************************************************************************
//
// 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);
}
Ejemplo n.º 29
0
static BOOL _getOpt(int argc, char **argv)
{
  int                  iOpt;
  CHAR                 acBuf[_MAX_PATH];
  PSZ                  pszDrv, pszDir, pszFile, pszExt;
  unsigned int         uiTotal;
  PSZ                  pszReq[32];
  ULONG                cReq = 0;
  BOOL                 fVerifyConfig = FALSE;

  _splitpath2( argv[0], &acBuf, &pszDrv, &pszDir, &pszFile, &pszExt );

  if ( pszDrv != NULL )
    _dos_setdrive( pszDrv[0] - 'A' + 1, &uiTotal );

  if ( pszDir != NULL )
  {
    uiTotal = strlen( pszDir );
    pszDir[uiTotal - 1] = '\0';

    if ( chdir( pszDir ) != 0 )
      debug( "chdir() for %s failed", pszDir );
  }

  opterr = 0;
  while( ( iOpt = getopt( argc, argv, "c:vr:h?" ) ) != -1 )
  { 
    switch( iOpt )
    { 
      case 'c':
        pszCfgFile = optarg;
        break; 

      case 'v':
        fVerifyConfig = TRUE;
        break;

      case 'r':
        if ( cReq < ARRAY_SIZE( pszReq ) )
        {
          pszReq[cReq] = optarg;
          cReq++;
        }
        break;

      case ':': 
      case '?':
      case 'h':
        printf( "Usage: %s%s [options]\nOptions:\n"
                "  -h, -?         Show this help.\n"
                "  -c <file>      Use given configuration file instead of "
                _DEF_CONFIG_FILE".\n"
                "  -v             Verify configuration file and exit.\n"
                "  -r <request>   Parse configuration file, then send query "
                "to running copy\n"
                "                 and exit. For example: -r reconfigure, -r "
                "\"shutdown\"\n"
                "                 It can be specified multiple times.",
                pszFile, pszExt );
        return FALSE;
    }
  }

  if ( !cfgInit( pszCfgFile ) )
    return FALSE;

  if ( fVerifyConfig )
  {
    cfgDone();

    if ( uiTotal )
    {
      printf( "Configuration has been verified: %s", pszCfgFile );
      xplDone();
      debugDone();
      exit( 0 );
    }
    return FALSE;
  }

  if ( cReq != 0 )
  {
    ifsockRequest( cReq, &pszReq );
    cfgDone();
    xplDone();
    exit( 0 );
  }

  return TRUE;
}
Ejemplo n.º 30
0
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;
}