/* Copyright © Oracle Corporation 1995. All Rights Reserved. */ /* The module contains run-time support routines for the sample loading programs. Everything in this module is intended to be portable. sql_load_rtl.h contains function prototypes for these functions. This module is maintained as a .SC program to allow for future enhancements that may include SQL statements and to allow easy cross compilation. */ #include #ifdef VMS #include "sql$sample:sql_load_rtl.h" #endif #ifdef __osf__ #include #endif #define RECORD_BUFFER_SIZE 1000 static char record_buffer[RECORD_BUFFER_SIZE+1]; static int record_buffer_cursor = 0; /* This function is called to read a record from an open file. The contents of the record should be read by calling get_field(), below. The return value, however, is a pointer to the record. Note that the input file MUST be open. If it is not open, a message is issued and a NULL pointer is returned. A NULL pointer is also returned on EOF (without a message). */ char *get_line( FILE *fp) /* IN - Input file */ { char *result = NULL; if (fp != NULL) { /* read a record and init the buffer cursor */ result = fgets(record_buffer,RECORD_BUFFER_SIZE,fp); record_buffer_cursor = 0; } else { printf("\n\nInput file is not open."); } return(result); } /* This function fetches a value from a record read by get_line(). The area from which the value is fetched is private to this module. The file must be open and at least one call to get_line() had to have been made. If the file is not open, a message is printed. If get_line() had not been called the value returned will be a blank string equal in size to 'count' + 1 (the \0). Note that the caller has to allocate storage for 'dest' which is equal in size to 'count' + 1. The value placed in 'dest' is padded to the size of 'count' and is NULL-terminated. */ void get_field( FILE *fp, /* IN - Input file */ char *dest, /* OUT - destination of field value */ int count) /* IN - number of characters to fetch */ { int i; if (fp != NULL) { if (dest != NULL) { for (i=0; i