FILE operations are converted to QFile, astyle

(cherry picked from commit b1cb204346f81775c1ad9eecc737e0f30465fd50)

adapted by Lancos
This commit is contained in:
Claudio Lanconelli 2017-04-24 18:19:41 +02:00
parent 19dc1c3bb2
commit e5f92fb401
18 changed files with 271 additions and 289 deletions

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: binfbuf.cpp,v 1.3 2009/11/16 22:29:18 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -27,7 +25,8 @@
//-------------------------------------------------------------------------//
//=========================================================================//
#include <stdio.h>
// #include <stdio.h>
#include <QDataStream>
#include "types.h"
#include "binfbuf.h" // Header file
@ -51,19 +50,17 @@ binFileBuf::~binFileBuf()
//======================>>> binFileBuf::Load <<<=======================
int binFileBuf::Load(int loadtype, long relocation_offset)
{
FILE *fh;
QFile fh(GetFileName());
int rval = OK;
if ( (fh = fopen(GetFileName().toLatin1(), "rb")) == NULL )
if (!fh.open(QIODevice::ReadOnly))
{
return FILENOTFOUND;
}
long fsize = GetFileSize(fh);
rewind(fh);
//rewind(fh);
//In questi formati di file "stupidi" la dimensione
//deve rimanere quella della eeprom attualmente selezionata
long buf_size = GetBufSize();
uint8_t *ptr = GetBufPtr();
@ -76,7 +73,7 @@ int binFileBuf::Load(int loadtype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
@ -88,7 +85,7 @@ int binFileBuf::Load(int loadtype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
@ -108,8 +105,11 @@ int binFileBuf::Load(int loadtype, long relocation_offset)
fsize = buf_size;
}
rval = fread(ptr, fsize, 1, fh);
fclose(fh);
QDataStream datastream(&fh);
rval = datastream.readRawData( (char*)ptr, fsize);
fh.close();
// SetStringID(""); //????
SetComment("");
@ -124,7 +124,7 @@ int binFileBuf::Load(int loadtype, long relocation_offset)
//======================>>> binFileBuf::Save <<<=======================
int binFileBuf::Save(int savetype, long relocation_offset)
{
FILE *fh;
QFile fh(FileBuf::GetFileName());
int rval;
if (FileBuf::GetNoOfBlock() <= 0)
@ -132,7 +132,7 @@ int binFileBuf::Save(int savetype, long relocation_offset)
return NOTHINGTOSAVE;
}
if ( (fh = fopen(FileBuf::GetFileName().toLatin1(), "wb")) == NULL )
if (!fh.open(QIODevice::WriteOnly))
{
return CREATEERROR;
}
@ -148,7 +148,7 @@ int binFileBuf::Save(int savetype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
@ -161,18 +161,19 @@ int binFileBuf::Save(int savetype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
rval = fwrite(ptr, buf_size, 1, fh);
QDataStream datastream(&fh);
rval = datastream.writeRawData((const char*) ptr, buf_size);
if (rval == 0)
{
rval = WRITEERROR;
}
fclose(fh);
fh.close();
return rval;
}

View File

@ -1,39 +1,36 @@
#include <stdio.h>
#include <QFile>
#include "crc.h"
/* Calcola il CRC in un file a partire da ini_ofs per un numero di bytes
dato da len. Se len e` zero prosegue fino alla fine del file, il file
deve essere aperto in modo da permettere la lettura (r, r+, w+) */
uint16_t fcalc_crc(FILE *fh, long ini_ofs, long len)
uint16_t fcalc_crc(QFile &fh, long ini_ofs, long len)
{
uint16_t crc16 = 0;
int ch;
char ch;
long old_pos;
if (!fh)
{
return 0;
}
old_pos = fh.pos();
old_pos = ftell(fh);
fseek(fh, ini_ofs, SEEK_SET);
fh.seek(ini_ofs);//, SEEK_SET); // from begin to init_ofs
if (len)
{
for (; len && (ch = getc(fh)) != EOF; len--)
for (; len && fh.read(&ch, 1) > 0; len--)
{
crc16 = updcrcr(crc16, ch);
}
}
else
{
while( (ch = getc(fh)) != EOF )
while (fh.read( &ch, 1) > 0) //while( (ch = getc(fh)) != EOF )
{
crc16 = updcrcr(crc16, ch);
}
}
fseek(fh, old_pos, SEEK_SET);
fh.seek(old_pos);//, SEEK_SET);
return crc16;
}

View File

@ -1,9 +1,11 @@
#include <QFile>
#include "types.h"
/* Calcola il CRC in un file a partire da ini_ofs per un numero di bytes
dato da len. Se len e` zero prosegue fino alla fine del file, il file
deve essere aperto in modo da permettere la lettura (r, r+, w+) */
uint16_t fcalc_crc(FILE *fh, long ini_ofs, long len);
uint16_t fcalc_crc(QFile &fh, long ini_ofs, long len);
/* Calcola il CRC in una zona di memoria a partire da ini_addr per un numero
di bytes dato da len */

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: csmfbuf.cpp,v 1.3 2009/11/16 22:29:18 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -27,8 +25,9 @@
//-------------------------------------------------------------------------//
//=========================================================================//
#include <stdio.h>
//#include <stdio.h>
#include <QString>
#include <QFile>
#include "csmfbuf.h" // Header file
#include "crc.h"
@ -47,23 +46,28 @@ csmFileBuf::csmFileBuf(e2AppWinInfo *wininfo)
//======================>>> csmFileBuf::Load <<<=======================
int csmFileBuf::Load(int loadtype, long relocation_offfset)
{
int GetE2PSubType(unsigned long x);
int GetE2PPriType(unsigned long x);
extern int GetE2PSubType(unsigned long x);
extern int GetE2PPriType(unsigned long x);
FILE *fh;
char *s, *s1;
(void)relocation_offfset; //unused
QFile fh(FileBuf::GetFileName());
char *s;//, *s1;
int rval = OK;
char riga[MAXLINE + 1];
if ( (fh = fopen(FileBuf::GetFileName().toLatin1(), "r")) == NULL )
if (!fh.open(QIODevice::ReadOnly | QIODevice::Text))
{
return FILENOTFOUND;
}
int state = 0;
while ( (s1 = fgets(riga, MAXLINE, fh)) != NULL && state < 3 )
while (!fh.atEnd() && state < 3)
{
fh.readLine(riga, MAXLINE);
switch (state)
{
case 0:
@ -113,7 +117,7 @@ int csmFileBuf::Load(int loadtype, long relocation_offfset)
}
}
if (s1 == NULL) //Header not found
if (state < 3) //Header not found
{
rval = BADFILETYPE;
}
@ -124,9 +128,11 @@ int csmFileBuf::Load(int loadtype, long relocation_offfset)
addr = 0;
//legge tutto il corpo del file
while ( (s = fgets(riga, MAXLINE, fh)) != NULL )
//read all remaining file (body)
while (!fh.atEnd())
{
fh.readLine(riga, MAXLINE);
if (strlen(riga) > 0) // salta righe vuote
{
n = sscanf(riga, "%x %x", &addr, &value);
@ -188,7 +194,7 @@ int csmFileBuf::Load(int loadtype, long relocation_offfset)
rval = addr;
}
fclose(fh);
fh.close();
return rval;
@ -196,7 +202,7 @@ int csmFileBuf::Load(int loadtype, long relocation_offfset)
// SetComment(hdr.e2pComment);
}
static char header[] =
static const char header[] =
"REFERENCE = =\n"
"CHASSIS = =\n"
"MODEL = =\n"
@ -213,9 +219,10 @@ static char header[] =
//======================>>> csmFileBuf::Save <<<=======================
int csmFileBuf::Save(int savetype, long relocation_offfset)
{
FILE *fh;
int rval = 0;
(void) relocation_offfset; //unused
long size = FileBuf::GetBlockSize() * FileBuf::GetNoOfBlock();
uint8_t *ptr = FileBuf::GetBufPtr();
@ -245,27 +252,28 @@ int csmFileBuf::Save(int savetype, long relocation_offfset)
if (size > 0)
{
fh = fopen(FileBuf::GetFileName().toLatin1(), "w");
QFile fh(FileBuf::GetFileName());
if (fh == NULL)
if (!fh.open(QIODevice::WriteOnly | QIODevice::Text ))
{
rval = CREATEERROR;
}
else
{
QTextStream out(&fh);
int addr, value;
//Write Header
fprintf(fh, "\"\n%s\n\"", header);
out << "\"\n" << header << "\n\"";
//Write buffer
for (addr = 0; addr < size; addr++)
{
value = ptr[addr];
fprintf(fh, "%x %x\n", addr, value);
out << (hex) << addr << " " << value << "\n";
}
fclose(fh);
fh.close();
rval = addr;
}

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: e2app.cpp,v 1.25 2016/06/24 12:21:06 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -48,14 +46,6 @@
#include <sys/time.h>
#include <unistd.h>
#include <signal.h>
#else
// # ifdef __BORLANDC__
// # define strncasecmp strnicmp
// # define strcasecmp stricmp
// # else // _MICROSOFT_ VC++
// # define strncasecmp _strnicmp
// # define strcasecmp _stricmp
// # endif
#endif
#include "microbus.h"
@ -711,7 +701,14 @@ void e2App::LookForBogoMips()
strcpy(sp + 1, "bogomips.out");
}
FILE *fh = fopen(strbuf, "w");
QFile fh(strbuf);
if (!fh.open(QIODevice::WriteOnly | QIODevice::Text))
{
return;
}
QTextStream out(&fh);
Wait w;
int k;
@ -735,10 +732,7 @@ void e2App::LookForBogoMips()
count = GetTickCount() - t0;
if (fh)
{
fprintf(fh, "bogo = %d, count = %lu\n", GetBogoMips(), count);
}
out << "bogo = " << GetBogoMips() << ", count =" << count << "\n";
}
while (count <= MSLICE / 11);
@ -751,10 +745,7 @@ void e2App::LookForBogoMips()
count = GetTickCount() - t0;
if (fh)
{
fprintf(fh, "1) count = %lu ** mslice = %f *** bogo = %d\n", count, MSLICE, GetBogoMips());
}
out << "1) count = " << count << " ** mslice = " << MSLICE << " *** bogo = " << GetBogoMips() << "\n";
int j;
@ -776,10 +767,7 @@ void e2App::LookForBogoMips()
count = GetTickCount() - t0;
if (fh)
{
fprintf(fh, "2) count = %lu ** mslice = %f *** bogo = %d\n", count, MSLICE, GetBogoMips());
}
out << "2) count = " << count << " ** mslice = " << MSLICE << " *** bogo = " << GetBogoMips() << "\n";
}
//Fine correction
@ -800,27 +788,21 @@ void e2App::LookForBogoMips()
count = GetTickCount() - t0;
if (fh)
{
fprintf(fh, "3) count = %lu ** mslice = %f *** bogo = %d\n", count, MSLICE, GetBogoMips());
}
count << "3) count = " << count << " ** mslice = " << MSLICE << " *** bogo = " << GetBogoMips() << "\n";
}
w.CheckHwTimer(); //Check to enable again Hw timer
if (fh)
if (w.GetHwTimer())
{
if (w.GetHwTimer())
{
fprintf(fh, "Hardware timer is OK.\n");
}
else
{
fprintf(fh, "Hardware timer is too slow, use bogomips (%d)\n", GetBogoMips());
}
fclose(fh);
out << "Hardware timer is OK.\n";
}
else
{
out << "Hardware timer is too slow, use bogomips (" << GetBogoMips() << ")\n";
}
fh.close();
#endif
}

View File

@ -279,16 +279,16 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
extern int GetE2PSubType(unsigned long x);
extern int GetE2PPriType(unsigned long x);
if (id == 0)
{
id = E2400; //to avoid segV
}
if (id == 0)
{
id = E2400; //to avoid segV
}
eep_id = id;
eep_id = id;
//eep_type, eep_subtype are local shadow variables of eep_id
int eep_type = GetE2PPriType(id);
int eep_subtype = GetE2PSubType(id);
//eep_type, eep_subtype are local shadow variables of eep_id
int eep_type = GetE2PPriType(id);
int eep_subtype = GetE2PSubType(id);
// int eep_type = type;
// int eep_subtype = subtype; //0 indica di usare GetNoOfBlock()
@ -306,7 +306,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E2401_A);
}
@ -317,7 +317,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E2401_B);
}
@ -328,11 +328,11 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E2432);
}
eep->DefaultBankSize();
eep->DefaultBankSize();
break;
case E24XX5:
@ -345,7 +345,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(AT90S1200);
}
@ -363,7 +363,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(AT89S8252);
}
@ -390,7 +390,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E9306);
}
@ -401,7 +401,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E9306_8);
}
@ -412,7 +412,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(PIC1684);
}
@ -431,7 +431,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(PIC12508);
}
@ -442,7 +442,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E25010);
}
@ -453,11 +453,11 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E25080);
}
//eep->SetBus(GetBusVectorPtr()[AT250BIG-1]);
//eep->SetBus(GetBusVectorPtr()[AT250BIG-1]);
break;
case E2506XX:
@ -465,7 +465,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(E2506);
}
@ -476,7 +476,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(ENVM3060);
}
@ -487,7 +487,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(AT1765);
}
@ -496,7 +496,7 @@ void e2AppWinInfo::SetEEProm(unsigned long id)
case X24C44XX:
if (eep_subtype == 0)
{
//no autodetect: set a reasonable default
//no autodetect: set a reasonable default
eep_subtype = GetE2PSubType(S24H30);
}

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: e2cmdw.cpp,v 1.32 2013/11/07 16:33:39 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -170,7 +168,7 @@ e2CmdWindow::e2CmdWindow(QWidget *parent ) :
// combo boxes
CbxMenuInit();
// UpdateMenuType(E2Profile::GetLastDevType());
// UpdateMenuType(E2Profile::GetLastDevType());
// The Canvas
e2HexEdit = new QHexEdit(this); //e2TextCanvasPane(this);
@ -1270,7 +1268,7 @@ void e2CmdWindow::selectTypeSubtype(const QString &t, const QString &st)
QString st_tmp = st;
st_tmp.remove(QChar('&'));
// qDebug() << t_tmp << st_tmp;
// qDebug() << t_tmp << st_tmp;
int nt = cbxEEPType->findText(t_tmp);
@ -2302,7 +2300,7 @@ int e2CmdWindow::CmdHelp()
#ifdef __linux__
QString str;
str = E2Profile::GetHtmlBrowseApp() + " \"http://www.lancos.com/e2p/ponyprog2000.html\" &";
system(str.toLatin1());
system(str.toLatin1().constData());
#endif
return OK;
@ -3168,7 +3166,7 @@ int e2CmdWindow::CmdRunScript(bool test_mode)
char *arg[32];
int n;
int linecounter;
FILE *fh;
VerboseType old_verbose = verbose;
@ -3182,17 +3180,18 @@ int e2CmdWindow::CmdRunScript(bool test_mode)
return BADPARAM;
}
fh = fopen(script_name.toLatin1(), "r");
QFile fh(script_name);
if (fh == NULL)
if (!fh.open(QIODevice::ReadOnly | QIODevice::Text))
{
return FILENOTFOUND;
}
linecounter = 0;
while (result == OK && fgets(buf, 511, fh) != NULL)
while(result == OK && !fh.atEnd())
{
fh.readLine(buf, 511);
linecounter++;
if (buf[0] == '#') //Skip comments
@ -4590,7 +4589,7 @@ int e2CmdWindow::CmdReadSpecial()
int rval;
int retry_flag = 1;
long type = awip->GetEEPId(); // BuildE2PType( awip->GetEEPPriType(), awip->GetEEPSubType() );
long type = awip->GetEEPId(); // BuildE2PType( awip->GetEEPPriType(), awip->GetEEPSubType() );
while (retry_flag)
{
@ -4667,7 +4666,7 @@ int e2CmdWindow::CmdWriteSpecial()
QMessageBox note;
long type = awip->GetEEPId(); //BuildE2PType( awip->GetEEPPriType(), awip->GetEEPSubType() );
long type = awip->GetEEPId(); //BuildE2PType( awip->GetEEPPriType(), awip->GetEEPSubType() );
/**
if (type == E2464) //Microchip 24C65 high endurance block
{
@ -4838,7 +4837,7 @@ int e2CmdWindow::CmdSelectDevice(long new_type, bool init)
UpdateMenuType(new_type);
first_line = 0;
// curIndex = 0;
// curIndex = 0;
Draw();
awip->RecalcCRC();
UpdateStatusBar();
@ -4846,13 +4845,14 @@ int e2CmdWindow::CmdSelectDevice(long new_type, bool init)
else
{
long old_type = awip->GetEEPId();
if (new_type != old_type)
{
awip->SetEEProm(new_type);
UpdateMenuType(new_type, old_type);
first_line = 0;
// curIndex = 0;
// curIndex = 0;
Draw();
awip->RecalcCRC();
UpdateStatusBar();
@ -5186,7 +5186,9 @@ void e2CmdWindow::UpdateMenuType(long new_type, long old_type)
Q_CHECK_PTR(cbxEEPSubType);
if (new_type == 0)
{
new_type = awip->GetEEPId();
}
// reset checkboxes
static menuToGroup* m = 0;
@ -5622,8 +5624,8 @@ int e2CmdWindow::OpenFile(const QString &file)
oldname = "";
}
awip->SetFileName(fileName); //Set FileName, update LastFile and PrevFile
long old_type = awip->GetEEPId(); //EEP type can be changed by E2P file load
awip->SetFileName(fileName); //Set FileName, update LastFile and PrevFile
long old_type = awip->GetEEPId(); //EEP type can be changed by E2P file load
rval = awip->Load();
@ -5647,7 +5649,7 @@ int e2CmdWindow::OpenFile(const QString &file)
UpdateMenuType(awip->GetEEPId(), old_type);
first_line = 0;
// curIndex = 0;
// curIndex = 0;
Draw();
UpdateStatusBar();

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: e2cmdw.h,v 1.9 2009/07/08 10:44:00 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -119,9 +117,13 @@ public: //---------------------------------------- public
long GetCurrentChipType()
{
if (awip)
{
return awip->GetEEPId();
}
else
{
return EID_INVALID;
}
}

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: e2pfbuf.cpp,v 1.5 2009/11/16 23:40:43 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -27,8 +25,9 @@
//-------------------------------------------------------------------------//
//=========================================================================//
#include <stdio.h>
// #include <stdio.h>
#include <QString>
#include <QDataStream>
#include "e2pfbuf.h" // Header file
#include "crc.h"
@ -40,16 +39,12 @@
static char const *id_string = "E2P!Lanc";
// EK 2017
// what is it?
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
//======================>>> e2pFileBuf::e2pFileBuf <<<=======================
e2pFileBuf::e2pFileBuf(e2AppWinInfo *wininfo)
: FileBuf(wininfo)
{
file_type = E2P;
BUILD_BUG_ON(sizeof(struct e2pHeader) != 152);
static_assert(sizeof(struct e2pHeader) == 152, "Bad size for e2pHeader");
}
//======================>>> e2pFileBuf::~e2pFileBuf <<<=======================
@ -91,17 +86,19 @@ int e2pFileBuf::Load(int loadtype, long relocation_offset)
extern int GetE2PSubType(unsigned long x);
extern int GetE2PPriType(unsigned long x);
FILE *fh;
QFile fh(FileBuf::GetFileName());
e2pHeader hdr;
int rval;
if ( (fh = fopen(FileBuf::GetFileName().toLatin1(), "rb")) == NULL )
if (!fh.open(QIODevice::ReadOnly))
{
return FILENOTFOUND;
}
QDataStream datastream(&fh);
// Controlla il tipo di file
if ( fread(&hdr, sizeof(e2pHeader), 1, fh) &&
if (datastream.readRawData( (char*)&hdr, sizeof(e2pHeader)) &&
strncmp(hdr.fileID, id_string, E2P_ID_SIZE) == 0 )
{
unsigned char *localbuf;
@ -111,10 +108,10 @@ int e2pFileBuf::Load(int loadtype, long relocation_offset)
{
//Controlla il CRC dell'Header
if ( mcalc_crc(&hdr, sizeof(hdr) - sizeof(hdr.headCrc)) == hdr.headCrc &&
//Check for CRC in memory
//Check for CRC in memory
fcalc_crc(fh, sizeof(e2pHeader), 0) == hdr.e2pCrc &&
//read buffer
fread(localbuf, hdr.e2pSize, 1, fh) )
//read buffer
datastream.readRawData( (char*)localbuf, hdr.e2pSize) )
// fread(FileBuf::GetBufPtr(), hdr.e2pSize, 1, fh) )
{
SetEEpromType(hdr.e2pType); //set eeprom device type (and block size too)
@ -210,14 +207,14 @@ int e2pFileBuf::Load(int loadtype, long relocation_offset)
rval = BADFILETYPE;
}
fclose(fh);
fh.close();
return rval;
}
//======================>>> e2pFileBuf::Save <<<=======================
int e2pFileBuf::Save(int savetype, long relocation_offset)
{
FILE *fh;
e2pHeader hdr;
int rval, create_file = 0;
@ -226,20 +223,18 @@ int e2pFileBuf::Save(int savetype, long relocation_offset)
return NOTHINGTOSAVE;
}
fh = fopen(FileBuf::GetFileName().toLatin1(), "r+b");
QFile fh(FileBuf::GetFileName());
if (fh == NULL)
if (!fh.exists())
{
fh = fopen(FileBuf::GetFileName().toLatin1(), "w+b");
if (fh == NULL)
{
return CREATEERROR;
}
create_file = 1;
}
if (!fh.open(QIODevice::ReadWrite))
{
return CREATEERROR;
}
//Header settings
memset(&hdr, 0, sizeof(hdr)); //Clear all to zero first
strncpy(hdr.fileID, id_string, E2P_ID_SIZE); //Id
@ -248,6 +243,8 @@ int e2pFileBuf::Save(int savetype, long relocation_offset)
unsigned char *localbuf;
localbuf = new unsigned char[hdr.e2pSize];
QDataStream datastream(&fh);
if (localbuf)
{
long s = GetSplitted();
@ -259,18 +256,18 @@ int e2pFileBuf::Save(int savetype, long relocation_offset)
//Initialize local buffer
// if the file already exist read the current content
// otherwise set the localbuffer to 0xFF
rv = fseek(fh, sizeof(hdr), SEEK_SET);
rv = fh.seek( sizeof(hdr));
if (rv == 0)
{
rv = fread(localbuf, hdr.e2pSize, 1, fh);
rv = datastream.readRawData( (char*)localbuf, hdr.e2pSize);
}
else
{
rv = 0;
}
rewind(fh);
fh.seek(0);
}
if (!rv)
@ -314,8 +311,8 @@ int e2pFileBuf::Save(int savetype, long relocation_offset)
hdr.headCrc = mcalc_crc(&hdr, sizeof(hdr) - sizeof(hdr.headCrc));
//Write to file
if ( fwrite(&hdr, sizeof(hdr), 1, fh) && //Write the header
fwrite(localbuf, hdr.e2pSize, 1, fh) ) //Write the buffer
if ( datastream.writeRawData((char*)&hdr, sizeof(hdr)) && //Write the header
datastream.writeRawData((char*)localbuf, hdr.e2pSize) ) //Write the buffer
{
rval = GetNoOfBlock();
}
@ -331,6 +328,6 @@ int e2pFileBuf::Save(int savetype, long relocation_offset)
rval = OUTOFMEMORY;
}
fclose(fh);
fh.close();
return rval;
}

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: e2pfbuf.h,v 1.4 2009/11/16 23:40:43 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //

View File

@ -45,18 +45,26 @@ long BuildE2PType(int pritype, int subtype)
int GetE2PSubType(unsigned long type)
{
if (type == EID_INVALID)
{
return -1;
}
else
{
return (int)(type & 0x7FFF);
}
}
int GetE2PPriType(unsigned long type)
{
// qDebug() << "GetE2PPriType" << type << ((type >> 16) & 0x7F);
if (type == EID_INVALID)
{
return -1;
}
else
{
return (int)((type >> 16) & 0x7F);
}
}

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: filebuf.cpp,v 1.5 2009/11/16 23:40:43 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -27,8 +25,10 @@
//-------------------------------------------------------------------------//
//=========================================================================//
#include <stdio.h>
// #include <stdio.h>
#include <QString>
#include <QFile>
#include <QFileInfo>
#include "types.h"
#include "filebuf.h" // Header file
@ -182,9 +182,9 @@ int FileBuf::GetEEpromSubType() const
//======================>>> FileBuf::SetEEpromType <<<=======================
void FileBuf::SetEEpromType(int pritype, int subtype)
{
extern long BuildE2PType(int pritype, int subtype);
extern long BuildE2PType(int pritype, int subtype);
awi->SetEEProm(BuildE2PType(pritype, subtype));
awi->SetEEProm(BuildE2PType(pritype, subtype));
}
void FileBuf::SetEEpromType(unsigned long id)
@ -194,18 +194,15 @@ void FileBuf::SetEEpromType(unsigned long id)
//======================>>> FileBuf::GetFileSize <<<=======================
long FileBuf::GetFileSize(FILE *fh)
long FileBuf::GetFileSize(QFile &fh)
{
long fsize = 0, old_pos;
if (fh)
if (fh.exists())
{
old_pos = ftell(fh); // salva la posizione attuale
fseek(fh, 0, SEEK_END); // si posizione in fondo al file
fsize = ftell(fh); // ne ricava la lunghezza
fseek(fh, old_pos, SEEK_SET); // si riposizione dove era prima
return fh.size();
}
else
{
return -1;
}
return fsize;
}

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: filebuf.h,v 1.5 2009/11/16 23:40:43 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -31,8 +29,9 @@
#define _FILEBUF_H
#include <QString>
#include <QFile>
#include <stdio.h>
// #include <stdio.h>
#include "types.h"
#include "globals.h"
@ -93,7 +92,7 @@ protected: //--------------------------------------- protected
uint8_t *GetBufPtr() const;
long GetBufSize() const;
e2AppWinInfo *GetAWInfo();
long GetFileSize(FILE *fh);
long GetFileSize(QFile &fh);
FileType file_type; //Identificativo del tipo di file (E2P, INTEL, ...)

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: intfbuf.cpp,v 1.7 2009/11/16 23:40:43 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -27,10 +25,12 @@
//-------------------------------------------------------------------------//
//=========================================================================//
#include <stdio.h>
// #include <stdio.h>
//Estensione al formato Intel Extended HEX
#include <QTextStream>
#include <QString>
#include <stdlib.h>
#include <ctype.h>
@ -63,7 +63,7 @@ IntelFileBuf::~IntelFileBuf()
}
int IntelFileBuf::WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long recsize, int fmt)
int IntelFileBuf::WriteRecord(QFile &fh, uint8_t *bptr, long curaddr, long recsize, int fmt)
{
int rval = 1;
@ -93,39 +93,41 @@ int IntelFileBuf::WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long recsiz
{
int checksum = 0;
int len = recsize;
QTextStream out(&fh);
fprintf(fh, ":");
out << ":";
//byte count
fprintf(fh, "%02X", len & 0xFF);
out << QString().sprintf("%02X", len & 0xFF);
checksum += len & 0xFF;
//addr field
fprintf(fh, "%04lX", curaddr & 0xFFFF);
out << QString().sprintf("%04lX", curaddr & 0xFFFF);
checksum += (curaddr >> 8) & 0xFF;
checksum += curaddr & 0xFF;
//record type
fprintf(fh, "%02X", fmt & 0xFF);
out << QString().sprintf( "%02X", fmt & 0xFF);
checksum += fmt & 0xFF;
for (j = 0; j < recsize; j++)
{
fprintf(fh, "%02X", bptr[curaddr + j]);
out << QString().sprintf( "%02X", bptr[curaddr + j]);
checksum += bptr[curaddr + j];
}
fprintf(fh, "%02X\n", (~checksum + 1) & 0xFF);
out << QString().sprintf("%02X\n", (~checksum + 1) & 0xFF);
}
return rval;
}
int IntelFileBuf::WriteAddressRecord(FILE *fh, long curaddr, bool linear_address)
int IntelFileBuf::WriteAddressRecord(QFile &fh, long curaddr, bool linear_address)
{
int rval = 1;
QTextStream out(&fh);
fprintf(fh, ":");
out << ":";
if (rval)
{
@ -133,16 +135,16 @@ int IntelFileBuf::WriteAddressRecord(FILE *fh, long curaddr, bool linear_address
int len = 2;
//byte count
fprintf(fh, "%02X", len & 0xFF);
out << QString().sprintf( "%02X", len & 0xFF);
checksum += len & 0xFF;
//addr field
fprintf(fh, "%04X", 0);
out << QString().sprintf( "%04X", 0);
if (linear_address)
{
//record type
fprintf(fh, "%02X", LIN_ADDR_RECORD & 0xFF);
out << QString().sprintf( "%02X", LIN_ADDR_RECORD & 0xFF);
checksum += LIN_ADDR_RECORD & 0xFF;
//adjust extended linear address
@ -151,18 +153,18 @@ int IntelFileBuf::WriteAddressRecord(FILE *fh, long curaddr, bool linear_address
else
{
//record type
fprintf(fh, "%02X", SEG_ADDR_RECORD & 0xFF);
out << QString().sprintf("%02X", SEG_ADDR_RECORD & 0xFF);
checksum += SEG_ADDR_RECORD & 0xFF;
//adjust extended segmented address
curaddr >>= 4;
}
fprintf(fh, "%04lX", curaddr & 0xFFFF);
out << QString().sprintf( "%04lX", curaddr & 0xFFFF);
checksum += (curaddr >> 8) & 0xFF;
checksum += curaddr & 0xFF;
fprintf(fh, "%02X\n", (~checksum + 1) & 0xFF);
out << QString().sprintf( "%02X\n", (~checksum + 1) & 0xFF);
}
return rval;
@ -174,12 +176,12 @@ int IntelFileBuf::WriteAddressRecord(FILE *fh, long curaddr, bool linear_address
//======================>>> IntelFileBuf::Save <<<=======================
int IntelFileBuf::Save(int savetype, long relocation_offset)
{
FILE *fh;
QFile fh(FileBuf::GetFileName());
int rval = OK;
(void)relocation_offset;
if ( (fh = fopen(FileBuf::GetFileName().toLatin1(), "w")) == NULL )
if (!fh.open(QIODevice::WriteOnly | QIODevice::Text ))
{
return CREATEERROR;
}
@ -202,7 +204,7 @@ int IntelFileBuf::Save(int savetype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
@ -215,7 +217,7 @@ int IntelFileBuf::Save(int savetype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
@ -254,7 +256,7 @@ int IntelFileBuf::Save(int savetype, long relocation_offset)
rval = NOTHINGTOSAVE;
}
fclose(fh);
fh.close();
return rval;
}
@ -293,9 +295,9 @@ int IntelFileBuf::Load(int loadtype, long relocation_offset)
uint32_t laddr = 0;
FILE *fh;
QFile fh(GetFileName());
if ( (fh = fopen(GetFileName().toLatin1(), "r")) == NULL )
if (!fh.open(QIODevice::ReadOnly | QIODevice::Text ))
{
return FILENOTFOUND;
}
@ -304,8 +306,10 @@ int IntelFileBuf::Load(int loadtype, long relocation_offset)
char riga[MAXLINE + 1];
riga[MAXLINE] = '\0';
while ( fgets(riga, MAXLINE, fh) )
while (!fh.atEnd())
{
fh.readLine(riga, MAXLINE);
char *s;
int k;
@ -502,7 +506,7 @@ int IntelFileBuf::Load(int loadtype, long relocation_offset)
}
}
fclose(fh);
fh.close();
if (okline_counter == 0)
{

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: intfbuf.h,v 1.4 2009/11/16 22:29:18 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -30,6 +28,8 @@
#ifndef _INTELFBUF_H
#define _INTELFBUF_H
#include <QFile>
#include "types.h"
#include "filebuf.h"
#include "device.h"
@ -49,8 +49,8 @@ protected: //--------------------------------------- protected
private: //--------------------------------------- private
int WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long recsize, int fmt);
int WriteAddressRecord(FILE *fh, long curaddr, bool linear_address = false);
int WriteRecord(QFile &fh, uint8_t *bptr, long curaddr, long recsize, int fmt);
int WriteAddressRecord(QFile &fh, long curaddr, bool linear_address = false);
int ScanHex(char **sp, int len, uint32_t &result);
int ScanHex(char **sp, int len, uint16_t &result);

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: motsfbuf.cpp,v 1.9 2009/11/16 22:29:18 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -27,8 +25,9 @@
//-------------------------------------------------------------------------//
//=========================================================================//
#include <stdio.h>
// #include <stdio.h>
#include <QString>
#include <QTextStream>
#include <stdlib.h>
@ -69,7 +68,7 @@ MotorolaSFileBuf::~MotorolaSFileBuf()
}
int MotorolaSFileBuf::WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long recsize, int fmt)
int MotorolaSFileBuf::WriteRecord(QTextStream &outs, uint8_t *bptr, long curaddr, long recsize, int fmt)
{
int rval = 1;
int len = 0;
@ -153,23 +152,23 @@ int MotorolaSFileBuf::WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long re
int checksum = 0;
//type field
fprintf(fh, "S%c", fmt);
outs << QString().sprintf("S%c", fmt);
//len field
fprintf(fh, "%02X", len & 0xFF);
outs << QString().sprintf("%02X", len & 0xFF);
checksum += len & 0xFF;
//addr field
if (fmt == DATA_RECORD24 || fmt == END_RECORD24)
{
fprintf(fh, "%06lX", curaddr & 0xFFFFFF);
outs << QString().sprintf("%06lX", curaddr & 0xFFFFFF);
checksum += (curaddr >> 16) & 0xFF;
checksum += (curaddr >> 8) & 0xFF;
checksum += curaddr & 0xFF;
}
else if (fmt == DATA_RECORD32 || fmt == END_RECORD32)
{
fprintf(fh, "%08lX", curaddr);
outs << QString().sprintf("%08lX", curaddr);
checksum += (curaddr >> 24) & 0xFF;
checksum += (curaddr >> 16) & 0xFF;
checksum += (curaddr >> 8) & 0xFF;
@ -177,18 +176,18 @@ int MotorolaSFileBuf::WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long re
}
else //all other have a 16 bit address field
{
fprintf(fh, "%04lX", curaddr & 0xFFFF);
outs << QString().sprintf("%04lX", curaddr & 0xFFFF);
checksum += (curaddr >> 8) & 0xFF;
checksum += curaddr & 0xFF;
}
for (j = 0; j < recsize; j++)
{
fprintf(fh, "%02X", bptr[curaddr + j]);
outs << QString().sprintf("%02X", bptr[curaddr + j]);
checksum += bptr[curaddr + j];
}
fprintf(fh, "%02X\n", ~checksum & 0xFF);
outs << QString().sprintf("%02X\n", ~checksum & 0xFF);
}
return rval;
@ -199,14 +198,18 @@ int MotorolaSFileBuf::WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long re
//======================>>> MotorolaSFileBuf::Save <<<=======================
int MotorolaSFileBuf::Save(int savetype, long relocation_offset)
{
FILE *fh;
QFile fh(FileBuf::GetFileName());
int rval = OK;
if ( (fh = fopen(FileBuf::GetFileName().toLatin1(), "w")) == NULL )
(void)relocation_offset; //unused
if (!fh.open(QIODevice::WriteOnly))
{
return CREATEERROR;
}
QTextStream out(&fh);
long dsize = FileBuf::GetBlockSize() * FileBuf::GetNoOfBlock();
long size = FileBuf::GetBufSize();
uint8_t *ptr = FileBuf::GetBufPtr();
@ -225,7 +228,7 @@ int MotorolaSFileBuf::Save(int savetype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
@ -238,7 +241,7 @@ int MotorolaSFileBuf::Save(int savetype, long relocation_offset)
}
else
{
fclose(fh);
fh.close();
return 0;
}
}
@ -248,7 +251,7 @@ int MotorolaSFileBuf::Save(int savetype, long relocation_offset)
char rectype;
long curaddr = 0;
WriteRecord(fh, ptr, 0, 0, START_RECORD);
WriteRecord(out, ptr, 0, 0, START_RECORD);
while (curaddr < size)
{
@ -266,7 +269,7 @@ int MotorolaSFileBuf::Save(int savetype, long relocation_offset)
rectype = DATA_RECORD32;
}
if ( !WriteRecord(fh, ptr, curaddr, recsize, rectype) )
if ( !WriteRecord(out, ptr, curaddr, recsize, rectype) )
{
rval = WRITEERROR;
break;
@ -287,7 +290,7 @@ int MotorolaSFileBuf::Save(int savetype, long relocation_offset)
rectype = END_RECORD32;
}
WriteRecord(fh, ptr, 0, 0, rectype);
WriteRecord(out, ptr, 0, 0, rectype);
rval = curaddr;
}
@ -296,7 +299,7 @@ int MotorolaSFileBuf::Save(int savetype, long relocation_offset)
rval = NOTHINGTOSAVE;
}
fclose(fh);
fh.close();
return rval;
}
@ -337,9 +340,9 @@ int MotorolaSFileBuf::Load(int loadtype, long relocation_offset)
highestAddr = 0;
lowestAddr = 0x7fffffff;
FILE *fh;
QFile fh(GetFileName());
if ( (fh = fopen(GetFileName().toLatin1(), "r")) == NULL )
if (!fh.open(QIODevice::ReadOnly | QIODevice::Text))
{
return FILENOTFOUND;
}
@ -349,8 +352,10 @@ int MotorolaSFileBuf::Load(int loadtype, long relocation_offset)
char riga[MAXLINE + 1];
riga[MAXLINE] = '\0';
while ( fgets(riga, MAXLINE, fh) )
while (!fh.atEnd())
{
fh.readLine(riga, MAXLINE);
if ( (rval = ParseRecord(riga, dp, endp, 0, nocopy_mode)) != OK )
{
if (rval == BUFFEROVERFLOW)
@ -380,12 +385,15 @@ int MotorolaSFileBuf::Load(int loadtype, long relocation_offset)
highestAddr = 0;
lowestAddr = 0x7fffffff;
rewind(fh);
fh.seek(0);
// rewind(fh);
riga[MAXLINE] = '\0';
while ( fgets(riga, MAXLINE, fh) )
while ( !fh.atEnd())
{
fh.readLine(riga, MAXLINE);
if ( (rval = ParseRecord(riga, dp, endp, l_offset, nocopy_mode)) != OK )
{
break;
@ -403,7 +411,7 @@ int MotorolaSFileBuf::Load(int loadtype, long relocation_offset)
img_size = highestPC + 1 - dp;
}
fclose(fh);
fh.close();
//This format doesn't contain information about the device size,
// so keep the size of the selected eeprom

View File

@ -7,8 +7,6 @@
// http://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// $Id: motsfbuf.h,v 1.6 2009/11/16 22:29:18 lancos Exp $
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
@ -32,6 +30,8 @@
#ifndef _MOTOSFBUF_H
#define _MOTOSFBUF_H
#include <QTextStream>
#include "types.h"
#include "filebuf.h"
@ -50,7 +50,7 @@ protected: //--------------------------------------- protected
private: //--------------------------------------- private
int WriteRecord(FILE *fh, uint8_t *bptr, long curaddr, long recsize, int fmt);
int WriteRecord(QTextStream &outs, uint8_t *bptr, long curaddr, long recsize, int fmt);
int ParseRecord(char *lbufPC, uint8_t *buf_startP, uint8_t *buf_endP, long offset, int nocopy);
uint8_t *highestPC;

View File

@ -27,12 +27,14 @@
//-------------------------------------------------------------------------//
//=========================================================================//
#include <stdio.h>
// #include <stdio.h>
#include "portint.h"
#include "errcode.h"
#include <QDebug>
#include <QString>
#include <QFile>
#include <QTextStream>
#include "globals.h"
@ -1034,7 +1036,7 @@ void PortInterface::DetectPorts9x()
delete KeyList;
}
static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_len *ports, int nports);
static int DetectPortsNT(const QString &ServiceName, const QString &PortFormat, base_len *ports, int nports);
//---------------------------------------------------------------------------
// DetectPorts() Win2K / NT version
@ -1051,9 +1053,8 @@ void PortInterface::DetectCOMPortsNT()
// Static member function
// See the two possible usage examples above!
static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_len *ports, int nports)
static int DetectPortsNT(const QString &ServiceName, const QString &PortFormat, base_len *ports, int nports)
{
FILE *fh;
LONG retval;
// This revised code keeps some registry keys open, rather than collecting intermediate strings.
// No silly key enumeration at all!
@ -1061,13 +1062,17 @@ static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_l
char buf[MAX_PATH]; // handy stack-allocated multi-purpose buffer
int Count = 0; // return value (can be greater than nports)
fh = fopen("detect_ports_NT.log", "a");
QFile fh("detect_ports_NT.log");
if (fh)
if (!fh.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
{
fprintf(fh, "Enter DetectPortsNT(%s, %s, %p, %d)\n", ServiceName, PortFormat, ports, nports);
return -1;
}
QTextStream out(&fh);
out << "Enter DetectPortsNT(" << ServiceName << ", " << PortFormat << ", " << (hex) << ports << (dec) << ", " << nports << ")\n";
memset(ports, 0, nports * sizeof(base_len)); // Clear port array
HKEY hCCS; // Open the registry (first stage)
retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet", 0, KEY_PERMISSIONS, &hCCS);
@ -1085,10 +1090,7 @@ static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_l
if (retval == ERROR_SUCCESS)
{
if (fh)
{
fprintf(fh, "Port count: %d)\n", Count);
}
out << "Port count: " << Count << ")\n";
for (int i = 0; i < Count; i++)
{
@ -1101,10 +1103,7 @@ static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_l
{
HKEY hParams;
if (fh)
{
fprintf(fh, "Cycle: %d, PNPPath: %s\n", i, PnpPath);
}
out << "Cycle: " << i << ", PNPPath: " << PnpPath << "\n";
_snprintf(buf, sizeof(buf), "Enum\\%s\\Device Parameters", PnpPath);
retval = RegOpenKeyEx(hCCS, buf, 0, KEY_PERMISSIONS, &hParams);
@ -1139,8 +1138,7 @@ static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_l
&& !p[3] // no high DWORD part
&& p[4] >= 8 && p[4] < 16) // length limited to 16
{
if (fh) fprintf(fh, "p=%p [0]=%lu, [1]=%lu, [2]=%lxh, [3]=%lxh, [4]=%lu\n",
(void *)p, p[0], p[1], p[2], p[3], p[4]);
out << "p=" << (hex) << (void *)p << (dec) << " [0]=" << p[0] << ", [1]=" << p[1] << ", [2]=" << (hex) << p[2] << "h, [3]=" << p[3] << "h, [4]=" << (dec) << p[4] << "\n";
ports[Index].base = p[2]; // We got one
ports[Index].len = p[4]; // (NO check for typical ISA addresses anymore!!)
@ -1148,20 +1146,14 @@ static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_l
}
else
{
if (fh)
{
fprintf(fh, "RegQueryValueEx(AllocConfig) Failed with code %ld\n", retval);
}
out << "RegQueryValueEx(AllocConfig) Failed with code " << retval << "\n";
}
RegCloseKey(hControl);
}
else
{
if (fh)
{
fprintf(fh, "RegOpenKeyEx(%s) Failed with code %ld\n", buf, retval);
}
out << "RegOpenKeyEx(" << buf << ") Failed with code " << retval << "\n";
}
}
@ -1169,47 +1161,32 @@ static int DetectPortsNT(const char *ServiceName, const char *PortFormat, base_l
}
else
{
if (fh)
{
fprintf(fh, "RegOpenKeyEx(%s) Failed with code %ld\n", buf, retval);
}
out << "RegOpenKeyEx(" << buf << ") Failed with code " << retval << "\n";
}
}
} //for
}
else
{
if (fh)
{
fprintf(fh, "RegQueryValueEx(Count) Failed with code %ld\n", retval);
}
out << "RegQueryValueEx(Count) Failed with code " << retval << "\n";
}
RegCloseKey(hSvcEnum);
}
else
{
if (fh)
{
fprintf(fh, "RegOpenKeyEx(%s) Failed with code %ld\n", buf, retval);
}
out << "RegOpenKeyEx(" << buf << ") Failed with code " << retval << "\n";
}
RegCloseKey(hCCS);
}
else
{
if (fh)
{
fprintf(fh, "RegOpenKeyEx(HKEY_LOCAL_MACHINE, SYSTEM\\CurrentControlSet) Failed with code %ld\n", retval);
}
out << "RegOpenKeyEx(HKEY_LOCAL_MACHINE, SYSTEM\\CurrentControlSet) Failed with code " << retval << "\n";
}
if (fh)
{
fprintf(fh, "Enter DetectPortsNT() *** Count = %d\n", Count);
fclose(fh);
}
out << "Enter DetectPortsNT() *** Count = " << count << "\n";
fh.close();
return (Count < nports) ? Count : nports;
}