2002-03-25 23:16:26 +03:00
/** \ingroup rpmbuild
* \ file build / parsePrep . c
* Parse % prep section from spec file .
*/
# include "system.h"
2002-03-26 01:02:39 +03:00
# include "rpmio_internal.h"
# include "rpmbuild.h"
2002-03-25 23:16:26 +03:00
# include "debug.h"
/*@access StringBuf @*/ /* compared with NULL */
/* These have to be global to make up for stupid compilers */
/*@unchecked@*/
static int leaveDirs , skipDefaultAction ;
/*@unchecked@*/
2006-11-19 02:44:03 +03:00
static int createDir , quietly , verbosely ;
2002-03-25 23:16:26 +03:00
/*@unchecked@*/
/*@observer@*/ /*@null@*/ static const char * dirName = NULL ;
/*@unchecked@*/
/*@observer@*/ static struct poptOption optionsTable [ ] = {
{ NULL , ' a ' , POPT_ARG_STRING , NULL , ' a ' , NULL , NULL } ,
{ NULL , ' b ' , POPT_ARG_STRING , NULL , ' b ' , NULL , NULL } ,
{ NULL , ' c ' , 0 , & createDir , 0 , NULL , NULL } ,
{ NULL , ' D ' , 0 , & leaveDirs , 0 , NULL , NULL } ,
{ NULL , ' n ' , POPT_ARG_STRING , & dirName , 0 , NULL , NULL } ,
{ NULL , ' T ' , 0 , & skipDefaultAction , 0 , NULL , NULL } ,
{ NULL , ' q ' , 0 , & quietly , 0 , NULL , NULL } ,
2006-11-19 02:44:03 +03:00
{ NULL , ' v ' , 0 , & verbosely , 0 , NULL , NULL } ,
2002-03-25 23:16:26 +03:00
{ 0 , 0 , 0 , 0 , 0 , NULL , NULL }
} ;
/**
* Check that file owner and group are known .
* @ param urlfn file url
* @ return 0 on success
*/
static int checkOwners ( const char * urlfn )
/*@globals fileSystem @*/
/*@modifies fileSystem @*/
{
struct stat sb ;
if ( Lstat ( urlfn , & sb ) ) {
rpmError ( RPMERR_BADSPEC , _ ( " Bad source: %s: %s \n " ) ,
urlfn , strerror ( errno ) ) ;
return RPMERR_BADSPEC ;
}
if ( ! getUname ( sb . st_uid ) | | ! getGname ( sb . st_gid ) ) {
rpmError ( RPMERR_BADSPEC , _ ( " Bad owner/group: %s \n " ) , urlfn ) ;
return RPMERR_BADSPEC ;
}
return 0 ;
}
/**
* Expand % patchN macro into % prep scriptlet .
* @ param spec build info
* @ param c patch index
* @ param strip patch level ( i . e . patch - p argument )
* @ param db saved file suffix ( i . e . patch - - suffix argument )
* @ param reverse include - R ?
* @ param removeEmpties include - E ?
* @ return expanded % patch macro ( NULL on error )
*/
/*@observer@*/ static char * doPatch ( Spec spec , int c , int strip , const char * db ,
2006-11-19 02:35:05 +03:00
int reverse , int removeEmpties , int silent )
2002-03-25 23:16:26 +03:00
/*@globals rpmGlobalMacroContext,
fileSystem @ */
/*@modifies rpmGlobalMacroContext, fileSystem @*/
{
struct Source * sp ;
for ( sp = spec - > sources ; sp ! = NULL ; sp = sp - > next ) {
if ( ( sp - > flags & RPMBUILD_ISPATCH ) & & ( sp - > num = = c ) ) {
break ;
}
}
if ( sp = = NULL ) {
rpmError ( RPMERR_BADSPEC , _ ( " No patch number %d \n " ) , c ) ;
return NULL ;
}
2009-09-24 11:09:30 +04:00
const char * urlfn = rpmGetPath ( " %{_sourcedir}/ " , sp - > source , NULL ) ;
2002-03-25 23:16:26 +03:00
2009-09-24 11:09:30 +04:00
char args [ BUFSIZ ] ;
sprintf ( args , " -p%d " , strip ) ;
2006-11-19 02:35:05 +03:00
if ( silent )
strcat ( args , " -s " ) ;
2002-03-25 23:16:26 +03:00
if ( db ) {
2009-09-24 11:09:30 +04:00
strcat ( args , " -b --suffix " ) ;
2002-03-25 23:16:26 +03:00
strcat ( args , db ) ;
}
2009-09-24 11:09:30 +04:00
if ( reverse )
2002-03-25 23:16:26 +03:00
strcat ( args , " -R " ) ;
2009-09-24 11:09:30 +04:00
if ( removeEmpties )
2002-03-25 23:16:26 +03:00
strcat ( args , " -E " ) ;
2009-09-24 11:09:30 +04:00
rpmCompressedMagic compressed = COMPRESSED_NOT ;
2002-03-25 23:16:26 +03:00
/* XXX On non-build parse's, file cannot be stat'd or read */
if ( ! spec - > force & & ( isCompressed ( urlfn , & compressed ) | | checkOwners ( urlfn ) ) ) {
urlfn = _free ( urlfn ) ;
return NULL ;
}
2009-09-24 11:09:30 +04:00
const char * fn = NULL ;
int urltype = urlPath ( urlfn , & fn ) ;
2002-03-25 23:16:26 +03:00
switch ( urltype ) {
case URL_IS_HTTP : /* XXX WRONG WRONG WRONG */
case URL_IS_FTP : /* XXX WRONG WRONG WRONG */
case URL_IS_PATH :
case URL_IS_UNKNOWN :
break ;
case URL_IS_DASH :
urlfn = _free ( urlfn ) ;
return NULL ;
/*@notreached@*/ break ;
}
2009-09-24 11:09:30 +04:00
const char * t ;
const char * patcher = rpmGetPath ( " %{__patch} " , NULL ) ;
char cmd [ BUFSIZ ] ;
2002-03-26 03:00:27 +03:00
if ( compressed ! = COMPRESSED_NOT ) {
2009-09-24 11:09:30 +04:00
switch ( compressed ) {
default : /* XXX can't happen */
case COMPRESSED_OTHER :
t = " %{__gzip} -dc " ;
break ;
case COMPRESSED_BZIP2 :
t = " %{__bzip2} -dc " ;
break ;
case COMPRESSED_ZIP :
t = " %{__unzip} -qq -p " ;
break ;
case COMPRESSED_LZMA :
t = " %{__lzma} -dc " ;
break ;
case COMPRESSED_XZ :
t = " %{__xz} -dc " ;
break ;
2002-03-26 03:00:27 +03:00
}
2009-09-24 11:09:30 +04:00
const char * zipper = rpmGetPath ( t , NULL ) ;
sprintf ( cmd , " %s '%s' | %s %s \n " , zipper , fn , patcher , args ) ;
2002-03-25 23:16:26 +03:00
zipper = _free ( zipper ) ;
} else {
2009-09-24 11:09:30 +04:00
sprintf ( cmd , " %s %s < '%s' \n " , patcher , args , fn ) ;
2002-03-25 23:16:26 +03:00
}
2002-03-26 03:00:27 +03:00
patcher = _free ( patcher ) ;
2009-09-24 11:09:30 +04:00
static char buf [ BUFSIZ ] ;
sprintf ( buf , " echo 'Patch #%d (%s):' \n " , c , basename ( fn ) ) ;
strcat ( buf , cmd ) ;
2002-03-25 23:16:26 +03:00
urlfn = _free ( urlfn ) ;
return buf ;
}
/**
* Expand % setup macro into % prep scriptlet .
* @ param spec build info
* @ param c source index
* @ param quietly should - vv be omitted from tar ?
* @ return expanded % setup macro ( NULL on error )
*/
/*@observer@*/ static const char * doUntar ( Spec spec , int c , int quietly )
/*@globals rpmGlobalMacroContext,
fileSystem @ */
/*@modifies rpmGlobalMacroContext, fileSystem @*/
{
struct Source * sp ;
for ( sp = spec - > sources ; sp ! = NULL ; sp = sp - > next ) {
if ( ( sp - > flags & RPMBUILD_ISSOURCE ) & & ( sp - > num = = c ) ) {
break ;
}
}
if ( sp = = NULL ) {
rpmError ( RPMERR_BADSPEC , _ ( " No source number %d \n " ) , c ) ;
return NULL ;
}
2009-09-24 11:09:30 +04:00
const char * urlfn = rpmGetPath ( " %{_sourcedir}/ " , sp - > source , NULL ) ;
2002-03-25 23:16:26 +03:00
# ifdef AUTOFETCH_NOT /* XXX don't expect this code to be enabled */
/* XXX
* XXX If nosource file doesn ' t exist , try to fetch from url .
* XXX TODO : add a " --fetch " enabler .
*/
if ( sp - > flags & RPMTAG_NOSOURCE & & autofetchnosource ) {
struct stat st ;
int rc ;
if ( Lstat ( urlfn , & st ) ! = 0 & & errno = = ENOENT & &
urlIsUrl ( sp - > fullSource ) ! = URL_IS_UNKNOWN ) {
if ( ( rc = urlGetFile ( sp - > fullSource , urlfn ) ) ! = 0 ) {
rpmError ( RPMERR_BADFILENAME ,
_ ( " Couldn't download nosource %s: %s \n " ) ,
sp - > fullSource , ftpStrerror ( rc ) ) ;
return NULL ;
}
}
}
# endif
2009-09-24 11:09:30 +04:00
rpmCompressedMagic compressed = COMPRESSED_NOT ;
2002-03-25 23:16:26 +03:00
/* XXX On non-build parse's, file cannot be stat'd or read */
if ( ! spec - > force & & ( isCompressed ( urlfn , & compressed ) | | checkOwners ( urlfn ) ) ) {
urlfn = _free ( urlfn ) ;
return NULL ;
}
2009-09-24 11:09:30 +04:00
const char * fn = NULL ;
int urltype = urlPath ( urlfn , & fn ) ;
2002-03-25 23:16:26 +03:00
switch ( urltype ) {
case URL_IS_HTTP : /* XXX WRONG WRONG WRONG */
case URL_IS_FTP : /* XXX WRONG WRONG WRONG */
case URL_IS_PATH :
case URL_IS_UNKNOWN :
break ;
case URL_IS_DASH :
urlfn = _free ( urlfn ) ;
return NULL ;
/*@notreached@*/ break ;
}
2009-09-24 11:09:30 +04:00
const char * t ;
if ( rpmIsVerbose ( ) & & ! quietly )
t = " %{__tar} -xvvf " ;
else
t = " %{__tar} -xf " ;
const char * tar = rpmGetPath ( t , NULL ) ;
char cmd [ BUFSIZ ] ;
2002-03-25 23:16:26 +03:00
if ( compressed ! = COMPRESSED_NOT ) {
2009-09-24 11:09:30 +04:00
switch ( compressed ) {
default : /* XXX can't happen */
case COMPRESSED_OTHER :
t = " %{__gzip} -dc " ;
break ;
case COMPRESSED_BZIP2 :
t = " %{__bzip2} -dc " ;
break ;
case COMPRESSED_ZIP :
if ( rpmIsVerbose ( ) & & ! quietly )
t = " %{__unzip} " ;
else
t = " %{__unzip} -qq " ;
break ;
case COMPRESSED_LZMA :
t = " %{__lzma} -dc " ;
break ;
case COMPRESSED_XZ :
t = " %{__xz} -dc " ;
break ;
2002-03-25 23:16:26 +03:00
}
2009-09-24 11:09:30 +04:00
const char * zipper = rpmGetPath ( t , NULL ) ;
if ( compressed = = COMPRESSED_ZIP )
sprintf ( cmd , " %s '%s' \n " , zipper , fn ) ;
else
sprintf ( cmd , " %s '%s' | %s - \n " , zipper , fn , tar ) ;
zipper = _free ( zipper ) ;
} else {
sprintf ( cmd , " %s '%s' \n " , tar , fn ) ;
2002-03-25 23:16:26 +03:00
}
2009-09-24 11:09:30 +04:00
tar = _free ( tar ) ;
static char buf [ BUFSIZ ] ;
sprintf ( buf , " echo 'Source #%d (%s):' \n " , c , basename ( fn ) ) ;
strcat ( buf , cmd ) ;
2002-03-25 23:16:26 +03:00
urlfn = _free ( urlfn ) ;
return buf ;
}
/**
* Parse % setup macro .
* @ todo FIXME : Option - q broken when not immediately after % setup .
* @ param spec build info
* @ param line current line from spec file
* @ return 0 on success
*/
static int doSetupMacro ( Spec spec , char * line )
/*@globals rpmGlobalMacroContext,
fileSystem @ */
/*@modifies spec->buildSubdir, spec->macros, spec->prep,
rpmGlobalMacroContext , fileSystem @ */
{
char buf [ BUFSIZ ] ;
StringBuf before ;
StringBuf after ;
poptContext optCon ;
int argc ;
const char * * argv ;
int arg ;
const char * optArg ;
int rc ;
int num ;
/*@-mods@*/
leaveDirs = skipDefaultAction = 0 ;
2006-11-19 02:44:03 +03:00
createDir = verbosely = 0 ;
quietly = 1 ;
2002-03-25 23:16:26 +03:00
dirName = NULL ;
/*@=mods@*/
if ( ( rc = poptParseArgvString ( line , & argc , & argv ) ) ) {
rpmError ( RPMERR_BADSPEC , _ ( " Error parsing %%setup: %s \n " ) ,
poptStrerror ( rc ) ) ;
return RPMERR_BADSPEC ;
}
before = newStringBuf ( ) ;
after = newStringBuf ( ) ;
optCon = poptGetContext ( NULL , argc , argv , optionsTable , 0 ) ;
while ( ( arg = poptGetNextOpt ( optCon ) ) > 0 ) {
optArg = poptGetOptArg ( optCon ) ;
/* We only parse -a and -b here */
if ( parseNum ( optArg , & num ) ) {
rpmError ( RPMERR_BADSPEC , _ ( " line %d: Bad arg to %%setup: %s \n " ) ,
spec - > lineNum , ( optArg ? optArg : " ??? " ) ) ;
before = freeStringBuf ( before ) ;
after = freeStringBuf ( after ) ;
optCon = poptFreeContext ( optCon ) ;
argv = _free ( argv ) ;
return RPMERR_BADSPEC ;
}
2006-11-19 02:44:03 +03:00
{ const char * chptr = doUntar ( spec , num , verbosely ? 0 : quietly ) ;
2002-03-25 23:16:26 +03:00
if ( chptr = = NULL )
return RPMERR_BADSPEC ;
appendLineStringBuf ( ( arg = = ' a ' ? after : before ) , chptr ) ;
}
}
if ( arg < - 1 ) {
rpmError ( RPMERR_BADSPEC , _ ( " line %d: Bad %%setup option %s: %s \n " ) ,
spec - > lineNum ,
poptBadOption ( optCon , POPT_BADOPTION_NOALIAS ) ,
poptStrerror ( arg ) ) ;
before = freeStringBuf ( before ) ;
after = freeStringBuf ( after ) ;
optCon = poptFreeContext ( optCon ) ;
argv = _free ( argv ) ;
return RPMERR_BADSPEC ;
}
if ( dirName ) {
spec - > buildSubdir = xstrdup ( dirName ) ;
} else {
const char * name , * version ;
( void ) headerNVR ( spec - > packages - > header , & name , & version , NULL ) ;
2002-03-26 03:00:27 +03:00
snprintf ( buf , sizeof ( buf ) , " %s-%s " , name , version ) ;
2002-03-25 23:16:26 +03:00
spec - > buildSubdir = xstrdup ( buf ) ;
}
addMacro ( spec - > macros , " buildsubdir " , NULL , spec - > buildSubdir , RMIL_SPEC ) ;
optCon = poptFreeContext ( optCon ) ;
argv = _free ( argv ) ;
/* cd to the build dir */
{ const char * buildDirURL = rpmGenPath ( spec - > rootURL , " %{_builddir} " , " " ) ;
const char * buildDir ;
( void ) urlPath ( buildDirURL , & buildDir ) ;
2011-08-06 19:38:30 +04:00
snprintf ( buf , sizeof ( buf ) , " cd '%s' " , buildDir ) ;
2002-03-25 23:16:26 +03:00
appendLineStringBuf ( spec - > prep , buf ) ;
buildDirURL = _free ( buildDirURL ) ;
}
/* delete any old sources */
if ( ! leaveDirs ) {
2011-08-06 19:38:30 +04:00
snprintf ( buf , sizeof ( buf ) , " rm -rf '%s' " , spec - > buildSubdir ) ;
2002-03-25 23:16:26 +03:00
appendLineStringBuf ( spec - > prep , buf ) ;
}
/* if necessary, create and cd into the proper dir */
if ( createDir ) {
2011-08-06 19:38:30 +04:00
snprintf ( buf , sizeof ( buf ) , MKDIR_P " '%s' \n cd '%s' " ,
2002-03-25 23:16:26 +03:00
spec - > buildSubdir , spec - > buildSubdir ) ;
appendLineStringBuf ( spec - > prep , buf ) ;
}
/* do the default action */
if ( ! createDir & & ! skipDefaultAction ) {
2006-11-19 02:44:03 +03:00
const char * chptr = doUntar ( spec , 0 , verbosely ? 0 : quietly ) ;
2002-03-25 23:16:26 +03:00
if ( ! chptr )
return RPMERR_BADSPEC ;
appendLineStringBuf ( spec - > prep , chptr ) ;
}
appendStringBuf ( spec - > prep , getStringBuf ( before ) ) ;
before = freeStringBuf ( before ) ;
if ( ! createDir ) {
2011-08-06 19:38:30 +04:00
snprintf ( buf , sizeof ( buf ) , " cd '%s' " , spec - > buildSubdir ) ;
2002-03-25 23:16:26 +03:00
appendLineStringBuf ( spec - > prep , buf ) ;
}
if ( createDir & & ! skipDefaultAction ) {
2006-11-19 02:44:03 +03:00
const char * chptr = doUntar ( spec , 0 , verbosely ? 0 : quietly ) ;
2002-03-25 23:16:26 +03:00
if ( chptr = = NULL )
return RPMERR_BADSPEC ;
appendLineStringBuf ( spec - > prep , chptr ) ;
}
appendStringBuf ( spec - > prep , getStringBuf ( after ) ) ;
after = freeStringBuf ( after ) ;
/* XXX FIXME: owner & group fixes were conditioned on !geteuid() */
/* Fix the owner, group, and permissions of the setup build tree */
{ /*@observer@*/ static const char * fixmacs [ ] =
2005-10-06 05:21:27 +04:00
{ " %{?_fixowner} " , " %{?_fixgroup} " , " %{?_fixperms} " , NULL } ;
2002-03-25 23:16:26 +03:00
const char * * fm ;
for ( fm = fixmacs ; * fm ; fm + + ) {
const char * fix ;
/*@-nullpass@*/
fix = rpmExpand ( * fm , " . " , NULL ) ;
/*@=nullpass@*/
2005-10-06 05:21:27 +04:00
if ( fix & & * fix ! = ' ' )
2002-03-25 23:16:26 +03:00
appendLineStringBuf ( spec - > prep , fix ) ;
fix = _free ( fix ) ;
}
}
return 0 ;
}
/**
* Parse % patch line .
* @ param spec build info
* @ param line current line from spec file
* @ return 0 on success
*/
static int doPatchMacro ( Spec spec , char * line )
/*@globals rpmGlobalMacroContext,
fileSystem @ */
/*@modifies spec->prep, rpmGlobalMacroContext, fileSystem @*/
{
char * opt_b ;
2006-11-19 02:35:05 +03:00
int opt_P , opt_p , opt_R , opt_E , opt_s ;
2002-03-25 23:16:26 +03:00
char * s ;
char buf [ BUFSIZ ] , * bp ;
int patch_nums [ 1024 ] ; /* XXX - we can only handle 1024 patches! */
int patch_index , x ;
memset ( patch_nums , 0 , sizeof ( patch_nums ) ) ;
2006-11-19 02:35:05 +03:00
opt_P = opt_p = opt_R = opt_E = opt_s = 0 ;
2002-03-25 23:16:26 +03:00
opt_b = NULL ;
patch_index = 0 ;
if ( ! strchr ( " \t \n " , line [ 6 ] ) ) {
/* %patchN */
2002-03-26 03:00:27 +03:00
snprintf ( buf , sizeof ( buf ) , " %%patch -P %s " , line + 6 ) ;
2002-03-25 23:16:26 +03:00
} else {
strcpy ( buf , line ) ;
}
/*@-internalglobs@*/ /* FIX: strtok has state */
for ( bp = buf ; ( s = strtok ( bp , " \t \n " ) ) ! = NULL ; ) {
if ( bp ) { /* remove 1st token (%patch) */
bp = NULL ;
continue ;
}
if ( ! strcmp ( s , " -P " ) ) {
opt_P = 1 ;
} else if ( ! strcmp ( s , " -R " ) ) {
opt_R = 1 ;
} else if ( ! strcmp ( s , " -E " ) ) {
opt_E = 1 ;
2006-11-19 02:35:05 +03:00
} else if ( ! strcmp ( s , " -s " ) ) {
opt_s = 1 ;
2002-03-25 23:16:26 +03:00
} else if ( ! strcmp ( s , " -b " ) ) {
/* orig suffix */
opt_b = strtok ( NULL , " \t \n " ) ;
if ( ! opt_b ) {
rpmError ( RPMERR_BADSPEC ,
_ ( " line %d: Need arg to %%patch -b: %s \n " ) ,
spec - > lineNum , spec - > line ) ;
return RPMERR_BADSPEC ;
}
} else if ( ! strcmp ( s , " -z " ) ) {
/* orig suffix */
opt_b = strtok ( NULL , " \t \n " ) ;
if ( ! opt_b ) {
rpmError ( RPMERR_BADSPEC ,
_ ( " line %d: Need arg to %%patch -z: %s \n " ) ,
spec - > lineNum , spec - > line ) ;
return RPMERR_BADSPEC ;
}
} else if ( ! strncmp ( s , " -p " , sizeof ( " -p " ) - 1 ) ) {
/* unfortunately, we must support -pX */
if ( ! strchr ( " \t \n " , s [ 2 ] ) ) {
s = s + 2 ;
} else {
s = strtok ( NULL , " \t \n " ) ;
if ( s = = NULL ) {
rpmError ( RPMERR_BADSPEC ,
_ ( " line %d: Need arg to %%patch -p: %s \n " ) ,
spec - > lineNum , spec - > line ) ;
return RPMERR_BADSPEC ;
}
}
if ( parseNum ( s , & opt_p ) ) {
rpmError ( RPMERR_BADSPEC ,
_ ( " line %d: Bad arg to %%patch -p: %s \n " ) ,
spec - > lineNum , spec - > line ) ;
return RPMERR_BADSPEC ;
}
} else {
/* Must be a patch num */
if ( patch_index = = 1024 ) {
rpmError ( RPMERR_BADSPEC , _ ( " Too many patches! \n " ) ) ;
return RPMERR_BADSPEC ;
}
if ( parseNum ( s , & ( patch_nums [ patch_index ] ) ) ) {
rpmError ( RPMERR_BADSPEC , _ ( " line %d: Bad arg to %%patch: %s \n " ) ,
spec - > lineNum , spec - > line ) ;
return RPMERR_BADSPEC ;
}
patch_index + + ;
}
}
/*@=internalglobs@*/
/* All args processed */
if ( ! opt_P ) {
2006-11-19 02:35:05 +03:00
s = doPatch ( spec , 0 , opt_p , opt_b , opt_R , opt_E , opt_s ) ;
2002-03-25 23:16:26 +03:00
if ( s = = NULL )
return RPMERR_BADSPEC ;
appendLineStringBuf ( spec - > prep , s ) ;
}
for ( x = 0 ; x < patch_index ; x + + ) {
2006-11-19 02:35:05 +03:00
s = doPatch ( spec , patch_nums [ x ] , opt_p , opt_b , opt_R , opt_E , opt_s ) ;
2002-03-25 23:16:26 +03:00
if ( s = = NULL )
return RPMERR_BADSPEC ;
appendLineStringBuf ( spec - > prep , s ) ;
}
return 0 ;
}
int parsePrep ( Spec spec )
{
int nextPart , res , rc ;
StringBuf sb ;
char * * lines , * * saveLines ;
if ( spec - > prep ! = NULL ) {
rpmError ( RPMERR_BADSPEC , _ ( " line %d: second %%prep \n " ) , spec - > lineNum ) ;
return RPMERR_BADSPEC ;
}
spec - > prep = newStringBuf ( ) ;
/* There are no options to %prep */
2005-10-06 22:21:40 +04:00
if ( ( rc = readLine ( spec , STRIP_NOTHING ) ) = = 1 ) {
2002-03-25 23:16:26 +03:00
return PART_NONE ;
}
if ( rc )
return rc ;
sb = newStringBuf ( ) ;
while ( ! ( nextPart = isPart ( spec - > line ) ) ) {
/* Need to expand the macros inline. That way we */
/* can give good line number information on error. */
appendStringBuf ( sb , spec - > line ) ;
2005-10-06 22:21:40 +04:00
if ( ( rc = readLine ( spec , STRIP_NOTHING ) ) = = 1 ) {
2002-03-25 23:16:26 +03:00
nextPart = PART_NONE ;
break ;
}
if ( rc )
return rc ;
}
2002-03-26 02:09:32 +03:00
if ( ! spec - > preprocess_mode ) {
2002-03-25 23:16:26 +03:00
saveLines = splitString ( getStringBuf ( sb ) , strlen ( getStringBuf ( sb ) ) , ' \n ' ) ;
/*@-usereleased@*/
for ( lines = saveLines ; * lines ; lines + + ) {
res = 0 ;
if ( ! strncmp ( * lines , " %setup " , sizeof ( " %setup " ) - 1 ) ) {
res = doSetupMacro ( spec , * lines ) ;
} else if ( ! strncmp ( * lines , " %patch " , sizeof ( " %patch " ) - 1 ) ) {
res = doPatchMacro ( spec , * lines ) ;
} else {
appendLineStringBuf ( spec - > prep , * lines ) ;
}
if ( res & & ! spec - > force ) {
freeSplitString ( saveLines ) ;
sb = freeStringBuf ( sb ) ;
return res ;
}
}
/*@=usereleased@*/
freeSplitString ( saveLines ) ;
sb = freeStringBuf ( sb ) ;
2002-03-26 02:09:32 +03:00
}
2002-03-25 23:16:26 +03:00
return nextPart ;
}