1
/****************************************************************************
2
Xplanet 0.94 - render an image of a planet into an X window
3
Copyright (C) 2002 Hari Nair <hari@alumni.caltech.edu>
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
****************************************************************************/
30
return(c == ' ' || c == '\t' || c == ',' || c == '/');
36
// 13 is DOS end-of-line, 28 is the file separator
37
return(c == '#' || c == '\0' || c == 13 || c == 28);
41
skipPastToken(int &i, const char *line)
43
while (!isDelimiter(line[i]))
45
if (isEndOfLine(line[i])) return;
51
getValue(const char *line, int &i, const char *key, char *&returnstring)
53
const unsigned int length = strlen(key);
54
if (strncmp(line + i, key, length) == 0)
58
skipPastToken(i, line);
59
returnstring = new char[i - istart + 1];
60
strncpy(returnstring, (line + istart), i - istart);
61
returnstring[i-istart] = '\0';
67
// This routine returns the next token in the line and its type.
69
parse(int &i, const char *line, char *&returnstring)
71
if (i >= (int) strlen(line)) return(ENDOFLINE);
73
if (returnstring != NULL) cerr << "returnstring is not NULL!\n";
75
int returnval = UNKNOWN;
77
if (isDelimiter(line[i]))
78
returnval = DELIMITER;
79
else if (isEndOfLine(line[i]))
80
returnval = ENDOFLINE;
81
else if (getValue(line, i, "align=", returnstring))
83
else if (getValue(line, i, "altcirc=", returnstring))
85
else if (getValue(line, i, "color=", returnstring))
87
else if (getValue(line, i, "font=", returnstring))
89
else if (getValue(line, i, "fontsize=", returnstring))
91
else if (getValue(line, i, "image=", returnstring))
93
else if (getValue(line, i, "symbolsize=", returnstring))
94
returnval = SYMBOLSIZE;
95
else if (getValue(line, i, "position=", returnstring))
97
else if (getValue(line, i, "radius=", returnstring))
99
else if (getValue(line, i, "spacing=", returnstring))
101
else if (line[i] == '"')
104
while (line[i] != '"')
107
if (i >= (int) strlen(line))
109
cerr << "Unterminated string in marker file!\n";
113
returnstring = new char[i - istart + 1];
114
strncpy(returnstring, (line + istart), i - istart);
115
returnstring[i-istart] = '\0';
118
else if (line[i] == '{')
121
while (line[i] != '}')
124
if (i >= (int) strlen(line))
126
cerr << "Unterminated string in marker file!\n";
130
returnstring = new char[i - istart + 1];
131
strncpy(returnstring, (line + istart), i - istart);
132
returnstring[i-istart] = '\0';
135
else if (strncmp(line+i, "timezone=", 9) == 0)
139
while (line[i] == '/' || line[i] == ',' || !isDelimiter(line[i]))
141
if (isEndOfLine(line[i])) break;
144
returnstring = new char[i - istart + 1];
145
strncpy(returnstring, (line + istart), i - istart);
146
returnstring[i-istart] = '\0';
147
returnval = TIMEZONE;
149
else if (strncmp(line+i, "trail={", 7) == 0)
153
while (line[i] != '}')
156
if (i >= (int) strlen(line))
158
cerr << "Unterminated trail value in satellite file!\n";
162
returnstring = new char[i - istart + 1];
163
strncpy(returnstring, (line + istart), i - istart);
164
returnstring[i-istart] = '\0';
167
else if (strncmp(line+i, "transparent={", 13) == 0)
171
while (line[i] != '}')
174
if (i >= (int) strlen(line))
176
cerr << "Unterminated pixel value in marker file!\n";
180
returnstring = new char[i - istart + 1];
181
strncpy(returnstring, (line + istart), i - istart);
182
returnstring[i-istart] = '\0';
183
returnval = TRANSPARENT;
185
else // assume it's a latitude/longitude value
188
skipPastToken(i, line);
189
returnstring = new char[i - istart + 1];
190
strncpy(returnstring, (line + istart), i - istart);
191
returnstring[i-istart] = '\0';
194
sscanf(returnstring, "%lf", &temp);
195
if (temp > -360 && temp < 360)
197
returnval = LATLON; // else defaults to UNKNOWN
207
returntype = "UNKNOWN";
210
returntype = "DELIMITER";
213
returntype = "ENDOFLINE";
216
returntype = "ALIGN";
219
returntype = "COLOR";
225
returntype = "FONTSIZE";
228
returntype = "IMAGE";
231
returntype = "POSITION";
234
returntype = "SPACING";
240
returntype = "TIMEZONE";
242
returntype = "TRANSPARENT";
245
returntype = "LATLON";
252
<< (returnstring == NULL ? "NULL" : returnstring)
253
<< "\t(" << returntype << ")"