Category : Files from Magazines
Archive   : BYTE0791.ZIP
Filename : SPOOLCTL.C

 
Output of file : SPOOLCTL.C contained in archive : BYTE0791.ZIP

#include
#include
#include
#include
#include
#include
#include
#include
#include

#define TRUE 1
#define FALSE 0

#define BELL 7
#define BS 8
#define LINEFEED 10
#define FORMFEED 12
#define CR 13
#define BACKTAB 15
#define ESC 27

#define HOMEKEY 71
#define ENDKEY 79
#define UPKEY 72
#define DOWNKEY 80
#define PGUPKEY 73
#define PGDNKEY 81
#define LEFTKEY 75
#define INSKEY 82
#define RIGHTKEY 77
#define DELKEY 83
#define CTRLLEFTKEY 115
#define CTRLRIGHTKEY 116
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65

#define F8 66
#define F9 67
#define F10 68

int get_video_mode(void);
void init_prog(void);
void setup_ptrs(void);
void show_info(void);
void draw_box(void);
void show_menu(void);
void get_menu_option(void);
void toggle_print(void);
void cancel_deinstall(void);
void change_priority(void);
void change_formfeeds(void);
void quit_program(void);
void save_cursor(struct csavetype *csave);
void restore_cursor(struct csavetype *csave);
int kbdstring(char buff[], int max_chars);
void getkey(void);

struct csavetype
{
unsigned int curloc;
unsigned int curmode;
};


struct CONTROLBLOCK
{
unsigned int SpoolSizeOfs;
unsigned int PriorityOfs;
unsigned int DoFFOfs;
unsigned int PIDOfs;
unsigned int OutputOfs;
unsigned int OPNameOfs;
unsigned int TimeSliceOfs;
unsigned int TotalCharsOfs;
unsigned int DeInstallOfs;
unsigned int ToggleOfs;
unsigned int ResetSwOfs;
};

struct CONTROLBLOCK far *ctl_blk_ptr;
struct csavetype cursor_data;

unsigned int far *SpoolSizePtr;
unsigned int far *PriorityPtr;
unsigned int far *DoFFPtr;
unsigned int far *PIDPtr;
unsigned int far *OutputPtr;
unsigned char far *OPNamePtr;
unsigned long far *TimeSlicePtr;
unsigned long far *TotalCharsPtr;
unsigned int far *DeInstallPtr;
unsigned int far *TogglePtr;
unsigned int far *ResetSwPtr;

char OutputName[101];

union REGS regs;
unsigned int i, j;
unsigned int spool_seg;
unsigned int spool_ofs;
unsigned long TimeSliceSave;
unsigned int low_inten;
unsigned int high_inten;
unsigned char screen_save[4000];
unsigned int menu_option;
unsigned int print_to_disk;
struct csavetype app_cursor;
unsigned char key_char;
unsigned char extended_char;


char *window_box[14] = {
"ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ[ SPOOL CONTROL ]ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿",
"³ Spool Size: K Priority: FormFeeds: In Queue: ³",
"³ Output File: ³",
"ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ[ MENU ]ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´",
"³ ³",
"³ 1. ³",
"³ 2. Change Priority ³",
"³ 3. Change FormFeeds ³",
"³ 4. ³",
"³ 5. Quit ³",
"³ ³",
"³ Enter Menu Choice (1-5) ÍÍ ³",
"³ ³",
"ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ" };



void main()
{
init_prog();
setup_ptrs();

TimeSliceSave = *TimeSlicePtr;
*TimeSlicePtr = 0xffff0000L;
textattr(low_inten);
gettext(1, 1, 80, 25, screen_save);
save_cursor(&cursor_data);

draw_box();

here_each_time:
show_info();
show_menu();

get_menu_option();
switch (menu_option)
{
case 1: {cancel_deinstall(); break;};
case 2: {change_priority(); break;};
case 3: {change_formfeeds(); break;};
case 4: {toggle_print(); break;};
case 5: {quit_program(); break;};
default: break;
}

goto here_each_time;
}


