API Question oapiReadLine

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
Is there any API that I don't know about that can be called let's say "oapiReadLine(FILEHANDLE fh,char* line)" ?

there is oapiWriteLine, and the APIs to read float, strings, vectors etc... but what if I want to read a general line and scan it for any value? of course I could use ifstream etc but that would require to "guess" the orbiter's directories structure, while using the default FILEHANDLE won't have this problem, but I can't use an orbiter FILEHANDLE as an ifstream without falling in version compiling issues...

So does anyone know if there is one? and if not shouldn't it be put in the workshop to be implemented?

Thanks
Fred
 
Last edited:

indy91

Addon Developer
Addon Developer
Joined
Oct 26, 2011
Messages
1,226
Reaction score
588
Points
128
oapiReadScenario_nextline is what you probably want.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
No need to guess. Orbiter API has all you need ;)

PHP:
// Orbiters default directories
std::string configDir(".\\Config\\");
std::string meshDir(".\\Meshes\\");
std::string textureDir(".\\Textures\\");
std::string hightexDir(".\\Textures2\\");
std::string scenarioDir(".\\Scenarios\\");

// If the add-on runs in Orbiter_NG,
// the 1st parameter has to be "Orbiter_NG.cfg" of course
FILEHANDLE f = oapiOpenFile("Orbiter.cfg", FILE_IN_ZEROONFAIL, ROOT);
if (f) {
	char  string[MAX_PATH];

	// Get directory config
	if (oapiReadItem_string(f, "ConfigDir", string)) {
		configDir = string;
	}
	if (oapiReadItem_string(f, "MeshDir", string)) {
		meshDir = string;
	}
	if (oapiReadItem_string(f, "TextureDir", string)) {
		textureDir = string;
	}
	if (oapiReadItem_string(f, "HightexDir", string)) {
		hightexDir = string;
	}
	if (oapiReadItem_string(f, "ScenarioDir", string)) {
		scenarioDir = string;
	}
	oapiCloseFile(f, FILE_IN_ZEROONFAIL);
}

oapiOpenFiles 3nd parameter can one of ROOT, CONFIG, SCENARIOS, TEXTURES, TEXTURES2, MESHES or MODULES.
When you "know" where your (config-)file might be located.
 
Last edited:

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
oapiReadScenario_nextline is what you probably want.

thanks but that doesn't do the job, at least I couldn't find a way to adapt it: it is the tool that gets closer but it is designed to work on scenario files. So if you put as a condition its return value you won't be able to use it, and I can't make it properly read the lines...

basically, in order to make a backup of a file from a filehandle the following does not work, it doesn't stop at the end of file (but that could be my mistake of course, I just make a quick test) and it doesn't print the lines properly but just symbols...

Code:
FILEHANDLE input = oapiOpenFile("TEST.txt", FILE_IN_ZEROONFAIL, ROOT);
	char *line;
	FILEHANDLE output = oapiOpenFile("BACKUP.txt", FILE_OUT, ROOT);
	oapiReadScenario_nextline(input, line);
	while (line[sizeof(line)-1] != char_traits<char>::eof()) {
		oapiWriteLine(output, line);
		oapiReadScenario_nextline(cfg, line);
	}
	oapiCloseFile(output,FILE_OUT);
	oapiCloseFile(input,FILE_IN_ZEROONFAIL);

No need to guess. Orbiter API has all you need ;)

Hey, you just copied my "FindOrbiterDirs()" function in my project :lol:

Except I added the test if gc is enabled to choose between orbiter.cfg and orbiter_ng.cfg.


Maybe you should take a look at this:

https://github.com/TheNewBob/Oparse

Wow, that's a lot of parsing options there... :tiphat:

Anyway I was basically saying that a function like oapiReadLine could be very useful because it would allow to skip all this passages, and it seems to me that is missing. for example for finding the dir I needed to check the gcenabled, so I had to add the entire gcApi.h to the project which would not have been needed.
 
Last edited:

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,666
Reaction score
795
Points
128
Based on my understanding FILEHANDLE in orbiter should be a pointer to (i)(o)fstream. So, std::getline(file_handle, line) might work.
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
Based on my understanding FILEHANDLE in orbiter should be a pointer to (i)(o)fstream. So, std::getline(file_handle, line) might work.

yes, but orb HERE states that it's VC version dependent... and I really don't want to dig into that. That is one of the reasons I think a oapiReadLine function could be very useful.
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,666
Reaction score
795
Points
128
yes, but orb HERE states that it's VC version dependent... and I really don't want to dig into that. That is one of the reasons I think a oapiReadLine function could be very useful.

Oh, I wasn't aware of that problem. I do agree that "oapiReadLine" would be useful and needed.
 
Last edited:
Top