⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mem.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 2 页
字号:
;/*
; *                      Microsoft Confidential
; *                      Copyright (C) Microsoft Corporation 1988 - 1991
; *                      All Rights Reserved.
; */

/*----------------------------------------------------------------------+
|                                                                       |
|                                                                       |
|       Title:          MEM                                             |
|                                                                       |
|       Syntax:                                                         |
|                                                                       |
|               From the DOS command line:                              |
|                                                                       |
|               MEM                                                     |
|                       - Used to display DOS memory map summary.       |
|                                                                       |
|               MEM /CLASSIFY                                           |
|                       - Lists modules' memory use.                    |
|                                                                       |
|               MEM /DEBUG                                              |
|                       - Used to display a detailed DOS memory map.    |
|                                                                       |
|               MEM /FREE                                               |
|                       - Lists free memory, in various forms.          |
|                                                                       |
|               MEM /MODULE                                             |
|                       - Details a single module's memory use.         |
|                           						|
|=======================================================================|
|   				Revision History                  	|   
|=======================================================================|
|                                                                       |
|       AN001 - PTM P2914 -> This PTM relates to MEM's ability to report|
|                            the accurate total byte count for EM       |
|                            memory.                                    |
|                                                                       |
|       AN002 - PTM P3477 -> MEM was displaying erroneous base memory   |
|                            information for "Total" and "Available"    |
|                            memory.  This was due to incorrect logic   |
|                            for RAM carving.                           |
|                                                                       |
|       AN003 - PTM P3912 -> MEM messages do not conform to spec.       |
|               PTM P3989                                               |
|                                                                       |
|               Date: 1/28/88                                           |
|                                                                       |
|       AN004 - PTM P4510 -> MEM does not give correct DOS size.        |
|                                                                       |
|               Date: 4/27/88                                           |
|                                                                       |
|       AN005 - PTM P4957 -> MEM does not give correct DOS size for     |
|                            programs loaded into high memory.          |
|                                                                       |
|               Date: 6/07/88                                           |
|									|
|   M000   SR   8/27/90   Added new Ctrl-C handler to delink UMBs	|
|									|
|   M003  NSM  12/28/90   Added a New switch /Classify which groups	|
|         			groups programs in conv and UMB and 	|
|				gives sizes in decimal and hex.         |
|                                                                       |
|   T-RICHJ     5/27/92   Rewrote 70% or so; different options, added   |
|                         mprintf(), reworked internal memory           |
|                         structure, replaced old command-line parser   |
|                                                                       |
+----------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/

#include "ctype.h"
#include "stdio.h"
#include "dos.h"
#include "string.h"
#include "stdlib.h"
#include "msgdef.h"
#include "version.h"         /* MSKK02 07/18/89 */
#include "mem.h"

/*---------------------------------------------------------------------------*/

/* All global declarations go here */

   char   *SingleDrive = "%c:";
   char   *MultipleDrives = "%c: - %c:";
   char   *UnOwned = "----------";

#if IBMCOPYRIGHT                                                        /*EGH*/
        char    *Ibmbio = "IBMBIO";                                     /*EGH*/
        char    *Ibmdos = "IBMDOS";                                     /*EGH*/
#else                                                                   /*EGH*/
        char    *Ibmbio = "IO    "; 
        char    *Ibmdos = "MSDOS "; 
#endif                                                                  /*EGH*/

   char  LinkedIn = 0;   /* Flag set when mem links in UMBs :M000 */
   void (interrupt far *OldCtrlc)(); /* Old Ctrlc handler save vector :M000*/

/*---------------------------------------------------------------------------*/

   struct sublistx sublist[10];

   struct SYSIVAR far *SysVarsPtr;

   char ddrivername[MAX_DDRIVER_REP][9];
   int  ddriveridx = 0;

   unsigned far *ArenaHeadPtr;

   char      OwnerName[128];
   char      TypeText[128];
   char      cmd_line[128];

   unsigned  long UMB_Head;
   unsigned  LastPSP=0;

   char      UseArgvZero = TRUE;
   char      EMSInstalledFlag = (char) 2;

   union  REGS  InRegs;
   union  REGS  OutRegs;
   struct SREGS SegRegs;

   int    BlockDeviceNumber;

   int       NoCR = 0;

   int       DataLevel;
   int       PageBreak;
   int       num_lines;        /* number of lines we've printed on the page */

   char      ModName[40];      /* MEM/M option name */

   struct mem_classif mem_table;

/*---------------------------------------------------------------------------*/

char *ArgPos;  /* Used to report which argument caused an error */

void interrupt cdecl far MemCtrlc (unsigned es, unsigned ds,
         unsigned di, unsigned si, unsigned bp, unsigned sp,
         unsigned bx, unsigned dx, unsigned cx, unsigned ax );

void
main (argc, argv)
int   argc;
char      **argv;
{
   unsigned char   UMB_Linkage;
   unsigned int    rc=0;      /* init to NO ERROR */

   if (argc)  (void)*argv;

   sysloadmsg(&InRegs,&OutRegs);
   if ((OutRegs.x.cflag & CarryFlag) == CarryFlag)
      {
      sysdispmsg(&OutRegs,&OutRegs);
      exit(1);
      }

   init_data();  /* Initialize memory totals */
   DataLevel = PageBreak = 0;
   num_lines = 0;

   if ((rc = parse_cmd (argc, argv)) != 0)
      {
      Parse_Message (rc, (char far *)ArgPos);
      exit (1);
      }

   if (PageBreak)
      {                          /* Find the # of lines on the console      */
      PageBreak = get_lines();   /* (error sets PageBreak to 0, which turns */
      }                          /* it off nicely)                          */

   /*
    * Store the current Ctrl-C handler and replace with our
    * Ctrl-C handler :M000
    */

   OldCtrlc = _dos_getvect( 0x23 ); /* M000 */
   _dos_setvect( 0x23, MemCtrlc );   /* M000 */

   /*
    * Check the UMB link state and do that nasty...
    *
    */

   InRegs.x.ax = GET_UMB_LINK_STATE; /* save current linkstate of UMBs */
   intdos(&InRegs, &OutRegs);

   LinkedIn = 0;

   if (! (UMB_Linkage = OutRegs.h.al))
      {                /* UMBs not presently linked, so do it now */
      InRegs.x.ax = SET_UMB_LINK_STATE;
      InRegs.x.bx = LINK_UMBS;
      intdos(&InRegs, &OutRegs);
      LinkedIn++;   /* Indicate that we have linked in UMBs :M000 */
      }

   rc = DisplayBaseDetail();      /* go show the memory state, and    */
				  /* restore original UMB link state: */
   if (!UMB_Linkage)      /* weren't linked originally */
      {
      InRegs.x.ax = SET_UMB_LINK_STATE;
      InRegs.x.bx = UNLINK_UMBS;
      intdos(&InRegs, &OutRegs);  /* take 'em out again */
      LinkedIn--;
      }

   _dos_setvect (0x23, OldCtrlc);   /* M000 */

		/* if no error in DisplayBaseDetail,    */
		/* go display other things as necessary */

   if (!rc)
      {
      GetSummary();  /* Fills in a few other things */

      switch (DataLevel)
         {
	 case  0:  DispMEMSummary();
	          break;
	          break;
         case  1:  DisplayClassification();
         case  2:  DisplaySummary();
	          break;
         }
      }

   /* If user did not issue Ctrl-C till here, we just remove the handler */

   exit (rc);
}

/*---------------------------------------------------------------------------*/

unsigned long AddressOf(Pointer)
char far *Pointer;
{
   unsigned long SegmentAddress,OffsetAddress;

   SegmentAddress = (unsigned long) (FP_SEG(Pointer)) * 16l;
   OffsetAddress  = (unsigned long) (FP_OFF(Pointer));

   return ((SegmentAddress + OffsetAddress)/16L);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -