2017-07-09 07:24:07 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2018-08-15 16:26:55 +00:00
|
|
|
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2017-07-09 07:24:07 +00:00
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* This file is part of GNU Mes.
|
2017-07-09 07:24:07 +00:00
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
2017-07-09 07:24:07 +00:00
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
2017-07-09 07:24:07 +00:00
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-22 12:24:36 +00:00
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2017-07-09 07:24:07 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-07 22:25:41 +00:00
|
|
|
#include <mes/lib.h>
|
2017-07-09 07:24:07 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-05-18 11:27:42 +00:00
|
|
|
char *env[] = { "foo", "bar", "baz", 0 };
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2019-05-29 14:15:12 +00:00
|
|
|
#if 0 //!SYSTEM_LIBC
|
2018-08-15 16:26:55 +00:00
|
|
|
#define getenv xgetenv
|
|
|
|
|
|
|
|
char *
|
2019-05-18 11:27:42 +00:00
|
|
|
getenv (char const *s)
|
2018-08-15 16:26:55 +00:00
|
|
|
{
|
|
|
|
eputs ("getenv\n");
|
|
|
|
char **p = environ;
|
|
|
|
int length = strlen (s);
|
2019-05-18 11:27:42 +00:00
|
|
|
eputs ("getenv length=");
|
|
|
|
eputs (itoa (length));
|
|
|
|
eputs ("\n");
|
2018-08-15 16:26:55 +00:00
|
|
|
while (*p)
|
|
|
|
{
|
2019-05-18 11:27:42 +00:00
|
|
|
eputs ("*p=");
|
|
|
|
eputs (*p);
|
|
|
|
eputs ("\n");;
|
|
|
|
eputs (" p=");
|
|
|
|
eputs (itoa ((long) p));
|
|
|
|
eputs ("\n");
|
2018-08-15 16:26:55 +00:00
|
|
|
if (!strncmp (s, *p, length) && *(*p + length) == '=')
|
|
|
|
return (*p + length + 1);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-09 07:24:07 +00:00
|
|
|
int
|
|
|
|
test (char **e)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("\n");
|
|
|
|
oputs ("a[i] = i-1\n");
|
2017-07-09 07:24:07 +00:00
|
|
|
int a[3];
|
2019-05-18 11:27:42 +00:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
a[i] = i - 1;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
if (a[i] != i - 1)
|
|
|
|
return 1;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("env [");
|
2019-05-18 11:27:42 +00:00
|
|
|
oputs (itoa ((long) env));
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("]\n");
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("e [");
|
2019-05-18 11:27:42 +00:00
|
|
|
oputs (itoa ((int) e));
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("]\n");
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("env [0] == \"foo\"\n");
|
|
|
|
if (strcmp (env[0], "foo"))
|
|
|
|
return 2;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("env [1] == \"bar\"\n");
|
|
|
|
if (strcmp (env[1], "bar"))
|
|
|
|
return 3;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: **p in *env[]\n");
|
2017-07-09 07:24:07 +00:00
|
|
|
|
|
|
|
char **pp = env;
|
|
|
|
while (*pp)
|
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("pp [");
|
2019-05-18 11:27:42 +00:00
|
|
|
oputs (itoa ((int) pp));
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("]: ");
|
|
|
|
if (*pp)
|
|
|
|
oputs (*pp);
|
|
|
|
oputs ("\n");
|
2017-07-09 07:24:07 +00:00
|
|
|
pp++;
|
|
|
|
i++;
|
|
|
|
}
|
2018-08-15 16:26:55 +00:00
|
|
|
if (i != 3)
|
|
|
|
return i;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
|
|
|
pp = env;
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: *pp++ == \"foo\"\n");
|
|
|
|
if (strcmp (*pp++, "foo"))
|
|
|
|
return 4;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: *pp++ == \"bar\"\n");
|
|
|
|
if (strcmp (*pp++, "bar"))
|
|
|
|
return 5;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
|
|
|
char *buf = "hello";
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: buf[0]\n");
|
|
|
|
if (buf[0] != 'h')
|
|
|
|
return 6;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: buf + 1\n");
|
2019-05-18 11:27:42 +00:00
|
|
|
if (*(buf + 1) != 'e')
|
2018-08-15 16:26:55 +00:00
|
|
|
return 7;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
|
|
|
char **p = &buf;
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: **p\n");
|
|
|
|
if (**p != 'h')
|
|
|
|
return 8;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: *(p + 1)\n");
|
|
|
|
if (*(*p + 1) != 'e')
|
|
|
|
return 9;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: getenv ()\n");
|
|
|
|
if (!getenv ("PATH"))
|
|
|
|
return 10;
|
2018-04-07 07:21:51 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: setenv ()\n");
|
|
|
|
if (setenv ("61-array", "yes", 1))
|
|
|
|
return 11;
|
2018-04-07 07:21:51 +00:00
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
oputs ("t: getenv2 ()\n");
|
|
|
|
if (strcmp (getenv ("61-array"), "yes"))
|
|
|
|
return 12;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return test (env);
|
|
|
|
}
|