home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / debug / edebug / ed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-05  |  1.6 KB  |  77 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include<stdio.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include "ed.h"
  6. #include "debug.h"
  7. #include <debug/syms.h>
  8. #include <libc/file.h>    /* Workaround for stderr bug below */
  9.  
  10. static char ansi_mode;    /* if set, OK to emit ansi control codes */
  11.  
  12. void ansi(int fg)
  13. {
  14.   if(ansi_mode)
  15.     printf("\033[%d;%dm", (fg & A_bold) ? 1 : 0, 30+(fg&7));
  16. }
  17.  
  18. /* for debugging a qdpmi bug */
  19. #if 0
  20. #define x printf("%s:%d\n", __FILE__, __LINE__);
  21. #else
  22. #define x
  23. #endif
  24.  
  25. void ansidetect(void)    /* Idea from DJ's install program */
  26. {
  27.   word16 oldp, newp;
  28.   asm("movb $3,%%ah;movb $0,%%bh;int $0x10;movw %%dx,%0" : "=g" (oldp) :
  29.     : "ax", "bx", "cx", "dx");
  30.   printf("\033[0m");
  31.   fflush(stdout);
  32.   asm("movb $3,%%ah;movb $0,%%bh;int $0x10;movw %%dx,%0" : "=g" (newp) :
  33.     : "ax", "bx", "cx", "dx");
  34.   if (newp == oldp)
  35.     ansi_mode = 1;
  36.   else {
  37.     printf("\r    \r");
  38.     fflush(stdout);
  39.     ansi_mode = 0;
  40.   }
  41. }
  42.  
  43. int main(int argc, char **argv)
  44. {
  45.   int i;
  46.   char cmdline[128];
  47.   jmp_buf start_state;
  48.  
  49.   if(argc < 2) {
  50.     printf("Usage: %s debug-image [args]\n", argv[0]);
  51.     exit(1);
  52.   }
  53. x
  54.   syms_init(argv[1]);
  55. x
  56.   cmdline[1] = 0;
  57.   for(i=2; argv[i]; i++) {
  58.       strcat(cmdline+1, " ");
  59.       strcat(cmdline+1, argv[i]);
  60.   }
  61.   i = strlen(cmdline+1);
  62.   cmdline[0] = i;
  63.   cmdline[i+1] = 13;
  64. x  if(v2loadimage(argv[1],cmdline,start_state)) {
  65. x    printf("Load failed for image %s\n",argv[1]);
  66.     exit(1);
  67.   }
  68. x
  69.   edi_init(start_state);
  70. x  ansidetect();
  71. x  stdout->_file = dup(fileno(stdout));
  72. x
  73. x  debugger();
  74.  
  75.   return 0;
  76. }
  77.