dfe.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "f2c.h"
  2. #include "fio.h"
  3. #include "fmt.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. int
  8. y_rsk(Void)
  9. {
  10. if(f__curunit->uend || f__curunit->url <= f__recpos
  11. || f__curunit->url == 1) return 0;
  12. do {
  13. getc(f__cf);
  14. } while(++f__recpos < f__curunit->url);
  15. return 0;
  16. }
  17. int
  18. y_getc(Void)
  19. {
  20. int ch;
  21. if(f__curunit->uend) return(-1);
  22. if((ch=getc(f__cf))!=EOF)
  23. {
  24. f__recpos++;
  25. if(f__curunit->url>=f__recpos ||
  26. f__curunit->url==1)
  27. return(ch);
  28. else return(' ');
  29. }
  30. if(feof(f__cf))
  31. {
  32. f__curunit->uend=1;
  33. errno=0;
  34. return(-1);
  35. }
  36. err(f__elist->cierr,errno,"readingd");
  37. }
  38. static int
  39. y_rev(Void)
  40. {
  41. if (f__recpos < f__hiwater)
  42. f__recpos = f__hiwater;
  43. if (f__curunit->url > 1)
  44. while(f__recpos < f__curunit->url)
  45. (*f__putn)(' ');
  46. if (f__recpos)
  47. f__putbuf(0);
  48. f__recpos = 0;
  49. return(0);
  50. }
  51. static int
  52. y_err(Void)
  53. {
  54. err(f__elist->cierr, 110, "dfe");
  55. }
  56. static int
  57. y_newrec(Void)
  58. {
  59. y_rev();
  60. f__hiwater = f__cursor = 0;
  61. return(1);
  62. }
  63. int
  64. #ifdef KR_headers
  65. c_dfe(a) cilist *a;
  66. #else
  67. c_dfe(cilist *a)
  68. #endif
  69. {
  70. f__sequential=0;
  71. f__formatted=f__external=1;
  72. f__elist=a;
  73. f__cursor=f__scale=f__recpos=0;
  74. f__curunit = &f__units[a->ciunit];
  75. if(a->ciunit>MXUNIT || a->ciunit<0)
  76. err(a->cierr,101,"startchk");
  77. if(f__curunit->ufd==NULL && fk_open(DIR,FMT,a->ciunit))
  78. err(a->cierr,104,"dfe");
  79. f__cf=f__curunit->ufd;
  80. if(!f__curunit->ufmt) err(a->cierr,102,"dfe")
  81. if(!f__curunit->useek) err(a->cierr,104,"dfe")
  82. f__fmtbuf=a->cifmt;
  83. if(a->cirec <= 0)
  84. err(a->cierr,130,"dfe")
  85. FSEEK(f__cf,(OFF_T)f__curunit->url * (a->cirec-1),SEEK_SET);
  86. f__curunit->uend = 0;
  87. return(0);
  88. }
  89. #ifdef KR_headers
  90. integer s_rdfe(a) cilist *a;
  91. #else
  92. integer s_rdfe(cilist *a)
  93. #endif
  94. {
  95. int n;
  96. if(!f__init) f_init();
  97. f__reading=1;
  98. if(n=c_dfe(a))return(n);
  99. if(f__curunit->uwrt && f__nowreading(f__curunit))
  100. err(a->cierr,errno,"read start");
  101. f__getn = y_getc;
  102. f__doed = rd_ed;
  103. f__doned = rd_ned;
  104. f__dorevert = f__donewrec = y_err;
  105. f__doend = y_rsk;
  106. if(pars_f(f__fmtbuf)<0)
  107. err(a->cierr,100,"read start");
  108. fmt_bg();
  109. return(0);
  110. }
  111. #ifdef KR_headers
  112. integer s_wdfe(a) cilist *a;
  113. #else
  114. integer s_wdfe(cilist *a)
  115. #endif
  116. {
  117. int n;
  118. if(!f__init) f_init();
  119. f__reading=0;
  120. if(n=c_dfe(a)) return(n);
  121. if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
  122. err(a->cierr,errno,"startwrt");
  123. f__putn = x_putc;
  124. f__doed = w_ed;
  125. f__doned= w_ned;
  126. f__dorevert = y_err;
  127. f__donewrec = y_newrec;
  128. f__doend = y_rev;
  129. if(pars_f(f__fmtbuf)<0)
  130. err(a->cierr,100,"startwrt");
  131. fmt_bg();
  132. return(0);
  133. }
  134. integer e_rdfe(Void)
  135. {
  136. en_fio();
  137. return 0;
  138. }
  139. integer e_wdfe(Void)
  140. {
  141. return en_fio();
  142. }
  143. #ifdef __cplusplus
  144. }
  145. #endif