home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / PRINT / PRINTING.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-07  |  4.3 KB  |  232 lines

  1. /* ==(bench/printing.c)== */
  2.  
  3. /* ----------------------------------------------- */
  4. /* Pro-C - Copyright (C) 1988, 1989 Vestronix Inc. */
  5. /* Modification to this source is not supported    */
  6. /* by Vestronix Inc.                               */
  7. /*            All Rights Reserved                  */
  8. /* ----------------------------------------------- */
  9. #include <stdio.h>
  10. #include <bench.h>
  11. #include <field.h>
  12.  
  13. char TopOfFile[] = "Top Of File!";
  14. char EndOfFile[] = "End Of File!";
  15. char OutFile[]   = " Output file ";
  16. char ScrolldPrompt[] = "Scroll Down";
  17. char ScrolluPrompt[] = "Scroll Up";
  18. char ScanningMsg[] = "Scanning Report\nPlease Wait..";
  19.  
  20. static PROTO (void display_page, (int));
  21. static PROTO (void text_disp, (int, int, int, char *));
  22. PROTO (void get_rpt_file, (char *));
  23.  
  24. long cur_line;
  25. long num_lines;
  26. FILE *Fp;
  27. long *line_idx;
  28.  
  29. void display_report(fname, rwidth)
  30. char *fname;
  31. int rwidth;
  32. {
  33.     int cc;
  34.     char lbuf[512 + 1];
  35.     int coloff = 0;
  36. #ifdef MOUSE
  37.     int dummy;
  38. #endif
  39.     cur_line = 0l;
  40.  
  41.     create_w(1, 1, w_nrows, w_ncols);
  42.  
  43.     keys_w(K_F1, help_prompt, K_PGDN, ScrolldPrompt, K_PGUP, ScrolluPrompt, K_ESC, exit_prompt, 0);
  44.  
  45. # ifdef ANSI
  46.     Fp = fopen(fname, "rb");
  47. # else
  48.     Fp = fopen(fname, "r");
  49. # endif
  50.     num_lines = 0;
  51.  
  52.     statmsg(ScanningMsg);
  53.  
  54.     for(num_lines = 0;; num_lines++)
  55.         if (fgets(lbuf, 512, Fp) == NULL)
  56.             break;
  57.  
  58.     line_idx = (long *)alloc(num_lines * sizeof(long));
  59.     
  60.     fseek(Fp, 0L, SEEK_SET);
  61.     for(cc = 0; cc < num_lines; cc++)
  62.     {
  63.         line_idx[cc] = ftell(Fp);
  64.         fgets(lbuf, 512, Fp);
  65.     }
  66.  
  67.     do
  68.     {
  69.         if (cur_line > num_lines - (w_nrows - 1))
  70.             cur_line = num_lines - (w_nrows - 1);
  71.         if (cur_line < 0)
  72.             cur_line = 0;
  73.         if (coloff > rwidth - w_ncols)
  74.             coloff = rwidth - w_ncols;
  75.         if (coloff < 0)
  76.             coloff = 0;
  77.  
  78.         display_page(coloff);
  79.  
  80.         cc = inchar();
  81.         switch(cc)
  82.         {
  83. #ifdef MOUSE
  84.             case M_PRESS:
  85.             case M_RELEASE:
  86.                 mouse_click(&dummy, cc);
  87.                 break;
  88. #endif
  89.             case K_F1:
  90.                 help_msg(12);
  91.                 break;
  92.             case K_UP:
  93.                 if (cur_line == 0)
  94.                     errmsg(TopOfFile);
  95.                 else
  96.                     cur_line--;
  97.                 break;
  98.             case K_DOWN:
  99.                 if (cur_line == num_lines - (w_nrows - 1))
  100.                     errmsg(EndOfFile);
  101.                 else
  102.                     cur_line++;
  103.                 break;
  104.             case K_BTAB:
  105.                 coloff -= 3;
  106.                 break;
  107.             case K_LEFT:
  108.                 coloff--;
  109.                 break;
  110.             case K_TAB:
  111.                 coloff += 3;
  112.                 break;
  113.             case K_RIGHT:
  114.                 coloff++;
  115.                 break;
  116.             case K_PGUP:
  117.                 if (cur_line == 0)
  118.                     errmsg(TopOfFile);
  119.                 else
  120.                     cur_line -= (w_nrows - 4);
  121.                 break;
  122.             case K_PGDN:
  123.                 if (cur_line == num_lines - (w_nrows - 1))
  124.                     errmsg(EndOfFile);
  125.                 else
  126.                     cur_line += (w_nrows - 4);
  127.                 break;
  128.             case K_HOME:
  129.                 cur_line = 0;
  130.                 coloff = 0;
  131.                 break;
  132.             case K_END:
  133.                 cur_line = num_lines - (w_nrows - 1);
  134.                 coloff = 0;
  135.                 break;
  136.         }
  137.     } while (cc != K_ESC);
  138.  
  139.     fclose(Fp);
  140.     delete_w();
  141. }
  142.  
  143. static void display_page(coloff)
  144. int coloff;
  145. {
  146.     register int i;
  147.     char lbuf[512];
  148.  
  149.     fseek(Fp, line_idx[cur_line], SEEK_SET);
  150.     for(i = 0; i < w_nrows - 1; i++)
  151.     {
  152.         memset(lbuf, '\0', 512);
  153.         if (fgets(lbuf, 512, Fp) == NULL)
  154.             break;
  155.         text_disp(i + 1, 1, coloff, lbuf);
  156.     }
  157. }
  158.  
  159. static void text_disp(row, col, coloff, bufp)
  160. int row, col, coloff;
  161. char *bufp;
  162. {
  163.     register int i = 0;
  164.     int c = 0;
  165.     int attr = 1;
  166.  
  167.     while(c < coloff)
  168.     {
  169.         switch(bufp[i++])
  170.         {
  171.             case '\t':
  172.                 while(++c%3)
  173.                     ;
  174.                 break;
  175.             case '\033':
  176.                 attr = bufp[i++] - '@';
  177.                 break;
  178.             default:
  179.                 ++c;
  180.                 break;
  181.         }
  182.     }
  183.  
  184.     do
  185.     {
  186.         switch(bufp[i])
  187.         {
  188.             case '\t':
  189.                 do
  190.                 {
  191.                     poke_w(row, col + c - coloff, attr, ' ');
  192.                 } while(++c%3);
  193.                 break;
  194.             case '\033':
  195.                 attr = bufp[++i] - '@';
  196.                 break;
  197.             case '\r':
  198.             case '\n':
  199.                 break;
  200.             default:
  201.                 poke_w(row, col + c - coloff, attr, bufp[i] ? bufp[i] : ' ');
  202.                 c++;
  203.                 break;
  204.         }
  205.         i++;
  206.     } while (c - coloff < w_ncols);
  207. }
  208.  
  209. char rfile_mask[] = "Cccccccc";
  210.  
  211. FIELD rfile = 
  212. {
  213.    2, 7, 3, NULL, rfile_mask,
  214.    13, 8, F_TEXT, REVVID, REVVID, CONFIRM_NEEDED | NO_BLANK,
  215.    NULL, text_input, NULL, NULL
  216. };
  217.  
  218. void get_rpt_file(filename)
  219. char *filename;
  220. {
  221.     char tmp[20];
  222.     create_w( 9, 30, 3, 20 );
  223.     border_w( 0, BOLD );
  224.     center_w(1, 1, BOLD, 20, OutFile);
  225.     rfile.fbuff = tmp;
  226.     strcpy( rfile.fbuff, filename );
  227.     input_wx(&rfile, K_ESC, K_DOWN, 0);
  228.     strncpy( filename, rfile.fbuff, 8 );
  229.     delete_w();
  230. }
  231.  
  232.