Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
3 registered members (TedMar, AndrewAMD, fairtrader), 578 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Read from txt #125051
04/19/07 17:01
04/19/07 17:01
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline OP
User
tompo  Offline OP
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
In this moment to read some file from a txt file we have to use read n function, where n is line number. But is not easy to use and remember. Maybe you should do something like read from .ini file where text is divide by sections with []?!

F.e. Read(file.txt,section,subsection); read(my.txt,smith,blablabla);
[smith]
\question_1\ .........
\answer_1\ .........
\answer_2\......
\blablabla\.........
Is this possible to do right kmow? If not... it should be
The same with writing to .txt files.


Never say never.
Re: Read from txt [Re: tompo] #125052
04/19/07 17:15
04/19/07 17:15
Joined: Jun 2005
Posts: 4,875
broozar Offline
Expert
broozar  Offline
Expert

Joined: Jun 2005
Posts: 4,875
file_var_read. file_str_read.

Re: Read from txt [Re: broozar] #125053
04/19/07 17:27
04/19/07 17:27
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline OP
User
tompo  Offline OP
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
Yes... but whith those functions you still have to "remember" n lines or n ","
and jump over next lines by n function
maybe you should add file_chr_read funcion too?!
and this is not answer for my question about sections

Last edited by tompo; 04/19/07 18:02.

Never say never.
Re: Read from txt [Re: tompo] #125054
04/19/07 18:30
04/19/07 18:30
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Did you take a look at the delimiter str?
http://manual.conitec.net/delimit_str.htm

Using this you could build some sort of search function which scans a given file for a given section and reads certain values.

I know this is not the answer to your question but might be a workaround for you, so you don't have to wait until its implemented

I would suggest an .xml wrapper but this is already in the making by HeelX as far as I remember.

Re: Read from txt [Re: tompo] #125055
04/19/07 19:39
04/19/07 19:39
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
this is a request which is already possible to do, as broozar said, so it's very unlikely to be implemented.

i'm using my linked list dynamic array functions i've posted here:
http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/734988/an/0/page/2#Post734988
they're suited for any data type and much more comfortable to use than standard c arrays.

so be sure to include them appropriately. note that i can't test the code i'm posting right now (the array code does indeed work), but i think it can be used nearly as-is. some of the string operations wouldn't work with ansi c but should if i understood the string explanation page in the manual. i must say it's a bit confusing.

Code:
// include dynamic array stuff here

typedef struct ini_setting {
STRING* name, value;
}
typedef struct ini_section {
STRING* name;
llist settings;
}

// here you can set the criteria for a section header
STRING* get_section_name(STRING* line) {
if ( (str_stri(line, "[") == 1) && (str_stri(line, "]") == str_len(line) ) {
str_trunc(line, 1);
str_clip(line, 1);
return line;
}

return NULL;
}

// and here a name, value touple
STRING*[] get_setting_touple(STRING* line) {
int n;
if ( !(n = str_stri(line, "=")) ) {
return NULL;
}

STRING*[] touple = (STRING*[])malloc(2*sizeof(STRING*));
str_cpy(touple[0], line); // no need for allocating in lite-c
str_trunc(touple[0], str_len(line)-n);
str_cpy(touple[1], line);
str_clip(touple[1], n);

return touple;
}

llist* load_ini_file(STRING* filename) {
var_nsave handle;
if ( (handle = file_open_read(filename)) == 0 ) {
return NULL;
}

STRING* line;
STRING*[] touple;
llist* sections = new_llist(), settings;
ini_section* section;
ini_setting* setting = NULL;
while (file_str_read(handle, line) != -1) {
if (get_section_name(line) != NULL) {
section = (ini_section*)malloc(sizeof(ini_section));
section->name = line;
settings = &(section->settings);

llist_add(sections, &section);
}
if ( (setting != NULL) && (touple = get_setting_touple(line)) != NULL) ) {
setting = (ini_setting*)malloc(sizeof(ini_setting));
setting->name = touple[0];
setting->value = touple[1];

llist_add(settings, &setting);
}
}

file_close(handle);
return sections;
}



Re: Read from txt [Re: Joey] #125056
04/19/07 19:51
04/19/07 19:51
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline OP
User
tompo  Offline OP
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
It looks quite complicate... at 22:00 PM
So my idea to add in the future function like:
Read(file.txt,section,subsection); seems to be a good idea


Never say never.
Re: Read from txt [Re: tompo] #125057
04/20/07 05:02
04/20/07 05:02
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
I probably won't seriously use C-Lite until I see a few more 'official steps'.
Currently, for ini processing I use a plugin dll I slapped together.
The plugin simply accesses the old Windows ini functions.
It does not yet support section validation and key iteration.

Recently, I combined a hodgepodge of material into a tD0.dll.
(I will probably just drop the plugin somewhere in the community pool.)
Code:


define tD0_wdl;
/*******************************
tD0_wdl (testDummy)
********************************/
//dynamic data instructions
dllfunction ddGetResult();
dllfunction ddGetVar(_sVarName);
dllfunction ddSetVar(_sVarName, _value);

//ini instructions
dllfunction iniGetPath(_sPath);
dllfunction iniSetPath(_sDirectory, _sFilename);

