home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 168_01 / pcjunk.c < prev    next >
Text File  |  1985-08-21  |  2KB  |  80 lines

  1. /*  PCJUNK.C     Misc. procedures */
  2.  
  3. #include "stdio.h"
  4. #include "sdbio.h"
  5.  
  6. /*    Replaces JUNK.C for the IBM/PC version            dns */
  7.  
  8.  
  9. char *alloc(n)
  10. int n;
  11. {
  12.    return (char*) malloc(n);
  13. }
  14.  
  15.  
  16. int getcx(fp)
  17.   FILE *fp;
  18. {
  19.     static char buf[LINEMAX] = {0};
  20.     static char *pbuf = buf;
  21.     int ch, i;
  22.  
  23.     if (fp!=stdin)
  24.        if ((ch = getc(fp)) == '\r')
  25.           return getc(fp);
  26.        else
  27.           return ch;
  28.  
  29.     if (*pbuf > 0)
  30.        return *pbuf++;
  31.  
  32.     pbuf = buf;
  33.     for (i = 0; (ch = getc(fp)) != -1; )
  34.         if (i < LINEMAX)  {
  35.             if (ch == ESC)     { i=0;  putchar('\n'); fflush(stdout); }  else
  36.             if (ch == BS)      { if (i>0)  i--;                       }  else
  37.                buf[i++] = ch;
  38.             if (ch == '\n')    break;
  39.             }
  40.         else {
  41.             printf("*** line too long ***\nRetype> ");
  42.             i = 0;
  43.         }
  44.     buf[i] = EOS;
  45.     return getcx(fp);
  46. }
  47.  
  48.  
  49.  
  50. /*    string copy up to n characters    */
  51. strncpy(to, from, n)
  52. char *to, *from;
  53. int n;
  54. {
  55.   char *cp;
  56.  
  57.   for( cp=to; n-- && (*cp++ = *from++);  ) ;
  58.   if( n<0 )   *cp = 0;
  59.   return to;
  60. }
  61.  
  62.  
  63. /*    string compare up to n characters     */
  64. strncmp(s1, s2, n)
  65. char *s1, *s2;
  66. int n;
  67. {
  68.  
  69.   for( ;n-- && (*s1==*s2); s2++ )
  70.      if( !*s1++ )
  71.         return 0;
  72.   if( n < 0 )
  73.      return 0;
  74.   if( *s1 < *s2 )
  75.      return -1;
  76.   return 1;
  77. }
  78. width = 1;
  79.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next)
  80.         twi