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
|
|
|
*/
|
2018-06-25 20:22:37 +00:00
|
|
|
#include "libm2.h"
|
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
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
static char* findname(char* s1, char* s2)
|
1987-05-13 14:36:45 +00:00
|
|
|
{
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
while (*s1 == *s2++)
|
|
|
|
s1++;
|
|
|
|
if (*s1 == '\0' && *(s2 - 1) == '=')
|
|
|
|
return s2;
|
1987-05-13 14:36:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
static unsigned int scopy(char* src, char* dst, unsigned int max)
|
1987-05-13 14:36:45 +00:00
|
|
|
{
|
|
|
|
register unsigned int i = 0;
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
while (*src && i <= max)
|
|
|
|
{
|
1987-05-13 14:36:45 +00:00
|
|
|
i++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
2018-06-25 20:22:37 +00:00
|
|
|
if (i <= max)
|
|
|
|
{
|
1987-05-13 14:36:45 +00:00
|
|
|
*dst = '\0';
|
2018-06-25 20:22:37 +00:00
|
|
|
return i + 1;
|
1987-05-13 14:36:45 +00:00
|
|
|
}
|
2018-06-25 20:22:37 +00:00
|
|
|
while (*src++)
|
|
|
|
i++;
|
1987-05-13 14:36:45 +00:00
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
void _Arguments_(void)
|
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
|
|
|
}
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
unsigned int _Arguments__Argv(int n, char* argument, int l, unsigned int u, int s)
|
1987-05-13 14:36:45 +00:00
|
|
|
{
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
if (n >= argc)
|
|
|
|
return 0;
|
1988-03-23 17:55:57 +00:00
|
|
|
return scopy(argv[n], argument, u);
|
1987-05-13 14:36:45 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
unsigned int _Arguments__GetEnv(
|
|
|
|
char* name, int nn, unsigned int nu, int ns, char* value, int l, unsigned int u, int s)
|
1987-05-13 14:36:45 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
register char** p = environ;
|
|
|
|
register char* v = 0;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
while (*p && !(v = findname(name, *p++)))
|
|
|
|
{
|
1987-05-13 14:36:45 +00:00
|
|
|
/* nothing */
|
|
|
|
}
|
2018-06-25 20:22:37 +00:00
|
|
|
if (!v)
|
|
|
|
return 0;
|
1987-05-13 14:36:45 +00:00
|
|
|
return scopy(v, value, u);
|
|
|
|
}
|