00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef CONFFILE_H
00027 #define CONFFILE_H
00028
00029 #include <stdio.h>
00030 #include "playercommon.h"
00031 #include "player.h"
00032
00033
00049 class ConfigFile
00050 {
00052 public: ConfigFile();
00053
00055 public: ~ConfigFile();
00056
00060 public: bool Load(const char *filename);
00061
00062
00063
00064 private: bool Save(const char *filename);
00065
00068 public: bool WarnUnused();
00069
00075 public: const char *ReadString(int section,
00076 const char *name,
00077 const char *value);
00078
00079
00080 private: void WriteString(int section,
00081 const char *name,
00082 const char *value);
00083
00089 public: int ReadInt(int section,
00090 const char *name,
00091 int value);
00092
00093
00094 private: void WriteInt(int section,
00095 const char *name,
00096 int value);
00097
00103 public: double ReadFloat(int section,
00104 const char *name,
00105 double value);
00106
00107
00108 private: void WriteFloat(int section,
00109 const char *name,
00110 double value);
00111
00117 public: double ReadLength(int section,
00118 const char *name,
00119 double value);
00120
00121
00122 private: void WriteLength(int section,
00123 const char *name,
00124 double value);
00125
00135 public: double ReadAngle(int section, const char *name, double value);
00136
00147 public: uint32_t ReadColor(int section,
00148 const char *name,
00149 uint32_t value);
00150
00160 public: const char *ReadFilename(int section,
00161 const char *name,
00162 const char *value);
00163
00167 public: int GetTupleCount(int section, const char *name);
00168
00175 public: const char *ReadTupleString(int section,
00176 const char *name,
00177 int index,
00178 const char *value);
00179
00180
00181 private: void WriteTupleString(int section,
00182 const char *name,
00183 int index,
00184 const char *value);
00185
00192 public: int ReadTupleInt(int section,
00193 const char *name,
00194 int index,
00195 int value);
00196
00197
00198 private: void WriteTupleInt(int section,
00199 const char *name,
00200 int index,
00201 int value);
00202
00203
00210 public: double ReadTupleFloat(int section,
00211 const char *name,
00212 int index,
00213 double value);
00214
00215
00216 private: void WriteTupleFloat(int section,
00217 const char *name,
00218 int index,
00219 double value);
00220
00227 public: double ReadTupleLength(int section,
00228 const char *name,
00229 int index,
00230 double value);
00231
00232
00233 private: void WriteTupleLength(int section,
00234 const char *name,
00235 int index,
00236 double value);
00237
00248 public: double ReadTupleAngle(int section,
00249 const char *name,
00250 int index,
00251 double value);
00252
00253
00254 private: void WriteTupleAngle(int section,
00255 const char *name,
00256 int index,
00257 double value);
00258
00270 public: uint32_t ReadTupleColor(int section,
00271 const char *name,
00272 int index,
00273 uint32_t value);
00274
00279
00287 public: int ReadDeviceId(player_device_id_t *id, int section, const char *name,
00288 int code, int index, const char *key);
00289
00291 public: int GetSectionCount();
00292
00294 public: const char *GetSectionType(int section);
00295
00298 public: int LookupSection(const char *type);
00299
00302 public: int GetSectionParent(int section);
00303
00304
00306
00307
00308
00309 private: bool LoadTokens(FILE *file, int include);
00310
00311
00312 private: bool LoadTokenComment(FILE *file, int *line, int include);
00313
00314
00315 private: bool LoadTokenWord(FILE *file, int *line, int include);
00316
00317
00318 private: bool LoadTokenInclude(FILE *file, int *line, int include);
00319
00320
00321 private: bool LoadTokenNum(FILE *file, int *line, int include);
00322
00323
00324 private: bool LoadTokenString(FILE *file, int *line, int include);
00325
00326
00327 private: bool LoadTokenSpace(FILE *file, int *line, int include);
00328
00329
00330 private: bool SaveTokens(FILE *file);
00331
00332
00333 private: void ClearTokens();
00334
00335
00336 private: bool AddToken(int type, const char *value, int include);
00337
00338
00339 private: bool SetTokenValue(int index, const char *value);
00340
00341
00342 private: const char *GetTokenValue(int index);
00343
00345 public: void DumpTokens();
00346
00347
00348 private: bool ParseTokens();
00349
00350
00351 private: bool ParseTokenInclude(int *index, int *line);
00352
00353
00354 private: bool ParseTokenDefine(int *index, int *line);
00355
00356
00357 private: bool ParseTokenWord(int section, int *index, int *line);
00358
00359
00360 private: bool ParseTokenSection(int section, int *index, int *line);
00361
00362
00363 private: bool ParseTokenField(int section, int *index, int *line);
00364
00365
00366 private: bool ParseTokenTuple(int section, int field,
00367 int *index, int *line);
00368
00369
00370 private: void ClearMacros();
00371
00372
00373 private: int AddMacro(const char *macroname, const char *sectionname,
00374 int line, int starttoken, int endtoken);
00375
00376
00377
00378 private: int LookupMacro(const char *macroname);
00379
00380
00381 private: void DumpMacros();
00382
00383
00384 private: void ClearSections();
00385
00386
00387 private: int AddSection(int parent, const char *type);
00388
00390 public: void DumpSections();
00391
00392
00393 private: void ClearFields();
00394
00395
00396 private: int AddField(int section, const char *name, int line);
00397
00398
00399 private: void AddFieldValue(int field, int index, int value_token);
00400
00401
00402 private: int GetField(int section, const char *name);
00403
00404
00405 private: int GetFieldValueCount(int field);
00406
00407
00408
00409 private: const char *GetFieldValue(int field, int index, bool flag_used = true);
00410
00411
00412 private: void SetFieldValue(int field, int index, const char *value);
00413
00415 public: void DumpFields();
00416
00417
00418 private: uint32_t LookupColor(const char *name);
00419
00421 public: char *filename;
00422
00423
00424 private: enum
00425 {
00426 TokenComment,
00427 TokenWord, TokenNum, TokenString,
00428 TokenOpenSection, TokenCloseSection,
00429 TokenOpenTuple, TokenCloseTuple,
00430 TokenSpace, TokenEOL
00431 };
00432
00433
00434 private: struct Token
00435 {
00436
00437 int include;
00438
00439
00440 int type;
00441
00442
00443 char *value;
00444 };
00445
00446
00447
00448 private: int token_size, token_count;
00449 private: Token *tokens;
00450
00451
00452 private: struct CMacro
00453 {
00454
00455 const char *macroname;
00456
00457
00458 const char *sectionname;
00459
00460
00461 int line;
00462
00463
00464 int starttoken, endtoken;
00465 };
00466
00467
00468 private: int macro_size;
00469 private: int macro_count;
00470 private: CMacro *macros;
00471
00472
00473 private: struct Section
00474 {
00475
00476 int parent;
00477
00478
00479 const char *type;
00480 };
00481
00482
00483 private: int section_size;
00484 private: int section_count;
00485 private: Section *sections;
00486
00487
00488 private: struct Field
00489 {
00490
00491 int section;
00492
00493
00494 const char *name;
00495
00496
00497 int value_count;
00498 int *values;
00499
00500
00501 bool *useds;
00502
00503
00504 int line;
00505 };
00506
00507
00508 private: int field_size;
00509 private: int field_count;
00510 private: Field *fields;
00511
00512
00513 private: double unit_length;
00514 private: double unit_angle;
00515 };
00516
00517 #endif