Category : C Source Code
Archive   : COMMAND.ZIP
Filename : COMMAND.C

 
Output of file : COMMAND.C contained in archive : COMMAND.ZIP
#include
#include
#include

/*
A replacement for COMMAND.COM

T. Jennings 28 Dec 84

Docs? You cant be serious ...

Modified 11/5/85 by T. Revay
This program must be linked with scrn.obj & sound.obj.

*/

version = 1; /* second (ahem) version */
char drive = 'A';
char alldrives[] = "BOZO";
unsigned rnd; /* fake random number */
int gl_abort = 0; /* command line DOSABORT() chance figure */

#define BACKDOOR 10 /* Ctrl-J pops you out in DOSABORT() */
#define same(s1,s2) (strcmp(s1,s2) == 0)
#define TRUE 1
#define FALSE 0

main(argc, argv)
int argc;
char **argv;
{

long l;
char ln[132];
char cmd[80],*arg,*cp;

for (l= 10000L; l > 0L; l--); /* look busy */

cprintf("Current date is Tue 1-01-1980\r\n");
get(ln,"Enter New date: ");
cprintf("Current time is 0:01:21.32\r\n");
get(ln,"Enter new time: ");

cprintf("\r\n\r\nThe IBM Personal Computer DOS\r\n");
cprintf("Version 2.00 (C)Copywrong IBM Corp 1981, 1982, 1983 so there\r\n");

if (argc > 1)
gl_abort = atoi(argv[1]);

if (gl_abort == 0)
gl_abort = 1;

/* Now the fun starts */

drive= 'A';
while (1) {
cprintf("%c>",drive);
newdrive( &drive );
if (!get(ln,"")) continue; /* get command line */
arg= cmd; /* copy of command name */
cp= ln;
while (*cp && (*cp != ' '))
*arg++= *cp++;
*arg= '\0'; /* terminate cmd name */
while (*cp && (*cp == ' ')) /* skip spaces, etc */
++cp;
arg= cp; /* arg is cmd tail */

if (same(cmd,"dir")) { dir(); continue; }
if (same(cmd,"ver")) { ver(); continue; }
if (same(cmd,"basic")) {basic(); continue; }
if (same(cmd, "bozo")) { goway(); continue; }
if (same(cmd, "help")) { help(); continue; }
if (same(cmd, "find")) {find(arg); continue; }
if (same(cmd,"basica")) {basica(); continue; }
if (same(cmd,"cls")) { cls(); continue; }
if (same(cmd, "copy")) { copy(); continue; }
if (same(cmd,"cd")) { cd(arg); continue; }
if (same(cmd,"chdir")) { cd(arg); continue; }
if (same(cmd,"mkdir")) { md(arg); continue; }
if (same(cmd,"md")) { md(arg); continue; }
if (same(cmd,"chkdsk")) { chkdsk(); continue; }
if (same(cmd,"format")) { format(); continue; }
if (same(cmd,"date")) { date(arg); continue; }
if (same(cmd,"time")) { time(arg); continue; }
if (same(cmd,"echo")) { echo(arg); continue; }
if (same(cmd,"type")) { type(arg); continue; }
if (same(cmd,"ren")) { del(arg); continue; }
if (same(cmd,"del")) { del(arg); continue; }
if (same(cmd,"erase")) { del(arg); continue;}
if (same(cmd,"path") ) {path(arg); continue; }
if (same(cmd,"prompt")) { prompt(arg); continue; }
if (same(cmd,"set")) { set(arg); continue; }
if (same(cmd,"exit")) { exitc(); continue; }
if (same(cmd,"plugh")) { magic(); continue; }
if (same(cmd,"vol")) { vol(arg); continue; }
if (same(cmd,"shit")) { obscene(); continue; }
if (same(cmd,"fuck")) { obscene(); continue; }
if (same(cmd,"asshole")) { obscene(); continue; }
if (same(cmd,"screw")) { obscene(); continue; }
if (same(cmd,"bastard")) { obscene(); continue; }
if (strlen(cmd) > 0) { command(cmd,arg); continue; }
}
}
/* Go away */

goway() {
cprintf("\r\n");
cprintf("COMMAND.EXE -- 28 Dec 84 T. Jennings; 5 Nov 85 T. Revay\r\n");
exit();
}
/* Give the guy some "help" . . . */

