Include <config.h> instead of "config.h".
[bpt/emacs.git] / src / vmsmap.c
CommitLineData
d427b66a
JB
1/* VMS mapping of data and alloc arena for GNU Emacs.
2 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20/* Written by Mukesh Prasad. */
21
22#ifdef VMS
23
18160b98 24#include <config.h>
d427b66a
JB
25#include "lisp.h"
26#include <rab.h>
27#include <fab.h>
28#include <rmsdef.h>
29#include <secdef.h>
30
31/* RMS block size */
32#define BLOCKSIZE 512
33
34/* Maximum number of bytes to be written in one RMS write.
35 * Must be a multiple of BLOCKSIZE.
36 */
37#define MAXWRITE (BLOCKSIZE * 30)
38
39/* This funniness is to ensure that sdata occurs alphabetically BEFORE the
40 $DATA psect and that edata occurs after ALL Emacs psects. This is
41 because the VMS linker sorts all psects in a cluster alphabetically
42 during the linking, unless you use the cluster_psect command. Emacs
43 uses the cluster command to group all Emacs psects into one cluster;
44 this keeps the dumped data separate from any loaded libraries. */
45
46globaldef {"$D$ATA"} char sdata[512]; /* Start of saved data area */
47globaldef {"__DATA"} char edata[512]; /* End of saved data area */
48
49/* Structure to write into first block of map file.
50 */
51
52struct map_data
53{
54 char * sdata; /* Start of data area */
55 char * edata; /* End of data area */
56 int datablk; /* Block in file to map data area from/to */
57};
58
59static void fill_fab (), fill_rab ();
60static int write_data ();
61
62extern char *start_of_data ();
63extern int vms_out_initial; /* Defined in malloc.c */
64
65/* Maps in the data and alloc area from the map file.
66 */
67
68int
69mapin_data (name)
70 char * name;
71{
72 struct FAB fab;
73 struct RAB rab;
74 int status, size;
75 int inadr[2];
76 struct map_data map_data;
77
78 /* Open map file. */
79 fab = cc$rms_fab;
80 fab.fab$b_fac = FAB$M_BIO|FAB$M_GET;
81 fab.fab$l_fna = name;
82 fab.fab$b_fns = strlen (name);
83 status = sys$open (&fab);
84 if (status != RMS$_NORMAL)
85 {
86 printf ("Map file not available, running bare Emacs....\n");
87 return 0; /* Map file not available */
88 }
89 /* Connect the RAB block */
90 rab = cc$rms_rab;
91 rab.rab$l_fab = &fab;
92 rab.rab$b_rac = RAB$C_SEQ;
93 rab.rab$l_rop = RAB$M_BIO;
94 status = sys$connect (&rab);
95 if (status != RMS$_NORMAL)
96 lib$stop (status);
97 /* Read the header data */
98 rab.rab$l_ubf = &map_data;
99 rab.rab$w_usz = sizeof (map_data);
100 rab.rab$l_bkt = 0;
101 status = sys$read (&rab);
102 if (status != RMS$_NORMAL)
103 lib$stop (status);
104 status = sys$close (&fab);
105 if (status != RMS$_NORMAL)
106 lib$stop (status);
107 if (map_data.sdata != start_of_data ())
108 {
109 printf ("Start of data area has moved: cannot map in data.\n");
110 return 0;
111 }
112 if (map_data.edata != edata)
113 {
114 printf ("End of data area has moved: cannot map in data.\n");
115 return 0;
116 }
117 fab.fab$l_fop |= FAB$M_UFO;
118 status = sys$open (&fab);
119 if (status != RMS$_NORMAL)
120 lib$stop (status);
121 /* Map data area. */
122 inadr[0] = map_data.sdata;
123 inadr[1] = map_data.edata;
124 status = sys$crmpsc (inadr, 0, 0, SEC$M_CRF | SEC$M_WRT, 0, 0, 0,
125 fab.fab$l_stv, 0, map_data.datablk, 0, 0);
126 if (! (status & 1))
127 lib$stop (status);
128}
129
130/* Writes the data and alloc area to the map file.
131 */
132mapout_data (into)
133 char * into;
134{
135 struct FAB fab;
136 struct RAB rab;
137 int status;
138 struct map_data map_data;
139 int datasize, msize;
140
141 if (vms_out_initial)
142 {
143 error ("Out of initial allocation. Must rebuild emacs with more memory (VMS_ALLOCATION_SIZE).");
144 return 0;
145 }
146 map_data.sdata = start_of_data ();
147 map_data.edata = edata;
148 datasize = map_data.edata - map_data.sdata + 1;
149 map_data.datablk = 2 + (sizeof (map_data) + BLOCKSIZE - 1) / BLOCKSIZE;
150 /* Create map file. */
151 fab = cc$rms_fab;
152 fab.fab$b_fac = FAB$M_BIO|FAB$M_PUT;
153 fab.fab$l_fna = into;
154 fab.fab$b_fns = strlen (into);
155 fab.fab$l_fop = FAB$M_CBT;
156 fab.fab$b_org = FAB$C_SEQ;
157 fab.fab$b_rat = 0;
158 fab.fab$b_rfm = FAB$C_VAR;
159 fab.fab$l_alq = 1 + map_data.datablk +
160 ((datasize + BLOCKSIZE - 1) / BLOCKSIZE);
161 status = sys$create (&fab);
162 if (status != RMS$_NORMAL)
163 {
164 error ("Could not create map file");
165 return 0;
166 }
167 /* Connect the RAB block */
168 rab = cc$rms_rab;
169 rab.rab$l_fab = &fab;
170 rab.rab$b_rac = RAB$C_SEQ;
171 rab.rab$l_rop = RAB$M_BIO;
172 status = sys$connect (&rab);
173 if (status != RMS$_NORMAL)
174 {
175 error ("RMS connect to map file failed");
176 return 0;
177 }
178 /* Write the header */
179 rab.rab$l_rbf = &map_data;
180 rab.rab$w_rsz = sizeof (map_data);
181 status = sys$write (&rab);
182 if (status != RMS$_NORMAL)
183 {
184 error ("RMS write (header) to map file failed");
185 return 0;
186 }
187 if (! write_data (&rab, map_data.datablk, map_data.sdata, datasize))
188 return 0;
189 status = sys$close (&fab);
190 if (status != RMS$_NORMAL)
191 {
192 error ("RMS close on map file failed");
193 return 0;
194 }
195 return 1;
196}
197
198static int
199write_data (rab, firstblock, data, length)
200 struct RAB * rab;
201 char * data;
202{
203 int status;
204
205 rab->rab$l_bkt = firstblock;
206 while (length > 0)
207 {
208 rab->rab$l_rbf = data;
209 rab->rab$w_rsz = length > MAXWRITE ? MAXWRITE : length;
210 status = sys$write (rab, 0, 0);
211 if (status != RMS$_NORMAL)
212 {
213 error ("RMS write to map file failed");
214 return 0;
215 }
216 data = &data[MAXWRITE];
217 length -= MAXWRITE;
218 rab->rab$l_bkt = 0;
219 }
220 return 1;
221} /* write_data */
222
223#endif /* VMS */
224