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

📄 msdos.c

📁 给出了 zip 压缩算法的完整实现过程。
💻 C
📖 第 1 页 / 共 3 页
字号:
    }    ziperr(ZE_MEM, "zcfree: ptr not found");}#endif /* __TURBOC__ */#if defined(MSC) || defined(__WATCOMC__)#if (!defined(_MSC_VER) || (_MSC_VER < 700))#  define _halloc  halloc#  define _hfree   hfree#endifzvoid far *zcalloc (unsigned items, unsigned size){    return (zvoid far *)_halloc((long)items, size);}zvoid zcfree (zvoid far *ptr){    _hfree((void huge *)ptr);}#endif /* MSC || __WATCOMC__ */#endif /* MY_ZCALLOC */#if (defined(__WATCOMC__) && defined(ASMV) && !defined(__386__))/* This is a hack to connect "call _exit" in match.asm to exit() */#pragma aux xit "_exit" parm caller []void xit(void){    exit(20);}#endif#endif /* !UTIL */local int is_running_on_windows(void){    char * var = getenv("OS");    /* if the OS env.var says 'Windows_NT' then */    /* we're likely running on a variant of WinNT */    if ((NULL != var) && (0 == strcmp("Windows_NT", var)))    {        return 1;    }    /* if the windir env.var is non-null then */    /* we're likely running on a variant of Win9x */    /* DOS mode of Win9x doesn't define windir, only winbootdir */    /* NT's command.com can't see lowercase env. vars */    var = getenv("windir");    if ((NULL != var) && (0 != var[0]))    {        return 1;    }    return 0;}void check_for_windows(const char *app){    /* Print a warning for users running under Windows */    /* to reduce bug reports due to running DOS version */    /* under Windows, when Windows version usually works correctly */    if (is_running_on_windows())    {        printf("\nzip warning:  You are running MSDOS %s on Windows.\n"               "Try the Windows version before reporting any problems.\n",               app);    }}#ifndef WINDLL/******************************//*  Function version_local()  *//******************************/static ZCONST char CompiledWith[] = "Compiled with %s%s for %s%s%s.\n\n";                        /* At module level to keep Turbo C++ 1.0 happy !! */void version_local(){#if defined(__DJGPP__) || defined(__WATCOMC__) || \    (defined(_MSC_VER) && (_MSC_VER != 800))    char buf[80];#endif/* Define the compiler name and version strings */#if defined(__GNUC__)#  if defined(__DJGPP__)    sprintf(buf, "djgpp v%d.%02d / gcc ", __DJGPP__, __DJGPP_MINOR__);#    define COMPILER_NAME1      buf#  elif defined(__GO32__)         /* __GO32__ is defined as "1" only (sigh) */#    define COMPILER_NAME1      "djgpp v1.x / gcc "#  elif defined(__EMX__)          /* ...so is __EMX__ (double sigh) */#    define COMPILER_NAME1      "emx+gcc "#  else#    define COMPILER_NAME1      "gcc "#  endif#  define COMPILER_NAME2        __VERSION__#elif defined(__WATCOMC__)#  if (__WATCOMC__ % 10 > 0)/* We do this silly test because __WATCOMC__ gives two digits for the  *//* minor version, but Watcom packaging prefers to show only one digit. */    sprintf(buf, "Watcom C/C++ %d.%02d", __WATCOMC__ / 100,            __WATCOMC__ % 100);#  else    sprintf(buf, "Watcom C/C++ %d.%d", __WATCOMC__ / 100,            (__WATCOMC__ % 100) / 10);#  endif#  define COMPILER_NAME1        buf#  define COMPILER_NAME2        ""#elif defined(__TURBOC__)#  ifdef __BORLANDC__#    define COMPILER_NAME1      "Borland C++"#    if (__BORLANDC__ < 0x0200)#      define COMPILER_NAME2    " 1.0"#    elif (__BORLANDC__ == 0x0200)   /* James:  __TURBOC__ = 0x0297 */#      define COMPILER_NAME2    " 2.0"#    elif (__BORLANDC__ == 0x0400)#      define COMPILER_NAME2    " 3.0"#    elif (__BORLANDC__ == 0x0410)   /* __BCPLUSPLUS__ = 0x0310 */#      define COMPILER_NAME2    " 3.1"#    elif (__BORLANDC__ == 0x0452)   /* __BCPLUSPLUS__ = 0x0320 */#      define COMPILER_NAME2    " 4.0 or 4.02"#    elif (__BORLANDC__ == 0x0460)   /* __BCPLUSPLUS__ = 0x0340 */#      define COMPILER_NAME2    " 4.5"#    elif (__BORLANDC__ == 0x0500)   /* __TURBOC__ = 0x0500 */#      define COMPILER_NAME2    " 5.0"#    else#      define COMPILER_NAME2    " later than 5.0"#    endif#  else#    define COMPILER_NAME1      "Turbo C"#    if (__TURBOC__ > 0x0401)#      define COMPILER_NAME2    "++ later than 3.0"#    elif (__TURBOC__ == 0x0401)     /* Kevin:  3.0 -> 0x0401 */#      define COMPILER_NAME2    "++ 3.0"#    elif (__TURBOC__ == 0x0296)     /* [662] checked by SPC */#      define COMPILER_NAME2    "++ 1.01"#    elif (__TURBOC__ == 0x0295)     /* [661] vfy'd by Kevin */#      define COMPILER_NAME2    "++ 1.0"#    elif (__TURBOC__ == 0x0201)     /* Brian:  2.01 -> 0x0201 */#      define COMPILER_NAME2    " 2.01"#    elif ((__TURBOC__ >= 0x018d) && (__TURBOC__ <= 0x0200)) /* James: 0x0200 */#      define COMPILER_NAME2    " 2.0"#    elif (__TURBOC__ > 0x0100)#      define COMPILER_NAME2    " 1.5"          /* James:  0x0105? */#    else#      define COMPILER_NAME2    " 1.0"          /* James:  0x0100 */#    endif#  endif#elif defined(MSC)#  if defined(_QC) && !defined(_MSC_VER)#    define COMPILER_NAME1      "Microsoft Quick C"#    define COMPILER_NAME2      ""      /* _QC is defined as 1 */#  else#    define COMPILER_NAME1      "Microsoft C "#    ifdef _MSC_VER#      if (_MSC_VER == 800)#        define COMPILER_NAME2  "8.0/8.0c (Visual C++ 1.0/1.5)"#      else#        define COMPILER_NAME2 \           (sprintf(buf, "%d.%02d", _MSC_VER/100, _MSC_VER%100), buf)#      endif#    else#      define COMPILER_NAME2    "5.1 or earlier"#    endif#  endif#else#    define COMPILER_NAME1      "unknown compiler"#    define COMPILER_NAME2      ""#endif/* Define the OS name and memory environment strings */#if defined(__WATCOMC__) || defined(__TURBOC__) || defined(MSC) || \    defined(__GNUC__)#  define OS_NAME1      "\nMS-DOS"#else#  define OS_NAME1      "MS-DOS"#endif#if (defined(__GNUC__) || (defined(__WATCOMC__) && defined(__386__)))#  define OS_NAME2      " (32-bit)"#elif defined(M_I86HM) || defined(__HUGE__)#  define OS_NAME2      " (16-bit, huge)"#elif defined(M_I86LM) || defined(__LARGE__)#  define OS_NAME2      " (16-bit, large)"#elif defined(M_I86MM) || defined(__MEDIUM__)#  define OS_NAME2      " (16-bit, medium)"#elif defined(M_I86CM) || defined(__COMPACT__)#  define OS_NAME2      " (16-bit, compact)"#elif defined(M_I86SM) || defined(__SMALL__)#  define OS_NAME2      " (16-bit, small)"#elif defined(M_I86TM) || defined(__TINY__)#  define OS_NAME2      " (16-bit, tiny)"#else#  define OS_NAME2      " (16-bit)"#endif/* Define the compile date string */#ifdef __DATE__#  define COMPILE_DATE " on " __DATE__#else#  define COMPILE_DATE ""#endif    printf(CompiledWith, COMPILER_NAME1, COMPILER_NAME2,           OS_NAME1, OS_NAME2, COMPILE_DATE);} /* end function version_local() */#endif /* !WINDLL */#if 0 /* inserted here for future use (clearing of archive bits) */#if (defined(__GO32__) && (!defined(__DJGPP__) || (__DJGPP__ < 2)))#include <errno.h>int volatile _doserrno;unsigned _dos_setfileattr(char *name, unsigned attr){#if 0   /* stripping of trailing '/' is not needed for zip-internal use */    unsigned namlen = strlen(name);    char *i_name = alloca(namlen + 1);    strcpy(i_name, name);    if (namlen > 1 && i_name[namlen-1] == '/' && i_name[namlen-2] != ':')        i_name[namlen-1] = '\0';    asm("movl %0, %%edx": : "g" (i_name));#else    asm("movl %0, %%edx": : "g" (name));#endif    asm("movl %0, %%ecx": : "g" (attr));    asm("movl $0x4301, %eax");    asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");    _doserrno = 0;    asm("jnc 1f");    asm("movl %%eax, %0": "=m" (_doserrno));    switch (_doserrno) {    case 2:    case 3:           errno = ENOENT;           break;    case 5:           errno = EACCES;           break;    }    asm("1:");    return (unsigned)_doserrno;}#endif /* DJGPP v1.x */#endif /* never (not yet used) */#if (defined(__DJGPP__) && (__DJGPP__ >= 2))/* Disable determination of "x" bit in st_mode field for [f]stat() calls. */int _is_executable (const char *path, int fhandle, const char *ext){    return 0;}/* Prevent globbing of filenames.  This gives the same functionality as * "stubedit <program> globbing=no" did with DJGPP v1. */#ifndef USE_DJGPP_GLOBchar **__crt0_glob_function(char *_arg){    return NULL;}#endif/* Reduce the size of the executable and remove the functionality to read * the program's environment from whatever $DJGPP points to. */#if !defined(USE_DJGPP_ENV) || defined(UTIL)void __crt0_load_environment_file(char *_app_name){}#endif#endif /* __DJGPP__ >= 2 */#if defined(_MSC_VER) && _MSC_VER == 700/* * ARGH.  MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not *  1970 Jan 1 00:00.  So we have to diddle time_t's appropriately:  add *  70 years' worth of seconds for localtime() wrapper function; *  (70*365 regular days + 17 leap days + 1 1899 day) * 86400 == *  (25550 + 17 + 1) * 86400 == 2209075200 seconds. *  Let time() and stat() return seconds since 1970 by using our own *  _dtoxtime() which is the routine that is called by these two functions. */#ifdef UTIL#  include <time.h>#endif#ifndef UTIL#undef localtimestruct tm *localtime(const time_t *);struct tm *msc7_localtime(const time_t *clock){   time_t t = *clock;   t += 2209075200L;   return localtime(&t);}#endif /* !UTIL */void __tzset(void);int _isindst(struct tm *);extern int _days[];/* Nonzero if `y' is a leap year, else zero. */#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)/* Number of leap years from 1970 to `y' (not including `y' itself). */#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)time_t _dtoxtime(year, month, mday, hour, min, sec)int year, month, mday, year, hour, min, sec;{   struct tm tm;   time_t t;   int days;   days = _days[month - 1] + mday;   year += 1980;   if (leap(year) && month > 2)     ++days;   tm.tm_yday = days;   tm.tm_mon = month - 1;   tm.tm_year = year - 1900;   tm.tm_hour = hour;   __tzset();   days += 365 * (year - 1970) + nleap (year);   t = 86400L * days + 3600L * hour + 60 * min + sec + _timezone;   if (_daylight && _isindst(&tm))      t -= 3600;   return t;}#endif /* _MSC_VER && _MSC_VER == 700 */#ifdef __WATCOMC__/* This papers over a bug in Watcom 10.6's standard library... sigh *//* Apparently it applies to both the DOS and Win32 stat()s.         */int stat_bandaid(const char *path, struct stat *buf){  char newname[4];  if (!stat(path, buf))    return 0;  else if (!strcmp(path, ".") || (path[0] && !strcmp(path + 1, ":."))) {    strcpy(newname, path);    newname[strlen(path) - 1] = '\\';   /* stat(".") fails for root! */    return stat(newname, buf);  } else    return -1;}#endif

⌨️ 快捷键说明

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