home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / xdbx / part02 / handler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-14  |  7.8 KB  |  299 lines

  1. /****************************************************************************** 
  2.  *
  3.  *  xdbx - X Window System interface to dbx
  4.  *
  5.  *  Copyright 1989 The University of Texas at Austin
  6.  *
  7.  *  Author:    Po Cheung
  8.  *  Date:    March 10, 1989
  9.  *
  10.  *  Permission to use, copy, modify, and distribute this software and
  11.  *  its documentation for any purpose and without fee is hereby granted,
  12.  *  provided that the above copyright notice appear in all copies and that
  13.  *  both that copyright notice and this permission notice appear in
  14.  *  supporting documentation.  The University of Texas at Austin makes no 
  15.  *  representations about the suitability of this software for any purpose.  
  16.  *  It is provided "as is" without express or implied warranty.
  17.  *
  18.  ******************************************************************************/
  19.  
  20.  
  21. #include <ctype.h>
  22. #include "global.h"
  23. #ifdef BSD
  24. #include "bsd_regex.h"
  25. #else
  26. #include "sun_regex.h"
  27. #endif
  28.  
  29. /*  Display text starting from the top position specified by pos */
  30.  
  31. static void TextSetTopPosition(w, pos)
  32.     Widget w;
  33.     XtTextPosition pos;
  34. {
  35.     Arg args[MAXARGS];
  36.     Cardinal n;
  37.  
  38.     n = 0;
  39.     XtSetArg(args[n], XtNdisplayPosition, (XtArgVal) pos);               n++;
  40.     XtSetValues(w, args, n);
  41.     XtTextDisplay(w);
  42. }
  43.  
  44. /*
  45.  *  Adjust text so that 'line' will fall into the viewable part of the
  46.  *  source window.
  47.  *  Arrows, stop signs, and line label are updated accordingly.
  48.  */
  49. static void AdjustText(w, line)
  50.     Widget w;
  51.     Line   line;
  52. {
  53.     FileRec *file;
  54.  
  55.     if ((file = displayedFile) == NULL) return;
  56.     file->currentline = line;
  57.     if (line < file->topline || line > file->bottomline ) {
  58.  
  59.     if (line < file->lines/2)               /* near top */
  60.         file->topline = 1;
  61.     else if (line > file->lastline - file->lines/2)  /* near bottom */
  62.         file->topline = MAX(file->lastline - file->lines + 1, 1);
  63.     else
  64.         file->topline = line - file->lines/2;
  65.     file->bottomline = MIN(file->topline + file->lines - 1, file->lastline);
  66.     TextSetTopPosition (w, file->linepos[file->topline]);
  67.         UpdateStops(file);
  68.     }
  69.     XtTextSetInsertionPoint(w, file->linepos[line]);
  70.     UpdateLineLabel(line);
  71.     UpdateArrow(file);
  72.     UpdateUpdown(file);
  73. }
  74.     
  75.  
  76. /*  Handle dbx output of run, cont, next, step commands.
  77.  *  Result of output parsing is returned in a set of tokens.
  78.  *  Done is a boolean which indicates completed execution of debugged program.
  79.  */
  80. void exec_handler(token, done)
  81.     Tokens     *token;
  82.     int      done;
  83. {
  84.     char s[LINESIZ], command[LINESIZ];
  85.  
  86.     /*  If done, remove all the arrow and updown signs, print message, then 
  87.      *  change the file variable to the file name displayed.
  88.      */
  89.     if (done) {
  90.     arrow.line = 0;
  91.     updown.line = 0;
  92.     UpdateArrow(displayedFile);
  93.     UpdateUpdown(displayedFile);
  94.     UpdateMessageWindow("Ready for execution");
  95.     if (displayedFile == NULL) return;
  96.     sprintf(command, "file %s\n", displayedFile->filename);
  97.     QueryDbx(command, FALSE);
  98.     return;
  99.     }
  100.  
  101.     /* Print "stopped in ..." line in meesage window 
  102.      * Adjust text displayed
  103.      */
  104.     if (token->func == NULL || token->line == 0) 
  105.     return; 
  106.     if (token->file)
  107.     displayedFile = LoadFile(token->file);
  108.     UpdateMessageWindow(token->mesg);
  109.     arrow.line = token->line;        /* update arrow sign position */
  110.     updown.line = 0;            /* remove updown, if any */
  111.     if (displayedFile)
  112.         strcpy(arrow.filename, displayedFile->filename);
  113.     AdjustText(sourceWindow, token->line);
  114.     if (displayedFile) {
  115.         XtTextSetInsertionPoint(sourceWindow, displayedFile->linepos[token->line]);
  116.     UpdateLineLabel(token->line);
  117.     }
  118. }
  119.  
  120.  
  121. /*  Place a stop sign next to the line specified on the source file window 
  122.  *  if it is to be viewable.
  123.  */
  124. void stop_at_handler(token)
  125.     Tokens *token;
  126. {
  127.     if (token->stop == 0 || token->line == 0 || displayedFile == NULL)
  128.     return;
  129.     if (token->file == NULL)
  130.     stops[token->stop].filename = displayedFile->filename;
  131.     else
  132.     stops[token->stop].filename = token->file;
  133.     DisplayStop(displayedFile, token->line);
  134.     stops[token->stop].line = token->line;
  135.     stops[token->stop].tag = 0;
  136.     nstops = token->stop;
  137. }
  138.  
  139.  
  140. /*
  141.  *  Place a stop sign next to the function routine, getting the line number 
  142.  *  by "list <func>", (which possibly changes the file variable), and 
  143.  *  resetting the file variable properly.
  144.  */
  145. void stop_in_handler(token)
  146.     Tokens *token;
  147. {
  148.     char command[LINESIZ], s[LINESIZ], *filename;
  149.     int  stop;
  150.     Line line;
  151.  
  152.     if (token->stop == 0 || token->func == NULL || displayedFile == NULL)
  153.     return;
  154.     stop = token->stop;
  155.     sprintf(command, "list %s\n", token->func);
  156.     if (QueryDbx(command, TRUE) != O_LIST || token->line <= 0) 
  157.     return;
  158.  
  159.     stops[stop].line = token->line;
  160.     nstops = stop;
  161.     line = token->line;
  162.  
  163.     /* check if funcname belongs to another file */
  164.     if ((filename = QueryFile()) && strcmp(filename, displayedFile->filename)) {
  165.     /* new file, record stop */
  166.     stops[nstops].filename = filename;
  167.  
  168.     /* restore variable file to original file */
  169.     sprintf(command, "file %s\n", displayedFile->filename);
  170.     QueryDbx(command, FALSE);
  171.     }
  172.     else { /* same file, display stop */
  173.     stops[nstops].filename = displayedFile->filename;
  174.     DisplayStop(displayedFile, line);
  175.     }
  176. }
  177.  
  178.  
  179. /*  
  180.  *  Display an outlined arrow to locate the calling routine in a stack
  181.  *  frame.  BSD and SUN dbx have slightly different output semantics here.
  182.  *  The appropriate file with the calling routine is displayed and the
  183.  *  file variable is set accordingly.
  184.  */
  185. void updown_handler(token)
  186.     Tokens *token;
  187. {
  188.     char s[LINESIZ], command[LINESIZ];
  189.  
  190. #ifndef BSD
  191.     displayedFile = LoadFile(QueryFile());
  192.     if (displayedFile)
  193.     token->file = displayedFile->filename;
  194.     if (token->line <= 0) token->line = 1;
  195. #endif
  196.  
  197.     if (token->line <= 0 || token->func == NULL || token->file == NULL) 
  198.     return;
  199.     if (token->file && displayedFile && 
  200.     strcmp(token->file, displayedFile->filename)) {
  201.     displayedFile = LoadFile(token->file);
  202.     /* set dbx file variable to filename */
  203.     sprintf(command, "file %s\n", token->file);
  204.     QueryDbx(command, FALSE);
  205.     }
  206.     updown.line = token->line;
  207.     if (displayedFile)
  208.         strcpy(updown.filename, displayedFile->filename);
  209.     AdjustText(sourceWindow, token->line);
  210. }
  211.  
  212.  
  213. /*
  214.  *  Delete handler remove the stop specified and undisplayed the stopsign
  215.  *  if it's visible.
  216.  *  It calls the dbx status command to find out what stops are left, and
  217.  *  then update the array of stops accordingly.
  218.  */
  219. /* ARGSUSED */
  220. void delete_handler()
  221. {
  222.     char s[LINESIZ];
  223.     int  i; 
  224.     Line line;
  225.  
  226.     Echo = FALSE;
  227.     writeDbx("status\n");
  228.     while (fgets(s, LINESIZ, dbxfp) == NULL);
  229.     do {
  230.     if (strcmp(s, "(dbx) ") || strcmp(s, "")) {
  231.         sscanf(s, BRACKET, &i);
  232.         if (i > 0 && i <= nstops && stops[i].line > 0) 
  233.             stops[i].tag = 1;
  234.     }
  235.     } while (fgets(s, LINESIZ, dbxfp));
  236.     Echo = TRUE;
  237.  
  238.     for (i=1; i<=nstops; i++)
  239.     if (stops[i].line > 0) {
  240.         if (stops[i].tag)
  241.         stops[i].tag = 0;
  242.         else {
  243.         line = stops[i].line;
  244.         stops[i].line = 0;
  245.         stops[i].filename = NULL;
  246.         if (LineToStop_no(line) == 0)
  247.             RemoveStop(line);
  248.         }
  249.     }
  250. }
  251.  
  252. /*
  253.  *  This handler displays the function routine on the source window.
  254.  *  It locates the function by sending the dbx command "list <func>",
  255.  *  and loads the appropriate file accordingly.
  256.  */
  257. void func_handler(token)
  258.     Tokens     *token;
  259. {
  260.     Line line = 0;
  261.     char s[LINESIZ], command[LINESIZ];
  262.  
  263.     if (token->func) {
  264.     sprintf(command, "list %s\n", token->func);
  265.     QueryDbx(command, TRUE);
  266.     displayedFile = LoadFile(QueryFile());
  267.     AdjustText(sourceWindow, token->line);
  268.     }
  269. }
  270.  
  271.  
  272. /*
  273.  *  File handler first queries the current file set by the user command,
  274.  *  and then loads the file.
  275.  */
  276. /* ARGSUSED */
  277. void file_handler(token)
  278.     Tokens     *token;
  279. {
  280.     char *filename;
  281.  
  282.     if (token->file)
  283.     displayedFile = LoadFile(QueryFile());
  284. }
  285.  
  286.  
  287. /* ARGSUSED */
  288. void debug_handler()
  289. {
  290.     DisplayInit();
  291. }
  292.  
  293.  
  294. /* ARGSUSED */
  295. void cd_handler()
  296. {
  297.     UpdateFileMenu();
  298. }
  299.