sue.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "f2c.h"
  2. #include "fio.h"
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. extern uiolen f__reclen;
  7. OFF_T f__recloc;
  8. int
  9. #ifdef KR_headers
  10. c_sue(a) cilist *a;
  11. #else
  12. c_sue(cilist *a)
  13. #endif
  14. {
  15. f__external=f__sequential=1;
  16. f__formatted=0;
  17. f__curunit = &f__units[a->ciunit];
  18. if(a->ciunit >= MXUNIT || a->ciunit < 0)
  19. err(a->cierr,101,"startio");
  20. f__elist=a;
  21. if(f__curunit->ufd==NULL && fk_open(SEQ,UNF,a->ciunit))
  22. err(a->cierr,114,"sue");
  23. f__cf=f__curunit->ufd;
  24. if(f__curunit->ufmt) err(a->cierr,103,"sue")
  25. if(!f__curunit->useek) err(a->cierr,103,"sue")
  26. return(0);
  27. }
  28. #ifdef KR_headers
  29. integer s_rsue(a) cilist *a;
  30. #else
  31. integer s_rsue(cilist *a)
  32. #endif
  33. {
  34. int n;
  35. if(!f__init) f_init();
  36. f__reading=1;
  37. if(n=c_sue(a)) return(n);
  38. f__recpos=0;
  39. if(f__curunit->uwrt && f__nowreading(f__curunit))
  40. err(a->cierr, errno, "read start");
  41. if(fread((char *)&f__reclen,sizeof(uiolen),1,f__cf)
  42. != 1)
  43. { if(feof(f__cf))
  44. { f__curunit->uend = 1;
  45. err(a->ciend, EOF, "start");
  46. }
  47. clearerr(f__cf);
  48. err(a->cierr, errno, "start");
  49. }
  50. return(0);
  51. }
  52. #ifdef KR_headers
  53. integer s_wsue(a) cilist *a;
  54. #else
  55. integer s_wsue(cilist *a)
  56. #endif
  57. {
  58. int n;
  59. if(!f__init) f_init();
  60. if(n=c_sue(a)) return(n);
  61. f__reading=0;
  62. f__reclen=0;
  63. if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
  64. err(a->cierr, errno, "write start");
  65. f__recloc=FTELL(f__cf);
  66. FSEEK(f__cf,(OFF_T)sizeof(uiolen),SEEK_CUR);
  67. return(0);
  68. }
  69. integer e_wsue(Void)
  70. { OFF_T loc;
  71. fwrite((char *)&f__reclen,sizeof(uiolen),1,f__cf);
  72. #ifdef ALWAYS_FLUSH
  73. if (fflush(f__cf))
  74. err(f__elist->cierr, errno, "write end");
  75. #endif
  76. loc=FTELL(f__cf);
  77. FSEEK(f__cf,f__recloc,SEEK_SET);
  78. fwrite((char *)&f__reclen,sizeof(uiolen),1,f__cf);
  79. FSEEK(f__cf,loc,SEEK_SET);
  80. return(0);
  81. }
  82. integer e_rsue(Void)
  83. {
  84. FSEEK(f__cf,(OFF_T)(f__reclen-f__recpos+sizeof(uiolen)),SEEK_CUR);
  85. return(0);
  86. }
  87. #ifdef __cplusplus
  88. }
  89. #endif