MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
env.c
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/utils/env.c,v 1.17 2017/01/12 15:10:27 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #include <unistd.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 
37 extern char **environ;
38 
39 int
40 main(void)
41 {
42  char** s = environ;
43  int c = 0;
44 
45  if (s == NULL || *s == NULL) {
46  printf("environment is empty!\n");
47  return EXIT_SUCCESS;
48  }
49 
50  do {
51  long int i = 0;
52  double d = 0.;
53  char* p = NULL;
54  char* v = NULL;
55  char* n = NULL;
56 
57  if (strncmp(*s, "MBDYN", 5) != 0) {
58  continue;
59  }
60 
61  c++;
62 
63  printf("%s\n", *s);
64 
65  p = strdup(*s);
66  if (p == NULL) {
67  fprintf(stderr, "error 1\n");
68  exit(EXIT_FAILURE);
69  }
70  v = strchr(p, '=');
71  if (v == NULL) {
72  fprintf(stderr, "error 2\n");
73  exit(EXIT_FAILURE);
74  }
75 
76  *v = '\0';
77  v++;
78 
79  if (strncmp(p+5, "_real_", 6) == 0) {
80  n = p+11;
81  d = atof(v);
82  printf("env=%s, var=%s, val=%s(%e, real)\n",
83  *s, n, v, d);
84  } else if (strncmp(p+5, "_integer_", 9) == 0) {
85  n = p+14;
86  i = atoi(v);
87  printf("env=%s, var=%s, val=%s(%ld, integer)\n",
88  *s, n, v, i);
89  } else {
90  fprintf(stderr, "error 3\n");
91  exit(EXIT_FAILURE);
92  }
93  } while (*++s);
94 
95  printf("%d entries\n", c);
96 
97  return EXIT_SUCCESS;
98 }
99 
int main(void)
Definition: env.c:40
char ** environ
static std::stack< cleanup * > c
Definition: cleanup.cc:59