home *** CD-ROM | disk | FTP | other *** search
- /* ==(bench/printing.c)== */
-
- /* ----------------------------------------------- */
- /* Pro-C - Copyright (C) 1988, 1989 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- #include <stdio.h>
- #include <bench.h>
- #include <field.h>
-
- char TopOfFile[] = "Top Of File!";
- char EndOfFile[] = "End Of File!";
- char OutFile[] = " Output file ";
- char ScrolldPrompt[] = "Scroll Down";
- char ScrolluPrompt[] = "Scroll Up";
- char ScanningMsg[] = "Scanning Report\nPlease Wait..";
-
- static PROTO (void display_page, (int));
- static PROTO (void text_disp, (int, int, int, char *));
- PROTO (void get_rpt_file, (char *));
-
- long cur_line;
- long num_lines;
- FILE *Fp;
- long *line_idx;
-
- void display_report(fname, rwidth)
- char *fname;
- int rwidth;
- {
- int cc;
- char lbuf[512 + 1];
- int coloff = 0;
- #ifdef MOUSE
- int dummy;
- #endif
- cur_line = 0l;
-
- create_w(1, 1, w_nrows, w_ncols);
-
- keys_w(K_F1, help_prompt, K_PGDN, ScrolldPrompt, K_PGUP, ScrolluPrompt, K_ESC, exit_prompt, 0);
-
- # ifdef ANSI
- Fp = fopen(fname, "rb");
- # else
- Fp = fopen(fname, "r");
- # endif
- num_lines = 0;
-
- statmsg(ScanningMsg);
-
- for(num_lines = 0;; num_lines++)
- if (fgets(lbuf, 512, Fp) == NULL)
- break;
-
- line_idx = (long *)alloc(num_lines * sizeof(long));
-
- fseek(Fp, 0L, SEEK_SET);
- for(cc = 0; cc < num_lines; cc++)
- {
- line_idx[cc] = ftell(Fp);
- fgets(lbuf, 512, Fp);
- }
-
- do
- {
- if (cur_line > num_lines - (w_nrows - 1))
- cur_line = num_lines - (w_nrows - 1);
- if (cur_line < 0)
- cur_line = 0;
- if (coloff > rwidth - w_ncols)
- coloff = rwidth - w_ncols;
- if (coloff < 0)
- coloff = 0;
-
- display_page(coloff);
-
- cc = inchar();
- switch(cc)
- {
- #ifdef MOUSE
- case M_PRESS:
- case M_RELEASE:
- mouse_click(&dummy, cc);
- break;
- #endif
- case K_F1:
- help_msg(12);
- break;
- case K_UP:
- if (cur_line == 0)
- errmsg(TopOfFile);
- else
- cur_line--;
- break;
- case K_DOWN:
- if (cur_line == num_lines - (w_nrows - 1))
- errmsg(EndOfFile);
- else
- cur_line++;
- break;
- case K_BTAB:
- coloff -= 3;
- break;
- case K_LEFT:
- coloff--;
- break;
- case K_TAB:
- coloff += 3;
- break;
- case K_RIGHT:
- coloff++;
- break;
- case K_PGUP:
- if (cur_line == 0)
- errmsg(TopOfFile);
- else
- cur_line -= (w_nrows - 4);
- break;
- case K_PGDN:
- if (cur_line == num_lines - (w_nrows - 1))
- errmsg(EndOfFile);
- else
- cur_line += (w_nrows - 4);
- break;
- case K_HOME:
- cur_line = 0;
- coloff = 0;
- break;
- case K_END:
- cur_line = num_lines - (w_nrows - 1);
- coloff = 0;
- break;
- }
- } while (cc != K_ESC);
-
- fclose(Fp);
- delete_w();
- }
-
- static void display_page(coloff)
- int coloff;
- {
- register int i;
- char lbuf[512];
-
- fseek(Fp, line_idx[cur_line], SEEK_SET);
- for(i = 0; i < w_nrows - 1; i++)
- {
- memset(lbuf, '\0', 512);
- if (fgets(lbuf, 512, Fp) == NULL)
- break;
- text_disp(i + 1, 1, coloff, lbuf);
- }
- }
-
- static void text_disp(row, col, coloff, bufp)
- int row, col, coloff;
- char *bufp;
- {
- register int i = 0;
- int c = 0;
- int attr = 1;
-
- while(c < coloff)
- {
- switch(bufp[i++])
- {
- case '\t':
- while(++c%3)
- ;
- break;
- case '\033':
- attr = bufp[i++] - '@';
- break;
- default:
- ++c;
- break;
- }
- }
-
- do
- {
- switch(bufp[i])
- {
- case '\t':
- do
- {
- poke_w(row, col + c - coloff, attr, ' ');
- } while(++c%3);
- break;
- case '\033':
- attr = bufp[++i] - '@';
- break;
- case '\r':
- case '\n':
- break;
- default:
- poke_w(row, col + c - coloff, attr, bufp[i] ? bufp[i] : ' ');
- c++;
- break;
- }
- i++;
- } while (c - coloff < w_ncols);
- }
-
- char rfile_mask[] = "Cccccccc";
-
- FIELD rfile =
- {
- 2, 7, 3, NULL, rfile_mask,
- 13, 8, F_TEXT, REVVID, REVVID, CONFIRM_NEEDED | NO_BLANK,
- NULL, text_input, NULL, NULL
- };
-
- void get_rpt_file(filename)
- char *filename;
- {
- char tmp[20];
- create_w( 9, 30, 3, 20 );
- border_w( 0, BOLD );
- center_w(1, 1, BOLD, 20, OutFile);
- rfile.fbuff = tmp;
- strcpy( rfile.fbuff, filename );
- input_wx(&rfile, K_ESC, K_DOWN, 0);
- strncpy( filename, rfile.fbuff, 8 );
- delete_w();
- }
-
-