xref: /haiku/src/apps/terminal/TermParse.h (revision d0f2d8282f3f59a1af7fe2d340d2af0cb36a9b20)
1 /*
2  * Copyright 2013, Haiku, Inc. All rights reserved.
3  * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
4  * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
5  *
6  * Distributed under the terms of the MIT License.
7  *
8  * Authors:
9  *		Kian Duffy, myob@users.sourceforge.net
10  *		Siarzhuk Zharski, zharik@gmx.li
11  */
12 #ifndef TERMPARSE_H
13 #define TERMPARSE_H
14 
15 
16 #include "TermConst.h"
17 
18 #include <Handler.h>
19 #include <OS.h>
20 
21 
22 #define READ_BUF_SIZE 2048
23 	// pty read buffer size
24 #define MIN_PTY_BUFFER_SPACE	16
25 	// minimal space left before the reader tries to read more
26 #define ESC_PARSER_BUFFER_SIZE	64
27 	// size of the parser buffer
28 
29 
30 class TerminalBuffer;
31 
32 class TermParse : public BHandler {
33 public:
34 	TermParse(int fd);
35 	~TermParse();
36 
37 	status_t StartThreads(TerminalBuffer *view);
38 	status_t StopThreads();
39 
40 private:
41 	inline uchar _NextParseChar();
42 
43 	// Initialize TermParse and PtyReader thread.
44 	status_t _InitTermParse();
45 	status_t _InitPtyReader();
46 
47 	void _StopTermParse();
48 	void _StopPtyReader();
49 
50 	int32 EscParse();
51 	int32 PtyReader();
52 
53 	void DumpState(int *groundtable, int *parsestate, uchar c);
54 
55 	static int32 _ptyreader_thread(void *);
56 	static int32 _escparse_thread(void *);
57 
58 	status_t _ReadParserBuffer();
59 
60 	void _DeviceStatusReport(int n);
61 	void _DecReqTermParms(int value);
62 	void _DecPrivateModeSet(int value);
63 	void _DecPrivateModeReset(int value);
64 	int* _GuessGroundTable(int encoding);
65 	void _ProcessOperatingSystemControls(uchar* params);
66 
67 	int fFd;
68 
69 	thread_id fParseThread;
70 	thread_id fReaderThread;
71 	sem_id fReaderSem;
72 	sem_id fReaderLocker;
73 
74 	uint fBufferPosition;
75 	uchar fReadBuffer[READ_BUF_SIZE];
76 	int32 fReadBufferSize;
77 
78 	uchar fParserBuffer[ESC_PARSER_BUFFER_SIZE];
79 	int32 fParserBufferSize;
80 	int32 fParserBufferOffset;
81 
82 	TerminalBuffer *fBuffer;
83 
84 	bool fQuitting;
85 };
86 
87 #endif // TERMPARSE_H
88