Here it is...
/*
* PSF4CFG.C
*
* Copyright (C) 1995 J.A. Keuter. All Rights Reserved.
*
* CONTAINS: All the code for the Print Screen FormFeeder Version 4.03
* configuration utility
*
* USES: The standard, standard I/O, file control, DOS and string libraries.
*
* IMPLEMENTATION DETAILS:
*
* First the commandline parameters are parsed. If there's an invalid
* parameter found the parsing is stopped and an error banner is printed
* indicating the location of the error.
*
* The parameter '/?' or '/H' (help) fills the banner with available
* parameters and displays it.
*
* The device driver can be opened by its name. If it's installed a
* positive handle is returned, otherwise a negative error code is
* returned. On error a banner is printed.
*
* The device driver reacts to opening by reinstalling itself on INT 05h,
* the Print Screen interrupt, and resetting it's receive buffer.
*
* If the parameter '/NU' (NoUser) was omitted the value of the environment
* variable SGUSER is requested. It's concatenated to the command byte (1h)
* +'User: ' string and written to the device. The command byte was added
* to avoid accidental device access. On error a banner is printed. If the
* parameter '/NU' was found the command byte and an empty string is
* written, effectively wipping the user name.
*
* If the parameter '/LPT?' (set LPT?) was specified the value ?, which
* ranges from 1 to 3, is concatenated to the command byte (2h) and written
* to the device. On error a banner is printed.
*
* If the parameter '/Q' (Quiet) was omitted a banner is printed to tell the
* user that the driver reinstalled itself to INT 05h, to what value the
* user name has been set and to what printer port the Print Screen will
* be send. The last two only if applicable.
*
* MODIFICATIONS
*
* February 5, 1995 4.00 : J.A. Keuter
* Created. Version number sync'ed with device driver.
*
* February 9, 1995 4.01 : J.A. Keuter
* Added /Q switch for quiet operation. Added /NU switch to clear
* username and ignore environment variable SGUSER.
*
* June 6, 1995 4.02 : J.A. Keuter
* Added write() check, error level and banner.
*
* June 20, 1995 4.03 : J.A. Keuter
* Added printer port selection code.
*/
#include
#include
#include
#include
#include
#define BOOL(x) (!(!x))
#define FALSE 0
#define TRUE !(FALSE)
typedef unsigned char BOOL;
char pcBanner[] =
"\n ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸"
"\n ³ Print Screen FormFeeder Configuration ³"
"\n ³ ³"
"\n ³ ³"
"\n ³ ³"
"\n ³ Ver 4.03 (C) 1995 by J.A. Keuter ³"
"\n ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;"
"\n";
int main(int nArgc, char *ppcArgv[])
{
int hDevice;
char *pcUser;
char *pcCommand1 = "\001 ";
char *pcCommand2 = "\002 ";
union REGS CPUregs;
int nArgCount;
int nArgError = 0;
BOOL fQuiet = FALSE;
BOOL fNoUser = FALSE;
BOOL fPortSet = FALSE;
BOOL fHelp = FALSE;
for (nArgCount = 1; (nArgCount < nArgc) && (nArgError == 0); nArgCount++) {
if ((ppcArgv[nArgCount][0] != '/') && (ppcArgv[nArgc][0] != '-')) {
nArgError = nArgCount;
break;
}
if ((toupper(ppcArgv[nArgCount][1]) == 'Q') &&
(ppcArgv[nArgCount][2] == '\0')) {
fQuiet = TRUE;
continue;
}
if ((toupper(ppcArgv[nArgCount][1]) == 'N') &&
(toupper(ppcArgv[nArgCount][2]) == 'U') &&
((ppcArgv[nArgCount][3]) == '\0')) {
fNoUser = TRUE;
continue;
}
if ((toupper(ppcArgv[nArgCount][1]) == 'L') &&
(toupper(ppcArgv[nArgCount][2]) == 'P') &&
(toupper(ppcArgv[nArgCount][3]) == 'T') &&
((ppcArgv[nArgCount][5]) == '\0')) {
if ((ppcArgv[nArgCount][4] > '0') && (ppcArgv[nArgCount][4] < '4')) {
pcCommand2[1] = ppcArgv[nArgCount][4];
fPortSet = TRUE;
continue;
}
}
if (((ppcArgv[nArgCount][1] == '?') ||
(toupper(ppcArgv[nArgCount][1] == 'H'))) &&
(ppcArgv[nArgCount][2] == '\0')) {
fHelp = TRUE;
continue;
}
nArgError = nArgCount;
}
if (nArgError) {
sprintf(&pcBanner[92],
"³ ! Invalid parameter at position %-2.d! ³", nArgCount-1);
pcBanner[135] = '\n';
printf("%s\007", pcBanner);
return 1;
}
if (fHelp) {
sprintf(&pcBanner[92], "³ /NU : Set no user name/clear user name³");
pcBanner[135] = '\n';
sprintf(&pcBanner[137], "³ /LPT? : Set printer port [1-3] ³");
pcBanner[180] = '\n';
sprintf(&pcBanner[182], "³ /Q : No banner ³");
pcBanner[225] = '\n';
printf("%s", pcBanner);
return 0;
}
if ((hDevice = open("PRTSCFF$", O_WRONLY)) > 0) {
strcpy(&pcBanner[92], "³ Device driver reinstalled on PrtSc INT ³");
pcBanner[135] = '\n';
} else {
strcpy(&pcBanner[92], "³ ! Device driver not installed ! ³");
pcBanner[135] = '\n';
printf("%s\007", pcBanner);
return 2;
}
if (!fNoUser) {
if (!(pcUser = getenv("SGUSER"))) {
strcpy(&pcBanner[137], "³ ! No SGUSER environment variable set ! ³");
pcBanner[180] = '\n';
printf("%s\007", pcBanner);
close(hDevice);
return 3;
}
sprintf(&pcCommand1[1], "User: %-20.20s", pcUser);
sprintf(&pcBanner[137], "³ Stored user name: %-20.20s ³", pcUser);
pcBanner[180] = '\n';
}
if (write(hDevice, pcCommand1, strlen(pcCommand1)+1) != strlen(pcCommand1)+1) {
if (fNoUser)
sprintf(&pcBanner[137], "³ ! Error clearing user name ! ³");
else
sprintf(&pcBanner[137], "³ ! Error storing user name ! ³");
pcBanner[180] = '\n';
printf("%s\007", pcBanner);
close(hDevice);
return 4;
}
if (fPortSet) {
if (write(hDevice, pcCommand2, strlen(pcCommand2)+1) != strlen(pcCommand2)+1) {
sprintf(&pcBanner[182], "³ ! Error setting printer port ! ³");
pcBanner[225] = '\n';
printf("%s\007", pcBanner);
close(hDevice);
return 5;
}
sprintf(&pcBanner[182], "³ Print Screen send to printer port LPT ³");
pcBanner[221] = pcCommand2[1];
pcBanner[225] = '\n';
}
if (!fQuiet)
printf("%s", pcBanner);
close(hDevice);
return 0;
}
/* end of file */
Written by my own two hands and an ASCII editor.
Problems? write me
Last updated May 21, 1997
Page best viewed with