summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Cesar Pereira de Andrade <pcpa@mandriva.com.br>2008-03-11 21:46:58 -0300
committerPaulo Cesar Pereira de Andrade <pcpa@mandriva.com.br>2008-07-02 19:04:52 -0300
commita2c47d3487aaf4667926195ba3f5b05b94626daf (patch)
treeb41f7989704e17c4687e4e7b3ba43a61864a38ba
parenta1949714b99a502a57b3dd7a99e619c10211d9fc (diff)
Fix several generic bugs including:
o Several memory read/write errors. o Implement smarter XeditPrintf that will show how many times a text has been printed. o Check all arguments to XeditPrintf to ensure the '%' character cannot be sent to it. o Some minor reindentation to code that still had the original 2 spaces indentation.
-rw-r--r--commands.c255
-rw-r--r--hook.c5
-rw-r--r--util.c128
-rw-r--r--xedit.c297
-rw-r--r--xedit.h1
5 files changed, 373 insertions, 313 deletions
diff --git a/commands.c b/commands.c
index e7f23b1..bb6d98f 100644
--- a/commands.c
+++ b/commands.c
@@ -67,6 +67,11 @@ static void AddDoubleClickCallback(Widget, Bool);
static Bool ReallyDoLoad(char*, char*);
static char *makeBackupName(String, String, unsigned);
+/*
+ * External
+ */
+extern void _XawTextShowPosition(TextWidget);
+
extern Widget scratch, texts[3], labels[3];
static Boolean double_click = FALSE;
@@ -209,7 +214,16 @@ int rename (from, to)
void
SaveFile(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
- DoSave(w, NULL, NULL);
+ if (line_edit) {
+ /* Don't try to save buffer with regex string.
+ * Call CancelFindFile() to leave line_edit mode.
+ */
+ XeditPrintf("Save: Leaving line edit mode -- nothing saved.\n");
+ CancelFindFile(w, event, params, num_params);
+ Feep();
+ }
+ else
+ DoSave(w, NULL, NULL);
}
/*ARGSUSED*/
@@ -218,7 +232,6 @@ DoSave(Widget w, XtPointer client_data, XtPointer call_data)
{
String name = GetString(filenamewindow);
String filename = ResolveName(name);
- char buf[BUFSIZ];
FileAccess file_access;
xedit_flist_item *item;
Boolean exists;
@@ -238,10 +251,8 @@ DoSave(Widget w, XtPointer client_data, XtPointer call_data)
struct stat st;
if (stat(filename, &st) == 0 && !S_ISREG(st.st_mode)) {
- XmuSnprintf(buf, sizeof(buf),
- "Save: file %s is not a regular file -- nothing saved.\n",
- name);
- XeditPrintf(buf);
+ XeditPrintf("Save: file %s is not a regular file "
+ "-- nothing saved.\n", name);
Feep();
return;
}
@@ -250,11 +261,9 @@ DoSave(Widget w, XtPointer client_data, XtPointer call_data)
item = FindTextSource(NULL, filename);
if (item != NULL && item->source != source) {
if (!double_click || (dc_state && dc_state != DC_LOADED)) {
- XmuSnprintf(buf, sizeof(buf),
- "Save: file %s is already loaded, "
+ XeditPrintf("Save: file %s is already loaded, "
"Save again to unload it -- nothing saved.\n",
name);
- XeditPrintf(buf);
Feep();
double_click = TRUE;
dc_state = DC_LOADED;
@@ -284,11 +293,9 @@ DoSave(Widget w, XtPointer client_data, XtPointer call_data)
if (!item || strcmp(item->filename, filename)) {
if (file_access == WRITE_OK && exists) {
if (!double_click || (dc_state && dc_state != DC_CLOBBER)) {
- XmuSnprintf(buf, sizeof(buf),
- "Save: file %s already exists, "
+ XeditPrintf("Save: file %s already exists, "
"Save again to overwrite it -- nothing saved.\n",
name);
- XeditPrintf(buf);
Feep();
double_click = TRUE;
dc_state = DC_CLOBBER;
@@ -301,95 +308,87 @@ DoSave(Widget w, XtPointer client_data, XtPointer call_data)
if (!item)
item = FindTextSource(source, NULL);
}
-
- if (app_resources.enableBackups && exists) {
- char backup_file[BUFSIZ];
-
- if (makeBackupName(backup_file, filename, sizeof(backup_file)) == NULL
- || rename(filename, backup_file) != 0) {
- XmuSnprintf(buf, sizeof(buf),"error backing up file: %s\n",
- filename);
- XeditPrintf(buf);
+
+ if (app_resources.enableBackups && exists) {
+ char backup_file[BUFSIZ];
+
+ if (makeBackupName(backup_file, filename, sizeof(backup_file)) == NULL
+ || rename(filename, backup_file) != 0) {
+ XeditPrintf("Error backing up file: %s\n", filename);
+ }
}
- }
-
- switch( file_access = MaybeCreateFile(filename)) {
- case NO_READ:
- case READ_OK:
- XmuSnprintf(buf, sizeof(buf),
- "File %s could not be opened for writing.\n", name);
- Feep();
- break;
- case WRITE_OK:
- if ( XawAsciiSaveAsFile(source, filename) ) {
- int i;
- Arg args[1];
- char label_buf[BUFSIZ];
-
- /* Keep file protection mode */
- if (item && item->mode)
- chmod(filename, item->mode);
-
- XmuSnprintf(label_buf, sizeof(label_buf),
- "%s Read - Write", name);
- XtSetArg(args[0], XtNlabel, label_buf);
- for (i = 0; i < 3; i++)
- if (XawTextGetSource(texts[i]) == source)
- XtSetValues(labels[i], args, 1);
-
- XmuSnprintf(buf, sizeof(buf), "Saved file: %s\n", name);
-
- if (item && item->source != scratch) {
- XtSetArg(args[0], XtNlabel, filename);
- XtSetValues(item->sme, args, 1);
-
- XtSetArg(args[0], XtNeditType, XawtextEdit);
- XtSetValues(item->source, args, 1);
-
- XtFree(item->name);
- XtFree(item->filename);
- item->name = XtNewString(name);
- item->filename = XtNewString(filename);
- item->flags = EXISTS_BIT;
- }
- else {
- item = flist.itens[0];
- XtRemoveCallback(scratch, XtNcallback, SourceChanged,
- (XtPointer)item);
- item->source = scratch =
- XtVaCreateWidget("textSource", international ?
- multiSrcObjectClass :
- asciiSrcObjectClass,
- topwindow,
- XtNtype, XawAsciiFile,
- XtNeditType, XawtextEdit,
- NULL, NULL);
- ResetSourceChanged(item);
- XtAddCallback(scratch, XtNcallback, SourceChanged,
- (XtPointer)item);
-
- item = AddTextSource(source, name, filename, EXISTS_BIT,
- file_access);
- XtAddCallback(item->source, XtNcallback, SourceChanged,
- (XtPointer)item);
- }
- item->flags |= EXISTS_BIT;
- ResetSourceChanged(item);
- }
- else {
- XmuSnprintf(buf, sizeof(buf), "Error saving file: %s\n", name);
- Feep();
- }
- break;
- default:
- XmuSnprintf(buf, sizeof(buf), "%s %s",
- "Internal function MaybeCreateFile()",
- "returned unexpected value.\n");
- Feep();
- break;
- }
- XeditPrintf(buf);
+ switch (file_access = MaybeCreateFile(filename)) {
+ case NO_READ:
+ case READ_OK:
+ XeditPrintf("File %s could not be opened for writing.\n", name);
+ Feep();
+ break;
+ case WRITE_OK:
+ if (XawAsciiSaveAsFile(source, filename)) {
+ int i;
+ Arg args[1];
+ char label_buf[BUFSIZ];
+
+ /* Keep file protection mode */
+ if (item && item->mode)
+ chmod(filename, item->mode);
+
+ XmuSnprintf(label_buf, sizeof(label_buf),
+ "%s Read - Write", name);
+ XtSetArg(args[0], XtNlabel, label_buf);
+ for (i = 0; i < 3; i++)
+ if (XawTextGetSource(texts[i]) == source)
+ XtSetValues(labels[i], args, 1);
+
+ XeditPrintf("Saved file: %s\n", name);
+
+ if (item && item->source != scratch) {
+ XtSetArg(args[0], XtNlabel, filename);
+ XtSetValues(item->sme, args, 1);
+
+ XtSetArg(args[0], XtNeditType, XawtextEdit);
+ XtSetValues(item->source, args, 1);
+
+ XtFree(item->name);
+ XtFree(item->filename);
+ item->name = XtNewString(name);
+ item->filename = XtNewString(filename);
+ item->flags = EXISTS_BIT;
+ }
+ else {
+ item = flist.itens[0];
+ XtRemoveCallback(scratch, XtNcallback, SourceChanged,
+ (XtPointer)item);
+ item->source = scratch =
+ XtVaCreateWidget("textSource", international ?
+ multiSrcObjectClass :
+ asciiSrcObjectClass,
+ topwindow,
+ XtNtype, XawAsciiFile,
+ XtNeditType, XawtextEdit,
+ NULL, NULL);
+ ResetSourceChanged(item);
+ XtAddCallback(scratch, XtNcallback, SourceChanged,
+ (XtPointer)item);
+
+ item = AddTextSource(source, name, filename, EXISTS_BIT,
+ file_access);
+ XtAddCallback(item->source, XtNcallback, SourceChanged,
+ (XtPointer)item);
+ }
+ item->flags |= EXISTS_BIT;
+ ResetSourceChanged(item);
+ }
+ else {
+ XeditPrintf("Error saving file: %s\n", name);
+ Feep();
+ }
+ break;
+ default:
+ Feep();
+ break;
+ }
}
/*ARGSUSED*/
@@ -402,12 +401,17 @@ DoLoad(Widget w, XtPointer client_data, XtPointer call_data)
}
}
+Bool
+LoadFileInTextwindow(char *name, char *resolved_name)
+{
+ return (ReallyDoLoad(name, resolved_name));
+}
+
static Bool
ReallyDoLoad(char *name, char *filename)
{
Arg args[5];
Cardinal num_args = 0;
- char buf[BUFSIZ];
xedit_flist_item *item;
Widget source = XawTextGetSource(textwindow);
@@ -456,37 +460,28 @@ ReallyDoLoad(char *name, char *filename)
switch( file_access = CheckFilePermissions(filename, &exists) ) {
case NO_READ:
if (exists)
- XmuSnprintf(buf, sizeof(buf), "File %s, %s", name,
- "exists, and could not be opened for reading.\n");
+ XeditPrintf("File %s, %s", name,
+ "exists, and could not be opened for reading.\n");
else
- XmuSnprintf(buf, sizeof(buf), "File %s %s %s", name,
+ XeditPrintf("File %s %s %s", name,
"does not exist, and",
- "the directory could not be opened for writing.\n");
+ "the directory could not be opened for writing.\n");
- XeditPrintf(buf);
Feep();
return (False);
case READ_OK:
XtSetArg(args[num_args], XtNeditType, XawtextRead); num_args++;
- XmuSnprintf(buf, sizeof(buf), "File %s opened READ ONLY.\n",
- name);
+ XeditPrintf("File %s opened READ ONLY.\n", name);
break;
case WRITE_OK:
XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++;
- XmuSnprintf(buf, sizeof(buf), "File %s opened read - write.\n",
- name);
+ XeditPrintf("File %s opened read - write.\n", name);
break;
default:
- XmuSnprintf(buf, sizeof(buf), "%s %s",
- "Internal function MaybeCreateFile()",
- "returned unexpected value.\n");
- XeditPrintf(buf);
Feep();
return (False);
}
- XeditPrintf(buf);
-
if (exists) {
flags = EXISTS_BIT;
XtSetArg(args[num_args], XtNstring, filename); num_args++;
@@ -511,7 +506,7 @@ ReallyDoLoad(char *name, char *filename)
if (exists && file_access == WRITE_OK) {
struct stat st;
- if (stat(filename, &st) == 0)
+ if (stat(item->filename, &st) == 0)
item->mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
}
SwitchTextSource(item);
@@ -729,14 +724,23 @@ KillFile(Widget w, XEvent *event, String *params, Cardinal *num_params)
void
FindFile(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
- char *string = GetString(filenamewindow);
- char *slash = NULL;
+ char *string;
+ char *slash;
XawTextBlock block;
XawTextPosition end = XawTextSourceScan(XawTextGetSource(filenamewindow),
0, XawstAll, XawsdRight, 1, True);
- if (string)
- slash = strrchr(string, '/');
+ if (!line_edit) {
+ string = GetString(filenamewindow);
+ if (string)
+ slash = strrchr(string, '/');
+ }
+ else {
+ string = "";
+ slash = NULL;
+ line_edit = False;
+ }
+
block.firstPos = 0;
block.format = FMT8BIT;
block.ptr = string;
@@ -746,7 +750,6 @@ FindFile(Widget w, XEvent *event, String *params, Cardinal *num_params)
XawTextReplace(filenamewindow, 0, end, &block);
XawTextSetInsertionPoint(filenamewindow, end);
XtSetKeyboardFocus(topwindow, filenamewindow);
- line_edit = False;
}
/*ARGSUSED*/
@@ -778,6 +781,9 @@ CancelFindFile(Widget w, XEvent *event, String *params, Cardinal *num_params)
XtSetArg(args[0], XtNstring, NULL);
XtSetValues(filenamewindow, args, 1);
+ /* XXX This probably should be done by the TextWidget, i.e. notice
+ * if the cursor became inivisible due to an horizontal scroll */
+ _XawTextShowPosition((TextWidget)filenamewindow);
if (XtIsManaged(XtParent(dirwindow)))
SwitchDirWindow(False);
@@ -893,7 +899,6 @@ FileCompletion(Widget w, XEvent *event, String *params, Cardinal *num_params)
strncpy(fname, slash2 + 1, sizeof(fname) - 1);
fname[sizeof(fname) - 1] = '\0';
save = XtRealloc(save, slen - diff + hlen + 2);
- (void)memmove(&save[hlen], slash2, slen - diff + 1);
(void)memmove(save, home, hlen);
save[hlen] = '/';
strcpy(&save[hlen + 1], fname);
@@ -937,11 +942,11 @@ FileCompletion(Widget w, XEvent *event, String *params, Cardinal *num_params)
mlen = 0;
match[0] = '\0';
- (void)readdir(dir); /* "." */
- (void)readdir(dir); /* ".." */
while ((ent = readdir(dir)) != NULL) {
unsigned d_namlen = strlen(ent->d_name);
+ if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
+ continue;
if (d_namlen >= len && strncmp(ent->d_name, file_name, len) == 0) {
char *tmp = &(ent->d_name[len]), *mat = match;
struct stat st;
@@ -996,7 +1001,7 @@ FileCompletion(Widget w, XEvent *event, String *params, Cardinal *num_params)
closedir(dir);
changed = mlen != 0;
- if (n_matches) {
+ if (first || n_matches) {
Bool free_matches = True, add_slash = n_matches == 1 && isdir && !slash;
if (mlen && has_dot && match[mlen - 1] == '.')
diff --git a/hook.c b/hook.c
index 913ccc3..87f0da6 100644
--- a/hook.c
+++ b/hook.c
@@ -1098,7 +1098,7 @@ print:
reerror(ecode, &einfo.regex,
buffer + length, sizeof(buffer) - length - 2);
strcat(buffer, "\n");
- XeditPrintf(buffer);
+ XeditPrintf("%s", buffer);
refree(&einfo.regex);
einfo.state = SubstituteDisabled;
Feep();
@@ -1159,8 +1159,7 @@ fail:
ptr = "Unknown error";
break;
}
- XmuSnprintf(buffer, sizeof(buffer), "Error: %s.\n", ptr);
- XeditPrintf(buffer);
+ XeditPrintf("Error: %s.\n", ptr);
}
if (redisplay)
XawTextEnableRedisplay(w);
diff --git a/util.c b/util.c
index 1d7c5f3..1657697 100644
--- a/util.c
+++ b/util.c
@@ -28,7 +28,10 @@
#include <stdio.h>
#include <stdarg.h>
+
+#include <libgen.h> /* POSIX basename() */
#include <stdlib.h> /* for realpath() */
+#include <errno.h> /* for ENOENT */
#include "xedit.h"
#include <X11/Xfuncs.h>
@@ -72,41 +75,63 @@ extern XawTextWrapMode wrapmodes[3];
void
XeditPrintf(const char *format, ...)
{
- char *str;
- size_t size;
- va_list va,
- va2;
- XawTextBlock text;
- XawTextPosition pos;
-
- va_start(va, format);
+ static struct {
+ XawTextPosition last;
+ int size;
+ int length;
+ int repeat;
+ char *buffer;
+ } info;
+
+ size_t size;
+ va_list va;
+ XawTextBlock text;
+ XawTextPosition left, right;
+ char buffer[BUFSIZ];
+ char *string, rbuffer[32];
- va_copy(va2, va);
- size = vsnprintf(NULL, 0, format, va2);
- va_end(va2);
-
- str = (char *)malloc(size + 1);
- if (str == NULL)
- return;
-
- vsnprintf(str, size + 1, format, va);
- str[size] = 0;
-
+ va_start(va, format);
+ size = vsnprintf(buffer, sizeof(buffer), format, va);
va_end(va);
-
- pos = XawTextSourceScan(XawTextGetSource(messwidget),
- 0, XawstAll, XawsdRight, 1, True);
- text.length = strlen(str);
- text.ptr = str;
- text.firstPos = 0;
- text.format = FMT8BIT;
+ /* Should never happen... */
+ if (size >= sizeof(buffer)) {
+ strcpy(buffer + sizeof(buffer) - 5, "...\n");
+ size = sizeof(buffer) - 1;
+ }
+ else if (size) {
+ left = right = XawTextSourceScan(XawTextGetSource(messwidget),
+ 0, XawstAll, XawsdRight, 1, True);
+
+ if (left == info.last &&
+ info.buffer &&
+ strcmp(buffer, info.buffer) == 0) {
+ string = rbuffer;
+ if (info.repeat == 1)
+ left -= info.buffer[strlen(info.buffer) - 1] == '\n';
+ else
+ left -= info.length;
+ size = info.length = XmuSnprintf(rbuffer, sizeof(rbuffer),
+ " [%d times]\n", ++info.repeat);
+ }
+ else {
+ string = buffer;
+ if (size >= info.size)
+ info.buffer = XtMalloc(size + 1);
+ strcpy(info.buffer, buffer);
+ info.repeat = 1;
+ }
+
+ text.length = size;
+ text.ptr = string;
+ text.firstPos = 0;
+ text.format = FMT8BIT;
- XawTextReplace(messwidget, pos, pos, &text);
+ XawTextReplace(messwidget, left, right, &text);
- XawTextSetInsertionPoint(messwidget, pos + text.length);
-
- free(str);
+ info.last = left + text.length;
+ XawTextSetInsertionPoint(messwidget, info.last);
+ }
}
Widget
@@ -243,7 +268,7 @@ AddTextSource(Widget source, char *name, char *filename, int flags,
else
++wid_name;
item->sme = XtVaCreateManagedWidget(wid_name, smeBSBObjectClass,
- flist.popup, XtNlabel, filename,
+ flist.popup, XtNlabel, item->filename,
NULL, NULL);
XtAddCallback(item->sme, XtNcallback,
SwitchSourceCallback, (XtPointer)item);
@@ -454,18 +479,53 @@ SwitchTextSource(xedit_flist_item *item)
XtSetArg(args[num_args], XtNstring, NULL); ++num_args;
}
XtSetValues(filenamewindow, args, num_args);
+ /* XXX This probably should be done by the TextWidget, i.e. notice
+ * if the cursor became inivisible due to an horizontal scroll */
+ _XawTextShowPosition((TextWidget)filenamewindow);
}
-/* XXX sizeof(name) must match argument size for realpath */
-static char name[BUFSIZ];
char *
ResolveName(char *filename)
{
+#ifndef __UNIXOS2__
+ static char *name;
+ char *result, *tmp = name;
+#endif
+
if (filename == NULL)
filename = GetString(filenamewindow);
#ifndef __UNIXOS2__
- return (realpath(filename, name));
+ /* Ensure not passing the same pointer again to realpath */
+ name = XtMalloc(BUFSIZ);
+ XtFree(tmp);
+ result = realpath(filename, name);
+
+ if (result == NULL && errno == ENOENT) {
+ int length;
+ char *dir, *file;
+
+ length = strlen(filename);
+ tmp = dir = XtMalloc(length + 1);
+ strcpy(dir, filename);
+
+ file = basename(filename);
+ dir = dirname(tmp);
+
+ /* Creating a new file? */
+ if (dir && file && strcmp(dir, file) &&
+ access(dir, F_OK) == 0 &&
+ (result = realpath(dir, name)) == name) {
+ int length = strlen(result);
+
+ XmuSnprintf(result + length, BUFSIZ - length, "%s%s",
+ dir[length - 1] == '/' ? "" : "/", file);
+ }
+
+ XtFree(tmp);
+ }
+
+ return (result);
#else
return filename;
#endif
diff --git a/xedit.c b/xedit.c
index 384b16f..deac576 100644
--- a/xedit.c
+++ b/xedit.c
@@ -123,161 +123,156 @@ String fallback_resources[] = {
int
main(int argc, char *argv[])
{
- XtAppContext appcon;
- unsigned num_loaded = 0;
+ Boolean exists;
+ char *filename;
+ FileAccess file_access;
+ Widget source;
+ XtAppContext appcon;
+ unsigned int i, num_loaded;
+
+ num_loaded = 0;
#ifdef INCLUDE_XPRINT_SUPPORT
- XtSetLanguageProc(NULL, NULL, NULL);
+ XtSetLanguageProc(NULL, NULL, NULL);
#endif
- topwindow = XtAppInitialize(&appcon, "Xedit", NULL, 0, &argc, argv,
+ topwindow = XtAppInitialize(&appcon, "Xedit", NULL, 0, &argc, argv,
#ifdef INCLUDE_XPRINT_SUPPORT
- fallback_resources,
+ fallback_resources,
#else
- NULL,
+ NULL,
#endif
- NULL, 0);
-
- XtAppAddActions(appcon, actions, XtNumber(actions));
- XtOverrideTranslations
- (topwindow, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
-
- XtGetApplicationResources(topwindow, (XtPointer) &app_resources, resources,
- XtNumber(resources), NULL, 0);
-
- CurDpy = XtDisplay(topwindow);
- XawSimpleMenuAddGlobalActions(appcon);
- XtRegisterGrabAction(PopupMenu, True,
- ButtonPressMask | ButtonReleaseMask,
- GrabModeAsync, GrabModeAsync);
-
- makeButtonsAndBoxes(topwindow);
-
- StartHints();
- StartFormatPosition();
- (void)StartHooks(appcon);
- if (position_format_mask == 0) {
- int i;
-
- for (i = 0; i < 3; i++)
- XtRemoveCallback(texts[i], XtNpositionCallback, PositionChanged, NULL);
- }
- XtRealizeWidget(topwindow);
+ NULL, 0);
+
+ XtAppAddActions(appcon, actions, XtNumber(actions));
+ XtOverrideTranslations(topwindow,
+ XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()"));
+
+ XtGetApplicationResources(topwindow, (XtPointer) &app_resources, resources,
+ XtNumber(resources), NULL, 0);
+
+ CurDpy = XtDisplay(topwindow);
+ XawSimpleMenuAddGlobalActions(appcon);
+ XtRegisterGrabAction(PopupMenu, True,
+ ButtonPressMask | ButtonReleaseMask,
+ GrabModeAsync, GrabModeAsync);
+
+ makeButtonsAndBoxes(topwindow);
+
+ StartHints();
+ StartFormatPosition();
+ (void)StartHooks(appcon);
+ if (position_format_mask == 0) {
+ for (i = 0; i < 3; i++)
+ XtRemoveCallback(texts[i], XtNpositionCallback,
+ PositionChanged, NULL);
+ }
+ XtRealizeWidget(topwindow);
#ifndef __UNIXOS2__
- XeditLispInitialize();
+ XeditLispInitialize();
#endif
- options_popup = XtCreatePopupShell("optionsMenu", simpleMenuWidgetClass,
- topwindow, NULL, 0);
- XtRealizeWidget(options_popup);
- XtAddCallback(XtCreateManagedWidget("ispell", smeBSBObjectClass,
- options_popup, NULL, 0),
- XtNcallback, IspellCallback, NULL);
- CreateEditPopup();
-
- wm_delete_window = XInternAtom(XtDisplay(topwindow), "WM_DELETE_WINDOW",
- False);
- (void) XSetWMProtocols (XtDisplay(topwindow), XtWindow(topwindow),
+ options_popup = XtCreatePopupShell("optionsMenu", simpleMenuWidgetClass,
+ topwindow, NULL, 0);
+ XtRealizeWidget(options_popup);
+ XtAddCallback(XtCreateManagedWidget("ispell", smeBSBObjectClass,
+ options_popup, NULL, 0),
+ XtNcallback, IspellCallback, NULL);
+ CreateEditPopup();
+
+ wm_delete_window = XInternAtom(XtDisplay(topwindow), "WM_DELETE_WINDOW",
+ False);
+ (void)XSetWMProtocols(XtDisplay(topwindow), XtWindow(topwindow),
&wm_delete_window, 1);
- /* This first call is just to save the default font and colors */
- UpdateTextProperties(0);
-
- if (argc > 1) {
- Boolean exists;
- xedit_flist_item *item;
- FileAccess file_access;
- char *filename;
- Widget source;
- Arg args[2];
- unsigned i, num_args;
- char buf[BUFSIZ];
-
- for (i = 1; i < argc; i++) {
- struct stat st;
-
- num_args = 0;
- filename = ResolveName(argv[i]);
- if (filename == NULL || FindTextSource(NULL, filename) != NULL)
- continue;
- if (stat(filename, &st) == 0 && !S_ISREG(st.st_mode)) {
- if (S_ISDIR(st.st_mode)) {
- if (!num_loaded) {
- char path[BUFSIZ + 1];
-
- strncpy(path, filename, sizeof(path) - 2);
- path[sizeof(path) - 2] = '\0';
- if (*path) {
- if (path[strlen(path) - 1] != '/')
- strcat(path, "/");
- }
- else
- strcpy(path, "./");
- XtSetArg(args[0], XtNlabel, "");
- XtSetValues(dirlabel, args, 1);
- SwitchDirWindow(True);
- DirWindowCB(dirwindow, path, NULL);
- ++num_loaded;
- }
- continue;
- }
- }
-
- switch (file_access = CheckFilePermissions(filename, &exists)) {
- case NO_READ:
- if (exists)
- XmuSnprintf(buf, sizeof(buf), "File %s, %s %s", argv[i],
- "exists, and could not be opened for",
- "reading.\n");
- else
- XmuSnprintf(buf, sizeof(buf), "File %s %s %s %s", argv[i],
- "does not exist, and",
- "the directory could not be opened for",
- "writing.\n");
- break;
- case READ_OK:
- XtSetArg(args[num_args], XtNeditType, XawtextRead); num_args++;
- XmuSnprintf(buf, sizeof(buf), "File %s opened READ ONLY.\n",
- argv[i]);
- break;
- case WRITE_OK:
- XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++;
- XmuSnprintf(buf, sizeof(buf), "File %s opened read - write.\n",
- argv[i]);
- break;
- }
- if (file_access != NO_READ) {
- int flags;
-
- if (exists) {
- flags = EXISTS_BIT;
- XtSetArg(args[num_args], XtNstring, filename);num_args++;
- }
- else {
- flags = 0;
- XtSetArg(args[num_args], XtNstring, NULL); num_args++;
- }
- source = XtVaCreateWidget("textSource", international ?
- multiSrcObjectClass :
- asciiSrcObjectClass, topwindow,
- XtNtype, XawAsciiFile,
- XtNeditType, XawtextEdit,
- NULL, NULL);
- XtSetValues(source, args, num_args);
- item = AddTextSource(source, argv[i], filename,
- flags, file_access);
- XtAddCallback(item->source, XtNcallback, SourceChanged,
- (XtPointer)item);
- if (exists && file_access == WRITE_OK)
- item->mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
- if (!num_loaded)
- SwitchTextSource(item);
- ++num_loaded;
- ResetSourceChanged(item);
- }
- XeditPrintf(buf);
- }
- }
+ /* This first call is just to save the default font and colors */
+ UpdateTextProperties(0);
+
+ if (argc > 1) {
+ xedit_flist_item *item;
+ Arg args[2];
+ unsigned int num_args;
+
+ for (i = 1; i < argc; i++) {
+ struct stat st;
+
+ filename = ResolveName(argv[i]);
+ if (filename == NULL || FindTextSource(NULL, filename) != NULL)
+ continue;
+
+ num_args = 0;
+ if (stat(filename, &st) == 0 && !S_ISREG(st.st_mode)) {
+ if (S_ISDIR(st.st_mode)) {
+ if (!num_loaded) {
+ char path[BUFSIZ + 1];
+
+ strncpy(path, filename, sizeof(path) - 2);
+ path[sizeof(path) - 2] = '\0';
+ if (*path) {
+ if (path[strlen(path) - 1] != '/')
+ strcat(path, "/");
+ }
+ else
+ strcpy(path, "./");
+ XtSetArg(args[0], XtNlabel, "");
+ XtSetValues(dirlabel, args, 1);
+ SwitchDirWindow(True);
+ DirWindowCB(dirwindow, path, NULL);
+ ++num_loaded;
+ }
+ continue;
+ }
+ }
+
+ switch (file_access = CheckFilePermissions(filename, &exists)) {
+ case NO_READ:
+ if (exists)
+ XeditPrintf("File %s exists, and could not be opened for "
+ "reading.\n", argv[i]);
+ else
+ XeditPrintf("File %s does not exist, and the directory "
+ "could not be opened for writing.\n", argv[i]);
+ break;
+ case READ_OK:
+ XtSetArg(args[num_args], XtNeditType, XawtextRead); num_args++;
+ XeditPrintf("File %s opened READ ONLY.\n", argv[i]);
+ break;
+ case WRITE_OK:
+ XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++;
+ XeditPrintf("File %s opened read - write.\n", argv[i]);
+ break;
+ }
+ if (file_access != NO_READ) {
+ int flags;
+
+ if (exists) {
+ flags = EXISTS_BIT;
+ XtSetArg(args[num_args], XtNstring, filename);num_args++;
+ }
+ else {
+ flags = 0;
+ XtSetArg(args[num_args], XtNstring, NULL); num_args++;
+ }
+ source = XtVaCreateWidget("textSource", international ?
+ multiSrcObjectClass
+ : asciiSrcObjectClass, topwindow,
+ XtNtype, XawAsciiFile,
+ XtNeditType, XawtextEdit,
+ NULL, NULL);
+ XtSetValues(source, args, num_args);
+ item = AddTextSource(source, argv[i], filename,
+ flags, file_access);
+ XtAddCallback(item->source, XtNcallback, SourceChanged,
+ (XtPointer)item);
+ if (exists && file_access == WRITE_OK)
+ item->mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
+ if (!num_loaded)
+ SwitchTextSource(item);
+ ++num_loaded;
+ ResetSourceChanged(item);
+ }
+ }
+ }
if (!flist.pixmap && strlen(app_resources.changed_pixmap_name)) {
XrmValue from, to;
@@ -290,15 +285,15 @@ main(int argc, char *argv[])
XtConvertAndStore(flist.popup, XtRString, &from, XtRBitmap, &to);
}
- if (num_loaded == 0) {
- XtSetKeyboardFocus(topwindow, filenamewindow);
- XtVaSetValues(textwindow, XtNwrap, XawtextWrapLine, NULL);
- }
- else
- XtSetKeyboardFocus(topwindow, textwindow);
+ if (num_loaded == 0) {
+ XtSetKeyboardFocus(topwindow, filenamewindow);
+ XtVaSetValues(textwindow, XtNwrap, XawtextWrapLine, NULL);
+ }
+ else
+ XtSetKeyboardFocus(topwindow, textwindow);
- XtAppMainLoop(appcon);
- return EXIT_SUCCESS;
+ XtAppMainLoop(appcon);
+ return EXIT_SUCCESS;
}
static void
diff --git a/xedit.h b/xedit.h
index 8d93611..2f0291a 100644
--- a/xedit.h
+++ b/xedit.h
@@ -138,6 +138,7 @@ void DoPrint(Widget, XtPointer, XtPointer);
void CancelFindFile(Widget, XEvent*, String*, Cardinal*);
void FindFile(Widget, XEvent*, String*, Cardinal*);
void LoadFile(Widget, XEvent*, String*, Cardinal*);
+Bool LoadFileInTextwindow(char *name, char *resolved_name);
#ifdef INCLUDE_XPRINT_SUPPORT
void PrintFile(Widget, XEvent*, String*, Cardinal*);
#endif /* INCLUDE_XPRINT_SUPPORT */