PIPS
fpips.c
Go to the documentation of this file.
1 /*
2 
3  $Id: fpips.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  * FPIPS stands for Full PIPS, or Fabien PIPS;-)
29  *
30  * it provides a single executable for {,t,w}pips, enabling faster
31  * link when developing and testing. Also a single executable can
32  * be exported, reducing the size of binary distributions.
33  * The execution depends on the name of the executable, or the first option.
34  *
35  * C macros of interest: FPIPS_WITHOUT_{,G,T,W}PIPS to disable some versions.
36  *
37  * FC, Mon Aug 18 09:09:32 GMT 1997
38  */
39 
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <unistd.h>
43 #include <string.h>
44 
45 #include "genC.h"
46 #include "misc.h"
47 
48 /******************************************************************** MACROS */
49 
50 #if defined(FPIPS_WITHOUT_PIPS)
51 #define PIPS(c, v) fpips_error("pips", c, v)
52 #else
53 extern int pips_main(int, char**);
54 #define PIPS(c, v) pips_main(c, v)
55 #endif
56 
57 #if defined(FPIPS_WITHOUT_TPIPS)
58 #define TPIPS(c, v) fpips_error("tpips", c, v)
59 #else
60 extern int tpips_main(int, char**);
61 #define TPIPS(c, v) tpips_main(c, v)
62 #endif
63 
64 #if defined(FPIPS_WITHOUT_WPIPS)
65 #define WPIPS(c, v) fpips_error("wpips", c, v)
66 #else
67 extern int wpips_main(int, char**);
68 #define WPIPS(c, v) wpips_main(c, v)
69 #endif
70 
71 #if defined(FPIPS_WITHOUT_GPIPS)
72 #define GPIPS(c, v) fpips_error("gpips", c, v)
73 #else
74 extern int gpips_main(int, char**);
75 #define GPIPS(c, v) gpips_main(c, v)
76 #endif
77 
78 #define USAGE \
79  "Usage: fpips [-hvGPTW] (other options and arguments...)\n" \
80  "\t-h: this help...\n" \
81  "\t-v: version\n" \
82  "\t-G: gpips\n" \
83  "\t-P: pips\n" \
84  "\t-T: tpips\n" \
85  "\t-W: wpips\n" \
86  "\tdefault: run as tpips\n\n"
87 
88 /******************************************************************** UTILS */
89 
90 /* print out usage informations.
91  */
92 static int fpips_usage(int ret)
93 {
94  fprintf(stderr, USAGE);
95  return ret;
96 }
97 
98 /* print out fpips version.
99  */
100 static int fpips_version(int ret)
101 {
102  fprintf(stderr, "[fpips] (ARCH=" STRINGIFY(SOFT_ARCH) ", DATE=" STRINGIFY(UTC_DATE) ")\n\n");
103  return ret;
104 }
105 
106 /* non static to avoid a gcc warning if not called.
107  */
108 int fpips_error(char * what,
109  int __attribute__ ((unused)) argc,
110  char __attribute__ ((unused)) ** argv)
111 {
112  fprintf(stderr, "[fpips] sorry, %s not available (" STRINGIFY(SOFT_ARCH) ")\n", what);
113  return fpips_usage(1);
114 }
115 
116 /* returns whether name ends with ref
117  */
118 static int name_end_p(char * name, char * ref)
119 {
120  int nlen = strlen(name), rlen = strlen(ref);
121  if (nlen<rlen) return false;
122  while (rlen>0)
123  if (ref[--rlen]!=name[--nlen])
124  return false;
125  return true;
126 }
127 
128 /********************************************************************* MAIN */
129 
130 int fpips_main(int argc, char ** argv)
131 {
132  int opt;
133 
134  debug_on("FPIPS_DEBUG_LEVEL");
135  pips_debug(1, "considering %s for execution\n", argv[0]);
136  debug_off();
137 
138  if (argc<1) return TPIPS(argc, argv); /* should not happen */
139 
140  /* According to the shell or the debugger, the path may be
141  complete or not... RK. */
142  if (name_end_p(argv[0], "gpips"))
143  return GPIPS(argc, argv);
144  if (name_end_p(argv[0], "tpips"))
145  return TPIPS(argc, argv);
146  if (name_end_p(argv[0], "wpips"))
147  return WPIPS(argc, argv);
148  if (name_end_p(argv[0], "/pips") || same_string_p(argv[0], "pips"))
149  return PIPS(argc, argv);
150 
151  /* parsing of options may be continuate by called version.
152  */
153  while ((opt = getopt(argc, argv, "hvGPTW"))!=-1)
154  {
155  switch (opt)
156  {
157  case 'h': fpips_usage(0); break;
158  case 'v': fpips_version(0); break;
159  case 'G': return GPIPS(argc, argv);
160  case 'P': return PIPS(argc, argv);
161  case 'T': return TPIPS(argc, argv);
162  case 'W': return WPIPS(argc, argv);
163  default: return fpips_version(1);
164  }
165  }
166 
167  /* else try tpips...
168  */
169  fprintf(stderr, "[fpips] default: running as tpips\n\n");
170  return TPIPS(argc, argv);
171 }
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
#define ret(why, what)
true if not a remapping for old.
Definition: dynamic.c:986
int gpips_main(int, char **)
static int fpips_version(int ret)
print out fpips version.
Definition: fpips.c:100
int pips_main(int, char **)
Definition: pips.c:160
#define PIPS(c, v)
Definition: fpips.c:54
static int name_end_p(char *name, char *ref)
returns whether name ends with ref
Definition: fpips.c:118
int wpips_main(int, char **)
static int fpips_usage(int ret)
print out usage informations.
Definition: fpips.c:92
int fpips_error(char *what, int __attribute__((unused)) argc, char __attribute__((unused)) **argv)
non static to avoid a gcc warning if not called.
Definition: fpips.c:108
#define USAGE
Definition: fpips.c:78
int tpips_main(int, char **)
#define TPIPS(c, v)
Definition: fpips.c:61
#define GPIPS(c, v)
Definition: fpips.c:75
int fpips_main(int argc, char **argv)
Definition: fpips.c:130
#define WPIPS(c, v)
Definition: fpips.c:68
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define STRINGIFY(symbol)
If not using this 2-stage macro evaluation, the generated string is not the value of the macro but th...
Definition: misc-local.h:50
#define debug_off()
Definition: misc-local.h:160
#define same_string_p(s1, s2)
#define UTC_DATE
Definition: pips_version.h:5
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...