Could someone take a look please?
OK, I am getting these compile warnings. At least they are presented
as warnings, but I'm not sure they really are as the app segfaults when I
run it.
I've attached the .h and .cpp files in question, along with the
output from make. If someone could spare the time to take a look and let
me know if this is something they've seen, etc, I'd appreciate it very
much.
BTW: Linux/gcc egcs-2.91.66/SuSE 6.1/V 1.22
Could this possibly be a problem because the expat lib is compiled
as C?
--
Ken Weinert kenw@ihs.com 303-858-6956 (V) 978-336-5652 (F)
PGP: DF 2B 6C 72 33 BE 06 D1 9D C4 ED 32 36 97 C0 6E
You may be right.
I may be crazy.
But a lunatic may be just what you're looking for. -- B. Joel
// ===== -*- c++ -*- ====================================================
// xvcmdw.h: Header for xvcmdw class
//=======================================================================
#ifndef xvCMDW_H
#define xvCMDW_H
#include <diamond/dbase.h>
#include <v/vcmdwin.h> // So we can use vCmdWindow
#include <v/vmenu.h> // For the menu pane
#include <v/vutil.h> // For V Utilities
#include <v/vcmdpane.h> // command pane
#include <v/vstatusp.h> // For the status pane
#ifdef vDEBUG
#include <v/vdebug.h>
#endif
#include "xvcnv.h" // xvTextCanvasPane
#include "xvdlg.h" // xvDialog
#include "xvmdlg.h" // xvModalDialog
#include "viewer.h" // diamondbase
extern diamondBase theDiamondBase;
#include <xmlparse.h> // xml parser
class xvCmdWindow : public vCmdWindow
{
friend int AppMain(int, char**); // allow AppMain access
public: //---------------------------------------- public
xvCmdWindow(char*, int, int);
virtual ~xvCmdWindow();
virtual void WindowCommand(ItemVal id, ItemVal val, CmdType cType);
virtual void KeyIn(vKey keysym, unsigned int shift);
protected: //--------------------------------------- protected
private: //--------------------------------------- private
// new routines
void inputFileName(char* name);
char* inputFileName(void);
void parseInput(void);
// parser related routines
void startElement(void* userData, const XML_Char* name,
const XML_Char** attrs);
void endElement(void* userData, const XML_Char* name);
void contentHandler(void* userData, const XML_Char* s, int len);
XML_Parser _parser; // parser instance for reading in the report
// database classes
planet _cPlanet;
player _cPlayer;
info _cInfo;
map _cMap;
groups _cGroups;
fleets _cFleets;
char _inputFileName[1024];
// Standard elements
vMenuPane* xvMenu; // For the menu bar
xvTextCanvasPane* xvReportCanvas; // For the canvas
vCommandPane* xvCmdPane; // for the command pane
vStatusPane* xvStatus; // For the status bar
// Dialogs associated with CmdWindow
xvDialog* xvDlg;
xvModalDialog* xvMDlg;
};
#endif
//=======================================================================
//@V@:Note: This file generated by vgen V1.07 (02:35:11 PM 20 Oct 1999).
// xvcmdw.cpp: Source for xvCmdWindow class
//=======================================================================
#include <v/vnotice.h> // for vNoticeDialog
#include <v/vkeys.h> // to map keys
#include <v/vfilesel.h>
#include "xvcmdw.h" // our header
// Start defines for the main window with 100
//@V@:BeginIDs
enum {
m_FirstCmd = 100, // Dummy Command
m_TestDialog, // TestDialog menu
m_Dialog, // TestDialog menu
m_ModalDialog, // TestDialog menu
btnTestTool, // Tool Bar test
lblTestStat, // Status Bar test
blkLast // Last item
};
//@V@:EndIDs
//@V@:BeginPulldownMenu FileMenu
static vMenu FileMenu[] =
{
{"&New", M_New, isSens, notChk, noKeyLbl, noKey, noSub},
{"&Open...", M_Open, isSens, notChk, noKeyLbl, noKey, noSub},
{"&Save", M_Save, isSens, notChk, noKeyLbl, noKey, noSub},
{"Save &as...", M_SaveAs, isSens, notChk, noKeyLbl, noKey, noSub},
{"&Close...", M_CloseFile, isSens, notChk, noKeyLbl, noKey, noSub},
{"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
{"E&xit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
{NULL}
};
//@V@:EndPulldownMenu
//@V@:BeginPulldownMenu EditMenu
static vMenu EditMenu[] =
{
{"Cut ", M_Cut, isSens, notChk, "Ctrl-X", 'X'-'@', noSub},
{"Copy ", M_Copy, isSens, notChk, "Ctrl-C", 'C'-'@', noSub},
{"Paste", M_Paste, isSens, notChk, "Ctrl-V", 'V'-'@', noSub},
{NULL}
};
//@V@:EndPulldownMenu
//@V@:BeginPulldownMenu TestDialog
static vMenu TestDialog[] =
{
{"Dialog", m_Dialog, isSens, notChk, noKeyLbl, noKey, noSub},
{"Modal Dialog", m_ModalDialog, isSens, notChk, noKeyLbl, noKey, noSub},
{NULL}
};
//@V@:EndPulldownMenu
//@V@:BeginMenu StandardMenu
static vMenu StandardMenu[] =
{
{"&File", M_File, isSens, notUsed, notUsed, noKey, &FileMenu[0]},
{"&Edit", M_Edit, isSens, notUsed, notUsed, noKey, &EditMenu[0]},
{"&TestDialog", m_TestDialog, isSens, notUsed, notUsed, noKey, &TestDialog[0]},
{NULL}
};
//@V@:EndMenu
//@V@:BeginCmdPane ToolBar
static CommandObject ToolBar[] =
{
{C_Button,btnTestTool,0,"Test",NoList,CA_None,isSens,NoFrame,0,0},
{C_EndOfList,0,0,0,0,CA_None,0,0,0}
};
//@V@:EndCmdPane
//@V@:BeginStatPane StatBar
static vStatus StatBar[] =
{
{"Galaxy XML Report Viewer", lblTestStat, CA_NoBorder, isSens, 0},
{0,0,0,0,0}
};
//@V@:EndStatPane
//====================>>> xvCmdWindow::xvCmdWindow <<<====================
xvCmdWindow::xvCmdWindow(char* name, int width, int height) :
vCmdWindow(name, width, height)
{
UserDebug1(Constructor,"xvCmdWindow::xvCmdWindow(%s) Constructor\n",name);
// The Menu Bar
xvMenu = new vMenuPane(StandardMenu);
AddPane(xvMenu);
// The Command Pane
xvCmdPane = new vCommandPane(ToolBar);
AddPane(xvCmdPane);
// The Canvas
xvReportCanvas = new xvTextCanvasPane;
AddPane(xvReportCanvas);
// The Status Bar
xvStatus = new vStatusPane(StatBar);
AddPane(xvStatus);
// Associated dialogs
xvDlg = new xvDialog(this,name);
xvMDlg = new xvModalDialog(this,name);
// Show Window
ShowWindow();
xvReportCanvas->ShowVScroll(1); // Show Vert Scroll
xvReportCanvas->ShowHScroll(1); // Show Horiz Scroll
}
//====================>>> xvCmdWindow::~xvCmdWindow <<<====================
xvCmdWindow::~xvCmdWindow()
{
UserDebug(Destructor,"xvCmdWindow::~xvCmdWindow() destructor\n");
// Now put a delete for each new in the constructor.
delete xvMenu;
delete xvReportCanvas;
delete xvCmdPane;
delete xvStatus;
delete xvDlg;
delete xvMDlg;
}
//====================>>> xvCmdWindow::KeyIn <<<====================
void xvCmdWindow::KeyIn(vKey keysym, unsigned int shift)
{
vCmdWindow::KeyIn(keysym, shift);
}
//====================>>> xvCmdWindow::WindowCommand <<<====================
void xvCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
{
// Default: route menu and toolbar commands here
UserDebug1(CmdEvents,"xvCmdWindow:WindowCommand(%d)\n",id);
switch (id)
{
//@V@:Case M_New
case M_New:
{
vNoticeDialog note(this);
note.Notice("New");
break;
} //@V@:EndCase
//@V@:Case M_Open
case M_Open:
{
vNoticeDialog note(this);
static char strInputFileName[1024];
static char* filter[] =
{
"*.xml",
"*.*",
NULL
};
static int fi = 0;
vFileSelect turnSel(this);
int oans = turnSel.FileSelect("Open Turn File", strInputFileName,
1024, filter, fi);
if (oans && *strInputFileName)
{
note.Notice(strInputFileName);
SetString(lblTestStat, strInputFileName);
inputFileName(strInputFileName);
note.Notice("click me");
parseInput();
}
break;
} //@V@:EndCase
//@V@:Case M_Save
case M_Save:
{
vNoticeDialog note(this);
note.Notice("Save");
break;
} //@V@:EndCase
//@V@:Case M_SaveAs
case M_SaveAs:
{
vNoticeDialog note(this);
note.Notice("Save As");
break;
} //@V@:EndCase
//@V@:Case M_CloseFile
case M_CloseFile:
{
vNoticeDialog note(this);
note.Notice("Close File");
break;
} //@V@:EndCase
//@V@:Case M_Exit
case M_Exit:
{
theApp->Exit();
break;
} //@V@:EndCase
//@V@:Case M_Cut
case M_Cut:
{
vNoticeDialog note(this);
note.Notice("Cut");
break;
} //@V@:EndCase
//@V@:Case M_Copy
case M_Copy:
{
vNoticeDialog note(this);
note.Notice("Copy");
break;
} //@V@:EndCase
//@V@:Case M_Paste
case M_Paste:
{
vNoticeDialog note(this);
note.Notice("Paste");
break;
} //@V@:EndCase
//@V@:Case m_Dialog
case m_Dialog:
{
if (!xvDlg->IsDisplayed())
{
xvDlg->ShowDialog("Sample Modeless Dialog");
}
break;
} //@V@:EndCase
//@V@:Case m_ModalDialog
case m_ModalDialog:
{
ItemVal rval = xvMDlg->xvAction("Sample Modal Dialog");
break;
} //@V@:EndCase
//@V@:Case btnTestTool
case btnTestTool:
{
vNoticeDialog note(this);
note.Notice("Tool Bar Test");
break;
} //@V@:EndCase
default: // route unhandled commands up
{
vCmdWindow::WindowCommand(id, val, cType);
break;
}
}
}
//==================>>> xvCmdWindow::contentHandler <<<======================
void xvCmdWindow::contentHandler(void* userData, const XML_Char* s,
int len)
{
int i;
if (s[0] == '\n')
{
return;
}
for (i = 0; i < len; i++)
{
xvReportCanvas->DrawChar(s[i], ChNormal);
}
xvReportCanvas->DrawChar('\n', ChNormal);
}
//====================>>> xvCmdWindow::startElement <<<======================
void xvCmdWindow::startElement(void *userData, const char *name,
const char **atts)
{
int i;
char* ptr;
int *depthPtr;
depthPtr = (int*)userData;
char strTmp[2048];
sprintf(strTmp, "name: \"%s\" depth:%d\n", name, *depthPtr);
SetString(lblTestStat, strTmp);
for (i = 0; i < *depthPtr; i++)
{
xvReportCanvas->DrawChar('\t', ChNormal);
}
xvReportCanvas->DrawText(name);
if (atts[0] != NULL)
{
xvReportCanvas->DrawChar('(', ChNormal);
i = 0;
while (atts[i] != NULL)
{
xvReportCanvas->DrawText(atts[i++]);
if (atts[i])
{
xvReportCanvas->DrawText(", ");
}
}
xvReportCanvas->DrawChar(')', ChNormal);
}
*depthPtr += 1;
}
//====================>>> xvCmdWindow::endElement <<<=======================
void xvCmdWindow::endElement(void *userData, const char *name)
{
int *depthPtr;
depthPtr = (int*)userData;
*depthPtr -= 1;
}
//=================>>> xvCmdWindow::inputFileName(arg) <<<===================
void
xvCmdWindow::inputFileName(char* name)
{
strcpy(_inputFileName, name);
}
//=================>>> xvCmdWindow::inputFileName(void) <<<==================
char*
xvCmdWindow::inputFileName(void)
{
static char strFileName[1024];
strcpy(strFileName, _inputFileName);
return strFileName;
}
//=================>>> xvCmdWindow::parseInput(void) <<<====================
void
xvCmdWindow::parseInput(void)
{
int done;
int depth = 0;
char buf[10240];
_parser = XML_ParserCreate(NULL);
XML_SetUserData(_parser, &depth);
XML_SetElementHandler(_parser, xvCmdWindow::startElement,
xvCmdWindow::endElement);
XML_SetCharacterDataHandler(_parser, xvCmdWindow::contentHandler);
FILE* inFP = fopen(inputFileName(), "r");
if (inFP == NULL)
{
vNoticeDialog note(this);
note.Notice("couldn't open input file");
return;
}
do
{
fpos_t location;
fgetpos(inFP, &location);
fgets(buf, sizeof(buf), inFP);
if (strstr(buf, "<?xml") != NULL)
{
fsetpos(inFP, &location);
break;
}
}
while (!feof(inFP));
do {
char errmsg[1024];
size_t len = fread(buf, 1, sizeof(buf), inFP);
done = len < sizeof(buf);
if (!XML_Parse(_parser, buf, len, done)) {
sprintf(errmsg,
"%s at line %d\n",
XML_ErrorString(XML_GetErrorCode(_parser)),
XML_GetCurrentLineNumber(_parser));
vNoticeDialog note(this);
note.Notice(errmsg);
return;
}
} while (!done);
XML_ParserFree(_parser);
}
//=======================================================================
//@V@:Note: This file generated by vgen V1.07 (02:35:11 PM 20 Oct 1999).
// xvcmdw.cpp: Source for xvCmdWindow class
//=======================================================================
#include <v/vnotice.h> // for vNoticeDialog
#include <v/vkeys.h> // to map keys
#include <v/vfilesel.h>
#include "xvcmdw.h" // our header
// Start defines for the main window with 100
//@V@:BeginIDs
enum {
m_FirstCmd = 100, // Dummy Command
m_TestDialog, // TestDialog menu
m_Dialog, // TestDialog menu
m_ModalDialog, // TestDialog menu
btnTestTool, // Tool Bar test
lblTestStat, // Status Bar test
blkLast // Last item
};
//@V@:EndIDs
//@V@:BeginPulldownMenu FileMenu
static vMenu FileMenu[] =
{
{"&New", M_New, isSens, notChk, noKeyLbl, noKey, noSub},
{"&Open...", M_Open, isSens, notChk, noKeyLbl, noKey, noSub},
{"&Save", M_Save, isSens, notChk, noKeyLbl, noKey, noSub},
{"Save &as...", M_SaveAs, isSens, notChk, noKeyLbl, noKey, noSub},
{"&Close...", M_CloseFile, isSens, notChk, noKeyLbl, noKey, noSub},
{"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
{"E&xit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
{NULL}
};
//@V@:EndPulldownMenu
//@V@:BeginPulldownMenu EditMenu
static vMenu EditMenu[] =
{
{"Cut ", M_Cut, isSens, notChk, "Ctrl-X", 'X'-'@', noSub},
{"Copy ", M_Copy, isSens, notChk, "Ctrl-C", 'C'-'@', noSub},
{"Paste", M_Paste, isSens, notChk, "Ctrl-V", 'V'-'@', noSub},
{NULL}
};
//@V@:EndPulldownMenu
//@V@:BeginPulldownMenu TestDialog
static vMenu TestDialog[] =
{
{"Dialog", m_Dialog, isSens, notChk, noKeyLbl, noKey, noSub},
{"Modal Dialog", m_ModalDialog, isSens, notChk, noKeyLbl, noKey, noSub},
{NULL}
};
//@V@:EndPulldownMenu
//@V@:BeginMenu StandardMenu
static vMenu StandardMenu[] =
{
{"&File", M_File, isSens, notUsed, notUsed, noKey, &FileMenu[0]},
{"&Edit", M_Edit, isSens, notUsed, notUsed, noKey, &EditMenu[0]},
{"&TestDialog", m_TestDialog, isSens, notUsed, notUsed, noKey, &TestDialog[0]},
{NULL}
};
//@V@:EndMenu
//@V@:BeginCmdPane ToolBar
static CommandObject ToolBar[] =
{
{C_Button,btnTestTool,0,"Test",NoList,CA_None,isSens,NoFrame,0,0},
{C_EndOfList,0,0,0,0,CA_None,0,0,0}
};
//@V@:EndCmdPane
//@V@:BeginStatPane StatBar
static vStatus StatBar[] =
{
{"Galaxy XML Report Viewer", lblTestStat, CA_NoBorder, isSens, 0},
{0,0,0,0,0}
};
//@V@:EndStatPane
//====================>>> xvCmdWindow::xvCmdWindow <<<====================
xvCmdWindow::xvCmdWindow(char* name, int width, int height) :
vCmdWindow(name, width, height)
{
UserDebug1(Constructor,"xvCmdWindow::xvCmdWindow(%s) Constructor\n",name);
// The Menu Bar
xvMenu = new vMenuPane(StandardMenu);
AddPane(xvMenu);
// The Command Pane
xvCmdPane = new vCommandPane(ToolBar);
AddPane(xvCmdPane);
// The Canvas
xvReportCanvas = new xvTextCanvasPane;
AddPane(xvReportCanvas);
// The Status Bar
xvStatus = new vStatusPane(StatBar);
AddPane(xvStatus);
// Associated dialogs
xvDlg = new xvDialog(this,name);
xvMDlg = new xvModalDialog(this,name);
// Show Window
ShowWindow();
xvReportCanvas->ShowVScroll(1); // Show Vert Scroll
xvReportCanvas->ShowHScroll(1); // Show Horiz Scroll
}
//====================>>> xvCmdWindow::~xvCmdWindow <<<====================
xvCmdWindow::~xvCmdWindow()
{
UserDebug(Destructor,"xvCmdWindow::~xvCmdWindow() destructor\n");
// Now put a delete for each new in the constructor.
delete xvMenu;
delete xvReportCanvas;
delete xvCmdPane;
delete xvStatus;
delete xvDlg;
delete xvMDlg;
}
//====================>>> xvCmdWindow::KeyIn <<<====================
void xvCmdWindow::KeyIn(vKey keysym, unsigned int shift)
{
vCmdWindow::KeyIn(keysym, shift);
}
//====================>>> xvCmdWindow::WindowCommand <<<====================
void xvCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
{
// Default: route menu and toolbar commands here
UserDebug1(CmdEvents,"xvCmdWindow:WindowCommand(%d)\n",id);
switch (id)
{
//@V@:Case M_New
case M_New:
{
vNoticeDialog note(this);
note.Notice("New");
break;
} //@V@:EndCase
//@V@:Case M_Open
case M_Open:
{
vNoticeDialog note(this);
static char strInputFileName[1024];
static char* filter[] =
{
"*.xml",
"*.*",
NULL
};
static int fi = 0;
vFileSelect turnSel(this);
int oans = turnSel.FileSelect("Open Turn File", strInputFileName,
1024, filter, fi);
if (oans && *strInputFileName)
{
note.Notice(strInputFileName);
SetString(lblTestStat, strInputFileName);
inputFileName(strInputFileName);
note.Notice("click me");
parseInput();
}
break;
} //@V@:EndCase
//@V@:Case M_Save
case M_Save:
{
vNoticeDialog note(this);
note.Notice("Save");
break;
} //@V@:EndCase
//@V@:Case M_SaveAs
case M_SaveAs:
{
vNoticeDialog note(this);
note.Notice("Save As");
break;
} //@V@:EndCase
//@V@:Case M_CloseFile
case M_CloseFile:
{
vNoticeDialog note(this);
note.Notice("Close File");
break;
} //@V@:EndCase
//@V@:Case M_Exit
case M_Exit:
{
theApp->Exit();
break;
} //@V@:EndCase
//@V@:Case M_Cut
case M_Cut:
{
vNoticeDialog note(this);
note.Notice("Cut");
break;
} //@V@:EndCase
//@V@:Case M_Copy
case M_Copy:
{
vNoticeDialog note(this);
note.Notice("Copy");
break;
} //@V@:EndCase
//@V@:Case M_Paste
case M_Paste:
{
vNoticeDialog note(this);
note.Notice("Paste");
break;
} //@V@:EndCase
//@V@:Case m_Dialog
case m_Dialog:
{
if (!xvDlg->IsDisplayed())
{
xvDlg->ShowDialog("Sample Modeless Dialog");
}
break;
} //@V@:EndCase
//@V@:Case m_ModalDialog
case m_ModalDialog:
{
ItemVal rval = xvMDlg->xvAction("Sample Modal Dialog");
break;
} //@V@:EndCase
//@V@:Case btnTestTool
case btnTestTool:
{
vNoticeDialog note(this);
note.Notice("Tool Bar Test");
break;
} //@V@:EndCase
default: // route unhandled commands up
{
vCmdWindow::WindowCommand(id, val, cType);
break;
}
}
}
//==================>>> xvCmdWindow::contentHandler <<<======================
void xvCmdWindow::contentHandler(void* userData, const XML_Char* s,
int len)
{
int i;
if (s[0] == '\n')
{
return;
}
for (i = 0; i < len; i++)
{
xvReportCanvas->DrawChar(s[i], ChNormal);
}
xvReportCanvas->DrawChar('\n', ChNormal);
}
//====================>>> xvCmdWindow::startElement <<<======================
void xvCmdWindow::startElement(void *userData, const char *name,
const char **atts)
{
int i;
char* ptr;
int *depthPtr;
depthPtr = (int*)userData;
char strTmp[2048];
sprintf(strTmp, "name: \"%s\" depth:%d\n", name, *depthPtr);
SetString(lblTestStat, strTmp);
for (i = 0; i < *depthPtr; i++)
{
xvReportCanvas->DrawChar('\t', ChNormal);
}
xvReportCanvas->DrawText(name);
if (atts[0] != NULL)
{
xvReportCanvas->DrawChar('(', ChNormal);
i = 0;
while (atts[i] != NULL)
{
xvReportCanvas->DrawText(atts[i++]);
if (atts[i])
{
xvReportCanvas->DrawText(", ");
}
}
xvReportCanvas->DrawChar(')', ChNormal);
}
*depthPtr += 1;
}
//====================>>> xvCmdWindow::endElement <<<=======================
void xvCmdWindow::endElement(void *userData, const char *name)
{
int *depthPtr;
depthPtr = (int*)userData;
*depthPtr -= 1;
}
//=================>>> xvCmdWindow::inputFileName(arg) <<<===================
void
xvCmdWindow::inputFileName(char* name)
{
strcpy(_inputFileName, name);
}
//=================>>> xvCmdWindow::inputFileName(void) <<<==================
char*
xvCmdWindow::inputFileName(void)
{
static char strFileName[1024];
strcpy(strFileName, _inputFileName);
return strFileName;
}
//=================>>> xvCmdWindow::parseInput(void) <<<====================
void
xvCmdWindow::parseInput(void)
{
int done;
int depth = 0;
char buf[10240];
_parser = XML_ParserCreate(NULL);
XML_SetUserData(_parser, &depth);
XML_SetElementHandler(_parser, xvCmdWindow::startElement,
xvCmdWindow::endElement);
XML_SetCharacterDataHandler(_parser, xvCmdWindow::contentHandler);
FILE* inFP = fopen(inputFileName(), "r");
if (inFP == NULL)
{
vNoticeDialog note(this);
note.Notice("couldn't open input file");
return;
}
do
{
fpos_t location;
fgetpos(inFP, &location);
fgets(buf, sizeof(buf), inFP);
if (strstr(buf, "<?xml") != NULL)
{
fsetpos(inFP, &location);
break;
}
}
while (!feof(inFP));
do {
char errmsg[1024];
size_t len = fread(buf, 1, sizeof(buf), inFP);
done = len < sizeof(buf);
if (!XML_Parse(_parser, buf, len, done)) {
sprintf(errmsg,
"%s at line %d\n",
XML_ErrorString(XML_GetErrorCode(_parser)),
XML_GetCurrentLineNumber(_parser));
vNoticeDialog note(this);
note.Notice(errmsg);
return;
}
} while (!done);
XML_ParserFree(_parser);
}
Reply to: