📄 flexos.c
字号:
if (FUNCTION == APPEND_NAME) { Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp))); while ((*end = *pathcomp++) != '\0') { ++end; if ((end-buildpath) >= FILNAMSIZ) { *--end = '\0'; Info(slide, 1, ((char *)slide, LoadFarString(PathTooLongTrunc), FnFilter1(G.filename), FnFilter2(buildpath))); return MPN_INF_TRUNC; /* filename truncated */ } } Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath))); /* could check for existence here, prompt for new name... */ return MPN_OK; }/*--------------------------------------------------------------------------- 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. ---------------------------------------------------------------------------*/ if (FUNCTION == INIT) { Trace((stderr, "initializing buildpath to ")); /* allocate space for full filename, root path, and maybe "./" */ if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+3)) == (char *)NULL) return MPN_NOMEM; if (renamed_fullpath) { /* pathcomp = valid data */ end = buildpath; while ((*end = *pathcomp++) != '\0') ++end; } else if (rootlen > 0) { 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 neces- sary; 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. Note that under FlexOS, if a candidate extract-to directory specification includes a drive letter (leading "x:"), it is treated just as if it had a trailing '/'--that is, one directory level will be created if the path doesn't exist, unless this is otherwise pro- hibited (e.g., freshening). ---------------------------------------------------------------------------*/#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) { int had_trailing_pathsep=FALSE, add_dot=FALSE; char *tmproot; if ((tmproot = (char *)malloc(rootlen+3)) == (char *)NULL) { rootlen = 0; return MPN_NOMEM; } strcpy(tmproot, pathcomp); if (tmproot[rootlen-1] == '/' || tmproot[rootlen-1] == '\\') { tmproot[--rootlen] = '\0'; had_trailing_pathsep = TRUE; } if (tmproot[rootlen-1] == ':') { if (!had_trailing_pathsep) /* i.e., original wasn't "xxx:/" */ add_dot = TRUE; /* relative path: add '.' before '/' */ } else if (rootlen > 0) && /* need not check "xxx:." and "xxx:/" */ (SSTAT(tmproot, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode)) { /* path does not exist */ if (!G.create_dirs /* || iswild(tmproot) */ ) { free(tmproot); rootlen = 0; /* treat as stored file */ return MPN_INF_SKIP; }/* GRR: scan for wildcard characters? OS-dependent... * if find any, return MPN_INF_SKIP: treat as stored file(s) */ /* create directory (could add loop here scanning tmproot * to create more than one level, but really necessary?) */ if (mkdir(tmproot, 0777) == -1) { Info(slide, 1, ((char *)slide, LoadFarString(CantCreateExtractDir), 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; } } if (add_dot) /* had just "x:", make "x:." */ tmproot[rootlen++] = '.'; tmproot[rootlen++] = '/'; 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 close_outfile() *//****************************/void close_outfile(__G) __GDEF /* * FlexOS VERSION * * Set the output file date/time stamp according to information from the * zipfile directory record for this member, then close the file and set * its permissions (archive, hidden, read-only, system). Aside from closing * the file, this routine is optional (but most compilers support it). */{ DISKFILE df; LONG fnum; struct { /* date and time words */ union { /* DOS file modification time word */ ush ztime; struct { unsigned zt_se : 5; unsigned zt_mi : 6; unsigned zt_hr : 5; } _tf; } _t; union { /* DOS file modification date word */ ush zdate; struct { unsigned zd_dy : 5; unsigned zd_mo : 4; unsigned zd_yr : 7; } _df; } _d; } zt;#ifdef USE_EF_UT_TIME iztimes z_utime; struct tm *t;#endif /* ?USE_EF_UT_TIME */ fclose(G.outfile); if ((fnum = s_open(A_SET, G.filename)) < 0) { Info(slide, 0x201, ((char *)slide, "warning: cannot open %s to set the time\n", FnFilter1(G.filename))); return; } if (s_get(T_FILE, fnum, &df, DSKFSIZE) < 0) { s_close(0, fnum); Info(slide, 0x201, ((char *)slide, "warning: cannot get info on %s\n", FnFilter1(G.filename))); return; }/*--------------------------------------------------------------------------- Copy and/or convert time and date variables, if necessary; then fill in the file time/date. ---------------------------------------------------------------------------*/#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)); t = localtime(&(z_utime.mtime)); } else t = (struct tm *)NULL; if (t != (struct tm *)NULL) { if (t->tm_year < 80) { df.df_modyear = 1980; df.df_modmonth = 1; df.df_modday = 1; df.df_modhr = 0; df.df_modmin = 0; df.df_modsec = 0; } else { df.df_modyear = t->tm_year + 1900; df.df_modmonth = t->tm_mon + 1; df.df_modday = t->tm_mday; df.df_modhr = t->tm_hour; df.df_modmin = t->tm_min; df.df_modsec = t->tm_sec; } } else#endif /* ?USE_EF_UX_TIME */ { zt._t.ztime = (ush)(G.lrec.last_mod_dos_datetime) & 0xffff; zt._d.zdate = (ush)(G.lrec.last_mod_dos_datetime >> 16); df.df_modyear = 1980 + zt._d._df.zd_yr; df.df_modmonth = zt._d._df.zd_mo; df.df_modday = zt._d._df.zd_dy; df.df_modhr = zt._t._tf.zt_hr; df.df_modmin = zt._t._tf.zt_mi; df.df_modsec = zt._t._tf.zt_se << 1; }/*--------------------------------------------------------------------------- Fill in the file attributes. ---------------------------------------------------------------------------*/ df.df_attr1 = (UBYTE)G.pInfo->file_attr;/*--------------------------------------------------------------------------- Now we try to set the attributes & date/time. ---------------------------------------------------------------------------*/ if (s_set(T_FILE, fnum, &df, DSKFSIZE) < 0) Info(slide, 0x201, ((char *)slide, "warning: cannot set info for %s\n", FnFilter1(G.filename))); s_close(0, fnum);}#ifndef SFX/*************************//* Function dateformat() *//*************************/int dateformat(){ return DF_DMY; /* default for systems without locale info */}/************************//* Function version() *//************************/void version(__G) __GDEF{ int len; len = sprintf((char *)slide, LoadFarString(CompiledWith), "MetaWare High C", "", "FlexOS", " (16-bit, big)",#ifdef __DATE__ " on ", __DATE__#else "", ""#endif ); (*G.message)((zvoid *)&G, slide, (ulg)len, 0);}#endif /* !SFX *//************************//* Function _wildarg() *//************************//* This prevents the PORTLIB startup code from preforming argument globbing */_wildarg() {}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -