home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / strfunc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  1.4 KB  |  90 lines

  1. #include  <stdio.h>
  2. #include  <string.h>
  3. #include  <libc.h>
  4. #include  "strfunc.h"
  5.  
  6. char *str_dup(const char *src)
  7. {
  8.     char *dst;
  9.  
  10.     dst = (char *)malloc(strlen(src) + 1);
  11.     strcpy(dst, src);
  12.     return dst;
  13. }
  14.  
  15.  
  16. int dircopy(char *dst, const char *src, int slash)
  17.     /* copy directory part of file path */
  18. {
  19.     int i, n;
  20.  
  21.     for (i = 0, n = -1; src[i]; i++) {
  22.         dst[i] = src[i];
  23.         if (src[i] == '/') n = i;
  24.     }
  25.     if (n >= 0) {
  26.         if (slash) ++n;
  27.         dst[n] = 0;
  28.     }
  29.     return n;
  30. }
  31.  
  32.  
  33. int getExtension(char const *fn)
  34. {
  35.     int i, j;
  36.  
  37.     for (i = 0, j = -1; fn[i]; i++) {
  38.         if (fn[i] == '.') j = i;
  39.         else if (fn[i] == '/') j = -1;
  40.     }
  41.     if (j <= 0 || fn[j - 1] == '/')
  42.         return 0;    /* No Extension */
  43.     return j + 1;
  44. }
  45.  
  46.  
  47. void str_lcat(char *p, const char *comm, int max)
  48. {
  49.     int i, limit;
  50.  
  51.     if (comm == NULL)
  52.         return;
  53.     limit = max - 1;
  54.     for (i = 0; i < limit && *p; i++, p++) ;
  55.     while(*comm && i < limit)
  56.         *p++ = *comm++;
  57.     *p = 0;
  58. }
  59.  
  60. const char *begin_comm(const char *comm, BOOL cont)
  61.     /* Get begining of comment (... : comment) */
  62. {
  63.     if (comm == NULL)
  64.         return NULL;
  65.     while (*comm && *comm != ':')
  66.         comm++;
  67.     if (*comm == ':' && cont)
  68.         while (*++comm == ' ') ;
  69.     if (*comm == 0)
  70.         return NULL;
  71.     return comm;
  72. }
  73.  
  74. void comment_copy(char *p, const char *comm)
  75. {
  76.     const char *q;
  77.  
  78.     if ((q = begin_comm(comm, NO)) == NULL)
  79.         return;
  80.     str_lcat(p, q, MAX_COMMENT);
  81. }
  82.  
  83. const char *key_comm(const commonInfo *cinf)
  84. {
  85.     const char *pp = begin_comm(cinf->memo, NO);
  86.     if (pp == NULL)
  87.         return ": by ToyViewer";
  88.     return pp;
  89. }
  90.