GRASS Programmer's Manual  6.4.2(2012)
loc_pad.c
Go to the documentation of this file.
00001 #include <string.h>
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 
00005 #include <grass/gis.h>
00006 #include <grass/raster.h>
00007 #include <grass/graphics.h>
00008 
00009 #include "transport.h"
00010 #include "pad.h"
00011 
00012 /* PAD FUNCTIONS
00013    The monitor has a very simple database management capabil­
00014    ity  which supports the windowing.  There are scratch pads
00015    to be written on. Each scratch pad can contain items,  and
00016    each  item can have a list of values.  These are NOT to be
00017    used by the programmer.  They are used indirectly  through
00018    the displaylib library calls.
00019  */
00020 
00021 static PAD *curpad;             /* current selected pad */
00022 
00023 int LOC_pad_create(const char *pad)
00024 {
00025     if (*pad == 0)              /* this is scratch pad */
00026         return OK;
00027     else if (find_pad(pad) != NULL)
00028         return DUPLICATE;       /* duplicate pad */
00029     else if (create_pad(pad))
00030         return OK;
00031     else
00032         return NO_MEMORY;
00033 }
00034 
00035 int LOC_pad_current(char *name)
00036 {
00037     if (curpad == NULL) {
00038         *name = '\0';
00039         return NO_CUR_PAD;
00040     }
00041     else {
00042         strcpy(name, curpad->name);
00043         return OK;
00044     }
00045 }
00046 
00047 int LOC_pad_delete(void)
00048 {
00049     if (curpad == NULL)
00050         return NO_CUR_PAD;
00051     else if (*curpad->name == 0)
00052         return ILLEGAL;
00053     else {
00054         delete_pad(curpad);
00055         curpad = NULL;
00056         return OK;
00057     }
00058 }
00059 
00060 int LOC_pad_invent(char *pad)
00061 {
00062     invent_pad(pad);
00063 
00064     return 0;
00065 }
00066 
00067 int LOC_pad_list(char ***list, int *count)
00068 {
00069     PAD *p;
00070     char **l;
00071     int n;
00072 
00073     for (p = pad_list(), n = 0; p; p = p->next)
00074         if (*p->name)
00075             n++;
00076 
00077     *count = n;
00078     *list = l = G_malloc(n * sizeof(char *));
00079 
00080     for (p = pad_list(); p; p = p->next)
00081         if (*p->name)
00082             *l++ = G_store(p->name);
00083 
00084     return 0;
00085 }
00086 
00087 int LOC_pad_select(const char *pad)
00088 {
00089     curpad = find_pad(pad);
00090 
00091     if (curpad == NULL)
00092         return NO_PAD;
00093 
00094     return OK;
00095 }
00096 
00097 int LOC_pad_append_item(const char *item, const char *value, int replace)
00098 {
00099     if (curpad == NULL)
00100         return NO_CUR_PAD;
00101 
00102     if (append_item(curpad, item, value, replace))
00103         return OK;
00104 
00105     return NO_MEMORY;
00106 }
00107 
00108 int LOC_pad_delete_item(const char *name)
00109 {
00110     if (curpad == NULL)
00111         return NO_CUR_PAD;
00112 
00113     delete_item(curpad, name);
00114     return OK;
00115 }
00116 
00117 int LOC_pad_get_item(const char *name, char ***list, int *count)
00118 {
00119     ITEM *item;
00120     LIST *p;
00121     char **l;
00122     int n;
00123 
00124     if (curpad == NULL)
00125         return NO_CUR_PAD;
00126 
00127     item = find_item(curpad, name);
00128     if (item == NULL)
00129         return NO_ITEM;
00130 
00131     for (p = item->list, n = 0; p; p = p->next)
00132         if (*p->value)
00133             n++;
00134 
00135     *count = n;
00136     *list = l = G_malloc(n * sizeof(char *));
00137 
00138     for (p = item->list, n = 0; p; p = p->next)
00139         if (*p->value)
00140             *l++ = G_store(p->value);
00141 
00142     return OK;
00143 }
00144 
00145 int LOC_pad_list_items(char ***list, int *count)
00146 {
00147     ITEM *p;
00148     char **l;
00149     int n;
00150 
00151     if (curpad == NULL)
00152         return NO_CUR_PAD;
00153 
00154     for (p = curpad->items, n = 0; p; p = p->next)
00155         if (*p->name)
00156             n++;
00157     *count = n;
00158     *list = l = G_malloc(n * sizeof(char *));
00159 
00160     for (p = curpad->items, n = 0; p; p = p->next)
00161         if (*p->name)
00162             *l++ = G_store(p->name);
00163 
00164     return OK;
00165 }
00166 
00167 int LOC_pad_set_item(const char *name, const char *value)
00168 {
00169     if (curpad == NULL)
00170         return NO_CUR_PAD;
00171 
00172     delete_item(curpad, name);
00173 
00174     if (append_item(curpad, name, value, 0))
00175         return OK;
00176 
00177     return NO_MEMORY;
00178 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines