PxConfigReadBool, PxConfigReadChar, PxConfigReadInt, PxConfigReadLong, PxConfigReadShort, PxConfigReadString, — read values from configuration files.
PxConfigReadBool (section, entry, default) PxConfigReadChar (section, entry, default) PxConfigReadInt (section, entry, default) PxConfigReadShort (section, entry, default) PxConfigReadLong (section, entry, default) PxConfigReadString (section, entry, default, maxlen)
The section name, as a string.
The entry name, as a string.
A default value for an entry.
The maximum length of the string to read.
These functions read the value of the entry in the specified section of the configuration file. If the section is passed as nil, the current section is used. If there is no value to read, or if it is invalid, or if the entry or section doesn't exist, the default value is returned.
Function | Readable entries |
---|---|
PxConfigReadBool | Any one of: on, off, yes, no, true, false. All are case-insensitive. Returns 0 for off, no, false; 1 for on, yes, true. |
PxConfigReadChar | Any number of digits (signed or unsigned), or a single character. |
PxConfigReadInt | A signed or unsigned decimal integer. |
PxConfigReadLong | A signed or unsigned decimal or hexadecimal long. |
PxConfigReadShort | A signed or unsigned decimal or hexadecimal short. |
PxConfigReadString | A string, of which maxlen characters will be read. |
This example, ex_PxConfigRead.g, and its configuration file (configtest.txt) are included in the product distribution.
#!/usr/cogent/bin/phgamma o = PxConfigOpen("configtest.txt", PXCONFIG_READ); princ(o,"\n"); princ("Read boolean : ",PxConfigReadBool("Section Four", "LineOne", 3),"\n"); princ("Read character : ",PxConfigReadChar("Section Four", "LineTwo", 9),"\n"); princ("Read integer : ",PxConfigReadInt("Section Four", "LineThree", 9),"\n"); princ("Read long : ",PxConfigReadLong("Section Four", "LineFour", 9),"\n"); princ("Read short : ",PxConfigReadShort("Section Four", "LineFive", 9),"\n"); princ("Read string : ",PxConfigReadString("Section Four", "LineSix", "nix", 20),"\n"); c = PxConfigClose(); princ(c,"\n"); /********* Sample output from program ********* -1 Read boolean : 1 Read character : 11 Read integer : -14 Read long : -21 Read short : -22 Read string : The end. -1 ************** End of sample output **************/ /******* Contents of configtest.txt file ******* [Section One] LineOne = 4 LineTwo = 555 LineThree = 6777777777777 [Section Two] LineOne = 2 LineTwo = 9 LineThree = Hello there. [Section Three] LineOne = 4 LineTwo = Hi again. LineThree = Hello there. [Section Four] LineOne = yes LineTwo = 11 LineThree = -14 LineFour = -0x15 LineFive = -0x16 LineSix = The end. ************* End of configtest.txt **************/
In Photon documentation: PxConfigReadBool, PxConfigReadChar, PxConfigReadInt, PxConfigReadLong, PxConfigReadShort, PxConfigReadString.
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.