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

📄 cmdline.c

📁 压缩算法的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#define module_name VMS_UNZIP_CMDLINE
#define module_ident "02-002"
/*
**
**  Facility:	UNZIP
**
**  Module:	VMS_UNZIP_CMDLINE
**
**  Author:	Hunter Goatley <goathunter@wkuvx1.wku.edu>
**
**  Date:	12 Jul 94 (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-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).
**
*/


#ifdef __alpha
#pragma module module_name module_ident
#else
#module module_name module_ident
#endif

#include "unzip.h"
#include "version.h"    /* for usage() */

#include <ssdef.h>
#include <descrip.h>
#include <climsgdef.h>
#include <clidef.h>
#include <lib$routines.h>
#include <str$routines.h>

#ifndef CLI$_COMMA
globalvalue 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 = 0;}

/*
**  Define descriptors for all of the CLI parameters and qualifiers.
*/
#if 0
$DESCRIPTOR(cli_extract,	"EXTRACT");	/* obsolete */
#endif
$DESCRIPTOR(cli_autotext,	"AUTOTEXT");	/* -a */
$DESCRIPTOR(cli_text,		"TEXT");	/* -aa */
$DESCRIPTOR(cli_case_insensitive,	"CASE_INSENSITIVE");	/* -C */
$DESCRIPTOR(cli_screen,		"SCREEN");	/* -c */
$DESCRIPTOR(cli_directory,	"DIRECTORY");	/* see JUNK */
$DESCRIPTOR(cli_freshen,	"FRESHEN");	/* -f */
$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,	"SUPER_QUIET");	/* -qq */
$DESCRIPTOR(cli_test,		"TEST");	/* -t */
$DESCRIPTOR(cli_type,		"TYPE");	/* -c */
$DESCRIPTOR(cli_pipe,		"PIPE");	/* -p */
$DESCRIPTOR(cli_uppercase,	"UPPERCASE");	/* -U */
$DESCRIPTOR(cli_update,		"UPDATE");	/* -u */
$DESCRIPTOR(cli_version,	"VERSION");	/* -V */
$DESCRIPTOR(cli_verbose,	"VERBOSE");	/* -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_header,		"HEADER");	/* -Zh */
$DESCRIPTOR(cli_totals,		"TOTALS");	/* -Zt */
$DESCRIPTOR(cli_times,		"TIMES");	/* -ZT */
$DESCRIPTOR(cli_one_line,	"ONE_LINE");	/* -Z2 */

$DESCRIPTOR(cli_yyz,		"YYZ");

$DESCRIPTOR(cli_zipfile,	"ZIPFILE");
$DESCRIPTOR(cli_infile,		"INFILE");
$DESCRIPTOR(unzip_command,	"unzip ");
$DESCRIPTOR(blank,		" ");

#ifdef __alpha
extern void *vms_unzip_cld;
#else
globalref 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 ***);
unsigned long get_list (struct dsc$descriptor_s *, char **,
			struct dsc$descriptor_d *, char);
unsigned long check_cli (struct dsc$descriptor_s *);


#ifdef TEST
unsigned long
main(int argc, char **argv)
{
    register status;
    return (vms_unzip_cmdline(&argc, &argv));
}
#endif /* TEST */


unsigned long
vms_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 status;
    char options[256];
    char *the_cmd_line;
    char *ptr;
    int  x, len, zipinfo;

    int new_argc;
    char **new_argv;

    struct dsc$descriptor_d work_str;
    struct dsc$descriptor_d foreign_cmdline;
    struct dsc$descriptor_d output_directory;

    init_dyndesc (work_str);
    init_dyndesc (foreign_cmdline);
    init_dyndesc (output_directory);

    /*
    **  See if the program was invoked by the CLI (SET COMMAND) or by
    **  a foreign command definition.  Check for /YYZ, which is a
    **  valid default qualifier solely for this test.
    */
    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) || (*(foreign_cmdline.dsc$a_pointer) == '-'))
            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 an new_argv[] because of the image name.
    */
    if ((the_cmd_line = (char *) malloc (sizeof("unzip")+1)) == NULL)
	return(SS$_INSFMEM);

    strcpy (the_cmd_line, "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';
	*ptr++ = ' ';
	*ptr++ = '-';

	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_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';

	/* If no other options were specified, remove the " -". */
	if (*(ptr - 1) == '-')
	    ptr = ptr - 2;

    }
    else {

#if 0
    /*
    **  Extract files?
    */
    status = cli$present (&cli_extract);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 'x';
#endif

    /*
    **  Convert all files as text (CR LF -> LF, etc.)
    */
    status = cli$present (&cli_text);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT) {
	*ptr++ = 'a';
	*ptr++ = 'a';
    }

    /*
    **  Auto-convert only text files as text
    */
    status = cli$present (&cli_autotext);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*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';

    /*
    **  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';

    /*
    **  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';

    status = cli$present (&cli_super_quiet);
    if (status & 1)
	*ptr++ = 'q';

    /*
    **  Test archive integrity
    */
    status = cli$present (&cli_test);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 't';

    /*
    **  Match filenames case-insensitively (-C)
    */
    status = cli$present (&cli_case_insensitive);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 'C';

    /*
    **  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)

⌨️ 快捷键说明

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