Ejemplo n.º 1
0
static int readline_intrinsic_internal (Slsh_Readline_Type *sri, char *prompt, int noecho)
{
    char *line;

    if (sri == NULL)
        sri = Intrinsic_Rline_Info;

#if USE_SLANG_READLINE
    if ((sri == NULL) && Use_Readline)
    {
        Intrinsic_Rline_Info = open_slsh_readline (NULL, SL_RLINE_BLINK_MATCH);
        if (Intrinsic_Rline_Info == NULL)
            return -1;
        (void) SLang_add_cleanup_function (close_intrinsic_readline);
        sri = Intrinsic_Rline_Info;
    }
#endif
    enable_keyboard_interrupt ();

    line = read_input_line (sri, prompt, noecho);
    if (noecho == 0)
        (void) save_input_line (sri, line);
    (void) SLang_push_malloced_string (line);
    return 0;
}
Ejemplo n.º 2
0
void compile_file(const char *src, const char *dest){
	printf("Compiling file: %s into %s\n", src, dest);
	printf("Initializing compiler...\n");
	compile_init();
	open_input_m4(src);

	codelist_entry *entry;
	while(is_input_open()){
		while(read_input_line()){
			entry = process_line();
			if(entry != NULL){
				printf("Adding codelist entry...\n");
				add_codelist_entry(entry);
			}
		}
		close_input();
	}

	close_input();
	compile_cleanup();
}
Ejemplo n.º 3
0
/* Returns a malloced value */
static char *get_input_line (SLang_Load_Type *x)
{
    char *line;
    int parse_level;
    int free_prompt = 0;
    char *prompt;

    parse_level = x->parse_level;
    if (Prompt_Hook != NULL)
    {
        if ((-1 == SLang_start_arg_list ())
                || (-1 == SLang_push_int (parse_level))
                || (-1 == SLang_end_arg_list ())
                || (-1 == SLexecute_function (Prompt_Hook))
                || (-1 == SLang_pop_slstring (&prompt)))
        {
            SLang_verror (SL_RunTime_Error, "Disabling prompt hook");
            SLang_free_function (Prompt_Hook);
            Prompt_Hook = NULL;
            return NULL;
        }
        free_prompt = 1;
    }
    else if (parse_level == 0)
        prompt = (char *) "slsh> ";
    else
        prompt = (char *) "       ";

    if (parse_level == 0)
    {
        if (-1 == SLang_run_hooks ("slsh_interactive_before_hook", 0))
        {
            if (free_prompt)
                SLang_free_slstring (prompt);
            return NULL;
        }
    }

    line = read_input_line (Default_Readline_Info, prompt, 0);

    if (free_prompt)
        SLang_free_slstring (prompt);

    if ((line == NULL)
            && (parse_level == 0)
            && (SLang_get_error() == 0))
    {
        Slsh_Quit = 1;
        return NULL;
    }

    if (line == NULL)
    {
        return NULL;
    }

    /* This hook is used mainly for logging input */
    (void) SLang_run_hooks ("slsh_interactive_after_hook", 1, line);

    (void) save_input_line (Default_Readline_Info, line);

    return line;
}
Ejemplo n.º 4
0
static int ReadQuotas(int i)
{
#ifdef _WINDOWS
    HANDLE hin;
    DWORD savemode, newmode;

    hin = GetStdHandle(STD_INPUT_HANDLE);

    GetConsoleMode(hin, &savemode);
    newmode = savemode | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT;
    newmode &= ~ENABLE_ECHO_INPUT;
    SetConsoleMode(hin, newmode);

    while (bytesAvailable[i] == 0)
    {
	DWORD read;
	BOOL r;
	char buffer[21];

	r = ReadFile(hin, buffer, 20, &read, 0);
	if (!r || read == 0)
	    fatalbox("ReadFile failed in ReadQuotas");
	buffer[read] = 0;

	if (buffer[0] != '-')
	{
	    if (input_pushback != 0)
		fatalbox("input_pushback not null!");
	    else
		input_pushback = strdup(buffer);
	}
	else
	    ProcessQuotaCmd(buffer);
    }

    SetConsoleMode(hin, savemode);
#else
    char* line;
    while (bytesAvailable[i] == 0)
    {
	int error = 0;
	line = read_input_line(1, &error);
	if (line == NULL || error)
	{
	    fatalbox("read_input_line failed in ReadQuotas");
	    break;
	}

	if (line[0] != '-')
	{
	    if (input_pushback != 0)
		fatalbox("input_pushback not null!");
	    else
		input_pushback = strdup(line);
	}
	else
	    ProcessQuotaCmd(line);
	sfree(line);
    }
#endif //_WINDOWS
    return 1;
}
Ejemplo n.º 5
0
Archivo: dsa.c Proyecto: skrieder/oops
ErrorCode init_dsa(const char* cfg)
{
    ErrorCode error = NO_ERROR;
    char *linehead = NULL;
    char *energyname = NULL;
    char *energycfg = NULL;
    char *rbasinsname = NULL;
    char *rbasinscfg = NULL;

    printf("    Initializing DSA sampler...\n");

    if (open_input_text_file(cfg) == NO_ERROR)
    {
        while (read_input_line())
        {
            get_input_strval(&linehead, "=", 0);
            if (strcmp(linehead, "ENERGY FUNCTION") == 0)
            {
                get_input_strval(&energyname, "=", 1);
            }
            else if (strcmp(linehead, "ENERGY CONFIG") == 0)
            {
                get_input_strval(&energycfg, "=", 1);
            }
            else if (strcmp(linehead, "RB CALCULATOR") == 0)
            {
                get_input_strval(&rbasinsname, "=", 1);
            }
            else if (strcmp(linehead, "RB CONFIG") == 0)
            {
                get_input_strval(&rbasinscfg, "=", 1);
            }
            else
            {
                print_error(UNKNOWN_PARAMETER_ERROR, "init_oops", 2, "header ", linehead);
            }
            free(linehead); 
            linehead = NULL; // Make sure of set this string pointer to NULL, beacause it will be used again when reading the next line. 
        }
        close_input_file();    
    }

    error = get_energy_module(&energymod, energyname);
    if (error != NO_ERROR)
    {
        print_error(error, "init_dsa", 1, " when getting energy module");
    }
    free(energyname);

    error = get_custom_module(&rbasinsmod, rbasinsname);
    if (error != NO_ERROR)
    {
        print_error(error, "init_dsa", 1, " when getting rbasins module");
    }
    free(rbasinsname);

    // Initializing energy module.
    execute_init_func_energy_module(energymod, energycfg);
    free(energycfg);

    // Initializing rbasins module.
    execute_init_func_custom_module(rbasinsmod, rbasinscfg);
    free(rbasinscfg);

    // Calculating initial assignement of torsional angles for the whole system.
    update_all_torsional_angles(residues, chains, nchains, coords);

    // Initializing global variables..
    T = 350.0;
    create_bool_array(&flags, nres);

    printf("    Done.\n");

    return error;
}
Ejemplo n.º 6
0
ErrorCode init_dopecb(const char* cfg)
{
    debug=0;
    nactivepairs=0;
    natoms2=natoms*natoms;

    create_float_array(&pairenergies,natoms2);

    create_index_array(&pairrows,natoms2);
    create_index_array(&updatepairs,natoms2);
    create_index_array(&activepairs,natoms2);

    BINSIZE=DISTANCECUTOFF/NUMBINS;

    printf("        Initializing DOPE function...\n");
    printf("              Loading Parameter file...\n");

    char *linehead = NULL;
    char *parfilename = NULL;
    if (open_input_text_file(cfg) == NO_ERROR)
    {
        while (read_input_line())
        {
            get_input_strval(&linehead, "=", 0);

            char firstchar=linehead[0];
            if (firstchar=='#') {
                free(linehead);
                linehead = NULL;
                continue;
            }
            if (strcmp(linehead, "PARFILE") == 0)
            {
                get_input_strval(&parfilename, "=,", 1);
            }
            else if (strcmp(linehead, "DEBUG") == 0)
            {
                get_input_ival(&debug, "=,", 1);
            }
            else
            {
                print_error(UNKNOWN_PARAMETER_ERROR, "init_debug", 0);
                printf("...line: %s\n",linehead);
            }
            free(linehead);
            linehead = NULL; // Make sure of set this string pointer to NULL, beacause it will be used again when reading the next line. 
        }
        close_input_file();
    }
    load_dopecb_parfile(parfilename);
    free(parfilename);

    //check to make sure dope is loaded correctly
    IndexValue i,j,k,l,m;
    if (debug){
        for (i=0;i<MAXAACODE;i++)
            for(j=0;j<MAXATCODE;j++)
                for(k=0;k<MAXAACODE;k++)
                    for(l=0;l<MAXATCODE;l++){
                        //printf("%i %i %i %i ",i,j,k,l);
                        printf("%s(%i) %s(%i) %s(%i) %s(%i)",aacodetoonelet[i+1],i,dopecodetolet[j],j,aacodetoonelet[k+1],k,dopecodetolet[l],l);
                        for(m=0;m<=MAXBINNUM;m++){
                            printf(" %4.2f ",dopeenergies[convert_to_dopecb_row(i,j,k,l)+m]);
                        }
                        printf("\n");
                    }
    }
    IndexValue resi,typei,restypei,resj,typej,restypej;
    for (i=0;i<natoms;i++){
        IndexValue dopeattypei=convtodope[atoms[i].type];
        typei=atoms[i].niprop=dopeattypei;
        resi=atoms[i].res; // starts from 0
        restypei=residues[resi].type-1; //starts from 1
        //atoms[i].niprop=0;
        //if (debug) printf("%i) Atom: %i, Type: %i,Residue type: %i\n",resi,i,typei,restypei);
        for (j=0;j<natoms;j++){
            IndexValue dopeattypej=convtodope[atoms[j].type];
            typej=atoms[j].niprop=dopeattypej;
            resj=atoms[j].res; // starts from 0
            restypej=residues[resj].type-1; //starts from 1
            pairrows[natoms*i+j]=pairrows[natoms*j+i]=convert_to_dopecb_row(restypei,typei,restypej,typej);
            //printf("Dope Row: %i,idx1: %i, idx2: %i\n",row,idx1,idx2);
            if (resj>resi+0) { //change this to reflect ii+n only
                activepairs[2*nactivepairs]=i;
                activepairs[2*nactivepairs+1]=j;
                nactivepairs+=1;
            }
            pairenergies[natoms*i+j]=0;
        }
    }
    printf("        Done.\n");
    return NO_ERROR;
}