home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
_tr_dosc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-21
|
3KB
|
126 lines
/*********
* _TR_DOSC.C
*
* by Ralph Davis and Tom Rettig
*
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* _tr_doscnf( <search string> )
*
* called by files(), buffers(), country(), and lastdrive()
*
* This function gets COMSPEC from the environment string,
* then loads CONFIG.SYS and looks for the requested parameter
*
* May return either an integer if parameter begins with a
* digit, otherwise returns a char pointer.
*
* modified by Leonard Zerman 02/04/88
* Second fix for last item in config.sys file with no trailing
* blank or CR.
*********/
#include "trlib.h"
_tr_doscnf(srch_strng)
char *srch_strng;
{
char *env = "COMSPEC";
char *p;
char boot_drive[16];
char *filename = "CONFIG.SYS";
char inline[80];
int i, j;
int fd, mode = READONLY;
int filestat;
int retnum;
int srch_len;
int flag;
/* Get COMSPEC */
if ((p = _tr_getenv(env)) == NULLLONG)
return(-1);
/* Extract drive letter and backslash for root directory */
for (i = 0; i < 3; i++)
boot_drive[i] = p[i];
boot_drive[i] = NULLC;
/* Concatenate filename to drive letter and backslash */
_tr_strcat(boot_drive, filename);
/* Open CONFIG.SYS */
if ((fd = _tr_open(boot_drive, mode)) == -1)
return(-1);
/* Read in each line of CONFIG.SYS */
i = 0;
flag= FALSE;
while (!flag)
{
filestat = (_tr_read(fd, &inline[i], 1) > 0);
if ((inline[i] != '\r') && (inline[i] != '\n') && filestat)
{
if (isalpha(inline[i]))
inline[i] &= 0xDF; /* force input to uppercase */
++i;
continue; /* not end of line, get next character */
}
inline[i] = NULLC; /* end of line, terminate with null */
/* Is this the parameter we're looking for? */
srch_len = _tr_strlen(srch_strng);
for (j = 0; j < srch_len; j++)
if (inline[j] != srch_strng[j])
{
i = 0;
break; /* not equal, move on and loop back */
}
if (i > 0) /* yes, this is it */
{
i--; /* back up one from null */
break; /* leave the while loop */
}
if(!filestat)
break;
}
if ( /*filestat*/ i > 0 ) /* we have our parameter line */
{
/* Back up over trailing white space, if any */
while ( inline[i]== ' ' || inline[i]=='\n' ||
inline[i]=='\t' || inline[i]=='\f' || inline[i]=='\r' )
i--;
/* Back up over parameter to space, tab, or equal sign */
while ( inline[i]!=SPACEC && inline[i]!='\t' && inline[i]!='=' )
i--;
/* Position the pointer to the parameter start */
++i;
/* Return parameter */
if ( isdigit(inline[i]) )
retnum = _tr_atoi(&inline[i]); /* return integer */
else
retnum = inline[i]; /* return char pointer */
_tr_close(fd);
return(retnum);
}
else
{ /* did not find the parameter in Config.sys */
_tr_close(fd);
return( ERROR );
}
}