home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cpicture.zip / TESTPIC.CPP < prev   
C/C++ Source or Header  |  1992-04-20  |  4KB  |  108 lines

  1. /*************************************************************************
  2. **           Paradox-Like Picture Field Input Processing
  3. **************************************************************************
  4. **                                                                      **
  5. **  Copyright (c) 1992  Flexible Information Systems, Inc.              **
  6. **                                                                      **
  7. **    This code may be freely used by any programmer                    **
  8. **    including royalty free inclusion in any commercial                **
  9. **    application, but any commercial rights to the source              **
  10. **    code or object files of this code is are reserved.                **
  11. **                                                                      **
  12. **    This code is supplied strictly as-is, and FIS, Inc. and the       **
  13. **    author assume no responsibility for the accuracy, use or fitness  **
  14. **    for a particular purpose                                          **
  15. **                                                                      **
  16. **                                                                      **
  17. **      Author:         Ken Vogel                                       **
  18. **      CIS Id:         74007,564                                       **
  19. **      Filename:       testpic.cpp                                    **
  20. **      Prefix:         PPIC_                                           **
  21. **      Date:           24-Mar-92                                       **
  22. **                                                                      **
  23. **      Description:    Demonstrates the PARAPICT.CPP input module.
  24. **                      Uses standard dos cputs routines
  25. **                                                                      **
  26. **************************************************************************/
  27.  
  28. #define Uses_TNSCollection
  29.  
  30. #include <stdio.h>
  31. #include <conio.h>
  32. #include <dos.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35.  
  36. #define Uses_parapict
  37. #include "parapict.hpp"
  38.  
  39. void main(void)
  40. {
  41.     char PictureA[100];
  42.     char ResultA[100];
  43.     char *CursorP;
  44.     PPIC_FlagsType Flags;
  45.  ReDo:
  46.     printf ("\nEnter picture >");
  47.     gets (PictureA);
  48.  
  49.     PPIC_PictureClass *PictureP = new PPIC_PictureClass (PictureA);
  50.     if (PictureP == 0 || !PictureP->valid)
  51.       {
  52.         printf ("Error - invalid picture\n");
  53.         goto ReDo;
  54.       }
  55.     printf ("\n:");
  56.     int Key;
  57.  
  58.     *ResultA = 0;
  59.     while (1)
  60.       {
  61.         Key = getch();
  62.         if (Key == 27)
  63.             exit (1);
  64.         if (Key == 8)
  65.           {
  66.             // Do this to reset the string
  67.             if (strlen (ResultA) > 0)
  68.               {
  69.                 ResultA[ strlen (ResultA) - 1] = 0;
  70.                 char *BadP = PictureP->ReprocessString (ResultA, &Flags);
  71.                 if (BadP)
  72.                   {
  73.                     printf ("\nBad reparse at %c\n", *BadP);
  74.                   }
  75.                 else
  76.                   {
  77.                     gotoxy (2, wherey());
  78.                     clreol();
  79.                     cputs (ResultA);
  80.                   }
  81.               }
  82.             continue;
  83.           }
  84.         CursorP = strchr (ResultA, 0);
  85.         if (!PictureP->ProcessLetter ((char)Key, &Flags, True, CursorP, 50))
  86.           {
  87.             if (Flags & PPIC_cOverflow)
  88.                 break;
  89.             sound (440);
  90.             delay (200);
  91.             nosound();
  92.  
  93.             // A necessary kludge because the picture classes do not recover
  94.             // well if a character is rejected (many of the optional classes
  95.             // assume that they are not chosen
  96.             char *BadP = PictureP->ReprocessString (ResultA, &Flags);
  97.             if (BadP)
  98.                 printf ("\nBad reparse at %c\n", *BadP);
  99.           }
  100.         else
  101.           {
  102.             cputs (CursorP);
  103.           }
  104.       }
  105.     goto ReDo;
  106. }
  107.  
  108.