/[public]/psiconv/trunk/lib/psiconv/configuration.c
ViewVC logotype

Annotation of /psiconv/trunk/lib/psiconv/configuration.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 176 - (hide annotations)
Tue Dec 2 19:47:47 2003 UTC (20 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 3344 byte(s)
(Frodo) Picture generation now supports all RLE's and many more config
        items. Mostly untested, though.

1 frodo 168 /*
2     configuration.c - Part of psiconv, a PSION 5 file formats converter
3     Copyright (c) 1999, 2000,2003 Frodo Looijaard <frodol@dds.nl>
4    
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9    
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     GNU General Public License for more details.
14    
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18     */
19    
20     #include "config.h"
21 frodo 173 #include "error.h"
22 frodo 168 #include "compat.h"
23     #include <stdio.h>
24     #include <stdlib.h>
25     #include <string.h>
26    
27     #include "configuration.h"
28    
29     #ifdef DMALLOC
30     #include <dmalloc.h>
31     #endif
32    
33     #ifndef CONFIGURATION_SEARCH_PATH
34     #define CONFIGURATION_SEARCH_PATH "/etc/psiconv.conf:~/.psiconv.conf"
35     #endif
36     struct psiconv_config_s default_config =
37 frodo 176 { PSICONV_VERB_WARN, 2, 0,0,0,psiconv_bool_false,NULL };
38 frodo 168
39     psiconv_config psiconv_config_read(const char *extra_config_file)
40     {
41     psiconv_config config;
42     if (!(config = malloc(sizeof(*config))))
43     return NULL;
44     memcpy(config,&default_config,sizeof(*config));
45     return config;
46     }
47    
48     /*TO DO */
49    
50     #if 0
51    
52     /* I hate string manipulation in C */
53     psiconv_config_t psiconv_config_read(const char *extra_config_files)
54     {
55     psiconv_config_t result = default_config;
56     char *path,pathptr;
57     int file;
58     struct stat stat_buf;
59    
60     /* Make path be the complete search path, colon separated */
61     if (extra_config_files && strlen(extra_config_files)) {
62     path = malloc(strlen(CONFIGURATION_SEARCH_PATH) +
63     strlen(extra_config_files) + 2);
64     strcpy(path,CONFIGURATION_SEARCH_PATH);
65     strcat(path,":");
66     strcat(path,extra_config_files)
67     } else {
68     path = strdup(CONFIGURATION_SEARCH_PATH)
69     }
70    
71     pathptr = path;
72     while (strlen(pathptr)) {
73     /* Isolate the next filename */
74     filename_len = (path - index(':',path)) || strlen(path);
75     filename = malloc(filename_len + 1);
76     filename = strncpy(filename,path,filename_len);
77     filename[filename_len + 1] = 0;
78     pathptr += filename_len;
79     if (strlen(pathptr))
80     pathptr ++;
81    
82     /* Try to open the file; it may fail, if it does not exist for example */
83     if ((file = open(filename,O_RDONLY)) == -1)
84     continue;
85    
86     /* Read the contents of the file into filebuffer */
87     if (!fstat(file,&stat_buf))
88     continue;
89     filesize = stat_buf.off_t;
90     filebuffer = malloc(filesize + 1);
91     filebuffer_ptr = filebuffer;
92     bytes_left = filesize;
93     bytes_read = 1 /* Dummy for the first time through the loop */
94     while ((bytes_read > 0) && bytes_left) {
95     bytes_read = read(file,filebuffer_ptr,bytes_left);
96     if (bytes_read == -1) {
97     filebuffer_ptr += bytes_read;
98     bytes_left -= bytes_read;
99     }
100     }
101     if (bytes_left)
102     continue;
103    
104     /* Try to parse the filebuffer */
105     filebuffer_ptr = file_buffer;
106     bytes_left = filesize;
107     while (bytes_left) {
108     /* Parse a line */
109     line_length = index(''
110    
111     }
112     }
113    
114     #endif
115    

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26