Descent3/lib/InfFile.h

90 lines
2.6 KiB
C
Raw Normal View History

/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2024-04-16 03:43:29 +00:00
// InfFile.h: interface for the InfFile class.
//
//////////////////////////////////////////////////////////////////////
2024-04-19 12:57:55 +00:00
#if !defined(AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_)
#define AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_
2024-04-16 03:43:29 +00:00
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "pstypes.h"
#include "psclass.h"
struct CFILE;
2024-04-19 12:57:55 +00:00
#define INFFILE_LINELEN 256
#define INFFILE_CUSTOM -128
#define INFFILE_ERROR -1
#define INFFILE_COMMENT -2
#define INFFILE_EOL -3
#define INFFILE_SYMBOL 1024
2024-04-16 18:56:40 +00:00
class InfFile {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
InfFile();
virtual ~InfFile();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// opens an inf file, pass in a lexical analyzer that will return a command index.
// tag_check is a string that must appear at the very beginning of the file.
// lexfn is a function to match a command to a number. num <= 0 and num >=1024 are taken.
bool Open(const char *filename, const char *tag_check, int (*lexfn)(const char *command));
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// closes the file
void Close();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// read a command line. returns false on eof.
bool ReadLine();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// parses a line of 'code'. return value from the lexfn
// check INFFILE constants above. (any value less than 0, you should read in a new line.)
int ParseLine(char *operand, int oprlen);
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
CFILE *m_fp; // file object.
int (*m_lexfn)(const char *); // lexical analyzer.
char m_linetext[INFFILE_LINELEN];
char *m_lineptr; // pointer to current text line.
char *m_endptr; // pointer to last character in text line
int m_line; // line #
struct sym_info // full runtime symbol
{
char name[PSPATHNAME_LEN];
2024-04-16 18:56:40 +00:00
char *text;
};
// inf file symbol list
tList<sym_info> m_sym_list; // symbol list.
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
void AddSymbol(const char *name, const char *text);
const char *GetSymbolText(const char *name);
void FreeSymbols();
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
// line number
int line() const { return m_line; };
2024-04-16 03:43:29 +00:00
};
2024-04-19 12:57:55 +00:00
#endif // !defined(AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_)