1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/* $Id: cleanfrom.c 7585 2006-11-21 09:37:51Z eagle $
**
*/
#include "config.h"
#include "clibrary.h"
#include "inn/libinn.h"
#define LPAREN '('
#define RPAREN ')'
/*
** Clean up a from line, making the following transformations:
** address address
** address (stuff) address
** stuff <address> address
*/
void HeaderCleanFrom(char *from)
{
char *p;
char *end;
int len;
if ((len = strlen(from)) == 0)
return;
/* concatenate folded header */
for (p = end = from ; p < from + len ;) {
if (*p == '\n') {
if ((p + 1 < from + len) && ISWHITE(p[1])) {
if ((p - 1 >= from) && (p[-1] == '\r')) {
end--;
*end = p[1];
p += 2;
} else {
*end = p[1];
p++;
}
} else {
*end = '\0';
break;
}
} else
*end++ = *p++;
}
if (end != from)
*end = '\0';
/* Do pretty much the equivalent of sed's "s/(.*)//g"; */
while ((p = strchr(from, LPAREN)) && (end = strchr(p, RPAREN))) {
while (*++end)
*p++ = *end;
*p = '\0';
}
/* Do pretty much the equivalent of sed's "s/\".*\"//g"; */
while ((p = strchr(from, '"')) && (end = strchr(p, '"'))) {
while (*++end)
*p++ = *end;
*p = '\0';
}
/* Do the equivalent of sed's "s/.*<\(.*\)>/\1/" */
if ((p = strrchr(from, '<')) && (end = strrchr(p, '>'))) {
while (++p < end)
*from++ = *p;
*from = '\0';
}
/* drop white spaces */
if ((len = strlen(from)) == 0)
return;
for (p = end = from ; p < from + len ;) {
if (ISWHITE(*p)) {
p++;
continue;
}
*end++ = *p++;
}
if (end != from)
*end = '\0';
}
|