add language_mode_hook(prev-mode)
[nedit-bw.git] / enhanced-alloc-DataValue-on-stack.patch
blob1264edcf987a95b8322aae0120a737c31b8f247b
1 ---
3 source/file.c | 8 ++++----
4 source/menu.c | 17 +++++++----------
5 source/selection.c | 17 +++++++----------
6 3 files changed, 18 insertions(+), 24 deletions(-)
8 diff --quilt old/source/file.c new/source/file.c
9 --- old/source/file.c
10 +++ new/source/file.c
11 @@ -932,11 +932,11 @@ static int doSave(WindowInfo *window)
12 char *fileString = NULL;
13 char fullname[MAXPATHLEN];
14 struct stat statbuf;
15 FILE *fp;
16 int fileLen, result;
17 - DataValue* fileNameArg = (DataValue*) XtMalloc(sizeof(DataValue));
18 + DataValue fileNameArg;
20 /* Get the full name of the file */
21 strcpy(fullname, window->path);
22 strcat(fullname, window->filename);
24 @@ -1070,13 +1070,13 @@ static int doSave(WindowInfo *window)
25 window->fileMissing = TRUE;
26 window->device = 0;
27 window->inode = 0;
30 - fileNameArg->tag = STRING_TAG;
31 - AllocNStringNCpy(&fileNameArg->val.str, fullname, MAXPATHLEN);
32 - MacroApplyHook(window, "post_save_hook", 1, fileNameArg, NULL);
33 + fileNameArg.tag = STRING_TAG;
34 + AllocNStringNCpy(&fileNameArg.val.str, fullname, MAXPATHLEN);
35 + MacroApplyHook(window, "post_save_hook", 1, &fileNameArg, NULL);
37 return TRUE;
41 diff --quilt old/source/menu.c new/source/menu.c
42 --- old/source/menu.c
43 +++ new/source/menu.c
44 @@ -2882,40 +2882,37 @@ static void openDialogAP(Widget w, XEven
46 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
48 WindowInfo *window = WidgetToWindow(w);
49 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
50 - DataValue* fileNameArg = (DataValue*) XtMalloc(sizeof(DataValue));
51 - DataValue* resultDV = (DataValue*) XtMalloc(sizeof(DataValue));
52 + DataValue fileNameArg;
53 + DataValue resultDV = {NO_TAG, {0}};
54 Boolean hook_successful = False;
55 char *fileNameToOpen;
57 if (*nArgs == 0) {
58 fprintf(stderr, "nedit: open action requires file argument\n");
59 return;
62 - resultDV->tag = NO_TAG;
63 - fileNameArg->tag = STRING_TAG;
64 - AllocNStringNCpy(&fileNameArg->val.str, args[0], MAXPATHLEN);
65 + fileNameArg.tag = STRING_TAG;
66 + AllocNStringNCpy(&fileNameArg.val.str, args[0], MAXPATHLEN);
67 hook_successful = MacroApplyHook(window, "file_name_hook",
68 - 1, fileNameArg, resultDV);
69 - XtFree((char*) fileNameArg);
70 + 1, &fileNameArg, &resultDV);
72 - if (hook_successful && resultDV->tag == STRING_TAG) {
73 - fileNameToOpen = resultDV->val.str.rep;
74 + if (hook_successful && resultDV.tag == STRING_TAG) {
75 + fileNameToOpen = resultDV.val.str.rep;
76 } else {
77 fileNameToOpen = args[0];
80 if (0 != ParseFilename(fileNameToOpen, filename, pathname)
81 || strlen(filename) + strlen(pathname) > MAXPATHLEN - 1) {
82 fprintf(stderr, "nedit: invalid file name for open action: %s\n",
83 fileNameToOpen);
84 return;
86 - XtFree((char*) resultDV);
88 EditExistingFile(window, filename, pathname, 0, NULL, False,
89 NULL, GetPrefOpenInTab(), False);
90 CheckCloseDim();
92 diff --quilt old/source/selection.c new/source/selection.c
93 --- old/source/selection.c
94 +++ new/source/selection.c
95 @@ -357,24 +357,22 @@ static void fileCB(Widget widget, Window
96 glob_t globbuf;
97 int i;
99 glob(nameText, GLOB_NOCHECK, NULL, &globbuf);
100 for (i = 0; i < (int) globbuf.gl_pathc; i++) {
101 - DataValue* fileNameArg = (DataValue*) XtMalloc(sizeof(DataValue));
102 - DataValue* resultDV = (DataValue*) XtMalloc(sizeof(DataValue));
103 + DataValue fileNameArg;
104 + DataValue resultDV = {NO_TAG, {0}};
105 Boolean hook_successful = False;
106 char *fileNameToOpen;
108 - resultDV->tag = NO_TAG;
109 - fileNameArg->tag = STRING_TAG;
110 - AllocNStringNCpy(&fileNameArg->val.str, globbuf.gl_pathv[i], MAXPATHLEN);
111 + fileNameArg.tag = STRING_TAG;
112 + AllocNStringNCpy(&fileNameArg.val.str, globbuf.gl_pathv[i], MAXPATHLEN);
113 hook_successful = MacroApplyHook(window, "file_name_hook",
114 - 1, fileNameArg, resultDV);
115 - XtFree((char*) fileNameArg);
116 + 1, &fileNameArg, &resultDV);
118 - if (hook_successful && resultDV->tag == STRING_TAG) {
119 - fileNameToOpen = resultDV->val.str.rep;
120 + if (hook_successful && resultDV.tag == STRING_TAG) {
121 + fileNameToOpen = resultDV.val.str.rep;
122 } else {
123 fileNameToOpen = globbuf.gl_pathv[i];
126 if (ParseFilename(fileNameToOpen, filename, pathname) != 0) {
127 @@ -382,11 +380,10 @@ static void fileCB(Widget widget, Window
128 } else {
129 EditExistingFile(GetPrefOpenInTab() ? window : NULL, filename,
130 pathname, 0, NULL, False, NULL, GetPrefOpenInTab(),
131 False);
133 - XtFree((char*) resultDV);
135 globfree(&globbuf);
137 #endif
138 CheckCloseDim();