home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0636.ZIP / CCE_0636 / CURSES / CRSSRC12.ZOO / src / tgetnum.c < prev    next >
C/C++ Source or Header  |  1991-09-27  |  2KB  |  116 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1982, Fred Fish            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  *    This software and/or documentation is released for public    *
  7.  *    distribution for personal, non-commercial use only.        *
  8.  *    Limited rights to use, modify, and redistribute are hereby    *
  9.  *    granted for non-commercial purposes, provided that all        *
  10.  *    copyright notices remain intact and all changes are clearly    *
  11.  *    documented.  The author makes no warranty of any kind with    *
  12.  *    respect to this product and explicitly disclaims any implied    *
  13.  *    warranties of merchantability or fitness for any particular    *
  14.  *    purpose.                            *
  15.  *                                    *
  16.  ************************************************************************
  17.  */
  18.  
  19.  
  20. /*
  21.  *  LIBRARY FUNCTION
  22.  *
  23.  *    tgetnum   extract numeric option from termcap entry
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *    termcap
  28.  *    ce functions
  29.  *
  30.  *  SYNOPSIS
  31.  *
  32.  *    tgetnum(id)
  33.  *    char *id;
  34.  *
  35.  *  DESCRIPTION
  36.  *
  37.  *    Returns numeric value of capability <id>, or -1 if <id>
  38.  *    is not found.   Knows about octal numbers, which
  39.  *    begin with 0.
  40.  *
  41.  */
  42.  
  43. #include <stdio.h>
  44. #include <ctype.h>
  45. #include <string.h>
  46. #include <termcap.h>
  47.  
  48. #ifndef _COMPILER_H
  49. #  include <compiler.h>
  50. #endif
  51.  
  52. # ifdef MSDOS
  53. # define index strchr
  54. # endif
  55.  
  56. extern char *_tcpbuf;        /* Termcap entry buffer pointer */
  57.  
  58. /*
  59.  *  PSEUDO CODE
  60.  *
  61.  *    Begin tgetnum
  62.  *        Initialize pointer to the termcap entry buffer.
  63.  *        While there is a field to process
  64.  *        Skip over the field separator character.
  65.  *        If this is the entry we want then
  66.  *            If the entry is not a numeric then
  67.  *            Return failure value.
  68.  *            Else
  69.  *            Initialize value to zero.
  70.  *            If number begins with zero then
  71.  *                Set accumulation base to 8.
  72.  *            Else
  73.  *                Set accumulation base to 10.
  74.  *            End if
  75.  *            While there is a numeric character
  76.  *                Accumulate the value.
  77.  *            End while
  78.  *            Return value.
  79.  *            End if
  80.  *        End if
  81.  *        End while
  82.  *        Return failure value.
  83.  *    End tgetnum
  84.  *
  85.  */
  86.  
  87. int tgetnum(id)
  88. char *id;
  89. {
  90.     int value, base;
  91.     char *bp;
  92.  
  93.     bp = _tcpbuf;
  94.     while ((bp = index(bp,':')) != NULL) {
  95.     bp++;
  96.     if (*bp++ == id[0] && *bp != '\0' && *bp++ == id[1]) {
  97.         if (*bp != '\0' && *bp++ != '#') {
  98.         return(-1);
  99.         } else {
  100.         value = 0;
  101.         if (*bp == '0') {
  102.             base = 8;
  103.         } else {
  104.             base = 10;
  105.         }
  106.         while (isdigit(*bp)) {
  107.             value *= base;
  108.             value += (*bp++ - '0');
  109.         }
  110.         return(value);
  111.         }
  112.     }
  113.     }
  114.     return(-1);
  115. }
  116.