diff --git a/Source/script.cpp b/Source/script.cpp index dabd8979..30334cd3 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1165,15 +1165,55 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) case TOK_P_DELFILE: { - char *file = line.gettoken_str(1); - PATH_CONVERT(file); - int result = unlink(file); - if (result == -1) { - ERROR_MSG("!delfile: \"%s\" couldn't be deleted.\n", line.gettoken_str(1)); - return PS_ERROR; + int fatal = 1; + int a = 1; + char *fc = line.gettoken_str(a); + if (line.getnumtokens()==3) + { + if(!stricmp(fc,"/nonfatal")) + { + fatal = 0; + fc = line.gettoken_str(++a); + } + else PRINTHELP(); } - SCRIPT_MSG("!delfile: \"%s\"\n", line.gettoken_str(1)); + SCRIPT_MSG("!delfile: \"%s\"\n", line.gettoken_str(a)); + + string dir = get_dir_name(fc); + string spec = get_file_name(fc); + string basedir = dir + PLATFORM_PATH_SEPARATOR_STR; + if (dir == spec) { + // no path, just file name + dir = "."; + basedir = ""; + } + + boost::scoped_ptr dr( new_dir_reader() ); + dr->read(dir); + + for (dir_reader::iterator files_itr = dr->files().begin(); + files_itr != dr->files().end(); + files_itr++) + { + if (!dir_reader::matches(*files_itr, spec)) + continue; + + string file = basedir + *files_itr; + + int result = unlink(file.c_str()); + if (result == -1) { + ERROR_MSG("!delfile: \"%s\" couldn't be deleted.\n", file.c_str()); + if (fatal) + { + return PS_ERROR; + } + } + else + { + SCRIPT_MSG("!delfile: deleted \"%s\"\n", file.c_str()); + } + } } return PS_OK; diff --git a/Source/tokens.cpp b/Source/tokens.cpp index c57533cd..9341bd46 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -254,11 +254,11 @@ static tokenType tokenlist[TOK__LAST] = {TOK_P_IFMACRONDEF,"!ifmacrondef",1,-1,"macro [| macro2 [& macro3 [...]]]",TP_ALL}, {TOK_P_TEMPFILE,"!tempfile",1,0,"symbol",TP_ALL}, -{TOK_P_DELFILE,"!delfile",1,0,"file",TP_ALL}, +{TOK_P_DELFILE,"!delfile",1,1,"[/nonfatal] file",TP_ALL}, {TOK_P_APPENDFILE,"!appendfile",2,0,"file appended_line",TP_ALL}, - -{TOK_P_SEARCHPARSESTRING,"!searchparse",3,-1,"[/ignorecase] [/noerrors] [/file] source_string substring OUTPUTSYM1 [substring [OUTPUTSYM2 [substring ...]]]",TP_ALL}, -{TOK_P_SEARCHREPLACESTRING,"!searchreplace",4,1,"[/ignorecase] output_name source_string substring replacestring", TP_ALL}, + +{TOK_P_SEARCHPARSESTRING,"!searchparse",3,-1,"[/ignorecase] [/noerrors] [/file] source_string substring OUTPUTSYM1 [substring [OUTPUTSYM2 [substring ...]]]",TP_ALL}, +{TOK_P_SEARCHREPLACESTRING,"!searchreplace",4,1,"[/ignorecase] output_name source_string substring replacestring", TP_ALL}, {TOK_MISCBUTTONTEXT,"MiscButtonText",0,4,"[back button text] [next button text] [cancel button text] [close button text]",TP_GLOBAL}, {TOK_DETAILSBUTTONTEXT,"DetailsButtonText",0,1,"[details button text]",TP_PG},