"Fossies" - the Fresh Open Source Software Archive

Member "grace-5.1.25/src/helpwin.c" (14 Feb 2015, 17447 Bytes) of package /linux/misc/grace-5.1.25.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "helpwin.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.1.24_vs_5.1.25.

    1 /*
    2  * Grace - GRaphing, Advanced Computation and Exploration of data
    3  * 
    4  * Home page: http://plasma-gate.weizmann.ac.il/Grace/
    5  * 
    6  * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
    7  * Copyright (c) 1996-2002 Grace Development Team
    8  * 
    9  * Maintained by Evgeny Stambulchik
   10  * 
   11  * 
   12  *                           All Rights Reserved
   13  * 
   14  *    This program is free software; you can redistribute it and/or modify
   15  *    it under the terms of the GNU General Public License as published by
   16  *    the Free Software Foundation; either version 2 of the License, or
   17  *    (at your option) any later version.
   18  * 
   19  *    This program is distributed in the hope that it will be useful,
   20  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
   21  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22  *    GNU General Public License for more details.
   23  * 
   24  *    You should have received a copy of the GNU General Public License
   25  *    along with this program; if not, write to the Free Software
   26  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   27  */
   28 
   29 #include <config.h>
   30 
   31 #include <stdlib.h>
   32 #include <string.h>
   33 
   34 #include "utils.h"
   35 #include "files.h"
   36 #include "protos.h"
   37 
   38 #include "motifinc.h"
   39 
   40 #define NO_HELP "doc/nohelp.html"
   41 
   42 #ifdef WITH_LIBHELP
   43 #  include <help.h>
   44 #endif
   45 
   46 #ifdef WITH_XMHTML
   47 #  include <XmHTML/XmHTML.h>
   48 void create_helper_frame(char *fname);
   49 #endif
   50 
   51 int force_external_viewer =
   52 #if defined WITH_XMHTML || defined WITH_LIBHELP
   53     FALSE;
   54 #else
   55     TRUE;
   56 #endif
   57 
   58 void HelpCB(void *data)
   59 {
   60     char *URL, *ha;
   61     int remote;
   62 
   63     ha = (char *) data;
   64     
   65     if (ha == NULL) {
   66         ha = NO_HELP;
   67     }
   68     
   69     if (strstr(ha, "http:") || strstr(ha, "ftp:") || strstr(ha, "mailto:")) {
   70         URL = copy_string(NULL, ha);
   71         remote = TRUE;
   72     } else {
   73         char *p, *pa;
   74         
   75         if (ha == strstr(ha, "file:")) {
   76             p = (ha + 5);
   77         } else {
   78             p = ha;
   79         }
   80 
   81         pa = strchr(p, '#');
   82         if (pa) {
   83             char *base = copy_string(NULL, p);
   84             base[pa - p] = '\0';
   85             if (force_external_viewer) {
   86                 URL = copy_string(NULL, "file://");
   87             } else {
   88                 URL = NULL;
   89             }
   90             URL = concat_strings(URL, grace_path(base));
   91             URL = concat_strings(URL, pa);
   92             xfree(base);
   93         } else {
   94             URL = copy_string(NULL, grace_path(p));
   95         }
   96 
   97         remote = FALSE;
   98     }
   99     
  100     if (remote || force_external_viewer) {
  101         char *help_viewer, *command;
  102         int i, j, len, urllen, comlen;
  103         
  104         help_viewer = get_help_viewer();
  105         len = strlen(help_viewer);
  106         urllen = strlen(URL);
  107         for (i = 0, comlen = len; i < len - 1; i++) {
  108             if ((help_viewer[i] == '%') && (help_viewer[i + 1] == 's')){
  109                 comlen += urllen - 2;
  110                 i++;
  111             }
  112         }
  113         command = xmalloc((comlen + 1)*SIZEOF_CHAR);
  114         command[comlen] = '\0';
  115         for (i = 0, j = 0; i < len; i++) {
  116             if ((help_viewer[i] == '%') && (help_viewer[i + 1] == 's')){
  117                 strcpy (&command[j], URL);
  118                 j += urllen;
  119                 i++;
  120             } else {
  121                 command[j++] = help_viewer[i];
  122             }
  123         }
  124 #ifdef VMS    
  125         system_spawn(command);
  126 #else
  127         command = concat_strings(command, "&");    
  128         system_wrap(command);
  129 #endif
  130         xfree(command);
  131     } else {
  132 #ifdef WITH_XMHTML
  133         create_helper_frame(URL);
  134 #endif
  135 #ifdef WITH_LIBHELP
  136         get_help(app_shell, (XtPointer) URL, NULL);
  137 #endif
  138     }
  139     
  140     xfree(URL);
  141 }
  142 
  143 /*
  144  * say a few things about Grace
  145  */
  146 static Widget about_frame;
  147 
  148 void create_about_grtool(void *data)
  149 {
  150     set_wait_cursor();
  151     
  152     if (about_frame == NULL) {
  153         Widget wbut, fr, rc, about_panel;
  154         char buf[1024];
  155         
  156     about_frame = CreateDialogForm(app_shell, "About");
  157     
  158         about_panel = CreateVContainer(about_frame);
  159         AddDialogFormChild(about_frame, about_panel);
  160 
  161     fr = CreateFrame(about_panel, NULL);
  162         rc = CreateVContainer(fr);
  163     CreateLabel(rc, bi_version_string());
  164 #ifdef DEBUG
  165     CreateLabel(rc, "Debugging is enabled");
  166 #endif
  167 
  168     fr = CreateFrame(about_panel, "Legal stuff");
  169         rc = CreateVContainer(fr);
  170     CreateLabel(rc, "Copyright (c) 1991-1995 Paul J Turner");
  171     CreateLabel(rc, "Copyright (c) 1996-2015 Grace Development Team");
  172     CreateLabel(rc, "Maintained by Evgeny Stambulchik");
  173     CreateLabel(rc, "All rights reserved");
  174     CreateLabel(rc,
  175             "The program is distributed under the terms of the GNU General Public License");
  176 
  177     fr = CreateFrame(about_panel, "Third party copyrights");
  178         rc = CreateVContainer(fr);
  179     CreateLabel(rc,
  180             "Tab widget, Copyright (c) 1997 Pralay Dakua");
  181     CreateLabel(rc, "Xbae widget,");
  182     CreateLabel(rc,
  183             "      Copyright (c) 1991, 1992 Bell Communications Research, Inc. (Bellcore)");
  184     CreateLabel(rc,
  185             "      Copyright (c) 1995-1999 Andrew Lister");
  186     CreateLabel(rc, "Raster driver based on the GD-1.3 library,");
  187     CreateLabel(rc,
  188             "      Portions copyright (c) 1994-1998 Cold Spring Harbor Laboratory");
  189     CreateLabel(rc,
  190             "      Portions copyright (c) 1996-1998 Boutell.Com, Inc");
  191 #ifdef HAVE_LIBPDF
  192     CreateLabel(rc, "PDFlib library, Copyright (c) 1997-2012 PDFlib GmbH");
  193 #endif
  194 
  195     fr = CreateFrame(about_panel, "Build info");
  196         rc = CreateVContainer(fr);
  197         sprintf(buf, "Host: %s", bi_system());
  198     CreateLabel(rc, buf);
  199     sprintf(buf, "Time: %s", bi_date());
  200     CreateLabel(rc, buf);
  201     sprintf(buf, "GUI toolkit: %s ", bi_gui());
  202     CreateLabel(rc, buf);
  203     sprintf(buf, "Xbae version: %s ", bi_gui_xbae());
  204     CreateLabel(rc, buf);
  205     sprintf(buf, "T1lib: %s ", bi_t1lib());
  206     CreateLabel(rc, buf);
  207 #ifdef HAVE_LIBPNG
  208     sprintf(buf, "libpng: %s ", bi_pnglib());
  209     CreateLabel(rc, buf);
  210 #endif
  211 #ifdef HAVE_LIBJPEG
  212     sprintf(buf, "libjpeg: %s ", bi_libjpeg());
  213     CreateLabel(rc, buf);
  214 #endif
  215 #ifdef HAVE_LIBPDF
  216     sprintf(buf, "PDFlib: %s ", bi_libpdf());
  217     CreateLabel(rc, buf);
  218 #endif
  219     fr = CreateFrame(about_panel, "Home page");
  220         rc = CreateVContainer(fr);
  221     CreateLabel(rc, "http://plasma-gate.weizmann.ac.il/Grace/");
  222     
  223     CreateSeparator(about_panel);
  224 
  225     wbut = CreateButton(about_panel, "Close");
  226     AlignLabel(wbut, ALIGN_CENTER);
  227         AddButtonCB(wbut, destroy_dialog_cb, GetParent(about_frame));
  228         
  229         ManageChild(about_frame);
  230     }
  231     
  232     RaiseWindow(GetParent(about_frame));
  233     
  234     unset_wait_cursor();
  235 }
  236 
  237 
  238 #ifdef WITH_XMHTML
  239 /*
  240  * Simplistic HTML viewer
  241  */
  242 
  243 typedef struct _html_ui {
  244     Widget top;
  245     Widget html;
  246     TextStructure *location;
  247     Widget track;
  248     
  249     char *url;
  250     char *base;
  251     char *anchor;
  252     
  253     TextStructure *input;
  254     Widget case_sensitive;
  255     Widget find_backwards;
  256     
  257     XmHTMLTextFinder finder;
  258     char *last;
  259 } html_ui;
  260 
  261 static char *loadFile(char *URL)
  262 {
  263     FILE *file;
  264     int size;
  265     char *content;
  266 
  267     /* open the given file */
  268     if ((file = grace_openr(URL, SOURCE_DISK)) == NULL) {
  269         return NULL;
  270     }
  271 
  272     /* see how large this file is */
  273     fseek(file, 0, SEEK_END);
  274     size = ftell(file);
  275     rewind(file);
  276 
  277     /* allocate a buffer large enough to contain the entire file */
  278     if ((content = xmalloc(size + 1)) == NULL) {
  279         errmsg("xmalloc failed");
  280         return NULL;
  281     }
  282 
  283     /* now read the contents of this file */
  284     if ((fread(content, 1, size, file)) != size) {
  285         errmsg("Warning: did not read entire file!");
  286     }
  287 
  288     grace_close(file);
  289 
  290     /* sanity */
  291     content[size] = '\0';
  292 
  293     return content;
  294 }
  295 
  296 static char *translateURL(char *url, char *base)
  297 {
  298     char *fname;
  299     URLType type;
  300     
  301     if (url == NULL) {
  302         return NULL;
  303     }
  304     
  305     type = XmHTMLGetURLType(url);
  306     if (type != ANCHOR_FILE_LOCAL || url[0] == '/') {
  307         fname = copy_string(NULL, url);
  308     } else {
  309         char *p;
  310         fname = copy_string(NULL, base);
  311         p = strrchr(fname, '/');
  312         if (p) {
  313             p++;
  314             *p = '\0';
  315             fname = concat_strings(fname, url);
  316         } else {
  317             fname = copy_string(NULL, url);
  318         }
  319     }
  320     
  321     return fname;
  322 }
  323 
  324 static void anchorCB(Widget w, XtPointer client_data, XtPointer call_data)
  325 {
  326     int id;
  327     XmHTMLAnchorPtr href_data = (XmHTMLAnchorPtr) call_data;
  328     html_ui *ui = (html_ui *) client_data;
  329     char *turl;
  330     
  331     /* see if we have been called with a valid reason */
  332     if (href_data->reason != XmCR_ACTIVATE) {
  333         return;
  334     }
  335 
  336     switch (href_data->url_type) {
  337     /* a named anchor */
  338     case ANCHOR_JUMP:
  339         /* see if XmHTML knows this anchor */
  340         if ((id = XmHTMLAnchorGetId(w, href_data->href)) != -1) {
  341             /* and let XmHTML jump and mark as visited */
  342             href_data->doit = True;
  343             href_data->visited = True;
  344             
  345             ui->url = copy_string(ui->url, ui->base);
  346             ui->url = concat_strings(ui->url, href_data->href);
  347             SetTextString(ui->location, ui->url);
  348         }
  349         break;
  350     /* let HelpCB check all other types */
  351     default:
  352         turl = translateURL(href_data->href, ui->base);
  353         HelpCB(turl);
  354         xfree(turl);
  355         break;
  356     }
  357 }
  358 
  359 static void trackCB(Widget w, XtPointer client_data, XtPointer call_data)
  360 {
  361     XmHTMLAnchorPtr href_data = (XmHTMLAnchorPtr) call_data;
  362     html_ui *ui = (html_ui *) client_data;
  363 
  364     /* see if we have been called with a valid reason */
  365     if (href_data->reason != XmCR_HTML_ANCHORTRACK) {
  366         return;
  367     }
  368 
  369     if (href_data->href) {
  370         /* a valid anchor, eg, moving into an anchor */
  371         SetLabel(ui->track, href_data->href);
  372     } else {
  373         /* a valid anchor, eg, moving away from an anchor */
  374         SetLabel(ui->track, "");
  375     }
  376 }
  377 
  378 static int find_cb(void *data)
  379 {
  380     char *s, *ptr;
  381     int case_sensitive, find_backwards;
  382     XmHTMLTextPosition start, end;
  383     html_ui *ui = (html_ui *) data;
  384     
  385     ptr = GetTextString(ui->input);
  386 
  387     if (!ptr || ptr[0] == '\0') {
  388         return RETURN_FAILURE;
  389     }
  390     
  391     if (ui->finder == NULL) {
  392         ui->finder = XmHTMLTextFinderCreate(ui->html);
  393         if (ui->finder == NULL) {
  394             errmsg("XmHTMLTextFinderCreate failed!");
  395             return RETURN_FAILURE;
  396         }
  397     }
  398 
  399     s = copy_string(NULL, ptr);
  400 
  401     case_sensitive = GetToggleButtonState(ui->case_sensitive);
  402     find_backwards = GetToggleButtonState(ui->find_backwards);
  403 
  404     /*****
  405     * The second arg represent regcomp flags, the default being
  406     * REG_EXTENDED. Using -1 for this arg instructs the finder to
  407     * keep the current flags. See man regcomp on possible values for
  408     * your system. The third arg specifies whether or not the search
  409     * should be done case-insensitive (True) or not (False). The last arg
  410     * specifies the search direction. Currently only forward (top to
  411     * bottom) is supported.
  412     *****/
  413     XmHTMLTextFinderSetPatternFlags(ui->finder,
  414         -1,
  415         case_sensitive ? False : True,
  416         find_backwards ? XmHTML_BACKWARD : XmHTML_FORWARD);
  417     
  418     if (ui->last == NULL || strcmp(ui->last, s)) {
  419         if(!XmHTMLTextFinderSetPattern(ui->finder, s)) {
  420             /* failure dialog */
  421             ptr = XmHTMLTextFinderGetErrorString(ui->finder);
  422 
  423             errmsg(ptr ? ptr : "(unknown error)");
  424 
  425             /* must free this */
  426             xfree(ptr);
  427             xfree(ui->last);
  428             ui->last = s;
  429             return RETURN_FAILURE;
  430         }
  431     }
  432 
  433     switch (XmHTMLTextFindString(ui->html, ui->finder)) {
  434     case XmREG_ERROR:
  435         ptr = XmHTMLTextFinderGetErrorString(ui->finder);
  436         errmsg(ptr ? ptr : "(unknown error)");
  437         xfree(ptr);
  438         break;
  439     case XmREG_NOMATCH:
  440         if (yesno("End of document reached; continue from beginning?",
  441                   NULL, NULL, NULL) == TRUE) {
  442             xfree(s);
  443             XCFREE(ui->last);
  444             return find_cb(ui);
  445         } 
  446         break;
  447     case XmREG_MATCH:
  448         if (XmHTMLTextFindToPosition(ui->html, ui->finder, &start, &end)) {
  449             XmHTMLTextSetHighlight(ui->html, start, end, XmHIGHLIGHT_SELECTED);
  450             XmHTMLTextShowPosition(ui->html, start);
  451         }
  452         break;
  453     }
  454 
  455     xfree(ui->last);
  456     ui->last = s;
  457     
  458     return RETURN_SUCCESS;
  459 }
  460 
  461 static void create_find_dialog(void *data)
  462 {
  463     static Widget dialog = NULL;
  464     html_ui *ui = (html_ui *) data;
  465 
  466     if (!dialog) {
  467         Widget rc, rc2;
  468         
  469         dialog = CreateDialogForm(ui->html, "Find Dialog");
  470         
  471         rc = CreateVContainer(dialog);
  472         ui->input = CreateTextInput(rc, "Find:");
  473         rc2 = CreateHContainer(rc);
  474         ui->case_sensitive = CreateToggleButton(rc2, "Case sensitive");
  475         ui->find_backwards = CreateToggleButton(rc2, "Find backwards (N/I)");
  476 
  477         CreateAACDialog(dialog, rc, find_cb, data);
  478         
  479         ManageChild(dialog);
  480     }
  481 
  482     RaiseWindow(GetParent(dialog));
  483 }
  484 
  485 static void refresh_cb(void *data)
  486 {
  487     html_ui *ui = (html_ui *) data;
  488     XmHTMLRedisplay(ui->html);
  489 }
  490 
  491 static XmImageInfo *loadImage(Widget w,
  492     String url, Dimension width, Dimension height, XtPointer client_data)
  493 {
  494     char *fname;
  495     XmImageInfo *image;
  496     html_ui *ui = (html_ui *) client_data;
  497     
  498     fname = translateURL(url, ui->base);
  499     if (fname == NULL) {
  500         return NULL;
  501     }
  502     
  503     image = XmHTMLImageDefaultProc(w, fname, NULL, 0);
  504     
  505     xfree(fname);
  506     
  507     return image;
  508 }
  509 
  510 void location_cb(void *data)
  511 {
  512     TextStructure *location = (TextStructure *) data;
  513     char *url = GetTextString(location);
  514     HelpCB(url);
  515 }
  516 
  517 void create_helper_frame(char *URL)
  518 {
  519     static html_ui *ui = NULL;
  520     char *content;
  521     
  522     set_wait_cursor();
  523     
  524     if (ui == NULL) {
  525         Widget fr1, fr2, menubar, menupane, rc;
  526         
  527     ui = xmalloc(sizeof(html_ui));
  528         
  529         ui->url = NULL;
  530         ui->base = NULL;
  531         ui->anchor = NULL;
  532         
  533         ui->finder = NULL;
  534         ui->last = NULL;
  535         
  536         ui->top = CreateDialogForm(NULL, "Gracilla");
  537     
  538         menubar = CreateMenuBar(ui->top);
  539         ManageChild(menubar);
  540         AddDialogFormChild(ui->top, menubar);
  541         
  542         menupane = CreateMenu(menubar, "File", 'F', FALSE);
  543         CreateMenuButton(menupane, "Close", 'C', destroy_dialog_cb, GetParent(ui->top));
  544         
  545         menupane = CreateMenu(menubar, "Edit", 'E', FALSE);
  546         CreateMenuButton(menupane, "Find", 'F', create_find_dialog, ui);
  547 
  548         menupane = CreateMenu(menubar, "View", 'V', FALSE);
  549         CreateMenuButton(menupane, "Refresh", 'R', refresh_cb, ui);
  550 
  551         menupane = CreateMenu(menubar, "Help", 'H', TRUE);
  552         CreateMenuButton(menupane, "User's Guide", 'G', HelpCB, "doc/UsersGuide.html");
  553         CreateMenuButton(menupane, "Tutorial", 'T', HelpCB, "doc/Tutorial.html");
  554         CreateMenuButton(menupane, "FAQ", 'Q', HelpCB, "doc/FAQ.html");
  555         CreateMenuButton(menupane, "Changes", 'C', HelpCB, "doc/CHANGES.html");
  556         CreateMenuSeparator(menupane);
  557         CreateMenuButton(menupane, "License terms", 'L', HelpCB, "doc/GPL.html");
  558 
  559         ui->location = CreateTextInput(ui->top, "Location:");
  560         AddTextInputCB(ui->location, location_cb, ui->location);
  561         AddDialogFormChild(ui->top, ui->location->form);
  562         
  563     fr1 = CreateFrame(ui->top, NULL);
  564         AddDialogFormChild(ui->top, fr1);
  565         ui->html = XtVaCreateManagedWidget("html",
  566             xmHTMLWidgetClass, fr1,
  567             XmNimageProc, loadImage,
  568             XmNclientData, (XtPointer) ui,
  569             XmNenableBadHTMLWarnings, XmHTML_NONE,
  570             XmNanchorButtons, False,
  571             XmNmarginWidth, 20,
  572             XmNmarginHeight, 20,
  573             NULL);
  574 
  575     XtAddCallback(ui->html, XmNactivateCallback, anchorCB, ui);
  576         XtAddCallback(ui->html, XmNanchorTrackCallback, trackCB, ui);
  577 
  578     fr2 = CreateFrame(ui->top, NULL);
  579         AddDialogFormChild(ui->top, fr2);
  580         rc = CreateVContainer(fr2);
  581         ui->track = CreateLabel(rc, "Welcome to Gracilla!");
  582         
  583         XtVaSetValues(fr1,
  584             XmNbottomAttachment, XmATTACH_WIDGET,
  585             XmNbottomWidget, fr2,
  586             NULL);
  587         XtVaSetValues(fr2,
  588             XmNtopAttachment, XmATTACH_NONE,
  589             NULL);
  590     
  591         ManageChild(ui->top);
  592         
  593         XtVaSetValues(rc, XmNresizeHeight, False, NULL);
  594         
  595         ManageChild(GetParent(ui->top));
  596     }
  597     
  598     ui->url  = copy_string(ui->url, URL);
  599     ui->base = copy_string(ui->base, URL);
  600     if (ui->url) {
  601         char *p;
  602         
  603         p = strchr(ui->url, '#');
  604         if (p) {
  605             ui->base[p - ui->url] = '\0';
  606             ui->anchor = copy_string(ui->anchor, p);
  607         } else {
  608             XCFREE(ui->anchor);
  609         }
  610     }
  611     
  612     SetTextString(ui->location, ui->url);
  613 
  614     if (ui->finder) {
  615         XmHTMLTextFinderDestroy(ui->finder);
  616         ui->finder = NULL;
  617         ui->last = NULL;
  618     }
  619     
  620     content = loadFile(ui->base);
  621     if (content != NULL) {
  622         XmHTMLTextSetString(ui->html, content);
  623         if (ui->anchor) {
  624             int id = XmHTMLAnchorGetId(ui->html, ui->anchor);
  625             if (id != -1) {
  626                 XmHTMLAnchorScrollToId(ui->html, id);
  627             }
  628         } else {
  629             XmHTMLTextScrollToLine(ui->html, 0);
  630         }
  631         xfree(content);
  632 
  633         RaiseWindow(GetParent(ui->top));
  634     }
  635     
  636     unset_wait_cursor();
  637 }
  638 #endif /* WITH_XMHTML */