void read_from_file(FILE* fd) { char buf[FILENAME_MAX], c; /* buf is our input buffer */ int i; /* read in each line from file, fgets returns NULL when done */ while (fgets(buf, FILENAME_MAX, fd)) { i = 0; c = buf[i]; while(c != '\0') { /* check for terminating character */ /* check for # or terminating char, * fill remaining buffer with 0's */ if (c== '#' || isspace(c)) bzero(&buf[i], FILENAME_MAX-i); i++; /* count suspected good input */ c = buf[i]; } if (buf[0] == '\0') continue; /* no good input found */ if (verbose) fprintf(stderr, "file arg: %s\n",buf); /* call show_stat, show_dir and show_fs from here as required, * this will save having to pass muliple buffers back to main, * terminate when done. */ show_stat(buf); show_dir(buf); if (filesystem) show_fs(buf); bzero(&buf, FILENAME_MAX); /* reset our buffer to all zero's */ } fclose(fd); exit(EXIT_SUCCESS); }
/****************************************************************************** * GAME_INIT * * * * This function will print the game version and game title. * * It will set the life to MAX_LIFE (7) and reset the stick man. * ******************************************************************************/ void game_init(void) { print_headings(); printstkfgr(MAX_LIFE); show_stat(RESET); lives(MAX_LIFE); }
/* Report system state */ static void sim_report() { #ifdef HAS_GUI if (gui_mode) { report_pc(f_pc, pc_curr->status != STAT_BUB, if_id_curr->stage_pc, if_id_curr->status != STAT_BUB, id_ex_curr->stage_pc, id_ex_curr->status != STAT_BUB, ex_mem_curr->stage_pc, ex_mem_curr->status != STAT_BUB, mem_wb_curr->stage_pc, mem_wb_curr->status != STAT_BUB); report_state("F", 0, format_pc(pc_next)); report_state("F", 1, format_pc(pc_curr)); report_state("D", 0, format_if_id(if_id_next)); report_state("D", 1, format_if_id(if_id_curr)); report_state("E", 0, format_id_ex(id_ex_next)); report_state("E", 1, format_id_ex(id_ex_curr)); report_state("M", 0, format_ex_mem(ex_mem_next)); report_state("M", 1, format_ex_mem(ex_mem_curr)); report_state("W", 0, format_mem_wb(mem_wb_next)); report_state("W", 1, format_mem_wb(mem_wb_curr)); /* signal_sources(); */ show_cc(cc); show_stat(status); show_cpi(); } #endif }
static void show_stats(struct stat64 *sp, char *what) { const char *s = ""; char *w; for (w = strtok(what, ","); w != NULL; w = strtok(NULL, ",")) { printf("%s", s); show_stat(sp, w); s = ","; } printf("\n"); }
/****************************************************************************** * UPDATE * * * * Update the word with the character input then re print the headings * ******************************************************************************/ void update(char c, int word_size, int index, char *guess_word, int rem_lives) { int i; print_headings(); printstkfgr(rem_lives); show_stat(c); lives(rem_lives); guess_word[index] = c; for (i = 0; i < word_size; i++) printf("%c ", guess_word[i]); printf("\n"); }
int main(int argc,char **argv) { anthy_context_t ac; FILE *fp; struct input cur_input; struct res_db *db; struct condition cond; cur_input.serial = 0; cur_input.str = 0; init_condition(&cond); parse_args(&cond, argc, argv); db = create_db(); read_db(db, expdata); printf("./test_anthy --help to print usage.\n"); print_run_env(); fp = fopen(testdata, "r"); if (!fp) { printf("failed to open %s.\n", testdata); return 0; } ac = init_lib(cond.use_utf8); /* ファイルを読んでいくループ */ while (!read_file(fp, &cur_input)) { if (check_cond(&cond, &cur_input)) { set_string(&cond, db, &cur_input, ac); } } anthy_release_context(ac); anthy_quit(); if (cond.ask) { /* ユーザに聞く */ ask_results(db); } show_stat(db); save_db(expdata, db); return 0; }
int main(int argc, char *argv[]) { if (argc < 2) usage(argv[0]); int opt, i, j; FILE *file_in, *file_out; /* declare file pointers for use */ file_in = file_out = NULL; while( -1 != (opt = getopt_long(argc, argv, "hvi:o:f", long_opts, &i)) ) { switch(opt) { case 'h': usage(argv[0]); break; case 'v': verbose = 1; printf(" --verbose enabled-- \n"); fflush(stdout); break; case 'f': filesystem = 1; break; case 'i': file_in = fopen(optarg, "r"); break; case 'o': file_out = freopen(optarg, "w", stdout); break; default: fprintf(stderr, "Invalid option.\n"); usage(argv[0]); break; } } // while if (file_in) read_from_file(file_in); /* if input file was specified */ for (j = optind; j < argc; j++) { /* iterate through argv starting */ show_stat(argv[j]); /* with optind position */ show_dir(argv[j]); if (filesystem) show_fs(argv[j]); /* check for -f flag */ } if (file_in) fclose(file_in); if (file_out) fclose(file_out); /* be sure to close file ptrs */ return 0; }
static void succeed_stat(const char *path) { struct stat buf; int ret; printf("succeed_stat: Try stat(%s)\n", path); ret = stat(path, &buf); if (ret != 0) { printf("succeed_stat: ERROR stat(%s) failed with errno=%d\n", path, errno); g_nerrors++; } else { printf("succeed_stat: stat(%s) succeeded\n", path); show_stat(path, &buf); } }
static int list_file(const char *path) { DIR *dir; struct dirent *entry; dir = opendir(path); if (dir == NULL) { perror("opendir"); return -1; } entry = readdir(dir); while (entry != NULL) { show_stat(entry->d_name); entry = readdir(dir); } closedir(dir); return 0; }
static void fail_stat(const char *path, int expectederror) { struct stat buf; int ret; /* Try stat() against a file or directory. It should fail with expectederror */ printf("fail_stat: Try stat(%s)\n", path); ret = stat(path, &buf); if (ret == 0) { printf("fail_stat: ERROR stat(%s) succeeded\n", path); show_stat(path, &buf); g_nerrors++; } else if (errno != expectederror) { printf("fail_stat: ERROR stat(%s) failed with errno=%d (expected %d)\n", path, errno, expectederror); g_nerrors++; } }
int main(int argc, char *argv[] ) { struct connection *head, *top; //start of list of cons char ch; int opt_idx = 0; static struct option long_opt[] = { {"month", 0, 0, 'm'}, {"user", 0, 0, 'u'}, {"isp", 0, 0, 'i'}, {"human", 0, 0, 'h'}, {"debug", 0, 0, 'd'}, {"help", 0, 0, 'H'}, {"version", 0, 0, 'v'}, {0, 0, 0, 0} }; setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); bindtextdomain(PACKAGE,LOCALEDIR); textdomain(PACKAGE); //getting command line if ( argc > 1 ) { while ( (ch = getopt_long(argc, argv, "muihdv", long_opt, &opt_idx)) != -1 ) switch ( ch ) { case 'm': fl.mounth = 1; break; case 'u': fl.user = 1; break; case 'i': fl.isp = 1; break; case 'h': fl.human = 1; break; case 'd': fl.debug = 1; break; case 'H': usage(); break; case 'v': version(); break; default: fprintf(stderr, _("Bad option %c\n"), ch); usage(); } } else usage(); //extracting logs from archives extract_logs(); //lets roll!! head = parse_logs(); if ( fl.debug ) { show_isp( get_isp() ); printf(_("\nSTAGE 1 - collected all connections:\n")); show_cons(head); } norm_cons(head); if ( fl.debug ) { printf(_("\nSTAGE 2 - normalize connections:\n")); show_cons(head); } top = mkstat(head, &fl); if ( fl.debug ) { printf(_("\nSTAGE 3 - counted specified stats (user=%d, isp=%d)per day:\n"), fl.user, fl.isp); show_cons(top); fprintf(stderr, _("STAGE 3 finished!\n")); } show_stat(head, &fl); exit(0); }
int main(int argc, char **argv) { extern char *optarg; extern int optind; char *optstr; char *servername = NULL; char *yomi = NULL; int ch; int port = -1; int family = AF_INET; optstr = gen_optstring(options); while ((ch = getopt(argc, argv, optstr)) != -1) { switch (ch) { case 'h': usage(); return 0; case 's': servername = strdup(optarg); break; case 'p': port = atoi(optarg); if (port < 0 || port > 65535) { err_message_fnc("Invalid port number(%d).\n", port); return INVALID_PORT_ERROR; } break; case 'f': if (strcasecmp("INET", optarg) == 0) family = AF_INET; else if (strcasecmp("INET6", optarg) == 0) family = AF_INET6; else if (strcasecmp("UNSPEC", optarg) == 0) family = AF_UNSPEC; else if (strcasecmp("4", optarg) == 0) family = AF_INET; else if (strcasecmp("6", optarg) == 0) family = AF_INET6; else if (strcasecmp("IPv4", optarg) == 0) family = AF_INET; else if (strcasecmp("IPv6", optarg) == 0) family = AF_INET6; else { err_message_fnc("Invalid family(%s).\n", optarg); return INVALID_FAMILY_ERROR; } break; case 'y': yomi = strdup(optarg); break; default: usage(); return 0; } } free(optstr); if (optind == argc) { usage(); return 0; } if (strcasecmp(argv[optind], "help") == 0) { usage(); } else if (strcasecmp(argv[optind], "stat") == 0) { if (!servername) servername = strdup("localhost"); show_stat(servername, port, family); free(servername); } else if (strcasecmp(argv[optind], "tran") == 0 && yomi) { if (!servername) servername = strdup("localhost"); translate(servername, port, family, yomi); free(servername); } else { usage(); return 1; } return 0; }
/* ARGSUSED */ void show_xstat(private_t *pri, int version, long offset) { show_stat(pri, offset); }
void show_statat(private_t *pri, long offset) { show_stat(pri, offset); }