rsfe.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* read sequential formatted external */
  2. #include "f2c.h"
  3. #include "fio.h"
  4. #include "fmt.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. int
  9. xrd_SL(Void)
  10. { int ch;
  11. if(!f__curunit->uend)
  12. while((ch=getc(f__cf))!='\n')
  13. if (ch == EOF) {
  14. f__curunit->uend = 1;
  15. break;
  16. }
  17. f__cursor=f__recpos=0;
  18. return(1);
  19. }
  20. int
  21. x_getc(Void)
  22. { int ch;
  23. if(f__curunit->uend) return(EOF);
  24. ch = getc(f__cf);
  25. if(ch!=EOF && ch!='\n')
  26. { f__recpos++;
  27. return(ch);
  28. }
  29. if(ch=='\n')
  30. { (void) ungetc(ch,f__cf);
  31. return(ch);
  32. }
  33. if(f__curunit->uend || feof(f__cf))
  34. { errno=0;
  35. f__curunit->uend=1;
  36. return(-1);
  37. }
  38. return(-1);
  39. }
  40. int
  41. x_endp(Void)
  42. {
  43. xrd_SL();
  44. return f__curunit->uend == 1 ? EOF : 0;
  45. }
  46. int
  47. x_rev(Void)
  48. {
  49. (void) xrd_SL();
  50. return(0);
  51. }
  52. #ifdef KR_headers
  53. integer s_rsfe(a) cilist *a; /* start */
  54. #else
  55. integer s_rsfe(cilist *a) /* start */
  56. #endif
  57. { int n;
  58. if(!f__init) f_init();
  59. f__reading=1;
  60. f__sequential=1;
  61. f__formatted=1;
  62. f__external=1;
  63. if(n=c_sfe(a)) return(n);
  64. f__elist=a;
  65. f__cursor=f__recpos=0;
  66. f__scale=0;
  67. f__fmtbuf=a->cifmt;
  68. f__cf=f__curunit->ufd;
  69. if(pars_f(f__fmtbuf)<0) err(a->cierr,100,"startio");
  70. f__getn= x_getc;
  71. f__doed= rd_ed;
  72. f__doned= rd_ned;
  73. fmt_bg();
  74. f__doend=x_endp;
  75. f__donewrec=xrd_SL;
  76. f__dorevert=x_rev;
  77. f__cblank=f__curunit->ublnk;
  78. f__cplus=0;
  79. if(f__curunit->uwrt && f__nowreading(f__curunit))
  80. err(a->cierr,errno,"read start");
  81. if(f__curunit->uend)
  82. err(f__elist->ciend,(EOF),"read start");
  83. return(0);
  84. }
  85. #ifdef __cplusplus
  86. }
  87. #endif