|
|
@ -4,10 +4,11 @@
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <regex.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "blaze822.h"
|
|
|
|
#include "blaze822.h"
|
|
|
@ -147,19 +148,22 @@ sed(char *file)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
case 'a':
|
|
|
|
// skipped here;
|
|
|
|
// skipped here;
|
|
|
|
sep = *++e;
|
|
|
|
e++;
|
|
|
|
|
|
|
|
if ((*e == ' ' || *e == ';' || *e == '\n' || !*e)) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sep = *e;
|
|
|
|
if (!sep) {
|
|
|
|
if (!sep) {
|
|
|
|
fprintf(stderr, "unterminated a command\n");
|
|
|
|
fprintf(stderr, "unterminated a command\n");
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*e && *e != sep)
|
|
|
|
while (*e && *e != sep)
|
|
|
|
e++;
|
|
|
|
e++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!(*e == ' ' || *e == ';' || *e == '\n' || !*e)) {
|
|
|
|
if (!(*e == ' ' || *e == ';' || *e == '\n' || !*e)) {
|
|
|
|
fprintf(stderr, "unterminated a command\n");
|
|
|
|
fprintf(stderr, "unterminated a command\n");
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'c':
|
|
|
|
sep = *++e;
|
|
|
|
sep = *++e;
|
|
|
|
s = ++e;
|
|
|
|
s = ++e;
|
|
|
@ -204,7 +208,7 @@ sed(char *file)
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*e && *e != ';')
|
|
|
|
while (*e && *e != ';' && *e != '\n')
|
|
|
|
e++;
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (v) {
|
|
|
|
if (v) {
|
|
|
@ -237,23 +241,48 @@ sed(char *file)
|
|
|
|
|
|
|
|
|
|
|
|
char sep;
|
|
|
|
char sep;
|
|
|
|
char *s;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
char *h = 0;
|
|
|
|
|
|
|
|
char *v = 0;
|
|
|
|
|
|
|
|
char buf[255];
|
|
|
|
switch (*e) {
|
|
|
|
switch (*e) {
|
|
|
|
case 'a':
|
|
|
|
case 'a':
|
|
|
|
sep = *++e;
|
|
|
|
if (he != hs) {
|
|
|
|
if (!sep) {
|
|
|
|
h = strndup(hs, he-hs);
|
|
|
|
fprintf(stderr, "unterminated a command\n");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fprintf(stderr, "used command a without header name\n");
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
s = ++e;
|
|
|
|
e++;
|
|
|
|
while (*e && *e != sep)
|
|
|
|
if (*e == ' ' || *e == '\t' || *e == '\n' || *e == ';' || !*e) {
|
|
|
|
e++;
|
|
|
|
if (strcasecmp(h, "date") == 0) {
|
|
|
|
if (he != hs) {
|
|
|
|
time_t now = time(0);
|
|
|
|
char *h = strndup(hs, he-hs);
|
|
|
|
strftime(buf, sizeof buf,
|
|
|
|
char *v = strndup(s, e-s);
|
|
|
|
"%a, %d %b %Y %T %z",
|
|
|
|
printhdr(h, 0);
|
|
|
|
localtime(&now));
|
|
|
|
printf(": %s\n", v);
|
|
|
|
v = buf;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fprintf(stderr, "no header value for %s\n", h);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sep = *e;
|
|
|
|
|
|
|
|
if (!sep) {
|
|
|
|
|
|
|
|
fprintf(stderr, "unterminated a command\n");
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s = ++e;
|
|
|
|
|
|
|
|
while (*e && *e != sep)
|
|
|
|
|
|
|
|
e++;
|
|
|
|
|
|
|
|
v = strndup(s, e-s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (blaze822_chdr(msg, h))
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printhdr(h, 0);
|
|
|
|
|
|
|
|
printf(": %s\n", v);
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
case 'c':
|
|
|
@ -262,7 +291,7 @@ sed(char *file)
|
|
|
|
// ignore here;
|
|
|
|
// ignore here;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*e && *e != ';')
|
|
|
|
while (*e && *e != ';' && *e != '\n')
|
|
|
|
e++;
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|