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}";
155 "echo \"Patch #%d (%s):\"\n"
156 "%s -d < '%s' | patch -p%d %s -s\n"
158 "if [ $STATUS -ne 0 ]; then\n"
161 c, (
const char *) basename(fn),
164 zipper =
_free(zipper);
167 "echo \"Patch #%d (%s):\"\n"
168 "patch -p%d %s -s < '%s'", c, (
const char *) basename(fn),
172 Lurlfn =
_free(Lurlfn);
190 const char *fn, *Lurlfn;
191 static char buf[BUFSIZ];
198 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
216 Lurlfn =
_free(Lurlfn);
221 urltype =
urlPath(Lurlfn, &fn);
231 Lurlfn =
_free(Lurlfn);
240 switch (compressed) {
246 t =
"%{__bzip2} -dc";
258 t =
"%{__unzip} -qq";
265 zipper =
_free(zipper);
275 "if [ $STATUS -ne 0 ]; then\n"
285 Lurlfn =
_free(Lurlfn);
319 if ((rc = poptParseArgvString(line, &argc, &argv))) {
328 optCon = poptGetContext(NULL, argc, argv,
optionsTable, 0);
329 while ((arg = poptGetNextOpt(optCon)) > 0) {
330 optArg = poptGetOptArg(optCon);
336 spec->
lineNum, (optArg ? optArg :
"???"));
339 optCon = poptFreeContext(optCon);
355 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
359 optCon = poptFreeContext(optCon);
367 const char *
name, *version;
369 sprintf(buf,
"%s-%s", name, version);
374 optCon = poptFreeContext(optCon);
379 const char *buildDir;
381 (void)
urlPath(buildDirURL, &buildDir);
382 sprintf(buf,
"cd '%s'", buildDir);
384 buildDirURL =
_free(buildDirURL);
395 sprintf(buf,
MKDIR_P " '%s'\ncd '%s'",
428 {
static const char *fixmacs[] =
429 {
"%{_fixowner}",
"%{_fixgroup}",
"%{_fixperms}", NULL };
432 for (fm = fixmacs; *fm; fm++) {
436 if (fix && *fix !=
'%')
460 int opt_P, opt_p, opt_R, opt_E, opt_F;
462 char buf[BUFSIZ], *bp;
463 int patch_nums[1024];
466 memset(patch_nums, 0,
sizeof(patch_nums));
467 opt_P = opt_p = opt_R = opt_E = opt_F = 0;
471 if (! strchr(
" \t\n", line[6])) {
473 sprintf(buf,
"%%patch -P %s", line + 6);
479 for (bp = buf; (s = strtok(bp,
" \t\n")) != NULL;) {
484 if (!strcmp(s,
"-P")) {
486 }
else if (!strcmp(s,
"-R")) {
488 }
else if (!strcmp(s,
"-E")) {
490 }
else if (!strcmp(s,
"-b")) {
492 opt_b = strtok(NULL,
" \t\n");
495 _(
"line %d: Need arg to %%patch -b: %s\n"),
499 }
else if (!strcmp(s,
"-z")) {
501 opt_b = strtok(NULL,
" \t\n");
504 _(
"line %d: Need arg to %%patch -z: %s\n"),
508 }
else if (!strcmp(s,
"-F")) {
510 const char * fnum = (!strchr(
" \t\n", s[2])
511 ? s+2 : strtok(NULL,
" \t\n"));
514 opt_F = (fnum ? strtol(fnum, &end, 10) : 0);
515 if (! opt_F || *end) {
517 _(
"line %d: Bad arg to %%patch -F: %s\n"),
521 }
else if (!strncmp(s,
"-p",
sizeof(
"-p")-1)) {
523 if (! strchr(
" \t\n", s[2])) {
526 s = strtok(NULL,
" \t\n");
529 _(
"line %d: Need arg to %%patch -p: %s\n"),
536 _(
"line %d: Bad arg to %%patch -p: %s\n"),
542 if (patch_index == 1024) {
546 if (
parseNum(s, &(patch_nums[patch_index]))) {
559 s =
doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E, opt_F);
565 for (x = 0; x < patch_index; x++) {
566 s =
doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E, opt_F);
583 const char *Lmacro, *Lurlfn = NULL;
584 const char *Rmacro, *Rurlfn = NULL;
592 Lurlfn =
rpmGenPath(NULL,
"%{?_sourcedir}", NULL);
593 if (Lurlfn != NULL && *Lurlfn !=
'\0')
595 Lurlfn =
_free(Lurlfn);
601 Lurlfn =
rpmGenPath(NULL,
"%{?_patchdir}", NULL);
602 if (Lurlfn != NULL && *Lurlfn !=
'\0')
604 Lurlfn =
_free(Lurlfn);
610 Lurlfn =
rpmGenPath(NULL,
"%{?_icondir}", NULL);
611 if (Lurlfn != NULL && *Lurlfn !=
'\0')
613 Lurlfn =
_free(Lurlfn);
619 for (sp = spec->
sources; sp != NULL; sp = sp->
next) {
622 Rmacro =
"%{_Rsourcedir}/";
623 Lmacro =
"%{_sourcedir}/";
626 Rmacro =
"%{_Rpatchdir}/";
627 Lmacro =
"%{_patchdir}/";
630 Rmacro =
"%{_Ricondir}/";
631 Lmacro =
"%{_icondir}/";
636 rc =
Lstat(Lurlfn, &st);
639 if (
errno != ENOENT) {
648 if (Rurlfn == NULL || *Rurlfn ==
'%' || !strcmp(Lurlfn, Rurlfn)) {
650 Lurlfn, strerror(
errno));
664 Lurlfn =
_free(Lurlfn);
665 Rurlfn =
_free(Rurlfn);
674 int nextPart, res, rc;
676 char **lines, **saveLines;
678 if (spec->
prep != NULL) {
714 for (lines = saveLines; *lines; lines++) {
717 if (! strncmp(*lines,
"%setup",
sizeof(
"%setup")-1)) {
719 }
else if (! strncmp(*lines,
"%patch",
sizeof(
"%patch")-1)) {
725 if (res && !spec->
force) {