cls.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. *
  5. * This product is part of the Amsterdam Compiler Kit.
  6. *
  7. * Permission to use, sell, duplicate or disclose this software must be
  8. * obtained in writing. Requests for such permissions may be sent to
  9. *
  10. * Dr. Andrew S. Tanenbaum
  11. * Wiskundig Seminarium
  12. * Vrije Universiteit
  13. * Postbox 7161
  14. * 1007 MC Amsterdam
  15. * The Netherlands
  16. *
  17. */
  18. /* Author: J.W. Stevenson */
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <pc_file.h>
  22. #include <pc_err.h>
  23. extern struct file *_curfil;
  24. extern _trp();
  25. extern _flush();
  26. extern _outcpt();
  27. _xcls(f) struct file *f; {
  28. if ((f->flags & WRBIT) == 0)
  29. return;
  30. if ((f->flags & (TXTBIT|ELNBIT)) == TXTBIT) {
  31. #ifdef CPM
  32. *f->ptr = '\r';
  33. _outcpt(f);
  34. #endif
  35. *f->ptr = '\n';
  36. _outcpt(f);
  37. }
  38. _flush(f);
  39. }
  40. _cls(f) struct file *f; {
  41. #ifdef MAYBE
  42. char *p;
  43. #endif
  44. _curfil = f;
  45. if ((f->flags&0377) != MAGIC)
  46. return;
  47. #ifdef MAYBE
  48. p = f->bufadr;
  49. if (f->ptr < p)
  50. return;
  51. if (f->buflen <= 0)
  52. return;
  53. p += f->buflen;
  54. if (f->ptr >= p)
  55. return;
  56. #endif
  57. _xcls(f);
  58. if (close(f->ufd) != 0)
  59. _trp(ECLOSE);
  60. f->flags = 0;
  61. }