6 #include <grass/dbmi.h>
9 static char *dbmscap_files[] = {
13 "/usr/local/lib/dbmscap",
14 "/usr/local/dbmi/lib/dbmscap",
18 static void add_entry();
20 static char *dbmscap_filename(err_flag)
29 for (i = 0; (file = dbmscap_files[i]); i++) {
30 if (access(file, 0) == 0)
36 return ((
char *)
NULL);
47 return dbmscap_filename(1);
58 return (dbmscap_filename(0) !=
NULL);
69 strcpy(dst->driverName, src->driverName);
70 strcpy(dst->comment, src->comment);
71 strcpy(dst->startup, src->startup);
101 dbDbmscap *list =
NULL;
109 return (dbDbmscap *)
NULL;
114 fd = fopen(file,
"r");
117 return (dbDbmscap *)
NULL;
127 for (line = 1; fgets(
buf,
sizeof buf,
fd); line++) {
128 if (sscanf(
buf,
"%1s", comment) != 1 || *comment ==
'#')
130 if (sscanf(
buf,
"%[^:]:%[^:]:%[^:\n]",
name, startup, comment) == 3)
131 add_entry(&list,
name, startup, comment);
132 else if (sscanf(
buf,
"%[^:]:%[^:\n]",
name, startup) == 2)
133 add_entry(&list,
name, startup,
"");
135 fprintf(stderr,
"%s: line %d: invalid entry\n", file, line);
136 fprintf(stderr,
"%d:%s\n", line,
buf);
149 dirpath = G_malloc(strlen(
"\\driver\\db\\") + strlen(
G_gisbase()) + 1);
156 G_debug(2,
"dbDbmscap(): opendir [%s]", dirpath);
160 return (dbDbmscap *)
NULL;
168 if ((strcmp(ent->d_name,
".") == 0)
169 || (strcmp(ent->d_name,
"..") == 0))
174 if (
G_strstr(ent->d_name,
".manifest"))
182 dirpath = G_malloc(strlen(
"\\driver\\db\\")
183 + strlen(
G_gisbase()) + strlen(ent->d_name) + 1);
189 add_entry(&list, name, dirpath,
"");
200 add_entry(dbDbmscap ** list,
char *
name,
char *startup,
char *comment)
202 dbDbmscap *head, *cur, *tail;
206 while (tail && tail->next)
210 cur = (dbDbmscap *)
db_malloc(
sizeof(dbDbmscap));
216 strcpy(cur->driverName, name);
217 strcpy(cur->startup, startup);
218 strcpy(cur->comment, comment);
237 dbDbmscap *next, *cur;
239 for (cur = list; cur; cur = next) {
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
dbDbmscap * db_read_dbmscap(void)
char * G_convert_dirseps_to_host(char *path)
Converts directory separator characters in a string to the native host separator character (/ on Unix...
int G_asprintf(char **out, const char *fmt,...)
void db_error(const char *s)
char * G_str_replace(char *buffer, const char *old_str, const char *new_str)
Replace all occurencies of old_str in buffer with new_str.
void db_syserror(const char *s)
const char * db_dbmscap_filename(void)
void db_copy_dbmscap_entry(dbDbmscap *dst, dbDbmscap *src)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
char * G_strstr(const char *mainString, const char *subString)
Finds the first occurrence of the character C in the null-terminated string beginning at mainString...
int G_debug(int level, const char *msg,...)
Print debugging message.
char * G_gisbase(void)
top level module directory
void db_free_dbmscap(dbDbmscap *list)