- Add hexa number support in smadmin,
- Code cleanup in smadmin.
This commit is contained in:
parent
04660e4607
commit
ef3ca27707
822
util/smadmin.c
822
util/smadmin.c
@ -1,3 +1,31 @@
|
|||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* smadmin.c */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* This file is part of LibShMem */
|
||||||
|
/* */
|
||||||
|
/* LibShMem is free software; you can redistribute it and/or modify */
|
||||||
|
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||||
|
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||||
|
/* (at your option) any later version. */
|
||||||
|
/* */
|
||||||
|
/* LibShMem is distributed in the hope that it will be useful, */
|
||||||
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||||
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||||
|
/* GNU Lesser General Public License for more details. */
|
||||||
|
/* */
|
||||||
|
/* You should have received a copy of the GNU Lesser General Public License */
|
||||||
|
/* along with LibShMem; if not, write to the Free Software */
|
||||||
|
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Includes */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -10,6 +38,13 @@
|
|||||||
|
|
||||||
#include <shmem.h>
|
#include <shmem.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Definitions */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//VER_INFO_EXPORT (smadmin, "$Revision: 2.3 $", "$Name: $", __FILE__, "$Author: agibert $")
|
//VER_INFO_EXPORT (smadmin, "$Revision: 2.3 $", "$Name: $", __FILE__, "$Author: agibert $")
|
||||||
|
|
||||||
#define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n"
|
#define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n"
|
||||||
@ -40,351 +75,476 @@
|
|||||||
#define TMP_LEN 100
|
#define TMP_LEN 100
|
||||||
#define TMP_SIZE ( TMP_LEN + 1)
|
#define TMP_SIZE ( TMP_LEN + 1)
|
||||||
|
|
||||||
char menu [1000];
|
#define TYPE_NUMBER 1
|
||||||
|
#define TYPE_STRING 2
|
||||||
|
|
||||||
char tmp [TMP_SIZE];
|
|
||||||
|
|
||||||
void init_menu (void);
|
|
||||||
int print_menu (void);
|
|
||||||
|
|
||||||
int main (int argc, char ** argv)
|
char menu[ 1000];
|
||||||
|
|
||||||
|
char tmp[ TMP_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define MENU_ENTRY_ADD( string, id, label) sprintf( tmp, (string), (id), (label)); strcat( menu, tmp);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Prototypes */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Init_Menu */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
void Init_Menu( void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Print_Menu */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int Print_Menu( void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Entry_Promp */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void Entry_Prompt( void *, char *, short);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Init_Menu */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void Init_Menu( void)
|
||||||
{
|
{
|
||||||
int choice;
|
sprintf( menu, "Menu :\n");
|
||||||
char name [NAME_SIZE];
|
|
||||||
int Mode, Locked;
|
|
||||||
void * ptr;
|
|
||||||
char answer [10];
|
|
||||||
SMT_Heap * Heap;
|
|
||||||
int Nb_Detected, Nb_Corrected;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
/* Lancement de commande d'administration */
|
MENU_ENTRY_ADD( " - %2d) %-18s\n", QUIT, "Quit");
|
||||||
|
MENU_ENTRY_ADD( " - %2d) %-18s", BASE_INIT, "Init library");
|
||||||
if (argc >= 2)
|
MENU_ENTRY_ADD( " - %2d) %-18s", BASE_OPEN, "Open library");
|
||||||
{
|
MENU_ENTRY_ADD( " - %2d) %-18s\n", BASE_INFO, "Info library");
|
||||||
if (!strcmp (argv[1], "--help"))
|
MENU_ENTRY_ADD( " - %2d) %-18s", BASE_CLOSE, "Close library");
|
||||||
{
|
MENU_ENTRY_ADD( " - %2d) %-18s", BASE_END, "End library");
|
||||||
fprintf (stderr, USAGE, argv[0]);
|
MENU_ENTRY_ADD( " - %2d) %-18s\n", MHH_INIT, "Init heap");
|
||||||
return -1;
|
MENU_ENTRY_ADD( " - %2d) %-18s", MHH_OPEN, "Open heap");
|
||||||
}
|
MENU_ENTRY_ADD( " - %2d) %-18s", MHH_CHECK, "Check/recover heap");
|
||||||
/* else if (!strcmp (argv[1], "--version"))
|
MENU_ENTRY_ADD( " - %2d) %-18s\n", MHH_COMPRESS, "Compress heap");
|
||||||
{
|
MENU_ENTRY_ADD( " - %2d) %-18s", MHH_CLOSE, "Close heap");
|
||||||
if (argc >= 3 && !strcmp (argv[2], "-v"))
|
MENU_ENTRY_ADD( " - %2d) %-18s", MHH_END, "End heap");
|
||||||
return VER_Object_Print (stdout, VERD_VERBOSE);
|
MENU_ENTRY_ADD( " - %2d) %-18s\n", ALLOC_CHUNK, "Allocate chunk");
|
||||||
else
|
MENU_ENTRY_ADD( " - %2d) %-18s", WRITE_CHUNK, "Write chunk");
|
||||||
return VER_Object_Print (stdout, VERD_MINIMAL);
|
MENU_ENTRY_ADD( " - %2d) %-18s", READ_CHUNK, "Read chunk");
|
||||||
} */
|
MENU_ENTRY_ADD( " - %2d) %-18s\n", FREE_CHUNK, "Free chunk");
|
||||||
else if (!strcmp (argv[1], "--create"))
|
MENU_ENTRY_ADD( " - %2d) %-18s", DSR_DUMP, "Dump DSR");
|
||||||
{
|
MENU_ENTRY_ADD( " - %2d) %-18s", ACR_DUMP, "Dump ACR");
|
||||||
if (SM_Library_Open (0, NULL, SMD_CREATE | SMD_DEBUG_ALL) != SMS_OK)
|
MENU_ENTRY_ADD( " - %2d) %-18s\n", FCR_DUMP, "Dump FCR");
|
||||||
{
|
|
||||||
fprintf (stderr, "=> Impossible de créer l'instance de la librairie LIBSHMEM\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (!strcmp (argv[1], "--destroy"))
|
|
||||||
{
|
|
||||||
if (SM_Library_Open (0, NULL, SMD_OPEN | SMD_DEBUG_ALL) != SMS_OK || SM_Library_Close (SMD_DESTROY) != SMS_OK)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "=> Impossible de détruire l'instance de la librairie LIBSHMEM\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf (stderr, USAGE, argv[0]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Lancement du menu intercatif */
|
|
||||||
|
|
||||||
init_menu ();
|
|
||||||
|
|
||||||
choice = print_menu ();
|
|
||||||
|
|
||||||
while (choice != QUIT)
|
|
||||||
{
|
|
||||||
strcpy (answer, "yes");
|
|
||||||
|
|
||||||
switch (choice)
|
|
||||||
{
|
|
||||||
case BASE_INIT:
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Library_Open (0, NULL, SMD_CREATE | SMD_DEBUG_ALL) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BASE_OPEN:
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Library_Open (0, NULL, SMD_OPEN | SMD_DEBUG_ALL) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BASE_END:
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Library_Close (SMD_DESTROY) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BASE_CLOSE:
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Library_Close (SMD_CLOSE) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BASE_INFO:
|
|
||||||
SM_Library_Dump (stderr);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MHH_INIT:
|
|
||||||
fprintf (stdout, "\nNew heap name ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
fprintf (stdout, "\nHeap segment size ? ");
|
|
||||||
fgets( tmp, NAME_SIZE, stdin);
|
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
|
||||||
|
|
||||||
size = atol (tmp);
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Heap_Open (name, &Heap, size, \
|
|
||||||
SMD_CREATE, &Locked) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MHH_OPEN:
|
|
||||||
fprintf (stdout, "\nHeap name to open ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
fprintf (stdout, "\nOpening mode (read=1 write=2) ? ");
|
|
||||||
fgets( tmp, TMP_SIZE, stdin);
|
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
|
||||||
|
|
||||||
if (tmp[0] == '1') Mode = SMD_READ;
|
|
||||||
else Mode = SMD_WRITE;
|
|
||||||
if (!strcmp (name, HEAP_SYSTEM))
|
|
||||||
{
|
|
||||||
fprintf (stdout, \
|
|
||||||
"\n*** Warning : you can not make this operation on the system heap ***\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", SM_Heap_Open (name, \
|
|
||||||
&Heap, 0, SMD_OPEN | Mode, &Locked) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MHH_COMPRESS:
|
|
||||||
fprintf (stdout, "\nHeap name à compresser ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
|
||||||
{
|
|
||||||
size_t Compress;
|
|
||||||
SM_Heap_Compress (Heap, &Compress);
|
|
||||||
fprintf (stdout, "\nCompression size = %d byte(s)\n", (int)Compress);
|
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MHH_END:
|
|
||||||
fprintf (stdout, "\nHeap name to remove ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
if (!strcmp (name, HEAP_SYSTEM))
|
|
||||||
{
|
|
||||||
fprintf (stdout, \
|
|
||||||
"\n*** Warning : you can not make this operation on the system heap ***\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Heap_End (name) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MHH_CLOSE:
|
|
||||||
fprintf (stdout, "\nHeap name to close ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
if (!strcmp (name, HEAP_SYSTEM))
|
|
||||||
{
|
|
||||||
fprintf (stdout, \
|
|
||||||
"\n*** Warning : you can not make this operation on the system heap ***\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (SM_Heap_IsOpen (name, &Heap) == SMS_OK)
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Heap_Close (Heap) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
else
|
|
||||||
fprintf (stdout, "\nHeap %s is not opened\n", name);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MHH_CHECK:
|
|
||||||
fprintf (stdout, "\nHeap name to check/recover ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
|
||||||
{
|
|
||||||
Nb_Detected = Nb_Corrected = 0;
|
|
||||||
SM_Heap_Check (Heap, &Nb_Detected, &Nb_Corrected, stderr);
|
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ALLOC_CHUNK:
|
|
||||||
fprintf (stdout, "\nHeap name ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
fprintf (stdout, "\nAllocation size ? ");
|
|
||||||
fgets( tmp, TMP_SIZE, stdin);
|
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
|
||||||
|
|
||||||
size = atol (tmp);
|
|
||||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
|
||||||
{
|
|
||||||
SM_Chunk_Alloc (Heap, size, &ptr);
|
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
|
||||||
}
|
|
||||||
fprintf (stdout, "\nAddress = 0x%p (%lu)\n", ptr, ptr);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WRITE_CHUNK:
|
|
||||||
fprintf (stdout, "\nAddress ? ");
|
|
||||||
fgets( tmp, TMP_SIZE, stdin);
|
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
|
||||||
|
|
||||||
ptr = (void *)atol (tmp);
|
|
||||||
fprintf (stdout, "\nString to put in ? ");
|
|
||||||
fgets( tmp, TMP_SIZE, stdin);
|
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
|
||||||
|
|
||||||
strcpy ( (char *)ptr, tmp);
|
|
||||||
fprintf (stdout, "\nOK\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case READ_CHUNK:
|
|
||||||
fprintf (stdout, "\nAddress ? ");
|
|
||||||
fgets( tmp, TMP_SIZE, stdin);
|
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
|
||||||
|
|
||||||
ptr = (void *)atol (tmp);
|
|
||||||
fprintf (stdout, "\nValeur du pointeur = %s\n", (char *)ptr);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FREE_CHUNK:
|
|
||||||
fprintf (stdout, "\nHeap name ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
fprintf (stdout, "\nAddress ? ");
|
|
||||||
fgets( tmp, TMP_SIZE, stdin);
|
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
|
||||||
|
|
||||||
ptr = (void *)atol (tmp);
|
|
||||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
|
||||||
{
|
|
||||||
fprintf (stdout, "\nReturn code = %s\n", \
|
|
||||||
SM_Chunk_Free (Heap, ptr) == SMS_OK ? "OK" : "NOK" );
|
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DSR_DUMP:
|
|
||||||
fprintf (stdout, "\nHeap name ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
|
||||||
{
|
|
||||||
ND_DataStruct_Info_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
|
||||||
ND_DataStruct_Value_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACR_DUMP:
|
|
||||||
fprintf (stdout, "\nHeap name ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
|
||||||
{
|
|
||||||
ND_DataStruct_Info_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
|
||||||
ND_DataStruct_Value_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FCR_DUMP:
|
|
||||||
fprintf (stdout, "\nHeap name ? ");
|
|
||||||
fgets( name, NAME_SIZE, stdin);
|
|
||||||
name[ strlen( name) - 1] = '\0';
|
|
||||||
|
|
||||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
|
||||||
{
|
|
||||||
ND_DataStruct_Info_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
|
||||||
ND_DataStruct_Value_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QUIT:
|
|
||||||
fprintf (stdout, "\nExiting program ...\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
fprintf (stdout, "\nUndefined choice %d\n", choice);
|
|
||||||
}
|
|
||||||
choice = print_menu ();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_menu (void)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Print_Menu */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int Print_Menu( void)
|
||||||
{
|
{
|
||||||
sprintf (menu, "Menu :\n");
|
fprintf (stdout, "------------------------------------------------------\n%s", menu);
|
||||||
sprintf (tmp, " - %2d) %-18s\n", QUIT, "Quit"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s", BASE_INIT, "Init library"); strcat (menu, tmp);
|
tmp[0] = '\0';
|
||||||
sprintf (tmp, " - %2d) %-18s", BASE_OPEN, "Open library"); strcat (menu, tmp);
|
while( tmp[0] == '\0')
|
||||||
sprintf (tmp, " - %2d) %-18s\n", BASE_INFO, "Info library"); strcat (menu, tmp);
|
{
|
||||||
sprintf (tmp, " - %2d) %-18s", BASE_CLOSE, "Close library"); strcat (menu, tmp);
|
printf ("\nChoice ? ");
|
||||||
sprintf (tmp, " - %2d) %-18s", BASE_END, "End library"); strcat (menu, tmp);
|
fgets( tmp, TMP_SIZE, stdin);
|
||||||
sprintf (tmp, " - %2d) %-18s\n", MHH_INIT, "Init heap"); strcat (menu, tmp);
|
tmp[ strlen( tmp) - 1] = '\0';
|
||||||
sprintf (tmp, " - %2d) %-18s", MHH_OPEN, "Open heap"); strcat (menu, tmp);
|
}
|
||||||
sprintf (tmp, " - %2d) %-18s", MHH_CHECK, "Check/recover heap"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s\n", MHH_COMPRESS, "Compress heap"); strcat (menu, tmp);
|
return atoi( tmp);
|
||||||
sprintf (tmp, " - %2d) %-18s", MHH_CLOSE, "Close heap"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s", MHH_END, "End heap"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s\n", ALLOC_CHUNK, "Allocate chunk"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s", WRITE_CHUNK, "Write chunk"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s", READ_CHUNK, "Read chunk"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s\n", FREE_CHUNK, "Free chunk"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s", DSR_DUMP, "Dump DSR"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s", ACR_DUMP, "Dump ACR"); strcat (menu, tmp);
|
|
||||||
sprintf (tmp, " - %2d) %-18s\n", FCR_DUMP, "Dump FCR"); strcat (menu, tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int print_menu (void)
|
|
||||||
{
|
|
||||||
fprintf (stdout, "------------------------------------------------------\n%s", menu);
|
|
||||||
|
|
||||||
tmp[0] = '\0';
|
|
||||||
while (tmp[0] == '\0')
|
|
||||||
{
|
|
||||||
printf ("\nChoice ? ");
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Entry_Promp */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void Entry_Prompt( void *Out_Ptr, char *Prompt_Ptr, short Type)
|
||||||
|
{
|
||||||
|
static char tmp[ TMP_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
fprintf( stdout, "\n%s", Prompt_Ptr);
|
||||||
|
|
||||||
fgets( tmp, TMP_SIZE, stdin);
|
fgets( tmp, TMP_SIZE, stdin);
|
||||||
tmp[ strlen( tmp) - 1] = '\0';
|
tmp[ strlen( tmp) - 1] = '\0';
|
||||||
|
|
||||||
|
switch( Type)
|
||||||
|
{
|
||||||
|
case TYPE_NUMBER:
|
||||||
|
{
|
||||||
|
if( sscanf( tmp, "0x%lx", Out_Ptr) != 1)
|
||||||
|
{
|
||||||
|
if( sscanf( tmp, "%ld", Out_Ptr) != 1)
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nInvalid number\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return atoi (tmp);
|
case TYPE_STRING:
|
||||||
|
{
|
||||||
|
strcpy( ( char *)Out_Ptr, tmp);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* main */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int main( int argc, char **argv)
|
||||||
|
{
|
||||||
|
int choice;
|
||||||
|
char name[ NAME_SIZE];
|
||||||
|
int Mode, Locked;
|
||||||
|
void *ptr;
|
||||||
|
char answer[ 10];
|
||||||
|
SMT_Heap *Heap;
|
||||||
|
int Nb_Detected, Nb_Corrected;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
|
||||||
|
/* Lancement de commande d'administration */
|
||||||
|
|
||||||
|
if( argc >= 2)
|
||||||
|
{
|
||||||
|
if( !strcmp( argv[ 1], "--help"))
|
||||||
|
{
|
||||||
|
fprintf( stderr, USAGE, argv[ 0]);
|
||||||
|
return( -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* else if( !strcmp( argv[1], "--version"))
|
||||||
|
{
|
||||||
|
if( argc >= 3 && !strcmp( argv[2], "-v"))
|
||||||
|
return VER_Object_Print( stdout, VERD_VERBOSE);
|
||||||
|
else
|
||||||
|
return VER_Object_Print( stdout, VERD_MINIMAL);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if( !strcmp( argv[1], "--create"))
|
||||||
|
{
|
||||||
|
if( SM_Library_Open( 0, NULL, SMD_CREATE | SMD_DEBUG_ALL) != SMS_OK)
|
||||||
|
{
|
||||||
|
fprintf( stderr, "=> Impossible de créer l'instance de la librairie LIBSHMEM\n");
|
||||||
|
return( -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0);
|
||||||
|
}
|
||||||
|
else if( !strcmp( argv[1], "--destroy"))
|
||||||
|
{
|
||||||
|
if( SM_Library_Open( 0, NULL, SMD_OPEN | SMD_DEBUG_ALL) != SMS_OK || SM_Library_Close( SMD_DESTROY) != SMS_OK)
|
||||||
|
{
|
||||||
|
fprintf( stderr, "=> Impossible de détruire l'instance de la librairie LIBSHMEM\n");
|
||||||
|
return( -1);
|
||||||
|
}
|
||||||
|
return( 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf( stderr, USAGE, argv[ 0]);
|
||||||
|
return( -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Lancement du menu intercatif */
|
||||||
|
|
||||||
|
Init_Menu();
|
||||||
|
|
||||||
|
choice = Print_Menu();
|
||||||
|
|
||||||
|
while( choice != QUIT)
|
||||||
|
{
|
||||||
|
strcpy( answer, "yes");
|
||||||
|
|
||||||
|
switch( choice)
|
||||||
|
{
|
||||||
|
case BASE_INIT:
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Library_Open( 0, NULL, SMD_CREATE | SMD_DEBUG_ALL) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BASE_OPEN:
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Library_Open( 0, NULL, SMD_OPEN | SMD_DEBUG_ALL) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BASE_END:
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Library_Close( SMD_DESTROY) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BASE_CLOSE:
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Library_Close( SMD_CLOSE) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BASE_INFO:
|
||||||
|
{
|
||||||
|
SM_Library_Dump( stderr);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MHH_INIT:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
Entry_Prompt( &size, "Allocation size ? ", TYPE_NUMBER);
|
||||||
|
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Heap_Open( name, &Heap, size, SMD_CREATE, &Locked) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MHH_OPEN:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
Entry_Prompt( &size, "Opening mode( read=1 write=2) ? ", TYPE_NUMBER);
|
||||||
|
|
||||||
|
if( size == '1')
|
||||||
|
{
|
||||||
|
Mode = SMD_READ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Mode = SMD_WRITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !strcmp( name, HEAP_SYSTEM))
|
||||||
|
{
|
||||||
|
fprintf( stdout, \
|
||||||
|
"\n*** Warning : you can not make this operation on the system heap ***\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Heap_Open( name, &Heap, 0, SMD_OPEN | Mode, &Locked) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MHH_COMPRESS:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
if( SM_Heap_Open( name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||||
|
{
|
||||||
|
size_t Compress;
|
||||||
|
SM_Heap_Compress( Heap, &Compress);
|
||||||
|
fprintf( stdout, "\nCompression size = %d byte(s)\n", (int)Compress);
|
||||||
|
if( Locked == TRUE) SM_Heap_Unlock( Heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MHH_CHECK:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
if( SM_Heap_Open( name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||||
|
{
|
||||||
|
Nb_Detected = Nb_Corrected = 0;
|
||||||
|
SM_Heap_Check( Heap, &Nb_Detected, &Nb_Corrected, stderr);
|
||||||
|
if( Locked == TRUE) SM_Heap_Unlock( Heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MHH_CLOSE:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
if( !strcmp( name, HEAP_SYSTEM))
|
||||||
|
{
|
||||||
|
fprintf( stdout, \
|
||||||
|
"\n*** Warning : you can not make this operation on the system heap ***\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( SM_Heap_IsOpen( name, &Heap) == SMS_OK)
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Heap_Close( Heap) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nHeap %s is not opened\n", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MHH_END:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
if( !strcmp( name, HEAP_SYSTEM))
|
||||||
|
{
|
||||||
|
fprintf( stdout, \
|
||||||
|
"\n*** Warning : you can not make this operation on the system heap ***\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", SM_Heap_End( name) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ALLOC_CHUNK:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
Entry_Prompt( &size, "Allocation size ? ", TYPE_NUMBER);
|
||||||
|
|
||||||
|
if( SM_Heap_Open( name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||||
|
{
|
||||||
|
SM_Chunk_Alloc( Heap, size, &ptr);
|
||||||
|
if( Locked == TRUE) SM_Heap_Unlock( Heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf( stdout, "\nAddress = 0x%p( %lu)\n", ptr, ptr);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WRITE_CHUNK:
|
||||||
|
{
|
||||||
|
Entry_Prompt( &ptr, "Address ? ", TYPE_NUMBER);
|
||||||
|
Entry_Prompt( ptr, "String to put in ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
fprintf( stdout, "\nOK\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case READ_CHUNK:
|
||||||
|
{
|
||||||
|
Entry_Prompt( &ptr, "Address ? ", TYPE_NUMBER);
|
||||||
|
|
||||||
|
fprintf( stdout, "\nValeur du pointeur = %s\n",( char *)ptr);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case FREE_CHUNK:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
Entry_Prompt( &ptr, "Address ? ", TYPE_NUMBER);
|
||||||
|
|
||||||
|
if( SM_Heap_Open( name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nReturn code = %s\n", \
|
||||||
|
SM_Chunk_Free( Heap, ptr) == SMS_OK ? "OK" : "NOK" );
|
||||||
|
if( Locked == TRUE) SM_Heap_Unlock( Heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case DSR_DUMP:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
if( SM_Heap_Open( name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
||||||
|
{
|
||||||
|
ND_DataStruct_Info_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||||
|
ND_DataStruct_Value_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||||
|
if( Locked == TRUE) SM_Heap_Unlock( Heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ACR_DUMP:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
if( SM_Heap_Open( name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
||||||
|
{
|
||||||
|
ND_DataStruct_Info_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||||
|
ND_DataStruct_Value_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||||
|
if( Locked == TRUE) SM_Heap_Unlock( Heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case FCR_DUMP:
|
||||||
|
{
|
||||||
|
Entry_Prompt( name, "Heap name ? ", TYPE_STRING);
|
||||||
|
|
||||||
|
if( SM_Heap_Open( name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
||||||
|
{
|
||||||
|
ND_DataStruct_Info_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||||
|
ND_DataStruct_Value_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||||
|
if( Locked == TRUE) SM_Heap_Unlock( Heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QUIT:
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nExiting program ...\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
fprintf( stdout, "\nUndefined choice %d\n", choice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
choice = Print_Menu();
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user