/** * Program dispatch; get a line of input, and call the appropriate * command function. */ int main( int argc, char** argv ) { #if DEBUG printf( "Program executed with %d arguments: \n", argc-1 ); for ( int i = 1; i < argc; i++ ) { printf( "Argument: %s \n", argv[i] ); } printf( "\n" ); #endif // Check for -v argument char* verbose_arg = "-v"; for ( int i = 1; i < argc; i++ ) { if ( strcmp( verbose_arg, argv[i] ) == 0 ) { verbose = 1; } } // Initialize database and setup error function db_database* db = db_init(); database = db; atexit( cleanup_db ); // Main loop, get input and process it line by line char input[ LINE_SIZE ]; // input buffer char* tokens[ ARGS_SIZE ]; // array of pointers into input buffer int count; // count of input tokens char* command; // the command string while ( ( count = tokenize_input( input, tokens ) ) >= 0 ) { // Dispatch processing based on the inputted command command = tokens[0]; if ( strcmp( "student", command ) == 0 ) { db_new_student( db, tokens[1], tokens + 2 ); } else if ( strcmp( "open", command ) == 0 ) { db_new_course( db, tokens[1], atoi( tokens[2] ) ); } else if ( strcmp( "cancel", command ) == 0 ) { db_cancel_course( db, tokens[1] ); } else if ( strcmp( "enroll", command ) == 0 ) { db_enroll_student( db, tokens[1], tokens[2] ); } else if ( strcmp( "withdraw", command ) == 0 ) { db_withdraw_student( db, tokens[1], tokens[2] ); } } // Done processing input db_dump( db ); db_destroy( db ); database = NULL; return 0; }
doadump() { FILE *fp; #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doadump()\n"); #endif if ((fp = fopen(dumpfile, "w")) == NULL) return; fprintf(fp, "$ORIGIN .\n"); if (hashtab != NULL) db_dump(hashtab, fp); (void) fclose(fp); }
int ged_dump(struct ged *gedp, int argc, const char *argv[]) { struct rt_wdb *op; int ret; static const char *usage = "file.g"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* must be wanting help */ if (argc == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } if (argc != 2) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } if ((op = wdb_fopen(argv[1])) == RT_WDB_NULL) { bu_vls_printf(gedp->ged_result_str, "dump: %s: cannot create", argv[1]); return GED_ERROR; } ret = db_dump(op, gedp->ged_wdbp->dbip); wdb_close(op); if (ret < 0) { bu_vls_printf(gedp->ged_result_str, "dump: %s: db_dump() error", argv[1]); return GED_ERROR; } return GED_OK; }
void yadb_dump() { db_dump(yadb()); }
void acl_ethertype::event_handler::show(std::ostream& os) { db_dump(m_db, os); }
void acl_ethertype::dump(std::ostream& os) { db_dump(m_db, os); }
/** * pclt for this routine is the comm for reply back to the client * that this command came from. */ static bool_typ slv_cmd( slv_db_typ *pdb, dl_head_typ *pusr, comm_clt_typ *pclt, db_data_typ *precv ) { bool_typ status; db_entry_typ *pentry; switch( precv->cmd ) { case DB_CREATE_CMD: status = db_entry_create( pdb, precv->var, precv->type, (unsigned) precv->value.db_long ); slv_bool_reply( pclt, DB_CREATE_REPLY, status ); if( verbose_flag == TRUE ) db_dump( pdb ); break; case DB_READ_CMD: if( (pentry = db_entry_find( pdb, precv->var, precv->type )) == NULL ) { pentry = db_entry_bad( pdb ); status = FALSE; } else status = TRUE; slv_var_reply( pclt, DB_READ_REPLY, pentry ); break; case DB_UPDATE_CMD: status = slv_update( pdb, precv, pclt->xport ); slv_bool_reply( pclt, DB_UPDATE_REPLY, status ); break; case DB_DESTROY_CMD: status = db_entry_rm( pdb, precv->var, precv->type ); slv_bool_reply( pclt, DB_DESTROY_REPLY, status ); if( verbose_flag == TRUE ) db_dump( pdb ); break; case DB_LOGIN_CMD: status = slv_clt_add( pusr, pclt, &precv->value.login_data ); slv_bool_reply( pclt, DB_LOGIN_REPLY, status ); if( verbose_flag == TRUE ) { slv_clt_dump( pusr ); db_dump( pdb ); } break; case DB_LOGOUT_CMD: status = slv_clt_rm( pusr, pclt ); slv_bool_reply( pclt, DB_LOGOUT_REPLY, status ); if( verbose_flag == TRUE ) slv_clt_dump( pusr ); break; case DB_TRIG_SET_CMD: status = slv_trig_set( pdb, pclt, precv ); slv_bool_reply( pclt, DB_TRIG_SET_REPLY, status ); if( verbose_flag == TRUE ) db_dump( pdb ); break; case DB_TRIG_UNSET_CMD: status = slv_trig_unset( pdb, pclt, precv ); slv_bool_reply( pclt, DB_TRIG_UNSET_REPLY, status ); if( verbose_flag == TRUE ) db_dump( pdb ); break; default: status = FALSE; break; } return( status ); }
doachkpt() { extern int errno; FILE *fp; char tmpcheckfile[256]; /* nowhere to checkpoint cache... */ if (cache_file == NULL) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(to where?)\n"); #endif return; } #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt()\n"); #endif (void) sprintf(tmpcheckfile, "%s.chk", cache_file); if ((fp = fopen(tmpcheckfile, "w")) == NULL) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(can't open %s for write)\n", tmpcheckfile); #endif return; } (void) gettime(&tt); fprintf(fp, "; Dumped at %s", ctime(&tt.tv_sec)); fflush(fp); if (ferror(fp)) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(write to checkpoint file failed)\n"); #endif return; } if (fcachetab != NULL) { int n; if ((n = scan_root(hashtab)) < MINROOTS) { syslog(LOG_ERR, "%d root hints... (too low)", n); fprintf(fp, "; ---- Root hint cache dump ----\n"); (void) db_dump(fcachetab, fp, DB_Z_CACHE, ""); } } if (hashtab != NULL) { fprintf(fp, "; ---- Cache dump ----\n"); if (db_dump(hashtab, fp, DB_Z_CACHE, "") == NODBFILE) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(checkpoint failed)\n"); #endif (void) fclose(fp); return; } } (void) fsync(fileno(fp)); if (fclose(fp) == EOF) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(close failed)\n"); #endif return; } if (rename(tmpcheckfile, cache_file)) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(install %s to %s failed, %d)\n", tmpcheckfile,cache_file, errno); #endif } }
void interface_span::dump(std::ostream& os) { db_dump(m_db, os); }
void interface_span::event_handler::show(std::ostream& os) { db_dump(m_db, os); }
int main(int argc, char *argv[]) { int script_shmid; int ret; char **args; char binary[16] = "launcher"; pid_t launcher_pid; char buffer[128]; FILE *from_child; char *test_case_id_s; int test_case_id; char *result_s; int result; struct item_data it_data; char *exdata; int exdata_len; /* init script and view */ db_msg("core: parse script %s...\n", SCRIPT_NAME); script_shmid = parse_script(SCRIPT_NAME); if (script_shmid == -1) { db_error("core: parse script failed\n"); return -1; } db_msg("core: init script...\n"); ret = init_script(script_shmid); if (ret) { db_error("core: init script failed(%d)\n", ret); return -1; } db_msg("core: init view...\n"); ret = init_view(); if (ret) { db_error("core: init view failed(%d)\n", ret); return -1; } /* parse and draw all test cases to view */ db_msg("core: parse test case from script...\n"); ret = parse_testcase(); if (ret < 0) { db_error("core: parse all test case from script failed(%d)\n", ret); return -1; } else if (ret == 0) { db_warn("core: NO TEST CASE to be run\n"); return -1; } db_msg("core: draw test case to view...\n"); ret = draw_testcases(); if (ret) { db_error("core: draw all test cases to view failed(%d)\n", ret); return -1; } view_sync(); /* create named pipe */ unlink(CMD_PIPE_NAME); if (mkfifo(CMD_PIPE_NAME, S_IFIFO | 0666) == -1) { db_error("core: mkfifo error(%s)\n", strerror(errno)); return -1; } /* fork launcher process */ db_msg("core: fork launcher process...\n"); args = malloc(sizeof(char *) * 6); args[0] = binary; args[1] = malloc(10); sprintf(args[1], "%d", DRAGONBOARD_VERSION); args[2] = malloc(10); sprintf(args[2], "%d", script_shmid); args[3] = malloc(10); sprintf(args[3], "%d", total_testcases); args[4] = malloc(10); sprintf(args[4], "%d", base_info_shmid); args[5] = NULL; launcher_pid = fork(); if (launcher_pid < 0) { db_error("core: fork launcher process failed(%s)\n", strerror(errno)); } else if (launcher_pid == 0) { execvp(binary, args); db_error("core: can't run %s(%s)\n", binary, strerror(errno)); _exit(-1); } /* listening to child process */ db_msg("core: listening to child process, starting...\n"); from_child = fopen(CMD_PIPE_NAME, "r"); while (1) { if (fgets(buffer, sizeof(buffer), from_child) == NULL) { continue; } db_dump("core: command from child: %s", buffer); /* test completion */ test_case_id_s = strtok(buffer, " \n"); db_dump("test case id #%s\n", test_case_id_s); if (strcmp(buffer, TEST_COMPLETION) == 0) break; if (test_case_id_s == NULL) continue; test_case_id = atoi(test_case_id_s); result_s = strtok(NULL, " \n"); db_dump("result: %s\n", result_s); if (result_s == NULL) continue; result = atoi(result_s); exdata = strtok(NULL, "\n"); db_dump("%s TEST %s\n", base_info[test_case_id].name, (result == 0) ? "OK" : "Fail"); /* update view item */ memset(&it_data, 0, sizeof(struct item_data)); strncpy(it_data.name, base_info[test_case_id].name, 32); strncpy(it_data.display_name, base_info[test_case_id].display_name, 64); it_data.category = base_info[test_case_id].category; it_data.status = result; if (exdata) { /* trim space */ while (*exdata == ' ' || *exdata == '\t') exdata++; exdata_len = strlen(exdata); exdata_len--; while (exdata >= 0 && (exdata[exdata_len] == ' ' || exdata[exdata_len] == '\t')) exdata_len--; if (exdata_len > 0) { exdata[++exdata_len] = '\0'; db_dump("extra data len #%d: %s\n", exdata_len, exdata); strncpy(it_data.exdata, exdata, 64); } } view_update_item(test_case_id, &it_data); } fclose(from_child); db_msg("core: listening to child process, stoping...\n"); deparse_testcase(); exit_view(); deinit_script(); deparse_script(script_shmid); return 0; }
int main(int argc, char *argv[]) { char dev_path[64]; FILE *fp; char evt_path[32]; int fd; int version; unsigned short id[4]; char name[32]; unsigned long bit[EV_MAX][NBITS(KEY_MAX)]; int i, j, k; int abs[5]; struct input_event evt[64]; int rd; char buf[64]; char pre_key[64]; INIT_CMD_PIPE(); strncpy(dev_path, "/sys/class/input/event0/device/name", 64); for (i = 0; i < 5; i++) { dev_path[22] = '0' + i; if (access(dev_path, F_OK)) { db_error("can't access %s(%s)\n", dev_path, strerror(errno)); goto err; } fp = fopen(dev_path, "r"); if (fp == NULL) { db_error("can't open %s(%s)\n", dev_path, strerror(errno)); goto err; } if (fgets(evt_path, 32, fp) == NULL) { db_error("can't read %s(%s)\n", dev_path, strerror(errno)); goto err; } if (match_ir(evt_path) == 0) { fclose(fp); break; } fclose(fp); } if (i == 5) { db_error("NO!!! ir input found\n"); goto err; } strncpy(evt_path, "/dev/input/event0", 32); evt_path[16] = '0' + i; if ((fd = open(evt_path, O_RDONLY)) < 0) { db_error("can't open %s(%s)\n", evt_path, strerror(errno)); goto err; } if (ioctl(fd, EVIOCGVERSION, &version)) { db_error("can't get version\n"); goto err; } db_debug("Input driver version is %d.%d.%d\n", version >> 16, (version >> 8) & 0xff, version & 0xff); ioctl(fd, EVIOCGID, id); db_debug("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n", id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]); ioctl(fd, EVIOCGNAME(sizeof(name)), name); db_debug("Input device name: \"%s\"\n", name); memset(bit, 0, sizeof(bit)); ioctl(fd, EVIOCGBIT(0, sizeof(bit[0])), bit[0]); db_dump("Supported events:\n"); for (i = 0; i < EV_MAX; i++) { if (test_bit(i, bit[0])) { db_dump(" Event type %d (%s)\n", i, events[i] ? events[i] : "?"); if (!i) continue; ioctl(fd, EVIOCGBIT(i, sizeof(bit[0])), bit[i]); for (j = 0; j < KEY_MAX; j++) { if (test_bit(j, bit[i])) { db_dump(" Event code %d (%s)\n", j, names[i] ? (names[i][j] ? names[i][j] : "?") : "?"); if (i == EV_ABS) { ioctl(fd, EVIOCGABS(j), abs); for (k = 0; k < 5; k++) { if ((k < 3) || abs[k]) printf("%s %6d\n", absval[k], abs[k]); } } } } } } memset(pre_key, 0, sizeof(pre_key)); while (1) { rd = read(fd, evt, sizeof(struct input_event) * 64); if (rd < (int)sizeof(struct input_event)) { db_error("error in reading\n"); goto err; } for (i = 0; i < rd / sizeof(struct input_event); i++) { if (evt[i].type == EV_SYN) { ; } else if (evt[i].type == EV_MSC && (evt[i].code == MSC_RAW || evt[i].code == MSC_SCAN)) { db_debug("%s, %s(%d, %02x)\n", events[evt[i].type] ? events[evt[i].type] : "?", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", evt[i].code, evt[i].value); if (evt[i].value) continue; if (pre_key[0]) { snprintf(buf, sizeof(buf), "%s, %s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", pre_key); } else { snprintf(buf, sizeof(buf), "%s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?"); } snprintf(pre_key, sizeof(pre_key), "%s", buf); SEND_CMD_PIPE_OK_EX(buf); } else { db_debug("%s, %s(%d, %02x)\n", events[evt[i].type] ? events[evt[i].type] : "?", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", evt[i].code, evt[i].value); if (evt[i].value) continue; if (pre_key[0]) { snprintf(buf, sizeof(buf), "%s, %s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", pre_key); } else { snprintf(buf, sizeof(buf), "%s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?"); } snprintf(pre_key, sizeof(pre_key), "%s", buf); SEND_CMD_PIPE_OK_EX(buf); } } } err: SEND_CMD_PIPE_FAIL(); EXIT_CMD_PIPE(); return 0; }