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 /******************************************************************************
24 BOOLEAN PROCEDURE OPEN */
25
26 char
__rpopen(p,t)27 __rpopen (p, t)
28 __bs6FILE *p;
29 __txtvp t;
30 {
31 if (!((__bs1FILE *) p)->open)
32 {
33 /* Trenger ikke ha med p->filename.start fordi start=1 siden */
34 /* filename er overf|rt by value */
35
36 if (((__bs1FILE *) p)->create != __ANYCREATE)
37 {
38 ((__bs1FILE *) p)->file
39 = fopen (((__bs1FILE *) p)->filename.obj->string, "r");
40 if (((__bs1FILE *) p)->file != __NULL)
41 (void) fclose (((__bs1FILE *) p)->file);
42 if ((((__bs1FILE *) p)->file == __NULL
43 && ((__bs1FILE *) p)->create == __NOCREATE) ||
44 (((__bs1FILE *) p)->file != __NULL
45 && ((__bs1FILE *) p)->create == __CREATE))
46 return (__FALSE);
47 }
48 if (((__bs1FILE *) p)->append == __APPEND)
49 ((__bs1FILE *) p)->file
50 = fopen (((__bs1FILE *) p)->filename.obj->string, "a");
51 else
52 ((__bs1FILE *) p)->file
53 = fopen (((__bs1FILE *) p)->filename.obj->string, "w");
54
55 if (((__bs1FILE *) p)->file == __NULL)
56 return (__FALSE);
57 ((__bs2FILE *) p)->IMAGE.obj = t->obj;
58 ((__bs2FILE *) p)->IMAGE.length = t->length;
59 ((__bs2FILE *) p)->IMAGE.pos = 1;
60 ((__bs2FILE *) p)->IMAGE.start = t->start;
61 p->page = 1;
62 p->line = 1;
63 ((__bs1FILE *) p)->open = __TRUE;
64 return (__TRUE);
65 }
66 else
67 return (__FALSE);
68 }
69