1

I'm currently developping a new library, which deals with TEXT files of the following form
;comment
variable_1 = 1235456
variable_2 = 5454512
variable_3 = 5211
;comment
variable_4 = 545421


There are currently 3 functions in my lib :
long reglib::getnumkey(const char *file, const char *key, long default, const short * error)
default value is returned in case of error (file not found, key not defined, ...) to allow avoiding special cases in client program

short reglib::addnumkey(const char *file, const char *key, long value)

short reglib::removekey(const char *file, const char *key)

these files can be changed in the integrated TEXT editor.

today only integer variables are allowed, but I want to integrate at least string variables
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

2

Well, I have a suggestion, which would make you closer to INI-files, and might be a quite usefull functionnality: why not allowing users to have "sections" in their ini-like files?
(that would even be closer to "real" ini-files)

for instance :
[main]
enable_tci_logo=0
enable_menu=1
enable_communicator=0
enable_confirmation_at_quit=0
enable_sablier_pendant_chargement=0
enable_verif_ram_au_chargement=0

[kbd]
allow_2nd_as_fire_on_92p=1
avatarTutorial C (TI-89/92+/v200) - Articles Développement Web (PHP, Javascript, ...)
« What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against? » - Larry Wall

3

good idea smile

I'll think to this idea in the next days. If it's not too hard to add this function, I'll implement it in future versions

I don't want a huge lib with a lot of functions, since I don't think that it's very useful on TIs
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

4

I'll think to this idea in the next days.

great smile
I don't want a huge lib with a lot of functions

actually, I was thinking to something just like this :

short config_get_short(const char *section asm("a0"), const char *node asm("a1"), const short defaut asm("d0"));

BOOL config_set_str(const char *section asm("a0"), const char *node asm("a1"), const char *data asm("d0"));


