/* * $Id: kxterm.c,v 1.1.1.1 1996/03/08 15:33:04 mclareni Exp $ * * $Log: kxterm.c,v $ * Revision 1.1.1.1 1996/03/08 15:33:04 mclareni * Kuip * */ /*CMZ : 2.06/03 10/01/95 08.59.54 by N.Cremel*/ /*-- Author : Fons Rademakers 8/01/93*/ /*********************************************************************** * * * KXTERM -- Kuip Terminal Emulator. * * * * This terminal emulator combines the best features from the (now * * defunct) Apollo DM pads (like: input and transcript pads, * * automatic file backup of transcript, search in transcript pad, * * etc.) and the Korn shell emacs-style command line editing and * * command line recall mechanism. * * * ***********************************************************************/ #include "kuip/kuip.h" #include #include #include #include #include #include #include #if defined(__hpux) && XtSpecificationRelease == 4 #include #else #include #endif #include #include #include "menu.h" #include "utils.h" #include "actions.h" #include "uxxt.h" #if defined(CERNLIB_VMS) #include "kuip/mkqio.h" #endif #define strrstr my_strrstr #if defined(__hpux) #undef strrstr #endif #define MAX_CMD_LENGTH 512 #define INC_LENGTH 128 #define MAX_FILE_LENGTH 256 #define MAX_ITEMS 30 #define CURSOR 1 #define LINE 2 #define ESCAPE "#@" /* escape sequence for special kxterm commands */ #define STX '\2' /* Start Transmission: application is ready */ #ifdef _NO_PROTO # define ZEROargs #else # define ZEROargs void #endif /* kxterm icon */ #define kxterm_width 50 #define kxterm_height 50 static char kxterm_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x80, 0x01, 0x00, 0xc0, 0x55, 0x55, 0x55, 0x55, 0x06, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x55, 0x55, 0x55, 0x55, 0x05, 0x00, 0x40, 0xaa, 0xaa, 0xaa, 0xaa, 0x06, 0x00, 0x40, 0xfd, 0xff, 0xff, 0xff, 0x05, 0x00, 0x40, 0xfe, 0xff, 0xff, 0x7f, 0x06, 0x00, 0x40, 0x0d, 0x00, 0xe0, 0x7f, 0x05, 0x00, 0x40, 0xee, 0xff, 0xef, 0x7f, 0x06, 0x00, 0x40, 0xed, 0xff, 0xeb, 0x7f, 0x05, 0x00, 0x40, 0xee, 0xff, 0xef, 0x7f, 0x06, 0x00, 0x40, 0xed, 0xff, 0xef, 0x7f, 0x05, 0x00, 0x40, 0x0e, 0x00, 0xe0, 0x7f, 0x06, 0x00, 0x40, 0xed, 0xff, 0xef, 0x7f, 0x05, 0x00, 0x40, 0x2e, 0xfe, 0xeb, 0x7f, 0x06, 0x00, 0x40, 0xed, 0xff, 0x0f, 0x40, 0x05, 0x00, 0x40, 0xee, 0xff, 0xef, 0x5f, 0x06, 0x00, 0x40, 0xed, 0xff, 0xef, 0x5f, 0x05, 0x00, 0x40, 0x0e, 0x00, 0xe0, 0x5f, 0x06, 0x00, 0x40, 0xfd, 0x7f, 0xff, 0x5f, 0x05, 0x00, 0x40, 0xfe, 0x7f, 0xff, 0x5f, 0x06, 0x00, 0x40, 0xfd, 0x7f, 0xf1, 0x5f, 0x05, 0x00, 0x40, 0xfe, 0x7f, 0xff, 0x5f, 0x06, 0x00, 0x40, 0xfd, 0x7f, 0x00, 0x40, 0x05, 0x00, 0x40, 0xfe, 0xff, 0xff, 0x7f, 0x06, 0x00, 0x40, 0xfd, 0xff, 0xff, 0x7f, 0x05, 0x00, 0x40, 0xfe, 0xff, 0xff, 0x7f, 0x06, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x40, 0xaa, 0xaa, 0xaa, 0xaa, 0x06, 0x00, 0x40, 0x55, 0x55, 0x55, 0x55, 0x05, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0xc0, 0x50, 0x55, 0x15, 0x2a, 0x02, 0x00, 0x60, 0xa8, 0xaa, 0x2a, 0x54, 0x04, 0x00, 0x30, 0x54, 0x55, 0x55, 0xa8, 0x08, 0x00, 0x18, 0xaa, 0xaa, 0xaa, 0x50, 0x11, 0x00, 0x0c, 0x15, 0x00, 0x40, 0xa1, 0x22, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xac, 0xaa, 0xaa, 0xaa, 0xaa, 0x6a, 0x00, 0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; /* Start houglass bitmaps (for wait_cursor) */ #define hourglass_width 32 #define hourglass_height 32 #define hourglass_x_hot 15 #define hourglass_y_hot 15 static char hourglass_bits[] = { 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0x40, 0x00, 0x00, 0x01, 0xe0, 0xff, 0xff, 0x03, 0x60, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 0x03, 0x60, 0xc0, 0x01, 0x03, 0xc0, 0xa8, 0x8e, 0x01, 0x80, 0x55, 0xdd, 0x00, 0x00, 0xab, 0x6f, 0x00, 0x00, 0x56, 0x37, 0x00, 0x00, 0xec, 0x1b, 0x00, 0x00, 0xd8, 0x0d, 0x00, 0x00, 0xb0, 0x06, 0x00, 0x00, 0xa0, 0x02, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0xb0, 0x06, 0x00, 0x00, 0x98, 0x0c, 0x00, 0x00, 0x8c, 0x18, 0x00, 0x00, 0x06, 0x30, 0x00, 0x00, 0x83, 0x60, 0x00, 0x80, 0xc1, 0xc3, 0x00, 0xc0, 0xb0, 0x86, 0x01, 0x60, 0x5c, 0x1d, 0x03, 0x60, 0x2a, 0x39, 0x03, 0x60, 0xdd, 0x7f, 0x03, 0x60, 0x00, 0x00, 0x03, 0xe0, 0xff, 0xff, 0x03, 0x40, 0x00, 0x00, 0x01, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03}; #define hourglass_mask_width 32 #define hourglass_mask_height 32 static char hourglass_mask_bits []= { 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x01, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x01, 0x80, 0xff, 0xff, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x80, 0xff, 0xff, 0x00, 0xc0, 0xff, 0xff, 0x01, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x01, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03}; /* ... end houglass bitmaps */ /* extern functions */ extern Widget create_kuipIo(ZEROargs); /* routine created by Architect */ extern Widget create_saveAsTrDialog(ZEROargs); extern Widget create_inputTrDialog(ZEROargs); extern Widget create_searchDialog(ZEROargs); extern void warn_user( /* from dialog.c */ #ifndef _NO_PROTO Widget parent, char *warning #endif ); extern void inform_user( #ifndef _NO_PROTO Widget parent, char *warning #endif ); extern void help_cb( #ifndef _NO_PROTO Widget w, int *type, XmAnyCallbackStruct *call_data #endif ); extern void set_kxtpanel_rows ( #ifndef _NO_PROTO int nrow, int ncol, int last #endif ); extern void set_kxtpanel_keys ( #ifndef _NO_PROTO int row, int col, char *key #endif ); extern void display_kxtpanel ( #ifndef _NO_PROTO char *title, char *geometry #endif ); /* extern widgets */ extern Widget panedWindow; /* kuipIo interface */ extern Widget cwdLabel; extern Widget lcdLabel; extern Widget outputText; extern Widget outputHoldButton; extern Widget inputText; extern Widget inputHoldButton; extern Widget menuBar; extern Widget aboutButton; extern Widget aboutAppButton; extern Widget saveTransButton; extern Widget saveTransAsButton; extern Widget printButton; extern Widget killButton; extern Widget exitButton; extern Widget cutButton; extern Widget copyButton; extern Widget pasteButton; extern Widget searchButton; extern Widget showInputButton; extern Widget clearTrButton; extern Widget helpKxtermButton; extern Widget helpResourceButton; extern Widget helpEditButton; extern Widget closeInputTrButton; /* Input Transcript Dialog */ extern Widget inputTrText; extern Widget caseToggle; /* Search Dialog */ extern Widget previousSearchButton; extern Widget nextSearchButton; extern Widget allSearchButton; extern Widget closeSearchButton; extern Widget searchText; /* global functions */ void send_cmd( #ifndef _NO_PROTO char * #endif ); /* local functions */ static void exit_action( #ifndef _NO_PROTO char **, int #endif ); static void quit_action( #ifndef _NO_PROTO char **, int #endif ); static void cwd_action( #ifndef _NO_PROTO char **, int #endif ); static void lcd_action( #ifndef _NO_PROTO char **, int #endif ); static void prompt_action( #ifndef _NO_PROTO char **, int #endif ); static void raise_action( #ifndef _NO_PROTO char **, int #endif ); static void cursor_action( #ifndef _NO_PROTO char **, int #endif ); static void newpanel_action( #ifndef _NO_PROTO char **, int #endif ); static void panelrows_action( #ifndef _NO_PROTO char **, int #endif ); static void panelkeys_action( #ifndef _NO_PROTO char **, int #endif ); static void display_panel_action( #ifndef _NO_PROTO char **, int #endif ); static void SendSignal( #ifndef _NO_PROTO Widget, XEvent *, String *, Cardinal * #endif ); static void GetPreviousCommand( #ifndef _NO_PROTO Widget, XEvent *, String *, Cardinal * #endif ); static void ResubmitCommand( #ifndef _NO_PROTO Widget, XEvent *, String *, Cardinal * #endif ); static void ToggleHold( #ifndef _NO_PROTO Widget, XEvent *, String *, Cardinal * #endif ); static void application_cmd_cb( #ifndef _NO_PROTO Widget, char *, XmAnyCallbackStruct * #endif ); static void application_toggle_cb( #ifndef _NO_PROTO Widget, char*, XmToggleButtonCallbackStruct* #endif ); /* global data */ XtAppContext UxAppContext; Display *UxDisplay; int UxScreen; Colormap UxColormap; Widget UxTopLevel; Widget kuipIo; /* kxterm toplevel widget */ XtInputId input_id; Boolean hold_input; Boolean hold_output; Boolean do_flush = False; Boolean changing_text = False; Boolean stop_sending = False; Boolean flow_control = False; int dont_move = 0; Boolean application_alive = True; Boolean user_said_exit = False; int parent_pid = 0; char *application_prompt = NULL; char *application_name = NULL; char *prog_name; /* name of this invocation of kxterm */ char *input_tr_text = NULL; char *transcript_text = NULL; Boolean lower_text = False; char transcript_file[MAX_FILE_LENGTH]; /* transcript pad file */ FILE *tfp; /* file pointer to transcript_file */ Boolean tr_tmp_file = False; /* is transcript file a tmp file ? */ char last_command[MAX_CMD_LENGTH]; Boolean kxterm_iconic = False; Cursor main_cursor, wait_cursor; int Error; /* wanted by libPW.a routines */ /* * Action commands that can be send by an application to kxterm. */ static KxtermActionsRec kxterm_actions[] = { {"exit", exit_action}, /* exit of application and kxterm */ {"quit", quit_action}, /* quit of application */ {"cwd", cwd_action}, /* change the current working directory */ {"lcd", lcd_action}, /* change the system working directory */ {"prompt", prompt_action}, /* change the application prompt */ {"raise", raise_action}, /* pop up kxterm window */ {"cursor", cursor_action}, /* change kxterm cursor shape */ {"setnewpanel", newpanel_action}, /* display new KXTERM panel */ {"setpanelrows", panelrows_action}, /* set KXTERM panel nrow & ncol */ {"setpanelkeys", panelkeys_action}, /* et KXTERM panel keys */ {"display_panel", display_panel_action}, /* display KXTERM panel */ {NULL, NULL}, }; static String fallbacks[] = { "*selectColor: green", "*kuipIo_shell.geometry: +0+0", "*outputForm.height: 205", /* "*keyboardFocusPolicy: pointer",*/ "*doubleClickInterval: 400", NULL }; static XrmOptionDescRec options[] = { {"-name", "*kuipIo_shell.title", XrmoptionSepArg, NULL}, {"-name", "*kuipIo_shell.iconName", XrmoptionSepArg, NULL}, {"-title", "*kuipIo_shell.title", XrmoptionSepArg, NULL}, {"-n", "*kuipIo_shell.iconName", XrmoptionSepArg, NULL}, {"-geometry", "*kuipIo_shell.geometry", XrmoptionSepArg, NULL}, {"-iconic", "*kuipIo_shell.iconic", XrmoptionNoArg, "True"}, {"-tfont", "*XmText*fontList", XrmoptionSepArg, NULL}, {"-font", "*fontList", XrmoptionSepArg, NULL}, }; static XtActionsRec actions[] = { {"SendSignal", SendSignal}, {"GetPreviousCommand", GetPreviousCommand}, {"ResubmitCommand", ResubmitCommand}, {"ToggleHold", ToggleHold}, }; /* emacs translations for the inputText widget */ static char *translation_table = "Ctrl b: backward-character()\n\ Alt b: backward-word()\n\ Meta b: backward-word()\n\ Shift Alt b: backward-word(extend)\n\ Shift Meta b: backward-word(extend)\n\ Alt [: backward-paragraph()\n\ Meta [: backward-paragraph()\n\ Shift Alt [: backward-paragraph(extend)\n\ Shift Meta [: backward-paragraph(extend)\n\ Alt <: beginning-of-file()\n\ Meta <: beginning-of-file()\n\ Ctrl a: beginning-of-line()\n\ Shift Ctrl a: beginning-of-line(extend)\n\ Ctrl osfInsert: copy-clipboard()\n\ Shift osfDelete: cut-clipboard()\n\ Shift osfInsert: paste-clipboard()\n\ Alt >: end-of-file()\n\ Meta >: end-of-file()\n\ Ctrl e: end-of-line()\n\ Shift Ctrl e: end-of-line(extend)\n\ Ctrl f: forward-character()\n\ Alt ]: forward-paragraph()\n\ Meta ]: forward-paragraph()\n\ Shift Alt ]: forward-paragraph(extend)\n\ Shift Meta ]: forward-paragraph(extend)\n\ Ctrl Alt f: forward-word()\n\ Ctrl Meta f: forward-word()\n\ Ctrl d: kill-next-character()\n\ Alt BackSpace: kill-previous-word()\n\ Meta BackSpace: kill-previous-word()\n\ Ctrl w: key-select() kill-selection()\n\ Ctrl y: unkill()\n\ Ctrl k: kill-to-end-of-line()\n\ Ctrl u: beginning-of-line() kill-to-end-of-line()\n\ Alt Delete: kill-to-start-of-line()\n\ Meta Delete: kill-to-start-of-line()\n\ Ctrl o: newline-and-backup()\n\ Ctrl j: newline-and-indent()\n\ Ctrl n: next-line() GetPreviousCommand(NEXT)\n\ Ctrl osfLeft: page-left()\n\ Ctrl osfRight: page-right()\n\ Ctrl p: previous-line() GetPreviousCommand()\n\ Ctrl g: process-cancel()\n\ Ctrl l: redraw-display()\n\ Ctrl osfDown: next-page()\n\ Ctrl osfUp: previous-page()\n\ osfDown: next-line() GetPreviousCommand(NEXT)\n\ osfUp: previous-line() GetPreviousCommand()\n\ Ctrl space: set-anchor()\n\ Ctrl c: SendSignal(SIGINT)\n\ Ctrl h: ToggleHold()\n\ Shift F8: ResubmitCommand()\n\ F8: ResubmitCommand(EXEC)"; /*********************************************************************** * * * Free transcript text. * * * ***********************************************************************/ void free_transcript_text() { XtFree(transcript_text); transcript_text = NULL; lower_text = False; } /*********************************************************************** * * * Get a line from the text. Pos_type can be either CURSOR or LINE. * * When it is CURSOR pos is a cursor position in the text. When it * * is LINE and pos > 0 then it is a line pos from the beginning of * * the text and when pos < 0 then it is from the end of the text. * * The line returned should be freed by the calling routine to * * prevent memory loss and does not contain the \n character. * * * ***********************************************************************/ static char *get_line( text, pos, pos_type ) char *text; int pos; int pos_type; { char *s, *line = NULL; int pos1, pos2; if (!text || !*text) return NULL; switch (pos_type) { case CURSOR: /* * From pos search forward to the first '\n', then backwards * to the previous '\n'. */ pos2 = 0; if ((s = strchr(&text[pos], '\n'))) { pos2 = (int)(s - text); text[pos2] = '\0'; } if ((s = strrchr(text, '\n'))) { pos1 = (int)(s - text); line = XtMalloc(strlen(&text[pos1+1]) + 1); strcpy(line, &text[pos1+1]); } else { line = XtMalloc(strlen(text) + 1); strcpy(line, text); } if (pos2) text[pos2] = '\n'; break; case LINE: if (!pos) return NULL; pos1 = 0; if (pos > 0) { for (s = text; (s = strchr(s, '\n')) != NULL; s++) if (++pos1 == pos) { line = get_line(text, (int)(s - text), CURSOR); return line; } return NULL; } else { pos2 = 0; while ((s = strrchr(text, '\n'))) { if (pos2) text[pos2] = '\n'; if (--pos1 == pos) { line = get_line(text, (int)(s - text), CURSOR); return line; } pos2 = (int)(s - text); text[pos2] = '\0'; } if (pos2) text[pos2] = '\n'; return NULL; } break; } return line; } /*********************************************************************** * * * Insert a string at the end of a XmText widget. * * * ***********************************************************************/ void insert_string( text_widget, buf, show ) Widget text_widget; char *buf; int show; { XmTextPosition pos = XmTextGetLastPosition(text_widget); XmTextInsert(text_widget, pos, buf); if (show) { pos = XmTextGetLastPosition(text_widget); XmTextSetInsertionPosition(text_widget, pos); XmTextShowPosition(text_widget, pos); } /* write into transcript file */ if (tfp && text_widget == outputText) { fprintf(tfp, "%s", buf); /* * transcript_text is not valid anymore, * free the space and reset pointer */ free_transcript_text(); } } /*********************************************************************** * * * Checks if a line begins with a prompt. If it does it returns * * the length of the prompt otherwise 0. * * * ***********************************************************************/ int begins_with_prompt(char *line) { int len = 0; if (application_prompt) { char *s; int pl = strlen(application_prompt); /* simple case: direct match */ if (!strncmp(line, application_prompt, pl)) return pl; /* variable prompt of type: paw [xxx] */ if ((s = strchr(application_prompt, '['))) { int l = s - application_prompt + 1; int extra = pl-(strchr(application_prompt,']')-application_prompt+1); if (!strncmp(line, application_prompt, l)) { len = strchr(line, ']') - line + 1 + extra; if (len < 0) len = 0; } } } return len; } /*********************************************************************** * * * Show prompt in inputText widget. Kxterm is ready to send next * * command. * * * ***********************************************************************/ void show_prompt() { if (application_prompt) { char *input = XmTextGetString(inputText); XmTextPosition pos = XmTextGetInsertionPosition(inputText); /* don't insert more than one prompt */ if (begins_with_prompt(input)) { XtFree(input); return; } XmTextInsert(inputText, (XmTextPosition) 0, application_prompt); pos += strlen(application_prompt); XmTextSetInsertionPosition(inputText, pos); XtFree(input); } } /*********************************************************************** * * * Close transcript file and exit kxterm. * * * ***********************************************************************/ void exit_kxterm() { /* close transcript file and if it is a tmp file remove it */ if (tfp) { fclose(tfp); if (tr_tmp_file) remove(transcript_file); } exit(0); } /*********************************************************************** * * * Handle menu building escape commands coming from the application. * * * ***********************************************************************/ void menu_escape( cmd ) char *cmd; { char *s, *menu, *menu_name; Widget pulldown; MenuItem *menu_item; /* get name of menu, e.g. *FileMenu */ if ((s = strchr(cmd, ':'))) { menu = XtCalloc(s-cmd+1, 1); menu_name = XtCalloc(s-cmd+5+1, 1); strncpy(menu, cmd, s-cmd); sprintf(menu_name, "*%sMenu", menu); menu_item = (MenuItem *)XtMalloc(MAX_ITEMS*sizeof(MenuItem)); if (add_menu_items(s+1, application_cmd_cb, application_toggle_cb, menu_item, MAX_ITEMS)) { /* does menu already exist? */ pulldown = XtNameToWidget(menuBar, menu_name); if (pulldown) { /* add to existing pulldown menu */ BuildMenu(pulldown, XmMENU_PULLDOWN, menu, menu[0], menu_item, True); } else { /* create new pulldown menu */ BuildMenu(menuBar, XmMENU_PULLDOWN, menu, menu[0], menu_item, False); } } XtFree((char *)menu_item); XtFree(menu); XtFree(menu_name); } } /*********************************************************************** * * * Handle exit action coming from the application. * * * ***********************************************************************/ static void exit_action( argv, argc ) char **argv; int argc; { user_said_exit = True; } /*********************************************************************** * * * Handle quit action coming from the application. * * * ***********************************************************************/ static void quit_action( argv, argc ) char **argv; int argc; { user_said_exit = True; } /*********************************************************************** * * * Handle cwd action coming from the application. * * This action displays the current working directory in the * * cwdLabel widget. * * * ***********************************************************************/ static void cwd_action( argv, argc ) char **argv; int argc; { XmString xms; if (argc) xms = XmStringCreate(argv[0], XmSTRING_DEFAULT_CHARSET); else xms = XmStringCreate("", XmSTRING_DEFAULT_CHARSET); XtVaSetValues(cwdLabel, XmNlabelString, xms, NULL); XmStringFree(xms); } /*********************************************************************** * * * Handle lcd action coming from the application. * * This action displays the current system working directory in the * * lcdLabel widget. The system working directory is changed by the * * kuip command lcd. * * * ***********************************************************************/ static void lcd_action( argv, argc ) char **argv; int argc; { XmString xms; if (argc) xms = XmStringCreate(argv[0], XmSTRING_DEFAULT_CHARSET); else xms = XmStringCreate("", XmSTRING_DEFAULT_CHARSET); XtVaSetValues(lcdLabel, XmNlabelString, xms, NULL); XmStringFree(xms); } /*********************************************************************** * * * Handle prompt action coming from the application. * * This action changes the application_prompt. * * * ***********************************************************************/ static void prompt_action( argv, argc ) char **argv; int argc; { char *newp; if (argc) { if (strempty(argv[0])) newp = NULL; else if (argv[0][strlen(argv[0])-1] != ' ') { /* prompt should end with ' ' */ newp = malloc(strlen(argv[0]) + 2); sprintf(newp, "%s ", argv[0]); } else newp = strdup(argv[0]); } else newp = NULL; if (application_prompt) { int lnew = strlen(newp); char *input = XmTextGetString(inputText); XmTextPosition pos = XmTextGetInsertionPosition(inputText); XFlush(UxDisplay); changing_text = True; /* replace old prompt by new prompt */ if (!strncmp(input, application_prompt, strlen(application_prompt))) { XmTextReplace(inputText, (XmTextPosition) 0, (XmTextPosition) strlen(application_prompt), newp); } else XmTextInsert(inputText, (XmTextPosition) 0, newp); /* changing_text = False; */ if (newp) pos += lnew - strlen(application_prompt); else pos -= strlen(application_prompt); if (pos < lnew) pos = lnew; XmTextSetInsertionPosition(inputText, pos); XFlush(UxDisplay); changing_text = False; XtFree(input); free(application_prompt); if (newp) application_prompt = strdup(newp); else application_prompt = NULL; } else { if (newp) application_prompt = strdup(newp); else application_prompt = NULL; show_prompt(); } if (newp) free(newp); } /*********************************************************************** * * * Handle raise action coming from the application. * * This action popups the executive window. * * * ***********************************************************************/ static void raise_action( argv, argc ) char **argv; int argc; { XtPopup( XtParent(kuipIo), XtGrabNone ); XMapRaised(XtDisplay(kuipIo), XtWindow(XtParent(kuipIo))); XFlush(XtDisplay(kuipIo)); } /*********************************************************************** * * * Handle raise action coming from the application. * * This action popups the executive window. * * * ***********************************************************************/ static void cursor_action( argv, argc ) char **argv; int argc; { XSetWindowAttributes attrs; if (!argc || strempty(argv[0])) return; if (!strcmp(argv[0], "wait")) { attrs.cursor = wait_cursor; XChangeWindowAttributes(UxDisplay, XtWindow(kuipIo), CWCursor, &attrs); } else if (!strcmp(argv[0], "main")) { attrs.cursor = main_cursor; XChangeWindowAttributes(UxDisplay, XtWindow(kuipIo), CWCursor, &attrs); } } static void newpanel_action( argv, argc ) char **argv; int argc; { char *title; char geometry[128]; int nc, nl, i, j; if (argc) { title = strdup(argv[0]); nl = atoi (argv[1]); nc = atoi (argv[2]); set_kxtpanel_rows (nl, 0, -1); for (i = 0; i < nl; i++) { set_kxtpanel_rows (i, nc, 0); } for (i = 0; i < nl; i++) { for (j = 0; j < nc; j++) { set_kxtpanel_keys (i, j, " "); } } sprintf (geometry,"%sx%s+%s+%s", argv[3], argv[4], argv[5], argv[6]); display_kxtpanel (title, geometry); free(title); } } static void panelrows_action( argv, argc ) char **argv; int argc; { int nl, nc; if (argc) { nl = atoi (argv[0]); nc = atoi (argv[1]); if (nc == -1) { set_kxtpanel_rows (nl, 0, -1); } else { set_kxtpanel_rows (nl, nc, 0); } } } static void panelkeys_action( argv, argc ) char **argv; int argc; { int nr, nc; if (argc) { nr = atoi (argv[0]); nc = atoi (argv[1]); if (strempty(argv[2])) set_kxtpanel_keys (nr, nc, " "); else set_kxtpanel_keys (nr, nc, argv[2]); } } static void display_panel_action( argv, argc ) char **argv; int argc; { char *title, *geometry; if (argc) { title = strdup(argv[0]); geometry = strdup(argv[1]); display_kxtpanel (title, geometry); free (title); free (geometry); } } /*********************************************************************** * * * Handle special (escaped) commands coming from the application. * * An escaped command starts with the ESCAPE sequence and ends with * * a newline (\n). * * There are two type of command: * * 1) Action commands with format: \n * * The part is a kxterm action, e.g. "exit" or * * "cwd(//lun1)". For all defined actions see the action table * * defined in deck actions. * * 2) Menu building commands with format: * * M:::[]: * * [