예제 #1
0
파일: popt.cpp 프로젝트: dankelley/gre
static void configLine(poptContext con, char * line) {
	int nameLength = strlen(con->appName);
	char * opt;
	struct poptAlias alias;
    
	if (strncmp(line, con->appName, nameLength)) return;
	line += nameLength;
	if (!*line || !isspace(*line)) return;
	while (*line && isspace(*line)) line++;

	if (!strncmp(line, "alias", 5)) {
		line += 5;
		if (!*line || !isspace(*line)) return;
		while (*line && isspace(*line)) line++;
		if (!*line) return;

		opt = line;
		while (*line && !isspace(*line)) line++;
		if (!*line) return;
		*line++ = '\0';
		while (*line && isspace(*line)) line++;
		if (!*line) return;

		if (!strlen(opt)) return;

		if (poptParseArgvString(line, &alias.argc, &alias.argv)) return;

		if (opt[0] == '-' && opt[1] == '-') {
			alias.longName = opt + 2;
			alias.shortName = '\0';
			poptAddAlias(con, alias, 0);
		} else if (opt[0] == '-' && !opt[2]) {
			alias.longName = NULL;
			alias.shortName = opt[1];
			poptAddAlias(con, alias, 0);
		}
	}
}
예제 #2
0
파일: poptconfig.c 프로젝트: AaronDnz/xbmc
static void configLine(poptContext con, char * line) {
    int nameLength = strlen(con->appName);
    char * opt;
    struct poptAlias alias;
    char * entryType;
    char * longName = NULL;
    char shortName = '\0';
    
    if (strncmp(line, con->appName, nameLength)) return;
    line += nameLength;
    if (!*line || !isspace(*line)) return;
    while (*line && isspace(*line)) line++;
    entryType = line;

    while (!*line || !isspace(*line)) line++;
    *line++ = '\0';
    while (*line && isspace(*line)) line++;
    if (!*line) return;
    opt = line;

    while (!*line || !isspace(*line)) line++;
    *line++ = '\0';
    while (*line && isspace(*line)) line++;
    if (!*line) return;

    if (opt[0] == '-' && opt[1] == '-')
	longName = opt + 2;
    else if (opt[0] == '-' && !opt[2])
	shortName = opt[1];

    if (!strcmp(entryType, "alias")) {
	if (poptParseArgvString(line, &alias.argc, &alias.argv)) return;
	alias.longName = longName, alias.shortName = shortName;
	poptAddAlias(con, alias, 0);
    } else if (!strcmp(entryType, "exec")) {
	con->execs = realloc(con->execs, 
				sizeof(*con->execs) * (con->numExecs + 1));
	if (longName)
	    con->execs[con->numExecs].longName = strdup(longName);
	else
	    con->execs[con->numExecs].longName = NULL;

	con->execs[con->numExecs].shortName = shortName;
	con->execs[con->numExecs].script = strdup(line);
	
	con->numExecs++;
    }
}
예제 #3
0
파일: popt.cpp 프로젝트: dankelley/gre
int poptReadDefaultConfig(poptContext con, int useEnv) {
	char * envName, * envValue;
	char * fn, * home, * chptr;
	int rc, skip;
	struct poptAlias alias;

	if (!con->appName) return 0;

	rc = poptReadConfigFile(con, "/etc/popt");
	if (rc) return rc;
	if (getuid() != geteuid()) return 0;

	if ((home = getenv("HOME"))) {
		fn = (char*)alloca(strlen(home) + 20);
		sprintf(fn, "%s/.popt", home);
		rc = poptReadConfigFile(con, fn);
		if (rc) return rc;
	}

	envName = (char*)alloca(strlen(con->appName) + 20);
	strcpy(envName, con->appName);
	chptr = envName;
	while (*chptr) {
		*chptr = toupper(*chptr);
		chptr++;
	}
	strcat(envName, "_POPT_ALIASES");

	if (useEnv && (envValue = getenv(envName))) {
		envValue = strcpy((char*)alloca(strlen(envValue) + 1), envValue);

		while (envValue && *envValue) {
			chptr = strchr(envValue, '=');
			if (!chptr) {
				envValue = strchr(envValue, '\n');
				if (envValue) envValue++;
				continue;
			}

			*chptr = '\0';

			skip = 0;
			if (!strncmp(envValue, "--", 2)) {
				alias.longName = envValue + 2;
				alias.shortName = '\0';
			} else if (*envValue == '-' && strlen(envValue) == 2) {
				alias.longName = NULL;	
				alias.shortName = envValue[1];
			} else {
				skip = 1;
			}

			envValue = chptr + 1;
			chptr = strchr(envValue, '\n');
			if (chptr) *chptr = '\0';

			if (!skip) {
				poptParseArgvString(envValue, &alias.argc, &alias.argv);
				poptAddAlias(con, alias, 0);
			}

			if (chptr)
				envValue = chptr + 1;
			else
				envValue = NULL;
		}
	}

	return 0;
}