(I think this is kinda close to what is used in allegro ; not sure, but I wonder if I didn't take a look at it before making my functions)
and the same for other data-types...
(and these functions only call a generalistic "get" or "set", which takaes/returns a char *... and the specific functions just converti to/from char *)
but There might be other solutions, to which I've not thought smile
avatarTutorial C (TI-89/92+/v200) - Articles Développement Web (PHP, Javascript, ...)
« What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against? » - Larry Wall

5

I think that I can easily implement the following functions

short reglib::add_section(const char *file, const char *section)

short reglib::remove_section(const char *file, const char *section)

long reglib::get_num_key(const char *file, const char *section, const char *key, long default, const short *error)

short reglib::add_num_key(const char *file, const char *section, const char *key, long value)

short reglib::remove_key(const char *file, const char *section, const char *key)


Removing a section will remove all keys in this section.
Section names will be limited to 8 or 10 chars (perhaps more, but I must to limit their size to a constant).

avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

6

I think that I can easily implement the following functions

ok
you don't plan to allow floats ? (I know you plan to implement strings ; else, I would have asked for it grin )
(but I don't know if floats are _really_ necessary... not for games, at least, I think
Removing a section will remove all keys in this section.

good idea
Section names will be limited to 8 or 10 chars

well, that's probably enough, isn't it ? after all, we don't need _lots_ of sections, so a not too long descriptor should be enough...
(but for variable names, more would be great, I think ; maybe 15 chars or so ? )
avatarTutorial C (TI-89/92+/v200) - Articles Développement Web (PHP, Javascript, ...)
« What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against? » - Larry Wall

7

I don't think that floats are really important smile
(but for variable names, more would be great, I think ; maybe 15 chars or so ? )

variables names are unlimited
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

8

1> OK.
(I don't think either they are very important ; they could be usefull for math applications;.. but, anyway, there are not so much people using C/ASM to write maths programs)

2> OK, perfect smile
avatarTutorial C (TI-89/92+/v200) - Articles Développement Web (PHP, Javascript, ...)
« What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against? » - Larry Wall

9

I suggest having the # char begin comments as ; does.
It believe it would not do much difference, and there is a significant number of users used to the # as the beginning of comments.

Also, correctly parsing strings may require quite a bit of thinking before. How are you going to handle these samples, for instance ?
a = hello
b = "hello"
c = hello      ; hi, I'm a comment, how are you ?
d = "hello     ; how are you ?"

(This assumed you decide to use "" as a quoting character for strings, as most ini parsers do. This also has a drawback : what if I want to put a quoting char inside a strings ?)

10

for instance, if the parser encounters an error, it stops to parse the ini file. I don't want to spend memory and time to correctly handle errors
'a' isn't a valid variable, so no key will be read :/
for the same reason, comments must be at the beginning of a line.
It isn't a beautiful way to proceed, but a simple one grin

strings are delimated by ", so if the ini file is
d = "hello ; how are you ?"
reglib::get_string_key will return "hello ; how are you ?"

I can easily modify my routine to handle the sequence \" or "" for allowing quoting chars in strings smile It was already planned (but I prefer to begin by correctly implementing basic strings)
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

11

Will you handle strings of arbitrary characters, too ? (e.g. with "\0", "\n" or "\r" too inside -- they won't interact too well with tios' encoding of newlines, and it would change the data if you opened it with the standard text editor ; you could consider doing it for other control characters too [in the range 0-31], as some text editors or computer link software might choke on them)

By the way, how much memory does it take for now ?

12

This seem interesting. I did a similar lib for TIM but it was much more like a "Windows registery" whereas your lib handle thislike the "Linux conf files"

I had question about some things you don't talk about:
- Are these files archived?(that was one of my problem with adblib since i wanted to reduce archive use) If not there should be options like "short reglib::archive_file(const char *file)"
- Are they placed in the PreOS system folder? (I think i know the awnser wink )
- Section sould be optionnal: if section value of a key is NULL, the key is placed directly
- Maybe repace "add_???_key" by "put_???_key" that would add the key or update it if it already exists
avatar

13

- Maybe repace "add_???_key" by "put_???_key" that would add the key or update it if it already exists
That is a good idea, provided that it was not what was already intended for add???key happy

14

Will you handle strings of arbitrary characters, too ? (e.g. with "\0", "\n" or "\r" too inside -- they won't interact too well with tios' encoding of newlines, and it would change the data if you opened it with the standard text editor

For instance, you can put any char in strings, except "". I don't think that's it's a very important point, but I can work this point more precisely smile
By the way, how much memory does it take for now ?

1563bytes (with the get_string function, but not the add_string function)
- Are these files archived?(that was one of my problem with adblib since i wanted to reduce archive use) If not there should be options like "short reglib::archive_file(const char *file)"

Files can be archived for a search. If you want to modify a file, it will be unarchived, but not rearchived after its modification
Are they placed in the PreOS system folder?

I'd like to use the same system as PreOS (system folder, main folder, current folder)
- Maybe repace "add_???_key" by "put_???_key" that would add the key or update it if it already exists

if the key already exists, it will be remplaced smile
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

15

>I'd like to use the same system as PreOS (system folder, main folder, current folder)
It is "Executable Folder", "Current Folder" and "System Folder".

And I won't export Executable Folder since you can get it by yourself.

16

- Section sould be optionnal: if section value of a key is NULL, the key is placed directly

If you give a null pointer to the library (for the section), the key will be placed at the end of the file (if it doesn't exist) or will replace at the same place the previous key
And I won't export Executable Folder since you can get it by yourself.

how can I get it ? Getting the library folder is simple, but the executable folder...
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

17

Flanker
:
Will you handle strings of arbitrary characters, too ? (e.g. with "\0", "\n" or "\r" too inside -- they won't interact too well with tios' encoding of newlines, and it would change the data if you opened it with the standard text editor

For instance, you can put any char in strings, except "". I don't think that's it's a very important point, but I can work this point more precisely smile

Yes, I understand that the library itself won't have any problem with "\r", but text editors will definitely have problems, so you will likely have to escape them... (or of course you can say that people should not enter binary data, but I think that's an interesting way to store lots of data)

18

put binary data in .ini files ? sick those who do that are really strange guys

If you really want to put binary data (like a crypted password or something else like that) you have to encode it something like UUE or juste hexadecimal pairs, but that not the job of the library

and .ini file is NOT for storing data, just storing configuration (an extrem case can be a HighScore file, but who want to have theire HS files edited with a simple text editor ? MS Mine sweeper ? trigic cheeky)
avatarProud to be CAKE©®™


GCC4TI importe qui a problème en Autriche, pour l'UE plus et une encore de correspours nucléaire, ce n'est pas ytre d'instérier. L'état très même contraire, toujours reconstruire un pouvoir une choyer d'aucrée de compris le plus mite de genre, ce n'est pas moins)
Stalin est l'élection de la langie.

19

What you call "binary" data could just as well be multi-line text, for example...

20

how can I get it ? Getting the library folder is simple, but the executable folder...

From the Preos doc:
		lea	0(Pc),a0
		jsr	kernel::Ptr2Hd
			; d0.w = handle of the program !

So you can search for the handle in the VAT. But I wonder if there is an easier way.
avatar

21

Well, I suppose if you already have to walk through the whole vat, knowing the handle before is not of much use. I mean, you can always test each symbol, stopping when you find the one that contains the current pc.

22

this method will give me the handle of my own library sad
and what can I do when the caller is a tsr ?
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

23

If it is a tsr, it will not be in the vat anyway ? So it does not make much sense to look for its directory, does it ?

24

certainly, but how can my library know that its caller is a tsr or a standard program ?
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

25

Well, maybe the choice of the place where to store the file is not for your lib to decide ?

26

you add a parameter to your library who say where to store the file ?

and if not it put the parameter in the "system" folder cheeky


(edit: corrected a #mac# typo)
avatarProud to be CAKE©®™


GCC4TI importe qui a problème en Autriche, pour l'UE plus et une encore de correspours nucléaire, ce n'est pas ytre d'instérier. L'état très même contraire, toujours reconstruire un pouvoir une choyer d'aucrée de compris le plus mite de genre, ce n'est pas moins)
Stalin est l'élection de la langie.

27

I thiink it's a good solution
avatar

28

I've some questions :
- do you think that an escape sequence is important for strings (to allow the "" char in strings) ?
- if yes, do you prefer \" or "" ?
- for comments, do you prefer ";", "#" or another char ? (it's currently ";", like in asm)
- for the ".ini file" folder, I'm not very interested by adding another parameter to each call of my lib - 6 parameters are already required sad for some functions)
I think to force to 'system' folder. It's will be simpler for everybody I think
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

29

short reglib::get_string_key(const char *file, const char *key, const char *value, long max_length, const char *default) is finished smile

I'm now working on
short reglib::add_string_key(const char *file, const char *key, const char *value)
avatar<<< Kernel Extremis©®™ >>> et Inventeur de la différence administratif/judiciaire ! (©Yoshi Noir)

<Vertyos> un poil plus mais elle suce bien quand même la mienne ^^
<Sabrina`> tinkiete flan c juste qu'ils sont jaloux que je te trouve aussi appétissant

30

Great smile
- if yes, do you prefer \" or "" ?
Definitely \" This would allow future additionnal escapes to be added constitently.
- for comments, do you prefer ";", "#" or another char ? (it's currently ";", like in asm)
Both would be nice if possible.
- for the ".ini file" folder, I'm not very interested by adding another parameter to each call of my lib - 6 parameters are already required for some functions)
Well, maybe you could replace the char * file with a HANDLE file ? This would allow the caller to do whatever it wants with the file.