Pārlūkot izejas kodu

[console] Pass escape sequence context to ANSI escape sequence handlers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 gadus atpakaļ
vecāks
revīzija
02a63c6dec

+ 9
- 3
src/arch/i386/firmware/pcbios/bios_console.c Parādīt failu

@@ -62,11 +62,13 @@ static unsigned int bios_attr = ATTR_DEFAULT;
62 62
 /**
63 63
  * Handle ANSI CUP (cursor position)
64 64
  *
65
+ * @v ctx		ANSI escape sequence context
65 66
  * @v count		Parameter count
66 67
  * @v params[0]		Row (1 is top)
67 68
  * @v params[1]		Column (1 is left)
68 69
  */
69
-static void bios_handle_cup ( unsigned int count __unused, int params[] ) {
70
+static void bios_handle_cup ( struct ansiesc_context *ctx __unused,
71
+			      unsigned int count __unused, int params[] ) {
70 72
 	int cx = ( params[1] - 1 );
71 73
 	int cy = ( params[0] - 1 );
72 74
 
@@ -85,10 +87,12 @@ static void bios_handle_cup ( unsigned int count __unused, int params[] ) {
85 87
 /**
86 88
  * Handle ANSI ED (erase in page)
87 89
  *
90
+ * @v ctx		ANSI escape sequence context
88 91
  * @v count		Parameter count
89 92
  * @v params[0]		Region to erase
90 93
  */
91
-static void bios_handle_ed ( unsigned int count __unused,
94
+static void bios_handle_ed ( struct ansiesc_context *ctx __unused,
95
+			     unsigned int count __unused,
92 96
 			     int params[] __unused ) {
93 97
 	/* We assume that we always clear the whole screen */
94 98
 	assert ( params[0] == ANSIESC_ED_ALL );
@@ -103,10 +107,12 @@ static void bios_handle_ed ( unsigned int count __unused,
103 107
 /**
104 108
  * Handle ANSI SGR (set graphics rendition)
105 109
  *
110
+ * @v ctx		ANSI escape sequence context
106 111
  * @v count		Parameter count
107 112
  * @v params		List of graphic rendition aspects
108 113
  */
109
-static void bios_handle_sgr ( unsigned int count, int params[] ) {
114
+static void bios_handle_sgr ( struct ansiesc_context *ctx __unused,
115
+			      unsigned int count, int params[] ) {
110 116
 	static const uint8_t bios_attr_fcols[10] = {
111 117
 		ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
112 118
 		ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA,

+ 6
- 4
src/core/ansiesc.c Parādīt failu

@@ -32,19 +32,20 @@ FILE_LICENCE ( GPL2_OR_LATER );
32 32
 /**
33 33
  * Call ANSI escape sequence handler
34 34
  *
35
- * @v handlers		List of escape sequence handlers
35
+ * @v ctx		ANSI escape sequence context
36 36
  * @v function		Control function identifier
37 37
  * @v count		Parameter count
38 38
  * @v params		Parameter list
39 39
  */
40
-static void ansiesc_call_handler ( struct ansiesc_handler *handlers,
40
+static void ansiesc_call_handler ( struct ansiesc_context *ctx,
41 41
 				   unsigned int function, int count,
42 42
 				   int params[] ) {
43
+	struct ansiesc_handler *handlers = ctx->handlers;
43 44
 	struct ansiesc_handler *handler;
44 45
 
45 46
 	for ( handler = handlers ; handler->function ; handler++ ) {
46 47
 		if ( handler->function == function ) {
47
-			handler->handle ( count, params );
48
+			handler->handle ( ctx, count, params );
48 49
 			break;
49 50
 		}
50 51
 	}
@@ -67,6 +68,7 @@ static void ansiesc_call_handler ( struct ansiesc_handler *handlers,
67 68
  * sequences we are prepared to accept as valid.
68 69
  */
69 70
 int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
71
+
70 72
 	if ( ctx->count == 0 ) {
71 73
 		if ( c == ESC ) {
72 74
 			/* First byte of CSI : begin escape sequence */
@@ -109,7 +111,7 @@ int ansiesc_process ( struct ansiesc_context *ctx, int c ) {
109 111
 			ctx->count = 0;
110 112
 			ctx->function <<= 8;
111 113
 			ctx->function |= c;
112
-			ansiesc_call_handler ( ctx->handlers, ctx->function,
114
+			ansiesc_call_handler ( ctx, ctx->function,
113 115
 					       count, ctx->params );
114 116
 		}
115 117
 		return -1;

+ 5
- 1
src/include/ipxe/ansiesc.h Parādīt failu

@@ -28,6 +28,8 @@
28 28
 
29 29
 FILE_LICENCE ( GPL2_OR_LATER );
30 30
 
31
+struct ansiesc_context;
32
+
31 33
 /** A handler for an escape sequence */
32 34
 struct ansiesc_handler {
33 35
 	/** The control function identifier
@@ -42,6 +44,7 @@ struct ansiesc_handler {
42 44
 	unsigned int function;
43 45
 	/** Handle escape sequence
44 46
 	 *
47
+	 * @v ctx		ANSI escape context
45 48
 	 * @v count		Parameter count
46 49
 	 * @v params		Parameter list
47 50
 	 *
@@ -54,7 +57,8 @@ struct ansiesc_handler {
54 57
 	 * omitted".  Consequently, the parameter list will always
55 58
 	 * contain at least one item.
56 59
 	 */
57
-	void ( * handle ) ( unsigned int count, int params[] );
60
+	void ( * handle ) ( struct ansiesc_context *ctx, unsigned int count,
61
+			    int params[] );
58 62
 };
59 63
 
60 64
 /** Maximum number of parameters within a single escape sequence */

+ 10
- 4
src/interface/efi/efi_console.c Parādīt failu

@@ -64,11 +64,13 @@ static unsigned int efi_attr = ATTR_DEFAULT;
64 64
 /**
65 65
  * Handle ANSI CUP (cursor position)
66 66
  *
67
+ * @v ctx		ANSI escape sequence context
67 68
  * @v count		Parameter count
68 69
  * @v params[0]		Row (1 is top)
69 70
  * @v params[1]		Column (1 is left)
70 71
  */
71
-static void efi_handle_cup ( unsigned int count __unused, int params[] ) {
72
+static void efi_handle_cup ( struct ansiesc_context *ctx __unused,
73
+			     unsigned int count __unused, int params[] ) {
72 74
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
73 75
 	int cx = ( params[1] - 1 );
74 76
 	int cy = ( params[0] - 1 );
@@ -84,11 +86,13 @@ static void efi_handle_cup ( unsigned int count __unused, int params[] ) {
84 86
 /**
85 87
  * Handle ANSI ED (erase in page)
86 88
  *
89
+ * @v ctx		ANSI escape sequence context
87 90
  * @v count		Parameter count
88 91
  * @v params[0]		Region to erase
89 92
  */
90
-static void efi_handle_ed ( unsigned int count __unused,
91
-			     int params[] __unused ) {
93
+static void efi_handle_ed ( struct ansiesc_context *ctx __unused,
94
+			    unsigned int count __unused,
95
+			    int params[] __unused ) {
92 96
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
93 97
 
94 98
 	/* We assume that we always clear the whole screen */
@@ -100,10 +104,12 @@ static void efi_handle_ed ( unsigned int count __unused,
100 104
 /**
101 105
  * Handle ANSI SGR (set graphics rendition)
102 106
  *
107
+ * @v ctx		ANSI escape sequence context
103 108
  * @v count		Parameter count
104 109
  * @v params		List of graphic rendition aspects
105 110
  */
106
-static void efi_handle_sgr ( unsigned int count, int params[] ) {
111
+static void efi_handle_sgr ( struct ansiesc_context *ctx __unused,
112
+			     unsigned int count, int params[] ) {
107 113
 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
108 114
 	static const uint8_t efi_attr_fcols[10] = {
109 115
 		ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,

+ 3
- 1
src/net/tcp/syslogs.c Parādīt failu

@@ -113,10 +113,12 @@ static unsigned int syslogs_severity = SYSLOG_DEFAULT_SEVERITY;
113 113
 /**
114 114
  * Handle ANSI set encrypted syslog priority (private sequence)
115 115
  *
116
+ * @v ctx		ANSI escape sequence context
116 117
  * @v count		Parameter count
117 118
  * @v params		List of graphic rendition aspects
118 119
  */
119
-static void syslogs_handle_priority ( unsigned int count __unused,
120
+static void syslogs_handle_priority ( struct ansiesc_context *ctx __unused,
121
+				      unsigned int count __unused,
120 122
 				      int params[] ) {
121 123
 	if ( params[0] >= 0 ) {
122 124
 		syslogs_severity = params[0];

+ 3
- 1
src/net/udp/syslog.c Parādīt failu

@@ -111,10 +111,12 @@ static unsigned int syslog_severity = SYSLOG_DEFAULT_SEVERITY;
111 111
 /**
112 112
  * Handle ANSI set syslog priority (private sequence)
113 113
  *
114
+ * @v ctx		ANSI escape sequence context
114 115
  * @v count		Parameter count
115 116
  * @v params		List of graphic rendition aspects
116 117
  */
117
-static void syslog_handle_priority ( unsigned int count __unused,
118
+static void syslog_handle_priority ( struct ansiesc_context *ctx __unused,
119
+				     unsigned int count __unused,
118 120
 				     int params[] ) {
119 121
 	if ( params[0] >= 0 ) {
120 122
 		syslog_severity = params[0];

Notiek ielāde…
Atcelt
Saglabāt