[9] | 1 | /*
|
---|
| 2 | (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
---|
| 3 | See the copyright notice in the ACK home directory, in the file "Copyright".
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | Module: Access to program arguments and environment
|
---|
| 8 | Author: Ceriel J.H. Jacobs
|
---|
| 9 | Version: $Header: /cvsup/minix/src/lib/ack/libm2/Arguments.c,v 1.1 2005/10/10 15:27:46 beng Exp $
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | extern char **argv, ***_penviron;
|
---|
| 13 | extern int argc;
|
---|
| 14 | unsigned int _Arguments__Argc;
|
---|
| 15 |
|
---|
| 16 | static char *
|
---|
| 17 | findname(s1, s2)
|
---|
| 18 | register char *s1, *s2;
|
---|
| 19 | {
|
---|
| 20 |
|
---|
| 21 | while (*s1 == *s2++) s1++;
|
---|
| 22 | if (*s1 == '\0' && *(s2-1) == '=') return s2;
|
---|
| 23 | return 0;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | static unsigned int
|
---|
| 27 | scopy(src, dst, max)
|
---|
| 28 | register char *src, *dst;
|
---|
| 29 | unsigned int max;
|
---|
| 30 | {
|
---|
| 31 | register unsigned int i = 0;
|
---|
| 32 |
|
---|
| 33 | while (*src && i <= max) {
|
---|
| 34 | i++;
|
---|
| 35 | *dst++ = *src++;
|
---|
| 36 | }
|
---|
| 37 | if (i <= max) {
|
---|
| 38 | *dst = '\0';
|
---|
| 39 | return i+1;
|
---|
| 40 | }
|
---|
| 41 | while (*src++) i++;
|
---|
| 42 | return i + 1;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | _Arguments_()
|
---|
| 46 | {
|
---|
| 47 | _Arguments__Argc = argc;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | unsigned
|
---|
| 51 | _Arguments__Argv(n, argument, l, u, s)
|
---|
| 52 | unsigned int u;
|
---|
| 53 | char *argument;
|
---|
| 54 | {
|
---|
| 55 |
|
---|
| 56 | if (n >= argc) return 0;
|
---|
| 57 | return scopy(argv[n], argument, u);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | unsigned
|
---|
| 61 | _Arguments__GetEnv(name, nn, nu, ns, value, l, u, s)
|
---|
| 62 | char *name, *value;
|
---|
| 63 | unsigned int nu, u;
|
---|
| 64 | {
|
---|
| 65 | register char **p = *_penviron;
|
---|
| 66 | register char *v = 0;
|
---|
| 67 |
|
---|
| 68 | while (*p && !(v = findname(name, *p++))) {
|
---|
| 69 | /* nothing */
|
---|
| 70 | }
|
---|
| 71 | if (!v) return 0;
|
---|
| 72 | return scopy(v, value, u);
|
---|
| 73 | }
|
---|