GRASS GIS 7 Programmer's Manual  7.0.5(2016)-r00000
option.c
Go to the documentation of this file.
1 
14 #include <string.h>
15 #include <grass/gis.h>
16 #include <grass/glocale.h>
17 
18 #include "manage_local_proto.h"
19 
28 struct Option* M_define_option(int n, const char *desc, int multiple)
29 {
30  char *str;
31  struct Option *p;
32 
33  if (n >= nlist)
34  return NULL;
35 
36  p = G_define_option();
37  p->key = list[n].alias;
38  p->type = TYPE_STRING;
39  if (multiple)
40  p->key_desc = "name";
41  else
42  p->key_desc = "from,to";
43  p->required = NO;
44  p->multiple = multiple;
45  G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
46  p->gisprompt = str;
47  G_asprintf(&str, _("%s to be %s"),
48  list[n].text, desc);
49  p->description = str;
50  if (strcmp(p->key, "raster") == 0 || strcmp(p->key, "raster_3d") == 0)
51  p->guisection = _("Raster");
52  else if (strcmp(p->key, "vector") == 0)
53  p->guisection = _("Vector");
54  else if (strcmp(p->key, "region") == 0)
55  p->guisection = _("Region");
56  else if (strcmp(p->key, "group") == 0)
57  p->guisection = _("Group");
58 
59  return p;
60 }
61 
71 const char *M_get_options(int do_all)
72 {
73  int len, n;
74  char *str;
75 
76  for (len = 0, n = 0; n < nlist; n++)
77  len += strlen(list[n].alias) + 1;
78  if (do_all)
79  len += 4;
80  str = G_malloc(len);
81 
82  for (n = 0; n < nlist; n++) {
83  if (n) {
84  strcat(str, ",");
85  strcat(str, list[n].alias);
86  }
87  else
88  strcpy(str, list[n].alias);
89  }
90 
91  if (do_all)
92  strcat(str, ",all");
93 
94  return str;
95 }
96 
106 const char *M_get_option_desc(int do_all)
107 {
108  int len, n;
109  char *str;
110  const char *str_all = "all;all types";
111 
112  for (len = 0, n = 0; n < nlist; n++) {
113  len += strlen(list[n].alias) + 1;
114  len += strlen(list[n].text) + 1;
115  }
116  if (do_all)
117  len += strlen(str_all) + 1;
118  str = G_malloc(len);
119 
120  for (n = 0; n < nlist; n++) {
121  if (n) {
122  strcat(str, ";");
123  strcat(str, list[n].alias);
124  strcat(str, ";");
125  strcat(str, list[n].text);
126  }
127  else {
128  strcpy(str, list[n].alias);
129  strcat(str, ";");
130  strcat(str, list[n].text);
131  }
132  }
133 
134  if (do_all) {
135  strcat(str, ";");
136  strcat(str, str_all);
137  }
138 
139  return str;
140 }
const char * M_get_options(int do_all)
Get list of element types separated by comma.
Definition: option.c:71
int nlist
Definition: read_list.c:23
int G_asprintf(char **out, const char *fmt,...)
Definition: asprintf.c:70
#define NULL
Definition: ccmath.h:32
const char * M_get_option_desc(int do_all)
Get list of element desc separated by comma.
Definition: option.c:106
struct Option * G_define_option(void)
Initializes an Option struct.
Definition: parser.c:208
struct list * list
Definition: read_list.c:24
struct Option * M_define_option(int n, const char *desc, int multiple)
Define option for parser.
Definition: option.c:28