CAMLprim value caml_picosat_adjust(value n) { CAMLparam1 (n); picosat_adjust(Int_val(n)); CAMLreturn(Val_unit); }
static const char * parse (PicoSAT * picosat, int force) { int ch, sign, lit, vars, clauses; lineno = 1; inputid = fileno (input); SKIP_COMMENTS: ch = next (); if (ch == 'c') { while ((ch = next ()) != EOF && ch != '\n') ; goto SKIP_COMMENTS; } if (isspace (ch)) goto SKIP_COMMENTS; if (ch != 'p') INVALID_HEADER: return "missing or invalid 'p cnf <variables> <clauses>' header"; if (!isspace (next ())) goto INVALID_HEADER; while (isspace (ch = next ())) ; if (ch != 'c' || next () != 'n' || next () != 'f' || !isspace (next ())) goto INVALID_HEADER; while (isspace (ch = next ())) ; if (!isdigit (ch)) goto INVALID_HEADER; vars = ch - '0'; while (isdigit (ch = next ())) vars = 10 * vars + (ch - '0'); if (!isspace (ch)) goto INVALID_HEADER; while (isspace (ch = next ())) ; if (!isdigit (ch)) goto INVALID_HEADER; clauses = ch - '0'; while (isdigit (ch = next ())) clauses = 10 * clauses + (ch - '0'); if (!isspace (ch) && ch != '\n' ) goto INVALID_HEADER; if (verbose) { fprintf (output, "c parsed header 'p cnf %d %d'\n", vars, clauses); fflush (output); } picosat_adjust (picosat, vars); if (incremental_rup_file) picosat_set_incremental_rup_file (picosat, incremental_rup_file, vars, clauses); lit = 0; READ_LITERAL: ch = next (); if (ch == 'c') { while ((ch = next ()) != EOF && ch != '\n') ; goto READ_LITERAL; } if (ch == EOF) { if (lit) return "trailing 0 missing"; if (clauses && !force) return "clause missing"; return 0; } if (isspace (ch)) goto READ_LITERAL; sign = 1; if (ch == '-') { sign = -1; ch = next (); } if (!isdigit (ch)) return "expected number"; lit = ch - '0'; while (isdigit (ch = next ())) lit = 10 * lit + (ch - '0'); if (!clauses && !force) return "too many clauses"; if (lit) { if (lit > vars && !force) return "maximal variable index exceeded"; lit *= sign; } else clauses--; picosat_add (picosat, lit); goto READ_LITERAL; }