io.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "bc_io.h"
  2. #include <sgtty.h>
  3. /* $Id$ */
  4. struct sgttyb _ttydef;
  5. /* BASIC has some nasty io characteristics */
  6. #define MAXWIDTH 255
  7. int _width = 75, _pos=0, _zonewidth=15;
  8. _out(str)
  9. char *str;
  10. {
  11. int pos;
  12. if( _chann== -1) pos= _pos;
  13. else pos= _fdtable[_chann].pos;
  14. while( *str)
  15. {
  16. if( pos>= _width){ _outnl(); pos=0;}
  17. fputc(*str++, _chanwr);
  18. pos++;
  19. }
  20. if( _chann== -1) _pos=pos;
  21. else _fdtable[_chann].pos= pos;
  22. }
  23. _outnl()
  24. {
  25. fputc('\n',_chanwr);
  26. if( _chann == -1)
  27. _pos=0;
  28. else
  29. _fdtable[_chann].pos=0;
  30. }
  31. _zone()
  32. {
  33. /* go to next zone */
  34. int pos;
  35. if( _chann == -1)
  36. pos= _pos;
  37. else pos= _fdtable[_chann].pos;
  38. do{
  39. fputc(' ',_chanwr);
  40. pos++;
  41. if( pos==_width)
  42. {
  43. _outnl();
  44. pos=0;
  45. break;
  46. }
  47. } while( pos % _zonewidth != 0);
  48. if( _chann== -1) _pos=pos;
  49. else _fdtable[_chann].pos= pos;
  50. }
  51. _in(buf)
  52. char *buf;
  53. {
  54. register int holder ;
  55. char *c;
  56. int pos;
  57. if( _chann == -1)
  58. {
  59. pos= _pos;
  60. gtty(0,_ttydef);
  61. _ttydef.sg_flags &= ~ECHO;
  62. stty(0,_ttydef);
  63. }else pos= _fdtable[_chann].pos;
  64. c= buf;
  65. while( (holder = fgetc(_chanrd)) != EOF && holder != '\n'){
  66. *c= holder ;
  67. if( _chann == -1) putchar(holder);
  68. c++; pos++;
  69. }
  70. *c= 0;
  71. if( _chann== -1)
  72. {
  73. _pos=pos;
  74. _ttydef.sg_flags |= ECHO;
  75. stty(0,_ttydef);
  76. } else _fdtable[_chann].pos= pos;
  77. }
  78. _tab(x)
  79. int x;
  80. {
  81. if( x> _width) error(3);
  82. if( x< _pos) _outnl();
  83. _spc(x-_pos);
  84. }
  85. _spc(x)
  86. int x;
  87. {
  88. while(x-->0) _out(" ");
  89. }