home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 214_01 / typer_r.c < prev    next >
Text File  |  1979-12-31  |  9KB  |  360 lines

  1. /* TYPER-R.C  VERS:- 01.00  DATE:- 09/26/86  TIME:- 09:37:23 PM*/
  2. /*
  3. %CC1 $1.C -X 
  4. %CLINK $1 -S
  5. %DELETE $1.CRL 
  6. */
  7. /* 
  8. Description:
  9.  
  10. Line editor that handles typing not suitable for a word processor, 
  11. eg, filling out forms, envelopes, short notes, etc.
  12.  
  13. The program offers control of full two-dimensional movement of the 
  14. printhead, for printers with reverse line feed.  It is set
  15. for Diablo conventions.
  16.  
  17. Based upon TYPER, by H. G. Lord.
  18.  
  19. By J.A. Rupley, Tucson, Arizona
  20. Coded for BDS C compiler, version 1.50a
  21. */
  22. /*
  23. Usage:    TYPER         <== prints instructions, output goes to LST:
  24.         TYPER PRINTER     <== no instructions, output to LST:
  25.         TYPER d:file.typ <== no instructions, output to disk file
  26. Commands:
  27.          ^H        = Destructive backspace
  28.         ^U         = Cancel current line
  29.         ^P        = Display prompts
  30.          ^R        = Clear screen
  31.         <cr>, ^J, or ^M = Send line to device or file
  32.         ^Z        = End of session
  33.         ^C        = Abort session
  34. Use wstar commands (^s,^d,^e,^x,tab) for immediate printhead movement,
  35.     after flush of buffer contents.
  36.  */
  37.  
  38.     /* page eject */
  39.  
  40.  
  41. #define EOF        -1
  42. #define NULL        '\0'
  43. #define EOS        NULL
  44. #define TRUE        1
  45. #define TAB        5    /* If you change TAB, change the ruler, too*/
  46. #define SPACE        0x20
  47. #define CTRLC        0x03
  48. #define CTRLD        0x04
  49. #define CTRLE        0x05
  50. #define CTRLH        0x08
  51. #define CTRLI        0x09
  52. #define CTRLJ        0x0A
  53. #define CTRLL        0x0C
  54. #define CTRLM        0x0D
  55. #define CTRLP        0x10
  56. #define CTRLR        0x12
  57. #define CTRLS        0x13
  58. #define CTRLU        0x15
  59. #define CTRLX        0x18
  60. #define ESC        0x1B
  61. #define DEL        0x7F
  62.  
  63. #define SCREEN_WIDTH    79        /*Televideo 920c dependent*/
  64. #define SCREEN_HEIGHT    23        /*Televideo 920c dependent*/
  65.  
  66. /*Televideo 920c dependent statments*/
  67. #define CLS        putchar('Z' - 0x40);
  68. #define HOME        putchar('^' - 0x40);
  69. #define DEL_LINE    {putchar(ESC); putchar('T');}
  70. #define INSERT_LINE    {putchar(ESC); putchar('E');}
  71.  
  72. /*Transtar dependent statements*/
  73. #define REV_LINE_FEED    {putc(ESC, fdes); putc('\n', fdes);}
  74.  
  75. #include <bdscio.h>
  76.  
  77. char line_buf[MAXLINE];
  78.  
  79. int i, vert, m;
  80.  
  81. main(argc, argv)
  82. int argc;
  83. char *argv[];
  84. {
  85.     char *fdes;        /* File descriptor*/
  86.     char obuf[MAXLINE];        /* IO buffer*/
  87.     if (argc != 2)        /* No arguments*/
  88.     {
  89.         CLS;
  90.         disp_instructions();        /* Display explanations*/
  91.         getchar();
  92.         CLS;
  93.         disp_message();
  94.         getchar();
  95.         fdes = 2;
  96.     }
  97.  
  98.     /* If argument is "PRINT", then send buffer to LST:*/
  99.     if (strcmp(argv[1], "PRINTER") == NULL)
  100.         fdes = 2;
  101.     else
  102.         if (fdes != 2)
  103.         {
  104.             file(argv[1], obuf);        /* Open file for writing*/
  105.             fdes = obuf;
  106.         }
  107.  
  108.     CLS;
  109.     /* Get stuff on screen and send it to the file or LST:*/
  110.     typer(fdes);
  111.     If(fdes != 2) putc(CPMEOF, fdes);
  112.  
  113.     CLS;
  114.     if (fclose(fdes) == ERROR)        /* Close file*/
  115.         printf("\n\nerror in closing file\n\n");
  116. }
  117.  
  118. int file(fname, iobuf)        /* Open output file in write mode*/
  119. char *fname;
  120. char *iobuf;
  121. {
  122.     int ii;
  123.     ii = fcreat(fname, iobuf);        /* Open the file*/
  124.     if (ii > 0)
  125.         return ii;        /* Return channel number*/
  126.     /* If no channel #, display an error message*/
  127.     puts("\nSorry, I can\'t open the file.\n\n");
  128.     exit();
  129. }
  130. /* End of fileout*/
  131.  
  132. void typer(fdes)
  133. char *fdes;
  134. {
  135.     /* i is the line_buffer subscript*/
  136.     /* m is the screen image cursor horizontal position*/
  137.     /* vert is the screen image cursor vertical position*/
  138.  
  139.     int c;
  140.     int j;
  141.  
  142.     i = m = NULL;        /* Reset character counter*/
  143.     vert = 1;        /* Begin at line 1, not line 0*/
  144.     ruler();        /*to allow display of ruler*/
  145.  
  146.     /* Get and process characters one at a time*/
  147.     while ((c = getchar()) != EOF && c != CPMEOF)
  148.     {
  149.         if (c >= SPACE && c < DEL)        /* Displayable ASCII char*/
  150.         {
  151.             line_buf[i++] = c;        /* Char into buffer*/
  152.             /* If cursor on screen, continue getting input*/
  153.             /* If cursor off screen, send backspace*/
  154.             /* to delete the last character*/
  155.             if (++m <= SCREEN_WIDTH)
  156.                 continue;
  157.             else
  158.                 putchar(c = CTRLH);
  159.         }
  160.         switch (c)        /* Process control character, etc*/
  161.         {
  162.             /* Backspace or Delete*/
  163.         case DEL :
  164.             putchar(c = CTRLH);
  165.         case CTRLH :
  166.             if (!i)        /* If beginning of line*/
  167.                 putchar(CTRLL);        /* Move right*/
  168.             else
  169.             {
  170.                 putchar(SPACE);        /* Write a space*/
  171.                 putchar(CTRLH);        /* Backspace*/
  172.                 --m;
  173.                 --i;        /* Decrement subscripts*/
  174.             }
  175.             break;
  176.             /* Flush line_buf then printhead movmt (back, fwrd, down, up)*/
  177.         case CTRLS :
  178.             for (j = 0; j < i; j++)
  179.                 putc(line_buf[j], fdes);
  180.             i = NULL;
  181.             /*backspace if cursor not at start of screen line*/
  182.             if (m)
  183.             {
  184.                 cursor(vert, --m);
  185.                 putc(CTRLH, fdes);
  186.             }
  187.             break;
  188.         case CTRLD :
  189.             for (j = 0; j < i; j++)
  190.                 putc(line_buf[j], fdes);
  191.             i = NULL;
  192.             /*advance if cursor not at end of screen line*/
  193.             if (m < SCREEN_WIDTH)
  194.             {
  195.                 cursor(vert, ++m);
  196.                 putc(SPACE, fdes);
  197.             }
  198.             break;
  199.         case CTRLX :
  200.             for (j = 0; j < i; j++)
  201.                 putc(line_buf[j], fdes);
  202.             i = NULL;
  203.             /*move down one line*/
  204.             /*but if cursor at screen bottom, scroll screen up*/
  205.             if (vert < SCREEN_HEIGHT)
  206.                 vert++;
  207.             putchar('\n');
  208.             ruler();
  209.             cursor(vert, m);
  210.             putc('\n', fdes);
  211.             break;
  212.         case CTRLE :
  213.             for (j = 0; j < i; j++)
  214.                 putc(line_buf[j], fdes);
  215.             i = NULL;
  216.             /*move up one line*/
  217.             /*but if cursor at screen top, scroll screen down*/
  218.             if (vert == 1)
  219.             {
  220.                 INSERT_LINE;
  221.             }
  222.             else
  223.                 --vert;
  224.             cursor(vert, m);
  225.             REV_LINE_FEED;
  226.             break;
  227.             /* Cancel line_buf contents*/
  228.         case CTRLU :
  229.             m = m - i;        /* Adjust cursor*/
  230.             cursor(vert, m);
  231.             for (j = 0; j < i; j++)
  232.                 putchar(SPACE);        /*blank screen*/
  233.             cursor(vert, m);        /*adjust cursor again*/
  234.             i = NULL;        /* Zero line_buf*/
  235.             break;
  236.             /* Tab = Place spaces in array & on screen*/
  237.         case CTRLI :
  238.             if ((SCREEN_WIDTH - m) >= TAB)
  239.                 detab();
  240.             cursor(vert, m);
  241.             break;
  242.             /* Clear screen*/
  243.         case CTRLR :
  244.             CLS;        /* Clear screen*/
  245.             ruler();        /* Replace ruler line*/
  246.             i = m = NULL;        /* Beginning of buffer*/
  247.             vert = 1;        /* First line below ruler*/
  248.             break;
  249.             /* CR/LF*/
  250.         case '\n' :
  251.         case CTRLJ :
  252.         case CTRLM :
  253.             for (j = 0; j < i; j++)
  254.                 putc(line_buf[j], fdes);
  255.             putc('\r', fdes);
  256.             putc('\n', fdes);
  257.             i = m = NULL;        /* Beginning of buffer*/
  258.             if (vert < SCREEN_HEIGHT)
  259.                 ++vert;        /* Increment vert counter*/
  260.             ruler();
  261.             cursor(vert, 0);
  262.             break;
  263.             /* Display instructions*/
  264.         case CTRLP :
  265.             CLS;
  266.             disp_instructions();
  267.             getchar();
  268.             vert = 1;        /* First line below ruler*/
  269.             i = m = NULL;        /* Beginning of buffer*/
  270.             CLS;
  271.             ruler();
  272.             break;
  273.         }
  274.     }
  275.     /* Final flush of buffer to file or LST:*/
  276.     for (j = 0; j < i; j++)
  277.         putc(line_buf[j], fdes);
  278. }
  279. /* End of typer*/
  280.  
  281.  
  282.  
  283. int cursor(v, h)        /* Televideo 920C cursor positioning*/
  284. int v, h;
  285. {
  286.     putchar(ESC);
  287.     putchar('=');
  288.     putchar(v + 32);
  289.     putchar(h + 32);
  290.     return 1;
  291. }
  292. /* End of cursor*/
  293.  
  294.  
  295.  
  296. int detab()        /* Expands tabs into spaces until next tabstop*/
  297. {
  298.     do        /* Every tab expands to at least one space*/
  299.     {
  300.         line_buf[i++] = SPACE;        /* Put space in buffer*/
  301.         putchar(SPACE);        /* Put space on screen*/
  302.     }
  303.     /* And check to see if we're on a tabstop now.*/
  304.     while (((++m % TAB) != NULL) && (m <= SCREEN_WIDTH))
  305.         ;
  306.     return 1;        /* If tabstop, return ok*/
  307. }
  308. /* End of detab*/
  309.  
  310.  
  311.  
  312. void ruler()        /* Put ruler line at screen top*/
  313. {
  314.     HOME;
  315.     puts("L----!----!----!----!----!----!----!----!----!----!----!----!----!----!----!---R");
  316. }
  317. /* End of ruler*/
  318.  
  319.  
  320.  
  321. void disp_instructions()
  322. {
  323.     puts("TYPER Ver. 2.0  by Harvey G. Lord\n");
  324.     puts("TYPER placed in the public domain by Harvey G. Lord (10/14/83)\n");
  325.     puts("Modified by J. A. Rupley for printhead movement (05/07/85)\n");
  326.     puts("Written for Televideo 920 terminal and printer with reverse linefeed.\n");
  327.     puts("\n");
  328.     puts("Simple line editor.  Sends one line at a time to the\n");
  329.     puts("    LST:  device (printer) or to a disk file.\n");
  330.     puts("\n");
  331.     puts("Usage: TYPER            <== Prints instructions, output goes to LST:\n");
  332.     puts("       TYPER PRINTER    <== No instructions, output to LST:\n");
  333.     puts("       TYPER d:file.typ <== No instructions, output to disk file\n");
  334.     puts("Editing Commands:\n");
  335.     puts("       ^H, DEL         = Destructive backspace\n");
  336.     puts("       ^U              = Cancel buffer contents\n");
  337.     puts("       ^R              = Clear screen\n");
  338.     puts("       ^P              = Display prompts\n");
  339.     puts("       <cr>, ^J, ^M    = Send line to indicated device\n");
  340.     puts("       ^Z              = End of session\n");
  341.     puts("       ^C              = Abort session\n");
  342.     puts("       ^S, ^D, ^E, ^X  = Immediate printhead movement\n");
  343.     puts("                             after write of buffer contents.\n");
  344.     puts("\n");
  345.     puts("Press any key to continue.\n");
  346. }
  347.  
  348.  
  349.  
  350. void disp_message()
  351. {
  352.     puts("\n");
  353.     puts("\n");
  354.     puts("Press any key when your printer is plugged in\n");
  355.     puts("and ready to run.\n");
  356.     puts("\n");
  357.     puts("^Z ends and ^C aborts session\n");
  358.     puts("\n");
  359. }
  360.