Ejemplo n.º 1
0
/* get the base name of a path */
void test_core_path__01_basename(void)
{
	check_basename(NULL, ".");
	check_basename("", ".");
	check_basename("a", "a");
	check_basename("/", "/");
	check_basename("/usr", "usr");
	check_basename("/usr/", "usr");
	check_basename("/usr/lib", "lib");
	check_basename("/usr/lib//", "lib");
	check_basename("usr/lib", "lib");

	check_basename(REP16("/abc"), "abc");
	check_basename(REP1024("/abc"), "abc");
}
Ejemplo n.º 2
0
void getopts(int argc, char *argv[])
{
	int i;
	int got_nos = 0;
	int got_nol = 0;
	int got_bn  = 0;
	int got_pn  = 0;
	int got_of  = 0;
	int got_f   = 0;
	int got_wd  = 0;
	int got_cmd = 0;
	char *endptr;

	for(i = 1; i < argc; i++) {
		if(!strcmp(argv[i], "-s")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (number of segments)");
			if(got_nos)	usage(argv, (char*) "Number of segments specified twice");
			no_of_segments = (int) strtol(argv[i], &endptr, 10);
			if((*endptr != '\0') || (no_of_segments < 0))	usage(argv, (char*) "Invalid numeric value for number of segments");
			got_nos = 1;
		} else if(!strcmp(argv[i], "-l")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (number of lines per segment)");
			if(got_nol)	usage(argv, (char*) "Number of lines per segment specified twice");
			no_of_lines = (int) strtol(argv[i], &endptr, 10);
			if((*endptr != '\0') || (no_of_lines < 1))	usage(argv, (char*) "Invalid numeric value for number of lines per segment");
			got_nol = 1;
		} else if(!strcmp(argv[i], "-n")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (basename)");
			if(got_bn)	usage(argv, (char*) "Basename of outputfiles specified twice");
			if(check_basename(argv[i]))	usage(argv, (char*) "Invalid basename");
			got_bn = 1;
		} else if(!strcmp(argv[i], "-o")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (outputfile)");
			if(got_of)	usage(argv, (char*) "Outputfile specified twice");
			if(check_name(argv[i], &outputfile))	usage(argv, (char*) "Invalid outputfilename");
			got_of = 1;
		} else if(!strcmp(argv[i], "-w")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (workdir)");
			if(got_wd)	usage(argv, (char*) "Workdir specified twice");
			if(check_name(argv[i], &workdir))	usage(argv, (char*) "Invalid workdir");
			got_wd = 1;
		} else if(!strcmp(argv[i], "-e")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (commandline)");
			if(got_cmd)	usage(argv, (char*) "Command specified twice");
			cmd = argv+i;
			got_cmd = 1;
			i = argc;
		} else if(!strcmp(argv[i], "-h")) {
			usage(argv, NULL);
		} else if(!strcmp(argv[i], "-v")) {
			verbose = 1;
		} else if(!strcmp(argv[i], "-f")) {
			if(got_f)	usage(argv, (char*) "Nodaemonflag specified twice");
			run_as_daemon = 0;
			got_f = 1;
		} else if(!strcmp(argv[i], "-D")) {
			i++;
			if(i >= argc)	{
				usage(argv, (char*) "Expected another parameter (environment variable specification)");
			}
			if(parseAndSetEnvironment(argc, argv, &i))	{
				usage(argv, (char*) "Invalid environment specification");
			}
		} else {
			if(got_pn)	usage(argv, (char*) "Pipename specified twice");
			if(check_pipename(argv[i]))	usage(argv, (char*) "Invalid pipename");
			got_pn = 1;
		}
	}
	if(!got_pn)	usage(argv, (char*) "Pipename missing");
	if(!got_bn)	logbasename = pipename;
	if(no_of_segments < 2)	usage(argv, (char*) "Number of segments should be at least 2");
	analyzer = getenv(ANALYZER);
}