summaryrefslogtreecommitdiff
path: root/xedit.c
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 /xedit.c
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.
Diffstat (limited to 'xedit.c')
-rw-r--r--xedit.c297
1 files changed, 146 insertions, 151 deletions
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