Ejemplo n.º 1
0
int read_bounds(FILE *fp, bounds *bconf)
{
    struct symbol sym;

    while (next_var(fp, &sym))
    {
        if (!strcmp(sym.name, "pmin"))
            bconf->pmin = sym.val;
        else if (!strcmp(sym.name, "pmax"))
            bconf->pmax = sym.val;
        else if (!strcmp(sym.name, "cgmin"))
            bconf->cgmin = sym.val;
        else if (!strcmp(sym.name, "cgmax"))
            bconf->cgmax = sym.val;
        else if (!strcmp(sym.name, "cmin"))
            bconf->cmin = sym.val;
        else if (!strcmp(sym.name, "cmax"))
            bconf->cmax = sym.val;
        else if (!strcmp(sym.name, "ppmin"))
            bconf->ppmin = sym.val;
        else if (!strcmp(sym.name, "ppmax"))
            bconf->ppmax = sym.val;
        else if (!strcmp(sym.name, "cgpmin"))
            bconf->cgpmin = sym.val;
        else if (!strcmp(sym.name, "cgpmax"))
            bconf->cgpmax = sym.val;
        else if (!strcmp(sym.name, "cpmin"))
            bconf->cpmin = sym.val;
        else if (!strcmp(sym.name, "cpmax"))
            bconf->cpmax = sym.val;
        else if (!strcmp(sym.name, "dtmin"))
            bconf->dtmin = sym.val;
        else if (!strcmp(sym.name, "dtmax"))
            bconf->dtmax = sym.val;
        else if (!strcmp(sym.name, "hmin"))
            bconf->hmin = sym.val;
        else if (!strcmp(sym.name, "hmax"))
            bconf->hmax = sym.val;
        else if (!strcmp(sym.name, "kmin"))
            bconf->kmin = sym.val;
        else if (!strcmp(sym.name, "kmax"))
            bconf->kmax = sym.val;
        else if (!strcmp(sym.name, "mmin"))
            bconf->mmin = sym.val;
        else if (!strcmp(sym.name, "mmax"))
            bconf->mmax = sym.val;
        else if (!strcmp(sym.name, "nmin"))
            bconf->nmin = sym.val;
        else if (!strcmp(sym.name, "nmax"))
            bconf->nmax = sym.val;
    }

    return 0;
}
Ejemplo n.º 2
0
Symbol*  NrnProperty::first_var() {
	npi_->iterator_ = -1;
	return next_var();	
}
Ejemplo n.º 3
0
/* Execute our inlined script to collect some info
   on our targeted python installation. */
static int get_python_info(char* python)
{
	FILE *pPipe;
	int retcode = 0;
	size_t szExecBuf, szExecLen;
	char psBuffer[OUTPUT_BUF_LEN] = "",
	*cmdExec,
	*psBuffPart;
	

	// Check that python string isn't null.
	if(is_null(python)) {
		debug("Python string is null.");
		return 0;
	}

	// Calculate our cmd buffer length.
	if(getinfo_script_length == 0) getinfo_script_length = strlen(getinfo_script);
	szExecLen = PYTHON_EXEC_LEN + getinfo_script_length + strlen(python);
	szExecBuf = sizeof(char) * szExecLen;

	// Attempt to allocate our cmd buffer.
	if(bad_stralloc(cmdExec, szExecBuf)) {
		debug("Allocation failed.");
		return 0;
	}

	// Zero out our cmd buffer, then assign the cmd to execute.
	zbuf(cmdExec, szExecBuf);
	sprintf(cmdExec, python_exec, python, getinfo_script);

	// Attempt to open our process.
	if(is_null(pPipe = _popen(cmdExec, "rt"))) {
		free(cmdExec);
		debug("Could not open pipe.");
		return 0;
	}

	// Read process pipe until end of file, or an error occurs.
	while(fgets(psBuffer, OUTPUT_BUF_LEN, pPipe));

	// Free our cmd buffer and make sure our process didn't error out.
	free(cmdExec);
	if (!feof( pPipe)) {
		debug("Pipe was not at EOF.");
		return 0;
	}

	// Close pipe & check the return value of our process.
	retcode = _pclose(pPipe);
	if(retcode != 0 || !strlen(psBuffer)) {
		debug("Python returned a non-zero return code.");
		return 0;
	}

	// Python major & minor version.
	if(is_null(psBuffPart = var_split(psBuffer)) || (strlen(psBuffPart) != 2)) {
		debug("Failed to parse python version.");
		return 0;
	}
	strcpy(python_version, (const char*)psBuffPart);

	// Python API version
	if(is_null(next_var(psBuffPart)) || (strlen(psBuffPart) != 4)) {
		debug("Failed to parse python API version.");
		return 0;
	}
	strcpy(python_api_string, (const char*)psBuffPart);
	if(!(python_api_version = atoi(python_api_string))) return 0;

	// Python prefix
	if(is_null(next_var(psBuffPart)) || (strlen(psBuffPart) == 0)) {
		debug("Failed to parse python prefix.");
		return 0;
	}
	strcpy(python_prefix, (const char*)psBuffPart);

	// Python dll
	if(is_null(next_var(psBuffPart)) || (strlen(psBuffPart) == 0)) {
		debug("Failed to parse python DLL.");
		return 0;
	}
	strcpy(python_library, (const char*)psBuffPart);
	return 1;
}
Ejemplo n.º 4
0
// Attempt to find python on the PATH environment variable.
// Note: We're not using any of the built in APIs like _searchenv,
// because we don't want just the first executable on PATH. We need
// to iterate through all matches until we find one that's valid
// for our configuration.
static int find_in_path()
{
	char *sSearch, *sBuffer;
	char sCheck[MAX_PATH+1] = {0};
	size_t szSearch;

	// Some debugging.
	debug("Searching the PATH for a valid python executable.");

	if(is_null(sBuffer = getenv(PATH_ENV))) {
		debug("Could not get PATH environment variable.");
		return 0;
	}

	if(is_null(sSearch = var_split(sBuffer))) {
		debug("Could not split PATH environment variable by ';'");
		debug("PATH = %s", sBuffer);
		return 0;
	}

	do {
		if(!(szSearch = strlen(sSearch))) continue;
		if(szSearch > MAX_PATH) {
			debug("Encounted a path in the PATH variable that is too big.");
			debug("Path: %s", sSearch);
			debug("Length: %d", szSearch);
			continue;
		}
		// Set up our temporary work variable.
		strcpy(sCheck, sSearch);

		// Remove trailing slashes.
		if(!remove_trailing_slashes(sCheck, &szSearch)) {
			debug(
				"After removing all trailing slashes, path's length was less than 3. This "
				"indicates an invalid path in your environment variables."
			);
			debug("Original: %s", sSearch);
			debug("Result: %s", sCheck);
			continue;
		}

		// Max sure our resulting string wont be too big.
		if(!(check_python_length(szSearch))) {
			debug(
				"Length of path, \"%s\" (%d) added to length of \"\\" PYTHON_EXE "\" (%d) results "
				"in a length that is bigger than the maximum file path length. Skipping.",
				sSearch,
				szSearch,
				szPyExe
			);
			continue;
		}

		// Assemble our python path and check it.
		strcat(sCheck, "\\" PYTHON_EXE);
		if(!check_python(sCheck)) continue;

		// If we make it here, we have successfully found our python installation.
		strcpy(python_exe, sCheck);
		break;

	} while(!is_null(next_var(sSearch)));

	// Some debugging.
	debug("find_in_path resulted in \"%s\"", python_exe);

	return *python_exe != 0;
}