home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / a / bin / modules-.2 / modules- / modules-1.2.8 / depmod / str.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-30  |  1.5 KB  |  87 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include "link.h"
  5.  
  6. /*
  7.     elimine les blancs et saut de ligne de la fin d'une chaine
  8.       newstr et str peuvent être la même variable
  9.     Retourne le nombre de byte eliminer au bout de la chaine
  10. */
  11. int str_strip (
  12.     const char *str,    /* Chaine a tronquer */
  13.     char *newstr)        /* Resultat */
  14. {
  15.     int ret = 0;
  16.     int len = strlen(str);
  17.     char *pt = newstr + len-1;
  18.     strcpy (newstr,str);
  19.     while (len > 0 && isspace(*pt)){
  20.         *pt-- = '\0';
  21.         len --;
  22.         ret ++;
  23.     }
  24.     return (ret);
  25. }
  26. /*
  27.     Strip white char at the end of a string.
  28.     Return the address of the last non white char + 1 (point on the '\0').
  29. */
  30.  
  31. char *strip_end(char *str)
  32. {
  33.     int len = strlen(str);
  34.     for (str += len - 1
  35.         ; len > 0 && (isspace(*str) || *str == 26)
  36.         ; len--, str--) *str = '\0';
  37.     return str+1;
  38. }
  39.     
  40. /*
  41.     Skip the white char in a string
  42. */
  43. char *str_skip (const char *str)
  44. {
  45.     while (isspace(*str)) str++;
  46.     return (char*)str;
  47. }
  48.  
  49. /*
  50.     strdup with error checking.
  51.     Does not return if any error.
  52. */
  53. char *strdup_err (const char *str)
  54. {
  55.     char *ret = strdup(str);
  56.     if (ret == NULL){
  57.         depmod_error ("Out of memory");
  58.         exit (-1);
  59.     }
  60.     return ret;
  61. }
  62.  
  63. /*
  64.     Free all string in a table
  65. */
  66. void tbstr_free (char *lst[], int nb)
  67. {
  68.     for (int i=0; i<nb; i++) free (lst[i]);
  69. }
  70.  
  71. extern "C" char *stpcpy(char *dst, const char *src)
  72. {
  73.     strcpy (dst,src);
  74.     return dst + strlen(dst);
  75. }
  76.  
  77. /*
  78.     Extract the name of a file (without the directory component).
  79. */
  80. void path_extrname (const char *path, char *name)
  81. {
  82.     const char *pt = strrchr(path,'/');
  83.     pt = pt == NULL ? path : pt + 1;
  84.     strcpy (name,pt);
  85. }
  86.  
  87.