iPXE
Data Structures | Functions | Variables
console_cmd.c File Reference

Console management commands. More...

#include <string.h>
#include <getopt.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/console.h>
#include <ipxe/image.h>
#include <ipxe/pixbuf.h>
#include <ipxe/ansiesc.h>
#include <ipxe/ansicol.h>
#include <usr/imgmgmt.h>

Go to the source code of this file.

Data Structures

struct  console_options
 "console" options More...
 
struct  colour_options
 "colour" options More...
 
struct  cpair_options
 "cpair" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static int console_exec (int argc, char **argv)
 "console" command More...
 
static int colour_exec (int argc, char **argv)
 "colour" command More...
 
static int cpair_exec (int argc, char **argv)
 "cpair" command More...
 
 COMMAND (console, console_exec)
 Console management commands. More...
 
 COMMAND (colour, colour_exec)
 
 COMMAND (cpair, cpair_exec)
 

Variables

static struct option_descriptor console_opts []
 "console" option list More...
 
static struct command_descriptor console_cmd
 "console" command descriptor More...
 
static struct option_descriptor colour_opts []
 "colour" option list More...
 
static struct command_descriptor colour_cmd
 "colour" command descriptor More...
 
static struct option_descriptor cpair_opts []
 "cpair" option list More...
 
static struct command_descriptor cpair_cmd
 "cpair" command descriptor More...
 

Detailed Description

Console management commands.

Definition in file console_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ console_exec()

static int console_exec ( int  argc,
char **  argv 
)
static

"console" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 87 of file console_cmd.c.

87  {
88  struct console_options opts;
89  struct image *image = NULL;
90  int rc;
91 
92  /* Parse options */
93  if ( ( rc = parse_options ( argc, argv, &console_cmd, &opts ) ) != 0 )
94  goto err_parse;
95 
96  /* Handle background picture, if applicable */
97  if ( opts.picture ) {
98 
99  /* Acquire image */
100  if ( ( rc = imgacquire ( opts.picture, 0, &image ) ) != 0 )
101  goto err_acquire;
102 
103  /* Convert to pixel buffer */
104  if ( ( rc = image_pixbuf ( image, &opts.config.pixbuf ) ) != 0){
105  printf ( "Could not use picture: %s\n",
106  strerror ( rc ) );
107  goto err_pixbuf;
108  }
109 
110  /* Apply image's width and height if none specified */
111  if ( ! opts.config.width )
112  opts.config.width = opts.config.pixbuf->width;
113  if ( ! opts.config.height )
114  opts.config.height = opts.config.pixbuf->height;
115  }
116 
117  /* Configure console */
118  if ( ( rc = console_configure ( &opts.config ) ) != 0 ) {
119  printf ( "Could not configure console: %s\n", strerror ( rc ) );
120  goto err_configure;
121  }
122 
123  /* Reapply default colour pair and clear screen */
125  printf ( CSI "2J" CSI "H" );
126 
127  err_configure:
128  pixbuf_put ( opts.config.pixbuf );
129  err_pixbuf:
130  /* Discard image unless --keep was specified */
131  if ( image && ( ! opts.keep ) )
133  err_acquire:
134  err_parse:
135  return rc;
136 }
int image_pixbuf(struct image *image, struct pixel_buffer **pixbuf)
Create pixel buffer from image.
Definition: pixbuf.c:100
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:485
An executable image.
Definition: image.h:24
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:90
#define CSI
Control Sequence Introducer.
Definition: ansiesc.h:96
"console" options
Definition: console_cmd.c:45
static struct command_descriptor console_cmd
"console" command descriptor
Definition: console_cmd.c:77
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
int console_configure(struct console_configuration *config)
Configure console.
Definition: console.c:147
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:38
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:358
static union @447 opts
"cert<xxx>" option list
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition: imgmgmt.c:143

References ansicol_set_pair(), console_cmd, console_configure(), CPAIR_DEFAULT, CSI, image_pixbuf(), imgacquire(), NULL, opts, parse_options(), printf(), rc, strerror(), and unregister_image().

