linux c++ equivalent

J

Jon

For the past month I have been porting a DirectX windows game to libSDL
on linux, for right now I am working on the basic syntax of the game
engine, I was having problems with opening, reading, and closeing of
directories, I have fixed that though...who woulda thought that it would
be open, read, and closedir()?

Anyway, I am still working on the syntax, and I have been getting these
errors when I compile:

UEngine.cpp: In member function `void UEngine::doGameMenu()':
UEngine.cpp:677: error: `fileinfo' undeclared (first use this function)
UEngine.cpp:677: error: (Each undeclared identifier is reported only
once for
each function it appears in.)
UEngine.cpp:678: error: `_findnext' undeclared (first use this function)
UEngine.cpp:743: error: aggregate `_finddata_t fileinfo' has incomplete type
and cannot be defined
UEngine.cpp:748: error: `_findfirst' undeclared (first use this function)
UEngine.cpp:830: error: name lookup of `i' changed for new ISO `for' scoping
UEngine.cpp:735: error: using obsolete binding at `i'

I would post the engine code but it's nearly 1000 lines of code, but
here are snippets:



// Go throug the /Skin directory and look for skins
int modCount = 0;
DIR *opendir(const char *Skin);
long filehandle = -1L;
int nRes;

skinCount = 0;

struct dirent *readdir(DIR *Skin);

if(filehandle == -1L)
{
menuOption = -1;

}
else
{
line 677 strcpy(skinList[skinCount],fileinfo.name);
line 678 nRes = _findnext(filehandle,&fileinfo);
skinCount++;

while((-1L != nRes) && (skinCount < 7))
{
strcpy(skinList[skinCount],fileinfo.name);
skinCount++;
nRes = _findnext(filehandle,&fileinfo);
}
}


subMenuOption = selectMenu(skinCount,skinList,skinListHelp,subMenuPos);

// ESC pressed
if(subMenuOption == -2)
menuOption = -1;

// Select skin
if(subMenuOption > -1)

{
strcpy(skinName,skinList[subMenuOption]);
menuOption = -1;
subMenuOption = -1;
subMenuPos = 0;
}

// Show skin preview
strcpy(tempSkinName,skinName);
strcpy(skinName,skinList[subMenuPos]);
BS_DELETE(wndSkinPreview);
wndSkinPreview = new UGameWindow;

wndSkinPreview->Create(800,400,400,200,RenderDevice,createSkinPath("skin_preview.tga"),1.0f);
strcpy(skinName,tempSkinName);

for(i = 0; i < skinCount; i++)
{
delete skinList;
delete skinListHelp;
}
}
int closedir(DIR *Skin);


..........................


line 735 for(int i = 0; i < 7; i++)
{
modList = new char[256];
modListFolder = new char[256];
modListHelp = new char[256];
}

int modCount = 0;
DIR *opendir(const char *Mods);
long filehandle = -1L;
int nRes;


struct dirent *readdir(DIR *Mods);

// Ignore the menu if there are no MODS installed
if(filehandle == -1L)
{
subMenuOption = -1;
menuOption = -1;
subMenuPos = 0;
}
else
{
// Read in first mod
FILE* f;
char path[256];
sprintf(path,"Mods/%s",fileinfo.name);

f = fopen(path,"rt");
fgets(modList[modCount],256,f);
fgets(modListFolder[modCount],256,f);
fgets(modListHelp[modCount],256,f);
fclose(f);


modCount++;

// Scan for next modes
nRes = _findnext(filehandle,&fileinfo);

while(( -1L != nRes) && (modCount < 7))
{
sprintf(path,"Mods/%s",fileinfo.name);
f = fopen(path,"rt");
fgets(modList[modCount],256,f);
fgets(modListFolder[modCount],256,f);
fgets(modListHelp[modCount],256,f);
fclose(f);
modCount++;

nRes = _findnext(filehandle,&fileinfo);
}
}




subMenuOption = selectMenu(modCount,modList,modListHelp,subMenuPos);
// ESC pressed
if(subMenuOption == -2)
{
subMenuOption = -1;
menuOption = -1;
subMenuPos = 0;
}

// Enter pressed, selecting mod
if(subMenuOption > -1)
{
// The mod folder name end with a \n
// we must clear this
modListFolder[subMenuOption][strlen(modListFolder[subMenuOption]) -
1] = 0;
// Set current mod to selected mod
strcpy(modName,modListFolder[subMenuOption]);

menuOption = -1;

// Reload the list with the game levels
FILE* pFile = fopen(createGamePath("LevelList.txt"),"rt");
fscanf(pFile,"%d",&levelCount);

for(int i = 0; i < this->levelCount;i++)
{
this->levelNameList = new char[256];
fscanf(pFile,"%s\n",levelNameList);
}

GameLog.printf("\nBSUCEngine :: Loading modification [%s] with [%d]
levels.",modList[subMenuOption],levelCount);

subMenuOption = -1;
subMenuPos = -1;
subMenuPos = 0;

}

line 831 for(i = 0; i < 7; i++)
 
V

Victor Bazarov

Jon said:
For the past month I have been porting a DirectX windows game to libSDL
on linux, for right now I am working on the basic syntax of the game
engine, I was having problems with opening, reading, and closeing of
directories, I have fixed that though...who woulda thought that it would
be open, read, and closedir()?

Anyway, I am still working on the syntax, and I have been getting these
errors when I compile:

UEngine.cpp: In member function `void UEngine::doGameMenu()':
UEngine.cpp:677: error: `fileinfo' undeclared (first use this function)
UEngine.cpp:677: error: (Each undeclared identifier is reported only
once for
each function it appears in.)
UEngine.cpp:678: error: `_findnext' undeclared (first use this function)
UEngine.cpp:743: error: aggregate `_finddata_t fileinfo' has incomplete
type
and cannot be defined
UEngine.cpp:748: error: `_findfirst' undeclared (first use this function)
UEngine.cpp:830: error: name lookup of `i' changed for new ISO `for'
scoping
UEngine.cpp:735: error: using obsolete binding at `i'

I would post the engine code but it's nearly 1000 lines of code, but
here are snippets:



// Go throug the /Skin directory and look for skins
int modCount = 0;
DIR *opendir(const char *Skin);

The line above is a declaration. Did you mean to call 'opendir'
function?
long filehandle = -1L;
int nRes;

skinCount = 0;

struct dirent *readdir(DIR *Skin);

The line above is a declaration. Did you mean to call 'readdir'
function?
if(filehandle == -1L)
{
menuOption = -1;

}
else
{
line 677 strcpy(skinList[skinCount],fileinfo.name);

'fileinfo' is not declared or not an object. Did you mean to define
'fileinfo' at the same like where you [try to] call 'readdir'?
line 678 nRes = _findnext(filehandle,&fileinfo);

Same thing. 'fileinfo' is not declared.
skinCount++;
[...]

line 831 for(i = 0; i < 7; i++)

for (int i = 0; i < 7; i++)

V
 
J

Jon

Victor said:
The line above is a declaration. Did you mean to call 'opendir'
function?
Yes I did, and I assume that it should be "DIR opendir(const char
*Skin);" instead of "DIR *opendir(const char *Skin);"
The line above is a declaration. Did you mean to call 'readdir'
function?

Again yes I did, and I assume that I should do the same thing as above
"struct dirent readdir(DIR *Skin);"
if(filehandle == -1L)
{
menuOption = -1;

}
else
{
line 677 strcpy(skinList[skinCount],fileinfo.name);


'fileinfo' is not declared or not an object. Did you mean to define
'fileinfo' at the same like where you [try to] call 'readdir'?

I guess I want to define 'fileinfo', not 100% sure as I am still
learning c++
Same thing. 'fileinfo' is not declared.

Also the same as above.
skinCount++;
[...]


line 831 for(i = 0; i < 7; i++)


for (int i = 0; i < 7; i++)

V

Not entirely sure what the 'V' us for, but the 'int' fixed the error I
was getting.
 
V

Victor Bazarov

Jon said:
Yes I did, and I assume that it should be "DIR opendir(const char
*Skin);" instead of "DIR *opendir(const char *Skin);"

No.

How should I put this?... Do you know C++? At all? Perhaps you should
find a decent book or something... I hate to break it to you like this,
but you seem to be really not ready for this porting effort.

OK, for the sake of experiment... The line should read

DIR *dirSkin = opendir(Skin); // assuming 'Skin' is a const char*.
Again yes I did, and I assume that I should do the same thing as above
"struct dirent readdir(DIR *Skin);"

Again, no. It might be something like

dirent fileinfo = *readdir(dirSkin);

maybe.
[...]
for (int i = 0; i < 7; i++)

V


Not entirely sure what the 'V' us for, but the 'int' fixed the error I
was getting.

'V' is the initial of my first name. I am too lazy to write 'Victor'
every time, given that I have this rather stupid habit of signing my
posts.

V
 
J

Jon

Victor said:
No.

How should I put this?... Do you know C++? At all? Perhaps you should
find a decent book or something... I hate to break it to you like this,
but you seem to be really not ready for this porting effort.

OK, for the sake of experiment... The line should read

DIR *dirSkin = opendir(Skin); // assuming 'Skin' is a const char*.

ok, I got that snippet working with the code. (after seeing one of the
stupidst mistakes ever)

I now have this code:

// Go through the /Skin directory and look for skins
int modCount = 0;
const char *Skin;
DIR *dirSkin = opendir(Skin); // assuming 'Skin' is a const char*
long filehandle = -1L;
int nRes;

I have no errors at this part of code...although one thing I don't under
stand, I have mode 'DIR opendir(const char *Skin);' statements in other
parts of the engine, how come I don't receive an error? (I also didn't
receive an error when I compiled before I changed it to 'DIR
*opendir(const char *Skin);'?
Again, no. It might be something like

dirent fileinfo = *readdir(dirSkin);

I have 'dirent fileinfo = *readdir(dirSkin);' in the code, and I now get
the error:

UEngine.cpp:678: error: 'struct dirent' has no member named 'name'

here is a code snippet from around that line:

strcpy(skinList[skinCount],fileinfo.name);
nRes = _findnext(filehandle,&fileinfo);
skinCount++;

I'm guessing that the '....' has no member named 'name' is the
'fileinfo.name' in '
strcpy(skinList[skinCount],fileinfo.name);'

I'm not really sure how to fix this....too much of a newbie to c++ :(
[...]
line 831 for(i = 0; i < 7; i++)




for (int i = 0; i < 7; i++)

V



Not entirely sure what the 'V' us for, but the 'int' fixed the error I
was getting.


'V' is the initial of my first name. I am too lazy to write 'Victor'
every time, given that I have this rather stupid habit of signing my
posts.

V

I guess I should have figured that...for some stupid reason I thought it
was part of the code snippet...stupid me :(


As a note to your comment

"How should I put this?... Do you know C++? At all? Perhaps you should
find a decent book or something... I hate to break it to you like this,
but you seem to be really not ready for this porting effort."

You are right I really am *not* ready for porting, nor do I know much
C++, but I like challanges, it's how I learn, if I read a book, or
tutorial, I don't learn anything, unless I look at the code of programs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,199
Messages
2,571,045
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top