Introduce 3 new options for pkg_create(1), -x for using basic

regular expressions for pkg-name, -E for extended regexps and -G for
exact matching.

Submitted by:	mux
MFC after:	3 days
This commit is contained in:
Kirill Ponomarev 2005-11-08 20:48:26 +00:00
parent 4e7e0183e1
commit 1d03b1a1ae
4 changed files with 61 additions and 7 deletions

View File

@ -23,6 +23,7 @@
#ifndef _INST_CREATE_H_INCLUDE
#define _INST_CREATE_H_INCLUDE
extern match_t MatchType;
extern char *Prefix;
extern char *Comment;
extern char *Desc;

View File

@ -16,8 +16,9 @@ __FBSDID("$FreeBSD$");
#include "lib.h"
#include "create.h"
static char Options[] = "YNORhjvyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
static char Options[] = "EGYNORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
match_t MatchType = MATCH_GLOB;
char *Prefix = NULL;
char *Comment = NULL;
char *Desc = NULL;
@ -57,6 +58,18 @@ main(int argc, char **argv)
Verbose = TRUE;
break;
case 'x':
MatchType = MATCH_REGEX;
break;
case 'E':
MatchType = MATCH_EREGEX;
break;
case 'G':
MatchType = MATCH_EXACT;
break;
case 'N':
AutoAnswer = NO;
break;
@ -216,6 +229,6 @@ usage()
" [-D displayfile] [-m mtreefile] [-o origin] ",
" [-s srcdir] [-S basedir] ",
" -c comment -d description -f packlist pkg-filename",
" pkg_create [-YNhvyzR] -b pkg-name [pkg-filename]");
" pkg_create [-EGYNhvxyzR] -b pkg-name [pkg-filename]");
exit(1);
}

View File

@ -81,9 +81,40 @@ pkg_perform(char **pkgs)
suf = "tar";
if (InstalledPkg != NULL) {
if (!Recursive)
return (create_from_installed(InstalledPkg, pkg, suf));
return (create_from_installed_recursive(pkg, suf));
char *pkgglob[] = { InstalledPkg, NULL };
char **matched, **pkgs;
int i, error;
pkgs = pkgglob;
if (MatchType != MATCH_EXACT) {
matched = matchinstalled(MatchType, pkgs, &error);
if (!error && matched != NULL)
pkgs = matched;
else if (MatchType != MATCH_GLOB)
errx(1, "no packages match pattern");
}
/*
* Is there is only one installed package matching the pattern,
* we need to respect the optional pkg-filename parameter. If,
* however, the pattern matches several packages, this parameter
* makes no sense and is ignored.
*/
if (pkgs[1] == NULL) {
if (pkg == InstalledPkg)
pkg = *pkgs;
InstalledPkg = *pkgs;
if (!Recursive)
return (create_from_installed(InstalledPkg, pkg, suf));
return (create_from_installed_recursive(pkg, suf));
}
for (i = 0; pkgs[i] != NULL; i++) {
InstalledPkg = pkg = pkgs[i];
if (!Recursive)
create_from_installed(pkg, pkg, suf);
else
create_from_installed_recursive(pkg, suf);
}
return TRUE;
}
get_dash_string(&Comment);

View File

@ -23,7 +23,7 @@
.\" [jkh] Took John's changes back and made some additional extensions for
.\" better integration with FreeBSD's new ports collection.
.\"
.Dd June 14, 2005
.Dd November 8, 2005
.Dt PKG_CREATE 1
.Os
.Sh NAME
@ -52,7 +52,7 @@
.Fl f Ar packlist
.Ar pkg-filename
.Nm
.Op Fl YNRhvy
.Op Fl EGYNRhvxy
.Fl b Ar pkg-name
.Op Ar pkg-filename
.Sh DESCRIPTION
@ -341,6 +341,15 @@ also create package files for all packages required by
Resulting archive(s) will be created in the current directory
and named using name of the respective package with appropriate
extraction suffix applied.
.It Fl x
Use basic regular expressions for
.Ar pkg-name .
.It Fl E
Use extended (modern) regular expressions for
.Ar pkg-name .
.It Fl G
Use exact matching for
.Ar pkg-name .
.El
.Sh PACKING LIST DETAILS
The