static tsi_peer peer_from_cert_name_test_entry(
    const cert_name_test_entry *entry) {
  size_t i;
  tsi_peer peer;
  name_list *nl;
  parsed_names dns_entries = parse_names(entry->dns_names);
  parsed_names ip_entries = parse_names(entry->ip_names);
  nl = dns_entries.names;
  GPR_ASSERT(tsi_construct_peer(
                 1 + dns_entries.name_count + ip_entries.name_count, &peer) ==
             TSI_OK);
  GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
                 TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, entry->common_name,
                 &peer.properties[0]) == TSI_OK);
  i = 1;
  while (nl != NULL) {
    char *processed = processed_name(nl->name);
    GPR_ASSERT(tsi_construct_string_peer_property(
                   TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed,
                   strlen(nl->name), &peer.properties[i++]) == TSI_OK);
    nl = nl->next;
    gpr_free(processed);
  }

  nl = ip_entries.names;
  while (nl != NULL) {
    char *processed = processed_name(nl->name);
    GPR_ASSERT(tsi_construct_string_peer_property(
                   TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed,
                   strlen(nl->name), &peer.properties[i++]) == TSI_OK);
    nl = nl->next;
    gpr_free(processed);
  }
  destruct_parsed_names(&dns_entries);
  destruct_parsed_names(&ip_entries);
  return peer;
}
Exemple #2
0
static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
                            t_blocka *block, char ***gn,
                            atom_id *nr, atom_id *index, char *gname)
{
    static char   **names, *ostring;
    static gmx_bool bFirst = TRUE;
    int             j, n_names, sel_nr1;
    atom_id         i, nr1, *index1;
    char            c;
    gmx_bool        bRet, bCompl;

    if (bFirst)
    {
        bFirst = FALSE;
        snew(names, MAXNAMES);
        for (i = 0; i < MAXNAMES; i++)
        {
            snew(names[i], NAME_LEN+1);
        }
    }

    bRet    = FALSE;
    sel_nr1 = NOTSET;

    while (*string[0] == ' ')
    {
        (*string)++;
    }

    if ((*string)[0] == '!')
    {
        bCompl = TRUE;
        (*string)++;
        while (*string[0] == ' ')
        {
            (*string)++;
        }
    }
    else
    {
        bCompl = FALSE;
    }

    ostring = *string;

    if (parse_int(string, &sel_nr1) ||
        parse_string(string, &sel_nr1, block->nr, *gn))
    {
        if ((sel_nr1 >= 0) && (sel_nr1 < block->nr))
        {
            copy_group(sel_nr1, block, nr, index);
            strcpy(gname, (*gn)[sel_nr1]);
            printf("Copied index group %d '%s'\n", sel_nr1, (*gn)[sel_nr1]);
            bRet = TRUE;
        }
        else
        {
            printf("Group %d does not exist\n", sel_nr1);
        }
    }
    else if ((*string)[0] == 'a')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring))
        {
            if (parse_int(string, &sel_nr1))
            {
                bRet = select_atomnumbers(string, atoms, sel_nr1, nr, index, gname);
            }
            else if (parse_names(string, &n_names, names))
            {
                bRet = select_atomnames(atoms, n_names, names, nr, index, FALSE);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if ((*string)[0] == 't')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring) &&
            parse_names(string, &n_names, names))
        {
            if (atoms->atomtype == NULL)
            {
                printf("Need a run input file to select atom types\n");
            }
            else
            {
                bRet = select_atomnames(atoms, n_names, names, nr, index, TRUE);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if (strncmp(*string, "res", 3) == 0)
    {
        (*string) += 3;
        if (check_have_atoms(atoms, ostring) &&
            parse_int(string, &sel_nr1) &&
            (sel_nr1 >= 0) && (sel_nr1 < block->nr) )
        {
            bRet = atoms_from_residuenumbers(atoms,
                                             sel_nr1, block, nr, index, (*gn)[sel_nr1]);
            sprintf(gname, "atom_%s", (*gn)[sel_nr1]);
        }
    }
    else if (strncmp(*string, "ri", 2) == 0)
    {
        (*string) += 2;
        if (check_have_atoms(atoms, ostring) &&
            parse_int_char(string, &sel_nr1, &c))
        {
            bRet = select_residueindices(string, atoms, sel_nr1, c, nr, index, gname);
        }
    }
    else if ((*string)[0] == 'r')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring))
        {
            if (parse_int_char(string, &sel_nr1, &c))
            {
                bRet = select_residuenumbers(string, atoms, sel_nr1, c, nr, index, gname);
            }
            else if (parse_names(string, &n_names, names))
            {
                bRet = select_residuenames(atoms, n_names, names, nr, index);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if (strncmp(*string, "chain", 5) == 0)
    {
        (*string) += 5;
        if (check_have_atoms(atoms, ostring) &&
            parse_names(string, &n_names, names))
        {
            bRet = select_chainnames(atoms, n_names, names, nr, index);
            sprintf(gname, "ch%s", names[0]);
            for (i = 1; i < n_names; i++)
            {
                strcat(gname, names[i]);
            }
        }
    }
    if (bRet && bCompl)
    {
        snew(index1, natoms-*nr);
        nr1 = 0;
        for (i = 0; i < natoms; i++)
        {
            j = 0;
            while ((j < *nr) && (index[j] != i))
            {
                j++;
            }
            if (j == *nr)
            {
                if (nr1 >= natoms-*nr)
                {
                    printf("There are double atoms in your index group\n");
                    break;
                }
                index1[nr1] = i;
                nr1++;
            }
        }
        *nr = nr1;
        for (i = 0; i < nr1; i++)
        {
            index[i] = index1[i];
        }
        sfree(index1);

        for (i = strlen(gname)+1; i > 0; i--)
        {
            gname[i] = gname[i-1];
        }
        gname[0] = '!';
        printf("Complemented group: %d atoms\n", *nr);
    }

    return bRet;
}
Exemple #3
0
void create_nullspace_system(boost::filesystem::path output_name,
							 boost::filesystem::path input_name,
							 BertiniRealConfig & program_options,
							 NullspaceConfiguration *ns_config)
/***************************************************************\
 * USAGE: setup input file for one deflation iteration           *
 * ARGUMENTS: number of declaration statments, name of file,     *
 *  command to run Matlab, and dimension of nullspace            *
 * RETURN VALUES: creates new file                               *
 * NOTES:                                                        *
 \***************************************************************/
{
	
	int *declarations = NULL;
	partition_parse(&declarations, input_name, "func_input_real" , "config_real" ,0); // the 0 means not self conjugate mode
	
	
	
	int ii, numVars = 0, numFuncs = 0, numConstants = 0;
	int *lineVars = NULL, *lineFuncs = NULL, *lineConstants = NULL;
	char ch, *str = NULL, **vars = NULL, **funcs = NULL, **consts = NULL;
	FILE *IN = NULL, *OUT = NULL;
	
	
	// move the file & open it
	IN = safe_fopen_read("func_input_real");
	// setup variables
	if (declarations[0] > 0)
	{ // using variable_group
		parse_names(&numVars, &vars, &lineVars, IN,const_cast< char *>("variable_group"), declarations[0]);
	}
	else
	{ // using hom_variable_group
		parse_names(&numVars, &vars, &lineVars, IN,const_cast< char *>("hom_variable_group"), declarations[1]);
	}
	
	// setup constants
	rewind(IN);
	parse_names(&numConstants, &consts, &lineConstants, IN,const_cast< char *>("constant"), declarations[8]);
	
	// setup functions
	rewind(IN);
	parse_names(&numFuncs, &funcs, &lineFuncs, IN, const_cast< char *>("function"), declarations[9]);
	
	fclose(IN);
	
	
	// setup Matlab script
	create_matlab_determinantal_system("matlab_nullspace_system.m", "func_input_real",
									   ns_config,
									   numVars, vars, lineVars, numConstants, consts, lineConstants, numFuncs, funcs, lineFuncs);
	
	
	
	// run Matlab script
	std::stringstream converter;
	converter << program_options.matlab_command() << " matlab_nullspace_system";
	system(converter.str().c_str());
	converter.clear(); converter.str("");
	
	
	
	// setup new file
	
	OUT = safe_fopen_write(output_name.c_str());
	
	fprintf(OUT, "\n\nINPUT\n");
	
	std::string constants = just_constants("func_input_real",numConstants,consts,lineConstants);
	
	fprintf(OUT, "%s\n\n",constants.c_str());
	
	
	fprintf(OUT,"variable_group ");
	for (ii=0;ii<numVars; ii++){
		fprintf(OUT,"%s",vars[ii]);
		(ii==numVars-1) ? fprintf(OUT,";\n") : fprintf(OUT,", ");
	}

	
	
	for (ii=0; ii<ns_config->num_projections; ii++) {
		std::stringstream projname;
		projname << "pi_" << ii+1;
		write_vector_as_constants(ns_config->target_projection[ii], projname.str(), OUT);
	}
	
	if (!ns_config->randomizer()->is_square()) {
		write_matrix_as_constants( *(ns_config->randomizer()->get_mat_full_prec()), "r", OUT);
	}
	
	WaitOnGeneratedFile("derivative_polynomials_declaration");
	
	IN = safe_fopen_read("derivative_polynomials_declaration");
	while ((ch = fgetc(IN)) != EOF)
		fprintf(OUT, "%c", ch);
	fclose(IN);
	
	// END; written in the above transciption
	fprintf(OUT,"END;\n\n\n");
	
	write_vector_as_constants(ns_config->v_patch, "synthetic_var_patch", OUT);
	fprintf(OUT,"function synth_var_patch;\n");
	fprintf(OUT,"synth_var_patch = ");
	for (ii=0; ii<(ns_config->num_v_vars); ii++) {
		fprintf(OUT,"synthetic_var_patch_%d * synth%d",ii+1,ii+1);
		(ii==ns_config->num_v_vars-1) ? fprintf(OUT,";\n") : fprintf(OUT," + ");
	}
	
	
	fprintf(OUT,"\n\nTODO: add natural variable patch");
	
	fclose(OUT);
	// clear memory
	free(str);
	
	for (ii = 0; ii < numVars; ii++)
		free(vars[ii]);
	free(vars);
	free(lineVars);
	for (ii = 0; ii < numConstants; ii++)
		free(consts[ii]);
	free(consts);
	free(lineConstants);
	for (ii = 0; ii < numFuncs; ii++)
		free(funcs[ii]);
	free(funcs);
	free(lineFuncs);
	
	return;
}