Minor changes on FOPENTEXT

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6077 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-05-03 10:12:33 +00:00
parent 2170215b06
commit b431c21048
5 changed files with 14 additions and 35 deletions

View file

@ -912,7 +912,7 @@ TCHAR SkipComments(FILE *f) {
// NSIS Language File parser
LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) {
FILE *f = FOPENTEXT(filename, _T("r"));
FILE *f = FOPENTEXT(filename, "r");
if (!f) {
ERROR_MSG(_T("Error: Can't open language file - \"%s\"!\n"),filename);
return 0;

View file

@ -189,7 +189,7 @@ static tstring get_home()
static int process_config(CEXEBuild& build, tstring& conf)
{
FILE *cfg=FOPENTEXT(conf.c_str(),_T("rt"));
FILE *cfg=FOPENTEXT(conf.c_str(),"rt");
if (cfg)
{
if (build.display_script)
@ -298,7 +298,7 @@ int _tmain(int argc, TCHAR **argv)
{
if (argc > tmpargpos && IS_OPT(argv[tmpargpos]) && (argv[tmpargpos][1]==_T('o') || argv[tmpargpos][1]==_T('O')) && argv[tmpargpos][2])
{
g_output=FOPENTEXT(argv[tmpargpos]+2,_T("w"));
g_output=FOPENTEXT(argv[tmpargpos]+2,"w");
if (!g_output)
{
_tprintf(_T("Error opening output log for writing. Using stdout.\n"));
@ -344,7 +344,7 @@ int _tmain(int argc, TCHAR **argv)
{
if (!outputtried)
{
g_output=FOPENTEXT(argv[argpos]+2,_T("w"));
g_output=FOPENTEXT(argv[argpos]+2,"w");
if (!g_output)
{
if (build.display_errors) _tprintf(_T("Error opening output log for writing. Using stdout.\n"));
@ -479,11 +479,11 @@ int _tmain(int argc, TCHAR **argv)
else
{
_tcscpy(sfile,argv[argpos]);
fp=FOPENTEXT(sfile,_T("rt"));
fp=FOPENTEXT(sfile,"rt");
if (!fp)
{
_stprintf(sfile,_T("%s.nsi"),argv[argpos]);
fp=FOPENTEXT(sfile,_T("rt"));
fp=FOPENTEXT(sfile,"rt");
if (!fp)
{
if (build.display_errors)

View file

@ -743,7 +743,7 @@ int CEXEBuild::parseScript()
int CEXEBuild::includeScript(TCHAR *f)
{
SCRIPT_MSG(_T("!include: \"%s\"\n"),f);
FILE *incfp=FOPENTEXT(f,_T("rt"));
FILE *incfp=FOPENTEXT(f,"rt");
if (!incfp)
{
ERROR_MSG(_T("!include: could not open file: \"%s\"\n"),f);
@ -1222,7 +1222,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
TCHAR *file = line.gettoken_str(1);
TCHAR *text = line.gettoken_str(2);
FILE *fp = FOPENTEXT(file, _T("a"));
FILE *fp = FOPENTEXT(file, "a");
if (!fp)
{
ERROR_MSG(_T("!appendfile: \"%s\" couldn't be opened.\n"), file);
@ -2834,7 +2834,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
define=line.gettoken_str(2);
const TCHAR *filename=line.gettoken_str(3);
FILE *fp=FOPENTEXT(filename,_T("r"));
FILE *fp=FOPENTEXT(filename,"r");
if (!fp && _tcsicmp(define,_T("/file_noerr"))) {
ERROR_MSG(_T("!define /file: file not found (\"%s\")\n"),filename);
@ -3122,7 +3122,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (isFile)
{
FILE *fp=FOPENTEXT(source_string,_T("r"));
FILE *fp=FOPENTEXT(source_string,"r");
if (!fp)
{
ERROR_MSG(_T("!searchparse /file: error opening \"%s\"\n"),source_string);

View file

@ -16,31 +16,9 @@
#include "tstring.h"
#include "validateunicode.h"
#include "util.h"
#include <vector>
// Simple RAII for C-styled FILE pointers.
class ScopedFile
{
public:
ScopedFile(FILE* file) : m_file(file) {}
~ScopedFile()
{
if (this->m_file != NULL)
{
fflush(this->m_file);
fclose(this->m_file);
}
}
operator FILE*(){ return this->m_file; }
operator bool() { return this->m_file != NULL; }
private:
FILE* m_file;
};
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode)
{
extern FILE *g_output;
@ -51,10 +29,11 @@ FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode)
if (_tcsstr(mode, _T("w+")) ||
_tcsstr(mode, _T("r")))
{
ScopedFile fp(_tfopen(file, _T("rb")));
FILE* fp = _tfopen(file, _T("rb"));
if (fp)
{
MANAGE_WITH(fp, fclose);
fseek(fp, 0, SEEK_END);
size_t fileSize = ftell(fp);
if (fileSize == 0)

View file

@ -30,7 +30,7 @@ typedef std::wofstream tofstream;
typedef std::wifstream tifstream;
// Use the following macros to open text files.
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode);
#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, mode)
#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, _T(mode))
#else
typedef std::string tstring;
typedef std::ofstream tofstream;