Debian Codegraph @

cfile/inffile.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
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 3 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, see <http://www.gnu.org/licenses/>.
17 */
18
19 // InfFile.h: interface for the InfFile class.
20 //
21 //////////////////////////////////////////////////////////////////////
22
23 #ifndef INFFILE_H
24 #define INFFILE_H
25
26 #if _MSC_VER >= 1000
27 #pragma once
28 #endif // _MSC_VER >= 1000
29
30 #include "pstypes.h"
31 #include "psclass.h"
32
33 struct CFILE;
34
35 enum InfFileError {
36 INFFILE_LINELEN = 256,
37 INFFILE_CUSTOM = -128,
38 INFFILE_ERROR = -1,
39 INFFILE_COMMENT = -2,
40 INFFILE_EOL = -3,
41 INFFILE_SYMBOL = 1024,
42 };
43
44 class InfFile {
45 public:
46 InfFile();
47 virtual ~InfFile();
48
49 // opens an inf file, pass in a lexical analyzer that will return a command index.
50 // tag_check is a string that must appear at the very beginning of the file.
51 // lexfn is a function to match a command to a number. num <= 0 and num >=1024 are taken.
52 bool Open(const char *filename, const char *tag_check, int (*lexfn)(const char *command));
53
54 // closes the file
55 void Close();
56
57 // read a command line. returns false on eof.
58 bool ReadLine();
59
60 // parses a line of 'code'. return value from the lexfn
61 // check INFFILE constants above. (any value less than 0, you should read in a new line.)
62 int ParseLine(char *operand, int oprlen);
63
64 private:
65 CFILE *m_fp; // file object.
66 int (*m_lexfn)(const char *); // lexical analyzer.
67 char m_linetext[INFFILE_LINELEN];
68 char *m_lineptr; // pointer to current text line.
69 char *m_endptr; // pointer to last character in text line
70 int m_line; // line #
71
72 struct sym_info // full runtime symbol
73 {
74 char name[_MAX_PATH];
75 char *text;
76 };
77
78 // inf file symbol list
79 tList<sym_info> m_sym_list; // symbol list.
80
81 private:
82 void AddSymbol(const char *name, const char *text);
83 const char *GetSymbolText(const char *name);
84 void FreeSymbols();
85
86 public:
87 // line number
88 int line() const { return m_line; };
89 };
90
91 #endif