iio.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "f2c.h"
  2. #include "fio.h"
  3. #include "fmt.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. extern char *f__icptr;
  8. char *f__icend;
  9. extern icilist *f__svic;
  10. int f__icnum;
  11. int
  12. z_getc(Void)
  13. {
  14. if(f__recpos++ < f__svic->icirlen) {
  15. if(f__icptr >= f__icend) err(f__svic->iciend,(EOF),"endfile");
  16. return(*(unsigned char *)f__icptr++);
  17. }
  18. return '\n';
  19. }
  20. void
  21. #ifdef KR_headers
  22. z_putc(c)
  23. #else
  24. z_putc(int c)
  25. #endif
  26. {
  27. if (f__icptr < f__icend && f__recpos++ < f__svic->icirlen)
  28. *f__icptr++ = c;
  29. }
  30. int
  31. z_rnew(Void)
  32. {
  33. f__icptr = f__svic->iciunit + (++f__icnum)*f__svic->icirlen;
  34. f__recpos = 0;
  35. f__cursor = 0;
  36. f__hiwater = 0;
  37. return 1;
  38. }
  39. static int
  40. z_endp(Void)
  41. {
  42. (*f__donewrec)();
  43. return 0;
  44. }
  45. int
  46. #ifdef KR_headers
  47. c_si(a) icilist *a;
  48. #else
  49. c_si(icilist *a)
  50. #endif
  51. {
  52. f__elist = (cilist *)a;
  53. f__fmtbuf=a->icifmt;
  54. f__curunit = 0;
  55. f__sequential=f__formatted=1;
  56. f__external=0;
  57. if(pars_f(f__fmtbuf)<0)
  58. err(a->icierr,100,"startint");
  59. fmt_bg();
  60. f__cblank=f__cplus=f__scale=0;
  61. f__svic=a;
  62. f__icnum=f__recpos=0;
  63. f__cursor = 0;
  64. f__hiwater = 0;
  65. f__icptr = a->iciunit;
  66. f__icend = f__icptr + a->icirlen*a->icirnum;
  67. f__cf = 0;
  68. return(0);
  69. }
  70. int
  71. iw_rev(Void)
  72. {
  73. if(f__workdone)
  74. z_endp();
  75. f__hiwater = f__recpos = f__cursor = 0;
  76. return(f__workdone=0);
  77. }
  78. #ifdef KR_headers
  79. integer s_rsfi(a) icilist *a;
  80. #else
  81. integer s_rsfi(icilist *a)
  82. #endif
  83. { int n;
  84. if(n=c_si(a)) return(n);
  85. f__reading=1;
  86. f__doed=rd_ed;
  87. f__doned=rd_ned;
  88. f__getn=z_getc;
  89. f__dorevert = z_endp;
  90. f__donewrec = z_rnew;
  91. f__doend = z_endp;
  92. return(0);
  93. }
  94. int
  95. z_wnew(Void)
  96. {
  97. if (f__recpos < f__hiwater) {
  98. f__icptr += f__hiwater - f__recpos;
  99. f__recpos = f__hiwater;
  100. }
  101. while(f__recpos++ < f__svic->icirlen)
  102. *f__icptr++ = ' ';
  103. f__recpos = 0;
  104. f__cursor = 0;
  105. f__hiwater = 0;
  106. f__icnum++;
  107. return 1;
  108. }
  109. #ifdef KR_headers
  110. integer s_wsfi(a) icilist *a;
  111. #else
  112. integer s_wsfi(icilist *a)
  113. #endif
  114. { int n;
  115. if(n=c_si(a)) return(n);
  116. f__reading=0;
  117. f__doed=w_ed;
  118. f__doned=w_ned;
  119. f__putn=z_putc;
  120. f__dorevert = iw_rev;
  121. f__donewrec = z_wnew;
  122. f__doend = z_endp;
  123. return(0);
  124. }
  125. integer e_rsfi(Void)
  126. { int n = en_fio();
  127. f__fmtbuf = NULL;
  128. return(n);
  129. }
  130. integer e_wsfi(Void)
  131. {
  132. int n;
  133. n = en_fio();
  134. f__fmtbuf = NULL;
  135. if(f__svic->icirnum != 1
  136. && (f__icnum > f__svic->icirnum
  137. || (f__icnum == f__svic->icirnum && (f__recpos | f__hiwater))))
  138. err(f__svic->icierr,110,"inwrite");
  139. if (f__recpos < f__hiwater)
  140. f__recpos = f__hiwater;
  141. if (f__recpos >= f__svic->icirlen)
  142. err(f__svic->icierr,110,"recend");
  143. if (!f__recpos && f__icnum)
  144. return n;
  145. while(f__recpos++ < f__svic->icirlen)
  146. *f__icptr++ = ' ';
  147. return n;
  148. }
  149. #ifdef __cplusplus
  150. }
  151. #endif