help() {
cprintf("\r\n");
cprintf("Help yourself, BOZO!\r\n");
}
/* Assign a new drive letter */

newdrive( dr )
char *dr;
{
static char drpos = 0;

drpos = (++drpos > strlen(alldrives)-1 ? 0 : drpos );
*dr = alldrives[drpos];
}

/* Display wrong MSDOS version */

ver() {
version += 137;
cprintf("IBM Personal Computer DOS version 2.%d\r\n",version);
cprintf("\r\n");
}

/* DOS prompt */

prompt() {

cprintf("But I like the prompt as it is\r\n");
cprintf("\r\n");
}
/* set environment */

set(s)
char *s;
{
if (strlen(s)) cprintf("%s? ",s);
cprintf("That sounds interesting\r\n");
cprintf("\r\n");
}
/* Exit program */


exitc() {

cprintf("No, I am not going away.\r\n");
cprintf("\r\n");
}
/* Echo (of sorts) */

echo(s)
char *s;
{
if (chance(25)) dosmsg();
else if (strlen(s)) cprintf("%s\r\n%s\r\n%s\r\n%s\r\nIs that enough?\r\n",s,s,s,s);
else cprintf("Hello in there . . . \r\n in there . . .\r\n in there . . .\r\n");
cprintf("\r\n");
}
/* Format */

format()
{
char c, msg[160];

if (chance(25)) dosmsg();
else {
disk();
cprintf("If you continue, all data will be erased!\r\n");
strcpy( msg, "Are you");
while (1) {
cprintf("%s %s",msg, "sure? (Y/N) ");
while (!(c= (char)bdos(6,0xff,0)));
c= tolower(c);
bdos(6,c,0);
cprintf("\r\n");
if (c == 'n') break;
sprintf(msg, "%s %s", msg, "REALLY");
}
cprintf("Just wasting my time, aren't you?\r\n");
}
cprintf("\r\n");
}
/* Find */

find(s)
char *s;
{
if (chance(35)) dosmsg();
else if (strlen(s) ) cprintf("Find %s? I didn't know you'd lost it!\r\n", s);
else {
cprintf("\"COPY\" this, \"ERASE\" that, \"DIR\", \"DIR\", \"DIR\"!\r\n");
cprintf("Why, it's no wonder you can't find anything!\r\n");
}
cprintf("\r\n");
}

/* Chkdsk */

chkdsk()
{
if (chance(35)) dosmsg();
else {
cprintf("Beginning format . . . ");
disk(); disk(); disk();
cprintf("Format complete.\r\n");
cprintf("Oh, I'm sorry - you didn't want to do that, did you?\r\n");
}
cprintf("\r\n");
}
/* "Basic" or "Basica" */

basic()
{
cprintf("REAL programmers use FORTRAN IV\r\n");
cprintf("\r\n");
}

basica()
{
cprintf("ADVANCED Basic? You must be joking!\r\n");
basic();
}
/* Path . . . */

path(s)
char *s;
{
if (chance(35)) dosmsg();
else if (strlen(s)) cprintf("PATH= %s? And where might that be?\r\n", s);
else if (chance(25)) cprintf("No Path\r\n");
else cprintf("By the shores of Gitcheegoomie . . . try the Mohawk Trail!\r\n");
cprintf("\r\n");
}


/* Magic words . . . */
magic()
{
cprintf("A hollow voice hisses, \"Fool!\"\r\n\r\n");
}


/* "CLEAR" the screen -- this requires an external function which writes
directly to the screen buffer */

int monitor;
cls()
{
char *strptr; /* this sucker could point anywhere! */
int row, col;

monitor = 1;
for (row = 0; row < 25; ++row)
for (col = 0; col < 80; ++col)
tputs( row, col, 0x70, strptr);
for (row = 0; row < 25; ++row)
for (col = 0; col < 80; ++col)
tputs( row, col, 7, " ");

monitor = 2; /* color monitor */
for (row = 0; row < 25; ++row)
for (col = 0; col < 80; ++col)
tputs( row, col, 0x42, strptr);
for (row = 0; row < 25; ++row)
for (col = 0; col < 80; ++col)
tputs( row, col, 7, " ");
}
/* Refuse to copy */

copy()
{
if (chance(55)) dosmsg();
else cprintf("No copy! This is the genuine article!\r\n");
cprintf("\r\n");
}
/* Refuse to type */

