home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / POLY3DHS.ZIP / XGENERAL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-05  |  3.5 KB  |  118 lines

  1. /*****************************************************************************
  2. * A replacer for the MSDOS functions.                         *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, Mar. 1990   *
  5. *****************************************************************************/
  6.  
  7. #ifndef __MSDOS__
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "program.h"
  13.  
  14. /*****************************************************************************
  15. *   Routine to concat a full path to a given name - used in non MSDOS        *
  16. * environment only, and in that case assumes path is in IRIT_PATH variable.  *
  17. *****************************************************************************/
  18. char *searchpath(char *Name)
  19. {
  20.     static char FullPath[LINE_LEN];
  21.     char *p;
  22.  
  23.     if ( p = getenv("IRIT_PATH") ) {
  24.     strcpy(FullPath, p);
  25.     strcat(FullPath, Name);
  26.     }
  27.     else {
  28.     strcpy(FullPath, Name);
  29.     }
  30.     return FullPath;
  31. }
  32.  
  33. /*****************************************************************************
  34. *   Routine to compare tow strings, ignoring case, up to given length.       *
  35. *****************************************************************************/
  36. int strnicmp(char *s1, char *s2, int n)
  37. {
  38.     return strncasecmp(s1, s2, n);
  39. }
  40.  
  41. /*****************************************************************************
  42. *   Routine to search for pattern (no regular expression) in s. Returns      *
  43. * address in s of first occurance of patern, NULL if non found.             *
  44. *****************************************************************************/
  45. char *strstr(char *s, char *Pattern)
  46. {
  47.     int Len = strlen(Pattern);
  48.     char *p = s;
  49.     
  50.     while (p = strchr(p, Pattern[0]))
  51.     if (strncmp(p, Pattern, Len) == 0) return p;
  52.         else p++;
  53.  
  54.     return NULL;
  55. }
  56.  
  57. /*****************************************************************************
  58. *   Routine to compare to strings, ignoring their case.                 *
  59. *****************************************************************************/
  60. int stricmp(char *s1, char *s2)
  61. {
  62.     int i;
  63.     char *u1, *u2;
  64.  
  65.     if (s1 == NULL) return -(s2 == NULL);
  66.     else
  67.     if (s2 == NULL) return 1;
  68.  
  69.     u1 = strdup(s1);
  70.     u2 = strdup(s2);
  71.  
  72.     for (i = 0; i < strlen(u1); i++) if (islower(u1[i])) u1[i] = toupper(u1[i]);
  73.     for (i = 0; i < strlen(u2); i++) if (islower(u2[i])) u2[i] = toupper(u2[i]);
  74.  
  75.     i = strcmp(u1, u2);
  76.  
  77.     free(u1);
  78.     free(u2);
  79.  
  80.     return i;
  81. }
  82.  
  83. #ifndef SYSV
  84. /*****************************************************************************
  85. *   Routine to compare to strings, ignoring their case.                 *
  86. *****************************************************************************/
  87. char *strdup(char *s)
  88. {
  89.     char *p;
  90.  
  91.     if (p == NULL) return NULL;
  92.  
  93.     p = MyMalloc(strlen(s) + 1);
  94.  
  95.     strcpy(p, s);
  96.  
  97.     return p;
  98. }
  99. #endif /* SYSV */
  100.  
  101. /*****************************************************************************
  102. *   Routine to move a block in memory. Unlike memcpy/bcopy, this routine     *
  103. * should support overlaying blocks. This stupid implemetation will copy it   *
  104. * twice - to a temporary block and back again. The temporary block size will *
  105. * be allocated by demand.                             *
  106. *****************************************************************************/
  107. void movmem(VoidPtr Src, VoidPtr Dest, int Len)
  108. {
  109.     VoidPtr p = MyMalloc(Len);
  110.  
  111.     memcpy(p, Src, Len);
  112.     memcpy(Dest, p, Len);
  113.  
  114.     free(p);
  115. }
  116.  
  117. #endif /* __MSDOS__ */
  118.