home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xdbx / part04 / xdbx.c < prev   
Encoding:
C/C++ Source or Header  |  1990-08-28  |  11.9 KB  |  332 lines

  1. /*****************************************************************************
  2.  *
  3.  *  xdbx - X Window System interface to the dbx debugger
  4.  *
  5.  *  Copyright 1989 The University of Texas at Austin
  6.  *  Copyright 1990 Microelectronics and Computer Technology Corporation
  7.  *
  8.  *  Permission to use, copy, modify, and distribute this software and its
  9.  *  documentation for any purpose and without fee is hereby granted,
  10.  *  provided that the above copyright notice appear in all copies and that
  11.  *  both that copyright notice and this permission notice appear in
  12.  *  supporting documentation, and that the name of The University of Texas
  13.  *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  14.  *  used in advertising or publicity pertaining to distribution of
  15.  *  the software without specific, written prior permission.  The
  16.  *  University of Texas and MCC makes no representations about the 
  17.  *  suitability of this software for any purpose.  It is provided "as is" 
  18.  *  without express or implied warranty.
  19.  *
  20.  *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  21.  *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22.  *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  23.  *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  24.  *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  25.  *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  26.  *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  *
  28.  *  Author:      Po Cheung
  29.  *  Created:       March 10, 1989
  30.  *
  31.  *****************************************************************************/
  32.  
  33. /*  xdbx.c
  34.  *
  35.  *    Contain main program and initialization, command line options handling,
  36.  *    and resource database management.
  37.  *
  38.  *    Syntax():        Print an error message if xdbx is invoked with an
  39.  *            incorrect number of arguments.
  40.  *    main_init():    Initialization routine.
  41.  *    dbxoptions():    Construct command line arguments for dbx.
  42.  *    main():        Main program.
  43.  */
  44.  
  45. #include "global.h"
  46. #include "bitmaps.h"
  47. #include "patchlevel.h"
  48.  
  49. #define VERSION    "2.1"
  50. #define Offset(field) (XtOffset(XdbxResources *, field))
  51.  
  52. XtAppContext      app_context;         /* application context */
  53. Widget      toplevel;         /* top level widget */
  54. Display        *display;        /* connection to X server */
  55. Cursor        watch;            /* XC_watch cursor */
  56. XdbxResources     app_resources;        /* application resources of xdbx */
  57. char         xdbxinit[LINESIZ];    /* initialization file name */
  58. Boolean        Tstartup = False;    /* if True, remove xdbxinit */
  59. Boolean        debug = False;        /* debug mode for xdbx */
  60.  
  61.  
  62. static XtResource resources[] = {
  63.     {"bell", "Bell", XtRBoolean, sizeof(Boolean), 
  64.     Offset(bell), XtRImmediate, (caddr_t)False},
  65.     {"displayWindow", "DisplayWindow", XtRBoolean, sizeof(Boolean), 
  66.     Offset(displayWindow), XtRImmediate, (caddr_t)False},
  67.     {"prompt", "Prompt", XtRString, sizeof(char *), 
  68.     Offset(prompt), XtRImmediate, (caddr_t)NULL},
  69.     {"delimiters", "Delimiters", XtRString, sizeof(char *), 
  70.     Offset(delimiters), XtRImmediate, (caddr_t)NULL},
  71.     {"stop_color", "StopColor", XtRPixel, sizeof(Pixel), 
  72.     Offset(stop_color), XtRString, "Red"},
  73.     {"arrow_color", "ArrowColor", XtRPixel, sizeof(Pixel), 
  74.     Offset(arrow_color), XtRString, "Blue"},
  75.     {"updown_color", "UpdownColor", XtRPixel, sizeof(Pixel), 
  76.     Offset(updown_color), XtRString, "Blue"},
  77.     {"bomb_color", "bombColor", XtRPixel, sizeof(Pixel), 
  78.     Offset(bomb_color), XtRString, "Red"},
  79.     {"dataDpyMaxHeight", "DataDpyMaxHeight", XtRDimension, sizeof(Dimension), 
  80.     Offset(dataDpyMaxHeight), XtRString, "300"},
  81.     {"dataDpyMaxWidth", "DataDpyMaxWidth", XtRDimension, sizeof(Dimension), 
  82.     Offset(dataDpyMaxWidth), XtRString, "600"},
  83.     {"bigicon", "Xdbxoptions", XtRBoolean, sizeof(Boolean), 
  84.     Offset(bigicon), XtRImmediate, (caddr_t)False},
  85.     {"debug", "Xdbxoptions", XtRBoolean, sizeof(Boolean), 
  86.     Offset(debug), XtRImmediate, (caddr_t)False},
  87.     {"dbxopt_r", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
  88.     Offset(dbxopt_r), XtRImmediate, (caddr_t)False},
  89.     {"dbxopt_i", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
  90.     Offset(dbxopt_i), XtRImmediate, (caddr_t)False},
  91.     {"includeDir", "Dbxoptions", XtRString, sizeof(char *), 
  92.     Offset(includeDir), XtRImmediate, (caddr_t)NULL},
  93.     {"dbxopt_k", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
  94.     Offset(dbxopt_k), XtRImmediate, (caddr_t)False},
  95.     {"cfile", "Dbxoptions", XtRString, sizeof(char *), 
  96.     Offset(cfile), XtRImmediate, (caddr_t)NULL},
  97.     {"dbxopt_kbd", "Dbxoptions", XtRBoolean, sizeof(Boolean), 
  98.     Offset(dbxopt_kbd), XtRImmediate, (caddr_t)False},
  99.     {"fcount", "Dbxoptions", XtRString, sizeof(char *), 
  100.     Offset(fcount), XtRImmediate, (caddr_t)NULL},
  101.     {"startup", "Dbxoptions", XtRString, sizeof(char *), 
  102.     Offset(startup), XtRImmediate, (caddr_t)NULL},
  103.     {"tstartup", "Dbxoptions", XtRString, sizeof(char *), 
  104.     Offset(tstartup), XtRImmediate, (caddr_t)NULL},
  105. };
  106.  
  107.  
  108. String fallback_resources[] = {
  109.     "*allowShellResize:                 True",
  110.     "*borderWidth:            1",
  111.     "*font:                             fixed",
  112.     "*vpane.width:                      550",
  113.     "*fileWindow*font:             variable",
  114.     "*fileLabel.width:             500",
  115.     "*lineLabel.width:             50",
  116.     "*sourceForm.preferredPaneSize:     320",
  117.     "*sourceWindow.leftMargin:          35",
  118.     "*sourceWindow.scrollHorizontal:    whenNeeded",
  119.     "*sourceWindow.translations:    #override \\n\
  120.         <Btn1Down>:             SelectStart() SelectWord() \\n\
  121.         Shift<Btn1Up>:          Update() SelectEnd() PrintSelection() \\n\
  122.         <Btn1Up>:               Update() SelectEnd() \\n",
  123.     "*messageWindow*font:          variable",
  124.     "*messageWindow.min:          30",
  125.     "*messageWindow.max:          30",
  126.     "*dialogWindow.preferredPaneSize:    200",
  127.     "*dialogWindow.resizeToPreferred:    True",
  128.     "*dialogWindow.translations:    #override \\n\
  129.         <Btn1Down>:     SelectStart() SelectWord() \\n\
  130.         Shift<Btn1Up>:  SelectEnd() PrintSelection() \\n\
  131.         <Btn1Up>:       SelectEnd() \\n",
  132.     "*commandWindow.preferredPaneSize:  106",
  133.     "*commandWindow.skipAdjust:        True",
  134.     "*commandWindow.hSpace:        14",
  135.     "*commandWindow.vSpace:        10",
  136.     "*Command.height:                   20",
  137.     "*Command.width:                    60",
  138.     "*List.columnSpacing:               10",
  139.     "*displayWindow.preferredPaneSize:  50",
  140.     "*displayWindow.skipAdjust:         True",
  141.     "*displayWindow.scrollVertical:    whenNeeded",
  142.     "*displayWindow.scrollHorizontal:    whenNeeded",
  143.     "*displayWindow.translations:    #override \\n\
  144.         <Btn1Down>:             SelectStart() SelectWord() \\n\
  145.         Shift<Btn1Up>:          SelectEnd() PrintSelection() \\n\
  146.         <Btn1Up>:               SelectEnd() \\n",
  147.     "*popup*showGrip:              False",
  148.     NULL,
  149. };
  150.  
  151. static XrmOptionDescRec options[] = {
  152.     {"-bigicon","bigicon",    XrmoptionNoArg, "True"},
  153.     {"-debug",    "debug",    XrmoptionNoArg, "True"},
  154.     {"-r",    "dbxopt_r",    XrmoptionNoArg, "True"},
  155.     {"-i",    "dbxopt_i",    XrmoptionNoArg, "True"},
  156.     {"-I",    "includeDir",    XrmoptionSepArg, NULL},
  157.     {"-k",    "dbxopt_k",    XrmoptionNoArg, "True"},
  158. #ifdef BSD   /* Berkeley dbx */
  159.     {"-c",    "cfile",    XrmoptionSepArg, NULL},
  160. #else         /* Sun dbx */
  161.     {"-kbd",    "dbxopt_kbd",    XrmoptionNoArg, "True"},
  162.     {"-f",    "fcount",    XrmoptionSepArg, NULL},
  163.     {"-s",    "startup",    XrmoptionSepArg, NULL},
  164.     {"-sr",    "tstartup",    XrmoptionSepArg, NULL},
  165. #endif
  166. #ifdef MIPS  /* Mips dbx */
  167.     {"-pixie",  "pixie",    XrmoptionNoArg, "True"},
  168. #endif
  169. };
  170.  
  171. XtActionsRec xdbx_actions[] = {
  172.     {"SelectStart",    (XtActionProc) SelectStart},
  173.     {"SelectEnd",    (XtActionProc) SelectEnd},
  174.     {"SelectWord",    (XtActionProc) SelectWord},
  175.     {"PrintSelection",    (XtActionProc) PrintSelection},
  176.     {"Update",        (XtActionProc) Update},
  177.     {"DeleteWord",    (XtActionProc) DeleteWord},
  178.     {"DeleteLine",    (XtActionProc) DeleteLine},
  179.     {NULL, NULL}
  180. };
  181.  
  182. static void Syntax(call)
  183. char *call;
  184. {
  185.     fprintf(stderr,
  186.         "Usage: %s [-toolkitoptions] [-dbxoptions] [objfile [corefile]]\n",
  187.         call);
  188.     exit(1);
  189. }
  190.  
  191. /*  Set window manager hints to indicate display accepts input.
  192.  *  Initialize routines in source.c, signs.c and parser.c.
  193.  *  Disable window resize of fileWindow.
  194.  *  Get the name of the dbx command initialization file.
  195.  */
  196. static void main_init()
  197. {
  198.     XWMHints    wmhints;
  199.     char    title[100];
  200.  
  201.     display = XtDisplay(toplevel);
  202.     watch = XCreateFontCursor(display, XC_watch);
  203.  
  204.     sprintf(title, "xdbx %s (patch level %d)", VERSION, PATCHLEVEL);
  205.     XStoreName(display, XtWindow(toplevel), title);
  206.     XSetIconName(display, XtWindow(toplevel), "xdbx");
  207.     wmhints.input = True;
  208.     if (app_resources.bigicon)
  209.     wmhints.icon_pixmap = XCreateBitmapFromData(display, XtWindow(toplevel),
  210.         xdbx64_bits, xdbx64_width, xdbx64_height);
  211.     else
  212.     wmhints.icon_pixmap = XCreateBitmapFromData(display, XtWindow(toplevel),
  213.         xdbx48_bits, xdbx48_width, xdbx48_height);
  214.     wmhints.flags = IconPixmapHint | InputHint;
  215.     XSetWMHints(display, XtWindow(toplevel), &wmhints);
  216.  
  217.     if (!app_resources.delimiters || 
  218.     strcmp(app_resources.delimiters, "") == NULL)
  219.     app_resources.delimiters = XtNewString(DELIMITERS);
  220.     if (app_resources.prompt && strcmp(app_resources.prompt, "") != NULL)
  221.     xdbxprompt = app_resources.prompt;
  222.     else
  223.     xdbxprompt = XtNewString(XDBXPROMPT);
  224.     debug = app_resources.debug;
  225.     DisableWindowResize(fileWindow);
  226.  
  227.     strcpy(xdbxinit, ".dbxinit");
  228.     if (access(xdbxinit, R_OK) == -1) {
  229.         sprintf(xdbxinit, "%s/%s", (char *) getenv("HOME"), ".dbxinit");
  230.         if (access(xdbxinit, R_OK) == -1) {
  231.         strcpy(xdbxinit, "");
  232.     }
  233.     }
  234.     source_init();
  235.     signs_init();
  236.     parser_init();
  237. }
  238.  
  239.  
  240. /*  Reconstruct command line arguments for calling dbx.
  241.  *  Return the argument list for dbx and new value of argc.
  242.  */
  243. static char **dbxoptions(argc, argv, app_resources)
  244.     int  *argc;
  245.     char **argv;
  246.     XdbxResources *app_resources;
  247. {
  248.     char **dbxargv;
  249.     char *temp = "xdbx.XXXXXX";
  250.     int  i=0;
  251.  
  252.     dbxargv = (char **) XtMalloc (MAXARGS * sizeof(char *));
  253.     for (i=0; i < *argc; i++)
  254.     dbxargv[i] = argv[i];
  255.  
  256.     if (app_resources->dbxopt_r)
  257.     dbxargv[i++] = "-r";
  258.     if (app_resources->dbxopt_i)
  259.     dbxargv[i++] = "-i";
  260.     if (app_resources->includeDir) {
  261.     dbxargv[i++] = "-I";
  262.     dbxargv[i++] = app_resources->includeDir;
  263.     }
  264.     if (app_resources->dbxopt_k)
  265.     dbxargv[i++] = "-k";
  266.     if (app_resources->cfile) {
  267.     dbxargv[i++] = "-c";
  268.     dbxargv[i++] = app_resources->cfile;
  269.     }
  270.     if (app_resources->dbxopt_kbd)
  271.     dbxargv[i++] = "-kbd";
  272.     if (app_resources->fcount) {
  273.     dbxargv[i++] = "-f";
  274.     dbxargv[i++] = app_resources->fcount;
  275.     }
  276.     /*  If .dbxinit exists in the local or home directory, include the option
  277.      *  -c (Berkeley dbx) or -s (Sun dbx) and a dummy filename as the option 
  278.      *    argument.  This will prevent dbx from reading the user's command
  279.      *    initialization file.  Xdbx will read each line and pass it to dbx
  280.      *  instead.
  281.      */
  282.     if (strcmp(xdbxinit, "")) {        /* .dbxinit or ~/.dbxinit exists */
  283. #ifdef BSD
  284.     dbxargv[i++] = "-c";
  285. #else
  286.     dbxargv[i++] = "-s";
  287. #endif
  288.     dbxargv[i++] = (char *) mktemp(temp);
  289.     }
  290.     if (app_resources->startup) {    /* overwrites dbxinit */
  291.     Tstartup = False;
  292.     strcpy(xdbxinit, app_resources->startup);
  293.     }
  294.     if (app_resources->tstartup) {    /* overwrites dbxinit */
  295.     Tstartup = True;
  296.     strcpy(xdbxinit, app_resources->tstartup);
  297.     }
  298. #ifdef MIPS
  299.     if (app_resources->pixie) {        /* pixie output */
  300.     dbxargv[i++] = "-pixie";
  301.     }
  302. #endif
  303.     dbxargv[i] = NULL;
  304.     *argc = i;
  305.     return dbxargv;
  306. }
  307.  
  308.  
  309. void main(argc, argv)
  310. int argc;
  311. char **argv;
  312. {
  313.     char     **dbxargv;
  314.  
  315.     trap_signals();
  316.  
  317.     toplevel = XtAppInitialize(&app_context, "XDbx", options, XtNumber(options),
  318.                    &argc, argv, fallback_resources, NULL, 0);
  319.     if (argc > 3) Syntax(argv[0]);
  320.     XtGetApplicationResources(toplevel, &app_resources, resources,
  321.                               XtNumber(resources), NULL, 0);
  322.     XtAppAddActions(app_context, xdbx_actions, XtNumber(xdbx_actions));
  323.     CreateSubWindows(toplevel);
  324.     XtRealizeWidget(toplevel);
  325.  
  326.     main_init();
  327.     dbxargv = dbxoptions(&argc, argv, &app_resources);
  328.     calldbx(argc, dbxargv);
  329.  
  330.     XtAppMainLoop(app_context);
  331. }
  332.