Arguments.c

Go to the documentation of this file.
00001 /*
00002   (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
00003   See the copyright notice in the ACK home directory, in the file "Copyright".
00004 */
00005 
00006 /*
00007   Module:       Access to program arguments and environment
00008   Author:       Ceriel J.H. Jacobs
00009   Version:      $Header: /opt/proj/minix/cvsroot/src/lib/ack/libm2/Arguments.c,v 1.1 2005/10/10 15:27:46 beng Exp $
00010 */
00011 
00012 extern char **argv, ***_penviron;
00013 extern int argc;
00014 unsigned int _Arguments__Argc;
00015 
00016 static char *
00017 findname(s1, s2)
00018 register char *s1, *s2;
00019 {
00020 
00021         while (*s1 == *s2++) s1++;
00022         if (*s1 == '\0' && *(s2-1) == '=') return s2;
00023         return 0;
00024 }
00025 
00026 static unsigned int
00027 scopy(src, dst, max)
00028         register char *src, *dst;
00029         unsigned int max;
00030 {
00031         register unsigned int i = 0;
00032 
00033         while (*src && i <= max) {
00034                 i++;
00035                 *dst++ = *src++;
00036         }
00037         if (i <= max) {
00038                 *dst = '\0';
00039                 return i+1;
00040         }
00041         while (*src++) i++;
00042         return i + 1;
00043 }
00044 
00045 _Arguments_()
00046 {
00047         _Arguments__Argc = argc;
00048 }
00049 
00050 unsigned
00051 _Arguments__Argv(n, argument, l, u, s)
00052         unsigned int u;
00053         char *argument;
00054 {
00055 
00056         if (n >= argc) return 0;
00057         return scopy(argv[n], argument, u);
00058 }
00059 
00060 unsigned
00061 _Arguments__GetEnv(name, nn, nu, ns, value, l, u, s)
00062         char *name, *value;
00063         unsigned int nu, u;
00064 {
00065         register char **p = *_penviron;
00066         register char *v = 0;
00067 
00068         while (*p && !(v = findname(name, *p++))) {
00069                 /* nothing */
00070         }
00071         if (!v) return 0;
00072         return scopy(v, value, u);
00073 }

Generated on Fri Apr 14 22:57:25 2006 for minix by  doxygen 1.4.6