/* look for the key word XPMEXT, skip lines before this */
while((notstart=strncmp("XPMEXT",string,6))
&&(notend=strncmp("XPMENDEXT",string,9))){
XpmFree(string);
xpmNextString(data);
status=xpmGetString(data,&string,&l);
if(status!=XpmSuccess){
XpmFree(exts);
return(status);
}
}
if(!notstart)
notend=strncmp("XPMENDEXT",string,9);
while(!notstart&¬end){
/* there starts an extension */
ext=(XpmExtension*)
XpmRealloc(exts,(num+1)*sizeof(XpmExtension));/* can the loop be forced to iterate often enough to make "(num + 1) * sizeof(XpmExtension)" wrapping? */
if(!ext){
XpmFree(string);
XpmFreeExtensions(exts,num);
return(XpmNoMemory);
}
exts=ext;
ext+=num;
/* skip whitespace and store its name */
s2=s=string+6;
while(isspace(*s2))
s2++;
a=s2-s;
ext->name=(char*)XpmMalloc(l-a-6);
if(!ext->name){
XpmFree(string);
ext->lines=NULL;
ext->nlines=0;
XpmFreeExtensions(exts,num+1);
return(XpmNoMemory);
}
strncpy(ext->name,s+a,l-a-6);
XpmFree(string);
/* now store the related lines */
xpmNextString(data);
status=xpmGetString(data,&string,&l);
if(status!=XpmSuccess){
ext->lines=NULL;
ext->nlines=0;
XpmFreeExtensions(exts,num+1);
return(status);
}
ext->lines=(char**)XpmMalloc(sizeof(char*));
nlines=0;
while((notstart=strncmp("XPMEXT",string,6))
&&(notend=strncmp("XPMENDEXT",string,9))){
sp=(char**)
XpmRealloc(ext->lines,(nlines+1)*sizeof(char*));/* can we iterate enough for a wrapping? */
if(!sp){
XpmFree(string);
ext->nlines=nlines;
XpmFreeExtensions(exts,num+1);
return(XpmNoMemory);
}
ext->lines=sp;
ext->lines[nlines]=string;
nlines++;
xpmNextString(data);
status=xpmGetString(data,&string,&l);
if(status!=XpmSuccess){
ext->nlines=nlines;
XpmFreeExtensions(exts,num+1);
return(status);
}
}
if(!nlines){
XpmFree(ext->lines);
ext->lines=NULL;
}
ext->nlines=nlines;
num++;
}
if(!num){
XpmFree(string);
XpmFree(exts);
exts=NULL;
}elseif(!notend)
XpmFree(string);
*nextensions=num;
*extensions=exts;
return(XpmSuccess);
}
/* function call in case of error */
#undef RETURN
#define RETURN(status) \
do { \
goto error; \
} while(0)
/*
* This function parses an Xpm file or data and store the found informations