#define unput_string(s) for (int i = strlen(s) - 1; i >= 0; i--) unput(s[i])
static char* copy_string(const char* s) {
+ char* buffer = NULL;
+
+ // Return NULL on NULL input
if (!s)
return NULL;
- // Remove any leading whitespace
- while (*s && isspace(*s))
- s++;
-
- // Remove any trailing whitespace
- const char* e = s + strlen(s);
- while (*e && isspace(*s))
- e--;
-
- // Determine the length of the string
- const size_t l = strlen(s);
+ // Copy the string
+ buffer = strdup(s);
- // Allocate a working buffer
- char* buffer = malloc(l + 1);
+ // Fail if we could not copy the string
if (!buffer)
return NULL;
- // Copy input string to buffer
- memcpy(buffer, s, l + 1);
+ // Strip any leading or trailing whitespace
+ pakfire_string_strip(buffer);
// Pointer to the start of the string
char* p = buffer;
+ // Determine the length of the string
+ const size_t l = strlen(s);
+
char* linebreak = strstr(p, "\\\n");
while (linebreak) {
// Move p to the beginning of the linebreak