home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a014 / 1.ddi / CDBINC.EXE / FOUNCT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-12  |  6.7 KB  |  337 lines

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