home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GRIPS 2: Government Rast…rocessing Software & Data
/
GRIPS_2.cdr
/
dos
/
ncsa_tel
/
tel_2_2_
/
source
/
pcutil.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-07-15
|
5KB
|
281 lines
/* PCUTIL.C
* Utilities for the network library that are PC specific
****************************************************************************
* *
* part of: *
* TCP/UDP/ICMP/IP Network kernel for NCSA Telnet *
* by Tim Krauskopf *
* *
* National Center for Supercomputing Applications *
* 152 Computing Applications Building *
* 605 E. Springfield Ave. *
* Champaign, IL 61820 *
* *
****************************************************************************
*/
#include "stdio.h"
#include "whatami.h"
unsigned char *malloc();
/**********************************************************************/
/*
* Find directory name -- return a code that indicates whether the
* directory exists or not.
* 0 = dir name ok
* -1 = error
* > 0 = dos error code, no dir by this name
*
* Accept certain unix conventions, like '/' for separator
*
* Also, append a '\' to the name before returning
*
* Note: There must be enough room in the string to append the '\'
*/
struct dosdta {
char junk[21];
char att;
int time,date;
long int size;
char name[13];
};
extern struct dosdta *dtaptr;
direxist(dirname)
char dirname[];
{
int i,ret;
char *p;
if (!strcmp(dirname,".") || !dirname[0]) {
dirname[0] = '\0';
return(0);
}
if (!strcmp(dirname,"\\"))
return(0);
p = dirname;
while (*p) {
switch (*p) {
case '*':
case '?':
return(-1);
case '/':
*p = '\\';
default:
break;
}
p++;
}
/*
* n_findfirst will return normal files AND directories
* must check attribute to see if it is really a directory
*/
ret = n_findfirst(dirname,0x10); /* find name */
if (ret)
return(ret);
if (!(dtaptr->att & 0x10))
return(-2); /* is a normal file */
i = strlen(dirname);
dirname[i] = '\\'; /* extend with '\' */
dirname[++i] = '\0';
return(0);
}
/**********************************************************************/
/* firstname
* find the first name in the given directory which matches the wildcard
* specification
*
* must malloc enough space for the path plus a full filename
*
* expand '*' (unix) to '*.*' (dos)
*/
static char *savepath;
static int rootlen;
char *firstname(path)
char path[];
{
int i,len;
char *p,*q;
if (!*path)
return(NULL);
len = strlen(path);
savepath = malloc(len+16);
i = 0;
rootlen = 0;
q = savepath;
p = path;
while (*q = *p) { /* basic string copy with extras */
if (*p == '\\')
rootlen = i+1; /* rootlen = position of last \ */
p++;
q++;
i++;
}
if (savepath[len-1] == '*' && rootlen == len-1) {
savepath[len++] = '.';
savepath[len++] = '*';
savepath[len++] = '\0';
}
if (n_findfirst(savepath,0))
return(NULL);
/*
* copy file name, translate to lower case
*/
q = &savepath[rootlen];
p = dtaptr->name;
while (*p) {
if (*p >= 'A' && *p <= 'Z')
*q++ = *p++ + 32;
else
*q++ = *p++;
}
*q = '\0';
return(savepath);
}
/**********************************************************************/
/* nextname
* modify the path spec to contain the next file name in the
* sequence as given by DOS
*
* if at the end of the sequence, return NULL
*/
char *nextname()
{
char *p,*q;
if (NULL == savepath)
return(NULL);
if (n_findnext()) {
free(savepath);
savepath = NULL;
return(NULL);
}
/*
* copy file name, translate to lower case
*/
q = &savepath[rootlen];
p = dtaptr->name;
while (*p) {
if (*p >= 'A' && *p <= 'Z')
*q++ = *p++ + 32;
else
*q++ = *p++;
}
*q = '\0';
return(savepath);
}
/**********************************************************************/
/* dopwd
* get the current directory, including disk drive letter
*/
dopwd(p,l)
char *p;
int l;
{
*p++ = 'A'+getdsk(); /* current disk drive */
*p++ = ':';
*p++ = '\\';
getcwd(p,l-2); /* get dir */
}
/**********************************************************************/
/* chgdir
* change directory, including disk drive letter
*/
#include <string.h>
chgdir(d)
char *d;
{
while (*d && *d < 33)
d++;
if (!(*d))
return(-1);
*d = toupper(*d);
if (*(d+1) == ':') {
chgdsk((*d)-'A');
d += 2;
}
if (!(*d))
return(0); /* just changed disk */
return(chdir(d));
}
/**********************************************************************/
/* Scolorset
* setup the color value from the config file string
*/
Scolorset(thecolor,st)
int thecolor[3];
char *st;
{
thecolor[0] = lookcolor(st);
return(1);
}
/**********************************************************************/
/* lookcolor
* search a list for the given color name
*/
static char *colist[] = {
"black",
"blue",
"green",
"cyan",
"red",
"magenta",
"yellow",
"white" };
lookcolor(s)
char *s;
{
int i;
for (i=0; i<7; i++)
if (!ncstrcmp(colist[i],s))
return(i);
return(7);
}
char *colorlook(cl)
int cl;
{
return(colist[cl]);
}