home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / micrognu / part09 < prev    next >
Encoding:
Internet Message Format  |  1987-01-26  |  56.5 KB

  1. Subject:  v08i016:  A Micro-Emacs variant that resembles GNU Emacs
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: Bob Larson <seismo!usc-oberon!blarson>
  6. Mod.sources: Volume 8, Issue 16
  7. Archive-name: micrognu/Part09
  8.  
  9.  
  10. #! /bin/sh
  11. # This is a shell archive, meaning:
  12. # 1. Remove everything above the #! /bin/sh line.
  13. # 2. Save the resulting text in a file.
  14. # 3. Execute the file with /bin/sh (not csh) to create the files:
  15. #    sys/vms/termcap/fgetlr.c
  16. #    sys/vms/termcap/isdigit.c
  17. #    sys/vms/termcap/testtcp.c
  18. #    sys/vms/termcap/tgetent.c
  19. #    sys/vms/termcap/tgetflag.c
  20. #    sys/vms/termcap/tgetnum.c
  21. #    sys/vms/termcap/tgetstr.c
  22. #    sys/vms/termcap/tgoto.c
  23. #    sys/vms/termcap/tputs.c
  24. #    sys/vms/termcap/ttest.c
  25. #    sys/vms/termcap/createlib.com
  26. #    sys/vms/termcap/makelib.com
  27. #    sys/vms/termcap/makefile
  28. # This archive created: Sat Nov 15 15:50:15 1986
  29. export PATH; PATH=/bin:$PATH
  30. if test -f 'sys/vms/termcap/fgetlr.c'
  31. then
  32.     echo shar: will not over-write existing file "'sys/vms/termcap/fgetlr.c'"
  33. else
  34. cat << \SHAR_EOF > 'sys/vms/termcap/fgetlr.c'
  35. /************************************************************************
  36.  *                                    *
  37.  *            Copyright (c) 1982, Fred Fish            *
  38.  *                All Rights Reserved                *
  39.  *                                    *
  40.  *    This software and/or documentation is released for public    *
  41.  *    distribution for personal, non-commercial use only.        *
  42.  *    Limited rights to use, modify, and redistribute are hereby    *
  43.  *    granted for non-commercial purposes, provided that all        *
  44.  *    copyright notices remain intact and all changes are clearly    *
  45.  *    documented.  The author makes no warranty of any kind with    *
  46.  *    respect to this product and explicitly disclaims any implied    *
  47.  *    warranties of merchantability or fitness for any particular    *
  48.  *    purpose.                            *
  49.  *                                    *
  50.  ************************************************************************
  51.  */
  52.  
  53.  
  54.  
  55.  
  56. /*
  57.  *  LIBRARY FUNCTION
  58.  *
  59.  *    fgetlr    get logical record from a file
  60.  *
  61.  *  KEY WORDS
  62.  *
  63.  *    fgetlr
  64.  *    string functions
  65.  *
  66.  *  SYNOPSIS
  67.  *
  68.  *    char *fgetlr(bp,bpsize,fp)
  69.  *    char *bp;
  70.  *    int bpsize;
  71.  *    FILE *fp;
  72.  *
  73.  *  DESCRIPTION
  74.  *
  75.  *    Reads the next logical record from stream "fp" into buffer "bp"
  76.  *    until next unescaped newline, "bpsize" minus one characters
  77.  *    have been read, end of file, or read error.
  78.  *    The last character read is followed by a NULL.
  79.  *
  80.  *    A logical record may span several physical records by having
  81.  *    each newline escaped with the standard C escape character
  82.  *    (backslash).
  83.  *
  84.  *    This is particularly useful for things like the termcap
  85.  *    file, where a single entry is too long for one physical
  86.  *    line, yet needs to be treated as a single record.
  87.  *
  88.  *    Returns its first argument unless an end of file or read
  89.  *    error occurs prior to any characters being read.
  90.  *
  91.  *  BUGS
  92.  *
  93.  *    The only way to know if read was terminated due to buffer size
  94.  *    limitation is to test for a newline before the terminating
  95.  *    null.
  96.  *
  97.  */
  98.  
  99. #include <stdio.h>
  100.  
  101.  
  102.  
  103. /*
  104.  *  PSEUDO CODE
  105.  *
  106.  *    Begin fgetlr
  107.  *        If read fails then
  108.  *        Return NULL.
  109.  *        Else
  110.  *        Find out how many characters were read.
  111.  *        Initialize pointer to terminating null.
  112.  *        If last char read was newline then
  113.  *            If newline was escaped then
  114.  *            Replace backslash with the newline.
  115.  *            Replace newline with null.
  116.  *            Read and append more.
  117.  *            End if
  118.  *        End if
  119.  *        Return buffer pointer.
  120.  *        End if
  121.  *    End fgetlr
  122.  *
  123.  */
  124.  
  125. char *fgetlr(bp,bpsize,fp)
  126. char *bp;
  127. int bpsize;
  128. FILE *fp;
  129. {
  130.     int numch;
  131.     char *cp;
  132.  
  133.     if (fgets(bp,bpsize,fp) == NULL) {
  134.     return(NULL);
  135.     } else {
  136.     numch = strlen(bp);
  137.     cp = &bp[numch];
  138.     if (*--cp == '\n') {
  139.         if (numch > 1 && *--cp == '\\') {
  140.         *cp++ = '\n';
  141.         *cp = NULL;
  142.         fgetlr(cp,bpsize-numch+1,fp);
  143.         }
  144.     }
  145.     return(bp);
  146.     }
  147. }
  148. SHAR_EOF
  149. fi # end of overwriting check
  150. if test -f 'sys/vms/termcap/isdigit.c'
  151. then
  152.     echo shar: will not over-write existing file "'sys/vms/termcap/isdigit.c'"
  153. else
  154. cat << \SHAR_EOF > 'sys/vms/termcap/isdigit.c'
  155. /************************************************************************
  156.  *                                    *
  157.  *            Copyright (c) 1982, Fred Fish            *
  158.  *                All Rights Reserved                *
  159.  *                                    *
  160.  *    This software and/or documentation is released for public    *
  161.  *    distribution for personal, non-commercial use only.        *
  162.  *    Limited rights to use, modify, and redistribute are hereby    *
  163.  *    granted for non-commercial purposes, provided that all        *
  164.  *    copyright notices remain intact and all changes are clearly    *
  165.  *    documented.  The author makes no warranty of any kind with    *
  166.  *    respect to this product and explicitly disclaims any implied    *
  167.  *    warranties of merchantability or fitness for any particular    *
  168.  *    purpose.                            *
  169.  *                                    *
  170.  ************************************************************************
  171.  */
  172.  
  173.  
  174.  
  175.  
  176. /*
  177.  *  LIBRARY FUNCTION
  178.  *
  179.  *    isdigit    test character for numeric property
  180.  *
  181.  *  SYNOPSIS
  182.  *
  183.  *    int isdigit(ch)
  184.  *    char ch;
  185.  *
  186.  *  DESCRIPTION
  187.  *
  188.  *    Returns TRUE or FALSE depending upon whether the specified
  189.  *    character is a numeric character or not.
  190.  *
  191.  *  BUGS
  192.  *
  193.  *    May fail on machines in which native character set is not ASCII.
  194.  *
  195.  */
  196.  
  197. #include <stdio.h>
  198.  
  199. #define TRUE 1
  200. #define FALSE 0
  201.  
  202. int isdigit(ch)
  203. char ch;
  204. {
  205.     if (ch > '9' || ch < '0') {
  206.     return(FALSE);
  207.     } else {
  208.     return(TRUE);
  209.     }
  210. }
  211. SHAR_EOF
  212. fi # end of overwriting check
  213. if test -f 'sys/vms/termcap/testtcp.c'
  214. then
  215.     echo shar: will not over-write existing file "'sys/vms/termcap/testtcp.c'"
  216. else
  217. cat << \SHAR_EOF > 'sys/vms/termcap/testtcp.c'
  218. /************************************************************************
  219.  *                                    *
  220.  *            Copyright (c) 1982, Fred Fish            *
  221.  *                All Rights Reserved                *
  222.  *                                    *
  223.  *    This software and/or documentation is released for public    *
  224.  *    distribution for personal, non-commercial use only.        *
  225.  *    Limited rights to use, modify, and redistribute are hereby    *
  226.  *    granted for non-commercial purposes, provided that all        *
  227.  *    copyright notices remain intact and all changes are clearly    *
  228.  *    documented.  The author makes no warranty of any kind with    *
  229.  *    respect to this product and explicitly disclaims any implied    *
  230.  *    warranties of merchantability or fitness for any particular    *
  231.  *    purpose.                            *
  232.  *                                    *
  233.  ************************************************************************
  234.  */
  235.  
  236.  
  237.  
  238.  
  239. /*
  240.  *  TEST PROGRAM
  241.  *
  242.  *    testtcp   test termcap functions
  243.  *
  244.  *  KEY WORDS
  245.  *
  246.  *    test routines
  247.  *    termcap test
  248.  *
  249.  *  SYNOPSIS
  250.  *
  251.  *    termcap [-efns] terminal [capability [capability ...]]
  252.  *
  253.  *        -e  =>   expand string capability given by -s
  254.  *        -f  =>   determine boolean capabilities for terminal
  255.  *        -n  =>   determine numeric capabilities for terminal
  256.  *        -s  =>   determine string capabilities for terminal
  257.  *
  258.  *        terminal =>  terminal name as given in termcap file
  259.  *        capability => a boolean, numeric, or string capability
  260.  *
  261.  *        NOTE:  All capabilities must be of same type, as
  262.  *               given by [-fns].
  263.  *
  264.  *        If terminal is only argument then entire entry is
  265.  *        printed.
  266.  *
  267.  *  DESCRIPTION
  268.  *
  269.  *    Provides way to test termcap functions.  Can find
  270.  *    and print an entire termcap terminal entry, or various
  271.  *    capabilities from the entry.
  272.  *
  273.  *  AUTHOR
  274.  *
  275.  *    Fred Fish
  276.  *
  277.  */
  278.  
  279. #include <stdio.h>
  280.  
  281. #define TRUE 1
  282. #define FALSE 0
  283. #define NO_FILE     -1            /* Returned if can't open file */
  284. #define NO_ENTRY  0            /* Returned if can't find entry */
  285. #define SUCCESS   1            /* Returned if entry found ok */
  286. #define TRUNCATED 2            /* Returned if entry found but trunc */
  287. #define BUFFER_SIZE 1024
  288.  
  289. int eflag = FALSE;
  290. int fflag = FALSE;
  291. int nflag = FALSE;
  292. int sflag = FALSE;
  293.  
  294. int got_terminal = FALSE;
  295. int got_capability = FALSE;
  296.  
  297.  
  298.  
  299.  
  300. /*
  301.  *  FUNCTION
  302.  *
  303.  *    main   termcap test entry point
  304.  *
  305.  *  KEY WORDS
  306.  *
  307.  *    main
  308.  *
  309.  *  SYNOPSIS
  310.  *
  311.  *    main(argc,argv)
  312.  *    int argc;
  313.  *    char *argv[];
  314.  *
  315.  *  DESCRIPTION
  316.  *
  317.  *    This is where the termcap test starts executing.  All argument list
  318.  *    switches are processed first, then all the specified
  319.  *    capability identification strings are processed.
  320.  *
  321.  */
  322.  
  323.  
  324.  
  325. /*
  326.  *  PSEUDO CODE
  327.  *
  328.  *    Begin main
  329.  *        Process command line options.
  330.  *        For each argument list field
  331.  *        If field was not erased during option processing
  332.  *            If terminal name field not yet processed then
  333.  *            Process an assumed terminal name field.
  334.  *            Set terminal name processed flag.
  335.  *            Else
  336.  *            Process a capability field.
  337.  *            Set capability field processed flag.
  338.  *            End if
  339.  *        End if
  340.  *        End for
  341.  *        If no capabilities processed then
  342.  *        Simply dump buffer.
  343.  *        End if
  344.  *    End main
  345.  *
  346.  */
  347.  
  348. main(argc, argv)
  349. int argc;
  350. char *argv[];
  351. {
  352.     char *argp;
  353.     int argnum;
  354.     char buffer[BUFFER_SIZE];
  355.  
  356.     options(argc,argv);
  357.     for (argnum = 1; argnum < argc; argnum++) {
  358.         if ((argp = argv[argnum]) != NULL) {
  359.         if (!got_terminal) {
  360.         terminal(buffer,argp);
  361.         got_terminal = TRUE;
  362.         } else {
  363.         capability(argp);
  364.         got_capability = TRUE;
  365.         }
  366.         }
  367.     }
  368.     if (got_terminal && !got_capability) {
  369.     printf("%s",buffer);
  370.     }
  371. }
  372.  
  373.  
  374.  
  375. /*
  376.  *  FUNCTION
  377.  *
  378.  *    options   process command line options
  379.  *
  380.  *  SYNOPSIS
  381.  *
  382.  *    options(argc,argv)
  383.  *    int argc;
  384.  *    char *argv[];
  385.  *
  386.  *  DESCRIPTION
  387.  *
  388.  *    Scans argument list, processing each switch as it is
  389.  *    found.  The pointer to each switch string is then
  390.  *    replaced with a NULL to effectively erase the switch
  391.  *    argument.
  392.  *
  393.  */
  394.  
  395.  
  396.  
  397. /*
  398.  *  PSEUDO CODE
  399.  *
  400.  *    Begin options
  401.  *        For each argument in the argument list
  402.  *        Get pointer to first char of argument.
  403.  *        If the argument is a switch then
  404.  *            Replace argument pointer with NULL.
  405.  *            Look at next argument character.
  406.  *            While there is another argument character
  407.  *            Switch on the argument character
  408.  *            Case "EXPAND":
  409.  *                Set expand (e) flag.
  410.  *                Break out of switch.
  411.  *            Case "BOOLEAN":
  412.  *                Set boolean (f) flag.
  413.  *                Break out of switch.
  414.  *            Case "NUMERIC":
  415.  *                Set numeric flag.
  416.  *                Break out of switch.
  417.  *            Case "STRING":
  418.  *                Set string flag.
  419.  *                Break out of switch.
  420.  *            Default:
  421.  *                Abort with usage message.
  422.  *            End switch
  423.  *            End while
  424.  *        End if
  425.  *        End for
  426.  *    End options
  427.  *
  428.  */
  429.  
  430.  
  431.  
  432. options(argc, argv)
  433. int argc;
  434. char *argv[];
  435. {
  436.     int i;
  437.     char c;        /* 1st char of current command-line argument */
  438.     char *cp;        /* current argument pointer */
  439.  
  440.     for (i=1; i<argc; i++) {
  441.         cp = argv[i];
  442.         if (*cp == '-') {
  443.             argv[i] = NULL;
  444.         cp++;
  445.         while (c = *cp++) {
  446.             switch (c) {
  447.         case 'e':
  448.             eflag = TRUE;
  449.             break;
  450.         case 'f':
  451.             fflag = TRUE;
  452.                 break;
  453.             case 'n':
  454.             nflag = TRUE;
  455.                 break;
  456.             case 's':
  457.             sflag = TRUE;
  458.                 break;
  459.             default:
  460.                 usage();
  461.             }
  462.             }
  463.         }
  464.     }
  465. }
  466.  
  467.  
  468.  
  469. /*
  470.  *  FUNCTION
  471.  *
  472.  *    usage   give usage message and abort
  473.  *
  474.  *  KEY WORDS
  475.  *
  476.  *    usage
  477.  *    help processing
  478.  *    abort locations
  479.  *
  480.  *  SYNOPSIS
  481.  *
  482.  *    usage()
  483.  *
  484.  *  DESCRIPTION
  485.  *
  486.  *    Usage is typically called when a problem has been
  487.  *    detected in the argument list.
  488.  *    It prints a usage message and exits.
  489.  *
  490.  */
  491.  
  492.  
  493.  
  494. /*
  495.  *  PSEUDO CODE
  496.  *
  497.  *    Begin usage
  498.  *        Print usage message.
  499.  *        Exit.
  500.  *    End usage
  501.  *
  502.  */
  503.  
  504. usage()
  505. {
  506.     printf("Usage: termcap [-fns] terminal [capability [capability ... ]]\n");
  507.     exit();
  508. }
  509.  
  510.  
  511.  
  512.  
  513. terminal(buffer,name)
  514. char *buffer;
  515. char *name;
  516. {
  517.     int status;
  518.  
  519.     status = tgetent(buffer,name);
  520.     switch (status) {
  521.     case NO_FILE:
  522.     fprintf(stderr,"Can't find a termcap data base file.\n");
  523.     exit();
  524.     case NO_ENTRY:
  525.     fprintf(stderr,"Can't find entry \"%s\"\n",name);
  526.     exit();
  527.     case TRUNCATED:
  528.     fprintf(stderr,"Warning --- entry \"%s\" too long\n",name);
  529.     break;
  530.     case SUCCESS:
  531.         break;
  532.     default:
  533.         fprintf(stderr,"? tgetent returned illegal status %d\n",status);
  534.     exit();
  535.     }
  536. }
  537.  
  538.  
  539.  
  540. capability(id)
  541. char *id;
  542. {
  543.     int value;
  544.     char buffer[256];
  545.     char *area;
  546.     char *ep, *tgoto();
  547.  
  548.     if (fflag) {
  549.     value = tgetflag(id);
  550.     if (value) {
  551.         printf("%s TRUE\n",id);
  552.     } else {
  553.         printf("%s FALSE\n",id);
  554.     }
  555.     } else if (nflag) {
  556.     value = tgetnum(id);
  557.     printf("%s = %o octal %d decimal\n",id,value,value);
  558.     } else if (sflag) {
  559.     area = buffer;
  560.     tgetstr(id,&area);
  561.     if (eflag) {
  562.         ep = tgoto(buffer,75,23);
  563.     }
  564.     doprint(id,buffer);
  565.     if (eflag) {
  566.         doprint(id,ep);
  567.         ep = tgoto(buffer,1,2);
  568.         doprint(id,ep);
  569.     }
  570.     }
  571. }
  572.  
  573.  
  574.  
  575. doprint(id,cp)
  576. char *id;
  577. char *cp;
  578. {
  579.     printf("%s = \"",id);
  580.     for ( ; *cp != NULL; cp++) {
  581.     if (*cp < 040) {
  582.         printf("^%c",*cp |= 0100);
  583.     } else {
  584.         printf("%c",*cp);
  585.     }
  586.     }
  587.     printf("\"\n");
  588. }
  589.  
  590. SHAR_EOF
  591. fi # end of overwriting check
  592. if test -f 'sys/vms/termcap/tgetent.c'
  593. then
  594.     echo shar: will not over-write existing file "'sys/vms/termcap/tgetent.c'"
  595. else
  596. cat << \SHAR_EOF > 'sys/vms/termcap/tgetent.c'
  597. /************************************************************************
  598.  *                                    *
  599.  *            Copyright (c) 1982, Fred Fish            *
  600.  *                All Rights Reserved                *
  601.  *                                    *
  602.  *    This software and/or documentation is released for public    *
  603.  *    distribution for personal, non-commercial use only.        *
  604.  *    Limited rights to use, modify, and redistribute are hereby    *
  605.  *    granted for non-commercial purposes, provided that all        *
  606.  *    copyright notices remain intact and all changes are clearly    *
  607.  *    documented.  The author makes no warranty of any kind with    *
  608.  *    respect to this product and explicitly disclaims any implied    *
  609.  *    warranties of merchantability or fitness for any particular    *
  610.  *    purpose.                            *
  611.  *                                    *
  612.  ************************************************************************
  613.  */
  614. /*
  615.  * Modified:
  616.  *    30-Apr-86 Mic Kaczmarczik ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  617.  *          Instead of using VAX C getenv("TERM"), which does not
  618.  *          return the value of logical name "TERM", translate the
  619.  *          logical name by hand.
  620.  *    11-Oct-86 Mic Kaczmarczik ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  621.  *          Support tc capability to allow the library to use standard
  622.  *          termcaps.  Rewrote tgetent to look for tc capability
  623.  *          and add new terminal definition to the caller's buffer. 
  624.  *          This makes it rather possible to overflow the caller's
  625.  *          buffer, but the library doesn't make any claim that it
  626.  *          won't overwrite the buffer anyway...
  627.  */
  628.  
  629.  
  630.  
  631. /*
  632.  *  LIBRARY FUNCTION
  633.  *
  634.  *    tgetent   load buffer with entry for specified terminal
  635.  *
  636.  *  KEY WORDS
  637.  *
  638.  *    termcap functions
  639.  *    utility routines
  640.  *
  641.  *  SYNOPSIS
  642.  *
  643.  *    int tgetent(bp,name)
  644.  *    char *bp;
  645.  *    char *name;
  646.  *
  647.  *  DESCRIPTION
  648.  *
  649.  *    Extracts the entry for terminal <name> from the termcap file
  650.  *    and places it in the character buffer <bp>.   It is currently
  651.  *    assumed that bp is at least 1024 characters.  If the entry in
  652.  *    the termcap file is larger than 1023 characters the excess
  653.  *    characters will be discarded and appropriate status will
  654.  *    be returned.
  655.  *
  656.  *    Also note that since bp is used by other termcap
  657.  *    routines, the storage associated with the termcap entry
  658.  *    cannot be freed until all termcap calls are completed.
  659.  *
  660.  *    Tgetent can be directed to look in a file other than
  661.  *    the default (/etc/termcap) by defining an environment
  662.  *    variable called TERMCAP to be the pathname of the desired
  663.  *    termcap file.  This is useful for debugging new entries.
  664.  *    NOTE: the pathname MUST begin with a '/' character.
  665.  *
  666.  *    Also, if the string assigned to TERMCAP does not begin with
  667.  *    a '/' and if the environment variable TERM matches <name> then
  668.  *    the string assigned to TERMCAP is copied to buffer <bp> 
  669.  *    instead of reading a termcap file.
  670.  *    
  671.  *  RETURNS
  672.  *
  673.  *    -1  if the termcap file cannot be opened
  674.  *     0  if no entry in termcap file matches <name>
  675.  *     1  if extraction is successful with no errors
  676.  *     2  if extraction is successful but entry truncated
  677.  *
  678.  *  SEE ALSO
  679.  *
  680.  *    tgetnum   extract numeric type capability
  681.  *    tgetflag  test boolean type capability
  682.  *    tgetstr   get string value of capability
  683.  *
  684.  *  AUTHOR
  685.  *
  686.  *    Fred Fish
  687.  *
  688.  */
  689.  
  690. #include <stdio.h>
  691.  
  692. #define TRUE 1
  693. #define FALSE 0
  694. #define BUFSIZE 1024            /* Assumed size of external buffer */
  695.  
  696. #define NO_FILE     -1            /* Returned if can't open file */
  697. #define NO_ENTRY  0            /* Returned if can't find entry */
  698. #define SUCCESS   1            /* Returned if entry found ok */
  699. #define TRUNCATED 2            /* Returned if entry found but trunc */
  700.  
  701. #define DEFAULT_FILE "/etc/termcap"    /* default termcap filename */
  702. #ifdef    VAXC
  703. #define    index strchr
  704. #endif
  705.  
  706. char *_tcpbuf;                /* Place to remember buffer pointer */
  707. FILE *fp, *find_file();            /* Termcap file            */
  708. extern char *index();
  709.  
  710. /*
  711.  *  PSEUDO CODE
  712.  *
  713.  *    Begin tgetent
  714.  *        Erase any previous buffer contents.
  715.  *        Remember the buffer pointer.
  716.  *        If termcap file is not found then
  717.  *        If buffer was filled anyway then
  718.  *            Return SUCCESS.
  719.  *        Else
  720.  *            Return NO_FILE.
  721.  *        End if
  722.  *        Else
  723.  *        Find entry associated with name
  724.  *        While an entry was found and limit not reached
  725.  *            If no tc capability found Then
  726.  *            Exit while loop with status = SUCCESS
  727.  *            Else
  728.  *                Call getent to get entry indicated by tc=
  729.  *            If entry not found then
  730.  *                Exit loop with status != SUCCESS
  731.  *            End if
  732.  *            Concatenate entry into buffer
  733.  *            End If
  734.  *        End while
  735.  *        End if
  736.  *        Close termcap file
  737.  *        Return status code
  738.  *    End tgetent
  739.  *            
  740.  */
  741.  
  742. int tgetent(bp,name)
  743. char *bp;
  744. char *name;
  745. {
  746.     char    *tc, *tcbufp, tcbuf[80], termbuf[BUFSIZE], *tgetstr();
  747.     char    *bufp, *cp;        /* current start of buffer    */
  748.     int    limit = 10;        /* maximum nesting        */
  749.     int    status;            /* return from getent()        */
  750.  
  751.     *bp = '\0';            /* clear buffer            */
  752.     _tcpbuf = bp;            /* save base of buffer        */
  753.  
  754.     /* Look for termcap file.  If NULL, find_file may have found a    */
  755.     /* a valid termcap string in the environment variable TERMCAP.    */
  756.     /* If non-null, attempt to find the entry in the termcap file    */
  757.  
  758.     if ((fp = find_file(bp)) == NULL) {
  759.         if (*bp != NULL)
  760.             return(SUCCESS);
  761.         else
  762.             return(NO_FILE);
  763.     }
  764.     status = getent(bp, name);/* look for main entry    */
  765.  
  766.     /* Start looking for tc capabilities in the termcap.  If
  767.      * found, concatenate the entry for the new terminal to the
  768.      * current buffer and try again.  To avoid infinite loops,
  769.      * allow only 10 loops through this process.
  770.      */
  771.     while ((status == SUCCESS) && limit--) {
  772.         /* look for tc capability.  If none found, exit loop    */
  773.         tcbufp = tcbuf;
  774.         if (((tc = tgetstr("tc",&tcbufp)) == NULL)
  775.               || (*tc == '\0')) {
  776.             status = SUCCESS;/* no more tc= entries    */
  777.             break;
  778.         }
  779.  
  780.         /* Attempt to get next entry. Exit loop if unsuccessful    */
  781.         if ((status = getent(termbuf, tcbuf)) != SUCCESS)
  782.             break;
  783.  
  784.         /* Copy new entry into buffer, right at "tc="         */
  785.         for (bufp = bp; *bufp; bufp++)        /* find tc=    */
  786.             if ((*bufp=='t') && (bufp[1]=='c') && (bufp[2]=='='))
  787.                 break;
  788.         if ((cp = index(termbuf,':')) == NULL)
  789.             cp = termbuf;
  790.         strcpy(bufp, cp + 1);
  791.     }
  792.  
  793.     /* close termcap file and return the status    */
  794.     fclose(fp);
  795.     return status;
  796. }
  797.  
  798.  
  799.  
  800.  
  801. /*
  802.  *  INTERNAL FUNCTION
  803.  *
  804.  *    getent    find termcap entry in termcap file
  805.  *
  806.  *  KEY WORDS
  807.  *
  808.  *    internal functions
  809.  *    getent
  810.  *
  811.  *  SYNOPSIS
  812.  *
  813.  *    static int getent(bp,name)
  814.  *    char *bp;
  815.  *    char *name;
  816.  *
  817.  *  DESCRIPTION
  818.  *
  819.  *    Getent is called by tgetent each time tgetent attempts to
  820.  *    read a capability from the termcap database file.  Places
  821.  *    the entry in the buffer pointed to by bp
  822.  *
  823.  *
  824.  *  PSEUDOCODE
  825.  *
  826.  *    Begin Getent
  827.  *        Seek to beginning of termcap file
  828.  *        Clear buffer
  829.  *        While records left to process
  830.  *        If this is entry is what we want then
  831.  *            If entry was truncated then
  832.  *            Return TRUNCATED status
  833.  *            Else
  834.  *            Return SUCCESS status.
  835.  *            End if
  836.  *        End if
  837.  *        End while
  838.  *        Return NO_ENTRY status.
  839.  *    End
  840.  */
  841.  
  842. static int getent(bp,name)
  843. char *bp;                /* Pointer to buffer (1024 char min) */
  844. char *name;                /* Pointer to terminal entry to find */
  845. {
  846.     *bp = '\0';            /* clear buffer            */
  847.     lseek(fileno(fp), 0L, 0l);    /* rewind termcap file        */
  848.  
  849.     while (fgetlr(bp,BUFSIZE,fp)) {
  850.             if (gotcha(bp,name)) {
  851.             if (bp[strlen(bp)-1] != '\n') {
  852.                 return(TRUNCATED);
  853.             } else {
  854.                 return(SUCCESS);
  855.             }
  856.         }
  857.     }
  858.     return(NO_ENTRY);
  859. }
  860.  
  861.  
  862.  
  863. /*
  864.  *  INTERNAL FUNCTION
  865.  *
  866.  *    find_file    find the termcap file and open it if possible
  867.  *
  868.  *  KEY WORDS
  869.  *
  870.  *    internal functions
  871.  *    find_file
  872.  *
  873.  *  SYNOPSIS
  874.  *
  875.  *    static FILE *find_file(bp)
  876.  *    char *bp;
  877.  *
  878.  *  DESCRIPTION
  879.  *
  880.  *    Attempts to locate and open the termcap file.  Also handles
  881.  *    using the environment TERMCAP string as the actual buffer
  882.  *    (that's why bp has to be an input parameter).
  883.  *
  884.  *    If TERMCAP is defined an begins with a '/' character then
  885.  *    it is taken to be the pathname of the termcap file and
  886.  *    an attempt is made to open it.  If this fails then
  887.  *    the default termcap file is used instead.
  888.  *
  889.  *    If TERMCAP is defined but does not begin with a '/' then
  890.  *    it is assumed to be the actual buffer contents provided
  891.  *    that <name> matches the environment variable TERM.
  892.  *
  893.  *  BUGS
  894.  *
  895.  *    There is currently no way to be sure which termcap
  896.  *    file was opened since the default will always be
  897.  *    tried.
  898.  *
  899.  */
  900.  
  901.  
  902.  
  903. /*
  904.  *  PSEUDO CODE
  905.  *
  906.  *    Begin find_file
  907.  *        If there is a TERMCAP environment string then
  908.  *        If the string is not null then
  909.  *            If the string is a pathname then
  910.  *            If that file is opened successfully then
  911.  *                Return its pointer.
  912.  *            End if
  913.  *            Else
  914.  *            If there is a TERM environment string then
  915.  *                If TERM matches <name> then
  916.  *                Copy TERMCAP string to buffer.
  917.  *                Return NULL for no file.
  918.  *                End if
  919.  *            End if
  920.  *            End if
  921.  *        End if
  922.  *        End if
  923.  *        Open default termcap file and return results.
  924.  *    End find_file
  925.  *
  926.  */
  927. #ifdef    VAXC
  928. char *trnlnm();
  929. #endif
  930.  
  931. static FILE *find_file(bp)
  932. char *bp;
  933. {
  934.     FILE *fp, *fopen();
  935.     char *cp, *ncp, *getenv(), vmsname[132];
  936.  
  937.     if ((cp = getenv("TERMCAP")) != NULL) {
  938.     if (*cp != NULL) {
  939.         if (*cp == '/') {
  940.         if ((fp = fopen(cp,"r")) != NULL) {
  941.             return(fp);
  942.         }
  943.         } else {
  944. #ifdef VAXC
  945.         if ((ncp = trnlnm("TERM")) != NULL) {
  946. #else
  947.         if ((ncp = getenv("TERM")) != NULL) {
  948. #endif
  949.             if (strcmp(cp,ncp) == 0) {
  950.             strcpy(bp,cp);
  951.             return((FILE *)NULL);
  952.             }
  953.         }
  954.         }
  955.     }
  956.     }
  957.     return(fopen(DEFAULT_FILE,"r"));
  958. }
  959.  
  960.  
  961.  
  962. /*
  963.  *  INTERNAL FUNCTION
  964.  *
  965.  *    gotcha   test to see if entry is for specified terminal
  966.  *
  967.  *  SYNOPSIS
  968.  *
  969.  *    gotcha(bp,name)
  970.  *    char *bp;
  971.  *    char *name;
  972.  *
  973.  *  DESCRIPTION
  974.  *
  975.  *    Tests to see if the entry in buffer bp matches the terminal
  976.  *    specified by name.  Returns TRUE if match is detected, FALSE
  977.  *    otherwise.
  978.  *
  979.  */
  980.  
  981.  
  982.  
  983. /*
  984.  *  PSEUDO CODE
  985.  *
  986.  *    Begin gotcha
  987.  *        If buffer character is comment character then
  988.  *        Return FALSE since remainder is comment
  989.  *        Else
  990.  *        Initialize name scan pointer.
  991.  *        Compare name and buffer until end or mismatch.
  992.  *        If valid terminators for both name and buffer strings
  993.  *            Return TRUE since a match was found.
  994.  *        Else
  995.  *            Find next non-name character in buffer.
  996.  *            If not an alternate name separater character
  997.  *            Return FALSE since no more names to check.
  998.  *            Else
  999.  *            Test next name and return results.
  1000.  *            End if
  1001.  *        End if
  1002.  *        End if
  1003.  *    End gotcha
  1004.  *
  1005.  */
  1006.  
  1007. gotcha(bp,name)
  1008. char *bp;
  1009. char *name;
  1010. {
  1011.     char *np;
  1012.  
  1013.     if (*bp == '#') {
  1014.     return(FALSE);
  1015.     } else {
  1016.     np = name;
  1017.     while (*np == *bp && *np != NULL) {np++; bp++;}
  1018.     if (*np == NULL && (*bp == NULL || *bp == '|' || *bp == ':')) {
  1019.         return(TRUE);
  1020.     } else {
  1021.         while (*bp != NULL && *bp != ':' && *bp != '|') {bp++;}
  1022.         if (*bp != '|') {
  1023.         return(FALSE);
  1024.         } else {
  1025.         return(gotcha(++bp,name));
  1026.         }
  1027.     }
  1028.     }
  1029. }
  1030.  
  1031. SHAR_EOF
  1032. fi # end of overwriting check
  1033. if test -f 'sys/vms/termcap/tgetflag.c'
  1034. then
  1035.     echo shar: will not over-write existing file "'sys/vms/termcap/tgetflag.c'"
  1036. else
  1037. cat << \SHAR_EOF > 'sys/vms/termcap/tgetflag.c'
  1038. /************************************************************************
  1039.  *                                    *
  1040.  *            Copyright (c) 1982, Fred Fish            *
  1041.  *                All Rights Reserved                *
  1042.  *                                    *
  1043.  *    This software and/or documentation is released for public    *
  1044.  *    distribution for personal, non-commercial use only.        *
  1045.  *    Limited rights to use, modify, and redistribute are hereby    *
  1046.  *    granted for non-commercial purposes, provided that all        *
  1047.  *    copyright notices remain intact and all changes are clearly    *
  1048.  *    documented.  The author makes no warranty of any kind with    *
  1049.  *    respect to this product and explicitly disclaims any implied    *
  1050.  *    warranties of merchantability or fitness for any particular    *
  1051.  *    purpose.                            *
  1052.  *                                    *
  1053.  ************************************************************************
  1054.  */
  1055. /*
  1056.  * Modified:
  1057.  *    30-Apr-86 Mic Kaczmarczik
  1058.  *    #define index to strchr if VAX C
  1059.  *
  1060.  */
  1061.  
  1062.  
  1063.  
  1064.  
  1065. /*
  1066.  *  LIBRARY FUNCTION
  1067.  *
  1068.  *    tgetflag   extract boolean termcap capability
  1069.  *
  1070.  *  KEY WORDS
  1071.  *
  1072.  *    termcap
  1073.  *
  1074.  *  SYNOPSIS
  1075.  *
  1076.  *    tgetflag(id)
  1077.  *    char *id;
  1078.  *
  1079.  *  DESCRIPTION
  1080.  *
  1081.  *    Returns TRUE if specified id is present in terminal
  1082.  *    entry, FALSE otherwise.
  1083.  *
  1084.  */
  1085.  
  1086. #include <stdio.h>
  1087. #ifdef VAXC
  1088. #define index strchr
  1089. #endif
  1090.  
  1091. #define TRUE 1
  1092. #define FALSE 0
  1093.  
  1094. extern char *_tcpbuf;        /* Termcap entry buffer pointer */
  1095.  
  1096.  
  1097.  
  1098. /*
  1099.  *  PSEUDO CODE
  1100.  *
  1101.  *    Begin tgetflag
  1102.  *        Initialize pointer to the termcap entry buffer.
  1103.  *        While there is a field to process
  1104.  *        Skip over the field separator character.
  1105.  *        If this is the entry we want then
  1106.  *            If entry is identifier only then
  1107.  *            Return TRUE
  1108.  *            Else
  1109.  *            Return FALSE
  1110.  *            End if
  1111.  *        End if
  1112.  *        End while
  1113.  *        Return FALSE as default.
  1114.  *    End tgetflag
  1115.  *
  1116.  */
  1117.  
  1118. tgetflag(id)
  1119. char *id;
  1120. {
  1121.     char *bp;
  1122.     extern char *index();
  1123.  
  1124.     bp = _tcpbuf;
  1125.     while ((bp = index(bp,':')) != NULL) {
  1126.     bp++;
  1127.     if (*bp++ == id[0] && *bp != NULL && *bp++ == id[1]) {
  1128.         if (*bp == NULL || *bp++ == ':') {
  1129.         return(TRUE);
  1130.         } else {
  1131.         return(FALSE);
  1132.         }
  1133.     }
  1134.     }
  1135.     return(FALSE);
  1136. }
  1137. SHAR_EOF
  1138. fi # end of overwriting check
  1139. if test -f 'sys/vms/termcap/tgetnum.c'
  1140. then
  1141.     echo shar: will not over-write existing file "'sys/vms/termcap/tgetnum.c'"
  1142. else
  1143. cat << \SHAR_EOF > 'sys/vms/termcap/tgetnum.c'
  1144. /************************************************************************
  1145.  *                                    *
  1146.  *            Copyright (c) 1982, Fred Fish            *
  1147.  *                All Rights Reserved                *
  1148.  *                                    *
  1149.  *    This software and/or documentation is released for public    *
  1150.  *    distribution for personal, non-commercial use only.        *
  1151.  *    Limited rights to use, modify, and redistribute are hereby    *
  1152.  *    granted for non-commercial purposes, provided that all        *
  1153.  *    copyright notices remain intact and all changes are clearly    *
  1154.  *    documented.  The author makes no warranty of any kind with    *
  1155.  *    respect to this product and explicitly disclaims any implied    *
  1156.  *    warranties of merchantability or fitness for any particular    *
  1157.  *    purpose.                            *
  1158.  *                                    *
  1159.  ************************************************************************
  1160.  */
  1161. /* Modified:
  1162.  * 30-Apr-86 Mic Kaczmarczik
  1163.  *         Use ctype.h macros instead of the function isdigit().
  1164.  *         #define index to strchr if VAXC
  1165.  */
  1166.  
  1167.  
  1168.  
  1169. /*
  1170.  *  LIBRARY FUNCTION
  1171.  *
  1172.  *    tgetnum   extract numeric option from termcap entry
  1173.  *
  1174.  *  KEY WORDS
  1175.  *
  1176.  *    termcap
  1177.  *    ce functions
  1178.  *
  1179.  *  SYNOPSIS
  1180.  *
  1181.  *    tgetnum(id)
  1182.  *    char *id;
  1183.  *
  1184.  *  DESCRIPTION
  1185.  *
  1186.  *    Returns numeric value of capability <id>, or -1 if <id>
  1187.  *    is not found.   Knows about octal numbers, which
  1188.  *    begin with 0.
  1189.  *
  1190.  */
  1191.  
  1192. #include <stdio.h>
  1193. #include <ctype.h>
  1194. #ifdef    VAXC
  1195. #define index strchr
  1196. #endif
  1197.  
  1198. extern char *_tcpbuf;        /* Termcap entry buffer pointer */
  1199.  
  1200.  
  1201.  
  1202. /*
  1203.  *  PSEUDO CODE
  1204.  *
  1205.  *    Begin tgetnum
  1206.  *        Initialize pointer to the termcap entry buffer.
  1207.  *        While there is a field to process
  1208.  *        Skip over the field separator character.
  1209.  *        If this is the entry we want then
  1210.  *            If the entry is not a numeric then
  1211.  *            Return failure value.
  1212.  *            Else
  1213.  *            Initialize value to zero.
  1214.  *            If number begins with zero then
  1215.  *                Set accumulation base to 8.
  1216.  *            Else
  1217.  *                Set accumulation base to 10.
  1218.  *            End if
  1219.  *            While there is a numeric character
  1220.  *                Accumulate the value.
  1221.  *            End while
  1222.  *            Return value.
  1223.  *            End if
  1224.  *        End if
  1225.  *        End while
  1226.  *        Return failure value.
  1227.  *    End tgetnum
  1228.  *
  1229.  */
  1230.  
  1231. tgetnum(id)
  1232. char *id;
  1233. {
  1234.     int value, base;
  1235.     char *bp;
  1236.     extern char *index();
  1237.  
  1238.     bp = _tcpbuf;
  1239.     while ((bp = index(bp,':')) != NULL) {
  1240.     bp++;
  1241.     if (*bp++ == id[0] && *bp != NULL && *bp++ == id[1]) {
  1242.         if (*bp != NULL && *bp++ != '#') {
  1243.         return(-1);
  1244.         } else {
  1245.         value = 0;
  1246.         if (*bp == '0') {
  1247.             base = 8;
  1248.         } else {
  1249.             base = 10;
  1250.         }
  1251.         while (isdigit(*bp)) {
  1252.             value *= base;
  1253.             value += (*bp++ - '0');
  1254.         }
  1255.         return(value);
  1256.         }
  1257.     }
  1258.     }
  1259.     return(-1);
  1260. }
  1261. SHAR_EOF
  1262. fi # end of overwriting check
  1263. if test -f 'sys/vms/termcap/tgetstr.c'
  1264. then
  1265.     echo shar: will not over-write existing file "'sys/vms/termcap/tgetstr.c'"
  1266. else
  1267. cat << \SHAR_EOF > 'sys/vms/termcap/tgetstr.c'
  1268. /************************************************************************
  1269.  *                                    *
  1270.  *            Copyright (c) 1982, Fred Fish            *
  1271.  *                All Rights Reserved                *
  1272.  *                                    *
  1273.  *    This software and/or documentation is released for public    *
  1274.  *    distribution for personal, non-commercial use only.        *
  1275.  *    Limited rights to use, modify, and redistribute are hereby    *
  1276.  *    granted for non-commercial purposes, provided that all        *
  1277.  *    copyright notices remain intact and all changes are clearly    *
  1278.  *    documented.  The author makes no warranty of any kind with    *
  1279.  *    respect to this product and explicitly disclaims any implied    *
  1280.  *    warranties of merchantability or fitness for any particular    *
  1281.  *    purpose.                            *
  1282.  *                                    *
  1283.  ************************************************************************
  1284.  */
  1285. /* Modified:
  1286.  * 30-Apr-86 Mic Kaczmarczik
  1287.  *         Use ctype.h macros instead of the function isdigit().
  1288.  *         #define index() to be strchr() if VAX C
  1289.  */
  1290.  
  1291.  
  1292.  
  1293.  
  1294. /*
  1295.  *  LIBRARY FUNCTION
  1296.  *
  1297.  *    tgetstr   extract string capability from termcap entry
  1298.  *
  1299.  *  KEY WORDS
  1300.  *
  1301.  *    termcap
  1302.  *
  1303.  *  SYNOPSIS
  1304.  *
  1305.  *    char *tgetstr(id,area)
  1306.  *    char *id;
  1307.  *    char **area;
  1308.  *
  1309.  *  DESCRIPTION
  1310.  *
  1311.  *    Gets the string capability for <id>, placing it in
  1312.  *    the buffer at *area, and advancing *area to point
  1313.  *    to next available storage.
  1314.  *
  1315.  *    For example, if the following capabilities are
  1316.  *    in the termcap file:
  1317.  *
  1318.  *        ZZ=zzzz
  1319.  *        YY=yyyyyy
  1320.  *        WW=www
  1321.  *
  1322.  *    then successive calls using YY, ZZ, and WW will
  1323.  *    build the following buffer:
  1324.  *
  1325.  *        yyyyyy0zzzz0www0
  1326.  *
  1327.  *    The first call will return a pointer to yyyyyy, the
  1328.  *    second will return a pointer to zzzz and the third
  1329.  *    will return a pointer to www.  Note that each
  1330.  *    string is null terminated, as are all C strings.
  1331.  *
  1332.  *    Characters preceded by the carot character (\136)
  1333.  *    are mapped into the corresponding control character.
  1334.  *    For example, the two character sequence ^A becomes
  1335.  *    a single control-A (\001) character.
  1336.  *
  1337.  *    The escape character is the normal C backslash and
  1338.  *    the normal C escape sequences are recognized, along
  1339.  *    with a special sequence for the ASCII escape character
  1340.  *    (\033).  The recognized sequences are:
  1341.  *
  1342.  *        \E   =>  '\033'  (ASCII escape character)
  1343.  *        \b   =>  '\010'  (ASCII backspace character)
  1344.  *        \f   =>  '\014'  (ASCII form feed character)
  1345.  *        \n   =>  '\012'  (ASCII newline/linefeed char)
  1346.  *        \r   =>  '\015'  (ASCII carriage return char)
  1347.  *        \t   =>  '\011'  (ASCII tab character)
  1348.  *        \ddd =>  '\ddd'  (arbitrary ASCII digit)
  1349.  *        \x   =>  'x'     (ordinary ASCII character)
  1350.  *
  1351.  */
  1352.  
  1353. #include <stdio.h>
  1354. #include <ctype.h>
  1355. #ifdef VAXC
  1356. #define index strchr
  1357. #endif
  1358.  
  1359. extern char *_tcpbuf;        /* Termcap entry buffer pointer */
  1360.  
  1361.  
  1362.  
  1363. /*
  1364.  *  PSEUDO CODE
  1365.  *
  1366.  *    Begin tgetstr
  1367.  *        Initialize pointer to the termcap entry buffer.
  1368.  *        While there is a field to process
  1369.  *        Skip over the field separator character.
  1370.  *        If this is the entry we want then
  1371.  *            If the entry is not a string then
  1372.  *            Return NULL.
  1373.  *            Else
  1374.  *            Transfer string and rtn pointer.
  1375.  *            End if
  1376.  *        End if
  1377.  *        End while
  1378.  *        Return NULL
  1379.  *    End tgetstr
  1380.  *
  1381.  */
  1382.  
  1383. char *tgetstr(id,area)
  1384. char *id;
  1385. char **area;
  1386. {
  1387.     char *bp;
  1388.     extern char *index();
  1389.     char *decode();
  1390.  
  1391.     bp = _tcpbuf;
  1392.     while ((bp = index(bp,':')) != NULL) {
  1393.     if (*++bp == NULL)
  1394.         break;
  1395.     if (*bp++ == id[0] && *bp != NULL && *bp++ == id[1]) {
  1396.         if (*bp != NULL && *bp++ != '=') {
  1397.         return(NULL);
  1398.         } else {
  1399.         return(decode(bp,area));
  1400.         }
  1401.     }
  1402.     }
  1403.     **area = NULL;
  1404.     bp = (*area)++;
  1405.     return(bp);
  1406. }
  1407.  
  1408.  
  1409.  
  1410. /*
  1411.  *  INTERNAL FUNCTION
  1412.  *
  1413.  *    decode   transfer string capability, decoding escapes
  1414.  *
  1415.  *  SYNOPSIS
  1416.  *
  1417.  *    static char *decode(bp,area)
  1418.  *    char *bp;
  1419.  *    char **area;
  1420.  *
  1421.  *  DESCRIPTION
  1422.  *
  1423.  *    Transfers the string capability, up to the next ':'
  1424.  *    character, or null, to the buffer pointed to by
  1425.  *    the pointer in *area.  Note that the initial
  1426.  *    value of *area and *area is updated to point
  1427.  *    to the next available location after the null
  1428.  *    terminating the transfered string.
  1429.  *
  1430.  *  BUGS
  1431.  *
  1432.  *    There is no overflow checking done on the destination
  1433.  *    buffer, so it better be large enough to hold
  1434.  *    all expected strings.
  1435.  *
  1436.  */
  1437.  
  1438.  
  1439.  
  1440. /*
  1441.  *  PSEUDO CODE
  1442.  *
  1443.  *    Begin decode
  1444.  *        Initialize the transfer pointer.
  1445.  *        While there is an input character left to process
  1446.  *        Switch on input character
  1447.  *        Case ESCAPE:
  1448.  *            Decode and xfer the escaped sequence.
  1449.  *            Break
  1450.  *        Case CONTROLIFY:
  1451.  *            Controlify and xfer the next character.
  1452.  *            Advance the buffer pointer.
  1453.  *            Break
  1454.  *        Default:
  1455.  *            Xfer a normal character.
  1456.  *        End switch
  1457.  *        End while
  1458.  *        Null terminate the output string.
  1459.  *        Remember where the output string starts.
  1460.  *        Update the output buffer pointer.
  1461.  *        Return pointer to the output string.
  1462.  *    End decode
  1463.  *
  1464.  */
  1465.  
  1466. static char *decode(bp,area)
  1467. char *bp;
  1468. char **area;
  1469. {
  1470.     char *cp, *bgn;
  1471.     char *do_esc();
  1472.  
  1473.     cp = *area;
  1474.     while (*bp != NULL && *bp != ':') {
  1475.     switch(*bp) {
  1476.     case '\\':
  1477.         bp = do_esc(cp++,++bp);
  1478.         break;
  1479.     case '^':
  1480.         *cp++ = *++bp & 037;
  1481.         bp++;
  1482.         break;
  1483.     default:
  1484.         *cp++ = *bp++;
  1485.         break;
  1486.     }
  1487.     }
  1488.     *cp++ = NULL;
  1489.     bgn = *area;
  1490.     *area = cp;
  1491.     return(bgn);
  1492. }
  1493.  
  1494.  
  1495.  
  1496. /*
  1497.  *  INTERNAL FUNCTION
  1498.  *
  1499.  *    do_esc    process an escaped sequence
  1500.  *
  1501.  *  SYNOPSIS
  1502.  *
  1503.  *    char *do_esc(out,in);
  1504.  *    char *out;
  1505.  *    char *in;
  1506.  *
  1507.  *  DESCRIPTION
  1508.  *
  1509.  *    Processes an escape sequence pointed to by
  1510.  *    in, transfering it to location pointed to
  1511.  *    by out, and updating the pointer to in.
  1512.  *
  1513.  */
  1514.  
  1515.  
  1516.  
  1517. /*
  1518.  *  PSEUDO CODE
  1519.  *
  1520.  *    Begin do_esc
  1521.  *        If the first character is not a NULL then
  1522.  *        If is a digit then
  1523.  *            Set value to zero.
  1524.  *            For up to 3 digits
  1525.  *                Accumulate the sum.
  1526.  *            End for
  1527.  *            Transfer the sum.
  1528.  *            Else if character is in remap list then
  1529.  *            Transfer the remapped character.
  1530.  *            Advance the input pointer once.
  1531.  *            Else
  1532.  *            Simply transfer the character.
  1533.  *            End if
  1534.  *        End if
  1535.  *        Return updated input pointer.
  1536.  *    End do_esc
  1537.  *
  1538.  */
  1539.  
  1540. static char *maplist = {
  1541.     "E\033b\bf\fn\nr\rt\t"
  1542. };
  1543.  
  1544. char *do_esc(out,in)
  1545. char *out;
  1546. char *in;
  1547. {
  1548.     int count;
  1549.     char ch;
  1550.     extern char *index();
  1551.     char *cp;
  1552.  
  1553.     if (*in != NULL) {
  1554.     if (isdigit(*in)) {
  1555.         ch = 0;
  1556.         for (count = 0; count < 3 && isdigit(*in); in++) {
  1557.          ch <<= 3;
  1558.          ch |= (*in - '0');
  1559.         }
  1560.         *out++ = ch;
  1561.     } else if ((cp = index(maplist,*in)) != NULL) {
  1562.         *out++ = *++cp;
  1563.         in++;
  1564.     } else {
  1565.         *out++ = *in++;
  1566.     }
  1567.     }
  1568.     return(in);
  1569. }
  1570. SHAR_EOF
  1571. fi # end of overwriting check
  1572. if test -f 'sys/vms/termcap/tgoto.c'
  1573. then
  1574.     echo shar: will not over-write existing file "'sys/vms/termcap/tgoto.c'"
  1575. else
  1576. cat << \SHAR_EOF > 'sys/vms/termcap/tgoto.c'
  1577. /************************************************************************
  1578.  *                                    *
  1579.  *            Copyright (c) 1982, Fred Fish            *
  1580.  *                All Rights Reserved                *
  1581.  *                                    *
  1582.  *    This software and/or documentation is released for public    *
  1583.  *    distribution for personal, non-commercial use only.        *
  1584.  *    Limited rights to use, modify, and redistribute are hereby    *
  1585.  *    granted for non-commercial purposes, provided that all        *
  1586.  *    copyright notices remain intact and all changes are clearly    *
  1587.  *    documented.  The author makes no warranty of any kind with    *
  1588.  *    respect to this product and explicitly disclaims any implied    *
  1589.  *    warranties of merchantability or fitness for any particular    *
  1590.  *    purpose.                            *
  1591.  *                                    *
  1592.  ************************************************************************
  1593.  */
  1594. /*
  1595.  * Modified:
  1596.  *    1 May 86 ...!ihnp4!ut-sally!ut-ngp!mic
  1597.  *        Now forces a '\0' at end of tgoto string.  Tgoto wasn't,
  1598.  *        and this screwed up VT100-style (i.e. variable) cursor
  1599.  *        addressing.
  1600.  */
  1601.  
  1602.  
  1603.  
  1604. /*
  1605.  *  LIBRARY FUNCTION
  1606.  *
  1607.  *    tgoto   expand cursor addressing string from cm capability
  1608.  *
  1609.  *  KEY WORDS
  1610.  *
  1611.  *    termcap
  1612.  *
  1613.  *  SYNOPSIS
  1614.  *
  1615.  *    char *tgoto(cm,destcol,destline)
  1616.  *    char *cm;
  1617.  *    int destcol;
  1618.  *    int destline;
  1619.  *
  1620.  *  DESCRIPTION
  1621.  *
  1622.  *    Returns cursor addressing string, decoded from the cm
  1623.  *    capability string, to move cursor to column destcol on
  1624.  *    line destline.
  1625.  *
  1626.  *    The following sequences uses one input argument, either
  1627.  *    line or column, and place the appropriate substitution
  1628.  *    in the output string:
  1629.  *
  1630.  *        %d    substitute decimal value (in ASCII)
  1631.  *        %2    like %d but forces field width to 2
  1632.  *        %3    like %d but forces field width to 3
  1633.  *        %.    like %c
  1634.  *        %+x    like %c but adds ASCII value of x
  1635.  *
  1636.  *    The following sequences cause processing modifications
  1637.  *    but do not "use up" one of the arguments.  If they
  1638.  *    act on an argument they act on the next one to
  1639.  *    be converted.
  1640.  *
  1641.  *        %>xy    if next value to be converted is
  1642.  *            greater than value of ASCII char x
  1643.  *            then add value of ASCII char y.
  1644.  *        %r    reverse substitution of line
  1645.  *            and column (line is substituted
  1646.  *            first by default).
  1647.  *        %i    causes input values destcol and
  1648.  *            destline to be incremented.
  1649.  *        %%    gives single % character in output.
  1650.  *
  1651.  *  BUGS
  1652.  *
  1653.  *    Does not implement some of the more arcane sequences for
  1654.  *    radically weird terminals (specifically %n, %B, & %D).
  1655.  *    If you have one of these you deserve whatever happens.
  1656.  *
  1657.  */
  1658.  
  1659.  
  1660.  
  1661. /*
  1662.  *    Miscellaneous stuff
  1663.  */
  1664.  
  1665. #include <stdio.h>
  1666.  
  1667. #define MAXARGS 2
  1668.  
  1669. static char *in;        /* Internal copy of input string pointer */
  1670. static char *out;        /* Pointer to output array */
  1671. static int args[MAXARGS];    /* Maximum number of args to convert */
  1672. static int pcount;        /* Count of args processed */
  1673. static char output[64];        /* Converted string */
  1674.  
  1675.  
  1676.  
  1677.  
  1678. /*
  1679.  *  PSEUDO CODE
  1680.  *
  1681.  *    Begin tgoto
  1682.  *        If no string to process then
  1683.  *        Return pointer to error string.
  1684.  *        Else
  1685.  *        Initialize pointer to input string.
  1686.  *        Initialize pointer to result string.
  1687.  *        First arg is line number by default.
  1688.  *        Second arg is col number by default.
  1689.  *        No arguments processed yet.
  1690.  *        While there is another character to process
  1691.  *            If character is a not a % character then
  1692.  *            Simply copy to output.
  1693.  *            Else
  1694.  *            Process the control sequence.
  1695.  *            End if
  1696.  *        End while
  1697.  *        Return pointer to static output string.
  1698.  *        End if
  1699.  *    End tgoto
  1700.  *
  1701.  */
  1702.  
  1703. char *tgoto(cm,destcol,destline)
  1704. char *cm;
  1705. int destcol;
  1706. int destline;
  1707. {
  1708.     if (cm == NULL) {
  1709.     return("OOPS");
  1710.     } else {
  1711.     in = cm;
  1712.     out = output;
  1713.     args[0] = destline;
  1714.     args[1] = destcol;
  1715.     pcount = 0;
  1716.     while (*in != NULL) {
  1717.         if (*in != '%') {
  1718.         *out++ = *in++;
  1719.         } else {
  1720.         process();
  1721.         }
  1722.     }
  1723.     *out = NULL;    /* Just to make sure */
  1724.     return(output);
  1725.     }
  1726. }
  1727.  
  1728.  
  1729.  
  1730. /*
  1731.  *  INTERNAL FUNCTION
  1732.  *
  1733.  *    process   process the conversion/command sequence
  1734.  *
  1735.  *  SYNOPSIS
  1736.  *
  1737.  *    static process()
  1738.  *
  1739.  *  DESCRIPTION
  1740.  *
  1741.  *    Processes the sequence beginning with the % character.
  1742.  *    Directly manipulates the input string pointer, the
  1743.  *    output string pointer, and the arguments.  Leaves
  1744.  *    the input string pointer pointing to the next character
  1745.  *    to be processed, and the output string pointer pointing
  1746.  *    to the next output location.  If conversion of
  1747.  *    one of the numeric arguments occurs, then the pcount
  1748.  *    is incremented.
  1749.  *
  1750.  */
  1751.  
  1752.  
  1753.  
  1754. /*
  1755.  *  PSEUDO CODE
  1756.  *
  1757.  *    Begin process
  1758.  *        Skip over the % character.
  1759.  *        Switch on next character after %
  1760.  *        Case 'd':
  1761.  *        Process %d type conversion (variable width).
  1762.  *        Reinitialize output pointer.
  1763.  *        Break;
  1764.  *        Case '2':
  1765.  *        Process %d type conversion (width 2).
  1766.  *        Reinitialize output pointer.
  1767.  *        Break;
  1768.  *        Case '3':
  1769.  *        Process %d type conversion (width 3).
  1770.  *        Reinitialize output pointer.
  1771.  *        Break;
  1772.  *        Case '.'
  1773.  *        Process %c type conversion.
  1774.  *        Break;
  1775.  *        Case '+':
  1776.  *        Process %c type conversion with offset.
  1777.  *        Break;
  1778.  *        Case '>':
  1779.  *        Process argument modification.
  1780.  *        Break;
  1781.  *        Case 'r':
  1782.  *        Process argument reversal.
  1783.  *        Break;
  1784.  *        Case 'i':
  1785.  *        Increment argument values.
  1786.  *        Break;
  1787.  *        Case '%':
  1788.  *        Copy to output, incrementing pointers.
  1789.  *        Break;
  1790.  *        End switch
  1791.  *    End process
  1792.  *
  1793.  */
  1794.  
  1795.  
  1796.  
  1797.  
  1798. static process()
  1799. {
  1800.     int temp;
  1801.  
  1802.     in++;
  1803.     switch(*in++) {
  1804.     case 'd':
  1805.     sprintf(out,"%d",args[pcount++]);
  1806.     out = &output[strlen(output)];    
  1807.     break;
  1808.     case '2':
  1809.     sprintf(out,"%02d",args[pcount++]);
  1810.     out = &output[strlen(output)];
  1811.     break;
  1812.     case '3':
  1813.     sprintf(out,"%03d",args[pcount++]);
  1814.     out = &output[strlen(output)];
  1815.     break;
  1816.     case '.':
  1817.     *out++ = args[pcount++];
  1818.     break;
  1819.     case '+':
  1820.     *out++ = args[pcount++] + *in++;
  1821.     break;
  1822.     case '>':
  1823.     if (args[pcount] > *in++) {
  1824.         args[pcount] += *in++;
  1825.     } else {
  1826.         in++;
  1827.     }
  1828.     break;
  1829.     case 'r':
  1830.     temp = args[pcount];
  1831.     args[pcount] = args[pcount+1];
  1832.     args[pcount+1] = temp;
  1833.     break;
  1834.     case 'i':
  1835.     args[pcount]++;
  1836.     args[pcount+1]++;
  1837.     break;
  1838.     case '%':
  1839.     *out++ = '%';
  1840.     break;
  1841.     }
  1842. }
  1843. SHAR_EOF
  1844. fi # end of overwriting check
  1845. if test -f 'sys/vms/termcap/tputs.c'
  1846. then
  1847.     echo shar: will not over-write existing file "'sys/vms/termcap/tputs.c'"
  1848. else
  1849. cat << \SHAR_EOF > 'sys/vms/termcap/tputs.c'
  1850. /************************************************************************
  1851.  *                                    *
  1852.  *            Copyright (c) 1982, Fred Fish            *
  1853.  *                All Rights Reserved                *
  1854.  *                                    *
  1855.  *    This software and/or documentation is released for public    *
  1856.  *    distribution for personal, non-commercial use only.        *
  1857.  *    Limited rights to use, modify, and redistribute are hereby    *
  1858.  *    granted for non-commercial purposes, provided that all        *
  1859.  *    copyright notices remain intact and all changes are clearly    *
  1860.  *    documented.  The author makes no warranty of any kind with    *
  1861.  *    respect to this product and explicitly disclaims any implied    *
  1862.  *    warranties of merchantability or fitness for any particular    *
  1863.  *    purpose.                            *
  1864.  *                                    *
  1865.  ************************************************************************
  1866.  */
  1867. /* Modified:
  1868.  * 30-Apr-86 Mic Kaczmarczik
  1869.  *         - Use ctype.h macros instead of the function isdigit().
  1870.  *         - Use VMS speed value for ospeed -- in microEmacs
  1871.  *           this is obtainted by ttinit().
  1872.  */
  1873.  
  1874.  
  1875.  
  1876.  
  1877. /*
  1878.  *  LIBRARY FUNCTION
  1879.  *
  1880.  *    tputs     output string with appropriate padding
  1881.  *
  1882.  *  KEY WORDS
  1883.  *
  1884.  *    termcap
  1885.  *
  1886.  *  SYNOPSIS
  1887.  *
  1888.  *    tputs(cp,affcnt,outc)
  1889.  *    char *cp;
  1890.  *    int affcnt;
  1891.  *    int (*outc)();
  1892.  *
  1893.  *  DESCRIPTION
  1894.  *
  1895.  *    Outputs string pointed to by cp, using function outc, and
  1896.  *    following it with the appropriate number of padding characters.
  1897.  *    Affcnt contains the number of lines affected, which is used
  1898.  *    as a multiplier for the specified per line pad time.  If
  1899.  *    per line pad count is not applicable, affcnt should be 1,
  1900.  *    NOT zero.
  1901.  *
  1902.  *    The format of the string pointed to by cp is:
  1903.  *
  1904.  *        [pad time][*]<string to send>
  1905.  *
  1906.  *        where:    pad time => time to delay in milliseconds
  1907.  *            * => specifies that time is per line
  1908.  *            
  1909.  *    The pad character is assumed to reside in the external
  1910.  *    variable "PC".  Also, the external variable "ospeed"
  1911.  *    should contain the output speed of the terminal as
  1912.  *    encoded in /usr/include/sgtty.h  (B0-B9600).
  1913.  *
  1914.  * SYSTEM DEPENDENCIES
  1915.  *
  1916.  *    On VMS, the external variable "ospeed" should contain the
  1917.  *    output speed of the terminal as obtained from byte 3 of
  1918.  *    the iosb status buffer, using the IO$_SENSEMODE QIO.
  1919.  *    The table times[] compiles into the correct values for VMS,
  1920.  *    and, happily, also handles 19200 baud.
  1921.  *
  1922.  *  BUGS
  1923.  *
  1924.  *    If ospeed is 0 for some reason, there is the chance of a
  1925.  *    divide by 0 operation.
  1926.  *
  1927.  */
  1928.  
  1929.  
  1930.  
  1931. /*
  1932.  *    Miscellaneous stuff
  1933.  */
  1934.  
  1935. #include <stdio.h>
  1936. #include <ctype.h>
  1937.  
  1938. extern char PC;            /* Pad character to use */
  1939. extern short ospeed;        /* Encoding of output speed */
  1940.  
  1941. #if    VMS
  1942. static int times[] = {
  1943.     10000,            /* Tenths of ms per char     0 baud (bogus) */
  1944.     2000,            /* Tenths of ms per char    50 baud */
  1945.     1333,            /* Tenths of ms per char    75 baud */
  1946.     909,            /* Tenths of ms per char   110 baud */
  1947.     743,            /* Tenths of ms per char   134 baud */
  1948.     666,            /* Tenths of ms per char   150 baud */
  1949.     333,            /* Tenths of ms per char   300 baud */
  1950.     166,            /* Tenths of ms per char   600 baud */
  1951.     83,                /* Tenths of ms per char  1200 baud */
  1952.     55,                /* Tenths of ms per char  1800 baud */
  1953.     50,                /* Tenths of ms per char  2000 baud */
  1954.     41,                /* Tenths of ms per char  2400 baud */
  1955.     28,                /* Tenths of ms per char  3600 baud */
  1956.     20,                /* Tenths of ms per char  4800 baud */
  1957.     14,                /* Tenths of ms per char  7200 baud */
  1958.     10,                /* Tenths of ms per char  9600 baud */
  1959.     5                /* Tenths of ms per char 19200 baud */
  1960. };
  1961. #else
  1962. /* Times for Unix */
  1963. static int times[] = {
  1964.     0,                /* Tenths of ms per char 0 baud */
  1965.     2000,            /* Tenths of ms per char 50 baud */
  1966.     1333,            /* Tenths of ms per char 75 baud */
  1967.     909,            /* Tenths of ms per char 110 baud */
  1968.     743,            /* Tenths of ms per char 134 baud */
  1969.     666,            /* Tenths of ms per char 150 baud */
  1970.     500,            /* Tenths of ms per char 200 baud */
  1971.     333,            /* Tenths of ms per char 300 baud */
  1972.     166,            /* Tenths of ms per char 600 baud */
  1973.     83,                /* Tenths of ms per char 1200 baud */
  1974.     55,                /* Tenths of ms per char 1800 baud */
  1975.     41,                /* Tenths of ms per char 2400 baud */
  1976.     20,                /* Tenths of ms per char 4800 baud */
  1977.     10                /* Tenths of ms per char 9600 baud */
  1978. };
  1979. #endif
  1980.  
  1981.  
  1982.  
  1983.  
  1984. /*
  1985.  *  PSEUDO CODE
  1986.  *
  1987.  *    Begin tgoto
  1988.  *        If string pointer is invalid then
  1989.  *        Return without doing anything.
  1990.  *        Else
  1991.  *        For each pad digit (if any)
  1992.  *            Do decimal left shift.
  1993.  *            Accumulate the lower digit.
  1994.  *        End for
  1995.  *        Adjust scale to tenths of milliseconds
  1996.  *        If there is a fractional field
  1997.  *            Skip the decimal point.
  1998.  *            If there is a valid tenths digit
  1999.  *            Accumulate the tenths.
  2000.  *            End if
  2001.  *            Discard remaining digits.
  2002.  *        End if
  2003.  *        If per line is specified then
  2004.  *            Adjust the pad time.
  2005.  *            Discard the per line flag char.
  2006.  *        End if
  2007.  *        While there are any characters left
  2008.  *            Send them out via output function.
  2009.  *        End while
  2010.  *        Transmit any padding required.
  2011.  *        End if
  2012.  *    End tgoto
  2013.  *
  2014.  */
  2015.  
  2016. tputs(cp,affcnt,outc)
  2017. char *cp;
  2018. int affcnt;
  2019. int (*outc)();
  2020. {
  2021.     int ptime;            /* Pad time in tenths of milliseconds */
  2022.  
  2023.     if (cp == NULL || *cp == NULL) {
  2024.     return;
  2025.     } else {
  2026.     for (ptime = 0; isdigit(*cp); cp++) {
  2027.         ptime *= 10;
  2028.         ptime += (*cp - '0');
  2029.     }
  2030.     ptime *= 10;
  2031.     if (*cp == '.') {
  2032.         cp++;
  2033.         if (isdigit(*cp)) {
  2034.         ptime += (*cp++ - '0');
  2035.         }
  2036.         while (isdigit(*cp)) {cp++;}
  2037.     }
  2038.     if (*cp == '*') {
  2039.         ptime *= affcnt;
  2040.         cp++;
  2041.     }
  2042.     while (*cp != NULL) {
  2043.         (*outc)(*cp++);
  2044.     }
  2045.     do_padding(ptime,outc);
  2046.     }
  2047. }
  2048.  
  2049.  
  2050.  
  2051. /*
  2052.  *  FUNCTION
  2053.  *
  2054.  *    do_padding    transmit any pad characters required
  2055.  *
  2056.  *  SYNOPSIS
  2057.  *
  2058.  *    static do_padding(ptime,outc)
  2059.  *    int ptime;
  2060.  *    int (*outc)();
  2061.  *
  2062.  *  DESCRIPTION
  2063.  *
  2064.  *    Does any padding required as specified by ptime (in tenths
  2065.  *    of milliseconds), the output speed given in the external
  2066.  *    variable ospeed, and the pad character given in the
  2067.  *    external variable PC.
  2068.  *
  2069.  */
  2070.  
  2071.  
  2072.  
  2073. /*
  2074.  *  PSEUDO CODE
  2075.  *
  2076.  *    Begin do_padding
  2077.  *        If there is a non-zero pad time then
  2078.  *        If the external speed is in range then
  2079.  *            Look up the delay per pad character.
  2080.  *            Round pad time up by half a character.
  2081.  *            Compute number of characters to send.
  2082.  *            For each pad character to send
  2083.  *            Transmit the pad character.
  2084.  *            End for
  2085.  *        End if
  2086.  *        End if
  2087.  *    End do_padding
  2088.  *
  2089.  */
  2090.  
  2091. static do_padding(ptime,outc)
  2092. int ptime;
  2093. int (*outc)();
  2094. {
  2095.     register int nchars;
  2096.     register int tpc;
  2097.  
  2098.     if (ptime >= 0) {
  2099.     if (ospeed >= 0 && ospeed <= (sizeof(times)/ sizeof(int))) {
  2100.         tpc = times[ospeed];
  2101.         ptime += (tpc / 2);
  2102.         nchars = ptime / tpc;
  2103.         for ( ; nchars > 0; --nchars) {
  2104.         (*outc)(PC);
  2105.         }
  2106.     }
  2107.     }
  2108. }
  2109. SHAR_EOF
  2110. fi # end of overwriting check
  2111. if test -f 'sys/vms/termcap/ttest.c'
  2112. then
  2113.     echo shar: will not over-write existing file "'sys/vms/termcap/ttest.c'"
  2114. else
  2115. cat << \SHAR_EOF > 'sys/vms/termcap/ttest.c'
  2116. /************************************************************************
  2117.  *                                    *
  2118.  *            Copyright (c) 1982, Fred Fish            *
  2119.  *                All Rights Reserved                *
  2120.  *                                    *
  2121.  *    This software and/or documentation is released for public    *
  2122.  *    distribution for personal, non-commercial use only.        *
  2123.  *    Limited rights to use, modify, and redistribute are hereby    *
  2124.  *    granted for non-commercial purposes, provided that all        *
  2125.  *    copyright notices remain intact and all changes are clearly    *
  2126.  *    documented.  The author makes no warranty of any kind with    *
  2127.  *    respect to this product and explicitly disclaims any implied    *
  2128.  *    warranties of merchantability or fitness for any particular    *
  2129.  *    purpose.                            *
  2130.  *                                    *
  2131.  ************************************************************************
  2132.  */
  2133.  
  2134.  
  2135.  
  2136. /*
  2137.  *  TEST PROGRAM
  2138.  *
  2139.  *    testtcp   test termcap functions
  2140.  *
  2141.  *  KEY WORDS
  2142.  *
  2143.  *    test routines
  2144.  *    termcap test
  2145.  *
  2146.  *  SYNOPSIS
  2147.  *
  2148.  *    termcap [-efns] terminal [capability [capability ...]]
  2149.  *
  2150.  *        -e  =>   expand string capability given by -s
  2151.  *        -f  =>   determine boolean capabilities for terminal
  2152.  *        -n  =>   determine numeric capabilities for terminal
  2153.  *        -s  =>   determine string capabilities for terminal
  2154.  *
  2155.  *        terminal =>  terminal name as given in termcap file
  2156.  *        capability => a boolean, numeric, or string capability
  2157.  *
  2158.  *        NOTE:  All capabilities must be of same type, as
  2159.  *               given by [-fns].
  2160.  *
  2161.  *        If terminal is only argument then entire entry is
  2162.  *        printed.
  2163.  *
  2164.  *  DESCRIPTION
  2165.  *
  2166.  *    Provides way to test termcap functions.  Can find
  2167.  *    and print an entire termcap terminal entry, or various
  2168.  *    capabilities from the entry.
  2169.  *
  2170.  *  AUTHOR
  2171.  *
  2172.  *    Fred Fish
  2173.  *
  2174.  */
  2175.  
  2176. #include <stdio.h>
  2177.  
  2178. #define TRUE 1
  2179. #define FALSE 0
  2180. #define NO_FILE     -1            /* Returned if can't open file */
  2181. #define NO_ENTRY  0            /* Returned if can't find entry */
  2182. #define SUCCESS   1            /* Returned if entry found ok */
  2183. #define TRUNCATED 2            /* Returned if entry found but trunc */
  2184. #define BUFFER_SIZE 1024
  2185.  
  2186. int eflag = FALSE;
  2187. int fflag = FALSE;
  2188. int nflag = FALSE;
  2189. int sflag = FALSE;
  2190.  
  2191. int got_terminal = FALSE;
  2192. int got_capability = FALSE;
  2193.  
  2194. int ospeed = 15;    /* fake lots of padding */
  2195.  
  2196.  
  2197. /*
  2198.  *  FUNCTION
  2199.  *
  2200.  *    main   termcap test entry point
  2201.  *
  2202.  *  KEY WORDS
  2203.  *
  2204.  *    main
  2205.  *
  2206.  *  SYNOPSIS
  2207.  *
  2208.  *    main(argc,argv)
  2209.  *    int argc;
  2210.  *    char *argv[];
  2211.  *
  2212.  *  DESCRIPTION
  2213.  *
  2214.  *    This is where the termcap test starts executing.  All argument list
  2215.  *    switches are processed first, then all the specified
  2216.  *    capability identification strings are processed.
  2217.  *
  2218.  */
  2219.  
  2220.  
  2221. /*
  2222.  *  PSEUDO CODE
  2223.  *
  2224.  *    Begin main
  2225.  *        Process command line options.
  2226.  *        For each argument list field
  2227.  *        If field was not erased during option processing
  2228.  *            If terminal name field not yet processed then
  2229.  *            Process an assumed terminal name field.
  2230.  *            Set terminal name processed flag.
  2231.  *            Else
  2232.  *            Process a capability field.
  2233.  *            Set capability field processed flag.
  2234.  *            End if
  2235.  *        End if
  2236.  *        End for
  2237.  *        If no capabilities processed then
  2238.  *        Simply dump buffer.
  2239.  *        End if
  2240.  *    End main
  2241.  *
  2242.  */
  2243.  
  2244. main(argc, argv)
  2245. int argc;
  2246. char *argv[];
  2247. {
  2248.     char *argp;
  2249.     int argnum;
  2250.     char buffer[BUFFER_SIZE];
  2251.  
  2252.     options(argc,argv);
  2253.     for (argnum = 1; argnum < argc; argnum++) {
  2254.         if ((argp = argv[argnum]) != NULL) {
  2255.         if (!got_terminal) {
  2256.         terminal(buffer,argp);
  2257.         got_terminal = TRUE;
  2258.         } else {
  2259.         capability(argp);
  2260.         got_capability = TRUE;
  2261.         }
  2262.         }
  2263.     }
  2264.     if (got_terminal && !got_capability) {
  2265.     printf("size = %d\n%s",strlen(buffer),buffer);
  2266.     }
  2267. }
  2268.  
  2269.  
  2270. /*
  2271.  *  FUNCTION
  2272.  *
  2273.  *    options   process command line options
  2274.  *
  2275.  *  SYNOPSIS
  2276.  *
  2277.  *    options(argc,argv)
  2278.  *    int argc;
  2279.  *    char *argv[];
  2280.  *
  2281.  *  DESCRIPTION
  2282.  *
  2283.  *    Scans argument list, processing each switch as it is
  2284.  *    found.  The pointer to each switch string is then
  2285.  *    replaced with a NULL to effectively erase the switch
  2286.  *    argument.
  2287.  *
  2288.  */
  2289.  
  2290.  
  2291. /*
  2292.  *  PSEUDO CODE
  2293.  *
  2294.  *    Begin options
  2295.  *        For each argument in the argument list
  2296.  *        Get pointer to first char of argument.
  2297.  *        If the argument is a switch then
  2298.  *            Replace argument pointer with NULL.
  2299.  *            Look at next argument character.
  2300.  *            While there is another argument character
  2301.  *            Switch on the argument character
  2302.  *            Case "EXPAND":
  2303.  *                Set expand (e) flag.
  2304.  *                Break out of switch.
  2305.  *            Case "BOOLEAN":
  2306.  *                Set boolean (f) flag.
  2307.  *                Break out of switch.
  2308.  *            Case "NUMERIC":
  2309.  *                Set numeric flag.
  2310.  *                Break out of switch.
  2311.  *            Case "STRING":
  2312.  *                Set string flag.
  2313.  *                Break out of switch.
  2314.  *            Default:
  2315.  *                Abort with usage message.
  2316.  *            End switch
  2317.  *            End while
  2318.  *        End if
  2319.  *        End for
  2320.  *    End options
  2321.  *
  2322.  */
  2323.  
  2324.  
  2325. options(argc, argv)
  2326. int argc;
  2327. char *argv[];
  2328. {
  2329.     int i;
  2330.     char c;        /* 1st char of current command-line argument */
  2331.     char *cp;        /* current argument pointer */
  2332.  
  2333.     for (i=1; i<argc; i++) {
  2334.         cp = argv[i];
  2335.         if (*cp == '-') {
  2336.             argv[i] = NULL;
  2337.         cp++;
  2338.         while (c = *cp++) {
  2339.             switch (c) {
  2340.         case 'e':
  2341.             eflag = TRUE;
  2342.             break;
  2343.         case 'f':
  2344.             fflag = TRUE;
  2345.                 break;
  2346.             case 'n':
  2347.             nflag = TRUE;
  2348.                 break;
  2349.             case 's':
  2350.             sflag = TRUE;
  2351.                 break;
  2352.             default:
  2353.                 usage();
  2354.             }
  2355.             }
  2356.         }
  2357.     }
  2358. }
  2359.  
  2360.  
  2361. /*
  2362.  *  FUNCTION
  2363.  *
  2364.  *    usage   give usage message and abort
  2365.  *
  2366.  *  KEY WORDS
  2367.  *
  2368.  *    usage
  2369.  *    help processing
  2370.  *    abort locations
  2371.  *
  2372.  *  SYNOPSIS
  2373.  *
  2374.  *    usage()
  2375.  *
  2376.  *  DESCRIPTION
  2377.  *
  2378.  *    Usage is typically called when a problem has been
  2379.  *    detected in the argument list.
  2380.  *    It prints a usage message and exits.
  2381.  *
  2382.  */
  2383.  
  2384.  
  2385. /*
  2386.  *  PSEUDO CODE
  2387.  *
  2388.  *    Begin usage
  2389.  *        Print usage message.
  2390.  *        Exit.
  2391.  *    End usage
  2392.  *
  2393.  */
  2394.  
  2395. usage()
  2396. {
  2397.     printf("Usage: termcap [-fns] terminal [capability [capability ... ]]\n");
  2398.     exit();
  2399. }
  2400.  
  2401.  
  2402.  
  2403. terminal(buffer,name)
  2404. char *buffer;
  2405. char *name;
  2406. {
  2407.     int status;
  2408.  
  2409.     status = tgetent(buffer,name);
  2410.     switch (status) {
  2411.     case NO_FILE:
  2412.     fprintf(stderr,"Can't find a termcap data base file.\n");
  2413.     exit();
  2414.     case NO_ENTRY:
  2415.     fprintf(stderr,"Can't find entry \"%s\"\n",name);
  2416.     exit();
  2417.     case TRUNCATED:
  2418.     fprintf(stderr,"Warning --- entry \"%s\" too long\n",name);
  2419.     break;
  2420.     case SUCCESS:
  2421.         break;
  2422.     default:
  2423.         fprintf(stderr,"? tgetent returned illegal status %d\n",status);
  2424.     exit();
  2425.     }
  2426. }
  2427.  
  2428.  
  2429. capability(id)
  2430. char *id;
  2431. {
  2432.     int value;
  2433.     char buffer[256];
  2434.     char *area;
  2435.     char *ep, *tgoto();
  2436.  
  2437.     if (fflag) {
  2438.     value = tgetflag(id);
  2439.     if (value) {
  2440.         printf("%s TRUE\n",id);
  2441.     } else {
  2442.         printf("%s FALSE\n",id);
  2443.     }
  2444.     } else if (nflag) {
  2445.     value = tgetnum(id);
  2446.     printf("%s = %o octal %d decimal\n",id,value,value);
  2447.     } else if (sflag) {
  2448.     area = buffer;
  2449.     tgetstr(id,&area);
  2450.     if (eflag) {
  2451.         ep = tgoto(buffer,75,23);
  2452.     }
  2453.     doprint(id,buffer);
  2454.     if (eflag) {
  2455.         doprint(id,ep);
  2456.         ep = tgoto(buffer,1,2);
  2457.         doprint(id,ep);
  2458.     }
  2459.     }
  2460. }
  2461.  
  2462.  
  2463. /*
  2464.  *  Use tputs to get a clearer picture of exactly what
  2465.  *  goes out to the terminal....
  2466.  */
  2467.  
  2468. princ(c)
  2469. int c;
  2470. {
  2471.     if (c < 040)
  2472.         printf("^%c",c |= 0100);
  2473.     else
  2474.         printf("%c",c);
  2475. }
  2476.  
  2477. doprint(id,cp)
  2478. char *id;
  2479. char *cp;
  2480. {
  2481.     printf("%s = \"",id);
  2482.     tputs(cp, 1, princ);
  2483.     printf("\"\n");
  2484. }
  2485.  
  2486. SHAR_EOF
  2487. fi # end of overwriting check
  2488. if test -f 'sys/vms/termcap/createlib.com'
  2489. then
  2490.     echo shar: will not over-write existing file "'sys/vms/termcap/createlib.com'"
  2491. else
  2492. cat << \SHAR_EOF > 'sys/vms/termcap/createlib.com'
  2493. $!
  2494. $! Command procedure to compile and create VMS termcap library
  2495. $!
  2496. $    ccom := @[-]ccom.com        ! Checks file dates
  2497. $!    ccom := cc            ! To force a recompile
  2498. $!
  2499. $    ccom fgetlr
  2500. $    ccom tgetent
  2501. $    ccom tgetflag
  2502. $    ccom tgetnum
  2503. $    ccom tgetstr
  2504. $    ccom tgoto
  2505. $    ccom tputs
  2506. $!
  2507. $ library/create/object termcap.olb fgetlr.obj,tgetent.obj,-
  2508. tgetflag.obj,tgetnum.obj,tgetstr.obj,tgoto.obj,tputs.obj
  2509. $ purge/keep=2 termcap.olb
  2510. SHAR_EOF
  2511. fi # end of overwriting check
  2512. if test -f 'sys/vms/termcap/makelib.com'
  2513. then
  2514.     echo shar: will not over-write existing file "'sys/vms/termcap/makelib.com'"
  2515. else
  2516. cat << \SHAR_EOF > 'sys/vms/termcap/makelib.com'
  2517. $!
  2518. $! Command procedure to make new VMS termcap library
  2519. $!
  2520. $ Library/Create/Object Termcap.Olb Fgetlr.Obj,Tgetent.Obj,-
  2521. Tgetflag.Obj,Tgetnum.Obj,Tgetstr.Obj,Tgoto.Obj,Tputs.Obj
  2522. $ Purge/Keep=2 Termcap.Olb
  2523. SHAR_EOF
  2524. fi # end of overwriting check
  2525. if test -f 'sys/vms/termcap/makefile'
  2526. then
  2527.     echo shar: will not over-write existing file "'sys/vms/termcap/makefile'"
  2528. else
  2529. cat << \SHAR_EOF > 'sys/vms/termcap/makefile'
  2530. #
  2531. #  FILE
  2532. #
  2533. #    Makefile    build termcap library
  2534. #
  2535. #  KEY WORDS
  2536. #
  2537. #    libraries
  2538. #    test functions
  2539. #
  2540. #  SYNOPSIS
  2541. #
  2542. #    make        compile the library sources
  2543. #    make tests    compile sources for tests
  2544. #
  2545. #  DESCRIPTION
  2546. #
  2547. #    Standard make file for building the termcap library and tests.
  2548. #
  2549. #  AUTHOR
  2550. #
  2551. #    Fred Fish
  2552. #
  2553.  
  2554. CC =        cc
  2555.  
  2556. TSOURCES =    testtcp.c 
  2557. LSOURCES =    tgetent.c tgetflag.c tgetnum.c tgetstr.c tgoto.c tputs.c
  2558.  
  2559.  
  2560. TOBJECTS =    testtcp.o
  2561. LOBJECTS =    tgetent.o tgetflag.o tgetnum.o tgetstr.o tgoto.o tputs.o
  2562.  
  2563. all :        library tests
  2564.  
  2565. library :    $(LOBJECTS)
  2566.  
  2567. tgetent.o :    tgetent.c
  2568.         $(CC) -c $(CFLAGS) tgetent.c
  2569.  
  2570. tgetflag.o :    tgetflag.c
  2571.         $(CC) -c $(CFLAGS) tgetflag.c
  2572.  
  2573. tgetnum.o :    tgetnum.c
  2574.         $(CC) -c $(CFLAGS) tgetnum.c
  2575.  
  2576. tgetstr.o :    tgetstr.c
  2577.         $(CC) -c $(CFLAGS) tgetstr.c
  2578.  
  2579. tgoto.o :    tgoto.c
  2580.         $(CC) -c $(CFLAGS) tgoto.c
  2581.  
  2582. tputs.o :    tputs.c
  2583.         $(CC) -c $(CFLAGS) tputs.c
  2584.  
  2585. tests :        testtcp
  2586.  
  2587. testtcp :    testtcp.o
  2588.         $(CC) -o testtcp testtcp.o -ltermcap
  2589.  
  2590. testtcp.o :    testtcp.c
  2591.         $(CC) -c $(CFLAGS) testtcp.c
  2592.  
  2593. #
  2594. #    Clean up the directory.
  2595. #
  2596.  
  2597. clean:
  2598.         rm -f *.o *.BAK *.bak nohup.out *.CKP *.tmp 
  2599. SHAR_EOF
  2600. fi # end of overwriting check
  2601. #    End of shell archive
  2602. exit 0
  2603.  
  2604.