home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / code_examples / librar / reed.c < prev    next >
Text File  |  1989-02-08  |  4KB  |  158 lines

  1. /*--------------------------------------*/
  2. /*                    */
  3. /*         REED(X,X,X,X,X,X,X)        */
  4. /*                    */
  5. /* Fills a character array with keyboard*/
  6. /* input. The first two arguments are   */
  7. /* the coordinates of the cursor posi-  */
  8. /* tion.  If the coordinates are both    */
  9. /* negative then the cursor positioning */
  10. /* is ignored.  The third argument is     */
  11. /* the array being passed. The fourth is*/
  12. /* the maximum length of the array. The */
  13. /* fifth is initial filler. The sixth    */
  14. /* is the back-arrow filler.  The       */
  15. /* seventh is a flag for special        */
  16. /* editing:                */
  17. /*                    */
  18. /*        0: normal input        */
  19. /*         1: numeric input        */
  20. /*         2: upper case input        */
  21. /*         3: date input        */
  22. /*         4: floating point input      */
  23. /*         5: security input        */
  24. /*                    */
  25. /*--------------------------------------*/
  26. # include "stdlib.h"
  27. reed(x,y,w,a,b1,b2,c)
  28. int x,y,a,b2,c;
  29. char w[],b1;
  30. {
  31.         int j,d,r,m,M[12],pntflag,xloc,yloc;
  32.         char X[6];
  33.         if (c==3){
  34.             M[0]=31;
  35.             M[1]=28;
  36.             M[2]=31;
  37.             M[3]=30;
  38.             M[4]=31;
  39.             M[5]=30;
  40.             M[6]=31;
  41.             M[7]=31;
  42.             M[8]=30;
  43.             M[9]=31;
  44.             M[10]=30;
  45.             M[11]=31;
  46.         }
  47.         if (c==4)
  48.             pntflag=0;
  49.  
  50. REED1:  charinit(w,a,b1);
  51.         if (x>=0 && y>=0)
  52.             scr_curs(x,y);
  53.         if (c==3){
  54.             printf("%c%c/%c%c/%c%c",b2,b2,b2,b2,b2,b2);
  55.             bspace(8);
  56.         }
  57.         for (j=0;j<a+1;j++){
  58.  
  59. REED2:       if (c==2 || c==5)
  60.                  d=key(0,0);
  61.              else
  62.                  d=key(-1,0);
  63.              if (d==3 && c==5)
  64.                  system("reboot");
  65.              if (d==13){
  66.                  if (c==3 && j!=a && j){
  67.                      cprintf("\a");
  68.                      goto REED2;
  69.                  }
  70.                  j=a+1;
  71.                  goto REED4;
  72.              }
  73.              if (j==a && d!=8 && d!=127)
  74.                  goto REED2;
  75.              if ((d==8 || d==127) && j){
  76.                   if (c==3){
  77.                       if (j==2 || j==4)
  78.                           bspace(1);
  79.                   }
  80.                   barrow(b2);
  81.                   j--;
  82.                   if (c==4 && w[j]==46)
  83.                       pntflag=0;
  84.                   w[j]=b1;
  85.                   goto REED2;
  86.              }
  87.              if (c==1 || c==3){
  88.                  if (d<48 || d>57)
  89.                      goto REED2;
  90.              }
  91.              if (c==4){
  92.                  if (d==46){
  93.                      if (pntflag==1)
  94.                          goto REED2;
  95.                      else{
  96.                          pntflag=1;
  97.                          goto REED3;
  98.                      }
  99.                  }
  100.                  if (d==45){
  101.                      if (j)
  102.                          goto REED2;
  103.                      else
  104.                          goto REED3;
  105.                  }
  106.                  if (d<48 || d>57)
  107.                      goto REED2;
  108.              }
  109.              if (d<32 || d>127)
  110.                  goto REED2;
  111.  
  112. REED3:       if (c!=5){
  113.                  scr_loc(&xloc,&yloc);
  114.              out(d,1);
  115.                  scr_curs(xloc,yloc+1);
  116.              }
  117.              w[j]=d;
  118.              if (c==3){
  119.                  if (j==1 || j==3)
  120.                      fspace(1);
  121.              }
  122.  
  123. REED4:       ;
  124.         }
  125.         if (c==3){
  126.             if (w[0]==b1)
  127.                 goto REED5;
  128.             r=(w[4]-48)*10+w[5]-48;
  129.             m=(w[0]-48)*10+w[1]-48;
  130.             d=(w[2]-48)*10+w[3]-48;
  131.             if (m<1 || m>12){
  132.                 cprintf("\a");
  133.                 bspace(8);
  134.                 goto REED1;
  135.             }
  136.             if (!efactor(r,4) && m==2 && d>29){
  137.                 cprintf("\a");
  138.                 bspace(8);
  139.                 goto REED1;
  140.             }
  141.             if (!efactor(r,4) && m==2)
  142.                 goto REED5;
  143.             if (d<1 || d>M[m-1]){
  144.                 cprintf("\a");
  145.                 bspace(8);
  146.                 goto REED1;
  147.             }
  148.  
  149. REED5:      for (j=0;j<2;j++)
  150.                  X[j]=w[j+4];
  151.             for (j=2;j<6;j++)
  152.                  X[j]=w[j-2];
  153.             for (j=0;j<6;j++)
  154.                  w[j]=X[j];
  155.         }
  156.     return(0);
  157. }
  158.