PxConfigWriteBool, PxConfigWriteChar, PxConfigWriteInt, PxConfigWriteLong, PxConfigWriteShort, PxConfigWriteString, — write values to configuration files.
PxConfigWriteBool (section, entry, format, value) PxConfigWriteChar (section, entry, format, value) PxConfigWriteInt (section, entry, format, value) PxConfigWriteShort (section, entry, format, value) PxConfigWriteLong (section, entry, format, value) PxConfigWriteString (section, entry, format, value)
The section name, as a string.
The entry name, as a string.
The format of the entry. Valid options are listed in the table below.
The value of the entry.
These functions write an entry value in the specified section of the configuration file. If nil is passed for section, the current section is used. Existing entry values are overwritten if that entry is being written. New entries and their values are added to the end of their respective sections, and new sections are created if they don't exist.
To use these functions, the file must first be opened with a call to PxConfigOpen. To create an empty section, use PxConfigForceEmptySection.
Table 3. PxConfigWriteBool Format Options
Format Options | Value | Written Output |
---|---|---|
PXCONFIG_FMT_BOOL_ON | 0 or non-0 | OFF or ON |
PXCONFIG_FMT_BOOL_YES | 0 or non-0 | NO or YES |
PXCONFIG_FMT_BOOL_TRUE | 0 or non-0 | FALSE or TRUE |
Table 4. PxConfigWriteChar Format Options
Format Options | Written Output |
---|---|
PXCONFIG_FMT_CHAR_CHAR | A single character (letter or digit). |
PXCONFIG_FMT_CHAR_HEX | A 2-digit hex number. |
This example, ex_PxConfigWrite.g, is included in the product distribution.
#!/usr/cogent/bin/phgamma system("echo \n"); system("echo Copying config file to new file to run tests."); system("cp configtest.txt configtest2.txt"); system("echo \n"); system("echo --------- Start example ----------"); op = PxConfigOpen("configtest2.txt", PXCONFIG_WRITE); princ("\nOpened? (0 = no, -1 = yes): ", op,"\n\n"); a = PxConfigWriteBool("Section Five", "LineOne", PXCONFIG_FMT_BOOL_TRUE, 2); b = PxConfigWriteChar("Section Four", "LineTwo", PXCONFIG_FMT_CHAR_CHAR, 'j'); c = PxConfigWriteChar("Section Five", "LineThree", PXCONFIG_FMT_CHAR_HEX, 0x6a); d = PxConfigWriteInt("Section Four", "LineFour", PXCONFIG_FMT_INT_DECIMAL, 25); e = PxConfigWriteInt("Section Five", "LineFive", PXCONFIG_FMT_INT_HEX, 25); f = PxConfigWriteShort("Section Five", "LineSix", PXCONFIG_FMT_INT_DECIMAL, 3.9); g = PxConfigWriteLong("Section Five", "LineSeven", PXCONFIG_FMT_INT_HEX, 9.5); h = PxConfigWriteString("Section Five", "LineEight", PXCONFIG_FMT_STRING, "Hello there."); with w in list(a,b,c,d,e,f,g,h) do princ("Line written? ", w, "\n"); cl = PxConfigClose(); princ("\nClosed? (0 = no, -1 = yes): ", cl,"\n"); system("echo \n"); system("echo --------- End example ----------"); system("echo \n"); system("echo Running diff to compare old and new config files:"); system("diff configtest.txt configtest2.txt"); system("echo \n"); system("echo Removing new copy of config file."); system("rm configtest2.txt"); system("echo \n"); /********* Sample output from program ********* Copying config file to new file to run tests. --------- Start example ---------- Opened? (0 = no, -1 = yes): -1 Line written? -1 Line written? -1 Line written? -1 Line written? -1 Line written? -1 Line written? -1 Line written? -1 Line written? -1 Closed? (0 = no, -1 = yes): -1 --------- End example ---------- Running diff to compare old and new config files: 21c21 < LineTwo = 11 --- > LineTwo = j 23c23 < LineFour = -0x15 --- > LineFour = 25 26a27,33 > [Section Five] > LineEight = Hello there. > LineSeven = 0x9 > LineSix = 3 > LineFive = 0x19 > LineThree = 0x6A > LineOne = TRUE Removing new copy of config file. ************** End of sample output **************/
PxConfigRead, PxConfigOpen, PxConfigForceEmptySection,
In Photon documentation: PxConfigWriteBool, PxConfigWriteChar, PxConfigWriteInt, PxConfigWriteLong, PxConfigWriteShort, PxConfigWriteString.
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.