3 source/file.c | 199 +++++++++++++++++++++++++++++++++++++++++++------------
4 util/fileUtils.c | 67 +++++++++++++++++-
5 2 files changed, 219 insertions(+), 47 deletions(-)
7 diff --quilt old/source/file.c new/source/file.c
10 @@ -478,33 +478,92 @@ static int doOpen(WindowInfo *window, co
11 "Can't open block device %s", "OK", name);
12 window->filenameSet = TRUE;
16 - fileLen = statbuf.st_size;
18 - /* Allocate space for the whole contents of the file (unfortunately) */
19 - fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
20 - if (fileString == NULL) {
22 - window->filenameSet = FALSE; /* Temp. prevent check for changes. */
23 - DialogF(DF_ERR, window->shell, 1, "Error while opening File",
24 - "File is too large to edit", "OK");
25 - window->filenameSet = TRUE;
29 - /* Read the file into fileString and terminate with a null */
30 - readLen = fread(fileString, sizeof(char), fileLen, fp);
33 - window->filenameSet = FALSE; /* Temp. prevent check for changes. */
34 - DialogF(DF_ERR, window->shell, 1, "Error while opening File",
35 - "Error reading %s:\n%s", "OK", name, errorString());
36 - window->filenameSet = TRUE;
39 + if (S_ISFIFO(statbuf.st_mode)) {
40 + int pipeBufLen, fileSize;
42 + window->fileMissing = TRUE;
43 + SET_PERM_LOCKED(window->lockReasons, TRUE);
45 + pipeBufLen = statbuf.st_blksize;
46 + if (pipeBufLen <= 0)
49 + fileSize = pipeBufLen << 2;
50 + fileString = malloc(fileSize + 1);
51 + if (fileString == NULL)
53 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
54 + "File is too large to include", "OK");
62 + readLen = fread(&fileString[fileLen], sizeof(char), pipeBufLen, fp);
66 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
67 + "Error reading %s:\n%s", "OK", name, errorString());
74 + if (fileSize - fileLen < pipeBufLen)
76 + char *tmpFileString;
78 + fileSize += pipeBufLen << 2;
79 + tmpFileString = realloc(fileString, fileSize + 1);
80 + if (tmpFileString == NULL)
82 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
83 + "File is too large to include", "OK");
88 + fileString = tmpFileString;
96 + fileLen = statbuf.st_size;
98 + /* Allocate space for the whole contents of the file (unfortunately) */
99 + fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
100 + if (fileString == NULL) {
102 + window->filenameSet = FALSE; /* Temp. prevent check for changes. */
103 + DialogF(DF_ERR, window->shell, 1, "Error while opening File",
104 + "File is too large to edit", "OK");
105 + window->filenameSet = TRUE;
109 + /* Read the file into fileString and terminate with a null */
110 + readLen = fread(fileString, sizeof(char), fileLen, fp);
113 + window->filenameSet = FALSE; /* Temp. prevent check for changes. */
114 + DialogF(DF_ERR, window->shell, 1, "Error while opening File",
115 + "Error reading %s:\n%s", "OK", name, errorString());
116 + window->filenameSet = TRUE;
121 fileString[readLen] = 0;
124 if (fclose(fp) != 0) {
125 @@ -622,31 +681,87 @@ int IncludeFile(WindowInfo *window, cons
126 DialogF(DF_ERR, window->shell, 1, "Error opening File",
127 "Can't open directory %s", "OK", name);
131 - fileLen = statbuf.st_size;
133 - /* allocate space for the whole contents of the file */
134 - fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
135 - if (fileString == NULL)
137 - DialogF(DF_ERR, window->shell, 1, "Error opening File",
138 - "File is too large to include", "OK");
143 - /* read the file into fileString and terminate with a null */
144 - readLen = fread(fileString, sizeof(char), fileLen, fp);
147 - DialogF(DF_ERR, window->shell, 1, "Error opening File",
148 - "Error reading %s:\n%s", "OK", name, errorString());
152 + if (S_ISFIFO(statbuf.st_mode)) {
153 + int pipeBufLen, fileSize;
155 + pipeBufLen = statbuf.st_blksize;
156 + if (pipeBufLen <= 0)
159 + fileSize = pipeBufLen << 2;
160 + fileString = malloc(fileSize + 1);
161 + if (fileString == NULL)
163 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
164 + "File is too large to include", "OK");
172 + readLen = fread(&fileString[fileLen], sizeof(char), pipeBufLen, fp);
176 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
177 + "Error reading %s:\n%s", "OK", name, errorString());
183 + fileLen += readLen;
184 + if (fileSize - fileLen < pipeBufLen)
186 + char *tmpFileString;
188 + fileSize += pipeBufLen << 2;
189 + tmpFileString = realloc(fileString, fileSize + 1);
190 + if (tmpFileString == NULL)
192 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
193 + "File is too large to include", "OK");
198 + fileString = tmpFileString;
206 + fileLen = statbuf.st_size;
208 + /* allocate space for the whole contents of the file */
209 + fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
210 + if (fileString == NULL)
212 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
213 + "File is too large to include", "OK");
218 + /* read the file into fileString and terminate with a null */
219 + readLen = fread(fileString, sizeof(char), fileLen, fp);
222 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
223 + "Error reading %s:\n%s", "OK", name, errorString());
229 fileString[readLen] = 0;
231 /* Detect and convert DOS and Macintosh format files */
232 switch (FormatOfFile(fileString)) {
233 diff --quilt old/util/fileUtils.c new/util/fileUtils.c
234 --- old/util/fileUtils.c
235 +++ new/util/fileUtils.c
236 @@ -677,18 +677,74 @@ char *ReadAnyTextFile(const char *fileNa
238 if (fstat(fileno(fp), &statbuf) != 0) {
242 - fileLen = statbuf.st_size;
243 - fileString = XtMalloc(fileLen+1); /* +1 = space for null */
244 - readLen = fread(fileString, sizeof(char), fileLen, fp);
246 - XtFree(fileString);
247 + if (S_ISDIR(statbuf.st_mode)) {
252 + if (S_ISFIFO(statbuf.st_mode)) {
253 + int pipeBufLen, fileBufSize;
256 + pipeBufLen = statbuf.st_blksize;
257 + if (pipeBufLen <= 0)
260 + fileBufSize = pipeBufLen << 2;
261 + fileBuf = malloc(fileBufSize);
262 + if (fileBuf == NULL) {
269 + readLen = fread(&fileBuf[fileLen], sizeof(char), pipeBufLen, fp);
277 + fileLen += readLen;
278 + if (fileBufSize - fileLen < pipeBufLen) {
281 + fileBufSize += pipeBufLen << 2;
282 + tmpFileBuf = realloc(fileBuf, fileBufSize);
283 + if (tmpFileBuf == NULL) {
288 + fileBuf = tmpFileBuf;
291 + } while (!feof(fp));
294 + fileString = XtMalloc(readLen+1); /* +1 = space for null */
295 + memcpy(fileString, fileBuf, readLen * sizeof(char));
298 + fileLen = statbuf.st_size;
299 + fileString = XtMalloc(fileLen+1); /* +1 = space for null */
300 + if (fileString == NULL) {
304 + readLen = fread(fileString, sizeof(char), fileLen, fp);
306 + XtFree(fileString);
312 fileString[readLen] = 0;
314 /* Convert linebreaks? */
315 format = FormatOfFile(fileString);
316 @@ -699,5 +755,6 @@ char *ReadAnyTextFile(const char *fileNa
317 ConvertFromMacFileString(fileString, readLen);