home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / DISPMEM.ZIP / DISPMEM.C next >
Encoding:
C/C++ Source or Header  |  1988-10-21  |  2.3 KB  |  101 lines

  1. /*
  2.  
  3.  DISPMEM.c       Bruce Hammerberg
  4.  
  5.  Shows the contents of a Clipper .MEM file
  6.  
  7.  Enhancement to article published in Reference(Clipper), October 1988
  8.  Published by Pinnacle Publishing, Inc.  Written by Rick Spence.
  9.  
  10.  Syntax:  DISPMEM memfile[.mem]
  11.  
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <fcntl.h>
  16. #include <stdlib.h>
  17. #include <io.h>
  18. #include <alloc.h>
  19.  
  20. #define O_RAW O_BINARY      /* for Turbo-C */
  21.  
  22. typedef struct
  23.  {char mname[11];
  24.   char mtype;
  25.   char mfiller1[4];
  26.   char mlen;
  27.   char mdec;
  28.   char mfiller[14];
  29.  }MEM_REC;
  30.  
  31. MEM_REC mem_rec;
  32.  
  33. main(argc, argv)
  34.  
  35. int argc;
  36. char *argv[];
  37. {int mem_handle;
  38.  char *cstr,ctype,*memfile="";
  39.  unsigned csize;
  40.  double num;
  41.  int log,clen,ndec,mon,day_mon,yrs,day_year;
  42.  int months[13]={0,31,59,90,121,151,181,212,243,273,304,334,366};
  43.  if (argc!=2)
  44.  {printf("SYNTAX: Dispmem file[.mem]\n\n");
  45.   exit(1);
  46.  }
  47.  strcpy(memfile,argv[1]);
  48.  if (strchr(memfile,'.')==NULL) strcat(memfile,".MEM");
  49.  mem_handle=open(memfile,O_RAW|O_RDONLY);
  50.  if (mem_handle==-1)
  51.  {printf("Error opening file %s\n",memfile);
  52.   exit(1);
  53.  }
  54.  
  55.  while (read(mem_handle,(char *) &mem_rec, sizeof(MEM_REC))==sizeof(MEM_REC))
  56.  {ctype=mem_rec.mtype&127;
  57.   clen=mem_rec.mlen;
  58.   ndec=mem_rec.mdec;
  59.   printf("\n%-10s ",mem_rec.mname);
  60.  
  61.   switch (ctype)
  62.   {case 'C':
  63.         csize=clen+ndec*256;
  64.         printf("%5d  ",csize-1);
  65.         cstr=malloc(csize);
  66.         read(mem_handle,cstr,csize);
  67.         printf("'%s'",cstr);
  68.         free(cstr);
  69.         break;
  70.    case 'N':
  71.         printf("%5d  ",clen);
  72.         read(mem_handle,(char *)&num,8);
  73.         printf("%g",num);
  74.         break;
  75.    case 'D':
  76.         /* dates are represented as Julian dates */
  77.         /* first value being 2415021 for 1/1/0   */
  78.         /* null date has value of 0              */
  79.         printf("%5d  ",8);
  80.         read(mem_handle,(char *)&num,8);
  81.         yrs=0;
  82.         mon=0;
  83.         day_mon=0;
  84.         num=num-2415020;
  85.         if (num>0)
  86.          {yrs=num/365.25;
  87.           day_year=num-yrs*365.25+(yrs%4!=0);
  88.           mon=1;
  89.           while (day_year>months[mon]) mon++;
  90.           day_mon=day_year-months[mon-1];
  91.          }
  92.         printf("%2u/%2u/%2u",mon,day_mon,yrs);
  93.         break;
  94.    case 'L':
  95.         printf("%5d  ",clen);
  96.         read(mem_handle,&log,1);
  97.         printf("%s",(log==0)?".f.":".t.");
  98.   }
  99.  }
  100. }
  101.