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

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