📄 cmdline.c
字号:
#define module_name VMS_UNZIP_CMDLINE#define module_ident "02-007"/***** Facility: UNZIP**** Module: VMS_UNZIP_CMDLINE**** Author: Hunter Goatley <goathunter@MadGoat.com>**** Date: 25 Apr 97 (orig. Zip version, 30 Jul 93)**** Abstract: Routines to handle a VMS CLI interface for UnZip. The CLI** command line is parsed and a new argc/argv are built and** returned to UnZip.**** Modified by:**** 02-007 Onno van der Linden 02-Jul-1998 19:07** Modified to support GNU CC 2.8 on Alpha; version unchanged.** 02-007 Johnny Lee 25-Jun-1998 07:38** Fixed typo (superfluous ';'); no version num change.** 02-007 Hunter Goatley 11-NOV-1997 10:38** Fixed "zip" vs. "unzip" typo; no version num change.** 02-007 Christian Spieler 14-SEP-1997 22:43** Cosmetic mods to stay in sync with Zip; no version num change.** 02-007 Christian Spieler 12-JUL-1997 02:05** Revised argv vector construction for better handling of quoted** arguments (e.g.: embedded white space); no version num change.** 02-007 Christian Spieler 04-MAR-1997 22:25** Made /CASE_INSENSITIVE common to UnZip and ZipInfo mode;** added support for /PASSWORD="decryption_key" argument.** 02-006 Christian Spieler 11-MAY-1996 22:40** Added SFX version of VMSCLI_usage().** 02-005 Patrick Ellis 09-MAY-1996 22:25** Show UNIX style usage screen when UNIX style options are used.** 02-004 Christian Spieler 06-FEB-1996 02:20** Added /HELP qualifier.** 02-003 Christian Spieler 23-DEC-1995 17:20** Adapted to UnZip 5.2.** 02-002 Hunter Goatley 16-JUL-1994 10:20** Fixed some typos.** 02-001 Cave Newt 14-JUL-1994 15:18** Removed obsolete /EXTRACT option; fixed /*TEXT options;** wrote VMSCLI usage() function** 02-000 Hunter Goatley 12-JUL-1994 00:00** Original UnZip version (v5.11).** 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#define UNZIP_INTERNAL#include "unzip.h"#ifndef TEST# include "version.h" /* for VMSCLI_usage() */#endif /* !TEST */#include <ssdef.h>#include <descrip.h>#include <climsgdef.h>#include <clidef.h>#include <lib$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.*/#if 0$DESCRIPTOR(cli_extract, "EXTRACT"); /* obsolete */#endif$DESCRIPTOR(cli_text, "TEXT"); /* -a[a] */$DESCRIPTOR(cli_text_auto, "TEXT.AUTO"); /* -a */$DESCRIPTOR(cli_text_all, "TEXT.ALL"); /* -aa */$DESCRIPTOR(cli_text_none, "TEXT.NONE"); /* ---a */$DESCRIPTOR(cli_binary, "BINARY"); /* -b[b] */$DESCRIPTOR(cli_binary_auto, "BINARY.AUTO"); /* -b */$DESCRIPTOR(cli_binary_all, "BINARY.ALL"); /* -bb */$DESCRIPTOR(cli_binary_none, "BINARY.NONE"); /* ---b */$DESCRIPTOR(cli_case_insensitive,"CASE_INSENSITIVE"); /* -C */$DESCRIPTOR(cli_screen, "SCREEN"); /* -c */$DESCRIPTOR(cli_directory, "DIRECTORY"); /* -d */$DESCRIPTOR(cli_freshen, "FRESHEN"); /* -f */$DESCRIPTOR(cli_help, "HELP"); /* -h */$DESCRIPTOR(cli_junk, "JUNK"); /* -j */$DESCRIPTOR(cli_lowercase, "LOWERCASE"); /* -L */$DESCRIPTOR(cli_list, "LIST"); /* -l */$DESCRIPTOR(cli_brief, "BRIEF"); /* -l */$DESCRIPTOR(cli_full, "FULL"); /* -v */$DESCRIPTOR(cli_overwrite, "OVERWRITE"); /* -o, -n */$DESCRIPTOR(cli_quiet, "QUIET"); /* -q */$DESCRIPTOR(cli_super_quiet, "QUIET.SUPER"); /* -qq */$DESCRIPTOR(cli_test, "TEST"); /* -t */$DESCRIPTOR(cli_type, "TYPE"); /* -c */$DESCRIPTOR(cli_pipe, "PIPE"); /* -p */$DESCRIPTOR(cli_password, "PASSWORD"); /* -P */$DESCRIPTOR(cli_uppercase, "UPPERCASE"); /* -U */$DESCRIPTOR(cli_update, "UPDATE"); /* -u */$DESCRIPTOR(cli_version, "VERSION"); /* -V */$DESCRIPTOR(cli_restore, "RESTORE"); /* -X */$DESCRIPTOR(cli_comment, "COMMENT"); /* -z */$DESCRIPTOR(cli_exclude, "EXCLUDE"); /* -x */$DESCRIPTOR(cli_information, "ZIPINFO"); /* -Z */$DESCRIPTOR(cli_short, "SHORT"); /* -Zs */$DESCRIPTOR(cli_medium, "MEDIUM"); /* -Zm */$DESCRIPTOR(cli_long, "LONG"); /* -Zl */$DESCRIPTOR(cli_verbose, "VERBOSE"); /* -Zv */$DESCRIPTOR(cli_header, "HEADER"); /* -Zh */$DESCRIPTOR(cli_totals, "TOTALS"); /* -Zt */$DESCRIPTOR(cli_times, "TIMES"); /* -ZT */$DESCRIPTOR(cli_one_line, "ONE_LINE"); /* -Z2 */$DESCRIPTOR(cli_page, "PAGE"); /* -M , -ZM */$DESCRIPTOR(cli_yyz, "YYZ_UNZIP");$DESCRIPTOR(cli_zipfile, "ZIPFILE");$DESCRIPTOR(cli_infile, "INFILE");$DESCRIPTOR(unzip_command, "unzip ");static int show_VMSCLI_usage;#if defined(__DECC) || defined(__GNUC__)extern void *vms_unzip_cld;#elseglobalref void *vms_unzip_cld;#endif/* extern unsigned long LIB$GET_INPUT(void), LIB$SIG_TO_RET(void); */extern unsigned long cli$dcl_parse ();extern unsigned long cli$present ();extern unsigned long cli$get_value ();unsigned long vms_unzip_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 check_cli (struct dsc$descriptor_s *);#ifdef TESTintmain(int argc, char **argv){ return (vms_unzip_cmdline(&argc, &argv));}#endif /* TEST */unsigned longvms_unzip_cmdline (int *argc_p, char ***argv_p){/*** Routine: vms_unzip_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_unzip_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[256]; 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, zipinfo, exclude_list; int new_argc; char **new_argv; struct dsc$descriptor_d work_str; struct dsc$descriptor_d foreign_cmdline; struct dsc$descriptor_d output_directory; struct dsc$descriptor_d password_arg; init_dyndesc(work_str); init_dyndesc(foreign_cmdline); init_dyndesc(output_directory); init_dyndesc(password_arg); /* ** See if the program was invoked by the CLI (SET COMMAND) or by ** a foreign command definition. Check for /YYZ_UNZIP, which is a ** valid default qualifier solely for this test. */ show_VMSCLI_usage = 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_usage = FALSE; return (SS$_NORMAL); } str$concat(&work_str, &unzip_command, &foreign_cmdline); status = cli$dcl_parse(&work_str, &vms_unzip_cld, 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, "unzip"); cmdl_len = sizeof("unzip"); /* ** First, check to see if any of the regular options were specified. */ options[0] = '-'; ptr = &options[1]; /* Point to temporary buffer */ /* ** Is it ZipInfo?? */ zipinfo = 0; status = cli$present(&cli_information); if (status & 1) { zipinfo = 1; *ptr++ = 'Z'; if (cli$present(&cli_one_line) & 1) *ptr++ = '2'; if (cli$present(&cli_short) & 1) *ptr++ = 's'; if (cli$present(&cli_medium) & 1) *ptr++ = 'm'; if (cli$present(&cli_long) & 1) *ptr++ = 'l'; if (cli$present(&cli_verbose) & 1) *ptr++ = 'v'; if (cli$present(&cli_header) & 1) *ptr++ = 'h'; if (cli$present(&cli_comment) & 1) *ptr++ = 'c'; if (cli$present(&cli_totals) & 1) *ptr++ = 't'; if (cli$present(&cli_times) & 1) *ptr++ = 'T'; } else {#if 0 /* ** Extract files? */ status = cli$present(&cli_extract); if (status == CLI$_NEGATED) *ptr++ = '-'; if (status != CLI$_ABSENT) *ptr++ = 'x';#endif /* ** Write binary files in VMS binary (fixed-length, 512-byte records, ** record attributes: none) format ** (auto-convert, or force to convert all files) */ status = cli$present(&cli_binary); if (status != CLI$_ABSENT) { *ptr++ = '-'; *ptr++ = '-'; *ptr++ = 'b'; if ((status & 1) && !((status = cli$present(&cli_binary_none)) & 1)) { *ptr++ = 'b'; if ((status = cli$present(&cli_binary_all)) & 1) *ptr++ = 'b'; } } /* ** Convert files as text (CR LF -> LF, etc.) ** (auto-convert, or force to convert all files) */ status = cli$present(&cli_text); if (status != CLI$_ABSENT) { *ptr++ = '-'; *ptr++ = '-'; *ptr++ = 'a'; if ((status & 1) && !((status = cli$present(&cli_text_none)) & 1)) { *ptr++ = 'a'; if ((status = cli$present(&cli_text_all)) & 1) *ptr++ = 'a'; } } /* ** Extract files to screen? */ status = cli$present(&cli_screen); if (status == CLI$_NEGATED) *ptr++ = '-'; if (status != CLI$_ABSENT) *ptr++ = 'c'; /* ** Re-create directory structure? (default) */ status = cli$present(&cli_directory); if (status == CLI$_PRESENT) { status = cli$get_value(&cli_directory, &output_directory); } /* ** Freshen existing files, create none */ status = cli$present(&cli_freshen); if (status == CLI$_NEGATED) *ptr++ = '-'; if (status != CLI$_ABSENT) *ptr++ = 'f'; /* ** Show the help. */ status = cli$present(&cli_help); if (status & 1) *ptr++ = 'h'; /* ** Junk stored directory names on unzip */ status = cli$present(&cli_junk); if (status == CLI$_NEGATED) *ptr++ = '-'; if (status != CLI$_ABSENT) *ptr++ = 'j'; /* ** List contents (/BRIEF or /FULL (default)) */ status = cli$present(&cli_list); if (status & 1) { if (cli$present(&cli_full) & 1) *ptr++ = 'v'; else *ptr++ = 'l'; } /* ** Overwrite files? */ status = cli$present(&cli_overwrite); if (status == CLI$_NEGATED) *ptr++ = 'n'; else if (status != CLI$_ABSENT) *ptr++ = 'o'; /* ** Decryption password from command line? */ status = cli$present(&cli_password); if (status == CLI$_PRESENT) { status = cli$get_value(&cli_password, &password_arg); } /* ** Pipe files to SYS$OUTPUT with no informationals? */ status = cli$present(&cli_pipe); if (status != CLI$_ABSENT) *ptr++ = 'p'; /* ** Quiet */ status = cli$present(&cli_quiet); if (status & 1) { *ptr++ = 'q'; if ((status = cli$present(&cli_super_quiet)) & 1) *ptr++ = 'q'; } /* ** Test archive integrity */ status = cli$present(&cli_test); if (status == CLI$_NEGATED) *ptr++ = '-'; if (status != CLI$_ABSENT) *ptr++ = 't'; /* ** Make (some) names lowercase */ status = cli$present(&cli_lowercase); if (status == CLI$_NEGATED) *ptr++ = '-'; if (status != CLI$_ABSENT) *ptr++ = 'L'; /* ** Uppercase (don't convert to lower) */ status = cli$present(&cli_uppercase); if (status == CLI$_NEGATED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -