Okej, my last message dissapeared into oblivion so I try again. * Wolf J. Flywheel <[EMAIL PROTECTED]>: Well, some more RTFM-ing solved the problem. File attached.
Regards, -- Aner Gusic, LiTH
/* * Written by Aner Gusic <[EMAIL PROTECTED]> * Licence: GPL, se http://www.gnu.org/licenses/gpl.txt for more information. * * TODO: search after FIXME: in the file */ #include <stdio.h> #include <errno.h> #include <time.h> enum { /* what have I just read */ SEPARATOR, SSPACE, ESPACE }; char *get_licqdate(char *s) { char *ch_p; char ch; int state = SEPARATOR, i = 0; static char licq_date[20] = "aaaaaaaaaaaaaaaaaaa"; ch_p = s; while (*ch_p != ']') { /* until end of line */ ch = *ch_p; ch_p++; switch(ch) { case ' ': if (state == SSPACE) { state = ESPACE; } if (state == SEPARATOR) { state = SSPACE; i = 0; /* reset string index */ } break; case '|': state = SEPARATOR; break; case '[': break; default: licq_date[i] = ch; if (i++ == 20) { /* licq_date is only 20 chars long */ licq_date[i] = (char)0; return NULL; } break; } } licq_date[i] = (char)0; return licq_date; /* this should work since licq_date is static */ } char *convert_date(char *licq_date) { char *d_p; time_t tt; tt = atol(licq_date); /* this will at least work on linux systems */ d_p = ctime(&tt); return d_p; } int main(int argc, char *argv[]) { FILE *fd; static char str[60]; char *date; char ch, prev_ch; if (argc == 1) { printf("Syntax: %s licq_history_file\n", argv[0]); exit(1); } fd = fopen(argv[1], "r"); if (fd == NULL) { error(errno); exit(1); } while ((ch = fgetc(fd)) != EOF) { if (ch == '[') { /* if infoline */ fgets(str, 59, fd); /* assume length is <59 chars */ date = convert_date(get_licqdate(str)); printf("\nDate: %s", date); if ((ch = fgetc(fd)) == EOF) break; } if (ch == ':' && prev_ch == '\n') /* indent messages */ if ((ch = fgetc(fd)) == EOF) break; printf("%c", ch); prev_ch = ch; } fclose(fd); exit(0); }