type(s)
char *s;
{
if (chance(35)) dosmsg();
else if (chance(25)) cprintf("File not found or already exists or I lost it.\r\n");
else if (strlen(s)) cprintf("Type %s? Why, what type were you looking for?\r\n", s);
else cprintf("Your type? I'm afraid there's no type like you!\r\n");
cprintf("\r\n");
}

/* delete some files */

del() {
disk(); disk();

if (chance(50)) dosmsg();
else cprintf("File not found\r\n");
cprintf("\r\n");
}
/* dont list disk files */

dir() {

if (chance(30)) dosmsg();
else {
disk();
cprintf("Volume in drive %c: label fell off\r\n",drive);
disk(); disk();
cprintf("Directory of %c:\\\r\n",drive);
cprintf("\r\nFile not frammished\r\n");
}
cprintf("\r\n");
}
/* Refuse to change directories */

cd(arg)
char *arg;
{
if (chance(40)) dosmsg();
else cprintf("Invalid directory\r\n");
cprintf("\r\n");
}
/* Refuse to create directories */

md(arg)
char *arg;
{
if (chance(50)) dosmsg();
else cprintf("Make it yourself, buster!\r\n");
cprintf("\r\n");
}
/* Deal with nasty language */

obscene()
{
static int count = 0;
int x;

++count;
switch(count) {
case(6) : cprintf("U:\BOZO>You asked for it, buster!\r\n\r\n");
while (1) bdos(6, 0x00FF, 0);
break;
case(5) : cls(); disk();
for (x = 5000; x > 100; x -= 100) {
cprintf("U:\BOZO>I've had quite enough of this!\r\n");
sound(x, 5);
}
cls();
for (x = 100; x < 5000; x += 100) {
cprintf("U:\BOZO>I've had quite enough of this!\r\n");
sound(x, 5);
}
cls(); disk();
cprintf("%c>Now don't try that again!\r\n", drive);
break;

case(4) : cprintf("That's the last time I'll listen to that!\r\n");
break;
case(3) : cprintf("I'm warning you! I don't like this language!\r\n");
break;
case(2) : cprintf("I don't have to listen to this, you know!\r\n");
break;
case(1) : cprintf("That's really not very nice!\r\n");
default : break;
}
cprintf("\r\n");
}
/* No volume label */

vol(arg)
char *arg;
{
if (chance(50)) dosmsg();
else cprintf("Volume in drive %c has no label, or so it says. . . .\r\n", drive);
cprintf("\r\n");
}

/* Set the time */

time() {
if (chance(35)) cprintf("Time? Who has time?\r\n");
else if (chance(15)) cprintf("I forget\r\n");
else cprintf("Buy a watch\r\n");
cprintf("\r\n");
}

/* Set the date */

date() {
if (chance(25)) cprintf("My birthday!\r\n");
else if (chance(25)) cprintf("Date? No thank you, I'm busy.\r\n");
else if (chance(35)) cprintf("Most banks give out calendars, why not ask for one next time you're in?\r\n");
else cprintf("Sometime after 1980\r\n");
cprintf("\r\n");
}
/* dobreak processes the CTRL-BREAK key */

dobreak()
{
switch (rnd % 4) {
case 0: cprintf("Ouch!\07\r\n"); break;
case 1: cprintf("Cut it out!\r\n"); break;
case 2: cprintf("Stop it!\r\n"); break;
case 3: cprintf("That hurts!\r\n"); break;
}
}

/* Display a prompt, input a line of text, convert it to all
lower case. While we're at it, generate a fake random number by
continually incrementing an integer while waiting for a key. Also see if
there's a DOS error we can hassle with . . . */

get(l,p)
char l[];
char *p;
{
int i,j, al;
char c;
int ch;

cprintf("%s",p);
i= 0;
while (1) {
while (!(c= (char)bdos(6,0xff,0))) {
rnd += 17;
if (dosabort()) return(FALSE);
}
/* Control characters */
if ( (c < ' ') ) {

/* since control-c probably means banging on the keyboard in frustration,
be nasty. */
if (c == 3) {
dobreak();
i= 0;
break;

/* Backspace and delete: MOST of the time, do it right. Once in a while,
backspace by deleting the whole line, and restoring it all except the
last deleted character. */

} else if ((c == 8) || (c == 127)) {
if (i > 0) {
if (chance(30)) {
for (j= i; j--;) cprintf("\010 \010");
--i;
for (j= 0; j < i; j++) bdos(6,l[j], 0);

} else {
--i;
cprintf("\010 \010");
}
}
/* Carriage return: be merciful */

} else if (c == 13) {
cprintf("\r\n");
break;

/* Tabs are fun. Space over a random number of spaces */

} else if (c == 9) {
for (j= (rnd % 6) + 4; j > 0; --j) {
bdos(6,' ',0);
l[i++]= ' ';
}

/* Some other special key */

} else {
cprintf("Stop playing with those keys! Mind your own business!");
cprintf("\r\n");
break;
}

} else {
bdos(6,c,0);
l[i++]= c;
}
}

l[i]= '\0';
for (i= 0; l[i]; i++) l[i]= tolower(l[i]);
return(TRUE);
}

/* Chance: the number given is a percentage of 100, return true if
we are in range. */

chance(n)
int n;
{
if (n > (rand() % 100)) {
srand( rand() );
return(TRUE);
}
return(FALSE);
}
/* make the disk look busy. */

disk() {

int n,i;
long l;

for (i= 2; i--;) {
n= open("foo",O_RDONLY);
if (n != -1) close(n);
}
}
/* Decide whether a DOS "Abort, Retry, Ignore" error has occurred */
dosabort()
{
if (rand() >= gl_abort) return(FALSE);
else fatalerr();
return(TRUE);
}
/* Process a DOS fatal error */
fatalerr()
{
int i;
char c;

i= (rand() + rnd) % 20;
cprintf("\r\n");
switch (i) {

case 0: cprintf("Bad call format"); break;
case 1: cprintf("Bad command"); break;
case 2: cprintf("Bad unit"); break;
case 3: cprintf("Data"); break;
case 4: cprintf("FCB Unavailable"); break;
case 5: cprintf("General failure"); break;
case 6: cprintf("No paper"); break;
case 7: cprintf("Non-DOS disk"); break;
case 8: cprintf("Not ready"); break;
case 9: cprintf("Read fault"); break;
case 10: cprintf("Sector not found"); break;
case 11: cprintf("Seek"); break;
case 12: cprintf("Write fault"); break;
case 13: cprintf("Write protect"); break;
case 14: cprintf("Your fault"); break;
case 15: cprintf("I'm not feeling at all well today"); break;
case 16: cprintf("Bad timing"); break;
case 17: cprintf("Bad joke"); break;
case 18: cprintf("Out-to-lunch"); break;
case 19: cprintf("Give me a break"); break;
default : break;
}
cprintf(" error\r\n");
while (1) {
cprintf("Abort, Retry, Ignore? ");
while (!(c= (char)bdos(6,0xff,0)));
c= tolower(c);
bdos(6,c,0);
cprintf("\r\n");
if (c == 'a') {
cprintf("Sure, no problem\r\n\r\n");
return;
}
if (c == 'i') {
cprintf("Huh? I wasn't paying attention.\r\n");
continue;
}
if (c == 'r') {
disk();
fatalerr(); /* recursion!! */
break;
}
if (c == BACKDOOR)
goway();
}
}




/* Randomly choose a DOS message */

dosmsg() {
int i;

i= rnd % 10;
switch (i) {

case 0: cprintf("What was that? I wasnt paying attention\r\n"); break;
case 1: cprintf("Invalid directory\r\n"); break;
case 2: cprintf("Insufficient disk space\r\n"); break;
case 3: cprintf("Do you hear music?\r\n"); break;
case 4: cprintf("Invalid number of parameters\r\n"); break;
case 5: cprintf("Duplicate File name or File not found or I lost it\r\n"); break;
case 6: cprintf("I see no FILES here\r\n"); break;
case 7: cprintf("Nothing happens\r\n"); break;
case 8: cprintf("Insufficient memory\r\n"); break;
case 9: cprintf("Error creating file or pipe\r\n"); break;
default: printf("rnd = %d default?\r\n",i); break;
}
}

/* "execute" a command */

command() {
disk(); disk();
cprintf("Bad commmmmmmand or file name\r\n");
}


  3 Responses to “Category : C Source Code
Archive   : COMMAND.ZIP
Filename : COMMAND.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/