⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acorn.c

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 C
📖 第 1 页 / 共 3 页
字号:
/*---------------------------------------------------------------------------    INIT:  allocate and initialize buffer space for the file currently being    extracted.  If file was renamed with an absolute path, don't prepend the    extract-to path.  ---------------------------------------------------------------------------*//* GRR:  for VMS and TOPS-20, add up to 13 to strlen */    if (FUNCTION == INIT) {        Trace((stderr, "initializing buildpath to "));        if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1))            == (char *)NULL)            return MPN_NOMEM;        if ((rootlen > 0) && !renamed_fullpath) {            strcpy(buildpath, rootpath);            end = buildpath + rootlen;        } else {            *buildpath = '\0';            end = buildpath;        }        Trace((stderr, "[%s]\n", FnFilter1(buildpath)));        return MPN_OK;    }/*---------------------------------------------------------------------------    ROOT:  if appropriate, store the path in rootpath and create it if    necessary; else assume it's a zipfile member and return.  This path    segment gets used in extracting all members from every zipfile specified    on the command line.  ---------------------------------------------------------------------------*/#if (!defined(SFX) || defined(SFX_EXDIR))    if (FUNCTION == ROOT) {        Trace((stderr, "initializing root path to [%s]\n",          FnFilter1(pathcomp)));        if (pathcomp == (char *)NULL) {            rootlen = 0;            return MPN_OK;        }        if (rootlen > 0)        /* rootpath was already set, nothing to do */            return MPN_OK;        if ((rootlen = strlen(pathcomp)) > 0) {            char *tmproot;            if ((tmproot = (char *)malloc(rootlen+2)) == (char *)NULL) {                rootlen = 0;                return MPN_NOMEM;            }            strcpy(tmproot, pathcomp);            if (tmproot[rootlen-1] == '.') {    /****** was '/' ********/                tmproot[--rootlen] = '\0';            }            if (rootlen > 0 && (SSTAT(tmproot, &G.statbuf) ||                                !S_ISDIR(G.statbuf.st_mode)))            {   /* path does not exist */                if (!G.create_dirs /* || isshexp(tmproot) */ ) {                    free(tmproot);                    rootlen = 0;                    /* skip (or treat as stored file) */                    return MPN_INF_SKIP;                }                /* create the directory (could add loop here scanning tmproot                 * to create more than one level, but why really necessary?) */                if (mkdir(tmproot, 0777) == -1) {                    Info(slide, 1, ((char *)slide,                      "checkdir:  cannot create extraction directory: %s\n",                      FnFilter1(tmproot)));                    free(tmproot);                    rootlen = 0;                    /* path didn't exist, tried to create, and failed: */                    /* file exists, or 2+ subdir levels required */                    return MPN_ERR_SKIP;                }            }            tmproot[rootlen++] = '.';   /*********** was '/' *************/            tmproot[rootlen] = '\0';            if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) {                free(tmproot);                rootlen = 0;                return MPN_NOMEM;            }            Trace((stderr, "rootpath now = [%s]\n", FnFilter1(rootpath)));        }        return MPN_OK;    }#endif /* !SFX || SFX_EXDIR *//*---------------------------------------------------------------------------    END:  free rootpath, immediately prior to program exit.  ---------------------------------------------------------------------------*/    if (FUNCTION == END) {        Trace((stderr, "freeing rootpath\n"));        if (rootlen > 0) {            free(rootpath);            rootlen = 0;        }        return MPN_OK;    }    return MPN_INVALID; /* should never reach */} /* end function checkdir() *//********************//* Function mkdir() *//********************/int mkdir(path, mode)    const char *path;    int mode;   /* ignored *//* * returns:   0 - successful *           -1 - failed (errno not set, however) */{    return (SWI_OS_File_8((char *)path) == NULL)? 0 : -1;}/*********************************//* extra_field-related functions *//*********************************/static void setRISCOSexfield(ZCONST char *path, ZCONST void *ef_spark){  if (ef_spark!=NULL) {    extra_block *block=(extra_block *)ef_spark;    SWI_OS_File_1((char *)path,block->loadaddr,block->execaddr,block->attr);  }}#ifdef DEBUGstatic void printRISCOSexfield(int isdir, ZCONST void *extra_field){ extra_block *block=(extra_block *)extra_field; printf("\n  This file has RISC OS file informations in the local extra field.\n"); if (isdir) {/*   I prefer not to print this string... should change later... *//*   printf("  The file is a directory.\n");*/ } else if ((block->loadaddr & 0xFFF00000) != 0xFFF00000) {   printf("  Load address: %.8X\n",block->loadaddr);   printf("  Exec address: %.8X\n",block->execaddr); } else {   /************* should change this to use OS_FSControl 18 to get filetype string ************/   char tmpstr[16];   char ftypestr[32];   int flen;   sprintf(tmpstr,"File$Type_%03x",(block->loadaddr & 0x000FFF00) >> 8);   if (SWI_OS_ReadVarVal(tmpstr,ftypestr,32,&flen)==NULL) {     ftypestr[flen]=0;     printf("  Filetype: %s (&%.3X)\n",ftypestr,(block->loadaddr & 0x000FFF00) >> 8);   } else {     printf("  Filetype: &%.3X\n",(block->loadaddr & 0x000FFF00) >> 8);   } } printf("  Access: "); if (block->attr & (1<<3))   printf("L"); if (block->attr & (1<<0))   printf("W"); if (block->attr & (1<<1))   printf("R"); printf("/"); if (block->attr & (1<<4))   printf("w"); if (block->attr & (1<<5))   printf("r"); printf("\n\n");}#endif /* DEBUG *//**********************************************//* internal help function for time conversion *//**********************************************/static int uxtime2acornftime(unsigned *pexadr, unsigned *pldadr, time_t ut){   unsigned timlo;      /* 3 lower bytes of acorn file-time plus carry byte */   unsigned timhi;      /* 2 high bytes of acorn file-time */   timlo = ((unsigned)ut & 0x00ffffffU) * 100 + 0x00996a00U;   timhi = ((unsigned)ut >> 24);   timhi = timhi * 100 + 0x0000336eU + (timlo >> 24);   if (timhi & 0xffff0000U)       return 1;        /* calculation overflow, do not change time */   /* insert the five time bytes into loadaddr and execaddr variables */   *pexadr = (timlo & 0x00ffffffU) | ((timhi & 0x000000ffU) << 24);   *pldadr = (*pldadr & 0xffffff00U) | ((timhi >> 8) & 0x000000ffU);   return 0;            /* subject to future extension to signal overflow */}/****************************//* Function close_outfile() *//****************************/void close_outfile(__G)    __GDEF{  zvoid *spark_ef;  fclose(G.outfile);  if ((spark_ef = getRISCOSexfield(G.extra_field, G.lrec.extra_field_length))      != NULL) {    setRISCOSexfield(G.filename, spark_ef);  } else {    unsigned int loadaddr, execaddr;    int attr;    int mode=G.pInfo->file_attr&0xffff;   /* chmod equivalent mode */    time_t m_time;#ifdef USE_EF_UT_TIME    iztimes z_utime;#endif#ifdef USE_EF_UT_TIME    if (G.extra_field &&#ifdef IZ_CHECK_TZ        G.tz_is_valid &&#endif        (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,                          G.lrec.last_mod_dos_datetime, &z_utime, NULL)         & EB_UT_FL_MTIME))    {        TTrace((stderr, "close_outfile:  Unix e.f. modif. time = %ld\n",          z_utime.mtime));        m_time = z_utime.mtime;    } else#endif /* USE_EF_UT_TIME */        m_time = dos_to_unix_time(G.lrec.last_mod_dos_datetime);    /* set the file's modification time */    SWI_OS_File_5(G.filename, NULL, &loadaddr, NULL, NULL, &attr);    uxtime2acornftime(&execaddr, &loadaddr, m_time);    loadaddr = (loadaddr & 0xfff000ffU) |               ((G.pInfo->file_attr&0xfff00000) >> 12);    attr=(attr&0xffffff00) | ((mode&0400) >> 8) | ((mode&0200) >> 6) |                             ((mode&0004) << 2) | ((mode&0002) << 4);    SWI_OS_File_1(G.filename, loadaddr, execaddr, attr);  }} /* end function close_outfile() */#ifdef TIMESTAMP/***************************//*  Function stamp_file()  *//***************************/int stamp_file(fname, modtime)    ZCONST char *fname;    time_t modtime;{    unsigned int loadaddr, execaddr;    int attr;    /* set the file's modification time */    if (SWI_OS_File_5((char *)fname, NULL, &loadaddr, NULL, NULL, &attr)        != NULL)        return -1;    if (uxtime2acornftime(&execaddr, &loadaddr, modtime) != 0)        return -1;    return (SWI_OS_File_1((char *)fname, loadaddr, execaddr, attr) == NULL) ?           0 : -1;} /* end function stamp_file() */#endif /* TIMESTAMP */#ifndef SFX/************************//*  Function version()  *//************************/void version(__G)    __GDEF{    sprintf((char *)slide, LoadFarString(CompiledWith),#ifdef __GNUC__      "gcc ", __VERSION__,#else#  ifdef __CC_NORCROFT      "Norcroft ", "cc",#  else      "cc", "",#  endif#endif      "RISC OS",      " (Acorn Computers Ltd)",#ifdef __DATE__      " on ", __DATE__#else      "", ""#endif      );    (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);} /* end function version() */#endif /* !SFX */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -