Preference File(s) on Linux (PB 5.73 LTS)
Preference File(s) on Linux (PB 5.73 LTS)
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
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
Re: Preference File(s) on Linux (PB 5.73 LTS)
If you want to delete comments, here's a regular expression.
(?m) = #PB_RegularExpression_MultiLine
Code: Select all
(?m)^[\h]*[#;].+?$
Re: Preference File(s) on Linux (PB 5.73 LTS)
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.)
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.
Re: Preference File(s) on Linux (PB 5.73 LTS)
It is better to use the internal commands of the lib, because they automatically ignore spaces and comments.
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.
Code: Select all
; Select a group
PreferenceGroup("Window")
See sample
All programs with INI file management functions (~= PB prefs files) also ignore blank lines and comments, so don't bother with them.
Re: Preference File(s) on Linux (PB 5.73 LTS)
In case you want the flexibility:
INI library (replacement for preferences)
viewtopic.php?f=12&t=62236
INI library (replacement for preferences)
viewtopic.php?f=12&t=62236
Re: Preference File(s) on Linux (PB 5.73 LTS)
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
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
Re: Preference File(s) on Linux (PB 5.73 LTS)
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?
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?
Re: Preference File(s) on Linux (PB 5.73 LTS)
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.)
Re: Preference File(s) on Linux (PB 5.73 LTS)
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.