/** * Read input from a given file, until being told to stop reading characters,
ID: 3552960 • Letter: #
Question
/** * Read input from a given file, until being told to stop reading characters, * or until EOF. * * IMPORTANT: * The input replaces, entirely, any data that was already in the MYSTRING * object. * * @param hString * The MYSTRING handle of the string into which the input data should be * placed, replacing any prior data in this string * * @param hFile * A FILE* handle from which input should be read * * @param bIgnoreLeadingWhiteSpace * If true, ignore any leading white space. Leading white space means any * spaces, horizontal or vertical tabs, and newlines that occur before any * non-whitespace character has been encountered. The function pointed to be * fTerminate is not called for leading white space, when this argument is * true, but is called when this argument is false. * * @param fTerminate * A pointer to a function to be called upon reading each character, to * determine whether the character just read is a "terminator", i.e., * whether mystring_input should return after storing (or not storing, as * indicated by *pbDiscardChar) this character. This function will be called * as each character is read. It must return TRUE (non-zero) if the * just-read character should terminate input. It should set * *pbDiscardChar, as described below, before returning. * * The fTerminate function's signature is: * int (* fTerminate)(char ch, int * pbDiscardChar); * * with the following documentation: * @param ch * The character that was just read. fTerminate should determine whether * this character is a terminator. * * @param pbDiscardChar * Whether this character should be added to the MYSTRING object. Prior * to returning TRUE (non-zero) or FALSE (zero), fTerminate should set * *pbDiscardChar to one of the following values: * * 0: Do not discard the character. Add it to the MYSTRING object * 1: Discard the character. Do not add it to the MYSTRING object * * @return * TRUE if this character should cause termination of input; FALSE * otherwise. * * The fTerminate function is not called upon EOF. * * @return * upon failure: * MYSTRING_STATUS_ERROR (any of the arguments are null) * * upon success: * MYSTRING_STATUS_SUCCESS
MyString_Status mystring_input(MYSTRING hString, FILE * hFile, int bIgnoreLeadingWhiteSpace, int (* fTerminate)(char ch, int * pbDiscardChar)); /** * Read input from a given file, until being told to stop reading characters, * or until EOF. * * IMPORTANT: * The input replaces, entirely, any data that was already in the MYSTRING * object. * * @param hString * The MYSTRING handle of the string into which the input data should be * placed, replacing any prior data in this string * * @param hFile * A FILE* handle from which input should be read * * @param bIgnoreLeadingWhiteSpace * If true, ignore any leading white space. Leading white space means any * spaces, horizontal or vertical tabs, and newlines that occur before any * non-whitespace character has been encountered. The function pointed to be * fTerminate is not called for leading white space, when this argument is * true, but is called when this argument is false. * * @param fTerminate * A pointer to a function to be called upon reading each character, to * determine whether the character just read is a "terminator", i.e., * whether mystring_input should return after storing (or not storing, as * indicated by *pbDiscardChar) this character. This function will be called * as each character is read. It must return TRUE (non-zero) if the * just-read character should terminate input. It should set * *pbDiscardChar, as described below, before returning. * * The fTerminate function's signature is: * int (* fTerminate)(char ch, int * pbDiscardChar); * * with the following documentation: * @param ch * The character that was just read. fTerminate should determine whether * this character is a terminator. * * @param pbDiscardChar * Whether this character should be added to the MYSTRING object. Prior * to returning TRUE (non-zero) or FALSE (zero), fTerminate should set * *pbDiscardChar to one of the following values: * * 0: Do not discard the character. Add it to the MYSTRING object * 1: Discard the character. Do not add it to the MYSTRING object * * @return * TRUE if this character should cause termination of input; FALSE * otherwise. * * The fTerminate function is not called upon EOF. * * @return * upon failure: * MYSTRING_STATUS_ERROR (any of the arguments are null) * * upon success: * MYSTRING_STATUS_SUCCESS
MyString_Status mystring_input(MYSTRING hString, FILE * hFile, int bIgnoreLeadingWhiteSpace, int (* fTerminate)(char ch, int * pbDiscardChar)); MyString_Status mystring_input(MYSTRING hString, FILE * hFile, int bIgnoreLeadingWhiteSpace, int (* fTerminate)(char ch, int * pbDiscardChar));
Explanation / Answer
The preprocessor directives that Pro*C/C++ supports are:
Some C preprocessor directives are not used by the Pro*C/C++ preprocessor. Most of these directives are not relevant for the precompiler. For example, #pragma is a directive for the C compiler--the precompiler does not process C pragmas. The C preprocessor directives not processed by the precompiler are
While your C compiler preprocessor may support these directives, Pro*C/C++ does not use them. Most of these directives are not used by the precompiler. You can use these directives in your Pro*C/C++ program if your compiler supports them, but only in C/C++ code, not in embedded SQL statements or declarations of variables using datatypes supplied by the precompiler, such as VARCHAR.
Pro*C/C++ predefines a C preprocessor macro called ORA_PROC that you can use to avoid having the precompiler process unnecessary or irrelevent sections of code. Some applications include large header files, which provide information that is unnecessary when precompiling. By conditionally including such header files based on the ORA_PROC macro, the precompiler never reads the file.
The following example uses the ORA_PROC macro to exclude the irrelevant.h file:
Because ORA_PROC is defined during precompilation, the irrelevant.h file is never included.
The ORA_PROC macro is available only for C preprocessor directives, such as #ifdef or #ifndef. The EXEC ORACLE conditional statements do not share the same the namespaces as the C preprocessor macros. Therefore, the condition in the following example doesnot use the predefined ORA_PROC macro:
ORA_PROC, in this case, must be set using either the DEFINE option or an EXEC ORACLE DEFINE statement for this conditional code fragment to work properly.
The Pro*C/C++ Precompiler for each port assumes a standard location for header files to be read by the preprocessor, such as sqlca.h,oraca.h, and sqlda.h. For example, on most UNIX ports, the standard location is $ORACLE_HOME/proc/lib. For the default location on your system, see your system-specific Oracle documentation. If header files that you need to include are not in the default location, you must use the INCLUDE= option, on the command line or as an EXEC ORACLE option. See Chapter 7 for more information about the precompiler options, and about the EXEC ORACLE options.
To specify the location of system header files, such as stdio.h or iostream.h, where the location might be different from that hard-coded into Pro*C/C++, use the SYS_INCLUDE precompiler option. See Chapter 7 for more information.
You can use the #define command to create named constants, and use them in place of ``magic numbers" in your source code. You can use #defined constants for declarations that the precompiler requires, such as VARCHAR[]. For example, instead of potentially buggy code like
you can code
You can use preprocessor macros with arguments for objects that the precompiler must process, just as you can for C objects. For example:
You can use the #include, #ifdef and #endif preprocessor directives to conditionally include a file that the precompiler requires. For example:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.