From 05d29ed34f79a1d744b606600cd77bfc87d510bf Mon Sep 17 00:00:00 2001 From: William McBrine Date: Tue, 3 Jan 2006 20:08:38 +0000 Subject: [PATCH] Removed broken thread port of X11. --- x11/thread/x11.c | 999 ----------------------------------------- x11/thread/x11.h | 85 ---- x11/thread/x11common.c | 100 ----- x11/thread/x11curses.c | 675 ---------------------------- 4 files changed, 1859 deletions(-) delete mode 100644 x11/thread/x11.c delete mode 100644 x11/thread/x11.h delete mode 100644 x11/thread/x11common.c delete mode 100644 x11/thread/x11curses.c diff --git a/x11/thread/x11.c b/x11/thread/x11.c deleted file mode 100644 index f1ac5fc7..00000000 --- a/x11/thread/x11.c +++ /dev/null @@ -1,999 +0,0 @@ -/* -*************************************************************************** -* This file comprises part of PDCurses. PDCurses is Public Domain software. -* You may use this code for whatever purposes you desire. This software -* is provided AS IS with NO WARRANTY whatsoever. -* Should this software be used in another application, an acknowledgement -* that PDCurses code is used would be appreciated, but is not mandatory. -* -* Any changes which you make to this software which may improve or enhance -* it, should be forwarded to the current maintainer for the benefit of -* other users. -* -* The only restriction placed on this code is that no distribution of -* modified PDCurses code be made under the PDCurses name, by anyone -* other than the current maintainer. -* -* See the file maintain.er for details of the current maintainer. -* -* This file is NOT public domain software. It is Copyright, Mark Hessling -* 1994-2000. -*************************************************************************** -*/ - -/* - * This file contains functions that are called by the "x11" thread; - * ie the child thread. - */ - -#include "pdcx11.h" - -static int visible_cursor=0; -int windowEntered = 1; - -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCursesExitXCursesProcess(int rc,int sig,char *msg) -#else -void XCursesExitXCursesProcess(rc,sig,msg) -int rc,sig; -char *msg; -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesExitXCursesProcess() - called: rc:%d sig:%d %s\n",(XCursesProcess)?" X":"CURSES",rc,sig,msg); -#endif - XCursesEndwin(); - close(display_sock); - close(exit_sock); - close(key_sock); - pthread_exit(rc); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCursesDisplayScreen(bool highlight) -#else -void XCursesDisplayScreen(highlight) -bool highlight; -#endif -/***********************************************************************/ -/*---------------------------------------------------------------------*/ -/* This function re-draws the entire screen. */ -/*---------------------------------------------------------------------*/ -{ - int row=0; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesDisplayScreen() - called:\n",(XCursesProcess)?" X":"CURSES"); -#endif - for (row=0;rowcursrow,SP->curscol, - SP->cursrow,SP->curscol); - /* - * Draw the border if required - */ - if (XCURSESBORDERWIDTH) - XDrawRectangle(XCURSESDISPLAY,XCURSESWIN,border_gc, - (XCURSESBORDERWIDTH/2),(XCURSESBORDERWIDTH/2), - (XCursesWindowWidth-XCURSESBORDERWIDTH), - (XCursesWindowHeight-XCURSESBORDERWIDTH)); - return; -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCursesRefreshScreen(void) -#else -int XCursesRefreshScreen() -#endif -/***********************************************************************/ -/*---------------------------------------------------------------------*/ -/* This function draws those portions of the screen that have changed. */ -/*---------------------------------------------------------------------*/ -{ - int row=0,start_col=0,num_cols=0; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesRefreshScreen() - called:\n",(XCursesProcess)?" X":"CURSES"); -#endif - for (row=0;rowcursrow,SP->curscol, - SP->cursrow,SP->curscol); - return(0); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCursesProcessRequestsFromCurses(XtPointer client_data,int *fid,XtInputId *id) -#else -void XCursesProcessRequestsFromCurses(client_data,fid,id) -XtPointer client_data; -int *fid; -XtInputId *id; -#endif -/***********************************************************************/ -{ - int s,idx; - int old_row,new_row; - int old_x,new_x; - int pos,num_cols; - long length; - char buf[12]; /* big enough for 2 integers */ - char title[1024]; /* big enough for window title */ - unsigned char save_atrtab[MAX_ATRTAB]; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesProcessRequestsFromCurses()\n",(XCursesProcess)?" X":"CURSES"); -#endif - - if (!ReceivedMapNotify) - return; -#if DONT_NEED_SELECT_HERE -/* - * Do we need select() ? Surely, that's what X does with XtAppAddInput() - */ - FD_ZERO ( &readfds ); - FD_SET ( display_sock, &readfds ); - - if ( ( s = select ( FD_SETSIZE, (FD_SET_CAST)&readfds, NULL, NULL, &socket_timeout ) ) < 0 ) - XCursesExitXCursesProcess(2,SIGKILL,"exiting from XCursesProcessRequestsFromCurses - select failed"); - - if ( s == 0 ) /* no requests pending - should never happen!*/ - return; -#endif - -#ifdef DONT_NEED_SELECT_HERE - if ( FD_ISSET ( display_sock, &readfds ) ) - { -#endif -/* read first integer to determine total message has been received */ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesProcessRequestsFromCurses() - before read_socket()\n",(XCursesProcess)?" X":"CURSES"); -#endif - if (read_from_parent(dis_r,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(3,SIGKILL,"exiting from XCursesProcessRequestsFromCurses - first read"); -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesProcessRequestsFromCurses() - after read_socket()\n",(XCursesProcess)?" X":"CURSES"); -#endif - memcpy((char *)&num_cols,buf,sizeof(int)); - after_first_curses_request = True; - - switch(num_cols) - { - case 0: break; - case CURSES_EXIT: /* request from curses to stop */ - say("CURSES_EXIT received from child\n"); - XCursesExitXCursesProcess(0,0,"XCursesProcess requested to exit by child"); - break; - case CURSES_BELL: /* request from curses to beep */ - say("CURSES_BELL received from child\n"); - XBell(XCURSESDISPLAY,50); - break; - case CURSES_CLEAR: /* request from curses to clear window */ - say("CURSES_CLEAR received from child\n"); - XClearWindow(XCURSESDISPLAY,XCURSESWIN); - break; - case CURSES_FLASH: /* request from curses to beep */ - say("CURSES_FLASH received from child\n"); -#if 0 - XFillRectangle(XCURSESDISPLAY,XCURSESWIN,normal_highlight_gc,10,10,XCursesWindowWidth-10,XCursesWindowHeight-10); - napms(50); - XFillRectangle(XCURSESDISPLAY,XCURSESWIN,normal_highlight_gc,10,10,XCursesWindowWidth-10,XCursesWindowHeight-10); - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); -#endif - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - case CURSES_REFRESH: /* request from curses to confirm completion of display */ - say("CURSES_REFRESH received from child\n"); - visible_cursor = 1; - XCursesRefreshScreen(); - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - case CURSES_REFRESH_SCROLLBAR: /* request from curses draw scrollbar */ - XCursesRefreshScrollbar(); -#if 0 - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); -#endif - break; - case CURSES_CURSOR: /* display cursor */ - say("CURSES_CURSOR received from child\n"); - if (read_from_parent(dis_r,buf,sizeof(int)*2) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_CURSOR XCursesProcessRequestsFromCurses"); - memcpy((char *)&pos,buf,sizeof(int)); - old_row = pos & 0xFF; - old_x = pos >> 8; - idx = sizeof(int); - memcpy((char *)&pos,buf+idx,sizeof(int)); - new_row = pos & 0xFF; - new_x = pos >> 8; - visible_cursor = 1; - XCursesDisplayCursor(old_row,old_x,new_row,new_x); - break; - case CURSES_DISPLAY_CURSOR: /* display cursor */ - say("CURSES_DISPLAY_CURSOR received from child. Vis now: %d\n",visible_cursor); - /* - * If the window is not active, ignore this command. The - * cursor will stay solid. - */ - if ( windowEntered ) - { - if ( visible_cursor ) - { - /* - * Cursor currently ON, turn it off - */ - int save_visibility = SP->visibility; - SP->visibility = 0; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - SP->visibility = save_visibility; - visible_cursor = 0; - } - else - { - /* - * Cursor currently OFF, turn it on - */ - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - visible_cursor = 1; - } - } - break; - case CURSES_TITLE: /* display window title */ - say("CURSES_TITLE received from child\n"); - if (read_from_parent(dis_r,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); - memcpy((char *)&pos,buf,sizeof(int)); - if (read_from_parent(dis_r,title,pos) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); - XtVaSetValues(topLevel, XtNtitle, title, NULL); - break; - case CURSES_RESIZE: /* resize window */ - after_first_curses_request = False; - say("CURSES_RESIZE received from child\n"); - SP->lines = XCursesLINES = ((resizeXCursesWindowHeight-(2*XCURSESBORDERWIDTH)) / XCursesFontHeight); - LINES = XCursesLINES - SP->linesrippedoff - SP->slklines; - SP->cols = COLS = XCursesCOLS = ((resizeXCursesWindowWidth-(2*XCURSESBORDERWIDTH)) / XCursesFontWidth); - XCursesWindowWidth = resizeXCursesWindowWidth; - XCursesWindowHeight = resizeXCursesWindowHeight; - visible_cursor = 1; - /* - * Draw the border if required - */ - if (XCURSESBORDERWIDTH) - XDrawRectangle(XCURSESDISPLAY,XCURSESWIN,border_gc, - (XCURSESBORDERWIDTH/2),(XCURSESBORDERWIDTH/2), - (XCursesWindowWidth-XCURSESBORDERWIDTH), - (XCursesWindowHeight-XCURSESBORDERWIDTH)); -/* - * detach and drop the current shared memory segment and create and attach - * to a new segment. - */ - memcpy(save_atrtab,atrtab,sizeof(save_atrtab)); - SP->XcurscrSize = XCURSCR_SIZE; - shmdt((char *)Xcurscr); - shmctl(shmid_Xcurscr,IPC_RMID,0); - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700|IPC_CREAT)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - } - Xcurscr = (unsigned char*)shmat(shmid_Xcurscr,0,0); - memset(Xcurscr, 0, SP->XcurscrSize); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - memcpy(atrtab,save_atrtab,sizeof(save_atrtab)); - - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - case CURSES_GET_SELECTION: /* request selection contents */ - say("CURSES_GET_SELECTION received from child\n"); - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - XtGetSelectionValue(topLevel,XA_PRIMARY,XA_STRING,XCursesRequestorCallbackForGetSelection,(XtPointer)NULL,0); - break; - case CURSES_SET_SELECTION: /* set the selection contents */ - say("CURSES_SET_SELECTION received from child\n"); - if (read_from_parent(dis_r,buf,sizeof(long)) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_SET_SELECTION XCursesProcessRequestsFromCurses"); - memcpy((char *)&length,buf,sizeof(long)); - if (length > tmpsel_length) - { - if (tmpsel_length == 0) - tmpsel = (char *)malloc(length+1); - else - tmpsel = (char *)realloc(tmpsel,length+1); - } - if (!tmpsel) - { - old_x = PDC_CLIP_MEMORY_ERROR; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - } - if (read_from_parent(dis_r,tmpsel,length) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_SET_SELECTION XCursesProcessRequestsFromCurses"); - tmpsel_length = length; - *(tmpsel+length) = '\0'; - if (XtOwnSelection(topLevel, - XA_PRIMARY, - CurrentTime, - XCursesConvertProc, - XCursesLoseOwnership, - NULL) == False) - { - old_x = PDC_CLIP_ACCESS_ERROR; - free(tmpsel); - tmpsel = NULL; - tmpsel_length = 0; - } - else - old_x = PDC_CLIP_SUCCESS; - SelectionOff(); - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - default: -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:Unknown request %d\n",(XCursesProcess)?" X":"CURSES",num_cols); -#endif - break; -#ifdef DONT_NEED_SELECT_HERE - } -#endif - } - return; -} -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCursesSetupX(char *display_name,int argc, char *argv[]) -#else -int XCursesSetupX(display_name,argc,argv) -char *display_name; -int arc; -char *argv[]; -#endif -/***********************************************************************/ -{ - extern bool sb_started; - - XColor pointerforecolor,pointerbackcolor; - XrmValue rmfrom,rmto; - char wait_buf[5]; - int wait_value=0,i=0; - int minwidth=0,minheight=0; - int myargc; - char *myargv[2]; -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesSetupX called\n",(XCursesProcess)?" X":"CURSES"); -#endif - - /* - * The following kludge is to force XtVaAppInitialize() to recognize the - * name of the program. Without it, a default value of "main" is used. - */ - if (argv) - { - argv[0] = XCursesProgramName; -#ifdef PDCDEBUG1 - for (i=0;i %s\n",i,argv[i]); -#endif - } - else - { - /* - * initscr() called rather than initscrX() - */ - myargv[0] = XCursesProgramName; - myargv[1] = NULL; - myargc=1; - } - - /* - * Trap all signals when XCurses is the child process... - */ - for (i=0;i 4 - XtSetLanguageProc(NULL, (XtLanguageProc)NULL,NULL); -#endif - /* - * If a DISPLAY value has been supplied, set the env variable DISPLAY. - */ - if (display_name) - { - strcpy(global_display_name,"DISPLAY="); - strcat(global_display_name,display_name); - putenv(global_display_name); - } - /* - * Exit if no DISPLAY variable set... - */ - if (getenv("DISPLAY") == NULL) - { - fprintf(stderr,"Error: no DISPLAY variable set\n"); - kill(otherpid,SIGKILL); - return(ERR); - } - /* - * Initialise the top level widget... - */ - if (argv) - { - topLevel = XtVaAppInitialize( &app_context, - XCursesClassName, - options, - XtNumber(options), - &argc, - argv, - NULL, -/* - XtNinput, (XtArgVal)True, - XtNtitle,XCursesProgramName, - XtNname,"xcurses", -*/ - NULL); - } - else - { - topLevel = XtVaAppInitialize( &app_context, - XCursesClassName, - options, - XtNumber(options), - &myargc, - myargv, - NULL, -/* - XtNinput, (XtArgVal)True, - XtNtitle,XCursesProgramName, - XtNname,"xcurses", -*/ - NULL); - } -#ifdef PDCDEBUG1 - for (i=0;i %s\n",i,argv[i]); -#endif - - XtVaGetApplicationResources(topLevel,&app_data,app_resources,XtNumber(app_resources),NULL); - /* check application resource values here... */ - -#if 0 -printf("Width %d Height %d\n",XCURSESGEOMETRY.width,XCURSESGEOMETRY.height); -#endif - - XCursesFontWidth = XCURSESNORMALFONTINFO->max_bounds.rbearing - XCURSESNORMALFONTINFO->min_bounds.lbearing; - XCursesFontHeight = XCURSESNORMALFONTINFO->max_bounds.ascent + XCURSESNORMALFONTINFO->max_bounds.descent; - XCursesFontAscent = XCURSESNORMALFONTINFO->max_bounds.ascent; - XCursesFontDescent = XCURSESNORMALFONTINFO->max_bounds.descent; -#if 0 - /* - * Check that the bold font and normal fonts are the same size... - */ - if (XCursesFontWidth != XCURSESBOLDFONTINFO->max_bounds.rbearing - XCURSESBOLDFONTINFO->min_bounds.lbearing - || XCursesFontHeight != XCURSESBOLDFONTINFO->max_bounds.ascent + XCURSESBOLDFONTINFO->max_bounds.descent) - { - fprintf(stderr,"Error: normal font and bold font are different sizes\n"); - fprintf(stderr,"\tNormal\tBold\n"); - fprintf(stderr,"Width :\t%d\t%d\n",XCursesFontWidth,XCURSESBOLDFONTINFO->max_bounds.rbearing - XCURSESBOLDFONTINFO->min_bounds.lbearing); - fprintf(stderr,"Height:\t%d\t%d\n",XCursesFontHeight,XCURSESBOLDFONTINFO->max_bounds.ascent + XCURSESBOLDFONTINFO->max_bounds.descent); - kill(otherpid,SIGKILL); - return(ERR); - } -#endif - /* - * Calculate size of display window... - */ - XCursesCOLS = XCURSESCOLS; - XCursesLINES = XCURSESLINES; - XCursesWindowWidth = (XCursesFontWidth * XCursesCOLS) + (2 * XCURSESBORDERWIDTH); - XCursesWindowHeight = (XCursesFontHeight * XCursesLINES) + (2 * XCURSESBORDERWIDTH); - minwidth = (XCursesFontWidth*2)+(XCURSESBORDERWIDTH*2); - minheight = (XCursesFontHeight*2)+(XCURSESBORDERWIDTH*2); - /* - * Set up the icon for the application. The default is an internal one - * for XCurses. Then set various application level resources... - */ - XCursesGetIcon(); - - XtVaSetValues(topLevel, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - XtNminWidth,minwidth, - XtNminHeight,minheight, - XtNiconPixmap,icon_pixmap, - NULL); - /* - * Create a BOX widget in which to draw... - */ -#if 0 - fprintf(stderr,"Width: %d Height: %d sb_started: %d\n",XCursesWindowWidth+XCURSESSCROLLBARWIDTH, - XCursesWindowHeight+XCURSESSCROLLBARWIDTH,sb_started); -#endif - if (XCURSESSCROLLBARWIDTH != 0 - && sb_started) - { - scrollBox = XtVaCreateManagedWidget(XCursesProgramName,scrollBoxWidgetClass,topLevel, - XtNwidth,XCursesWindowWidth+XCURSESSCROLLBARWIDTH+8+2, - XtNheight,XCursesWindowHeight+XCURSESSCROLLBARWIDTH+8+2, - NULL); - drawing = XtVaCreateManagedWidget(XCursesProgramName,boxWidgetClass, - scrollBox, - XtNwidth,XCursesWindowWidth, - XtNheight,XCursesWindowHeight, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - NULL); - scrollVert = XtVaCreateManagedWidget("scrollVert", scrollbarWidgetClass, - scrollBox, - XtNorientation, XtorientVertical, - XtNheight, XCursesWindowHeight, - XtNwidth, XCURSESSCROLLBARWIDTH, - NULL); - XtAddCallback(scrollVert, XtNscrollProc, Scroll_up_down, drawing); - XtAddCallback(scrollVert, XtNjumpProc, Thumb_up_down, drawing); - scrollHoriz = XtVaCreateManagedWidget("scrollHoriz", scrollbarWidgetClass, - scrollBox, - XtNorientation, XtorientHorizontal, - XtNwidth, XCursesWindowWidth, - XtNheight, XCURSESSCROLLBARWIDTH, - NULL); - XtAddCallback(scrollHoriz, XtNscrollProc, Scroll_left_right, drawing); - XtAddCallback(scrollHoriz, XtNjumpProc, Thumb_left_right, drawing); - } - else - { - drawing = XtVaCreateManagedWidget(XCursesProgramName,boxWidgetClass,topLevel, - XtNwidth,XCursesWindowWidth, - XtNheight,XCursesWindowHeight, - NULL); - } - -#if 0 - fprintf(stderr,"Width: %d Height: %d\n",XCursesWindowWidth+XCURSESSCROLLBARWIDTH, - XCursesWindowHeight+XCURSESSCROLLBARWIDTH); -#endif -/* - XtVaSetValues(drawing, - XtNwidth,XCursesWindowWidth, - XtNheight,XCursesWindowHeight, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - XtNminWidth,XCursesFontWidth*2, - XtNminHeight,XCursesFontHeight*2, - XtNborderWidth,20, - NULL); -*/ - /* - * Process any default translations... - */ - XCursesTranslations = XtParseTranslationTable(defaultTranslations); - XtAugmentTranslations(drawing,XCursesTranslations); - XtAppAddActions(app_context,XCursesActions,XtNumber(XCursesActions)); - /* - * Process the supplied colors... - */ - if (get_colors() == ERR) - { - kill(otherpid,SIGKILL); - return(ERR); - } - /* - * Now have LINES and COLS. Set these in the shared SP so the - * curses program can find them... - */ - LINES = XCursesLINES; - COLS = XCursesCOLS; - if ((shmidSP = shmget(shmkeySP,sizeof(SCREEN)+XCURSESSHMMIN,0700|IPC_CREAT)) < 0) - { - perror("Cannot allocate shared memory for SCREEN"); - kill(otherpid,SIGKILL); - return(ERR); - } - SP = (SCREEN*)shmat(shmidSP,0,0); - memset(SP, 0, sizeof(SCREEN)); - SP->XcurscrSize = XCURSCR_SIZE; - SP->lines = XCursesLINES; - SP->cols = XCursesCOLS; -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:SHM size for curscr %d\n",(XCursesProcess)?" X":"CURSES",SP->XcurscrSize); -#endif - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700|IPC_CREAT)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - kill(otherpid,SIGKILL); - shmdt((char *)SP); - shmctl(shmidSP,IPC_RMID,0); - return(ERR); - } - Xcurscr = (unsigned char *)shmat(shmid_Xcurscr,0,0); - memset(Xcurscr, 0, SP->XcurscrSize); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - PDC_init_atrtab(); -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:shmid_Xcurscr %d shmkey_Xcurscr %d LINES %d COLS %d\n",(XCursesProcess)?" X":"CURSES",shmid_Xcurscr,shmkey_Xcurscr,LINES,COLS); -#endif - /* - * Add Event handlers to the drawing widget... - */ - XtAddEventHandler(drawing,ExposureMask,False,XCursesExpose,NULL); - /* XtAddEventHandler(drawing,KeyPressMask|KeyReleaseMask,False,XCursesKeyPressKeyRelease,NULL); */ - /* XtAddEventHandler(drawing,ButtonPressMask|ButtonReleaseMask,False,XCursesButtonPressButtonRelease,NULL);*/ - XtAddEventHandler(drawing,StructureNotifyMask,False,XCursesStructureNotify,NULL); - XtAddEventHandler(drawing,EnterWindowMask|LeaveWindowMask,False,XCursesEnterLeaveWindow,NULL); -#if 0 - XtAddEventHandler(drawing,0,True,XCursesNonmaskable,NULL); -#endif - XtAddEventHandler(topLevel,0,True,XCursesNonmaskable,NULL); - /* - * Add input handler form display_sock (requests from curses program) - */ - XtAppAddInput(app_context,dis_r,(XtPointer)XtInputReadMask,XCursesProcessRequestsFromCurses,NULL); - /* - * Realize the widget... - */ - XtRealizeWidget(topLevel); - /* - * Handle trapping of the WM_DELETE_WINDOW property... - */ - wm_atom[0] = XInternAtom(XtDisplay(topLevel),"WM_DELETE_WINDOW",False); - wm_atom[1] = XInternAtom(XtDisplay(topLevel),"WM_SAVE_YOURSELF",False); - /* (void)XSetWMProtocols(XtDisplay(topLevel),RootWindowOfScreen(XtScreen(topLevel)),&wm_delete_window_atom,1);*/ - /* (void)XSetWMProtocols(XtDisplay(topLevel),XCURSESWIN,&wm_delete_window_atom,1);*/ - (void)XSetWMProtocols(XtDisplay(topLevel),XtWindow(topLevel),wm_atom,2); - /* - * Create the Graphics Context for drawing. This MUST be done AFTER the - * associated widget has been realized... - */ -#ifdef PDCDEBUG - say("before get_GC\n"); -#endif - get_GC(XCURSESDISPLAY,XCURSESWIN,&normal_gc,XCURSESNORMALFONTINFO,COLOR_WHITE,COLOR_BLACK,FALSE); - get_GC(XCURSESDISPLAY,XCURSESWIN,&normal_highlight_gc,XCURSESNORMALFONTINFO,COLOR_WHITE,COLOR_BLACK,TRUE); - get_GC(XCURSESDISPLAY,XCURSESWIN,&bold_highlight_gc,XCURSESBOLDFONTINFO,COLOR_WHITE,COLOR_BLACK,TRUE); - get_GC(XCURSESDISPLAY,XCURSESWIN,&block_cursor_gc,XCURSESNORMALFONTINFO,COLOR_BLACK,COLOR_CURSOR,FALSE); - get_GC(XCURSESDISPLAY,XCURSESWIN,&rect_cursor_gc,XCURSESNORMALFONTINFO,COLOR_CURSOR,COLOR_BLACK,FALSE); - get_GC(XCURSESDISPLAY,XCURSESWIN,&border_gc,XCURSESNORMALFONTINFO,COLOR_BORDER,COLOR_BLACK,FALSE); - /* - XSetLineAttributes(XCURSESDISPLAY,normal_gc,2,LineSolid,CapButt,JoinMiter); - */ - XSetLineAttributes(XCURSESDISPLAY,rect_cursor_gc,2,LineSolid,CapButt,JoinMiter); - XSetLineAttributes(XCURSESDISPLAY,border_gc,XCURSESBORDERWIDTH,LineSolid,CapButt,JoinMiter); - /* - * Set the cursor for the application... - */ - XDefineCursor(XCURSESDISPLAY,XCURSESWIN,XCURSESPOINTER); - rmfrom.size = sizeof(Pixel); - rmto.size = sizeof(XColor); -#if XtSpecificationRelease > 4 - rmto.addr = (XPointer)&pointerforecolor; - rmfrom.addr = (XPointer)&(XCURSESPOINTERFORECOLOR); - XtConvertAndStore(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#else - rmto.addr = (char *)&pointerforecolor; - rmfrom.addr = (char *)&(XCURSESPOINTERFORECOLOR); - XtConvert(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#endif - rmfrom.size = sizeof(Pixel); - rmto.size = sizeof(XColor); -#if XtSpecificationRelease > 4 - rmfrom.addr = (XPointer)&(XCURSESPOINTERBACKCOLOR); - rmto.addr = (XPointer)&pointerbackcolor; - XtConvertAndStore(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#else - rmfrom.addr = (char *)&(XCURSESPOINTERBACKCOLOR); - rmto.addr = (char *)&pointerbackcolor; - XtConvert(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#endif - XRecolorCursor(XCURSESDISPLAY,XCURSESPOINTER,&pointerforecolor,&pointerbackcolor); - /* - * Convert the supplied compose key to a Keysym... - */ - compose_key = XStringToKeysym(XCURSESCOMPOSEKEY); - if (compose_key - && IsModifierKey(compose_key)) - { - register int i=0,j=0; - KeyCode *kcp; - XModifierKeymap *map; - KeyCode compose_keycode=XKeysymToKeycode(XCURSESDISPLAY,compose_key); - map = XGetModifierMapping(XCURSESDISPLAY); - kcp = map->modifiermap; - for (i=0;i<8;i++) - { - for (j=0;jmax_keypermod;j++,kcp++) - { - if (!*kcp) - continue; - if (compose_keycode == *kcp) - { - compose_mask = state_mask[i]; - break; - } - } - if (compose_mask) - break; - } - XFreeModifiermap(map); - } - /* fprintf(stderr,"COMPOSE KEY: %d %s STATE: %d\n",compose_key,XCURSESCOMPOSEKEY,compose_mask);*/ - -#ifdef FOREIGN - sleep(20); - if ((Xim = XOpenIM(XCURSESDISPLAY,NULL,NULL,NULL)) == NULL) - { - perror("Cannot open Input Method"); - kill(otherpid,SIGKILL); - shmdt((char *)SP); - shmdt((char *)Xcurscr); - shmctl(shmidSP,IPC_RMID,0); - shmctl(shmid_Xcurscr,IPC_RMID,0); - return(ERR); - } - XGetIMValues(Xim,XNQueryInputStyle, &im_supported_styles, NULL); - my_style = XIMPreeditNone|XIMStatusNone; - /* call XtCvtStringToFontSet ??? */ - if ((Xic = XCreateIC(Xim, XNInputStyle, my_style, - /* - - */ - NULL)) == NULL) - { - perror("ERROR: Cannot create input context"); - kill(otherpid,SIGKILL); - shmdt((char *)SP); - shmdt((char *)Xcurscr); - shmctl(shmidSP,IPC_RMID,0); - shmctl(shmid_Xcurscr,IPC_RMID,0); - return(ERR); - } - XFree(im_supported_styles); - XGetICValues(Xic, XNFilterEvents, &im_event_mask, NULL); - XtAddEventHandler(drawing,im_event_mask,False,NULL,NULL); - XSetICFocus(Xic); -#endif - /* - * Leave telling the curses process that it can start to here so that - * when the curses process makes a request, the Xcurses process can - * service the request... - */ - wait_value = CURSES_CHILD; - memcpy(wait_buf,(char *)&wait_value,sizeof(int)); - (void)write_to_parent(dis_w,wait_buf,sizeof(int)); - /* - * Wait for events... - */ - XtAppMainLoop(app_context); - return(OK); /* won't get here */ -} -/***********************************************************************/ -#ifdef HAVE_PROTO -RETSIGTYPE XCursesSignalHandler(int signo) -#else -RETSIGTYPE XCursesSignalHandler(signo) -int signo; -#endif -/***********************************************************************/ -{ - char buf[10]; - int flag = CURSES_EXIT; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesSignalHandler() - called: %d\n",(XCursesProcess)?" X":"CURSES",signo); -#endif - /* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 04-Dec-1998 - */ - XCursesSetSignal(signo,XCursesSignalHandler); -#ifdef SIGTSTP - if (signo == SIGTSTP) { pause(); return; } -#endif -#ifdef SIGCONT - if (signo == SIGCONT) return; -#endif -#ifdef SIGCLD - if (signo == SIGCLD) return; -#endif -#ifdef SIGTTIN - if (signo == SIGTTIN) return; -#endif -#ifdef SIGWINCH - if (signo == SIGWINCH) return; -#endif - /* - * End of patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 04-Dec-1998 - */ - XCursesSetSignal(signo,SIG_IGN); - /* - * Send a CURSES_EXIT to myself... - */ - memcpy(buf,(char *)&flag,sizeof(int)); - if (write_socket(exit_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(7,signo,"exitting from XCursesSignalHandler"); -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCursesRequestorCallbackForGetSelection(Widget w,XtPointer data, Atom *selection, - Atom *type, XtPointer value, - unsigned long *length, int *format) -#else -void XCursesRequestorCallbackForGetSelection(w,data,selection,type,value,length,format) -Widget w; -XtPointer data; -Atom *selection; -Atom *type; -XtPointer value; -unsigned long *length; -int *format; -#endif -/***********************************************************************/ -{ - int rc; - char buf[12]; /* big enough for 2 integers */ - char *string=(char *)value; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesRequestorCallbackForSelection() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - - if ((value == NULL) && (*length == 0)) - { - rc = PDC_CLIP_EMPTY; - memcpy(buf,(char *)&rc,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); - return; - } - /* - * Here all is OK, send PDC_CLIP_SUCCESS, then length, then contents - */ - rc = PDC_CLIP_SUCCESS; - memcpy(buf,(char *)&rc,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); - - rc = *(length); - memcpy(buf,(char *)&rc,sizeof(int)); - if (write_to_parent(dis_w,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); - - if (write_to_parent(dis_w,string,*length) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); - - return; -} -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCursesStructureNotify(Widget w,XtPointer client_data,XEvent *event,Boolean *continue_to_dispatch) -#else -void XCursesStructureNotify(w,client_data,event,continue_to_dispatch) -Widget w; -XtPointer client_data; -XEvent *event; -Boolean *continue_to_dispatch; -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesStructureNotify called\n",(XCursesProcess)?" X":"CURSES"); -#endif - -#if 0 -printf("Notify: %d\n",event->type); -#endif - switch(event->type) - { - case ConfigureNotify: -#ifdef PDCDEBUG - say("ConfigureNotify received\n"); -#endif - /* window has been resized, change width and - * height to send to place_text and place_graphics - * in next Expose. - * Also will need to kill (SIGWINCH) curses process if screen - * size changes - */ - resizeXCursesWindowWidth = (event->xconfigure.width); - resizeXCursesWindowHeight = (event->xconfigure.height); - after_first_curses_request = False; -#ifdef SIGWINCH -# ifdef BEFORE_CHANGE_BY_G_FUCHS -/* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ -# else - SP->resized = 1; -# endif - kill(otherpid,SIGWINCH); -#endif -#if 000 - SP->lines = XCursesLINES = ((resizeXCursesWindowHeight-(2*XCURSESBORDERWIDTH)) / XCursesFontHeight); - LINES = XCursesLINES - SP->linesrippedoff - SP->slklines; - SP->cols = COLS = XCursesCOLS = ((resizeXCursesWindowWidth-(2*XCURSESBORDERWIDTH)) / XCursesFontWidth); -printf("X11:LINES %d COLS %d\n",SP->lines, SP->cols); -#endif - XCursesSendKeyToCurses( (unsigned long)KEY_RESIZE, NULL ); - break; - case MapNotify: -#ifdef PDCDEBUG - say("MapNotify received\n"); -#endif - ReceivedMapNotify=1; - /* - * Draw the window border - */ - if (XCURSESBORDERWIDTH) - XDrawRectangle(XCURSESDISPLAY,XCURSESWIN,border_gc, - (XCURSESBORDERWIDTH/2),(XCURSESBORDERWIDTH/2), - (XCursesWindowWidth-XCURSESBORDERWIDTH), - (XCursesWindowHeight-XCURSESBORDERWIDTH)); - break; - default: -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesStructureNotify - unknown event %d\n",(XCursesProcess)?" X":"CURSES",event->type); -#endif - break; - } - return; -} diff --git a/x11/thread/x11.h b/x11/thread/x11.h deleted file mode 100644 index 0e733eb8..00000000 --- a/x11/thread/x11.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifdef HAVE_PROTO -void dummy_function(void); -void get_GC(Display *,Window, GC *, XFontStruct *,int ,int, bool ); -void makeXY(int ,int ,int ,int ,int *,int *); -int get_colors(void); -void start_event_handler(void); -int XCursesTransformLine(int ,int ,chtype ,int ,int,int,char *); -int XCursesDisplayText(chtype *, int, int, int,bool); -void XCursesDisplayScreen(bool); -void XCursesDisplayCursor( int ,int ,int ,int ); -void XCursesStructureNotify(Widget,XtPointer ,XEvent *,Boolean *); -void XCursesEnterLeaveWindow(Widget,XtPointer ,XEvent *,Boolean *); -void XCursesPasteSelection(Widget,XButtonEvent *); -void XCursesHandleString(Widget,XEvent *,String *,Cardinal *); -void XCursesKeyPress(Widget,XEvent *,String *,Cardinal *); -void XCursesModifierPress(Widget,XEvent *,String *,Cardinal *); -Boolean XCursesConvertProc(Widget,Atom *,Atom *,Atom *,XtPointer *,unsigned long *,int *); -void XCursesLoseOwnership(Widget,Atom *); -void XCursesRequestorCallbackForPaste(Widget,XtPointer,Atom *,Atom *,XtPointer,unsigned long *,int *); -void XCursesRequestorCallbackForGetSelection(Widget,XtPointer,Atom *,Atom *,XtPointer,unsigned long *,int *); -RETSIGTYPE XCursesSignalHandler(int); -void XCursesExitXCursesProcess(int,int,char *); -void SelectionOff(void); -void SelectionOn(int,int); -void SelectionExtend(int,int); -void SelectionSet( void ); - -int write_socket(int,char *,int); -int read_socket(int,char *,int); -int XCursesSetupX(char *display_name,int argc, char *argv[]); -RETSIGTYPE XCursesSigwinchHandler(int signo); -#else -void dummy_function(void); -void get_GC(); -void makeXY(); -int get_colors(); -void start_event_handler(); -int XCursesTransformLine(); -int XCursesDisplayText(); -void XCursesDisplayScreen(); -void XCursesDisplayCursor(); -void XCursesStructureNotify(); -void XCursesEnterLeaveWindow(); -void XCursesHandleString(); -void XCursesKeyPress(); -void XCursesModifierPress(); -void XCursesPasteSelection(); -Boolean XCursesConvertProc(); -void XCursesLoseOwnership(); -void XCursesRequestorCallbackForPaste(); -void XCursesRequestorCallbackForGetSelection(); -RETSIGTYPE XCursesSignalHandler(); -void XCursesExitXCursesProcess(); -void SelectionOff(); -void SelectionOn(); -void SelectionExtend(); -void SelectionSet(); - -int write_socket(); -int read_socket(); -int XCursesSetupX(); -RETSIGTYPE XCursesSigwinchHandler(); -#endif - -#ifdef _HPUX_SOURCE -# define FD_SET_CAST int * -#else -# define FD_SET_CAST fd_set * -#endif -extern fd_set readfds; -extern fd_set writefds; -extern struct timeval socket_timeout; - -extern unsigned char *Xcurscr; -extern int XCursesLINES; -extern int XCursesCOLS; -extern unsigned char *atrtab; - -typedef struct key_queue_type -{ - int key; - MOUSE_STATUS mouse; -} key_queue_t; - -extern key_type_t key_queue; diff --git a/x11/thread/x11common.c b/x11/thread/x11common.c deleted file mode 100644 index ba13a547..00000000 --- a/x11/thread/x11common.c +++ /dev/null @@ -1,100 +0,0 @@ -/* -*************************************************************************** -* This file comprises part of PDCurses. PDCurses is Public Domain software. -* You may use this code for whatever purposes you desire. This software -* is provided AS IS with NO WARRANTY whatsoever. -* Should this software be used in another application, an acknowledgement -* that PDCurses code is used would be appreciated, but is not mandatory. -* -* Any changes which you make to this software which may improve or enhance -* it, should be forwarded to the current maintainer for the benefit of -* other users. -* -* The only restriction placed on this code is that no distribution of -* modified PDCurses code be made under the PDCurses name, by anyone -* other than the current maintainer. -* -* See the file maintain.er for details of the current maintainer. -* -* This file is NOT public domain software. It is Copyright, Mark Hessling -* 1994-2000. -*************************************************************************** -*/ - -#include "pdcx11.h" -/* - * Variables specific to thread port - */ -unsigned char *Xcurscr; -int XCursesProcess=1; -int XCursesLINES=24; -int XCursesCOLS=80; - -/***********************************************************************/ -#ifdef HAVE_PROTO -int read_socket(int sock_num,char *buf,int len) -#else -int read_socket(sock_num,buf,len) -int sock_num; -char *buf; -int len; -#endif -/***********************************************************************/ -{ - int start=0,length=len,rc; -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:read_socket called: sock_num %d len %d\n",(XCursesProcess)?" X":"CURSES",sock_num,len); -#endif - while(1) - { - rc = read(sock_num,buf+start,length); -#ifdef MOUSE_DEBUG1 - if (sock_num == key_sock) - printf("%s:read_socket(key) rc %d errno %d resized: %d\n",(XCursesProcess)?" X":"CURSES", - rc,errno,SP->resized); -#endif - if (rc < 0 - && sock_num == key_sock - && errno == EINTR -#ifdef BEFORE_CHANGE_BY_G_FUCHS -/* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - && SP->resized == TRUE) - { -#ifdef MOUSE_DEBUG1 - printf("%s:continuing\n",(XCursesProcess)?" X":"CURSES"); -#endif - rc = 0; -#else - && SP->resized != FALSE) - { -#ifdef MOUSE_DEBUG1 - printf("%s:continuing\n",(XCursesProcess)?" X":"CURSES"); -#endif - rc = 0; - if (SP->resized > 1) - SP->resized = TRUE; - else - SP->resized = FALSE; -#endif - memcpy(buf,(char *)&rc,sizeof(int)); - return(0); /* must be >= 0 to avoid error */ - } - -#ifdef BEFORE_CHANGE_BY_G_FUCHS -/* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - if (rc < 0 -#else - if (rc <= 0 -#endif - || rc == length) - return(rc); - length -= rc; - start = rc; - } -} diff --git a/x11/thread/x11curses.c b/x11/thread/x11curses.c deleted file mode 100644 index 88d103d1..00000000 --- a/x11/thread/x11curses.c +++ /dev/null @@ -1,675 +0,0 @@ -/* -*************************************************************************** -* This file comprises part of PDCurses. PDCurses is Public Domain software. -* You may use this code for whatever purposes you desire. This software -* is provided AS IS with NO WARRANTY whatsoever. -* Should this software be used in another application, an acknowledgement -* that PDCurses code is used would be appreciated, but is not mandatory. -* -* Any changes which you make to this software which may improve or enhance -* it, should be forwarded to the current maintainer for the benefit of -* other users. -* -* The only restriction placed on this code is that no distribution of -* modified PDCurses code be made under the PDCurses name, by anyone -* other than the current maintainer. -* -* See the file maintain.er for details of the current maintainer. -* -* This file is NOT public domain software. It is Copyright, Mark Hessling -* 1994-2000. -*************************************************************************** -*/ - -/* - * This file contains functions that are called by the "curses" thread; - * ie the parent thread. - */ - -/* - * Communications required between threads: - * - * Thread Action Name Purpose - * ----------------------------------------------------------------- - * parent write dis_w dis_pipe[1] send requests to X thread such as - * display cursor, refresh - * child read dis_r dis_pipe[0] read requests from parent thread - * parent read key_r key_pipe[0] read key/mouse/clipboard from X11 - * thread - * child write key_r key_pipe[1] write key/mouse/clipboard to parent - * thread. NOTE. PIPE_BUF size and - * size of clipboard!! - * Need a semaphore or similar to allow child thread to let the parent - * know when it has completed the actions given by a write on dis_w - * When using socketpairs, this is the same socket, as these are bidirectional - */ - -#include "pdcx11.h" - -#ifdef PROTO -static void XCursesExitCursesProcess(int, char *); -#else -static void XCursesExitCursesProcess(); -#endif - -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCursesResizeScreen(int nlines, int ncols) -#else -int XCursesResizeScreen(nlines, ncols) -int nlines,ncols; -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesResizeScreen() - called: Lines: %d Cols: %d\n",(XCursesProcess)?" X":"CURSES",nlines,ncols); -#endif - shmdt((char *)Xcurscr); - XCursesInstructAndWait(CURSES_RESIZE); - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - kill(otherpid,SIGKILL); - return(ERR); - } - XCursesLINES = SP->lines; - XCursesCOLS = SP->cols; -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:shmid_Xcurscr %d shmkey_Xcurscr %d SP->lines %d SP->cols %d\n",(XCursesProcess)?" X":"CURSES",shmid_Xcurscr,shmkey_Xcurscr,SP->lines,SP->cols); -#endif - Xcurscr = (unsigned char*)shmat(shmid_Xcurscr,0,0); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - SP->resized=FALSE; - return(OK); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCurses_display_cursor(int oldrow, int oldcol, int newrow,int newcol,int visibility) -#else -int XCurses_display_cursor(oldrow,oldcol,newrow,newcol,visibility) -int oldrow,oldcol,newrow,newcol,visibility; -#endif -/***********************************************************************/ -{ - char buf[30]; - int idx,pos; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_display_cursor() - called: NEW row %d col %d, vis %d\n", - (XCursesProcess)?"X":"CURSES",newrow,newcol,visibility); -#endif - - if ( visibility == -1 ) - { - /* - * Only send the CURSES_DISPLAY_CURSOR message, no data - */ - idx = CURSES_DISPLAY_CURSOR; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); - } - else - { - idx = CURSES_CURSOR; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); - pos = oldrow + (oldcol << 8); - memcpy(buf+idx,(char *)&pos,sizeof(int)); - idx += sizeof(int); - pos = newrow + (newcol << 8); - memcpy(buf+idx,(char *)&pos,sizeof(int)); - idx += sizeof(int); - } - - if (write_socket(display_sock,buf,idx) < 0) - XCursesExitCursesProcess(1,"exitting from XCurses_display_cursor"); - - return(OK); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCurses_set_title(char *title) -#else -void XCurses_set_title(title) -char *title; -#endif -/***********************************************************************/ -{ - char buf[30]; - int idx,len; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_set_title() - called: TITLE: %s\n", - (XCursesProcess)?"X":"CURSES",title); -#endif - - idx = CURSES_TITLE; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); - len = strlen(title)+1; /* write nul character */ - memcpy(buf+idx,(char *)&len,sizeof(int)); - idx += sizeof(int); - - if (write_socket(display_sock,buf,idx) < 0) - XCursesExitCursesProcess(1,"exitting from XCurses_set_title"); - - if (write_socket(display_sock,title,len) < 0) - XCursesExitCursesProcess(1,"exitting from XCurses_set_title"); - - return; -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCurses_refresh_scrollbar(void) -#else -int XCurses_refresh_scrollbar() -#endif -/***********************************************************************/ -{ - char buf[30]; - int idx; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_refresh_scrollbar() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - - idx = CURSES_REFRESH_SCROLLBAR; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); - - if (write_socket(display_sock,buf,idx) < 0) - XCursesExitCursesProcess(1,"exitting from XCurses_refresh_scrollbar"); - - return(OK); -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCurses_rawgetch( int delaytenths) -#else -int XCurses_rawgetch( delaytenths ) -int delaytenths; -#endif -/***********************************************************************/ -{ - unsigned long newkey=0; - int key=0; - char buf[100]; /* big enough for MOUSE_STATUS struct */ - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_rawgetch() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - - while(1) - { - if ( delaytenths && !XCurses_kbhit() ) - { - key = -1; - } - else - { - if (read_socket(key_sock,buf,sizeof(unsigned long)) < 0) - XCursesExitCursesProcess(2,"exiting from XCurses_rawchar"); /* what else ?? */ - memcpy((char *)&newkey,buf,sizeof(unsigned long)); - pdc_key_modifier = (newkey >> 24) & 0xFF; /*(sizeof(unsigned long) - sizeof(unsigned char)); */ - key = (int)(newkey & 0x00FFFFFF); - } -#if 0 - printf("%s:reading %d mod %ld\n",(XCursesProcess)?" X":"CURSES",key,pdc_key_modifier); -#endif - if (key == KEY_MOUSE) - { - if (read_socket(key_sock,buf,sizeof(MOUSE_STATUS)) < 0) - XCursesExitCursesProcess(2,"exitting from XCurses_rawchar"); /* what else ?? */ - memcpy((char *)&Trapped_Mouse_status,buf,sizeof(MOUSE_STATUS)); - /* - * Check if the mouse has been clicked on a slk area. If the return - * value is > 0 (indicating the - * label number, return with the KEY_F(key) value. - */ -/*fprintf(stderr,"%d %d %x\n",TRAPPED_MOUSE_Y_POS,TRAPPED_MOUSE_X_POS,SP->slk_winptr);*/ - if ((newkey = PDC_mouse_in_slk(TRAPPED_MOUSE_Y_POS,TRAPPED_MOUSE_X_POS))) - { - if (TRAPPED_BUTTON_STATUS(1) & BUTTON_PRESSED) - { - key = KEY_F(newkey); - break; - } - } - else - { - if ( key == KEY_RESIZE) - { -#if 000 - LINES = XCursesLINES = SP->lines - SP->linesrippedoff - SP->slklines; - XCursesCOLS = COLS = SP->cols; -printf("LINES %d COLS %d\n",LINES,COLS); -#endif - } - } - break; - -#ifdef MOUSE_DEBUG - printf("rawgetch-x: %d y: %d Mouse status: %x\n", - MOUSE_X_POS, - MOUSE_Y_POS, - Mouse_status.changes); - printf("rawgetch-Button1: %x Button2: %x Button3: %x\n", - BUTTON_STATUS(1), - BUTTON_STATUS(2), - BUTTON_STATUS(3)); -#endif - } - else - break; - } - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_rawgetch() - key %d returned\n",(XCursesProcess)?" X":"CURSES",key); -#endif - return(key); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCurses_get_input_fd(void) -#else -int XCurses_get_input_fd() -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_get_input_fd() - called\n",(XCursesProcess)?" X":"CURSES"); - if (trace_on) PDC_debug("%s:XCurses_get_input_fd() - returning %i\n",(XCursesProcess)?" X":"CURSES",key_sock); -#endif - return key_sock; -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -bool XCurses_kbhit(void) -#else -bool XCurses_kbhit() -#endif -/***********************************************************************/ -{ - int s; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_kbhit() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - /* - * Is something ready to be read on the socket ? Must be a key. - */ - FD_ZERO( &readfds ); - FD_SET( key_sock, &readfds ); - if ( ( s = select ( FD_SETSIZE, (FD_SET_CAST)&readfds, NULL, NULL, &socket_timeout ) ) < 0 ) - XCursesExitCursesProcess(3,"child - exiting from XCurses_kbhit select failed"); - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_kbhit() - returning %s\n",(XCursesProcess)?" X":"CURSES",(s == 0) ? "FALSE" : "TRUE"); -#endif - if ( s == 0 ) - return(FALSE); - return(TRUE); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCursesInstruct(int flag) -#else -int XCursesInstruct(flag) -int flag; -#endif -/***********************************************************************/ -{ - char buf[10]; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesInstruct() - called flag %d\n",(XCursesProcess)?" X":"CURSES",flag); -#endif - /* - * Send a request to X... - */ - memcpy(buf,(char *)&flag,sizeof(int)); - if (write_to_child(dis_w,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(4,"exitting from XCursesInstruct"); - return(OK); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCursesInstructAndWait(int flag) -#else -int XCursesInstructAndWait(flag) -int flag; -#endif -/***********************************************************************/ -{ - int result; - char buf[10]; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesInstructAndWait() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - /* - * Tell X we want to do something... - */ - XCursesInstruct(flag); - /* - * ... wait for X to say the refresh has occurred. - */ - if (read_from_chil(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCursesInstructAndWait"); - memcpy((char *)&result,buf,sizeof(int)); - if (result != CURSES_CONTINUE) - XCursesExitCursesProcess(6,"exitting from XCursesInstructAndWait - synchronization error"); - return(OK); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCurses_transform_line(chtype *ch, int row, int start_col, int num_cols) -#else -int XCurses_transform_line(ch, row, start_col, num_cols) -chtype *ch; -int row,start_col,num_cols; -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_transform_line() called: row %d start_col %d num_cols %d flag %d\n", - (XCursesProcess)?"X":"CURSES",row,start_col,num_cols,*(Xcurscr+XCURSCR_FLAG_OFF+row)); -#endif - - while(*(Xcurscr+XCURSCR_FLAG_OFF+row)) - /* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - dummy_function(); /* loop until we can write to the line */ - /* - * End of patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - - *(Xcurscr+XCURSCR_FLAG_OFF+row) = 1; - memcpy(Xcurscr+XCURSCR_Y_OFF(row)+(start_col*sizeof(chtype)),ch,num_cols*sizeof(chtype)); -#if 0 - *((int*)(Xcurscr+XCURSCR_START_OFF+row)) = start_col; - *((int*)(Xcurscr+XCURSCR_LENGTH_OFF+row)) = num_cols; - if ( (int)*(Xcurscr+XCURSCR_START_OFF+row) != start_col ) - printf("%d difference: start_col %d mem: %d\n",__LINE__,start_col,(int)*(Xcurscr+XCURSCR_START_OFF+row) ); - if ( (int)*(Xcurscr+XCURSCR_LENGTH_OFF+row) != num_cols ) - printf("%d difference: num_cols %d mem: %d\n",__LINE__,num_cols,(int)*(Xcurscr+XCURSCR_LENGTH_OFF+row) ); -#else - *(Xcurscr+XCURSCR_START_OFF+row) = start_col; - *(Xcurscr+XCURSCR_LENGTH_OFF+row) = num_cols; -#endif - *(Xcurscr+XCURSCR_FLAG_OFF+row) = 0; - return(0); -} -/***********************************************************************/ -#ifdef HAVE_PROTO -static int XCursesSetupCurses(void) -#else -static int XCursesSetupCurses() -#endif -/***********************************************************************/ -{ - char wait_buf[5]; - int wait_value; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesSetupCurses called\n",(XCursesProcess)?" X":"CURSES"); -#endif - close ( display_sockets[1] ); - close ( key_sockets[1] ); - display_sock = display_sockets[0]; - key_sock = key_sockets[0]; - FD_ZERO ( &readfds ); - FD_ZERO ( &writefds ); - read_socket(display_sock,wait_buf,sizeof(int)); - memcpy((char *)&wait_value,wait_buf,sizeof(int)); - if (wait_value != CURSES_CHILD) - return(ERR); - /* - * Set LINES and COLS now so that the size of the - * shared memory segment can be allocated - */ - if ((shmidSP = shmget(shmkeySP,sizeof(SCREEN)+XCURSESSHMMIN,0700)) < 0) - { - perror("Cannot allocate shared memory for SCREEN"); - kill(otherpid,SIGKILL); - return(ERR); - } - SP = (SCREEN*)shmat(shmidSP,0,0); - XCursesLINES = SP->lines; - LINES = XCursesLINES - SP->linesrippedoff - SP->slklines; - XCursesCOLS = COLS = SP->cols; - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - kill(otherpid,SIGKILL); - return(ERR); - } -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:shmid_Xcurscr %d shmkey_Xcurscr %d LINES %d COLS %d\n",(XCursesProcess)?" X":"CURSES",shmid_Xcurscr,shmkey_Xcurscr,LINES,COLS); -#endif - Xcurscr = (unsigned char *)shmat(shmid_Xcurscr,0,0); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - PDC_init_atrtab(); -#ifdef PDCDEBUG - say ("cursesprocess exiting from Xinitscr\n"); -#endif - /* - * Always trap SIGWINCH if the C library supports SIGWINCH... - */ - XCursesSetSignal(SIGWINCH, XCursesSigwinchHandler ); - return(OK); -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCursesInitscr(char *display_name, int argc, char *argv[]) -#else -int XCursesInitscr(display_name,argc,argv) -char *display_name; -int argc; -char *argv[]; -#endif -/***********************************************************************/ -{ - int pid,rc; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesInitscr() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - -#if defined FOREIGN - if (setlocale(LC_ALL, "") == NULL) - { - fprintf(stderr, "ERROR: cannot set locale\n"); - return(ERR); - } -/* - * Shouldn't this code be in x11.c with the X11 thread stuff ?? - */ - if (!XSupportsLocale()) - { - fprintf(stderr, "ERROR: X does not support locale\n"); - return(ERR); - } - if (XSetLocaleModifiers("") == NULL) - fprintf(stderr, "WARNING: Cannot set locale modifiers\n"); -#endif - - if ( pipe( dis_pipe ) < 0 ) - { - fprintf(stderr, "ERROR: cannot create display pipe\n"); - return(ERR); - } - dis_r = dis_pipe[0]; - dis_w = dis_pipe[1]; - - if ( pipe( key_pipe ) < 0 ) - { - fprintf(stderr, "ERROR: cannot create key pipe\n"); - return(ERR); - } - key_r = key_pipe[0]; - key_w = key_pipe[1]; - - tid = pthread_create(&tid, XCursesSetupX(), NULL, ) - pid = fork(); - switch(pid) - { - case (-1): - fprintf(stderr,"ERROR: cannot fork()\n"); - return(ERR); - break; - case 0: /* child */ - shmkey_Xcurscr = getpid(); -#ifdef XISPARENT - XCursesProcess=0; - rc = XCursesSetupCurses(); -#else - XCursesProcess=1; - otherpid = getppid(); - rc = XCursesSetupX(display_name,argc,argv); -#endif - break; - default: /* parent */ - shmkey_Xcurscr = pid; -#ifdef XISPARENT - XCursesProcess=1; - otherpid = pid; - rc = XCursesSetupX(display_name,argc,argv); -#else - XCursesProcess=0; - rc = XCursesSetupCurses(); -#endif - break; - } - return(rc); -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCurses_getclipboard( char **contents, long *length ) -#else -int XCurses_getclipboard( contents, length ) -char **contents; -long *length; -#endif -/***********************************************************************/ -{ - int result=0; - int len; - char buf[12]; - -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_getclipboard() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - XCursesInstructAndWait(CURSES_GET_SELECTION); - - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_getclipboard"); - memcpy((char *)&result,buf,sizeof(int)); - if (result == PDC_CLIP_SUCCESS) - { - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_getclipboard"); - memcpy((char *)&len,buf,sizeof(int)); - if (len != 0) - { - *contents = (char *)malloc(len+1); - if (!*contents) - XCursesExitCursesProcess(6,"exitting from XCurses_getclipboard - synchronization error"); - if (read_socket(display_sock,*contents,len) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_getclipboard"); - *length = len; - } - } - return result; -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -int XCurses_setclipboard( char *contents, long length ) -#else -int XCurses_setclipboard( contents, length ) -char *contents; -long length; -#endif -/***********************************************************************/ -{ - int rc=0; - char buf[12]; /* big enough for 2 integers */ - long len=length; -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCurses_setclipboard() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - XCursesInstruct(CURSES_SET_SELECTION); - memcpy(buf,(char *)&len,sizeof(long)); - if (write_socket(display_sock,buf,sizeof(long)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_setclipboard"); - if (write_socket(display_sock,contents,length) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_setclipboard"); - /* - * Wait for X to do its stuff. Now expect return code... - */ - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_setclipboard"); - memcpy((char *)&rc,buf,sizeof(int)); - return rc; -} - -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCursesCleanupCursesProcess(int rc) -#else -void XCursesCleanupCursesProcess(rc) -int rc; -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesCleanupCursesProcess() - called: %d\n",(XCursesProcess)?" X":"CURSES",rc); -#endif - close(display_sock); - close(key_sock); - if (rc) - _exit(rc); - else - return; -} -/***********************************************************************/ -#ifdef HAVE_PROTO -static void XCursesExitCursesProcess(int rc,char *msg) -#else -static void XCursesExitCursesProcess(rc,msg) -int rc; -char *msg; -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesExitCursesProcess() - called: %d %s\n",(XCursesProcess)?" X":"CURSES",rc,msg); -#endif - endwin(); - XCursesCleanupCursesProcess(rc); - return; -} -/***********************************************************************/ -#ifdef HAVE_PROTO -void XCursesExit(void) -#else -void XCursesExit() -#endif -/***********************************************************************/ -{ -#ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesExit() - called\n",(XCursesProcess)?" X":"CURSES"); -#endif - XCursesInstruct(CURSES_EXIT); - XCursesCleanupCursesProcess(0); - return; -}