File: syslinux.c

package info (click to toggle)
evms 1.0.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,168 kB
  • ctags: 5,853
  • sloc: ansic: 87,317; makefile: 691; sh: 238
file content (366 lines) | stat: -rw-r--r-- 9,986 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*----------------------------------------------------------------------
 *
 *   Copyright (c) International Business Machines  Corp., 2001
 *
 *   This program is free software;  you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program;  if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Module: syslinux.c
 *---------------------------------------------------------------------*/

/*----------------------------------------------------------------------
 * Change History:
 *
 * 9/2001  John Stiles   Initial version.
 *
 *---------------------------------------------------------------------*/


/* Identify this file. */
#define SYSLINUX_C   1

/*----------------------------------------------------------------------
 * Necessary include files
 *---------------------------------------------------------------------*/
#include <stdlib.h>        /* malloc, free */
#include <string.h>        /* strcat, strcpy */
#include <curses.h>        /* For terminal interactive operation  */

#include "evmsn.h"


/*----------------------------------------------------------------------
 * Global Variables
 *---------------------------------------------------------------------*/


/*----------------------------------------------------------------------
 * There are No Private Constants
 * There are No Private Type Definitions
 * There are No Private Global Variables.
 *---------------------------------------------------------------------*/


/*----------------------------------------------------------------------
 * Public Functions
 *---------------------------------------------------------------------*/


/*----------------------------------------------------------------------
 *
 *   Function Name:  kb_video_setup
 *
 *   Descriptive Name:  Sets up the ncurses environment.
 *
 *   Input:  no inputs
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  ncurses environment is set up - to return to
 *                   normal command mode, the equivalent terminate
 *                   function must be called.
 *
 *   Notes:  only call once when starting program.
 *
 *---------------------------------------------------------------------*/
void kb_video_setup( void )
{
  (void) initscr();                 /* initialize curses                   */
  (void) flushinp();                /* flush the input buffer              */
  (void) keypad( stdscr, TRUE );    /* return extra keys as int values     */
/* void) cbreak();                   * Take input one char at a time       */
  (void) nonl();                    /* don't do CR/LF on output            */
  (void) noecho();                  /* stop echoing input to screen        */

  // Check for mono or color screen...
  if( !has_colors() )
    GL_use_color = 0;               /* no colors                           */
  else {
    GL_use_color = 1;               /* display colors                      */
    start_color();                  /* set up color environment            */
    init_pair( COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK );
    init_pair( COLOR_TITLE, COLOR_YELLOW, COLOR_BLACK );
    init_pair( COLOR_BAR, COLOR_BLACK, COLOR_CYAN );
    init_pair( COLOR_FKEYS, COLOR_WHITE, COLOR_BLUE );
    attron( COLOR_PAIR( COLOR_DEFAULT ) );
  }

}


/*----------------------------------------------------------------------
 *
 *   Function Name:  update_screen_info
 *
 *   Descriptive Name:  Check if screen size changed.
 *
 *   Input:  no inputs
 *
 *   Output:  0 == nothing changed, !0 == changed screen dimensions
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  screen size Globals may be changed.
 *
 *   Notes:
 *
 *---------------------------------------------------------------------*/
