home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 211.lha / Spiff / visual.c < prev    next >
C/C++ Source or Header  |  1996-02-14  |  8KB  |  412 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2. **                            All Rights Reserved
  3. **       Permission is granted to copy or use this program, EXCEPT that it
  4. **       may not be sold for profit, the copyright notice must be reproduced
  5. **       on copies, and credit should be given to Bellcore where it is due.
  6. **       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7. */
  8.  
  9.  
  10. #ifndef lint
  11. static char rcsid[]= "$Header: visual.c,v 1.1 88/09/15 11:34:02 daniel Rel $";
  12. #endif
  13.  
  14. #ifdef MGR
  15.  
  16. #include "misc.h"
  17. #include "line.h"
  18. #include "token.h"
  19. #include "/usr/public/pkg/mgr/include/term.h"
  20. #include "/usr/public/pkg/mgr/include/restart.h"
  21.  
  22. #define OTHER        0
  23. #define ON_DEBUG    1
  24. #define OFF_DEBUG    2
  25. #define DO_QUIT        3
  26. #define DO_PAGE        4
  27. #define NEW_PREC    5
  28.  
  29.  
  30. #define NROW    60
  31. #define NCOL    80
  32.  
  33. int isdiff[MAXTOKENS];    /* flag showing if a token pair was shown different*/
  34.  
  35. int comwin,wina, winb;    /* location to store window numbers */
  36. int fontx,fonty;    /* size of the font in pixels */
  37.  
  38. int debug =0;
  39.  
  40.  
  41. int firsttoken = 0;    /* index of first token pair being displayed */
  42. int tokencnt;        /* count of the number of token pairs being displayed */
  43.  
  44. V_visual(flags)
  45. int flags;
  46. {
  47.  
  48.     int moretodo = 1;    /* flag to clear when we're finished */
  49.  
  50.     messup();
  51.  
  52.     m_selectwin(comwin);
  53.     m_setmode(W_ACTIVATE);
  54.  
  55.     showpages(comroutine,flags);
  56.  
  57.     do
  58.     {
  59.         switch(getinput())
  60.         {
  61.             case ON_DEBUG:
  62.                 debug = 0;
  63.                 break;
  64.             case OFF_DEBUG:
  65.                 debug = 1;
  66.                 break;
  67.             case DO_QUIT:
  68.                 moretodo = 0;
  69.                 break;
  70.             case DO_PAGE:
  71.                 if((firsttoken+tokencnt>= K_gettmax(0))||
  72.                    (firsttoken+tokencnt>= K_gettmax(1)))
  73.                 {
  74.                     m_selectwin(comwin);
  75.                     m_printstr("\007this is the last page\n");
  76.                     break;
  77.                 }
  78.                 firsttoken += tokencnt;
  79.                 showpages(comroutine,flags);
  80.                 break;
  81.             case NEW_PREC:
  82.                 updatepages(comroutine,flags);
  83.                 break;
  84.             case OTHER:
  85.                 break;
  86.             default :
  87.                 Z_fatal("bad value in main switch");
  88.                 
  89.         }
  90.     } while (moretodo);
  91.  
  92.     V_cleanup();
  93.     return(0);
  94. }
  95.  
  96. getinput()
  97. {
  98.     char ibuf[Z_LINELEN];    /* input buffer */
  99.     char *ptr;
  100.  
  101.     m_selectwin(comwin);
  102.     m_setmode(W_ACTIVATE);
  103.     switch (m_getchar())
  104.     {
  105.         case 't':
  106.             m_gets(ibuf);
  107.             /*
  108.             **    skip the 'tol'
  109.             */
  110.             ptr = ibuf;
  111.             S_nextword(&ptr);
  112.             T_setdef(ptr);
  113.             return(NEW_PREC);
  114.         case 'q':
  115.             return(DO_QUIT);
  116.         case 'd':
  117.             return(OFF_DEBUG);
  118.         case 'D':
  119.             return(ON_DEBUG);
  120.         case 'm':
  121.             return(DO_PAGE);
  122.         default:
  123.             return(OTHER);
  124.     }
  125.     
  126. }
  127.  
  128. showpages(comroutine,flags)
  129. int (*comroutine)();
  130. int flags;
  131. {
  132.     int i;
  133.         m_selectwin(wina);
  134.         m_clear();
  135.         m_selectwin(winb);
  136.         m_clear();
  137.         showlines();
  138.  
  139.         for(i=firsttoken;i<tokencnt+firsttoken; i++)
  140.         {
  141.             isdiff[i] = 0;
  142.         }
  143.         updatepages(comroutine,flags);
  144. }
  145.  
  146. updatepages(comroutine,flags)
  147. int (*comroutine)();
  148. int flags;
  149. {
  150.     int i;
  151.  
  152.     for(i=firsttoken;i<tokencnt+firsttoken; i++)
  153.     {
  154.         if (isdiff[i])
  155.         {
  156.  
  157.             if (0 == X_com(i,i,flags))
  158.             {
  159.                 m_selectwin(wina);
  160.                 un_highlight(0,K_gettoken(0,i),K_getline(K_gettoken(0,firsttoken)));
  161.                 m_selectwin(winb);
  162.                 un_highlight(1,K_gettoken(1,i),K_getline(K_gettoken(1,firsttoken)));
  163.                 isdiff[i] = 0;
  164.             }
  165.         }
  166.         else
  167.         {
  168.             if (0 != X_com(i,i,flags))
  169.             {
  170.                 m_selectwin(wina);
  171.                 highlight(0,K_gettoken(0,i),K_getline(K_gettoken(0,firsttoken)));
  172.                 m_selectwin(winb);
  173.                 highlight(1,K_gettoken(1,i),K_getline(K_gettoken(1,firsttoken)));
  174.                 isdiff[i] = 1;
  175.             }
  176.         }
  177.     }
  178. }
  179.  
  180. un_highlight(file,ptr,firstline)
  181. int file;
  182. K_token ptr;
  183. int firstline;
  184. {
  185.     highlight(file,ptr,firstline);
  186. }
  187.  
  188. /*
  189. **    argument expressed in terms of token lines
  190. */
  191. highlight(file,ptr,firstline)
  192. int file;
  193. K_token ptr;
  194. int firstline;
  195. {
  196.     int startx = K_getpos(ptr)*fontx;
  197.     int starty = (L_tl2cl(file,K_getline(ptr))-L_tl2cl(file,firstline))*fonty;
  198.  
  199.     int sizex = fontx*strlen(K_gettext(ptr));
  200.     int sizey = fonty;
  201.     m_bitwrite(startx,starty,sizex,sizey);
  202. }
  203.  
  204. showlines()
  205. {
  206.     int Alinecnt = 0;
  207.     int Blinecnt = 0;
  208.  
  209.     int Atfirstline = K_getline(K_gettoken(0,firsttoken));
  210.     int Btfirstline = K_getline(K_gettoken(1,firsttoken));
  211.     int Afirstline =  L_tl2cl(0,K_getline(K_gettoken(0,firsttoken)));
  212.     int Bfirstline =  L_tl2cl(1,K_getline(K_gettoken(1,firsttoken)));
  213.     int Anexttoken = L_getindex(0,Atfirstline);
  214.     int Bnexttoken = L_getindex(1,Btfirstline);
  215.     int i;
  216.     /*
  217.     **    first print the lines on the screen
  218.     */
  219.     for(i=0;i < NROW;i++)
  220.     {
  221.         if(Afirstline+i < L_getclmax(0))
  222.         {
  223.             m_selectwin(wina);
  224.             showline(0,Afirstline+i,i);
  225.             Alinecnt++;
  226.         }
  227.  
  228.         if(Bfirstline+i < L_getclmax(1))
  229.         {
  230.             m_selectwin(winb);
  231.             showline(1,Bfirstline+i,i);
  232.             Blinecnt++;
  233.         }
  234.     }
  235.     /*
  236.     **    now figure out how many tokens we actually printed
  237.     */
  238.     for(i=Atfirstline;Anexttoken<K_gettmax(0) && L_tl2cl(0,i) < Afirstline+Alinecnt;i++)
  239.     {
  240.             Anexttoken += L_getcount(0,i);
  241.     }
  242.  
  243.     for(i=Btfirstline;Bnexttoken<K_gettmax(1) && L_tl2cl(1,i) < Bfirstline+Blinecnt;i++)
  244.     {
  245.             Bnexttoken += L_getcount(1,i);
  246.     }
  247.     tokencnt = MIN(Anexttoken,Bnexttoken) - firsttoken;
  248.  
  249.     /*
  250.     **    draw a line through any tokens that come before the first
  251.     **        token that is being compared
  252.     */
  253.     if (L_getindex(0,Atfirstline) != firsttoken)
  254.     {
  255.         m_selectwin(wina);
  256.         for(i=L_getindex(0,Atfirstline);i<firsttoken;i++)
  257.         {
  258.             drawline(K_gettoken(0,i),0);
  259.         }
  260.     }
  261.  
  262.     if (L_getindex(1,Btfirstline) != firsttoken)
  263.     {
  264.         m_selectwin(winb);
  265.  
  266.         for(i=L_getindex(1,Btfirstline);i<firsttoken;i++)
  267.         {
  268.             drawline(K_gettoken(1,i),0);
  269.         }
  270. /*
  271. m_line(Bt[Bindex[Bfirstline]]->pos*fontx,fonty/2,(Bt[firsttoken]->pos*fontx)-2,fonty/2);
  272. */
  273.     }
  274.  
  275.     if (Anexttoken > Bnexttoken)
  276.     {
  277.         m_selectwin(wina);
  278.         for(i=Bnexttoken;i<Anexttoken;i++)
  279.         {
  280.             drawline(K_gettoken(0,i),L_tl2cl(0,K_getline(K_gettoken(0,i)))-Afirstline);
  281.         }
  282.     }
  283.  
  284.     if (Anexttoken < Bnexttoken)
  285.     {
  286.         m_selectwin(winb);
  287.         for(i=Anexttoken;i<Bnexttoken;i++)
  288.         {
  289.             drawline(K_gettoken(1,i),L_tl2cl(1,K_getline(K_gettoken(1,i)))-Bfirstline);
  290.         }
  291.     }
  292.  
  293. }
  294.  
  295. /*
  296. **    line is given in conten line
  297. */
  298. drawline(ptr,line)
  299. K_token ptr;
  300. int line;
  301. {
  302.         m_line(K_getpos(ptr)*fontx,
  303.             (line*fonty)+fonty/2,
  304.             (K_getpos(ptr)+strlen(K_gettext(ptr)))*fontx,
  305.             (line*fonty)+fonty/2);
  306. }
  307.  
  308. /*
  309. **    takes arguments in terms of content lines
  310. */
  311. showline(file,index,row)
  312. int file;
  313. int index;
  314. int row;
  315. {
  316.     static char tmp[Z_LINELEN];
  317.     m_move(0,row);
  318.     stripnl(tmp,L_getcline(file,index));
  319.     m_printstr(tmp);
  320. }
  321.  
  322. stripnl(to,from)
  323. char *to,*from;
  324. {
  325.     while ((*from != '\n') && (*from != '\0'))
  326.     {
  327.         *to++ = *from++;
  328.     }
  329.     *to = '\0';
  330. }
  331.  
  332. static int didscr = 0;
  333.  
  334. messup()
  335. {
  336.     int col, row;
  337.     int dum1,dum2,dum3,border;
  338.  
  339.     m_setup(W_FLUSH|W_DEBUG);
  340.     m_push(P_EVENT|P_FLAGS|P_POSITION);
  341.     get_param(&dum1,&dum2,&dum3,&border);
  342.     didscr = 1;
  343.     comwin =  m_makewindow(192,50,732,116);
  344.     wina = m_makewindow(0,218,570,670);
  345.     m_selectwin(wina);
  346.     m_font(2);
  347.     get_font(&fontx,&fonty);
  348.     m_shapewindow(0,218,NCOL*fontx+(2*border),NROW*fonty+(2*border));
  349.  
  350.     get_colrow(&col,&row);
  351.     if ((col != NCOL) || (row != NROW))
  352.     {
  353.         Z_fatal("bad window size");
  354.     }
  355.     m_func(B_INVERT);
  356.     m_setmode(W_ABS);
  357.  
  358.     winb = m_makewindow(580,218,570,670);
  359.     m_selectwin(winb);
  360.     m_font(2);
  361.     get_font(&fontx,&fonty);
  362.     m_shapewindow(580,218,NCOL*fontx+(2*border),NROW*fonty+(2*border));
  363.  
  364.     get_colrow(&col,&row);
  365.     if ((col != NCOL) || (row != NROW))
  366.     {
  367.         Z_fatal("bad window size");
  368.     }
  369.     m_func(B_INVERT);
  370.     m_setmode(W_ABS);
  371.  
  372.     m_selectwin(comwin);
  373.     m_clear();
  374.     m_setmode(W_ABS);
  375.     m_setmode(W_ACTIVATE);
  376. }
  377.  
  378. V_cleanup()
  379. {
  380.     if (didscr)
  381.     {
  382.         m_destroywin(wina);
  383.         m_destroywin(winb);
  384.         m_destroywin(comwin);
  385.         m_popall();
  386.         m_setecho();
  387.         (void) fclose(m_termin);
  388.         (void) fclose(m_termout);
  389.     }
  390. }
  391.  
  392. #else
  393.  
  394. #include "misc.h"
  395. /*
  396. **    dummy code for systems that don't have
  397. **    the mgr window manager installed
  398. */
  399. V_visual(d)
  400. int d;
  401. {
  402.     Z_fatal("visual mode is not available on this machine\n");
  403.     return(-d);    /* boiler plate */
  404. }
  405.  
  406. void
  407. V_cleanup()
  408. {
  409. }
  410.  
  411. #endif
  412.