/* iniwrt.p Using the Parm table, create an ini file. Written by Scott Auge Copyright (c) 2001 Amduus Information Works, Inc. scott_auge@yahoo.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Explaination of formats: # anywhere in line represents a comment - best to have these at the beginning for readability. [] represents a stanza parm=value represents the value under that stanza Example: # Example Ini File [Stanza1] Parm1=this Parm2=that [Stanza2] Parm1=that Parm2=this Returns the value of the parm under the stanza or ? if not found. */ DEF VAR RCSVersion AS CHARACTER INIT "$Header: /home/appl/opensrc/misc/RCS/iniwrt.p,v 1.2 2001/08/05 01:13:55 sauge Exp $" NO-UNDO. DEF INPUT PARAMETER pDirectoryName AS CHARACTER NO-UNDO. DEF VAR lConfFileName AS CHARACTER NO-UNDO. DEF VAR lLastConfFileName AS CHARACTER NO-UNDO. DEF VAR lOpenFile AS LOGICAL NO-UNDO. DEF VAR lLastGroupName AS CHARACTER NO-UNDO. ASSIGN lConfFileName = "" lOpenFile = NO lLastGroupName = "". /* Loop through parms table deciding which file to create and append configs */ /* into. */ FOR EACH Parms NO-LOCK BY Parms.Application BY Parms.GroupName BY Parms.ParmName: /* Determine where the configuration file goes, and what it's name will */ /* be. */ ASSIGN lConfFileName = pDirectoryName + "/" + Parms.Application + ".conf". /* Determine if we have hit a new appliction for the parms table. (Multi- */ /* ple applications may use the same database, hence the parms table has a */ /* application field to help sort them out. */ IF lConfFileName <> lLastConfFileName THEN DO: /* Close any previously openned files for the LAST application that was */ /* encountered in the Parms table. */ IF lOpenFile = YES THEN OUTPUT CLOSE. /* Open the file and make note of what application we are currently */ /* working with so when the Parms.Application changes, we know we */ /* need to do some file housekeeping and start a new file. */ OUTPUT TO VALUE(lConfFileName). ASSIGN lLastConfFileName = lConfFileName. ASSIGN lOpenFile = YES. /* Put out some information for any human reader of the configuration */ /* file. */ PUT UNFORMATTED "# Automatically Generated " TODAY FORMAT ("99/99/99") " " STRING (TIME,"HH:MM:SS") "~n". PUT UNFORMATTED "# File Name: " lConfFileName "~n". PUT UNFORMATTED "# Generated by code derived from open source of~n". PUT UNFORMATTED "# Amduus Information Works, Inc. www.amduus.com~n". END. /* IF lConfFileName <> Parms.Application + ".conf" */ /* Groups are known by the [] notation. If we encounter a new group */ /* from the Parms. GroupName, set that Group name out and fill in the */ /* associated Name Value pairings. */ IF lLastGroupName <> Parms.GroupName THEN DO: PUT UNFORMATTED "~n[" Parms.GroupName "]~n". ASSIGN lLastGroupName = Parms.GroupName. END. /* IF lLastGroupName <> Parms.GroupName */ /* Dump out the name value pairing. */ PUT UNFORMATTED Parms.ParmName "=" Parms.ParmValue "~n". END. /* FOR EACH Parms */