Superpixel::Superpixel(int id, int num_points) { this->id = id; this->num_points = num_points; init_structures(num_points); //this->pixels = cv::Mat(50, 50, CV_8UC3, cvScalar(0,0,0)); }
void simulator_main(int argc, char** argv) { init_knobs(argc, argv); // trace driven simulation read_trace_file(); init_structures(); run_a_cycle(); }
void simulator_main(int argc, char** argv) { init_knobs(argc, argv); // trace driven simulation read_trace_file(); /** NEW-LAB2 */ /* just note: passing main memory pointers is hack to mix up c++ objects and c-style code */ /* Not recommended at all */ memory_c *main_memory = new memory_c(); // /** NEW-LAB2 */ init_structures(main_memory); // please modify run_a_cycle function argument /** NEW-LAB2 */ run_a_cycle(main_memory); // please modify run_a_cycle function argument /** NEW-LAB2 */ }
void simulator_main(int argc, char** argv) { init_knobs(argc, argv); // trace driven simulation read_trace_file(); /** NEW-LAB2 */ /* just note: passing main memory pointers is hack to mix up c++ objects and c-style code */ /* Not recommended at all */ memory_c *main_memory = new memory_c(); // /** NEW-LAB2 */ init_structures(main_memory); // please modify run_a_cycle function argument /** NEW-LAB2 */ /*LAB 3*/ if(KNOB(KNOB_USE_BPRED)->getValue()) { use_bpred=true; bpred_type type=(bpred_type) KNOB(KNOB_BPRED_TYPE)->getValue(); unsigned int bhr_len; if(type == BPRED_TAKEN || type == BPRED_NOTTAKEN || type == BPRED_BIMODAL) bhr_len=0; else if(type == BPRED_GSHARE) bhr_len=KNOB(KNOB_BPRED_HIST_LEN)->getValue(); branchpred=bpred_new(type,bhr_len); } /*LAB 3*/ if(KNOB(KNOB_ENABLE_VMEM)->getValue()) { vmem_enabled=true; dtlb = tlb_new(KNOB(KNOB_TLB_ENTRIES)->getValue()); vmem_page_size=KNOB(KNOB_VMEM_PAGE_SIZE)->getValue(); } run_a_cycle(main_memory); // please modify run_a_cycle function argument /** NEW-LAB2 */ }
/* ** This is the initializer function of the display structure. ** It puts every parameter to default value, then creates the window ** and prints the loading screen before loading the assets. */ int init_display(t_display *d) { if (init_structures(d) == -1) return (-1); if (SDL_Init(SDL_INIT_EVERYTHING) || TTF_Init()) return (-1); SDL_WM_SetCaption("Zappy", NULL); d->w = SDL_SetVideoMode(1440, 900, 32, SDL_SWSURFACE); d->loading_screen = SDL_LoadBMP("./assets/screens/loading_screen.bmp"); if (d->w == NULL || d->loading_screen == NULL) return (-1); display_loading_screen(d, 0); if (launch_music(d) == -1) return (-1); d->font = TTF_OpenFont("./assets/fonts/filxgirl.ttf", 30); if (!d->font) return (-1); load_images(d); if (strlen(SDL_GetError()) > 0) return (-1); if (display_loading_screen(d, 1) == -1) return (-1); return (0); }
void load_conf(void) { FILE *fc; char line[128]; char *p, *q, **tmp; int lineno = 0; size_t tmplen; struct conf_entry *curr_section = NULL; void *value = NULL; /* initialize the structures */ init_structures(); DEBUG_MSG("load_conf"); /* the user has specified an alternative config file */ if (GBL_CONF->file) { DEBUG_MSG("load_conf: alternative config: %s", GBL_CONF->file); fc = fopen(GBL_CONF->file, FOPEN_READ_TEXT); ON_ERROR(fc, NULL, "Cannot open %s", GBL_CONF->file); } else { /* errors are handled by the function */ fc = open_data("etc", ETTER_CONF, FOPEN_READ_TEXT); ON_ERROR(fc, NULL, "Cannot open %s", ETTER_CONF); } /* read the file */ while (fgets(line, 128, fc) != 0) { /* update the line count */ lineno++; /* trim out the comments */ if ((p = strchr(line, '#'))) *p = '\0'; /* trim out the new line */ if ((p = strchr(line, '\n'))) *p = '\0'; q = line; /* trim the initial spaces */ while (q < line + sizeof(line) && *q == ' ') q++; /* skip empty lines */ if (line[0] == '\0' || *q == '\0') continue; /* here starts a new section [...] */ if (*q == '[') { /* remove the square brackets */ if ((p = strchr(line, ']'))) *p = '\0'; else FATAL_ERROR("Missing ] in %s line %d", ETTER_CONF, lineno); p = q + 1; DEBUG_MSG("load_conf: SECTION: %s", p); /* get the pointer to the right structure */ if ( (curr_section = search_section(p)) == NULL) FATAL_ERROR("Invalid section in %s line %d", ETTER_CONF, lineno); /* read the next line */ continue; } /* variable outside a section */ if (curr_section == NULL) FATAL_ERROR("Entry outside a section in %s line %d", ETTER_CONF, lineno); /* sanity check */ if (!strchr(q, '=')) FATAL_ERROR("Parse error %s line %d", ETTER_CONF, lineno); p = q; /* split the entry name from the value */ do { if (*p == ' ' || *p == '='){ *p = '\0'; break; } } while (p++ < line + sizeof(line) ); /* move p to the value */ p++; do { if (*p != ' ' && *p != '=') break; } while (p++ < line + sizeof(line) ); /* * if it is the "dissector" section, * do it in a different way */ if (curr_section == (struct conf_entry *)&dissectors) { set_dissector(q, p, lineno); continue; } /* search the entry name */ if ( (value = search_entry(curr_section, q)) == NULL) FATAL_ERROR("Invalid entry in %s line %d", ETTER_CONF, lineno); /* strings must be handled in a different way */ if (curr_section == (struct conf_entry *)&strings) { /* trim the quotes */ if (*p == '"') p++; /* set the string value */ tmp = (char **)value; *tmp = strdup(p); /* trim the ending quotes */ p = *tmp; tmplen = strlen(*tmp); do { if (*p == '"') { *p = 0; break; } } while (p++ < *tmp + tmplen ); DEBUG_MSG("load_conf: \tENTRY: %s [%s]", q, *tmp); } else { /* set the integer value */ *(int *)value = strtol(p, (char **)NULL, 10); DEBUG_MSG("load_conf: \tENTRY: %s %d", q, *(int *)value); } } sanity_checks(); fclose(fc); }
/* *************************************************************************** * Main entry to the sar program. *************************************************************************** */ int main(int argc, char **argv) { int i, rc, opt = 1, args_idx = 2; int fd[2]; int day_offset = 0; char from_file[MAX_FILE_LEN], to_file[MAX_FILE_LEN]; char ltemp[20]; /* Get HZ */ get_HZ(); /* Compute page shift in kB */ get_kb_shift(); from_file[0] = to_file[0] = '\0'; #ifdef USE_NLS /* Init National Language Support */ init_nls(); #endif tm_start.use = tm_end.use = FALSE; /* Allocate and init activity bitmaps */ allocate_bitmaps(act); init_structures(); /* Process options */ while (opt < argc) { if (!strcmp(argv[opt], "-I")) { if (argv[++opt]) { /* Parse -I option */ if (parse_sar_I_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-D")) { /* Option to tell sar to write to saYYYYMMDD data files */ flags |= S_F_SA_YYYYMMDD; opt++; } else if (!strcmp(argv[opt], "-P")) { /* Parse -P option */ if (parse_sa_P_opt(argv, &opt, &flags, act)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-o")) { if (to_file[0]) { /* Output file already specified */ usage(argv[0]); } /* Save stats to a file */ if ((argv[++opt]) && strncmp(argv[opt], "-", 1) && (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { strncpy(to_file, argv[opt++], MAX_FILE_LEN); to_file[MAX_FILE_LEN - 1] = '\0'; } else { strcpy(to_file, "-"); } } else if (!strcmp(argv[opt], "-f")) { if (from_file[0]) { /* Input file already specified */ usage(argv[0]); } /* Read stats from a file */ if ((argv[++opt]) && strncmp(argv[opt], "-", 1) && (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { strncpy(from_file, argv[opt++], MAX_FILE_LEN); from_file[MAX_FILE_LEN - 1] = '\0'; /* Check if this is an alternate directory for sa files */ check_alt_sa_dir(from_file, day_offset, -1); } else { set_default_file(from_file, day_offset, -1); } } else if (!strcmp(argv[opt], "-s")) { /* Get time start */ if (parse_timestamp(argv, &opt, &tm_start, DEF_TMSTART)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-e")) { /* Get time end */ if (parse_timestamp(argv, &opt, &tm_end, DEF_TMEND)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-h")) { /* Display help message */ display_help(argv[0]); } else if (!strcmp(argv[opt], "-i")) { if (!argv[++opt] || (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval < 1) { usage(argv[0]); } flags |= S_F_INTERVAL_SET; } else if (!strcmp(argv[opt], "-m")) { if (argv[++opt]) { /* Parse option -m */ if (parse_sar_m_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-n")) { if (argv[++opt]) { /* Parse option -n */ if (parse_sar_n_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if ((strlen(argv[opt]) > 1) && (strlen(argv[opt]) < 4) && !strncmp(argv[opt], "-", 1) && (strspn(argv[opt] + 1, DIGITS) == (strlen(argv[opt]) - 1))) { day_offset = atoi(argv[opt++] + 1); } else if (!strncmp(argv[opt], "-", 1)) { /* Other options not previously tested */ if ((rc = parse_sar_opt(argv, &opt, act, &flags, C_SAR)) != 0) { if (rc == 1) { usage(argv[0]); } exit(1); } opt++; } else if (interval < 0) { /* Get interval */ if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval < 0) { usage(argv[0]); } } else { /* Get count value */ if ((strspn(argv[opt], DIGITS) != strlen(argv[opt])) || !interval) { usage(argv[0]); } if (count) { /* Count parameter already set */ usage(argv[0]); } count = atol(argv[opt++]); if (count < 1) { usage(argv[0]); } } } /* 'sar' is equivalent to 'sar -f' */ if ((argc == 1) || ((interval < 0) && !from_file[0] && !to_file[0])) { set_default_file(from_file, day_offset, -1); } if (tm_start.use && tm_end.use && (tm_end.tm_hour < tm_start.tm_hour)) { tm_end.tm_hour += 24; } /* * Check option dependencies. */ /* You read from a file OR you write to it... */ if (from_file[0] && to_file[0]) { fprintf(stderr, _("-f and -o options are mutually exclusive\n")); exit(1); } /* Use time start or option -i only when reading stats from a file */ if ((tm_start.use || INTERVAL_SET(flags)) && !from_file[0]) { fprintf(stderr, _("Not reading from a system activity file (use -f option)\n")); exit(1); } /* Don't print stats since boot time if -o or -f options are used */ if (!interval && (from_file[0] || to_file[0])) { usage(argv[0]); } /* Cannot enter a day shift with -o option */ if (to_file[0] && day_offset) { usage(argv[0]); } if (USE_PRETTY_OPTION(flags)) { dm_major = get_devmap_major(); } if (!count) { /* * count parameter not set: Display all the contents of the file * or generate a report continuously. */ count = -1; } /* Default is CPU activity... */ select_default_activity(act); /* Reading stats from file: */ if (from_file[0]) { if (interval < 0) { interval = 1; } /* Read stats from file */ read_stats_from_file(from_file); /* Free stuctures and activity bitmaps */ free_bitmaps(act); free_structures(act); return 0; } /* Reading stats from sadc: */ /* Create anonymous pipe */ if (pipe(fd) == -1) { perror("pipe"); exit(4); } switch (fork()) { case -1: perror("fork"); exit(4); break; case 0: /* Child */ if (dup2(fd[1], STDOUT_FILENO) < 0) { perror("dup2"); exit(4); } CLOSE_ALL(fd); /* * Prepare options for sadc. */ /* Program name */ salloc(0, SADC); /* Interval value */ if (interval < 0) { usage(argv[0]); } else if (!interval) { strcpy(ltemp, "1"); } else { sprintf(ltemp, "%ld", interval); } salloc(1, ltemp); /* Count number */ if (count >= 0) { sprintf(ltemp, "%ld", count + 1); salloc(args_idx++, ltemp); } /* Flags to be passed to sadc */ salloc(args_idx++, "-z"); /* Writing data to a file (option -o) */ if (to_file[0]) { /* Set option -D if entered */ if (USE_SA_YYYYMMDD(flags)) { salloc(args_idx++, "-D"); } /* Collect all possible activities (option -S XALL for sadc) */ salloc(args_idx++, "-S"); salloc(args_idx++, K_XALL); /* Outfile arg */ salloc(args_idx++, to_file); } else { /* * If option -o hasn't been used, then tell sadc * to collect only activities that will be displayed. */ int act_id = 0; for (i = 0; i < NR_ACT; i++) { if (IS_SELECTED(act[i]->options)) { act_id |= act[i]->group; } } if (act_id) { act_id <<= 8; snprintf(ltemp, 19, "%d", act_id); ltemp[19] = '\0'; salloc(args_idx++, "-S"); salloc(args_idx++, ltemp); } } /* Last arg is NULL */ args[args_idx] = NULL; /* Call now the data collector */ execv(SADC_PATH, args); execvp(SADC, args); /* * Note: Don't use execl/execlp since we don't have a fixed number of * args to give to sadc. */ fprintf(stderr, _("Cannot find the data collector (%s)\n"), SADC); perror("exec"); exit(4); break; default: /* Parent */ if (dup2(fd[0], STDIN_FILENO) < 0) { perror("dup2"); exit(4); } CLOSE_ALL(fd); /* Get now the statistics */ read_stats(); break; } /* Free structures and activity bitmaps */ free_bitmaps(act); free_structures(act); return 0; }
/* *************************************************************************** * Main entry to the sar program *************************************************************************** */ int main(int argc, char **argv) { int opt = 1, args_idx = 2; int fd[2]; char from_file[MAX_FILE_LEN], to_file[MAX_FILE_LEN]; char ltemp[20]; /* Get HZ */ get_HZ(); /* Compute page shift in kB */ get_kb_shift(); from_file[0] = to_file[0] = '\0'; #ifdef USE_NLS /* Init National Language Support */ init_nls(); #endif tm_start.use = tm_end.use = FALSE; /* Allocate and init activity bitmaps */ allocate_bitmaps(act); init_structures(); /* Process options */ while (opt < argc) { if (!strcmp(argv[opt], "-I")) { if (argv[++opt]) { /* Parse -I option */ if (parse_sar_I_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-P")) { /* Parse -P option */ if (parse_sa_P_opt(argv, &opt, &flags, act)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-o")) { /* Save stats to a file */ if ((argv[++opt]) && strncmp(argv[opt], "-", 1) && (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { strncpy(to_file, argv[opt++], MAX_FILE_LEN); to_file[MAX_FILE_LEN - 1] = '\0'; } else { strcpy(to_file, "-"); } } else if (!strcmp(argv[opt], "-f")) { /* Read stats from a file */ if ((argv[++opt]) && strncmp(argv[opt], "-", 1) && (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { strncpy(from_file, argv[opt++], MAX_FILE_LEN); from_file[MAX_FILE_LEN - 1] = '\0'; } else { set_default_file(&rectime, from_file); } } else if (!strcmp(argv[opt], "-s")) { /* Get time start */ if (parse_timestamp(argv, &opt, &tm_start, DEF_TMSTART)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-e")) { /* Get time end */ if (parse_timestamp(argv, &opt, &tm_end, DEF_TMEND)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-i")) { if (!argv[++opt] || (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval < 1) { usage(argv[0]); } flags |= S_F_INTERVAL_SET; } else if (!strcmp(argv[opt], "-n")) { if (argv[++opt]) { /* Parse option -n */ if (parse_sar_n_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strncmp(argv[opt], "-", 1)) { /* Other options not previously tested */ if (parse_sar_opt(argv, &opt, act, &flags, C_SAR)) { usage(argv[0]); } opt++; } else if (interval < 0) { /* Get interval */ if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval < 0) { usage(argv[0]); } } else { /* Get count value */ if ((strspn(argv[opt], DIGITS) != strlen(argv[opt])) || !interval) { usage(argv[0]); } if (count) { /* Count parameter already set */ usage(argv[0]); } count = atol(argv[opt++]); if (count < 1) { usage(argv[0]); } } } /* 'sar' is equivalent to 'sar -f' */ if ((argc == 1) || ((interval < 0) && !from_file[0] && !to_file[0])) { set_default_file(&rectime, from_file); } if (tm_start.use && tm_end.use && (tm_end.tm_hour < tm_start.tm_hour)) { tm_end.tm_hour += 24; } /* * Check option dependencies */ /* You read from a file OR you write to it... */ if (from_file[0] && to_file[0]) { fprintf(stderr, _("-f and -o options are mutually exclusive\n")); exit(1); } /* Use time start or option -i only when reading stats from a file */ if ((tm_start.use || INTERVAL_SET(flags)) && !from_file[0]) { fprintf(stderr, _("Not reading from a system activity file (use -f option)\n")); exit(1); } /* Don't print stats since boot time if -o or -f options are used */ if (!interval && (from_file[0] || to_file[0])) { usage(argv[0]); } if (!count) { /* * count parameter not set: Display all the contents of the file * or generate a report continuously. */ count = -1; } /* Default is CPU activity... */ select_default_activity(act); /* ---Reading stats from file */ if (from_file[0]) { if (interval < 0) { interval = 1; } /* Read stats from file */ read_stats_from_file(from_file); return 0; } /* ---Reading stats from sadc */ /* Create anonymous pipe */ if (pipe(fd) == -1) { perror("pipe"); exit(4); } switch (fork()) { case -1: perror("fork"); exit(4); break; case 0: /* Child */ if (dup2(fd[1], STDOUT_FILENO) < 0) { perror("dup2"); exit(4); } CLOSE_ALL(fd); /* * Prepare options for sadc */ /* Program name */ salloc(0, SADC); /* Interval value */ if (interval < 0) { usage(argv[0]); } else if (!interval) { strcpy(ltemp, "1"); } else { sprintf(ltemp, "%ld", interval); } salloc(1, ltemp); /* Count number */ if (count >= 0) { sprintf(ltemp, "%ld", count + 1); salloc(args_idx++, ltemp); } /* Flags to be passed to sadc */ salloc(args_idx++, "-z"); salloc(args_idx++, "-S"); salloc(args_idx++, K_ALL); /* Outfile arg */ if (to_file[0]) { salloc(args_idx++, to_file); } /* Last arg is NULL */ args[args_idx] = NULL; /* Call now the data collector */ execv(SADC_PATH, args); execvp(SADC, args); /* * Note: don't use execl/execlp since we don't have a fixed number of * args to give to sadc. */ fprintf(stderr, _("Cannot find the data collector (%s)\n"), SADC); perror("exec"); exit(4); break; default: /* Parent */ if (dup2(fd[0], STDIN_FILENO) < 0) { perror("dup2"); exit(4); } CLOSE_ALL(fd); /* Get now the statistics */ read_stats(); break; } return 0; }
/* *************************************************************************** * Main entry to the sadf program *************************************************************************** */ int main(int argc, char **argv) { int opt = 1, sar_options = 0; int i; char dfile[MAX_FILE_LEN]; struct tm rectime; /* Get HZ */ get_HZ(); /* Compute page shift in kB */ get_kb_shift(); dfile[0] = '\0'; #ifdef USE_NLS /* Init National Language Support */ init_nls(); #endif tm_start.use = tm_end.use = FALSE; /* Allocate and init activity bitmaps */ allocate_bitmaps(act); /* Init some structures */ init_structures(); /* Process options */ while (opt < argc) { if (!strcmp(argv[opt], "-I")) { if (argv[++opt] && sar_options) { if (parse_sar_I_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-P")) { if (parse_sa_P_opt(argv, &opt, &flags, act)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-s")) { /* Get time start */ if (parse_timestamp(argv, &opt, &tm_start, DEF_TMSTART)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-e")) { /* Get time end */ if (parse_timestamp(argv, &opt, &tm_end, DEF_TMEND)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "--")) { sar_options = 1; opt++; } else if (!strcmp(argv[opt], "-m")) { if (argv[++opt] && sar_options) { /* Parse sar's option -m */ if (parse_sar_m_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-n")) { if (argv[++opt] && sar_options) { /* Parse sar's option -n */ if (parse_sar_n_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strncmp(argv[opt], "-", 1)) { /* Other options not previously tested */ if (sar_options) { if (parse_sar_opt(argv, &opt, act, &flags, C_SADF)) { usage(argv[0]); } } else { for (i = 1; *(argv[opt] + i); i++) { switch (*(argv[opt] + i)) { case 'C': flags |= S_F_COMMENT; break; case 'd': if (format) { usage(argv[0]); } format = F_DB_OUTPUT; break; case 'h': flags |= S_F_HORIZONTALLY; break; case 'H': flags |= S_F_HDR_ONLY; break; case 'j': if (format) { usage(argv[0]); } format = F_JSON_OUTPUT; break; case 'p': if (format) { usage(argv[0]); } format = F_PPC_OUTPUT; break; case 't': flags |= S_F_TRUE_TIME; break; case 'T': flags |= S_F_SEC_EPOCH; break; case 'x': if (format) { usage(argv[0]); } format = F_XML_OUTPUT; break; case 'V': print_version(); break; default: usage(argv[0]); } } } opt++; } /* Get data file name */ else if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { if (!dfile[0]) { if (!strcmp(argv[opt], "-")) { /* File name set to '-' */ set_default_file(&rectime, dfile); opt++; } else if (!strncmp(argv[opt], "-", 1)) { /* Bad option */ usage(argv[0]); } else { /* Write data to file */ strncpy(dfile, argv[opt++], MAX_FILE_LEN); dfile[MAX_FILE_LEN - 1] = '\0'; } } else { /* File already specified */ usage(argv[0]); } } else if (interval < 0) { /* Get interval */ if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval <= 0) { usage(argv[0]); } } else { /* Get count value */ if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { usage(argv[0]); } if (count) { /* Count parameter already set */ usage(argv[0]); } count = atol(argv[opt++]); if (count < 0) { usage(argv[0]); } else if (!count) { count = -1; /* To generate a report continuously */ } } } /* sadf reads current daily data file by default */ if (!dfile[0]) { set_default_file(&rectime, dfile); } if (tm_start.use && tm_end.use && (tm_end.tm_hour < tm_start.tm_hour)) { tm_end.tm_hour += 24; } if (USE_PRETTY_OPTION(flags)) { dm_major = get_devmap_major(); } /* * Display all the contents of the daily data file if the count parameter * was not set on the command line. */ if (!count) { count = -1; } /* Default is CPU activity */ select_default_activity(act); /* Check options consistency with selected output format. Default is PPC display */ check_format_options(); if (interval < 0) { interval = 1; } /* Read stats from file */ read_stats_from_file(dfile); /* Free bitmaps */ free_bitmaps(act); return 0; }
/* *************************************************************************** * Main entry to the sadf program *************************************************************************** */ int main(int argc, char **argv) { int opt = 1, sar_options = 0; int day_offset = 0; int i, rc; char dfile[MAX_FILE_LEN]; char *t; /* Get HZ */ get_HZ(); /* Compute page shift in kB */ get_kb_shift(); dfile[0] = '\0'; #ifdef USE_NLS /* Init National Language Support */ init_nls(); #endif tm_start.use = tm_end.use = FALSE; /* Allocate and init activity bitmaps */ allocate_bitmaps(act); /* Init some structures */ init_structures(); /* Process options */ while (opt < argc) { if (!strcmp(argv[opt], "-I")) { if (argv[++opt] && sar_options) { if (parse_sar_I_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-P")) { if (parse_sa_P_opt(argv, &opt, &flags, act)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-s")) { /* Get time start */ if (parse_timestamp(argv, &opt, &tm_start, DEF_TMSTART)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-e")) { /* Get time end */ if (parse_timestamp(argv, &opt, &tm_end, DEF_TMEND)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-O")) { /* Parse SVG options */ if (!argv[++opt] || sar_options) { usage(argv[0]); } for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) { if (!strcmp(t, K_SKIP_EMPTY)) { flags |= S_F_SVG_SKIP; } else if (!strcmp(t, K_AUTOSCALE)) { flags |= S_F_SVG_AUTOSCALE; } else { usage(argv[0]); } } opt++; } else if ((strlen(argv[opt]) > 1) && (strlen(argv[opt]) < 4) && !strncmp(argv[opt], "-", 1) && (strspn(argv[opt] + 1, DIGITS) == (strlen(argv[opt]) - 1))) { if (dfile[0] || day_offset) { /* File already specified */ usage(argv[0]); } day_offset = atoi(argv[opt++] + 1); } else if (!strcmp(argv[opt], "--")) { sar_options = 1; opt++; } else if (!strcmp(argv[opt], "-m")) { if (argv[++opt] && sar_options) { /* Parse sar's option -m */ if (parse_sar_m_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-n")) { if (argv[++opt] && sar_options) { /* Parse sar's option -n */ if (parse_sar_n_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strncmp(argv[opt], "-", 1)) { /* Other options not previously tested */ if (sar_options) { if ((rc = parse_sar_opt(argv, &opt, act, &flags, C_SADF)) != 0) { if (rc == 1) { usage(argv[0]); } exit(1); } } else { for (i = 1; *(argv[opt] + i); i++) { switch (*(argv[opt] + i)) { case 'C': flags |= S_F_COMMENT; break; case 'c': if (format) { usage(argv[0]); } format = F_CONV_OUTPUT; break; case 'd': if (format) { usage(argv[0]); } format = F_DB_OUTPUT; break; case 'g': if (format) { usage(argv[0]); } format = F_SVG_OUTPUT; break; case 'h': flags |= S_F_HORIZONTALLY; break; case 'H': flags |= S_F_HDR_ONLY; break; case 'j': if (format) { usage(argv[0]); } format = F_JSON_OUTPUT; break; case 'p': if (format) { usage(argv[0]); } format = F_PPC_OUTPUT; break; case 'T': flags |= S_F_LOCAL_TIME; break; case 't': flags |= S_F_TRUE_TIME; break; case 'U': flags |= S_F_SEC_EPOCH; break; case 'x': if (format) { usage(argv[0]); } format = F_XML_OUTPUT; break; case 'V': print_version(); break; default: usage(argv[0]); } } } opt++; } /* Get data file name */ else if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { if (dfile[0] || day_offset) { /* File already specified */ usage(argv[0]); } if (!strcmp(argv[opt], "-")) { /* File name set to '-' */ set_default_file(dfile, 0, -1); opt++; } else if (!strncmp(argv[opt], "-", 1)) { /* Bad option */ usage(argv[0]); } else { /* Write data to file */ strncpy(dfile, argv[opt++], MAX_FILE_LEN); dfile[MAX_FILE_LEN - 1] = '\0'; /* Check if this is an alternate directory for sa files */ check_alt_sa_dir(dfile, 0, -1); } } else if (interval < 0) { /* Get interval */ if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval <= 0) { usage(argv[0]); } } else { /* Get count value */ if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { usage(argv[0]); } if (count) { /* Count parameter already set */ usage(argv[0]); } count = atol(argv[opt++]); if (count < 0) { usage(argv[0]); } else if (!count) { count = -1; /* To generate a report continuously */ } } } /* sadf reads current daily data file by default */ if (!dfile[0]) { set_default_file(dfile, day_offset, -1); } if (tm_start.use && tm_end.use && (tm_end.tm_hour < tm_start.tm_hour)) { tm_end.tm_hour += 24; } if (USE_PRETTY_OPTION(flags)) { dm_major = get_devmap_major(); } /* Options -T, -t and -U are mutually exclusive */ if ((PRINT_LOCAL_TIME(flags) + PRINT_TRUE_TIME(flags) + PRINT_SEC_EPOCH(flags)) > 1) { usage(argv[0]); } /* * Display all the contents of the daily data file if the count parameter * was not set on the command line. */ if (!count) { count = -1; } /* Default is CPU activity */ select_default_activity(act); /* Check options consistency with selected output format. Default is PPC display */ check_format_options(); if (interval < 0) { interval = 1; } if (format == F_CONV_OUTPUT) { /* Convert file to current format */ convert_file(dfile, act); } else { /* Read stats from file */ read_stats_from_file(dfile); } /* Free bitmaps */ free_bitmaps(act); return 0; }
int main(int argc, char** argv) { int tmpresult = 0,i=0,prlen=0,txtlen=0; char tmpbuf[50],tmpbuf2[50]; DEBUG_flag = 1; init_structures(); tmpresult = init_query(TRUE); if (!tmpresult) { sys.error = ERR_SYSINITIALIZE; printf("init_query fail\n"); printf("FAIL\n"); } memset(tmpbuf,0,50); memset(tmpbuf2,0,50); if (argc >= 2) { tmpresult = mode2_detect(argv[1]); if (!tmpresult) { sys.error = ERR_UNKNOWNMODE; printf("FAIL\n"); } } else { sys.error = ERR_UNKNOWNMODE; printf("FAIL\n"); } switch (sys.mode) { case MODE_TEST: printf("send BEEP request\n"); tmpbuf[0] = CMD_BEEP; process_qmes(tmpbuf,1); break; case MODE_STOP: printf("send QMSG_ABORT_S request\n"); send_qmessage(QMSG_ABORT_S, getpid(), 1, query.qbody.message); for (i=0;i<100;i++) { if (recv_qmessage(QMSG_ABORT_R)) break; usleep(1000); } break; case MODE_PTEST: printf("send PTESTPAGE request\n"); tmpbuf[0] = CMD_TEST; process_qmes(tmpbuf,1); break; case MODE_OPENSMENA: printf("send OPEN_SMENA request\n"); tmpbuf[0] = CMD_OPENSMENA; process_qmes(tmpbuf,1); break; case MODE_CLOSESMENA: printf("send CLOSE_SMENA request\n"); tmpbuf[0] = CMD_CLOSESMENA; process_qmes(tmpbuf,1); break; case MODE_NEWPAYMENT: if (argc >= 4) { /*printf("send PRINTTITLE request\n"); tmpbuf[0] = CMD_PRINTTITLE; tmpresult = process_qmes(tmpbuf,1); if (!tmpresult) break;*/ printf("send OPEN_CHECK request\n"); tmpbuf[0] = CMD_OPENCHECK; tmpresult = process_qmes(tmpbuf,1); if (!tmpresult) break; tmpresult = printfile(); if (!tmpresult) break; printf("send SALE request\n"); // FORMAT: // Price:50, text:MTS // <SALE> <Price length> <Price chars> <Text length> <Text chars> // 0 1 2...2+price length price length+3 price length+4...price length+4+text length // [0]=SALE;[1]=2;[2]=5;[3]=0;[4]=3;[5]=M;[6]=T;[7]=S; tmpbuf[0] = CMD_SALE; prlen = strlen(argv[2]); tmpbuf[1] = prlen; //price length for (i=0;i<prlen;i++) { tmpbuf[2+i] = argv[2][i]; //price chars } txtlen = strlen(argv[3]); printf("text length: %d\n",txtlen); tmpbuf[2+prlen] = txtlen; // text message len for (i=0;i<txtlen;i++) { tmpbuf[3+prlen+i] = argv[3][i]; // text mesage } tmpresult = process_qmes(tmpbuf,3+prlen+txtlen); if (!tmpresult) break; printf("send CLOSE_CHECK request\n"); memset(tmpbuf,0,50); tmpbuf[0] = CMD_CLOSECHECK; tmpbuf[1] = prlen; for (i=0;i<prlen;i++) { tmpbuf[2+i] = argv[2][i]; //price chars } txtlen = strlen(argv[3]); printf("text length: %d\n",txtlen); tmpbuf[2+prlen] = txtlen; // text message len for (i=0;i<txtlen;i++) { tmpbuf[3+prlen+i] = argv[3][i]; // text mesage } tmpresult = process_qmes(tmpbuf,3+prlen+txtlen); } else { sys.error = ERR_TOOSHORTPARAM; printf("unknown mode\n"); } break; case MODE_SELFTEST: printf("send SELFTEST request\n"); tmpbuf[0] = CMD_SELFTEST; process_qmes(tmpbuf,1); break; case MODE_GETMODE: printf("send GETMODE request\n"); tmpbuf[0] = CMD_GETMODE; process_qmes(tmpbuf,1); if (query.qbody.message[0] != FALSE) { printf("MODE:%d;\n", query.qbody.message[0]); return 1; } case MODE_INCASS: printf("send INCASS request\n"); tmpbuf[0] = CMD_INCASS; process_qmes(tmpbuf,1); break; case MODE_REPEAT: printf("send REPEAT request\n"); tmpbuf[0] = CMD_REPEAT; process_qmes(tmpbuf,1); break; default: printf("unknown mode\n"); } if (query.qbody.message[0] == TRUE) { printf("DONE\n"); } else { printf("FAIL\n"); } return 1; }