home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 190_01 / lib68.c < prev    next >
Text File  |  1985-11-14  |  3KB  |  178 lines

  1. /******************************************************************
  2.     lib68.c, the library of misc. functions used by as68
  3. */
  4.  
  5. /*        (C) Copyright 1982 Steve Passe        */
  6. /*        All Rights Reserved                    */
  7.  
  8. /* version 1.01
  9.  
  10.     8/30/83    ver. 1.01 modified for Aztec ver. 1.05g    smp
  11.     9/1/83    split off from as68.c, the main module
  12.  
  13. */
  14.  
  15. /* begincode */
  16.  
  17. /* includes */
  18.  
  19. #define AZTECZII 1
  20.  
  21. #ifndef AZTECZII
  22. #include <stdio.h>
  23. #else
  24. #include "stdio.h"                                /* with aztecII compiler */
  25. #endif
  26. #include "b:as68.h"
  27.  
  28. /* copy the first word from string into word, return length */
  29.  
  30. word_copy(word, maxl, str)
  31. char *word;
  32. int maxl;
  33. char *str;
  34. {
  35.     register int length = 0;
  36.     while (isspace(*str))    ++str;                                /* skip ws */
  37.     if (!*str) return NULL;                                        /* eos */
  38.     while ((!isspace(*word = *str)) && *str && maxl--) {        /* copy word */
  39.         ++str;                                                    /* bump... */
  40.         ++word;                                                    /* ...ptrs */
  41.         ++length;                                                /* count it */
  42.     }
  43.     *word = '\0';
  44.     return length;
  45. }
  46.  
  47. /* check for length, report error to console */
  48.  
  49. too_long(str, maxl)
  50. char *str;
  51. int maxl;
  52. {
  53.     if (strlen(str) > maxl) {
  54.         printf("\...too long (\"%s\")", str);
  55.         return YES;
  56.     }
  57.     return OK;
  58. }
  59.  
  60. /* compare two strings, first converting uppercase alphas to lower in first */
  61.  
  62. a1strcmp(s, t)
  63. char *s;
  64. char *t;
  65. {
  66.     register char c;
  67.     for ( ; (c = ((*s >= 'A') && (*s <= 'Z')) ? *s + 32 : *s) == *t; ++s, ++t)
  68.         if (c == '\0') return NULL;
  69.     return (c - *t);
  70. }
  71.  
  72. isalpha(c)
  73. char c;
  74. {
  75.     return (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')));
  76. }
  77.  
  78. /* returns pointer to char c in str, or NULL if not found */
  79.  
  80. char *
  81. cisat(c, str)
  82. char c;
  83. char *str;
  84. {
  85.     while (*str) if (c == *str++) return --str;
  86.     return NULL;
  87. }
  88.  
  89. /* change all uppercase alpha to lowercase */
  90.  
  91. purge_uc(str)
  92. char *str;
  93. {
  94.     for ( ; *str = tolower(*str); ++str)
  95.         ;
  96. }
  97.  
  98. /** redo in .asm someday  --- now done, keep this for those without it:
  99.  
  100. movmem(a, b, c)
  101. char *a;
  102. char *b;
  103. int c;
  104. {
  105.     if (a < b) {                    // moving toward high memory //
  106.         a += (c - 1);                    // calculate tail of source block //
  107.         b += (c - 1);                    // calculate tail of dest block //
  108.         for ( ; c--; *b-- = *a--)
  109.             ;
  110.     }
  111.     else if (b < a) {                // moving toward low memory //
  112.         for ( ; c--; *a-- = *b--)
  113.             ;
  114.     }
  115.     return;
  116. }
  117. **/
  118.  
  119. /** now using -> fputs(str, lst_d);
  120. lputs(str)
  121. char *str;
  122. {
  123.     register int y, x = 0;
  124.  
  125.     while (str[x]) {
  126.         if (str[x] == '\t') {
  127.             for (y = 8 - (x % 8); y--; ) bdos(5, ' ');
  128.             ++x;
  129.         }
  130.         else bdos(5, str[x++]);
  131.     }
  132. }
  133. **/
  134.  
  135.  
  136. /***
  137.     buffer words from second field to first field, wrapping or cutting
  138. as necessary
  139.  
  140. buf_field(dest, src, size)
  141. char *dest;
  142. char **src;
  143. int size;
  144. {
  145.     register int x, cnt = 1;
  146.  
  147.     for ( ;--size; ++cnt) {
  148.         switch (**src) {
  149.         case NULL:
  150.         case '\n':
  151.             *dest++ = '\n';
  152.             *dest = NULL;
  153.             if (!**src) return NULL;
  154.             (*src)++;
  155.             return TRUE;
  156.         case '\t':
  157.             size -= (x = 7 - (cnt % 8));    /* 7 'cause loop subs 1 //
  158.             if (size < 1) {                    /* tab overflow //
  159.                 size = 1;
  160.                 continue;
  161.             }
  162.             cnt += x;                        /* fall thru to default //
  163.         default:
  164.             *dest++ = *(*src)++;
  165.             continue;
  166.         }
  167.     }
  168.     *dest++ = '\n';
  169.     *dest = NULL;
  170.     return TRUE;
  171. }
  172. ***/
  173.  
  174. /* endcode */
  175. / moving toward low memory //
  176.         for ( ; c--; *a-- = *b--)
  177.             ;
  178.     }