📄 cmdline.c
字号:
/* Copyright (C) 1990-1997 Mark Adler, Richard B. Wales, Jean-loup Gailly, Kai Uwe Rommel, Christian Spieler, Onno van der Linden and Igor Mandrichenko. Permission is granted to any individual or institution to use, copy, or redistribute this software so long as all of the original files are included, that it is not sold for profit, and that this copyright notice is retained.*/#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 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).***/#ifdef __DECC#pragma module module_name module_ident#else#module module_name module_ident#endif#include "zip.h"#ifndef TEST#include "crypt.h" /* for VMSCLI_help() */#ifndef NOCPYRT# define NOCPYRT#endif#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_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_more, "VERBOSE.MORE"); /* -vv */$DESCRIPTOR(cli_verbose_debug, "VERBOSE.DEBUG"); /* -vvv */$DESCRIPTOR(cli_vms, "VMS"); /* -V */$DESCRIPTOR(cli_yyz, "YYZ_ZIP");$DESCRIPTOR(cli_zipfile, "ZIPFILE");$DESCRIPTOR(cli_infile, "INFILE");$DESCRIPTOR(zip_command, "zip ");static int show_VMSCLI_help;#ifdef __DECCextern void *zip_clitable;#elseglobalref void *zip_clitable;#endif/* extern unsigned long LIB$GET_INPUT(void), LIB$SIG_TO_RET(void); */#ifndef __STARLET_LOADEDextern int sys$bintim ();extern int sys$numtim ();#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 *);#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); } *ptr++ = binval + '0'; } /* ** Adjust offsets of zip archive entries. */ status = cli$present(&cli_adjust); if (status & 1) *ptr++ = 'A'; /* ** Add comments? */ status = cli$present(&cli_comments); if (status & 1) {/* while ((status = cli$get_value(&cli_comments, &work_str)) & 1) { if (strncmp(work_str.dsc$a_pointer,"ZIP",3) == 0) *ptr++ = 'z'; if (strncmp(work_str.dsc$a_pointer,"FIL",3) == 0) *ptr++ = 'c'; } */ if ((status = cli$present(&cli_comment_zipfile)) & 1) *ptr++ = 'z'; if ((status = cli$present(&cli_comment_files)) & 1) *ptr++ = 'c'; } /* ** Do not add/modify directory entries. */ status = cli$present(&cli_dirnames); if (!(status & 1)) *ptr++ = 'D'; /* ** Encrypt? */ status = cli$present(&cli_encrypt); if (status & 1) if ((status = cli$get_value(&cli_encrypt, &work_str)) & 1) { x = cmdl_len; cmdl_len += work_str.dsc$w_length + 4; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-P"); strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer, work_str.dsc$w_length); the_cmd_line[cmdl_len-1] = '\0'; } else { *ptr++ = 'e'; } /* ** Fix the zip archive structure. */ status = cli$present(&cli_fix_archive); if (status & 1) { *ptr++ = 'F'; if ((status = cli$present(&cli_fix_full)) & 1) { *ptr++ = 'F'; } } /* ** Append (allow growing of existing zip file). */ status = cli$present(&cli_append); if (status & 1) *ptr++ = 'g'; /* ** Show the help. */ status = cli$present(&cli_help); if (status & 1) *ptr++ = 'h'; /* ** Junk path names (directory specs). */ status = cli$present(&cli_junk); if (status & 1) *ptr++ = 'j'; /* ** Simulate zip file made by PKZIP. */ status = cli$present(&cli_pkzip); if (status & 1) *ptr++ = 'k'; /* ** Translate end-of-line. */ status = cli$present(&cli_translate_eol); if (status & 1) { *ptr++ = 'l'; if ((status = cli$present(&cli_transl_eol_crlf)) & 1) { *ptr++ = 'l'; } } /* ** Show the software license. */ status = cli$present(&cli_license); if (status & 1) *ptr++ = 'L'; /* ** Set zip file time to time of latest file in it. */ status = cli$present(&cli_latest); if (status & 1) *ptr++ = 'o'; /* ** Store full path (default). */ status = cli$present(&cli_full_path); if (status == CLI$_PRESENT) *ptr++ = 'p'; else if (status == CLI$_NEGATED) *ptr++ = 'j'; /* ** Junk Zipfile prefix (SFX stub etc.). */ status = cli$present(&cli_unsfx); if (status & 1) *ptr++ = 'J'; /* ** Recurse through subdirectories. */ status = cli$present(&cli_recurse); if (status & 1) { if ((status = cli$present(&cli_recurse_fnames)) & 1) *ptr++ = 'R'; else *ptr++ = 'r'; } /* ** Be verbose. */ status = cli$present(&cli_verbose); if (status & 1) { *ptr++ = 'v'; if ((status = cli$present(&cli_verbose_more)) & 1) *ptr++ = 'v'; if ((status = cli$present(&cli_verbose_debug)) & 1) { *ptr++ = 'v'; *ptr++ = 'v'; } } /* ** Quiet mode. ** (Quiet mode is processed after verbose, because a "-v" modifier ** resets "noisy" to 1.) */ status = cli$present(&cli_quiet); if (status & 1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -