comparison src/libident/support.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children
comparison
equal deleted inserted replaced
9:31cc8a89cb74 10:26e34ae9a3e3
16 16
17 #define IN_LIBIDENT_SRC 17 #define IN_LIBIDENT_SRC
18 #include "ident.h" 18 #include "ident.h"
19 19
20 20
21 char *id_strdup __P1(char *, str) 21 char*
22 id_strdup __P1(char *, str)
22 { 23 {
23 char *cp; 24 char *cp;
24 25
25 cp = (char *) malloc(strlen(str)+1); 26 cp = (char *) malloc(strlen(str) + 1);
26 if (cp == NULL) 27 if (cp == NULL) {
27 {
28 #ifdef DEBUG 28 #ifdef DEBUG
29 perror("libident: malloc"); 29 perror("libident: malloc");
30 #endif 30 #endif
31 return NULL; 31 return NULL;
32 } 32 }
33 33
34 strcpy(cp, str); 34 strcpy(cp, str);
35 35
36 return cp; 36 return cp;
37 } 37 }
38 38
39 39
40 char *id_strtok __P3(char *, cp, 40 char*
41 char *, cs, 41 id_strtok __P3(char *, cp, char *, cs, char *, dc)
42 char *, dc)
43 { 42 {
44 static char *bp = 0; 43 static char *bp = 0;
45 44
46 if (cp) 45 if (cp)
47 bp = cp; 46 bp = cp;
48 47
49 /* 48 /*
50 ** No delimitor cs - return whole buffer and point at end 49 ** No delimitor cs - return whole buffer and point at end
51 */ 50 */
52 if (!cs) 51 if (!cs) {
53 { 52 while (*bp)
54 while (*bp) 53 bp++;
55 bp++; 54 return cs;
56 return cs; 55 }
57 } 56
58 57 /*
59 /* 58 ** Skip leading spaces
60 ** Skip leading spaces 59 */
61 */ 60 while (isspace(*bp))
62 while (isspace(*bp)) 61 bp++;
62
63 /*
64 ** No token found?
65 */
66 if (!*bp)
67 return 0;
68
69 cp = bp;
70 while (*bp && !strchr(cs, *bp))
71 bp++;
72
73 /*
74 ** Remove trailing spaces
75 */
76 *dc = *bp;
77 for (dc = bp - 1; dc > cp && isspace(*dc); dc--);
78 *++dc = '\0';
79
63 bp++; 80 bp++;
64 81
65 /* 82 return cp;
66 ** No token found?
67 */
68 if (!*bp)
69 return 0;
70
71 cp = bp;
72 while (*bp && !strchr(cs, *bp))
73 bp++;
74
75 /*
76 ** Remove trailing spaces
77 */
78 *dc = *bp;
79 for (dc = bp-1; dc > cp && isspace(*dc); dc--)
80 ;
81 *++dc = '\0';
82
83 bp++;
84
85 return cp;
86 } 83 }