int update_screen_info( void )
{
  int  rc = 0;

  if( GL_screen_lines != LINES ) {
      GL_screen_lines  = LINES;
      rc++;                          /* set changed indicator           */
  }

  if( GL_screen_cols != COLS ) {
      GL_screen_cols  = COLS;
      rc++;                          /* set changed indicator           */
  }

  return( rc );
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  signal_user
 *
 *   Descriptive Name:  send an audible signal ( beep ).
 *
 *   Input:  no inputs
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  user jumps upon hearing beep.
 *
 *   Notes:
 *
 *---------------------------------------------------------------------*/
void signal_user( void )
{
  (void) beep();
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  clear_screen
 *
 *   Descriptive Name:  clear the display.
 *
 *   Input:  no inputs
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  all displayed data is lost.
 *
 *   Notes:
 *
 *---------------------------------------------------------------------*/
void clear_screen( void )
{
  (void) clear();
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  print_string
 *
 *   Descriptive Name:  print a character string on the screen.
 *
 *   Input:  no inputs
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  string appears on screen.
 *
 *   Notes:
 *
 *---------------------------------------------------------------------*/
void print_string( int x, int y, int color, char * charstring )
{
  NCURSES_ATTR_T attr = COLOR_PAIR( color );
  int size;

  if ( GL_use_color )
    attron( attr );
  else if ( color == COLOR_BAR )
    attron( A_REVERSE );

  if ( x < GL_screen_cols && y < GL_screen_lines ) {
    size = strlen( charstring );
    if ( x + size >= GL_screen_cols )
      size = GL_screen_cols - x;

    mvaddnstr( y, x, charstring, size );
    if ( !GL_use_color && color == COLOR_BAR )
      attroff( A_REVERSE );
    
    /*
     * Flush output now
     */
    refresh ();
  }
  else {
    log_error( "%s: string %s is off the screen:  x == %i (max == %i), y == %i (max == %i).\n", __FUNCTION__, charstring, x, GL_screen_cols, y, GL_screen_lines );
  }
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  move_cursor
 *
 *   Descriptive Name:  move the cursor to a place on the screen.
 *
 *   Input:  no inputs
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  cursor appears on screen.
 *
 *   Notes:
 *
 *---------------------------------------------------------------------*/
void move_cursor( int x, int y )
{
  move( y, x );
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  get_inputc
 *
 *   Descriptive Name:  get a single input character from the keyboard.
 *
 *   Input:  no inputs
 *
 *   Output:  one key character.
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  none
 *
 *   Notes:
 *
 *---------------------------------------------------------------------*/
int get_inputc( void )
{
  (void) flushinp();                /* flush the input buffer              */
  return  getch();
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  kb_video_shutdown
 *
 *   Descriptive Name:  Shuts down the ncurses environment.
 *
 *   Input:  no inputs
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  ncurses environment is terminated.
 *
 *   Notes:  only call once when ending program.
 *
 *---------------------------------------------------------------------*/
void kb_video_shutdown( void )
{
  endwin();           /* shut down curses                    */
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  drawhline, drawvline
 *
 *   Descriptive Name:  Draws horizontal or vertical lines on screen.
 *
 *   Input:  x and y start coordinates, length of line
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  line drawn on screen.
 *
 *   Notes:  need to make insure it does NOT run off the screen.
 *
 *---------------------------------------------------------------------*/
void drawhline( int x, int y, int count )
{
  mvhline( y, x, ACS_HLINE, count );
}


void drawvline( int x, int y, int count )
{
  mvvline( y, x, ACS_VLINE, count );
}


/*----------------------------------------------------------------------
 *
 *   Function Name:  drawbleft, drawbright
 *
 *   Descriptive Name:  Draws left or right side of box on screen.
 *
 *   Input:  x and y start coordinates, height of box
 *
 *   Output:  nothing returned
 *
 *   Error Handling:  none needed
 *
 *   Side Effects:  line drawn on screen.
 *
 *   Notes:  the box left/right is essentially a vertical line w/ corners.
 *           need to make insure it does NOT run off the screen.
 *
 *---------------------------------------------------------------------*/
void drawbleft( int x, int y, int count )
{
  if ( count > 2 ) {
    mvvline( y, x, ACS_ULCORNER, 1 );
    mvvline( y + 1, x, ACS_VLINE, count - 2 );
    mvvline( y + count - 1, x, ACS_LLCORNER, 1 );
  }
}


void drawbright( int x, int y, int count )
{
  if ( count > 2 ) {
    mvvline( y, x, ACS_URCORNER, 1 );
    mvvline( y + 1, x, ACS_VLINE, count - 2 );
    mvvline( y + count - 1, x, ACS_LRCORNER, 1 );
  }
}