home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / uupoll068.lha / source / str.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-03  |  2.1 KB  |  133 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5. #include "defines.h"
  6. #include "cus.h"
  7.  
  8. int isanyof(char c, char *cp)
  9. {
  10.     while (*cp != NUL) {
  11.         if (c == *cp)
  12.             return TRUE;
  13.         ++cp;
  14.     }
  15.     return FALSE;
  16. }
  17.  
  18. /*    Unqoute a string buffer if quoted by skipping the first char
  19.     and replacing the last char by the null terminater.            */
  20.  
  21. char *strcvt(char *str)
  22. {
  23.     char *ptr = str;
  24.     int found = NO;
  25.  
  26.     if (*ptr == QUOTE) {
  27.         while (*ptr != NUL) {
  28.             if (*ptr != QUOTE)
  29.                 found = YES;
  30.             ptr++;
  31.         }
  32.         if (found) {
  33.             *(--ptr) = NUL;
  34.             return (++str);
  35.         }
  36.         else return str;
  37.     }
  38.     else
  39.         return str;
  40. }
  41.  
  42.  
  43. /*  Truncate a domain extension if exists in a given ARPA address, so
  44.     that the name of the host will be remain only.                    */
  45.  
  46. void truncdomain(char *str)
  47. {
  48.     while( (*str != '.') && (*str != NUL))
  49.         str++;
  50.     if (*str == '.')
  51.         *str = NUL;
  52.     return;
  53. }
  54.  
  55.  
  56. /*    Split an argument string into an argument array with pointers to
  57.     null-terminated argument strings like argv[].        */
  58.  
  59. void splitarg(char **cppArgv, char *cpCmnd)
  60. {
  61.     char *cp;
  62.  
  63.     cp = cpCmnd;
  64.  
  65.     for ( ; ; ) {
  66.         *cppArgv++ = cp;
  67.         while ( (*cp != SP) && (*cp != HT) && (*cp != NL) && (*cp != NUL) )
  68.             cp++;
  69.         if (*cp == NUL)
  70.             break;
  71.         *cp++ = NUL;
  72.         while ( (*cp == SP) || (*cp == HT) )
  73.             cp++;
  74.     }
  75.     *cppArgv = NULL;
  76.  
  77.     return;
  78. }
  79.  
  80.  
  81. int cnvbuf(char *cpBufFirst, char *cpBufLast)
  82. {
  83.     char *cpRead;
  84.     char *cpWrite;
  85.     int rc;
  86.  
  87.     cpRead = cpWrite = cpBufFirst;
  88.  
  89.     for ( ; ; ) {
  90.         if (cpRead > cpBufLast)
  91.             CU(cpWrite - cpBufFirst);
  92.         if (cpRead < cpBufLast) {
  93.             if (*cpRead == '\\' && *(cpRead+1) == LF) {
  94.                 cpRead += 2;
  95.                 continue;
  96.             }
  97.         }
  98.         *cpWrite++ = *cpRead++;
  99.     }
  100.  
  101.     CUS:
  102.     return rc;
  103. }
  104.  
  105. #define STRBPLRC_ERR -1
  106.  
  107. int strbplst(char *cpaPointers[], int pnPointersMax, char *cpStrings)
  108. {
  109.     char *cpStringsCur;
  110.     int iPointers;
  111.     int rc;
  112.  
  113.     cpStringsCur = cpStrings;
  114.     iPointers = 0;
  115.  
  116.     for (;;) {
  117.         if (*cpStringsCur == NUL) {
  118.             cpaPointers[iPointers] = NULL;
  119.             break;
  120.         }
  121.         if (iPointers >= pnPointersMax)
  122.             CU(STRBPLRC_ERR);
  123.         cpaPointers[iPointers++] = cpStringsCur;
  124.         while (*cpStringsCur++ != NUL);
  125.             ;
  126.     }
  127.     rc = iPointers;
  128.  
  129.     CUS:
  130.     return rc;
  131. }
  132.  
  133.