Changed indent style

SVN revision: 648
This commit is contained in:
Stefan Ritt 2004-01-06 13:21:34 +00:00
parent 862faeb750
commit dac9eaa2c4
4 changed files with 12698 additions and 13253 deletions

View File

@ -35,6 +35,9 @@ all: $(EXECS)
%: src/%.c %: src/%.c
$(CC) $(CFLAGS) -o $@ $< $(LIBS) $(CC) $(CFLAGS) -o $@ $< $(LIBS)
indent:
find . -name "*.[hc]" -exec indent -kr -nut -i3 {} \;
install: $(EXECS) install: $(EXECS)
$(INSTALL) -m 0755 -d $(DESTDIR) $(SDESTDIR) $(MANDIR)/man1/ $(MANDIR)/man8/ $(INSTALL) -m 0755 -d $(DESTDIR) $(SDESTDIR) $(MANDIR)/man1/ $(MANDIR)/man8/
$(INSTALL) -m 0755 -o bin -g bin elog elconv $(DESTDIR) $(INSTALL) -m 0755 -o bin -g bin elog elconv $(DESTDIR)

View File

@ -6,6 +6,9 @@
Contents: Conversion program for ELOG messages Contents: Conversion program for ELOG messages
$Log$ $Log$
Revision 1.2 2004/01/06 13:21:34 midas
Changed indent style
Revision 1.1 2003/01/30 14:45:07 midas Revision 1.1 2003/01/30 14:45:07 midas
Moved files to src/ subdirectory Moved files to src/ subdirectory
@ -136,16 +139,16 @@ BOOL equal_ustring(char *str1, char *str2)
void el_decode(char *message, char *key, char *result) void el_decode(char *message, char *key, char *result)
{ {
char *pc; char *pc;
if (result == NULL) if (result == NULL)
return; return;
*result = 0; *result = 0;
if (strstr(message, key)) if (strstr(message, key)) {
{ for (pc = strstr(message, key) + strlen(key);
for (pc=strstr(message, key)+strlen(key) ; *pc != '\n' && *pc != '\r' ; ) *pc != '\n' && *pc != '\r';)
*result++ = *pc++; *result++ = *pc++;
*result = 0; *result = 0;
} }
@ -159,8 +162,8 @@ char *pc;
int fnmatch1(const char *pattern, const char *string) int fnmatch1(const char *pattern, const char *string)
{ {
const char *stringstart; const char *stringstart;
char c, test; char c, test;
for (stringstart = string;;) for (stringstart = string;;)
switch (c = *pattern++) { switch (c = *pattern++) {
@ -182,8 +185,7 @@ char c, test;
return (0); return (0);
/* General case, use recursion. */ /* General case, use recursion. */
while ((test = *string) != EOS) while ((test = *string) != EOS) {
{
if (!fnmatch1(pattern, string)) if (!fnmatch1(pattern, string))
return (0); return (0);
++string; ++string;
@ -200,7 +202,7 @@ char c, test;
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
INT ss_file_find(char * path, char * pattern, char **plist) INT ss_file_find(char *path, char *pattern, char **plist)
/********************************************************************\ /********************************************************************\
Routine: ss_file_find Routine: ss_file_find
@ -229,13 +231,12 @@ INT ss_file_find(char * path, char * pattern, char **plist)
return 0; return 0;
*plist = (char *) malloc(MAX_PATH_LENGTH); *plist = (char *) malloc(MAX_PATH_LENGTH);
i = 0; i = 0;
for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
{ if (fnmatch1(pattern, dp->d_name) == 0) {
if (fnmatch1(pattern, dp->d_name) == 0) *plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
{ strncpy(*plist + (i * MAX_PATH_LENGTH), dp->d_name,
*plist = (char *)realloc(*plist, (i+1)*MAX_PATH_LENGTH); strlen(dp->d_name));
strncpy(*plist+(i*MAX_PATH_LENGTH), dp->d_name, strlen(dp->d_name)); *(*plist + (i * MAX_PATH_LENGTH) + strlen(dp->d_name)) = '\0';
*(*plist+(i*MAX_PATH_LENGTH)+strlen(dp->d_name)) = '\0';
i++; i++;
seekdir(dir_pointer, telldir(dir_pointer)); seekdir(dir_pointer, telldir(dir_pointer));
} }
@ -249,9 +250,9 @@ INT ss_file_find(char * path, char * pattern, char **plist)
char str[255]; char str[255];
int first; int first;
strcpy(str,path); strcpy(str, path);
strcat(str,"\\"); strcat(str, "\\");
strcat(str,pattern); strcat(str, pattern);
first = 1; first = 1;
i = 0; i = 0;
lpfdata = malloc(sizeof(WIN32_FIND_DATA)); lpfdata = malloc(sizeof(WIN32_FIND_DATA));
@ -260,15 +261,17 @@ INT ss_file_find(char * path, char * pattern, char **plist)
if (pffile == INVALID_HANDLE_VALUE) if (pffile == INVALID_HANDLE_VALUE)
return 0; return 0;
first = 0; first = 0;
*plist = (char *)realloc(*plist, (i+1)*MAX_PATH_LENGTH); *plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
strncpy(*plist+(i*MAX_PATH_LENGTH), lpfdata->cFileName, strlen(lpfdata->cFileName)); strncpy(*plist + (i * MAX_PATH_LENGTH), lpfdata->cFileName,
*(*plist+(i*MAX_PATH_LENGTH)+strlen(lpfdata->cFileName)) = '\0'; strlen(lpfdata->cFileName));
*(*plist + (i * MAX_PATH_LENGTH) + strlen(lpfdata->cFileName)) = '\0';
i++; i++;
while (FindNextFile(pffile, lpfdata)) while (FindNextFile(pffile, lpfdata)) {
{ *plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
*plist = (char *)realloc(*plist, (i+1)*MAX_PATH_LENGTH); strncpy(*plist + (i * MAX_PATH_LENGTH), lpfdata->cFileName,
strncpy(*plist+(i*MAX_PATH_LENGTH), lpfdata->cFileName, strlen(lpfdata->cFileName)); strlen(lpfdata->cFileName));
*(*plist+(i*MAX_PATH_LENGTH)+strlen(lpfdata->cFileName)) = '\0'; *(*plist + (i * MAX_PATH_LENGTH) + strlen(lpfdata->cFileName)) =
'\0';
i++; i++;
} }
free(lpfdata); free(lpfdata);
@ -280,11 +283,12 @@ INT ss_file_find(char * path, char * pattern, char **plist)
INT el_search_message(char *tag, int *fh, BOOL walk, BOOL first) INT el_search_message(char *tag, int *fh, BOOL walk, BOOL first)
{ {
int lfh, i, n, d, min, max, size, offset, direction, last, status, did_walk; int lfh, i, n, d, min, max, size, offset, direction, last, status,
struct tm *tms, ltms; did_walk;
time_t lt, ltime, lact; struct tm *tms, ltms;
char str[256], file_name[256], dir[256]; time_t lt, ltime, lact;
char *file_list; char str[256], file_name[256], dir[256];
char *file_list;
did_walk = 0; did_walk = 0;
ltime = lfh = 0; ltime = lfh = 0;
@ -294,21 +298,19 @@ char *file_list;
/* check tag for direction */ /* check tag for direction */
direction = 0; direction = 0;
if (strpbrk(tag, "+-")) if (strpbrk(tag, "+-")) {
{
direction = atoi(strpbrk(tag, "+-")); direction = atoi(strpbrk(tag, "+-"));
*strpbrk(tag, "+-") = 0; *strpbrk(tag, "+-") = 0;
} }
/* if tag is given, open file directly */ /* if tag is given, open file directly */
if (tag[0]) if (tag[0]) {
{
/* extract time structure from tag */ /* extract time structure from tag */
tms = &ltms; tms = &ltms;
memset(tms, 0, sizeof(struct tm)); memset(tms, 0, sizeof(struct tm));
tms->tm_year = (tag[0]-'0')*10 + (tag[1]-'0'); tms->tm_year = (tag[0] - '0') * 10 + (tag[1] - '0');
tms->tm_mon = (tag[2]-'0')*10 + (tag[3]-'0') -1; tms->tm_mon = (tag[2] - '0') * 10 + (tag[3] - '0') - 1;
tms->tm_mday = (tag[4]-'0')*10 + (tag[5]-'0'); tms->tm_mday = (tag[4] - '0') * 10 + (tag[5] - '0');
tms->tm_hour = 12; tms->tm_hour = 12;
if (tms->tm_year < 90) if (tms->tm_year < 90)
@ -319,45 +321,43 @@ char *file_list;
return -1; return -1;
strcpy(str, tag); strcpy(str, tag);
if (strchr(str, '.')) if (strchr(str, '.')) {
{ offset = atoi(strchr(str, '.') + 1);
offset = atoi(strchr(str, '.')+1);
*strchr(str, '.') = 0; *strchr(str, '.') = 0;
} } else
else
return -1; return -1;
do do {
{
tms = localtime(&ltime); tms = localtime(&ltime);
sprintf(file_name, "%s%02d%02d%02d.log", dir, sprintf(file_name, "%s%02d%02d%02d.log", dir,
tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday); tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday);
lfh = open(file_name, O_RDWR | O_BINARY, 0644); lfh = open(file_name, O_RDWR | O_BINARY, 0644);
if (lfh < 0) if (lfh < 0) {
{
if (!walk) if (!walk)
return EL_FILE_ERROR; return EL_FILE_ERROR;
did_walk = 1; did_walk = 1;
if (direction == -1) if (direction == -1)
ltime -= 3600*24; /* one day back */ ltime -= 3600 * 24; /* one day back */
else else
ltime += 3600*24; /* go forward one day */ ltime += 3600 * 24; /* go forward one day */
/* set new tag */ /* set new tag */
tms = localtime(&ltime); tms = localtime(&ltime);
sprintf(tag, "%02d%02d%02d.0", tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday); sprintf(tag, "%02d%02d%02d.0", tms->tm_year % 100,
tms->tm_mon + 1, tms->tm_mday);
} }
/* in forward direction, stop today */ /* in forward direction, stop today */
if (direction != -1 && ltime > (time_t)(time(NULL)+3600*24)) if (direction != -1 && ltime > (time_t) (time(NULL) + 3600 * 24))
break; break;
/* in backward direction, go back 10 years */ /* in backward direction, go back 10 years */
if (direction == -1 && abs((int)(lt-ltime)) > 3600*24*365*10) if (direction == -1
&& abs((int) (lt - ltime)) > 3600 * 24 * 365 * 10)
break; break;
} while (lfh < 0); } while (lfh < 0);
@ -372,24 +372,20 @@ char *file_list;
} }
/* open most recent file if no tag given */ /* open most recent file if no tag given */
if (tag[0] == 0) if (tag[0] == 0) {
{ if (first) {
if (first)
{
/* go through whole directory, find first file */ /* go through whole directory, find first file */
file_list = NULL; file_list = NULL;
n = ss_file_find(dir, "??????.log", &file_list); n = ss_file_find(dir, "??????.log", &file_list);
if (n == 0) if (n == 0) {
{
if (file_list) if (file_list)
free(file_list); free(file_list);
return EL_FILE_ERROR; return EL_FILE_ERROR;
} }
for (i=0,min=9999999 ; i<n ; i++) for (i = 0, min = 9999999; i < n; i++) {
{ d = atoi(file_list + i * MAX_PATH_LENGTH);
d = atoi(file_list+i*MAX_PATH_LENGTH);
if (d == 0) if (d == 0)
continue; continue;
@ -411,23 +407,19 @@ char *file_list;
/* on tag "+1", don't go to next message */ /* on tag "+1", don't go to next message */
if (direction == 1) if (direction == 1)
direction = 0; direction = 0;
} } else {
else
{
/* go through whole directory, find last file */ /* go through whole directory, find last file */
file_list = NULL; file_list = NULL;
n = ss_file_find(dir, "??????.log", &file_list); n = ss_file_find(dir, "??????.log", &file_list);
if (n == 0) if (n == 0) {
{
if (file_list) if (file_list)
free(file_list); free(file_list);
return EL_NO_MSG; return EL_NO_MSG;
} }
for (i=0,max=0 ; i<n ; i++) for (i = 0, max = 0; i < n; i++) {
{ d = atoi(file_list + i * MAX_PATH_LENGTH);
d = atoi(file_list+i*MAX_PATH_LENGTH);
if (d < 900000) if (d < 900000)
d += 1000000; /* last century */ d += 1000000; /* last century */
@ -447,30 +439,26 @@ char *file_list;
} }
} }
if (direction == -1) if (direction == -1) {
{
/* seek previous message */ /* seek previous message */
if (TELL(lfh) == 0) if (TELL(lfh) == 0) {
{
/* go back one day */ /* go back one day */
close(lfh); close(lfh);
lt = ltime; lt = ltime;
do do {
{ lt -= 3600 * 24;
lt -= 3600*24;
tms = localtime(&lt); tms = localtime(&lt);
sprintf(str, "%02d%02d%02d.0", sprintf(str, "%02d%02d%02d.0",
tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday); tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday);
status = el_search_message(str, &lfh, FALSE, FALSE); status = el_search_message(str, &lfh, FALSE, FALSE);
} while (status != SUCCESS && } while (status != SUCCESS &&
(INT)ltime-(INT)lt < 3600*24*365); (INT) ltime - (INT) lt < 3600 * 24 * 365);
if (status != EL_SUCCESS) if (status != EL_SUCCESS) {
{
if (fh) if (fh)
*fh = lfh; *fh = lfh;
else else
@ -488,75 +476,63 @@ char *file_list;
/* read previous message size */ /* read previous message size */
lseek(lfh, -17, SEEK_CUR); lseek(lfh, -17, SEEK_CUR);
i = read(lfh, str, 17); i = read(lfh, str, 17);
if (i <= 0) if (i <= 0) {
{
close(lfh); close(lfh);
return EL_FILE_ERROR; return EL_FILE_ERROR;
} }
if (strncmp(str, "$End$: ", 7) == 0) if (strncmp(str, "$End$: ", 7) == 0) {
{ size = atoi(str + 7);
size = atoi(str+7);
lseek(lfh, -size, SEEK_CUR); lseek(lfh, -size, SEEK_CUR);
} } else {
else
{
close(lfh); close(lfh);
return EL_FILE_ERROR; return EL_FILE_ERROR;
} }
/* adjust tag */ /* adjust tag */
sprintf(strchr(tag, '.')+1, "%d", (int) (TELL(lfh))); sprintf(strchr(tag, '.') + 1, "%d", (int) (TELL(lfh)));
} }
if (direction == 1) if (direction == 1) {
{
/* seek next message */ /* seek next message */
/* read current message size */ /* read current message size */
last = TELL(lfh); last = TELL(lfh);
i = read(lfh, str, 15); i = read(lfh, str, 15);
if (i <= 0) if (i <= 0) {
{
close(lfh); close(lfh);
return EL_FILE_ERROR; return EL_FILE_ERROR;
} }
lseek(lfh, -15, SEEK_CUR); lseek(lfh, -15, SEEK_CUR);
if (strncmp(str, "$Start$: ", 9) == 0) if (strncmp(str, "$Start$: ", 9) == 0) {
{ size = atoi(str + 9);
size = atoi(str+9);
lseek(lfh, size, SEEK_CUR); lseek(lfh, size, SEEK_CUR);
} } else {
else
{
close(lfh); close(lfh);
return EL_FILE_ERROR; return EL_FILE_ERROR;
} }
/* if EOF, goto next day */ /* if EOF, goto next day */
i = read(lfh, str, 15); i = read(lfh, str, 15);
if (i < 15) if (i < 15) {
{
close(lfh); close(lfh);
time(&lact); time(&lact);
lt = ltime; lt = ltime;
do do {
{ lt += 3600 * 24;
lt += 3600*24;
tms = localtime(&lt); tms = localtime(&lt);
sprintf(str, "%02d%02d%02d.0", sprintf(str, "%02d%02d%02d.0",
tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday); tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday);
status = el_search_message(str, &lfh, FALSE, FALSE); status = el_search_message(str, &lfh, FALSE, FALSE);
} while (status != EL_SUCCESS && } while (status != EL_SUCCESS &&
(INT)lt-(INT)lact < 3600*24); (INT) lt - (INT) lact < 3600 * 24);
if (status != EL_SUCCESS) if (status != EL_SUCCESS) {
{
if (fh) if (fh)
*fh = lfh; *fh = lfh;
else else
@ -569,12 +545,11 @@ char *file_list;
/* go to beginning of current file */ /* go to beginning of current file */
lseek(lfh, 0, SEEK_SET); lseek(lfh, 0, SEEK_SET);
} } else
else
lseek(lfh, -15, SEEK_CUR); lseek(lfh, -15, SEEK_CUR);
/* adjust tag */ /* adjust tag */
sprintf(strchr(tag, '.')+1, "%d", (int) (TELL(lfh))); sprintf(strchr(tag, '.') + 1, "%d", (int) (TELL(lfh)));
} }
if (fh) if (fh)
@ -592,8 +567,7 @@ INT el_submit(char attr_name[MAX_N_ATTR][NAME_LENGTH],
int n_attr, char *text, char *reply_to, char *encoding, int n_attr, char *text, char *reply_to, char *encoding,
char afilename[MAX_ATTACHMENTS][256], char afilename[MAX_ATTACHMENTS][256],
char *buffer[MAX_ATTACHMENTS], char *buffer[MAX_ATTACHMENTS],
INT buffer_size[MAX_ATTACHMENTS], INT buffer_size[MAX_ATTACHMENTS], char *tag, INT tag_size)
char *tag, INT tag_size)
/********************************************************************\ /********************************************************************\
Routine: el_submit Routine: el_submit
@ -624,44 +598,39 @@ INT el_submit(char attr_name[MAX_N_ATTR][NAME_LENGTH],
\********************************************************************/ \********************************************************************/
{ {
INT n, i, size, fh, status, index, offset, tail_size; INT n, i, size, fh, status, index, offset, tail_size;
struct tm *tms; struct tm *tms;
char file_name[256], afile_name[MAX_ATTACHMENTS][256], dir[256], str[256], char file_name[256], afile_name[MAX_ATTACHMENTS][256], dir[256],
start_str[80], end_str[80], last[80], date[80], thread[80], attachment_all[64*MAX_ATTACHMENTS]; str[256], start_str[80], end_str[80], last[80], date[80],
time_t now; thread[80], attachment_all[64 * MAX_ATTACHMENTS];
char message[TEXT_SIZE+100], *p; time_t now;
BOOL bedit; char message[TEXT_SIZE + 100], *p;
BOOL bedit;
bedit = (tag[0] != 0); bedit = (tag[0] != 0);
for (index = 0 ; index < MAX_ATTACHMENTS ; index++) for (index = 0; index < MAX_ATTACHMENTS; index++) {
{
/* generate filename for attachment */ /* generate filename for attachment */
afile_name[index][0] = file_name[0] = 0; afile_name[index][0] = file_name[0] = 0;
if (afilename[index][0] && buffer_size[index] == 0) if (afilename[index][0] && buffer_size[index] == 0) {
{
/* resubmission of existing attachment */ /* resubmission of existing attachment */
strcpy(afile_name[index], afilename[index]); strcpy(afile_name[index], afilename[index]);
} } else {
else if (afilename[index][0]) {
{
if (afilename[index][0])
{
/* strip directory, add date and time to filename */ /* strip directory, add date and time to filename */
strcpy(file_name, afilename[index]); strcpy(file_name, afilename[index]);
p = file_name; p = file_name;
while (strchr(p, ':')) while (strchr(p, ':'))
p = strchr(p, ':')+1; p = strchr(p, ':') + 1;
while (strchr(p, '\\')) while (strchr(p, '\\'))
p = strchr(p, '\\')+1; /* NT */ p = strchr(p, '\\') + 1; /* NT */
while (strchr(p, '/')) while (strchr(p, '/'))
p = strchr(p, '/')+1; /* Unix */ p = strchr(p, '/') + 1; /* Unix */
/* assemble ELog filename */ /* assemble ELog filename */
if (p[0]) if (p[0]) {
{
strcpy(dir, data_dir); strcpy(dir, data_dir);
time(&now); time(&now);
@ -669,20 +638,17 @@ BOOL bedit;
strcpy(str, p); strcpy(str, p);
sprintf(afile_name[index], "%02d%02d%02d_%02d%02d%02d_%s", sprintf(afile_name[index], "%02d%02d%02d_%02d%02d%02d_%s",
tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday, tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday,
tms->tm_hour, tms->tm_min, tms->tm_sec, str); tms->tm_hour, tms->tm_min, tms->tm_sec, str);
sprintf(file_name, "%s%02d%02d%02d_%02d%02d%02d_%s", dir, sprintf(file_name, "%s%02d%02d%02d_%02d%02d%02d_%s", dir,
tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday, tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday,
tms->tm_hour, tms->tm_min, tms->tm_sec, str); tms->tm_hour, tms->tm_min, tms->tm_sec, str);
/* save attachment */ /* save attachment */
fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644); fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644);
if (fh < 0) if (fh < 0) {
{
printf("Cannot write attachment file \"%s\"", file_name); printf("Cannot write attachment file \"%s\"", file_name);
} } else {
else
{
write(fh, buffer[index], buffer_size[index]); write(fh, buffer[index], buffer_size[index]);
close(fh); close(fh);
} }
@ -694,13 +660,11 @@ BOOL bedit;
/* generate new file name YYMMDD.log in data directory */ /* generate new file name YYMMDD.log in data directory */
strcpy(dir, data_dir); strcpy(dir, data_dir);
if (bedit) if (bedit) {
{
/* edit existing message */ /* edit existing message */
strcpy(str, tag); strcpy(str, tag);
if (strchr(str, '.')) if (strchr(str, '.')) {
{ offset = atoi(strchr(str, '.') + 1);
offset = atoi(strchr(str, '.')+1);
*strchr(str, '.') = 0; *strchr(str, '.') = 0;
} }
sprintf(file_name, "%s%s.log", dir, str); sprintf(file_name, "%s%s.log", dir, str);
@ -710,7 +674,7 @@ BOOL bedit;
lseek(fh, offset, SEEK_SET); lseek(fh, offset, SEEK_SET);
read(fh, str, 16); read(fh, str, 16);
size = atoi(str+9); size = atoi(str + 9);
read(fh, message, size); read(fh, message, size);
el_decode(message, "Date: ", date); el_decode(message, "Date: ", date);
@ -719,30 +683,26 @@ BOOL bedit;
/* buffer tail of logfile */ /* buffer tail of logfile */
lseek(fh, 0, SEEK_END); lseek(fh, 0, SEEK_END);
tail_size = TELL(fh) - (offset+size); tail_size = TELL(fh) - (offset + size);
if (tail_size > 0) if (tail_size > 0) {
{
buffer = malloc(tail_size); buffer = malloc(tail_size);
if (buffer == NULL) if (buffer == NULL) {
{
close(fh); close(fh);
return -1; return -1;
} }
lseek(fh, offset+size, SEEK_SET); lseek(fh, offset + size, SEEK_SET);
n = read(fh, buffer, tail_size); n = read(fh, buffer, tail_size);
} }
lseek(fh, offset, SEEK_SET); lseek(fh, offset, SEEK_SET);
} } else {
else
{
/* create new message */ /* create new message */
time(&now); time(&now);
tms = localtime(&now); tms = localtime(&now);
sprintf(file_name, "%s%02d%02d%02d.log", dir, sprintf(file_name, "%s%02d%02d%02d.log", dir,
tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday); tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday);
fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644); fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644);
if (fh < 0) if (fh < 0)
@ -762,76 +722,68 @@ BOOL bedit;
/* compose message */ /* compose message */
sprintf(message, "Date: %s\n", date); sprintf(message, "Date: %s\n", date);
sprintf(message+strlen(message), "Thread: %s\n", thread); sprintf(message + strlen(message), "Thread: %s\n", thread);
for (i=0 ; i<n_attr ; i++) for (i = 0; i < n_attr; i++)
sprintf(message+strlen(message), "%s: %s\n", attr_name[i], attr_value[i]); sprintf(message + strlen(message), "%s: %s\n", attr_name[i],
attr_value[i]);
/* keep original attachment if edit and no new attachment */ /* keep original attachment if edit and no new attachment */
if (bedit) if (bedit) {
{ for (i = n = 0; i < MAX_ATTACHMENTS; i++) {
for (i=n=0 ; i<MAX_ATTACHMENTS ; i++)
{
if (i == 0) if (i == 0)
p = strtok(attachment_all, ","); p = strtok(attachment_all, ",");
else else if (p != NULL)
if (p != NULL)
p = strtok(NULL, ","); p = strtok(NULL, ",");
if (p && (afile_name[i][0])) if (p && (afile_name[i][0])) {
{
/* delete old attachment */ /* delete old attachment */
strcpy(str, data_dir); strcpy(str, data_dir);
strcat(str, p); strcat(str, p);
remove(str); remove(str);
} }
if (afile_name[i][0]) if (afile_name[i][0]) {
{ if (n == 0) {
if (n == 0) sprintf(message + strlen(message), "Attachment: %s",
{ afile_name[i]);
sprintf(message+strlen(message), "Attachment: %s", afile_name[i]);
n++; n++;
} } else
else sprintf(message + strlen(message), ",%s", afile_name[i]);
sprintf(message+strlen(message), ",%s", afile_name[i]);
} }
else if (p) else if (p) {
{ if (n == 0) {
if (n == 0) sprintf(message + strlen(message), "Attachment: %s", p);
{
sprintf(message+strlen(message), "Attachment: %s", p);
n++; n++;
} } else
else sprintf(message + strlen(message), ",%s", p);
sprintf(message+strlen(message), ",%s", p);
} }
} }
} } else {
else sprintf(message + strlen(message), "Attachment: %s", afile_name[0]);
{ for (i = 1; i < MAX_ATTACHMENTS; i++)
sprintf(message+strlen(message), "Attachment: %s", afile_name[0]);
for (i=1 ; i<MAX_ATTACHMENTS ; i++)
if (afile_name[i][0]) if (afile_name[i][0])
sprintf(message+strlen(message), ",%s", afile_name[i]); sprintf(message + strlen(message), ",%s", afile_name[i]);
} }
sprintf(message+strlen(message), "\n"); sprintf(message + strlen(message), "\n");
sprintf(message+strlen(message), "Encoding: %s\n", encoding); sprintf(message + strlen(message), "Encoding: %s\n", encoding);
sprintf(message+strlen(message), "========================================\n"); sprintf(message + strlen(message),
"========================================\n");
strcat(message, text); strcat(message, text);
size = 0; size = 0;
sprintf(start_str, "$Start$: %6d\n", size); sprintf(start_str, "$Start$: %6d\n", size);
sprintf(end_str, "$End$: %6d\n\f", size); sprintf(end_str, "$End$: %6d\n\f", size);
size = strlen(message)+strlen(start_str)+strlen(end_str); size = strlen(message) + strlen(start_str) + strlen(end_str);
if (tag != NULL && !bedit) if (tag != NULL && !bedit)
sprintf(tag, "%02d%02d%02d.%d", tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday, (int) (TELL(fh))); sprintf(tag, "%02d%02d%02d.%d", tms->tm_year % 100, tms->tm_mon + 1,
tms->tm_mday, (int) (TELL(fh)));
sprintf(start_str, "$Start$: %6d\n", size); sprintf(start_str, "$Start$: %6d\n", size);
sprintf(end_str, "$End$: %6d\n\f", size); sprintf(end_str, "$End$: %6d\n\f", size);
@ -840,10 +792,8 @@ BOOL bedit;
write(fh, message, strlen(message)); write(fh, message, strlen(message));
write(fh, end_str, strlen(end_str)); write(fh, end_str, strlen(end_str));
if (bedit) if (bedit) {
{ if (tail_size > 0) {
if (tail_size > 0)
{
n = write(fh, buffer, tail_size); n = write(fh, buffer, tail_size);
free(buffer); free(buffer);
} }
@ -859,14 +809,11 @@ BOOL bedit;
close(fh); close(fh);
/* if reply, mark original message */ /* if reply, mark original message */
if (reply_to[0] && !bedit) if (reply_to[0] && !bedit) {
{
strcpy(last, reply_to); strcpy(last, reply_to);
do do {
{
status = el_search_message(last, &fh, FALSE, FALSE); status = el_search_message(last, &fh, FALSE, FALSE);
if (status == EL_SUCCESS) if (status == EL_SUCCESS) {
{
/* position to next thread location */ /* position to next thread location */
lseek(fh, 72, SEEK_CUR); lseek(fh, 72, SEEK_CUR);
memset(str, 0, sizeof(str)); memset(str, 0, sizeof(str));
@ -874,21 +821,17 @@ BOOL bedit;
lseek(fh, -16, SEEK_CUR); lseek(fh, -16, SEEK_CUR);
/* if no reply yet, set it */ /* if no reply yet, set it */
if (atoi(str) == 0) if (atoi(str) == 0) {
{
sprintf(str, "%16s", tag); sprintf(str, "%16s", tag);
write(fh, str, 16); write(fh, str, 16);
close(fh); close(fh);
break; break;
} } else {
else
{
/* if reply set, find last one in chain */ /* if reply set, find last one in chain */
strcpy(last, strtok(str, " ")); strcpy(last, strtok(str, " "));
close(fh); close(fh);
} }
} } else
else
/* stop on error */ /* stop on error */
break; break;
@ -923,17 +866,14 @@ INT el_get_v1(char *tag, char *message, int *bufsize)
\********************************************************************/ \********************************************************************/
{ {
int i, size, fh, offset, search_status; int i, size, fh, offset, search_status;
char str[256]; char str[256];
if (tag[0]) if (tag[0]) {
{
search_status = el_search_message(tag, &fh, TRUE, FALSE); search_status = el_search_message(tag, &fh, TRUE, FALSE);
if (search_status != EL_SUCCESS) if (search_status != EL_SUCCESS)
return search_status; return search_status;
} } else {
else
{
/* open most recent message */ /* open most recent message */
strcpy(tag, "-1"); strcpy(tag, "-1");
search_status = el_search_message(tag, &fh, TRUE, FALSE); search_status = el_search_message(tag, &fh, TRUE, FALSE);
@ -944,16 +884,14 @@ char str[256];
/* extract message size */ /* extract message size */
offset = TELL(fh); offset = TELL(fh);
i = read(fh, str, 16); i = read(fh, str, 16);
if (i <= 0) if (i <= 0) {
{
close(fh); close(fh);
return EL_FILE_ERROR; return EL_FILE_ERROR;
} }
if (strncmp(str, "$Start$: ", 9) == 0) if (strncmp(str, "$Start$: ", 9) == 0)
size = atoi(str+9); size = atoi(str + 9);
else else {
{
close(fh); close(fh);
return EL_FILE_ERROR; return EL_FILE_ERROR;
} }
@ -973,11 +911,11 @@ char str[256];
void scan_messages() void scan_messages()
{ {
int size, status, fh, message_id, i, n, n_messages; int size, status, fh, message_id, i, n, n_messages;
char file_name[256], tag[256], str[256], last_file[256]; char file_name[256], tag[256], str[256], last_file[256];
char message[TEXT_SIZE+1000]; char message[TEXT_SIZE + 1000];
char *ps, *pd, *file_list; char *ps, *pd, *file_list;
THREAD *thread_list; THREAD *thread_list;
tag[0] = 0; tag[0] = 0;
message_id = 1; message_id = 1;
@ -986,8 +924,7 @@ THREAD *thread_list;
/* search first message */ /* search first message */
status = el_search_message(tag, NULL, TRUE, TRUE); status = el_search_message(tag, NULL, TRUE, TRUE);
if (status == EL_FILE_ERROR) if (status == EL_FILE_ERROR) {
{
printf("Cannot find any ??????.log file in this directory.\n"); printf("Cannot find any ??????.log file in this directory.\n");
return; return;
} }
@ -996,14 +933,13 @@ THREAD *thread_list;
file_list = NULL; file_list = NULL;
getcwd(str, sizeof(str)); getcwd(str, sizeof(str));
n = ss_file_find(str, "??????a.log", &file_list); n = ss_file_find(str, "??????a.log", &file_list);
for (i=0 ; i<n ; i++) for (i = 0; i < n; i++)
unlink(file_list+i*MAX_PATH_LENGTH); unlink(file_list + i * MAX_PATH_LENGTH);
if (file_list) if (file_list)
free(file_list); free(file_list);
/* build thread_list */ /* build thread_list */
do do {
{
size = sizeof(message); size = sizeof(message);
status = el_get_v1(tag, message, &size); status = el_get_v1(tag, message, &size);
@ -1013,17 +949,16 @@ THREAD *thread_list;
if (status == EL_LAST_MSG) if (status == EL_LAST_MSG)
break; break;
strcpy(thread_list[message_id-1].v1_tag, tag); strcpy(thread_list[message_id - 1].v1_tag, tag);
thread_list[message_id-1].message_id = message_id; thread_list[message_id - 1].message_id = message_id;
/* extract thread */ /* extract thread */
if (strstr(message, "Thread:")) if (strstr(message, "Thread:")) {
{ ps = strstr(message, "Thread:") + 7;
ps = strstr(message, "Thread:")+7;
while (*ps && !isdigit(*ps)) while (*ps && !isdigit(*ps))
ps++; ps++;
pd = thread_list[message_id-1].in_reply_to; pd = thread_list[message_id - 1].in_reply_to;
while (isdigit(*ps) || ispunct(*ps)) while (isdigit(*ps) || ispunct(*ps))
*pd++ = *ps++; *pd++ = *ps++;
*pd = 0; *pd = 0;
@ -1031,7 +966,7 @@ THREAD *thread_list;
while (*ps && !isdigit(*ps)) while (*ps && !isdigit(*ps))
ps++; ps++;
pd = thread_list[message_id-1].reply; pd = thread_list[message_id - 1].reply;
while (isdigit(*ps) || ispunct(*ps)) while (isdigit(*ps) || ispunct(*ps))
*pd++ = *ps++; *pd++ = *ps++;
*pd = 0; *pd = 0;
@ -1039,7 +974,7 @@ THREAD *thread_list;
message_id++; message_id++;
strcat(tag, "+1"); strcat(tag, "+1");
thread_list = realloc(thread_list, sizeof(THREAD)*message_id); thread_list = realloc(thread_list, sizeof(THREAD) * message_id);
} while (1); } while (1);
@ -1054,8 +989,7 @@ THREAD *thread_list;
/* search first message */ /* search first message */
status = el_search_message(tag, NULL, TRUE, TRUE); status = el_search_message(tag, NULL, TRUE, TRUE);
do do {
{
size = sizeof(message); size = sizeof(message);
status = el_get_v1(tag, message, &size); status = el_get_v1(tag, message, &size);
@ -1068,18 +1002,15 @@ THREAD *thread_list;
if (verbose) if (verbose)
printf("Converting %s -> %s, ID %d\n", tag, str, message_id); printf("Converting %s -> %s, ID %d\n", tag, str, message_id);
else else {
{ if (!equal_ustring(str, last_file)) {
if (!equal_ustring(str, last_file))
{
printf("Converting %s.log to %sa.log\n", str, str); printf("Converting %s.log to %sa.log\n", str, str);
strcpy(last_file, str); strcpy(last_file, str);
} }
} }
fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644); fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644);
if (fh < 0) if (fh < 0) {
{
printf("Error: Cannot open file %s for writing.\n", file_name); printf("Error: Cannot open file %s for writing.\n", file_name);
free(thread_list); free(thread_list);
return; return;
@ -1092,29 +1023,28 @@ THREAD *thread_list;
write(fh, str, strlen(str)); write(fh, str, strlen(str));
/* write reply-to and in-reply-to */ /* write reply-to and in-reply-to */
if (atoi(thread_list[message_id-1].reply) > 0) if (atoi(thread_list[message_id - 1].reply) > 0) {
{
/* search id for reply */ /* search id for reply */
for (i=0 ; i<n_messages ; i++) for (i = 0; i < n_messages; i++)
if (strstr(thread_list[i].v1_tag, thread_list[message_id-1].reply)) if (strstr
(thread_list[i].v1_tag, thread_list[message_id - 1].reply))
break; break;
if (i < n_messages) if (i < n_messages) {
{
sprintf(str, "Reply to: %d\n", thread_list[i].message_id); sprintf(str, "Reply to: %d\n", thread_list[i].message_id);
write(fh, str, strlen(str)); write(fh, str, strlen(str));
} }
} }
if (atoi(thread_list[message_id-1].in_reply_to) > 0) if (atoi(thread_list[message_id - 1].in_reply_to) > 0) {
{
/* search id for reply */ /* search id for reply */
for (i=0 ; i<n_messages ; i++) for (i = 0; i < n_messages; i++)
if (strstr(thread_list[i].v1_tag, thread_list[message_id-1].in_reply_to)) if (strstr
(thread_list[i].v1_tag,
thread_list[message_id - 1].in_reply_to))
break; break;
if (i < n_messages) if (i < n_messages) {
{
sprintf(str, "In reply to: %d\n", thread_list[i].message_id); sprintf(str, "In reply to: %d\n", thread_list[i].message_id);
write(fh, str, strlen(str)); write(fh, str, strlen(str));
} }
@ -1124,7 +1054,7 @@ THREAD *thread_list;
if (strstr(message, "$End$")) if (strstr(message, "$End$"))
*strstr(message, "$End$") = 0; *strstr(message, "$End$") = 0;
if (message[strlen(message)-1] != '\n') if (message[strlen(message) - 1] != '\n')
strcat(message, "\n"); strcat(message, "\n");
write(fh, message, strlen(message)); write(fh, message, strlen(message));
@ -1142,20 +1072,17 @@ THREAD *thread_list;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i; int i;
/* parse command line parameters */ /* parse command line parameters */
for (i=1 ; i<argc ; i++) for (i = 1; i < argc; i++) {
{
if (argv[i][0] == '-' && argv[i][1] == 'v') if (argv[i][0] == '-' && argv[i][1] == 'v')
verbose = TRUE; verbose = TRUE;
else if (argv[i][0] == '-') else if (argv[i][0] == '-') {
{ if (i + 1 >= argc || argv[i + 1][0] == '-')
if (i+1 >= argc || argv[i+1][0] == '-')
goto usage; goto usage;
else else {
{ usage:
usage:
printf("usage: %s ", argv[0]); printf("usage: %s ", argv[0]);
printf(" -v debugging output\n"); printf(" -v debugging output\n");
return 0; return 0;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff