// Feeds input into the machine's standard in. void cmd_inp(char **argv){ char *esc; esc = escapestr(argv[0]); if (!esc){ return; } write(pipe_fds[1],esc,strlen(esc)); free(esc); }
int printtype(collection_type *collection_ptr,struct genhashtable *ght) { int j=0; int offset=0; int value=0; struct valuepair *vp=NULL; if (gencontains(ght,collection_ptr->name)) vp=(struct valuepair *)gengettable(ght,collection_ptr->name); if (vp!=NULL) collection_ptr=(collection_type*) dwarf_entry_array[vp->index].entry_ptr; for(j=0;j<collection_ptr->num_members;j++) { dwarf_entry *entry=collection_ptr->members[j]; if (entry->tag_name==DW_TAG_inheritance) { inherit * inherit_ptr=(inherit *)entry->entry_ptr; if (inherit_ptr->data_member_location>offset) { printf(" reserved byte[%ld];\n",inherit_ptr->data_member_location-offset); offset=inherit_ptr->data_member_location; } { dwarf_entry *type=inherit_ptr->target_ptr; collection_type *c_ptr=(collection_type*)type->entry_ptr; offset+=printtype(c_ptr,ght); } } else { member * member_ptr=(member *)entry->entry_ptr; char *name=member_ptr->name; char *newname=NULL; dwarf_entry *type=member_ptr->type_ptr; char *typestr=printname(type,GETTYPE); char *poststr=printname(type,POSTNAME); if (member_ptr->data_member_location>offset) { printf(" reserved byte[%ld];\n",member_ptr->data_member_location-offset); offset=member_ptr->data_member_location; } offset+=getsize(type); newname=escapestr(name); { char buf[512]; char *dtype; sprintf(buf, "%s.%s\0", collection_ptr->name,newname); if (arrayt!=NULL&&gencontains(arrayt, &buf)) { genputtable(arraytype, buf, typestr); dtype=deref(typestr); printf(" %s_array * %s%s;\n",dtype,newname,poststr); free(dtype); } else printf(" %s %s%s;\n",typestr,newname,poststr); } free(newname); } } return offset; }
void initializeTypeArray() { int i; dwarf_entry * cur_entry; struct genhashtable * ght=genallocatehashtable((unsigned int (*)(void *)) & hashstring,(int (*)(void *,void *)) &equivalentstrings); struct genhashtable * sht=NULL; if (rootfile!=NULL) { char buf[512]; char a; int fd=open(rootfile,O_RDONLY); int offset=0; sht=genallocatehashtable((unsigned int (*)(void *)) & hashstring,(int (*)(void *,void *)) &equivalentstrings); while(1) { if (read(fd,&a,1)>0) { if (a!=13&&a!=10) buf[offset++]=a; } else break; if (offset>0&&(a==13||a==10)) { buf[offset++]=0; { char *str=copystr(buf); genputtable(sht,str,str); } offset=0; } } } if (arrayfile!=NULL) { char buf[512]; char sizebuf[512]; char a; int fd=open(arrayfile,O_RDONLY); int offset=0; int readmore=1; int state=0; arrayt=genallocatehashtable((unsigned int (*)(void *)) & hashstring,(int (*)(void *,void *)) &equivalentstrings); arraytype=genallocatehashtable((unsigned int (*)(void *)) & hashstring,(int (*)(void *,void *)) &equivalentstrings); while(readmore) { if (read(fd,&a,1)<=0) readmore=0; if (readmore) { if (a==' ') { state=1; buf[offset]=0; offset=0; } else if (a!=13&&a!=10) { if (state==0) buf[offset++]=a; else sizebuf[offset++]=a; } } if ((state==1)&&offset>0&&(a==13||a==10||!readmore)) { state=0; sizebuf[offset]=0; { char *str=copystr(buf); char *sizestr=copystr(sizebuf); genputtable(arrayt,str,sizestr); } offset=0; } } } /* Assign names */ for (i = 0; i < dwarf_entry_array_size; i++) { cur_entry = &dwarf_entry_array[i]; if (entry_is_type(cur_entry)) { collection_type* collection_ptr = (collection_type*)(cur_entry->entry_ptr); int j=0; int offset=0; int value=0; for(j=0;j<collection_ptr->num_members;j++) { dwarf_entry *entry=collection_ptr->members[j]; if (entry->tag_name==DW_TAG_inheritance) { value++; } else { member * member_ptr=(member *)entry->entry_ptr; char *name=member_ptr->name; dwarf_entry *type=member_ptr->type_ptr; char *typestr=printname(type,GETTYPE); char *poststr=printname(type,POSTNAME); if (typestr!=NULL) value++; } } } } for (i = 0; i < dwarf_entry_array_size; i++) { cur_entry = &dwarf_entry_array[i]; if (entry_is_type(cur_entry)) { collection_type* collection_ptr = (collection_type*)(cur_entry->entry_ptr); int j=0; int offset=0; int value=0; for(j=0;j<collection_ptr->num_members;j++) { dwarf_entry *entry=collection_ptr->members[j]; if (entry->tag_name==DW_TAG_inheritance) { value++; } else { member * member_ptr=(member *)entry->entry_ptr; char *name=member_ptr->name; dwarf_entry *type=member_ptr->type_ptr; char *typestr=printname(type,GETTYPE); char *poststr=printname(type,POSTNAME); if (typestr!=NULL) value++; } } if (collection_ptr->name!=NULL) { struct valuepair *vp=NULL; if (gencontains(ght,collection_ptr->name)) vp=(struct valuepair *)gengettable(ght,collection_ptr->name); if (vp==NULL||vp->value<value) { if (vp==NULL) { vp=(struct valuepair*)calloc(1,sizeof(struct valuepair)); genputtable(ght,collection_ptr->name,vp); } vp->value=value; vp->index=i; } } } } assigntype=1; if (sht!=NULL) { int repeat=1; while(repeat) { repeat=0; for (i = 0; i < dwarf_entry_array_size; i++) { cur_entry = &dwarf_entry_array[i]; if (entry_is_type(cur_entry)) { collection_type* collection_ptr = (collection_type*)(cur_entry->entry_ptr); int j=0; int offset=0; int value=0; if (!gencontains(sht,collection_ptr->name)) continue; if (gencontains(ght,collection_ptr->name)) { struct valuepair *vp=(struct valuepair*)gengettable(ght,collection_ptr->name); if (vp->index!=i) continue; } for(j=0;j<collection_ptr->num_members;j++) { dwarf_entry *entry=collection_ptr->members[j]; if (entry->tag_name==DW_TAG_inheritance) { inherit *in_ptr=(inherit*)collection_ptr->members[j]->entry_ptr; dwarf_entry *typeptr=in_ptr->target_ptr; collection_type* sub_ptr = (collection_type*)(typeptr->entry_ptr); if (!gencontains(sht,sub_ptr->name)) { repeat=1; genputtable(sht,sub_ptr->name,sub_ptr->name); } } else { member * member_ptr=(member *)entry->entry_ptr; char *name=member_ptr->name; dwarf_entry *type=member_ptr->type_ptr; char *typestr=printname(type,GETJUSTTYPE); if (typestr!=NULL&&!gencontains(sht,typestr)) { repeat=1; genputtable(sht,typestr,typestr); } } } } } } } for (i = 0; i < dwarf_entry_array_size; i++) { cur_entry = &dwarf_entry_array[i]; if (entry_is_type(cur_entry)) { collection_type* collection_ptr = (collection_type*)(cur_entry->entry_ptr); int j=0; int offset=0; if (collection_ptr->name==NULL) continue; if (sht!=NULL&&!gencontains(sht,collection_ptr->name)) continue; if (gencontains(ght,collection_ptr->name)) { struct valuepair *vp=(struct valuepair*)gengettable(ght,collection_ptr->name); if (vp->index!=i) continue; } j=0; printf("structure %s ",collection_ptr->name); while(j<collection_ptr->num_members&& collection_ptr->members[j]->tag_name==DW_TAG_inheritance) { inherit *in_ptr=(inherit*)collection_ptr->members[j]->entry_ptr; dwarf_entry *typeptr=in_ptr->target_ptr; collection_type* sub_ptr = (collection_type*)(typeptr->entry_ptr); if (j==0) printf("subclass of "); else printf(", "); printf("%s ",sub_ptr->name); j++; } printf("{ \n"); for(j=0;j<collection_ptr->num_members;j++) { dwarf_entry *entry=collection_ptr->members[j]; if (entry->tag_name==DW_TAG_inheritance) { inherit * inherit_ptr=(inherit *)entry->entry_ptr; if (inherit_ptr->data_member_location>offset) { printf(" reserved byte[%ld];\n",inherit_ptr->data_member_location-offset); offset=inherit_ptr->data_member_location; } { dwarf_entry *type=inherit_ptr->target_ptr; collection_type *c_ptr=(collection_type*)type->entry_ptr; offset+=printtype(c_ptr,ght); } } else { member * member_ptr=(member *)entry->entry_ptr; char *name=member_ptr->name; dwarf_entry *type=member_ptr->type_ptr; char *typestr=printname(type,GETTYPE); char *poststr=printname(type,POSTNAME); char *newname=NULL; if (member_ptr->data_member_location>offset) { printf(" reserved byte[%ld];\n",member_ptr->data_member_location-offset); offset=member_ptr->data_member_location; } offset+=getsize(type); newname=escapestr(name); { char buf[512]; char *dtype; sprintf(buf, "%s.%s\0", collection_ptr->name,newname); if (arrayt!=NULL&&gencontains(arrayt, &buf)) { genputtable(arraytype, copystr(buf), typestr); dtype=deref(typestr); printf(" %s_array * %s%s;\n",dtype,newname,poststr); free(dtype); } else printf(" %s %s%s;\n",typestr,newname,poststr); } free(newname); } } if (offset<collection_ptr->byte_size) printf(" reserved byte[%ld];\n",collection_ptr->byte_size-offset); printf("}\n\n"); } } if (arrayt!=NULL) { struct geniterator * gi=gengetiterator(arrayt); while(1) { char * str=(char *)gennext(gi); char *size=NULL; char *typestr=NULL; if (str==NULL) break; size=(char *)gengettable(arrayt,str); typestr=deref((char *)gengettable(arraytype,str)); printf("structure %s_array {\n",typestr); printf(" %s elem[%s];\n",typestr,size); printf("}\n"); free(typestr); } genfreeiterator(gi); } }