Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/editors/ecce/files/patch-ecce.c
16462 views
1
--- ecce.c.orig 2016-09-11 21:27:36 UTC
2
+++ ecce.c
3
@@ -12,6 +12,9 @@
4
#include <ctype.h>
5
#include <signal.h>
6
#include <errno.h>
7
+#include <sys/types.h>
8
+#include <unistd.h>
9
+#include <sys/stat.h>
10
11
#ifdef WANT_UTF8
12
/* EXPERIMENTAL SUPPORT FOR UTF-8 */
13
@@ -47,7 +50,7 @@ typedef char ecce_char;
14
15
/**************************************************************************/
16
17
-#define NOTE_FILE "/tmp/Note0"
18
+#define NOTE_FILE "/tmp/ecceNote0%06d"
19
/* Name of temp file for multiple contexts - system dependant. */
20
/* Something like "/tmp/Note%c" would be a small improvement, */
21
/* but using a proper function like tmpnam() would be best. */
22
@@ -61,7 +64,7 @@ typedef char ecce_char;
23
/* moving this to sourceforge. */
24
25
26
-#define CONTEXT_OFFSET (strlen(NOTE_FILE)-1)
27
+#define CONTEXT_OFFSET 13
28
/* Index of variable part in name above (i.e. of '0') */
29
30
static char *ProgName = NULL;
31
@@ -400,8 +403,7 @@ static int symtype[256] = {
32
};
33
34
static int sym_type(ecce_char c) {
35
- if ((0 <= c) && (c <= 255)) return symtype[(unsigned int)c];
36
- return err;
37
+ return symtype[(unsigned int)c];
38
}
39
40
static cindex a;
41
@@ -412,7 +414,7 @@ static FILE *tty_out;
42
static FILE *log_out;
43
44
static ecce_int *com;
45
-static int *link;
46
+static int *xlink;
47
static ecce_char *text;
48
static long *num;
49
static long *lim;
50
@@ -442,7 +444,8 @@ int main(int argc, char **argv) {
51
char *locale = setlocale(LC_ALL, "");
52
#endif
53
54
- backup_save = tmpnam(backup_save_buf);
55
+ sprintf(backup_save_buf, "/tmp/eccesave%06d", getpid());
56
+ backup_save = backup_save_buf;
57
58
ProgName = argv[0];
59
s = strrchr(ProgName, '/');
60
@@ -596,7 +599,7 @@ void init_globals (void) {
61
note_file = malloc (Max_parameter+1);
62
63
com = (ecce_int *) malloc ((Max_command_units+1)*sizeof(ecce_int));
64
- link = (int *) malloc ((Max_command_units+1)*sizeof(int));
65
+ xlink = (int *) malloc ((Max_command_units+1)*sizeof(int));
66
text = (ecce_char *) malloc ((Max_command_units+1) * sizeof(ecce_char));
67
68
num = (long *) malloc ((Max_command_units+1)*sizeof(long));
69
@@ -605,7 +608,7 @@ void init_globals (void) {
70
com_prompt = malloc (Max_prompt_length+1);
71
72
if (a == NULL || note_file == NULL || com == NULL ||
73
- link == NULL || text == NULL || num == NULL || lim == NULL ||
74
+ xlink == NULL || text == NULL || num == NULL || lim == NULL ||
75
com_prompt == NULL) {
76
fprintf (stderr, "Unable to claim buffer space\n");
77
free_buffers();
78
@@ -628,7 +631,7 @@ void init_globals (void) {
79
pending_sym = '\n';
80
blank_line = TRUE;
81
82
- (void)strcpy (note_file, NOTE_FILE);
83
+ sprintf (note_file, NOTE_FILE, getpid());
84
noted = NULL;
85
changes = 0;
86
in_second = FALSE;
87
@@ -640,7 +643,7 @@ void free_buffers (void) { /* only neede
88
if (lim) free (lim); lim = NULL;
89
if (num) free (num); num = NULL;
90
if (text) free (text); text = NULL;
91
- if (link) free (link); link = NULL;
92
+ if (xlink) free (xlink); xlink = NULL;
93
if (com) free (com); com = NULL;
94
if (com_prompt) free (com_prompt); com_prompt = NULL;
95
if (note_file) free (note_file); note_file = NULL;
96
@@ -820,7 +823,9 @@ void percent (ecce_int Command_sym) {
97
the edit and writing out the file. This is a quick hack: I
98
should change this and the copy in percent('S') so that both
99
share the same subroutine ensure_main_edit() *****************/
100
+ int oldmask = umask (0077);
101
FILE *sec_out = fopen (note_file, "wb");
102
+ umask(oldmask);
103
(void)strcpy (com_prompt, ">");
104
if (sec_out == NULL) {
105
(void) fail_with ("Cannot save context", ' ');
106
@@ -851,8 +856,10 @@ void percent (ecce_int Command_sym) {
107
*/
108
} /* End of copied bit */
109
if (Command_sym == 'c') {
110
+ int oldmask = umask(0077);
111
parameter[inoutlog] = backup_save;
112
main_out = fopen (parameter[inoutlog], "wb");
113
+ umask(oldmask);
114
if (main_out == NULL) {
115
fprintf(stderr,
116
"Sorry - I can't save your edit (even %s failed)\n", backup_save);
117
@@ -865,10 +872,12 @@ void percent (ecce_int Command_sym) {
118
else
119
main_out = fopen (parameter[inoutlog], "wb");
120
if (main_out == NULL) {
121
+ int oldmask = umask(0077);
122
fprintf (stderr,
123
"Can't create \"%s\" - attempting to save to %s instead\n",
124
parameter[inoutlog], backup_save);
125
main_out = fopen (backup_save, "w");
126
+ umask(oldmask);
127
if (main_out == NULL) {
128
fprintf(stderr, "Cannot save file at all. Giving up. Sorry!\n");
129
exit(1);
130
@@ -947,7 +956,9 @@ void percent (ecce_int Command_sym) {
131
pending_sym = '\n';
132
note_file[CONTEXT_OFFSET] = note_sec;
133
if (in_second) {
134
+ int oldmask = umask(0077);
135
FILE *sec_out = fopen (note_file, "wb");
136
+ umask(oldmask);
137
(void)strcpy (com_prompt, ">");
138
if (sec_out == NULL) {
139
(void) fail_with ("Cannot save context", ' ');
140
@@ -1028,14 +1039,14 @@ void unchain(void) {
141
do {
142
pointer = last_unit;
143
if (pointer < 0) return;
144
- last_unit = link[pointer];
145
- link[pointer] = this_unit;
146
+ last_unit = xlink[pointer];
147
+ xlink[pointer] = this_unit;
148
} while (com[pointer] != '(');
149
}
150
151
void stack(void) {
152
com[this_unit] = command;
153
- link[this_unit] = pointer;
154
+ xlink[this_unit] = pointer;
155
num[this_unit] = repeat_count;
156
lim[this_unit] = limit;
157
this_unit++;
158
@@ -1369,7 +1380,9 @@ void execute_command(void) {
159
}
160
note_file[CONTEXT_OFFSET] = lim[this_unit]+'0';
161
{
162
+ int oldmask = umask(0077);
163
FILE *note_out = fopen (note_file, "wb");
164
+ umask(oldmask);
165
cindex p = noted;
166
167
if (note_out == NULL) {
168
@@ -1628,7 +1641,7 @@ bool execute_unit (void) {
169
170
command = com[this_unit];
171
culprit = command;
172
- pointer = link[this_unit];
173
+ pointer = xlink[this_unit];
174
175
repeat_count = num[this_unit];
176
for (;;) { /* On repeats of this_unit */
177
@@ -1669,7 +1682,7 @@ bool execute_unit (void) {
178
switch (command) {
179
180
case '(':
181
- this_unit = link[this_unit];
182
+ this_unit = xlink[this_unit];
183
break; /* Skip over (...) as if it were single command. */
184
185
case ',':
186
187