int op_zbreak(stack_frame *fp) { unsigned char *line_addr; zbrk_struct *z_ptr; line_addr = find_line_start(fp->mpc, fp->rvector); assert(NULL != line_addr); line_addr = (unsigned char *)find_line_call(line_addr) - SIZEOF_LA; z_ptr = zr_find(&zbrk_recs, (zb_code *)line_addr); assert(NULL != z_ptr); if (0 < z_ptr->count && 0 < --z_ptr->count) return (TRUE); else { flush_pio(); comp_indr(&z_ptr->action->obj); frame_pointer->type = SFT_ZBRK_ACT; return (FALSE); } }
int main(int argc, char **argv) { int param; long old_pos; unsigned seconds = 0; char *endptr; char *format = strdup(DEFAULT_FORMAT); time_t now = time(NULL); progname = *argv; while ((param = getopt(argc, argv, "s:f:h")) != -1) { switch (param) { case 's': seconds = strtol(optarg, &endptr, 10); if (*endptr != '\0') { die("can't parse seconds"); } break; case 'f': format = strdup(optarg); break; case '?': die("unknown option"); default: die("unknown option"); } } if (optind == argc) { die("need at least one file to process"); } for (; optind < argc; ++optind) { char buffer[DEFAULT_OFFSET]; size_t r; FILE *file = fopen(argv[optind], "r"); if (file == 0) { fprintf(stderr, "%s: can't open '%s': %s\n", progname, argv[optind], strerror(errno)); continue; } if (fseek(file, -DEFAULT_OFFSET, SEEK_END) == -1) { if (fseek(file, 0, SEEK_END) != -1) { fseek(file, 0, SEEK_SET); /* it's short file */ } else { fprintf(stderr, "%s: can't seek in '%s': %s\n", progname, argv[optind], strerror(errno)); continue; } } if (ftell(file) != 0) { find_line_start(file); } while (ftell(file) != 0) { time_t current = read_time(file, format); if (current == 0) { /* can't match line */ fprintf(stderr, "match failed\n"); break; } else { if (current < now - seconds) { break; } } if (fseek(file, -DEFAULT_OFFSET, SEEK_CUR) == -1) { /* it's file start */ break; } if (ftell(file) != 0) { find_line_start(file); } } while (!feof(file)) { old_pos = ftell(file); time_t current = read_time(file, format); find_line_start(file); if (old_pos == ftell(file)) break; if (current == 0) continue; if (current >= now - seconds) { fseek(file, old_pos, SEEK_SET); break; } } while ((r = fread(buffer, 1, DEFAULT_OFFSET, file)) != 0) { fwrite(buffer, 1, r, stdout); } } free(format); return 0; }