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:
parent
2170215b06
commit
b431c21048
5 changed files with 14 additions and 35 deletions
|
@ -912,7 +912,7 @@ TCHAR SkipComments(FILE *f) {
|
||||||
|
|
||||||
// NSIS Language File parser
|
// NSIS Language File parser
|
||||||
LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) {
|
LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) {
|
||||||
FILE *f = FOPENTEXT(filename, _T("r"));
|
FILE *f = FOPENTEXT(filename, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
ERROR_MSG(_T("Error: Can't open language file - \"%s\"!\n"),filename);
|
ERROR_MSG(_T("Error: Can't open language file - \"%s\"!\n"),filename);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -189,7 +189,7 @@ static tstring get_home()
|
||||||
|
|
||||||
static int process_config(CEXEBuild& build, tstring& conf)
|
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 (cfg)
|
||||||
{
|
{
|
||||||
if (build.display_script)
|
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])
|
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)
|
if (!g_output)
|
||||||
{
|
{
|
||||||
_tprintf(_T("Error opening output log for writing. Using stdout.\n"));
|
_tprintf(_T("Error opening output log for writing. Using stdout.\n"));
|
||||||
|
@ -344,7 +344,7 @@ int _tmain(int argc, TCHAR **argv)
|
||||||
{
|
{
|
||||||
if (!outputtried)
|
if (!outputtried)
|
||||||
{
|
{
|
||||||
g_output=FOPENTEXT(argv[argpos]+2,_T("w"));
|
g_output=FOPENTEXT(argv[argpos]+2,"w");
|
||||||
if (!g_output)
|
if (!g_output)
|
||||||
{
|
{
|
||||||
if (build.display_errors) _tprintf(_T("Error opening output log for writing. Using stdout.\n"));
|
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
|
else
|
||||||
{
|
{
|
||||||
_tcscpy(sfile,argv[argpos]);
|
_tcscpy(sfile,argv[argpos]);
|
||||||
fp=FOPENTEXT(sfile,_T("rt"));
|
fp=FOPENTEXT(sfile,"rt");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
_stprintf(sfile,_T("%s.nsi"),argv[argpos]);
|
_stprintf(sfile,_T("%s.nsi"),argv[argpos]);
|
||||||
fp=FOPENTEXT(sfile,_T("rt"));
|
fp=FOPENTEXT(sfile,"rt");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
if (build.display_errors)
|
if (build.display_errors)
|
||||||
|
|
|
@ -743,7 +743,7 @@ int CEXEBuild::parseScript()
|
||||||
int CEXEBuild::includeScript(TCHAR *f)
|
int CEXEBuild::includeScript(TCHAR *f)
|
||||||
{
|
{
|
||||||
SCRIPT_MSG(_T("!include: \"%s\"\n"),f);
|
SCRIPT_MSG(_T("!include: \"%s\"\n"),f);
|
||||||
FILE *incfp=FOPENTEXT(f,_T("rt"));
|
FILE *incfp=FOPENTEXT(f,"rt");
|
||||||
if (!incfp)
|
if (!incfp)
|
||||||
{
|
{
|
||||||
ERROR_MSG(_T("!include: could not open file: \"%s\"\n"),f);
|
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 *file = line.gettoken_str(1);
|
||||||
TCHAR *text = line.gettoken_str(2);
|
TCHAR *text = line.gettoken_str(2);
|
||||||
|
|
||||||
FILE *fp = FOPENTEXT(file, _T("a"));
|
FILE *fp = FOPENTEXT(file, "a");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
ERROR_MSG(_T("!appendfile: \"%s\" couldn't be opened.\n"), file);
|
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);
|
define=line.gettoken_str(2);
|
||||||
const TCHAR *filename=line.gettoken_str(3);
|
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"))) {
|
if (!fp && _tcsicmp(define,_T("/file_noerr"))) {
|
||||||
ERROR_MSG(_T("!define /file: file not found (\"%s\")\n"),filename);
|
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)
|
if (isFile)
|
||||||
{
|
{
|
||||||
FILE *fp=FOPENTEXT(source_string,_T("r"));
|
FILE *fp=FOPENTEXT(source_string,"r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
ERROR_MSG(_T("!searchparse /file: error opening \"%s\"\n"),source_string);
|
ERROR_MSG(_T("!searchparse /file: error opening \"%s\"\n"),source_string);
|
||||||
|
|
|
@ -16,31 +16,9 @@
|
||||||
|
|
||||||
#include "tstring.h"
|
#include "tstring.h"
|
||||||
#include "validateunicode.h"
|
#include "validateunicode.h"
|
||||||
|
#include "util.h"
|
||||||
#include <vector>
|
#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)
|
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode)
|
||||||
{
|
{
|
||||||
extern FILE *g_output;
|
extern FILE *g_output;
|
||||||
|
@ -51,10 +29,11 @@ FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode)
|
||||||
if (_tcsstr(mode, _T("w+")) ||
|
if (_tcsstr(mode, _T("w+")) ||
|
||||||
_tcsstr(mode, _T("r")))
|
_tcsstr(mode, _T("r")))
|
||||||
{
|
{
|
||||||
ScopedFile fp(_tfopen(file, _T("rb")));
|
FILE* fp = _tfopen(file, _T("rb"));
|
||||||
|
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
|
MANAGE_WITH(fp, fclose);
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
size_t fileSize = ftell(fp);
|
size_t fileSize = ftell(fp);
|
||||||
if (fileSize == 0)
|
if (fileSize == 0)
|
||||||
|
|
|
@ -30,7 +30,7 @@ typedef std::wofstream tofstream;
|
||||||
typedef std::wifstream tifstream;
|
typedef std::wifstream tifstream;
|
||||||
// Use the following macros to open text files.
|
// Use the following macros to open text files.
|
||||||
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode);
|
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode);
|
||||||
#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, mode)
|
#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, _T(mode))
|
||||||
#else
|
#else
|
||||||
typedef std::string tstring;
|
typedef std::string tstring;
|
||||||
typedef std::ofstream tofstream;
|
typedef std::ofstream tofstream;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue