attribute attribute_find ( relation rel, char *name) { /* attribute_find * Locates the given attribute, and returns an attribute structure */ attribute catt,ratt; tuple ctuple; word anum; /* Get the first attribute */ /* catt=attribute_findfirst(rel,&attribute_file); */ catt=relation_attribute_readfirst(rel,&ctuple,&anum); /* Whilst the attribute is valid, and the attribute does * not match the search criteria */ while ( (catt!=NULL) && (name!=NULL) && (strcmp(attribute_name(catt),name)!=0) ) { /* Locate the next field */ catt=relation_attribute_readnext(rel,&ctuple,catt,&anum); } /* Check to see if we actually found anything */ if ( (catt!=NULL) && (name!=NULL) && (strcmp(attribute_name(catt),name)==0) ) { /* We're about to destroy the tuple, which will destroy the attribute * we just found. Make a copy quick! */ /* Create a ptr to an attribute structure */ ratt=(attribute_struct *) malloc(sizeof(attribute_struct)); /* Check that the ptr was allocated. */ check_assign(ratt,"attributes.attribute_find(cpy)"); strcpy(attribute_name(ratt),attribute_name(catt)); attribute_type(ratt)=attribute_type(catt); attribute_size(ratt)=attribute_size(catt); attribute_no(ratt)=attribute_no(catt); close_tuple(&ctuple,TUPLE_DISPOSE); /* Return the ptr */ return(ratt); } else { /* Close the tuple */ close_tuple(&ctuple,TUPLE_DISPOSE); /* Return nothing */ return(NULL); } }
char *fmt_build(char *fmt,attribute att) { /* fmt_build * Builds a format string for printing out an attribute or value of * specified size */ int tabs=0; char *spacing_var; spacing_var=resolve_variable("width"); if (spacing_var!=NULL) { if (strcmp(spacing_var,"auto")==0) { tabs=0; } else if (strcmp(spacing_var,"tab")==0) { tabs=-1; } else { tabs=atoi(spacing_var); } } if ( (att->attrib_size>0) && (tabs==0) ) if ( (attribute_type(att)==DT_BOOLEAN) ) { sprintf(fmt,"%%-5.5s "); } else { sprintf(fmt,"%%-%d.%ds ",att->attrib_size,att->attrib_size); } else if ( (att->attrib_size<=0) || (tabs==-1) ) { sprintf(fmt,"%%s \t"); } else { sprintf(fmt,"%%-%d.%ds ",tabs,tabs); } return(fmt); }
void attribute_print(attribute att) { /* attribute_print * Print out the information contained in the specified * attribute */ char fmt[FORMAT_SIZE]; fmt_build(fmt,att); /* Check that the ptr is assigned! */ if (att!=NULL) { switch (attribute_type(att)) { case DT_STRING: leap_printf(DTS_STRING); leap_printf(" "); break; case DT_NUMBER: leap_printf(DTS_NUMBER); leap_printf(" "); break; case DT_BOOLEAN: leap_printf(DTS_BOOLEAN); leap_printf(" "); break; default: leap_printf(DTS_UNSUPPORTED); leap_printf(" "); } if (attribute_size(att)==0) leap_printf("-"); else leap_printf("%d",attribute_size(att)); if (attribute_size(att)<9) leap_printf(" "); else if (attribute_size(att)<99) leap_printf(" "); else leap_printf(" "); leap_printf("%-25.25s \n",attribute_name(att)); } }
virtual attribute_type attribute(value_type const& key) const { return this->valid() ? this->forward().attribute(key) : attribute_type(); }