# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

PIC_System.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <malloc.h>
00004 #include <string.h>
00005 #include <stdarg.h>
00006 
00007 #define PIC_ERRSIZE             256
00008 
00009 static unsigned long    PIC_Sys_MEM_Allocated;
00010 static unsigned long    PIC_Sys_MEM_NbAllocs;
00011 
00012 // ----------------------------------------------------------------------------------------------------------------------------------
00013 
00014 void *Pic_malloc(unsigned long size)
00015 {
00016         void    *mem;
00017         mem=malloc(size);
00018         if (mem) 
00019         {
00020                 PIC_Sys_MEM_Allocated+=size;
00021                 PIC_Sys_MEM_NbAllocs++;
00022         }
00023         return(mem);
00024 }
00025 // -----
00026 void *Pic_calloc(unsigned long count, unsigned long size)
00027 {
00028         void    *mem;
00029         mem=calloc(count,size);
00030         if (mem) 
00031         {
00032                 PIC_Sys_MEM_Allocated+=(size*count);
00033                 PIC_Sys_MEM_NbAllocs++;
00034         }
00035         return(mem);
00036 }
00037 // -----
00038 void Pic_free(void *memblock)
00039 {
00040         unsigned long   size;
00041         size=_msize(memblock);
00042         PIC_Sys_MEM_Allocated-=size;
00043         PIC_Sys_MEM_NbAllocs--;
00044         free(memblock);
00045 }
00046 // -----
00047 unsigned long Pic__msize(void *memblock)
00048 {
00049         return(_msize(memblock));
00050 }
00051 // -----
00052 unsigned long PIC_GetMemNbAllocs(void)
00053 {
00054         return(PIC_Sys_MEM_NbAllocs);
00055 }
00056 // -----
00057 unsigned long PIC_GetMemAllocated(void)
00058 {
00059         return(PIC_Sys_MEM_Allocated);
00060 }
00061 
00062 // ----------------------------------------------------------------------------------------------------------------------------------
00063 
00064 static unsigned char    PIC_ErrorFlag;
00065 static unsigned char    PIC_ErrorString[PIC_ERRSIZE];
00066 static unsigned char    PIC_Sys_FnctActive=0;
00067 static void                             (*PIC_Sys_Fnct)(void);
00068 
00069 void Pic_SetError(unsigned char *msg, ...)
00070 {
00071         unsigned char   curerr[PIC_ERRSIZE],olderr[PIC_ERRSIZE];
00072         va_list                 args;
00073 
00074         va_start(args,msg);
00075         vsprintf(curerr,msg,args);
00076         va_end(args);
00077         if ( (strlen(curerr)+strlen(PIC_ErrorString))>PIC_ERRSIZE ) return;
00078 
00079         if (PIC_ErrorFlag)
00080         {
00081                 strcpy(olderr,PIC_ErrorString);
00082                 sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
00083                 strcat(PIC_ErrorString,"\n");
00084                 strcat(PIC_ErrorString,olderr);
00085         }
00086         else
00087         {
00088                 sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
00089         }
00090         PIC_ErrorFlag++;
00091         if (PIC_Sys_FnctActive) PIC_Sys_Fnct();
00092         return;
00093 }
00094 // -----
00095 char* PIC_GetError(void)
00096 {
00097         return(PIC_ErrorString);
00098 }
00099 // -----
00100 unsigned char PIC_Error(void)
00101 {
00102         return(PIC_ErrorFlag);
00103 }
00104 // -----
00105 void PIC_ResetError(void)
00106 {
00107         strcpy(PIC_ErrorString,"");
00108         PIC_ErrorFlag=0;
00109 }
00110 // -----
00111 unsigned char PIC_OnErrorCall( void pFnct(void) )
00112 {
00113         if (pFnct)
00114         {
00115                 PIC_Sys_Fnct=pFnct;
00116                 PIC_Sys_FnctActive=1;
00117         }
00118         else
00119         {
00120                 PIC_Sys_FnctActive=0;
00121         }
00122         return(1);
00123 }
00124 
00125 // ----------------------------------------------------------------------------------------------------------------------------------
00126