int main() { mysql_connect(); list_drivers(); list_data_sources(); list_driver_information(); list_tables(); execute_query("select * from junk"); execute_query("select count(*), sum(a) from junk"); execute_query("select a, a+3, 3.141592654 from junk"); execute_query("select j1.a, j2.a from junk j1 natural join junk j2"); mysql_disconnect(); }
void get_driver() { char buffer[20]; int choice; NET_DRIVERNAME *drivers; NET_DRIVERLIST avail; printf ("Detecting available drivers...\n"); avail = net_detectdrivers (net_drivers_all); printf ("Getting detected driver names...\n"); drivers = net_getdrivernames (avail); do { list_drivers (drivers, "Available drivers"); printf ("Please choose a driver from the above list.\n"); fgets (buffer,10,stdin); choice = atoi (buffer); } while (!in_list (drivers, choice)); free (drivers); netdriver = choice; }
static struct snobj *handle_list_drivers(struct snobj *q) { struct snobj *r; int cnt = 1; int offset; r = snobj_list(); for (offset = 0; cnt != 0; offset += cnt) { const int arr_size = 16; const struct driver *drivers[arr_size]; int i; cnt = list_drivers(drivers, arr_size, offset); for (i = 0; i < cnt; i++) snobj_list_add(r, snobj_str(drivers[i]->name)); }; return r; }
int main(int argc, char * const argv[]) { int err = 0, r, c, long_optind = 0; int do_list_readers = 0; int do_list_drivers = 0; int do_list_rdrivers = 0; int do_list_files = 0; int do_send_apdu = 0; int do_print_atr = 0; int do_print_serial = 0; int do_print_name = 0; int action_count = 0; const char *opt_driver = NULL; sc_context_param_t ctx_param; setbuf(stderr, NULL); setbuf(stdout, NULL); while (1) { c = getopt_long(argc, argv, "nlfr:vs:DRc:aw", options, &long_optind); if (c == -1) break; if (c == '?') print_usage_and_die(app_name, options, option_help); switch (c) { case 'l': do_list_readers = 1; action_count++; break; case 'D': do_list_drivers = 1; action_count++; break; case 'R': do_list_rdrivers = 1; action_count++; break; case 'f': do_list_files = 1; action_count++; break; case 's': opt_apdus = (char **) realloc(opt_apdus, (opt_apdu_count + 1) * sizeof(char *)); opt_apdus[opt_apdu_count] = optarg; do_send_apdu++; if (opt_apdu_count == 0) action_count++; opt_apdu_count++; break; case 'a': do_print_atr = 1; action_count++; break; case 'n': do_print_name = 1; action_count++; break; case 'r': opt_reader = atoi(optarg); break; case 'v': verbose++; break; case 'c': opt_driver = optarg; break; case 'w': opt_wait = 1; break; case OPT_SERIAL: do_print_serial = 1; action_count++; break; } } if (action_count == 0) print_usage_and_die(app_name, options, option_help); memset(&ctx_param, 0, sizeof(ctx_param)); ctx_param.ver = 0; ctx_param.app_name = app_name; r = sc_context_create(&ctx, &ctx_param); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); return 1; } if (verbose > 1) ctx->debug = verbose-1; if (do_list_rdrivers) { if ((err = list_reader_drivers())) goto end; action_count--; } if (do_list_readers) { if ((err = list_readers())) goto end; action_count--; } if (do_list_drivers) { if ((err = list_drivers())) goto end; action_count--; } if (action_count <= 0) goto end; if (opt_driver != NULL) { err = sc_set_card_driver(ctx, opt_driver); if (err) { fprintf(stderr, "Driver '%s' not found!\n", opt_driver); err = 1; goto end; } } err = connect_card(ctx, &card, opt_reader, 0, opt_wait, verbose); if (err) goto end; if (do_print_atr) { if (verbose) { printf("Card ATR:\n"); hex_dump_asc(stdout, card->atr, card->atr_len, -1); } else { char tmp[SC_MAX_ATR_SIZE*3]; sc_bin_to_hex(card->atr, card->atr_len, tmp, sizeof(tmp) - 1, ':'); fprintf(stdout,"%s\n",tmp); } action_count--; } if (do_print_serial) { if (verbose) printf("Card serial number:"); print_serial(card); action_count--; } if (do_print_name) { if (verbose) printf("Card name: "); printf("%s\n", card->name); action_count--; } if (do_send_apdu) { if ((err = send_apdu())) goto end; action_count--; } if (do_list_files) { if ((err = list_files())) goto end; action_count--; } end: if (card) { sc_unlock(card); sc_disconnect_card(card, 0); } if (ctx) sc_release_context(ctx); return err; }
int main (void) { NET_DRIVERNAME *drivers; char buffer[NET_MAX_ADDRESS_LENGTH], buffer2[NET_MAX_ADDRESS_LENGTH]; char *ch; int not_ok, x, choice; NET_DRIVERLIST avail; net_init(); net_loadconfig (NULL); printf ("Detecting available drivers...\n"); avail = net_detectdrivers (net_drivers_all); printf ("Getting detected driver names...\n"); drivers = net_getdrivernames (avail); do { list_drivers (drivers, "Available drivers"); printf ("Please choose a driver from the above list.\n"); fgets (buffer, 10, stdin); choice = atoi (buffer); } while (!in_list (drivers, choice)); free (drivers); avail = net_driverlist_create(); net_driverlist_add (avail, choice); if (!net_initdrivers (avail)) { printf("Error initialising driver.\n"); exit (1); } do { printf ("Enter address to prepare:\n"); fgets (buffer, sizeof buffer, stdin); if (feof (stdin)) break; ch = strchr (buffer, '\n'); if (!ch) { printf ("Too long for this lame program...\n"); while (1) { char ch = getchar(); if (ch == EOF || ch == '\n') break; } } else { NET_PREPADDR_DATA *data; *ch = '\0'; printf ("Converting...\n"); data = net_prepareaddress (choice, buffer, buffer2); if (!data) { printf ("Failed to initiate\n"); } else { int x; printf ("Waiting..."); do { printf ("."); fflush(stdout); sleep (1); x = net_poll_prepareaddress (data); } while (!x); printf ("\n"); if (x < 0) { printf ("Failed to convert address\n"); } else { printf ("%s => %s\n", buffer, buffer2); } } } } while (!feof (stdin)); printf ("Quitting...\n"); return 0; }