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                                                  PROCEDURE INIMAGE           */
25 
26 __dhp
__riinimage(p)27 __riinimage (p)
28      __bs2FILE *p;
29 {
30   long i,
31     j;
32   FILE *f;
33   char *s;
34   long c;
35   if (!((__bs1FILE *) p)->open)
36     __rerror ("Inimage: File not open");
37   if (((__bs4FILE *) p)->endfile)
38     __rerror ("Inimage: End of file");
39   if (p->IMAGE.obj == __NULL)
40     __rerror ("Inimage: IMAGE equals notext");
41   if (((__bs2FILE *) p)->IMAGE.obj->h.konstant)
42     __rerror ("Inimage: Constant text object");
43 
44   f = ((__bs1FILE *) p)->file;
45   s = p->IMAGE.obj->string;
46   i = p->IMAGE.start - 1;
47   j = i + p->IMAGE.length;
48 
49   while ((c = getc (f)) != __EOF)
50     {
51       if (c == '\n')
52 	goto utinimage;
53       if (i == j)
54 	goto inimageerror;
55       s[i++] = c;
56     }
57 
58   if (i == p->IMAGE.start - 1)
59     {
60       ((__bs4FILE *) p)->endfile = __TRUE;
61       s[i++] = 25;
62       for (; i < j; i++)
63 	s[i] = ' ';
64       p->IMAGE.pos = 1;
65       return ((__dhp) p);
66     }
67   else
68     (void) ungetc ((int) c, f);
69 
70 utinimage:
71   while (i != j)
72     s[i++] = ' ';
73   p->IMAGE.pos = 1;
74   return ((__dhp) p);
75 inimageerror:
76   __rerror ("Inimage: IMAGE to short");
77 }
78