◆ colour_exec()

static int colour_exec ( int  argc,
char **  argv 
)
static

"colour" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 165 of file console_cmd.c.

165  {
166  struct colour_options opts;
167  unsigned int colour;
168  int rc;
169 
170  /* Initialise options */
171  memset ( &opts, 0, sizeof ( opts ) );
172  opts.basic = COLOUR_DEFAULT;
173  opts.rgb = ANSICOL_NO_RGB;
174 
175  /* Parse options */
176  if ( ( rc = reparse_options ( argc, argv, &colour_cmd, &opts ) ) != 0 )
177  return rc;
178 
179  /* Parse colour index */
180  if ( ( rc = parse_integer ( argv[optind], &colour ) ) != 0 )
181  return rc;
182 
183  /* Define colour */
184  if ( ( rc = ansicol_define ( colour, opts.basic, opts.rgb ) ) != 0 ) {
185  printf ( "Could not define colour: %s\n", strerror ( rc ) );
186  return rc;
187  }
188 
189  /* Reapply default colour pair, in case definition has changed */
191 
192  return 0;
193 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
int optind
Current option index.
Definition: getopt.c:52
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:90
static struct command_descriptor colour_cmd
"colour" command descriptor
Definition: console_cmd.c:155
#define colour
Colour for debug messages.
Definition: acpi.c:42
int ansicol_define(unsigned int colour, unsigned int basic, uint32_t rgb)
Define ANSI colour.
Definition: ansicoldef.c:126
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition: parseopt.c:402
#define COLOUR_DEFAULT
Default colour (usually white foreground, black background)
Definition: ansicol.h:17
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define ANSICOL_NO_RGB
RGB value for "not defined".
Definition: ansicol.h:30
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:38
static union @447 opts
"cert<xxx>" option list
"colour" options
Definition: console_cmd.c:139
void * memset(void *dest, int character, size_t len) __nonnull

References ansicol_define(), ANSICOL_NO_RGB, ansicol_set_pair(), colour, colour_cmd, COLOUR_DEFAULT, CPAIR_DEFAULT, memset(), optind, opts, parse_integer(), printf(), rc, reparse_options(), and strerror().

◆ cpair_exec()

static int cpair_exec ( int  argc,
char **  argv 
)
static

"cpair" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 222 of file console_cmd.c.

222  {
223  struct cpair_options opts;
224  unsigned int cpair;
225  int rc;
226 
227  /* Initialise options */
228  memset ( &opts, 0, sizeof ( opts ) );
229  opts.foreground = COLOUR_DEFAULT;
230  opts.background = COLOUR_DEFAULT;
231 
232  /* Parse options */
233  if ( ( rc = reparse_options ( argc, argv, &cpair_cmd, &opts ) ) != 0 )
234  return rc;
235 
236  /* Parse colour pair index */
237  if ( ( rc = parse_integer ( argv[optind], &cpair ) ) != 0 )
238  return rc;
239 
240  /* Define colour pair */
241  if ( ( rc = ansicol_define_pair ( cpair, opts.foreground,
242  opts.background ) ) != 0 ) {
243  printf ( "Could not define colour pair: %s\n",
244  strerror ( rc ) );
245  return rc;
246  }
247 
248  /* Reapply default colour pair, in case definition has changed */
250 
251  return 0;
252 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
int optind
Current option index.
Definition: getopt.c:52
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition: ansicol.c:90
int ansicol_define_pair(unsigned int cpair, unsigned int foreground, unsigned int background)
Define ANSI colour pair.
Definition: ansicol.c:111
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition: parseopt.c:402
#define COLOUR_DEFAULT
Default colour (usually white foreground, black background)
Definition: ansicol.h:17
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:38
static union @447 opts
"cert<xxx>" option list
static struct command_descriptor cpair_cmd
"cpair" command descriptor
Definition: console_cmd.c:212
"cpair" options
Definition: console_cmd.c:196
void * memset(void *dest, int character, size_t len) __nonnull

References ansicol_define_pair(), ansicol_set_pair(), COLOUR_DEFAULT, cpair_cmd, CPAIR_DEFAULT, memset(), optind, opts, parse_integer(), printf(), rc, reparse_options(), and strerror().

◆ COMMAND() [1/3]

COMMAND ( console  ,
console_exec   
)

Console management commands.

◆ COMMAND() [2/3]

COMMAND ( colour  ,
colour_exec   
)

◆ COMMAND() [3/3]

COMMAND ( cpair  ,
cpair_exec   
)

Variable Documentation

◆ console_opts

struct option_descriptor console_opts[]
static
Initial value:
= {
struct console_options, config.width, parse_integer ),
struct console_options, config.height, parse_integer ),
struct console_options, config.left, parse_integer ),
OPTION_DESC ( "right", 'r', required_argument,
struct console_options, config.right, parse_integer ),
struct console_options, config.top, parse_integer ),
OPTION_DESC ( "bottom", 'b', required_argument,
struct console_options, config.bottom, parse_integer ),
OPTION_DESC ( "depth", 'd', required_argument,
struct console_options, config.depth, parse_integer ),
OPTION_DESC ( "picture", 'p', required_argument,
struct console_options, picture, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument,
struct console_options, keep, parse_flag ),
}
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
"console" options
Definition: console_cmd.c:45
int parse_string(char *text, char **value)
Parse string value.
Definition: parseopt.c:74
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:227
Option does not take an argument.
Definition: getopt.h:17
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:68
Option requires an argument.
Definition: getopt.h:19

