char * printname(dwarf_entry * type,int op) { if (type==NULL) { if (op==GETTYPE||op==GETJUSTTYPE) return NULL; } switch(type->tag_name) { case DW_TAG_enumeration_type: if (op==GETTYPE) return "int"; break; case DW_TAG_array_type: { modifier_type * modifier_ptr=(modifier_type*)type->entry_ptr; if (op==GETTYPE||op==GETJUSTTYPE) { char *typename=printname(modifier_ptr->target_ptr,op); return typename; } else if (op==POSTNAME) { int i; int size=1; char *typename=printname(modifier_ptr->target_ptr,op); char *newptr=(char *)malloc(200); for(i=0;i<modifier_ptr->num_array;i++) { size*=((array_bound*)modifier_ptr->array_ptr[i]->entry_ptr)->upperbound+1; } sprintf(newptr,"%s[%ld]",typename,size); return newptr; }
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; }
int testandextractfromlist(listname **lin, char*nom) { listname *newvar; int val_1, val_2; int return_stmt; printname(*lin); if (!(*lin)) { return 0; } else { sscanf(nom,"%d",&val_1); sscanf((*lin)->n_name,"%d",&val_2); if (val_1==val_2) { /* newvar = *lin; *lin = (*lin)->suiv; free(newvar);*/ /* continue to remove while the label stays the same */ /* return_stmt=testandextractfromlist(lin,nom);*/ return 1; } else { return 0; } } }
/* * print [inode] [size] name * return # of characters printed, no trailing characters. */ static int printaname(const FTSENT *p, u_long inodefield, u_long sizefield) { struct stat *sp; int chcnt; #ifdef COLORLS int color_printed = 0; #endif sp = p->fts_statp; chcnt = 0; if (f_inode) chcnt += xo_emit("{t:inode/%*ju} ", (int)inodefield, (uintmax_t)sp->st_ino); if (f_size) chcnt += xo_emit("{t:size/%*jd} ", (int)sizefield, howmany(sp->st_blocks, blocksize)); #ifdef COLORLS if (f_color) color_printed = colortype(sp->st_mode); #endif chcnt += printname("name", p->fts_name); #ifdef COLORLS if (f_color && color_printed) endcolor(0); #endif if (f_type) chcnt += printtype(sp->st_mode); return (chcnt); }
void FunNameStack::printdel(std::ostream& file) { if (s_print==2) { #ifdef USE_BOOST_MULTITHREADING NameStack* ns = get_thread_stack(); file << "FunNameStack::del: id=" << ns->id << " qname =" << ns->qname << " last name= \""; printname(file, ns, ns->qname - 1); file << " \"\n"; #else file << "FunNameStack::del: qname =" << qname << " last name="; printname(file, qname - 1) << '\n'; #endif } else if(s_print==4) { file << "FunNameStack::del:\n" << (*this); } }
/********************************************** * Lists the node names in ascending sequence * **********************************************/ void listnodes(Node *pNode) { if(pNode->pLeft) listnodes(pNode->pLeft); for(int i = 0; i<pNode->count ; i++) printname(pNode->pName); if(pNode->pRight) listnodes(pNode->pRight); }
/* * given this parent, depth first number its children. */ void dfn(nltype *parentp) { arctype *arcp; #ifdef DEBUG if (debug & DFNDEBUG) { (void) printf("[dfn] dfn("); printname(parentp); (void) printf(")\n"); } #endif /* DEBUG */ if (!dfn_stack) { dfn_sz = DFN_DEPTH; dfn_stack = (dfntype *) malloc(dfn_sz * sizeof (dfntype)); if (!dfn_stack) { (void) fprintf(stderr, "fatal: can't malloc %d objects\n", dfn_sz); exit(1); } } /* * if we're already numbered, no need to look any furthur. */ if (dfn_numbered(parentp)) return; /* * if we're already busy, must be a cycle */ if (dfn_busy(parentp)) { dfn_findcycle(parentp); return; } /* * visit yourself before your children */ dfn_pre_visit(parentp); /* * visit children */ for (arcp = parentp->children; arcp; arcp = arcp->arc_childlist) dfn(arcp->arc_childp); /* * visit yourself after your children */ dfn_post_visit(parentp); }
/* * visit a node after all its children * [MISSING: an explanation] * and pop it off the stack */ void dfn_post_visit(nltype *parentp) { nltype *memberp; #ifdef DEBUG if (debug & DFNDEBUG) { (void) printf("[dfn_post_visit]\t%d: ", dfn_depth); printname(parentp); (void) printf("\n"); } #endif /* DEBUG */ /* * number functions and things in their cycles * unless the function is itself part of a cycle */ if (parentp->cyclehead == parentp) { dfn_counter += 1; for (memberp = parentp; memberp; memberp = memberp->cnext) { memberp->toporder = dfn_counter; #ifdef DEBUG if (debug & DFNDEBUG) { (void) printf("[dfn_post_visit]\t\tmember "); printname(memberp); (void) printf(" -> toporder = %d\n", dfn_counter); } #endif /* DEBUG */ } #ifdef DEBUG } else { if (debug & DFNDEBUG) (void) printf( "[dfn_post_visit]\t\tis part of a cycle\n"); #endif /* DEBUG */ } dfn_depth -= 1; }
/* * deal with self-cycles * for lint: ARGSUSED */ dfn_self_cycle(nltype *parentp) { /* * since we are taking out self-cycles elsewhere * no need for the special case, here. */ # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_self_cycle] " ); printname( parentp ); printf( "\n" ); } # endif /* DEBUG */ }
/* * push a parent onto the stack and mark it busy */ void dfn_pre_visit(nltype *parentp) { dfn_depth += 1; if ( dfn_depth >= DFN_DEPTH ) errx( 1 , "[dfn] out of my depth (dfn_stack overflow)" ); dfn_stack[ dfn_depth ].nlentryp = parentp; dfn_stack[ dfn_depth ].cycletop = dfn_depth; parentp -> toporder = DFN_BUSY; # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_pre_visit]\t\t%d:" , dfn_depth ); printname( parentp ); printf( "\n" ); } # endif /* DEBUG */ }
/* * given this parent, depth first number its children. */ void dfn(nltype *parentp) { arctype *arcp; # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn] dfn(" ); printname( parentp ); printf( ")\n" ); } # endif /* DEBUG */ /* * if we're already numbered, no need to look any further. */ if ( dfn_numbered( parentp ) ) { return; } /* * if we're already busy, must be a cycle */ if ( dfn_busy( parentp ) ) { dfn_findcycle( parentp ); return; } /* * visit yourself before your children */ dfn_pre_visit( parentp ); /* * visit children */ for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) { if ( arcp -> arc_flags & DEADARC ) continue; dfn( arcp -> arc_childp ); } /* * visit yourself after your children */ dfn_post_visit( parentp ); }
static void printlink(const FTSENT *p) { int lnklen; char name[MAXPATHLEN + 1]; char path[MAXPATHLEN + 1]; if (p->fts_level == FTS_ROOTLEVEL) (void)snprintf(name, sizeof(name), "%s", p->fts_name); else (void)snprintf(name, sizeof(name), "%s/%s", p->fts_parent->fts_accpath, p->fts_name); if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) { xo_error("\nls: %s: %s\n", name, strerror(errno)); return; } path[lnklen] = '\0'; xo_emit(" -> "); (void)printname("target", path); }
/* * push a parent onto the stack and mark it busy */ void dfn_pre_visit(nltype *parentp) { if (!dfn_stack) { dfn_sz = DFN_DEPTH; dfn_stack = (dfntype *) malloc(dfn_sz * sizeof (dfntype)); if (!dfn_stack) { (void) printf("fatal: can't malloc %d objects\n", dfn_sz); exit(1); } } dfn_depth += 1; if (dfn_depth >= dfn_sz) { dfn_sz += DFN_DEPTH; dfn_stack = (dfntype *) realloc(dfn_stack, dfn_sz * sizeof (dfntype)); if (!dfn_stack) { (void) fprintf(stderr, "fatal: can't realloc %d objects\n", dfn_sz); exit(1); } } dfn_stack[dfn_depth].nlentryp = parentp; dfn_stack[dfn_depth].cycletop = dfn_depth; parentp->toporder = DFN_BUSY; #ifdef DEBUG if (debug & DFNDEBUG) { (void) printf("[dfn_pre_visit]\t\t%d:", dfn_depth); printname(parentp); (void) printf("\n"); } #endif /* DEBUG */ }
void removefromlist(listname **lin, char*nom) { listname *newvar,*prev; int val_1, val_2; int return_stmt; int out; printname(*lin); if (*lin) { sscanf(nom,"%d",&val_1); prev=(listname *) calloc(1,sizeof(listname)); prev->suiv=*lin; *lin=prev; newvar=(*lin)->suiv; out = 0; while (newvar && out == 0) { sscanf((newvar)->n_name,"%d",&val_2); if (val_1==val_2) { prev->suiv=newvar->suiv; free(newvar); } if (prev->suiv) { prev=prev->suiv; newvar=prev->suiv; } else { out = 1; } } prev=*lin; *lin=(*lin)->suiv; free(prev); } }
/* * in one top to bottom pass over the topologically sorted namelist * propagate: * printflag as the union of parents' printflags * propfraction as the sum of fractional parents' propfractions * and while we're here, sum time for functions. */ static void doflags( void) { long index; nltype *childp; nltype *oldhead; oldhead = 0; for(index = nname-1; index >= 0; index -= 1){ childp = topsortnlp[index]; /* * if we haven't done this function or cycle, * inherit things from parent. * this way, we are linear in the number of arcs * since we do all members of a cycle (and the cycle itself) * as we hit the first member of the cycle. */ if(childp->cyclehead != oldhead){ oldhead = childp->cyclehead; inheritflags(childp); } #ifdef DEBUG if(debug & PROPDEBUG){ printf("[doflags] "); printname(childp); printf(" inherits printflag %d and propfraction %f\n", childp->printflag, childp->propfraction); } #endif if(!childp->printflag){ /* * printflag is off * it gets turned on by * being on -f list, * or there not being any -f list and not being on -e list. */ if(onlist(flist, childp->name) || (!fflag && !onlist(elist, childp->name))){ childp->printflag = TRUE; } } else{ /* * this function has printing parents: * maybe someone wants to shut it up * by putting it on -e list. (but favor -f over -e) */ if((!onlist(flist, childp->name)) && onlist(elist, childp->name)){ childp->printflag = FALSE; } } if(childp->propfraction == 0.0){ /* * no parents to pass time to. * collect time from children if * its on -F list, * or there isn't any -F list and its not on -E list. */ if(onlist(Flist, childp->name) || (!Fflag && !onlist(Elist, childp->name))){ childp->propfraction = 1.0; } } else{ /* * it has parents to pass time to, * but maybe someone wants to shut it up * by puttting it on -E list. (but favor -F over -E) */ if(!onlist(Flist, childp->name) && onlist(Elist, childp->name)){ childp->propfraction = 0.0; } } childp->propself = childp->time * childp->propfraction; printtime += childp->propself; #ifdef DEBUG if(debug & PROPDEBUG){ printf("[doflags] "); printname(childp); printf(" ends up with printflag %d and propfraction %f\n", childp->printflag, childp->propfraction); printf("time %f propself %f printtime %f\n", childp->time, childp->propself, printtime); } #endif } }
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); } }
/* * MISSING: an explanation */ void dfn_findcycle(nltype *childp) { int cycletop; nltype *cycleheadp; nltype *tailp; int index; for ( cycletop = dfn_depth ; cycletop > 0 ; cycletop -= 1 ) { cycleheadp = dfn_stack[ cycletop ].nlentryp; if ( childp == cycleheadp ) { break; } if ( childp -> cyclehead != childp && childp -> cyclehead == cycleheadp ) { break; } } if ( cycletop <= 0 ) errx( 1 , "[dfn_findcycle] couldn't find head of cycle" ); # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_findcycle] dfn_depth %d cycletop %d " , dfn_depth , cycletop ); printname( cycleheadp ); printf( "\n" ); } # endif /* DEBUG */ if ( cycletop == dfn_depth ) { /* * this is previous function, e.g. this calls itself * sort of boring */ dfn_self_cycle( childp ); } else { /* * glom intervening functions that aren't already * glommed into this cycle. * things have been glommed when their cyclehead field * points to the head of the cycle they are glommed into. */ for ( tailp = cycleheadp ; tailp -> cnext ; tailp = tailp -> cnext ) { /* void: chase down to tail of things already glommed */ # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_findcycle] tail " ); printname( tailp ); printf( "\n" ); } # endif /* DEBUG */ } /* * if what we think is the top of the cycle * has a cyclehead field, then it's not really the * head of the cycle, which is really what we want */ if ( cycleheadp -> cyclehead != cycleheadp ) { cycleheadp = cycleheadp -> cyclehead; # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_findcycle] new cyclehead " ); printname( cycleheadp ); printf( "\n" ); } # endif /* DEBUG */ } for ( index = cycletop + 1 ; index <= dfn_depth ; index += 1 ) { childp = dfn_stack[ index ].nlentryp; if ( childp -> cyclehead == childp ) { /* * not yet glommed anywhere, glom it * and fix any children it has glommed */ tailp -> cnext = childp; childp -> cyclehead = cycleheadp; # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_findcycle] glomming " ); printname( childp ); printf( " onto " ); printname( cycleheadp ); printf( "\n" ); } # endif /* DEBUG */ for ( tailp = childp ; tailp->cnext ; tailp = tailp->cnext ) { tailp -> cnext -> cyclehead = cycleheadp; # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_findcycle] and its tail " ); printname( tailp -> cnext ); printf( " onto " ); printname( cycleheadp ); printf( "\n" ); } # endif /* DEBUG */ } } else if ( childp -> cyclehead != cycleheadp /* firewall */ ) { fprintf( stderr , "[dfn_busy] glommed, but not to cyclehead\n" ); } } } }
/* * Traverse() walks the logical directory structure specified by the argv list * in the order specified by the mastercmp() comparison function. During the * traversal it passes linked lists of structures to display() which represent * a superset (may be exact set) of the files to be displayed. */ static void traverse(int argc, char *argv[], int options) { FTS *ftsp; FTSENT *p, *chp; int ch_options; if ((ftsp = fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL) err(1, "fts_open"); /* * We ignore errors from fts_children here since they will be * replicated and signalled on the next call to fts_read() below. */ chp = fts_children(ftsp, 0); if (chp != NULL) display(NULL, chp, options); if (f_listdir) return; /* * If not recursing down this tree and don't need stat info, just get * the names. */ ch_options = !f_recursive && !f_label && options & FTS_NOSTAT ? FTS_NAMEONLY : 0; while ((p = fts_read(ftsp)) != NULL) switch (p->fts_info) { case FTS_DC: warnx("%s: directory causes a cycle", p->fts_name); break; case FTS_DNR: case FTS_ERR: warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); rval = 1; break; case FTS_D: if (p->fts_level != FTS_ROOTLEVEL && p->fts_name[0] == '.' && !f_listdot) break; /* * If already output something, put out a newline as * a separator. If multiple arguments, precede each * directory with its name. */ if (output) { putchar('\n'); (void)printname(p->fts_path); puts(":"); } else if (argc > 1) { (void)printname(p->fts_path); puts(":"); output = 1; } chp = fts_children(ftsp, ch_options); display(p, chp, options); if (!f_recursive && chp != NULL) (void)fts_set(ftsp, p, FTS_SKIP); break; default: break; } if (errno) err(1, "fts_read"); }
void printlong(const DISPLAY *dp) { struct stat *sp; FTSENT *p; NAMES *np; char buf[20]; #ifdef COLORLS int color_printed = 0; #endif if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) && (f_longform || f_size)) { (void)printf("total %lu\n", howmany(dp->btotal, blocksize)); } for (p = dp->list; p; p = p->fts_link) { if (IS_NOPRINT(p)) continue; sp = p->fts_statp; if (f_inode) (void)printf("%*lu ", dp->s_inode, (u_long)sp->st_ino); if (f_size) (void)printf("%*jd ", dp->s_block, howmany(sp->st_blocks, blocksize)); strmode(sp->st_mode, buf); aclmode(buf, p); np = p->fts_pointer; (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink, sp->st_nlink, dp->s_user, np->user, dp->s_group, np->group); if (f_flags) (void)printf("%-*s ", dp->s_flags, np->flags); if (f_label) (void)printf("%-*s ", dp->s_label, np->label); if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) printdev(dp->s_size, sp->st_rdev); else printsize(dp->s_size, sp->st_size); if (f_accesstime) printtime(sp->st_atime); else if (f_birthtime) printtime(sp->st_birthtime); else if (f_statustime) printtime(sp->st_ctime); else printtime(sp->st_mtime); #ifdef COLORLS if (f_color) color_printed = colortype(sp->st_mode); #endif (void)printname(p->fts_name); #ifdef COLORLS if (f_color && color_printed) endcolor(0); #endif if (f_type) (void)printtype(sp->st_mode); if (S_ISLNK(sp->st_mode)) printlink(p); (void)putchar('\n'); } }
void loadlgf(int mode) { FILE *ps; char inname[150], temp[500], *pdchar; char **signals; short *signets; objectptr *libobj; genericptr *iolabel; int i, sigs; sscanf(_STR, "%149s", inname); ps = fopen(inname, "r"); if (ps == NULL) { sprintf(inname, "%s.lgf", _STR); ps = fopen(inname, "r"); if (ps == NULL) { sprintf(inname, "%s.lfo", _STR); ps = fopen(inname, "r"); if (ps == NULL) { Wprintf("Can't open LGF file %s", inname); return; } } } /* for PostScript file, remove ".lgf" or ".lfo" (to be replaced with ".ps") */ if ((pdchar = strstr(inname, ".l")) != NULL) *pdchar = '\0'; Wprintf("Loaded file: %s", inname); /* Make sure that LGF object library has been loaded by loading it now. */ if (NameToLibrary(LGF_LIB) < 0) { int ilib; strcpy(_STR, LGF_LIB); ilib = createlibrary(FALSE); loadlibrary(ilib); } /* Read header information */ if (fgets(temp, 149, ps) == NULL) { Wprintf("Error: end of file."); return; } for (pdchar = temp; *pdchar != '-' && *pdchar != '\n'; pdchar++); if (*pdchar == '\n') { Wprintf("Not an LGF file?"); return; } if (*(++pdchar) != '5') { Wprintf("Don't know how to read version %c.", *pdchar); return; } if (fgets(temp, 149, ps) == NULL) { Wprintf("Error: end of file."); return; } for (pdchar = temp; *pdchar != 'f' && *pdchar != '\n'; pdchar++); for (; *pdchar != 's' && *pdchar != '\n'; pdchar++); if (*pdchar == '\n') { Wprintf("Something wrong with the LGF file?"); return; } /* Done with header. . . okay to clear current page now unless importing */ if (mode == 0) { reset(topobject, NORMAL); pagereset(areawin->page); } /* Set up filename and object (page) name */ xobjs.pagelist[areawin->page]->filename = (char *) realloc ( xobjs.pagelist[areawin->page]->filename, (strlen(inname) + 1) * sizeof(char)); strcpy(xobjs.pagelist[areawin->page]->filename, inname); /* If the filename has a path component, use only the root */ if ((pdchar = strrchr(inname, '/')) != NULL) sprintf(topobject->name, "%s", pdchar + 1); else sprintf(topobject->name, "%s", inname); renamepage(areawin->page); printname(topobject); /* Read objects */ for(;;) { char *lineptr, keyptr, tmpstring[256]; int dval; short pvalx, pvaly, pvalx2, pvaly2; if (fgets(temp, 499, ps) == NULL) break; /* End-Of-File */ /* ignore whitespace */ for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); if (*lineptr == '\n') continue; /* ignore blank lines */ switch(keyptr = *lineptr) { case '#': /* comment */ break; case 'n': /* nodes */ sscanf(++lineptr, "%d", &dval); for (i = 0; i < dval; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in node section"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr == '\n'); } break; case 's': /* signal names --- save for future reference */ sscanf(++lineptr, "%d", &sigs); signals = (char **) malloc(sigs * sizeof(char *)); signets = (short *) malloc(sigs * sizeof(short)); for (i = 0; i < sigs; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in signal section"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr == '\n'); sscanf(lineptr, "%hd %249s", &signets[i], tmpstring); signals[i] = (char *)malloc((strlen(tmpstring) + 1) * sizeof(char)); sprintf(signals[i], "%s", tmpstring); } break; case 'l': { /* labels */ labelptr *newlabel; char *tstrp; sscanf(++lineptr, "%d", &dval); for (i = 0; i < dval; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in signal section"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr == '\n'); /* Allocate label, and put node number into X value, to be replaced */ /* Flag it using an inappropriate rotation value (= 500) */ sscanf(lineptr, "%hd %hd", &pvalx, &pvaly); /* Get rid of newline character, if any */ ridnewline(lineptr); /* forward to the label part of the input line */ tstrp = lineptr - 1; while (isdigit(*(++tstrp))); while (isspace(*(++tstrp))); while (isdigit(*(++tstrp))); while (isspace(*(++tstrp))); while (isdigit(*(++tstrp))); while (isspace(*(++tstrp))); if (tstrp != NULL) { /* could be a blank line */ stringpart *strptr; NEW_LABEL(newlabel, topobject); labeldefaults(*newlabel, False, xmat(pvalx), ymat(pvaly)); (*newlabel)->justify = TOP | NOTBOTTOM; (*newlabel)->color = DEFAULTCOLOR; (*newlabel)->string->data.font = 0; strptr = makesegment(&((*newlabel)->string), NULL); strptr->type = TEXT_STRING; strptr->data.string = (char *)malloc(1 + strlen(tstrp)); strcpy(strptr->data.string, tstrp); (*newlabel)->pin = NORMAL; } }} break; case 'w': { /* wires, implemented as single-segment polygons */ polyptr *newwire; XPoint *tmppnts; sscanf(++lineptr, "%d", &dval); for (i = 0; i < dval; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in wire section"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr == '\n'); /* Allocate wire */ NEW_POLY(newwire, topobject); sscanf(lineptr, "%hd %hd %hd %hd", &pvalx, &pvaly, &pvalx2, &pvaly2); (*newwire)->number = 2; (*newwire)->points = (XPoint *)malloc(2 * sizeof(XPoint)); (*newwire)->width = 1.0; (*newwire)->style = UNCLOSED; (*newwire)->color = DEFAULTCOLOR; (*newwire)->passed = NULL; tmppnts = (*newwire)->points; tmppnts->x = xmat(pvalx); tmppnts->y = ymat(pvaly); (++tmppnts)->x = xmat(pvalx2); tmppnts->y = ymat(pvaly2); }} break; case 'p': /* solder dot */ sscanf(++lineptr, "%d", &dval); for (i = 0; i < dval; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in solder dot section"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr == '\n'); /* Allocate arc */ sscanf(lineptr, "%hd %hd", &pvalx, &pvaly); drawdot(xmat(pvalx), ymat(pvaly)); } break; case 'b': { /* boxes */ polyptr *newpoly; pointlist newpoints; sscanf(++lineptr, "%d", &dval); for (i = 0; i < dval; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in box section"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr == '\n'); NEW_POLY(newpoly, topobject); (*newpoly)->style = DASHED; (*newpoly)->color = DEFAULTCOLOR; (*newpoly)->width = 1.0; (*newpoly)->number = 4; (*newpoly)->points = (pointlist) malloc(4 * sizeof(XPoint)); (*newpoly)->passed = NULL; newpoints = (*newpoly)->points; sscanf(lineptr, "%hd %hd %hd %hd", &pvalx, &pvaly, &pvalx2, &pvaly2); newpoints->x = xmat(pvalx); newpoints->y = ymat(pvaly); (newpoints + 1)->x = xmat(pvalx2); (newpoints + 2)->y = ymat(pvaly2); (newpoints + 2)->x = (newpoints + 1)->x; (newpoints + 3)->x = newpoints->x; (newpoints + 1)->y = newpoints->y; (newpoints + 3)->y = (newpoints + 2)->y; }} break; case 'g': { /* gates */ objinstptr *newinst; labelptr *newlabel; int j, k, hval, flip; sscanf(++lineptr, "%d", &dval); for (i = 0; i < dval; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in gates section"); return; } for (lineptr = temp; *lineptr != '\n'; lineptr++); *lineptr = '\0'; for (lineptr = temp; isspace(*lineptr) && *lineptr != '\0'; lineptr++); } while (*lineptr == '\0'); /* double loop through user libraries */ for (j = 0; j < xobjs.numlibs; j++) { for (k = 0; k < xobjs.userlibs[j].number; k++) { libobj = xobjs.userlibs[j].library + k; if (!strcmp(lineptr, (*libobj)->name)) break; } if (k < xobjs.userlibs[j].number) break; } strcpy(tmpstring, lineptr); /* read gate definition */ if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file during gate read"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); if (j < xobjs.numlibs || k < xobjs.userlibs[xobjs.numlibs - 1].number) { NEW_OBJINST(newinst, topobject); sscanf(lineptr, "%hd %hd %hd %*d %*d %*d %d", &pvalx, &pvaly, &pvalx2, &hval); flip = (pvalx2 >= 4) ? 1 : 0; if (!strcmp(tmpstring, "FROM")) flip = 1 - flip; (*newinst)->position.x = xmat(pvalx); (*newinst)->position.y = ymat(pvaly); (*newinst)->scale = 1.0; (*newinst)->color = DEFAULTCOLOR; (*newinst)->params = NULL; (*newinst)->passed = NULL; if (pvalx2 & 0x01) pvalx2 ^= 0x02; if (pvalx2 >= 4) (*newinst)->rotation = -(((pvalx2 - 4) * 90) + 1); else (*newinst)->rotation = (pvalx2 * 90) + 1; (*newinst)->thisobject = *libobj; (*newinst)->bbox.lowerleft.x = (*libobj)->bbox.lowerleft.x; (*newinst)->bbox.lowerleft.y = (*libobj)->bbox.lowerleft.y; (*newinst)->bbox.width = (*libobj)->bbox.width; (*newinst)->bbox.height = (*libobj)->bbox.height; /* Add label to "TO" and "FROM" */ if (!strcmp(tmpstring, "FROM") || !strcmp(tmpstring, "TO")) { int nval; hval--; fgets(temp, 499, ps); sscanf(temp, "%d", &nval); for (k = 0; k < sigs; k++) if (signets[k] == nval) { stringpart *strptr; NEW_LABEL(newlabel, topobject); /* reconnect newinst if displaced by realloc() */ newinst = (objinstptr *)(topobject->plist + topobject->parts - 2); labeldefaults(*newlabel, False, (*newinst)->position.x, (*newinst)->position.y); (*newlabel)->color = DEFAULTCOLOR; (*newlabel)->pin = LOCAL; (*newlabel)->color = LOCALPINCOLOR; if (!strcmp(tmpstring, "TO")) (*newlabel)->position.x += ((flip) ? 48 : -48); else (*newlabel)->position.x += ((flip) ? 54 : -54); (*newlabel)->justify = NOTBOTTOM; if (flip) (*newlabel)->justify |= (RIGHT | NOTLEFT); (*newlabel)->string->data.font = 0; strptr = makesegment(&((*newlabel)->string), NULL); strptr->type = TEXT_STRING; strptr->data.string = (char *)malloc(1 + strlen(signals[k])); strcpy(strptr->data.string, signals[k]); break; } } } /* read through list of attributes */ else { sscanf(lineptr, "%*d %*d %*d %*d %*d %*d %d", &hval); Wprintf("No library object %s", tmpstring); } for (j = 0; j < hval + 1; j++) { if (fgets(temp, 499, ps) == NULL) { Wprintf("Unexpected end of file"); return; } } /* read to next blank line */ do { if (fgets(temp, 499, ps) == NULL) break; for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr != '\n'); }} break; case 'h': { /* history */ int j, hval; sscanf(++lineptr, "%d", &dval); for (i = 0; i < dval; i++) { do { if (fgets(temp, 499, ps) == NULL) { Wprintf("End of file in history section"); return; } for (lineptr = temp; isspace(*lineptr) && *lineptr != '\n'; lineptr++); } while (*lineptr == '\n'); /* read through history */ sscanf(lineptr, "%*d %d", &hval); for (j = 0; j < hval; j++) if (fgets(temp, 499, ps) == NULL) { Wprintf("Unexpected end of file"); return; } }} break; case '.': /* blank, don't use for EOF */ break; default: Wprintf("Don't understand statement '%c'", *lineptr); break; } } /* check for unattached labels and delete them */ for (iolabel = topobject->plist; iolabel < topobject->plist + topobject->parts; iolabel++) if (IS_LABEL(*iolabel)) { if (TOLABEL(iolabel)->rotation == 500) { genericptr *tmplabel; free(TOLABEL(iolabel)->string); free(*iolabel); for (tmplabel = iolabel + 1; tmplabel < topobject->plist + topobject->parts; tmplabel++) *(tmplabel - 1) = *tmplabel; topobject->parts--; iolabel--; } } calcbbox(areawin->topinstance); centerview(areawin->topinstance); for (i = 0; i < sigs; i++) free(signals[i]); free(signals); free(signets); }
void loadmat4(caddr_t nullval) { char inname[150], *temp, *buffer, keyword[30], percentc, *pdchar; int bufsize = 256; short curcolor = DEFAULTCOLOR; char colorstr[100][5]; short matcolors = 0; float curwidth = 1.0; int tmpstyle = UNCLOSED; sscanf(_STR, "%149s", inname); ps = fopen(inname, "r"); if (ps == NULL) { sprintf(inname, "%s.ps", _STR); ps = fopen(inname, "r"); if (ps == NULL) { sprintf(inname, "%s.eps", _STR); ps = fopen(inname, "r"); if (ps == NULL) { Wprintf("Can't open Matlab PostScript file %s", inname); return; } } } /* Keep same filename---overwriting file is end-user's own risk */ if ((pdchar = strstr(_STR, ".ps")) != NULL) *pdchar = '\0'; sprintf(topobject->name, "%s", _STR); Wprintf("Loaded file: %s", inname); renamepage(areawin->page); printname(topobject); /* Create input string buffer */ buffer = (char *)malloc(bufsize * sizeof(char)); temp = buffer; /* Read header information */ if (fgets(temp, 149, ps) == NULL) { Wprintf("Error: end of file."); return; } if (*temp != '%' || *(temp + 1) != '!') { Wprintf("Not a PostScript file?"); return; } if (fgets(temp, 149, ps) == NULL) { Wprintf("Error: end of file."); return; } if (!strstr(temp, "MATLAB")) { Wprintf("Not a Matlab PostScript file?"); return; } /* Read through to Page start */ do { if (fgets(temp, 149, ps) == NULL) { Wprintf("Error: no pages in input."); return; } if (strstr(temp, "%%Page:") != NULL) break; } while (1); /* Read objects */ do { char *lineptr, keyptr; if (fgets(temp, 255, ps) == NULL) break; /* End-Of-File */ temp = buffer; /* scan from the end; ignore blank lines. */ for (lineptr = buffer; (*lineptr != '\n') && (*lineptr != '\0'); lineptr++); /* ignore any blank lines and PostScript comment lines */ if (lineptr != buffer && *buffer != '%') { for (keyptr = lineptr - 1; isspace(*keyptr) && keyptr != buffer; keyptr--); for (; !isspace(*keyptr) && keyptr != buffer; keyptr--); sscanf(keyptr, "%29s", keyword); if (!strcmp(keyword, "showpage")) { free(buffer); return False; /* end of page */ } else if (!strcmp(keyword, "bdef")) { /* new color definition */ char *bb; float red, green, blue; if ((bb = strchr(buffer, '{')) != NULL) { sscanf(bb + 1, "%f %f %f", &red, &green, &blue); curcolor = rgb_alloccolor((int)(red * 65535), (int)(green * 65535), (int)(blue * 65535)); addnewcolorentry(curcolor); } if ((bb = strchr(buffer, '/')) != NULL) { sscanf(bb, "%4s", &colorstr[matcolors]); matcolors++; } } else if (!strcmp(keyword, "w")) { /* linewidth */ float tmpwidth; sscanf(buffer, "%f", &tmpwidth) } else if (!strcmp(keyword, "DO")) { /* style */ tmpstyle = DOTTED | UNCLOSED; } else if (!strcmp(keyword, "SO")) { /* style */ tmpstyle = UNCLOSED; } else if (!strcmp(keyword, "DA")) { /* style */ tmpstyle = DASHED | UNCLOSED; } else if (!strcmp(keyword, "FMSR")) ; /* ignore font spec for now */ else if (!strcmp(keyword, "j")) ; /* ignore line join */ else if (!strcmp(keyword, "def")) ; /* ignore */ else if (!strcmp(keyword, "dictionary")) ; /* ignore */ else if (!strcmp(keyword, "np")) ; /* ignore clip paths */ else { /* continuation line ? */ for (lineptr = buffer; (*lineptr != '\n') && (*lineptr != '\0'); lineptr++); if (*lineptr == '\n') *lineptr = ' '; bufsize = (int)(lineptr - buffer) + 256; buffer = (char *)realloc(buffer, bufsize * sizeof(char)); temp = buffer + (bufsize - 256); } }
// error: !=0 si erreur fatale static RESP_STRUCT readtable(htsmoduleStruct * str, FILE * fp, RESP_STRUCT trans, int *error) { char rname[1024]; unsigned short int length; int j; *error = 0; // pas d'erreur trans.file_position = -1; trans.type = (int) (unsigned char) fgetc(fp); switch (trans.type) { case HTS_CLASS: strcpy(trans.name, "Class"); trans.index1 = readshort(fp); break; case HTS_FIELDREF: strcpy(trans.name, "Field Reference"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_METHODREF: strcpy(trans.name, "Method Reference"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_INTERFACE: strcpy(trans.name, "Interface Method Reference"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_NAMEANDTYPE: strcpy(trans.name, "Name and Type"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_STRING: // CONSTANT_String strcpy(trans.name, "String"); trans.index1 = readshort(fp); break; case HTS_INTEGER: strcpy(trans.name, "Integer"); for(j = 0; j < 4; j++) fgetc(fp); break; case HTS_FLOAT: strcpy(trans.name, "Float"); for(j = 0; j < 4; j++) fgetc(fp); break; case HTS_LONG: strcpy(trans.name, "Long"); for(j = 0; j < 8; j++) fgetc(fp); break; case HTS_DOUBLE: strcpy(trans.name, "Double"); for(j = 0; j < 8; j++) fgetc(fp); break; case HTS_ASCIZ: case HTS_UNICODE: if (trans.type == HTS_ASCIZ) strcpy(trans.name, "HTS_ASCIZ"); else strcpy(trans.name, "HTS_UNICODE"); { char BIGSTK buffer[1024]; char *p; p = &buffer[0]; //fflush(fp); trans.file_position = ftell(fp); length = readshort(fp); if (length < HTS_URLMAXSIZE) { // while ((length > 0) && (length<500)) { while(length > 0) { *p++ = fgetc(fp); length--; } *p = '\0'; //#if JDEBUG // if(tris(buffer)==1) printf("%s\n ",buffer); // if(tris(buffer)==2) printf("%s\n ",printname(buffer)); //#endif if (tris(str->opt, buffer) == 1) str->addLink(str, buffer); /* trans.file_position */ else if (tris(str->opt, buffer) == 2) str->addLink(str, printname(rname, buffer)); strcpy(trans.name, buffer); } else { // gros pb while((length > 0) && (!feof(fp))) { fgetc(fp); length--; } if (!feof(fp)) { trans.type = -1; } else { sprintf(str->err_msg, "Internal stucture error (ASCII)"); *error = 1; } return (trans); } } break; default: // printf("Type inconnue\n"); // on arrête tout sprintf(str->err_msg, "Internal structure unknown (type %d)", trans.type); *error = 1; return (trans); break; } return (trans); }
static void timepropagate( nltype *parentp) { arctype *arcp; nltype *childp; double share; double propshare; if(parentp->propfraction == 0.0){ return; } /* * Gather time from children of this parent. */ for(arcp = parentp->children; arcp; arcp = arcp->arc_childlist){ childp = arcp->arc_childp; if(arcp->arc_count == 0){ continue; } if(childp == parentp){ continue; } if(childp->propfraction == 0.0){ continue; } if(childp->cyclehead != childp){ if(parentp->cycleno == childp->cycleno){ continue; } if(parentp->toporder <= childp->toporder){ fprintf(stderr, "[propagate] toporder botches\n"); } childp = childp->cyclehead; } else{ if(parentp->toporder <= childp->toporder){ fprintf(stderr, "[propagate] toporder botches\n"); continue; } } if(childp->ncall == 0){ continue; } /* * Distribute time for this arc. */ arcp->arc_time = childp->time * ( ((double)arcp->arc_count) / ((double)childp->ncall) ); arcp->arc_childtime = childp->childtime * ( ((double)arcp->arc_count) / ((double)childp->ncall) ); share = arcp->arc_time + arcp->arc_childtime; parentp->childtime += share; /* * ( 1 - propfraction ) gets lost along the way */ propshare = parentp->propfraction * share; /* * fix things for printing */ parentp->propchild += propshare; arcp->arc_time *= parentp->propfraction; arcp->arc_childtime *= parentp->propfraction; /* * add this share to the parent's cycle header, if any. */ if(parentp->cyclehead != parentp){ parentp->cyclehead->childtime += share; parentp->cyclehead->propchild += propshare; } #ifdef DEBUG if(debug & PROPDEBUG){ printf("[dotime] child \t"); printname(childp); printf(" with %f %f %ld/%ld\n", childp->time, childp->childtime, arcp->arc_count, childp->ncall); printf("[dotime] parent\t"); printname(parentp); printf("\n[dotime] share %f\n", share); } #endif } }
static void cyclelink( void) { nltype *nlp; nltype *cyclenlp; int cycle; nltype *memberp; arctype *arcp; /* * Count the number of cycles, and initialze the cycle lists */ ncycle = 0; for(nlp = nl; nlp < npe; nlp++){ /* * This is how you find unattached cycles */ if(nlp->cyclehead == nlp && nlp->cnext != 0){ ncycle += 1; } } /* * cyclenl is indexed by cycle number: * i.e. it is origin 1, not origin 0. */ cyclenl = (nltype *)calloc(ncycle + 1, sizeof(nltype)); if(cyclenl == NULL) fatal("no room for %lu bytes of cycle headers", (ncycle + 1) * sizeof(nltype)); /* * now link cycles to true cycleheads, * number them, accumulate the data for the cycle */ cycle = 0; for(nlp = nl; nlp < npe; nlp++){ if(!(nlp->cyclehead == nlp && nlp->cnext != 0)){ continue; } cycle += 1; cyclenlp = &cyclenl[cycle]; cyclenlp->name = 0; /* the name */ cyclenlp->value = 0; /* the pc entry point */ cyclenlp->time = 0.0; /* ticks in this routine */ cyclenlp->childtime = 0.0; /* cumulative ticks in children */ cyclenlp->ncall = 0; /* how many times called */ cyclenlp->selfcalls = 0; /* how many calls to self */ cyclenlp->propfraction = 0.0;/* what % of time propagates */ cyclenlp->propself = 0.0; /* how much self time propagates */ cyclenlp->propchild = 0.0; /* how much child time propagates */ cyclenlp->printflag = TRUE; /* should this be printed? */ cyclenlp->index = 0; /* index in the graph list */ cyclenlp->toporder = DFN_NAN;/* graph call chain top-sort order */ cyclenlp->cycleno = cycle; /* internal number of cycle on */ cyclenlp->cyclehead = cyclenlp;/* pointer to head of cycle */ cyclenlp->cnext = nlp; /* pointer to next member of cycle */ cyclenlp->parents = 0; /* list of caller arcs */ cyclenlp->children = 0; /* list of callee arcs */ #ifdef DEBUG if(debug & CYCLEDEBUG){ printf("[cyclelink] "); printname(nlp); printf(" is the head of cycle %d\n", cycle); } #endif /* * link members to cycle header */ for(memberp = nlp; memberp; memberp = memberp->cnext){ memberp->cycleno = cycle; memberp->cyclehead = cyclenlp; } /* * count calls from outside the cycle * and those among cycle members */ for(memberp = nlp; memberp; memberp = memberp->cnext){ for(arcp = memberp->parents; arcp; arcp = arcp->arc_parentlist){ if(arcp->arc_parentp == memberp){ continue; } if(arcp->arc_parentp->cycleno == cycle){ cyclenlp->selfcalls += arcp->arc_count; } else{ cyclenlp->ncall += arcp->arc_count; } } } } }