home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Tex / Tex29 / StTeXsrc.zoo / src / io.c < prev    next >
C/C++ Source or Header  |  1988-09-27  |  3KB  |  148 lines

  1.  
  2. /*
  3.  * @(#)io.c 2.5 EPA
  4.  *
  5.  * Copyright 1987,1988 Pat J Monardo
  6.  *
  7.  * Redistribution of this file is permitted through
  8.  * the specifications in the file COPYING.
  9.  *
  10.  * 
  11.  */
  12.  
  13. #include "tex.h"
  14. #include "tokenstack.h"
  15. #include "file.h"
  16.  
  17. int     last;
  18. ascii   buffer[BUF_SIZE];
  19. int     first;
  20. int     max_buf_stack;
  21.  
  22. FILE *
  23. a_open_in ()
  24. {
  25.     if (test_access(READ_ACCESS, INPUT_FILE_PATH))
  26.         return (fopen(name_of_file, "r"));
  27.     return NULL;
  28. }
  29.  
  30. FILE *
  31. a_open_out ()
  32. {
  33.     if (test_access(WRITE_ACCESS, NO_FILE_PATH))
  34.         return (fopen(name_of_file, "w"));
  35.     return NULL;
  36. }
  37.  
  38. FILE *
  39. b_open_in ()
  40. {
  41.     if (test_access(READ_ACCESS, FONT_FILE_PATH))
  42.         return (fopen(name_of_file, "r"));
  43.     return NULL;
  44. }
  45.  
  46. FILE *
  47. b_open_out ()
  48. {
  49.     if (test_access(WRITE_ACCESS, NO_FILE_PATH))
  50.         return (fopen(name_of_file, "w"));
  51.     return NULL;
  52. }
  53.  
  54. FILE *
  55. w_open_in ()
  56. {
  57.     if (test_access(READ_ACCESS, FORMAT_FILE_PATH))
  58.         return (fopen(name_of_file, "r"));
  59.     return NULL;
  60. }
  61.  
  62. FILE *
  63. w_open_out ()
  64. {
  65.     if (test_access(WRITE_ACCESS, NO_FILE_PATH))
  66.         return (fopen(name_of_file, "w"));
  67.     return NULL;
  68. }
  69.  
  70. bool 
  71. input_ln (f, bypass_eoln)
  72.     alpha_file  f;
  73.     bool        bypass_eoln;
  74. {
  75.     int         c;
  76.  
  77.     last = first;
  78.     loop {
  79.         c = getc(f);
  80.         if (c == EOLN)
  81.             break;
  82.         if (c == EOF) {
  83.             if (last == first)
  84.                 return FALSE;
  85.             else
  86.                 break;
  87.         }
  88.         if (last > max_buf_stack) {
  89.             max_buf_stack = last + 1;
  90.             if (max_buf_stack == BUF_SIZE - 1)
  91.                 overflow("buffer size", BUF_SIZE);
  92.         }
  93. #ifdef atarist
  94.         if(c != '\r')
  95.     {
  96.         buffer[last] = c;
  97.         incr(last);
  98.     }
  99. #else
  100.         buffer[last] = c;
  101.         incr(last);
  102. #endif
  103.     }
  104.     loop {
  105.         if (last == first)
  106.             break;  
  107.         else if (buffer[last - 1] != ' ')
  108.             break;
  109.         else decr(last);
  110.     }
  111.     return TRUE;
  112. }
  113.  
  114. term_input ()
  115. {
  116.     int     k;
  117.  
  118.     update_terminal();
  119.     if (!input_ln(term_in, FALSE)) 
  120.         fatal_error("! End of file on the terminal");
  121.     term_offset = 0;
  122.     decr(selector);
  123.     if (last != first)
  124.         for (k = first; k < last; incr(k))
  125.             print_char(buffer[k]);
  126.     print_ln();
  127.     incr(selector);
  128. }
  129.  
  130. bool
  131. init_terminal ()
  132. {
  133.     loop {
  134.         fputs("**", stdout);
  135.         update_terminal();
  136.         if (!input_ln(term_in, FALSE)) {
  137.             puts("\n! End of file on the terminal...why?");
  138.             return FALSE;
  139.         }
  140.         loc = first;
  141.         while (loc < last && buffer[loc] == ' ')
  142.             incr(loc);
  143.         if (loc < last)
  144.             return TRUE;
  145.         puts("Please type the name of your input file.");
  146.     }
  147. }
  148.