static void Realize(Widget aw, XtValueMask * value_mask, XSetWindowAttributes * attributes) { XltFontChooserWidget fc = (XltFontChooserWidget) aw; char *f = XtMalloc(256), **list; int i, j, nfonts; #define superclass (&xmMessageBoxClassRec) (*superclass->core_class.realize) (aw, value_mask, attributes); #undef superclass if (! FC_ShowDemo(fc)) return; /* Show the right font initially */ f[0] = '\0'; for (j=0; j<14; j++) { strcat(f, "-"); strcat(f, FC_Setting(fc)[j]); } if (FC_FontName(fc)) XtFree(FC_FontName(fc)); FC_FontName(fc) = f; /* How many fonts ? */ list = XListFonts(XtDisplay(fc), f, 4096, &nfonts); for (i=0; i<nfonts; i++) EnableMenu(aw, list[i]); XFreeFontNames(list); if (FC_DemoWidget(fc)) { XmFontList fl; XmFontListEntry fle; XFontSet fs; char m1[2][80], **missing = (char **)&m1[0][0]; char m2[80], *def = &m2[0]; int nmissing = 0; fs = XCreateFontSet(XtDisplay(fc), f, &missing, &nmissing, &def); if (fs != NULL) { fle = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONTSET, (XtPointer)fs); fl = XmFontListAppendEntry(NULL, fle); XtVaSetValues(FC_DemoWidget(fc), XmNfontList, fl, NULL); XmFontListEntryFree(&fle); XmFontListFree(fl); #if 0 /* Freeing the font set produces nice little core dumps */ XFreeFontSet(XtDisplay(fc), fs); /* FIX ME leak ?? */ #endif } } ShowCount(aw, nfonts); }
/*########################### setup_window() ###########################*/ void setup_window(char *font_name) { XmFontListEntry entry; /* Get width and height of font and fid for the GC. */ if ((font_struct = XLoadQueryFont(display, font_name)) == NULL) { (void)fprintf(stderr, "Could not load %s font.\n", font_name); if ((font_struct = XLoadQueryFont(display, "fixed")) == NULL) { (void)fprintf(stderr, "Could not load %s font.\n", "fixed"); exit(INCORRECT); } } if ((entry = XmFontListEntryLoad(display, font_name, XmFONT_IS_FONT, "TAG1")) == NULL) { (void)fprintf(stderr, "Failed to load font with XmFontListEntryLoad() : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); glyph_height = font_struct->ascent + font_struct->descent; glyph_width = font_struct->per_char->width; y_offset_xaxis = font_struct->ascent + 4; x_offset_left_xaxis = 9 * glyph_width; x_offset_right_xaxis = 2 * glyph_width; y_offset_top_yaxis = glyph_height; y_offset_bottom_yaxis = 5 * glyph_height; if (time_type == YEAR_STAT) { no_of_chars = 4; } else { no_of_chars = 3; } x_data_spacing = no_of_chars * glyph_width; y_data_spacing = glyph_height; return; }
XmFontList CommonGetFontListWithCharset(char *fontstr, char *charset) { #ifdef MOTIF1_1 XFontStruct *newfont; #else static XmFontListEntry fixed_font = NULL; XmFontListEntry fontlistEntry; #endif XmFontList fontlist; #ifdef MOTIF1_1 if (!(newfont = XLoadQueryFont (display, fontstr))) newfont = XLoadQueryFont (display, default_font); fontlist = XmFontListCreate (newfont, charset); #else if (!fixed_font) { fixed_font = XmFontListEntryLoad(display, "fixed", XmFONT_IS_FONT, charset); } if ((fontlistEntry = XmFontListEntryLoad(display, fontstr, XmFONT_IS_FONT, charset)) == NULL) { fontlist = XmFontListAppendEntry(NULL, fixed_font); } else { fontlist = XmFontListAppendEntry(NULL, fontlistEntry); XmFontListEntryFree(&fontlistEntry); } #endif return(fontlist); }
void XIM_init_frame (struct frame *f) { Widget w = FRAME_X_TEXT_WIDGET (f); XPoint spot = {0,0}; XmFontList fontlist; XmFontListEntry fontlistEntry; typedef struct { XFontSet fontset; Pixel fg; Pixel bg; } xim_resources_t; xim_resources_t xim_resources; /* mrb: #### Fix so that background and foreground is set from default face, rather than foreground and background resources, or that the user can use set-frame-parameters to set xic attributes */ #define res(name, class, representation, field, default_value) \ { name, class, representation, sizeof(xim_resources.field), \ XtOffsetOf(xim_resources_t, field), \ XtRString, (XtPointer) (default_value) } static XtResource resources[] = { /* name class represent'n field default value */ res(XtNfontSet, XtCFontSet, XtRFontSet, fontset, XtDefaultFontSet), res(XtNximForeground, XtCForeground, XtRPixel, fg, XtDefaultForeground), res(XtNximBackground, XtCBackground, XtRPixel, bg, XtDefaultBackground) }; XtGetApplicationResources (w, &xim_resources, resources, XtNumber (resources), NULL, 0); if (! xim_resources.fontset) { stderr_out ("Can't get fontset resource for Input Method\n"); return; } fontlistEntry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONTSET, (XtPointer) xim_resources.fontset); fontlist = XmFontListAppendEntry (NULL, fontlistEntry); XmImRegister (w, 0); XmImVaSetValues (w, XmNfontList, fontlist, XmNforeground, xim_resources.fg, XmNbackground, xim_resources.bg, XmNspotLocation, &spot, /* XmNlineSpace, 0, */ NULL); XmFontListEntryFree (&fontlistEntry); XtAddCallback (w, XmNdestroyCallback, XIM_delete_frame, (XtPointer) w); }
static void FCFilter(Widget w, XtPointer client, XtPointer call) { int i = (int)client, j, nfonts; Widget fc, b, demo; char *f = XtMalloc(256), **list; XmRowColumnCallbackStruct *cbs = (XmRowColumnCallbackStruct *)call; /* Figure out who we are and who called us */ #if 0 for (fc = w; fc && ! XltIsFontChooser(fc); fc = XtParent(fc)) ; if (fc == NULL) { /* Probably in a tearoff */ abort(); } #endif b = cbs->widget; /* This widget invoked us */ XtVaGetValues(b, XmNuserData, &fc, NULL); demo = FC_DemoWidget(fc); /* Store the setting */ if (FC_Setting(fc)[i] != NULL) XtFree(FC_Setting(fc)[i]); FC_Setting(fc)[i] = XtNewString(XtName(b)); f[0] = '\0'; for (j=0; j<14; j++) { strcat(f, "-"); strcat(f, FC_Setting(fc)[j]); } if (FC_FontName(fc)) XtFree(FC_FontName(fc)); FC_FontName(fc) = f; /* How many fonts ? */ DisableAllMenus(fc, i); list = XListFonts(XtDisplay(fc), f, 4096, &nfonts); for (i=0; i<nfonts; i++) EnableMenu(fc, list[i]); XFreeFontNames(list); /* Change the display */ if (FC_ShowDemo(fc)) { if (demo) { XmFontList fl; XmFontListEntry fle; XFontSet fs; char m1[2][80], **missing = (char **)&m1[0][0]; char m2[80], *def = &m2[0]; int nmissing = 0; fs = XCreateFontSet(XtDisplay(fc), f, &missing, &nmissing, &def); if (fs != NULL) { fle = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONTSET, (XtPointer)fs); fl = XmFontListAppendEntry(NULL, fle); XtVaSetValues(demo, XmNfontList, fl, NULL); XmFontListEntryFree(&fle); XmFontListFree(fl); #if 0 /* Freeing the font set produces nice little core dumps */ XFreeFontSet(XtDisplay(fc), fs); /* FIX ME leak ?? */ #endif } } ShowCount(fc, nfonts); } }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int i; char window_title[100], work_dir[MAX_PATH_LENGTH], str_line[MAX_INFO_STRING_LENGTH], tmp_str_line[MAX_INFO_STRING_LENGTH]; static String fallback_res[] = { "*mwmDecorations : 42", "*mwmFunctions : 12", ".mon_info.form*background : NavajoWhite2", ".mon_info.form.msa_box.?.?.?.text_wl.background : NavajoWhite1", ".mon_info.form.msa_box.?.?.?.text_wr.background : NavajoWhite1", ".mon_info.form.host_infoSW.host_info.background : NavajoWhite1", ".mon_info.form.buttonbox*background : PaleVioletRed2", ".mon_info.form.buttonbox*foreground : Black", ".mon_info.form.buttonbox*highlightColor : Black", NULL }; Widget form_w, msa_box_w, msa_box1_w, msa_box2_w, msa_text_w, button_w, buttonbox_w, rowcol1_w, rowcol2_w, h_separator1_w, h_separator2_w, v_separator_w; XmFontListEntry entry; XmFontList fontlist; Arg args[MAXARGS]; Cardinal argcount; uid_t euid, /* Effective user ID. */ ruid; /* Real user ID. */ CHECK_FOR_VERSION(argc, argv); /* Initialise global values. */ p_work_dir = work_dir; init_mon_info(&argc, argv); /* * SSH uses wants to look at .Xauthority and with setuid flag * set we cannot do that. So when we initialize X lets temporaly * disable it. After XtAppInitialize() we set it back. */ euid = geteuid(); ruid = getuid(); if (euid != ruid) { if (seteuid(ruid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", ruid, strerror(errno)); } } (void)strcpy(window_title, afd_name); (void)strcat(window_title, " Info"); argcount = 0; XtSetArg(args[argcount], XmNtitle, window_title); argcount++; appshell = XtAppInitialize(&app, "AFD", NULL, 0, &argc, argv, fallback_res, args, argcount); disable_drag_drop(appshell); if (euid != ruid) { if (seteuid(euid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", euid, strerror(errno)); } } display = XtDisplay(appshell); #ifdef HAVE_XPM /* Setup AFD logo as icon. */ setup_icon(display, appshell); #endif /* Create managing widget. */ form_w = XmCreateForm(appshell, "form", NULL, 0); entry = XmFontListEntryLoad(XtDisplay(form_w), font_name, XmFONT_IS_FONT, "TAG1"); fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); argcount = 0; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; msa_box_w = XmCreateForm(form_w, "msa_box", args, argcount); XtManageChild(msa_box_w); argcount = 0; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; msa_box1_w = XmCreateForm(msa_box_w, "msa_box1", args, argcount); XtManageChild(msa_box1_w); rowcol1_w = XtVaCreateWidget("rowcol1", xmRowColumnWidgetClass, msa_box1_w, NULL); for (i = 0; i < NO_OF_MSA_ROWS; i++) { msa_text_w = XtVaCreateWidget("msa_text", xmFormWidgetClass, rowcol1_w, XmNfractionBase, 41, NULL); label_l_widget[i] = XtVaCreateManagedWidget(label_l[i], xmLabelGadgetClass, msa_text_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 1, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 40, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNalignment, XmALIGNMENT_END, NULL); text_wl[i] = XtVaCreateManagedWidget("text_wl", xmTextWidgetClass, msa_text_w, XmNfontList, fontlist, XmNcolumns, MON_INFO_LENGTH, XmNtraversalOn, False, XmNeditable, False, XmNcursorPositionVisible, False, XmNmarginHeight, 1, XmNmarginWidth, 1, XmNshadowThickness, 1, XmNhighlightThickness, 0, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 22, NULL); XtManageChild(msa_text_w); } XtManageChild(rowcol1_w); /* Fill up the text widget with some values. */ (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, prev.real_hostname[(int)prev.afd_toggle]); XmTextSetString(text_wl[0], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.port[(int)prev.afd_toggle]); XmTextSetString(text_wl[1], str_line); (void)strftime(tmp_str_line, MAX_INFO_STRING_LENGTH, "%d.%m.%Y %H:%M:%S", localtime(&prev.last_data_time)); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, tmp_str_line); XmTextSetString(text_wl[2], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.max_connections); XmTextSetString(text_wl[3], str_line); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, prev.afd_version); XmTextSetString(text_wl[4], str_line); if (prev.top_tr > 1048576) { (void)sprintf(str_line, "%*u MB/s", MON_INFO_LENGTH - 5, prev.top_tr / 1048576); } else if (prev.top_tr > 1024) { (void)sprintf(str_line, "%*u KB/s", MON_INFO_LENGTH - 5, prev.top_tr / 1024); } else { (void)sprintf(str_line, "%*u Bytes/s", MON_INFO_LENGTH - 8, prev.top_tr); } XmTextSetString(text_wl[5], str_line); /* Create the first horizontal separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNtopWidget, msa_box_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; h_separator1_w = XmCreateSeparator(form_w, "h_separator1_w", args, argcount); XtManageChild(h_separator1_w); /* Create the vertical separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmVERTICAL); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNleftWidget, msa_box1_w); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; v_separator_w = XmCreateSeparator(msa_box_w, "v_separator", args, argcount); XtManageChild(v_separator_w); argcount = 0; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNleftWidget, v_separator_w); argcount++; msa_box2_w = XmCreateForm(msa_box_w, "msa_box2", args, argcount); XtManageChild(msa_box2_w); rowcol2_w = XtVaCreateWidget("rowcol2", xmRowColumnWidgetClass, msa_box2_w, NULL); for (i = 0; i < NO_OF_MSA_ROWS; i++) { msa_text_w = XtVaCreateWidget("msa_text", xmFormWidgetClass, rowcol2_w, XmNfractionBase, 41, NULL); label_r_widget[i] = XtVaCreateManagedWidget(label_r[i], xmLabelGadgetClass, msa_text_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 1, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 40, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNalignment, XmALIGNMENT_END, NULL); text_wr[i] = XtVaCreateManagedWidget("text_wr", xmTextWidgetClass, msa_text_w, XmNfontList, fontlist, XmNcolumns, MON_INFO_LENGTH, XmNtraversalOn, False, XmNeditable, False, XmNcursorPositionVisible, False, XmNmarginHeight, 1, XmNmarginWidth, 1, XmNshadowThickness, 1, XmNhighlightThickness, 0, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 20, NULL); XtManageChild(msa_text_w); } XtManageChild(rowcol2_w); /* Fill up the text widget with some values. */ get_ip_no(msa[afd_position].hostname[(int)prev.afd_toggle], tmp_str_line); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, tmp_str_line); XmTextSetString(text_wr[0], str_line); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, prev.r_work_dir); XmTextSetString(text_wr[1], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.poll_interval); XmTextSetString(text_wr[2], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.top_not); XmTextSetString(text_wr[3], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.no_of_hosts); XmTextSetString(text_wr[4], str_line); (void)sprintf(str_line, "%*u files/s", MON_INFO_LENGTH - 8, prev.top_fr); XmTextSetString(text_wr[5], str_line); argcount = 0; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNfractionBase, 21); argcount++; buttonbox_w = XmCreateForm(form_w, "buttonbox", args, argcount); /* Create the second horizontal separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, buttonbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; h_separator2_w = XmCreateSeparator(form_w, "h_separator2", args, argcount); XtManageChild(h_separator2_w); if (editable == YES) { button_w = XtVaCreateManagedWidget("Save", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 19, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 9, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)save_button, (XtPointer)0); button_w = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 19, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 10, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 20, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)close_button, (XtPointer)0); } else { button_w = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 19, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 20, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)close_button, (XtPointer)0); } XtManageChild(buttonbox_w); /* Create log_text as a ScrolledText window. */ argcount = 0; XtSetArg(args[argcount], XmNfontList, fontlist); argcount++; XtSetArg(args[argcount], XmNrows, 10); argcount++; XtSetArg(args[argcount], XmNcolumns, 80); argcount++; if (editable == YES) { XtSetArg(args[argcount], XmNeditable, True); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, True); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, True); } else { XtSetArg(args[argcount], XmNeditable, False); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, False); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, False); } argcount++; XtSetArg(args[argcount], XmNeditMode, XmMULTI_LINE_EDIT); argcount++; XtSetArg(args[argcount], XmNwordWrap, False); argcount++; XtSetArg(args[argcount], XmNscrollHorizontal, False); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, False); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, False); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNtopWidget, h_separator1_w); argcount++; XtSetArg(args[argcount], XmNtopOffset, 3); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftOffset, 3); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightOffset, 3); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, h_separator2_w); argcount++; XtSetArg(args[argcount], XmNbottomOffset, 3); argcount++; info_w = XmCreateScrolledText(form_w, "host_info", args, argcount); XtManageChild(info_w); XtManageChild(form_w); /* Free font list. */ XmFontListFree(fontlist); #ifdef WITH_EDITRES XtAddEventHandler(appshell, (EventMask)0, True, _XEditResCheckMessages, NULL); #endif /* Realize all widgets. */ XtRealizeWidget(appshell); wait_visible(appshell); /* Read and display the information file. */ (void)check_info_file(afd_name, AFD_INFO_FILE, YES); XmTextSetString(info_w, NULL); /* Clears old entry. */ XmTextSetString(info_w, info_data); /* Call update_info() after UPDATE_INTERVAL ms. */ interval_id_host = XtAppAddTimeOut(app, UPDATE_INTERVAL, (XtTimerCallbackProc)update_info, form_w); /* We want the keyboard focus on the Done button. */ XmProcessTraversal(button_w, XmTRAVERSE_CURRENT); /* Write window ID, so mon_ctrl can set focus if it is called again. */ write_window_id(XtWindow(appshell), getpid(), MON_INFO); /* Start the main event-handling loop. */ XtAppMainLoop(app); exit(SUCCESS); }
/****************************************************************************** * Function: int FormatChunksToXmString () * * Parameters: * *ret_list may be NULL when called * * Returns: 0 if successful, -1 if errors * * errno Values: * * Purpose: Take some rich text chunks and turn it into an XmString. * ******************************************************************************/ static int FormatChunksToXmString( DtHelpDispAreaStruct *pDAS, Boolean free_flag, void **title_chunks, XmString *ret_title, XmFontList *ret_list, Boolean *ret_mod ) { int result = 0; int i; long j; int quarkCount; long chunkType; long myIdx; _DtCvPointer fontPtr; char *charSet; const char *strChunk; char buffer[16]; _DtHelpFontHints fontSpecs; XmFontContext fontContext; XmString partTitle; XmString newTitle; XrmQuark charSetQuark; XrmName myCharSetQuarks[20]; XrmName xrmName[_CEFontAttrNumber]; Boolean myMore; /* * Initialize the pointers. */ *ret_title = NULL; *ret_mod = False; if (title_chunks == NULL) return -1; /* * initialize the font context */ _DtHelpCeCopyDefFontAttrList(&fontSpecs); if ( NULL != *ret_list ) { if (XmFontListInitFontContext (&fontContext, *ret_list) == False) result = -1; else { XFontStruct *myFontStruct; /* * quarkize all the character sets found. */ quarkCount = 0; do { myMore = XmFontListGetNextFont (fontContext, &charSet, &myFontStruct); if (myMore) { myCharSetQuarks[quarkCount++] = XrmStringToQuark (charSet); XtFree (charSet); } } while (myMore); XmFontListFreeFontContext (fontContext); } } /* if NULL != *ret_list */ else { /* if NULL == *ret_list */ quarkCount = 0; myCharSetQuarks[0] = 0; } /* * Build the XrmString based on the segments. * The format of the returned information is * 'DT_HELP_CE_CHARSET locale string' * 'DT_HELP_CE_FONT_PTR fontptr string' * 'DT_HELP_CE_SPC spc' * 'DT_HELP_CE_STRING string' - uses last specified * charset/font_ptr. * * The order and manner in which the title_chunks are processed * is known and depended upon in several locations. * Do not change this without changing the other locations. * See the _DtHelpFormatxxx() routines and the ones that * create the title_chunk arrays in FormatSDL.c and FormatCCDF.c */ myIdx = __DtHelpDefaultFontIndexGet(pDAS); _DtHelpCopyDefaultList(xrmName); for (i = 0; result == 0 && title_chunks[i] != DT_HELP_CE_END; i++) { /* * create a string for the char set and a quark for it. */ chunkType = (long) title_chunks[i++]; /* * i now points to the first value after the type */ if (chunkType & DT_HELP_CE_CHARSET) { char *charSet; char *lang = (char *) title_chunks[i]; /* * test to see if the locale is in a lang.codeset form */ if (_DtHelpCeStrchr(lang, ".", 1, &charSet) == 0) { *charSet = '\0'; charSet++; } else { charSet = lang; lang = NULL; } /* * resolve/load the font for the default fonts */ _DtHelpDAResolveFont(pDAS, lang, charSet, fontSpecs, &fontPtr); myIdx = (long) fontPtr; if (lang != NULL) { charSet--; *charSet = '.'; } if (free_flag) free(title_chunks[i]); /* * move the i to point to the string. */ i++; } else if (chunkType & DT_HELP_CE_FONT_PTR) { /* * get the default font for the language and code set. */ (void) __DtHelpFontCharSetQuarkGet(pDAS, (long)title_chunks[i], &xrmName[_DT_HELP_FONT_CHAR_SET]); (void) __DtHelpFontLangQuarkGet(pDAS, (long)title_chunks[i], &xrmName[_DT_HELP_FONT_LANG_TER]); (void) __DtHelpFontIndexGet(pDAS, xrmName, &myIdx); /* * move the i to point to the string. */ i++; } /* * the i point spc or string. */ if (chunkType & DT_HELP_CE_SPC) { j = (long) title_chunks[i]; strChunk = _DtHelpDAGetSpcString(pDAS->spc_chars[j].spc_idx); fontPtr = pDAS->spc_chars[j].font_ptr; /* * get the default font for the language and code set. */ (void) __DtHelpFontCharSetQuarkGet(pDAS, (long)fontPtr, &xrmName[_DT_HELP_FONT_CHAR_SET]); (void) __DtHelpFontLangQuarkGet(pDAS, (long)fontPtr, &xrmName[_DT_HELP_FONT_LANG_TER]); (void) __DtHelpFontIndexGet(pDAS, xrmName, &myIdx); } else /* if (chunkType & _DT_HELP_CE_STRING) */ strChunk = (char *) title_chunks[i]; sprintf(buffer, "%ld", myIdx); charSetQuark = XrmStringToQuark(buffer); j = 0; while (j < quarkCount && myCharSetQuarks[j] != charSetQuark) j++; /* * If we didn't find a matching character set, * add it to the list. */ if (j >= quarkCount) { /* Copy the input list so XmFontListAppendEntry can mangle it. */ /* But only do it once! */ if (False == *ret_mod) *ret_list = XmFontListCopy(*ret_list); if (myIdx < 0) { XFontSet fontSet = __DtHelpFontSetGet(pDAS->font_info, myIdx); XmFontListEntry fontEntry; fontEntry = XmFontListEntryCreate (buffer, XmFONT_IS_FONTSET, (XtPointer) fontSet); *ret_list = XmFontListAppendEntry (*ret_list, fontEntry); XmFontListEntryFree (&fontEntry); } else { XFontStruct *fontStruct = __DtHelpFontStructGet(pDAS->font_info, myIdx); XmFontListEntry fontEntry; fontEntry = XmFontListEntryCreate (buffer, XmFONT_IS_FONT, (XtPointer) fontStruct); *ret_list = XmFontListAppendEntry (*ret_list, fontEntry); XmFontListEntryFree (&fontEntry); } *ret_mod = True; if (*ret_list == NULL) result = -1; myCharSetQuarks[quarkCount++] = charSetQuark; } /* * add this segment to the XmString. */ if (result == 0) { if (*ret_title == NULL) *ret_title = XmStringGenerate ((char *) strChunk, buffer, XmCHARSET_TEXT, NULL); else { partTitle = XmStringGenerate ((char *) strChunk, buffer, XmCHARSET_TEXT, NULL); newTitle = XmStringConcat (*ret_title, partTitle); XmStringFree (*ret_title); XmStringFree (partTitle); *ret_title = newTitle; } /* * if a newline was specified, * replace it with a blank. */ if (*ret_title != NULL && (chunkType & DT_HELP_CE_NEWLINE)) { partTitle = XmStringGenerate (" ", buffer, XmCHARSET_TEXT, NULL); newTitle = XmStringConcat (*ret_title, partTitle); XmStringFree (*ret_title); XmStringFree (partTitle); *ret_title = newTitle; } if (*ret_title == NULL) result = -1; } if (free_flag && (chunkType & DT_HELP_CE_STRING)) free(title_chunks[i]); } /* * deallocate the memory. */ if (free_flag) free(title_chunks); return result; }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { char font_name[256], *heading_str[4] = { "FILE LOAD", "KBYTE LOAD", "CONNECTION LOAD", "ACTIVE TRANSFERS", }, *unit_str[4] = { "Files/s", "KBytes/s", "Connections/s", " " }, window_title[100], work_dir[MAX_PATH_LENGTH]; XtAppContext app_context; Widget appshell, bottom_separator_w, buttonbox_w, button_w, chart_w, headingbox_w, label_w, mainform_w, top_separator_w; static String fallback_res[] = { ".afd_load*mwmDecorations : 110", ".afd_load*mwmFunctions : 30", ".afd_load.mainform*background : NavajoWhite2", ".afd_load.mainform.headingbox.current_value*background : NavajoWhite1", ".afd_load.mainform.chart*background : NavajoWhite1", ".afd_load.mainform.buttonbox*background : PaleVioletRed2", ".afd_load.mainform.buttonbox*foreground : Black", ".afd_load.mainform.buttonbox*highlightColor : Black", NULL }; Arg args[MAXARGS]; Cardinal argcount; XmFontList fontlist; XmFontListEntry entry; uid_t euid, /* Effective user ID. */ ruid; /* Real user ID. */ CHECK_FOR_VERSION(argc, argv); /* Initialize global variables. */ p_work_dir = work_dir; init_afd_load(&argc, argv, font_name, window_title); /* * SSH uses wants to look at .Xauthority and with setuid flag * set we cannot do that. So when we initialize X lets temporaly * disable it. After XtAppInitialize() we set it back. */ euid = geteuid(); ruid = getuid(); if (euid != ruid) { if (seteuid(ruid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", ruid, strerror(errno)); } } argcount = 0; XtSetArg(args[argcount], XmNtitle, window_title); argcount++; appshell = XtAppInitialize(&app_context, "afd_load", NULL, 0, &argc, argv, fallback_res, args, argcount); if (euid != ruid) { if (seteuid(euid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", euid, strerror(errno)); } } #ifdef HAVE_XPM /* Setup AFD logo as icon. */ setup_icon(XtDisplay(appshell), appshell); #endif /* Create managing widget. */ mainform_w = XmCreateForm(appshell, "mainform", NULL, 0); /* Prepare font. */ if ((entry = XmFontListEntryLoad(XtDisplay(mainform_w), font_name, XmFONT_IS_FONT, "TAG1")) == NULL) { if ((entry = XmFontListEntryLoad(XtDisplay(mainform_w), "fixed", XmFONT_IS_FONT, "TAG1")) == NULL) { (void)fprintf(stderr, "Failed to load font with XmFontListEntryLoad() : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } } fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); /*-----------------------------------------------------------------------*/ /* Heading Box */ /* ----------- */ /*-----------------------------------------------------------------------*/ XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; headingbox_w = XmCreateForm(mainform_w, "headingbox", args, argcount); label_w = XtVaCreateManagedWidget(heading_str[(int)chart_type], xmLabelGadgetClass, headingbox_w, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 5, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 5, XmNfontList, fontlist, XmNalignment, XmALIGNMENT_BEGINNING, NULL); label_w = XtVaCreateManagedWidget(unit_str[(int)chart_type], xmLabelGadgetClass, headingbox_w, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 5, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 5, XmNfontList, fontlist, XmNalignment, XmALIGNMENT_BEGINNING, NULL); current_value_w = XtVaCreateWidget("current_value", xmTextWidgetClass, headingbox_w, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, label_w, XmNrightOffset, 5, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 5, XmNfontList, fontlist, XmNrows, 1, XmNcolumns, MAX_CURRENT_VALUE_DIGIT, XmNeditable, False, XmNcursorPositionVisible, False, XmNmarginHeight, 1, XmNmarginWidth, 1, XmNshadowThickness, 1, XmNhighlightThickness, 0, NULL); XtManageChild(current_value_w); XtManageChild(headingbox_w); /*-----------------------------------------------------------------------*/ /* Horizontal Separator */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNtopWidget, headingbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; top_separator_w = XmCreateSeparator(mainform_w, "top separator", args, argcount); XtManageChild(top_separator_w); /*-----------------------------------------------------------------------*/ /* Button Box */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; buttonbox_w = XmCreateForm(mainform_w, "buttonbox", args, argcount); button_w = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)close_button, (XtPointer)0); XtManageChild(buttonbox_w); /*-----------------------------------------------------------------------*/ /* Horizontal Separator */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, buttonbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; bottom_separator_w = XmCreateSeparator(mainform_w, "bottom separator", args, argcount); XtManageChild(bottom_separator_w); /*-----------------------------------------------------------------------*/ /* Chart Box */ /*-----------------------------------------------------------------------*/ chart_w = XtVaCreateManagedWidget("chart", stripChartWidgetClass, mainform_w, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, top_separator_w, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, bottom_separator_w, XtNupdate, (int)update_interval, XtNjumpScroll, 1, XtNheight, 100, XtNwidth, 260, NULL); if (chart_type == FILE_CHART) { XtAddCallback(chart_w, XtNgetValue, get_file_value, (XtPointer)0); } else if (chart_type == KBYTE_CHART) { XtAddCallback(chart_w, XtNgetValue, get_kbyte_value, (XtPointer)0); } else if (chart_type == CONNECTION_CHART) { XtAddCallback(chart_w, XtNgetValue, get_connection_value, (XtPointer)0); } else { XtAddCallback(chart_w, XtNgetValue, get_transfer_value, (XtPointer)0); } XtManageChild(mainform_w); /* Free font list. */ XmFontListFree(fontlist); /* Realize all widgets. */ XtRealizeWidget(appshell); XmTextSetString(current_value_w, " 0.00"); /* Start the main event-handling loop. */ XtAppMainLoop(app_context); exit(SUCCESS); }
void medmInit(char *displayFont) { XmFontListEntry entry; int i; char dashList[2]; Boolean useDefaultFont; char *sizePosition; #if 0 /* KE: This doesn't appear in the Motif documentation. * Assume it is not needed any more. */ XmRegisterConverters(); #endif #if 0 /* Register action table */ XtAppAddActions(appContext,actions,XtNumber(actions)); #endif /* Register a warning handler */ XtSetWarningHandler((XtErrorHandler)trapExtraneousWarningsHandler); /* Initialize alarm color array */ alarmColorPixel[NO_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[NO_ALARM]); alarmColorPixel[MINOR_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[MINOR_ALARM]); alarmColorPixel[MAJOR_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[MAJOR_ALARM]); alarmColorPixel[INVALID_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[INVALID_ALARM]); alarmColorPixel[ALARM_MAX-1]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[ALARM_MAX-1]); /* Initialize Channel Access */ medmCAInitialize(); /* Initialize DisplayInfo structures list */ displayInfoListHead = (DisplayInfo *)malloc(sizeof(DisplayInfo)); displayInfoListHead->next = NULL; displayInfoListTail = displayInfoListHead; /* Initialize DisplayInfoSave structures list */ displayInfoSaveListHead = (DisplayInfo *)malloc(sizeof(DisplayInfo)); displayInfoSaveListHead->next = NULL; displayInfoSaveListTail = displayInfoSaveListHead; /* Initialize common XmStrings */ dlXmStringMoreToComeSymbol = XmStringCreateLocalized(MORE_TO_COME_SYMBOL); /* Create the highlight GC */ highlightGC = XCreateGC(display,rootWindow,0,NULL); /* Eliminate events that we do not handle anyway */ XSetGraphicsExposures(display,highlightGC,False); /* Set the function to invert */ XSetFunction(display,highlightGC,GXinvert); /* Pick a color which XOR-ing with makes reasonable sense for most colors */ /* KE: Forground is irrelevant for GXinvert */ XSetForeground(display,highlightGC,WhitePixel(display,screenNum)); #if 0 XSetForeground(display,highlightGC,getPixelFromColormapByString(display, screenNum,cmap,"grey50")); #endif XSetLineAttributes(display,highlightGC,HIGHLIGHT_LINE_THICKNESS, LineOnOffDash,CapButt,JoinMiter); dashList[0] = 3; dashList[1] = 3; XSetDashes(display,highlightGC,0,dashList,2); /* Initialize the execute popup menu stuff for all shells. Must be consistent with medmWidget.h definitions. */ executePopupMenuButtonType[0] = XmPUSHBUTTON; executePopupMenuButtons[0] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_PRINT); executePopupMenuButtonType[1] = XmPUSHBUTTON; executePopupMenuButtons[1] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_CLOSE); executePopupMenuButtonType[2] = XmPUSHBUTTON; executePopupMenuButtons[2] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_PVINFO); executePopupMenuButtonType[3] = XmPUSHBUTTON; executePopupMenuButtons[3] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_PVLIMITS); executePopupMenuButtonType[4] = XmPUSHBUTTON; executePopupMenuButtons[4] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_MAIN); executePopupMenuButtonType[5] = XmPUSHBUTTON; executePopupMenuButtons[5] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_DISPLAY_LIST); executePopupMenuButtonType[6] = XmPUSHBUTTON; executePopupMenuButtons[6] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_FLASH_HIDDEN); executePopupMenuButtonType[7] = XmPUSHBUTTON; executePopupMenuButtons[7] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_REFRESH); executePopupMenuButtonType[8] = XmPUSHBUTTON; executePopupMenuButtons[8] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_RETRY); /* Note that the Execute Menu is a cascade button */ executePopupMenuButtonType[9] = XmCASCADEBUTTON; executePopupMenuButtons[9] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_EXECUTE); /* Load font and fontList tables (but only once) */ if(!strcmp(displayFont,FONT_ALIASES_STRING)) { /* Use the ALIAS fonts if possible */ strcpy(displayFont,ALIAS_FONT_PREFIX); sizePosition = strstr(displayFont,"_"); printf("\n%s: Loading aliased fonts.",MEDM_VERSION_STRING); for(i = 0; i < MAX_FONTS; i++) { sprintf(sizePosition,"_%d",fontSizeTable[i]); fontTable[i] = XLoadQueryFont(display,displayFont); printf("."); if(fontTable[i] == NULL) { medmPrintf(1,"\nmedmInit: Unable to load font %s\n" " Trying default (fixed) instead\n", displayFont); /* one last attempt: try a common default font */ fontTable[i] = XLoadQueryFont(display,LAST_CHANCE_FONT); if(fontTable[i] == NULL) { medmCATerminate(); dmTerminateX(); exit(-1); } } /* Load the XmFontList table for Motif font sizing */ entry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, (XtPointer)fontTable[i]); fontListTable[i] = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); } } else { /* Try using scalable font - either default or passed in one */ /* User requested default scalable, copy that name into string and proceed */ if(!strcmp(displayFont,DEFAULT_SCALABLE_STRING)) strcpy(displayFont,DEFAULT_SCALABLE_DISPLAY_FONT); useDefaultFont = !isScalableFont(displayFont); if(useDefaultFont) { /* This name wasn't in XLFD format */ medmPrintf(1,"\nmedmInit:" " Invalid scalable display font selected (Not in XLFD format)\n" " font: %s\n" " Using fixed font\n",displayFont); } else { printf("\n%s: Loading scalable fonts.",MEDM_VERSION_STRING); } for(i = 0; i < MAX_FONTS; i++) { if(!useDefaultFont) { fontTable[i] = loadQueryScalableFont(display, screenNum, displayFont, fontSizeTable[i]); printf("."); } else { fontTable[i] = XLoadQueryFont(display,LAST_CHANCE_FONT); } if(fontTable[i] == NULL) { medmCATerminate(); dmTerminateX(); exit(-1); } /* Load the XmFontList table for Motif font sizing */ entry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, (XtPointer)fontTable[i]); fontListTable[i] = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); } } printf("\n"); }
/*######################### setup_mon_window() #########################*/ void setup_mon_window(char *font_name) { int i, his_log_length, led_width, new_max_bar_length; XmFontListEntry entry; /* Get width and height of font and fid for the GC. */ if (font_struct != NULL) { XFreeFont(display, font_struct); font_struct = NULL; } if (fontlist != NULL) { XmFontListFree(fontlist); fontlist = NULL; } if ((font_struct = XLoadQueryFont(display, font_name)) == NULL) { (void)fprintf(stderr, "Could not load %s font.\n", font_name); if ((font_struct = XLoadQueryFont(display, DEFAULT_FONT)) == NULL) { (void)fprintf(stderr, "Could not load %s font.\n", DEFAULT_FONT); exit(INCORRECT); } else { (void)strcpy(font_name, DEFAULT_FONT); } } if ((entry = XmFontListEntryLoad(display, font_name, XmFONT_IS_FONT, "TAG1")) == NULL) { (void)fprintf(stderr, "Failed to load font with XmFontListEntryLoad() : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); if (line_height != 0) { /* Set the font for the monitor pulldown. */ XtVaSetValues(mw[MON_W], XmNfontList, fontlist, NULL); if ((mcp.show_ms_log != NO_PERMISSION) || (mcp.show_mon_log != NO_PERMISSION) || (mcp.mon_info != NO_PERMISSION) || (mcp.retry != NO_PERMISSION) || (mcp.switch_afd != NO_PERMISSION) || (mcp.disable != NO_PERMISSION)) { if (mcp.show_ms_log != NO_PERMISSION) { XtVaSetValues(ow[MON_SYS_LOG_W], XmNfontList, fontlist, NULL); XtVaSetValues(pw[0], XmNfontList, fontlist, NULL); } if (mcp.show_mon_log != NO_PERMISSION) { XtVaSetValues(ow[MON_LOG_W], XmNfontList, fontlist, NULL); XtVaSetValues(pw[1], XmNfontList, fontlist, NULL); } if (mcp.mon_info != NO_PERMISSION) { XtVaSetValues(ow[MON_INFO_W], XmNfontList, fontlist, NULL); XtVaSetValues(pw[4], XmNfontList, fontlist, NULL); } if (mcp.retry != NO_PERMISSION) { XtVaSetValues(ow[MON_RETRY_W], XmNfontList, fontlist, NULL); XtVaSetValues(pw[2], XmNfontList, fontlist, NULL); } if (mcp.switch_afd != NO_PERMISSION) { XtVaSetValues(ow[MON_SWITCH_W], XmNfontList, fontlist, NULL); XtVaSetValues(pw[3], XmNfontList, fontlist, NULL); } if (mcp.disable != NO_PERMISSION) { XtVaSetValues(ow[MON_DISABLE_W], XmNfontList, fontlist, NULL); XtVaSetValues(pw[5], XmNfontList, fontlist, NULL); } if ((ping_cmd != NULL) || (traceroute_cmd != NULL)) { XtVaSetValues(ow[MON_TEST_W], XmNfontList, fontlist, NULL); if (ping_cmd != NULL) { XtVaSetValues(tw[PING_W], XmNfontList, fontlist, NULL); } if (traceroute_cmd != NULL) { XtVaSetValues(tw[TRACEROUTE_W], XmNfontList, fontlist, NULL); } } } XtVaSetValues(ow[MON_SELECT_W], XmNfontList, fontlist, NULL); XtVaSetValues(ow[MON_EXIT_W], XmNfontList, fontlist, NULL); /* Set the font for the RAFD pulldown. */ if ((mcp.afd_ctrl != NO_PERMISSION) || (mcp.show_slog != NO_PERMISSION) || (mcp.show_elog != NO_PERMISSION) || (mcp.show_rlog != NO_PERMISSION) || (mcp.show_tlog != NO_PERMISSION) || (mcp.show_ilog != NO_PERMISSION) || (mcp.show_plog != NO_PERMISSION) || (mcp.show_olog != NO_PERMISSION) || (mcp.show_dlog != NO_PERMISSION) || (mcp.show_queue != NO_PERMISSION) || (mcp.afd_load != NO_PERMISSION)) { XtVaSetValues(mw[LOG_W], XmNfontList, fontlist, NULL); if (mcp.afd_ctrl != NO_PERMISSION) { XtVaSetValues(vw[MON_AFD_CTRL_W], XmNfontList, fontlist, NULL); } if (mcp.show_slog != NO_PERMISSION) { XtVaSetValues(vw[MON_SYSTEM_W], XmNfontList, fontlist, NULL); } if (mcp.show_elog != NO_PERMISSION) { XtVaSetValues(vw[MON_EVENT_W], XmNfontList, fontlist, NULL); } if (mcp.show_rlog != NO_PERMISSION) { XtVaSetValues(vw[MON_RECEIVE_W], XmNfontList, fontlist, NULL); } if (mcp.show_tlog != NO_PERMISSION) { XtVaSetValues(vw[MON_TRANS_W], XmNfontList, fontlist, NULL); } if (mcp.show_ilog != NO_PERMISSION) { XtVaSetValues(vw[MON_INPUT_W], XmNfontList, fontlist, NULL); } if (mcp.show_plog != NO_PERMISSION) { XtVaSetValues(vw[MON_PRODUCTION_W], XmNfontList, fontlist, NULL); } if (mcp.show_olog != NO_PERMISSION) { XtVaSetValues(vw[MON_OUTPUT_W], XmNfontList, fontlist, NULL); } if (mcp.show_dlog != NO_PERMISSION) { XtVaSetValues(vw[MON_DELETE_W], XmNfontList, fontlist, NULL); } if (mcp.show_queue != NO_PERMISSION) { XtVaSetValues(vw[MON_SHOW_QUEUE_W], XmNfontList, fontlist, NULL); } if (mcp.afd_load != NO_PERMISSION) { XtVaSetValues(vw[MON_VIEW_LOAD_W], XmNfontList, fontlist, NULL); XtVaSetValues(lw[FILE_LOAD_W], XmNfontList, fontlist, NULL); XtVaSetValues(lw[KBYTE_LOAD_W], XmNfontList, fontlist, NULL); XtVaSetValues(lw[CONNECTION_LOAD_W], XmNfontList, fontlist, NULL); XtVaSetValues(lw[TRANSFER_LOAD_W], XmNfontList, fontlist, NULL); } } /* Set the font for the Control pulldown. */ if ((mcp.amg_ctrl != NO_PERMISSION) || (mcp.fd_ctrl != NO_PERMISSION) || (mcp.rr_dc != NO_PERMISSION) || (mcp.rr_hc != NO_PERMISSION) || (mcp.edit_hc != NO_PERMISSION) || (mcp.dir_ctrl != NO_PERMISSION) || (mcp.startup_afd != NO_PERMISSION) || (mcp.shutdown_afd != NO_PERMISSION)) { XtVaSetValues(mw[CONTROL_W], XmNfontList, fontlist, NULL); if (mcp.amg_ctrl != NO_PERMISSION) { XtVaSetValues(cw[AMG_CTRL_W], XmNfontList, fontlist, NULL); } if (mcp.fd_ctrl != NO_PERMISSION) { XtVaSetValues(cw[FD_CTRL_W], XmNfontList, fontlist, NULL); } if (mcp.rr_dc != NO_PERMISSION) { XtVaSetValues(cw[RR_DC_W], XmNfontList, fontlist, NULL); } if (mcp.rr_hc != NO_PERMISSION) { XtVaSetValues(cw[RR_HC_W], XmNfontList, fontlist, NULL); } if (mcp.edit_hc != NO_PERMISSION) { XtVaSetValues(cw[EDIT_HC_W], XmNfontList, fontlist, NULL); } if (mcp.dir_ctrl != NO_PERMISSION) { XtVaSetValues(cw[DIR_CTRL_W], XmNfontList, fontlist, NULL); } if (mcp.startup_afd != NO_PERMISSION) { XtVaSetValues(cw[STARTUP_AFD_W], XmNfontList, fontlist, NULL); } if (mcp.shutdown_afd != NO_PERMISSION) { XtVaSetValues(cw[SHUTDOWN_AFD_W], XmNfontList, fontlist, NULL); } } /* Set the font for the Setup pulldown. */ XtVaSetValues(mw[CONFIG_W], XmNfontList, fontlist, NULL); XtVaSetValues(sw[FONT_W], XmNfontList, fontlist, NULL); XtVaSetValues(sw[ROWS_W], XmNfontList, fontlist, NULL); XtVaSetValues(sw[STYLE_W], XmNfontList, fontlist, NULL); XtVaSetValues(sw[HISTORY_W], XmNfontList, fontlist, NULL); XtVaSetValues(sw[MON_OTHER_W], XmNfontList, fontlist, NULL); if (have_groups == YES) { XtVaSetValues(sw[MON_OPEN_ALL_GROUPS_W], XmNfontList, fontlist, NULL); XtVaSetValues(sw[MON_CLOSE_ALL_GROUPS_W], XmNfontList, fontlist, NULL); } XtVaSetValues(sw[MON_SAVE_W], XmNfontList, fontlist, NULL); /* Set the font for the Help pulldown. */ #ifdef _WITH_HELP_PULLDOWN XtVaSetValues(mw[HELP_W], XmNfontList, fontlist, NULL); XtVaSetValues(hw[ABOUT_W], XmNfontList, fontlist, NULL); XtVaSetValues(hw[HYPER_W], XmNfontList, fontlist, NULL); XtVaSetValues(hw[VERSION_W], XmNfontList, fontlist, NULL); #endif /* Set the font for the Row pulldown. */ XtVaSetValues(rw[ROW_0_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_1_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_2_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_3_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_4_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_5_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_6_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_7_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_8_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_9_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_10_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_11_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_12_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_13_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_14_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_15_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_16_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_17_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_18_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_19_W], XmNfontList, fontlist, NULL); XtVaSetValues(rw[ROW_20_W], XmNfontList, fontlist, NULL); /* Set the font for the Line Style pulldown. */ XtVaSetValues(lsw[STYLE_0_W], XmNfontList, fontlist, NULL); XtVaSetValues(lsw[STYLE_1_W], XmNfontList, fontlist, NULL); XtVaSetValues(lsw[STYLE_2_W], XmNfontList, fontlist, NULL); /* Set the font for the history pulldown. */ for (i = 0; i < NO_OF_HISTORY_LOGS; i++) { XtVaSetValues(hlw[i], XmNfontList, fontlist, NULL); } /* Set the font for the Other options pulldown. */ XtVaSetValues(oow[FORCE_SHIFT_SELECT_W], XmNfontList, fontlist, NULL); XtVaSetValues(oow[AUTO_SAVE_W], XmNfontList, fontlist, NULL); XtVaSetValues(oow[FRAMED_GROUPS_W], XmNfontList, fontlist, NULL); } glyph_height = font_struct->ascent + font_struct->descent; glyph_width = font_struct->per_char->width; new_max_bar_length = glyph_width * BAR_LENGTH_MODIFIER; /* We now have to recalculate the length of all */ /* bars and the scale, because a font change */ /* might have occurred. */ if (new_max_bar_length != max_bar_length) { unsigned int new_bar_length; max_bar_length = new_max_bar_length; step_size = MAX_INTENSITY / max_bar_length; /* NOTE: We do not care what the line style is because the */ /* following could happen: font size = 7x13 style = */ /* chars + bars, the user now wants chars only and */ /* then reduces the font to 5x7. After a while he */ /* wants the bars again. Thus we always need to re- */ /* calculate the bar length and queue scale! */ for (i = 0; i < no_of_afds; i++) { /* Calculate new scale for active transfers bar. */ if (connect_data[i].max_connections < 1) { connect_data[i].scale[ACTIVE_TRANSFERS_BAR_NO - 1] = (double)max_bar_length; } else { connect_data[i].scale[ACTIVE_TRANSFERS_BAR_NO - 1] = max_bar_length / connect_data[i].max_connections; } if (connect_data[i].no_of_transfers == 0) { new_bar_length = 0; } else if (connect_data[i].no_of_transfers >= connect_data[i].max_connections) { new_bar_length = max_bar_length; } else { new_bar_length = connect_data[i].no_of_transfers * connect_data[i].scale[ACTIVE_TRANSFERS_BAR_NO - 1]; } if (new_bar_length >= max_bar_length) { connect_data[i].bar_length[ACTIVE_TRANSFERS_BAR_NO] = max_bar_length; connect_data[i].blue_color_offset = MAX_INTENSITY; connect_data[i].green_color_offset = 0; } else { connect_data[i].bar_length[ACTIVE_TRANSFERS_BAR_NO] = new_bar_length; connect_data[i].blue_color_offset = new_bar_length * step_size; connect_data[i].green_color_offset = MAX_INTENSITY - connect_data[i].blue_color_offset; } /* Calculate new scale for error bar. */ if (connect_data[i].no_of_hosts < 1) { connect_data[i].scale[HOST_ERROR_BAR_NO - 1] = (double)max_bar_length; } else { connect_data[i].scale[HOST_ERROR_BAR_NO - 1] = max_bar_length / connect_data[i].no_of_hosts; } if (connect_data[i].host_error_counter == 0) { connect_data[i].bar_length[HOST_ERROR_BAR_NO] = 0; } else if (connect_data[i].host_error_counter >= connect_data[i].no_of_hosts) { connect_data[i].bar_length[HOST_ERROR_BAR_NO] = max_bar_length; } else { connect_data[i].bar_length[HOST_ERROR_BAR_NO] = connect_data[i].host_error_counter * connect_data[i].scale[HOST_ERROR_BAR_NO - 1]; } /* Calculate new bar length for the transfer rate. */ if (connect_data[i].average_tr > 1.0) { /* First ensure we do not divide by zero. */ if (connect_data[i].max_average_tr < 2.0) { connect_data[i].bar_length[MON_TR_BAR_NO] = log10(connect_data[i].average_tr) * max_bar_length / log10((double) 2.0); } else { connect_data[i].bar_length[MON_TR_BAR_NO] = log10(connect_data[i].average_tr) * max_bar_length / log10(connect_data[i].max_average_tr); } } else { connect_data[i].bar_length[MON_TR_BAR_NO] = 0; } } /* for (i = 0; i < no_of_afds; i++) */ } text_offset = font_struct->ascent; line_height = SPACE_ABOVE_LINE + glyph_height + SPACE_BELOW_LINE; bar_thickness_3 = glyph_height / 3; y_offset_led = (glyph_height - glyph_width) / 2; led_width = glyph_height / 3; y_center_log = SPACE_ABOVE_LINE + (glyph_height / 2); if (his_log_set > 0) { his_log_length = (his_log_set * bar_thickness_3) + DEFAULT_FRAME_SPACE; } else { his_log_length = 0; } line_length = DEFAULT_FRAME_SPACE + (MAX_AFDNAME_LENGTH * glyph_width) + DEFAULT_FRAME_SPACE + (3 * (led_width + PROC_LED_SPACING)) + glyph_height + (glyph_height / 2) + DEFAULT_FRAME_SPACE + his_log_length + DEFAULT_FRAME_SPACE; if (line_style == BARS_ONLY) { line_length += (int)max_bar_length + DEFAULT_FRAME_SPACE; } else if (line_style == CHARACTERS_ONLY) { line_length += (32 * glyph_width) + DEFAULT_FRAME_SPACE; } else { line_length += (32 * glyph_width) + DEFAULT_FRAME_SPACE + (int)max_bar_length + DEFAULT_FRAME_SPACE; } x_offset_led = DEFAULT_FRAME_SPACE + (MAX_AFDNAME_LENGTH * glyph_width) + DEFAULT_FRAME_SPACE; x_offset_log_status = x_offset_led + (3 * (led_width + PROC_LED_SPACING)) + (glyph_height / 2) + DEFAULT_FRAME_SPACE; x_center_log_status = x_offset_log_status + (glyph_height / 2); x_offset_log_history = x_offset_log_status + glyph_height + DEFAULT_FRAME_SPACE; for (i = 0; i < LOG_FIFO_SIZE; i++) { coord[i].x = x_center_log_status + (int)((glyph_height / 2) * cos((double)((log_angle * i * PI) / 180))); coord[i].y = y_center_log - (int)((glyph_height / 2) * sin((double)((log_angle * i * PI) / 180))); } if (line_style == BARS_ONLY) { x_offset_bars = x_offset_log_history + his_log_length; } else if (line_style == CHARACTERS_ONLY) { x_offset_characters = x_offset_log_history + his_log_length; x_offset_ec = x_offset_characters + (27 * glyph_width); x_offset_eh = x_offset_ec + (3 *glyph_width); } else { x_offset_characters = x_offset_log_history + his_log_length; x_offset_bars = x_offset_characters + (32 * glyph_width) + DEFAULT_FRAME_SPACE; x_offset_ec = x_offset_characters + (27 * glyph_width); x_offset_eh = x_offset_ec + (3 *glyph_width); } return; }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { char window_title[MAX_TITLE_CMD_LENGTH + 1 + 25 + 1]; static String fallback_res[] = { ".show_cmd*mwmDecorations : 110", ".show_cmd*mwmFunctions : 30", ".show_cmd.mainform_w.cmd_outputSW*XmText.fontList : fixed", ".show_cmd*background : NavajoWhite2", ".show_cmd.mainform_w.cmd_outputSW.cmd_output.background : NavajoWhite1", ".show_cmd.mainform_w.buttonbox_w*background : PaleVioletRed2", ".show_cmd.mainform_w.buttonbox_w*foreground : Black", ".show_cmd.mainform_w.buttonbox_w*highlightColor : Black", ".show_cmd.Print Data*background : NavajoWhite2", ".show_cmd.Print Data*XmText.background : NavajoWhite1", ".show_cmd.Print Data.main_form.buttonbox*background : PaleVioletRed2", ".show_cmd.Print Data.main_form.buttonbox*foreground : Black", ".show_cmd.Print Data.main_form.buttonbox*highlightColor : Black", NULL }; Widget mainform_w, button, buttonbox_w, separator_w; Arg args[MAXARGS]; Cardinal argcount; XmFontListEntry entry; XmFontList fontlist; uid_t euid, /* Effective user ID. */ ruid; /* Real user ID. */ CHECK_FOR_VERSION(argc, argv); p_work_dir = work_dir; init_cmd(&argc, argv, window_title); /* * SSH wants to look at .Xauthority and with setuid flag * set we cannot do that. So when we initialize X lets temporaly * disable it. After XtAppInitialize() we set it back. */ euid = geteuid(); ruid = getuid(); if (euid != ruid) { if (seteuid(ruid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", ruid, strerror(errno)); } } argcount = 0; XtSetArg(args[argcount], XmNtitle, window_title); argcount++; appshell = XtAppInitialize(&app, "AFD", NULL, 0, &argc, argv, fallback_res, args, argcount); disable_drag_drop(appshell); if (euid != ruid) { if (seteuid(euid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", euid, strerror(errno)); } } if ((display = XtDisplay(appshell)) == NULL) { (void)fprintf(stderr, "ERROR : Could not open Display : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } #ifdef HAVE_XPM /* Setup AFD logo as icon. */ setup_icon(display, appshell); #endif /* Create managing widget. */ mainform_w = XmCreateForm(appshell, "mainform_w", NULL, 0); /* Prepare the font. */ entry = XmFontListEntryLoad(XtDisplay(appshell), font_name, XmFONT_IS_FONT, "TAG1"); fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); argcount = 0; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNfractionBase, 31); argcount++; buttonbox_w = XmCreateForm(mainform_w, "buttonbox_w", args, argcount); button = XtVaCreateManagedWidget("Repeat", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 1, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 10, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 30, NULL); XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)repeat_button, 0); button = XtVaCreateManagedWidget("Print", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 1, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 11, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 20, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 30, NULL); XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)print_button, 0); button = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 1, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 21, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 30, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 30, NULL); XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)close_button, 0); XtManageChild(buttonbox_w); /*-----------------------------------------------------------------------*/ /* Horizontal Separator */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, buttonbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; separator_w = XmCreateSeparator(mainform_w, "separator", args, argcount); XtManageChild(separator_w); /*-----------------------------------------------------------------------*/ /* Status Box */ /* ---------- */ /* The status of the output log is shown here. If eg. no files are found */ /* it will be shown here. */ /*-----------------------------------------------------------------------*/ statusbox_w = XtVaCreateManagedWidget(" ", xmLabelWidgetClass, mainform_w, XmNfontList, fontlist, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, separator_w, NULL); /*-----------------------------------------------------------------------*/ /* Horizontal Separator */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, statusbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; separator_w = XmCreateSeparator(mainform_w, "separator", args, argcount); XtManageChild(separator_w); /* Create cmd_output as a ScrolledText window. */ argcount = 0; XtSetArg(args[argcount], XmNrows, 18); argcount++; XtSetArg(args[argcount], XmNcolumns, 80); argcount++; XtSetArg(args[argcount], XmNeditable, False); argcount++; XtSetArg(args[argcount], XmNeditMode, XmMULTI_LINE_EDIT); argcount++; XtSetArg(args[argcount], XmNwordWrap, False); argcount++; XtSetArg(args[argcount], XmNscrollHorizontal, True); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, True); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, False); argcount++; XtSetArg(args[argcount], XmNfontList, fontlist); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, separator_w); argcount++; cmd_output = XmCreateScrolledText(mainform_w, "cmd_output", args, argcount); XtManageChild(cmd_output); XtManageChild(mainform_w); #ifdef WITH_EDITRES XtAddEventHandler(appshell, (EventMask)0, True, _XEditResCheckMessages, NULL); #endif /* Realize all widgets. */ XtRealizeWidget(appshell); /* Set some signal handlers. */ if ((signal(SIGBUS, sig_bus) == SIG_ERR) || (signal(SIGSEGV, sig_segv) == SIG_ERR)) { (void)xrec(WARN_DIALOG, "Failed to set signal handler's for %s : %s", SHOW_CMD, strerror(errno)); } xexec_cmd(cmd); /* We want the keyboard focus on the cmd output. */ XmProcessTraversal(cmd_output, XmTRAVERSE_CURRENT); /* Start the main event-handling loop. */ XtAppMainLoop(app); exit(SUCCESS); }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int glyph_height, max_vertical_lines; char window_title[100], work_dir[MAX_PATH_LENGTH]; static String fallback_res[] = { "*mwmDecorations : 42", "*mwmFunctions : 12", ".view_dc.form*background : NavajoWhite2", ".view_dc.form.buttonbox2.searchbox*background : NavajoWhite1", ".view_dc.form.dc_textSW.dc_text.background : NavajoWhite1", ".view_dc.form.buttonbox*background : PaleVioletRed2", ".view_dc.form.buttonbox*foreground : Black", ".view_dc.form.buttonbox*highlightColor : Black", NULL }; Widget form_w, button_w, buttonbox_w, h_separator_w; XmFontListEntry entry; XFontStruct *font_struct; XmFontList fontlist; XmFontType dummy; Arg args[MAXARGS]; Cardinal argcount; uid_t euid, /* Effective user ID. */ ruid; /* Real user ID. */ CHECK_FOR_VERSION(argc, argv); /* Initialise global values. */ p_work_dir = work_dir; init_view_dc(&argc, argv); /* * SSH uses wants to look at .Xauthority and with setuid flag * set we cannot do that. So when we initialize X lets temporaly * disable it. After XtAppInitialize() we set it back. */ euid = geteuid(); ruid = getuid(); if (euid != ruid) { if (seteuid(ruid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", ruid, strerror(errno)); } } (void)strcpy(window_title, "DIR_CONFIG "); (void)strcat(window_title, p_title); argcount = 0; XtSetArg(args[argcount], XmNtitle, window_title); argcount++; appshell = XtAppInitialize(&app, "AFD", NULL, 0, &argc, argv, fallback_res, args, argcount); disable_drag_drop(appshell); if (euid != ruid) { if (seteuid(euid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", euid, strerror(errno)); } } /* Get display pointer. */ if ((display = XtDisplay(appshell)) == NULL) { (void)fprintf(stderr, "ERROR : Could not open Display : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } #ifdef HAVE_XPM /* Setup AFD logo as icon. */ setup_icon(display, appshell); #endif /* Create managing widget. */ form_w = XmCreateForm(appshell, "form", NULL, 0); if ((entry = XmFontListEntryLoad(XtDisplay(form_w), font_name, XmFONT_IS_FONT, "TAG1")) == NULL) { if ((entry = XmFontListEntryLoad(XtDisplay(form_w), "fixed", XmFONT_IS_FONT, "TAG1")) == NULL) { (void)fprintf(stderr, "Failed to load font with XmFontListEntryLoad() : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } } font_struct = (XFontStruct *)XmFontListEntryGetFont(entry, &dummy); glyph_height = font_struct->ascent + font_struct->descent; fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); /* Calculate the maximum lines to show. */ max_vertical_lines = (8 * (DisplayHeight(display, DefaultScreen(display)) / glyph_height)) / 10; if (max_y > max_vertical_lines) { max_y = max_vertical_lines; } argcount = 0; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNfractionBase, 21); argcount++; buttonbox_w = XmCreateForm(form_w, "buttonbox", args, argcount); /* Create a horizontal separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, buttonbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; h_separator_w = XmCreateSeparator(form_w, "h_separator", args, argcount); XtManageChild(h_separator_w); button_w = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 19, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 20, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)close_button, (XtPointer)0); XtManageChild(buttonbox_w); /* Create DIR_CONFIG data as a ScrolledText window. */ argcount = 0; XtSetArg(args[argcount], XmNfontList, fontlist); argcount++; XtSetArg(args[argcount], XmNeditable, False); argcount++; XtSetArg(args[argcount], XmNeditMode, XmMULTI_LINE_EDIT); argcount++; XtSetArg(args[argcount], XmNwordWrap, False); argcount++; XtSetArg(args[argcount], XmNscrollHorizontal, False); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, False); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, False); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftOffset, 3); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightOffset, 3); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, h_separator_w); argcount++; XtSetArg(args[argcount], XmNbottomOffset, 3); argcount++; XtSetArg(args[argcount], XmNrows, max_y); argcount++; XtSetArg(args[argcount], XmNcolumns, max_x); argcount++; XtSetArg(args[argcount], XmNvalue, view_buffer); argcount++; text_w = XmCreateScrolledText(form_w, "dc_text", args, argcount); XtManageChild(text_w); /* Create a horizontal separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, text_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; h_separator_w = XmCreateSeparator(form_w, "h_separator", args, argcount); XtManageChild(h_separator_w); argcount = 0; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNtopOffset, 1); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, h_separator_w); argcount++; XtSetArg(args[argcount], XmNbottomOffset, 1); argcount++; XtSetArg(args[argcount], XmNfractionBase, 31); argcount++; buttonbox_w = XmCreateForm(form_w, "buttonbox2", args, argcount); searchbox_w = XtVaCreateWidget("searchbox", xmTextWidgetClass, buttonbox_w, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 5, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 26, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 20, XmNfontList, fontlist, XmNrows, 1, XmNeditable, True, XmNcursorPositionVisible, True, XmNmarginHeight, 1, XmNmarginWidth, 1, XmNshadowThickness, 1, XmNhighlightThickness, 0, NULL); XtManageChild(searchbox_w); button_w = XtVaCreateManagedWidget("Search", xmPushButtonWidgetClass, buttonbox_w, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 22, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 28, XmNtopAttachment, XmATTACH_FORM, XmNfontList, fontlist, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)search_button, (XtPointer)0); XtManageChild(buttonbox_w); XtManageChild(form_w); /* Free font list. */ XmFontListFree(fontlist); #ifdef WITH_EDITRES XtAddEventHandler(appshell, (EventMask)0, True, _XEditResCheckMessages, NULL); #endif /* Realize all widgets. */ XtRealizeWidget(appshell); /* We want the keyboard focus on the Close button. */ XmProcessTraversal(button_w, XmTRAVERSE_CURRENT); /* Write window ID, so afd_ctrl can set focus if it is called again. */ write_window_id(XtWindow(appshell), getpid(), VIEW_DC); /* Start the main event-handling loop. */ XtAppMainLoop(app); exit(SUCCESS); }