#include <string.h>
#include <assert.h>
#include <gpxe/ansiesc.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static void | ansiesc_call_handler (struct ansiesc_handler *handlers, unsigned int function, int count, int params[]) |
| Call ANSI escape sequence handler. | |
| int | ansiesc_process (struct ansiesc_context *ctx, int c) |
| Process character that may be part of ANSI escape sequence. | |
Definition in file ansiesc.c.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| static void ansiesc_call_handler | ( | struct ansiesc_handler * | handlers, | |
| unsigned int | function, | |||
| int | count, | |||
| int | params[] | |||
| ) | [static] |
Call ANSI escape sequence handler.
| handlers | List of escape sequence handlers | |
| function | Control function identifier | |
| count | Parameter count | |
| params | Parameter list |
Definition at line 39 of file ansiesc.c.
References ansiesc_handler::function, and ansiesc_handler::handle.
Referenced by ansiesc_process().
00041 { 00042 struct ansiesc_handler *handler; 00043 00044 for ( handler = handlers ; handler->function ; handler++ ) { 00045 if ( handler->function == function ) { 00046 handler->handle ( count, params ); 00047 break; 00048 } 00049 } 00050 }
| int ansiesc_process | ( | struct ansiesc_context * | ctx, | |
| int | c | |||
| ) |
Process character that may be part of ANSI escape sequence.
| ctx | ANSI escape sequence context | |
| c | Character |
| c | Original character if not part of escape sequence | |
| <0 | Character was part of escape sequence |
In the interests of code size, we are rather liberal about the sequences we are prepared to accept as valid.
Definition at line 68 of file ansiesc.c.
References ansiesc_call_handler(), ansiesc_context::count, DBG, ESC, ansiesc_context::function, ansiesc_context::handlers, memset(), and ansiesc_context::params.
Referenced by bios_putchar(), and efi_putchar().
00068 { 00069 if ( ctx->count == 0 ) { 00070 if ( c == ESC ) { 00071 /* First byte of CSI : begin escape sequence */ 00072 ctx->count = 1; 00073 memset ( ctx->params, 0xff, sizeof ( ctx->params ) ); 00074 ctx->function = 0; 00075 return -1; 00076 } else { 00077 /* Normal character */ 00078 return c; 00079 } 00080 } else { 00081 if ( c == '[' ) { 00082 /* Second byte of CSI : do nothing */ 00083 } else if ( ( c >= '0' ) && ( c <= '9' ) ) { 00084 /* Parameter Byte : part of a parameter value */ 00085 int *param = &ctx->params[ctx->count - 1]; 00086 if ( *param < 0 ) 00087 *param = 0; 00088 *param = ( ( *param * 10 ) + ( c - '0' ) ); 00089 } else if ( c == ';' ) { 00090 /* Parameter Byte : parameter delimiter */ 00091 ctx->count++; 00092 if ( ctx->count > ( sizeof ( ctx->params ) / 00093 sizeof ( ctx->params[0] ) ) ) { 00094 /* Excessive parameters : abort sequence */ 00095 ctx->count = 0; 00096 DBG ( "Too many parameters in ANSI escape " 00097 "sequence\n" ); 00098 } 00099 } else if ( ( c >= 0x20 ) && ( c <= 0x2f ) ) { 00100 /* Intermediate Byte */ 00101 ctx->function <<= 8; 00102 ctx->function |= c; 00103 } else { 00104 /* Treat as Final Byte. Zero ctx->count before 00105 * calling handler to avoid potential infinite loops. 00106 */ 00107 int count = ctx->count; 00108 ctx->count = 0; 00109 ctx->function <<= 8; 00110 ctx->function |= c; 00111 ansiesc_call_handler ( ctx->handlers, ctx->function, 00112 count, ctx->params ); 00113 } 00114 return -1; 00115 } 00116 }
1.5.7.1