char *node_desc(Vec_Expr_Node *enp) { static char desc_str[N_DESC][64]; which_desc++; which_desc %= N_DESC; sprintf(desc_str[which_desc],"%s node ",NNAME(enp)); prt_node(enp,&desc_str[which_desc][strlen(desc_str[which_desc])]); return(desc_str[which_desc]); }
static void prt_apply(value *node, void *data) { FILE *fp = (FILE *)data; prt_node(fp, node); }
static void _dump_node_basic(QSP_ARG_DECL Vec_Expr_Node *enp) { Tree_Code code; int i; const char *s; if( enp==NULL ) return; /* print the node "name", and a code that tells about shape knowledge */ // Temporarily print to stderr instead of stdout for debugging... prt_node(enp,msg_str); prt_msg_frag(msg_str); if( SHOWING_LHS_REFS ){ sprintf(msg_str,"\t%d",VN_LHS_REFS(enp)); prt_msg_frag(msg_str); } if( SHOWING_COST ){ if( VN_SHAPE(enp) != NULL ){ sprintf(msg_str,"\t%d", SHP_N_MACH_ELTS(VN_SHAPE(enp))); } prt_msg_frag(msg_str); sprintf(msg_str,"\t%d\t%d", VN_FLOPS(enp),VN_N_MATH(enp)); prt_msg_frag(msg_str); } if( IS_CURDLED(enp) ){ sprintf(msg_str,"\t%s (curdled!?)", NNAME(enp)); prt_msg(msg_str); return; } sprintf(msg_str,"\t%s", NNAME(enp)); prt_msg_frag(msg_str); /* print the special op-dependent args in human-readable form */ code = VN_CODE(enp); if( code==T_DYN_OBJ || code == T_UNDEF || code == T_PROTO || code==T_POINTER || code==T_FUNCPTR || code==T_STR_PTR ){ sprintf(msg_str,"\t%s",VN_STRING(enp)); prt_msg_frag(msg_str); if( code == T_POINTER ){ Identifier *idp; /* We don't use get_set_ptr() here because we don't want an error msg... */ idp = id_of(VN_STRING(enp)); if( idp != NULL && IS_POINTER(idp) && POINTER_IS_SET(idp) ){ if( PTR_REF(ID_PTR(idp)) == NULL ){ /* how could this ever happen??? */ prt_msg_frag("->???"); } else { Data_Obj *dp; dp = REF_OBJ(PTR_REF(ID_PTR(idp))); sprintf(msg_str,"->%s",OBJ_NAME(dp)); prt_msg_frag(msg_str); } } } } else if( code == T_STATIC_OBJ ){ sprintf(msg_str,"\t%s",OBJ_NAME(VN_OBJ(enp))); prt_msg_frag(msg_str); #ifdef SCALARS_NOT_OBJECTS } else if( code == T_SCALAR_VAR ){ sprintf(msg_str,"\t%s",VN_STRING(enp)); prt_msg_frag(msg_str); #endif // SCALARS_NOT_OBJECTS } else if ( code == T_FUNCREF ){ Subrt *srp; srp=VN_SUBRT(enp); sprintf(msg_str,"\t%s",SR_NAME(srp)); prt_msg_frag(msg_str); } else if( code == T_SIZE_FN ){ sprintf(msg_str,"\t%s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } #ifdef NOT_YET else if(code == T_CALL_NATIVE ){ // was kw_token??? // curr_native_func_tbl... sprintf(msg_str,"\t%s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } #endif /* NOT_YET */ else if(code == T_TYPECAST ){ // BUG not how we do precision any more!!! //sprintf(msg_str," %s",NAME_FOR_PREC_CODE(VN_INTVAL(enp))); if( VN_SHAPE(enp) == NULL ) error1("CAUTIOUS: null node shape for typecast node!?"); else { sprintf(msg_str," %s",PREC_NAME(VN_PREC_PTR(enp))); prt_msg_frag(msg_str); } } else if( code == T_SUBRT_DECL || code == T_SCRIPT ){ Subrt *srp; srp=VN_SUBRT(enp); sprintf(msg_str,"\t%s",SR_NAME(srp)); prt_msg_frag(msg_str); } else if( code==T_DECL_STAT ){ //sprintf(msg_str," %s",NAME_FOR_PREC_CODE(VN_INTVAL(enp))); sprintf(msg_str," %s",PREC_NAME(VN_DECL_PREC(enp))); prt_msg_frag(msg_str); } else if( IS_DECL(code) ){ sprintf(msg_str," %s",VN_STRING(enp)); prt_msg_frag(msg_str); } else if( code==T_ADVISE ){ /* BUG need to elim yylex_qsp */ s=eval_string(VN_CHILD(enp,0)); sprintf(msg_str,"\t\"%s\"",s); prt_msg_frag(msg_str); } else if( code==T_WARN ){ /* BUG need to elim yylex_qsp */ s=eval_string(VN_CHILD(enp,0)); sprintf(msg_str,"\t\"%s\"",s); prt_msg_frag(msg_str); } else if( code==T_STRING ){ sprintf(msg_str,"\t\"%s\"",VN_STRING(enp)); prt_msg_frag(msg_str); } else if( code == T_LABEL || code ==T_GO_BACK || code == T_GO_FWD ){ sprintf(msg_str," %s",VN_STRING(enp)); prt_msg_frag(msg_str); } else if( code==T_LIT_DBL ){ sprintf(msg_str," %g",VN_DBLVAL(enp)); prt_msg_frag(msg_str); } else if( code == T_MATH0_FN ){ sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } else if( code == T_MATH1_FN ){ sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } else if( code == T_MATH2_FN ){ sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } else if ( code == T_MATH0_VFN || code == T_MATH1_VFN || code == T_MATH2_VFN || code == T_MATH2_VSFN || code == T_CHAR_VFN /* BUG? shouldn't there bre a VSFN2 ??? */ || code == T_VS_FUNC || code == T_VV_FUNC ){ sprintf(msg_str," %s",VF_NAME(FIND_VEC_FUNC(VN_VFUNC_CODE(enp)))); prt_msg_frag(msg_str); } else if( code==T_CALLFUNC ){ assert(VN_SUBRT(enp)!=NULL); sprintf(msg_str," %s", SR_NAME(VN_SUBRT(enp))); prt_msg_frag(msg_str); } else if( code==T_LIT_INT ){ sprintf(msg_str," %"PRId64, VN_INTVAL(enp) ); prt_msg_frag(msg_str); } else if( code==T_ASSIGN ){ prt_msg_frag("\t"); } else if( code==T_MAXVAL ){ prt_msg_frag("\t"); } else if( code==T_MINVAL ){ prt_msg_frag("\t"); } else if( code==T_RAMP ){ prt_msg_frag("\t"); } /* Now print the addresses of the child nodes */ if( VN_CHILD(enp,0)!=NULL){ sprintf(msg_str,"\t\tn%d",VN_SERIAL(VN_CHILD(enp,0))); prt_msg_frag(msg_str); } for(i=1;i<MAX_CHILDREN(enp);i++){ if( VN_CHILD(enp,i)!=NULL){ sprintf(msg_str,", n%d",VN_SERIAL(VN_CHILD(enp,i))); prt_msg_frag(msg_str); } } prt_msg(""); if( SHOWING_SHAPES && VN_SHAPE(enp) != NULL ){ prt_msg_frag("\t"); if( OWNS_SHAPE(enp) ){ sprintf(msg_str,"* 0x%lx ",(u_long)VN_SHAPE(enp)); prt_msg_frag(msg_str); } else { sprintf(msg_str,"@ 0x%lx ",(u_long)VN_SHAPE(enp)); prt_msg_frag(msg_str); } prt_msg_frag("\t"); describe_shape(VN_SHAPE(enp)); } if( SHOWING_RESOLVERS && VN_RESOLVERS(enp)!=NULL ){ Node *np; Vec_Expr_Node *enp2; prt_msg("\tResolvers:"); np=QLIST_HEAD(VN_RESOLVERS(enp)); while(np!=NULL){ enp2=(Vec_Expr_Node *)NODE_DATA(np); sprintf(msg_str,"\t\t%s",node_desc(enp2)); prt_msg(msg_str); np=NODE_NEXT(np); } } }
void process_chunk(void) { yaffs_ObjectHeader oh; yaffs_PackedTags2 *pt; object *obj, *eq_obj; int out_file, remain, s; oh = *(yaffs_ObjectHeader *)chunk_data; pt = (yaffs_PackedTags2 *)spare_data; if (pt->t.byteCount == 0xffffffff) /* empty object */ return; else if (pt->t.byteCount != 0xffff) { /* not a new object */ prt_err(0, 0, "Warning: Invalid header at chunk #%d, skipping...", chunk_no); if (++warn_count >= MAX_WARN) prt_err(1, 0, "Giving up"); return; } obj = add_object(&oh, pt); /* listing */ if (opt_verbose) prt_node(obj->path_name, &oh); else if (opt_list) printf("%s\n", obj->path_name); if (opt_list) { if (oh.type == YAFFS_OBJECT_TYPE_FILE) { remain = oh.fileSize; /* skip over data chunks */ while(remain > 0) { if (!read_chunk()) prt_err(1, 0, "Broken image file"); remain -= pt->t.byteCount; } } return; } switch(oh.type) { case YAFFS_OBJECT_TYPE_FILE: remain = oh.fileSize; out_file = creat(obj->path_name, oh.yst_mode & STD_PERMS); if (out_file < 0) prt_err(1, errno, "Can't create file %s", obj->path_name); while(remain > 0) { if (!read_chunk()) prt_err(1, 0, "Broken image file"); s = (remain < pt->t.byteCount) ? remain : pt->t.byteCount; if (xwrite(out_file, chunk_data, s) < 0) prt_err(1, errno, "Can't write to %s", obj->path_name); remain -= s; } close(out_file); lchown(obj->path_name, oh.yst_uid, oh.yst_gid); if ((oh.yst_mode & EXTRA_PERMS) != 0 && chmod(obj->path_name, oh.yst_mode) < 0) prt_err(0, errno, "Warning: Can't chmod %s", obj->path_name); break; case YAFFS_OBJECT_TYPE_SYMLINK: if (symlink(oh.alias, obj->path_name) < 0) prt_err(1, errno, "Can't create symlink %s", obj->path_name); lchown(obj->path_name, oh.yst_uid, oh.yst_gid); break; case YAFFS_OBJECT_TYPE_DIRECTORY: if (pt->t.objectId != YAFFS_OBJECTID_ROOT && mkdir(obj->path_name, oh.yst_mode & STD_PERMS) < 0) prt_err(1, errno, "Can't create directory %s", obj->path_name); lchown(obj->path_name, oh.yst_uid, oh.yst_gid); if ((pt->t.objectId == YAFFS_OBJECTID_ROOT || (oh.yst_mode & EXTRA_PERMS) != 0) && chmod(obj->path_name, oh.yst_mode) < 0) prt_err(0, errno, "Warning: Can't chmod %s", obj->path_name); break; case YAFFS_OBJECT_TYPE_HARDLINK: eq_obj = get_object(oh.equivalentObjectId); if (eq_obj == NULL) prt_err(1, 0, "Invalid equivalentObjectId %u in object %u (%s)", oh.equivalentObjectId, pt->t.objectId, oh.name); if (link(eq_obj->path_name, obj->path_name) < 0) prt_err(1, errno, "Can't create hardlink %s", obj->path_name); break; case YAFFS_OBJECT_TYPE_SPECIAL: if (mknod(obj->path_name, oh.yst_mode, oh.yst_rdev) < 0) { if (errno == EPERM || errno == EINVAL) prt_err(0, errno, "Warning: Can't create device %s", obj->path_name); else prt_err(1, errno, "Can't create device %s", obj->path_name); } lchown(obj->path_name, oh.yst_uid, oh.yst_gid); break; case YAFFS_OBJECT_TYPE_UNKNOWN: break; } /* set file date and time */ switch(oh.type) { case YAFFS_OBJECT_TYPE_FILE: case YAFFS_OBJECT_TYPE_SPECIAL: #ifdef HAS_LUTIMES case YAFFS_OBJECT_TYPE_SYMLINK: #endif set_utime(obj->path_name, oh.yst_atime, oh.yst_mtime); break; case YAFFS_OBJECT_TYPE_DIRECTORY: default: break; } }