void check_and_display_model(SOLVER_CONTEXT c, FILE *out) { Z3_context ctx = (Z3_context) c; Z3_model m = 0; Z3_lbool result = Z3_check_and_get_model(ctx, &m); switch (result) { case Z3_L_FALSE: fprintf(out, "unsat\n"); break; case Z3_L_UNDEF: fprintf(out, "unknown\n"); fprintf(out, "potential model:\n"); display_model(ctx, out, m); break; case Z3_L_TRUE: fprintf(out, "sat\n"); display_model(ctx, out, m); break; } if (m) { Z3_del_model(ctx, m); } return; }
int main(int argc, const char** argv) { poptContext optCon; exword_t *device; int rsp; optCon = poptGetContext(NULL, argc, argv, options, 0); setlocale(LC_ALL, ""); if (poptGetNextOpt(optCon) < -1) usage(optCon, 1, NULL); if (command & CMD_INTERACTIVE) { interactive(); exit(0); } if ((command & CMD_MASK) == 0) usage(optCon, 1, NULL); if (sd_path && mem_path) usage(optCon, 1, "--sd and --internal options mutually exclusive"); device = exword_open(); if (device == NULL) { fprintf(stderr, "Failed to open device or no device found\n"); } else { exword_set_debug(debug_level); rsp = connect(device); if (rsp == 0x20) { if (sd_path) rsp = set_path(device, SD_CARD, sd_path); else if (mem_path) rsp = set_path(device, INTERNAL_MEM, mem_path); else rsp = set_path(device, INTERNAL_MEM, "\\"); } if (rsp == 0x20) { switch(command & CMD_MASK) { case CMD_LIST: rsp = list_files(device); break; case CMD_MODEL: rsp = display_model(device); break; case CMD_CAPACITY: rsp = display_capacity(device); break; case CMD_SEND: rsp = send_file(device, filename); break; case CMD_GET: rsp = get_file(device, filename); break; case CMD_DELETE: rsp = delete_file(device, filename); break; case CMD_FORMAT: rsp = sd_format(device); break; default: usage(optCon, 1, "No such command"); } } disconnect(device); printf("%s\n", exword_response_to_string(rsp)); exword_close(device); } poptFreeContext(optCon); return 0; }
void interactive() { char * line = NULL; int rsp, ret = 0; exword_t *handle = NULL; printf("exword interactive mode\n"); while (ret != 1) { free(line); line = readline(">> "); if (line == NULL || *line == '\0') continue; add_history(line); ret = parse_commandline(line); if (ret < 0) { printf("Invalid command\n"); continue; } if (handle == NULL && command & REQ_CON_MASK) { printf("Not connected\n"); continue; } switch(command & CMD_MASK) { case CMD_CONNECT: printf("connecting to device..."); handle = exword_open2(open_opts); if (handle == NULL) { printf("device not found\n"); } else { exword_set_debug(debug_level); if(connect(handle) != 0x20) { printf("connect failed\n"); exword_close(handle); handle = NULL; } else { rsp = set_path(handle, INTERNAL_MEM, "/"); printf("done\n"); } } break; case CMD_DISCONNECT: printf("disconnecting..."); disconnect(handle); exword_close(handle); handle = NULL; printf("done\n"); break; case CMD_SETPATH: if (sd_path) rsp = set_path(handle, SD_CARD, sd_path); else rsp = set_path(handle, INTERNAL_MEM, mem_path); if (rsp != 0x20) printf("%s\n", exword_response_to_string(rsp)); break; case CMD_MODEL: rsp = display_model(handle); if (rsp != 0x20) printf("%s\n", exword_response_to_string(rsp)); break; case CMD_LIST: rsp = list_files(handle); if (rsp != 0x20) printf("%s\n", exword_response_to_string(rsp)); break; case CMD_CAPACITY: rsp = display_capacity(handle); if (rsp != 0x20) printf("%s\n", exword_response_to_string(rsp)); break; case CMD_DELETE: printf("deleting..."); rsp = delete_file(handle, filename); printf("%s\n", exword_response_to_string(rsp)); break; case CMD_SEND: printf("uploading..."); rsp = send_file(handle, filename); printf("%s\n", exword_response_to_string(rsp)); break; case CMD_GET: printf("downloading..."); rsp = get_file(handle, filename); printf("%s\n", exword_response_to_string(rsp)); break; case CMD_FORMAT: printf("formatting..."); rsp = sd_format(handle); printf("%s\n", exword_response_to_string(rsp)); break; } } if (handle != NULL) { disconnect(handle); exword_close(handle); } free(line); free(filename); free(sd_path); free(mem_path); }