BOOL FcbRename(xfcb FAR * lpXfcb) { rfcb FAR *lpRenameFcb; COUNT FcbDrive; /* Build a traditional DOS file name */ lpRenameFcb = (rfcb FAR *) CommonFcbInit(lpXfcb, SecPathName, &FcbDrive); /* check for a device */ if (IsDevice(SecPathName)) { return FALSE; } else { BYTE FAR *lpOldDta = dta; dmatch Dmatch; dta = (BYTE FAR *) & Dmatch; if (DosFindFirst(D_ALL, SecPathName[1] == ':' ? &SecPathName[2] : SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; } do { fcb LocalFcb; BYTE *pToName, *pszFrom; BYTE FAR *pFromPattern; COUNT nIndex; /* First, expand the find match into fcb style */ /* file name entry */ /* Fill with blanks first */ memset(LocalFcb.fcb_fname, ' ', FNAME_SIZE); memset(LocalFcb.fcb_fext, ' ', FEXT_SIZE); /* next move in the file name while overwriting */ /* the filler blanks */ pszFrom = Dmatch.dm_name; pToName = LocalFcb.fcb_fname; for (nIndex = 0; nIndex < FNAME_SIZE; nIndex++) { if (*pszFrom != 0 && *pszFrom != '.') *pToName++ = *pszFrom++; else if (*pszFrom == '.') { ++pszFrom; break; } else break; } if (*pszFrom != '\0') { pToName = LocalFcb.fcb_fext; for (nIndex = 0; nIndex < FEXT_SIZE; nIndex++) { if (*pszFrom != '\0') *pToName++ = *pszFrom++; else break; } } /* Overlay the pattern, skipping '?' */ /* I'm cheating because this assumes that the */ /* struct alignments are on byte boundaries */ pToName = LocalFcb.fcb_fname; for (pFromPattern = lpRenameFcb->renNewName, nIndex = 0; nIndex < FNAME_SIZE + FEXT_SIZE; nIndex++) { if (*pFromPattern != '?') *pToName++ = *pFromPattern++; else ++pFromPattern; } /* now to build a dos name again */ LocalFcb.fcb_drive = 0; FcbNameInit((fcb FAR *) & LocalFcb, SecPathName, &FcbDrive); truename(Dmatch.dm_name, PriPathName, FALSE); if (DosRenameTrue(PriPathName, SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; } } while (DosFindNext() == SUCCESS); dta = lpOldDta; return TRUE; } }
MRESULT EXPENTRY SwapProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) { static HWND hwndMenu = (HWND)0; switch(msg) { case WM_CREATE: { MRESULT mr = PFNWPStatic(hwnd,msg,mp1,mp2); WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID); return mr; } case WM_MOUSEMOVE: break; case WM_PRESPARAMCHANGED: { char *rootname = "SwapMon"; switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case CLOCK_FRAME: rootname = "Clock"; break; case HARD_FRAME: rootname = "Hard"; break; case CPU_FRAME: rootname = "CPU"; break; case CLP_FRAME: rootname = "ClipMon"; break; case MEM_FRAME: rootname = "Mem"; break; case TSK_FRAME: rootname = "Task"; break; } PresParamChanged(hwnd, rootname, mp1, mp2); PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); PostMsg(hwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); } break; case WM_APPTERMINATENOTIFY: if(WinQueryWindowUShort(hwnd,QWS_ID) == CPU_FRAME) { if(!StartCPUThreads()) WinDestroyWindow(hwnd); } break; case WM_BUTTON1MOTIONSTART: { POINTL ptl; ptl.x = SHORT1FROMMP(mp1); ptl.y = SHORT2FROMMP(mp1); WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1L); PostMsg(hwndConfig, UM_SHOWME, MPFROM2SHORT((USHORT)ptl.x,(USHORT)ptl.y), mp2); } return MRFROMSHORT(TRUE); case WM_BUTTON2MOTIONSTART: { TRACKINFO TrackInfo; SWP Position; memset(&TrackInfo,0,sizeof(TrackInfo)); TrackInfo.cxBorder = 1 ; TrackInfo.cyBorder = 1 ; TrackInfo.cxGrid = 1 ; TrackInfo.cyGrid = 1 ; TrackInfo.cxKeyboard = 8 ; TrackInfo.cyKeyboard = 8 ; WinQueryWindowPos(hwnd,&Position); TrackInfo.rclTrack.xLeft = Position.x ; TrackInfo.rclTrack.xRight = Position.x + Position.cx ; TrackInfo.rclTrack.yBottom = Position.y ; TrackInfo.rclTrack.yTop = Position.y + Position.cy ; WinQueryWindowPos(HWND_DESKTOP,&Position); TrackInfo.rclBoundary.xLeft = Position.x ; TrackInfo.rclBoundary.xRight = Position.x + Position.cx ; TrackInfo.rclBoundary.yBottom = Position.y ; TrackInfo.rclBoundary.yTop = Position.y + Position.cy ; TrackInfo.ptlMinTrackSize.x = 0 ; TrackInfo.ptlMinTrackSize.y = 0 ; TrackInfo.ptlMaxTrackSize.x = Position.cx ; TrackInfo.ptlMaxTrackSize.y = Position.cy ; TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY ; if(WinTrackRect(HWND_DESKTOP, (HPS)0, &TrackInfo)) { WinSetWindowPos(hwnd, HWND_TOP, TrackInfo.rclTrack.xLeft, TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE); switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case SWAP_FRAME: WinQueryWindowPos(hwnd,&swpSwap); SavePrf("SwapSwp", &swpSwap, sizeof(SWP)); break; case CLOCK_FRAME: WinQueryWindowPos(hwnd,&swpClock); SavePrf("ClockSwp", &swpClock, sizeof(SWP)); break; case HARD_FRAME: WinQueryWindowPos(hwnd,&swpHard); SavePrf("HardSwp", &swpHard, sizeof(SWP)); break; case CPU_FRAME: WinQueryWindowPos(hwnd,&swpCPU); SavePrf("CPUSwp", &swpCPU, sizeof(SWP)); break; case CLP_FRAME: WinQueryWindowPos(hwnd,&swpClip); SavePrf("ClipSwp", &swpClip, sizeof(SWP)); break; case MEM_FRAME: WinQueryWindowPos(hwnd,&swpMem); SavePrf("MemSwp", &swpMem, sizeof(SWP)); break; case TSK_FRAME: WinQueryWindowPos(hwnd,&swpTask); SavePrf("TaskSwp", &swpTask, sizeof(SWP)); break; } } } return MRFROMSHORT(TRUE); case WM_BUTTON1DOWN: WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_DEACTIVATE); return MRFROMSHORT(TRUE); case WM_BUTTON1DBLCLK: case WM_BUTTON1CLICK: if((!fNoMonClick && msg == WM_BUTTON1CLICK) || (fNoMonClick && msg == WM_BUTTON1DBLCLK)) { switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case HARD_FRAME: { ULONG ulDriveNum,ulDriveMap,x; ulDriveMon = min(ulDriveMon,26); if(!DosQCurDisk(&ulDriveNum, &ulDriveMap)) { for(x = ulDriveMon + 1;x < 26;x++) { if(ulDriveMap & (1 << x)) { ulDriveMon = x; break; } } if(x >= 26) { for(x = 3;x < ulDriveMon - 1;x++) { if(ulDriveMap & (1 << x)) { ulDriveMon = x; break; } } } SavePrf("MonDrive", &ulDriveMon, sizeof(ULONG)); } PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); } break; case CLP_FRAME: case MEM_FRAME: case TSK_FRAME: case SWAP_FRAME: case CLOCK_FRAME: case CPU_FRAME: { USHORT cmd = CPU_PULSE; switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case MEM_FRAME: cmd = CLOCK_CMDLINE; break; case TSK_FRAME: cmd = CPU_KILLPROC; break; case CLP_FRAME: cmd = CLOCK_CLIPBOARD; break; case SWAP_FRAME: cmd = SWAP_LAUNCHPAD; break; case CLOCK_FRAME: cmd = CLOCK_SETTINGS; if((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0) cmd = CLOCK_CLOCK; break; } PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd,0), MPVOID); } break; } return MRFROMSHORT(TRUE); } else PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); break; case WM_CONTEXTMENU: WinInvalidateRect(hwnd, NULL, FALSE); WinSendMsg(hwnd, UM_TIMER, MPVOID, MPVOID); WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_DEACTIVATE); { USHORT id; id = WinQueryWindowUShort(hwnd,QWS_ID); hwndMenu = WinLoadMenu(HWND_DESKTOP, 0, id); if(hwndMenu) { POINTL ptl; SWP swp; ULONG ulDriveNum,ulDriveMap,x; MENUITEM mi; char s[80]; SetPresParams(hwndMenu, -1, -1, -1, helvtext); switch(id) { case CLP_FRAME: WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(CLP_APPEND,FALSE), MPFROM2SHORT(MIA_CHECKED, ((fClipAppend) ? MIA_CHECKED : 0))); break; case HARD_FRAME: if(!DosQCurDisk(&ulDriveNum, &ulDriveMap)) { mi.iPosition = 0; mi.hwndSubMenu = (HWND)0; mi.hItem = 0L; mi.afStyle = MIS_TEXT | MIS_STATIC; mi.afAttribute = MIA_FRAMED; mi.id = -1; sprintf(s, "Current drive is %c:", (char)(ulDriveMon + '@')); WinSendMsg(hwndMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(s)); mi.iPosition = MIT_END; for(x = 2;x < 26;x++) { if(ulDriveMap & (1 << x)) { if(x != ulDriveMon - 1) { mi.afStyle = MIS_TEXT; mi.afAttribute = 0; mi.id = HARD_C + (x - 2); if(fShowFreeInMenus) SetDriveText(x + 1, s); else sprintf(s, "%c:", (char)(x + 'A')); WinSendMsg(hwndMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(s)); } } } } break; case CLOCK_FRAME: WinEnableMenuItem(hwndMenu, CLOCK_VIRTUAL, fDesktops); WinEnableMenuItem(hwndMenu, CLOCK_CLIPBOARD, (ClipHwnd != (HWND)0)); break; default: break; } WinQueryWindowPos(hwnd, &swp); ptl.x = SHORT1FROMMP(mp1); ptl.y = SHORT2FROMMP(mp1); WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1L); ptl.y = max(ptl.y,swp.y + swp.cy + 4); if(!WinPopupMenu(HWND_DESKTOP, hwnd, hwndMenu, ptl.x - 4, ptl.y - 4, 0, PU_HCONSTRAIN | PU_VCONSTRAIN | PU_KEYBOARD | PU_MOUSEBUTTON1)) { WinDestroyWindow(hwndMenu); hwndMenu = (HWND)0; } } } return MRFROMSHORT(TRUE); case WM_MENUEND: WinSetFocus(HWND_DESKTOP, HWND_DESKTOP); WinDestroyWindow((HWND)mp2); if(hwndMenu == (HWND)mp2) hwndMenu = (HWND)0; return 0; case UM_SETUP: { char *rootname = "SwapMon"; switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case SWAP_FRAME: SwapHwnd = hwnd; swaptick = 0; break; case CLOCK_FRAME: ClockHwnd = hwnd; rootname = "Clock"; break; case TSK_FRAME: TaskHwnd = hwnd; rootname = "Task"; break; case MEM_FRAME: MemHwnd = hwnd; rootname = "Mem"; break; case HARD_FRAME: HardHwnd = hwnd; rootname = "Hard"; break; case CPU_FRAME: CPUHwnd = hwnd; rootname = "CPU"; PostMsg(hwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); break; case CLP_FRAME: ClipMonHwnd = hwnd; rootname = "ClipMon"; PostMsg(hwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); break; } if(!RestorePresParams(hwnd,rootname)) SetPresParams(hwnd, RGB_WHITE, RGB_BLACK, RGB_BLACK, helvtext); } PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); return 0; case UM_REFRESH: switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case CLP_FRAME: { char s[] = " Clip: [TtBbMmP] + ",*p; ULONG fmt[] = {CF_TEXT,CF_DSPTEXT, CF_BITMAP,CF_DSPBITMAP, CF_METAFILE,CF_DSPMETAFILE, CF_PALETTE,0}; ULONG x,ret; if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) { p = s + 8; for(x = 0;fmt[x];x++) { ret = WinQueryClipbrdData(WinQueryAnchorBlock(hwnd), fmt[x]); if(!ret) *p = '-'; p++; } p += 2; if(!fClipAppend) *p = 0; WinCloseClipbrd(WinQueryAnchorBlock(hwnd)); } else strcpy(s + 7, "Can't open. "); SetMonitorSize(hwnd, hwndMenu, &swpClip, s); } break; case CPU_FRAME: { char s[32]; ULONG percent,lastaverage; static BOOL lastavgset = 0; *s = 0; if(mp2) { strcpy(s," CPU: -% "); if(fAverage) strcat(s,"Avg: -%) "); } else { percent = ((MaxCount - (ULONG)mp1) * 100) / MaxCount; lastaverage = AveCPU; AveCPU = (((AveCPU * NumAveCPU) + percent) / ((ULONG)NumAveCPU + 1)); NumAveCPU++; if(!NumAveCPU) NumAveCPU = 65535; if(percent != LastPercent || (AveCPU != lastaverage && fAverage) || NumAveCPU == 1 || lastavgset != fAverage) { lastavgset = fAverage; LastPercent = percent; sprintf(s, " CPU: %lu%% ", percent); if(fAverage) sprintf(s + strlen(s), "(Avg: %lu%%) ", AveCPU); } } if(*s) SetMonitorSize(hwnd, hwndMenu, &swpCPU, s); } break; } return 0; case WM_TIMER: if(fSwapFloat && !hwndMenu) WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_SHOW); if(WinQueryWindowUShort(hwnd,QWS_ID) == CLP_FRAME) { if(!ClipHwnd) WinDestroyWindow(hwnd); else TakeClipboard(); } return 0; case UM_TIMER: switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case CLP_FRAME: ClipMonHwnd = hwnd; WinSendMsg(hwnd, WM_TIMER, MPVOID, MPVOID); break; case CPU_FRAME: CPUHwnd = hwnd; WinSendMsg(hwnd, WM_TIMER, MPVOID, MPVOID); break; case HARD_FRAME: { char s[80]; HardHwnd = hwnd; SetDriveText(ulDriveMon, s); SetMonitorSize(hwnd, hwndMenu, &swpHard, s); } break; case SWAP_FRAME: { FILEFINDBUF3 ffb; ULONG nm = 1,fl = SWP_SIZE | SWP_SHOW | SWP_MOVE, sh,sl,nh; HDIR hdir = HDIR_CREATE; FSALLOCATE fsa; char s[128],ss[8],sss[8],mb,smb; static ULONG lastcbFile = 0; static BOOL warned = FALSE; static char SwapperDat[CCHMAXPATH] = ""; strcpy(s, " Unable to locate SWAPPER.DAT. "); SwapHwnd = hwnd; if(!*SwapperDat) FindSwapperDat(SwapperDat); if(*SwapperDat) { DosError(FERR_DISABLEHARDERR); if(!DosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY, &ffb, sizeof(ffb), &nm, FIL_STANDARD)) { DosFindClose(hdir); if(ffb.cbFile != lastcbFile && lastcbFile) swaptick = 9; lastcbFile = ffb.cbFile; DosError(FERR_DISABLEHARDERR); if(!DosQueryFSInfo(toupper(*SwapperDat) - '@', FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) nm = fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector); else nm = 0; if(nm <= 32768 * 1024) { swaptick = 10; if(!warned) { SetPresParams(hwnd, RGB_RED, -1, -1, NULL); warned = TRUE; DosBeep(250,15); } } else if(warned) { PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID); warned = FALSE; } mb = MakeNumber(nm, &nh, &sl); *sss = 0; if(sl) sprintf(sss, ".%02lu", sl); smb = MakeNumber(ffb.cbFile, &sh, &sl); *ss = 0; if(sl) sprintf(ss, ".%02lu", sl); sprintf(s, " Swap: %lu%s%cb ", sh, ss, smb); if(fShowSwapFree) sprintf(s + strlen(s), "(%lu%s%cb free) ", nh, sss, mb); } } SetMonitorSize(hwnd, hwndMenu, &swpSwap, s); } break; case TSK_FRAME: { PROCESSINFO *ppi; BUFFHEADER *pbh = NULL; MODINFO *pmi; long numprocs = -1,numthreads = -1; char s[80]; if(!DosAllocMem((PVOID)&pbh, USHRT_MAX + 4096, PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)) { if(!DosQProcStatus(pbh, USHRT_MAX)) { numprocs = numthreads = 0; ppi = pbh->ppi; while(ppi->ulEndIndicator != PROCESS_END_INDICATOR ) { pmi = pbh->pmi; while(pmi && ppi->hModRef != pmi->hMod) pmi = pmi->pNext; if(pmi) { numprocs++; numthreads += ppi->usThreadCount; } ppi = (PPROCESSINFO)(ppi->ptiFirst + ppi->usThreadCount); } } DosFreeMem(pbh); sprintf(s, " Procs: %ld Thrds: %ld ", numprocs, numthreads); SetMonitorSize(hwnd, hwndMenu, &swpTask, s); } } break; case MEM_FRAME: { ULONG sh,sl,nh,amem; char s[128],ss[8],sss[8],mb,smb; strcpy(s, "Can't check virtual memory."); MemHwnd = hwnd; if(!DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM, &amem, sizeof(amem))) { mb = MakeNumber(amem, &nh, &sl); *ss = 0; if(sl) sprintf(ss, ".%02lu", sl); sprintf(s, " VMem: %lu%s%cb ", nh, ss, mb); } if(fShowPMem) { if(!Dos16MemAvail(&amem)) { mb = MakeNumber(amem, &nh, &sl); *ss = 0; if(sl) sprintf(ss, ".%02lu", sl); sprintf(s + strlen(s), " PMem: %lu%s%cb ", nh, ss, mb); } } SetMonitorSize(hwnd, hwndMenu, &swpMem, s); } break; case CLOCK_FRAME: { char s[80]; DATETIME dt; ClockHwnd = hwnd; if(!DosGetDateTime(&dt)) { sprintf(s, " %0*u:%02u%s ", ((ampm) ? 0 : 2), (dt.hours % ((ampm) ? 12 : 24)) + ((ampm && !(dt.hours % 12)) ? 12 : 0), dt.minutes, ((ampm) ? (dt.hours > 11) ? "pm" : "am" : "")); if(showdate) sprintf(s + strlen(s), "%02u/%02u ", dt.month, dt.day); } else strcpy(s,"Unknown time"); SetMonitorSize(hwnd, hwndMenu, &swpClock, s); } break; } return 0; case WM_COMMAND: { BOOL ctrl,shift; ctrl = ((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0); shift = ((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0); switch(SHORT1FROMMP(mp1)) { case CLP_CLEAR: if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) { WinEmptyClipbrd(WinQueryAnchorBlock(hwnd)); WinCloseClipbrd(WinQueryAnchorBlock(hwnd)); PostMsg(hwnd, UM_REFRESH, MPVOID, MPVOID); } break; case CLP_APPEND: fClipAppend = (fClipAppend) ? FALSE : TRUE; SavePrf("ClipAppend", &fClipAppend, sizeof(BOOL)); PostMsg(hwnd, UM_REFRESH, MPVOID, MPVOID); if(ClipSetHwnd) PostMsg(ClipSetHwnd, UM_REFRESH, MPVOID, MPVOID); break; case MSE_HELP: ViewHelp(hwnd, "Monitors page"); break; case CPU_PULSE: { PROGDETAILS pgd; WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_FOCUSACTIVATE); memset(&pgd, 0, sizeof(pgd)); pgd.Length = sizeof(pgd); pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER; pgd.swpInitial.hwndInsertBehind = HWND_TOP; pgd.progt.fbVisible = SHE_VISIBLE; pgd.progt.progc = PROG_DEFAULT; pgd.pszExecutable = "PULSE.EXE"; if(WinStartApp(CPUHwnd, &pgd, NULL, NULL, 0)) { if(CPUHwnd) { closethreads = 1; DosSleep(1); PostMsg(CPUHwnd, UM_REFRESH, MPVOID, MPFROMSHORT(TRUE)); } } } break; case CPU_RESET: AveCPU = 0; NumAveCPU = 0; break; case CLOCK_VIRTUAL: case CLOCK_SWITCHLIST: case CLOCK_CMDLINE: case CLOCK_CLIPBOARD: case CLOCK_CALCULATOR: case HARD_FM2: case MSE_FRAME: { ULONG msg2 = UM_SHOWME; MPARAM mp12 = 0,mp22 = 0; HWND hwndP = hwndConfig; switch(SHORT1FROMMP(mp1)) { case CLOCK_CMDLINE: mp12 = MPFROMLONG(((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0)); msg2 = UM_CMDLINE; break; case CLOCK_CLIPBOARD: msg2 = UM_CLIPMGR; hwndP = ObjectHwnd3; break; case CLOCK_SWITCHLIST: msg2 = UM_SWITCHLIST; break; case CLOCK_VIRTUAL: msg2 = UM_VIRTUAL; break; case CLOCK_CALCULATOR: msg2 = UM_CALC; break; case HARD_FM2: msg2 = UM_STARTWIN; mp12 = MPFROM2SHORT(C_STARTFM2,0); break; } PostMsg(hwndP, msg2, mp12, mp22); } break; case CLOCK_SETTINGS: case CLOCK_CLOCK: case SWAP_LAUNCHPAD: case SWAP_WARPCENTER: case SWAP_CONNECTIONS: case SWAP_INFO: case SWAP_SETTINGS: case SWAP_SYSTEM: case SWAP_TEMPS: case SWAP_FM2: case HARD_OPEN: case CVR_COLORPALETTE: case CVR_HICOLORPALETTE: case CVR_FONTPALETTE: case CPU_KILLPROC: case CPU_HARDWARE: { char *p = "<WP_CLOCK>",*pp = defopen; char s[8]; switch(SHORT1FROMMP(mp1)) { case HARD_OPEN: sprintf(s, "%c:\\", (char)(ulDriveMon + '@')); p = s; break; case SWAP_FM2: p = "<FM3_Folder>"; break; case SWAP_TEMPS: p = "<WP_TEMPS>"; break; case SWAP_SYSTEM: p = "<WP_OS2SYS>"; break; case SWAP_SETTINGS: p = "<WP_CONFIG>"; break; case SWAP_INFO: p = "<WP_INFO>"; break; case SWAP_CONNECTIONS: p = "<WP_CONNECTIONSFOLDER>"; break; case SWAP_WARPCENTER: p = "<WP_WARPCENTER>"; break; case SWAP_LAUNCHPAD: p = "<WP_LAUNCHPAD>"; break; case CLOCK_SETTINGS: pp = setopen; break; case CVR_COLORPALETTE: p = "<WP_LORESCLRPAL>"; break; case CVR_HICOLORPALETTE: p = "<WP_HIRESCLRPAL>"; break; case CVR_FONTPALETTE: p = "<WP_FNTPAL>"; break; case CPU_KILLPROC: p = "<FM/2_KILLPROC>"; break; case CPU_HARDWARE: p = "<WP_HWMGR>"; break; } OpenObject(p, pp); } break; case HARD_VDIR: { PROGDETAILS pgd; char s[36]; sprintf(s, "/C VDIR.CMD %c:\\", (char)(ulDriveMon + '@')); memset(&pgd, 0, sizeof(pgd)); pgd.Length = sizeof(pgd); pgd.swpInitial.fl = SWP_MINIMIZE | SWP_ACTIVATE | SWP_ZORDER; pgd.swpInitial.hwndInsertBehind = HWND_TOP; pgd.progt.fbVisible = SHE_VISIBLE; pgd.progt.progc = PROG_DEFAULT; pgd.pszExecutable = "CMD.EXE"; WinStartApp((HWND)0, &pgd, s, NULL, 0); } break; case HARD_CHKDSK: { PROGDETAILS pgd; char s[8]; WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_FOCUSACTIVATE); sprintf(s, "%c:", (char)(ulDriveMon + '@')); memset(&pgd, 0, sizeof(pgd)); pgd.Length = sizeof(pgd); pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER; pgd.swpInitial.hwndInsertBehind = HWND_TOP; pgd.progt.fbVisible = SHE_VISIBLE; pgd.progt.progc = PROG_DEFAULT; pgd.pszExecutable = "PMCHKDSK.EXE"; WinStartApp((HWND)0, &pgd, s, NULL, 0); } break; default: if(SHORT1FROMMP(mp1) >= HARD_C && SHORT1FROMMP(mp1) <= HARD_C + 24) { ulDriveMon = (SHORT1FROMMP(mp1) - HARD_C) + 3; PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID); if(ctrl) PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(HARD_OPEN,0), MPVOID); else if(shift) PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(HARD_VDIR,0), MPVOID); } break; } } return 0; case WM_DESTROY: switch(WinQueryWindowUShort(hwnd,QWS_ID)) { case SWAP_FRAME: SwapHwnd = (HWND)0; break; case CLOCK_FRAME: ClockHwnd = (HWND)0; break; case HARD_FRAME: HardHwnd = (HWND)0; break; case CPU_FRAME: closethreads = 1; DosSleep(1); CPUHwnd = (HWND)0; break; case CLP_FRAME: ClipMonHwnd = (HWND)0; break; case MEM_FRAME: MemHwnd = (HWND)0; break; case TSK_FRAME: TaskHwnd = (HWND)0; break; } break; } return PFNWPStatic(hwnd,msg,mp1,mp2); }
APIRET ProcessFiles (void) { APIRET rc = NO_ERROR; /* this is an API-returncode */ HDIR dirHandle = HDIR_CREATE; /* directory scan handle */ FILEFINDBUF3 *fileData; PVOID pDirectoryBuffer; /* pointer to directory data buffer */ ULONG ulCount; /* how many files have been found on drive ? */ PSZ pszFiles = Options.pszFileInput; /* pointer to variable space */ char szFilePath[MAXPATHLEN]; /* local buffer for filename xform */ PSZ pszTemp; /* used for determination if path was passed. */ pDirectoryBuffer = malloc(FFBUF); if (pDirectoryBuffer == NULL) /* check if allocation was successful */ return (ERROR_NOT_ENOUGH_MEMORY); /* signal error */ ulCount = NFILES; /* set how many files shall be read per API call */ fileData = (FILEFINDBUF3 *)pDirectoryBuffer; /* map to buffer */ rc = DosFindFirst(pszFiles, /* call to the first directory scan */ &dirHandle, FILE_ARCHIVED | FILE_NORMAL, fileData, FFBUF, &ulCount, FIL_STANDARD); if (rc != NO_ERROR) /* check if there has been an error */ return (rc); /* signal error */ /* modify the path buffer ! */ strcpy(szFilePath, /* copy the data first */ Options.pszFileInput); pszTemp = strrchr(szFilePath, /* scan for the last slash */ '/'); if (pszTemp == NULL) /* the slash has not been found */ { pszTemp = strrchr(szFilePath, /* scan for the last backslash */ '\\'); if (pszTemp == NULL) /* the backslash has not been found */ pszTemp = strrchr(szFilePath, /* scan for the last colon */ ':'); } if (pszTemp != NULL) /* a path delimiting character has been found ! */ *(pszTemp+1) = 0; /* cut the path string there */ else szFilePath[0] = 0; /* then no additional path applies ! */ while (rc == NO_ERROR) /* as long as everything is OK */ { printf ("\nDEBUG: [%u scanned]",ulCount); while (ulCount != 0) /* as long as there are files left */ { Globals.ulProcessedFiles++; /* adjust the statistics */ Globals.ulProcessedBytes += fileData->cbFile; rc = ProcessFile(szFilePath, /* now process this single file */ fileData->achName); if (rc != NO_ERROR) /* check if an error occured ? */ goto __label_process_exit; /* abort processing here ! */ ulCount--; /* skip to the next file */ fileData = (FILEFINDBUF3 *) ((PBYTE)fileData + fileData->oNextEntryOffset); } ulCount = NFILES; fileData = (FILEFINDBUF3 *)pDirectoryBuffer; rc = DosFindNext (dirHandle, /* now call the next few files */ fileData, FFBUF, &ulCount); } __label_process_exit: /* here begins the routine's exit processing */ DosFindClose(dirHandle); free(pDirectoryBuffer); return (rc); /* signal success */ }
int Directory::fill(CPCHAR fileSpec) { MStackCall(__FILE__,__LINE__); if (dirName != "") { HDIR hdir = HDIR_CREATE; ULONG count = 1000; char* buf = new char[BUF_SIZE]; int attrib = FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED; Array<RegExp> r; FileExp2RegExpArray(fileSpec, r); if (DosFindFirst((PSZ)(const char*)mergePath(dirName, "*"), &hdir, attrib, buf, BUF_SIZE, &count, FIL_STANDARD) == NO_ERROR) { do { MTrace(("%s, %i matching entries", (const char*)mergePath(dirName, "*"), count)); FILEFINDBUF3* pffb = (FILEFINDBUF3*)buf; entry.SetDynamic(TRUE); // fake . & .. entries in / dir under MS-DOS / FAT file systems if (strcmp(pffb->achName, ".") != 0) { if (match(".", r)) entry[entry.Size()] = Dirent(this, ".", pffb->fdateLastWrite, pffb->ftimeLastWrite, 0, FILE_READONLY | FILE_DIRECTORY); if (match("..", r)) entry[entry.Size()] = Dirent(this, "..", pffb->fdateLastWrite, pffb->ftimeLastWrite, 0, FILE_READONLY | FILE_DIRECTORY); } do { if (match(pffb->achName, r)) { Dirent aDirent(this, pffb->achName, pffb->fdateLastWrite, pffb->ftimeLastWrite, pffb->cbFile, pffb->attrFile); int size = entry.Size(); entry[size] = aDirent; } if (pffb->oNextEntryOffset) pffb = (FILEFINDBUF3*)(((char*)pffb) + pffb->oNextEntryOffset); else pffb = 0; } while (pffb); } while (DosFindNext(hdir, buf, BUF_SIZE, &count) == NO_ERROR); DosFindClose(hdir); entry.SetDynamic(FALSE); } delete buf; } return entry.Size(); }
static void FindSwapperDat (char *SwapperDat) { char *filename = "C:\\CONFIG.SYS",*p,*pp; char *input = NULL; FILE *fp; FILEFINDBUF3 ffb; ULONG nm = 1L,size = sizeof(SwapperDat); HDIR hdir = HDIR_CREATE; APIRET rc = 1L; input = malloc(8192); if(input) { *input = 0; *SwapperDat = 0; PrfQueryProfileData(prof, appname, "SwapperDat", (PVOID)SwapperDat, &size); if(*SwapperDat) { rc = DosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_ARCHIVED | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY, &ffb, sizeof(ffb), &nm, FIL_STANDARD); if(!rc) { DosFindClose(hdir); fp = fopen(SwapperDat,"r"); if(fp) { fclose(fp); *SwapperDat = 0; rc = 1L; } } else *SwapperDat = 0; } if(rc) { if(DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, (PVOID)&nm, (ULONG)sizeof(ULONG))) nm = 3L; *filename = (char)nm + '@'; fp = fopen(filename,"r"); if(fp) { while(!feof(fp)) { if(!fgets(input,8192,fp)) break; input[8191] = 0; lstrip(input); if(!strnicmp(input,"SWAPPATH",8)) { p = input + 8; while(*p == ' ') p++; if(*p == '=') { p++; stripcr(p); rstrip(p); while(*p == ' ') p++; if(*p == '\"') { p++; pp = p; while(*pp && *pp != '\"') *pp++; if(*pp) *pp = 0; } else { pp = strchr(p,' '); if(pp) *pp = 0; } if(*p) { strncpy(SwapperDat,p,CCHMAXPATH); SwapperDat[CCHMAXPATH - 1] = 0; if(SwapperDat[strlen(SwapperDat) - 1] != '\\') strcat(SwapperDat,"\\"); strcat(SwapperDat,"SWAPPER.DAT"); hdir = HDIR_CREATE; nm = 1L; if(!DosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_ARCHIVED | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY, &ffb, sizeof(ffb), &nm, FIL_STANDARD)) { DosFindClose(hdir); PrfWriteProfileString(prof, appname, "SwapperDat", SwapperDat); } else *SwapperDat = 0; break; } } } } fclose(fp); } } if(!*SwapperDat) { if(DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, (PVOID)&nm, (ULONG)sizeof(ULONG))) nm = 3L; sprintf(SwapperDat, "%c:\\OS2\\SYSTEM\\SWAPPER.DAT", (char)nm + '@'); hdir = HDIR_CREATE; nm = 1L; if(!DosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_ARCHIVED | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY, &ffb, sizeof(ffb), &nm, FIL_STANDARD)) { DosFindClose(hdir); PrfWriteProfileString(prof, appname, "SwapperDat", SwapperDat); } else *SwapperDat = 0; } free(input); } }
VOID int21_service(iregs FAR * r) { COUNT rc = 0, rc1; psp FAR *p = MK_FP(cu_psp, 0); void FAR *FP_DS_DX = MK_FP(r->DS, r->DX); /* this is saved so often, that this saves ~100 bytes */ #define CLEAR_CARRY_FLAG() r->FLAGS &= ~FLG_CARRY #define SET_CARRY_FLAG() r->FLAGS |= FLG_CARRY p->ps_stack = (BYTE FAR *) r; #ifdef DEBUG if (bDumpRegs) { fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs, sizeof(iregs)); printf("System call (21h): %02x\n", user_r->AX); dump_regs = TRUE; dump(); } #endif if(r->AH >=0x38 && r->AH <= 0x4F) CLEAR_CARRY_FLAG(); /* Clear carry by default for these functions */ dispatch: /* Check for Ctrl-Break */ switch (r->AH) { default: if (!break_ena) break; case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x08: case 0x09: case 0x0a: case 0x0b: if (control_break()) handle_break(); } /* The dispatch handler */ switch (r->AH) { /* int 21h common error handler */ case 0x64: error_invalid: r->AX = -DE_INVLDFUNC; goto error_out; error_exit: r->AX = -rc; error_out: CritErrCode = r->AX; /* Maybe set */ SET_CARRY_FLAG(); break; /* case 0x00: --> Simulate a DOS-4C-00 */ /* Read Keyboard with Echo */ case 0x01: r->AL = _sti(TRUE); sto(r->AL); break; /* Display Character */ case 0x02: sto(r->DL); break; /* Auxiliary Input */ case 0x03: { COUNT scratch; GenericRead(STDAUX, 1, (BYTE FAR *) & r->AL, (COUNT FAR *) & scratch, TRUE); break; } /* Auxiliary Output */ case 0x04: { COUNT scratch; DosWrite(STDAUX, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) &scratch); break; } /* Print Character */ case 0x05: { COUNT scratch; DosWrite(STDPRN, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) &scratch); break; } /* Direct Console I/O */ case 0x06: if (r->DL != 0xff) sto(r->DL); else if (StdinBusy()) { r->AL = 0x00; r->FLAGS |= FLG_ZERO; } else { r->FLAGS &= ~FLG_ZERO; r->AL = _sti(FALSE); } break; /* Direct Console Input */ case 0x07: r->AL = _sti(FALSE); break; /* Read Keyboard Without Echo */ case 0x08: r->AL = _sti(TRUE); break; /* Display String */ case 0x09: { BYTE FAR * q; q = FP_DS_DX; while (*q != '$') ++q; DosWrite(STDOUT, FP_OFF(q) - FP_OFF(FP_DS_DX), FP_DS_DX, (COUNT FAR *) & UnusedRetVal); } r->AL = '$'; break; /* Buffered Keyboard Input */ case 0x0a: sti_0a((keyboard FAR *) FP_DS_DX); break; /* Check Stdin Status */ case 0x0b: if (StdinBusy()) r->AL = 0x00; else r->AL = 0xFF; break; /* Flush Buffer, Read Keayboard */ case 0x0c: KbdFlush(); switch (r->AL) { case 0x01: case 0x06: case 0x07: case 0x08: case 0x0a: r->AH = r->AL; goto dispatch; default: r->AL = 0x00; break; } break; /* Reset Drive */ case 0x0d: flush(); break; /* Set Default Drive */ case 0x0e: r->AL = DosSelectDrv(r->DL); break; case 0x0f: if (FcbOpen(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; case 0x10: if (FcbClose(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; case 0x11: if (FcbFindFirst(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; case 0x12: if (FcbFindNext(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; case 0x13: if (FcbDelete(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; case 0x14: { if (FcbRead(FP_DS_DX, &CritErrCode)) r->AL = 0; else r->AL = CritErrCode; break; } case 0x15: { if (FcbWrite(FP_DS_DX, &CritErrCode)) r->AL = 0; else r->AL = CritErrCode; break; } case 0x16: if (FcbCreate(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; case 0x17: if (FcbRename(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; default: #ifdef DEBUG printf("Unsupported INT21 AH = 0x%x, AL = 0x%x.\n", r->AH, r->AL); #endif /* Fall through. */ /* CP/M compatibility functions */ case 0x18: case 0x1d: case 0x1e: case 0x20: #ifndef TSC case 0x61: #endif case 0x6b: r->AL = 0; break; /* Get Default Drive */ case 0x19: r->AL = default_drive; break; /* Set DTA */ case 0x1a: { psp FAR *p = MK_FP(cu_psp, 0); p->ps_dta = FP_DS_DX; dos_setdta(p->ps_dta); } break; /* Get Default Drive Data */ case 0x1b: { BYTE FAR *p; FatGetDrvData(0, (COUNT FAR *) & r->AX, (COUNT FAR *) & r->CX, (COUNT FAR *) & r->DX, (BYTE FAR **) & p); r->DS = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Get Drive Data */ case 0x1c: { BYTE FAR *p; FatGetDrvData(r->DL, (COUNT FAR *) & r->AX, (COUNT FAR *) & r->CX, (COUNT FAR *) & r->DX, (BYTE FAR **) & p); r->DS = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Get default DPB */ /* case 0x1f: see case 0x32 */ /* Random read using FCB */ case 0x21: { if (FcbRandomIO(FP_DS_DX, &CritErrCode, FcbRead)) r->AL = 0; else r->AL = CritErrCode; break; } /* Random write using FCB */ case 0x22: { if (FcbRandomIO(FP_DS_DX, &CritErrCode, FcbWrite)) r->AL = 0; else r->AL = CritErrCode; break; } /* Get file size in records using FCB */ case 0x23: if (FcbGetFileSize(FP_DS_DX)) r->AL = 0; else r->AL = 0xff; break; /* Set random record field in FCB */ case 0x24: FcbSetRandom(FP_DS_DX); break; /* Set Interrupt Vector */ case 0x25: { VOID(INRPT FAR * p) () = FP_DS_DX; setvec(r->AL, p); } break; /* Dos Create New Psp */ case 0x26: { psp FAR *p = MK_FP(cu_psp, 0); new_psp((psp FAR *) MK_FP(r->DX, 0), p->ps_size); } break; /* Read random record(s) using FCB */ case 0x27: { if (FcbRandomBlockRead(FP_DS_DX, r->CX, &CritErrCode)) r->AL = 0; else r->AL = CritErrCode; break; } /* Write random record(s) using FCB */ case 0x28: { if (FcbRandomBlockWrite(FP_DS_DX, r->CX, &CritErrCode)) r->AL = 0; else r->AL = CritErrCode; break; } /* Parse File Name */ case 0x29: { BYTE FAR *lpFileName; lpFileName = MK_FP(r->DS, r->SI); r->AL = FcbParseFname(r->AL, &lpFileName, MK_FP(r->ES, r->DI)); r->DS = FP_SEG(lpFileName); r->SI = FP_OFF(lpFileName); } break; /* Get Date */ case 0x2a: DosGetDate( (BYTE FAR *) & (r->AL), /* WeekDay */ (BYTE FAR *) & (r->DH), /* Month */ (BYTE FAR *) & (r->DL), /* MonthDay */ (COUNT FAR *) & (r->CX)); /* Year */ break; /* Set Date */ case 0x2b: rc = DosSetDate( (BYTE FAR *) & (r->DH), /* Month */ (BYTE FAR *) & (r->DL), /* MonthDay */ (COUNT FAR *) & (r->CX)); /* Year */ if (rc != SUCCESS) r->AL = 0xff; else r->AL = 0; break; /* Get Time */ case 0x2c: DosGetTime( (BYTE FAR *) & (r->CH), /* Hour */ (BYTE FAR *) & (r->CL), /* Minutes */ (BYTE FAR *) & (r->DH), /* Seconds */ (BYTE FAR *) & (r->DL)); /* Hundredths */ break; /* Set Date */ case 0x2d: rc = DosSetTime( (BYTE FAR *) & (r->CH), /* Hour */ (BYTE FAR *) & (r->CL), /* Minutes */ (BYTE FAR *) & (r->DH), /* Seconds */ (BYTE FAR *) & (r->DL)); /* Hundredths */ if (rc != SUCCESS) r->AL = 0xff; else r->AL = 0; break; /* Set verify flag */ case 0x2e: verify_ena = (r->AL ? TRUE : FALSE); break; /* Get DTA */ case 0x2f: r->ES = FP_SEG(dta); r->BX = FP_OFF(dta); break; /* Get DOS Version */ case 0x30: r->AL = os_major; r->AH = os_minor; r->BH = OEM_ID; r->CH = REVISION_MAJOR; /* JPP */ r->CL = REVISION_MINOR; r->BL = REVISION_SEQ; if (ReturnAnyDosVersionExpected) { /* TE for testing purpose only and NOT to be documented: return programs, who ask for version == XX.YY exactly this XX.YY. this makes most MS programs more happy. */ UBYTE FAR *retp = MK_FP(r->cs, r->ip); if ( retp[0] == 0x3d && /* cmp ax, xxyy */ (retp[3] == 0x75 || retp[3] == 0x74)) /* je/jne error */ { r->AL = retp[1]; r->AH = retp[2]; } else if(retp[0] == 0x86 && /* xchg al,ah */ retp[1] == 0xc4 && retp[2] == 0x3d && /* cmp ax, xxyy */ (retp[5] == 0x75 || retp[5] == 0x74)) /* je/jne error */ { r->AL = retp[4]; r->AH = retp[3]; } } break; /* Keep Program (Terminate and stay resident) */ case 0x31: DosMemChange(cu_psp, r->DX < 6 ? 6 : r->DX, 0); return_mode = 3; return_code = r->AL; tsr = TRUE; return_user(); break; /* Get default BPB */ case 0x1f: /* Get DPB */ case 0x32: /* r->DL is NOT changed by MS 6.22 */ /* INT21/32 is documented to reread the DPB */ { struct dpb FAR *dpb; UCOUNT drv = r->DL; if (drv == 0 || r->AH == 0x1f) drv = default_drive; else drv--; if (drv >= lastdrive) { r->AL = 0xFF; CritErrCode = 0x0f; break; } dpb = CDSp->cds_table[drv].cdsDpb; if (dpb == 0 || CDSp->cds_table[drv].cdsFlags & CDSNETWDRV) { r->AL = 0xFF; CritErrCode = 0x0f; break; } dpb->dpb_flags = M_CHANGED; /* force reread of drive BPB/DPB */ if (media_check(dpb) < 0) { r->AL = 0xff; CritErrCode = 0x0f; break; } r->DS = FP_SEG(dpb); r->BX = FP_OFF(dpb); r->AL = 0; } break; /* case 0x33: see int21_syscall */ /* Get InDOS flag */ case 0x34: { BYTE FAR *p; p = (BYTE FAR *) ((BYTE *) & InDOS); r->ES = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Get Interrupt Vector */ case 0x35: { BYTE FAR *p; p = getvec((COUNT) r->AL); r->ES = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Dos Get Disk Free Space */ case 0x36: DosGetFree( r->DL, (COUNT FAR *) & r->AX, (COUNT FAR *) & r->BX, (COUNT FAR *) & r->CX, (COUNT FAR *) & r->DX); break; /* Undocumented Get/Set Switchar */ case 0x37: switch (r->AL) { /* Get switch character */ case 0x00: r->DL = switchar; r->AL = 0x00; break; /* Set switch character */ case 0x01: switchar = r->DL; r->AL = 0x00; break; default: goto error_invalid; } break; /* Get/Set Country Info */ case 0x38: { UWORD cntry = r->AL; if(cntry == 0) cntry = (UWORD)-1; else if(cntry == 0xff) cntry = r->BX; if (0xffff == r->DX) { /* Set Country Code */ if((rc = DosSetCountry(cntry)) < 0) goto error_invalid; } else { /* Get Country Information */ if((rc = DosGetCountryInformation(cntry, FP_DS_DX)) < 0) goto error_invalid; /* HACK FIXME */ if(cntry == (UWORD)-1) cntry = 1; /* END OF HACK */ r->AX = r->BX = cntry; } } break; /* Dos Create Directory */ case 0x39: rc = DosMkdir((BYTE FAR *) FP_DS_DX); if (rc != SUCCESS) goto error_exit; break; /* Dos Remove Directory */ case 0x3a: rc = DosRmdir((BYTE FAR *) FP_DS_DX); if (rc != SUCCESS) goto error_exit; break; /* Dos Change Directory */ case 0x3b: if ((rc = DosChangeDir((BYTE FAR *) FP_DS_DX)) < 0) goto error_exit; break; /* Dos Create File */ case 0x3c: if ((rc = DosCreat(FP_DS_DX, r->CX)) < 0) goto error_exit; else r->AX = rc; break; /* Dos Open */ case 0x3d: if ((rc = DosOpen(FP_DS_DX, r->AL)) < 0) goto error_exit; else r->AX = rc; break; /* Dos Close */ case 0x3e: if ((rc = DosClose(r->BX)) < 0) goto error_exit; break; /* Dos Read */ case 0x3f: rc1 = DosRead(r->BX, r->CX, FP_DS_DX, (COUNT FAR *) & rc); if (rc != SUCCESS) goto error_exit; else r->AX = rc1; break; /* Dos Write */ case 0x40: rc1 = DosWrite(r->BX, r->CX, FP_DS_DX, (COUNT FAR *) & rc); if (rc != SUCCESS) goto error_exit; else r->AX = rc1; break; /* Dos Delete File */ case 0x41: rc = DosDelete((BYTE FAR *) FP_DS_DX); if (rc < 0) goto error_exit; break; /* Dos Seek */ case 0x42: { ULONG lrc; if ((rc = DosSeek(r->BX, (LONG) ((((LONG) (r->CX)) << 16) + r->DX), r->AL, &lrc)) < 0) goto error_exit; else { r->DX = (lrc >> 16); r->AX = (UWORD)lrc; } } break; /* Get/Set File Attributes */ case 0x43: switch (r->AL) { case 0x00: rc = DosGetFattr((BYTE FAR *) FP_DS_DX); if (rc >= SUCCESS) r->CX = rc; break; case 0x01: rc = DosSetFattr((BYTE FAR *) FP_DS_DX, r->CX); break; default: goto error_invalid; } if (rc < SUCCESS) goto error_exit; break; /* Device I/O Control */ case 0x44: rc = DosDevIOctl(r); if (rc != SUCCESS) goto error_exit; break; /* Duplicate File Handle */ case 0x45: rc = DosDup(r->BX); if (rc < SUCCESS) goto error_exit; else r->AX = rc; break; /* Force Duplicate File Handle */ case 0x46: rc = DosForceDup(r->BX, r->CX); if (rc < SUCCESS) goto error_exit; break; /* Get Current Directory */ case 0x47: if ((rc = DosGetCuDir(r->DL, MK_FP(r->DS, r->SI))) < 0) goto error_exit; else r->AX = 0x0100; /*jpp: from interrupt list */ break; /* Allocate memory */ case 0x48: if ((rc = DosMemAlloc(r->BX, mem_access_mode, &(r->AX), &(r->BX))) < 0) { DosMemLargest(&(r->BX)); goto error_exit; } else ++(r->AX); /* DosMemAlloc() returns seg of MCB rather than data */ break; /* Free memory */ case 0x49: if ((rc = DosMemFree((r->ES) - 1)) < 0) goto error_exit; break; /* Set memory block size */ case 0x4a: { UWORD maxSize; if ((rc = DosMemChange(r->ES, r->BX, &maxSize)) < 0) { if (rc == DE_NOMEM) r->BX = maxSize; #if 0 if (cu_psp == r->ES) { psp FAR *p; p = MK_FP(cu_psp, 0); p->ps_size = r->BX + cu_psp; } #endif goto error_exit; } break; } /* Load and Execute Program */ case 0x4b: break_flg = FALSE; if ((rc = DosExec(r->AL, MK_FP(r->ES, r->BX), FP_DS_DX)) != SUCCESS) goto error_exit; break; /* Terminate Program */ case 0x00: r->AX = 0x4c00; /* End Program */ case 0x4c: if (cu_psp == RootPsp || ((psp FAR *) (MK_FP(cu_psp, 0)))->ps_parent == cu_psp) break; tsr = FALSE; if (ErrorMode) { ErrorMode = FALSE; return_mode = 2; } else if (break_flg) { break_flg = FALSE; return_mode = 1; } else { return_mode = 0; } return_code = r->AL; if (DosMemCheck() != SUCCESS) panic("MCB chain corrupted"); #ifdef TSC StartTrace(); #endif return_user(); break; /* Get Child-program Return Value */ case 0x4d: r->AL = return_code; r->AH = return_mode; break; /* Dos Find First */ case 0x4e: /* dta for this call is set on entry. This */ /* needs to be changed for new versions. */ if ((rc = DosFindFirst((UCOUNT) r->CX, (BYTE FAR *) FP_DS_DX)) < 0) goto error_exit; r->AX = 0; break; /* Dos Find Next */ case 0x4f: /* dta for this call is set on entry. This */ /* needs to be changed for new versions. */ if ((rc = DosFindNext()) < 0) { if (rc == DE_FILENOTFND) rc = DE_NFILES; goto error_exit; } else r->AX = -SUCCESS; break; /* case 0x50: case 0x51: see int21_syscall */ /* ************UNDOCUMENTED************************************* */ /* Get List of Lists */ case 0x52: { BYTE FAR *p; p = (BYTE FAR *) & DPBp; r->ES = FP_SEG(p); r->BX = FP_OFF(p); } break; case 0x53: /* DOS 2+ internal - TRANSLATE BIOS PARAMETER BLOCK TO DRIVE PARAM BLOCK */ bpb_to_dpb((bpb FAR *)MK_FP(r->DS, r->SI), (struct dpb FAR *)MK_FP(r->ES, r->BP)); break; /* Get verify state */ case 0x54: r->AL = (verify_ena ? TRUE : FALSE); break; /* ************UNDOCUMENTED************************************* */ /* Dos Create New Psp & set p_size */ case 0x55: new_psp((psp FAR *) MK_FP(r->DX, 0), r->SI); cu_psp = r->DX; break; /* Dos Rename */ case 0x56: rc = DosRename((BYTE FAR *) FP_DS_DX, (BYTE FAR *) MK_FP(r->ES, r->DI)); if (rc < SUCCESS) goto error_exit; else CLEAR_CARRY_FLAG(); break; /* Get/Set File Date and Time */ case 0x57: CLEAR_CARRY_FLAG(); switch (r->AL) { case 0x00: rc = DosGetFtime( (COUNT) r->BX, /* Handle */ (date FAR *) & r->DX, /* FileDate */ (time FAR *) & r->CX); /* FileTime */ if (rc < SUCCESS) goto error_exit; break; case 0x01: rc = DosSetFtime( (COUNT) r->BX, /* Handle */ (date) r->DX, /* FileDate */ (time) r->CX); /* FileTime */ if (rc < SUCCESS) goto error_exit; break; default: goto error_invalid; } break; /* Get/Set Allocation Strategy */ case 0x58: CLEAR_CARRY_FLAG(); switch (r->AL) { case 0x00: r->AL = mem_access_mode; r->AH = 0; break; case 0x01: { switch (r->BL) { case LAST_FIT: case LAST_FIT_U: case LAST_FIT_UO: case BEST_FIT: case BEST_FIT_U: case BEST_FIT_UO: case FIRST_FIT: case FIRST_FIT_U: case FIRST_FIT_UO: mem_access_mode = r->BL; break; default: goto error_invalid; } } break; case 0x02: r->AL = uppermem_link; break; case 0x03: if (uppermem_root) { DosUmbLink(r->BL); break; } /* else fall through */ default: goto error_invalid; #ifdef DEBUG case 0xff: show_chain(); break; #endif } break; /* Get Extended Error */ case 0x59: r->AX = CritErrCode; r->ES = FP_SEG(CritErrDev); r->DI = FP_OFF(CritErrDev); r->CH = CritErrLocus; r->BH = CritErrClass; r->BL = CritErrAction; CLEAR_CARRY_FLAG(); break; /* Create Temporary File */ case 0x5a: if ((rc = DosMkTmp(FP_DS_DX, r->CX)) < 0) goto error_exit; else { r->AX = rc; CLEAR_CARRY_FLAG(); } break; /* Create New File */ case 0x5b: if (!IsDevice(FP_DS_DX) && (rc = DosOpen(FP_DS_DX, 0)) >= 0) { DosClose(rc); r->AX = 80; goto error_out; } else { if ((rc = DosCreat(FP_DS_DX, r->CX)) < 0) goto error_exit; else { r->AX = rc; CLEAR_CARRY_FLAG(); } } break; /* /// Added for SHARE. - Ron Cemer */ /* Lock/unlock file access */ case 0x5c: if ((rc = DosLockUnlock (r->BX, (((unsigned long)r->CX)<<16)|(((unsigned long)r->DX)&0xffffL), (((unsigned long)r->SI)<<16)|(((unsigned long)r->DI)&0xffffL), ((r->AX & 0xff) != 0))) != 0) goto error_exit; CLEAR_CARRY_FLAG(); break; /* /// End of additions for SHARE. - Ron Cemer */ /* UNDOCUMENTED: server, share.exe and sda function */ case 0x5d: switch (r->AL) { /* Remote Server Call */ case 0x00: { UWORD FAR *x = FP_DS_DX; r->AX = x[0]; r->BX = x[1]; r->CX = x[2]; r->DX = x[3]; r->SI = x[4]; r->DI = x[5]; r->DS = x[6]; r->ES = x[7]; } goto dispatch; case 0x06: r->DS = FP_SEG(internal_data); r->SI = FP_OFF(internal_data); r->CX = swap_always - internal_data; r->DX = swap_indos - internal_data; CLEAR_CARRY_FLAG(); break; case 0x07: case 0x08: case 0x09: rc = -int2f_Remote_call(REM_PRINTREDIR, 0, 0, r->DX, 0, 0, (MK_FP(0, Int21AX))); if (rc != SUCCESS) goto error_exit; CLEAR_CARRY_FLAG(); break; default: goto error_invalid; } break; case 0x5e: CLEAR_CARRY_FLAG(); switch (r->AL) { case 0x00: r->CX = get_machine_name(FP_DS_DX); break; case 0x01: set_machine_name(FP_DS_DX, r->CX); break; default: rc = -int2f_Remote_call(REM_PRINTSET, r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX))); if (rc != SUCCESS) goto error_exit; r->AX=SUCCESS; break; } break; case 0x5f: CLEAR_CARRY_FLAG(); switch (r->AL) { case 0x07: if (r->DL < lastdrive) { CDSp->cds_table[r->DL].cdsFlags |= 0x100; } break; case 0x08: if (r->DL < lastdrive) { CDSp->cds_table[r->DL].cdsFlags &= ~0x100; } break; default: /* void int_2f_111e_call(iregs FAR *r); int_2f_111e_call(r); break;*/ rc = -int2f_Remote_call(REM_DOREDIRECT, r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX))); if (rc != SUCCESS) goto error_exit; r->AX=SUCCESS; break; } break; case 0x60: /* TRUENAME */ CLEAR_CARRY_FLAG(); if ((rc = truename(MK_FP(r->DS, r->SI), adjust_far(MK_FP(r->ES, r->DI)), FALSE)) != SUCCESS) goto error_exit; break; #ifdef TSC /* UNDOCUMENTED: no-op */ /* */ /* DOS-C: tsc support */ case 0x61: #ifdef DEBUG switch (r->AL) { case 0x01: bTraceNext = TRUE; break; case 0x02: bDumpRegs = FALSE; break; } #endif r->AL = 0x00; break; #endif /* UNDOCUMENTED: return current psp case 0x62: is in int21_syscall r->BX = cu_psp; break; */ /* UNDOCUMENTED: Double byte and korean tables */ case 0x63: { #define DBLBYTE #ifdef DBLBYTE static char dbcsTable[2] = { 0, 0 }; void FAR *dp = &dbcsTable; r->DS = FP_SEG(dp); r->SI = FP_OFF(dp); r->AL = 0; #else /* not really supported, but will pass. */ r->AL = 0x00; /*jpp: according to interrupt list */ /*Bart: fails for PQDI: use the above again */ #endif break; } /* case 0x64: see above (invalid) */ /* Extended country info */ case 0x65: switch(r->AL) { case 0x20: /* upcase single character */ r->DL = DosUpChar(r->DL); break; case 0x21: /* upcase memory area */ DosUpMem(FP_DS_DX, r->CX); break; case 0x22: /* upcase ASCIZ */ DosUpString(FP_DS_DX); break; case 0xA0: /* upcase single character of filenames */ r->DL = DosUpFChar(r->DL); break; case 0xA1: /* upcase memory area of filenames */ DosUpFMem(FP_DS_DX, r->CX); break; case 0xA2: /* upcase ASCIZ of filenames */ DosUpFString(FP_DS_DX); break; case 0x23: /* check Yes/No response */ r->AX = DosYesNo(r->DL); break; default: if ((rc = DosGetData( r->AL, r->BX, r->DX, r->CX, MK_FP(r->ES, r->DI))) < 0) { #ifdef NLS_DEBUG printf("DosGetData() := %d\n", rc); #endif goto error_exit; } #ifdef NLS_DEBUG printf("DosGetData() returned successfully\n", rc); #endif break; } CLEAR_CARRY_FLAG(); break; /* Code Page functions */ case 0x66: { int rc; switch (r->AL) { case 1: rc = DosGetCodepage(&r->BX, &r->DX); break; case 2: rc = DosSetCodepage(r->BX, r->DX); break; default: goto error_invalid; } if(rc != SUCCESS) goto error_exit; CLEAR_CARRY_FLAG(); break; } /* Set Max file handle count */ case 0x67: if ((rc = SetJFTSize(r->BX)) != SUCCESS) goto error_exit; else CLEAR_CARRY_FLAG(); break; /* Flush file buffer -- COMMIT FILE -- dummy function right now. */ case 0x68: case 0x6a: CLEAR_CARRY_FLAG(); break; /* Get/Set Serial Number */ case 0x69: rc = ( r->BL == 0 ? default_drive : r->BL - 1); if (rc < lastdrive) { UWORD saveCX = r->CX; if (CDSp->cds_table[rc].cdsFlags & CDSNETWDRV) { goto error_invalid; } switch(r->AL){ case 0x00: r->AL = 0x0d; r->CX = 0x0866; rc = DosDevIOctl(r); break; case 0x01: r->AL = 0x0d; r->CX = 0x0846; rc = DosDevIOctl(r); break; } r->CX = saveCX; if (rc != SUCCESS) goto error_exit; CLEAR_CARRY_FLAG(); break; } else r->AL = 0xFF; break; /* case 0x6a: see case 0x68 case 0x6b: dummy func: return AL=0 */ /* Extended Open-Creat, not fully functional. (bits 4,5,6 of BH) */ case 0x6c: { COUNT x = 0; if (r->AL != 0 || r->DH != 0 || (r->DL&0x0f) > 0x2 || (r->DL&0xf0) > 0x10) goto error_invalid; CLEAR_CARRY_FLAG(); if ((rc = DosOpen(MK_FP(r->DS, r->SI), (r->DL&0x0f) == 0x1 ? r->BL : 0)) < 0) { if (r->DL < 0x10) goto error_exit; /* else try to create below */ } else switch (r->DL & 0x0f) { case 0x0: /* fail if file exists */ DosClose(rc); rc = DE_FILEEXISTS; goto error_exit; case 0x1: /* file exists and opened: OK */ r->CX = 0x01; goto break_out; case 0x2: /* file exists: replace/open */ DosClose(rc); x = 1; break; } /* cases 0x00, 0x01 are finished now */ if ((rc = DosCreat(MK_FP(r->DS, r->SI), r->CX)) < 0) goto error_exit; r->CX = x+2; break_out: r->AX = rc; break; } /* case 0x6d and above not implemented : see default; return AL=0 */ } #ifdef DEBUG if (bDumpRegs) { fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs, sizeof(iregs)); dump_regs = TRUE; dump(); } #endif }
static HB_BOOL hb_fsFindNextLow( PHB_FFIND ffind ) { HB_BOOL bFound; int iYear = 0; int iMonth = 0; int iDay = 0; int iHour = 0; int iMin = 0; int iSec = 0; HB_FATTR raw_attr = 0, nAttr = 0; /* Set the default values in case some platforms don't support some of these, or they may fail on them. */ ffind->szName[ 0 ] = '\0'; ffind->size = 0; /* Do platform dependant first/next search */ hb_vmUnlock(); #if defined( HB_OS_DOS ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; /* Handling HB_FA_LABEL doesn't need any special tricks under the MS-DOS platform. */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; /* tzset(); */ #if defined( __WATCOMC__ ) bFound = ( _dos_findfirst( ffind->pszFileMask, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ), &info->entry ) == 0 ); #else bFound = ( findfirst( ffind->pszFileMask, &info->entry, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ) ) == 0 ); #endif } else { #if defined( __WATCOMC__ ) bFound = ( _dos_findnext( &info->entry ) == 0 ); #else bFound = ( findnext( &info->entry ) == 0 ); #endif } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( ffind->szName, info->entry.ff_name, sizeof( ffind->szName ) - 1 ); ffind->size = info->entry.ff_fsize; raw_attr = info->entry.ff_attrib; { time_t ftime; struct tm * ft; struct stat sStat; stat( info->entry.ff_name, &sStat ); ftime = sStat.st_mtime; ft = localtime( &ftime ); iYear = ft->tm_year + 1900; iMonth = ft->tm_mon + 1; iDay = ft->tm_mday; iHour = ft->tm_hour; iMin = ft->tm_min; iSec = ft->tm_sec; } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_OS2 ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; APIRET rc = NO_ERROR; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; /* tzset(); */ info->hFindFile = HDIR_CREATE; info->findCount = 128; rc = DosAllocMem( ( PPVOID ) &info->entry, 4 * 1024, OBJ_TILE | PAG_COMMIT | PAG_WRITE ); if( rc == NO_ERROR ) { bFound = DosFindFirst( ( PCSZ ) ffind->pszFileMask, &info->hFindFile, ( ULONG ) hb_fsAttrToRaw( ffind->attrmask ), info->entry, 4 * 1024, &info->findCount, FIL_STANDARD ) == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } else { info->entry = NULL; bFound = HB_FALSE; } } else { if( info->findCount > 0 ) bFound = HB_TRUE; else { info->findCount = 128; bFound = DosFindNext( info->hFindFile, info->entry, 4 * 1024, &info->findCount ) == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } } if( bFound ) { hb_strncpy( ffind->szName, info->next->achName, sizeof( ffind->szName ) - 1 ); ffind->size = info->next->cbFile; raw_attr = info->next->attrFile; iYear = info->next->fdateLastWrite.year + 1980; iMonth = info->next->fdateLastWrite.month; iDay = info->next->fdateLastWrite.day; iHour = info->next->ftimeLastWrite.hours; iMin = info->next->ftimeLastWrite.minutes; iSec = info->next->ftimeLastWrite.twosecs; if( info->next->oNextEntryOffset > 0 ) { info->next = ( PFILEFINDBUF3 )( ( char * ) info->next + info->next->oNextEntryOffset ); info->findCount--; } else info->findCount = 0; } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_WIN ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; bFound = HB_FALSE; #if ! defined( HB_OS_WIN_CE ) if( ( ffind->attrmask & HB_FA_LABEL ) != 0 && ! info->fLabelDone ) { TCHAR lpVolName[ HB_PATH_MAX ]; LPTSTR lpFileMask = NULL; char * mask = NULL; info->fLabelDone = HB_TRUE; if( ffind->pszFileMask && *ffind->pszFileMask ) { PHB_FNAME pFileName = hb_fsFNameSplit( ffind->pszFileMask ); if( pFileName->szName && pFileName->szName[ 0 ] ) mask = hb_strdup( pFileName->szName ); if( pFileName->szPath && pFileName->szPath[ 0 ] && ( pFileName->szPath[ 1 ] || pFileName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR ) ) lpFileMask = HB_CHARDUP( pFileName->szPath ); hb_xfree( pFileName ); } bFound = GetVolumeInformation( lpFileMask, lpVolName, HB_SIZEOFARRAY( lpVolName ), NULL, NULL, NULL, NULL, 0 ) != 0; if( bFound ) { HB_OSSTRDUP2( lpVolName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( mask && *mask && ! hb_strMatchFile( ffind->szName, mask ) ) { ffind->szName[ 0 ] = '\0'; bFound = HB_FALSE; } } if( lpFileMask ) hb_xfree( lpFileMask ); if( mask ) hb_xfree( mask ); } #endif if( ! bFound && ( ffind->attrmask & ( HB_FA_LABEL | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY ) ) != HB_FA_LABEL ) { if( ffind->bFirst ) { LPTSTR lpFileMask = HB_CHARDUP( ffind->pszFileMask ); ffind->bFirst = HB_FALSE; info->dwAttr = ( DWORD ) hb_fsAttrToRaw( ffind->attrmask ); info->hFindFile = FindFirstFile( lpFileMask, &info->pFindFileData ); hb_xfree( lpFileMask ); if( ( info->hFindFile != INVALID_HANDLE_VALUE ) && _HB_WIN_MATCH() ) bFound = HB_TRUE; } if( ! bFound && info->hFindFile != INVALID_HANDLE_VALUE ) { while( FindNextFile( info->hFindFile, &info->pFindFileData ) ) { if( _HB_WIN_MATCH() ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { HB_OSSTRDUP2( info->pFindFileData.cFileName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( info->pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ffind->size = 0; else { #if defined( __XCC__ ) || ( defined( __POCC__ ) && __POCC__ >= 500 ) /* NOTE: PellesC 5.00.1 will go into an infinite loop if we don't split this into two operations. [vszakats] */ ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow; ffind->size += ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32; #else ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow + ( ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32 ); #endif } raw_attr = ( HB_FATTR ) info->pFindFileData.dwFileAttributes; /* NOTE: One of these may fail when searching on an UNC path, I don't know yet what's the reason. [vszakats] */ { FILETIME ft; SYSTEMTIME time; if( FileTimeToLocalFileTime( &info->pFindFileData.ftLastWriteTime, &ft ) && FileTimeToSystemTime( &ft, &time ) ) { iYear = time.wYear; iMonth = time.wMonth; iDay = time.wDay; iHour = time.wHour; iMin = time.wMinute; iSec = time.wSecond; } } } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_UNIX ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; char dirname[ HB_PATH_MAX ]; bFound = HB_FALSE; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { char * pos; ffind->bFirst = HB_FALSE; hb_strncpy( dirname, ffind->pszFileMask, sizeof( dirname ) - 1 ); pos = strrchr( dirname, HB_OS_PATH_DELIM_CHR ); if( pos ) { hb_strncpy( info->pattern, pos + 1, sizeof( info->pattern ) - 1 ); *( pos + 1 ) = '\0'; } else { hb_strncpy( info->pattern, dirname, sizeof( info->pattern ) - 1 ); dirname[ 0 ] = '.'; dirname[ 1 ] = HB_OS_PATH_DELIM_CHR; dirname[ 2 ] = '\0'; } /* tzset(); */ info->dir = opendir( dirname ); hb_strncpy( info->path, dirname, sizeof( info->path ) - 1 ); } if( info->dir && info->pattern[ 0 ] != '\0' ) { while( ( info->entry = readdir( info->dir ) ) != NULL ) { if( hb_strMatchFile( info->entry->d_name, info->pattern ) ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( dirname, info->path, sizeof( dirname ) - 1 ); hb_strncat( dirname, info->entry->d_name, sizeof( dirname ) - 1 ); { time_t ftime; struct tm lt; #if defined( HB_USE_LARGEFILE64 ) struct stat64 sStat, sStatL; if( lstat64( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) ) { if( stat64( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #else struct stat sStat, sStatL; if( lstat( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) ) { if( stat( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #endif hb_strncpy( ffind->szName, info->entry->d_name, sizeof( ffind->szName ) - 1 ); ffind->size = sStat.st_size; raw_attr = sStat.st_mode; ftime = sStat.st_mtime; # if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, < ); # else lt = *localtime( &ftime ); # endif iYear = lt.tm_year + 1900; iMonth = lt.tm_mon + 1; iDay = lt.tm_mday; iHour = lt.tm_hour; iMin = lt.tm_min; iSec = lt.tm_sec; } else bFound = HB_FALSE; } } hb_fsSetIOError( bFound, 0 ); } #else { int iTODO; /* TODO: for given platform */ /* HB_SYMBOL_UNUSED( ffind ); */ HB_SYMBOL_UNUSED( iYear ); HB_SYMBOL_UNUSED( iMonth ); HB_SYMBOL_UNUSED( iDay ); HB_SYMBOL_UNUSED( iHour ); HB_SYMBOL_UNUSED( iMin ); HB_SYMBOL_UNUSED( iSec ); HB_SYMBOL_UNUSED( raw_attr ); bFound = HB_FALSE; hb_fsSetIOError( bFound, 0 ); } #endif /* Fill common Harbour found file info */ if( bFound ) { /* Do the conversions common for all platforms */ ffind->szName[ sizeof( ffind->szName ) - 1 ] = '\0'; #if ! defined( HB_OS_WIN ) /* Convert from OS codepage */ { char * pszFree = NULL; HB_SIZE nSize = sizeof( ffind->szName ); const char * pszResult = hb_osDecodeCP( ffind->szName, &pszFree, &nSize ); if( pszFree ) { hb_strncpy( ffind->szName, pszResult, sizeof( ffind->szName ) - 1 ); hb_xfree( pszFree ); } } #endif ffind->attr = hb_fsAttrFromRaw( raw_attr ) | nAttr; ffind->lDate = hb_dateEncode( iYear, iMonth, iDay ); hb_dateStrPut( ffind->szDate, iYear, iMonth, iDay ); ffind->szDate[ 8 ] = '\0'; hb_snprintf( ffind->szTime, sizeof( ffind->szTime ), "%02d:%02d:%02d", iHour, iMin, iSec ); } hb_vmLock(); return bFound; } PHB_FFIND hb_fsFindFirst( const char * pszFileMask, HB_FATTR attrmask ) { PHB_FFIND ffind; ffind = ( PHB_FFIND ) hb_xgrab( sizeof( HB_FFIND ) ); memset( ffind, 0, sizeof( HB_FFIND ) ); /* Allocate platform dependent file find info storage */ ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) ); memset( ffind->info, 0, sizeof( HB_FFIND_INFO ) ); /* Store search parameters */ #if defined( HB_OS_WIN ) ffind->pszFileMask = pszFileMask; #else /* Convert to OS codepage */ ffind->pszFileMask = hb_fsNameConv( pszFileMask, &ffind->pszFree ); #endif ffind->attrmask = attrmask; ffind->bFirst = HB_TRUE; /* Find first/next matching file */ if( hb_fsFindNext( ffind ) ) return ffind; /* If no file found at all, free stuff allocated so far and return NULL. */ hb_fsFindClose( ffind ); return NULL; }
//------------------------------ CMD_GetFileInfo ------------------------------- void CMD_GetFileInfo(HFILE hFile,LXIOCPA_DMN_CMDPARMPACKET* pParam ,PLXGETFILEINFOSTRUCT pf) { ULONG rc; ULONG blen; CHAR filemask[CCHMAXPATH]; CHAR tmp[LX_MAXPATH]; pf->num_subdirs=0; pf->num_files=0; pf->mode=0; pf->uid=0; pf->gid=0; pf->lc_count=0; pf->link_broken=0; pf->flags=0; memset(pf->linkName,0,LX_MAXPATH); // Get Info rc=DosQueryPathInfo(pf->fileName,FIL_QUERYEASIZE,&pf->fs4,sizeof(FILESTATUS4)); if(!rc) { // If it is a directory, get number of subdirs and files if(pf->fs4.attrFile&FILE_DIRECTORY) { HDIR hDir=HDIR_CREATE; FILEFINDBUF3 fb; ULONG ulFindCount=1; strcpy(filemask,pf->fileName); strcat(filemask,"/*"); rc=DosFindFirst(filemask,&hDir ,FILE_ARCHIVED|FILE_DIRECTORY|FILE_SYSTEM|FILE_HIDDEN|FILE_READONLY ,&fb,sizeof(FILEFINDBUF3) ,&ulFindCount ,FIL_STANDARD); while(!rc && ulFindCount>0) { if(fb.attrFile&FILE_DIRECTORY) pf->num_subdirs++; else pf->num_files++; rc=DosFindNext(hDir,&fb,sizeof(FILEFINDBUF3),&ulFindCount); } DosFindClose(hDir); rc=0; } // If it contains EA's, try to get LX_LC (link count) if(pf->fs4.cbList>4) { blen=CCHMAXPATH; eahReadStringEA(pf->fileName,LXEAN_LINKEDTO,pf->linkName,&blen); blen=CCHMAXPATH; strcpy(filemask,"0"); eahReadStringEA(pf->fileName,LXEAN_LINKBYCOUNT,filemask,&blen); pf->lc_count=atoi(filemask); // Check, if link target exists if(strcmp(pf->fileName,pf->linkName)) { FILESTATUS4 fs4; if(DosQueryPathInfo(pf->linkName,FIL_QUERYEASIZE,&fs4,sizeof(FILESTATUS4))) { pf->link_broken=1; memset(pf->linkName,0,LX_MAXPATH); } } else memset(pf->linkName,0,LX_MAXPATH); } blen=LX_MAXPATH; if(!eahReadStringEA(pf->fileName,LXEAN_MODE,tmp,&blen)) { pf->mode=atoi(tmp); pf->flags|=LXGETFILEINFOFLAG_MODE; } blen=LX_MAXPATH; if(!eahReadStringEA(pf->fileName,LXEAN_UID,tmp,&blen)) { pf->uid=atoi(tmp); pf->flags|=LXGETFILEINFOFLAG_UID; } blen=LX_MAXPATH; if(!eahReadStringEA(pf->fileName,LXEAN_GID,tmp,&blen)) { pf->gid=atoi(tmp); pf->flags|=LXGETFILEINFOFLAG_GID; } // SYMLINK !!! } pParam->rc=rc; }
VOID int21_service(iregs FAR * r) { COUNT rc, rc1; ULONG lrc; psp FAR *p = MK_FP(cu_psp, 0); p->ps_stack = (BYTE FAR *) r; #ifdef DEBUG if (bDumpRegs) { fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs, sizeof(iregs)); printf("System call (21h): %02x\n", user_r->AX); dump_regs = TRUE; dump(); } #endif dispatch: /* Check for Ctrl-Break */ switch (r->AH) { default: if (!break_ena) break; case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x08: case 0x09: case 0x0a: case 0x0b: if (control_break()) handle_break(); } /* The dispatch handler */ switch (r->AH) { /* int 21h common error handler */ case 0x64: case 0x6b: default: error_invalid: r->AX = -DE_INVLDFUNC; goto error_out; error_exit: r->AX = -rc; error_out: r->FLAGS |= FLG_CARRY; break; #if 0 /* Moved to simulate a 0x4c00 -- 1999/04/21 ska */ /* Terminate Program */ case 0x00: if (cu_psp == RootPsp) break; else if (((psp FAR *) (MK_FP(cu_psp, 0)))->ps_parent == cu_psp) break; tsr = FALSE; return_mode = break_flg ? 1 : 0; return_code = r->AL; if (DosMemCheck() != SUCCESS) panic("MCB chain corrupted"); #ifdef TSC StartTrace(); #endif return_user(); break; #endif /* Read Keyboard with Echo */ case 0x01: Do_DosIdle_loop(); r->AL = _sti(); sto(r->AL); break; /* Display Character */ case 0x02: sto(r->DL); break; /* Auxiliary Input */ case 0x03: r->AL = _sti(); break; /* Auxiliary Output */ case 0x04: sto(r->DL); break; /* Print Character */ case 0x05: sto(r->DL); break; /* Direct Cosole I/O */ case 0x06: if (r->DL != 0xff) sto(r->DL); else if (StdinBusy()) { r->AL = 0x00; r->FLAGS |= FLG_ZERO; } else { r->FLAGS &= ~FLG_ZERO; r->AL = _sti(); } break; /* Direct Console Input */ case 0x07: /* Read Keyboard Without Echo */ case 0x08: Do_DosIdle_loop(); r->AL = _sti(); break; /* Display String */ case 0x09: { static COUNT scratch; BYTE FAR *p = MK_FP(r->DS, r->DX), FAR * q; q = p; while (*q != '$') ++q; DosWrite(STDOUT, q - p, p, (COUNT FAR *) & scratch); } r->AL = '$'; break; /* Buffered Keyboard Input */ case 0x0a: ((keyboard FAR *) MK_FP(r->DS, r->DX))->kb_count = 0; sti((keyboard FAR *) MK_FP(r->DS, r->DX)); ((keyboard FAR *) MK_FP(r->DS, r->DX))->kb_count -= 2; break; /* Check Stdin Status */ case 0x0b: if (StdinBusy()) r->AL = 0xFF; else r->AL = 0x00; break; /* Flush Buffer, Read Keayboard */ case 0x0c: KbdFlush(); switch (r->AL) { case 0x01: case 0x06: case 0x07: case 0x08: case 0x0a: r->AH = r->AL; goto dispatch; default: r->AL = 0x00; break; } break; /* Reset Drive */ case 0x0d: flush(); break; /* Set Default Drive */ case 0x0e: r->AL = DosSelectDrv(r->DL); break; case 0x0f: if (FcbOpen(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; case 0x10: if (FcbClose(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; case 0x11: if (FcbFindFirst(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; case 0x12: if (FcbFindNext(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; case 0x13: if (FcbDelete(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; case 0x14: { COUNT nErrorCode; if (FcbRead(MK_FP(r->DS, r->DX), &nErrorCode)) r->AL = 0; else r->AL = nErrorCode; break; } case 0x15: { COUNT nErrorCode; if (FcbWrite(MK_FP(r->DS, r->DX), &nErrorCode)) r->AL = 0; else r->AL = nErrorCode; break; } case 0x16: if (FcbCreate(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; case 0x17: if (FcbRename(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; /* CP/M compatibility functions */ case 0x18: case 0x1d: case 0x1e: case 0x20: #ifndef TSC case 0x61: #endif r->AL = 0; break; /* Get Default Drive */ case 0x19: r->AL = default_drive; break; /* Set DTA */ case 0x1a: { psp FAR *p = MK_FP(cu_psp, 0); p->ps_dta = MK_FP(r->DS, r->DX); dos_setdta(p->ps_dta); } break; /* Get Default Drive Data */ case 0x1b: { BYTE FAR *p; FatGetDrvData(0, (COUNT FAR *) & r->AX, (COUNT FAR *) & r->CX, (COUNT FAR *) & r->DX, (BYTE FAR **) & p); r->DS = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Get Drive Data */ case 0x1c: { BYTE FAR *p; FatGetDrvData(r->DL, (COUNT FAR *) & r->AX, (COUNT FAR *) & r->CX, (COUNT FAR *) & r->DX, (BYTE FAR **) & p); r->DS = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Get default DPB */ case 0x1f: if (default_drive < lastdrive) { struct dpb FAR *dpb = (struct dpb FAR *)CDSp->cds_table[default_drive].cdsDpb; if (dpb == 0) { r->AL = 0xff; break; } r->DS = FP_SEG(dpb); r->BX = FP_OFF(dpb); r->AL = 0; } else r->AL = 0xff; break; /* Random read using FCB */ case 0x21: { COUNT nErrorCode; if (FcbRandomRead(MK_FP(r->DS, r->DX), &nErrorCode)) r->AL = 0; else r->AL = nErrorCode; break; } /* Random write using FCB */ case 0x22: { COUNT nErrorCode; if (FcbRandomWrite(MK_FP(r->DS, r->DX), &nErrorCode)) r->AL = 0; else r->AL = nErrorCode; break; } /* Get file size in records using FCB */ case 0x23: if (FcbGetFileSize(MK_FP(r->DS, r->DX))) r->AL = 0; else r->AL = 0xff; break; /* Set random record field in FCB */ case 0x24: FcbSetRandom(MK_FP(r->DS, r->DX)); break; /* Set Interrupt Vector */ case 0x25: { VOID(INRPT FAR * p) () = MK_FP(r->DS, r->DX); setvec(r->AL, p); } break; /* Dos Create New Psp */ case 0x26: { psp FAR *p = MK_FP(cu_psp, 0); new_psp((psp FAR *) MK_FP(r->DX, 0), p->ps_size); } break; /* Read random record(s) using FCB */ case 0x27: { COUNT nErrorCode; if (FcbRandomBlockRead(MK_FP(r->DS, r->DX), r->CX, &nErrorCode)) r->AL = 0; else r->AL = nErrorCode; break; } /* Write random record(s) using FCB */ case 0x28: { COUNT nErrorCode; if (FcbRandomBlockWrite(MK_FP(r->DS, r->DX), r->CX, &nErrorCode)) r->AL = 0; else r->AL = nErrorCode; break; } /* Parse File Name */ case 0x29: { BYTE FAR *lpFileName; lpFileName = MK_FP(r->DS, r->SI); r->AL = FcbParseFname(r->AL, &lpFileName, MK_FP(r->ES, r->DI)); r->DS = FP_SEG(lpFileName); r->SI = FP_OFF(lpFileName); } break; /* Get Date */ case 0x2a: DosGetDate( (BYTE FAR *) & (r->AL), /* WeekDay */ (BYTE FAR *) & (r->DH), /* Month */ (BYTE FAR *) & (r->DL), /* MonthDay */ (COUNT FAR *) & (r->CX)); /* Year */ break; /* Set Date */ case 0x2b: rc = DosSetDate( (BYTE FAR *) & (r->DH), /* Month */ (BYTE FAR *) & (r->DL), /* MonthDay */ (COUNT FAR *) & (r->CX)); /* Year */ if (rc != SUCCESS) r->AL = 0xff; else r->AL = 0; break; /* Get Time */ case 0x2c: DosGetTime( (BYTE FAR *) & (r->CH), /* Hour */ (BYTE FAR *) & (r->CL), /* Minutes */ (BYTE FAR *) & (r->DH), /* Seconds */ (BYTE FAR *) & (r->DL)); /* Hundredths */ break; /* Set Date */ case 0x2d: rc = DosSetTime( (BYTE FAR *) & (r->CH), /* Hour */ (BYTE FAR *) & (r->CL), /* Minutes */ (BYTE FAR *) & (r->DH), /* Seconds */ (BYTE FAR *) & (r->DL)); /* Hundredths */ if (rc != SUCCESS) r->AL = 0xff; else r->AL = 0; break; /* Set verify flag */ case 0x2e: verify_ena = (r->AL ? TRUE : FALSE); break; /* Get DTA */ case 0x2f: r->ES = FP_SEG(dta); r->BX = FP_OFF(dta); break; /* Get DOS Version */ case 0x30: r->AL = os_major; r->AH = os_minor; r->BH = OEM_ID; r->CH = REVISION_MAJOR; /* JPP */ r->CL = REVISION_MINOR; r->BL = REVISION_SEQ; break; /* Keep Program (Terminate and stay resident) */ case 0x31: DosMemChange(cu_psp, r->DX < 6 ? 6 : r->DX, 0); return_mode = 3; return_code = r->AL; tsr = TRUE; return_user(); break; /* Get DPB */ case 0x32: if (r->DL < lastdrive) { struct dpb FAR *dpb = CDSp->cds_table[r->DL].cdsDpb; if (dpb == 0) { r->AL = 0xff; break; } r->DS = FP_SEG(dpb); r->BX = FP_OFF(dpb); r->AL = 0; } else r->AL = 0xFF; break; /* Get InDOS flag */ case 0x34: { BYTE FAR *p; p = (BYTE FAR *) ((BYTE *) & InDOS); r->ES = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Get Interrupt Vector */ case 0x35: { BYTE FAR *p; p = getvec((COUNT) r->AL); r->ES = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Dos Get Disk Free Space */ case 0x36: DosGetFree( (COUNT) r->DL, (COUNT FAR *) & r->AX, (COUNT FAR *) & r->BX, (COUNT FAR *) & r->CX, (COUNT FAR *) & r->DX); break; /* Undocumented Get/Set Switchar */ case 0x37: switch (r->AL) { /* Get switch character */ case 0x00: r->DL = switchar; r->AL = 0x00; break; /* Set switch character */ case 0x01: switchar = r->DL; r->AL = 0x00; break; default: goto error_invalid; } break; /* Get/Set Country Info */ case 0x38: { BYTE FAR *lpTable = (BYTE FAR *) MK_FP(r->DS, r->DX); BYTE nRetCode; if (0xffff == r->DX) { r->BX = SetCtryInfo( (UBYTE FAR *) & (r->AL), (UWORD FAR *) & (r->BX), (BYTE FAR *) & lpTable, (UBYTE *) & nRetCode); if (nRetCode != 0) { r->AX = 0xff; r->FLAGS |= FLG_CARRY; } else { r->AX = nRetCode; r->FLAGS &= ~FLG_CARRY; } } else { r->BX = GetCtryInfo(&(r->AL), &(r->BX), lpTable); r->FLAGS &= ~FLG_CARRY; } } break; /* Dos Create Directory */ case 0x39: rc = dos_mkdir((BYTE FAR *) MK_FP(r->DS, r->DX)); if (rc != SUCCESS) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; } break; /* Dos Remove Directory */ case 0x3a: rc = dos_rmdir((BYTE FAR *) MK_FP(r->DS, r->DX)); if (rc != SUCCESS) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; } break; /* Dos Change Directory */ case 0x3b: if ((rc = DosChangeDir((BYTE FAR *) MK_FP(r->DS, r->DX))) < 0) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; } break; /* Dos Create File */ case 0x3c: if ((rc = DosCreat(MK_FP(r->DS, r->DX), r->CX)) < 0) goto error_exit; else { r->AX = rc; r->FLAGS &= ~FLG_CARRY; } break; /* Dos Open */ case 0x3d: if ((rc = DosOpen(MK_FP(r->DS, r->DX), r->AL)) < 0) goto error_exit; else { r->AX = rc; r->FLAGS &= ~FLG_CARRY; } break; /* Dos Close */ case 0x3e: if ((rc = DosClose(r->BX)) < 0) goto error_exit; else r->FLAGS &= ~FLG_CARRY; break; /* Dos Read */ case 0x3f: rc = DosRead(r->BX, r->CX, MK_FP(r->DS, r->DX), (COUNT FAR *) & rc1); if (rc1 != SUCCESS) { r->FLAGS |= FLG_CARRY; r->AX = -rc1; } else { r->FLAGS &= ~FLG_CARRY; r->AX = rc; } break; /* Dos Write */ case 0x40: rc = DosWrite(r->BX, r->CX, MK_FP(r->DS, r->DX), (COUNT FAR *) & rc1); if (rc1 != SUCCESS) { r->FLAGS |= FLG_CARRY; r->AX = -rc1; } else { r->FLAGS &= ~FLG_CARRY; r->AX = rc; } break; /* Dos Delete File */ case 0x41: rc = dos_delete((BYTE FAR *) MK_FP(r->DS, r->DX)); if (rc < 0) { r->FLAGS |= FLG_CARRY; r->AX = -rc1; } else r->FLAGS &= ~FLG_CARRY; break; /* Dos Seek */ case 0x42: if ((rc = DosSeek(r->BX, (LONG) ((((LONG) (r->CX)) << 16) + r->DX), r->AL, &lrc)) < 0) goto error_exit; else { r->DX = (lrc >> 16); r->AX = lrc & 0xffff; r->FLAGS &= ~FLG_CARRY; } break; /* Get/Set File Attributes */ case 0x43: switch (r->AL) { case 0x00: rc = DosGetFattr((BYTE FAR *) MK_FP(r->DS, r->DX), (UWORD FAR *) & r->CX); if (rc < SUCCESS) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; } break; case 0x01: rc = DosSetFattr((BYTE FAR *) MK_FP(r->DS, r->DX), (UWORD FAR *) & r->CX); if (rc != SUCCESS) goto error_exit; else r->FLAGS &= ~FLG_CARRY; break; default: goto error_invalid; } break; /* Device I/O Control */ case 0x44: { rc = DosDevIOctl(r, (COUNT FAR *) & rc1); if (rc1 != SUCCESS) { r->FLAGS |= FLG_CARRY; r->AX = -rc1; } else { r->FLAGS &= ~FLG_CARRY; } } break; /* Duplicate File Handle */ case 0x45: rc = DosDup(r->BX); if (rc < SUCCESS) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; r->AX = rc; } break; /* Force Duplicate File Handle */ case 0x46: rc = DosForceDup(r->BX, r->CX); if (rc < SUCCESS) goto error_exit; else r->FLAGS &= ~FLG_CARRY; break; /* Get Current Directory */ case 0x47: if ((rc = DosGetCuDir(r->DL, MK_FP(r->DS, r->SI))) < 0) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; r->AX = 0x0100; /*jpp: from interrupt list */ } break; /* Allocate memory */ case 0x48: if ((rc = DosMemAlloc(r->BX, mem_access_mode, &(r->AX), &(r->BX))) < 0) { DosMemLargest(&(r->BX)); goto error_exit; } else { ++(r->AX); /* DosMemAlloc() returns seg of MCB rather than data */ r->FLAGS &= ~FLG_CARRY; } break; /* Free memory */ case 0x49: if ((rc = DosMemFree((r->ES) - 1)) < 0) goto error_exit; else r->FLAGS &= ~FLG_CARRY; break; /* Set memory block size */ case 0x4a: { UWORD maxSize; if ((rc = DosMemChange(r->ES, r->BX, &maxSize)) < 0) { if (rc == DE_NOMEM) r->BX = maxSize; #if 0 if (cu_psp == r->ES) { psp FAR *p; p = MK_FP(cu_psp, 0); p->ps_size = r->BX + cu_psp; } #endif goto error_exit; } else r->FLAGS &= ~FLG_CARRY; break; } /* Load and Execute Program */ case 0x4b: break_flg = FALSE; if ((rc = DosExec(r->AL, MK_FP(r->ES, r->BX), MK_FP(r->DS, r->DX))) != SUCCESS) goto error_exit; else r->FLAGS &= ~FLG_CARRY; break; /* Terminate Program */ case 0x00: r->AX = 0x4c00; /* End Program */ case 0x4c: if (cu_psp == RootPsp || ((psp FAR *) (MK_FP(cu_psp, 0)))->ps_parent == cu_psp) break; tsr = FALSE; /* int2f_Remote_call(0x1122, 0, 0, 0, 0, 0, 0); int2f_Remote_call(REM_CLOSEALL, 0, 0, 0, 0, 0, 0); */ if (ErrorMode) { ErrorMode = FALSE; return_mode = 2; } else if (break_flg) { break_flg = FALSE; return_mode = 1; } else { return_mode = 0; } return_code = r->AL; if (DosMemCheck() != SUCCESS) panic("MCB chain corrupted"); #ifdef TSC StartTrace(); #endif return_user(); break; /* Get Child-program Return Value */ case 0x4d: r->AL = return_code; r->AH = return_mode; break; /* Dos Find First */ case 0x4e: { /* dta for this call is set on entry. This */ /* needs to be changed for new versions. */ if ((rc = DosFindFirst((UCOUNT) r->CX, (BYTE FAR *) MK_FP(r->DS, r->DX))) < 0) goto error_exit; else { r->AX = 0; r->FLAGS &= ~FLG_CARRY; } } break; /* Dos Find Next */ case 0x4f: { /* dta for this call is set on entry. This */ /* needs to be changed for new versions. */ if ((rc = DosFindNext()) < 0) { r->AX = -rc; if (r->AX == 2) r->AX = 18; r->FLAGS |= FLG_CARRY; } else { r->FLAGS &= ~FLG_CARRY; } } break; /* ************UNDOCUMENTED************************************* */ /* Get List of Lists */ case 0x52: { BYTE FAR *p; p = (BYTE FAR *) & DPBp; r->ES = FP_SEG(p); r->BX = FP_OFF(p); } break; /* Get verify state */ case 0x54: r->AL = (verify_ena ? TRUE : FALSE); break; /* ************UNDOCUMENTED************************************* */ /* Dos Create New Psp & set p_size */ case 0x55: new_psp((psp FAR *) MK_FP(r->DX, 0), r->SI); break; /* Dos Rename */ case 0x56: rc = dos_rename( (BYTE FAR *) MK_FP(r->DS, r->DX), /* OldName */ (BYTE FAR *) MK_FP(r->ES, r->DI)); /* NewName */ if (rc < SUCCESS) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; } break; /* Get/Set File Date and Time */ case 0x57: switch (r->AL) { case 0x00: rc = DosGetFtime( (COUNT) r->BX, /* Handle */ (date FAR *) & r->DX, /* FileDate */ (time FAR *) & r->CX); /* FileTime */ if (rc < SUCCESS) goto error_exit; else r->FLAGS &= ~FLG_CARRY; break; case 0x01: rc = DosSetFtime( (COUNT) r->BX, /* Handle */ (date FAR *) & r->DX, /* FileDate */ (time FAR *) & r->CX); /* FileTime */ if (rc < SUCCESS) goto error_exit; else r->FLAGS &= ~FLG_CARRY; break; default: goto error_invalid; } break; /* Get/Set Allocation Strategy */ case 0x58: switch (r->AL) { case 0x00: r->AX = mem_access_mode; break; case 0x01: if (((COUNT) r->BX) < 0 || r->BX > 2) goto error_invalid; else { mem_access_mode = r->BX; r->FLAGS &= ~FLG_CARRY; } break; default: goto error_invalid; #ifdef DEBUG case 0xff: show_chain(); break; #endif } break; /* Create Temporary File */ case 0x5a: if ((rc = DosMkTmp(MK_FP(r->DS, r->DX), r->CX)) < 0) goto error_exit; else { r->AX = rc; r->FLAGS &= ~FLG_CARRY; } break; /* Create New File */ case 0x5b: if ((rc = DosOpen(MK_FP(r->DS, r->DX), 0)) >= 0) { DosClose(rc); r->AX = 80; r->FLAGS |= FLG_CARRY; } else { if ((rc = DosCreat(MK_FP(r->DS, r->DX), r->CX)) < 0) goto error_exit; else { r->AX = rc; r->FLAGS &= ~FLG_CARRY; } } break; /* UNDOCUMENTED: server, share.exe and sda function */ case 0x5d: switch (r->AL) { /* Remote Server Call */ case 0x00: { UWORD FAR *x = MK_FP(r->DS, r->DX); r->AX = x[0]; r->BX = x[1]; r->CX = x[2]; r->DX = x[3]; r->SI = x[4]; r->DI = x[5]; r->DS = x[6]; r->ES = x[7]; } goto dispatch; case 0x06: r->DS = FP_SEG(internal_data); r->SI = FP_OFF(internal_data); r->CX = swap_always - internal_data; r->DX = swap_indos - internal_data; r->FLAGS &= ~FLG_CARRY; break; case 0x07: case 0x08: case 0x09: int2f_Remote_call(REM_PRINTREDIR, 0, 0, r->DX, 0, 0, (MK_FP(0, Int21AX))); break; default: goto error_invalid; } break; case 0x5e: switch (r->AL) { case 0x00: r->CX = get_machine_name(MK_FP(r->DS, r->DX)); break; case 0x01: set_machine_name(MK_FP(r->DS, r->DX), r->CX); break; default: int2f_Remote_call(REM_PRINTSET, r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX))); break; } break; case 0x5f: switch (r->AL) { case 0x07: CDSp->cds_table[r->DL].cdsFlags |= 0x100; break; case 0x08: CDSp->cds_table[r->DL].cdsFlags &= ~0x100; break; default: int2f_Remote_call(REM_DOREDIRECT, r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX))); break; } break; case 0x60: /* TRUENAME */ if ((rc = truename(MK_FP(r->DS, r->SI), adjust_far(MK_FP(r->ES, r->DI)), TRUE)) != SUCCESS) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; } break; #ifdef TSC /* UNDOCUMENTED: no-op */ /* */ /* DOS-C: tsc support */ case 0x61: #ifdef DEBUG switch (r->AL) { case 0x01: bTraceNext = TRUE; break; case 0x02: bDumpRegs = FALSE; break; } #endif r->AL = 0x00; break; #endif /* UNDOCUMENTED: return current psp */ case 0x62: r->BX = cu_psp; break; /* UNDOCUMENTED: Double byte and korean tables */ case 0x63: { #ifdef DBLBYTE static char dbcsTable[2] = { 0, 0 }; void FAR *dp = &dbcsTable; r->DS = FP_SEG(dp); r->SI = FP_OFF(dp); r->AL = 0; #else /* not really supported, but will pass. */ r->AL = 0x00; /*jpp: according to interrupt list */ #endif break; } /* Extended country info */ case 0x65: if (r->AL <= 0x7) { if (ExtCtryInfo( r->AL, r->BX, r->CX, MK_FP(r->ES, r->DI))) r->FLAGS &= ~FLG_CARRY; else goto error_invalid; } else if ((r->AL >= 0x20) && (r->AL <= 0x22)) { switch (r->AL) { case 0x20: r->DL = upChar(r->DL); goto okay; case 0x21: upMem( MK_FP(r->DS, r->DX), r->CX); goto okay; case 0x22: upString(MK_FP(r->DS, r->DX)); okay: r->FLAGS &= ~FLG_CARRY; break; case 0x23: r->AX = yesNo(r->DL); goto okay; default: goto error_invalid; } } else r->FLAGS |= FLG_CARRY; break; /* Code Page functions */ case 0x66: switch (r->AL) { case 1: GetGlblCodePage( (UWORD FAR *) & (r->BX), (UWORD FAR *) & (r->DX)); goto okay_66; case 2: SetGlblCodePage( (UWORD FAR *) & (r->BX), (UWORD FAR *) & (r->DX)); okay_66: r->FLAGS &= ~FLG_CARRY; break; default: goto error_invalid; } break; /* Set Max file handle count */ case 0x67: if ((rc = SetJFTSize(r->BX)) != SUCCESS) goto error_exit; else { r->FLAGS &= ~FLG_CARRY; } break; /* Flush file buffer -- dummy function right now. */ case 0x68: r->FLAGS &= ~FLG_CARRY; break; } #ifdef DEBUG if (bDumpRegs) { fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs, sizeof(iregs)); dump_regs = TRUE; dump(); } #endif }
/** * Process a file pattern. * @returns 0 on success. * error code on fatal failure. * @param pszFilePattern File pattern to search. * @author knut st. osmundsen ([email protected]) */ int ProcessFiles(const char *pszFilePattern1, const char *pszFilePattern2) { int cPrevTotalFiles = cTotalFiles; char szFilename[CCHMAXPATH]; char * pszFilename; const char * pszPath; const char * pszPath1; const char * pszPath2; APIRET rc; ULONG cFiles = 500; HDIR hDir = HDIR_CREATE; char achfindbuf[1024*16]; PFILEFINDBUF3 pfindbuf = (PFILEFINDBUF3)&achfindbuf[0]; /* * Extract path from pattern. */ pszPath1 = strrchr(pszFilePattern1, '\\'); pszPath2 = strrchr(pszFilePattern1, '/'); if (pszPath1 != NULL && pszPath1 > pszPath2) pszPath = pszPath1+1; else if (pszPath2 != NULL && pszPath2 > pszPath1) pszPath = pszPath2+1; else if (pszFilePattern1[1] == ':') pszPath = &pszFilePattern1[2]; else pszPath = &pszFilePattern1[0]; memcpy(szFilename, pszFilePattern1, pszPath - pszFilePattern1); pszFilename = &szFilename[pszPath - pszFilePattern1]; *pszFilename = '\0'; /* * First search. */ rc = DosFindFirst((PSZ)pszFilePattern1, &hDir, 0, pfindbuf, sizeof(achfindbuf), &cFiles, FIL_STANDARD); while (rc == NO_ERROR && cFiles > 0) { PFILEFINDBUF3 pCur = pfindbuf; /* * Loop thru the result. */ while (pCur && cFiles--) { /* * Make filename. * Process the file. * Maintain statistics. */ strcpy(pszFilename, pCur->achName); rc = ProcessFile(szFilename, pCur->cbFile, pszFilePattern2); if (rc == 0) cSuccess++; else cErrors++; cTotalFiles++; /* * Next file. */ pCur = pCur->oNextEntryOffset == 0 ? NULL : (PFILEFINDBUF3)((char*)pCur + pCur->oNextEntryOffset); } /* * Next chunk. */ cFiles = 500; rc = DosFindNext(hDir, pfindbuf, sizeof(achfindbuf), &cFiles); } /* * Terminate find. */ DosFindClose(hDir); /* * Warning about no files and return. */ if (cTotalFiles == cPrevTotalFiles) fprintf(stderr, "No files found matching the pattern: %s\n", pszFilePattern1); return rc == ERROR_NO_MORE_FILES ? NO_ERROR : rc; }