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 @@ -494,29 +494,88 @@ static int doOpen(WindowInfo *window, co
14 - fileLen = statbuf.st_size;
16 - /* Allocate space for the whole contents of the file (unfortunately) */
17 - fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
18 - if (fileString == NULL) {
20 - window->filenameSet = FALSE; /* Temp. prevent check for changes. */
21 - DialogF(DF_ERR, window->shell, 1, "Error while opening File",
22 - "File is too large to edit", "OK");
23 - window->filenameSet = TRUE;
27 - /* Read the file into fileString and terminate with a null */
28 - readLen = fread(fileString, sizeof(char), fileLen, fp);
31 - window->filenameSet = FALSE; /* Temp. prevent check for changes. */
32 - DialogF(DF_ERR, window->shell, 1, "Error while opening File",
33 - "Error reading %s:\n%s", "OK", name, errorString());
34 - window->filenameSet = TRUE;
37 + if (S_ISFIFO(statbuf.st_mode)) {
38 + int pipeBufLen, fileSize;
40 + window->fileMissing = TRUE;
41 + SET_PERM_LOCKED(window->lockReasons, TRUE);
43 + pipeBufLen = statbuf.st_blksize;
44 + if (pipeBufLen <= 0)
47 + fileSize = pipeBufLen << 2;
48 + fileString = malloc(fileSize + 1);
49 + if (fileString == NULL)
51 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
52 + "File is too large to include", "OK");
60 + readLen = fread(&fileString[fileLen], sizeof(char), pipeBufLen, fp);
64 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
65 + "Error reading %s:\n%s", "OK", name, errorString());
72 + if (fileSize - fileLen < pipeBufLen)
74 + char *tmpFileString;
76 + fileSize += pipeBufLen << 2;
77 + tmpFileString = realloc(fileString, fileSize + 1);
78 + if (tmpFileString == NULL)
80 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
81 + "File is too large to include", "OK");
86 + fileString = tmpFileString;
94 + fileLen = statbuf.st_size;
96 + /* Allocate space for the whole contents of the file (unfortunately) */
97 + fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
98 + if (fileString == NULL) {
100 + window->filenameSet = FALSE; /* Temp. prevent check for changes. */
101 + DialogF(DF_ERR, window->shell, 1, "Error while opening File",
102 + "File is too large to edit", "OK");
103 + window->filenameSet = TRUE;
107 + /* Read the file into fileString and terminate with a null */
108 + readLen = fread(fileString, sizeof(char), fileLen, fp);
111 + window->filenameSet = FALSE; /* Temp. prevent check for changes. */
112 + DialogF(DF_ERR, window->shell, 1, "Error while opening File",
113 + "Error reading %s:\n%s", "OK", name, errorString());
114 + window->filenameSet = TRUE;
119 fileString[readLen] = 0;
121 @@ -634,27 +693,83 @@ int IncludeFile(WindowInfo *window, cons
125 - fileLen = statbuf.st_size;
127 - /* allocate space for the whole contents of the file */
128 - fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
129 - if (fileString == NULL)
131 - DialogF(DF_ERR, window->shell, 1, "Error opening File",
132 - "File is too large to include", "OK");
137 - /* read the file into fileString and terminate with a null */
138 - readLen = fread(fileString, sizeof(char), fileLen, fp);
141 - DialogF(DF_ERR, window->shell, 1, "Error opening File",
142 - "Error reading %s:\n%s", "OK", name, errorString());
146 + if (S_ISFIFO(statbuf.st_mode)) {
147 + int pipeBufLen, fileSize;
149 + pipeBufLen = statbuf.st_blksize;
150 + if (pipeBufLen <= 0)
153 + fileSize = pipeBufLen << 2;
154 + fileString = malloc(fileSize + 1);
155 + if (fileString == NULL)
157 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
158 + "File is too large to include", "OK");
166 + readLen = fread(&fileString[fileLen], sizeof(char), pipeBufLen, fp);
170 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
171 + "Error reading %s:\n%s", "OK", name, errorString());
177 + fileLen += readLen;
178 + if (fileSize - fileLen < pipeBufLen)
180 + char *tmpFileString;
182 + fileSize += pipeBufLen << 2;
183 + tmpFileString = realloc(fileString, fileSize + 1);
184 + if (tmpFileString == NULL)
186 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
187 + "File is too large to include", "OK");
192 + fileString = tmpFileString;
200 + fileLen = statbuf.st_size;
202 + /* allocate space for the whole contents of the file */
203 + fileString = (char *)malloc(fileLen+1); /* +1 = space for null */
204 + if (fileString == NULL)
206 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
207 + "File is too large to include", "OK");
212 + /* read the file into fileString and terminate with a null */
213 + readLen = fread(fileString, sizeof(char), fileLen, fp);
216 + DialogF(DF_ERR, window->shell, 1, "Error opening File",
217 + "Error reading %s:\n%s", "OK", name, errorString());
223 fileString[readLen] = 0;
225 diff --quilt old/util/fileUtils.c new/util/fileUtils.c
226 --- old/util/fileUtils.c
227 +++ new/util/fileUtils.c
228 @@ -679,14 +679,70 @@ char *ReadAnyTextFile(const char *fileNa
232 - fileLen = statbuf.st_size;
233 - fileString = XtMalloc(fileLen+1); /* +1 = space for null */
234 - readLen = fread(fileString, sizeof(char), fileLen, fp);
236 - XtFree(fileString);
237 + if (S_ISDIR(statbuf.st_mode)) {
242 + if (S_ISFIFO(statbuf.st_mode)) {
243 + int pipeBufLen, fileBufSize;
246 + pipeBufLen = statbuf.st_blksize;
247 + if (pipeBufLen <= 0)
250 + fileBufSize = pipeBufLen << 2;
251 + fileBuf = malloc(fileBufSize);
252 + if (fileBuf == NULL) {
259 + readLen = fread(&fileBuf[fileLen], sizeof(char), pipeBufLen, fp);
267 + fileLen += readLen;
268 + if (fileBufSize - fileLen < pipeBufLen) {
271 + fileBufSize += pipeBufLen << 2;
272 + tmpFileBuf = realloc(fileBuf, fileBufSize);
273 + if (tmpFileBuf == NULL) {
278 + fileBuf = tmpFileBuf;
281 + } while (!feof(fp));
284 + fileString = XtMalloc(readLen+1); /* +1 = space for null */
285 + memcpy(fileString, fileBuf, readLen * sizeof(char));
288 + fileLen = statbuf.st_size;
289 + fileString = XtMalloc(fileLen+1); /* +1 = space for null */
290 + if (fileString == NULL) {
294 + readLen = fread(fileString, sizeof(char), fileLen, fp);
296 + XtFree(fileString);
302 fileString[readLen] = 0;
304 @@ -701,3 +757,4 @@ char *ReadAnyTextFile(const char *fileNa