2 * Copyright (C) 2003 Timothy Bauscher <timothy@linuxfromscratch.org>
12 void error (const char *fmt
, ...) {
17 vsnprintf(msg
, sizeof msg
, fmt
, args
);
20 fprintf(stderr
, "Error: %s\n", msg
);
25 int string_cat (char *str1
, const char *str2
) {
30 while ('\0' != str2
[d
])
31 str1
[c
++] = str2
[d
++];
37 int string_comp (const char *str1
, const char *str2
) {
39 len
= string_len(str1
);
41 if (len
!= string_len(str2
)) return(0);
42 for (; len
>= 0; len
--)
43 if (str1
[len
] != str2
[len
]) return(0);
48 char *string_cpy (const char *str1
) {
52 /* Allocate space for new string */
54 dest
= malloc((string_len(str1
)+1) * sizeof(char));
65 int string_len (const char *string
) {
67 for (c
=0; '\0' != string
[c
]; c
++);
71 char *string_snip (const char *string
, const int start
, const int end
) {
75 /* Allocate space for new string */
76 str
= malloc((end
-start
+1) * sizeof(char));
79 /* Record text from start to stop */
80 for (c
=start
; c
< end
; c
++)
87 /* TODO: This function is nasty; recode. */
88 char *string_strip (const char *string
, const char *strip
) {
93 len_stp
= string_len(strip
);
94 len_str
= string_len(string
);
95 str
= malloc((len_str
+ 1) * sizeof(char));
98 for (s
=0; '\0' != string
[s
];)
100 tmp
= string_snip(string
, s
, s
+ len_stp
);
102 if (string_comp(strip
, tmp
))
105 str
[c
++] = string
[s
++];