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