home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff240.lzh / MemLib / test.c < prev   
C/C++ Source or Header  |  1989-08-28  |  2KB  |  90 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <stdio.h>
  4. #include <proto/exec.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8. #define MWDEBUG 1
  9.  
  10. #include "memwatch.h"
  11.  
  12. void main(int, char **);
  13.  
  14. void main(argc, argv)
  15. int argc;
  16. char **argv;
  17. {
  18.    char *tmpchar = NULL;
  19.    int doit = 1;
  20.    int offset = 0;
  21.    long tmplong;
  22.    char buffer[100];
  23.  
  24.    MWInit(NULL, 0);
  25.  
  26.    while(doit)
  27.    {
  28.       printf("\nEnter command (h for help): ");
  29.       fgets(buffer, 100, stdin);
  30.       offset = 0;
  31.       switch(buffer[0])
  32.       {
  33.          case 'a': case 'A':  /* Allocate memory */
  34.             while(buffer[++offset] == ' ' && buffer[offset]);
  35.             stcd_l(buffer+offset, &tmplong);
  36.             tmpchar=AllocMem(tmplong, 0);
  37.             printf("%ld bytes allocated, value 0x%08lx\n", 
  38.                tmplong, tmpchar);
  39.             break;
  40.  
  41.          case 'w': case 'W':  /* Write to memory */
  42.             while(buffer[++offset] == ' ' && buffer[offset]);
  43.             stcd_l(buffer+offset, &tmplong);
  44.             if(tmpchar) memset(tmpchar, 0, tmplong);
  45.             else printf("Can't write, no memory allocated\n");
  46.             printf("%d bytes cleared\n", tmplong);
  47.             break;
  48.  
  49.          case 'r': case 'R':  /* Report */
  50.             while(buffer[++offset] == ' ' && buffer[offset]);
  51.             offset+=stcd_l(buffer+offset, &tmplong);
  52.             MWReport(buffer+offset, tmplong);
  53.             printf("Report complete\n\n\n");
  54.             break;
  55.  
  56.          case 'c': case 'C':  /* Check */
  57.             MWCheck();
  58.             printf("Check complete\n\n\n");
  59.             break;
  60.  
  61.          case 'f': case 'F':  /* Free */
  62.             while(buffer[++offset] == ' ' && buffer[offset]);
  63.             stcd_l(buffer+offset, &tmplong);
  64.             FreeMem(tmpchar, tmplong);
  65.             printf("%d bytes freed\n", tmplong);
  66.             break;
  67.  
  68.          case 'q': case 'Q':  /* QUIT */
  69.             doit = 0;
  70.             break;
  71.  
  72.          default:
  73. printf("Commands are:\n");
  74. printf("A <n>     --> Allocate 'n' bytes, replace current allocation\n");
  75. printf("W <n>     --> Write 'n' bytes to most recent allocation\n");
  76. printf("F <n>     --> Free 'n' bytes starting at most recent allocation\n");
  77. printf("R <lvl>   --> Report on usage; <lvl> is 1 for less, 2 for more detail\n");
  78. printf("C         --> Check all allocations, report errors\n");
  79. printf("Q         --> Quit program\n");
  80.             break;
  81.       }
  82.    }
  83.  
  84.    MWTerm();
  85.  
  86.    exit(0);
  87. }
  88.  
  89.  
  90.