PIPS
hyperplane_direction.c
Go to the documentation of this file.
1 /*
2 
3  $Id: hyperplane_direction.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 /* Find out a legal hyperplane direction. In a first phase, trust the user blindly!
28  */
29 
30 #include <stdio.h>
31 #include <strings.h>
32 
33 #include "boolean.h"
34 #include "arithmetique.h"
35 #include "matrice.h"
36 #include "genC.h"
37 #include "misc.h"
38 
39 bool
41 {
42  int i;
43  int n_read;
44  string resp = string_undefined;
45  string cn = string_undefined;
46  bool return_status = false;
47 
48  /* Query the user for h's coordinates */
49  pips_assert("hyperplane_direction", n>=1);
50  debug(8, "interactive_hyperplane_direction", "Reading h\n");
51  resp = user_request("Hyperplane direction vector?\n"
52  "(give all its integer coordinates on one line): ");
53  if (resp[0] == '\0') {
54  user_log("Hyperplane loop transformation has been cancelled.\n");
55  return_status = false;
56  }
57  else {
58  cn = strtok(resp, " \t");
59 
60  return_status = true;
61  for( i = 0; i<n; i++) {
62  if(cn==NULL) {
63  user_log("Not enough coordinates. "
64  "Hyperplane loop transformation has been cancelled.\n");
65  return_status = false;
66  break;
67  }
68  n_read = sscanf(cn," " VALUE_FMT, h+i);
69  if(n_read!=1) {
70  user_log("Not enough coordinates. "
71  "Hyperplane loop transformation has been cancelled.\n");
72  return_status = false;
73  break;
74  }
75  cn = strtok(NULL, " \t");
76  }
77  }
78 
79  if(cn!=NULL) {
80  user_log("Too many coordinates. "
81  "Hyperplane loop transformation has been cancelled.\n");
82  return_status = false;
83  }
84 
85  ifdebug(8) {
86  if(return_status) {
87  pips_debug(8, "Hyperplane direction vector:\n");
88  for( i = 0; i<n; i++) {
89  (void) fprintf(stderr," " VALUE_FMT, *(h+i));
90  }
91  (void) fprintf(stderr,"\n");
92  pips_debug(8, "End\n");
93  }
94  else {
95  pips_debug(8, "Ends with failure\n");
96  }
97  }
98 
99  return return_status;
100 }
void user_log(const char *format,...)
Definition: message.c:234
#define VALUE_FMT
int Value
bool interactive_hyperplane_direction(Value *h, int n)
Find out a legal hyperplane direction.
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
string user_request(const char *,...)
#define string_undefined
Definition: newgen_types.h:40
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define ifdebug(n)
Definition: sg.c:47