23 { NULL,
'a', POPT_ARG_STRING, NULL,
'a', NULL, NULL},
24 { NULL,
'b', POPT_ARG_STRING, NULL,
'b', NULL, NULL},
25 { NULL,
'c', 0, &
createDir, 0, NULL, NULL},
26 { NULL,
'D', 0, &
leaveDirs, 0, NULL, NULL},
27 { NULL,
'n', POPT_ARG_STRING, &
dirName, 0, NULL, NULL},
29 { NULL,
'q', 0, &
quietly, 0, NULL, NULL},
30 { 0, 0, 0, 0, 0, NULL, NULL}
44 if (
Lstat(urlfn, &sb)) {
46 urlfn, strerror(
errno));
70 static char *
doPatch(
Spec spec,
int c,
int strip,
const char *db,
71 int reverse,
int removeEmpties,
int fuzz)
75 const char *fn, *Lurlfn;
76 static char buf[BUFSIZ];
77 char args[BUFSIZ], *t = args;
84 #if HAVE_OLDPATCH_21 == 0
91 sprintf(t,
"%10.10d", fuzz);
99 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
112 Lurlfn =
_free(Lurlfn);
117 urltype =
urlPath(Lurlfn, &fn);
127 Lurlfn =
_free(Lurlfn);
135 switch (compressed) {
140 zipper =
"%{__gzip}";
143 zipper =
"%{__bzip2}";
146 zipper =
"%{__lzop}";
149 zipper =
"%{__lzma}";
158 "echo \"Patch #%d (%s):\"\n"
159 "%s -d < '%s' | patch -p%d %s -s\n"
161 "if [ $STATUS -ne 0 ]; then\n"
164 c, (
const char *) basename(fn),
167 zipper =
_free(zipper);
170 "echo \"Patch #%d (%s):\"\n"
171 "patch -p%d %s -s < '%s'", c, (
const char *) basename(fn),
175 Lurlfn =
_free(Lurlfn);
193 const char *fn, *Lurlfn;
194 static char buf[BUFSIZ];
201 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
219 Lurlfn =
_free(Lurlfn);
224 urltype =
urlPath(Lurlfn, &fn);
234 Lurlfn =
_free(Lurlfn);
243 switch (compressed) {
249 t =
"%{__bzip2} -dc";
264 t =
"%{__unzip} -qq";
271 zipper =
_free(zipper);
281 "if [ $STATUS -ne 0 ]; then\n"
291 Lurlfn =
_free(Lurlfn);
325 if ((rc = poptParseArgvString(line, &argc, &argv))) {
334 optCon = poptGetContext(NULL, argc, argv,
optionsTable, 0);
335 while ((arg = poptGetNextOpt(optCon)) > 0) {
336 optArg = poptGetOptArg(optCon);
342 spec->
lineNum, (optArg ? optArg :
"???"));
345 optCon = poptFreeContext(optCon);
361 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
365 optCon = poptFreeContext(optCon);
373 const char *
name, *version;
375 sprintf(buf,
"%s-%s", name, version);
380 optCon = poptFreeContext(optCon);
385 const char *buildDir;
387 (void)
urlPath(buildDirURL, &buildDir);
388 sprintf(buf,
"cd '%s'", buildDir);
390 buildDirURL =
_free(buildDirURL);
401 sprintf(buf,
MKDIR_P " '%s'\ncd '%s'",
434 {
static const char *fixmacs[] =
435 {
"%{_fixowner}",
"%{_fixgroup}",
"%{_fixperms}", NULL };
438 for (fm = fixmacs; *fm; fm++) {
442 if (fix && *fix !=
'%')
466 int opt_P, opt_p, opt_R, opt_E, opt_F;
468 char buf[BUFSIZ], *bp;
469 int patch_nums[1024];
472 memset(patch_nums, 0,
sizeof(patch_nums));
473 opt_P = opt_p = opt_R = opt_E = opt_F = 0;
477 if (! strchr(
" \t\n", line[6])) {
479 sprintf(buf,
"%%patch -P %s", line + 6);
485 for (bp = buf; (s = strtok(bp,
" \t\n")) != NULL;) {
490 if (!strcmp(s,
"-P")) {
492 }
else if (!strcmp(s,
"-R")) {
494 }
else if (!strcmp(s,
"-E")) {
496 }
else if (!strcmp(s,
"-b")) {
498 opt_b = strtok(NULL,
" \t\n");
501 _(
"line %d: Need arg to %%patch -b: %s\n"),
505 }
else if (!strcmp(s,
"-z")) {
507 opt_b = strtok(NULL,
" \t\n");
510 _(
"line %d: Need arg to %%patch -z: %s\n"),
514 }
else if (!strcmp(s,
"-F")) {
516 const char * fnum = (!strchr(
" \t\n", s[2])
517 ? s+2 : strtok(NULL,
" \t\n"));
520 opt_F = (fnum ? strtol(fnum, &end, 10) : 0);
521 if (! opt_F || *end) {
523 _(
"line %d: Bad arg to %%patch -F: %s\n"),
527 }
else if (!strncmp(s,
"-p",
sizeof(
"-p")-1)) {
529 if (! strchr(
" \t\n", s[2])) {
532 s = strtok(NULL,
" \t\n");
535 _(
"line %d: Need arg to %%patch -p: %s\n"),
542 _(
"line %d: Bad arg to %%patch -p: %s\n"),
548 if (patch_index == 1024) {
552 if (
parseNum(s, &(patch_nums[patch_index]))) {
565 s =
doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E, opt_F);
571 for (x = 0; x < patch_index; x++) {
572 s =
doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E, opt_F);
589 const char *Lmacro, *Lurlfn = NULL;
590 const char *Rmacro, *Rurlfn = NULL;
598 Lurlfn =
rpmGenPath(NULL,
"%{?_sourcedir}", NULL);
599 if (Lurlfn != NULL && *Lurlfn !=
'\0')
601 Lurlfn =
_free(Lurlfn);
607 Lurlfn =
rpmGenPath(NULL,
"%{?_patchdir}", NULL);
608 if (Lurlfn != NULL && *Lurlfn !=
'\0')
610 Lurlfn =
_free(Lurlfn);
616 Lurlfn =
rpmGenPath(NULL,
"%{?_icondir}", NULL);
617 if (Lurlfn != NULL && *Lurlfn !=
'\0')
619 Lurlfn =
_free(Lurlfn);
625 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
628 Rmacro =
"%{_Rsourcedir}/";
629 Lmacro =
"%{_sourcedir}/";
632 Rmacro =
"%{_Rpatchdir}/";
633 Lmacro =
"%{_patchdir}/";
636 Rmacro =
"%{_Ricondir}/";
637 Lmacro =
"%{_icondir}/";
642 rc =
Lstat(Lurlfn, &st);
645 if (
errno != ENOENT) {
654 if (Rurlfn == NULL || *Rurlfn ==
'%' || !strcmp(Lurlfn, Rurlfn)) {
656 Lurlfn, strerror(
errno));
670 Lurlfn =
_free(Lurlfn);
671 Rurlfn =
_free(Rurlfn);
680 int nextPart, res, rc;
682 char **lines, **saveLines;
684 if (spec->
prep != NULL) {
720 for (lines = saveLines; *lines; lines++) {
723 if (! strncmp(*lines,
"%setup",
sizeof(
"%setup")-1)) {
725 }
else if (! strncmp(*lines,
"%patch",
sizeof(
"%patch")-1)) {
731 if (res && !spec->
force) {