1 /* 2 ** support.c 3 ** 4 ** Author: Pr Emanuelsson <pell@lysator.liu.se> 5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se> 6 */ 7 #include <stdio.h> 8 #include <ctype.h> 9 #include <stdlib.h> 10 #include <string.h> 11 12 #define IN_LIBIDENT_SRC 13 #include "ident.h" 14 15 id_strdup(char * str)16char *id_strdup (char *str) 17 { 18 char *cp; 19 20 cp = (char *) malloc(strlen(str)+1); 21 if (cp == NULL) 22 { 23 #ifdef DEBUG 24 perror("libident: malloc"); 25 #endif 26 return NULL; 27 } 28 29 strcpy(cp, str); 30 31 return cp; 32 } 33 34 id_strtok(char * cp,char * cs,char * dc)35char *id_strtok (char *cp, char *cs, char *dc) 36 { 37 static char *bp = 0; 38 39 if (cp) 40 bp = cp; 41 42 /* 43 ** No delimitor cs - return whole buffer and point at end 44 */ 45 if (!cs) 46 { 47 while (*bp) 48 bp++; 49 return cs; 50 } 51 52 /* 53 ** Skip leading spaces 54 */ 55 while (isspace(*bp)) 56 bp++; 57 58 /* 59 ** No token found? 60 */ 61 if (!*bp) 62 return 0; 63 64 cp = bp; 65 while (*bp && !strchr(cs, *bp)) 66 bp++; 67 68 /* 69 ** Remove trailing spaces 70 */ 71 *dc = *bp; 72 for (dc = bp-1; dc > cp && isspace(*dc); dc--) 73 ; 74 *++dc = '\0'; 75 76 bp++; 77 78 return cp; 79 } 80