home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff254.lzh / Etale / numget.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  2KB  |  91 lines

  1. /*  numget.c  -- (part of efr)  Copyright © 1989 by William F. Hammond  */
  2. /*            --  get user's number from custom window, providing on    */
  3. /*                the spot rejection of invalid input                   */
  4. #ifndef TDM_H
  5. #include "tdm.h"
  6. #endif
  7. /*********************************************************************/
  8. LONG numget(gstr)
  9. UBYTE *gstr;
  10. {
  11. struct IntuiMessage *msg;
  12. LONG lskip;        /*  that which is returned  */
  13. UBYTE signflag, zeroflag;
  14. UBYTE chx, holdskip[HSL + 1];
  15. ULONG flags;
  16. LONG firstx, lastx;
  17. int gsl;
  18. SHORT jdir, kdir;
  19. zeroflag = NULB;
  20. gsl = strlen(gstr);
  21. savestyle = SetSoftStyle(rp, (ULONG)FS_NORMAL, enable);
  22. SetDrMd(rp,(LONG)(JAM2));
  23. Move(rp, 0L, (LONG)maxrowpix);
  24. ClearScreen(rp);
  25. Text(rp, gstr, (LONG)gsl);
  26. jdir = 0;
  27. firstx = (LONG)rp->cp_x;
  28. lastx = (LONG)rp->cp_x;
  29. flags = VANILLAKEY;
  30. holdskip[0] = '1';   /*  1  is the default return  */
  31. signflag = NULB;
  32. while(1)
  33.    {
  34.    Wait(1L << mw->UserPort->mp_SigBit);
  35.    while(msg = (struct IntuiMessage *)GetMsg(mw->UserPort))
  36.       {
  37.       if(msg->Class == VANILLAKEY) chx = (UBYTE)msg->Code;
  38.       ReplyMsg(msg);
  39.       }
  40.    if ( (chx == 0x0a) || (chx == 0x0d) )break;
  41.    else if (jdir >= HSL)
  42.       {
  43.       zeroflag = ONEB;
  44.       break;
  45.       }
  46.    else if (chx == 0x08)
  47.       {
  48.       Move(rp, firstx, (LONG)maxrowpix);
  49.       ClearScreen(rp);
  50.       if (jdir > 0) jdir --;
  51.       for (kdir = 0; kdir < jdir; kdir ++)
  52.          {
  53.          Text(rp, &holdskip[kdir], 1L);
  54.          }
  55.       lastx = (LONG)rp->cp_x;
  56.       }
  57.    else if( (chx == '-') && (jdir == 0) )
  58.       {
  59.       signflag = ONEB;
  60.       Text(rp, &chx, 1L);
  61.       lastx = (LONG)rp->cp_x;
  62.       }
  63.    else if( (chx < '0') || (chx > '9') )
  64.       {
  65.       DisplayBeep(mw->WScreen);
  66.       Move(rp, lastx, (LONG)maxrowpix);
  67.       ClearScreen(rp);
  68.       }
  69.    else
  70.       {
  71.       holdskip[jdir] = chx;
  72.       jdir ++;
  73.       Text(rp, &chx, 1L);
  74.       lastx = (LONG)rp->cp_x;
  75.       }
  76.    }
  77. lskip = 0L;
  78. kdir = 0;
  79. if(zeroflag) jdir = 0;
  80. while(kdir < jdir)
  81.    {
  82.    lskip = 10L * lskip + (LONG)(holdskip[kdir] - '0');
  83.    kdir ++;
  84.    }
  85. if(signflag) lskip = -lskip;
  86. /*if(lskip == 0L) lskip = numget(gstr);*/
  87. Move(rp, 0L, (LONG)maxrowpix);
  88. ClearScreen(rp);
  89. return lskip;
  90. }
  91.