GRASS Programmer's Manual  6.5.svn(2014)-r66266
 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­ ity which supports the windowing. There are scratch pads to be written on. Each scratch pad can contain items, and each item can have a list of values. These are NOT to be used by the programmer. They are used indirectly through the displaylib library calls. */ static PAD *curpad; /* current selected pad */ int LOC_pad_create(const char *pad) { if (*pad == 0) /* this is scratch pad */ return OK; else if (find_pad(pad) != NULL) return DUPLICATE; /* duplicate pad */ else if (create_pad(pad)) return OK; else return NO_MEMORY; } int LOC_pad_current(char *name) { if (curpad == NULL) { *name = '\0'; return NO_CUR_PAD; } else { strcpy(name, curpad->name); return OK; } } int LOC_pad_delete(void) { if (curpad == NULL) return NO_CUR_PAD; else if (*curpad->name == 0) return ILLEGAL; else { delete_pad(curpad); curpad = NULL; return OK; } } int LOC_pad_invent(char *pad) { invent_pad(pad); return 0; } int LOC_pad_list(char ***list, int *count) { PAD *p; char **l; int n; for (p = pad_list(), n = 0; p; p = p->next) if (*p->name) n++; *count = n; *list = l = G_malloc(n * sizeof(char *)); for (p = pad_list(); p; p = p->next) if (*p->name) *l++ = G_store(p->name); return 0; } int LOC_pad_select(const char *pad) { curpad = find_pad(pad); if (curpad == NULL) return NO_PAD; return OK; } int LOC_pad_append_item(const char *item, const char *value, int replace) { if (curpad == NULL) return NO_CUR_PAD; if (append_item(curpad, item, value, replace)) return OK; return NO_MEMORY; } int LOC_pad_delete_item(const char *name) { if (curpad == NULL) return NO_CUR_PAD; delete_item(curpad, name); return OK; } int LOC_pad_get_item(const char *name, char ***list, int *count) { ITEM *item; LIST *p; char **l; int n; if (curpad == NULL) return NO_CUR_PAD; item = find_item(curpad, name); if (item == NULL) return NO_ITEM; for (p = item->list, n = 0; p; p = p->next) if (*p->value) n++; *count = n; *list = l = G_malloc(n * sizeof(char *)); for (p = item->list, n = 0; p; p = p->next) if (*p->value) *l++ = G_store(p->value); return OK; } int LOC_pad_list_items(char ***list, int *count) { ITEM *p; char **l; int n; if (curpad == NULL) return NO_CUR_PAD; for (p = curpad->items, n = 0; p; p = p->next) if (*p->name) n++; *count = n; *list = l = G_malloc(n * sizeof(char *)); for (p = curpad->items, n = 0; p; p = p->next) if (*p->name) *l++ = G_store(p->name); return OK; } int LOC_pad_set_item(const char *name, const char *value) { if (curpad == NULL) return NO_CUR_PAD; delete_item(curpad, name); if (append_item(curpad, name, value, 0)) return OK; return NO_MEMORY; }
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 }
int l
Definition: dataquad.c:292
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
int LOC_pad_current(char *name)
Definition: loc_pad.c:35
string name
Definition: render.py:1314
Definition: pad.h:5
int LOC_pad_delete(void)
Definition: loc_pad.c:47
int count
struct _pad_ * next
Definition: pad.h:22
ITEM * items
Definition: pad.h:21
int LOC_pad_delete_item(const char *name)
Definition: loc_pad.c:108
char * value
Definition: pad.h:7
LIST * list
Definition: pad.h:14
#define NO_MEMORY
Definition: plot.c:386
struct _list * next
Definition: pad.h:8
int invent_pad(char *name)
Definition: pad.c:217
ITEM * find_item(PAD *pad, const char *name)
Definition: pad.c:135
int LOC_pad_set_item(const char *name, const char *value)
Definition: loc_pad.c:167
#define OK
Definition: plot.c:384
char * name
Definition: pad.h:20
Definition: pad.h:11
Definition: pad.h:18
char * value
Definition: env.c:30
int LOC_pad_select(const char *pad)
Definition: loc_pad.c:87
int LOC_pad_list_items(char ***list, int *count)
Definition: loc_pad.c:145
int LOC_pad_get_item(const char *name, char ***list, int *count)
Definition: loc_pad.c:117
int LOC_pad_list(char ***list, int *count)
Definition: loc_pad.c:67
int LOC_pad_append_item(const char *item, const char *value, int replace)
Definition: loc_pad.c:97
PAD * find_pad(const char *name)
Definition: pad.c:207
return NULL
Definition: dbfopen.c:1394
PAD * pad_list(void)
Definition: pad.c:146
int LOC_pad_invent(char *pad)
Definition: loc_pad.c:60
struct _item_ * next
Definition: pad.h:15
int delete_item(PAD *pad, const char *name)
Definition: pad.c:113
char * name
Definition: pad.h:13
int LOC_pad_create(const char *pad)
Definition: loc_pad.c:23
int delete_pad(PAD *pad)
Definition: pad.c:188
int create_pad(const char *name)
Definition: pad.c:167
int n
Definition: dataquad.c:291
int append_item(PAD *pad, const char *name, const char *value, int replace)
Definition: pad.c:70