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

📄 cmdline.c

📁 给出了 zip 压缩算法的完整实现过程。
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  Copyright (c) 1990-2006 Info-ZIP.  All rights reserved.  See the accompanying file LICENSE, version 2005-Feb-10 or later  (the contents of which are also included in zip.h) for terms of use.  If, for some reason, all these files are missing, the Info-ZIP license  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html*/#define module_name VMS_ZIP_CMDLINE#define module_ident "02-006"/*****  Facility:   ZIP****  Module:     VMS_ZIP_CMDLINE****  Author:     Hunter Goatley <goathunter@MadGoat.com>****  Date:       July 30, 1993****  Abstract:   Routines to handle a VMS CLI interface for Zip.  The CLI**              command line is parsed and a new argc/argv are built and**              returned to Zip.****  Modified by:****      02-006          Onno van der Linden,**                      Christian Spieler       07-JUL-1998 23:03**              Support GNU CC 2.8 on Alpha AXP (vers-num unchanged).**      02-006          Johnny Lee              25-JUN-1998 07:40**              Fixed typo (superfluous ';') (vers-num unchanged).**      02-006          Christian Spieler       12-SEP-1997 23:17**              Fixed bugs in /BEFORE and /SINCE handlers (vers-num unchanged).**      02-006          Christian Spieler       12-JUL-1997 02:05**              Complete revision of the argv strings construction.**              Added handling of "-P pwd", "-R", "-i@file", "-x@file" options.**      02-005          Patrick Ellis           09-MAY-1996 22:25**              Show UNIX style help screen when UNIX style options are used.**      02-004          Onno van der Linden,**                      Christian Spieler       13-APR-1996 20:05**              Removed /ENCRYPT=VERIFY ("-ee" option).**      02-003          Christian Spieler       11-FEB-1996 23:05**              Added handling of /EXTRAFIELDS qualifier ("-X" option).**      02-002          Christian Spieler       09-JAN-1996 22:25**              Added "#include crypt.h", corrected typo.**      02-001          Christian Spieler       04-DEC-1995 16:00**              Fixed compilation in DEC CC's ANSI mode.**      02-000          Christian Spieler       10-OCT-1995 17:54**              Modified for Zip v2.1, added several new options.**      01-000          Hunter Goatley          30-JUL-1993 07:54**              Original version (for Zip v1.9p1).***/#if defined(__DECC) || defined(__GNUC__)#pragma module module_name module_ident#else#module module_name module_ident#endif#include "zip.h"#ifndef TEST#include "crypt.h"      /* for VMSCLI_help() */#include "revision.h"   /* for VMSCLI_help() */#endif /* !TEST */#include <ssdef.h>#include <descrip.h>#include <climsgdef.h>#include <clidef.h>#include <lib$routines.h>#include <ots$routines.h>#include <str$routines.h>#ifndef CLI$_COMMAglobalvalue CLI$_COMMA;#endif/***  "Macro" to initialize a dynamic string descriptor.*/#define init_dyndesc(dsc) {\        dsc.dsc$w_length = 0;\        dsc.dsc$b_dtype = DSC$K_DTYPE_T;\        dsc.dsc$b_class = DSC$K_CLASS_D;\        dsc.dsc$a_pointer = NULL;}/***  Memory allocation step for argv string buffer.*/#define ARGBSIZE_UNIT 256/***  Memory reallocation macro for argv string buffer.*/#define CHECK_BUFFER_ALLOCATION(buf, reserved, requested) { \    if ((requested) > (reserved)) { \        char *save_buf = (buf); \        (reserved) += ARGBSIZE_UNIT; \        if (((buf) = (char *) realloc((buf), (reserved))) == NULL) { \            if (save_buf != NULL) free(save_buf); \            return (SS$_INSFMEM); \        } \    } \}/***  Define descriptors for all of the CLI parameters and qualifiers.*/$DESCRIPTOR(cli_delete,         "DELETE");              /* -d */$DESCRIPTOR(cli_freshen,        "FRESHEN");             /* -f */$DESCRIPTOR(cli_move,           "MOVE");                /* -m */$DESCRIPTOR(cli_update,         "UPDATE");              /* -u */$DESCRIPTOR(cli_exclude,        "EXCLUDE");             /* -x */$DESCRIPTOR(cli_include,        "INCLUDE");             /* -i */$DESCRIPTOR(cli_exlist,         "EXLIST");              /* -x@ */$DESCRIPTOR(cli_inlist,         "INLIST");              /* -i@ */$DESCRIPTOR(cli_adjust,         "ADJUST_OFFSETS");      /* -A */$DESCRIPTOR(cli_append,         "APPEND");              /* -g */$DESCRIPTOR(cli_batch,          "BATCH");               /* -@ */$DESCRIPTOR(cli_before,         "BEFORE");              /* -tt */$DESCRIPTOR(cli_comments,       "COMMENTS");            /* -c,-z */$DESCRIPTOR(cli_comment_zipfile,"COMMENTS.ZIP_FILE");   /* -z */$DESCRIPTOR(cli_comment_files,  "COMMENTS.FILES");      /* -c */$DESCRIPTOR(cli_dirnames,       "DIRNAMES");            /* -D */$DESCRIPTOR(cli_encrypt,        "ENCRYPT");             /* -e,-P */$DESCRIPTOR(cli_extra_fields,   "EXTRA_FIELDS");        /* -X */$DESCRIPTOR(cli_fix_archive,    "FIX_ARCHIVE");         /* -F[F] */$DESCRIPTOR(cli_fix_normal,     "FIX_ARCHIVE.NORMAL");  /* -F */$DESCRIPTOR(cli_fix_full,       "FIX_ARCHIVE.FULL");    /* -FF */$DESCRIPTOR(cli_full_path,      "FULL_PATH");           /* -p */$DESCRIPTOR(cli_help,           "HELP");                /* -h */$DESCRIPTOR(cli_junk,           "JUNK");                /* -j */$DESCRIPTOR(cli_keep_version,   "KEEP_VERSION");        /* -w */$DESCRIPTOR(cli_latest,         "LATEST");              /* -o */$DESCRIPTOR(cli_level,          "LEVEL");               /* -[0-9] */$DESCRIPTOR(cli_license,        "LICENSE");             /* -L */$DESCRIPTOR(cli_must_match,     "MUST_MATCH");          /* -MM */$DESCRIPTOR(cli_pkzip,          "PKZIP");               /* -k */$DESCRIPTOR(cli_quiet,          "QUIET");               /* -q */$DESCRIPTOR(cli_recurse,        "RECURSE");             /* -r,-R */$DESCRIPTOR(cli_recurse_path,   "RECURSE.PATH");        /* -r */$DESCRIPTOR(cli_recurse_fnames, "RECURSE.FILENAMES");   /* -R */$DESCRIPTOR(cli_since,          "SINCE");               /* -t */$DESCRIPTOR(cli_store_types,    "STORE_TYPES");         /* -n */$DESCRIPTOR(cli_temp_path,      "TEMP_PATH");           /* -b */$DESCRIPTOR(cli_test,           "TEST");                /* -T */$DESCRIPTOR(cli_translate_eol,  "TRANSLATE_EOL");       /* -l[l] */$DESCRIPTOR(cli_transl_eol_lf,  "TRANSLATE_EOL.LF");    /* -l */$DESCRIPTOR(cli_transl_eol_crlf,"TRANSLATE_EOL.CRLF");  /* -ll */$DESCRIPTOR(cli_unsfx,          "UNSFX");               /* -J */$DESCRIPTOR(cli_verbose,        "VERBOSE");             /* -v (?) */$DESCRIPTOR(cli_verbose_normal, "VERBOSE.NORMAL");      /* -v */$DESCRIPTOR(cli_verbose_more,   "VERBOSE.MORE");        /* -vv */$DESCRIPTOR(cli_verbose_debug,  "VERBOSE.DEBUG");       /* -vvv */$DESCRIPTOR(cli_verbose_command,"VERBOSE.COMMAND");     /* (none) */$DESCRIPTOR(cli_vms,            "VMS");                 /* -V */$DESCRIPTOR(cli_vms_all,        "VMS.ALL");             /* -VV */$DESCRIPTOR(cli_yyz,            "YYZ_ZIP");$DESCRIPTOR(cli_zipfile,        "ZIPFILE");$DESCRIPTOR(cli_infile,         "INFILE");$DESCRIPTOR(zip_command,        "zip ");static int show_VMSCLI_help;#if !defined(zip_clitable)#  define zip_clitable ZIP_CLITABLE#endif#if defined(__DECC) || defined(__GNUC__)extern void *zip_clitable;#elseglobalref void *zip_clitable;#endif/* extern unsigned long LIB$GET_INPUT(void), LIB$SIG_TO_RET(void); */#ifndef __STARLET_LOADED#ifndef sys$bintim#  define sys$bintim SYS$BINTIM#endif#ifndef sys$numtim#  define sys$numtim SYS$NUMTIM#endifextern int sys$bintim ();extern int sys$numtim ();#endif /* !__STARLET_LOADED */#ifndef cli$dcl_parse#  define cli$dcl_parse CLI$DCL_PARSE#endif#ifndef cli$present#  define cli$present CLI$PRESENT#endif#ifndef cli$get_value#  define cli$get_value CLI$GET_VALUE#endifextern unsigned long cli$dcl_parse ();extern unsigned long cli$present ();extern unsigned long cli$get_value ();unsigned long vms_zip_cmdline (int *, char ***);static unsigned long get_list (struct dsc$descriptor_s *,                               struct dsc$descriptor_d *, int,                               char **, unsigned long *, unsigned long *);static unsigned long get_time (struct dsc$descriptor_s *qual, char *timearg);static unsigned long check_cli (struct dsc$descriptor_s *);static int verbose_command = 0;#ifdef TESTintmain(int argc, char **argv){    return (vms_zip_cmdline(&argc, &argv));}#endif /* TEST */unsigned longvms_zip_cmdline (int *argc_p, char ***argv_p){/***  Routine:    vms_zip_cmdline****  Function:****      Parse the DCL command line and create a fake argv array to be**      handed off to Zip.****      NOTE: the argv[] is built as we go, so all the parameters are**      checked in the appropriate order!!****  Formal parameters:****      argc_p          - Address of int to receive the new argc**      argv_p          - Address of char ** to receive the argv address****  Calling sequence:****      status = vms_zip_cmdline (&argc, &argv);****  Returns:****      SS$_NORMAL      - Success.**      SS$_INSFMEM     - A malloc() or realloc() failed**      SS$_ABORT       - Bad time value***/    register unsigned long status;    char options[48];    char *the_cmd_line;                 /* buffer for argv strings */    unsigned long cmdl_size;            /* allocated size of buffer */    unsigned long cmdl_len;             /* used size of buffer */    char *ptr;    int  x, len;    int new_argc;    char **new_argv;    struct dsc$descriptor_d work_str;    struct dsc$descriptor_d foreign_cmdline;    init_dyndesc(work_str);    init_dyndesc(foreign_cmdline);    /*    **  See if the program was invoked by the CLI (SET COMMAND) or by    **  a foreign command definition.  Check for /YYZ_ZIP, which is a    **  valid default qualifier solely for this test.    */    show_VMSCLI_help = TRUE;    status = check_cli(&cli_yyz);    if (!(status & 1)) {        lib$get_foreign(&foreign_cmdline);        /*        **  If nothing was returned or the first character is a "-", then        **  assume it's a UNIX-style command and return.        */        if (foreign_cmdline.dsc$w_length == 0)            return (SS$_NORMAL);        if ((*(foreign_cmdline.dsc$a_pointer) == '-') ||            ((foreign_cmdline.dsc$w_length > 1) &&             (*(foreign_cmdline.dsc$a_pointer) == '"') &&             (*(foreign_cmdline.dsc$a_pointer + 1) == '-'))) {            show_VMSCLI_help = FALSE;            return (SS$_NORMAL);        }        str$concat(&work_str, &zip_command, &foreign_cmdline);        status = cli$dcl_parse(&work_str, &zip_clitable, lib$get_input,                        lib$get_input, 0);        if (!(status & 1)) return (status);    }    /*    **  There's always going to be a new_argv[] because of the image name.    */    if ((the_cmd_line = (char *) malloc(cmdl_size = ARGBSIZE_UNIT)) == NULL)        return (SS$_INSFMEM);    strcpy(the_cmd_line, "zip");    cmdl_len = sizeof("zip");    /*    **  First, check to see if any of the regular options were specified.    */    options[0] = '-';    ptr = &options[1];          /* Point to temporary buffer */    /*    **  Delete the specified files from the zip file?    */    status = cli$present(&cli_delete);    if (status & 1)        *ptr++ = 'd';    /*    **  Freshen (only changed files).    */    status = cli$present(&cli_freshen);    if (status & 1)        *ptr++ = 'f';    /*    **  Delete the files once they've been added to the zip file.    */    status = cli$present(&cli_move);    if (status & 1)        *ptr++ = 'm';    /*    **  Add changed and new files.    */    status = cli$present(&cli_update);    if (status & 1)        *ptr++ = 'u';    /*    **  Check for the compression level (-0 through -9).    */    status = cli$present(&cli_level);    if (status & 1) {        unsigned long binval;        status = cli$get_value(&cli_level, &work_str);        status = ots$cvt_tu_l(&work_str, &binval);        if (!(status & 1) || (binval > 9)) {           return (SS$_ABORT);        }

⌨️ 快捷键说明

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