Пример #1
0
static void
on_source_uri_change (GObject *object, GParamSpec *pspec, gpointer data)
{
#if 0
  GSwatDebuggable *debuggable = GSWAT_DEBUGGABLE (object);
  char *uri = gswat_debuggable_get_source_uri (debuggable);
  gint line = gswatt_debuggable_get_source_line (debuggable);
  print_file_range (uri, line, line);
  g_free (uri);
#endif
}
Пример #2
0
/*  Estimates the location, goes to it, calls self
    base case: seems to be close enough to the file

    Assumes we are currently at range->off1
				range->ct1

    pass in buffer to avoid excess memory allocation
    probably should have just made it a loop instead  */
int rec_search_file(FILE *log_file, file_time_range *range, regex_t *date_reg, char *buffer)
{/*{{{*/
  my_time	    cur_time;
  int		    cur_day;
  off_t		    cur_off;
  off_t		    min_dist = (range->avg_sec_size / 2 > MIN_PRINT_RANGE) ? range->avg_sec_size/2 : MIN_PRINT_RANGE;
  regmatch_t	    date_match[2];

  off_t		    est_dist;

  // find out where to seek to
  if(strict_binary_search)
    cur_off = range->off1/2 + range->off2/2;
  else
    cur_off = range->off1 + estimate_distance(range, range->pre_time1);

  // if we are jumping by a trivial amount, just bump it up a bit
  if(0 < cur_off - range->off1 && cur_off - range->off1 < min_dist && range->off2 - range->off1 > 2 * min_dist)
    cur_off = range->off1 + min_dist;
  if(0 > cur_off - range->off1 && cur_off - range->off1 > min_dist && range->off2 - range->off1 > 2 * min_dist)
    cur_off = range->off1 - min_dist;

  // might happen if you're searching for the beginning of a file
  if(cur_off < 0) cur_off = 0;

  fseeko(log_file, cur_off, SEEK_SET);

  // get time where we are
  if(0 >= fread(buffer, 1, MAX_LINE_LEN, log_file)){
    if(feof(log_file))
      fprintf(stderr, "hit eof at offset %lld\n", cur_off);
    else
      fprintf(stderr, "read error!\n");
    return 1;
  } else buffer[MAX_LINE_LEN] = '\0';

  int reg_err = regexec(date_reg, buffer, 2, date_match, 0);
  if(reg_err == REG_NOMATCH){
    fprintf(stderr, "REGEX! Y U NO MATCH?\n");
    return 1;
  }
  else if(reg_err){
    printf("forever alone\n");
    return 1;
  }
  else{
    sscanf(buffer + date_match[1].rm_so, "%d%d:%d:%d", &cur_day, &(cur_time.hour), &(cur_time.min), &(cur_time.sec));
    cur_time.day = (cur_day == range->start_day) ? 0 : 1;
  }
  
  // decide which params to pass to the next recursive call
  file_time_range new_range;
  // if cur_time is ahead of time1, then we make it our new ct2
  // otherwise we make it our new ct1
  if(time_diff(&cur_time, range->time1) >= 0)
    set_range(range, &new_range, range->ct1, &cur_time, range->off1, cur_off);
  else
    set_range(range, &new_range, &cur_time, range->ct2, cur_off, range->off2);

  // REAL BASE CASE!
  // if the estimated distance is greater than 0 (we have to be before the time1)
  // and it's less than the minimum print range, then print
  // - the only case where we accept an est_dist of 0 is at the beginning of the file
  est_dist = estimate_distance(&new_range, range->time1);

  if(((0 < est_dist) && (est_dist < MIN_PRINT_RANGE)) ||
      ((0 == est_dist) && (0 == new_range.off1))){
    fseeko(log_file, new_range.off1, SEEK_SET);
    print_file_range(log_file, &new_range, date_reg);
    return 0;
  }

  // recurse
  return rec_search_file(log_file, &new_range, date_reg, buffer);
}/*}}}*/