To: vim-dev@vim.org Subject: patch 5.5a.16 (extra) Fcc: outbox From: Bram Moolenaar ------------ Patch 5.5a.16 Problem: VMS: GUI does not compile and run. Solution: Various fixes. (Zoltan Arpadffy) Moved functions from os_unix.c to ui.c, so that VMS can use them too: open_app_context(), x11_setup_atoms() and clip_x11* functions. Made xterm_dpy global, it's now used by ui.c and os_unix.c. Use gethostname() always, sys_hostname doesn't exist. Files: src/globals.h, src/gui_x11.c, src/os_vms.mms, src/os_unix.c, src/os_vms.c, src/ui.c, src/proto/os_unix.pro, src/proto/ui.pro *** ../vim-5.5a.15/src/globals.h Mon Aug 30 10:40:47 1999 --- src/globals.h Wed Sep 8 18:18:56 1999 *************** *** 668,673 **** --- 668,674 ---- #ifdef XTERM_CLIP EXTERN char *xterm_display INIT(= NULL); /* xterm display name */ + EXTERN Display *xterm_dpy INIT(= NULL); /* xterm display pointer */ #endif #if defined(XTERM_CLIP) || defined(USE_GUI_X11) EXTERN XtAppContext app_context INIT(= (XtAppContext)NULL); *** ../vim-5.5a.15/src/os_vms.mms Mon Aug 30 10:40:57 1999 --- src/os_vms.mms Thu Sep 9 20:48:24 1999 *************** *** 94,100 **** SRC = buffer.c charset.c digraph.c edit.c eval.c ex_cmds.c ex_docmd.c \ ex_getln.c fileio.c getchar.c \ ! main.c mark.c \ memfile.c memline.c message.c misc1.c misc2.c normal.c ops.c option.c \ pty.c quickfix.c regexp.c search.c syntax.c tag.c term.c termlib.c \ ui.c undo.c version.c screen.c window.c os_vms.c pathdef.c \ --- 94,100 ---- SRC = buffer.c charset.c digraph.c edit.c eval.c ex_cmds.c ex_docmd.c \ ex_getln.c fileio.c getchar.c \ ! main.c mark.c menu.c\ memfile.c memline.c message.c misc1.c misc2.c normal.c ops.c option.c \ pty.c quickfix.c regexp.c search.c syntax.c tag.c term.c termlib.c \ ui.c undo.c version.c screen.c window.c os_vms.c pathdef.c \ *************** *** 102,108 **** OBJ = buffer.obj charset.obj digraph.obj edit.obj eval.obj ex_cmds.obj \ ex_docmd.obj ex_getln.obj fileio.obj getchar.obj \ ! main.obj mark.obj memfile.obj memline.obj message.obj misc1.obj \ misc2.obj normal.obj ops.obj option.obj pty.obj quickfix.obj \ regexp.obj search.obj syntax.obj tag.obj term.obj termlib.obj ui.obj \ undo.obj screen.obj window.obj os_vms.obj pathdef.obj \ --- 102,108 ---- OBJ = buffer.obj charset.obj digraph.obj edit.obj eval.obj ex_cmds.obj \ ex_docmd.obj ex_getln.obj fileio.obj getchar.obj \ ! main.obj mark.obj menu.obj memfile.obj memline.obj message.obj misc1.obj \ misc2.obj normal.obj ops.obj option.obj pty.obj quickfix.obj \ regexp.obj search.obj syntax.obj tag.obj term.obj termlib.obj ui.obj \ undo.obj screen.obj window.obj os_vms.obj pathdef.obj \ *************** *** 148,153 **** --- 148,154 ---- -@ write pd " * Change the file os_vms.mms only. */" -@ write pd "#include ""vim.h""" -@ write pd "char_u *default_vim_dir = (char_u *)""$(VIMLOC)"";" + -@ write pd "char_u *default_vimruntime_dir = (char_u *)"""";" -@ write pd "char_u *all_cflags = (char_u *)""$(CC) /incl=[] $(ALL_CFLAGS)"";" -@ write pd "char_u *all_lflags = (char_u *)""$(LD) $(LDFLAGS) /exe=$(TARGET) $+ $(ALL_LIBS)"";" -@ close pd *************** *** 225,230 **** --- 226,234 ---- $(CC) $(ALL_CFLAGS) $< mark.obj : mark.c vim.h config.h feature.h os_unix.h osdef.h ascii.h keymap.h term.h \ macros.h structs.h gui.h globals.h proto.h regexp.h option.h + $(CC) $(ALL_CFLAGS) $< + menu.obj : menu.c vim.h config.h feature.h os_unix.h osdef.h ascii.h keymap.h \ + term.h macros.h structs.h gui.h globals.h proto.h regexp.h option.h $(CC) $(ALL_CFLAGS) $< memfile.obj : memfile.c vim.h config.h feature.h os_unix.h osdef.h ascii.h keymap.h \ term.h macros.h structs.h gui.h globals.h proto.h regexp.h option.h *** ../vim-5.5a.15/src/os_unix.c Thu Sep 9 17:35:18 1999 --- src/os_unix.c Wed Sep 8 18:25:28 1999 *************** *** 100,106 **** # include # include # include - static Display *xterm_dpy = NULL; static Widget xterm_Shell = (Widget)0; static void xterm_update __ARGS((void)); # endif --- 100,105 ---- *************** *** 109,124 **** Display *x11_display = NULL; int got_x_error = FALSE; - #if defined(USE_GUI) && defined(XTERM_CLIP) - # define X_DISPLAY gui.in_use ? gui.dpy : xterm_dpy - #else - # ifdef USE_GUI - # define X_DISPLAY gui.dpy - # else - # define X_DISPLAY xterm_dpy - # endif - #endif - # ifdef WANT_TITLE static int get_x11_windis __ARGS((void)); static int test_x11_window __ARGS((Display *dpy)); --- 108,113 ---- *************** *** 3863,3896 **** } #endif /* GPM_MOUSE */ - #if defined(XTERM_CLIP) || defined(USE_GUI_X11) || defined(PROTO) - /* - * Open the application context (if it hasn't been opened yet). - * Used for Motif and Athena GUI and the xterm clipboard. - */ - void - open_app_context() - { - if (app_context == NULL) - { - XtToolkitInitialize(); - app_context = XtCreateApplicationContext(); - } - } - #endif - - #if defined(XTERM_CLIP) || defined(USE_GUI_X11) || defined(PROTO) - void - x11_setup_atoms(dpy) - Display *dpy; - { - clipboard.xatom = XInternAtom(dpy, "_VIM_TEXT", False); - clipboard.xa_compound_text = XInternAtom(dpy, "COMPOUND_TEXT", False); - clipboard.xa_text = XInternAtom(dpy, "TEXT", False); - clipboard.xa_targets = XInternAtom(dpy, "TARGETS", False); - } - #endif - #if (defined(HAVE_X11) && defined(WANT_X11) && defined(XTERM_CLIP)) \ || defined(PROTO) static int xterm_trace = -1; /* default: disabled */ --- 3852,3857 ---- *************** *** 4131,4388 **** clip_xterm_set_selection() { clip_x11_set_selection(); - } - #endif - - #if defined(XTERM_CLIP) || defined(USE_GUI_X11) || defined(PROTO) - - /* - * X Selection stuff, for cutting and pasting text to other windows. - */ - - static void clip_x11_request_selection_cb __ARGS((Widget, XtPointer, Atom *, Atom *, XtPointer, long_u *, int *)); - - /* ARGSUSED */ - static void - clip_x11_request_selection_cb(w, success, selection, type, value, length, - format) - Widget w; - XtPointer success; - Atom *selection; - Atom *type; - XtPointer value; - long_u *length; - int *format; - { - int motion_type; - long_u len; - char_u *p; - char **text_list = NULL; - - if (value == NULL || *length == 0) - { - clip_free_selection(); /* ??? */ - *(int *)success = FALSE; - return; - } - motion_type = MCHAR; - p = (char_u *)value; - len = *length; - if (*type == clipboard.xatom) - { - motion_type = *p++; - len--; - } - else if (*type == clipboard.xa_compound_text || ( - #ifdef MULTI_BYTE - is_dbcs && - #endif - *type == clipboard.xa_text)) - { - XTextProperty text_prop; - int n_text = 0; - int status; - - text_prop.value = (unsigned char *)value; - text_prop.encoding = *type; - text_prop.format = *format; - text_prop.nitems = STRLEN(value); - status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop, - &text_list, &n_text); - if (status != Success || n_text < 1) - { - *(int *)success = FALSE; - return; - } - p = (char_u *)text_list[0]; - len = STRLEN(p); - } - clip_yank_selection(motion_type, p, (long)len); - - if (text_list != NULL) - XFreeStringList(text_list); - - XtFree((char *)value); - *(int *)success = TRUE; - } - - void - clip_x11_request_selection(myShell, dpy) - Widget myShell; - Display *dpy; - { - XEvent event; - Atom type; - static int success; - int i; - - for (i = 0; i < 4; i++) - { - switch (i) - { - case 0: type = clipboard.xatom; - case 1: type = clipboard.xa_compound_text; - case 2: type = clipboard.xa_text; - default: type = XA_STRING; - } - XtGetSelectionValue(myShell, XA_PRIMARY, type, - clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); - - /* Do we need this?: */ - XFlush(dpy); - - /* - * Wait for result of selection request, otherwise if we type more - * characters, then they will appear before the one that requested the - * paste! Don't worry, we will catch up with any other events later. - */ - for (;;) - { - if (XCheckTypedEvent(dpy, SelectionNotify, &event)) - break; - - /* Do we need this?: */ - XSync(dpy, False); - } - - /* this is where clip_x11_request_selection_cb() is actually called */ - XtDispatchEvent(&event); - - if (success) - return; - } - } - - static Boolean clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *)); - - /* ARGSUSED */ - static Boolean - clip_x11_convert_selection_cb(w, selection, target, type, value, length, format) - Widget w; - Atom *selection; - Atom *target; - Atom *type; - XtPointer *value; - long_u *length; - int *format; - { - char_u *string; - char_u *result; - int motion_type; - - if (!clipboard.owned) - return False; /* Shouldn't ever happen */ - - /* requestor wants to know what target types we support */ - if (*target == clipboard.xa_targets) - { - Atom *array; - - if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 5))) == NULL) - return False; - *value = (XtPointer)array; - array[0] = XA_STRING; - array[1] = clipboard.xa_targets; - array[2] = clipboard.xatom; - array[3] = clipboard.xa_text; - array[4] = clipboard.xa_compound_text; - *type = XA_ATOM; - *format = sizeof(Atom) * 8; - *length = 5; - return True; - } - - if ( *target != XA_STRING - && *target != clipboard.xatom - && *target != clipboard.xa_text - && *target != clipboard.xa_compound_text) - return False; - - clip_get_selection(); - motion_type = clip_convert_selection(&string, length); - if (motion_type < 0) - return False; - - /* For our own format, the first byte contains the motion type */ - if (*target == clipboard.xatom) - (*length)++; - - *value = XtMalloc((Cardinal)*length); - result = (char_u *)*value; - if (result == NULL) - { - vim_free(string); - return False; - } - - if (*target == XA_STRING) - { - mch_memmove(result, string, (size_t)(*length)); - *type = XA_STRING; - } - else if (*target == clipboard.xa_compound_text - || *target == clipboard.xa_text) - { - XTextProperty text_prop; - char *string_nt = (char *)alloc((unsigned)*length + 1); - - /* create NUL terminated string which XmbTextListToTextProperty wants */ - mch_memmove(string_nt, string, (size_t)*length); - string_nt[*length] = NUL; - XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, 1, - XCompoundTextStyle, &text_prop); - vim_free(string_nt); - XtFree(*value); /* replace with COMPOUND text */ - *value = (XtPointer)(text_prop.value); /* from plain text */ - *length = text_prop.nitems; - *type = clipboard.xa_compound_text; - } - else - { - result[0] = motion_type; - mch_memmove(result + 1, string, (size_t)(*length - 1)); - *type = clipboard.xatom; - } - *format = 8; /* 8 bits per char */ - vim_free(string); - return True; - } - - static void clip_x11_lose_ownership_cb __ARGS((Widget, Atom *)); - - /* ARGSUSED */ - static void - clip_x11_lose_ownership_cb(w, selection) - Widget w; - Atom *selection; - { - clip_lose_selection(); - } - - void - clip_x11_lose_selection(myShell) - Widget myShell; - { - XtDisownSelection(myShell, XA_PRIMARY, CurrentTime); - } - - int - clip_x11_own_selection(myShell) - Widget myShell; - { - if (XtOwnSelection(myShell, XA_PRIMARY, CurrentTime, - clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, - NULL) == False) - return FAIL; - return OK; - } - - /* - * Send the current selection to the clipboard. Do nothing for X because we - * will fill in the selection only when requested by another app. - */ - void - clip_x11_set_selection() - { } #endif --- 4092,4096 ---- *** ../vim-5.5a.15/src/os_vms.c Mon Aug 30 10:40:56 1999 --- src/os_vms.c Thu Sep 9 20:52:14 1999 *************** *** 938,944 **** void mch_get_host_name(char_u *s, int len) { ! #if defined(__DECC) && defined(__STDC__) extern char_u *sys_hostname; /* presumably compiled with /decc */ --- 938,944 ---- void mch_get_host_name(char_u *s, int len) { ! #if 0 /* defined(__DECC) && defined(__STDC__) */ extern char_u *sys_hostname; /* presumably compiled with /decc */ *** ../vim-5.5a.15/src/ui.c Mon Aug 30 10:40:58 1999 --- src/ui.c Wed Sep 8 20:05:20 1999 *************** *** 1378,1380 **** --- 1378,1673 ---- return row; } #endif + + /* + * Stuff for the X clipboard. Shared between VMS and Unix. + */ + + #if defined(XTERM_CLIP) || defined(USE_GUI_X11) || defined(PROTO) + # include + # include + + # if defined(USE_GUI) && defined(XTERM_CLIP) + # define X_DISPLAY gui.in_use ? gui.dpy : xterm_dpy + # else + # ifdef USE_GUI + # define X_DISPLAY gui.dpy + # else + # define X_DISPLAY xterm_dpy + # endif + # endif + + /* + * Open the application context (if it hasn't been opened yet). + * Used for Motif and Athena GUI and the xterm clipboard. + */ + void + open_app_context() + { + if (app_context == NULL) + { + XtToolkitInitialize(); + app_context = XtCreateApplicationContext(); + } + } + + void + x11_setup_atoms(dpy) + Display *dpy; + { + clipboard.xatom = XInternAtom(dpy, "_VIM_TEXT", False); + clipboard.xa_compound_text = XInternAtom(dpy, "COMPOUND_TEXT", False); + clipboard.xa_text = XInternAtom(dpy, "TEXT", False); + clipboard.xa_targets = XInternAtom(dpy, "TARGETS", False); + } + + /* + * X Selection stuff, for cutting and pasting text to other windows. + */ + + static void clip_x11_request_selection_cb __ARGS((Widget, XtPointer, Atom *, Atom *, XtPointer, long_u *, int *)); + + /* ARGSUSED */ + static void + clip_x11_request_selection_cb(w, success, selection, type, value, length, + format) + Widget w; + XtPointer success; + Atom *selection; + Atom *type; + XtPointer value; + long_u *length; + int *format; + { + int motion_type; + long_u len; + char_u *p; + char **text_list = NULL; + + if (value == NULL || *length == 0) + { + clip_free_selection(); /* ??? */ + *(int *)success = FALSE; + return; + } + motion_type = MCHAR; + p = (char_u *)value; + len = *length; + if (*type == clipboard.xatom) + { + motion_type = *p++; + len--; + } + else if (*type == clipboard.xa_compound_text || ( + #ifdef MULTI_BYTE + is_dbcs && + #endif + *type == clipboard.xa_text)) + { + XTextProperty text_prop; + int n_text = 0; + int status; + + text_prop.value = (unsigned char *)value; + text_prop.encoding = *type; + text_prop.format = *format; + text_prop.nitems = STRLEN(value); + status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop, + &text_list, &n_text); + if (status != Success || n_text < 1) + { + *(int *)success = FALSE; + return; + } + p = (char_u *)text_list[0]; + len = STRLEN(p); + } + clip_yank_selection(motion_type, p, (long)len); + + if (text_list != NULL) + XFreeStringList(text_list); + + XtFree((char *)value); + *(int *)success = TRUE; + } + + void + clip_x11_request_selection(myShell, dpy) + Widget myShell; + Display *dpy; + { + XEvent event; + Atom type; + static int success; + int i; + + for (i = 0; i < 4; i++) + { + switch (i) + { + case 0: type = clipboard.xatom; + case 1: type = clipboard.xa_compound_text; + case 2: type = clipboard.xa_text; + default: type = XA_STRING; + } + XtGetSelectionValue(myShell, XA_PRIMARY, type, + clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); + + /* Do we need this?: */ + XFlush(dpy); + + /* + * Wait for result of selection request, otherwise if we type more + * characters, then they will appear before the one that requested the + * paste! Don't worry, we will catch up with any other events later. + */ + for (;;) + { + if (XCheckTypedEvent(dpy, SelectionNotify, &event)) + break; + + /* Do we need this?: */ + XSync(dpy, False); + } + + /* this is where clip_x11_request_selection_cb() is actually called */ + XtDispatchEvent(&event); + + if (success) + return; + } + } + + static Boolean clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *)); + + /* ARGSUSED */ + static Boolean + clip_x11_convert_selection_cb(w, selection, target, type, value, length, format) + Widget w; + Atom *selection; + Atom *target; + Atom *type; + XtPointer *value; + long_u *length; + int *format; + { + char_u *string; + char_u *result; + int motion_type; + + if (!clipboard.owned) + return False; /* Shouldn't ever happen */ + + /* requestor wants to know what target types we support */ + if (*target == clipboard.xa_targets) + { + Atom *array; + + if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 5))) == NULL) + return False; + *value = (XtPointer)array; + array[0] = XA_STRING; + array[1] = clipboard.xa_targets; + array[2] = clipboard.xatom; + array[3] = clipboard.xa_text; + array[4] = clipboard.xa_compound_text; + *type = XA_ATOM; + *format = sizeof(Atom) * 8; + *length = 5; + return True; + } + + if ( *target != XA_STRING + && *target != clipboard.xatom + && *target != clipboard.xa_text + && *target != clipboard.xa_compound_text) + return False; + + clip_get_selection(); + motion_type = clip_convert_selection(&string, length); + if (motion_type < 0) + return False; + + /* For our own format, the first byte contains the motion type */ + if (*target == clipboard.xatom) + (*length)++; + + *value = XtMalloc((Cardinal)*length); + result = (char_u *)*value; + if (result == NULL) + { + vim_free(string); + return False; + } + + if (*target == XA_STRING) + { + mch_memmove(result, string, (size_t)(*length)); + *type = XA_STRING; + } + else if (*target == clipboard.xa_compound_text + || *target == clipboard.xa_text) + { + XTextProperty text_prop; + char *string_nt = (char *)alloc((unsigned)*length + 1); + + /* create NUL terminated string which XmbTextListToTextProperty wants */ + mch_memmove(string_nt, string, (size_t)*length); + string_nt[*length] = NUL; + XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, 1, + XCompoundTextStyle, &text_prop); + vim_free(string_nt); + XtFree(*value); /* replace with COMPOUND text */ + *value = (XtPointer)(text_prop.value); /* from plain text */ + *length = text_prop.nitems; + *type = clipboard.xa_compound_text; + } + else + { + result[0] = motion_type; + mch_memmove(result + 1, string, (size_t)(*length - 1)); + *type = clipboard.xatom; + } + *format = 8; /* 8 bits per char */ + vim_free(string); + return True; + } + + static void clip_x11_lose_ownership_cb __ARGS((Widget, Atom *)); + + /* ARGSUSED */ + static void + clip_x11_lose_ownership_cb(w, selection) + Widget w; + Atom *selection; + { + clip_lose_selection(); + } + + void + clip_x11_lose_selection(myShell) + Widget myShell; + { + XtDisownSelection(myShell, XA_PRIMARY, CurrentTime); + } + + int + clip_x11_own_selection(myShell) + Widget myShell; + { + if (XtOwnSelection(myShell, XA_PRIMARY, CurrentTime, + clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, + NULL) == False) + return FAIL; + return OK; + } + + /* + * Send the current selection to the clipboard. Do nothing for X because we + * will fill in the selection only when requested by another app. + */ + void + clip_x11_set_selection() + { + } + #endif *** ../vim-5.5a.15/src/proto/os_unix.pro Mon Aug 30 10:40:40 1999 --- src/proto/os_unix.pro Wed Sep 8 19:59:53 1999 *************** *** 41,48 **** int mch_expandpath __ARGS((struct growarray *gap, char_u *path, int flags)); int mch_expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags)); int mch_has_wildcard __ARGS((char_u *p)); - void open_app_context __ARGS((void)); - void x11_setup_atoms __ARGS((Display *dpy)); void setup_xterm_clip __ARGS((void)); void start_xterm_trace __ARGS((int button)); void stop_xterm_trace __ARGS((void)); --- 41,46 ---- *************** *** 51,57 **** void clip_xterm_lose_selection __ARGS((void)); void clip_xterm_request_selection __ARGS((void)); void clip_xterm_set_selection __ARGS((void)); - void clip_x11_request_selection __ARGS((Widget myShell, Display *dpy)); - void clip_x11_lose_selection __ARGS((Widget myShell)); - int clip_x11_own_selection __ARGS((Widget myShell)); - void clip_x11_set_selection __ARGS((void)); --- 49,51 ---- *** ../vim-5.5a.15/src/proto/ui.pro Mon Aug 30 10:40:39 1999 --- src/proto/ui.pro Wed Sep 8 20:00:36 1999 *************** *** 39,41 **** --- 39,47 ---- void ui_cursor_shape __ARGS((void)); int check_col __ARGS((int col)); int check_row __ARGS((int row)); + void open_app_context __ARGS((void)); + void x11_setup_atoms __ARGS((Display *dpy)); + void clip_x11_request_selection __ARGS((Widget myShell, Display *dpy)); + void clip_x11_lose_selection __ARGS((Widget myShell)); + int clip_x11_own_selection __ARGS((Widget myShell)); + void clip_x11_set_selection __ARGS((void)); *** ../vim-5.5a.15/src/version.c Fri Sep 10 11:33:37 1999 --- src/version.c Sat Sep 11 16:21:19 1999 *************** *** 420,420 **** --- 420,421 ---- { /* Add new patch number below this line */ + 16, -- A village. Sound of chanting of Latin canon, punctuated by short, sharp cracks. It comes nearer. We see it is a line of MONKS ala SEVENTH SEAL flagellation scene, chanting and banging themselves on the foreheads with wooden boards. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\-- \ \ www.vim.org/iccf www.moolenaar.net www.vim.org / / .