HP 3000 Manuals

Running HP C/iX Programs [ HP C/iX Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Reference Manual

Running HP C/iX Programs 

You can run HP C/iX programs using the RUN command or by entering the
program name (an implied run).  You can pass parameters to the main
program and redirect the standard input (stdin), standard output
(stdout), and error output (stderr) to specific files by using the INFO
string.

Program Parameters 

You can pass parameters to an HP C/iX program by declaring them in the
function main as shown in the following example:

     main(argc, argv, envp, parm, info)
        int   argc;
        char  *argv[];
        char  *envp[];
        int   parm;
        char  *info;


NOTE The envp parameter is required as a placeholder in the formal parameter list for main. This parameter is not initialized on MPE/iX and must not be used. It is provided for compatibility with programs on other systems that pass envp to main.
You invoke the program (called MYPROG) with the following command: RUN MYPROG; INFO="STR1 STR2 STR3"; PARM=11 The C compiler separates the INFO string into argv arguments using blanks as argument delimiters and sets argc to the number of argv elements. To pass an argument that contains embedded blanks, enclose the argument in quotes. Use single quotes to delimit the argument if the INFO string is enclosed in double quotes; use double quotes if the INFO string is enclosed in single quotes. A quote may be included within a quoted string by escaping the quote with another quote similar to the manner in which the MPE/iX command interpreter allows quotes to be passed in the INFO string. The argv[0] argument is set equal to the program name, and argv[argc] is set equal to NULL. The PARM and INFO values are passed unchanged to the program. The order of the declaration of parameters to main is significant, but the names of the formal parameters can be any valid identifier. For the previous RUN command: argv[0] = MYPROG.MYGROUP.MYACCT argv[1] = "STR1" argv[2] = "STR2" argv[3] = "STR3" argv[4] = NULL argc = 4 parm = 11 info = "STR1 STR2 STR3" To include blanks within a single entry in the argv array, the following command: RUN MYPROG; INFO="STR1 'STR2 WITH BLANKS' STR3" yields: argv[0] = MYPROG.MYGROUP.MYACCT argv[1] = "STR1" argv[2] = "STR2 WITH BLANKS" argv[3] = "STR3" argv[4] = NULL argc = 4 info = "STR1 'STR2 WITH BLANKS' STR3" To include a single quote in a single quoted argument, the following command: RUN MYPROG; INFO="STR1 'STR2 WITH QUOTE HID' 'DEN' STR3" yields: argv[0] = MYPROG.MYGROUP.MYACCT argv[1] = "STR1" argv[2] = "STR2 WITH QUOTE HID'DEN" argv[3] = "STR3" argv[4] = NULL argc = 4 info = "STR1 'STR2 WITH QUOTE HID' 'DEN' STR3" A maximum of 1023 argv[] entries are allowed and the maximum length of the info string is 279 characters. Redirection of Standard Files The special characters <, >, >>, and & may be specified in the INFO string to redirect standard files for a compiled HP C/iX program. The special characters are described in the following table. Table 8-3. Redirection Characters --------------------------------------------------------------------------------------------- | | | | Character | Description | | | | --------------------------------------------------------------------------------------------- | | | | < | The name immediately following this symbol in the INFO string is | | | considered a file name and the standard input for the program is read | | | from that file. | | | | --------------------------------------------------------------------------------------------- | | | | > | The name immediately following this symbol in the INFO string is | | | considered a file name and the standard output of the program is sent | | | to that file. | | | | --------------------------------------------------------------------------------------------- | | | | >> | The name immediately following this symbol in the INFO string is | | | considered a file name and the standard output of the program is | | | appended to the end of the file. | | | | --------------------------------------------------------------------------------------------- | | | | & | When included after > or >>, this character redirects the diagnostic | | | output as well as the standard output to the specified file. The | | | diagnostic output cannot be redirected separately from standard | | | output. | | | | --------------------------------------------------------------------------------------------- The redirection characters and the file names which follow these characters do not appear in the argv vectors or the argc count. For example, RUN MYPROG; INFO= "FILE1 FILE2 >& OUTFILE" runs MYPROG with FILE1 and FILE2 passed in argv and redirects both the diagnostic output and the standard output to the file OUTFILE. In this example, argc is set to 3. The Fileset Wildcard Feature If the fileset wildcard feature is selected when the program is linked, the INFO string handler for a compiled HP C/iX program expands valid fileset wildcards into fully qualified permanent file names and passes them into the main program through the argv vectors. To use the wildcard feature, add the relocatable library LIBCWC.LIB.SYS to the FROM list when linking your program. If this file is not in the FROM list, the wildcard feature is not enabled. The CCXLLK and CCXLGO commands do not include this library when linking. Example. LINK FROM=MYOBJ,LIBCWC.LIB.SYS; RL=LIBCINIT.LIB.SYS; TO=MYPROG This example enables the wildcard feature for INFO strings passed to MYPROG. The fileset wildcards characters for an HP C/iX program are @, ?, and #. They are based on the standard MPE/iX wildcards recognized by commands and subsystems. The wildcard characters are described in the following table. Table 8-4. Fileset Wildcard Characters -------------------------------------------------------------------------------------------- | | | | Character | Description | | | | -------------------------------------------------------------------------------------------- | | | | @ | Specifies zero or more alphanumeric characters. When used | | | by itself, @ represents all members of a set. | | | | -------------------------------------------------------------------------------------------- | | | | # | Specifies a single numeric character. | | | | -------------------------------------------------------------------------------------------- | | | | ? | Specifies a single alphanumeric character. | | | | -------------------------------------------------------------------------------------------- These characters can be used as follows: Character Description n@ Represents all filenames starting with the character n. @n Represents all filenames ending with the character n. n@x Represents all filenames starting with the character n and ending with the character x. n####### Represents all filenames starting with the character n followed by a maximum of seven digits. ?n@ Represents all filenames whose second character is n. n? Represents all 2-character filenames starting with the character n. ?n Represents all 2-character filenames ending with the character n
NOTE Each wildcard character is one of the 8-character limit for account, group, and filename. A valid wildcard fileset must start with an alphabetic character, an @, or a ?. Invalid wildcard filesets are passed unaltered to the main program.
Example. If the permanent files in the group and account MYGROUP.MYACCT contains FILE1, FILEX, MYFILE, and MYPROG, the following: RUN MYPROG; INFO="@ FILE# FILE?" yields: argv[0] = "MYPROG.MYGROUP.MYACCT" /* name of program */ argv[1] = "FILE1.MYGROUP.MYACCT" /* @ */ argv[2] = "FILEX.MYGROUP.MYACCT" /* @ */ argv[3] = "MYFILE.MYGROUP.MYACCT" /* @ */ argv[4] = "MYPROG.MYGROUP.MYACCT" /* @ */ argv[5] = "FILE1.MYGROUP.MYACCT" /* FILE# */ argv[6] = "FILE1.MYGROUP.MYACCT" /* FILE? */ argv[7] = "FILEX.MYGROUP.MYACCT" /* FILE? */ argv[8] = NULL argc = 8 info = "@ FILE# FILE?" If no files are found in the fileset, or an error occurs in attempting to expand a wildcard fileset, a diagnostic message is printed to $STDLIST and the process terminates immediately. Attempting to use a wildcard fileset that would expand the number of argv elements beyond the 1023 element maximum also results in an error. Escaping Special INFO String Characters Special INFO string characters are characters that have special meaning to the C INFO string parser. They include the standard I/O redirection characters <, >, and &, as well as the fileset wildcard characters @, ?, and # if the wildcard feature is enabled. If you wish to pass strings containing these characters into a program in the argv vectors, you must enclose these strings with either single or double quotes. Use single quotes if your INFO string is delimited with double quotes, and double quotes if your INFO string is delimited with single quotes. This will disable their special functions and cause the INFO string parser to pass them along to the main program. Example. RUN MYPROG; INFO ="'@' '<IDENTIFIER>'" yields: argv[0] = "MYPROG.MYGROUP.MYACCT" argv[1] = "@" argv[2] = "<IDENTIFIER>" argv[3] = NULL argc = 3 info = "'@' '<IDENTIFIER>'" HP C/iX and Job Control Words When an HP C/iX program terminates normally, a special job control word, CJCW, is set to the exit value of the program. It contains the value of the parameter passed to the C library routine exit, or _exit, or the value returned from the function main if exit is not explicitly called. The convention for C programs is to exit with a nonzero value if an error condition has occurred, or exit with zero if no errors have occurred. CJCW could be used for checking the exit value of a program in a job file, or programmatically checking the exit value of a child process. [REV BEG] The value of CJCW is unpredictable if [REV END] the function main does not take care to return a value or if the exit function is not explicitly called. Examples main() { . . exit(7); } or main() { . . return(7); } Either of the above examples sets CJCW to the value of 7 on program termination. If a C program calls the C library routine abort, the system job control word JCW is set to FATAL and a diagnostic message is printed to $STDLIST. CJCW is set to a nonzero value. Arithmetic Traps C/iX programs execute with all arithmetic traps disabled. The C program startup routines call the ARITRAP intrinsic with an argument of zero to disable the traps.


MPE/iX 5.0 Documentation