void init_prog(void)
{
_AX = 'NB';
geninterrupt(0x16);
if (_AX == 'nb')
{
spool_seg = _ES;
spool_ofs = _BX;
goto is_resident;
}

printf("\nThe SPOOLER program is not resident.\n");
printf("You must run SPOOLER before using SPOOLCTL.\n\n");
exit(0);

is_resident:
if (get_video_mode() == 7)
{
low_inten = 0x07;
high_inten = 0x0f;
}
else
{
low_inten = 0x17;
high_inten = 0x1f;
}
}


void setup_ptrs(void)
{
ctl_blk_ptr = MK_FP(spool_seg, spool_ofs);
SpoolSizePtr= MK_FP(spool_seg, ctl_blk_ptr->SpoolSizeOfs);
PriorityPtr = MK_FP(spool_seg, ctl_blk_ptr->PriorityOfs);
DoFFPtr = MK_FP(spool_seg, ctl_blk_ptr->DoFFOfs);
PIDPtr = MK_FP(spool_seg, ctl_blk_ptr->PIDOfs);
OutputPtr = MK_FP(spool_seg, ctl_blk_ptr->OutputOfs);
OPNamePtr = MK_FP(spool_seg, ctl_blk_ptr->OPNameOfs);
TimeSlicePtr= MK_FP(spool_seg, ctl_blk_ptr->TimeSliceOfs);
TotalCharsPtr= MK_FP(spool_seg, ctl_blk_ptr->TotalCharsOfs);
DeInstallPtr= MK_FP(spool_seg, ctl_blk_ptr->DeInstallOfs);
TogglePtr = MK_FP(spool_seg, ctl_blk_ptr->ToggleOfs);
ResetSwPtr = MK_FP(spool_seg, ctl_blk_ptr->ResetSwOfs);

movedata(FP_SEG(OPNamePtr), FP_OFF(OPNamePtr),
_DS, (unsigned) OutputName, 100);

print_to_disk = FALSE;
if (strlen(OutputName) == 0)
strcpy(OutputName, "");
else
{
strupr(OutputName);
print_to_disk = TRUE;
}
}

void show_info(void)
{
gotoxy(19, 7);
cprintf("%3u", (*SpoolSizePtr / 2));
gotoxy(36, 7);
cprintf("%2u", *PriorityPtr);
gotoxy(52, 7);
cprintf("%-3s", (*DoFFPtr) ? "YES" : "NO ");

gotoxy(67, 7);
cprintf(" ");
gotoxy(67, 7);
cprintf("%lu", *TotalCharsPtr);

gotoxy(20, 8);
cprintf("%-50s", OutputName);
}

void draw_box(void)
{
for (i=0; i<14; i++)
{
gotoxy(5, i+6);
cprintf("%s", window_box[i]);
}
}

void show_menu(void)
{
if (*TotalCharsPtr == 0l)
{
gotoxy(28, 11);
cprintf("Remove SPOOLER from memory ");
}
else
{
gotoxy(28, 11);
cprintf("Cancel Print ");
}

if (*TogglePtr == 1)
{
gotoxy(28, 14);
cprintf("Re-Enable SPOOLER ");
}
else
{
gotoxy(28, 14);
cprintf("Disable SPOOLER (go directly to printer) ");
}
}

void get_menu_option(void)
{
char s1[10];

get_response:
menu_option = 0;
gotoxy(42, 17);
cprintf(" ");
gotoxy(42, 17);
strcpy(s1, "");
kbdstring(s1, 4);
if (strlen(s1) == 0)
goto get_response;

menu_option = atoi(s1);
if (menu_option < 1 || menu_option > 5)
goto get_response;
}

int get_video_mode(void)
{
regs.x.ax = 0x0f00;
int86(0x10, ®s, ®s);
regs.h.ah = 0;
return(regs.x.ax);
}

void toggle_print(void)
{
if (*TogglePtr == 1)
*TogglePtr = 0;
else
*TogglePtr = 1;
}

void cancel_deinstall(void)
{
if (*TotalCharsPtr == 0l)
{
*DeInstallPtr = 1;
restore_cursor(&cursor_data);
puttext(1, 1, 80, 25, screen_save);
printf(
"\nSPOOLER will remove itself from memory automatically.\n\n");
exit(0);
}

*TotalCharsPtr = 0l;
*ResetSwPtr = 1;
}

