* Norberto Bensa <[EMAIL PROTECTED]>:
> Hi,
> 
> is there some way I could do that? I can see any option here :-(

Well, now there is. :)  Se the attachment.  Code might not be great
and I didn't know how that date/time string in history-files is
formated so the program is not really fully functional.


Regards,

-- 
Aner Gusic

"A day for firm decisions!  Or is it?"
   -- fortune
/*
 * 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>

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 15 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) {
  /* FIXME: unknown licq_date format */
  return licq_date;
}


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);       /* hope that length is <29 chars */
      date = convert_date(get_licqdate(str));
      printf("\ndate: %s\n", 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);
}

Reply via email to