Exemple #1
0
hline_t *mkh_received(HEADER_State *head, hline_t *t, char *line) {

  memset(t, 0, sizeof(hline_t));
  t->tag = hltRCV;
  t->toffset = head->hdata.curline;

  if( parse_822_received(line, &t->data.rcv.rfc822) ) {
    t->state |= (1<<H_STATE_RFC822);
  }

  if( parse_821_time_stamp_line(line, &t->data.rcv.rfc821) ) {
    t->state |= (1<<H_STATE_RFC821);
  }

  if( parse_2821_time_stamp_line(line, &t->data.rcv.rfc2821, RFC_2821_STRICT) ) {
    t->state |= (1<<H_STATE_RFC2821);
  } else if( parse_2821_time_stamp_line(line, &t->data.rcv.rfc2821, RFC_2821_LAX) ) {
    t->state |= (1<<H_STATE_RFC2821lax);
  }

  if( parse_2822_received(line, &t->data.rcv.rfc2822, RFC_2822_STRICT) ) {
    t->state |= (1<<H_STATE_RFC2822);
  } else if( parse_2822_received(line, &t->data.rcv.rfc2822, RFC_2822_OBSOLETE) ) {
    t->state |= (1<<H_STATE_RFC2822obs);
  } else if( parse_2822_received(line, &t->data.rcv.rfc2822, RFC_2822_LAX) ) {
    t->state |= (1<<H_STATE_RFC2822lax);
  }


  if( t->state & ((1<<H_STATE_RFC2821)|(1<<H_STATE_RFC2821lax)) ) {
    t->data.rcv.numsec = cvt_date(&t->data.rcv.rfc2821.datetime_);
  } else if( t->state & ((1<<H_STATE_RFC2822)|(1<<H_STATE_RFC2822obs)|(1<<H_STATE_RFC2822lax)) ) {
    t->data.rcv.numsec = cvt_date(&t->data.rcv.rfc2822.datetime_);
  } else if( t->state & (1<<H_STATE_RFC822) ) {
    t->data.rcv.numsec = cvt_date(&t->data.rcv.rfc822.datetime_);
  } else {
    t->data.rcv.numsec = -1;
  }

  if( t->data.dat.numsec == (time_t)(-1) ) {
    t->state |= (1<<H_STATE_BAD_DATA);
  }

  if( (u_options & (1<<U_OPTION_DEBUG)) ) {
    fprintf(stdout, "RECEIVED %ld", t->data.rcv.numsec);
    print_state(stdout, t);
  }

  return t;
}
static int get_session_info(
  char *line,
  int line_len,
  struct session_info_struct *session_info,
  int session_ix)
{
  int n;
  int work;

  for (n = 0; n < line_len; n++) {
    if (line[n] == TAB)
      break;
  }

  if (n == line_len)
    return 1;

  line[n++] = 0;

  session_info->start_date = cvt_date(line);
  session_info->start_ix = session_ix;

  sscanf(&line[n],"%d",&work);

  session_info->ending_amount = work;
  session_info->max_underwater_length = -1;

  return 0;
}
static int get_session_info(
  char *line,
  int line_len,
  struct session_info_struct *session_info)
{
  int n;
  int work;

  for (n = 0; n < line_len; n++) {
    if (line[n] == TAB)
      break;
  }

  if (n == line_len)
    return 1;

  line[n++] = 0;

  session_info->start_date = cvt_date(line);

  sscanf(&line[n],"%d",&work);

  session_info->delta = work;

  return 0;
}
static int get_session_date(char *line,time_t *session_date)
{
  *session_date = cvt_date(line);

  if (*session_date == -1L)
    return 1;

  return 0;
}
static int get_today(time_t *today_ptr)
{
    int n;
    time_t now;
    char *cpt;
    int retval;
    int month;
    char today_buf[11];
    time_t today;

    time(&now);
    cpt = ctime(&now);

    retval = get_month(&cpt[4],&month);

    if (retval)
        return 1;

    sprintf(today_buf,"%02d-",month);

    for (n = 0; n < 2; n++)
        today_buf[3+n] = cpt[8+n];

    if (today_buf[3] == ' ')
        today_buf[3] = '0';

    today_buf[5] = '-';

    for (n = 0; n < 4; n++)
        today_buf[6+n] = cpt[20+n];

    today_buf[10] = 0;

    today = cvt_date(today_buf);

    if (today == -1L)
        return 2;

    *today_ptr = today;

    return 0;
}
static int get_session_info(
  char *line,
  int line_len,
  struct session_info_struct *session_info)
{
  int m;
  int n;

  for (n = 0; n < line_len; n++) {
    if (line[n] == TAB)
      break;
  }

  if (n == line_len)
    return 1;

  line[n++] = 0;

  session_info->poker_session_date = cvt_date(line);

  m = n;

  for ( ; n < line_len; n++) {
    if (line[n] == TAB)
      break;
  }

  if (n == line_len)
    return 1;

  line[n++] = 0;

  sscanf(&line[m],"%d",&session_info->delta);
  sscanf(&line[n],"%d",&session_info->starting_amount);

  return 0;
}
int main(int argc,char **argv)
{
    int n;
    int curr_arg;
    bool bDebug;
    bool bRuntot;
    int retval;
    time_t today;
    time_t date1;
    time_t date2;
    char *cpt;
    int weekday_counts[NUM_WEEKDAYS];
    int weekday;
    int total_days;

    if ((argc < 3) || (argc > 5)) {
        printf(usage);
        return 1;
    }

    bDebug = false;
    bRuntot= false;

    for (curr_arg = 1; curr_arg < argc; curr_arg++) {
        if (!strcmp(argv[curr_arg],"-debug"))
            bDebug = true;
        else if (!strcmp(argv[curr_arg],"-runtot"))
            bRuntot = true;
        else
            break;
    }

    if (argc - curr_arg != 2) {
        printf(usage);
        return 2;
    }

    retval = get_today(&today);

    if (retval) {
        printf("get_today() failed: %d\n",retval);
        return 3;
    }

    if (!strcmp(argv[curr_arg],"today"))
        date1 = today;
    else
        date1 = cvt_date(argv[curr_arg]);

    if (date1 == -1L) {
        printf("%s: invalid date\n",argv[curr_arg]);
        return 4;
    }

    if (!strcmp(argv[curr_arg+1],"today"))
        date2 = today;
    else
        date2 = cvt_date(argv[curr_arg+1]);

    if (date2 == -1L) {
        printf("%s: invalid date\n",argv[curr_arg+1]);
        return 5;
    }

    if (bDebug) {
        cpt = ctime(&date1);
        cpt[strlen(cpt)-1] = 0;
        printf("date1: %s\n",cpt);
        cpt = ctime(&date2);
        cpt[strlen(cpt)-1] = 0;
        printf("date2: %s\n",cpt);
    }

    if (date1 >= date2) {
        printf("date1 must be less than date2\n");
        return 6;
    }

    for (n = 0; n < NUM_WEEKDAYS; n++)
        weekday_counts[n] = 0;

    for ( ; date1 < date2; date1 += SECS_PER_DAY) {
        cpt = ctime(&date1);

        retval = get_weekday(&cpt[0],&weekday);

        if (retval) {
            printf("get_weekday_failed: %d\n",retval);
            return 7;
        }

        weekday_counts[weekday]++;
    }

    total_days = 0;

    for (n = 0; n < NUM_WEEKDAYS; n++) {
        total_days += weekday_counts[n];

        if (!bRuntot)
            printf("%7d %s\n",weekday_counts[n],weekdays[n]);
        else
            printf("%7d %s %7d\n",weekday_counts[n],weekdays[n],total_days);
    }

    if (!bRuntot)
        printf("\n%7d\n",total_days);

    return 0;
}