Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc.

Reply
 
Thread Tools
Old 02-06-2019, 05:28 PM   #1
fred18
Addon Developer

Default oapiReadLine

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 by fred18; 02-06-2019 at 05:35 PM.
fred18 is offline   Reply With Quote
Old 02-06-2019, 06:03 PM   #2
indy91
Addon Developer
Default

oapiReadScenario_nextline is what you probably want.
indy91 is online now   Reply With Quote
Old 02-06-2019, 06:16 PM   #3
kuddel
Donator
Default

No need to guess. Orbiter API has all you need

PHP Code:
// 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_ZEROONFAILROOT);
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(fFILE_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 by kuddel; 02-06-2019 at 06:20 PM.
kuddel is offline   Reply With Quote
Old 02-06-2019, 06:19 PM   #4
Urwumpe
Not funny anymore
 
Urwumpe's Avatar

Default

Maybe you should take a look at this:

https://github.com/TheNewBob/Oparse
Urwumpe is offline   Reply With Quote
Old 02-06-2019, 07:42 PM   #5
fred18
Addon Developer

Default

Quote:
Originally Posted by indy91 View Post
 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);
Quote:
Originally Posted by kuddel View Post
 No need to guess. Orbiter API has all you need
Hey, you just copied my "FindOrbiterDirs()" function in my project

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


Quote:
Originally Posted by Urwumpe View Post
 Maybe you should take a look at this:

https://github.com/TheNewBob/Oparse
Wow, that's a lot of parsing options there...

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 by fred18; 02-06-2019 at 07:46 PM.
fred18 is offline   Reply With Quote
Old 02-06-2019, 11:02 PM   #6
jarmonik
Beta Tester

Default

Based on my understanding FILEHANDLE in orbiter should be a pointer to (i)(o)fstream. So, std::getline(file_handle, line) might work.
jarmonik is offline   Reply With Quote
Old 02-06-2019, 11:06 PM   #7
fred18
Addon Developer

Default

Quote:
Originally Posted by jarmonik View Post
 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.
fred18 is offline   Reply With Quote
Thanked by:
Old 02-07-2019, 11:23 AM   #8
jarmonik
Beta Tester

Default

Quote:
Originally Posted by fred18 View Post
 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 by jarmonik; 02-07-2019 at 11:26 AM.
jarmonik is offline   Reply With Quote
Thanked by:
Reply

  Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK

Tags
filehandle, oapi, oapireadline, oapiwriteline


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 01:44 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.