void displayVersion(char *firmwareVersion) { /* display the version - pass to copyAndReplace to make a dot-separated string */ char outputVersion[ICS_IMAGE_HEADER_VERSION_SIZE]; copyAndReplace(firmwareVersion, outputVersion, USCORE, DOT); printf("%s\n", outputVersion); }
ConcreteNodePtr copyAndReplace( ConcreteNodePtr node, const ReplacementMap& rm ) { ReplacementMap::const_iterator fi = rm.find(node); if (fi != rm.end()) { return fi->second; } if (REN_DYNAMIC_CAST(p, ApplicationNode*, node.get())) { ConcreteNodePtr function = copyAndReplace(p->getFunction(), rm); ConcreteNodeList arguments = p->getArguments(); for (size_t i = 0; i < arguments.size(); ++i) { arguments[i] = copyAndReplace(arguments[i], rm); } return ConcreteNodePtr(new ApplicationNode(function, arguments)); } else if (REN_DYNAMIC_CAST(p, AbstractionNode*, node.get())) {
if (REN_DYNAMIC_CAST(p, ApplicationNode*, node.get())) { ConcreteNodePtr function = copyAndReplace(p->getFunction(), rm); ConcreteNodeList arguments = p->getArguments(); for (size_t i = 0; i < arguments.size(); ++i) { arguments[i] = copyAndReplace(arguments[i], rm); } return ConcreteNodePtr(new ApplicationNode(function, arguments)); } else if (REN_DYNAMIC_CAST(p, AbstractionNode*, node.get())) { return ConcreteNodePtr( new AbstractionNode( p->getReplacements(), copyAndReplace(p->getInside(), rm))); } else if (REN_DYNAMIC_CAST(p, ArgumentNode*, node.get())) { (void)p; return node; } else if (REN_DYNAMIC_CAST(p, FunctionNode*, node.get())) { (void)p; return node; } else if (REN_DYNAMIC_CAST(p, ValueNode*, node.get())) { (void)p; return node; } else { assert(!"ICE: Unknown Concrete Node Type"); return node; } }
int doFuncInp(char *fromName, char *toName, char *baseSrcName, char *baseToName, int allowAppend, char *archiveExtension) { FILE *fp; char *fileBuf; char *toBuf; int ch; char *chP; struct stat st; int count=0; FileType type; int toLen; int toNameLen = strlen(toName); int archExtLen = strlen(archiveExtension); //printf("%s %s %s %s\n",fromName,toName,baseSrcName,baseToName); stat(fromName,&st); if (st.st_mode & S_IFDIR) { if (!fileExists(toName)) { if (mkdir(toName,st.st_mode)) { fprintf(stderr,"Error: Failed making directory %s\n",toName); exit(1); } } else if (!isDirectory(toName)) { fprintf(stderr,"Error: %s is not a directory, but should be\n",toName); exit(1); } } else { if (fileExists(toName)) { fprintf(stderr,"Error: File %s already exists and I'm not going to overwrite it!",toName); exit(1); } if ((fileBuf = calloc(st.st_size+1,sizeof(char))) == NULL) { fprintf(stderr,"Error: Failed allocating space for file buffer of size %ld\n", st.st_size+1); exit(1); } /* Hack */ if ((toBuf = calloc(st.st_size+1000000,sizeof(char))) == NULL) { fprintf(stderr,"Error: Failed allocating space for file buffer\n"); exit(1); } if ((fp = fopen(fromName,"r")) == NULL) { fprintf(stderr,"Error: Failed opening from perl file %s\n",fromName); exit(1); } fread(fileBuf,st.st_size,1,fp); /* chP = fileBuf; while ((ch = getc(fp)) != EOF) { count++; *chP = ch; chP++; } */ fclose(fp); if ((fp = fopen(toName,"w")) == NULL) { fprintf(stderr,"Error: Failed opening to perl file %s\n",toName); exit(1); } type = fileType(fileBuf,st.st_size); //printf("Type = %d (%s)\n",type,typeStrings[type]); copyAndReplace(fileBuf,toBuf,baseSrcName,baseToName,toName,st.st_size,&toLen,type); fwrite(toBuf,toLen,1,fp); fclose(fp); chmod(toName,st.st_mode); if (archExtLen && toNameLen > archExtLen) { //printf("toNameLen = %d archExtLen = %d toName bit = %s\n", // toNameLen,archExtLen,&(toName[toNameLen-archExtLen])); if (!strcmp(&(toName[toNameLen-archExtLen]),archiveExtension)) { char comStr[MAXPATHLEN + 1024]; sprintf(comStr,"ranlib %s",toName); printf("%s\n",comStr); system(comStr); } } free(fileBuf); free(toBuf); } return 1; }