void update_text_values ( void ) { int i,lastpos; char line[256]; /*---------------------------------------------------------------------*/ if((text_dialog == NULL) || (sndgp == NULL)) return; lastpos = 0; XtVaSetValues(textfield,XmNvalue,sndgp->title, NULL); lastpos += (int)strlen(sndgp->title); sprintf(line,"\n LEVEL HGHT TEMP DWPT WDIR WSPD OMEG\n"); XmTextInsert(textfield,lastpos,line); lastpos += (int)strlen(line); for(i=0;i<sndgp->numlev;i++) { sprintf(line,"%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %11.6f\n", sndgp->sndg[i].pres,sndgp->sndg[i].hght,sndgp->sndg[i].temp,sndgp->sndg[i].dwpt, sndgp->sndg[i].drct,sndgp->sndg[i].sped,sndgp->sndg[i].omega); XmTextInsert(textfield,lastpos,line); lastpos += (int)strlen(line); } }
/*--------------------------- catch_child() -----------------------------*/ static void catch_child(Widget w) { int n; char buffer[4096 + 3]; if ((n = read(cmd_fd, buffer, 4096)) > 0) { buffer[n] = '\0'; XmTextInsert(cmd_output, wpr_position, buffer); wpr_position += n; if (go_to_beginning == NO) { XmTextShowPosition(cmd_output, wpr_position); } XFlush(display); } else if (n == 0) { buffer[0] = '>'; buffer[1] = '\0'; XmTextInsert(cmd_output, wpr_position, buffer); if (go_to_beginning == NO) { XmTextShowPosition(cmd_output, wpr_position); } else { XmTextShowPosition(cmd_output, 0); } XFlush(display); if (cmd_pid > 0) { if (wait(NULL) == -1) { (void)fprintf(stderr, "wait() error : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } cmd_pid = 0; } wpr_position = 0; if (cmd_input_id != 0L) { XtRemoveInput(cmd_input_id); cmd_input_id = 0L; if (close(cmd_fd) == -1) { (void)fprintf(stderr, "close() error : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); } } } return; }
static int motTextSetAppendAttrib(Ihandle* ih, const char* value) { XmTextPosition pos; if (!ih->handle) /* do not store the action before map */ return 0; pos = XmTextGetLastPosition(ih->handle); /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); if (ih->data->is_multiline && ih->data->append_newline) XmTextInsert(ih->handle, pos, "\n"); if (value) XmTextInsert(ih->handle, pos+1, (char*)value); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); return 0; }
void listener_append_and_prompt(const char *msg) { if ((listener_print_p(msg)) && (listener_text)) { XmTextPosition cmd_eot; if (msg) XmTextInsert(listener_text, XmTextGetLastPosition(listener_text), (char *)msg); cmd_eot = XmTextGetLastPosition(listener_text); XmTextInsert(listener_text, cmd_eot, listener_prompt_with_cr()); cmd_eot = XmTextGetLastPosition(listener_text); printout_end = cmd_eot - 1; XmTextShowPosition(listener_text, cmd_eot - 1); } }
void runCB(Widget w, XtPointer client_data, XtPointer xt_call_data) { XmPushButtonCallbackStruct *call_data = (XmPushButtonCallbackStruct *) xt_call_data ; char* cmd; cmd = (char*)XmTextGetString(inW); FILE *fp; fp = popen(cmd, "r"); char c[1024]; XmTextPosition pos; pos = XmTextGetLastPosition(outW); while(fgets(c, 1024, fp)) { pos = XmTextGetLastPosition(outW); XmTextInsert(outW, pos, c); #ifdef DEBUG printf("fp: %s", c); printf("pos: %d\n", (int)pos); #endif } pclose(fp); }
/****inserttexts()************************************************************/ void inserttexts(char texts[256], int dummy) { dummy = dummy; /*PC uses 0 insert, 1 replace*/ #ifdef UNIX_MOTIF /*060324 re compile with NOGUI, requires Lquiet=1*/ if(Lquiet==0) /*was Lcommanded before 990402*/ { if(!Limittext) { laststrlen = (long)strlen(texts); maxtextchar = maxtextchar + laststrlen; if(maxtextchar >= 32767L) { Limittext = 1; printf("Text about to exceed 32767 characters, \n" " no more text will be put into Text Window!\n"); } else { position = XmTextGetLastPosition(textwindow); XmTextInsert(textwindow, position, texts); /*advance position*/ position = XmTextGetLastPosition(textwindow); /*set laststrlength=0 as will not overwrite this new text*/ laststrlen = 0; } } } #endif /* UNIX_MOTIF 060324 re compile with NOGUI, requires Lquiet=1*/ }
static void templates_cb( Widget w, XtPointer cbd, XtPointer cbs) { TemplateCallbackData *cbdata = cbd; XmTextPosition start, end, after; if(!text_w) { char m[80]; sprintf(m, "unexpected argument %p", cbdata); msg("template handler", m); return; } if(get_map_state(text_w) != IsViewable) { beep(); return; } if( XmTextGetSelectionPosition(text_w, &start, &end) && start < end) { XmTextReplace(text_w, start, end, *cbdata); XmTextClearSelection(text_w, CurrentTime); } else { start = XmTextGetInsertionPosition(text_w); XmTextInsert(text_w, start, *cbdata); } after = start + strlen (*cbdata); XmTextSetInsertionPosition(text_w, after); XmTextShowPosition(text_w, after); set_input_focus(text_w); }
void Output_text (char *text) { static int pos = 0; XmTextInsert (textshow, pos, text); pos += strlen (text); return; }
void timestampCB (Widget w, XtPointer clientData, XmAnyCallbackStruct *cbs) { char buf[128]; XmTextPosition curpos; Widget textw = (Widget) clientData; curpos = XmTextGetInsertionPosition (textw); sprintf (buf, "%s", theTime()); XmTextInsert (textw, curpos, buf); }
/* Appends str to the command text */ static void AppendComText(String str) { XmTextPosition old_pos; old_pos = XmTextGetInsertionPosition(appData->com_text); XmTextInsert(appData->com_text, old_pos, str); XmTextSetInsertionPosition(appData->com_text, old_pos + strlen(str)); }
void append_listener_text(int end, const char *msg) { if (listener_text) { if (end == -1) end = XmTextGetLastPosition(listener_text); XmTextInsert(listener_text, end, (char *)msg); XmTextSetCursorPosition(listener_text, XmTextGetLastPosition(listener_text)); } }
/* appends text at the bottom of the main text widget */ void appendText(char *msg) { XmTextPosition lastPos; lastPos = XmTextGetLastPosition(outputArea); XmTextInsert(outputArea, lastPos, msg); lastPos = XmTextGetLastPosition(outputArea); XmTextSetInsertionPosition(outputArea, lastPos); }
static int motTextSetClipboardAttrib(Ihandle *ih, const char *value) { if (iupStrEqualNoCase(value, "COPY")) { char *str = XmTextGetSelection(ih->handle); if (!str) return 0; XmTextCopy(ih->handle, CurrentTime); /* do it also for the X clipboard */ XStoreBytes(iupmot_display, str, strlen(str)+1); XtFree(str); } else if (iupStrEqualNoCase(value, "CUT")) { char *str = XmTextGetSelection(ih->handle); if (!str) return 0; /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XmTextCut(ih->handle, CurrentTime); /* do it also for the X clipboard */ XStoreBytes(iupmot_display, str, strlen(str)+1); XtFree(str); XmTextRemove(ih->handle); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } else if (iupStrEqualNoCase(value, "PASTE")) { int size; char* str = XFetchBytes(iupmot_display, &size); if (!str) return 0; /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XmTextPaste(ih->handle); /* TODO: this could force 2 pastes, check in CDE */ /* do it also for the X clipboard */ XmTextRemove(ih->handle); XmTextInsert(ih->handle, XmTextGetInsertionPosition(ih->handle), str); XFree(str); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } else if (iupStrEqualNoCase(value, "CLEAR")) { /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XmTextRemove(ih->handle); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } return 0; }
static int motTextSetAppendAttrib(Ihandle* ih, const char* value) { XmTextPosition pos; if (!ih->handle) /* do not do the action before map */ return 0; pos = XmTextGetLastPosition(ih->handle); /* disable callbacks */ ih->data->disable_callbacks = 1; if (ih->data->is_multiline && ih->data->append_newline && pos!=0) { XmTextInsert(ih->handle, pos, "\n"); pos++; } if (value) XmTextInsert(ih->handle, pos, (char*)value); ih->data->disable_callbacks = 0; return 0; }
void listener_append(const char *msg) { if ((listener_print_p(msg)) && /* we need this first -- runs print-hook */ (listener_text)) { XmTextInsert(listener_text, XmTextGetLastPosition(listener_text), (char *)msg); printout_end = XmTextGetLastPosition(listener_text) - 1; } }
// TTY input received static void tty_command(Agent *, void *, void *call_data) { annotate("post-prompt"); DataLength *d = (DataLength *)call_data; // Simply insert text, invoking all necessary callbacks tty_gdb_input = true; XmTextInsert(gdb_w, XmTextGetLastPosition(gdb_w), (String)d->data); tty_gdb_input = false; }
void RXmTextInsert(message_t message) { Widget w; XmTextPosition pos; String value; toolkit_read_value(message,&w,XtRWidget); toolkit_read_value(message,&pos,XtRInt); toolkit_read_value(message,&value,XtRString); XmTextInsert(w,pos,value); }
void wxTextEntry::WriteText(const wxString& text) { long pos = GetInsertionPoint(); XmTextInsert(GetText(), pos, text.char_str()); pos += text.length(); XtVaSetValues(GetText(), XmNcursorPosition, pos, NULL); SetInsertionPoint(pos); XmTextShowPosition(GetText(), pos); }
int main(int argc, char *argv[]) { int i, n; Arg args[10]; XtAppContext app; Widget toplevel, rowcol, textf, text; XmString str_months[12]; setlocale(LC_ALL, ""); //建立顶级窗口 toplevel = XtVaAppInitialize(&app, "Edit", NULL, 0, &argc, argv, NULL, NULL); //建立rowcolumn 布局 n = 0; XtSetArg(args[n], XmNpacking, XmPACK_TIGHT); n++; rowcol = XmCreateRowColumn(toplevel, "rowcol", args, n); XtManageChild(rowcol); //建立输入条 n = 0; XtSetArg(args[n], XmNvalue, "输入条"); n++; textf = XmCreateTextField(rowcol, "textf", args, n); XtManageChild(textf); //建立文本区 n = 0; XtSetArg(args[n], XmNrows, 10); n++; XtSetArg(args[n], XmNcolumns, 40); n++; XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++; XtSetArg(args[n], XmNwordWrap, True); n++; XtSetArg(args[n], XmNvalue, "输入区域\n请测试"); n++; text = XmCreateScrolledText(rowcol, "text", args, n); XtManageChild(text); //显示窗口 XtRealizeWidget(toplevel); //edit XmTextSetInsertionPosition(text, 3); XmTextInsert(text, 5, "测试插入"); XmTextSetSelection(text, 5, 8, CurrentTime); XmTextCopy(text, CurrentTime); XmTextSetInsertionPosition(text, 1); XmTextPaste(text); //进入事件循环 XtAppMainLoop(app); }
/*********************************************************************** * * * Handle mail type toggle button changes. * * * ***********************************************************************/ static void handle_toggle(Widget w, XtPointer cd, XmToggleButtonCallbackStruct *cbs) { char **s; XmTextPosition pos = 0; if (!cbs->set) return; XmTextSetString(bugMailText, NULL); if (w == bugMailToggle) s = br_tmpl_bugrep; else s = br_tmpl_comment; for ( ; *s; s++) { XmTextInsert(bugMailText, pos, *s); pos += strlen(*s); XmTextInsert(bugMailText, pos, "\n"); pos++; } }
static void Yank(Widget w, XEvent *ev, char **str, Cardinal *num) { /* copy current selection at current cursor position */ if (listener_selection) { XmTextPosition curpos; curpos = XmTextGetCursorPosition(w); XmTextInsert(w, curpos, listener_selection); curpos += strlen(listener_selection); XmTextShowPosition(w, curpos); XmTextSetCursorPosition(w, curpos); XmTextClearSelection(w, ev->xkey.time); /* so C-y + edit doesn't forbid the edit */ } }
static int motTextSetInsertAttrib(Ihandle* ih, const char* value) { if (!ih->handle) /* do not store the action before map */ return 0; if (!value) return 0; /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XmTextRemove(ih->handle); XmTextInsert(ih->handle, XmTextGetInsertionPosition(ih->handle), (char*)value); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); return 0; }
static int motTextSetInsertAttrib(Ihandle* ih, const char* value) { if (!ih->handle) /* do not do the action before map */ return 0; if (!value) return 0; /* disable callbacks */ ih->data->disable_callbacks = 1; XmTextRemove(ih->handle); XmTextInsert(ih->handle, XmTextGetInsertionPosition(ih->handle), (char*)value); ih->data->disable_callbacks = 0; return 0; }
void DmxPrintOutput::appendContents (void* stream, char *contents) { DmxPrintOutput *thisOutput = (DmxPrintOutput *) stream; #ifdef USE_DTEDITOR DtEditorContentRec rec; rec.type = DtEDITOR_TEXT; rec.value.string = contents; DtEditorInsert(thisOutput->_editor, &rec); #else XmTextPosition pos; pos = XmTextGetLastPosition(thisOutput->_editor); XmTextInsert(thisOutput->_editor, pos, contents); #endif }
/* -------------------------------------------------------------------- */ void SetStatsData() { size_t i; static bool firstTime = True; if (firstTime) { CreateStatsWindow(); firstTime = False; } XmTextSetString(statsText, statTitle); for (i = 0; i < NumberDataSets; ++i) { formatLine(buffer, &dataSet[i]); XmTextInsert(statsText, XmTextGetLastPosition(statsText), buffer); } for (i = 0; i < NumberXYXsets; ++i) { formatLine(buffer, &xyXset[i]); XmTextInsert(statsText, XmTextGetLastPosition(statsText), buffer); } for (i = 0; i < NumberXYYsets; ++i) { formatLine(buffer, &xyYset[i]); XmTextInsert(statsText, XmTextGetLastPosition(statsText), buffer); } for (i = 0; i < 3; ++i) if (xyzSet[i].varInfo) { formatLine(buffer, &xyzSet[i]); XmTextInsert(statsText, XmTextGetLastPosition(statsText), buffer); } if (WindBarbs) { formatLine(buffer, &ui); XmTextInsert(statsText, XmTextGetLastPosition(statsText), buffer); formatLine(buffer, &vi); XmTextInsert(statsText, XmTextGetLastPosition(statsText), buffer); } } /* END SETSTATSDATA */
static void completions_browse_callback(Widget w, XtPointer context, XtPointer info) { int i, j, old_len, new_len; char *text = NULL, *old_text = NULL; XmListCallbackStruct *cbs = (XmListCallbackStruct *)info; Widget requestor; if (ss->sgx->completion_requestor == NULL) requestor = listener_text; else requestor = ss->sgx->completion_requestor; /* choice = cbs->item_position - 1; */ text = (char *)XmStringUnparse(cbs->item, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL); old_text = XmTextGetString(requestor); old_len = snd_strlen(old_text); new_len = snd_strlen(text); for (i = old_len - 1, j = new_len - 1; j >= 0; j--) { if (old_text[i] != text[j]) { i = old_len - 1; if (old_text[i] == text[j]) i--; /* this added 15-Apr-02 for case like map-chan(nel) */ /* probably should go back new_len and scan forwards instead */ } else i--; } if (requestor == listener_text) append_listener_text(XmTextGetLastPosition(listener_text), (char *)(text - 1 + old_len - i)); else { /* try to append to who(m?)ever asked for completion help */ XmTextInsert(requestor, XmTextGetLastPosition(requestor), (char *)(text - 1 + old_len - i)); } if (text) XtFree(text); if (old_text) XtFree(old_text); unpost_completion(requestor); }
int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) { if (instance != NULL) { PluginInstance* This = (PluginInstance*) instance->pdata; char *cbuf; #ifdef TEXT_PLUGIN XmTextPosition pos = 0; #endif /* TEXT_PLUGIN */ /* If this was a NODATA plugin, then we should not be getting * this write call. */ if (This->nodata) fprintf(stderr, "TextPlugin ERROR: Although NODATA attribute was used (NPP_WriteReady returned 0),\nwe got a NPP_Write call. Tell Netscape about this.\n"); cbuf = (char *) NPN_MemAlloc(len + 1); if (!cbuf) return 0; memcpy(cbuf, (char *)buffer, len); cbuf[len] = '\0'; #ifdef TEXT_PLUGIN if (This->text) { XtVaGetValues(This->text, XmNcursorPosition, &pos, 0); XmTextInsert(This->text, pos, cbuf); } else { /* This must be a hidden plugin */ fprintf(stderr, "%s", cbuf); } #else /* TEXT_PLUGIN */ fprintf(stderr, "%s", cbuf); #endif /* TEXT_PLUGIN */ NPN_MemFree(cbuf); } return len; /* The number of bytes accepted */ }
void includeFileCB( Widget w, XtPointer client_data, XtPointer call_data) { char *file_data, *c_path; Widget widget; XmFileSelectionBoxCallbackStruct *res; XmTextPosition pos; res = (XmFileSelectionBoxCallbackStruct *) call_data; c_path = XmStringUnparse(res->value, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL); file_data = get_file_contents(w, "fileOpenCB", c_path); widget = get_document_text(w, "fileOpenCB"); pos = XmTextGetInsertionPosition(widget); XmTextInsert(widget, pos, file_data); update_document_linecount(w, "includeFileCB"); update_message(w, "fileOpenCB", "Included file."); XtFree(c_path); XtFree(file_data); XtUnmanageChild(w); }
/*############################## read_text() ############################*/ static void read_text(void) { int fd = fileno(p_log_file); char *src = NULL, *dst = NULL, *ptr, *ptr_dst, *ptr_start, *ptr_line; struct stat stat_buf; XSetWindowAttributes attrs; XEvent event; if (fstat(fd, &stat_buf) < 0) { (void)xrec(FATAL_DIALOG, "fstat() error : %s (%s %d)", strerror(errno), __FILE__, __LINE__); return; } if (stat_buf.st_size > 0) { int block_length, length, last = MISS; off_t tmp_total_length = 0; /* Change cursor to indicate we are doing something. */ attrs.cursor = cursor1; XChangeWindowAttributes(display, XtWindow(appshell), CWCursor, &attrs); XFlush(display); /* Copy file to memory. */ #ifdef HAVE_MMAP if (lseek(fd, stat_buf.st_size, SEEK_SET) == -1) { (void)xrec(FATAL_DIALOG, "lseek() error : %s (%s %d)", strerror(errno), __FILE__, __LINE__); return; } if ((src = mmap(NULL, stat_buf.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (caddr_t) -1) { (void)xrec(FATAL_DIALOG, "mmap() error : %s (%s %d)", strerror(errno), __FILE__, __LINE__); return; } #else if ((src = malloc(stat_buf.st_size)) == NULL) { (void)xrec(FATAL_DIALOG, "malloc() error : %s (%s %d)", strerror(errno), __FILE__, __LINE__); return; } if (read(fd, src, stat_buf.st_size) != stat_buf.st_size) { int tmp_errno = errno; free(src); (void)xrec(FATAL_DIALOG, "read() error : %s (%s %d)", strerror(tmp_errno), __FILE__, __LINE__); return; } #endif if ((dst = malloc(stat_buf.st_size + 1)) == NULL) { (void)xrec(FATAL_DIALOG, "malloc() error [%d bytes] : %s (%s %d)", stat_buf.st_size + 1, strerror(errno), __FILE__, __LINE__); return; } ptr_start = ptr = src; ptr_dst = dst; block_length = 0; *ptr_dst = '\0'; if (no_of_hosts > 0) { int i; while (tmp_total_length < stat_buf.st_size) { length = 0; ptr_line = ptr; while ((*ptr != '\n') && (*ptr != '\0')) { length++; ptr++; } length++; ptr++; tmp_total_length += length; if ((log_type_flag == TRANSFER_LOG_TYPE) || (log_type_flag == TRANS_DB_LOG_TYPE)) { if ((length > (LOG_SIGN_POSITION + MAX_HOSTNAME_LENGTH + 4)) && ((((toggles_set & SHOW_INFO) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'I')) || (((toggles_set & SHOW_WARN) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'W')) || (((toggles_set & SHOW_ERROR) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'E')) || (((toggles_set & SHOW_FATAL) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'F')) || (((toggles_set & SHOW_OFFLINE) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'O')) || (((toggles_set & SHOW_DEBUG) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'D')) || (((toggles_set & SHOW_TRACE) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'T')) || (((toggles_set_parallel_jobs - 1) != (*(ptr_line + LOG_SIGN_POSITION + MAX_HOSTNAME_LENGTH + 4) - 48)) && (toggles_set_parallel_jobs != 0)))) { if (last == HIT) { (void)memcpy(ptr_dst, ptr_start, block_length); *(ptr_dst + block_length) = '\0'; ptr_dst += block_length; block_length = 0; } last = MISS; } else { for (i = 0; i < no_of_hosts; i++) { if (log_filter(hosts[i], ptr_line + 16) == 0) { i = no_of_hosts + 1; } } if (i == (no_of_hosts + 2)) { if (last == MISS) { ptr_start = ptr - length; } block_length += length; line_counter++; last = HIT; } else { if (last == HIT) { memcpy(ptr_dst, ptr_start, block_length); *(ptr_dst + block_length) = '\0'; ptr_dst += block_length; block_length = 0; } last = MISS; } } } else { if ((length > LOG_SIGN_POSITION) && ((((toggles_set & SHOW_INFO) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'I')) || (((toggles_set & SHOW_CONFIG) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'C')) || (((toggles_set & SHOW_WARN) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'W')) || (((toggles_set & SHOW_ERROR) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'E')) || (((toggles_set & SHOW_FATAL) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'F')) || (((toggles_set & SHOW_OFFLINE) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'O')) || (((toggles_set & SHOW_DEBUG) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'D')))) { if (last == HIT) { (void)memcpy(ptr_dst, ptr_start, block_length); *(ptr_dst + block_length) = '\0'; ptr_dst += block_length; block_length = 0; } last = MISS; } else { for (i = 0; i < no_of_hosts; i++) { if (log_filter(hosts[i], ptr_line + 16) == 0) { i = no_of_hosts + 1; } } if (i == (no_of_hosts + 2)) { if (last == MISS) { ptr_start = ptr - length; } block_length += length; line_counter++; last = HIT; } else { if (last == HIT) { memcpy(ptr_dst, ptr_start, block_length); *(ptr_dst + block_length) = '\0'; ptr_dst += block_length; block_length = 0; } last = MISS; } } } } } else { while (tmp_total_length < stat_buf.st_size) { length = 0; ptr_line = ptr; while ((*ptr != '\n') && (*ptr != '\0')) { length++; ptr++; } length++; ptr++; tmp_total_length += length; if ((log_type_flag == TRANSFER_LOG_TYPE) || (log_type_flag == TRANS_DB_LOG_TYPE)) { if ((length > (LOG_SIGN_POSITION + MAX_HOSTNAME_LENGTH + 4)) && ((((toggles_set & SHOW_INFO) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'I')) || (((toggles_set & SHOW_WARN) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'W')) || (((toggles_set & SHOW_ERROR) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'E')) || (((toggles_set & SHOW_FATAL) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'F')) || (((toggles_set & SHOW_OFFLINE) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'O')) || (((toggles_set & SHOW_DEBUG) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'D')) || (((toggles_set & SHOW_TRACE) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'T')) || (((toggles_set_parallel_jobs - 1) != (*(ptr_line + LOG_SIGN_POSITION + MAX_HOSTNAME_LENGTH + 4) - 48)) && (toggles_set_parallel_jobs != 0)))) { if (last == HIT) { memcpy(ptr_dst, ptr_start, block_length); *(ptr_dst + block_length) = '\0'; ptr_dst += block_length; block_length = 0; } last = MISS; } else { if (last == MISS) { ptr_start = ptr - length; } block_length += length; line_counter++; last = HIT; } } else { if ((length > LOG_SIGN_POSITION) && ((((toggles_set & SHOW_INFO) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'I')) || (((toggles_set & SHOW_CONFIG) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'C')) || (((toggles_set & SHOW_WARN) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'W')) || (((toggles_set & SHOW_ERROR) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'E')) || (((toggles_set & SHOW_FATAL) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'F')) || (((toggles_set & SHOW_OFFLINE) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'O')) || (((toggles_set & SHOW_DEBUG) == 0) && (*(ptr_line + LOG_SIGN_POSITION) == 'D')))) { if (last == HIT) { memcpy(ptr_dst, ptr_start, block_length); *(ptr_dst + block_length) = '\0'; ptr_dst += block_length; block_length = 0; } last = MISS; } else { if (last == MISS) { ptr_start = ptr - length; } block_length += length; line_counter++; last = HIT; } } } } if (block_length > 0) { memcpy(ptr_dst, ptr_start, block_length); *(ptr_dst + block_length) = '\0'; } #ifdef HAVE_MMAP if (munmap(src, stat_buf.st_size) < 0) { (void)xrec(WARN_DIALOG, "munmap() error : %s (%s %d)", strerror(errno), __FILE__, __LINE__); } #else free(src); #endif if (wpr_position == 0) { XmTextSetString(log_output, dst); } else { #ifndef LESSTIF_WORKAROUND XtUnmanageChild(log_output); #endif XmTextInsert(log_output, wpr_position, dst); #ifndef LESSTIF_WORKAROUND XtManageChild(log_output); #endif } wpr_position += tmp_total_length; total_length += tmp_total_length; free((void *)dst); attrs.cursor = None; XChangeWindowAttributes(display, XtWindow(appshell), CWCursor, &attrs); XFlush(display); /* Get rid of all events that have occurred. */ XSync(display, False); while (XCheckMaskEvent(display, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask | KeyPressMask, &event) == TRUE) { /* do nothing */; } } return; }
/*************************************************************************** This routine is called to pop up the process dialog/form. This is done only after obtaining information about the process and setting various fields. The form can be used to shows process information, set process priority and/or send a signal to the process or process group. If want_kill is True and active.quick_killis True, this routine instead sends the signal last selected to the process. ***************************************************************************/ void Handle_Process(Widget w, pid_t pid, XEvent *event, Boolean want_kill) { char line[MAXLINE]; FILE *fp; XmProcessTraversal(active.canvas, XmTRAVERSE_CURRENT); #ifdef HAVE_KILL if (active.quick_kill && want_kill) { if (last_global_signal_pos>=0 && last_global_signal_pos<sigmap_elts) { do_kill(w, pid, signal_map[last_global_signal_pos+1].sig); ForceRedisplay(); } else { char buf[300]; sprintf(buf, "Invalid signal position in signal list: %d\n", last_global_signal_pos+1); ShowDialog(w, XmDIALOG_ERROR, buf); } return; } #endif base.selected_pid = pid; ForceRedisplay(); /* Set priority to current priority value for the process */ #ifdef HAVE_GETPRIORITY errno = 0; priority = getpriority(PRIO_PROCESS, base.selected_pid); if ( priority == -1 && errno != 0 ) { /* beep if we can't get the priority. */ XBell(XtDisplay(active.shell),0); } else { XmScaleSetValue(priority_slider, priority); } #endif #ifdef HAVE_KILL /* Unless we have selected quick kill, make sure position 1 -- no action is selected for the signal value. */ if (active.quick_kill) { /* Off by one because we have "NO ACTION" while other menu doesn't */ XmListSelectPos(signal_list, last_global_signal_pos+1+1, False); } else { XmListSelectPos(signal_list, 1, False); } #endif /* process group button is not pushed/selected */ do_process_group = False; XmToggleButtonSetState(process_group_button, do_process_group, False); #ifdef HAVE_SETPRIORITY do_priority = False; XmToggleButtonSetState(priority_button, do_priority, False); #endif /* Set process command info . */ sprintf(line, base.ps_cmd_info, base.selected_pid); XmTextRemove(ps_info); /*XmScrollBarSetValues(ps_info, 1, 4, 1, 4, False);*/ fp = popen(line, "r"); if (fp != NULL) { int pos; XmTextSetString(ps_info, ""); while(fgets(line, MAXLINE, fp) != NULL) { pos = XmTextGetLastPosition(ps_info); XmTextInsert(ps_info, pos, line); } } pclose(fp); /* Set to show full command-line invocation. */ sprintf(line, base.ps_cmdline, base.selected_pid); fp = popen(line, "r"); if (fp != NULL) { int pos; while(fgets(line, MAXLINE, fp) != NULL) { pos = XmTextGetLastPosition(ps_info); XmTextInsert(ps_info, pos, line); } pclose(fp); } XtManageChild(ps_info); XtManageChild(process_dialog); /* By itself the popup appears at 0,0. I don't know why XMenuPosition doesn't do better. */ /* XmMenuPosition(process_dialog, (XButtonPressedEvent *) event); */ #ifdef TESTING switch (event->type) { case ButtonPress: XtVaSetValues(process_dialog, XmNx, event->xbutton.x, XmNy, event->xbutton.y, NULL); break; case KeyPress: XtVaSetValues(process_dialog, XmNx, event->xkey.x, XmNy, event->xkey.y, NULL); break; default: } #endif }