home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / ansi / tcxlansi.zip / PUTANSI.C < prev    next >
C/C++ Source or Header  |  1992-11-10  |  12KB  |  290 lines

  1. //
  2. //   putansi.c                             P.J. van Zeeland
  3. //                                         Het Wapenschild 27
  4. //                                         8255 DP Swifterbant
  5. //                                         The Netherlands
  6. //
  7. //   prototype : VOID CTYP putansi(ChrP ansiname,WndT win)
  8. //
  9. //   This subroutine may be called to display an ANSI picture
  10. //   in a full-screen (virtual) window. This should be acceptable to
  11. //   any compiler, using TCXL 6.XX
  12. //   For TCXL 5.XX just change the single occurence of WVprtc() to Wprtc()
  13. //
  14. //   Use, modify, or share this source code freely.
  15. //
  16. //   However, if you use this in any of your programs, please be so kind
  17. //   to drop me a line in the Fidonet CXL area, and upload any improvements
  18. //   to the IDC support board.
  19. //                                          Peter Van.Zeeland
  20. //                                          -----------------
  21. //
  22. #include <stdio.h>                          // just a few headers.
  23. #include <stdlib.h>                         // may be overkill
  24. #include <string.h>
  25. #include <dir.h>
  26. #include <dos.h>
  27. #include <bios.h>
  28. #include <io.h>
  29. #include <conio.h>
  30. #include <fcntl.h>
  31. #include <string.h>
  32. #include <float.h>
  33. #include <math.h>
  34. #include <sys\types.h>
  35. #include <sys\stat.h>
  36. #include <ctype.h>
  37. #include <TCXLwin.h>
  38. #include <TCXLcur.h>
  39. #include <TCXLmnu.h>
  40. #include <TCXLent.h>
  41. #include <TCXLsel.h>
  42. #include <TCXLinp.h>
  43. #include <TCXLhlp.h>
  44. #include <TCXLcod.h>
  45. #include <TCXLstr.h>
  46. #include <TCXLmem.h>
  47.  
  48.  
  49. VOID CTYP putansi(ChrP ansiname,WndT win)
  50. {//       ------------
  51.  
  52.  
  53.     FILE *ansifile;                         // file handle for pic
  54.     ChrT ch[50];                            // used to build esc seq
  55.     IntT item,c,number;
  56.     AtrT color=LGREY|_BLACK;                // initial color
  57.     IntT row=1,col=1,saverow,savecol;       // initial coords
  58.  
  59.  
  60.     ansifile=fopen(ansiname,"rb");          // open file
  61.     if(ansifile==NULL)                      // if not found
  62.       return;                               // quit
  63. getseq:                                     // get a complete sequence
  64.     c=0;                                    // in array ch, indexed by c
  65. getone:
  66.     item=fgetc(ansifile);                   // get next element
  67.     if(item==EOF)                           // end-of-file found ?
  68.     {
  69.       fclose(ansifile);                     // close it
  70.       return;                               // done
  71.     }
  72.  
  73.     if(item==27)                            // escape found ?
  74.     {
  75.       ch[c]=(ChrT) item;                    // get next element
  76.       while(item !='A' &&                   // xA = cursor up x
  77.             item !='B' &&                   // xB = cursor down x
  78.             item !='C' &&                   // xC = cursor right x
  79.             item !='D' &&                   // xD = cursor left x
  80.             item !='f' &&                   // x;yf = goto xy
  81.             item !='H' &&                   // x;yH = goto xy
  82.             item !='J' &&                   // 2J = cls
  83.             item !='K' &&                   // K = deleol
  84.             item !='m' &&                   // xm = attribute m
  85.             item !='s' &&                   // s = save cursor
  86.             item !='u' &&                   // u = restore cursor
  87.             ch[c]!= 0)
  88.       {
  89.          item=fgetc(ansifile);              // get next item from file
  90.          c++;
  91.          if(item==EOF)
  92.             ch[c]=0;
  93.          else
  94.             ch[c]=(ChrT)item;
  95.       }
  96.       if(ch[1] != '[')                      // if not a proper esc seq
  97.          ch[c] = ' ';                       // ignore it by changing termin.
  98.       switch(ch[c])                         // terminator tells us what to do
  99.       {
  100.          case 0   : fclose(ansifile);       // end of file found
  101.                     return;
  102.                                             // up n lines
  103.          case 'A' : if(c==2) number=1;
  104.                     if(c==3) number=(ch[2]-'0');
  105.                     if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
  106.                     row -= number;
  107.                     if(row<1) row = 1;
  108.                     break;
  109.                                             // down n lines
  110.          case 'B' : if(c==2) number=1;
  111.                     if(c==3) number=(ch[2]-'0');
  112.                     if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
  113.                     row += number;
  114.                     if(row>VidDep) row = VidDep;
  115.                     break;
  116.                                             // right n columns
  117.          case 'C' : if(c==2) number=1;
  118.                     if(c==3) number=(ch[2]-'0');
  119.                     if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
  120.                     col += number;
  121.                     if(col>VidWid) col = VidWid;
  122.                     break;
  123.                                             // left n columns
  124.          case 'D' : if(c==2) number=1;
  125.                     if(c==3) number=(ch[2]-'0');
  126.                     if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
  127.                     col -= number;
  128.                     if(col<1) col = 1;
  129.                     break;
  130.                                             // goto xy
  131.          case 'f' :
  132.          case 'H' :
  133.                     if(ch[2]=='H')         // no coords ? then home
  134.                     {
  135.                       row=col=1;
  136.                       break;
  137.                     }
  138.                     c=2;                  // first digit of row
  139.                     row=(ch[c++]-'0');
  140.                     if(ch[c]!=';' && ch[c] != 'H')
  141.                     {
  142.                        row*=10;           // 2nd digit of row
  143.                        row+=(ch[c++]-'0');
  144.                     }
  145.                     if(ch[c]!='H')        // column specified too ?
  146.                     {
  147.                        c++;               // skip semicolon
  148.                        col=(ch[c++]-'0'); // first digit of column
  149.                        if(ch[c]!='H')
  150.                        {
  151.                           col*=10;        // 2n digit
  152.                           col+=(ch[c]-'0');
  153.                        }
  154.                     }
  155.                     else                  // no column specified
  156.                        col=1;
  157.                     break;
  158.                                             // clear screen & home cursor
  159.          case 'J' : if(ch[2]=='2')
  160.                     {
  161.                       WchgAtrV(WinLoc(win),color,color);
  162.                       WclearV(WinLoc(win));
  163.                       row=col=1;
  164.                     }
  165.                     break;
  166.                                             // clear to end of line
  167.          case 'K' : while(col-1<VidWid)
  168.                     {
  169.                       WVprtc(win,row-1,col-1,color,' ');
  170.                       col++;
  171.                     }
  172.                     break;
  173.                                             // set color
  174.          case 'm' :
  175.                     c=2;
  176.                     while(ch[c] != 'm')
  177.                     {
  178.                        number=(ch[c++]-'0');
  179.                        if(ch[c]!=';' && ch[c] != 'm')
  180.                        {
  181.                           number*=10;
  182.                           number+=(ch[c++]-'0');
  183.                        }
  184.                        switch(number)
  185.                        {
  186.                            case    0 : color = LGREY|_BLACK;
  187.                                        break;
  188.                            case    1 : color |= INTENSE;
  189.                                        break;
  190.                            case    5 : color |= _BLINK;
  191.                                        break;
  192.                            case    7 : color &= BLACK|_LGREY;
  193.                                        break;
  194.                            case    8 : color = BLACK|_BLACK;
  195.                                        break;
  196.                            case   30 : color &= ~LGREY;
  197.                                        color |= BLACK;
  198.                                        break;
  199.                            case   31 : color &= ~LGREY;
  200.                                        color |= RED;
  201.                                        break;
  202.                            case   32 : color &= ~LGREY;
  203.                                        color |= GREEN;
  204.                                        break;
  205.                            case   33 : color &= ~LGREY;
  206.                                        color |= BROWN;
  207.                                        break;
  208.                            case   34 : color &= ~LGREY;
  209.                                        color |= BLUE;
  210.                                        break;
  211.                            case   35 : color &= ~LGREY;
  212.                                        color |= MAGENTA;
  213.                                        break;
  214.                            case   36 : color &= ~LGREY;
  215.                                        color |= CYAN;
  216.                                        break;
  217.                            case   37 : color |= LGREY;
  218.                                        break;
  219.                            case   40 : color &= ~_LGREY;
  220.                                        color |= _BLACK;
  221.                                        break;
  222.                            case   41 : color &= ~_LGREY;
  223.                                        color |= _RED;
  224.                                        break;
  225.                            case   42 : color &= ~_LGREY;
  226.                                        color |= _GREEN;
  227.                                        break;
  228.                            case   43 : color &= ~_LGREY;
  229.                                        color |= _BROWN;
  230.                                        break;
  231.                            case   44 : color &= ~_LGREY;
  232.                                        color |= _BLUE;
  233.                                        break;
  234.                            case   45 : color &= ~_LGREY;
  235.                                        color |= _MAGENTA;
  236.                                        break;
  237.                            case   46 : color &= ~_LGREY;
  238.                                        color |= _CYAN;
  239.                                        break;
  240.                            case   47 : color |= _LGREY;
  241.                            default   :
  242.                                        break;
  243.                        }
  244.                        if(ch[c]==';')
  245.                           c++;
  246.                     }
  247.                     break;
  248.                                             // save cursor position
  249.          case 's' : saverow=row;
  250.                     savecol=col;
  251.                     break;
  252.                                             // restore cursor position
  253.          case 'u' : row=saverow;
  254.                     col=savecol;
  255.                     break;
  256.                                             // default
  257.          default  : break;
  258.       }
  259.       goto getseq;
  260.     }
  261.  
  262.     if(item==13)                            // carriage return ?
  263.     {
  264.       col=1;                                // go far left
  265.       goto getone;                          // and get next item
  266.     }
  267.  
  268.     if(item==10)                            // line feed ?
  269.     {
  270.       row+=1;                               // go to next line
  271.       goto getone;                          // and get next item
  272.     }
  273.  
  274.                                             // if nothing special: display it !
  275.     WVprtc(win,row-1,col-1,color,(ChrT)item);
  276. updposn:
  277.     col++;                                  // increase column
  278.     if(col>VidWid)                          // if out-of-bounds
  279.     {                                       // wrap to next line
  280.         col=1;
  281.         row++;
  282.         if(row-1>=VidDep)                   // if next line does not exist
  283.           row--;                            // don't increase line
  284.     }
  285.     goto getseq;                            // and get another chr or seq
  286.  
  287. }
  288.  
  289.  
  290.