ack/lang/m2/libm2/Arguments.c

74 lines
1.2 KiB
C
Raw Normal View History

1988-02-19 15:54:01 +00:00
/*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/*
Module: Access to program arguments and environment
Author: Ceriel J.H. Jacobs
1994-06-24 14:02:31 +00:00
Version: $Id$
1988-02-19 15:54:01 +00:00
*/
1988-03-23 17:55:57 +00:00
extern char **argv, **environ;
extern int argc;
unsigned int _Arguments__Argc;
1987-05-13 14:36:45 +00:00
static char *
findname(s1, s2)
register char *s1, *s2;
{
while (*s1 == *s2++) s1++;
if (*s1 == '\0' && *(s2-1) == '=') return s2;
return 0;
}
static unsigned int
scopy(src, dst, max)
register char *src, *dst;
unsigned int max;
{
register unsigned int i = 0;
1988-09-06 15:34:47 +00:00
while (*src && i <= max) {
1987-05-13 14:36:45 +00:00
i++;
*dst++ = *src++;
}
if (i <= max) {
*dst = '\0';
return i+1;
}
while (*src++) i++;
return i + 1;
}
1988-03-23 17:55:57 +00:00
_Arguments_()
1987-05-13 14:36:45 +00:00
{
1988-03-23 17:55:57 +00:00
_Arguments__Argc = argc;
1987-05-13 14:36:45 +00:00
}
unsigned
1988-03-23 17:55:57 +00:00
_Arguments__Argv(n, argument, l, u, s)
1987-05-13 14:36:45 +00:00
unsigned int u;
char *argument;
{
1988-03-23 17:55:57 +00:00
if (n >= argc) return 0;
return scopy(argv[n], argument, u);
1987-05-13 14:36:45 +00:00
}
unsigned
1988-03-23 17:55:57 +00:00
_Arguments__GetEnv(name, nn, nu, ns, value, l, u, s)
1987-05-13 14:36:45 +00:00
char *name, *value;
unsigned int nu, u;
{
1988-03-23 17:55:57 +00:00
register char **p = environ;
1987-05-13 14:36:45 +00:00
register char *v = 0;
while (*p && !(v = findname(name, *p++))) {
/* nothing */
}
if (!v) return 0;
return scopy(v, value, u);
}