home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
disks
/
disk466.lzh
/
Dice
/
dice206b.lzh
/
netdcc
/
cc
/
subs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-12
|
1KB
|
88 lines
/*
* SUBS.C
*
* (c)Copyright 1990, All Rights Reserved
*/
#include "defs.h"
Prototype int ExtArgsEnv(short, char ***, char *);
Prototype char *skipspace(char *);
Prototype char *skipnspace(char *);
/*
* ExtArgsEnv() DCCOPTS
*/
int
ExtArgsEnv(ac, pav, envname)
short ac;
char ***pav;
char *envname;
{
int fd = open(envname, O_RDONLY);
long len;
if (fd < 0)
return(ac);
if ((len = lseek(fd, 0L, 2)) > 0) {
char *str = malloc(len + 1);
char *ptr;
int nac = 0;
char **nav;
lseek(fd, 0L, 0);
read(fd, str, len);
str[len] = 0;
/*
* parse
*/
ptr = skipspace(str);
while (*ptr) {
++nac;
ptr = skipnspace(ptr);
ptr = skipspace(ptr);
}
nav = malloc((ac + nac + 1) * sizeof(char *));
movmem(*pav, nav, ac * sizeof(char *));
nac = ac;
ptr = skipspace(str);
while (*ptr) {
nav[nac] = ptr;
ptr = skipnspace(ptr);
if (*ptr)
*ptr++ = 0;
ptr = skipspace(ptr);
++nac;
}
nav[nac] = NULL;
ac = nac;
*pav = nav;
}
close(fd);
return(ac);
}
char *
skipspace(ptr)
char *ptr;
{
while (*ptr == ' ' || *ptr == 9)
++ptr;
return(ptr);
}
char *
skipnspace(ptr)
char *ptr;
{
while (*ptr != ' ' && *ptr != 9 && *ptr)
++ptr;
return(ptr);
}