"console" option list

Definition at line 55 of file console_cmd.c.

◆ console_cmd

struct command_descriptor console_cmd
static
Initial value:
=
static struct option_descriptor console_opts[]
"console" option list
Definition: console_cmd.c:55
"console" options
Definition: console_cmd.c:45
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

"console" command descriptor

Definition at line 77 of file console_cmd.c.

Referenced by console_exec().

◆ colour_opts

struct option_descriptor colour_opts[]
static
Initial value:
= {
OPTION_DESC ( "basic", 'b', required_argument,
struct colour_options, basic, parse_integer ),
struct colour_options, rgb, parse_integer ),
}
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:68
Option requires an argument.
Definition: getopt.h:19
"colour" options
Definition: console_cmd.c:139

"colour" option list

Definition at line 147 of file console_cmd.c.

◆ colour_cmd

struct command_descriptor colour_cmd
static
Initial value:
=
COMMAND_DESC ( struct colour_options, colour_opts, 1, 1, "<colour>" )
static struct option_descriptor colour_opts[]
"colour" option list
Definition: console_cmd.c:147
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109
"colour" options
Definition: console_cmd.c:139

"colour" command descriptor

Definition at line 155 of file console_cmd.c.

Referenced by colour_exec().

◆ cpair_opts

struct option_descriptor cpair_opts[]
static
Initial value:
= {
OPTION_DESC ( "foreground", 'f', required_argument,
OPTION_DESC ( "background", 'b', required_argument,
}
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
unsigned int background
Background colour.
Definition: console_cmd.c:200
unsigned int foreground
Foreground colour.
Definition: console_cmd.c:198
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:68
Option requires an argument.
Definition: getopt.h:19
"cpair" options
Definition: console_cmd.c:196

"cpair" option list

Definition at line 204 of file console_cmd.c.

◆ cpair_cmd

struct command_descriptor cpair_cmd
static
Initial value:
=
COMMAND_DESC ( struct cpair_options, cpair_opts, 1, 1, "<cpair>" )
static struct option_descriptor cpair_opts[]
"cpair" option list
Definition: console_cmd.c:204
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109
"cpair" options
Definition: console_cmd.c:196

"cpair" command descriptor

Definition at line 212 of file console_cmd.c.

Referenced by cpair_exec().