コード例 #1
0
ファイル: md2html.c プロジェクト: klampworks/beelzebub
/* Convert a given markdown file into a HTML file of the same name but in the given 
 * directory path_out. */
int convert_move_file(const char *file_in, const char *path_out)
{
	const char *file_tmp = "tmp";

	if (path_out && *path_out != '\0') {
		if (xmkdir(path_out)) {
			printf("Could not create directory <%s>\n", path_out);
			return 1;
		}
	}

	if (convert_file(file_in, file_tmp)) {
		printf("Could not convert file <%s>\n", file_in);
		return 1;
	}

	char *file_out = create_path(file_in, path_out);
	if (rename(file_tmp, file_out)) {
		printf("Could not move <%s> to <%s>\n%s\n", 
			file_tmp, file_out, strerror(errno));
		free(file_out);
		return 1;
	}

	free(file_out);
	return 0;
}
コード例 #2
0
ファイル: ucn.cpp プロジェクト: FoxKyong/boinc
int main(int argc, char **argv) {
    char buf[256];
    int retval = boinc_init();
    if (retval) {
        fprintf(stderr, "%s boinc_init returned %d\n",
            boinc_msg_prefix(buf, sizeof(buf)), retval
        );
        exit(retval);
    }

    for (int i=1; i<argc; i++) {
        if (!strcmp(argv[i], "--cpu_time")) {
            cpu_time = atof(argv[++i]);
        } else {
            retval = convert_file(argv[i], argv[i+1]);
            if (retval) exit(-1);
            i++;
        }
    }

    // burn up some CPU time if needed
    //
    if (cpu_time) {
        double start = dtime();
        for (int i=0; ; i++) {
            double e = dtime()-start;
            if (e > cpu_time) break;
            comp_result = do_some_computing(i);
        }
    }
    boinc_finish(0);
}
コード例 #3
0
int
main(int argc, char **argv) {
    int rc = 1;
    opts.spaces = 2;

    command_t cmd;
    command_init(&cmd, argv[0], "1.0.0");
    command_option(&cmd
                   , "-v"
                   , "--verbose"
                   , "enable verbose stuff"
                   , set_verbose);
    command_option(&cmd
                   , "-s"
                   , "--spaces [count]"
                   , "optional number of spaces (defaults to 2)"
                   , set_spaces);
    command_parse(&cmd, argc, argv);

    for (int i = 0; i < cmd.argc; ++i) {
        if (-1 == convert_file(cmd.argv[i])) goto cleanup;
    }

    rc = 0;

cleanup:
    command_free(&cmd);
    return rc;
}
コード例 #4
0
ファイル: ctohtml.c プロジェクト: HarryR/sanos
void convert_directory(char *path) {
  struct dirent *dp;
  DIR *dirp;
  char filename[NAME_MAX + 1];
  char dirname[NAME_MAX + 1];
  struct stat st;

  strcpy(dirname, output_dir);
  if (strlen(path) > source_prefix_len) {
    strcat(dirname, "/");
    strcat(dirname, path + source_prefix_len);
  }
  mkdir(dirname, 0644);

  dirp = opendir(path);
  if (!dirp) return;
  while ((dp = readdir(dirp))) {
    if (strcmp(dp->d_name, ".") == 0) continue;
    if (strcmp(dp->d_name, "..") == 0) continue;
    if (strcmp(dp->d_name, "CVS") == 0) continue;
    
    strcpy(filename, path);
    strcat(filename, "/");
    strcat(filename, dp->d_name);
    if (stat(filename, &st) < 0) continue;
    if (S_ISDIR(st.st_mode)) convert_directory(filename);
    if (S_ISREG(st.st_mode)) convert_file(filename);
  }
  closedir(dirp);
}
コード例 #5
0
ファイル: sch2bob.c プロジェクト: Bronski/sch2bob
int main(int argc, char **argv) {
    for (int i = 1; i < argc; ++i) {
	convert_file(argv[i]);
    }

    return 0;
}
コード例 #6
0
int main(int argc, char** argv) {
    char *input_filename = NULL;
    char *catalog_filename = NULL;
    char *output_filename = NULL;

    rs_module_t *modules = NULL;
    long modules_count = 2;
    long module_index = 0;

#if HAVE_XLSXWRITER
    modules_count++;
#endif

    modules = calloc(modules_count, sizeof(rs_module_t));

    modules[module_index++] = rs_mod_readstat;
    modules[module_index++] = rs_mod_csv;

#if HAVE_XLSXWRITER
    modules[module_index++] = rs_mod_xlsx;
#endif

    if (argc == 2 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) {
        print_version();
        return 0;
    } else if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
        print_usage(argv[0]);
        return 0;
    } else if (argc == 2) {
        if (!can_read(argv[1])) {
            print_usage(argv[0]);
            return 1;
        }
        input_filename = argv[1];
    } else if (argc == 3) {
        if (!can_read(argv[1]) || !can_write(modules, modules_count, argv[2])) {
            print_usage(argv[0]);
            return 1;
        }
        input_filename = argv[1];
        output_filename = argv[2];
    } else if (argc == 4) {
        if (!can_read(argv[1]) || !is_catalog(argv[2]) || !can_write(modules, modules_count, argv[3])) {
            print_usage(argv[0]);
            return 1;
        }
        input_filename = argv[1];
        catalog_filename = argv[2];
        output_filename = argv[3];
    } else {
        print_usage(argv[0]);
        return 1;
    }

    if (output_filename)
        return convert_file(input_filename, catalog_filename, output_filename, modules, modules_count);

    return dump_file(input_filename);
}
コード例 #7
0
ファイル: WAVEDIT.CPP プロジェクト: jimmccurdy/ArchiveGit
void convert_files(const char *pName,
						 int nNewAmplitude,
						 int nPercent,
						 DWORD __huge *pdwHistogram,
						 int nNewBits,
						 const char *pExtension,
						 const char *pDestDir)
{
	struct _find_t findbuf;

	for (unsigned uRet = _dos_findfirst(pName, _A_NORMAL|_A_RDONLY, &findbuf);
		  uRet == 0;
		  uRet = _dos_findnext(&findbuf))
	{
		char cbDestName[_MAX_PATH];
		char *p;

	/*
	// Prepend the path we want.
	*/

		if (pDestDir == NULL)
		{
			*cbDestName = '\0';
		}
		else
		{
			strcpy(cbDestName, pDestDir);
			p = cbDestName + strlen(cbDestName);
			if (p[-1] != '\\' && p[-1] != ':')
			{
				*p++ = '\\';
				*p = 0;
			}
		}

		strcat(cbDestName, findbuf.name);

	/*
	// Append the extension we want.
	*/

		if ((p = strrchr(cbDestName, '.')) == NULL)
		{
			strcat(cbDestName, pExtension);
		}
		else
		{
			strcpy(p, pExtension);
		}

		convert_file(findbuf.name,
						 cbDestName,
						 nNewAmplitude,
						 nPercent,
						 pdwHistogram,
						 nNewBits);
	}
}
コード例 #8
0
ファイル: iconvert.cpp プロジェクト: Nazg-Gul/oiio
int
main (int argc, char *argv[])
{
    Filesystem::convert_native_arguments (argc, (const char **)argv);
    getargs (argc, argv);

    OIIO::attribute ("threads", nthreads);

    bool ok = true;

    if (inplace) {
        for (auto&& s : filenames)
            ok &= convert_file (s, s);
    } else {
        ok = convert_file (filenames[0], filenames[1]);
    }

    return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #9
0
ファイル: client.c プロジェクト: ujohnny/infocoll
int main(int argc, char **argv)
{
	signal(SIGINT, sigint_handler);
	if (argc == 1 || argc == 2 && strcmp(argv[1], "-h") == 0) {
		print_help();
		return 0;
	}

	if (argc == 3) {
		int file_format;
		if (strcmp(argv[1], "-b") == 0) {
			fp = fopen(argv[2], "wb");
			file_format = BINARY;
		} else if (strcmp(argv[1], "-t") == 0) {
			fp = fopen(argv[2], "w");
			file_format = TEXT;
		} else {
			printf("Incorrect option.\n");
			print_help();
			return -1; 
		}
		
		if (!fp) {
			printf("Error opening file.\n");
			return -2;
		}
		
		start_logging(fp, file_format);
		close(fp);
		return 0;
	} 

	if (argc == 4 && strcmp(argv[1], "-c") == 0) {
		f_in = fopen(argv[2], "rb");
		f_out = fopen(argv[3], "w");
		
		if (!(f_in && f_out)) {
			printf("Error opening file\n");
			return -3;
		}

		convert_file(f_in, f_out);
		
		fclose(f_in);
		fclose(f_out);
		return 0;
	} 
	
	printf("Incorrect option.\n");
	print_help();
	return -1;
}
コード例 #10
0
int main(int argc, char **argv)
{
	struct arguments args;
	int idx = -1, missing = 0;
	const struct argp argp = {
		.options = options,
		.parser = parse_opt,
		.doc = N_("scan DVB services using the channel file"),
		.args_doc = N_("<input file> <output file>"),
	};

#ifdef ENABLE_NLS
	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);
#endif

	memset(&args, 0, sizeof(args));
	argp_parse(&argp, argc, argv, ARGP_NO_HELP | ARGP_NO_EXIT, &idx, &args);

	if (idx + 1 < argc) {
		args.input_file = argv[idx];
		args.output_file = argv[idx + 1];
	}

	if (args.input_format == FILE_UNKNOWN) {
		fprintf(stderr, _("ERROR: Please specify a valid input format\n"));
		missing = 1;
	} else if (!args.input_file) {
		fprintf(stderr, _("ERROR: Please specify a valid input file\n"));
		missing = 1;
	} else if (args.output_format == FILE_UNKNOWN) {
		fprintf(stderr, _("ERROR: Please specify a valid output format\n"));
		missing = 1;
	} else if (!args.output_file) {
		fprintf(stderr, _("ERROR: Please specify a valid output file\n"));
		missing = 1;
	} else if (((args.input_format == FILE_ZAP) ||
		   (args.output_format == FILE_ZAP)) &&
		   (args.delsys <= 0 || args.delsys == SYS_ISDBS)) {
		fprintf(stderr, _("ERROR: Please specify a valid delivery system for ZAP format\n"));
		missing = 1;
	}
	if (missing) {
		argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME);
		return -1;
	}

	return convert_file(&args);
}
コード例 #11
0
ファイル: main.cpp プロジェクト: yilinhe/graphpartition
int main(int argc, const char * argv[]) {
    // insert code here...
    int k = 2;
    std::string inputFile = "example_input.txt";
    std::string outputFile = "result";
    convert_file(inputFile,outputFile); 
    std::string cmd = "./kway ";
    cmd+=outputFile + " ";
    cmd.append(std::to_string(k));
    system(cmd.c_str());
    cmd = "rm ";
    cmd.append(outputFile);
    system(cmd.c_str());
    return 0;
}
コード例 #12
0
int main(int argc, char **argv)
{
	struct arguments args;
	int idx = -1, missing = 0;
	const struct argp argp = {
		.options = options,
		.parser = parse_opt,
		.doc = "scan DVB services using the channel file",
		.args_doc = "<input file> <output file>",
	};

	memset(&args, 0, sizeof(args));
	argp_parse(&argp, argc, argv, 0, &idx, &args);

	if (idx + 1 < argc) {
		args.input_file = argv[idx];
		args.output_file = argv[idx + 1];
	}

	if (args.input_format == FILE_UNKNOWN) {
		fprintf(stderr, "ERROR: Please specify a valid input format\n");
		missing = 1;
	} else if (!args.input_file) {
		fprintf(stderr, "ERROR: Please specify a valid input file\n");
		missing = 1;
	} else if (args.output_format == FILE_UNKNOWN) {
		fprintf(stderr, "ERROR: Please specify a valid output format\n");
		missing = 1;
	} else if (!args.output_file) {
		fprintf(stderr, "ERROR: Please specify a valid output file\n");
		missing = 1;
	} else if (((args.input_format == FILE_ZAP) ||
		   (args.output_format == FILE_ZAP)) && args.delsys <= 0) {
		fprintf(stderr, "ERROR: Please specify a valid delivery system for ZAP format\n");
		missing = 1;
	}
	if (missing) {
		argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME);
		return -1;
	}

	return convert_file(&args);
}
コード例 #13
0
int main(int argc, char *argv[])
{
	DIR *dir;
	struct dirent *ent;
	if (argc != 4)
		return EXIT_FAILURE;

	systemd_service_dir = argv[1];

	dir = opendir(DBUS_DEFAULT_SERVICE_DIR);
	if (!dir) {
		perror("opendir");
		return EXIT_FAILURE;
	}
	
	while (ent = readdir (dir)) {
#ifdef THREADS
		pthread_t tid;
#endif
		char *fpath = ent->d_name;
		int len = strlen(fpath);

		if (!streq(fpath+(len-8), ".service"))
			continue;
#ifdef THREADS
		fpath = strdup(fpath);
		if (!fpath)
			goto fail;
		if (pthread_create(&tid, NULL, convert_file, (void *) fpath))
			goto fail;

		pthread_detach(tid);
#else
		convert_file((void *) fpath);
#endif
	}
	closedir (dir);
	return 0;
fail:
	closedir(dir);
	return EXIT_FAILURE;
}
コード例 #14
0
ファイル: replace.c プロジェクト: liuqian1990/mariadb-10.0
int main(int argc, char *argv[])
{
    int i,error;
    char word_end_chars[256],*pos;
    POINTER_ARRAY from,to;
    REPLACE *replace;
    MY_INIT(argv[0]);

    if (static_get_options(&argc,&argv))
        exit(1);
    if (get_replace_strings(&argc,&argv,&from,&to))
        exit(1);

    for (i=1,pos=word_end_chars ; i < 256 ; i++)
        if (my_isspace(&my_charset_latin1,i))
            *pos++= (char) i;
    *pos=0;
    if (!(replace=init_replace((char**) from.typelib.type_names,
                               (char**) to.typelib.type_names,
                               (uint) from.typelib.count,word_end_chars)))
        exit(1);
    free_pointer_array(&from);
    free_pointer_array(&to);
    if (initialize_buffer())
        return 1;

    error=0;
    if (argc == 0)
        error=convert_pipe(replace,stdin,stdout);
    else
    {
        while (argc--)
        {
            error=convert_file(replace,*(argv++));
        }
    }
    free_buffer();
    my_free(replace);
    my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
    exit(error ? 2 : 0);
    return 0;					/* No compiler warning */
} /* main */
コード例 #15
0
int main(int argc, char *argv[])
{
  char *p_outfile_name = NULL;
  char *p_memo_name = NULL;
  FILE *p_outfile = stdout;
  FILE *p_infile = stdin;
  int nr_chunks;
  int last_opt;

  /* Parse the arguments to the program */
  if ( (last_opt = parse_options(argc, argv, &p_memo_name, &p_outfile_name)) < 0)
    return -1;

  /* Was any options given? */
  if (p_memo_name == NULL)
    p_memo_name = "STD_memo";

  if (p_outfile_name != NULL)
    {
      if ( !(p_outfile = fopen(p_outfile_name, "w")) )
	{
	  fprintf(stderr, "ERROR: Could not open %s\n", p_outfile_name);
	  return -1;
	}
    }

  /* Convert the file */
  if (write_convert_header(p_outfile, p_memo_name) < 0)
    {
      fprintf(stderr, "File conversion header failed!\n");
      return -1;
    }

  /* If no infile was given, assume stdin */
  if (last_opt >= argc)
    {
      if ( (nr_chunks = convert_file(p_infile, p_outfile, p_memo_name)) < 0)
	{
	  fprintf(stderr, "File conversion failed!\n");
	  return -1;
	}
    }
  else
    {
      /* Else, convert each file */
      while (last_opt < argc)
	{
	  if ( !(p_infile = fopen(argv[last_opt], "r")) )
	    {
	      fprintf(stderr, "ERROR: Could not open %s\n", argv[last_opt]);
	      return -1;
	    }
	  if ( (nr_chunks = convert_file(p_infile, p_outfile, p_memo_name)) < 0)
	    {
	      fprintf(stderr, "File conversion failed!\n");
	      return -1;
	    }
	  fclose(p_infile);
	  last_opt++;
	}
    }


  if (write_convert_footer(p_outfile, nr_chunks) < 0)
    {
      fprintf(stderr, "File conversion header failed!\n");
      return -1;
    }



  if (p_outfile != stdout)
    fclose(p_outfile);

  return 0;
}
コード例 #16
0
ファイル: iconv.c プロジェクト: Ga-vin/apache
int
main(int argc, const char **argv)
{
	apr_iconv_t cd;
	iconv_stream *is;
	const char *from = NULL, *to = NULL, *input = NULL;
	char opt;
	apr_pool_t *ctx; 
	apr_status_t status;
    apr_getopt_t *options;
    const char *opt_arg;

    /* Initialize APR */
    apr_initialize();
    atexit(closeapr);
    if (apr_pool_create(&ctx, NULL) != APR_SUCCESS) {
        fprintf(stderr, "Couldn't allocate context.\n");
        exit(-1);
    }

    apr_getopt_init(&options, ctx, argc, argv);

    status = apr_getopt(options, "f:s:t:v", &opt, &opt_arg);

    while (status == APR_SUCCESS) {
        switch (opt) {
        case 'f':
            from = opt_arg;
            break;
        case 't':
            to = opt_arg;
            break;
        case 's':
            input = opt_arg;
            break;
        case 'v':
            fprintf(stderr, "APR-iconv version " API_VERSION_STRING "\n");
            exit(0);
        default:
            fprintf(stderr, "Usage: iconv -f <name> -t <name> [-s <input>]\n");
            exit(3);
        }

        status = apr_getopt(options, "f:s:t:v",&opt, &opt_arg);
    }

    if (status == APR_BADCH || status == APR_BADARG) {
        fprintf(stderr, "Usage: iconv -f <name> -t <name> [-s <input>]\n");
        exit(3);
    }
	if (from == NULL) {
		fprintf(stderr, "missing source charset (-f <name>)\n");
		exit(4);
	}
	if (to == NULL) {
		fprintf(stderr, "missing destination charset (-t <name>)\n");
		exit(5);
	}

	/* Use it */
	status = apr_iconv_open(to, from, ctx, &cd);
	if (status) {
		fprintf(stderr, "unable to open specified converter\n");
		exit(6);
		}
	if (!(is = iconv_ostream_fopen(cd, stdout))) {
		apr_iconv_close(cd,ctx);
		exit(7);
	}
	if (input) {
		if (iconv_bwrite(is, input, strlen(input)) <= 0)
			exit(8);
	} else if (optind < argc) {
		for (opt = optind; opt < argc; opt ++)
			convert_file(argv[opt], is);
	} else
		convert_file("-", is);
	if (iconv_write(is, NULL, 0) < 0)
		exit(9);
	iconv_stream_close(is);
	apr_iconv_close(cd,ctx);
	return 0;
}
コード例 #17
0
int
main(int argc, char **argv)
{
  struct nettle_buffer buffer;
  enum object_type type = 0;
  int base64 = 0;
  int c;

  enum {
    OPT_HELP = 0x300,
    OPT_PRIVATE_RSA = RSA_PRIVATE_KEY,
    OPT_PUBLIC_RSA = RSA_PUBLIC_KEY,
    OPT_PRIVATE_DSA = DSA_PRIVATE_KEY,
    OPT_PUBLIC_KEY = GENERAL_PUBLIC_KEY,
  };
  
  static const struct option options[] =
    {
      /* Name, args, flag, val */
      { "help", no_argument, NULL, OPT_HELP },
      { "version", no_argument, NULL, 'V' },
      { "private-rsa-key", no_argument, NULL, OPT_PRIVATE_RSA },
      { "public-rsa-key", no_argument, NULL, OPT_PUBLIC_RSA },
      { "private-dsa-key", no_argument, NULL, OPT_PRIVATE_DSA },
      { "public-key-info", no_argument, NULL, OPT_PUBLIC_KEY },
      { "base-64", no_argument, NULL, 'b' },
      { NULL, 0, NULL, 0 }
    };

  while ( (c = getopt_long(argc, argv, "Vb", options, NULL)) != -1)
    {
      switch (c)
	{
	default:
	  abort();

	case 'b':
	  base64 = 1;
	  break;

	case OPT_PRIVATE_RSA:
	case OPT_PUBLIC_RSA:
	case OPT_PRIVATE_DSA:
	case OPT_PUBLIC_KEY:
	  /* Same values as the type codes. */
	  type = c;
	  break;

	case OPT_HELP:
	  printf("FIXME: Usage information.\n");
	  return EXIT_SUCCESS;
	case '?':
	  return EXIT_FAILURE;

	case 'V':
	  printf("pkcs1-conv (" PACKAGE_STRING ")\n");
	  return EXIT_SUCCESS;
	}
    }

  nettle_buffer_init_realloc(&buffer, NULL, nettle_xrealloc);  

  if (optind == argc)
    {
      if (!convert_file(&buffer, stdin, type, base64))
	return EXIT_FAILURE;
    }
  else
    {
      int i;
      const char *mode = (type || base64) ? "r" : "rb";
      
      for (i = optind; i < argc; i++)
	{
	  FILE *f = fopen(argv[i], mode);
	  if (!f)
	    die("Failed to open `%s': %s.\n", argv[i], strerror(errno));

	  if (!convert_file(&buffer, f, type, base64))
	    return EXIT_FAILURE;

	  fclose(f);
	}
    }
  return EXIT_SUCCESS;
}
コード例 #18
0
ファイル: async_functions.cpp プロジェクト: m2osw/turnwatcher
void parse(const char *filename)
{
	FILE		*f, *h, *cpp;
	const char	*ext, *basename;
	char		*input;
	long		len;

/* make sure the extension is .async */
	ext = strrchr(filename, '.');
	if(ext == 0 || strcmp(".async", ext) != 0) {
		return;
	}

/* open the input file */
	f = fopen(filename, "rb");
	if(f == 0) {
		fprintf(stderr, "%s:0: error: cannot open file\n", filename);
		return;
	}

/* open the output files */
	basename = strrchr(filename, '/');
	if(basename == 0) {
		basename = strrchr(filename, '\\');
		if(basename == 0) {
			basename = filename;
		}
		else {
			basename++;
		}
	}
	else {
		basename++;
	}
	len = static_cast<long>(strlen(basename) - size_t(6));	// strlen(".async") == 6
	h = open_output(basename, len, ".h");
	cpp = open_output(basename, len, ".c++");

	if(h == 0 || cpp == 0) {
		if(h != 0) {
			fclose(h);
		}
		if(cpp != 0) {
			fclose(cpp);
		}
		fclose(f);
		return;
	}

	input = read_input(filename, f);

	if(input != 0) {
		// mo_event.h needs to be included from within the .async file!
		//fprintf(h, "#include <mo_event.h>\n");

		// auto-include the header
		fprintf(cpp, "#include \"%.*s.h\"\n", static_cast<int>(len), basename);

		remove_cr(input);
		convert_file(filename, input, h, cpp);
		delete [] input;

		// Need extra newline at end of file to keep compiler from complaining.
		fprintf(h, "\n" );
	}

	fclose(f);
	fclose(h);
	fclose(cpp);
}
コード例 #19
0
ファイル: sadf.c プロジェクト: jackzhou121/sysstat
/*
 ***************************************************************************
 * 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;
}
コード例 #20
0
ファイル: mdnconv.c プロジェクト: aosm/bind
int
main(int ac, char **av) {
	char *cmd = *av;
	char *normalizer[MAX_NORMALIZER];
	int nnormalizer = 0;
	const char *in_code = NULL;
	const char *out_code = NULL;
	char *resconf_file = NULL;
	int no_resconf = 0;
	char zld[256 + 1];
	int zld_specified = 0;
	int auto_zld = 0;
	char *encoding_alias = NULL;
	int selective = 1;
	FILE *fp;
	mdn_resconf_t resconf;

#ifdef HAVE_SETLOCALE
	(void)setlocale(LC_ALL, "");
#endif

	zld[0] = '\0';

	ac--;
	av++;
	while (ac > 0 && **av == '-') {

#define MUST_HAVE_ARG if (ac < 2) usage(cmd)
		if (strcmp(*av, "-in") == 0) {
			MUST_HAVE_ARG;
			in_code = av[1];
			ac--;
			av++;
		} else if (strcmp(*av, "-out") == 0) {
			MUST_HAVE_ARG;
			out_code = av[1];
			ac--;
			av++;
		} else if (strcmp(*av, "-conf") == 0) {
			MUST_HAVE_ARG;
			resconf_file = av[1];
			ac--;
			av++;
		} else if (strcmp(*av, "-noconf") == 0) {
			no_resconf = 1;
		} else if (strcmp(*av, "-zld") == 0) {
			MUST_HAVE_ARG;
			canonical_zld(zld, av[1]);
			zld_specified = 1;
			ac--;
			av++;
		} else if (strcmp(*av, "-auto") == 0) {
			auto_zld = 1;
		} else if (strcmp(*av, "-normalize") == 0) {
			MUST_HAVE_ARG;
			if (nnormalizer >= MAX_NORMALIZER) {
				errormsg("too many normalizers\n");
				exit(1);
			}
			normalizer[nnormalizer++] = av[1];
			ac--;
			av++;
		} else if (strcmp(*av, "-alias") == 0) {
			MUST_HAVE_ARG;
			encoding_alias = *av;
		} else if (strcmp(*av, "-flush") == 0) {
			flush_every_line = 1;
		} else if (strcmp(*av, "-whole") == 0) {
			selective = 0;
		} else {
			usage(cmd);
		}
#undef MUST_HAVE_ARG

		ac--;
		av++;
	}

	if (ac > 1)
		usage(cmd);

	/*
	 * Load configuration file.
	 */
	resconf = NULL;
	if (!no_resconf) {
		mdn_result_t r;

		r = mdn_resconf_initialize();
		if (r == mdn_success)
			r = mdn_resconf_create(&resconf);
		if (r == mdn_success)
			r = mdn_resconf_loadfile(resconf, resconf_file);
		if (r != mdn_success) {
			errormsg("error reading configuration file: %s\n",
				 mdn_result_tostring(r));
			return (1);
		}
	}

	/*
	 * Get default input/output code.
	 */
	if (in_code == NULL)
		in_code = mdn_localencoding_name();

	if (out_code == NULL) {
		mdn_converter_t c;
		if (resconf != NULL &&
		    (c = mdn_resconf_serverconverter(resconf)) != NULL)
			out_code = mdn_converter_localencoding(c);
	}

	if (in_code == NULL) {
		errormsg("input codeset must be specified\n");
		return (1);
	}
	if (out_code == NULL) {
		errormsg("output codeset must be specified\n");
		return (1);
	}

	/*
	 * Initialize codeset converter.
	 */
	if (!initialize_converter(in_code, out_code, encoding_alias))
		return (1);

	/*
	 * Initialize normalizer.
	 */
	if (nnormalizer == 0 && resconf != NULL)
		norm_ctx = mdn_resconf_normalizer(resconf);
	if (norm_ctx == NULL &&
	    !initialize_normalizer(normalizer, nnormalizer))
		return (1);

	/*
	 * Default ZLD.
	 */
	if (!zld_specified && resconf != NULL) {
		const char *conf_zld = mdn_resconf_zld(resconf);
		if (conf_zld != NULL)
			canonical_zld(zld, conf_zld);
	}

	/*
	 * Open input file.
	 */
	if (ac > 0) {
		if ((fp = fopen(av[0], "r")) == NULL) {
			errormsg("cannot open file %s: %s\n",
				 av[0], strerror(errno));
			return (1);
		}
	} else {
		fp = stdin;
	}

	/*
	 * Do the conversion.
	 */
	return convert_file(fp, zld, auto_zld, selective);
}