home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / RECIO110.ZIP / USAGE.TXT < prev    next >
Text File  |  1994-03-28  |  24KB  |  785 lines

  1.     Title: STANDARD USAGE OF C LANGUAGE RECIO LIBRARY
  2. Copyright: (C) 1994 William Pierpoint
  3.   Version: 1.10
  4.      Date: March 28, 1994
  5.  
  6.  
  7.  
  8. 1.0 INTRODUCTION
  9.  
  10. The implementation descibed by this standard usage is a superset of the
  11. recio specification.  Enhancements are noted in the text.
  12.  
  13.  
  14. 1.1 Mnemonics
  15.  
  16. The recio functions have been given a consistent mnemonic naming
  17. convention.  All recio functions are in lower case and start with
  18. the letter r.  Function names are analogous to <stdio.h> functions.
  19. Mnemonics are as follows:
  20.  
  21. Single letter (field functions)               Multi-letter
  22. ----------------------------------------      -----------------
  23. b - base (prefix)                             beg - beginning
  24. c - column (prefix), character (suffix)       ch  - character
  25. d - double (suffix)                           col - column         
  26. f - float (suffix)                            cxt - context        
  27. i - integer (suffix)                          eof - end of file
  28. l - long (suffix)                             err - error          
  29. n - number                                    fld - field buffer
  30. r - record pointer (first letter)             fn  - function
  31. s - string pointer (suffix)                   no  - number         
  32. u - unsigned (suffix)                           rec - record buffer  
  33.                           siz - size of buffer
  34.                           str - string
  35.                           txt - text
  36. 1.2 Order
  37.  
  38. The order in which the prefix mnemonics appear indicates the order in which
  39. the arguments appear in the function.  The suffix mnemonics tell you what
  40. the function returns.  For example,
  41.  
  42. rbgetui():
  43.     arguments:  r - record pointer
  44.                 b - base (radix) of input
  45.       returns: ui - unsigned integer
  46.  
  47. Note: c is used in the prefix of a function's name only once even if there
  48.       are two column arguments.  If the function returns a character, there
  49.       is only one column argument; otherwise there are two.
  50.  
  51.  
  52.  
  53. 2.0 ERROR CHECKING
  54.  
  55. The functions declared in the header <recio.h> make use of the errno macro
  56. defined in section 4.1.3 of ANSI X3.159-1989.  This mechanism was chosen
  57. because (1) the <stdlib.h> conversion functions (strtod(), strtol(), etc.)
  58. make use of this error reporting mechanism and (2) the <recio.h> functions
  59. make use of the <stdlib.h> conversion functions.
  60.  
  61. In this implementation, errno can return the following macro constants:
  62.  
  63.          0 - No error.
  64.     EACCES - permission denied.
  65.     EINVAL - invalid argument (usually null record pointer).
  66.     EMFILE - too many open files.
  67.     ENOENT - no such file or directory.
  68.     ENOMEM - out of memory.
  69.  
  70. Beginning with version 1.1, recio functions set errno when the record 
  71. pointer is invalid and set an internal error number when the record pointer 
  72. is valid.  The recio error number is accessed through the rerror function.
  73.  
  74. The rerror function can return the following macro constants:
  75.  
  76.          0 - No error.
  77.   R_EINVAL - invalid argument (not the record pointer).
  78.  R_EINVDAT - invalid data.
  79.  R_EMISDAT - missing data.
  80.   R_ENOMEM - out of memory.
  81.   R_ENOREG - unable to register exit function with atexit().
  82.   R_ERANGE - data out of range.
  83.  
  84.  
  85.  
  86. 2.1 Define Callback Error Function
  87.  
  88. First define a callback error function to be used by the recio functions.
  89. You may give the function any name you wish.  In the sample function below,
  90. the name rerrfn is used.  The function takes one argument, a record pointer
  91. (REC *).  It returns nothing (void).  The function must first check for a
  92. valid record pointer using the risvalid function.  Other than that, you can
  93. customize it to do whatever you want.
  94.  
  95. The recio functions use a callback error function in order to give the
  96. most flexibility in handling errors.  This rerrfn function just sends
  97. information to stderr.  You may wish to send information to a printer,
  98. a file, a window, or a dialog box.  You might even want to give users
  99. the ability to examine errors and enter corrections.  If the error is
  100. corrected, you will want to call the rclearerr function before your
  101. callback error function returns.
  102.  
  103. When your callback error function is invoked, check rerror() or errno
  104. to determine the cause of the error.
  105.  
  106. Symbolic errno constants:
  107.  
  108. * EACCESS means that you don't have permission to access this file.  All
  109.   MSDOS files have read permission.
  110.  
  111. * EINVAL indicates an invalid argument to a function, usually a NULL record
  112.   pointer.  This resulted from a programming error.
  113.  
  114. * EMFILE means the program tried to open more files than the maximum allotted
  115.   by ROPEN_MAX or FOPEN_MAX.  If your program is interactive, the user can
  116.   close one or more open record streams.  Or you might decide that ROPEN_MAX
  117.   or FOPEN_MAX needs to be a larger value.
  118.  
  119. * ENOENT says that ropen() could not find the requested file to open.
  120.   Perhaps the name of the file was misspelled, or your program looked in
  121.   wrong directory.  If your program was trying to read a configuration file,
  122.   it could use internal default values when the configuration file does
  123.   not exist.
  124.  
  125. * ENOMEM indicates that the program ran out of heap space.  You may be able
  126.   to correct this if you are able to deallocate memory you no longer need.
  127.   For example, you could reduce the size of buffers when the size only
  128.   affects speed.  Such buffers need to be flushed first.  Buffers used by
  129.   the recio library do not fit this criteria.
  130.  
  131. Symbolic rerror() constants:
  132.  
  133. * R_ENOREG means the program was unable to register the internal recio exit
  134.   function with the ANSI atexit() function.  The internal recio exit
  135.   function ensures that all open record streams are closed and all dynamic
  136.   memory allocated by the recio library is deallocated.  This error is not
  137.   fatal.  EFAULT only has this meaning within the context of the recio
  138.   library.
  139.  
  140. * R_EINVDAT says the data is invalid.  Invalid data is caused by an 
  141.   unrecognized character in the field.  For example, rgetui() doesn't 
  142.   expect to see a negative sign, so a negative number will be flagged as 
  143.   invalid data.
  144.  
  145. * R_EMISDAT says the data is missing.  Missing data means the field is empty.  
  146.   If you expect a number, you could substitute either zero or some unique 
  147.   number to indicate an empty field.
  148.  
  149. * R_ENOMEM indicates that the program ran out of heap space.  You may be able
  150.   to correct this if you are able to deallocate memory you no longer need.
  151.   For example, you could reduce the size of buffers when the size only
  152.   affects speed.  Such buffers need to be flushed first.  Buffers used by
  153.   the recio library do not fit this criteria.
  154.  
  155. * R_ERANGE tells you that the data is outside the range of the function.
  156.   For instance, suppose you used rgeti() to get an integer and the data
  157.   value is 32768.  If a 16-bit integer has an upper limit of 32767, the
  158.   value is too large.  If the data is wrong, you can have the error
  159.   function correct it.  If the data is right, you have to correct the
  160.   program.
  161.  
  162. The main purpose of this sample callback error function is to show some of
  163. kinds of things you can do in a callback error function.  Note that when an
  164. error occurs, the column number indicator rcolno() has moved just beyond
  165. the error.  To make it clearer to the user where the error occurred, rerrfn()
  166. displays rcolno()-1, but not less than the column number for the first column 
  167. of the record.  For a more detailed callback error function, see the source 
  168. code for one the test programs.
  169.  
  170. /* define callback error function */
  171. void rerrfn(REC *rp)
  172. {
  173.     int errnum; /* error number */
  174.  
  175.     /* if rp is a valid record pointer */
  176.     if (risvalid(rp)) {
  177.  
  178.       /* reof flag set */
  179.       if (reof(rp)) {
  180.           fprintf(stderr, "ERROR reading %s: "
  181.            "tried to read past end of file\n\n", rnames(rp));
  182.  
  183.       /* rerror flag set */
  184.       } else {
  185.  
  186.           /* determine cause of error */
  187.           errnum = rerror(rp);
  188.           switch (errnum) {
  189.  
  190.           /* data errors */
  191.           case R_ERANGE:
  192.           case R_EINVDAT:
  193.           case R_EMISDAT:
  194.  
  195.               /* print location of error */
  196.               fprintf(stderr, "DATA ERROR in FILE %s at LINE %ld,"
  197.                " FIELD %u, COLUMN %u\n", rnames(rp), rrecno(rp),
  198.                rfldno(rp), max(rcolno(rp)-1, rbegcolno(rp)));
  199.  
  200.           /* warnings: non-fatal errors */
  201.           case R_ENOREG:
  202.               fprintf(stderr, "WARNING: could not register exit function\n");
  203.               rclearerr();
  204.               break;
  205.  
  206.           /* fatal errors (R_EINVAL, R_ENOMEM) */
  207.           case R_EINVAL:
  208.             fprintf(errout, "FATAL ERROR reading FILE %s: invalid argument", 
  209.              rnames(rp));
  210.             abort();
  211.             break;
  212.           case R_ENOMEM:
  213.             fprintf(errout, "FATAL ERROR reading FILE %s: out of memory", 
  214.              rnames(rp));
  215.             abort();
  216.             break;
  217.           default:
  218.             fprintf(errout, "FATAL ERROR reading FILE %s: unknown error", 
  219.              rnames(rp));
  220.             abort();
  221.             break;
  222.           }
  223.       }
  224.  
  225.     /* else invalid record pointer */
  226.     } else {
  227.         switch (errno) {
  228.  
  229.         /* non-fatal errors */
  230.         case EACCES:
  231.         case EMFILE:
  232.           fprintf(errout, "WARNING: %s\n", strerror(errno));
  233.           break;
  234.  
  235.         /* fatal errors (EINVAL, ENOMEM) */
  236.         default:
  237.           fprintf(errout, "FATAL ERROR: %s\n", strerror(errno));
  238.           abort();
  239.           break;
  240.         }
  241.     }
  242. }
  243.  
  244.  
  245. 2.2 Register Callback Error Function
  246.  
  247. Once you have written your callback error function, you must let the other 
  248. recio functions know that it exists.  You use the rseterrfn function to 
  249. register your callback error function.
  250.  
  251.     /* register rerrfn() as callback error function for recio */
  252.     rseterrfn(rerrfn);
  253.  
  254.  
  255.  
  256. 3.0 OPEN FILE
  257.  
  258.  
  259. 3.1 Open File and Get Record Pointer
  260.  
  261. Use the ropen function to open the file you want to read.  Store the record
  262. pointer returned by the ropen function.  To read from standard input, do 
  263. not try to open recin.  It is always open, so it does not need to be opened 
  264. or closed.
  265.  
  266.     REC *rp = ropen("FILENAME.DAT", "r");
  267.  
  268.  
  269. 3.2 Check Record Pointer
  270.  
  271. Following the ropen function, you need to check to see if the file was
  272. opened correctly.  If ropen returned a NULL pointer, then the file was not
  273. opened.
  274.  
  275. Errors other than ENOENT are reported to your callback error function.
  276. ENOENT is not reported since you may want to use default values if the
  277. data file is not available.
  278.  
  279.     /* if ropen() failed */
  280.     if (!rp) {
  281.         /* if it failed because file does not exist */
  282.         if (errno==ENOENT) {
  283.             /* action to take when file does not exist */
  284.             ...
  285.         }
  286.     /* else ropen() succeeded */
  287.     } else {
  288.         /* set up for read (see sections 3.3 and 3.4) */
  289.         ...
  290.         /* read through file (see sections 4 and 5) */
  291.         ...
  292.         /* close file (see section 6) */
  293.         rclose(rp);
  294.     }
  295.  
  296.  
  297. 3.3 Set Field and Text Delimiters
  298.  
  299. The space character is the default value for both the field and text 
  300. delimiters.  If you need to use something else, you need to explicitly
  301. set the values.  Application maintenance may be easier if you always 
  302. set the values.
  303.  
  304.     rsetfldch(rp, ',');  /* set field delimiter character */
  305.     rsettxtch(rp, '"');  /* set text delimiter character */
  306.  
  307.  
  308. 3.4 Set Field and Record Buffer Sizes
  309.  
  310. Setting the field and record buffer sizes is optional.  Buffers will be
  311. automatically reallocated as necessary.  However if you set the field and 
  312. record sizes in advance to the maximum value needed, you can reduce memory 
  313. fragmentation.
  314.  
  315.     rsetfldsiz(rp, 41);  /* set size of field buffer */
  316.     rsetrecsiz(rp, 133); /* set size of record buffer */
  317.  
  318.  
  319. 3.5 Set Context Number
  320.  
  321. If your application opens record streams with more than one data format, you 
  322. will want to set a context number.  You use the context number so that your 
  323. callback error function can determine (using the rcxtno function) which data 
  324. format it is dealing with.  Each context number must be a positive integer; 
  325. zero and negative numbers are reserved.
  326.  
  327. #define SOILS_DB      1
  328. #define BUILDINGS_DB  2
  329.  
  330.      rsetcxtno(rp, SOILS_DB); /* set context number */
  331.  
  332.  
  333. 3.6 Set Beginning Column Number
  334.  
  335. The first column number in the record buffer defaults to zero.  If you prefer 
  336. column numbering to start at one, use the rsetbegcolno function.  It is mainly 
  337. useful if using column delimited data.  If a number takes up the first ten 
  338. columns of the record, the column numbering will be 0 to 9 if rsetbegcolno() 
  339. is set to 0, or 1 to 10 is rsetbegcolno() is set to 1.
  340.  
  341.      rsetbegcolno(rp, 1); /* number first column as one */
  342.  
  343.  
  344.  
  345. 4.0 READ ALL RECORDS IN FILE
  346.  
  347. 4.1 The rgetrec Function
  348.  
  349. If all the records in a data file have the same format, you will want to 
  350. loop through all the records until the end of file is reached.  If each
  351. record has a different format, you must call the rgetrec function each
  352. time you want to get the next record.  Calling rgetrec() is optional for
  353. the first record.
  354.  
  355.     /* loop through all records in file */
  356.     while (rgetrec(rp)) {
  357.         /* Section 5 field functions go here ... */
  358.     }
  359.  
  360.  
  361. 4.2 The rrecs Macro
  362.  
  363. To get a pointer to the start of the record buffer, use the rrecs macro.
  364.  
  365.     /* echo record contents to stdout */
  366.     printf("%s\n", rrecs(rp));
  367.  
  368.  
  369. 4.3 The rrecno Macro
  370.  
  371. To get the record number, use the rrecno macro.
  372.  
  373.     /* echo record number and record contents to stdout */
  374.     printf("%ld: %s\n", rrecno(rp), rrecs(rp));
  375.  
  376.  
  377.  
  378. 5.0 GET FIELD DATA FOR EACH RECORD
  379.  
  380. The recio functions can handle records for two types of fields: 
  381. (1) character delimited and (2) column delimited.  
  382.  
  383.  
  384. 5.1 Character delimited fields
  385.  
  386. 5.1.1 Character fields
  387.  
  388. 5.1.1.1 The rgetc Function
  389.  
  390. Use the rgetc function to get a field consisting of a single non-whitespace 
  391. character.  Any whitespace in the field is skipped.
  392.  
  393.     /* get one non-whitespace character */
  394.     int ch = rgetc(rp);
  395.  
  396.  
  397. 5.1.2 String fields
  398.  
  399. String field functions return a pointer to the string buffer.  The string 
  400. buffer is overwritten each time a new string field is read.  To save the 
  401. string for later use, copy the string to a character array with sufficient
  402. space to hold the string (including the terminating null).
  403.  
  404.  
  405. 5.1.2.1 The rgets Function
  406.  
  407. Use the rgets function to get a field consisting of a string.
  408.  
  409.     /* duplicate string in string buffer */
  410.     char *str = strdup(rgets(rp));
  411.     ...
  412.     /* free string memory space when done with string */
  413.     free (str);
  414.  
  415.  
  416. 5.1.3 Floating point fields
  417.  
  418. 5.1.3.1 The rgetd Function
  419.  
  420. Use the rgetd function to get a field consisting of a double precision 
  421. floating point number.
  422.  
  423.     /* get a double */
  424.     double result = rgetd(rp);
  425.  
  426.  
  427. 5.1.3.2 The rgetf Function
  428.  
  429. Use the rgetf function to get a field consisting of a single precision
  430. floating point number.
  431.  
  432.     /* get a float */
  433.     float result = rgetf(rp);
  434.  
  435.  
  436. 5.1.4 Integer fields
  437.  
  438. 5.1.4.1 Base 10 integer fields
  439.  
  440. 5.1.4.1.1 The rgeti Macro
  441.  
  442. Use the rgeti macro to get a field consisting of an decimal integer.
  443.  
  444.     /* get a decimal integer */
  445.     int result = rgeti(rp);
  446.  
  447.  
  448. 5.1.4.1.2 The rgetl Macro
  449.  
  450. Use the rgetl macro to get a field consisting of a decimal long.
  451.  
  452.     /* get a decimal long */
  453.     long result = rgetl(rp);
  454.  
  455.  
  456. 5.1.4.1.3 The rgetui Macro
  457.  
  458. Use the rgetui macro to get a field consisting of an unsigned decimal 
  459. integer.
  460.  
  461.     /* get an unsigned decimal integer */
  462.     unsigned int result = rgetui(rp);
  463.  
  464.  
  465. 5.1.4.1.4 The rgetul Macro
  466.  
  467. Use the rgetul macro to get a field consisting of an unsigned long decimal 
  468. integer.
  469.  
  470.     /* get an unsigned decimal long */
  471.     unsigned long result = rgetul(rp);
  472.  
  473.  
  474. 5.1.4.2 Explicit base integer fields
  475.  
  476. 5.1.4.2.1 The rbgeti Function
  477.  
  478. Use the rbgeti function to get a field consisting of an integer in a 
  479. specified radix.
  480.  
  481.     /* get a hexadecimal integer */
  482.     int result = rbgeti(rp, 16);
  483.  
  484.  
  485. 5.1.4.2.2 The rbgetl Function
  486.  
  487. Use the rbgetl function to get a field consisting of a long integer in a 
  488. specified radix.
  489.  
  490.     /* get a hexadecimal long integer */
  491.     long result = rgetl(rp, 16);
  492.  
  493.  
  494. 5.1.4.2.3 The rbgetui Function
  495.  
  496. Use the rbgetui function to get a field consisting of an unsigned integer in 
  497. a specified radix.
  498.  
  499.     /* get a hexadecimal unsigned integer */
  500.     unsigned int result = rgetui(rp, 16);
  501.  
  502.  
  503. 5.1.4.2.4 The rbgetul Function
  504.  
  505. Use the rbgetul function to get a field consisting of an unsigned long 
  506. integer in a specified radix.
  507.  
  508.     /* get a hexadecimal unsigned long integer */
  509.     unsigned long result = rgetul(rp, 16);
  510.  
  511.  
  512. 5.1.5 Other Functions
  513.  
  514. 5.1.5.1 The rskipfld Macro
  515.  
  516. If your application does not need the data in a field, you can skip over the
  517. field by using the rskipfld macro.
  518.  
  519.     /* skip over a field */
  520.     if (rskipfld(rp) != 1) printf("Unable to skip field.\n");
  521.  
  522.  
  523. 5.1.5.2 The rskipnfld Function
  524.  
  525. If your application does not need the data in several adjacent fields, you 
  526. can skip over the fields by using the rskipnfld function.
  527.  
  528.     /* skip over three fields */
  529.     if (rskipnfld(rp, 3) != 3) printf("Unable to skip 3 fields.\n");
  530.  
  531.  
  532. 5.2 Column delimited fields
  533.     
  534. 5.2.1 Character fields
  535.  
  536. 5.2.1.1 The rcgetc Function
  537.  
  538. Use the rcgetc function to get a character from a specific column.
  539.  
  540.     /* get character from column number 12 */
  541.     int ch = rcgetc(rp, 12);
  542.  
  543.  
  544. 5.2.2 String fields
  545.  
  546. String field functions return a pointer to a static string.  This static
  547. string is overwritten each time a new string field is read.  To save the 
  548. string for later use, copy the string to a character array with sufficient
  549. space to hold the string (including the terminating null).
  550.  
  551.  
  552. 5.2.2.1 The rcgets Function
  553.  
  554. Use the rcgets function to get a string between two column locations.
  555.  
  556.     /* duplicate string in string buffer */
  557.     char *str = strdup(rcgets(rp, 0, 9));
  558.     ...
  559.     /* free string space when done with string */
  560.     free (str);
  561.  
  562.  
  563. 5.2.3 Floating point fields
  564.  
  565. 5.2.3.1 The rcgetd Function
  566.  
  567. Use the rcgetd function to get a double between two column locations.
  568.  
  569.     /* get a double between columns 0 and 9 */
  570.     double result = rcgetd(rp, 0, 9);
  571.  
  572.  
  573. 5.2.3.2 The rcgetf Function
  574.  
  575. Use the rcgetf function to get a float between two column locations.
  576.  
  577.     /* get a float between columns 0 and 9 */
  578.     float result = rgetd(rp, 0, 9);
  579.  
  580.  
  581. 5.2.4 Integer fields
  582.  
  583. 5.2.4.1 Base 10 integer fields
  584.  
  585. 5.2.4.1.1 The rcgeti Macro
  586.  
  587. Use the rcgeti macro to get a decimal integer between two column locations.
  588.  
  589.     /* get a decimal integer between columns 0 and 9 */
  590.     int result = rcgeti(rp, 0, 9);
  591.  
  592.  
  593. 5.2.4.1.2 The rcgetl Marco
  594.  
  595. Use the rcgetl macro to get a decimal long integer between two column 
  596. locations.
  597.  
  598.     /* get a decimal long between columns 0 and 9 */
  599.     long result = rcgetl(rp, 0, 9);
  600.  
  601.  
  602. 5.2.4.1.3 The rcgetui Macro
  603.  
  604. Use the rcgetui macro to get a decimal unsigned integer between two column 
  605. locations.
  606.  
  607.     /* get a decimal unsigned integer between columns 0 and 9 */
  608.     unsigned int result = rcgetui(rp, 0, 9);
  609.  
  610.  
  611. 5.2.4.1.4 The rcgetul Macro 
  612.  
  613. Use the rcgetul macro to get a decimal unsigned long between two column 
  614. locations.
  615.  
  616.     /* get a decimal unsigned long between columns 0 and 9 */
  617.     unsigned long result = rcgetul(rp, 0, 9);
  618.  
  619.  
  620. 5.2.4.2 Explicit base integer fields
  621.  
  622. 5.2.4.2.1 The rcbgeti Function
  623.  
  624. Use the rcbgeti function to get an integer in a specified radix from between
  625. two column locations.
  626.  
  627.     /* get a hexadecimal integer between columns 0 and 9 */
  628.     int result = rcbgeti(rp, 0, 9, 16);
  629.  
  630.  
  631. 5.2.4.2.2 The rcbgetl Function
  632.  
  633. Use the rcbgetl function to get a long in a specified radix from between two 
  634. column locations.
  635.  
  636.     /* get a hexadecimal long between columns 0 and 9 */
  637.     long result = rcbgetl(rp, 0, 9, 16);
  638.  
  639.  
  640. 5.2.4.2.3 The rcbgetui Function
  641.  
  642. Use the rcbgetui function to get an unsigned integer in a specified radix from 
  643. between two column locations.
  644.  
  645.     /* get a hexadecimal unsigned integer between columns 0 and 9 */
  646.     unsigned int result = rcbgetui(rp, 0, 9, 16);
  647.  
  648.  
  649. 5.2.4.2.4 The rcbgetul Function
  650.  
  651. Use the rcbgetul function to get an unsigned long in a specified radix from 
  652. between two column locations.
  653.  
  654.     /* get a hexadecimal unsigned long between columns 0 and 9 */
  655.     unsigned long result = rcbgetul(rp, 0, 9, 16);
  656.  
  657.  
  658. 5.3 Other Functions
  659.  
  660. 5.3.1 The reof Macro
  661.  
  662. Use the reof macro to determine when the record stream has reached the 
  663. end of file.
  664.  
  665.     /* if error or end of file reached */
  666.     if (rgetrec(rp)==EOF) {
  667.     
  668.         /* if end of file */
  669.         if (reof(rp)) {
  670.            ...
  671.         /* else error */
  672.         } else {
  673.            ...
  674.         }
  675.     }
  676.     
  677.  
  678. 5.3.2 The rerror Macro
  679.  
  680. Use the rerror macro to determine if an error has occurred on a record 
  681. stream.  The rerror macro returns the error number.  It is a good practice 
  682. to check for any errors just prior to closing a record stream.  If the 
  683. error indicator is clear, you have additional confidence that the stream 
  684. was read correctly.  
  685.  
  686.     if (rerror(rp)) printf("File %s not read correctly.\n", rnames(rp));
  687.     rclose(rp);
  688.  
  689.  
  690. 5.3.3 The rseterr Function
  691.  
  692. If you write wrapper functions or other functions that interact with 
  693. recio functions, your code will need to handle errors.  If can use 
  694. the rseterr function to set the error number and to call the record 
  695. stream callback error function.
  696.  
  697. /* get integer and validate range */
  698. int rrgeti(REC *rp, int min, int max) {
  699.     int result;
  700.     
  701.     result = rgeti(rp);
  702.     if (result < min || result > max) {
  703.         rseterr(rp, R_ERANGE);
  704.     }
  705.     return result;
  706. }
  707.  
  708.  
  709. 6.0 CLOSE FILE
  710.  
  711. 6.1 Close File
  712.  
  713. When finished reading a data file, close it.  Do not attempt to close recin 
  714. as it is always open.
  715.  
  716.     /* close record file */
  717.     rclose(rp);
  718.  
  719.  
  720. 6.2 Close All Files
  721.  
  722. Rather than closing record files one at a time, one can close all open 
  723. record files at once using the rcloseall function.
  724.  
  725.     /* all done */
  726.     rcloseall();
  727.  
  728.  
  729.  
  730. 7.0 INDEX
  731.  
  732. errno macro ............ 2.0, 2.1, 3.2
  733. rbegcolno macro ........ 2.1
  734. rbgeti function ........ 5.1.4.2.1
  735. rbgetl function ........ 5.1.4.2.2
  736. rbgetui function ....... 5.1.4.2.3
  737. rbgetul function ....... 5.1.4.2.4
  738. rcbgeti function ....... 5.2.4.2.1
  739. rcbgetl function ....... 5.2.4.2.2
  740. rcbgetui function ...... 5.2.4.2.3
  741. rcbgetul function ...... 5.2.4.2.4
  742. rcgetc function ........ 5.2.1.1
  743. rcgetd function ........ 5.2.3.1
  744. rcgetf function ........ 5.2.3.2
  745. rcgeti macro ........... 5.2.4.1.1
  746. rcgetl macro ........... 5.2.4.1.2
  747. rcgets function ........ 5.2.2.1
  748. rcgetui macro .......... 5.2.4.1.3
  749. rcgetul macro .......... 5.2.4.1.4
  750. rclearerr macro ........ 2.1
  751. rclose function ........ 6.1
  752. rcloseall function ..... 6.2
  753. rcolno macro ........... 2.1
  754. rcxtno macro ........... 3.5
  755. recin expression ....... 3.1, 6.1
  756. reof macro ............. 2.1, 5.3.1
  757. rerror macro ........... 2.1, 5.3.2
  758. rflds macro ............ 2.1
  759. rfldno macro ........... 2.1
  760. rgetc function ......... 5.1.1.1
  761. rgetd function ......... 5.1.3.1
  762. rgetf function ......... 5.1.3.2
  763. rgeti macro ............ 5.1.4.1.1
  764. rgetl macro ............ 5.1.4.1.2
  765. rgetrec function ....... 4.1
  766. rgets function ......... 5.1.2.1
  767. rgetui macro ........... 5.1.4.1.3
  768. rgetul macro ........... 5.1.4.1.4
  769. risvalid function ...... 2.1
  770. rnames macro ........... 2.1
  771. ropen function  ........ 3.1
  772. rrecs macro ............ 2.1, 4.2
  773. rrecno macro ........... 2.1, 4.3
  774. rsetbegcolno function .. 3.6
  775. rsetcxtno function ..... 3.5
  776. rseterr function ....... 5.3.3
  777. rseterrfn function ..... 2.2
  778. rsetfldch function ..... 3.3
  779. rsetfldsiz function .... 3.4
  780. rsetfldstr function .... 2.1
  781. rsetrecsiz function .... 3.4
  782. rsettxtch function ..... 3.3
  783. rskipfld macro  ........ 5.1.5.1
  784. rskipnfld function ..... 5.1.5.2
  785.