home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / handy / !Handy / c / History < prev    next >
Encoding:
Text File  |  1993-09-13  |  1.0 KB  |  50 lines

  1. #include "DeskLib:Core.h"
  2. #include "DeskLib:Error.h"
  3.  
  4. #include "Handy.h"
  5. #define BUFFER_SIZE 31
  6.  
  7. static char buffer[BUFFER_SIZE] [MAXLEN];
  8. static int last = 0;         /* last entry in buffer */
  9. static int popPos = 0;      /* last entry to be poped */
  10.  
  11. int History_Push(char *string)
  12. {
  13.     if(*string != NULL){
  14.         register int index = 0;
  15.         register int same = TRUE;
  16.         
  17.         while(string[index] >31 && index<BUFFER_SIZE){
  18.             if ( (same &=(buffer[last][index] == string[index]) ) == FALSE)
  19.                 {   /* if strings are different, copy string into buffer */
  20.                     index = 0;
  21.                     /* inc last modulus buf size */
  22.                     last = ++last % BUFFER_SIZE;
  23.                     while(string[index] > 31 && index<BUFFER_SIZE){
  24.                         buffer[last][index] = string[index];
  25.                         index++;
  26.                     }
  27.                     popPos = last;
  28.                     return(1);
  29.                 }
  30.             index++;
  31.         }
  32.         popPos = last;
  33.         return(2);
  34.     }
  35.     return(FALSE);
  36. }
  37.  
  38. char* History_Backward(void)
  39. {
  40.      popPos = --popPos % BUFFER_SIZE;
  41.      return(&buffer[popPos][0]);
  42. }
  43.  
  44. char* History_Forward(void)
  45. {
  46.      popPos = ++popPos % BUFFER_SIZE;
  47.      return(&buffer[popPos][0]);
  48. }
  49.  
  50.