static int process_stream(FILE *fp) { int follow; struct stat sb; ino_t last_ino = 0; dev_t last_dev = 0; dev_t last_rdev = 0; size_t last_size = 0; char line[LINE_SIZE]; /* Initialise our current position and file "instance" variables. */ if (fstat(fileno(fp), &sb) == 0) { last_ino = sb.st_ino; last_dev = sb.st_dev; last_rdev = sb.st_rdev; last_size = sb.st_size; } follow = follow_flag && fileno(fp) != STDIN_FILENO; while (fgets(line, sizeof (line), fp) != NULL) { process_rules(line); if (follow) { /* Wait for new data to accumulate. */ sleep(POLL_INTERVAL); /* Check for truncation or new instance of file. */ if (fstat(fileno(fp), &sb) || sb.st_size < last_size || sb.st_ino != last_ino || sb.st_dev != last_dev || sb.st_dev != last_rdev) return -1; last_ino = sb.st_ino; last_dev = sb.st_dev; last_rdev = sb.st_rdev; last_size = sb.st_size; } } return 0; }
void solve_sub(bool emscripten_mode) { bool happy = true; #ifdef HEAP_CHECK acf_setup(); #endif if (happy) { index_from = ac_index_new(); happy = index_from; if (!happy) report_fallback(0); } if (happy) { index_to = ac_index_new(); happy = index_to; if (!happy) report_fallback(1); } if (happy) { CARRAY(masks_from, rules_count); happy = masks_from; if (!happy) report_fallback(2); } if (happy) { CARRAY(masks_to, rules_count); happy = masks_to; if (!happy) report_fallback(3); } if (happy) { happy = process_rules(); if (!happy) report_fallback(4); } if (happy) { happy = ac_index_fix(index_from); if (!happy) report_fallback(5); } if (happy) { happy = ac_index_fix(index_to); if (!happy) report_fallback(6); } if (happy) { CARRAY(query_from, rules_count); happy = query_from; if (!happy) report_fallback(7); } if (happy) { CARRAY(query_to, rules_count); happy = query_to; if (!happy) report_fallback(8); } if (happy) { MALLOC_REMAINING(emscripten_mode); happy = results_buffer; if (!happy) report_fallback(9); } if (happy) { happy = process_messages(false); if (!happy) report_fallback(10); } if (happy) { #ifdef HEAP_CHECK fprintf(stderr, "\n--=== no fallback ===--\n\n"); #endif } else { cleanup(); MALLOC_REMAINING(emscripten_mode); if (!results_buffer) abort(); // must work second time process_messages(true); } // fprintf(stderr, "minimal_width %d\n", minimal_width); // fprintf(stderr, "candidates_count %d\n", candidates_count); // fprintf(stderr, "candidates_length %d\n", candidates_length); // fprintf(stderr, "insertions_count %d\n", insertions_count); // fprintf(stderr, "insertions_length %d\n", insertions_length); // fprintf(stderr, "wildcards_count %d\n", wildcards_count); // fprintf(stderr, "wildcards_length %d\n", wildcards_length); // fprintf(stderr, "query_successes %d\n", query_successes); // fprintf(stderr, "handy_calls %d\n", handy_calls); }