static USHORT _FillDirLb(HWND hDlg, ULONG CurDrive) { CHAR Path[CCHMAXPATH]; ULONG PathLen, NrOfFiles; APIRET rc; FILEFINDBUF3 FileInfo; HDIR hDir; WinSendDlgItemMsg(hDlg, LID_CD_DIRS, LM_DELETEALL, 0L, 0L); WinSendDlgItemMsg(hDlg, LID_SELECT_FILE_FILES, LM_DELETEALL, 0L, 0L); PathLen = CCHMAXPATH; if (DosQCurDir(CurDrive, (PUCHAR)Path, &PathLen)) return (1); if (strlen(Path) == 0) sprintf(TfText, "%c:\\*.*", (CHAR) (CurDrive + 64)); else sprintf(TfText, "%c:\\%s\\*.*", (CHAR) (CurDrive + 64), Path); _ShowTextField(hDlg); NrOfFiles = 1; hDir = HDIR_CREATE; rc = DosFindFirst2(TfText, &hDir, FILE_DIRECTORY | FILE_HIDDEN, &FileInfo, sizeof(FILEFINDBUF3), &NrOfFiles, FIL_STANDARD); while (!rc) { if (FileInfo.attrFile & FILE_DIRECTORY) { if (strlen(TfText) != 6 && strcmp(FileInfo.achName, ".") == 0) sprintf(FileInfo.achName, " <root %c:>", (CHAR) (CurDrive + 64)); if (strlen(TfText) != 6 || FileInfo.achName[0] != '.') { WinSendDlgItemMsg(hDlg, LID_CD_DIRS, LM_INSERTITEM, MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(FileInfo.achName)); } } NrOfFiles = 1; rc = DosFindNext(hDir, &FileInfo, sizeof(FILEFINDBUF3), &NrOfFiles); } DosFindClose(hDir); if (rc != ERROR_NO_MORE_FILES) return (1); return (0); }
unsigned LocalGetCwd( int drive, char *where ) /****************************************/ { USHORT len; len = 256; return( StashErrCode( DosQCurDir( drive, where, &len ), OP_LOCAL ) ); }
_WCRTLINK CHAR_TYPE *__F_NAME(getcwd,_wgetcwd)( CHAR_TYPE *buf, size_t size ) { APIRET error; ULONG drive_map; #ifndef __WIDECHAR__ char path[_MAX_PATH]; /* single-byte chars */ OS_UINT pathlen = _MAX_PATH - 3; #else char path[MB_CUR_MAX*_MAX_PATH]; /* multi-byte chars */ OS_UINT pathlen = MB_CUR_MAX * _MAX_PATH - 3; #endif OS_UINT drive; error = DosQCurDir( 0, &path[3], &pathlen ); if( error ) { __set_errno_dos( error ); return( NULL ); } DosQCurDisk( &drive, &drive_map ); path[ 0 ] = drive + 'A' - 1; path[ 1 ] = ':'; path[ 2 ] = '\\'; if( buf == NULL ) { if( (buf = malloc( max(size,pathlen+4)*CHARSIZE )) == NULL ) { __set_errno( ENOMEM ); return( NULL ); } size = pathlen + 3; } /*** Copy the pathname into a buffer and quit ***/ #ifndef __WIDECHAR__ return( strncpy( buf, path, size ) ); #else if( mbstowcs( buf, path, size ) != (size_t)-1 ) return( buf ); else return( NULL ); #endif }
_WCRTLINK CHAR_TYPE *__F_NAME(_sys_fullpath,_sys_wfullpath) ( CHAR_TYPE *buff, const CHAR_TYPE *path, size_t size ) /*********************************************************************/ { #if defined(__NT__) CHAR_TYPE *filepart; DWORD rc; if( __F_NAME(stricmp,_wcsicmp)( path, STRING( "con" ) ) == 0 ) { _WILL_FIT( 3 ); return( __F_NAME(strcpy,wcscpy)( buff, STRING( "con" ) ) ); } /*** Get the full pathname ***/ rc = __lib_GetFullPathName( path, size, buff, &filepart ); // If the buffer is too small, the return value is the size of // the buffer, in TCHARs, required to hold the path. // If the function fails, the return value is zero. To get extended error // information, call GetLastError. if( ( rc == 0 ) || ( rc > size ) ) { __set_errno_nt(); return( NULL ); } return( buff ); #elif defined(__WARP__) APIRET rc; char root[ 4 ]; /* SBCS: room for drive, ':', '\\', and null */ #ifdef __WIDECHAR__ char mbBuff[ _MAX_PATH * MB_CUR_MAX ]; char mbPath[ _MAX_PATH * MB_CUR_MAX ]; #endif if( __F_NAME(isalpha,iswalpha)( path[ 0 ] ) && ( path[ 1 ] == STRING( ':' ) ) && ( path[ 2 ] == STRING( '\\' ) ) ) { int i; i = __F_NAME(strlen,wcslen)( path ); _WILL_FIT( i ); __F_NAME(strcpy,wcscpy)( buff, path ); return( buff ); } /* * Check for x:filename.ext when drive x doesn't exist. In this * case, return x:\filename.ext, not NULL, to be consistent with * MS and with the NT version of _fullpath. */ if( __F_NAME(isalpha,iswalpha)( path[ 0 ] ) && path[ 1 ] == STRING( ':' ) ) { /*** We got this far, so path can't start with letter:\ ***/ root[ 0 ] = (char)path[ 0 ]; root[ 1 ] = ':'; root[ 2 ] = '\\'; root[ 3 ] = '\0'; rc = DosQueryPathInfo( root, FIL_QUERYFULLNAME, buff, size ); if( rc != NO_ERROR ) { /*** Drive does not exist; return x:\filename.ext ***/ _WILL_FIT( __F_NAME(strlen,wcslen)( &path[ 2 ] ) + 3 ); buff[ 0 ] = root[ 0 ]; buff[ 1 ] = STRING( ':' ); buff[ 2 ] = STRING( '\\' ); __F_NAME(strcpy,wcscpy)( &buff[ 3 ], &path[ 2 ] ); return( buff ); } } #ifdef __WIDECHAR__ if( wcstombs( mbPath, path, sizeof( mbPath ) ) == (size_t)-1 ) { return( NULL ); } rc = DosQueryPathInfo( (PSZ)mbPath, FIL_QUERYFULLNAME, mbBuff, sizeof( mbBuff ) ); #else rc = DosQueryPathInfo( (PSZ)path, FIL_QUERYFULLNAME, buff, size ); #endif if( rc != 0 ) { __set_errno_dos( rc ); return( NULL ); } #ifdef __WIDECHAR__ if( mbstowcs( buff, mbBuff, size ) != (size_t)-1 ) { return( buff ); } else { return( NULL ); } #else return( buff ); #endif #elif defined(__QNX__) || defined( __NETWARE__ ) size_t len; char temp_dir[ _MAX_PATH ]; #if defined(__NETWARE__) if( ConvertNameToFullPath( path, temp_dir ) != 0 ) { return( NULL ); } #else if( __qnx_fullpath( temp_dir, path ) == NULL ) { return( NULL ); } #endif len = strlen( temp_dir ); if( len >= size ) { __set_errno( ERANGE ); return( NULL ); } return( strcpy( buff, temp_dir ) ); #elif defined(__UNIX__) const char *p; char *q; size_t len; char curr_dir[ _MAX_PATH ]; p = path; q = buff; if( ! _IS_SLASH( p[ 0 ] ) ) { if( getcwd( curr_dir, sizeof( curr_dir ) ) == NULL ) { __set_errno( ENOENT ); return( NULL ); } len = strlen( curr_dir ); _WILL_FIT( len ); strcpy( q, curr_dir ); q += len; if( q[ -1 ] != '/' ) { _WILL_FIT( 1 ); *(q++) = '/'; } for( ;; ) { if( p[ 0 ] == '\0' ) break; if( p[ 0 ] != '.' ) { _WILL_FIT( 1 ); *(q++) = *(p++); continue; } ++p; if( _IS_SLASH( p[ 0 ] ) ) { /* ignore "./" in directory specs */ if( ! _IS_SLASH( q[ -1 ] ) ) { *q++ = '/'; } ++p; continue; } if( p[ 0 ] == '\0' ) break; if( p[ 0 ] == '.' && _IS_SLASH( p[ 1 ] ) ) { /* go up a directory for a "../" */ p += 2; if( ! _IS_SLASH( q[ -1 ] ) ) { return( NULL ); } q -= 2; for( ;; ) { if( q < buff ) { return( NULL ); } if( _IS_SLASH( *q ) ) break; --q; } ++q; *q = '\0'; continue; } _WILL_FIT( 1 ); *(q++) = '.'; } *q = '\0'; } else { len = strlen( p ); _WILL_FIT( len ); strcpy( q, p ); } return( buff ); #else const CHAR_TYPE *p; CHAR_TYPE *q; size_t len; int path_drive_idx; char curr_dir[ _MAX_PATH ]; p = path; q = buff; _WILL_FIT( 2 ); if( __F_NAME(isalpha,iswalpha)( p[ 0 ] ) && p[ 1 ] == STRING( ':' ) ) { path_drive_idx = ( __F_NAME(tolower,towlower)( p[ 0 ] ) - STRING( 'a' ) ) + 1; q[ 0 ] = p[ 0 ]; q[ 1 ] = p[ 1 ]; p += 2; } else { #if defined(__OS2__) ULONG drive_map; OS_UINT os2_drive; if( DosQCurDisk( &os2_drive, &drive_map ) ) { __set_errno( ENOENT ); return( NULL ); } path_drive_idx = os2_drive; #else path_drive_idx = TinyGetCurrDrive() + 1; #endif q[ 0 ] = STRING( 'A' ) + ( path_drive_idx - 1 ); q[ 1 ] = STRING( ':' ); } q += 2; if( ! _IS_SLASH( p[ 0 ] ) ) { #if defined(__OS2__) OS_UINT dir_len = sizeof( curr_dir ); if( DosQCurDir( path_drive_idx, curr_dir, &dir_len ) ) { __set_errno( ENOENT ); return( NULL ); } #else if( __getdcwd( curr_dir, path_drive_idx ) ) { __set_errno( ENOENT ); return( NULL ); } #endif len = strlen( curr_dir ); if( curr_dir[ 0 ] != '\\' ) { _WILL_FIT( 1 ); *(q++) = STRING( '\\' ); } _WILL_FIT( len ); #ifdef __WIDECHAR__ if( mbstowcs( q, curr_dir, len + 1 ) == (size_t)-1 ) { return( NULL ); } #else strcpy( q, curr_dir ); #endif q += len; if( q[ -1 ] != STRING( '\\' ) ) { _WILL_FIT( 1 ); *(q++) = STRING( '\\' ); } for( ;; ) { if( p[ 0 ] == NULLCHAR ) break; if( p[ 0 ] != STRING( '.' ) ) { _WILL_FIT( 1 ); *(q++) = *(p++); continue; } ++p; // at least '.' if( _IS_SLASH( p[ 0 ] ) ) { /* ignore "./" in directory specs */ if( ! _IS_SLASH( q[ -1 ] ) ) { *q++ = STRING( '\\' ); } ++p; continue; } if( p[ 0 ] == NULLCHAR ) break; if( p[ 0 ] == STRING( '.' ) ) { /* .. */ ++p; if( _IS_SLASH( p[ 0 ] ) ) { /* "../" */ ++p; } if( ! _IS_SLASH( q[ -1 ] ) ) { return( NULL ); } q -= 2; for( ;; ) { if( q < buff ) { return( NULL ); } if( _IS_SLASH( *q ) ) break; if( *q == STRING( ':' ) ) { ++q; *q = STRING( '\\' ); break; } --q; } ++q; *q = NULLCHAR; continue; } _WILL_FIT( 1 ); *(q++) = STRING( '.' ); } *q = NULLCHAR; } else { len = __F_NAME(strlen,wcslen)( p ); _WILL_FIT( len ); __F_NAME(strcpy,wcscpy)( q, p ); } /* force to all backslashes */ for( q = buff; *q != NULLCHAR; ++q ) { if( *q == STRING( '/' ) ) { *q = STRING( '\\' ); } } return( buff ); #endif }
void StartProg( const char *cmd, const char *prog, char *full_args, char *dos_args ) { const char *src; char *dst; USHORT drive; ULONG map; USHORT len; USHORT tid; USHORT rc; char buff[BSIZE]; seg_offset where; char *cmd_tail; /* unused parameters */ (void)cmd; MaxThread = 0; GrowArrays( 1 ); src = prog; dst = UtilBuff; DosQCurDisk( &drive, &map ); if( src[0] == '\0' || src[1] == '\0' || src[1] != ':' ) { *dst++ = drive - 1 + 'A'; *dst++ = ':'; } else { *dst++ = *src++; *dst++ = *src++; } if( src[0] != '\\' ) { ++dst; len = BUFF_SIZE - ( dst - UtilBuff ); DosQCurDir( drive, (PBYTE)dst, &len ); dst[-1] = '\\'; if( *dst == '\\' || *dst == '\0' ) { *dst = '\0'; } else { while( *dst != '\0' ) { ++dst; } *dst++ = '\\'; } } strcpy( dst, src ); dst = UtilBuff + strlen( UtilBuff ) + 1; cmd_tail = dst; strcpy( dst, full_args ); dst += strlen( dst ); *++dst = '\0'; /* Need two nulls at end */ LoadProg( UtilBuff, cmd_tail ); Output( MsgArray[MSG_SAMPLE_1 - ERR_FIRST_MESSAGE] ); Output( UtilBuff ); Output( "\r\n" ); Buff.pid = Pid; Buff.tid = 1; Buff.cmd = PT_CMD_STOP; LibLoadPTrace( &Buff ); if( OSVer < 0x1400 ) { /* OS/2 2.x already dumped out MainMod as a Module load */ CodeLoad( &Buff, MainMod, ExeName, SAMP_MAIN_LOAD ); } InitialCS = Buff.u.r.CS; rc = DosCreateThread( Sleeper, (PUSHORT)&tid, Stack + STACK_SIZE ); if( rc != 0 ) { InternalError( MsgArray[MSG_SAMPLE_4 - ERR_FIRST_MESSAGE] ); } rc = DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, tid ); if( rc != 0 ) { InternalError( MsgArray[MSG_SAMPLE_5 - ERR_FIRST_MESSAGE] ); } Buff.pid = Pid; Buff.tid = 1; for( ;; ) { Buff.cmd = PT_CMD_GO; if( LibLoadPTrace( &Buff ) != 0 ) { InternalError( MsgArray[MSG_SAMPLE_7 - ERR_FIRST_MESSAGE] ); } if( Buff.cmd == PT_RET_BREAK && Buff.u.r.DX != 0 ) { /* a mark */ len = 0; Buff.segv = Buff.u.r.DX; Buff.offv = Buff.u.r.AX; for( ;; ) { Buff.cmd = PT_CMD_READ_MEM_D; DosPTrace( &Buff ); buff[len] = Buff.value; if( Buff.cmd != PT_RET_SUCCESS ) buff[len] = '\0'; if( len == BSIZE ) buff[len] = '\0'; if( buff[len] == '\0' ) break; ++len; Buff.offv++; } where.segment = Buff.u.r.CS; where.offset = Buff.u.r.IP; WriteMark( buff, where ); Buff.cmd = PT_CMD_READ_REGS; DosPTrace( &Buff ); Buff.u.r.IP++; Buff.cmd = PT_CMD_WRITE_REGS; DosPTrace( &Buff ); continue; } else if( Buff.cmd == PT_RET_BREAK ) { /* common info pass */ CommonAddr.segment = Buff.u.r.CX; CommonAddr.offset = Buff.u.r.BX; Buff.cmd = PT_CMD_READ_REGS; DosPTrace( &Buff ); Buff.u.r.IP++; Buff.cmd = PT_CMD_WRITE_REGS; DosPTrace( &Buff ); continue; } if( Buff.cmd == PT_RET_FUNERAL ) break; if( Buff.cmd != PT_RET_LIB_LOADED && Buff.cmd != PT_RET_STOPPED && Buff.cmd != PT_RET_TRD_TERMINATE ) { InternalError( MsgArray[MSG_SAMPLE_6 - ERR_FIRST_MESSAGE] ); break; } RecordSample( Buff.u.r.IP, Buff.u.r.CS, Buff.tid ); } report(); }
long LocalGetFreeSpace( int drv ) /*******************************/ { struct _FSALLOCATE usage; #ifdef _M_I86 if( DosQFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) { #else if( DosQueryFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) { #endif return( -1L ); } return( usage.cbSector * usage.cSectorUnit * usage.cUnitAvail ); } error_handle LocalDateTime( sys_handle fh, int *time, int *date, int set ) /************************************************************************/ { struct _FILESTATUS fstatus; struct _FDATE *pdate; struct _FTIME *ptime; unsigned rc; pdate = (struct _FDATE *)date; ptime = (struct _FTIME *)time; if( set ) { #ifdef _M_I86 rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); #else rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) ); #endif if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); fstatus.ftimeLastWrite = *ptime; fstatus.fdateLastWrite = *pdate; rc = DosSetFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); if( rc != 0 ) { return( StashErrCode( rc, OP_LOCAL ) ); } } else { #ifdef _M_I86 rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); #else rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) ); #endif if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); *ptime = fstatus.ftimeLastWrite; *pdate = fstatus.fdateLastWrite; } return( 0 ); } error_handle LocalGetCwd( int drive, char *where ) /************************************************/ { APIRET len; len = 256; #ifdef _M_I86 return( StashErrCode( DosQCurDir( drive, (PBYTE)where, &len ), OP_LOCAL ) ); #else return( StashErrCode( DosQueryCurrentDir( drive, (PBYTE)where, &len ), OP_LOCAL ) ); #endif }
MRESULT EXPENTRY ChangeCurDirWndProc(HWND hDlg, ULONG Msg, MPARAM mp1, MPARAM mp2) { SHORT DriveId, DirId; CHAR HlpStr[CCHMAXPATH]; ULONG DriveMap; ULONG PathLen; APIRET rc; switch (Msg) { case WM_INITDLG: /*--- save current drive/dir ---*/ PathLen = CCHMAXPATH; if (DosQCurDisk(&SaveCurDisk, &DriveMap) || DosQCurDir(SaveCurDisk, (PUCHAR)SaveCurDir, &PathLen)) { DosBeep(1000, 1000); WinDismissDlg(hDlg, FALSE); break; } if (PathLen == 0) strcpy(SaveCurDir, "\\"); else { memmove(&SaveCurDir[1], SaveCurDir, strlen(SaveCurDir) + 1); SaveCurDir[0] = '\\'; } WinSendDlgItemMsg(hDlg, TID_CD_PATH, EM_SETTEXTLIMIT, MPFROMSHORT(CCHMAXPATH), 0L); if (_FillDriveLb(hDlg)) { DosBeep(1000, 1000); WinDismissDlg(hDlg, FALSE); break; } CenterDialog(hWndFrame, hDlg); WinSetFocus(HWND_DESKTOP, WinWindowFromID(hDlg, LID_CD_DIRS)); return ((MRESULT) TRUE); break; case WM_CONTROL: switch (SHORT1FROMMP(mp1)) { case LID_CD_DRIVES: if (SHORT2FROMMP(mp1) == LN_ENTER) { DriveId = SHORT1FROMMR(WinSendMsg(WinWindowFromID(hDlg, LID_CD_DRIVES), LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), NULL)); WinSendMsg(WinWindowFromID(hDlg, LID_CD_DRIVES), LM_QUERYITEMTEXT, MPFROM2SHORT(DriveId, CCHMAXPATH), MPFROMP(HlpStr)); SelectedDrive = (USHORT) HlpStr[1] - 64; DosSelectDisk(SelectedDrive); _FillDirLb(hDlg, SelectedDrive); } break; case LID_CD_DIRS: if (SHORT2FROMMP(mp1) == LN_ENTER) { DirId = SHORT1FROMMR(WinSendMsg(WinWindowFromID(hDlg, LID_CD_DIRS), LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), NULL)); WinSendMsg(WinWindowFromID(hDlg, LID_CD_DIRS), LM_QUERYITEMTEXT, MPFROM2SHORT(DirId, CCHMAXPATH), MPFROMP(HlpStr)); if (strncmp(HlpStr, " <root", 6) == 0) strcpy(HlpStr, "\\"); if (DosChDir(HlpStr)) DosBeep(1000, 1000); _FillDirLb(hDlg, SelectedDrive); } break; } break; case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { case DID_OK: if (FileSelected) { rc = WinMessageBox(HWND_DESKTOP, hDlg, "Refresh tree window?", ApplTitle, 0, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); if (rc == MBID_YES) WinPostMsg(hWndClient, WUM_START_REBUILD, 0L, 0L); else WinInvalidateRect(hWndClient, NULL, FALSE); } else WinInvalidateRect(hWndClient, NULL, FALSE); WinDismissDlg(hDlg, TRUE); break; case DID_CANCEL: if (DosSelectDisk(SaveCurDisk) || DosChDir(SaveCurDir)) DosBeep(1000, 1000); WinInvalidateRect(hWndClient, NULL, FALSE); WinDismissDlg(hDlg, FALSE); break; } break; default: return WinDefDlgProc(hDlg, Msg, mp1, mp2); break; } return NULL; }