proper line endings

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5948 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2009-03-10 20:14:10 +00:00
parent d03b413e34
commit 407033f1d6

View file

@ -2767,7 +2767,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
case TOK_P_DEFINE: case TOK_P_DEFINE:
{ {
char *define=line.gettoken_str(1); char *define=line.gettoken_str(1);
char *value; char *value;
GrowBuf file_buf; GrowBuf file_buf;
char datebuf[256]; char datebuf[256];
char mathbuf[256]; char mathbuf[256];
@ -2795,39 +2795,39 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
datebuf[max(s,sizeof(datebuf)-1)]=0; datebuf[max(s,sizeof(datebuf)-1)]=0;
value=datebuf; value=datebuf;
} else if (!stricmp(define,"/file") || !stricmp(define,"/file_noerr")) { } else if (!stricmp(define,"/file") || !stricmp(define,"/file_noerr")) {
if (line.getnumtokens()!=4) PRINTHELP() if (line.getnumtokens()!=4) PRINTHELP()
define=line.gettoken_str(2); define=line.gettoken_str(2);
const char *filename=line.gettoken_str(3); const char *filename=line.gettoken_str(3);
FILE *fp=fopen(filename,"r"); FILE *fp=fopen(filename,"r");
if (!fp && stricmp(define,"/file_noerr")) { if (!fp && stricmp(define,"/file_noerr")) {
ERROR_MSG("!define /file: file not found (\"%s\")\n",filename); ERROR_MSG("!define /file: file not found (\"%s\")\n",filename);
return PS_ERROR; return PS_ERROR;
} }
if (fp) { if (fp) {
char str[MAX_LINELENGTH]; char str[MAX_LINELENGTH];
for (;;) { for (;;) {
char *p=str; char *p=str;
*p=0; *p=0;
fgets(str,MAX_LINELENGTH,fp); fgets(str,MAX_LINELENGTH,fp);
linecnt++; linecnt++;
if (feof(fp)&&!str[0]) break; if (feof(fp)&&!str[0]) break;
while (*p) p++; while (*p) p++;
if (p > str) p--; if (p > str) p--;
while (p >= str && (*p == '\r' || *p == '\n')) p--; while (p >= str && (*p == '\r' || *p == '\n')) p--;
*++p=0; *++p=0;
if (file_buf.getlen()) file_buf.add("\n",1); if (file_buf.getlen()) file_buf.add("\n",1);
file_buf.add(str,strlen(str)); file_buf.add(str,strlen(str));
} }
fclose(fp); fclose(fp);
} }
file_buf.add("\0",1); file_buf.add("\0",1);
value = (char *)file_buf.get(); value = (char *)file_buf.get();
} else if (!stricmp(define,"/math")) { } else if (!stricmp(define,"/math")) {
@ -3076,167 +3076,167 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_OK; return PS_OK;
case TOK_P_ECHO: case TOK_P_ECHO:
SCRIPT_MSG("%s (%s:%d)\n", line.gettoken_str(1),curfilename,linecnt); SCRIPT_MSG("%s (%s:%d)\n", line.gettoken_str(1),curfilename,linecnt);
return PS_OK; return PS_OK;
case TOK_P_SEARCHPARSESTRING: case TOK_P_SEARCHPARSESTRING:
{ {
bool ignCase=false; bool ignCase=false;
bool noErrors=false; bool noErrors=false;
bool isFile=false; bool isFile=false;
int parmOffs=1; int parmOffs=1;
while (parmOffs < line.getnumtokens()) while (parmOffs < line.getnumtokens())
{ {
if (!stricmp(line.gettoken_str(parmOffs),"/ignorecase")) { ignCase=true; parmOffs++; } if (!stricmp(line.gettoken_str(parmOffs),"/ignorecase")) { ignCase=true; parmOffs++; }
else if (!stricmp(line.gettoken_str(parmOffs),"/noerrors")) { noErrors=true; parmOffs++; } else if (!stricmp(line.gettoken_str(parmOffs),"/noerrors")) { noErrors=true; parmOffs++; }
else if (!stricmp(line.gettoken_str(parmOffs),"/file")) { isFile=true; parmOffs++; } else if (!stricmp(line.gettoken_str(parmOffs),"/file")) { isFile=true; parmOffs++; }
else break; else break;
} }
if (parmOffs+3 > line.getnumtokens()) if (parmOffs+3 > line.getnumtokens())
{ {
ERROR_MSG("!searchparse: not enough parameters\n"); ERROR_MSG("!searchparse: not enough parameters\n");
return PS_ERROR; return PS_ERROR;
} }
const char *source_string = line.gettoken_str(parmOffs++); const char *source_string = line.gettoken_str(parmOffs++);
DefineList *list=NULL; DefineList *list=NULL;
if (isFile) if (isFile)
{ {
FILE *fp=fopen(source_string,"r"); FILE *fp=fopen(source_string,"r");
if (!fp) if (!fp)
{ {
ERROR_MSG("!searchparse /file: error opening \"%s\"\n",source_string); ERROR_MSG("!searchparse /file: error opening \"%s\"\n",source_string);
return PS_ERROR; return PS_ERROR;
} }
int req_parm = (line.getnumtokens() - parmOffs)/2; int req_parm = (line.getnumtokens() - parmOffs)/2;
GrowBuf tmpstr; GrowBuf tmpstr;
char str[MAX_LINELENGTH]; char str[MAX_LINELENGTH];
for (;;) for (;;)
{ {
for (;;) for (;;)
{ {
str[0]=0; str[0]=0;
fgets(str,sizeof(str),fp); fgets(str,sizeof(str),fp);
if (!str[0]) break; if (!str[0]) break;
char *p=str; char *p=str;
while (*p) p++; while (*p) p++;
if (p > str) p--; if (p > str) p--;
while (p >= str && (*p == '\r' || *p == '\n')) p--; while (p >= str && (*p == '\r' || *p == '\n')) p--;
*++p=0; *++p=0;
bool endSlash = (str[0] && str[strlen(str)-1] == '\\'); bool endSlash = (str[0] && str[strlen(str)-1] == '\\');
if (tmpstr.getlen() || endSlash) tmpstr.add(str,strlen(str)); if (tmpstr.getlen() || endSlash) tmpstr.add(str,strlen(str));
if (!endSlash) break; if (!endSlash) break;
} }
char *thisline=str; char *thisline=str;
if (tmpstr.getlen()) if (tmpstr.getlen())
{ {
tmpstr.add("\0",1); tmpstr.add("\0",1);
thisline=(char *)tmpstr.get(); thisline=(char *)tmpstr.get();
} }
DefineList *tlist = searchParseString(thisline,&line,parmOffs,ignCase,true); DefineList *tlist = searchParseString(thisline,&line,parmOffs,ignCase,true);
if (tlist && tlist->getnum()) if (tlist && tlist->getnum())
{ {
if (!list || tlist->getnum() > list->getnum()) if (!list || tlist->getnum() > list->getnum())
{ {
delete list; delete list;
list=tlist; list=tlist;
if (tlist->getnum() >= req_parm) break; // success! if (tlist->getnum() >= req_parm) break; // success!
} }
else delete list; else delete list;
} }
// parse line // parse line
tmpstr.resize(0); tmpstr.resize(0);
} }
fclose(fp); fclose(fp);
if (!noErrors) if (!noErrors)
{ {
if (!list) if (!list)
{ {
ERROR_MSG("!searchparse: starting string \"%s\" not found in file!\n",line.gettoken_str(parmOffs)); ERROR_MSG("!searchparse: starting string \"%s\" not found in file!\n",line.gettoken_str(parmOffs));
return PS_ERROR; return PS_ERROR;
} }
else if (list->getnum() < req_parm) else if (list->getnum() < req_parm)
{ {
char *p=line.gettoken_str(parmOffs + list->getnum()*2); char *p=line.gettoken_str(parmOffs + list->getnum()*2);
ERROR_MSG("!searchparse: failed search at string \"%s\" not found in file!\n",p?p:"(null)"); ERROR_MSG("!searchparse: failed search at string \"%s\" not found in file!\n",p?p:"(null)");
return PS_ERROR; return PS_ERROR;
} }
} }
} }
else else
{ {
list=searchParseString(source_string,&line,parmOffs,ignCase,noErrors); list=searchParseString(source_string,&line,parmOffs,ignCase,noErrors);
if (!list && !noErrors) return PS_ERROR; if (!list && !noErrors) return PS_ERROR;
} }
if (list) // if we got our list, merge them defines in if (list) // if we got our list, merge them defines in
{ {
int i; int i;
for (i=0;i<list->getnum(); i ++) for (i=0;i<list->getnum(); i ++)
{ {
char *def=list->getname(i); char *def=list->getname(i);
char *val=list->getvalue(i); char *val=list->getvalue(i);
if (def && val) if (def && val)
{ {
if (definedlist.find(def)) definedlist.del(def); if (definedlist.find(def)) definedlist.del(def);
definedlist.add(def,val); definedlist.add(def,val);
} }
} }
} }
delete list; delete list;
} }
return PS_OK; return PS_OK;
case TOK_P_SEARCHREPLACESTRING: case TOK_P_SEARCHREPLACESTRING:
{ {
int ignoreCase=!stricmp(line.gettoken_str(1),"/ignorecase"); int ignoreCase=!stricmp(line.gettoken_str(1),"/ignorecase");
if (line.getnumtokens()!=5+ignoreCase) PRINTHELP() if (line.getnumtokens()!=5+ignoreCase) PRINTHELP()
char *define=line.gettoken_str(1+ignoreCase); char *define=line.gettoken_str(1+ignoreCase);
char *src = line.gettoken_str(2+ignoreCase); char *src = line.gettoken_str(2+ignoreCase);
char *search = line.gettoken_str(3+ignoreCase); char *search = line.gettoken_str(3+ignoreCase);
char *replace = line.gettoken_str(4+ignoreCase); char *replace = line.gettoken_str(4+ignoreCase);
int searchlen=strlen(search); int searchlen=strlen(search);
int replacelen=strlen(replace); int replacelen=strlen(replace);
if (!searchlen) if (!searchlen)
{ {
ERROR_MSG("!searchreplace: search string must not be empty for search/replace!\n"); ERROR_MSG("!searchreplace: search string must not be empty for search/replace!\n");
return PS_ERROR; return PS_ERROR;
} }
GrowBuf valout; GrowBuf valout;
while (*src) while (*src)
{ {
if (ignoreCase ? strnicmp(src,search,searchlen) : strncmp(src,search,searchlen)) if (ignoreCase ? strnicmp(src,search,searchlen) : strncmp(src,search,searchlen))
valout.add(src++,1); valout.add(src++,1);
else else
{ {
valout.add(replace,replacelen); valout.add(replace,replacelen);
src+=searchlen; src+=searchlen;
} }
} }
valout.add("",1); valout.add("",1);
definedlist.del(define); // allow changing variables since we'll often use this in series definedlist.del(define); // allow changing variables since we'll often use this in series
if (definedlist.add(define,(char*)valout.get())) if (definedlist.add(define,(char*)valout.get()))
{ {
ERROR_MSG("!searchreplace: error defining \"%s\"!\n",define); ERROR_MSG("!searchreplace: error defining \"%s\"!\n",define);
return PS_ERROR; return PS_ERROR;
} }
SCRIPT_MSG("!searchreplace: \"%s\"=\"%s\"\n",define,(char*)valout.get()); SCRIPT_MSG("!searchreplace: \"%s\"=\"%s\"\n",define,(char*)valout.get());
} }
return PS_OK; return PS_OK;
case TOK_P_VERBOSE: case TOK_P_VERBOSE:
{ {
@ -6379,70 +6379,69 @@ int CEXEBuild::do_add_file_create_dir(const string& local_dir, const string& dir
return PS_OK; return PS_OK;
} }
#endif #endif
DefineList *CEXEBuild::searchParseString(const char *source_string, LineParser *line, int parmOffs, bool ignCase, bool noErrors)
DefineList *CEXEBuild::searchParseString(const char *source_string, LineParser *line, int parmOffs, bool ignCase, bool noErrors) {
{ const char *tok = line->gettoken_str(parmOffs++);
const char *tok = line->gettoken_str(parmOffs++); if (tok && *tok)
if (tok && *tok) {
{ int toklen = strlen(tok);
int toklen = strlen(tok); while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):strncmp(source_string,tok,toklen))) source_string++;
while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):strncmp(source_string,tok,toklen))) source_string++;
if (!*source_string)
if (!*source_string) {
{ if (!noErrors) ERROR_MSG("!searchparse: starting string \"%s\" not found, aborted search!\n",tok);
if (!noErrors) ERROR_MSG("!searchparse: starting string \"%s\" not found, aborted search!\n",tok); return NULL;
return NULL; }
} if (*source_string) source_string+=toklen;
if (*source_string) source_string+=toklen; }
}
DefineList *ret = NULL;
DefineList *ret = NULL;
while (parmOffs < line->getnumtokens())
while (parmOffs < line->getnumtokens()) {
{ const char *defout = line->gettoken_str(parmOffs++);
const char *defout = line->gettoken_str(parmOffs++); if (parmOffs < line->getnumtokens()) tok=line->gettoken_str(parmOffs++);
if (parmOffs < line->getnumtokens()) tok=line->gettoken_str(parmOffs++); else tok=NULL;
else tok=NULL;
int maxlen=-1;
int maxlen=-1; const char *src_start = source_string;
const char *src_start = source_string; if (tok && *tok)
if (tok && *tok) {
{ int toklen = strlen(tok);
int toklen = strlen(tok); while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):strncmp(source_string,tok,toklen))) source_string++;
while (*source_string && (ignCase?strnicmp(source_string,tok,toklen):strncmp(source_string,tok,toklen))) source_string++;
maxlen = source_string - src_start;
maxlen = source_string - src_start;
if (*source_string) source_string += toklen;
if (*source_string) source_string += toklen; else if (!noErrors)
else if (!noErrors) {
{ ERROR_MSG("!searchparse: string \"%s\" not found, aborted search!\n",tok);
ERROR_MSG("!searchparse: string \"%s\" not found, aborted search!\n",tok); delete ret;
delete ret; return NULL;
return NULL; }
}
}
}
if (defout && defout[0])
if (defout && defout[0]) {
{ if (!ret) ret = new DefineList;
if (!ret) ret = new DefineList;
if (maxlen < 0) ret->add(defout,src_start);
if (maxlen < 0) ret->add(defout,src_start); else
else {
{ char *p=strdup(src_start);
char *p=strdup(src_start); if (p)
if (p) {
{ p[maxlen]=0;
p[maxlen]=0; ret->add(defout,p);
ret->add(defout,p); free(p);
free(p); }
} }
} }
} }
} return ret;
return ret; }
}