Esempio n. 1
0
File: rna.c Progetto: cjpatton/misc
void make_structure (const rna_t *mol, char *structure, int i, int j)
/* Called by print_structure. Reconstruct the optimal structure 
 * and create a friendly string. */
{
  int a = mol->opt[i][j].a,
      b = mol->opt[i][j].b; 

  if (a >= 0 && j >= 0) 
  {
    structure[a] = '(';
    structure[b] = ')'; 
    make_structure (mol, structure, i, a-1); 
    make_structure (mol, structure, a+1, b-1);
  }

}
Esempio n. 2
0
def_t *
emit_structure (const char *name, int su, struct_def_t *defs, type_t *type,
				void *data, storage_class_t storage)
{
	int         i, j;
	int         saw_null = 0;
	int         saw_func = 0;
	symbol_t   *struct_sym;
	symbol_t   *field_sym;
	def_t      *struct_def;
	def_t       field_def;

	name = save_string (name);
	if (!type)
		type = make_structure (0, su, defs, 0)->type;
	if (!is_struct (type) || (su == 's' && type->meta != ty_struct)
		|| (su == 'u' && type->meta != ty_union))
		internal_error (0, "structure %s type mismatch", name);
	for (i = 0, field_sym = type->t.symtab->symbols; field_sym;
		 i++, field_sym = field_sym->next) {
		if (!defs[i].name)
			internal_error (0, "structure %s unexpected end of defs", name);
		if (field_sym->type != defs[i].type)
			internal_error (0, "structure %s.%s field type mismatch", name,
							defs[i].name);
		if ((!defs[i].emit && saw_func) || (defs[i].emit && saw_null))
			internal_error (0, "structure %s mixed emit/copy", name);
		if (!defs[i].emit)
			saw_null = 1;
		if (defs[i].emit)
			saw_func = 1;
	}
	if (defs[i].name)
		internal_error (0, "structure %s too many defs", name);
	if (storage != sc_global && storage != sc_static)
		internal_error (0, "structure %s must be global or static", name);

	struct_sym = make_symbol (name, type, pr.far_data, storage);

	struct_def = struct_sym->s.def;
	if (struct_def->initialized)
		internal_error (0, "structure %s already initialized", name);
	struct_def->initialized = struct_def->constant = 1;
	struct_def->nosave = 1;

	for (i = 0, field_sym = type->t.symtab->symbols; field_sym;
		 i++, field_sym = field_sym->next) {
		field_def.type = field_sym->type;
		field_def.name = save_string (va ("%s.%s", name, field_sym->name));
		field_def.space = struct_def->space;
		field_def.offset = struct_def->offset + field_sym->s.offset;
		if (!defs[i].emit) {
			//FIXME relocs? arrays? structs?
			pr_type_t  *val = (pr_type_t *) data;
			memcpy (D_POINTER (void, &field_def), val,
					type_size (field_def.type) * sizeof (pr_type_t));
			data = &val[type_size (field_def.type)];
		} else {
			if (is_array (field_def.type)) {
Esempio n. 3
0
File: rna.c Progetto: cjpatton/misc
void print_structure (const rna_t *mol)
/* Print a string representation of the structure. */
{
  char structure [MAX]; 
  memset(structure, '.', sizeof(char) * MAX); 
  make_structure (mol, structure, 0, mol->n-1);
  if (mol->n == MAX)
    structure[mol->n-1] = '\0';
  else 
    structure[mol->n] = '\0'; 
  printf("%s", structure); 
}