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

📄 cmdline.c

📁 压缩算法的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    */
    status = cli$present (&cli_uppercase);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 'U';

    /*
    **  Update (extract only new and newer files)
    */
    status = cli$present (&cli_update);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 'u';

    /*
    **  Version (retain VMS/DEC-20 file versions)
    */
    status = cli$present (&cli_version);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 'V';

    /*
    **  Verbose
    */
    status = cli$present (&cli_verbose);
    if (status & 1)
	*ptr++ = 'v';

    /*
    **  Restore owner/protection info
    */
    status = cli$present (&cli_restore);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 'X';

    /*
    **  Display only the archive comment
    */
    status = cli$present (&cli_comment);
    if (status == CLI$_NEGATED)
	*ptr++ = '-';
    if (status != CLI$_ABSENT)
	*ptr++ = 'z';

    }	/* Zipinfo check way up there.... */

    /*
    **  If the user didn't give any DCL qualifier, assume he wants the
    **  Un*x interface.
    if (ptr == &options[1])
      return(SS$_NORMAL);
    */

    /*
    **  Now copy the final options string to the_cmd_line.
    */
    x = ptr - &options[0];
    if (x > 1) {
	options[x] = '\0';
	len = strlen(the_cmd_line) + x + 2;
	if ((the_cmd_line = (char *) realloc (the_cmd_line, len)) == NULL)
	    return(SS$_INSFMEM);
	strcat (the_cmd_line, " ");
	strcat (the_cmd_line, options);
    }

    /*
    **  Now get the specified zip file name.
    */
    status = cli$present (&cli_zipfile);
    if (status & 1) {
	status = cli$get_value (&cli_zipfile, &work_str);

	len = strlen(the_cmd_line) + work_str.dsc$w_length + 2;
	if ((the_cmd_line = (char *) realloc (the_cmd_line, len)) == NULL)
	    return(SS$_INSFMEM);
	strcat (the_cmd_line, " ");
	x = strlen(the_cmd_line);
	strncpy(&the_cmd_line[x], work_str.dsc$a_pointer,
		work_str.dsc$w_length);
	the_cmd_line[len] = '\0';

    }

    /*
    **  Run through the list of files to unzip.
    */
    status = cli$present (&cli_infile);
    if (status & 1) {
	len = strlen(the_cmd_line) + 2;
	if ((the_cmd_line = (char *) realloc (the_cmd_line, len)) == NULL)
	    return(SS$_INSFMEM);
	strcat (the_cmd_line, " ");
	status = get_list (&cli_infile, &the_cmd_line, &foreign_cmdline, ' ');
	if (!(status & 1)) return (status);
    }

    /*
    **  Get the list of files to exclude, if there are any.
    */
    status = cli$present (&cli_exclude);
    if (status & 1) {
	len = strlen(the_cmd_line) + 5;
	if ((the_cmd_line = (char *) realloc (the_cmd_line, len)) == NULL)
	    return(SS$_INSFMEM);
	strcat (the_cmd_line, " -x ");
	status = get_list (&cli_exclude, &the_cmd_line, &foreign_cmdline, ' ');
	if (!(status & 1)) return (status);
    }

    /*
    **  Get the output directory, for UnZip.
    **/
    if (output_directory.dsc$w_length != 0) {
	len = strlen(the_cmd_line) + output_directory.dsc$w_length + 5;
	if ((the_cmd_line = (char *) realloc (the_cmd_line, len)) == NULL)
	    return(SS$_INSFMEM);
	strcat (the_cmd_line, " -d ");
	x = strlen(the_cmd_line);
	strncpy(&the_cmd_line[x], output_directory.dsc$a_pointer,
		output_directory.dsc$w_length);
	the_cmd_line[len] = '\0';
    }

    /*
    **  Now that we've built our new UNIX-like command line, count the
    **  number of args and build an argv array.
    */

#if defined(TEST) || defined(DEBUG)
    printf("%s\n",the_cmd_line);
