PxConfigRead

PxConfigReadBool, PxConfigReadChar, PxConfigReadInt, PxConfigReadLong, PxConfigReadShort, PxConfigReadString, — read values from configuration files.

Syntax

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)

		

Arguments

section

The section name, as a string.

entry

The entry name, as a string.

default

A default value for an entry.

maxlen

The maximum length of the string to read.

Returns

The number, character, or string read, or the default entry. Otherwise, 0 for error.

Description

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.

FunctionReadable entries
PxConfigReadBoolAny one of: on, off, yes, no, true, false. All are case-insensitive. Returns 0 for off, no, false; 1 for on, yes, true.
PxConfigReadCharAny number of digits (signed or unsigned), or a single character.
PxConfigReadIntA signed or unsigned decimal integer.
PxConfigReadLongA signed or unsigned decimal or hexadecimal long.
PxConfigReadShortA signed or unsigned decimal or hexadecimal short.
PxConfigReadStringA string, of which maxlen characters will be read.

Example

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 **************/
		  

See Also

PxConfigRead

In Photon documentation: PxConfigReadBool, PxConfigReadChar, PxConfigReadInt, PxConfigReadLong, PxConfigReadShort, PxConfigReadString.