PIPS
help.c
Go to the documentation of this file.
1 /*
2 
3  $Id: help.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 #include <stdio.h>
29 #include <string.h>
30 #include <errno.h>
31 #include <stdlib.h>
32 
33 #include "genC.h"
34 #include "constants.h"
35 #include "misc.h"
36 
37 #include "top-level.h"
38 
39 #define BEGIN_STR "BEGIN"
40 #define END_STR "END"
41 
42 void
44 {
45  int index = 0, begin_length;
46  FILE *fd;
47  char *line;
48 
49 
50  begin_length = strlen(BEGIN_STR);
51 
52  fd = fopen_config(XV_HELP_RC, NULL,NULL);
53 
54  while ((line = safe_readline(fd)) != NULL) {
55  if (strncmp(line, BEGIN_STR, begin_length) == 0)
56  gen_array_dupaddto(array, index++, line+begin_length+1);
57  free(line);
58  }
59 
60  fclose(fd);
61 }
62 
63 void
65 {
66  FILE *fd;
67  int selected = false, index=0;
68  int begin_length, end_length;
69 
70  char *line;
71 
72 
73  begin_length = strlen(BEGIN_STR);
74  end_length = strlen(END_STR);
75 
76  fd = fopen_config(XV_HELP_RC, NULL,NULL);
77  while ((line = safe_readline(fd)) != NULL)
78  {
79  if (strncmp(line, BEGIN_STR, begin_length) == 0 &&
80  strcmp(line + begin_length + 1, topic) == 0) {
81  selected = true;
82  } else if (strncmp(line, END_STR, end_length) == 0) {
83  if (selected) break;
84  }
85  else if (selected)
86  gen_array_dupaddto(array, index++, line);
87  free(line);
88  }
89 
90  if (! selected)
91  gen_array_dupaddto(array, index++, "Sorry: no help on this topic");
92 
93  fclose(fd);
94 }
95 
96 /* add checkings here (FI: why in help.c?)
97  * SG : PIPS_ROOT should not be required :)
98  */
99 void
101 {
102  /*
103  if (!getenv("PIPS_ROOT")) {
104  (void) fprintf(stderr, "PIPS_ROOT environment variable not set. \n"
105  "Set it properly and relaunch.\n");
106  exit(1);
107  }
108  */
109 }
110 
void gen_array_dupaddto(gen_array_t a, size_t i, void *what)
Definition: array.c:111
char * safe_readline(FILE *file)
returns the allocated line read, whatever its length.
Definition: file.c:497
FILE * fopen_config(const char *canonical_name, const char *cproperty, const char *cenv)
Definition: file.c:952
void free(void *)
#define END_STR
Definition: help.c:40
void pips_checks(void)
add checkings here (FI: why in help.c?) SG : PIPS_ROOT should not be required :)
Definition: help.c:100
void get_help_topic(string topic, gen_array_t array)
Definition: help.c:64
void get_help_topics(gen_array_t array)
help.c
Definition: help.c:43
#define BEGIN_STR
Definition: help.c:39
static int line
FLEX_SCANNER.
Definition: scanner.c:852
static entity array