home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cidsam.zip
/
SAMPLE1.C
< prev
next >
Wrap
Text File
|
1993-06-28
|
11KB
|
156 lines
/*********************************/
/* NOTE */
/* */
/* This sample code has been */
/* provided by IBM. It is not */
/* warranted for any particular */
/* use or purpose. */
/* */
/* IBM releases this code into */
/* the public domain. You may */
/* use it, modify it, or */
/* incorporate it into other */
/* products without restriction. */
/*********************************/
/* This sample program uses the high-level Response File APIs to read a */
/* response file and extract the keyword/value pairs. It writes */
/* command (bat) file lines that will put the keywork/value pairs in the */
/* environment. You would redirect the output of this program to */
/* a file in real life. */
/* The Response File APIs described here operate at a fairly high */
/* level. They let you concentrate on the logic of your program */
/* rather than the details of file processing and parsing. They make */
/* certain assumptions, though. The Response File APIs assume that */
/* the response files follow certain syntax conventions. */
/* */
/* First, response files are assumed to consist of _keyword_ and */
/* _value_ pairs, connected by an equal (=) sign. For example, */
/* a keyword/value pair might look like */
/* */
/* color = blue */
/* */
/* All lines in a response file are assumed to contain keyword/value */
/* pairs except */
/* - Blank lines */
/* - Lines with an asterisk ('*') as the first non-blank character */
/* - Lines with a semicolon (';') as the first non-blank character */
/* These lines are treated as comment lines and ignored. */
/* */
/* The keyword is assumed to start with the first non-blank character */
/* of a line. It may not contain any blanks or tabs, and it may not */
/* contain the equal sign (=). */
/* */
/* The value is assumed to start with the first non-blank character */
/* after the equal sign and to continue to the end of the line. */
/* */
/* There can be only one keyword/value pair per line. */
/* */
/* Keywords can have either of two kinds of values: strings or lists. */
/* A string value is a 'simple' value consisting of a single string; */
/* the following are examples of keywords with string values: */
/* */
/* machine = IBM-PS/2 */
/* Preamble = We the People of the United States... */
/* comment = This is the way the world ends, this is the way */
/* Num_sessions = 3 */
/* */
/* A list value is a group of further keyword value pairs. The start */
/* of a list is indicated by a left paren to the right of the equal */
/* sign. The end of a list is indicated by a right paren on a line by */
/* itself. The following are examples of keywords with list values: */
/* */
/* list1 = ( */
/* name = george */
/* comment = simple list */
/* color = puce */
/* ) */
/* */
/* list2 = ( */
/* name = lucy */
/* comment = more complicated list */
/* sublist1 = ( */
/* adapter = 0 */
/* protocol = tcpip */
/* } */
/* sublist2 = ( */
/* adapter = 1 */
/* protocol = netbios */
/* ) */
/* ) */
/* */
/* Second, a 'special' keyword, include, is assumed. The purpose of */
/* this keyword is to imbed other response files within the current one. */
/* When the 'include' keyword is encountered, the Response File APIs */
/* open the included file and start processing its contents as if they */
/* were part of the original response file. Response file may be */
/* nested to any depth. Here's an example: */
/* */
/* Response file A.rsp contains */
/* color = brown */
/* speed = fast */
/* include = B.rsp */
/* */
/* Response file B.rsp contains */
/* level = 1 */
/* modification = 0 */
/* include = C.rsp */
/* */
/* Response file C.rsp contains */
/* buffers = 12 */
/* */
/* The Response File APIs read these these response files and return */
/* the keywords and values as if it were all one big file that contained */
/* */
/* color = brown */
/* speed = fast */
/* level = 1 */
/* modification = 0 */
/* buffers = 12 */
/* */
/* The Response File APIs contains code to guard against 'loops' of */
/* included response files. */
/* */
/* This sample uses the two most common Response File APIs, RFOpen() */
/* and RFGetNextKeyword(). RFOpen() takes the name of a response file */
/* and opens that file; subsequent 'reads' (using RFGetNextKeyword()) */
/* are taken from that response file and from any response files */
/* _included_ in it. */
/* */
/* */
/*************************************************************************
**************************************************************************/
#include <stdio.h>
#include "hlrfio.h" /* This header file contains the prototypes for */
/* The Response File APIs, and defines for the */
/* codes returned by the Response File APIs */
char *ResponseFileName = "test.rsp"; /* This is the name of the response*/
/* file we will open first. It */
/* might contain imbedded */
/* (included) response files, but */
/* that's OK. */
int main(int argc, char **argv)
{
int rc; /* return code */
char *keyword; /* Holds address of the keyword */
char *value; /* Holds address of the value */
unsigned type; /* Indicates the type of the value */
/* (string or list) */
rc = RFOpen(ResponseFileName); /* Open the response file. If the */
/* open was successful, RFH0 is */
/* returned. Otherwise, RFHERR. */
if (rc == RFH0) /* If the open worked, */
{ /* look at each keyword/value pair*/
while (RFGetNextKeyword(&keyword, &value, &type) == RFH0)
{ /* Check if the value returned is a*/
if (type == RFHSTRING) /* string. Lists don't fit in the */
/* environment very well. */
printf("@set %s=%s\n", keyword, value); /* write bat line */
}
} /* Note we don't have to close the */
} /* response file explicitely */