dllfunction iniReadBool(_sSection, _sKey, _defaultValue);
dllfunction iniReadFloat(_sSection, _sKey, _defaultValue);
dllfunction iniReadInt(_sSection, _sKey, _defaultValue);
dllfunction iniReadStr(_sSection, _sKey, _sDefaultValue, _sResult);

dllfunction iniWriteFloat(_sSection, _sKey, _value);
dllfunction iniWriteInt(_sSection, _sKey, _value);
dllfunction iniWriteStr(_sSection, _sKey, _value);


dllfunction drawfColor(_vec);


// ea (entity array) instructions
dllfunction eaAdd(_easIndex, _ent);
dllfunction eaDelete(_easIndex, _ent);
dllfunction eaDeleteAll(_easIndex);
dllfunction eaGetCount(_easIndex);
dllfunction eaGet(_easIndex, _eaIndex);
dllfunction eaGetCapacity(_easIndex);
dllfunction eaGetSize(_easIndex);
dllfunction eaIndexOf(_easIndex, _ent);
dllfunction eaNew(_easIndex, _eaCapacity);
dllfunction eaSet(_easIndex, _eaIndex, _ent);
dllfunction easDelete();
dllfunction easGet1stFree();
dllfunction easGetCapacity();
dllfunction easNew(_easCapacity, _eaCapacity);

// eLL (entity linked list) instructions
dllfunction eLLAppend(_eLLIndex, _ent);
dllfunction eLLContains(_eLLIndex, _ent);
dllfunction eLLDelete(_eLLIndex, _ent);
dllfunction eLLDeleteAll(_eLLIndex, _eLLClearInUse);
dllfunction eLLGetLength(_eLLIndex);
dllfunction eLLIsEmpty(_eLLIndex);
dllfunction eLLIsInUse(_eLLIndex);
dllfunction eLLNext(_eLLIndex);
dllfunction eLLNextReset(_eLLIndex);
dllfunction eLLPop(_eLLIndex);
dllfunction eLLPush(_eLLIndex, _ent);
dllfunction eLLsDelete();
dllfunction eLLsGet1stFree();
dllfunction eLLsGetIndexOf(_ent);
dllfunction eLLSetInUse(_eLLIndex, _inUse);
dllfunction eLLsGetMaxLimit();
dllfunction eLLsNew(_eLLsMax);

//dllfunction eLLsLoadSet(_fileName, _number);
dllfunction eLLsLoad(_fileName, _number); //loads eLL structure from file
dllfunction eLLsSave(_fileName, _number); //saves eLLs structure to file

dllfunction sfEndsWith(_sIn, _sFind, _ignoreCase); //string ends with
dllfunction sfStartsWith(_sIn, _sFind, _ignoreCase); //string starts with

//phoney menu instructions
//sets factor for sizing / aligning TP set
dllfunction uifTPFactor(_factor);
//stores current active TP (TEXT/PANEL) set
dllfunction uifTPSet(_txt1, _txt2, _pnl);
dllfunction uifTPSetVisible(_visible); //sets visibility of active or old TP (TEXT/PANEL) set
dllfunction uifTPAlign(_txtC, _sLenDefault); //aligns and resizes TP set
dllfunction uifTxtHitTest(_txtC, _str1, _str2); //performs a mouse cursor hit test on TP (TEXT/PANEL) set
dllfunction uifTxtSLenMax(_txt, _txtC, _sLenDefault); //returns max len of strings in text

//dynamic var array instructions
dllfunction vaGet(_vasIndex, _vaIndex);
dllfunction vaIndexOf(_vasIndex, _value);
dllfunction vaResize(_vasIndex, _vaCapacity);
dllfunction vaSize(_vasIndex);
dllfunction vaSet(_vasIndex, _vaIndex, _value);
dllfunction vaSetAll(_vasIndex, _value);
dllfunction vasResize(_vasCapacity);
dllfunction vasSize();



With a plugin a var can be read from file and set like so in C-Script:
Code:

var myVar = 3.14;
//the C-Script var is set to the value in the ini file or the default,
// which is the value in the .wdl file
ddSetVar("myVar", iniReadFloat("vars", "myVar", myVar));


This is relatively easy to do. It only takes a bit of patience and and possibly, a smidgeon of research.

Re: Read from txt [Re: testDummy] #125058
04/21/07 14:02
04/21/07 14:02
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline OP
User
tompo  Offline OP
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
It means that people want to read and write from txt with sections.
So it's good idea to make this possible and easy to use without plugin, dll...etc but just by simple function


Never say never.
Re: Read from txt [Re: tompo] #125059
04/22/07 09:04
04/22/07 09:04
Joined: Jun 2003
Posts: 1,017
Germany
T
Thomas_Nitschke Offline
Senior Developer
Thomas_Nitschke  Offline
Senior Developer
T

Joined: Jun 2003
Posts: 1,017
Germany
Agreed. Tompo, you have my support on this one


Formerly known as The Matrix - ICQ 170408644 I've been here for much longer than most people think. So where's my "Expert" status?
Re: Read from txt [Re: Thomas_Nitschke] #125060
04/23/07 05:59
04/23/07 05:59
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Do a Google search for "Ini file reading" and you have your solution.

http://msdn2.microsoft.com/en-us/library/ms724345.aspx

An engine is not the Windows API. We can't implement any and every trivial function.


Moderated by  aztec, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1