diff options
Diffstat (limited to 'demo/pager.erl')
-rw-r--r-- | demo/pager.erl | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/demo/pager.erl b/demo/pager.erl index 37f6a14..527d16c 100644 --- a/demo/pager.erl +++ b/demo/pager.erl @@ -1,7 +1,7 @@ %%%---------------------------------------------------------------------- %%% File : pager.erl %%% Author : Claes Wikstrom <klacke@kaja.hemma.net> -%%% Purpose : +%%% Purpose : %%% Created : 1 Dec 2000 by Claes Wikstrom <klacke@kaja.hemma.net> %%%---------------------------------------------------------------------- @@ -24,7 +24,7 @@ demolib_exit (Signal) -> slang:reset_tty (), slang:smg_reset_smg (), - + if Signal == 0 -> halt(); @@ -50,10 +50,10 @@ sigint_handler (Signal) -> % } exit_error_hook (Fmt, Args) -> - + slang:reset_tty (), slang:reset_smg (), - + io:format(Fmt, Args), io:nl(), halt(). @@ -62,27 +62,27 @@ exit_error_hook (Fmt, Args) -> demolib_init_terminal () -> - + %% SLang_Exit_Error_Hook = exit_error_hook - % It is wise to block the occurance of display related - %signals while we are - %initializing. + % It is wise to block the occurance of display related + %signals while we are + %initializing. %SLsig_block_signals (), - + slang:tt_get_terminfo (), - - %% SLkp_init assumes that SLtt_get_terminfo has been called. - + + %% SLkp_init assumes that SLtt_get_terminfo has been called. + case slang:kp_init() of -1 -> -1; Ret -> - + slang:init_tty (-1, 0, 1), %slang:tty_set_suspend_state (1), - + case slang:smg_init_smg () of -1 -> -1; @@ -94,12 +94,12 @@ demolib_init_terminal () -> main() -> File="tmp/test", - + int main (int argc, char **argv) -{ +{ if (argc == 2) { File_Name = argv[1]; @@ -107,36 +107,36 @@ int main (int argc, char **argv) else if ((argc != 1) || (1 == isatty (fileno(stdin)))) usage (argv[0]); - + if (-1 == read_file (File_Name)) { fprintf (stderr, "Unable to read %s\n", File_Name); return 1; } - + /* This sets up the terminal, signals, screen management routines, etc... */ if (-1 == demolib_init_terminal (1, 1)) { fprintf (stderr, "Unable to initialize terminal."); return 1; } - + #define APP_KEY_EOB 0x1001 #define APP_KEY_BOB 0x1002 - - /* Add a few application defined keysyms. 0x1000 and above are for + + /* Add a few application defined keysyms. 0x1000 and above are for * applications. */ (void) SLkp_define_keysym ("\033>", APP_KEY_EOB); (void) SLkp_define_keysym ("\033<", APP_KEY_BOB); - + main_loop (); /* should not return */ return 1; } - + /* The SLscroll routines will be used for pageup/down commands. They assume - * a linked list of lines. The first element of the structure MUST point to + * a linked list of lines. The first element of the structure MUST point to * the NEXT line, the second MUST point to the PREVIOUS line. */ typedef struct _File_Line_Type @@ -155,7 +155,7 @@ static SLscroll_Window_Type Line_Window; static void free_lines (void) { File_Line_Type *line, *next; - + line = File_Lines; while (line != NULL) { @@ -170,19 +170,19 @@ static void free_lines (void) static File_Line_Type *create_line (char *buf) { File_Line_Type *line; - + line = (File_Line_Type *) malloc (sizeof (File_Line_Type)); if (line == NULL) return NULL; - + memset ((char *) line, sizeof (File_Line_Type), 0); - + line->data = SLmake_string (buf); /* use a slang routine */ if (line->data == NULL) { free (line); return NULL; } - + return line; } @@ -193,45 +193,45 @@ static int read_file (char *file) char buf [1024]; File_Line_Type *line, *last_line; unsigned int num_lines; - - if (file == NULL) + + if (file == NULL) fp = stdin; else fp = fopen (file, "r"); - + if (fp == NULL) return -1; - + last_line = NULL; num_lines = 0; - + while (NULL != fgets (buf, sizeof(buf), fp)) { num_lines++; - + if (NULL == (line = create_line (buf))) { fprintf (stderr, "Out of memory."); free_lines (); return -1; } - + if (last_line == NULL) File_Lines = line; - else + else last_line->next = line; - + line->prev = last_line; line->next = NULL; - + last_line = line; } - + memset ((char *)&Line_Window, 0, sizeof (SLscroll_Window_Type)); - + Line_Window.current_line = (SLscroll_Type *) File_Lines; Line_Window.lines = (SLscroll_Type *) File_Lines; Line_Window.line_num = 1; Line_Window.num_lines = num_lines; - + return 0; } @@ -245,7 +245,7 @@ static void update_display (void) * the display while performing screen update. */ SLsig_block_signals (); - + Line_Window.nrows = nrows = SLtt_Screen_Rows - 1; /* Always make the current line equal to the top window line. */ @@ -253,17 +253,17 @@ static void update_display (void) Line_Window.current_line = Line_Window.top_window_line; SLscroll_find_top (&Line_Window); - + row = 0; line = (File_Line_Type *) Line_Window.top_window_line; - + SLsmg_normal_video (); - + while (row < Line_Window.nrows) { SLsmg_gotorc (row, 0); - - if (line != NULL) + + if (line != NULL) { SLsmg_write_string (line->data); line = line->next; @@ -271,13 +271,13 @@ static void update_display (void) SLsmg_erase_eol (); row++; } - + SLsmg_gotorc (row, 0); SLsmg_reverse_video (); SLsmg_printf ("%s", (File_Name == NULL) ? "<stdin>" : File_Name); SLsmg_erase_eol (); SLsmg_refresh (); - + SLsig_unblock_signals (); } @@ -297,13 +297,13 @@ static void main_loop (void) case 'Q': demolib_exit (0); break; - + case SL_KEY_RIGHT: Screen_Start += 1; screen_start = Screen_Start; SLsmg_set_screen_start (NULL, &screen_start); break; - + case SL_KEY_LEFT: Screen_Start -= 1; if (Screen_Start < 0) Screen_Start = 0; @@ -315,13 +315,13 @@ static void main_loop (void) SLscroll_prev_n (&Line_Window, 1); Line_Window.top_window_line = Line_Window.current_line; break; - + case '\r': case SL_KEY_DOWN: SLscroll_next_n (&Line_Window, 1); Line_Window.top_window_line = Line_Window.current_line; break; - + case SL_KEY_NPAGE: case ' ': case 4: SLscroll_pagedown (&Line_Window); @@ -336,12 +336,12 @@ static void main_loop (void) while (-1 != SLscroll_pageup (&Line_Window)) ; break; - + case APP_KEY_EOB: while (-1 != SLscroll_pagedown (&Line_Window)) ; break; - + default: SLtt_beep (); } |