Preference File(s) on Linux (PB 5.73 LTS)

Just starting out? Need help? Post your questions and find answers here.
mocitymm
User
User
Posts: 37
Joined: Wed Feb 08, 2017 6:56 pm

Preference File(s) on Linux (PB 5.73 LTS)

Post by mocitymm »

I don't know if this is a 'bug' per se or if someone has run into before and there might be a work around.

I have a 'config' file on Linux (any flavor is applicable), very similar to the set up on the Preference file example included in PB. The file I am working with includes comments that start with the '#' symbol i.e. (# This would be a comment in the file).

Many times within the 'config' file the comments are 2 or 3 lines above the 'PreferenceGroup' and 'PreferenceKey' but, some are on the line above the information I wish to gather. As in the following:

# This is a Group

[Group 1]

# This is another Group
[Group 2]


Same situation with the PreferenceKeys, the problem is reading the information where the comments are directly above the Group or Key on Linux (as in the second example above). On Windows with the same 'config' file used, it has no problem reading all of the information (utilizing the same code used on Linux).

Has anyone run into this issue before and know of a work around? Or am I stuck with reading the file, using a RegExp to remove the comments and writing the information to another file?

Any advise greatly appreciated.

Thanks,
-Mo
AZJIO
Addict
Addict
Posts: 1364
Joined: Sun May 14, 2017 1:48 am

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by AZJIO »

If you want to delete comments, here's a regular expression.

Code: Select all

(?m)^[\h]*[#;].+?$
(?m) = #PB_RegularExpression_MultiLine
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by Tenaja »

Did you use the Linux program to generate the file? If you copied the windows version, you might have a different line-end character set than the Linux version is expecting.

Did you manually type those comments in? If so, then I recommend you avoid the native prefs library, and switch to the open source INI version available in this forum. The PB prefs library has limitations, is not really intended for manual editing. (Unless it's been updated, which I doubt.)
Last edited by Tenaja on Wed Nov 17, 2021 2:50 pm, edited 1 time in total.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by Marc56us »

It is better to use the internal commands of the lib, because they automatically ignore spaces and comments.

Code: Select all

  ; Select a group
  PreferenceGroup("Window")
Select the group, then read the keys automatically until the next group

See sample

All programs with INI file management functions (~= PB prefs files) also ignore blank lines and comments, so don't bother with them. :wink:
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by Tenaja »

In case you want the flexibility:
INI library (replacement for preferences)
viewtopic.php?f=12&t=62236
mocitymm
User
User
Posts: 37
Joined: Wed Feb 08, 2017 6:56 pm

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by mocitymm »

Ok, where to start... sorry for the late reply to your comments and suggestions.

AZJIO:

Thank you for the head start on the RegEx!

Tenaja:

The file is generated via a service installation, no copies were made.

No manual editing involved, the native pref libs work fine on Windows accessing the file via a
Samba share on the Linux box... so they work - just not running them from Linux utilizing the same
code as provided in the example in the 'Help' application (PB) that Marc56us referred.

I've double checked the installation of PB with the 'check' installation script provided and it indicates that
all is good so, not missing any support files.

The external INI libraries have been utilized before and work on Windows, not Linux with this file.

So good suggestions but, I have tried them already and no go for joy on that. Thank you for the suggestions,
we were thinking the same on narrowing the issue down.

Marc56us:

That isn't working, I've tried multiple iterations of the code and same result. Thank you though.

I will bang head till either it works or I quit! :)

Thank you everyone!

Regards,
-Mo
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by kenmo »

First reaction, if it's parsing the same file differently on Linux vs Windows, it sounds like a PB bug.
A comment above should not prevent a line of data from being read.

Second reaction, maybe there is something strange about the file? Non-visible characters encoded in there?
You said it doesn't work with the INI library linked above either. That surprises me.
The INI code is totally independent from the official PB lib, I don't understand how it would have the exact same bug.


Could you post a small test program, your expected good output, and the resulting bad output?

Maybe post the exact prefs file you're parsing, if it's not private?
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by Tenaja »

For the Preferences library, you cannot use file functions outside of the Preferences library and expect the reads to function properly. They may periodically (or randomly) work, but it is not supported, iirc. (Hence the need for that ini library.)
AZJIO
Addict
Addict
Posts: 1364
Joined: Sun May 14, 2017 1:48 am

Re: Preference File(s) on Linux (PB 5.73 LTS)

Post by AZJIO »

Tenaja wrote: Fri Nov 19, 2021 3:36 pmyou cannot use file functions
ini is a file. If you follow the rules of the file format, as well as work with the file when the handle is closed (ClosePreferences), then there should be no problem.
I myself wrote 2 ways to work with the ini-file, in one case the ini file is loaded into memory as an array of arrays, in the other case a one-time request for a file operation is made. And also made a library where the flag of choice between the registry and the ini-file was indicated and the same functions were performed. Used AutoIt3 and regular expressions.
Windows works with ANSI and "Unicode UTF16 Little Endian" encodings.
Post Reply