Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/services_mkdb/uniq.c
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | comp(const char *origline, char **compline, size_t *len) | ||||
char *cline; | char *cline; | ||||
size_t l = *len, complen; | size_t l = *len, complen; | ||||
int hasalnum, iscomment; | int hasalnum, iscomment; | ||||
/* Eat leading space */ | /* Eat leading space */ | ||||
for (p = (const unsigned char *)origline; l && *p && isspace(*p); | for (p = (const unsigned char *)origline; l && *p && isspace(*p); | ||||
p++, l--) | p++, l--) | ||||
continue; | continue; | ||||
if (*p == '\0' || l == 0) | |||||
return 0; | |||||
if ((cline = malloc(l + 1)) == NULL) | if ((cline = malloc(l + 1)) == NULL) | ||||
err(1, "Cannot allocate %zu bytes", l + 1); | err(1, "Cannot allocate %zu bytes", l + 1); | ||||
(void)memcpy(cline, p, l); | (void)memcpy(cline, p, l); | ||||
cline[l] = '\0'; | cline[l] = '\0'; | ||||
if (*cline == '\0') | |||||
return 0; | |||||
complen = 0; | complen = 0; | ||||
hasalnum = 0; | hasalnum = 0; | ||||
iscomment = 0; | iscomment = 0; | ||||
for (q = (unsigned char *)cline; l && *p; p++, l--) { | for (q = (unsigned char *)cline; l && *p; p++, l--) { | ||||
if (isspace(*p)) { | if (isspace(*p)) { | ||||
if (complen && isspace(q[-1])) | if (complen && isspace(q[-1])) | ||||
Show All 13 Lines | comp(const char *origline, char **compline, size_t *len) | ||||
} | } | ||||
/* Eat trailing space */ | /* Eat trailing space */ | ||||
while (complen && isspace(q[-1])) { | while (complen && isspace(q[-1])) { | ||||
--q; | --q; | ||||
--complen; | --complen; | ||||
} | } | ||||
*q = '\0'; | *q = '\0'; | ||||
if (!hasalnum) { | |||||
free(cline); | |||||
cline = NULL; | |||||
complen = 0; | |||||
} | |||||
*compline = cline; | *compline = cline; | ||||
*len = complen; | *len = complen; | ||||
return hasalnum; | return hasalnum; | ||||
} | } |