home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a014 / 1.ddi / CDBINC.EXE / FOUNCTBK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-31  |  6.6 KB  |  340 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <string.h>
  4. #include "screen.h"
  5. go_to( row,  column)
  6. int row;
  7. int column;
  8. {
  9. union REGS inregs;
  10. union REGS outregs;
  11.  
  12. inregs.h.ah=2;
  13. inregs.h.bh=0;
  14. inregs.h.dh=row;
  15. inregs.h.dl=column;
  16. int86(0x10,&inregs,&outregs);
  17. return(1);
  18. }
  19.  
  20. now_cursor(x,y)
  21. int *x,*y;
  22. {
  23.   union REGS r;
  24.  
  25.    r.h.ah=3;
  26.    r.h.bh=0;
  27.    int86(0x10,&r,&r);
  28.    *x = r.h.dh;
  29.    *y = r.h.dl;
  30.   return;
  31.  }
  32.  
  33.  color_puts(s,color)
  34.  char *s;
  35.  int color;
  36.  {
  37.    union REGS r;
  38.    int x,y,z;
  39.  
  40.    now_cursor(&x,&z);
  41.    y=z;
  42.    while (*s) {
  43.     if (*s=='\n') {
  44.       s++;
  45.       x++;
  46.       y=z;
  47.       continue;
  48.           }
  49.      go_to(x,y);
  50.      r.h.ah=9;
  51.      r.h.al=*s++;
  52.      r.h.bl=color;
  53.      r.h.bh=0;
  54.      r.x.cx=1;
  55.      int86(0x10,&r,&r);
  56.      y++;
  57.           }
  58.      go_to(x,y);
  59.      return;
  60.      }
  61.    getcc(){
  62.    union REGS r;
  63.    r.h.ah=0;
  64.    int86(0x16,&r,&r);
  65.    if (r.h.al==27) exit(0);
  66.    if (r.h.al) return(r.h.al);
  67.    return(r.x.ax);
  68.       }
  69.  
  70. clear_win(startx,starty,endx,endy,action,line)
  71. int startx,starty;
  72. int endx,endy;
  73. int action,line;
  74. {
  75. union REGS r;
  76.  
  77. r.h.ah=action;
  78. r.h.al=line;
  79. r.x.bx=0x0700;
  80. r.h.ch=startx;
  81. r.h.cl=starty;
  82. r.h.dh=endx;
  83. r.h.dl=endy;
  84. int86(0x10,&r,&r);
  85. return;
  86. }
  87.  
  88.  
  89. gframe(startx,starty,endx,endy,sss,color)
  90. int startx,starty;
  91. int endx,endy;
  92. int sss;
  93. int color;
  94. {
  95. static char dd[3][6][3]={
  96.       "⌐Ñ","⌐º","⌐│","⌐╖","⌐╗","⌐┐",
  97.       "⌐ñ","⌐ª","⌐░","⌐┤","⌐╕","⌐╝" ,
  98.       "  ","  ","  ","  ","  ","  "
  99.                      };
  100. int row,col;
  101. char *s;
  102.  
  103. clear_win(startx,starty,endx,endy,6,0);
  104. go_to(startx,starty);
  105. color_puts(dd[sss][2],color);
  106. for(col=starty+2; col<endy; col+=2){
  107.        go_to(startx,col);
  108.        color_puts(dd[sss][0],color);
  109.                                    }
  110. go_to(startx,endy);
  111. color_puts(dd[sss][3],color);
  112.  
  113. for(row=startx+1; row<endx; ++row){
  114.    go_to(row,starty);
  115.    color_puts(dd[sss][1],color);
  116.    go_to(row,endy);
  117.    color_puts(dd[sss][1],color);
  118.    go_to(row,starty+2);
  119.                                  }
  120.    go_to(endx,starty);
  121.   color_puts(dd[sss][4],color);
  122.  
  123.   for(col=starty+2; col<endy; ++col,++col){
  124.        go_to(endx,col);
  125.        color_puts(dd[sss][0],color);
  126.      }
  127.   go_to(endx,endy);
  128.   color_puts(dd[sss][5],color);
  129.    return;
  130. }
  131. read_string(string,length)
  132. char *string;
  133. int length;
  134. {
  135.    char middstr[41];
  136.    int  ctc,charact;
  137.    int x,y;
  138.    for (ctc=0;ctc<20;ctc++) middstr[ctc]='\0';
  139.    ctc=0;
  140.    while (ctc<length-1)
  141.       {
  142.       charact=getchb();
  143.       if (charact==13) break;
  144.       if ((charact==8)&&(ctc>0)) {
  145.      now_cursor(&x,&y);
  146.      go_to(x,y-1); printf(" ");
  147.      go_to(x,y-1); middstr[--ctc]='\0';
  148.      continue;
  149.      }
  150.       if (charact<=30 || charact>=128) continue;
  151.       printf("%c",charact);
  152.       middstr[ctc++]=charact;
  153.       }
  154.    if (strcmp(middstr,NULL)!=0)
  155.       strcpy(string,middstr);
  156.    return(0);
  157. }
  158.  
  159. getchb()
  160. {
  161.   union REGS regs;
  162.   int t,m;
  163.   regs.x.ax=0;
  164.   int86(0x16,®s,®s);
  165.   t=regs.x.ax & 0x00ff;
  166.   m=(regs.x.ax-t)/256;
  167.   if (t!=0) return(t);
  168.   return(m+200);
  169. }
  170. oneline(pos,fixlen,dislen,fldin)
  171. int pos,fixlen,dislen;
  172. char *fldin;
  173. {
  174.  int in,count=0,i,insert=1,sum;
  175.  int row,col;
  176.  char *str;
  177.  char *tstr;
  178.  in=strlen(fldin);
  179.  if (in!=0){
  180.     for (in=0;fldin[in]!='\0'&&fldin[in]!='\n';in++);
  181.     fldin[in]='\0';}
  182.  tstr=(char *)malloc(sizeof(char)*(dislen+1));
  183.  ncpy(tstr,fldin,0,dislen);
  184.  row=pos/100;
  185.  col=pos%100;
  186.  printf("\033[25;1H\033[0;37;41m%79s\033[25;5Hí√,í·  ╥╞╢»╣Γ▒Ω    Del  ╔╛│²╫╓╖√    Ins  ▓σ╚δ/╕▓╕╟    ESC  ═╦│÷"," ");
  187.  printf("\033[25;70H\033[0;0;0mIns");
  188.  printf("\033[0;0;0m\033[%u;%uH%-.*s",row,col,dislen,tstr);
  189.  for(;;)
  190.    {
  191.      printf("\033[%u;%uH",row,col);
  192.      in=get_key();
  193.      switch(in)
  194.        {
  195.      case KEY_RIGHT:
  196.         if(fldin[col-pos%100+count]=='\0')
  197.           {
  198.             printf("\007");
  199.             continue;
  200.           }
  201.         else
  202.           {
  203.             if(col<(pos%100+dislen-1))
  204.               {
  205.             col++;
  206.             continue;
  207.               }
  208.            else
  209.              {
  210.             count++;
  211.             if(count<strlen(fldin))
  212.               ncpy(tstr,fldin,count,dislen);
  213.             else
  214.               ncpy(tstr,fldin,count,strlen(fldin));
  215.              }
  216.           }
  217.          printf("\033[0;0;0m\033[%u;%uH%-.*s",pos/100,pos%100,dislen,tstr);
  218.          continue;
  219.     case KEY_LEFT:
  220.          if(col==pos%100 && count==0)
  221.            {
  222.              printf("\007");
  223.              continue;
  224.            }
  225.          else
  226.            {
  227.              if(col>pos%100)
  228.             {
  229.               col--;
  230.               continue;
  231.             }
  232.              else
  233.             {
  234.               count--;
  235.               ncpy(tstr,fldin,count,dislen);
  236.             }
  237.            }
  238.          printf("\033[0;0;0m\033[%u;%uH%-.*s",pos/100,pos%100,dislen,tstr);
  239.          continue;
  240.     case KEY_INSERT : if (insert==0)
  241.              {
  242.                printf("\033[25;70H\033[0;0;0mIns\033[0;33;46m");
  243.                insert=1;
  244.              }
  245.            else
  246.              {
  247.                printf("\033[25;70H\033[0;37;41m   \033[0;33;46m");
  248.                insert=0;
  249.              }
  250.            break;
  251.     case Del:
  252.         for(i=0;fldin[i]!='\0';i++);sum=i;
  253.         if(sum==0||fldin[col-(pos%100)+count]=='\0')
  254.         {
  255.             printf("\007");
  256.             continue;
  257.         }
  258.         for(i=col-(pos%100)+count;i<sum;i++)
  259.              fldin[i]=fldin[i+1];
  260.         ncpy(tstr,fldin,count,dislen);
  261.         printf("\033[0;0;0m\033[%u;%uH%-.*s ",pos/100,pos%100,dislen,tstr);
  262.         continue;
  263.     case Backspace:
  264.         for(i=0;fldin[i]!='\0';i++);sum=i;
  265.         if(sum==0)
  266.           {
  267.             printf("\007");
  268.             continue;
  269.           }
  270.         if(col<=pos%100)
  271.           {
  272.             printf("\007");
  273.             continue;
  274.           }
  275.         for(i=col-(pos%100)+count;i<=sum;i++)
  276.           fldin[i-1]=fldin[i];
  277.         fldin[i-1]='\0';
  278.         ncpy(tstr,fldin,count,dislen);
  279.         printf("\033[0;0;0m\033[%u;%uH%-.*s ",pos/100,pos%100,dislen,tstr);
  280.         col--;
  281.         continue;
  282.     case KEY_ESC:
  283.     case KEY_ENTER:
  284.         free(tstr);
  285.         return(0);
  286.     default:
  287.         if((unsigned char)in==0)continue;
  288.         for(i=0;fldin[i]!='\0'&&fldin[0]!='\0';i++);sum=i;
  289.         if(sum>=fixlen)
  290.           {
  291.             printf("\033[25;1H\033[1;36;41m┐φ╢╚│¼│÷╖╢╬º\033[0;0;7m\007");
  292.             continue;
  293.           }
  294.         if(insert==1)
  295.           {
  296.             for(i=sum;i>=col-pos%100+count;i--)
  297.             fldin[i+1]=fldin[i];
  298.             fldin[i+1]=(char)in;
  299.             ncpy(tstr,fldin,count,dislen);
  300.           }
  301.         else
  302.           {
  303.             fldin[col-pos%100+count]=(char)in;
  304.             ncpy(tstr,fldin,count,dislen);
  305.             fldin[sum+1]='\0';
  306.           }
  307.         if(col++==(pos%100+dislen))
  308.           {
  309.             col=pos%100+dislen;
  310.             count++;
  311.             if(count<strlen(fldin))
  312.              ncpy(tstr,fldin,count,dislen);
  313.             else
  314.              ncpy(tstr,fldin,count,strlen(fldin));
  315.           }
  316.         printf("\033[0;0;0m\033[%u;%uH%-.*s",pos/100,pos%100,dislen,tstr);
  317.         continue;
  318.     }
  319.     }
  320. }
  321. ncpy(tstr,fldin,start,no)
  322. char *tstr;
  323. char *fldin;
  324. int start,no;
  325. {
  326.  int i=0;
  327.  if(start!=0)
  328.    for(i=0;i<start;i++) fldin++;
  329.  for(i=start;(i<start+no && (*fldin)!='\0');i++)
  330.  *tstr++=*fldin++;
  331.  *tstr='\0';
  332. }
  333. get_key()
  334. {
  335.   union REGS r;
  336.   r.h.ah=0;
  337.   int86(0x16,&r,&r);
  338.   return(r.x.ax);
  339.  }
  340.