home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MSGDP206.SZH / STRING.C < prev    next >
C/C++ Source or Header  |  1990-07-30  |  1KB  |  73 lines

  1. /**
  2.  
  3.  * string.c
  4.  * released into the PUBLIC DOMAIN 30 jul 1990 by jim nutt
  5.  * a few string handling routines for msged
  6.  
  7. **/
  8.  
  9. #if defined(__ZTC__)
  10. #define NO_HANDLE 1
  11. #include <handle.h>
  12. #else
  13. #include "nohandl.h"
  14. #endif
  15.  
  16. #include <string.h>
  17. #include <ctype.h>
  18.  
  19. #include "pascal.h"
  20.  
  21. char __handle * _pascal strdup_handle(const char *s);
  22.  
  23.  
  24. #if defined(__ZTC__)
  25. int _pascal strncmpi(char *s, char *t, int n);
  26. #endif
  27. void _pascal strins(char *l, char c, int x);
  28. void _pascal strdel(char *l, int x);
  29.  
  30. void _pascal strins(char *l, char c, int x)
  31.  
  32. {
  33.     int     i = strlen(l);
  34.  
  35.     if (x > (i+1))
  36.         return;
  37.     else {
  38.         x--;
  39.         memmove((l + x + 1), (l + x), (i - x) + 1);
  40.         *(l + x) = c;
  41.     }
  42. }
  43.  
  44. void _pascal strdel(char *l, int x)
  45.  
  46. {
  47.     int     i = strlen(l);
  48.  
  49.     if (x > i) return;
  50.     x--;
  51.     memmove((l + x), (l + x + 1), (i - x) + 1);
  52.     *(l + i) = 0;
  53. }
  54.  
  55. #if defined(__ZTC__)
  56. /*
  57.  *    strncmpi() ->    strncmp(), ignore case
  58.  */
  59.  
  60. int _pascal strncmpi(char *s, char *t, int n)
  61.  
  62. {
  63.     for (; n-- && (tolower(*s) == tolower(*t)); ++t)
  64.         if (!*s++)
  65.             return (0); /* equal */
  66.  
  67.     if (n < 0)        /* maximum hit */
  68.         return (0);     /* equal */
  69.  
  70.     return ((tolower(*s) > tolower(*t)) ? 1 : (-1));    /* not equal */
  71. }
  72. #endif
  73.