1 #include "f2c.h"
2 #include "fio.h"
3 #ifdef KR_headers
f_clos(a)4 integer f_clos(a) cllist *a;
5 #else
6 #undef abs
7 #undef min
8 #undef max
9 #include "stdlib.h"
10 #ifdef NON_UNIX_STDIO
11 #ifndef unlink
12 #define unlink remove
13 #endif
14 #else
15 #ifdef MSDOS
16 #include "io.h"
17 #else
18 #ifdef __cplusplus
19 extern "C" int unlink(const char*);
20 #else
21 extern int unlink(const char*);
22 #endif
23 #endif
24 #endif
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 integer f_clos(cllist *a)
31 #endif
32 {	unit *b;
33 
34 	if(a->cunit >= MXUNIT) return(0);
35 	b= &f__units[a->cunit];
36 	if(b->ufd==NULL)
37 		goto done;
38 	if (b->uscrtch == 1)
39 		goto Delete;
40 	if (!a->csta)
41 		goto Keep;
42 	switch(*a->csta) {
43 		default:
44 	 	Keep:
45 		case 'k':
46 		case 'K':
47 			if(b->uwrt == 1)
48 				t_runc((alist *)a);
49 			if(b->ufnm) {
50 				fclose(b->ufd);
51 				free(b->ufnm);
52 				}
53 			break;
54 		case 'd':
55 		case 'D':
56 		Delete:
57 			fclose(b->ufd);
58 			if(b->ufnm) {
59 				unlink(b->ufnm); /*SYSDEP*/
60 				free(b->ufnm);
61 				}
62 		}
63 	b->ufd=NULL;
64  done:
65 	b->uend=0;
66 	b->ufnm=NULL;
67 	return(0);
68 	}
69  void
70 #ifdef KR_headers
71 f_exit()
72 #else
73 f_exit(void)
74 #endif
75 {	int i;
76 	static cllist xx;
77 	if (!xx.cerr) {
78 		xx.cerr=1;
79 		xx.csta=NULL;
80 		for(i=0;i<MXUNIT;i++)
81 		{
82 			xx.cunit=i;
83 			(void) f_clos(&xx);
84 		}
85 	}
86 }
87  int
88 #ifdef KR_headers
89 flush_()
90 #else
91 flush_(void)
92 #endif
93 {	int i;
94 	for(i=0;i<MXUNIT;i++)
95 		if(f__units[i].ufd != NULL && f__units[i].uwrt)
96 			fflush(f__units[i].ufd);
97 return 0;
98 }
99 #ifdef __cplusplus
100 }
101 #endif
102