1 /* $Id: $ */
2
3 /* Copyright (C) 1997 Sverre Hvammen Johansen,
4 * Department of Informatics, University of Oslo.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "file.h"
21 #include "simfile.h"
22
23 /* RUNTIME rutiner for klassen outfile skrevet i c. */
24
25 FILE *fopen ();
26
27 /******************************************************************************
28 BOOLEAN PROCEDURE OPEN */
29
30 char
__roopen(p,t)31 __roopen (p, t)
32 __bs1FILE *p;
33 __txtvp t;
34 {
35 if (!p->open)
36 {
37 /* Trenger ikke ha med p->filename.start fordi start=1 siden */
38 /* filename er overf|rt by value */
39
40 if (((__bs1FILE *) p)->create != __ANYCREATE)
41 {
42 ((__bs1FILE *) p)->file = fopen (p->filename.obj->string, "r");
43 if (((__bs1FILE *) p)->file != __NULL)
44 (void) fclose (((__bs1FILE *) p)->file);
45 if ((((__bs1FILE *) p)->file == __NULL
46 && ((__bs1FILE *) p)->create == __NOCREATE) ||
47 (((__bs1FILE *) p)->file != __NULL
48 && ((__bs1FILE *) p)->create == __CREATE))
49 return (__FALSE);
50 }
51 if (((__bs1FILE *) p)->append == __APPEND)
52 ((__bs1FILE *) p)->file = fopen (p->filename.obj->string, "a");
53 else
54 ((__bs1FILE *) p)->file = fopen (p->filename.obj->string, "w");
55
56 if (((__bs1FILE *) p)->file == __NULL)
57 return (__FALSE);
58
59 ((__bs2FILE *) p)->IMAGE.obj = t->obj;
60 ((__bs2FILE *) p)->IMAGE.length = t->length;
61 ((__bs2FILE *) p)->IMAGE.pos = 1;
62 ((__bs2FILE *) p)->IMAGE.start = t->start;
63 return ((long) (p->open = __TRUE));
64 }
65 else
66 return (__FALSE);
67 }
68