📄 acornzip.c
字号:
} if (exts2swap!=NULL && lastdir!=NULL) { if (lastlastdir==NULL) lastlastdir=t; if (checkext(lastlastdir)) { if (swapext(lastlastdir,lastdir-1)) { free((void *)tmp); return NULL; } } } if (!pathput) t = last(t, PATH_END); /* Malloc space for internal name and copy it */ if ((n = malloc(strlen(t) + 1)) == NULL) { free((void *)tmp); return NULL; } strcpy(n, t); free((void *)tmp); if (dosify) msname(n); /* Returned malloc'ed name */ if (pdosflag) *pdosflag = dosflag; return n;}char *in2ex(n)char *n; /* internal file name *//* Convert the zip file name to an external file name, returning the malloc'ed string or NULL if not enough memory. */{ char *x; /* external file name */ char *t; /* scans name */ char *lastext=NULL; /* pointer to last extension */ char *lastdir=NULL; /* pointer to last dir */ if ((x = malloc(strlen(n) + 1 + PAD)) == NULL) return NULL; strcpy(x, n); for(t=x;*t;t++) { if (*t=='.') { *t='/'; lastext=t+1; } else if (*t=='/') { *t='.'; lastdir=t+1; } } if (exts2swap!=NULL && (int)lastext>(int)lastdir) { if (lastdir==NULL) lastdir=x; if (checkext(lastext)) { if (swapext(lastdir,lastext-1)) { free((void *)x); return NULL; } } } return x;}local 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 */}void stamp(f, d)char *f; /* name of file to change */ulg d; /* dos-style time to change it to *//* Set last updated and accessed time of file f to the DOS time d. */{ time_t m_time; unsigned int loadaddr, execaddr; int attr; /* Convert DOS time to time_t format in m_time */ m_time = dos2unixtime(d); /* set the file's modification time */ SWI_OS_File_5(f,NULL,&loadaddr,NULL,NULL,&attr); if (uxtime2acornftime(&execaddr, &loadaddr, m_time) != 0) return; SWI_OS_File_1(f,loadaddr,execaddr,attr);}ulg filetime(f, a, n, t)char *f; /* name of file to get info on */ulg *a; /* return value: file attributes */long *n; /* return value: file size */iztimes *t; /* return value: access, modific. and creation times *//* If file *f does not exist, return 0. Else, return the file's last modified date and time as an MSDOS date and time. The date and time is returned in a long with the date most significant to allow unsigned integer comparison of absolute times. Also, if a is not a NULL pointer, store the file attributes there, with the high two bytes being the Unix attributes, and the low byte being a mapping of that to DOS attributes. If n is not NULL, store the file size there. If t is not NULL, the file's access, modification and creation times are stored there as UNIX time_t values. If f is "-", use standard input as the file. If f is a device, return a file size of -1 */{ struct stat s; /* results of stat() */ char *name; unsigned int len = strlen(f); if (f == label) { if (a != NULL) *a = label_mode; if (n != NULL) *n = -2L; /* convention for a label name */ if (t != NULL) t->atime = t->mtime = t->ctime = label_utim; return label_time; } if ((name = malloc(len + 1)) == NULL) { ZIPERR(ZE_MEM, "filetime"); } strcpy(name, f); if (name[len - 1] == '.') name[len - 1] = '\0'; /* not all systems allow stat'ing a file with / appended */ if (strcmp(f, "-") == 0) { /* forge stat values for stdin since Amiga and RISCOS have no fstat() */ s.st_mode = (S_IREAD|S_IWRITE|S_IFREG); s.st_size = -1; s.st_mtime = time(&s.st_mtime); } else if (LSSTAT(name, &s) != 0) { /* Accept about any file kind including directories * (stored with trailing / with -r option) */ free(name); return 0; } if (a != NULL) { *a = ((ulg)s.st_mode << 16) | !(s.st_mode & S_IWRITE); if ((s.st_mode & S_IFDIR) != 0) { *a |= MSDOS_DIR_ATTR; } } if (n != NULL) *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L; if (t != NULL) { t->atime = s.st_atime; t->mtime = s.st_mtime; t->ctime = s.st_ctime; } free(name); return unix2dostime((time_t *) &s.st_mtime);}int set_extra_field(z, z_utim) struct zlist far *z; iztimes *z_utim;{#ifdef USE_EF_UT_TIME char *eb_ptr;#endif /* USE_EF_UT_TIME */ char *name; extra_block *block;#define EB_SPARK_LEN 20#define EB_SPARK_SIZE (EB_HEADSIZE+EB_SPARK_LEN)#ifdef USE_EF_UT_TIME# ifdef IZ_CHECK_TZ# define EB_UTTIME_SIZE (zp_tz_is_valid ? EB_HEADSIZE+EB_UT_LEN(1) : 0)# else# define EB_UTTIME_SIZE (EB_HEADSIZE+EB_UT_LEN(1))# endif#else# define EB_UTTIME_SIZE 0#endif#define EF_SPARK_TOTALSIZE (EB_SPARK_SIZE + EB_UTTIME_SIZE) if ((name=(char *)malloc(strlen(z->name)+1))==NULL) { fprintf(stderr," set_extra_field: not enough memory for directory name\n"); return ZE_MEM; } strcpy(name,z->name); if (name[strlen(name)-1]=='.') { /* remove the last '.' in directory names */ name[strlen(name)-1]=0; } z->extra=(char *)malloc(EF_SPARK_TOTALSIZE); if (z->extra==NULL) { fprintf(stderr," set_extra_field: not enough memory\n"); free(name); return ZE_MEM; } z->cextra = z->extra; z->cext = z->ext = EF_SPARK_TOTALSIZE; block=(extra_block *)z->extra; block->ID=SPARKID; block->size=EB_SPARK_LEN; block->ID_2=SPARKID_2; block->zero=0; if (SWI_OS_File_5(name,NULL,&block->loadaddr,&block->execaddr, NULL,&block->attr) != NULL) { fprintf(stderr," OS error while set_extra_field of %s\n",name); } free(name);#ifdef USE_EF_UT_TIME# ifdef IZ_CHECK_TZ if (zp_tz_is_valid) {# endif eb_ptr = z->extra + EB_SPARK_SIZE; eb_ptr[0] = 'U'; eb_ptr[1] = 'T'; eb_ptr[2] = EB_UT_LEN(1); /* length of data part of e.f. */ eb_ptr[3] = 0; eb_ptr[4] = EB_UT_FL_MTIME; eb_ptr[5] = (char)(z_utim->mtime); eb_ptr[6] = (char)(z_utim->mtime >> 8); eb_ptr[7] = (char)(z_utim->mtime >> 16); eb_ptr[8] = (char)(z_utim->mtime >> 24);# ifdef IZ_CHECK_TZ }# endif#endif /* USE_EF_UT_TIME */ return ZE_OK;}#endif /* !UTIL *//******************************//* Function version_local() *//******************************/void version_local(){ static ZCONST char CompiledWith[] = "Compiled with %s%s for %s%s%s%s.\n\n"; printf(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 );} /* end function version_local() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -