├── dog ├── src │ ├── dog.h │ ├── ext │ │ ├── hh.c │ │ ├── pt.dog │ │ ├── pp.dog │ │ ├── cl.c │ │ ├── ext.h │ │ ├── br.c │ │ ├── Makefile │ │ ├── vf.c │ │ ├── bp.c │ │ ├── hd.c │ │ ├── tp.c │ │ ├── wi.c │ │ ├── dt.c │ │ ├── mv.c │ │ ├── ds.c │ │ ├── rm.c │ │ ├── sz.c │ │ ├── cm.c │ │ ├── cp.c │ │ └── vr.c │ ├── msdos.dog │ ├── cc.c │ ├── util │ │ ├── generr.c │ │ ├── util.h │ │ └── Makefile │ ├── xx.c │ ├── debug.h │ ├── dog.dog │ ├── tn.c │ ├── hh.c │ ├── ct.c │ ├── eh.c │ ├── testbat.dog │ ├── Makefile │ ├── cmrd.c │ └── tint24.c ├── bin │ ├── DOG.ICO │ └── DOG2.ICO ├── doc │ ├── manual.txt │ ├── rn082b.txt │ ├── rn080b.txt │ ├── readme_s.txt │ ├── rn081b.txt │ ├── readme_x.txt │ ├── rn084b.txt │ ├── rn085b.txt │ ├── rn083b.txt │ └── ggpl.txt └── Makefile ├── .gitignore ├── README.md └── LICENSE.TXT /dog/src/dog.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/susi/dog/HEAD/dog/src/dog.h -------------------------------------------------------------------------------- /dog/bin/DOG.ICO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/susi/dog/HEAD/dog/bin/DOG.ICO -------------------------------------------------------------------------------- /dog/bin/DOG2.ICO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/susi/dog/HEAD/dog/bin/DOG2.ICO -------------------------------------------------------------------------------- /dog/src/ext/hh.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/susi/dog/HEAD/dog/src/ext/hh.c -------------------------------------------------------------------------------- /dog/doc/manual.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/susi/dog/HEAD/dog/doc/manual.txt -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.EXE 2 | *.COM 3 | *.OBJ 4 | *.com 5 | *.exe 6 | *.obj 7 | *.map 8 | .gitignore 9 | *~ 10 | *.MAP 11 | dog/bin/*.dog 12 | -------------------------------------------------------------------------------- /dog/src/msdos.dog: -------------------------------------------------------------------------------- 1 | al dir ls 2 | al alias al 3 | al beep bp 4 | al cls cl 5 | al copy cp 6 | al date dt -d 7 | al time dt -t 8 | al move mv 9 | al del rm 10 | al verify vf 11 | al ver vr 12 | al ctty ct 13 | al chcp cc 14 | al echo eh 15 | al mkdir md 16 | al rmdir rd 17 | al set se 18 | al exit xx 19 | al type tp 20 | -------------------------------------------------------------------------------- /dog/doc/rn082b.txt: -------------------------------------------------------------------------------- 1 | Fixes/changes: 2 | Bypassed FreeDOS bug witth findfirst. 3 | Fixed processing of varname in commandline. 4 | 5 | New features: 6 | prompt: new meta $e - prints errorlevel 7 | -P will execute dog in the current directory (ie root on boot) 8 | That is why it is suggested that DOG.COM doesn't exist there. 9 | It is possible to use %envname% in the commandline, and in dog-files, and in 10 | prompt. 11 | -------------------------------------------------------------------------------- /dog/doc/rn080b.txt: -------------------------------------------------------------------------------- 1 | Fixes/changes: 2 | 1. Most commands are now external (standalone) programs. This 3 | will reduse the size of DOG. 4 | 2. Batchfiles are reasonably stable. 5 | 3. % is the variable char $ is the prompt and eh special char 6 | 7 | New features: 8 | 1. Pipes (only one at the time for now) 9 | 2. Environmental variables can now be used in 10 | a) batchfiles %0 - %9 for the batchfile parameters 11 | b) commandline %0 - %9 for the params of the previous command. 12 | 13 | -------------------------------------------------------------------------------- /dog/src/ext/pt.dog: -------------------------------------------------------------------------------- 1 | # PT.DOG - Part of DOG a Command interpeter for FreeDOS. 2 | # 3 | # This file implements the PT command to set and display the PATH 4 | 5 | se IN x%1 6 | # if no args are given then display the prompt 7 | if IN is x go get 8 | # check if -a was given 9 | if IN is x-a go append 10 | # else set the PATH 11 | se PATH %1 12 | go get 13 | :append 14 | se PATH %PATH%;%2 15 | # and display it 16 | :get 17 | # print the PATH. 18 | eh %PATH% 19 | # UNSET temp variables 20 | se IN 21 | -------------------------------------------------------------------------------- /dog/doc/readme_s.txt: -------------------------------------------------------------------------------- 1 | HOW TO COMPILE? 2 | just do the following commands: 3 | cd dog 4 | make install 5 | 6 | The DOG.COM is now located in dog\BIN. 7 | The External commands are also located in dog\BIN 8 | The utility programs are also located in dog\BIN 9 | 10 | NOTE: The Makefiles assume your compiler is installed in C:\BORLANDC. 11 | You can use -DBORLAND=D:\MYBORLAND_DIR to override this. 12 | Note that Borland C/C++ 3.1 is required to compile the source code. 13 | 14 | For more information please refer to the dog website at: 15 | https://dog.zumppe.net/ 16 | -------------------------------------------------------------------------------- /dog/doc/rn081b.txt: -------------------------------------------------------------------------------- 1 | Fixes/changes: 2 | 1. Fixed many bugs in the external commands 3 | 4 | New features: 5 | 1. Execution of DOG.DOG if DOG is invoked with -P SWITCH. 6 | 2. DOG - Backdoor interrupt 7 | INT D0 8 | AL = 01h 9 | 10 | Return: 11 | AX = Version 12 | 13 | Notes: 14 | Version is built up like this: 15 | 16 | A H A L 17 | --- --- 18 | | | | | 19 | | | | +-- code maturity allways one of a (=alpha), b (=beta) OR f (=final) 20 | | | +---- Patchlevel 21 | | +------- Minor version 22 | +--------- Major version 23 | 24 | (this implies that the maximum version for DOG is 15.15.15f ;) 25 | 26 | -------------------------------------------------------------------------------- /dog/doc/readme_x.txt: -------------------------------------------------------------------------------- 1 | How to install? 2 | 3 | You can use (but it's not manditory) to use DOG as your primary shell. Here 4 | is how: 5 | comment any lines beginning with SHELL from by adding REM and a space in front 6 | of the line. Then add tis line: 7 | 8 | SHELL=C:\DOG\BIN\DOG.COM -P -E:1024 -A:1024 9 | 10 | In the directory dog\bin there is a file called dog.dog to be used as an example 11 | You will probably want to convert your FDAUTO.BAT file to DOG.DOG. 12 | The example DOG.DOG is loosely based on the FreeDOS 1.3 version of FDAUTO.BAT 13 | 14 | Note that the drive and path may vary according to where you put DOG. 15 | This line will start DOG as the primary shell next time when DOS restarts. 16 | 17 | For more information please refer to the dog website at: 18 | https://dog.zumppe.net/ 19 | -------------------------------------------------------------------------------- /dog/src/ext/pp.dog: -------------------------------------------------------------------------------- 1 | # PP.DOG - Part of DOG a Command interpeter for FreeDOS. 2 | # 3 | # This file implements the PP command to set and display the prompt 4 | 5 | se IN x%1 6 | # if no args are given then display the prompt 7 | if IN is x go get 8 | # if arg #1 is "dog" set the special DOG prompt. 9 | if IN is xdog go setdog 10 | # else set the prompt 11 | se PROMPT %1 12 | # and display it 13 | go get 14 | :setdog 15 | # set the prompt to the special DOG prompt 16 | se PROMPT $n$_$_$b\_$n$_$_$b$_.\---.$n$_/$_$_$_,__/$n/$_$_$_/$p$_%%%%$_ 17 | :get 18 | # set temp variable to check if PROMPT is set. 19 | se PP x%PROMPT% 20 | # if the prompt is not set display the default DOG prompt 21 | if PP is x go dogprompt 22 | # else print the PROMPT. 23 | eh -n %PROMPT% 24 | go end 25 | :dogprompt 26 | eh -n $n$_$_$b\_$n$_$_$b$_.\---.$n$_/$_$_$_,__/$n/$_$_$_/$p$_%%%%$_ 27 | :end 28 | # UNSET temp variables 29 | se PP 30 | se IN 31 | -------------------------------------------------------------------------------- /dog/src/cc.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | CC.C - DOG - Change Codepage 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 2024-05-12 - Placeholder implementation - WB 27 | */ 28 | #include "dog.h" 29 | 30 | void do_cc(BYTE n) 31 | { 32 | printf("CC - Change Codepage, currently unimplemented\n"); 33 | } 34 | -------------------------------------------------------------------------------- /dog/src/util/generr.c: -------------------------------------------------------------------------------- 1 | /* generr.c - Utility for returning a requested error code 2 | 3 | Copyright (C) 1999 Wolf Bergenheim 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | History 20 | 2024-05-24 - creation - WB 21 | 22 | */ 23 | #include 24 | #include 25 | #include 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | int n; 30 | randomize(); 31 | if (argc < 2) { 32 | return 0; 33 | } else { 34 | if (strcmp(argv[1], "-r") == 0) { 35 | n = atoi(argv[2]); 36 | return random(n+1); 37 | } 38 | return atoi(argv[1]); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /dog/src/xx.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | XX.C - DOG - Alternate command processor for (currently) MS-DOS ver 3.30 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 2024-05-11 - Building as a module. - WB 27 | 28 | **************************************************************************/ 29 | 30 | #include "dog.h" 31 | 32 | void do_xx(void) 33 | { 34 | #ifdef XX_DEBUG 35 | printf("Xitable=%d Xit=%d\n",Xitable,Xit); 36 | #endif 37 | if(Xitable==1) Xit = 1; 38 | #ifdef XX_DEBUG 39 | printf("Xitable=%d Xit=%d\n",Xitable,Xit); 40 | #endif 41 | return; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dog/doc/rn084b.txt: -------------------------------------------------------------------------------- 1 | Fixes/changes: 2 | ============== 3 | 4 | DOG: 5 | - Fixed init + mkudata (for env and alias blocks). 6 | - Restored the old DOG prompt as the default when no PROMPT variable is set. 7 | - Now using Borland C++ 3.1 to build, and Make instead of the batch files 8 | in previous versions. 9 | - HH utilizes HELP to display more thorough help texts, through the alias HHH. 10 | The example DOG.DOG file sets up the alias: 11 | al hhh %DOGDIR%\bin\help.com 12 | - Updated the IF syntax to be more versatile and to be similar with do. 13 | - Implemented 44 and DO and IN and TI. 14 | - Fixed the Control-C implementation. Now it asks the user if they want to 15 | abort the program. 16 | - Implemented a proper Critical Error handler. 17 | - Fixed environment initialization and management. 18 | - Default dog.dog is used to set up the basic environment, edit this to suit your needs. 19 | 20 | External commands: 21 | - CP: now takes more options: -i (interactive), -f (force) 22 | - VR: Fixed FreeDOS detection + print FD kernel string. Also added DOSbox detection. 23 | - LS: -w option to display a wide listing with no details -z to show human readable sizes. 24 | - RT: Is now built from the rm.c file in addition to RM. 25 | 26 | Utilities: 27 | - HELP - Expanded help to fully document all commands and DOG itself. The manual.txt is 28 | built with HELP. 29 | - GENERR - is a silly utility which returns the error code given as arg 1. Used in 30 | testbat.dog to have predictable errorlevels. 31 | - TINT24 - test utility for testing the critical error handler. 32 | -------------------------------------------------------------------------------- /dog/src/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | DEBUG.H - DEBUG definitions 3 | 4 | Copyright (C) 2024 Wolf Bergenheim 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #ifndef __DOG_DEBUG__ 22 | #define __DOG_DEBUG__ 23 | 24 | #ifdef _ENV_DEBUG_ 25 | #define ENV_DEBUG 26 | #endif 27 | 28 | #ifdef _DOG_DEBUG_ 29 | #define DOG_DEBUG 30 | #endif 31 | 32 | #ifdef _BAT_DEBUG_ 33 | #define BAT_DEBUG 34 | #endif 35 | 36 | #ifdef _DEBUG_ALL_ 37 | 38 | #define DOG_DEBUG 39 | #define EXE_DEBUG 40 | #define BAT_DEBUG 41 | #define B_DEBUG 42 | #define LIST_DEBUG 43 | #define PARSE_DEBUG 44 | #define PROMPT_DEBUG 45 | #define ENV_DEBUG 46 | 47 | #define DO_DEBUG 48 | #define LS_DEBUG 49 | #define CA_DEBUG 50 | #define CD_DEBUG 51 | #define EH_DEBUG 52 | #define CA_DEBUG 53 | #define XX_DEBUG 54 | 55 | /* EXT specific */ 56 | #define BP_DEBUG 57 | #define EXT_DEBUG 58 | #define CM_DEBUG 59 | #define LS_DEBUG 60 | #define MV_DEBUG 61 | #define RM_DEBUG 62 | #define SZ_DEBUG 63 | #define TP_DEBUG 64 | #define VR_DEBUG 65 | 66 | #endif /* _DEBUG_ALL_ */ 67 | #endif /* __DOG_DEBUG__ */ 68 | -------------------------------------------------------------------------------- /dog/doc/rn085b.txt: -------------------------------------------------------------------------------- 1 | Fixes/changes: 2 | ============== 3 | 4 | DOG: 5 | - Fixed dogfile arg parsing and variable initialization. 6 | - Fixed command line reading so that DOS provided line editing works (F3). 7 | - Removed util shorthands since they are now external commands (HH, HD & WI). 8 | - EH: Added -n flag to not format. 9 | - MD: Added -p flag to make the whole path if any part doesn't exist. 10 | - TN: New internal command displays the canonical (TRUENAME) of a file 11 | 12 | External commands: 13 | - DS: New command contributed by K. Hari Kiran 14 | - SZ: New -r and -z flags to recurse into subdirectories and to show human- 15 | readable file sizes. 16 | - VR: Even more accurate version detection and also get kernel string from 17 | DR-DOS. 18 | - PP: A new command for setting and getting the PROMPT. It's written as 19 | a DOGFile. It's treated as an external command in documentation. 20 | PP is also a demo on what kind of programs can be written in DOG. 21 | - PT: A new command, like PP, but shows and sets the PATH. Also written in DOG. 22 | - LS: New flags & features: 23 | -p enables a page break for each screen full 24 | -s sort output according to different attributes 25 | -c use color rules to colorize files 26 | -x show file total size and file & dir count 27 | - CM: New command to change file attributes (CHMOD). 28 | - RM: New flag -a to also attempt removing read-only, system, and hidden files. 29 | - HH: Migrated the HELP utility to external command HH. 30 | - HD: Migrated the HEAD utility to external command HD. 31 | - WI: Migrated the WHICH utility to external command WI. Also updated flags 32 | to be parsed first. 33 | 34 | Utilities: 35 | - Moved the HELP, HEAD & WHICH to external commands. There are no more 36 | non-development utilities. 37 | -------------------------------------------------------------------------------- /dog/src/dog.dog: -------------------------------------------------------------------------------- 1 | # DOG.DOG - Part of DOG a Command interpeter for FreeDOS. 2 | # 3 | # This file is an example default dog.dog file 4 | # (like fdauto.bat in FreeDOS). 5 | 6 | # This is a default path that should work in many configurations 7 | se DOG c:\dog 8 | se DOSDIR c:\FreeDOS 9 | se LANG EN 10 | se TC UTC 11 | se path %DOG%\bin;%DOSDIR%\bin;c:\dos;c:\bin 12 | se TEMP %DOSDIR%\TEMP 13 | se TMP %TEMP% 14 | se BLASTER A220 I5 D1 H5 P330 15 | se EMACS C:\APPS\EMACS 16 | if EXIST %EMACS%\emacs.exe se PATH %PATH%;%EMACS% 17 | se LSCOLORS _D=34;0;1,_H=30;40;8,_R=33;40,_S=31;40;1,_L=32;40,EXE=35;40,COM=35;40,DOG=35;40,C=32;40,H=32;40,OBJ=31;40,_A=33;40 18 | # Default flags for certain commands through aliases. 19 | eh common aliases. Try the AL command to see them! 20 | al l ls -w -c -s -x 21 | al ll ls -z -c -s -x 22 | al lll ls -a -z -c -s -p -z 23 | 24 | # Don't ask to overwrite, just do it like on linux 25 | al cp cp -f -v 26 | al mv mv -v 27 | 28 | # Use dir stack, you can bypass the stack by just running the 29 | # directory, since directories are executable in DOG. 30 | al cd ds push 31 | al pd ds pop 32 | al ld ds list 33 | 34 | # freedos aliases 35 | se dogfile C:\dog.dog 36 | se cfgfile C:\FDCONFIG.SYS 37 | 38 | al cfg edit %cfgfile% 39 | al audo edit %dogfile% 40 | al reboot fdapm warmboot 41 | al reset fdisk /reboot 42 | al halt fdapm poweroff 43 | al shutdown fdapm poweroff 44 | 45 | IN APM Do you want APM (Y/N)? 46 | IF APM IS Y FDAPM APMDOS ELSE IF APM IS y FDAPM APMDOS 47 | se APM 48 | IN MOUSE Do you want mouse support (Y/N)? 49 | IF MOUSE IS Y CTMOUSE ELSE IF MOUSE IS y CTMOUSE 50 | se mouse 51 | 52 | IN KEYB What keyboard layout do you want? 53 | mkeyb %KEYB% 54 | # mkeyb SU 55 | 56 | MEM /C /N 57 | 58 | eh 59 | in DOGHELP Do you want to see dog help (Y/N)? 60 | if DOGHELP IS y help 61 | if DOGHELP IS Y help 62 | se DOGHELP 63 | -------------------------------------------------------------------------------- /dog/src/util/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | UTIL.H - Header for DOG utilities. 3 | 4 | Copyright (C) 1999, 2000 Wolf Bergenheim 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | 20 | Developers: 21 | Wolf Bergenheim (WB) 22 | 23 | */ 24 | 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | /* TURBO C 2.01 doesn't like our debug file */ 37 | #ifndef TC201 38 | /* See ..\debug.h for all the possible debugs. ext.h includes it 39 | _DEBUG_ALL_ turns all all debugging and turns off optimization */ 40 | #include "debug.h" 41 | #endif 42 | 43 | #define BYTE unsigned char 44 | #define WORD unsigned int 45 | #define DWORD unsigned long 46 | 47 | #ifdef MK_FP 48 | #undef MK_FP 49 | #endif 50 | #define MK_FP(seg,ofs) ((void far*)(((unsigned long)(seg) << 16) | (ofs))) 51 | 52 | #ifndef FA_NORMAL 53 | #define FA_NORMAL 0x0 54 | #endif 55 | 56 | #define EVER ;; 57 | 58 | #define FNF 18 59 | #define PATH_SIZE 80 60 | 61 | #define _BS 0x8; 62 | #define _TAB 0x9; 63 | #define _SPC 0x32; 64 | -------------------------------------------------------------------------------- /dog/src/ext/cl.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | CL.C - DOG - Alternate command processor for freeDOS 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 27 | ****************************************************************************/ 28 | 29 | 30 | #include "ext.h" 31 | 32 | void do_cl(void); 33 | 34 | #pragma argsused 35 | int main(BYTE n, BYTE *arg[]) 36 | { 37 | /* 38 | switch because this WILL be extended to clear 39 | the screen in to differnt video modes. 40 | */ 41 | switch (n) { 42 | case 1: 43 | do_cl(); 44 | break; 45 | default: 46 | do_cl(); 47 | break; 48 | } 49 | 50 | return 0; 51 | } 52 | 53 | 54 | void do_cl(void) 55 | { 56 | 57 | asm MOV ax,0600h 58 | asm MOV bh,07h 59 | asm MOV cx,0000h /* (0,0) to*/ 60 | asm MOV dx,5079h /* (50,79) */ 61 | asm INT 10h /*Clear screen*/ 62 | asm MOV ah,02h 63 | asm MOV bh,00h 64 | asm MOV dx,0000h /* (0,0)*/ 65 | asm INT 10h /*Move cursor to upper left corner*/ 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /dog/doc/rn083b.txt: -------------------------------------------------------------------------------- 1 | Fixes/changes: 2 | some bugfixes esp. in the setevar() and initialize() functions 3 | Fixed (completely rewrote) processing of varname in commandline (now it 4 | works as it should have). 5 | 6 | New features: 7 | 1) New command AL (ALias) by request of Stuart Axon: 8 | al alone will display the aliases that are set. 9 | al alias will clear the alias "alias" if it is set 10 | al alias real command. 11 | 12 | DOG will check for the first word on the command line, if it is an alias, if 13 | it is it will replace the alias with the "real command". DOG will do 14 | recursive aliases up to 20 levels of recursion. This is to avoid unlimited 15 | recusrion if you have set Foo=BAR and BAR=FOO you could potentially end up 16 | in an infinite loop if you say foo or bar. 17 | 18 | -A will set the size of the alias block (default is 256 bytes) 19 | 20 | Remade the DOG int D0 functions. Here are the new specs: 21 | 22 | Int D0 23 | ****** 24 | 25 | DOG - Get version 26 | AH = 01h 27 | 28 | Return: 29 | AX = Version 30 | 31 | Notes: 32 | Version is built up like this: 33 | 34 | A H A L 35 | --- --- 36 | | | | | 37 | | | | +-- code maturity allways one of a (=alpha), b (=beta) OR f (=final) 38 | | | +---- Patchlevel 39 | | +------- Minor version 40 | +--------- Major version 41 | 42 | (this implies that the maximum version for DOG is 15.15.15f ;) 43 | ------ 44 | 45 | DOG - Get internal variables: 46 | Call with: AH = 02h 47 | AL = what variable 48 | AL=01 Returns DX = environment segment ;ES:BX points to envseg variable 49 | AL=02 Returns DX = alias segment ; ES:BX points to aliasseg variable 50 | AL=03 Returns CX = number of strings; ES:BX points to commands 51 | AL=04 Returns CX = number of strings; ES:BX points to ext_commands 52 | AL=05 Returns CX = number of strings; ES:BX points to commands_des 53 | AL=06 Returns CX = number of strings; ES:BX pointsto ext_commands_des 54 | AL=07 Returns ES:BX points to bf (first bf param block) 55 | -------------------------------------------------------------------------------- /dog/src/util/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile - DOG - Alternate command processor for freeDosDOS 2 | # Copyright (C) 2024 Wolf Bergenheim 3 | 4 | # This program is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU General Public License 6 | # as published by the Free Software Foundation; either version 2 7 | # of the License, or (at your option) any later version. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | CP=cp -v -f 18 | 19 | !ifndef BORLAND 20 | BORLAND=C:\BORLANDC 21 | !endif 22 | 23 | BCCDIR=$(BORLAND)\BIN 24 | 25 | CC=$(BCCDIR)\BCC.EXE 26 | LD=$(BCCDIR)\TLINK.EXE 27 | ASM=$(BCCDIR)\TASM.EXE 28 | CFLAGS=-B -E$(ASM) -d -mt -O1 -Z -Fs -f- -g15 -tDc -Fc -Tq -Tml -Tmx -Tt -I.. 29 | LDFLAGS=-lc -ld -lt -lTdc 30 | 31 | # See debug.h for all the possible debugs. ext.h includes it 32 | # _DEBUG_ALL_ turns all all debugging and durns off optimization 33 | !if $(DEBUG) 34 | DEBUG=-D_DEBUG_ALL_ -N -Od -w 35 | LDFLAGS=$(LDFLAGS) -ll -lm -ls -lv 36 | !endif 37 | 38 | PROGS=generr.com 39 | 40 | .c.com: 41 | $(CC) @&&! 42 | $(CFLAGS) 43 | $(LDFLAGS) 44 | $(DEBUG) 45 | $. 46 | ! 47 | 48 | all: $(PROGS) 49 | 50 | ge: generr.com 51 | 52 | cp: cp.com 53 | 54 | rm: rm.com 55 | 56 | cp.com: 57 | cd ..\ext 58 | $(MAKE) cp 59 | $(CP) cp.com ..\util 60 | $(MAKE) clean 61 | cd ..\util 62 | 63 | rm.com: cp 64 | cd ..\ext 65 | $(MAKE) cp rm 66 | $(CP) rm.com ..\util 67 | $(MAKE) clean 68 | cd ..\util 69 | 70 | install: cp.com $(PROGS) 71 | $(CP) generr.com ..\..\bin 72 | 73 | .ignore 74 | clean: rm 75 | rm *.obj 76 | rm *.com 77 | -------------------------------------------------------------------------------- /dog/src/tn.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | TN.C - DOG - TRUENAME 4 | 5 | Copyright (C) 2024 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 2024-10-13 - Initial implementation - WB 26 | */ 27 | #include "dog.h" 28 | 29 | void do_tn(BYTE n) 30 | { 31 | BYTE buffer[128]; 32 | BYTE far *fn; 33 | BYTE far *tn; 34 | WORD tn_error_code; 35 | 36 | if (n != 2) { 37 | printf("Usage: TN FILEPATH\n"); 38 | return; 39 | } 40 | 41 | fn = (BYTE far*)arg[1]; 42 | tn = (BYTE far*)buffer; 43 | 44 | asm push di; 45 | asm push si; 46 | asm push es; 47 | asm lds si, fn; /* DS:SI is the input */ 48 | asm les di, tn; /* ES:DI is a 128 byte buffer for output */ 49 | asm mov ah, 60h; /* Function 60h = TRUENAME */ 50 | asm int 21h; 51 | asm pop es; 52 | asm pop si; 53 | asm pop di; 54 | asm jc tn_error; /* CF set on error */ 55 | printf("%s => %s\n", arg[1], tn); 56 | return; 57 | tn_error: 58 | asm mov tn_error_code, ax; 59 | if (tn_error_code == 2) { 60 | printf("Cannot resolve %s - invalid path component\n", arg[1]); 61 | } 62 | else if (tn_error_code == 3) { 63 | printf("Cannot resolve %s - malformed path or invalid drive letter\n", arg[1]); 64 | } 65 | return; 66 | } 67 | -------------------------------------------------------------------------------- /dog/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile - DOG - Alternate command processor for freeDosDOS 2 | # Copyright (C) 2024 Wolf Bergenheim 3 | 4 | # This program is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU General Public License 6 | # as published by the Free Software Foundation; either version 2 7 | # of the License, or (at your option) any later version. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | 18 | RM=bin\rm -v -f 19 | RT=bin\rt -v 20 | CP=bin\cp -v -f 21 | ZIP=zip -9 22 | VERSION=085b 23 | BIN=DOG$(VERSION)x.zip 24 | SRC=DOG$(VERSION)s.zip 25 | 26 | !ifndef BORLAND 27 | BORLAND=C:\BORLANDC 28 | !endif 29 | 30 | MAKE=$(MAKE) -DBORLAND=$(BORLAND) 31 | 32 | dog: src 33 | 34 | all: src 35 | 36 | src: 37 | cd src 38 | $($(MAKE)) all 39 | cd .. 40 | 41 | install: 42 | cd src 43 | $(MAKE) install 44 | cd .. 45 | 46 | bindist: install 47 | $(ZIP) -@ tmp.zip < 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | /* TURBO C 2.01 doesn't like our debug file */ 38 | #ifndef TC201 39 | /* See ..\debug.h for all the possible debugs. ext.h includes it 40 | _DEBUG_ALL_ turns all all debugging and turns off optimization */ 41 | #include "debug.h" 42 | #endif 43 | 44 | #define BYTE unsigned char 45 | #define WORD unsigned int 46 | #define DWORD unsigned long 47 | #define QWORD unsigned long long 48 | 49 | /* we want to use the ones in dos.h. not in dir.h */ 50 | #if 0 51 | #define findfirst(A,B,C) _dos_findfirst(A,C,B) 52 | #define findnext _dos_findnext 53 | #define ffblk find_t 54 | #define ff_attrib attrib 55 | #define ff_ftime wr_time 56 | #define ff_fdate wr_date 57 | #define ff_fsize size 58 | #define ff_name name 59 | #endif 60 | 61 | #ifdef MK_FP 62 | #undef MK_FP 63 | #endif 64 | #define MK_FP(seg,ofs) ((void far*)(((unsigned long)(seg) << 16) | (ofs))) 65 | 66 | #ifndef FA_NORMAL 67 | #define FA_NORMAL 0x0 68 | #endif 69 | 70 | #define EVER ;; 71 | 72 | 73 | #define FNF 18 74 | #define PATH_SIZE 80 75 | 76 | #define _BS 0x8; 77 | #define _TAB 0x9; 78 | #define _SPC 0x32; 79 | 80 | #define FLAG_UNSET 0 81 | #define FLAG_SET 1 82 | -------------------------------------------------------------------------------- /dog/src/ext/br.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | BR.C - DOG - Alternate command processor for freeDOS 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 27 | ****************************************************************************/ 28 | 29 | #include "ext.h" 30 | 31 | BYTE cbreak(BYTE s); 32 | 33 | int main(BYTE n, BYTE *arg[]) 34 | { 35 | 36 | BYTE f; 37 | 38 | if(n==1) { 39 | 40 | f = cbreak(0xff); 41 | printf("BReak is "); 42 | switch(f) { 43 | case 0 : 44 | puts("OFF"); 45 | break; 46 | case 1 : 47 | puts("ON"); 48 | break; 49 | } 50 | } 51 | else if(n==2) { 52 | 53 | if (stricmp(arg[1],"ON")==0) { 54 | f=cbreak(1); 55 | } 56 | else if (stricmp(arg[1],"OFF")==0) { 57 | f=cbreak(0); 58 | } 59 | else { 60 | puts("You MUST specify either ON or OFF."); 61 | return 0xFF; 62 | } 63 | } 64 | else { 65 | puts("Invalid number of arguments."); 66 | return 0xFF; 67 | } 68 | return 0; 69 | } 70 | 71 | /**************************************************************************/ 72 | 73 | BYTE cbreak(BYTE s) 74 | { 75 | 76 | asm MOV AH,33h 77 | asm MOV AL,s 78 | asm CMP AL,0FFh 79 | asm JE cbreak_query 80 | asm MOV DL,AL 81 | asm MOV AL,01h 82 | asm INT 21h 83 | 84 | return 0; 85 | cbreak_query: 86 | 87 | asm MOV AL,00h 88 | asm INT 21h 89 | asm MOV s,DL 90 | 91 | return s; 92 | } 93 | 94 | 95 | -------------------------------------------------------------------------------- /dog/src/ct.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | CT.C - DOG - Change Terminal (CTTY) 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | David McIlwraith (DMcI) 24 | 25 | History 26 | 25.03.00 - started... based on the code written by David MacIlwraith 27 | 2024-05-11 - Building as a module. - WB 28 | */ 29 | #include "dog.h" 30 | 31 | #pragma argsused 32 | void do_ct(BYTE n) 33 | { 34 | asm MOV ax,3d02h ;/* open file using handle */ 35 | asm MOV dx,offset arg[1] ;/* filename */ 36 | asm INT 21h ;/* open file... er device */ 37 | asm JC do_ct_err 38 | asm MOV bx,ax ;/* save handle */ 39 | asm MOV ax,4400h ;/* IOCTL - Get dev info */ 40 | asm INT 21h 41 | asm JC do_ct_err 42 | asm test dl,80h ;/* is it a device */ 43 | asm JZ do_ct_err 44 | asm MOV ax,4406h 45 | asm INT 21h ;/* IOCT - Get input status */ 46 | asm JC do_ct_err 47 | asm OR al,al ;/* is it ready? */ 48 | asm JZ do_ct_dnr 49 | asm MOV ax,4407h 50 | asm INT 21h ;/* IOCT - Get output status */ 51 | asm JC do_ct_err 52 | asm OR al,al ;/* is it ready? */ 53 | asm JZ do_ct_dnr 54 | asm MOV cx,0003h ;/* STDERR */ 55 | asm MOV ah,46h ;/* DUP2: make handle in CX same as */ 56 | 57 | do_ct_dup2: ;/* handle in BX = handle of input dev */ 58 | 59 | asm INT 21h 60 | asm JC do_ct_err 61 | asm loop do_ct_dup2 ;/*decreases cx and jmp to label while cx>0 */ 62 | 63 | return; 64 | 65 | do_ct_err: 66 | fprintf(stderr,"Invalid device.\n"); 67 | return; 68 | do_ct_dnr: 69 | fprintf(stderr,"Device %s not ready error.\n",arg[1]); 70 | return; 71 | } 72 | -------------------------------------------------------------------------------- /dog/src/ext/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile - DOG - Alternate command processor for freeDosDOS 2 | # Copyright (C) 2024 Wolf Bergenheim 3 | 4 | # This program is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU General Public License 6 | # as published by the Free Software Foundation; either version 2 7 | # of the License, or (at your option) any later version. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | 18 | CP=cp -v -f 19 | !ifndef BORLAND 20 | BORLAND=C:\BORLANDC 21 | !endif 22 | BCCDIR=$(BORLAND)\BIN 23 | 24 | MAKE=$(MAKE) -DBORLAND=$(BORLAND) 25 | CC=$(BCCDIR)\BCC.EXE 26 | LD=$(BCCDIR)\TLINK.EXE 27 | ASM=$(BCCDIR)\TASM.EXE 28 | 29 | CFLAGS=-B -E$(ASM) -d -mt -O1 -Z -Fs -f- -g15 -tDc -Fc -Tq -Tml -Tmx -Tt -I.. 30 | LDFLAGS=-lc -ld -lt -lTdc 31 | 32 | # See debug.h for all the possible debugs. ext.h includes it 33 | # _DEBUG_ALL_ turns all all debugging and durns off optimization 34 | !if $(DEBUG) 35 | DEBUG=-D_DEBUG_ALL_ -N -Od 36 | LDFLAGS=$(LDFLAGS) -ll -lm -ls -lv 37 | !endif 38 | 39 | PROGS=bp.com br.com cl.com cm.com cp.com ds.com dt.com hd.com hh.com ls.com mv.com rm.com rt.com sz.com tp.com vf.com vr.com wi.com 40 | MANUAL=..\..\doc\manual.txt 41 | 42 | .c.com: 43 | $(CC) @&&! 44 | $(CFLAGS) 45 | $(LDFLAGS) 46 | $(DEBUG) 47 | $. 48 | ! 49 | 50 | all: $(PROGS) 51 | 52 | bp: bp.com 53 | 54 | br: br.com 55 | 56 | cl: cl.com 57 | 58 | cm: cm.com 59 | 60 | cp: cp.com 61 | 62 | ds: ds.com 63 | 64 | dt: dt.com 65 | 66 | hd: hd.com 67 | 68 | hh: hh.com 69 | 70 | ls: ls.com 71 | 72 | mv: mv.com 73 | 74 | pp: pp.dog cp.com 75 | $(CP) pp.dog ..\..\bin\ 76 | 77 | pt: pt.dog cp.com 78 | $(CP) pt.dog ..\..\bin\ 79 | 80 | rm: rm.com 81 | 82 | sz: sz.com 83 | 84 | tp: tp.com 85 | 86 | vf: vf.com 87 | 88 | vr: vr.com 89 | 90 | wi: wi.com 91 | 92 | rt.com: rm.com cp.com 93 | $(CP) rm.com rt.com 94 | 95 | rt: rt.com 96 | 97 | man: hh 98 | hh all > $(MANUAL) 99 | 100 | install: $(PROGS) man pp pt 101 | $(CP) *.com ..\..\bin\ 102 | 103 | .ignore 104 | clean: rm 105 | rm *.OBJ 106 | rm *.COM 107 | rm $(MANUAL) 108 | -------------------------------------------------------------------------------- /dog/src/eh.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | EH.C - DOG - Alternate command processor for (currently) MS-DOS ver 3.30 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 2024-05-11 - Building as a module. - WB 27 | 2024-10-14 - Add -n to not format - WB 28 | **************************************************************************/ 29 | 30 | #include "dog.h" 31 | 32 | void do_eh( BYTE n) 33 | { 34 | BYTE i,j; 35 | 36 | if((n > 1) && !strncmp(arg[1], "-n", 2)) { 37 | for(i=2;i'); 61 | break; 62 | case 'h': 63 | putchar('\b'); 64 | break; 65 | case 'l': 66 | putchar('<'); 67 | break; 68 | case 'n': 69 | putchar('\n'); 70 | break; 71 | case 'r': 72 | putchar('\r'); 73 | break; 74 | case 't': 75 | putchar('\t'); 76 | break; 77 | default : 78 | putchar(arg[i][j]); 79 | 80 | } 81 | } 82 | else 83 | putchar(arg[i][j]); 84 | 85 | } 86 | printf(" "); 87 | } 88 | printf("\n"); 89 | } 90 | -------------------------------------------------------------------------------- /dog/src/testbat.dog: -------------------------------------------------------------------------------- 1 | # TESTBAT.DOG - Part of DOG. 2 | # This file tests that DOGfile commands work. Especially the 3 | 4 | eh DOGFile test script. This DOGFile tests that the DOGFile 5 | eh commands work as expected. Especially CA, DO, 44, GO and IF 6 | eh and labels 7 | eh 8 | 9 | :iftests 10 | eh test1: IF ERROR IS 7 11 | generr 7 12 | if ERROR IS 7 eh Test PASS ELSE eh test1 FAIL 13 | eh 14 | 15 | eh test2: IF ERROR 7 16 | generr 7 17 | if ERROR 7 go pass2 18 | eh Test 2 FAIL 19 | go end2 20 | :pass2 21 | eh Test 2 PASS 22 | :end2 23 | eh 24 | 25 | eh test3: IF ERROR NOT 7 26 | generr 0 27 | if ERROR NOT 7 eh test3 PASS ELSE eh test3 FAIL 28 | eh 29 | 30 | eh test4: IF FOO IS BAR 31 | se FOO BAR 32 | IF FOO IS BAR eh test4 PASS ELSE test4 FAIL 33 | eh 34 | 35 | eh test5: IF FOO BAR 36 | se FOO BAR 37 | IF FOO BAR eh test5 PASS ELSE test5 FAIL 38 | eh 39 | 40 | eh test6: IF FOO NOT BAR 41 | se foo bar 42 | IF FOO NOT BAR eh test6 PASS ELSE test6 FAIL 43 | eh 44 | 45 | eh test7: IF EXIST 46 | IF EXIST testbat.dog eh test7 PASS ELSE eh test7 FAIL 47 | eh 48 | 49 | eh test8: IF EXIST DIR 50 | IF EXIST c:\temp eh test8 PASS ELSE eh test8 FAIL 51 | eh 52 | 53 | eh test9: IF NOT EXIST 54 | IF NOT EXIST GARGAR.GAR eh test9 PASS ELSE eh test9 FAIL 55 | eh 56 | 57 | eh test10: IF ELSE GO 58 | generr 0 59 | if ERROR 7 eh test10 FAIL ELSE go test10pass 60 | eh test10 really FAIL 61 | :test10pass 62 | eh test10 PASS 63 | eh 64 | 65 | :endiftests 66 | 67 | # for looping with 44 68 | eh test11: 44 loop 69 | 44 animal in dog,cat,bear,wolf,mouse,rat,fox do se animal %%animal%% 70 | if animal IS fox eh test11 PASS ELSE eh test11 FAIL 71 | eh 72 | 73 | eh test12: 44 LOOP with IF 74 | se animal fox 75 | 44 animal in dog,cat,bear,wolf,mouse,rat,fox do if animal IS %%animal%% eh test12 PASS 76 | eh 77 | 78 | eh test13: DO WHILE ERROR IS 1 79 | eh press any key to start 80 | ti 81 | generr 1 82 | do generr -r 3 WHILE ERROR IS 2 83 | eh test13 PASS 84 | eh 85 | 86 | eh test14: DO WHILE ERROR 1 87 | eh press any key to start 88 | ti 89 | generr 1 90 | do generr -r 3 WHILE ERROR 2 91 | eh test14 PASS 92 | eh 93 | 94 | eh test15: DO WHILE ERROR NOT 1 95 | eh press any key to start 96 | ti 97 | generr 0 98 | do generr -r 3 WHILE ERROR NOT 2 99 | eh test15 PASS 100 | eh 101 | 102 | eh test16: DO WHILE FOO NOT BAR 103 | se FOO GAR 104 | do in FOO Type BAR to end loop: WHILE FOO NOT BAR 105 | eh test16 PASS 106 | eh 107 | 108 | eh test17: IN FOO 109 | se FOO BAR 110 | in FOO 111 | if FOO NOT BAR eh test17 PASS ELSE eh test17 FAIL (%FOO%) 112 | eh 113 | 114 | eh test18: IN FOO Message 115 | se FOO 116 | in FOO Please type 'FOO' and press enter. 117 | if FOO IS FOO eh test18 PASS else eh test18 FAIL (%FOO%) 118 | eh 119 | 120 | eh test19: TI input 121 | eh press a key to continue... 122 | ti 123 | eh test19 PASS 124 | eh 125 | 126 | eh test20: TI input 127 | eh Please wait 5 seconds 128 | ti 5 129 | eh test20 PASS 130 | eh 131 | 132 | eh If you read this then all tests have probably passed! 133 | -------------------------------------------------------------------------------- /dog/src/ext/vf.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | VF.C - DOG - Alternate command processor for freeDOS 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 02.01.02 - Fixed bug: In call to set state of verify flag A call ti int 21 and 27 | NOT int 21h was made (oops :) Other bugfixes too: main returns int 28 | added return to the end of the prog to make the compiler happy - WB 29 | 2002-11-21 - Added help text, prints to std err - WB 30 | 31 | ***************************************************************************/ 32 | 33 | #include "ext.h" 34 | 35 | int main(BYTE n, BYTE *arg[]) 36 | { 37 | 38 | if (n==1) { 39 | printf("Verify is "); 40 | 41 | asm MOV ah,54h /* Get verify flag */ 42 | asm INT 21h 43 | asm MOV dl,01h 44 | asm CMP al,dl 45 | asm JE on 46 | 47 | puts("OFF"); 48 | return 0; 49 | on: 50 | puts("ON"); 51 | return 0; 52 | } 53 | else if (n==2) { 54 | if (stricmp(arg[1],"ON")==0) { 55 | 56 | asm MOV ah,2eh /*Set Verify flag*/ 57 | asm MOV al,01h /* to on*/ 58 | asm XOR dl,dl 59 | asm INT 21h 60 | 61 | } 62 | else if (stricmp(arg[1],"OFF")==0) { 63 | 64 | asm MOV ah,2eh /* Set Verify flag */ 65 | asm MOV al,00h /* to off */ 66 | asm XOR dl,dl 67 | asm INT 21h 68 | 69 | } 70 | else { 71 | fputs("Usage: VF [ ON | OFF ]\n\nGet [ Set | Clear ] the system verify flag\n\n", stderr); 72 | fputs("Second argument is either ON or OFF\n", stderr); 73 | fputs("\tON\tSet the system verify flag.\n\tOFF\tClear the system verify flag\n", stderr); 74 | fputs("\nVF is part of DOG (http://dog.sf.net/)\n", stderr); 75 | return 1; 76 | } 77 | 78 | } 79 | else { 80 | fputs("Invalid number of arguments.\n", stderr); 81 | fputs("Usage: VF [ ON | OFF ]\n\nGet [ Set | Clear ] the system verify flag\n\n", stderr); 82 | fputs("Second argument is either ON or OFF\n", stderr); 83 | fputs("\tON\tSet the system verify flag.\n\tOFF\tClear the system verify flag\n", stderr); 84 | fputs("\nVF is part of DOG (http://dog.sf.net/)\n", stderr); 85 | return 0xFF; 86 | } 87 | return 0; 88 | } 89 | 90 | 91 | -------------------------------------------------------------------------------- /dog/src/ext/bp.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | BP.C - DOG - Alternate command processor for freeDOS 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 15.08.00 - Extracted from BAT.C, changed t & f to beWORD instead of BYTE - WB 26 | 2002-11-26 - Improved help text. - WB 27 | */ 28 | 29 | #include "ext.h" 30 | 31 | WORD t,f; 32 | 33 | 34 | int init(int n, char *arg[]); 35 | void do_bp(void); 36 | 37 | int main(int nargs, char *args[]) 38 | { 39 | BYTE r; 40 | 41 | r = init(nargs, args); 42 | if (r == 0) 43 | do_bp(); 44 | 45 | return r; 46 | } 47 | 48 | 49 | /* 50 | * return -1 Error, = OK, 1 OK, but stop. 51 | */ 52 | int init(int n, char *arg[]) 53 | { 54 | 55 | #ifdef BP_DEBUG 56 | BYTE b; 57 | printf("n = %u\n",n); 58 | for(b=0;b2) { 43 | arg[1] = &arg[0][2]; 44 | arg[0][1] = '\0'; 45 | 46 | n++; 47 | } 48 | /* for every dot(.) after .. change to \.. */ 49 | 50 | 51 | p = arg[1]; 52 | q = dir; 53 | 54 | for(i=0;i<80;i++) { 55 | dir[i]=0; 56 | } 57 | 58 | while(*p!=0) { 59 | if(*p=='.'){ 60 | for(i=0;*p=='.';i++) { 61 | *(q++) = *(p++); 62 | } 63 | q--; 64 | if(i>2){ 65 | i-=2; 66 | for(j=0;j= 'A') 88 | printf("%c:\\%s\n",D,P); 89 | return; 90 | } 91 | else { 92 | do_mrd(n); 93 | return; 94 | } 95 | 96 | } 97 | 98 | /**************************************************************************/ 99 | 100 | void do_mrd(BYTE n) 101 | { 102 | BYTE f, r=0, *p, *q; 103 | 104 | f = toupper(arg[0][0]); /* check the first letter to determine what func*/ 105 | p = arg[1]; 106 | if (n == 1) { 107 | puts("Required argument missing"); 108 | return; 109 | } 110 | if (n == 3) { 111 | if ((arg[1][0] == '-') && (toupper(arg[1][1]) == 'P') && (f == 'M')) { 112 | r = 1; 113 | p = arg[2]; 114 | } 115 | } 116 | if ((n > 2) && (r == 0)) { 117 | puts("Invalid number of arguments."); 118 | return; 119 | } 120 | 121 | asm mov AL, f; 122 | asm cmp AL, 'C'; 123 | asm je do_mrd_cd; 124 | asm cmp AL, 'M'; 125 | asm je do_mrd_md; 126 | asm cmp AL, 'R'; 127 | asm je do_mrd_rd; 128 | 129 | do_mrd_md: 130 | asm mov AH, 39h; /* mkdir */ 131 | asm jmp do_mrd_doit; 132 | 133 | do_mrd_rd: 134 | asm mov AH, 3ah; /* rmdir */ 135 | asm jmp do_mrd_doit; 136 | 137 | do_mrd_cd: 138 | asm mov AH,3bh; /* chdir */ 139 | 140 | do_mrd_doit: 141 | asm mov DX, p; /* path to act on */ 142 | asm int 21h; 143 | asm jnc do_mrd_OK; 144 | asm cmp AL, 03h; /* path not found */ 145 | asm je do_mrd_pnf; 146 | asm cmp AL,05h; /* access denied */ 147 | asm je do_mrd_ad; 148 | asm cmp AL,06h; 149 | asm je do_mrd_ih; /* invalid handle */ 150 | asm jmp do_mrd_rcd; /* rm current dir */ 151 | 152 | do_mrd_pnf: 153 | if (r == 1) { /* recusrsive path creation was requested */ 154 | q = strrchr(p, '\\'); 155 | *q = '\0'; 156 | do_mrd(n); 157 | *q = '\\'; 158 | do_mrd(n); 159 | } else { 160 | puts("Invalid path."); 161 | } 162 | return; 163 | do_mrd_ad: 164 | puts("Access denied."); 165 | return; 166 | do_mrd_ih: 167 | puts("Invalid handle."); 168 | return; 169 | do_mrd_rcd: 170 | puts("Attempted to remove current directory."); 171 | do_mrd_OK: 172 | return; 173 | 174 | } 175 | -------------------------------------------------------------------------------- /dog/src/ext/tp.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | TP.C - DOG - Alternate command processor for freeDOS 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 02.01.02 - Bugfix: return errorcode 1 on missing filename - WB 27 | 2002-11-21 - Added help text, prints to std err - WB 28 | 29 | **************************************************************************/ 30 | 31 | #include "ext.h" 32 | 33 | /* 1 kB buffer */ 34 | #define BUFF_SIZE 1024 35 | 36 | /* BYTE flag_v = FLAG_UNSET; */ 37 | 38 | void print_help(void); 39 | 40 | int main(BYTE n, BYTE *arg[]) 41 | { 42 | FILE *fp; 43 | struct ffblk *fb; 44 | BYTE i,j,r,*buff,dir[200],savedir[200],dir_flag; 45 | 46 | buff = malloc(BUFF_SIZE); 47 | 48 | if(n == 1) { 49 | fputs("Missing filename.\n\n",stderr); 50 | print_help(); 51 | return 1; 52 | } 53 | else if(n >1) { 54 | 55 | /* check flags */ 56 | for(i=1;i0;j--) { 79 | #ifdef TP_DEBUG 80 | printf("dir[%d]=%c\n",j,dir[j]); 81 | #endif 82 | if(dir[j] == '\\') { 83 | dir[j+1] = '\0'; 84 | dir_flag = 1; 85 | break; 86 | } 87 | } 88 | strcpy(savedir,dir); 89 | #ifdef TP_DEBUG 90 | printf("dir=%s\n",dir); 91 | #endif 92 | 93 | printf("\n---------------%s---------------\n\n",fb->ff_name); 94 | if (dir_flag == 1) 95 | strcat(dir,fb->ff_name); 96 | else 97 | strcpy(dir,fb->ff_name); 98 | 99 | fp = fopen(dir,"r"); 100 | if (fp == NULL) { 101 | fprintf(stderr,"\n****Error opening file %s\n",dir); 102 | } 103 | else { 104 | while(fgets(buff,BUFF_SIZE,fp)) { 105 | /* printf("%s",buff);*/ 106 | write(1, buff, strlen(buff)+1); 107 | } 108 | fclose(fp); 109 | } 110 | } 111 | else if((r == 255) && (errno !=ENMFILE)) { 112 | switch(errno) { 113 | case ENOFILE: 114 | fprintf(stderr,"\n****File not found: %s\n",arg[i]); 115 | break; 116 | case ENOPATH: 117 | fprintf(stderr,"\n****File not found: %s (Invalid path)\n",arg[i]); 118 | break; 119 | case EMFILE: 120 | fprintf(stderr,"\n****File not found: %s (Too many open files)\n",arg[i]); 121 | break; 122 | default: 123 | fprintf(stderr,"\n****File not found: %s (DOS error (%x))\n",arg[i],errno); 124 | break; 125 | 126 | } 127 | continue; 128 | } 129 | 130 | r = findnext(fb); 131 | while(errno != 2) { 132 | printf("\n---------------%s---------------\n\n",fb->ff_name); 133 | strcpy(dir,savedir); 134 | if (dir_flag == 1) 135 | strcat(dir,fb->ff_name); 136 | else 137 | strcpy(dir,fb->ff_name); 138 | 139 | fp = fopen(dir,"r"); 140 | if (fp == NULL) { 141 | fprintf(stderr,"\n****Error opening file %s\n",dir); 142 | } 143 | else { 144 | while(fgets(buff,BUFF_SIZE,fp) != 0) { 145 | /* printf("%s\n",buff);*/ 146 | write(1, buff, strlen(buff)+1); 147 | } 148 | fclose(fp); 149 | } 150 | r = findnext(fb); 151 | } 152 | 153 | if((r == 255) && (errno !=ENOFILE)) { 154 | switch(errno) { 155 | /* 156 | case ENOFILE: 157 | fprintf(stderr,"\n****File not found: %s\n",arg[i]); 158 | break; 159 | */ 160 | case ENOPATH: 161 | fprintf(stderr,"\n****File not found: %s (Invalid path)\n",arg[i]); 162 | break; 163 | case EMFILE: 164 | fprintf(stderr,"\n****File not found: %s (Too many open files)\n",arg[i]); 165 | break; 166 | default: 167 | fprintf(stderr,"\n****File not found: %s (DOS error (%x))\n",arg[i],errno); 168 | break; 169 | 170 | } 171 | } 172 | 173 | } 174 | 175 | } 176 | free(fb); 177 | free(buff); 178 | return 0; 179 | } 180 | 181 | void print_help(void) 182 | { 183 | fputs("Usage: TP [OPTION] FILE...\n\nTyPe FILE(s) to standard output device\n\n", stderr); 184 | fputs("The OPTIONS are:\n",stderr); 185 | /* fputs("\t-v: verbose: print filename of each removed file\n",stderr); 186 | \t-i: interactive mode: prompt (Y/N) for each file or directory\n */ 187 | fputs(" -h|-H|-?: display this help and exit\n",stderr); 188 | fputs("\nFILE is a name of a file to write\n", stderr); 189 | fputs("\nTP is part of DOG (http://dog.sf.net/)\n", stderr); 190 | } 191 | -------------------------------------------------------------------------------- /dog/src/ext/wi.c: -------------------------------------------------------------------------------- 1 | /* 2 | WI.C - version 1.1 3 | Finds programs in path-like environment variables. 4 | 5 | Copyright (C) 1999 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | This program is part of DOG - The DOG Operating Ground 22 | 23 | History 24 | 25 | 19.07.99 - Created by Wolf Bergenheim 26 | 26.07.99 - Added switches 27 | 2000.10.21 - Ported to BCC - WB 28 | 2024-11-16 - Moved as external command WI - WB 29 | */ 30 | #include "ext.h" 31 | 32 | #define FULL (1) 33 | #define NFLAGS 4 34 | 35 | #define COM 0 36 | #define EXE 1 37 | #define DOG 2 38 | 39 | #define _A 0 40 | #define _E 1 41 | #define _X 2 42 | #define _F 3 43 | 44 | BYTE e[3][5] = {".COM",".EXE",".DOG"}; 45 | BYTE name[80]={0}; 46 | BYTE f = 0; 47 | BYTE flags[4][3] = { 48 | "-A", 49 | "-E", 50 | "-X", 51 | "-F"}; 52 | 53 | 54 | void check(BYTE *p,BYTE ext); 55 | 56 | int main(int nargs,char *args[]) 57 | { 58 | BYTE i,j,*env_val,*p,env_name[80],c=0; 59 | 60 | if(nargs == 1) { 61 | puts("WI - Shows which program is run with a command."); 62 | puts("usage: WHICH [-A | -E env.variable] | -F | -X] [program]..."); 63 | puts("\n-F = Full info, -X = use DOS .BAT files in stead of DOG .DOG files"); 64 | return 1; 65 | } 66 | 67 | strcpy(env_name,"PATH"); 68 | 69 | for(i=1;i>9)+1980, (b.ff_fdate >> 5) & 0x0f,b.ff_fdate & 0x1F); 159 | printf(" %2d:%02d ",b.ff_ftime >> 11, (b.ff_ftime & 0x7e0) >> 5); 160 | 161 | 162 | if ((b.ff_attrib & FA_ARCH) == FA_ARCH) printf("A"); 163 | else if((b.ff_attrib & FA_LABEL) == FA_LABEL) printf("L"); 164 | else printf("-"); 165 | 166 | if ((b.ff_attrib & FA_SYSTEM) == FA_SYSTEM) printf("S"); 167 | else if((b.ff_attrib & FA_LABEL) == FA_LABEL) printf("A"); 168 | else printf("-"); 169 | 170 | if ((b.ff_attrib & FA_RDONLY) == FA_RDONLY) printf("R"); 171 | else if((b.ff_attrib & FA_LABEL) == FA_LABEL) printf("B"); 172 | else printf("-"); 173 | 174 | if ((b.ff_attrib & FA_HIDDEN) == FA_HIDDEN) printf("H"); 175 | else if((b.ff_attrib & FA_LABEL) == FA_LABEL) printf("E"); 176 | else printf("-"); 177 | 178 | if ((b.ff_attrib & FA_DIREC) == FA_DIREC) printf("D"); 179 | else if((b.ff_attrib & FA_LABEL) == FA_LABEL) printf("L"); 180 | else printf("-"); 181 | 182 | ltoa(b.ff_fsize,size,10); 183 | printf("%9s",size); 184 | 185 | } 186 | puts(""); 187 | 188 | } 189 | return; 190 | } 191 | -------------------------------------------------------------------------------- /dog/src/tint24.c: -------------------------------------------------------------------------------- 1 | /* 2 | tint24.c - Test for int24 handler 3 | 4 | Copyright (C) 1999 Wolf Bergenheim 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | 20 | History 21 | 22 | 2024-06-08 - Implemented a test for all int 24 handlers. - WB 23 | */ 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #define BYTE unsigned char 38 | #define WORD unsigned int 39 | #define DWORD unsigned long 40 | 41 | #ifdef MK_FP 42 | #undef MK_FP 43 | #endif 44 | #define MK_FP(seg,ofs) ((void far*)(((unsigned long)(seg) << 16) | (ofs))) 45 | 46 | /* PSP */ 47 | #define PSP_I22_OFS 0x000A 48 | #define PSP_I22_SEG 0x000C 49 | #define PSP_I23_OFS 0x000E 50 | #define PSP_I23_SEG 0x0010 51 | #define PSP_I24_OFS 0x0012 52 | #define PSP_I24_SEG 0x0014 53 | #define PSP_PPID_OFS 0x0016 54 | #define PSP_ENVSEG_OFS 0x002C 55 | 56 | extern unsigned _psp; 57 | extern unsigned _heaplen; 58 | extern unsigned _stklen; 59 | 60 | extern BYTE _osmajor; 61 | extern BYTE _osminor; 62 | 63 | BYTE cBreak = 0, in_getln=0; 64 | WORD my_i22_s, my_i22_o; 65 | WORD my_i23_s, my_i23_o; /* When making a permanent shell take over */ 66 | WORD my_i24_s, my_i24_o; /* int 23 and int 24. */ 67 | WORD i23_s, i23_o; /* variables to store old ctrl-c handler*/ 68 | WORD i24_s, i24_o; 69 | WORD i2e_s, i2e_o; 70 | WORD id0_s, id0_o; /* the old handler for the D0GFunc */ 71 | WORD envseg=0,envsz=512; 72 | WORD aliasseg=0,aliassz=2048; 73 | 74 | #define _NCOMS 2 75 | #define _NECOMS 2 76 | 77 | BYTE *commands[] = {"FOO", "BAR"}; 78 | BYTE *command_des[] = {"foo", "bar"}; 79 | BYTE *ext_commands[] = {"BAZ", "FOZ"}; 80 | BYTE *ext_command_des[] = {"baz", "foz"}; 81 | BYTE *bf = "bf"; 82 | 83 | /* ints.c */ 84 | void save_error_ints(void); 85 | void set_error_ints(void); 86 | void restore_error_ints(void); 87 | void set_int2e(void); 88 | void set_intd0(void); 89 | void restore_intd0(void); 90 | void display_string(char *sd); 91 | void DOGFunc(void); 92 | 93 | void printprompt(void); 94 | void make_int24_call(BYTE rAH, BYTE rAL, WORD rBP, WORD rSI, WORD rDI); 95 | 96 | #define ABORT 0x02 97 | #define FAIL 0x03 98 | #define IGNORE 0x00 99 | #define RETRY 0x01 100 | 101 | BYTE *response[] = { 102 | "Ignore", 103 | "Retry", 104 | "Abort", 105 | "Fail", 106 | }; 107 | 108 | void printprompt(void) 109 | { 110 | puts("PROMPT"); 111 | } 112 | 113 | void make_int24_call(BYTE rAH, BYTE rAL, WORD rBP, WORD rSI, WORD rDI) 114 | { 115 | BYTE retval; 116 | WORD far *fpBPSI; 117 | WORD rBPSI; 118 | fpBPSI = MK_FP(rBP, rSI+4); 119 | rBPSI = *fpBPSI; 120 | printf("Triggering int 24h with AH=%02Xh AL=%02Xh BP:[SI+4]=%Fp=%04Xh DI=%04X\n", 121 | rAH, rAL, fpBPSI, rBPSI, rDI); 122 | asm push ax; 123 | asm push bx; 124 | asm push si; 125 | asm push di; 126 | 127 | asm mov si, rSI; 128 | asm mov di, rDI; 129 | asm mov ah, rAH; 130 | asm mov al, rAL; 131 | asm mov bx, rBP; 132 | asm push bp; 133 | asm mov bp, bx; 134 | 135 | asm int 24h; 136 | asm pop bp; 137 | asm mov retval, al; 138 | 139 | asm pop di; 140 | asm pop si; 141 | asm pop bx; 142 | asm pop ax; 143 | 144 | printf("int 24h returned %s(%02Xh)\n", response[retval], retval); 145 | } 146 | 147 | int main(void) 148 | { 149 | BYTE BPSIa[6]={0x12, 0x34, 0x56, 0x78, 0xbc, 0x9a}; 150 | WORD far *fpBPSI; 151 | WORD rDI=0; 152 | BYTE d, fri, rw, diskarea,i, j, rAH, rAL; 153 | 154 | fpBPSI = (WORD far *)(BPSIa+4); 155 | 156 | save_error_ints(); 157 | set_error_ints(); 158 | 159 | puts("Starting I/O error tests:"); 160 | for(i=0; i < 4; i++) { 161 | diskarea = i<<1; 162 | printf("disk area: %02Xh\n", diskarea); 163 | for (j=0; j < 8; j++) { 164 | fri = j << 3; 165 | printf("fri: %02Xh\n", fri); 166 | for (d=0; d<6; d++) { 167 | printf("drive: %02Xh\n", d); 168 | for (rw=0; rw < 2; rw++) { 169 | if (rw) 170 | puts("write"); 171 | else 172 | puts("read"); 173 | rAH = rw + diskarea + fri; 174 | rAL = d; 175 | make_int24_call(rAH, rAL, _DS, (WORD) BPSIa, rDI); 176 | } 177 | } 178 | } 179 | } 180 | 181 | puts("Block device errors tests:"); 182 | *fpBPSI=(WORD)0x0d06; 183 | diskarea = 0; 184 | for (j=0; j < 8; j++) { 185 | fri = j << 3; 186 | printf("fri: %02Xh\n", fri); 187 | d=0; 188 | for (rw=0; rw < 2; rw++) { 189 | if (rw) 190 | puts("write"); 191 | else 192 | puts("read"); 193 | rAH = 0x80 + rw + diskarea + fri; 194 | rAL = d; 195 | make_int24_call(rAH, rAL, _DS, (WORD)BPSIa, rDI); 196 | } 197 | } 198 | 199 | puts("CHAR dev errors tests:"); 200 | *fpBPSI=(WORD)0x8d06; 201 | diskarea = 0; 202 | d = 0; 203 | for(i=0; i < 0x15; i++) { 204 | printf("errno: %02Xh\n", i); 205 | for (j=0; j < 8; j++) { 206 | fri = j << 3; 207 | printf("fri: %02Xh\n", fri); 208 | for (rw=0; rw < 2; rw++) { 209 | if (rw) 210 | puts("write"); 211 | else 212 | puts("read"); 213 | rAH = 0x80 + rw + diskarea + fri; 214 | rAL = d; 215 | rDI = (WORD)i; 216 | make_int24_call(rAH, rAL, _DS, (WORD) BPSIa, rDI); 217 | } 218 | } 219 | } 220 | 221 | puts("int 24 testing done"); 222 | return 0; 223 | } 224 | -------------------------------------------------------------------------------- /dog/src/ext/dt.c: -------------------------------------------------------------------------------- 1 | /* 2 | DT.C - DOG - Alternate command processor for freeDOS Day and Time - version 1.2 3 | Get and/or set date and time. 4 | Correct date format anywhere. 5 | 6 | Copyright (C) 1999,2000 Wolf Bergenheim 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | 22 | This program is part of DOG - The DOG Operating Ground 23 | 24 | Developers: 25 | Wolf Bergenheim (WB) 26 | Eugene Wong (EW) 27 | 28 | History 29 | Based on CLK skeleton by Eugene Wong 30 | 30.11.99 - Created by Wolf Bergenheim 31 | 08.12.99 - Made DT check current CountryCode and use the CC-block to show time and date correctly 32 | 12.03.00 - Added DOSCC struct to fix program - WB 33 | 02.04.00 - I put the date ahead of the time when displayed, 34 | because I thought it might be more standard. - EW 35 | */ 36 | #include "ext.h" 37 | 38 | #define NEITHER 0 39 | #define TIME 1 40 | #define DATE 2 41 | #define BOTH 3 42 | #undef DWORD 43 | #define DWORD unsigned char far * 44 | 45 | struct DOSCC { 46 | WORD dtf; /* Day and Time Format 0=USA, 1=Europe 2=Japan*/ 47 | BYTE mk[5]; /* currency string */ 48 | BYTE Ms[2]; /* thousand separator */ 49 | BYTE ds[2]; /* decimal separator */ 50 | BYTE dts[2]; /* date separator */ 51 | BYTE tms[2]; /* time separator*/ 52 | BYTE csf; /* currency symbol format*/ 53 | BYTE ndd; /* digits after decimal */ 54 | BYTE tf; /* timeformat 0=12h 1=24h */ 55 | DWORD cmca; /* case map call address */ 56 | BYTE dls[2]; /* datalist separator */ 57 | BYTE reserved[10]; 58 | }ccb; 59 | 60 | BYTE mo=0,dy=0,wk=0,h=0,mi=0,s=0,ms=0, str[50]={0}; 61 | WORD off=0,seg=0,yy=0,cc=0; 62 | static BYTE Day[7][4] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; 63 | static BYTE Time[2][3] = {"am","pm"}; 64 | 65 | int get_sw(int nargs, char *arg[]); 66 | void put_dt(void); 67 | void put_tm(void); 68 | void set_dt(void); 69 | void set_tm(void); 70 | BYTE parse_tm(void); 71 | BYTE parse_dt(void); 72 | 73 | int main(int nargs, char *arg[]) 74 | { 75 | int set; 76 | if(nargs == 1) { 77 | put_dt(); 78 | printf(" "); 79 | put_tm(); 80 | printf("\n"); 81 | } 82 | else { 83 | set = get_sw(nargs,arg); 84 | if((set & DATE) == DATE){ 85 | put_dt(); 86 | printf("\n"); 87 | set_dt(); 88 | printf("\n"); 89 | } 90 | if((set & TIME) == TIME){ 91 | put_tm(); 92 | printf("\n"); 93 | set_tm(); 94 | printf("\n"); 95 | } 96 | } 97 | return 0; 98 | } 99 | 100 | #pragma argsused /* no complaints from the compiler */ 101 | int get_sw(int nargs, char *arg[]) 102 | { 103 | switch(toupper(arg[1][1])) { 104 | case '?': 105 | case 'H': 106 | default : 107 | printf("Usage: %s [-[s|d|t]]\ns = set date AND time\nd = set DATE\nt = set TIME\n",arg[0]); 108 | return NEITHER; 109 | case 'D': 110 | return DATE; 111 | case 'A': 112 | case 'S': 113 | return BOTH; 114 | case 'T': 115 | return TIME; 116 | } 117 | } 118 | 119 | void put_dt(void) 120 | { 121 | asm MOV AH,2Ah 122 | asm INT 21h ;/*get DATE*/ 123 | asm MOV wk,AL 124 | asm MOV dy,DL 125 | asm MOV mo,DH 126 | asm MOV yy,CX 127 | asm MOV DX, offset ccb 128 | asm MOV AX,3800h 129 | asm INT 21h ;/*get country info.*/ 130 | asm MOV cc,BX 131 | 132 | 133 | switch(ccb.dtf) { 134 | case 0: 135 | printf("%s %02d%s%02d%s%d",Day[wk],mo,ccb.dts,dy,ccb.dts,yy); 136 | break; 137 | case 1: 138 | printf("%s %02d%s%02d%s%d",Day[wk],dy,ccb.dts,mo,ccb.dts,yy); 139 | break; 140 | case 2: 141 | printf("%s %d%s%02d%s%02d",Day[wk],yy,ccb.dts,mo,ccb.dts,dy); 142 | break; 143 | } 144 | return; 145 | } 146 | 147 | void put_tm(void) { 148 | asm MOV AH,2Ch 149 | asm INT 21h ;/*GET TIME*/ 150 | asm MOV h,CH 151 | asm MOV mi,CL 152 | asm MOV s,DH 153 | asm MOV ms,DL 154 | asm MOV DX, offset ccb 155 | asm MOV AX,3800h 156 | asm INT 21h ;/*get country info.*/ 157 | asm MOV cc,BX 158 | 159 | 160 | if((ccb.tf&1) == 0) { 161 | if(h==0) h = 12; 162 | printf("%02d%s%02d%s%02d%c%02d%s",(h>12)?h-12:h,ccb.tms,mi,ccb.tms,s,(ccb.dtf==0)?'.':',',ms,(h>12)?Time[1]:Time[0]); 163 | } 164 | else 165 | printf("%02d%s%02d%s%02d%c%02d",h,ccb.tms,mi,ccb.tms,s,(ccb.dtf==0)?'.':',',ms); 166 | 167 | return; 168 | } 169 | 170 | void set_dt(void) 171 | { 172 | BYTE res; 173 | 174 | while(1) { 175 | printf("Enter new date "); 176 | switch(ccb.dtf) { 177 | case 0: 178 | printf("(mm%sdd%syy): ",ccb.dts,ccb.dts); 179 | break; 180 | case 1: 181 | printf("(dd%smm%syy): ",ccb.dts,ccb.dts); 182 | break; 183 | case 2: 184 | printf("(yy%smm%sdd: ",ccb.dts,ccb.dts); 185 | break; 186 | } 187 | res = parse_dt(); 188 | if(res==0x0FF) { 189 | puts("Invalid date.\n"); 190 | } 191 | else { 192 | break; 193 | } 194 | } 195 | return; 196 | } 197 | 198 | void set_tm(void) 199 | { 200 | BYTE res; 201 | 202 | while(1) { 203 | printf("Enter new time: "); 204 | res = parse_tm(); 205 | if(res == 0x0FF) 206 | puts("Invalid time.\n"); 207 | else 208 | break; 209 | } 210 | return; 211 | } 212 | 213 | 214 | BYTE parse_dt(void) 215 | { 216 | BYTE *p,l,i; 217 | 218 | p=gets(str); 219 | i=0; 220 | l=strlen(str); 221 | if(l==0) return 0; 222 | dy =0; mo=0;yy=0; 223 | switch(ccb.dtf) { 224 | case 0: 225 | while((isdigit(*p))&&(p31) || (mo>12)) return 0x0FF; 260 | switch(i) { 261 | case 1: 262 | yy +=2000; 263 | break; 264 | case 2: 265 | yy += (yy<80)?2000:1900; 266 | break; 267 | case 4: 268 | if((yy<1980)||(yy>2099)) return 0x0FF; 269 | break; 270 | default : 271 | return 0x0FF; 272 | } 273 | 274 | asm MOV AX,2B00h 275 | asm MOV CX,yy 276 | asm MOV DH,mo 277 | asm MOV dL,dy 278 | asm INT 21h 279 | asm MOV i,AL 280 | 281 | return i; 282 | } 283 | 284 | 285 | 286 | BYTE parse_tm(void) 287 | { 288 | BYTE *p,l,i; 289 | 290 | p=gets(str); 291 | i=0; 292 | l=strlen(str); 293 | if(l==0) return 0; 294 | h=0; mo=0; s=0; ms=0; 295 | 296 | while((isdigit(*p))&&(p23) || (mi>60) || (s>60) || (ms>99)) return 0x0FF; 307 | 308 | asm MOV AX,2D00h 309 | asm MOV CH,h 310 | asm MOV CL,mi 311 | asm MOV DH,s 312 | asm MOV dL,ms 313 | asm INT 21h ;/*set time*/ 314 | asm MOV i,AL 315 | 316 | return i; 317 | } 318 | -------------------------------------------------------------------------------- /dog/src/ext/mv.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MV.C - DOG - Alternate command processor for freeDOS 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | TODO: support moving over drives, implement -i 25 | 26 | History 27 | 18.03.00 - Extracted from DOG.C - WB 28 | 20.10.00 - Renamed nn to mv (It should havee been named mv from the beginning) 29 | Fixed do_mv. - WB 30 | 03.01.02 - Fixed bug that prevented moving to/from root directory (same as in 31 | rm.c) - WB 32 | 2003-03-11 - Added wildcard support - WB (used K.Harikirian's source from CP.C) 33 | 34 | **************************************************************************/ 35 | 36 | #include 37 | #include 38 | #include "ext.h" 39 | 40 | BYTE flag_i = FLAG_UNSET; 41 | BYTE flag_v = FLAG_UNSET; 42 | BYTE flag_h = FLAG_UNSET; 43 | 44 | WORD newname(BYTE *oldname, BYTE *newname); 45 | BYTE *trueName(BYTE *name,BYTE *tn); 46 | void print_help(void); 47 | 48 | int main(BYTE n, BYTE *arg[]) 49 | { 50 | struct ts_args { 51 | BYTE **patt; 52 | BYTE npatt; 53 | }mv_p; 54 | BYTE sn_fil[MAXPATH+13], st_fil[MAXPATH+13], dn_fil[MAXPATH+13], dt_fil[MAXPATH+13]; 55 | BYTE s_drv[MAXDRIVE], s_dir[MAXDIR], s_fil[MAXFILE], s_ext[MAXEXT]; 56 | BYTE d_drv[MAXDRIVE], d_dir[MAXDIR], d_fil[MAXFILE], d_ext[MAXEXT]; 57 | BYTE *p, b, ndir[129], odir[129], nn[129]={0},on[129]={0},tn[12]={0}, c; 58 | #ifdef MV_WILD 59 | BYTE fn[129]={0}, wild=0; 60 | #endif 61 | WORD r; 62 | BYTE i,j,k; 63 | struct ffblk ffb,*fb=&ffb; 64 | struct ffblk ff; 65 | 66 | k = 0; 67 | mv_p.npatt = 0; 68 | 69 | for(i=1;i 2) { 106 | fputs("Too many file arguments",stderr); 107 | print_help(); 108 | return -1; 109 | } 110 | 111 | strcpy(sn_fil,mv_p.patt[0]); 112 | fnsplit(sn_fil, s_drv, s_dir, s_fil, s_ext); 113 | 114 | strcpy(dn_fil,mv_p.patt[1]); 115 | 116 | b = findfirst(mv_p.patt[0],fb,FA_NORMAL|FA_DIREC|FA_ARCH|FA_SYSTEM|FA_RDONLY|FA_HIDDEN); 117 | if((b != 0) && (errno == ENOFILE) ) { 118 | printf("Can not find %s.\n",mv_p.patt[0]); 119 | return -1; 120 | } 121 | 122 | while (b == 0) { 123 | 124 | strcpy(sn_fil,mv_p.patt[0]); 125 | strcpy(dn_fil,mv_p.patt[1]); 126 | 127 | strcpy(sn_fil, s_drv); 128 | strcat(sn_fil, s_dir); 129 | strcat(sn_fil, ffb.ff_name); /*Got the fullpath of source*/ 130 | 131 | fnsplit(sn_fil, s_drv, s_dir, s_fil, s_ext); 132 | fnsplit(dn_fil, d_drv, d_dir, d_fil, d_ext); 133 | 134 | /*Replace wildcards '?' and/or '*'*/ 135 | for(j = 0; j < strlen(d_fil); j++){ 136 | /* fileneme */ 137 | if(d_fil[j] == '?'){ 138 | d_fil[j] = s_fil[j]; 139 | #ifdef MV_DEBUG 140 | printf("%s:%d: ? found at %d: s_fil[%d]=%c\n",__FILE__,__LINE__,j,j,s_fil[j]); 141 | #endif 142 | } 143 | else if((d_fil[j] == '*') && (strlen(s_fil) >= strlen(d_fil))){ 144 | #ifdef MV_DEBUG 145 | printf("%s:%d: * found at %d: s_fil='%s' d_fil='%s'\n",__FILE__,__LINE__,j,j,s_fil,d_fil); 146 | #endif 147 | for(k = j; k <= strlen(s_fil); k++){ 148 | d_fil[k] = s_fil[k]; 149 | } 150 | } 151 | else if((d_fil[j] == '*') && (strlen(s_fil) < strlen(d_fil))){ 152 | #ifdef MV_DEBUG 153 | printf("%s:%d: * found at %d: s_fil='%s' d_fil='%s', source SHORTER than dest\n",__FILE__,__LINE__,j,j,s_fil,d_fil); 154 | #endif 155 | for(k = j; k <= strlen(d_fil); k++){ 156 | d_fil[k] = '\0'; 157 | #ifdef MV_DEBUG 158 | printf("%s:%d: %d: s_fil[%d]='%c'\n",__FILE__,__LINE__,k,k,s_fil[k]); 159 | #endif 160 | } 161 | } 162 | } 163 | /* extension */ 164 | for(j = 0; j < strlen(d_ext); j++){ 165 | if(d_ext[j] == '?'){ 166 | d_ext[j] = s_ext[j]; 167 | #ifdef MV_DEBUG 168 | printf("%s:%d: ? found at %d: s_ext[%d]=%c\n",__FILE__,__LINE__,j,j,s_ext[j]); 169 | #endif 170 | } 171 | else if((d_ext[j] == '*') && (strlen(s_ext) >= strlen(d_ext))){ 172 | #ifdef MV_DEBUG 173 | printf("%s:%d: * found at %d: s_ext='%s' d_ext='%s'\n",__FILE__,__LINE__,j,j,s_ext,d_ext); 174 | #endif 175 | for(k = j; k <= strlen(s_ext); k++){ 176 | d_ext[k] = s_ext[k]; 177 | #ifdef MV_DEBUG 178 | printf("%s:%d: %d: s_ext[%d]='%c'\n",__FILE__,__LINE__,k,k,s_ext[k]); 179 | #endif 180 | } 181 | } 182 | else if((d_ext[j] == '*') && (strlen(s_ext) < strlen(d_ext))){ 183 | #ifdef MV_DEBUG 184 | printf("%s:%d: * found at %d: s_ext='%s' d_ext='%s', source SHORTER than dest\n",__FILE__,__LINE__,j,j,s_ext,d_ext); 185 | #endif 186 | for(k = j; k <= strlen(d_ext); k++){ 187 | d_ext[k] = '\0'; 188 | } 189 | } 190 | } 191 | 192 | strcpy(dn_fil, d_drv); 193 | strcat(dn_fil, d_dir); 194 | strcat(dn_fil, d_fil); 195 | strcat(dn_fil, d_ext); 196 | 197 | if(flag_v == FLAG_SET) printf("%s --> %s",sn_fil,dn_fil); 198 | if(flag_i == FLAG_SET) { 199 | if(findfirst(dn_fil,&ff,FA_NORMAL|FA_DIREC|FA_ARCH|FA_SYSTEM|FA_RDONLY|FA_HIDDEN)==0) { 200 | if((ff.ff_attrib & FA_DIREC) == FA_DIREC) 201 | printf(": Replace EXISTING directory? (Y/N)? "); 202 | else 203 | printf(": Replace EXISTING file? (Y/N)? "); 204 | c=(BYTE)getchar(); 205 | if(c=='y' || c=='Y') { 206 | if((ff.ff_attrib & FA_DIREC) == FA_DIREC) { 207 | if(rmdir(dn_fil)!=0) { 208 | printf("Error removing directory"); 209 | b = findnext(fb); 210 | continue; 211 | } 212 | } 213 | else { 214 | if(unlink(dn_fil)!=0) { 215 | printf("Error removing file"); 216 | b = findnext(fb); 217 | continue; 218 | } 219 | } 220 | } 221 | } 222 | else { 223 | if((ffb.ff_attrib & FA_DIREC) == FA_DIREC) 224 | printf(": Move directory? (Y/N)? "); 225 | else 226 | printf(": Move file? (Y/N)? "); 227 | c=(BYTE)getchar(); 228 | if(c=='y' || c=='Y'); 229 | else { 230 | b = findnext(fb); 231 | continue; 232 | } 233 | } 234 | } 235 | 236 | printf("\n"); 237 | 238 | 239 | if(rename(sn_fil,dn_fil)!=0) { 240 | switch(errno) { 241 | case ENOENT: 242 | printf("Can not find file or directory %s.\n",sn_fil); 243 | break; 244 | case EACCES: 245 | puts("Access denied."); 246 | break; 247 | case ENOTSAM: 248 | puts("Source and destination on different drives"); 249 | break; 250 | } 251 | } 252 | 253 | b = findnext(fb); 254 | } 255 | return 0; 256 | 257 | } 258 | 259 | /**************************************************************************/ 260 | 261 | WORD newname(BYTE *oldname, BYTE *newname) 262 | { 263 | WORD r; 264 | 265 | asm mov ah,56h 266 | asm push ds 267 | asm pop es 268 | asm mov dx,oldname 269 | asm mov di,newname 270 | asm int 21h 271 | asm jnc nn_ok 272 | asm mov r,ax 273 | 274 | 275 | return r; 276 | nn_ok: 277 | printf("r=0x%x\n",r); 278 | 279 | return 0; 280 | } 281 | 282 | /**************************************************************************/ 283 | 284 | void print_help(void) 285 | { 286 | fputs("Usage: MV [OPTION]... SOURCE DEST\n or: MV [OPTION]... [PATH\\]PATTERN1 [PATH\\]PATTERN2\n\n", stderr); 287 | fputs("MoVe (Rename) SOURCE to DEST or All files with PATTERN1 [with an optional path]\n" 288 | " to new names with PATTERN2 [with an optionional path]",stderr); 289 | fputs("The OPTIONS are:\n",stderr); 290 | fputs("\t-v: verbose: print filename of each moved file\n",stderr); 291 | /* \t-i: interactive mode: prompt (Y/N) for each file or directory\n */ 292 | fputs(" -h|-H|-?: display this help and exit\n",stderr); 293 | fputs("\nFILE is a name of a file to write\n", stderr); 294 | fputs("\nMV is part of DOG (http://dog.sf.net/)\n", stderr); 295 | } 296 | -------------------------------------------------------------------------------- /dog/src/ext/ds.c: -------------------------------------------------------------------------------- 1 | /* 2 | ds.c - Directory stack implementation for DOG. 3 | Copyright (C) 2004 K. Hari Kiran, 2024 Wolf Bergenheim 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | History 20 | 2004-06-05 - Initial implementation - KHK 21 | 2024-06-30 - Using DSDIR env variable to point to the directory stack file. 22 | 2024-07-01 - Secondary location is TEMP directory, with fall back to using 23 | the directory of the executable. - WB 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /* used for storing the stack file of DS */ 35 | char Stack_File[MAXPATH]; 36 | /* used for storing the temp stack file of DS */ 37 | char Temp_Stack[MAXPATH]; 38 | 39 | /* sets the Stack_File and Temp_File */ 40 | void Set_Stack_Files(char *Exe_Name) 41 | { 42 | /* used for storing the directory of DS */ 43 | char Stack_Path[MAXPATH]; 44 | char *dsDir; 45 | /* First look for the DSFile env variable */ 46 | dsDir = getenv("DSDIR"); 47 | if (dsDir == NULL) { 48 | dsDir = getenv("TEMP"); 49 | if (dsDir == NULL) { 50 | /* copy complete path and file name of DS.COM 51 | i.e. "DRIVE:\SOMEDIR\DS.COM" */ 52 | strcpy(Stack_Path, Exe_Name); 53 | /* null terminate this at the last occurance of '\' 54 | i.e. "DRIVE:\SOMEDIR\DS.COM" becomes "DRIVE:\SOMEDIR\" */ 55 | Stack_Path[(strrchr(Stack_Path, '\\') - Stack_Path) + 1] = '\0'; 56 | } 57 | else { 58 | strcpy(Stack_Path, dsDir); 59 | } 60 | } 61 | else { 62 | strcpy(Stack_Path, dsDir); 63 | } 64 | /* build full path and name for both files */ 65 | strcpy(Stack_File, Stack_Path); 66 | strcat(Stack_File, "\\stack.dat"); 67 | 68 | strcpy(Temp_Stack, Stack_Path); 69 | strcat(Temp_Stack, "\\stack.tmp"); 70 | } 71 | 72 | 73 | /* returns true if directory stack is empty */ 74 | int Empty_Dir(FILE *Stream) 75 | { 76 | fgetc(Stream); /* read one character */ 77 | 78 | if(feof(Stream)) /* EOF reached */ 79 | return 1; 80 | else 81 | return 0; 82 | } 83 | 84 | /* pops a directory off the stack and returns it */ 85 | char *Pop_Dir(void) 86 | { 87 | FILE *Stack, *Temp; /* streams for the stack and temp file */ 88 | unsigned long Current_Line = 0, Total_Lines = 0; /* line counts */ 89 | char *Dir_Name = malloc(MAXPATH); /* popped directory name */ 90 | if (Dir_Name == NULL) { 91 | printf("DS: out of memory\n"); 92 | } 93 | 94 | /* open the files */ 95 | /* "at+" mode is used since we want to create a file if it does not exist 96 | and we want to read it, using "w" overwrites a file */ 97 | if((Stack = fopen(Stack_File, "at+")) == NULL) 98 | { 99 | printf("DS: error creating stack file\n"); 100 | return NULL; 101 | } 102 | 103 | /* "w" mode is used since we want to always overwrite the temporary file */ 104 | if((Temp = fopen(Temp_Stack, "wt")) == NULL) 105 | { 106 | printf("DS: error creating temporary file\n"); 107 | fclose(Stack); 108 | return NULL; 109 | } 110 | 111 | /* not an empty stack */ 112 | if(!Empty_Dir(Stack)) 113 | { 114 | /* determine the number of lines in the file */ 115 | while(!feof(Stack)) 116 | { 117 | fgets(Dir_Name, MAXPATH, Stack); 118 | Total_Lines++; 119 | } 120 | 121 | /* rewind file pointer since we have reached EOF in 122 | determining the no of lines */ 123 | rewind(Stack); 124 | 125 | /* start over */ 126 | while(!feof(Stack)) 127 | { 128 | fgets(Dir_Name, MAXPATH, Stack); 129 | 130 | Current_Line++; 131 | 132 | /* copy all lines except the last one on to the temporary file */ 133 | if(Current_Line < Total_Lines - 1) 134 | { 135 | fputs(strupr(Dir_Name), Temp); 136 | } 137 | } 138 | 139 | /* close both files */ 140 | fclose(Stack); 141 | fclose(Temp); 142 | 143 | unlink(Stack_File); /* delete old stack file */ 144 | rename(Temp_Stack, Stack_File); /* rename temporary file to stack file */ 145 | 146 | /* null terminate to get rid of trailing '\n' */ 147 | Dir_Name[strlen(Dir_Name) - 1] = '\0'; 148 | 149 | return Dir_Name; /* return popped directory name */ 150 | } 151 | else /* an empty stack */ 152 | { 153 | printf("DS: directory stack empty\n"); 154 | 155 | /* close both files */ 156 | fclose(Stack); 157 | fclose(Temp); 158 | 159 | /* remove temporary file */ 160 | unlink(Temp_Stack); 161 | 162 | return NULL; /* error */ 163 | } 164 | } 165 | 166 | /* pushes a directory onto the stack */ 167 | void Push_Dir(char *Dir_Name) 168 | { 169 | FILE *Stack; /* stream for stack file */ 170 | 171 | /* open file for appending */ 172 | if((Stack = fopen(Stack_File, "at")) == NULL) 173 | { 174 | printf("DS: error creating stack file\n"); 175 | return; 176 | } 177 | 178 | /* put the directory onto the file and append a new line */ 179 | fputs(strupr(Dir_Name), Stack); 180 | fputs("\n", Stack); 181 | 182 | /* close stack file */ 183 | fclose(Stack); 184 | } 185 | 186 | /* prints the stack */ 187 | void Print_Stack(void) 188 | { 189 | FILE *Stack; /* stream for stack file */ 190 | char Dir_Name[MAXPATH]; /* popped directory name */ 191 | 192 | /* open file for appending */ 193 | if((Stack = fopen(Stack_File, "r")) == NULL) 194 | { 195 | printf("DS: error creating stack file\n"); 196 | return; 197 | } 198 | 199 | while(!feof(Stack)) 200 | { 201 | if(fgets(Dir_Name, MAXPATH, Stack) != NULL) 202 | printf(strupr(Dir_Name)); 203 | } 204 | 205 | /* close stack file */ 206 | fclose(Stack); 207 | } 208 | 209 | /* changes the directory */ 210 | int Change_Directory(char *New_Dir) 211 | { 212 | char Drive[MAXPATH]; /* drive of the specified path */ 213 | 214 | /* get the drive of the specified path */ 215 | fnsplit(New_Dir, Drive, NULL, NULL, NULL); 216 | 217 | /* if drive is there; sometimes only directory names are 218 | pushed onto the stack */ 219 | if(Drive != NULL) 220 | { 221 | /* change drive first if the drive of the specified 222 | path not equal to current working drive */ 223 | if((toupper(Drive[0])) != ('A' + getdisk())) 224 | setdisk(toupper(Drive[0]) - 'A'); 225 | } 226 | 227 | /* change the working directory */ 228 | if(chdir(New_Dir) == -1) { 229 | printf("DS: path not found\n"); 230 | return -1; 231 | } 232 | return 0; 233 | } 234 | 235 | /* main function */ 236 | void main(int argc, char *argv[]) 237 | { 238 | char Current_Dir[MAXPATH], *New_Dir; /* directory names */ 239 | 240 | Set_Stack_Files(argv[0]); /* build paths for files */ 241 | 242 | if(argc < 2) 243 | { 244 | printf("DS: insufficient arguments\n"); 245 | return; 246 | } 247 | 248 | if(argv[1][0] == '-') 249 | { 250 | if(strcmpi(argv[1] + 1, "h") == 0) 251 | { 252 | puts("DS push [[drive:]path]|pop|clear\n"); 253 | puts(" push pushes the current directory on to the stack, if a\n" 254 | " directory name is given the current directory is changed\n" 255 | " to that directory\n" 256 | " [drive:]path the directory to change to with optional drive\n" 257 | " pop pops a directory off the stack and change to that directory\n" 258 | " clear clears the stack\n" 259 | " list lists the entire stack"); 260 | } 261 | else 262 | printf("DS: invalid switch\n"); 263 | 264 | return; 265 | } 266 | 267 | if(strcmpi(argv[1], "pop") == 0) /* pop operation*/ 268 | { 269 | New_Dir = Pop_Dir(); /* pop it */ 270 | if(New_Dir != NULL) { /* if not null (end-of-stack) change directory */ 271 | Change_Directory(New_Dir); 272 | } 273 | } 274 | else if(strcmpi(argv[1], "push") == 0) /* push operation */ 275 | { 276 | getcwd(Current_Dir, MAXPATH); /* get the new directory */ 277 | Push_Dir(Current_Dir); /* push the new directory onto the stack */ 278 | /* argument of the form "push dirname" so change to "dirname" */ 279 | if(argc > 2) { 280 | if (Change_Directory(argv[2]) == -1) { 281 | return; 282 | } 283 | } 284 | } 285 | else if(strcmpi(argv[1], "clear") == 0) /* clear operation */ 286 | { 287 | /* remove the stack file */ 288 | unlink(Stack_File); 289 | } 290 | else if(strcmpi(argv[1], "list") == 0) /* clear operation */ 291 | { 292 | Print_Stack(); 293 | /* remove the stack file */ 294 | 295 | } 296 | else /* some other options? syntax error */ 297 | printf("DS: syntax error\n"); 298 | } 299 | -------------------------------------------------------------------------------- /dog/src/ext/rm.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | RM.C - DOG - Alternate command processor for freeDOS 4 | 5 | Copyright (C) 1999,2000 Wolf Bergenheim 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Developers: 22 | Wolf Bergenheim (WB) 23 | 24 | History 25 | 18.03.00 - Extracted from DOG.C - WB 26 | 2024-06-01 - Made the RT command buildable and documented. 27 | 2024-11-11 - Added -a flag to (try) to also remove hidden and system files. 28 | Read-Only files will get permission denied error. 29 | **************************************************************************/ 30 | #include "ext.h" 31 | 32 | #include 33 | 34 | #define MODE_RM 0 35 | #define MODE_RT 1 36 | 37 | BYTE flag_i = FLAG_UNSET; 38 | BYTE flag_r = FLAG_UNSET; 39 | BYTE flag_v = FLAG_UNSET; 40 | BYTE flag_h = FLAG_UNSET; 41 | BYTE flag_a = FLAG_UNSET; 42 | 43 | BYTE search_attribs = 0; 44 | 45 | BYTE rm_dir(BYTE *dir); 46 | BYTE rm_file(BYTE *patt); 47 | BYTE rm_list(BYTE *list); 48 | 49 | BYTE rm_dir(BYTE *dir) 50 | { 51 | BYTE path[80]; 52 | strcpy(path,dir); 53 | strcat(path,"\\*.*"); 54 | #ifdef RM_DEBUG 55 | printf("rm_dir (%d): path=(%s)[%x] dir=(%s)[%x]\n",__LINE__,path,path,dir,dir); 56 | #endif 57 | return rm_file((BYTE *)path); 58 | 59 | } 60 | 61 | BYTE rm_file(BYTE *patt) 62 | { 63 | BYTE r,f,i,ok=0,ret=0; 64 | BYTE *p; 65 | BYTE fn[129]={0}; 66 | struct ffblk fb; 67 | 68 | #ifdef RM_DEBUG 69 | printf("rm_file (%d): patt=(%s)[%x]\n",__LINE__,patt,patt); 70 | #endif 71 | 72 | f=findfirst(patt,&fb,search_attribs|FA_DIREC); 73 | #ifdef RM_DEBUG 74 | printf("rm_file (%d): patt=(%s)[%x] f=%x\n",__LINE__,patt,patt,f); 75 | #endif 76 | 77 | if(f==0) { 78 | 79 | p = patt; 80 | p+=strlen(patt) - 1; 81 | if((*p == '\\') || (*p == '/')) { 82 | *p = '\0'; 83 | p--; 84 | } 85 | for(;(*p!='\\')&&(*p!='/');p--); 86 | if(p>patt) { 87 | *(++p)=0; 88 | strcpy(fn,patt); 89 | strcat(fn,fb.ff_name); 90 | } 91 | else 92 | strcpy(fn,fb.ff_name); 93 | 94 | #ifdef RM_DEBUG 95 | printf("rm_file (%d): fn=(%s)[%x]\n",__LINE__,fn,fn); 96 | #endif 97 | if((fb.ff_name)[0] != '.') { 98 | #ifdef RM_DEBUG 99 | printf("rm_file (%d): fb.ff_name=(%s)[%x],ok=%x\n",__LINE__,fb.ff_name,fb.ff_name,ok); 100 | #endif 101 | 102 | if(flag_i == FLAG_SET) { 103 | printf("remove %s (Y/N/A)? ",fn); 104 | r = getch(); 105 | if (r==3) /* C-c */ 106 | return -1; 107 | else 108 | printf("%c\n",r); 109 | 110 | if((r=='A') || (r=='a')) { 111 | r = 'y'; 112 | flag_i = FLAG_UNSET; 113 | } 114 | #ifdef RM_DEBUG 115 | printf("rm_file (%d): r=(%c)[%x],ok=%x\n",__LINE__,r,r,ok); 116 | #endif 117 | if((r == 'y') || (r == 'Y')) { 118 | if((fb.ff_attrib & FA_DIREC) == FA_DIREC) { 119 | if(flag_r == FLAG_SET) { 120 | ret = rm_dir(fn); 121 | } 122 | #ifdef RM_DEBUG 123 | printf("rm_file (%d): fb.ff_name=(%s)[%x],ok=%x\n",__LINE__,fb.ff_name,fb.ff_name,ok); 124 | #endif 125 | ok = rmdir(fn); 126 | } 127 | else 128 | ok = unlink(fn); 129 | 130 | if(ok==0) { 131 | if(flag_v == FLAG_SET) { 132 | puts(fn); 133 | } 134 | } 135 | else { 136 | ret = 1; 137 | printf("error while removing %s ",fn); 138 | perror(""); 139 | } 140 | 141 | } 142 | } 143 | else { 144 | if((fb.ff_attrib & FA_DIREC) == FA_DIREC) { 145 | if(flag_r == FLAG_SET) { 146 | ret = rm_dir(fn); 147 | } 148 | #ifdef RM_DEBUG 149 | printf("rm_file (%d): fb.ff_name=(%s)[%x],ok=%x\n",__LINE__,fb.ff_name,fb.ff_name,ok); 150 | #endif 151 | ok = rmdir(fn); 152 | } 153 | else 154 | ok = unlink(fn); 155 | 156 | if(ok==0) { 157 | if(flag_v == FLAG_SET) { 158 | puts(fn); 159 | } 160 | } 161 | else { 162 | ret = 1; 163 | printf("error while removing %s ",fn); 164 | perror(""); 165 | } 166 | 167 | } 168 | 169 | #ifdef RM_DEBUG 170 | printf("rm_file (%d): fb.ff_name=(%s)[%x],ok=%x\n",__LINE__,fb.ff_name,fb.ff_name,ok); 171 | #endif 172 | } 173 | } 174 | else if((f==255) && (errno==2)) { 175 | ret = 1; 176 | printf("%s - no such file or directory.\n",patt); 177 | } 178 | 179 | #ifdef RM_DEBUG 180 | printf("rm_file (%d): f=(%d)[%x],ok=%x\n",__LINE__,f,f,fb.ff_name,ok); 181 | #endif 182 | 183 | while((f=findnext(&fb))==0) { 184 | #ifdef RM_DEBUG 185 | printf("rm_file (%d): f=(%d)[%x],ok=%d\n",__LINE__,f,f,fb.ff_name,ok); 186 | printf("rm_file (%d): fb.ff_name=(%s)[%x],ok=%x\n",__LINE__,fb.ff_name,fb.ff_name,ok); 187 | #endif 188 | if(fb.ff_name[0] == '.') 189 | continue; /* ignore . and .. */ 190 | for(p+=strlen(patt)+1;(*p!='\\')&&(*p!='/');p--); 191 | if(p>patt) { 192 | *(++p)=0; 193 | strcpy(fn,patt); 194 | if((*p != '\\') && (*p != '/')) 195 | strcat(fn,fb.ff_name); 196 | } 197 | else 198 | strcpy(fn,fb.ff_name); 199 | #ifdef RM_DEBUG 200 | printf("rm_file (%d): fb.ff_name=(%s)[%x],ok=%x\n",__LINE__,fb.ff_name,fb.ff_name,ok); 201 | #endif 202 | 203 | if(flag_i == FLAG_SET) { 204 | printf("remove %s (Y/N/A)? ",fn); 205 | /* Get character */ 206 | r = getch(); 207 | if (r==3) /* C-c */ 208 | return -1; 209 | else 210 | printf("%c\n",r); 211 | 212 | #ifdef RM_DEBUG 213 | printf("rm_file (%d): r=(%c)[%x],ok=%x\n",__LINE__,r,r,ok); 214 | #endif 215 | if((r=='A') || (r=='a')) { 216 | r = 'y'; 217 | flag_i = FLAG_UNSET; 218 | } 219 | 220 | if((r != 'y') && (r != 'Y')) { 221 | ret = 1; 222 | continue; 223 | } 224 | } 225 | 226 | if((fb.ff_attrib & FA_DIREC) == FA_DIREC) { 227 | if(flag_r == FLAG_SET) { 228 | rm_dir(fn); 229 | } 230 | ok = rmdir(fn); 231 | } 232 | else 233 | ok = unlink(fn); 234 | if(ok==0) { 235 | if(flag_v == FLAG_SET) { 236 | puts(fn); 237 | } 238 | } 239 | else { 240 | ret = 1; 241 | printf("error while removing %s ",fn); 242 | perror(""); 243 | } 244 | } 245 | return ret; 246 | } 247 | 248 | BYTE rm_list(BYTE *list) 249 | { 250 | BYTE fn[129]={0}; 251 | FILE *f; 252 | BYTE ret=0; 253 | 254 | #ifdef RM_DEBUG 255 | fprintf(stderr,"list=(%s)\n",list); 256 | #endif 257 | 258 | f = fopen(list,"r"); 259 | if(f != NULL) { 260 | while(fscanf(f,"%s",&fn)!=EOF){ 261 | ret = rm_file(fn); 262 | } 263 | fclose(f); 264 | } 265 | else { 266 | ret = 1; 267 | fprintf(stderr,"Can not open list-file: %s - ",list); 268 | perror(""); 269 | } 270 | 271 | return ret; 272 | 273 | } 274 | 275 | void print_help(BYTE mode) { 276 | if(mode == MODE_RM) 277 | printf("Usage: RM [OPTION]... FILE...\n\nRemove the FILE(s).\n\n"); 278 | else 279 | printf("Usage: RT [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(s) with all subdirectories and files.\n\n"); 280 | printf("The OPTIONS are:\n\t-i: interactive mode: prompt (Yes/No/All) for each file or directory\n"); 281 | printf("\t-v: verbose: print filename of each removed file\n"); 282 | if(mode == MODE_RM) { 283 | printf("\t-a: also remove read-only, system and hidden files\n"); 284 | printf("\t-r: recurse sub-directories. Removes all files in subdirectories too\n"); 285 | printf("\t if the program is executed as rt, -r is implicit\n"); 286 | } 287 | printf(" -h|-H|-?: display this help and exit\n"); 288 | if(mode == MODE_RM) 289 | printf("\nFILE is either a filename OR a filename preceeded by '@',\n"); 290 | else 291 | printf("\nDIRECTORY is either a directory OR a filename preceeded by '@',\n"); 292 | printf(" in which case the file is opened and read, treating every\n" 293 | " line as a file/directory to remove.\n"); 294 | printf("\nRM is part of DOG (https://dog.zumppe.net/)\n"); 295 | return; 296 | } 297 | 298 | int main(BYTE n,BYTE *arg[]) 299 | { 300 | BYTE r,f,i,j,dir[80]; 301 | BYTE mode = MODE_RM; 302 | int ret = 0; 303 | 304 | if(strstr(arg[0],"RT.COM")!=NULL) { 305 | mode = MODE_RT; 306 | flag_r = FLAG_SET; 307 | } 308 | 309 | if(n > 1) { 310 | 311 | /* check flags */ 312 | for(i=1;i 27 | this feature is now disabled 28 | 2002-11-21 - Improved help text, prints to std err - WB 29 | 2024-07-02 - Add -z for human a readable size, like ls - WB 30 | 2024-07-04 - Add -r to recurse into subdirectories - WB 31 | **************************************************************************/ 32 | 33 | #include "ext.h" 34 | 35 | #define FLAG_K 0x01 /* 0000 0001 */ 36 | #define FLAG_M 0x02 /* 0000 0010 */ 37 | #define FLAG_Z 0x04 /* 0000 0100 */ 38 | #define FLAG_R 0x08 /* 0000 1000 */ 39 | 40 | #define GIGA 1073741824 41 | #define MEGA 1048576 42 | #define KILO 1024 43 | 44 | DWORD disk_free = 0, disk_size = 0; 45 | 46 | struct ts_flags 47 | { 48 | WORD attrs; 49 | BYTE **patt; 50 | BYTE npatt; 51 | BYTE flags; 52 | }sz_f; 53 | 54 | struct sz_fsize 55 | { 56 | DWORD fsize; 57 | DWORD hsize; 58 | WORD fn; 59 | WORD hn; 60 | }; 61 | 62 | void do_sz(void); 63 | int init(int nargs, char *arg[]); 64 | char * format_size(DWORD sz, BYTE *s); 65 | struct sz_fsize* sz_dir(BYTE *dir); 66 | struct sz_fsize* mk_sz_fsize(void); 67 | void add_sz_fsize(struct sz_fsize *sz, struct sz_fsize *add); 68 | struct sz_fsize* sz_file(BYTE *patt); 69 | void print_size(char *patt, struct sz_fsize *sz); 70 | 71 | struct sz_fsize* sz_dir(BYTE *dir) 72 | { 73 | struct sz_fsize *sz; 74 | BYTE *patt; 75 | 76 | patt = malloc(strlen(dir)+4); 77 | if (patt == NULL) { 78 | fprintf(stderr, "Out of memory! (malloc failed in sz_dir)\n"); 79 | exit(-1); 80 | } 81 | strcpy(patt, dir); 82 | strcat(patt, "\\*.*"); 83 | #ifdef SZ_DEBUG 84 | printf("sz_dir (%d): patt=(%s)[%x] dir=(%s)[%x]\n",__LINE__,patt,patt,dir,dir); 85 | #endif 86 | 87 | sz = sz_file(patt); 88 | free(patt); 89 | return sz; 90 | } 91 | 92 | struct sz_fsize* mk_sz_fsize(void) 93 | { 94 | struct sz_fsize *sz; 95 | sz = malloc(sizeof(struct sz_fsize)); 96 | if (sz == NULL) { 97 | fprintf(stderr, "Out of memory! (malloc failed in mk_sz_fsize)\n"); 98 | exit(-1); 99 | } 100 | sz->fsize=0; 101 | sz->hsize=0; 102 | sz->fn=0; 103 | sz->hn=0; 104 | return sz; 105 | } 106 | 107 | void add_sz_fsize(struct sz_fsize *sz, struct sz_fsize *add) 108 | { 109 | sz->fsize += add->fsize; 110 | sz->hsize += add->hsize; 111 | sz->fn += add->fn; 112 | sz->hn += add->hn; 113 | } 114 | 115 | struct sz_fsize *sz_file(BYTE *patt) 116 | { 117 | struct sz_fsize *sz; 118 | struct sz_fsize *dsz; 119 | struct ffblk *fb; 120 | BYTE *dir, *p; 121 | WORD nf, hf; 122 | int done, attr; 123 | DWORD s, h; 124 | 125 | fb = malloc(sizeof(struct ffblk)); 126 | if (fb == NULL) { 127 | fprintf(stderr, "Out of memory! (malloc failed in sz_file)\n"); 128 | exit(-1); 129 | } 130 | sz = mk_sz_fsize(); 131 | 132 | #ifdef SZ_DEBUG 133 | fprintf(stderr,"sz_file:1: patt=%s\n",patt); 134 | #endif 135 | 136 | done = findfirst(patt, fb, sz_f.attrs); 137 | while(!done) { 138 | #ifdef SZ_DEBUG 139 | fprintf(stderr,"sz_file:2: date:%x time:%x size:%lu name:%s\n", 140 | fb->ff_fdate,fb->ff_ftime, fb->ff_fsize, fb->ff_name); 141 | #endif 142 | if ( (fb->ff_attrib & FA_HIDDEN) == FA_HIDDEN ) { 143 | sz->hsize += fb->ff_fsize; 144 | sz->hn++; 145 | } 146 | else if ((fb->ff_attrib & FA_DIREC) == FA_DIREC) { 147 | if (fb->ff_name[0] != '.') { // ignore . and .. 148 | dir = malloc(strlen(patt)+strlen(fb->ff_name)); 149 | if (dir == NULL) { 150 | fprintf(stderr, "Out of memory! (malloc failed in sz_file)\n"); 151 | exit(-1); 152 | } 153 | strcpy(dir, patt); 154 | #ifdef SZ_DEBUG 155 | printf("sz_file:3a: dir='%s'\n"); 156 | #endif 157 | p = strrchr(dir, '\\'); 158 | #ifdef SZ_DEBUG 159 | printf("sz_file:3b: dir='%s'\n"); 160 | #endif 161 | if (p == NULL) { 162 | p = dir + strlen(dir)-1; 163 | } 164 | else { 165 | p++; 166 | *p='\0'; 167 | } 168 | #ifdef SZ_DEBUG 169 | printf("sz_file:3c: dir='%s'\n"); 170 | #endif 171 | strcat(dir, fb->ff_name); 172 | #ifdef SZ_DEBUG 173 | printf("sz_file:3d: dir='%s'\n"); 174 | #endif 175 | dsz = sz_dir(dir); 176 | #ifdef SZ_DEBUG 177 | print_size(fb->ff_name, dsz); 178 | #endif 179 | add_sz_fsize(sz, dsz); 180 | free(dir); 181 | free(dsz); 182 | } 183 | } 184 | else { 185 | sz->fsize += fb->ff_fsize; 186 | sz->fn++; 187 | } 188 | done = findnext(fb); 189 | } 190 | free(fb); 191 | return sz; 192 | } 193 | 194 | void print_size(char *patt, struct sz_fsize *sz) 195 | { 196 | BYTE *p, s10[10], s10h[10]; 197 | DWORD s, h; 198 | 199 | printf("\n\n%s:", patt); 200 | if ((sz_f.flags & FLAG_Z) == FLAG_Z) { 201 | printf("\n%10s in %d file(s)" 202 | "\n%10s in %d hidden file(s)\n", 203 | format_size(sz->fsize, s10), sz->fn, 204 | format_size(sz->hsize, s10h), sz->hn); 205 | } 206 | else { 207 | if ((sz_f.flags & FLAG_K) == FLAG_K) { 208 | h = sz->hsize / KILO; 209 | s = sz->fsize / KILO; 210 | p = "kilo"; 211 | } 212 | else if ((sz_f.flags & FLAG_M) == FLAG_M) { 213 | h = sz->hsize / MEGA; 214 | s = sz->fsize / MEGA; 215 | p = "mega"; 216 | } 217 | else { 218 | h = sz->hsize; 219 | s = sz->fsize; 220 | p = ""; 221 | } 222 | printf("\n%11lu %sbytes in %d file(s)\n" 223 | "%11lu %sbytes in %d hidden file(s)\n", 224 | s, p, sz->fn, h, p, sz->hn); 225 | } 226 | } 227 | 228 | /* 229 | * Returns a char string representing the size in human readable form: 230 | * e.g. 231 | * - >1024 ==> 1KB 232 | * - >1048576 ==> 1MB 233 | * - etc. 234 | */ 235 | char * format_size(DWORD sz, BYTE *s) 236 | { 237 | unsigned long int f; 238 | 239 | if (sz < KILO) { 240 | sprintf(s, "%lu B ", sz); 241 | } 242 | else if (sz < MEGA) { 243 | f = ((sz % KILO) * 10) / KILO; /* 1 decimal point */ 244 | sz = sz / KILO; 245 | sprintf(s, "%lu.%u KB", sz, f); 246 | } 247 | else if (sz < GIGA) { 248 | f = ((sz % MEGA) * 10) / MEGA; /* 1 decimal point */ 249 | sz = sz / MEGA; 250 | sprintf(s, "%lu.%u MB", sz, f); 251 | } 252 | else { 253 | f = ((sz % GIGA) / KILO); 254 | f = (f * 10) / KILO; 255 | f = f / KILO; /* 1 decimal point, keep it within long int... */ 256 | sz = sz / GIGA; 257 | sprintf(s, "%lu.%u GB", sz, f); 258 | } 259 | 260 | return s; 261 | } 262 | 263 | void do_sz(void) 264 | { 265 | struct sz_fsize *tsz; 266 | struct sz_fsize *sz; 267 | BYTE i, c; 268 | 269 | tsz = mk_sz_fsize(); 270 | 271 | for(i=0;i < sz_f.npatt;i++) { 272 | c = sz_f.patt[i][strlen(sz_f.patt[i])-1]; 273 | if((c == '\\') || (c == ':')) { 274 | sz = sz_dir(sz_f.patt[i]); 275 | } else { 276 | sz = sz_file(sz_f.patt[i]); 277 | } 278 | add_sz_fsize(tsz, sz); 279 | print_size(sz_f.patt[i], sz); 280 | free(sz); 281 | } 282 | if (sz_f.npatt > 1) { 283 | print_size("Total", tsz); 284 | } 285 | free(tsz); 286 | } 287 | 288 | /* 289 | * Return -1 for error 0 for OK 1 for OK, but stop (e.g. help) 290 | */ 291 | int init(int nargs, char *arg[]) 292 | { 293 | BYTE t,i,j,k,*p; 294 | WORD df[2], dt[2]; 295 | 296 | sz_f.npatt = 0; 297 | sz_f.patt = (BYTE **) malloc(nargs * (sizeof(BYTE *))); 298 | if (sz_f.patt == NULL) { 299 | fprintf(stderr, "Out of memory! (malloc failed in init)\n"); 300 | exit(-1); 301 | } 302 | 303 | sz_f.patt[0] = "*.*"; 304 | 305 | #ifdef SZ_DEBUG 306 | fprintf(stderr,"init:0: sz_f.patt[0]=%s; nargs=%d\n",sz_f.patt[0],nargs); 307 | #endif 308 | 309 | sz_f.attrs = FA_NORMAL|FA_HIDDEN|FA_SYSTEM; 310 | sz_f.flags = 0; 311 | k = 0; 312 | 313 | if (nargs > 1) { 314 | for(i=1;i