void change_priority(void)
{
char s1[10];
unsigned int newpri;

get_pri_value:
newpri = 0;
gotoxy(13, 17);
cprintf("Enter new value for Priority (1-20)ÍÍ ");
gotoxy(52, 17);
strcpy(s1, "");
kbdstring(s1, 4);
if (strlen(s1) == 0)
goto outa_here;

newpri = atoi(s1);
if (newpri < 1 || newpri > 20)
goto get_pri_value;

*PriorityPtr = newpri;

outa_here:
gotoxy(13, 17);
cprintf("Enter Menu Choice (1-5) ÍÍ ");
}

void change_formfeeds(void)
{
*DoFFPtr = (*DoFFPtr) ? 0 : 1;
}

void quit_program(void)
{
restore_cursor(&cursor_data);
puttext(1, 1, 80, 25, screen_save);
*TimeSlicePtr = TimeSliceSave;
exit(0);
}


void save_cursor(struct csavetype *csave)
{
_AH = 3;
_BH = 0;
geninterrupt(0x10);
csave->curloc = _DX;
csave->curmode = _CX;
}


void restore_cursor(struct csavetype *csave)
{
_DX = csave->curloc;
_AH = 2;
_BH = 0;
geninterrupt(0x10);

_CX = csave->curmode;
_AH = 1;
geninterrupt(0x10);
}



int kbdstring(char buff[], int max_chars)
{
int i, j, insert_mode, ctype, res;
unsigned char row, col, trow, tcol;
unsigned int cblock;

i = j = insert_mode = 0;
if (get_video_mode() == 7)
cblock = 0x000D;
else
cblock = 0x0007;

_AH = 3;
_BH = 0;
geninterrupt(0x10);
ctype = _CX;

col = wherex();
row = wherey();
cprintf("%-*s", max_chars-1, buff);
gotoxy(col, row);

ks1: getkey();
tcol = wherex();
trow = wherey();

if (key_char == ESC)
{
buff[0] = '\0';
res = 0;
goto kbdstring_exit;
}

if (key_char == 0)
{
if (extended_char == INSKEY)
{
if (insert_mode)
{
insert_mode = FALSE;
_CX = ctype;
_AH = 1;
geninterrupt(0x10);
}
else
{
insert_mode = TRUE;
_CX = cblock;
_AH = 1;
geninterrupt(0x10);
}
}
else
if (extended_char == HOMEKEY)
{
i = 0;
gotoxy(col, row);
}
else
if (extended_char == ENDKEY)
{
i = strlen(buff);
gotoxy(col+strlen(buff), row);
}
else
if (extended_char == DELKEY)
{
for (j = i; j < strlen(buff); j++)
buff[j] = buff[j+1];
gotoxy(col, row);
cprintf("%-*s", max_chars-1, buff);
gotoxy(tcol, trow);
}
else
if (extended_char == RIGHTKEY)
{
if (i < strlen(buff))
{
i++;
gotoxy(tcol+1, trow);
}
}
else
if (extended_char == LEFTKEY)
{
if (i > 0)
{
i--;
gotoxy(tcol-1, trow);
}
}
}

if (key_char == 0)
goto ks1;

if (key_char == BS)
{
if (i > 0)
{
i--;
gotoxy(tcol-1, trow);
}
}

if (key_char == CR)
{
res = 0;
goto kbdstring_exit;
}

if (key_char < 32)
goto ks1;
if (i == max_chars-1)
goto ks1;

if (insert_mode)
{
for (j = strlen(buff)-1; j >= i; j--)
if (j < max_chars-2)
buff[j+1] = buff[j];
buff[i++] = key_char;
_CX = ctype;
_AH = 1;
geninterrupt(0x10);
gotoxy(col, row);
cprintf("%-*s", max_chars-1, buff);
gotoxy(++tcol, trow);
_CX = cblock;
_AH = 1;
geninterrupt(0x10);
}
else
{
buff[i++] = key_char;
cprintf("%c", key_char);
}

goto ks1;


kbdstring_exit:
_CX = ctype;
_AH = 1;
geninterrupt(0x10);
return(res);
}


void getkey(void)
{
int k;

k = bioskey(0);
key_char = k & 0x00FF;
extended_char = (k & 0xFF00) >> 8;
}




  3 Responses to “Category : Files from Magazines
Archive   : BYTE0791.ZIP
Filename : SPOOLCTL.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/