home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / researchmachines / rmlcsu.c < prev    next >
Text File  |  1985-07-10  |  3KB  |  189 lines

  1. /* File  KCSUPP.C  -  Useful routines for C programs;
  2.         Chris Kennington.    RML.    5th July 1985. */
  3.  
  4. #include  "stdio.h"
  5.  
  6. #define  CTLC    0x03
  7. #define  BKSP    0x08
  8. #define  TAB    0x09
  9. #define  CR    0x0d
  10. #define  LF    0x0a
  11. #define  SP    0x20
  12.  
  13. extern    char    blanx[], null[], pager, scrline;
  14.  
  15.  
  16.  
  17. bell()
  18. {
  19.     putchar(0x07);
  20.     return;
  21. }
  22.  
  23.  
  24.  
  25. blockmv(to,from,len)        /* move block of memory        */
  26. char    *to, *from;
  27. int    len;
  28. /* convert to new routine movmem() by parm swapping        */
  29. {
  30.     movmem(from,to,len);
  31.     return;
  32. }                /* end of blockmv()        */
  33.  
  34.  
  35.  
  36. clrscrn()        /* clear scrolling screen    */
  37. {
  38.     int        i;
  39.  
  40.     for (i=5; i<25; ++i)
  41.     vtline(i*256,blanx);
  42.     curset(6,0);
  43.     return;
  44. }            /* end of clrscrn()        */
  45.  
  46.  
  47.  
  48. char  decol8(line,arr,num)    /* decollate command-line    */
  49. /* Splits up line into sections delimited by controls or blanks,
  50.      zeros all such chars & places start-addresses into array,
  51.      up to maximum of num entries; zeros rest of entries and
  52.      returns count of valid entries.            */
  53. char  *line, *arr[], num;
  54. {
  55.     char  c, count, i, j, *start;
  56.  
  57.     j = count = 0;
  58.     start = line;
  59.     for (i=0; i<80, j<num; ++i) {
  60.     if ( ( (c = line[i]) <= SP) || (c == '=') ) {
  61.         line[i] = 0;    /* terminator        */
  62.         if (count > 0) {
  63.         arr[j++] = start;
  64.         count = 0;
  65.         }
  66.         if (c == 0)
  67.         break;        /* out of for        */
  68.     } 
  69.     else if (count++ == 0)     /* printable        */
  70.         start = &line[i];    /* start next parm    */
  71.     }                /* end else, for    */
  72.     line[i] = 0;        /* terminate last parm    */
  73.     i = j;            /* number of parms    */
  74.     while (j < num)
  75.     arr[j++] = 0;        /* clear garbage    */
  76.     return(i);
  77. }            /* End of decol8()        */
  78.  
  79.  
  80.  
  81. char  strcop(s,t)    /* as C manual p. 101; copy *s => *t        */
  82. char    *s, *t;
  83. {
  84.     while (*t++ = *s++)
  85.     ;
  86. }                /* End of strcop()            */
  87.  
  88.  
  89.  
  90. txtout(str)        /* string to screen by outc()    */
  91. char    *str;
  92. {
  93.     char  c;
  94.  
  95.     while( (c = *str++) != 0 )
  96.     outc(c);
  97.     return;
  98. }            /* end of txtout()        */
  99.  
  100.  
  101.  
  102. /************************************************************************/
  103.  
  104. /* printf() extracted form Aztec-c 1.06d CP/M
  105.     modified to use outfc()                */
  106.  
  107. /*    Copyright (C) 1981, 1982 by Manx Software Systems */
  108. /*    Copyright (C) 1983 by Manx Software Systems */
  109. /*    Copyright 1985 by RML - Chris K. March 1985.    */
  110.  
  111.  
  112. printf(fmt,args)
  113. char *fmt; unsigned args;
  114. {
  115.     int outfc();
  116.  
  117.     format(outfc,fmt,&args);
  118. }
  119.  
  120. format(putsub, fmt, args)
  121. register int (*putsub)(); register char *fmt; unsigned *args;
  122. {
  123.     register int c;
  124.     char *ps;
  125.     char s[8];
  126.     static char *dconv(), *hexconv();
  127.  
  128.     while ( c = *fmt++ ) {
  129.         if ( c == '%' ) {
  130.             switch ( c = *fmt++ ) {
  131.             case 'x':
  132.                 ps = hexconv(*args++, s+7);
  133.                 break;
  134.             case 'u':
  135.                 ps = dconv(*args++, s+7);
  136.                 break;
  137.             case 'd':
  138.                 if ( (int)*args < 0 ) {
  139.                     ps = dconv(-*args++, s+7);
  140.                     *--ps = '-';
  141.                 } else
  142.                     ps = dconv(*args++, s+7);
  143.                 break;
  144.             case 's':
  145.                 ps = *args++;
  146.                 break;
  147.             case 'c':
  148.                 c = *args++;
  149.             default:
  150.                 goto deflt;
  151.             }
  152.  
  153.             while ( *ps )
  154.                 (*putsub)(*ps++);
  155.             
  156.         } else
  157.     deflt:
  158.             (*putsub)(c);
  159.     }
  160. }
  161.  
  162. static char *
  163. dconv(n, s)
  164. register char *s; register unsigned n;
  165. {
  166.     *s = 0;
  167.     do {
  168.         *--s = n%10 + '0';
  169.     } while ( (n /= 10) != 0 );
  170.     return s;
  171. }
  172.  
  173. static char *
  174. hexconv(n, s)
  175. register char *s; register unsigned n;
  176. {
  177.     *s = 0;
  178.     do {
  179.         *--s = "0123456789abcdef" [n&15];
  180.     } while ( (n >>= 4) != 0 );
  181.     return s;
  182. }
  183.  
  184. /************* End of Aztec printf.c ***********************************/
  185.  
  186. /****************  End of file KCSUPP.C  *************************/
  187.  
  188.  
  189.