GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
loc_pad.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 
5 #include <grass/gis.h>
6 #include <grass/raster.h>
7 #include <grass/graphics.h>
8 
9 #include "transport.h"
10 #include "pad.h"
11 
12 /* PAD FUNCTIONS
13  The monitor has a very simple database management capabil­
14  ity which supports the windowing. There are scratch pads
15  to be written on. Each scratch pad can contain items, and
16  each item can have a list of values. These are NOT to be
17  used by the programmer. They are used indirectly through
18  the displaylib library calls.
19  */
20 
21 static PAD *curpad; /* current selected pad */
22 
23 int LOC_pad_create(const char *pad)
24 {
25  if (*pad == 0) /* this is scratch pad */
26  return OK;
27  else if (find_pad(pad) != NULL)
28  return DUPLICATE; /* duplicate pad */
29  else if (create_pad(pad))
30  return OK;
31  else
32  return NO_MEMORY;
33 }
34 
36 {
37  if (curpad == NULL) {
38  *name = '\0';
39  return NO_CUR_PAD;
40  }
41  else {
42  strcpy(name, curpad->name);
43  return OK;
44  }
45 }
46 
47 int LOC_pad_delete(void)
48 {
49  if (curpad == NULL)
50  return NO_CUR_PAD;
51  else if (*curpad->name == 0)
52  return ILLEGAL;
53  else {
54  delete_pad(curpad);
55  curpad = NULL;
56  return OK;
57  }
58 }
59 
60 int LOC_pad_invent(char *pad)
61 {
62  invent_pad(pad);
63 
64  return 0;
65 }
66 
67 int LOC_pad_list(char ***list, int *count)
68 {
69  PAD *p;
70  char **l;
71  int n;
72 
73  for (p = pad_list(), n = 0; p; p = p->next)
74  if (*p->name)
75  n++;
76 
77  *count = n;
78  *list = l = G_malloc(n * sizeof(char *));
79 
80  for (p = pad_list(); p; p = p->next)
81  if (*p->name)
82  *l++ = G_store(p->name);
83 
84  return 0;
85 }
86 
87 int LOC_pad_select(const char *pad)
88 {
89  curpad = find_pad(pad);
90 
91  if (curpad == NULL)
92  return NO_PAD;
93 
94  return OK;
95 }
96 
97 int LOC_pad_append_item(const char *item, const char *value, int replace)
98 {
99  if (curpad == NULL)
100  return NO_CUR_PAD;
101 
102  if (append_item(curpad, item, value, replace))
103  return OK;
104 
105  return NO_MEMORY;
106 }
107 
108 int LOC_pad_delete_item(const char *name)
109 {
110  if (curpad == NULL)
111  return NO_CUR_PAD;
112 
113  delete_item(curpad, name);
114  return OK;
115 }
116 
117 int LOC_pad_get_item(const char *name, char ***list, int *count)
118 {
119  ITEM *item;
120  LIST *p;
121  char **l;
122  int n;
123 
124  if (curpad == NULL)
125  return NO_CUR_PAD;
126 
127  item = find_item(curpad, name);
128  if (item == NULL)
129  return NO_ITEM;
130 
131  for (p = item->list, n = 0; p; p = p->next)
132  if (*p->value)
133  n++;
134 
135  *count = n;
136  *list = l = G_malloc(n * sizeof(char *));
137 
138  for (p = item->list, n = 0; p; p = p->next)
139  if (*p->value)
140  *l++ = G_store(p->value);
141 
142  return OK;
143 }
144 
145 int LOC_pad_list_items(char ***list, int *count)
146 {
147  ITEM *p;
148  char **l;
149  int n;
150 
151  if (curpad == NULL)
152  return NO_CUR_PAD;
153 
154  for (p = curpad->items, n = 0; p; p = p->next)
155  if (*p->name)
156  n++;
157  *count = n;
158  *list = l = G_malloc(n * sizeof(char *));
159 
160  for (p = curpad->items, n = 0; p; p = p->next)
161  if (*p->name)
162  *l++ = G_store(p->name);
163 
164  return OK;
165 }
166 
167 int LOC_pad_set_item(const char *name, const char *value)
168 {
169  if (curpad == NULL)
170  return NO_CUR_PAD;
171 
172  delete_item(curpad, name);
173 
174  if (append_item(curpad, name, value, 0))
175  return OK;
176 
177  return NO_MEMORY;
178 }