⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psp_scanner.h

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 H
字号:
#ifndef _PI3_PSP_SCANNER_H
#define _PI3_PSP_SCANNER_H

#include <stdio.h>
#include <assert.h>

#define MAX_INCLUDE_DEPTH 10
#define MAX_IMPORT_DEPTH 64

#ifdef POSIX
#	include <sys/param.h>
#	define _MAX_PATH	PATH_MAX
#	ifdef __GNUC__
#		undef __GNUC__
#	endif
#endif

/* Macros, which control the generated scanner and the parser */
#define YYLEX_PARAM pp
#define YYPARSE_PARAM pp
#define YY_DECL inline int PspFlexLexer::yylex(int *pi3lval)

/* Macros for convenience used by scanner */
#define pi3text YYText()
#define PG ((pPG)YYPARSE_PARAM)
#define PI3LESS(text, len) i = strlen(text) - len; yyless(i)

/**
* The block of global values for the parser,
* we need this to keep the parser reentrant
**/
typedef struct {

	/**
	* In the 1st pass we collect information for the class
	* header of the servlet, in the 2nd pass we print out the
	* stuff.
	**/
	void *scanner; // scanner_globals;
	char msgbuf[256];
} parser_globals, *pPG;

#ifdef __cplusplus
typedef struct yy_buffer_state *YY_BUFFER_STATE;

/**
* The C++ class version of the globals struct, for easier
* encapsulation of struct as class member of scanner class
**/
class PspFlexLexer;
class p_globals : public parser_globals {

public:
	p_globals( PspFlexLexer *PspFlexLexer )
	{
		assert( PspFlexLexer );
		scanner = PspFlexLexer;
	}
};

/* Scanner class */
class PspFlexLexer : public yyFlexLexer
{
private:
	const char *inFileName;
	int i, iParsedLen;
	p_globals *pp;
	char fname_buf[_MAX_PATH]; // include file info
	int include_stack_ptr;
	YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
	int iPass;
public:
	PspFlexLexer( const char *ifname = 0 );
	virtual ~PspFlexLexer();
	int exec();
	int prepare_next_pass();
	inline int get_pass() { return iPass; };
	inline const char *get_incl_name() { return (const char *)&fname_buf; };
	inline int get_incl_level() { return include_stack_ptr; };
	inline pPG get_globals() { return (pPG)pp; };

	inline int yylex( int *pi3lval );
	virtual int doShebang(const char *) = 0;
	virtual int doPlain(const char *) = 0;
	virtual int doScriptlet(const char *) = 0;
	virtual int doExpression(const char *) = 0;
	virtual int doError(const char *) = 0;
	virtual const char *makeAbsolute(const char *) = 0;
	inline int setParsedLen(int set) { iParsedLen = set; return 0; };
	inline int getParsedLen() { return iParsedLen; };
};

#	define SG ((PspFlexLexer *)((parser_globals *)pp)->scanner)
#	define EC extern "C"
#else
#	define EC
#endif // #ifdef __cplusplus

// common function prototypes
EC int pi3lex(int *, void *);
EC int pi3error(char *);
EC int pi3parse(void *);
//EC const char *get_incl_name(void *);
//EC int get_incl_level(void *);
EC int get_lineno(void *);
EC int cb_shebang(void *, const char *);
EC int cb_plain(void *, const char *);
EC int cb_scriptlet(void *, const char *);
EC int cb_expression(void *, const char *);
EC int cb_error(void *, const char *);
EC const char *cb_abspath(void *, const char *);
EC int cb_parsedlen(void *, int);

#undef EC

#endif /* _PI3_PSP_SCANNER_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -