1
2
3 THESE ROUTINES ARE NOT USED
YET(MAYBE NEVER...)4 YET (MAYBE NEVER...)
5
6
7 /* .GMF file I/O
8
9 * Copyright (C) 1998 J.A. Bezemer
10 *
11 * Licensed under the terms of the GNU General Public License.
12 * ABSOLUTELY NO WARRANTY.
13 * See the file `COPYING' in this directory.
14 */
15
16 /*#include "gmffileio.h"
17 */
18 #include <stdio.h>
19 #include <stdlib.h>
20
21 /* structure = better?
22 typedef struct {
23 FILE *file;
24 char filename[250];
25 ...?
26 } gmffile_t;
27 */
28
29 FILE *create_gmf (char *filename)
30 /* Makes new .gmf file, writes comment-headers */
31 {
32 }
33
34 FILE *
open_gmf(char * filename)35 open_gmf (char *filename)
36 /* Opens a .gmf file for in/output. Returns NULL if not successful */
37 {
38 FILE *gmffile;
39
40 gmffile = fopen (filename, "r");
41
42 return gmffile;
43 }
44
45 int
close_gmf(FILE * gmffile)46 close_gmf (FILE * gmffile)
47 {
48 return fclose (gmffile);
49 }
50
51 int
read_line_from_gmf(FILE * gmffile,char ** line)52 read_line_from_gmf (FILE * gmffile, char **line)
53 /* Reads 1 line from gmf file, terminated by 10 or 13 or EOF.
54 1: successful, 0: not (EOF). line will be malloc'ed.
55 If successful, file pointer will be on start of next line */
56 {
57 long oldpos;
58 long numofchars = 0;
59 int i;
60
61 oldpos = ftell (gmffile);
62
63 do
64 {
65 i = fgetc (gmffile);
66 numofchars++;
67 }
68 while (i != 10 && i != 13 && i != EOF);
69
70 /* numofchars is including 10, 13 or EOF, so always >= 1 */
71
72 if (numofchars == 1 && i == EOF)
73 return 0; /* End of file */
74
75 *line = (char *) malloc (numofchars * sizeof (char));
76
77 if (fseek (gmffile, oldpos, SEEK_SET))
78 return 0;
79
80 for (i = 0; i < numofchars; i++)
81 (*line)[i] = fgetc (gmffile);
82
83 (*line)[numofchars - 1] = '\0';
84
85 return 1;
86 }
87
88 char *
strip_spaces(char * instring)89 strip_spaces (char *instring)
90 /* Strips spaces from beginning and end. Return-string will be malloc'ed */
91 {
92 char *outstring;
93 char *startptr;
94 char *endptr;
95 char *tempcharptr;
96
97 startptr = instring;
98
99 while ((*startptr == ' ' || *startptr == 9)
100 && *startptr != '\0')
101 startptr++;
102 /* startptr now on real start of text */
103
104 endptr = startptr;
105 while (*endptr != '\0')
106 endptr++;
107 /* endptr now on last character */
108
109 while ((*endptr == ' ' || *endptr == 9 || *endptr == '\0')
110 && endptr > startptr)
111 endptr--;
112 /* endptr now on real end of text */
113
114 outstring = (char *) malloc (((endptr + 2) - startptr) * sizeof (char));
115 outstring[(endptr + 1) - startptr] = '\0';
116
117 tempcharptr = outstring;
118
119 while (startptr <= endptr)
120 {
121 *tempcharptr = *startptr;
122 tempcharptr++;
123 startptr++;
124 }
125
126 return outstring;
127 }
128
129 void
del_comments(char * line)130 del_comments (char *line)
131 /* strip_comments -> '\0' if starting with '#'. So `line' is modified. */
132 {
133 if (line[0] = '#')
134 line[0] = '\0';
135 }
136
137
138 int
search_identifier(FILE * gmffile,char * identifier)139 search_identifier (FILE * gmffile, char *identifier)
140 /* Returns 1 if found, 0 if not found */
141 {
142 rewind (gmffile);
143
144 }
145
146 int
read_simpval_from_gmf(FILE * gmffile,char * identifier,char * value)147 read_simpval_from_gmf (FILE * gmffile, char *identifier, char *value)
148 /* Reads simple value; `value' will be malloc'ed.
149 Returns 1: OK, 0: failure (not present, etc.) */
150 {
151 }
152
153 void
write_simpval_to_gmf(FILE * gmffile,char * identifier,char * value)154 write_simpval_to_gmf (FILE * gmffile, char *identifier, char *value)
155 /* Writes simple value `identifier = value', discarding old value if present */
156 {
157 }
158
159 int
start_read_list_from_gmf(FILE * gmffile,char * identifier)160 start_read_list_from_gmf (FILE * gmffile, char *identifier)
161 /* Start reading a list. Returns 1: OK, 0: failure (not present, etc.) */
162 {
163 }
164
165 int
read_listitem_from_gmf(FILE * gmffile,char * value)166 read_listitem_from_gmf (FILE * gmffile, char *value)
167 /* Read one value from a list that has been started using
168 start_read_list_from_gmf(). `value' will be malloc'ed.
169 Returns 1: OK, 0: failure (no more items, etc.) */
170 {
171 }
172
173 void
start_write_list_to_gmf(FILE * gmffile,char * identifier)174 start_write_list_to_gmf (FILE * gmffile, char *identifier)
175 /* Start writing a (new) list, discarding old contents if present */
176 {
177 }
178
179 void
write_listitem_to_gmf(FILE * gmffile,char * value)180 write_listitem_to_gmf (FILE * gmffile, char *value)
181 /* Writes one item to list opened by start_write_list_to_gmf() */
182 {
183 }
184
185 void
stop_write_list_to_gmf(FILE * gmffile)186 stop_write_list_to_gmf (FILE * gmffile)
187 /* Closes writing of the list opened by start_write_list_to_gmf() */
188 {
189 }
190
191
main()192 main ()
193 {
194 char *line = 0;
195 char *line2 = 0;
196 FILE *gmffile;
197
198 gmffile = open_gmf ("/tmp/test.gmf");
199
200 while (read_line_from_gmf (gmffile, &line))
201 {
202 printf ("%p>%s<\n", line, line);
203 line2 = strip_spaces (line);
204 printf ("%p>%s<\n", line2, line2);
205 free (line);
206 free (line2);
207 }
208
209 close_gmf (gmffile);
210
211 }
212