source: trunk/minix/lib/ack/libm2/Arguments.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.3 KB
Line 
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
12extern char **argv, ***_penviron;
13extern int argc;
14unsigned int _Arguments__Argc;
15
16static char *
17findname(s1, s2)
18register char *s1, *s2;
19{
20
21 while (*s1 == *s2++) s1++;
22 if (*s1 == '\0' && *(s2-1) == '=') return s2;
23 return 0;
24}
25
26static unsigned int
27scopy(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
50unsigned
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
60unsigned
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}
Note: See TracBrowser for help on using the repository browser.