void goto_selected_file(FileView *view, const char spec[], int try_open) { char *path_buf; int line_num; path_buf = parse_spec(spec, &line_num); if(path_buf == NULL) { show_error_msg("Memory Error", "Unable to allocate enough memory"); return; } if(access(path_buf, F_OK) == 0) { if(try_open) { open_selected_file(path_buf, line_num); } else { navigate_to_selected_file(view, path_buf); } } else { show_error_msgf("Missing file", "File \"%s\" doesn't exist", path_buf); } free(path_buf); }
static void parse_id (struct sym_id *id) { char *slash; DBG (IDDEBUG, printf ("[parse_id] %s -> ", id->spec)); slash = strchr (id->spec, '/'); if (slash) { parse_spec (slash + 1, &id->right.sym); *slash = '\0'; id->has_right = TRUE; } parse_spec (id->spec, &id->left.sym); #ifdef DEBUG if (debug_level & IDDEBUG) { printf ("%s:", id->left.sym.file ? id->left.sym.file->name : "*"); if (id->left.sym.name) printf ("%s", id->left.sym.name); else if (id->left.sym.line_num) printf ("%d", id->left.sym.line_num); else printf ("*"); if (id->has_right) { printf ("/%s:", id->right.sym.file ? id->right.sym.file->name : "*"); if (id->right.sym.name) printf ("%s", id->right.sym.name); else if (id->right.sym.line_num) printf ("%d", id->right.sym.line_num); else printf ("*"); } printf ("\n"); } #endif }
/* addr is like "udp://127.0.0.1:3333". * only one listener can be set up currently. * we set up a UDP socket file descriptor bound to the port, * during the main loop we get SIGIO on incoming datagram */ void set_listen(parse_t *ps, char *addr) { in_addr_t local_ip; int rc = -1, port, flags; if (parse_spec(ps->cfg, ps->em, addr, &local_ip, &port, NULL)) goto done; if (ps->cfg->test_only) return; /* syntax looked ok */ int fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd == -1) {rc = -2; goto done;} /* set close-on-exec flag for the descriptor so our jobs don't inherit it */ flags = fcntl(fd, F_GETFD); flags |= FD_CLOEXEC; if (fcntl(fd, F_SETFD, flags) == -1) {rc = -3; goto done;} /* specify the local address and port */ struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_addr.s_addr = local_ip; sin.sin_port = htons(port); /* bind our socket to it */ if (bind(fd, (struct sockaddr*)&sin, sizeof(sin)) == -1) { close(fd); rc = -4; utstring_printf(ps->em,"can't bind to %s: %s", addr, strerror(errno)); goto done; } /* enable SIGIO to our pid whenever it becomes readable */ int fl = fcntl(fd, F_GETFL); fl |= O_ASYNC | O_NONBLOCK; fcntl(fd, F_SETFL, fl); fcntl(fd, F_SETOWN, getpid()); /* success */ utarray_push_back(ps->cfg->listen, &fd); rc = 0; done: if (rc == -1) utstring_printf(ps->em, " (at line %d)", ps->line); if (rc == -2) utstring_printf(ps->em,"can't open file descriptor"); if (rc == -3) utstring_printf(ps->em,"can't set close-on-exec"); if (rc == -4) { /* ps->em already set */ } if (rc < 0) ps->rc = -1; }
int main(int argc, char* argv[]) { int retval = NO_ERROR; CLState_p state; ProofState_p proofstate; ProofControl_p proofcontrol; Clause_p success = NULL, filter_success; bool out_of_clauses; char *finals_state = "exists", *sat_status = "Derivation"; long raw_clause_no, preproc_removed=0, neg_conjectures, parsed_ax_no, relevancy_pruned = 0; double preproc_time; assert(argv[0]); pid = getpid(); InitIO(NAME); #ifdef STACK_SIZE IncreaseMaxStackSize(argv, STACK_SIZE); #endif ESignalSetup(SIGXCPU); h_parms = HeuristicParmsAlloc(); fvi_parms = FVIndexParmsAlloc(); wfcb_definitions = PStackAlloc(); hcb_definitions = PStackAlloc(); state = process_options(argc, argv); OpenGlobalOut(outname); print_info(); if(state->argc == 0) { CLStateInsertArg(state, "-"); } proofstate = parse_spec(state, parse_format, error_on_empty, free_symb_prop, &parsed_ax_no); relevancy_pruned += ProofStateSinE(proofstate, sine); relevancy_pruned += ProofStatePreprocess(proofstate, relevance_prune_level); if(strategy_scheduling) { ExecuteSchedule(StratSchedule, h_parms, print_rusage); } FormulaSetDocInital(GlobalOut, OutputLevel, proofstate->f_axioms); ClauseSetDocInital(GlobalOut, OutputLevel, proofstate->axioms); if(prune_only) { fprintf(GlobalOut, "\n# Pruning successful!\n"); TSTPOUT(GlobalOut, "Unknown"); goto cleanup1; } if(relevancy_pruned || incomplete) { proofstate->state_is_complete = false; } if(BuildProofObject) { FormulaSetArchive(proofstate->f_axioms, proofstate->f_ax_archive); } if((neg_conjectures = FormulaSetPreprocConjectures(proofstate->f_axioms, proofstate->f_ax_archive, answer_limit>0, conjectures_are_questions))) { VERBOUT("Negated conjectures.\n"); } if(FormulaSetCNF(proofstate->f_axioms, proofstate->f_ax_archive, proofstate->axioms, proofstate->original_terms, proofstate->freshvars, proofstate->gc_original_terms)) { VERBOUT("CNFization done\n"); } ProofStateInitWatchlist(proofstate, watchlist_filename, parse_format); raw_clause_no = proofstate->axioms->members; if(!no_preproc) { if(BuildProofObject) { ClauseSetArchive(proofstate->ax_archive, proofstate->axioms); if(proofstate->watchlist) { ClauseSetArchive(proofstate->ax_archive, proofstate->watchlist); } } preproc_removed = ClauseSetPreprocess(proofstate->axioms, proofstate->watchlist, proofstate->archive, proofstate->tmp_terms, eqdef_incrlimit, eqdef_maxclauses); } proofcontrol = ProofControlAlloc(); ProofControlInit(proofstate, proofcontrol, h_parms, fvi_parms, wfcb_definitions, hcb_definitions); PCLFullTerms = pcl_full_terms; /* Preprocessing always uses full terms, so we set the flag for the main proof search only now! */ ProofStateInit(proofstate, proofcontrol); VERBOUT2("Prover state initialized\n"); preproc_time = GetTotalCPUTime(); if(print_rusage) { fprintf(GlobalOut, "# Preprocessing time : %.3f s\n", preproc_time); } if(proofcontrol->heuristic_parms.presat_interreduction) { LiteralSelectionFun sel_strat = proofcontrol->heuristic_parms.selection_strategy; proofcontrol->heuristic_parms.selection_strategy = SelectNoGeneration; success = Saturate(proofstate, proofcontrol, LONG_MAX, LONG_MAX, LONG_MAX, LONG_MAX, LONG_MAX); fprintf(GlobalOut, "# Presaturation interreduction done\n"); proofcontrol->heuristic_parms.selection_strategy = sel_strat; if(!success) { ProofStateResetProcessed(proofstate, proofcontrol); } } PERF_CTR_ENTRY(SatTimer); if(!success) { success = Saturate(proofstate, proofcontrol, step_limit, proc_limit, unproc_limit, total_limit, answer_limit); } PERF_CTR_EXIT(SatTimer); out_of_clauses = ClauseSetEmpty(proofstate->unprocessed); if(filter_sat) { filter_success = ProofStateFilterUnprocessed(proofstate, proofcontrol, filterdesc); if(filter_success) { success = filter_success; PStackPushP(proofstate->extract_roots, success); } } if(success||proofstate->answer_count) { assert(!PStackEmpty(proofstate->extract_roots)); if(success) { DocClauseQuoteDefault(2, success, "proof"); } fprintf(GlobalOut, "\n# Proof found!\n"); if(!proofstate->status_reported) { TSTPOUT(GlobalOut, neg_conjectures?"Theorem":"Unsatisfiable"); proofstate->status_reported = true; retval = PROOF_FOUND; } if(BuildProofObject) { DerivationComputeAndPrint(GlobalOut, proofstate->extract_roots, proofstate->signature, proof_graph); } } else if(proofstate->watchlist && ClauseSetEmpty(proofstate->watchlist)) { ProofStatePropDocQuote(GlobalOut, OutputLevel, CPSubsumesWatch, proofstate, "final_subsumes_wl"); fprintf(GlobalOut, "\n# Watchlist is empty!\n"); TSTPOUT(GlobalOut, "ResourceOut"); retval = RESOURCE_OUT; } else { if(out_of_clauses&& proofstate->state_is_complete&& (inf_sys_complete || assume_inf_sys_complete)) { finals_state = "final"; } ProofStatePropDocQuote(GlobalOut, OutputLevel, CPIgnoreProps, proofstate, finals_state); if(cnf_only) { fprintf(GlobalOut, "\n# CNFization successful!\n"); TSTPOUT(GlobalOut, "Unknown"); } else if(out_of_clauses) { if(!(inf_sys_complete || assume_inf_sys_complete)) { fprintf(GlobalOut, "\n# Clause set closed under " "restricted calculus!\n"); if(!SilentTimeOut) { TSTPOUT(GlobalOut, "GaveUp"); } retval = INCOMPLETE_PROOFSTATE; } else if(proofstate->state_is_complete && inf_sys_complete) { fprintf(GlobalOut, "\n# No proof found!\n"); TSTPOUT(GlobalOut, neg_conjectures?"CounterSatisfiable":"Satisfiable"); sat_status = "Saturation"; retval = SATISFIABLE; } else { fprintf(GlobalOut, "\n# Failure: Out of unprocessed clauses!\n"); if(!SilentTimeOut) { TSTPOUT(GlobalOut, "GaveUp"); } retval = INCOMPLETE_PROOFSTATE; } } else { fprintf(GlobalOut, "\n# Failure: User resource limit exceeded!\n"); if(!SilentTimeOut) { TSTPOUT(GlobalOut, "ResourceOut"); } retval = RESOURCE_OUT; } if(BuildProofObject && (retval!=INCOMPLETE_PROOFSTATE)&& (retval!=RESOURCE_OUT)) { ClauseSetPushClauses(proofstate->extract_roots, proofstate->processed_pos_rules); ClauseSetPushClauses(proofstate->extract_roots, proofstate->processed_pos_eqns); ClauseSetPushClauses(proofstate->extract_roots, proofstate->processed_neg_units); ClauseSetPushClauses(proofstate->extract_roots, proofstate->processed_non_units); if(cnf_only) { ClauseSetPushClauses(proofstate->extract_roots, proofstate->unprocessed); print_sat = false; } DerivationComputeAndPrint(GlobalOut, proofstate->extract_roots, proofstate->signature, proof_graph); } } /* ClauseSetDerivationStackStatistics(proofstate->unprocessed); */ if(print_sat) { if(proofstate->non_redundant_deleted) { fprintf(GlobalOut, "\n# Saturated system is incomplete!\n"); } if(success) { fprintf(GlobalOut, "# Saturated system contains the empty clause:\n"); ClausePrint(GlobalOut, success, true); fputc('\n',GlobalOut); fputc('\n',GlobalOut); } ProofStatePrintSelective(GlobalOut, proofstate, outdesc, outinfo); fprintf(GlobalOut, "\n"); } if(success) { ClauseFree(success); } fflush(GlobalOut); print_proof_stats(proofstate, parsed_ax_no, relevancy_pruned, raw_clause_no, preproc_removed); #ifndef FAST_EXIT #ifdef FULL_MEM_STATS fprintf(GlobalOut, "# sizeof TermCell : %ld\n" "# sizeof EqnCell : %ld\n" "# sizeof ClauseCell : %ld\n" "# sizeof PTreeCell : %ld\n" "# sizeof PDTNodeCell : %ld\n" "# sizeof EvalCell : %ld\n" "# sizeof ClausePosCell: %ld\n" "# sizeof PDArrayCell : %ld\n", sizeof(TermCell), sizeof(EqnCell), sizeof(ClauseCell), sizeof(PTreeCell), sizeof(PDTNodeCell), sizeof(EvalCell), sizeof(ClausePosCell), sizeof(PDArrayCell)); fprintf(GlobalOut, "# Estimated memory usage: %ld\n", ProofStateStorage(proofstate)); MemFreeListPrint(GlobalOut); #endif ProofControlFree(proofcontrol); #endif cleanup1: #ifndef FAST_EXIT ProofStateFree(proofstate); CLStateFree(state); PStackFree(hcb_definitions); PStackFree(wfcb_definitions); FVIndexParmsFree(fvi_parms); HeuristicParmsFree(h_parms); #ifdef FULL_MEM_STATS MemFreeListPrint(GlobalOut); #endif #endif if(print_rusage && !SilentTimeOut) { PrintRusage(GlobalOut); } #ifdef CLB_MEMORY_DEBUG RegMemCleanUp(); MemFlushFreeList(); MemDebugPrintStats(stdout); #endif OutClose(GlobalOut); return retval; }
/* report destination is like "udp://machine.org:3333". there can be multiple instances of report destinations. we set up a UDP socket file descriptor 'connected' to the destination so that events can be sent to it at runtime */ void set_report(parse_t *ps, char *dest) { int rc = -1, port, flags; in_addr_t dest_ip; char *iface; if (parse_spec(ps->cfg, ps->em, dest, &dest_ip, &port, &iface)) goto done; if (ps->cfg->test_only) return; /* syntax looked ok */ int fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd == -1) {rc = -2; goto done;} /* set close-on-exec flag for the descriptor so our jobs don't inherit it */ flags = fcntl(fd, F_GETFD); flags |= FD_CLOEXEC; if (fcntl(fd, F_SETFD, flags) == -1) {rc = -3; goto done;} gethostname(ps->cfg->report_id, sizeof(ps->cfg->report_id)); /* use a specific NIC if one was specified, supported here for multicast */ if (iface) { int l = strlen(iface); if (l+1 >IFNAMSIZ) {utstring_printf(ps->em,"interface too long\n"); goto done;} struct ifreq ifr; ifr.ifr_addr.sa_family = AF_INET; memcpy(ifr.ifr_name, iface, l+1); /* does this interface support multicast? */ if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {utstring_printf(ps->em,"ioctl: %s\n", strerror(errno)); goto done;} if (!(ifr.ifr_flags & IFF_MULTICAST)) {utstring_printf(ps->em,"%s does not multicast\n",iface); goto done;} /* get the interface IP address */ struct in_addr iface_addr; if (ioctl(fd, SIOCGIFADDR, &ifr)) {utstring_printf(ps->em,"ioctl: %s\n", strerror(errno)); goto done;} iface_addr = (((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); // utstring_printf(ps->em,"iface %s has addr %s\n", iface, inet_ntoa(iface_addr)); strcat(ps->cfg->report_id, " "); strcat(ps->cfg->report_id, inet_ntoa(iface_addr)); /* ask kernel to use its IP address for outgoing multicast */ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &iface_addr, sizeof(iface_addr))) { utstring_printf(ps->em,"setsockopt: %s\n", strerror(errno)); goto done; } } /* specify the local address and port */ struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_addr.s_addr = dest_ip; sin.sin_port = htons(port); if (connect(fd, (struct sockaddr*)&sin, sizeof(sin)) == -1) { utstring_printf(ps->em, "can't connect to %s: %s", dest, strerror(errno)); rc = -3; goto done; } /* success */ utarray_push_back(ps->cfg->report, &fd); rc = 0; done: if (rc == -1) { /* ps->em already set */ } if (rc == -2) utstring_printf(ps->em,"can't open file descriptor"); if (rc == -3) { /* ps->em already set */ } if (rc < 0) { utstring_printf(ps->em, " at line %d", ps->line); ps->rc = -1; } }