#endif /* TEST */

    new_argc = 1;
    for (ptr = the_cmd_line;
	 (ptr = strchr(ptr,' ')) != NULL;
	 ptr++, new_argc++);

    /*
    **  Allocate memory for the new argv[].  The last element of argv[]
    **  is supposed to be 0, so allocate enough for new_argc+1.
    */
    if ((new_argv = (char **) calloc (new_argc+1, sizeof(char *))) == NULL)
	return(SS$_INSFMEM);

    /*
    **  For each option, store the address in new_argv[] and convert the
    **  separating blanks to nulls so each argv[] string is terminated.
    */
    for (ptr = the_cmd_line, x = 0; x < new_argc; x++) {
	new_argv[x] = ptr;
	if ((ptr = strchr (ptr, ' ')) != NULL)
	    *ptr++ = '\0';
    }
    new_argv[new_argc] = 0;

#if defined(TEST) || defined(DEBUG)
    printf("new_argc    = %d\n", new_argc);
    for (x = 0; x < new_argc; x++)
	printf("new_argv[%d] = %s\n", x, new_argv[x]);
#endif /* TEST */

    /*
    **  All finished.  Return the new argc and argv[] addresses to Zip.
    */
    *argc_p = new_argc;
    *argv_p = new_argv;

    return(SS$_NORMAL);
}



unsigned long
get_list (struct dsc$descriptor_s *qual, char **str,
	  struct dsc$descriptor_d *cmdline, char c)
{
/*
**  Routine:	get_list
**
**  Function:	This routine runs through a comma-separated CLI list
**		and copies the strings to the command line.  The
**		specified separation character is used to separate
**		the strings on the command line.
**
**		All strings are converted to lower-case.
**
**  Formal parameters:
**
**	qual	- Address of descriptor for the qualifier name
**	str	- Address of pointer pointing to string (command line)
**	c	- Character to use to separate the list items
**
*/

    register status;
    struct dsc$descriptor_d work_str;

    init_dyndesc(work_str);

    status = cli$present (qual);
    if (status & 1) {

	unsigned long len, old_len, lower_it, ind, sind;

	len = strlen(*str);
	while ((status = cli$get_value (qual, &work_str)) & 1) {
	    /*
	    **  Just in case the string doesn't exist yet, though it does.
	    */
	    if (*str == NULL) {
		len = work_str.dsc$w_length + 1;
		if ((*str = (char *) malloc (work_str.dsc$w_length)) == NULL)
		    return(SS$_INSFMEM);
		strncpy(*str,work_str.dsc$a_pointer,len);
	    } else {
		char *src, *dst; int x;
		old_len = len;
		len += work_str.dsc$w_length + 1;
		if ((*str = (char *) realloc (*str, len)) == NULL)
		    return(SS$_INSFMEM);

		/*
		**  Look for the filename in the original foreign command
		**  line to see if it was originally quoted.  If so, then
		**  don't convert it to lowercase.
		*/
		lower_it = 0;
		str$find_first_substring (cmdline, &ind, &sind, &work_str);
		if (*(cmdline->dsc$a_pointer + ind - 2) == '"')
		    lower_it = 1;

		/*
		**  Copy the string to the buffer, converting to lowercase.
		*/
		src = work_str.dsc$a_pointer;
		dst = *str+old_len;
		for (x = 0; x < work_str.dsc$w_length; x++) {
		    if (!lower_it && ((*src >= 'A') && (*src <= 'Z')))
			*dst++ = *src++ + 32;
		    else
			*dst++ = *src++;
		}
	    }
	    if (status == CLI$_COMMA)
		(*str)[len-1] = c;
	    else
		(*str)[len-1] = '\0';
	}
    }

    return (SS$_NORMAL);

}


unsigned long
check_cli (struct dsc$descriptor_s *qual)
{
/*
**  Routine:	check_cli
**
**  Function:	Check to see if a CLD was used to invoke the program.
**
**  Formal parameters:
**
**	qual	- Address of descriptor for qualifier name to check.
**
*/
    lib$establish(lib$sig_to_ret);	/* Establish condition handler */
    return (cli$present(qual));		/* Just see if something was given */
}



#ifndef SFX

#ifdef VMSWILD
#  define ZI_XMPL  "*, %, () (e.g., \"(a-j)*pk.%%\")"
#else
#  define ZI_XMPL  "*, ?, [] (e.g., \"[a-j]*pk.??\")"
#endif

int usage( int error)   /* VMSCLI version; returns PK-type error code */
{
    FILE *usagefp;
    extern char UnzipUsageLine1[];


/*---------------------------------------------------------------------------
    If user requested usage, send it to stdout; else send to stderr.
  ---------------------------------------------------------------------------*/

    if (error)
        usagefp = (FILE *)stderr;
    else
        usagefp = (FILE *)stdout;

/*---------------------------------------------------------------------------
    Print either ZipInfo usage or UnZip usage, depending on incantation.
  ---------------------------------------------------------------------------*/

    if (zipinfo_mode) {

#ifndef NO_ZIPINFO

        fprintf(usagefp, "\
ZipInfo %s, by Newtware and the fine folks at Info-ZIP.\n\n\
List name, date/time, attribute, size, compression method, etc., about files\n\
in list (excluding those in xlist) contained in the specified .zip archive(s).\
\n\"file[.zip]\" may be a wildcard name containing %s.\n", ZI_VERSION, ZI_XMPL);

        fprintf(usagefp, "\n\
   usage:  zipinfo file[.zip] [list] [/EXCL=(xlist)] [/DIR=exdir] /options\n\
   or:  unzip /ZIPINFO file[.zip] [list] [/EXCL=(xlist)] [/DIR=exdir] /options\
\n\nmain\
 listing-format options:              /SHORT   short \"ls -l\" format (def.)\n\
  /ONE_LINE  just filenames, one/line     /MEDIUM  medium Unix \"ls -l\" format\n\
  /VERBOSE   verbose, multi-page format   /LONG    long Unix \"ls -l\" format\n\
	");

        fprintf(usagefp, "\n\
miscellaneous options:\n  \
/HEADER   print header line       /TOTALS  totals for listed files or for all\n\
  /COMMENT  print zipfile comment   /TIMES   times in sortable decimal format\n\
  /EXCLUDE=(file-spec1,etc.)  exclude file-specs from listing\n");

        fprintf(usagefp, "\nRemember that non-lowercase filespecs must be\
 quoted in VMS (e.g., \"Makefile\").\n");

#endif /* !NO_ZIPINFO */

    } else {   /* UnZip mode */

        fprintf(usagefp, UnzipUsageLine1, UZ_VERSION);

#ifdef BETA
        fprintf(usagefp, "\
      THIS IS STILL A BETA VERSION OF UNZIP%s -- DO NOT DISTRIBUTE.\n\n",
          "", "");
#endif

        fprintf(usagefp, "\
Usage: unzip file[.zip] [list] [/EXCL=(xlist)] [/DIR=exdir] /options /modifiers\
\n  Default action is to extract files in list, except those in xlist, to exdir\
;\n  file[.zip] may be a wildcard.  %s\n\n",
#ifdef NO_ZIPINFO
          "(ZipInfo mode is disabled in this version.)"
#else
          "Type \"unzip /ZIPINFO\" for ZipInfo-mode usage."
#endif
          );

        fprintf(usagefp, "\
Major options include:\n\
   /[NO]TEST, /LIST, /[NO]SCREEN, /PIPE, /[NO]FRESHEN, /[NO]UPDATE,\n\
   /[NO]COMMENT, /DIRECTORY=directory-spec, /EXCLUDE=(file-spec1,etc.)\n\n\
Modifiers include:\n\
   /BRIEF, /FULL, /[NO]AUTOTEXT, /[NO]TEXT, /[NO]OVERWRITE, /[NO]JUNK,\n\
   /QUIET, /SUPER_QUIET, /[NO]CASE_INSENSITIVE, /[NO]LOWERCASE,\n\
   /[NO]VERSION, /[NO]RESTORE\n\n");

        fprintf(usagefp, "\
Examples (see unzip.doc or \"HELP UNZIP\" for more info):\n   \
unzip edit1 /EXCL=joe.jou /CASE_INSENSITIVE    => extract all files except\n   \
   joe.jou (or JOE.JOU, or any combination of case) from zipfile edit1.zip\n   \
unzip zip201 \"Makefile.VMS\" vms/*.[ch]         => extract VMS Makefile and\n\
      *.c and *.h files; must quote uppercase names if /CASE_INSENS not used\n\
   unzip foo /DIR=tmp:[.test] /JUNK /AUTO /OVER   => extract all files to temp.\
\n      directory without paths, auto-converting text files and overwriting\n");

    } /* end if (zipinfo_mode) */

    if (error)
        return PK_PARAM;
    else
        return PK_COOL;     /* just wanted usage screen: no error */

} /* end function usage() */

#endif /* !SFX */

⌨️ 快捷键说明

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