8 #include <grass/glocale.h>
9 #include <grass/raster.h>
10 #include <grass/monitors.h>
12 static FILE *monitors =
NULL;
13 static struct MON_CAP cap;
15 static char *substr(
char *,
char *);
16 static int read_line(FILE *,
char *,
int);
29 if (!(field == MON_NEXT || field == MON_NAME ||
30 field == MON_PATH || field == MON_LINK || field == MON_CLOSE))
32 if (monitors ==
NULL) {
33 sprintf(file,
"%s/etc/monitorcap", gisbase);
34 if ((monitors = fopen(file,
"r")) ==
NULL)
38 if (field == MON_CLOSE) {
45 if (read_line(monitors, line,
sizeof line)) {
46 if (field == MON_NEXT)
49 if (read_line(monitors, line,
sizeof line) || rewound)
53 cap.path = cap.comment = cap.link = cap.tty = cap.where =
NULL;
54 if ((cap.name = G_malloc(strlen(line) + 1)) ==
NULL)
56 strcpy(cap.name, line);
57 if ((p = substr(
":", cap.name)) !=
NULL) {
60 if ((p = substr(
":", p)) !=
NULL) {
63 if ((p = substr(
":", p)) !=
NULL) {
66 if ((p = substr(
":", p)) !=
NULL) {
69 if ((p = substr(
":", p)) !=
NULL) {
72 if ((p = substr(
"\n", p)) !=
NULL)
79 if (cap.path ==
NULL || cap.link ==
NULL || cap.where ==
NULL ||
80 cap.tty ==
NULL || cap.comment ==
NULL)
83 sprintf(line,
"%s/%s", gisbase, cap.path);
86 if (field == MON_NEXT ||
87 (field == MON_NAME && !strcmp(key, cap.name))
88 || (field == MON_PATH && !strcmp(key, cap.path))
89 || (field == MON_LINK && !strcmp(key, cap.link)))
99 static int read_line(FILE *
file,
103 int length, full_line, eof, done;
107 for (length = full_line = eof = 0; !full_line && !eof;) {
109 eof = (fgets(line + length, size - length - 1, file) ==
NULL);
112 if (*(line + length) !=
'#')
115 length = strlen(line) - 1;
116 if (*(line + length) ==
'\n') {
117 if (*(line + length - 1) ==
'\\')
124 fprintf(stderr,
"error: input line too long\n");
127 for (done = 0; !done;) {
128 if ((c = getc(file)) != EOF) {
129 if (c ==
'\n' && last_c !=
'\\')
146 static char *substr(
char *
string,
char *buffer)
151 start = i = found = 0;
152 while ((c = *(buffer + start + i)) !=
'\0' && !found) {
153 if (c == *(
string + i)) {
154 if (*(
string + ++i) ==
'\0')
163 return (buffer + start);
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
char * G_store(const char *s)
Copy string to allocated memory.
struct MON_CAP * R_parse_monitorcap(int field, char *key)
char * G_gisbase(void)
top level module directory
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.