Beispiel #1
0
int main(int argc,const char *argv[]) {
	const char **args;

	int res = ca_parse(argc,argv,0,"");
	if(res < 0) {
		printe("Invalid arguments: %s",ca_error(res));
		usage(argv[0]);
	}
	if(ca_hasHelp() || ca_getFreeCount() == 0)
		usage(argv[0]);

	args = ca_getFree();
	while(*args) {
		if(mkdir(*args,DIR_DEF_MODE) < 0)
			printe("Unable to create directory '%s'",*args);
		args++;
	}
	return EXIT_SUCCESS;
}
Beispiel #2
0
int main(int argc,const char *argv[]) {
	int rec = false;
	const char **args;

	int res = ca_parse(argc,argv,0,"r",&rec,&rec);
	if(res < 0) {
		printe("Invalid arguments: %s",ca_error(res));
		usage(argv[0]);
	}
	if(ca_hasHelp() || ca_getFreeCount() == 0)
		usage(argv[0]);

	args = ca_getFree();
	while(*args) {
		removeRec(*args,rec);
		args++;
	}
	return EXIT_SUCCESS;
}
Beispiel #3
0
int main(int argc,const char *argv[]) {
	char c;
	const char **args;
	size_t i,argCount;
	size_t freeArgs;
	FILE *file = stdin;
	const char *filename = NULL;

	/* parse args */
	int res = ca_parse(argc,argv,0,"a=s",&filename);
	if(res < 0) {
		printe("Invalid arguments: %s",ca_error(res));
		usage(argv[0]);
	}
	if(ca_hasHelp())
		usage(argv[0]);

	/* open file? */
	if(filename != NULL) {
		file = fopen(filename,"r");
		if(file == NULL)
			error("Unable to open file '%s'",filename);
	}

	/* read arguments */
	argCount = 0;
	while((c = fgetc(file)) != EOF) {
		if(isspace(c)) {
			appendArg();
			argCount++;
			argPos = 0;
		}
		else {
			if(argPos < MAX_ARG_LEN)
				argBuf[argPos++] = c;
			else
				error("Argument too long");
		}
	}
	if(ferror(file))
		error("Read failed");
	if(filename != NULL)
		fclose(file);
	/* append last one */
	if(argPos > 0) {
		appendArg();
		argCount++;
	}

	/* build args-array and copy arguments into it */
	freeArgs = ca_getFreeCount();
	if(freeArgs == 0)
		freeArgs = 1;
	args = (const char**)malloc(sizeof(char*) * (argCount + freeArgs + 1));
	if(!args)
		error("Not enough mem");
	i = 0;
	if(ca_getFreeCount() == 0)
		args[i++] = "echo";
	else {
		for(i = 0; i < freeArgs; i++)
			args[i] = ca_getFree()[i];
	}
	for(; first != NULL; i++) {
		args[i] = first->arg;
		first = first->next;
	}
	args[i] = NULL;
	/* exchange us with requested command */
	execvp(args[0],args);
	return EXIT_SUCCESS;
}