gCAD3D 2.40
ut_mem.c File Reference

Memory manipulations: swap, insert, delete, invert .. More...

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "../ut/ut_geo.h"

Functions

int MEM_chg_str (char *datStart, long maxSiz, long delSiz, char *insDat)
 
int MEM_del_str (char *cp1, int sizDel)
 
int MEM_ins_str (int *s2Siz, char *s1, char *s2, int maxlen)
 
int MEM_get_file (char *txbuf, long *fSiz, char *fnam)
 
int MEM_wri_spc (char *fnam, char *data, long cNr)
 
int MEM_swap__ (void *stru1, void *stru2, long strSiz)
 
int MEM_swap_2bit (int *ii, int ib1, int ib2)
 
int MEM_ins_IndRec (int *iTab, int *recNr, int recPos, int reVal)
 
int MEM_ins_rec (void *insPos, long movSiz, void *insDat, long insSiz)
 
int MEM_ins_nrec (int *recNr, void *recTab, int ipos, void *insDat, int insRecNr, int sizRec)
 
int MEM_chg_rec (void *datStart, long *datSiz, void *insDat, long insSiz, void *delPos, long delSiz)
 
int MEM_del_IndRec (int *recNr, void *recTab, int ipos)
 
int MEM_del_DbRec (int *recNr, void *recTab, int ipos)
 
int MEM_del_ShRec (int *recNr, void *recTab, int ipos)
 
int MEM_del_nrec (int *recNr, void *recTab, int ipos, int delRecNr, int sizRec)
 
int MEM_inv_btab (int recNr, char *recTab)
 
int MEM_inv_itab (int recNr, int *recTab)
 
int MEM_inv_dtab (int recNr, double *recTab)
 
int MEM_inv_rtab (int recNr, void *recTab, int sizRec)
 
int MEM_copy_tab (void *tabo, void *tabi, int recNr, int sizRec)
 
int MEM_copy_oTab (void **poso, long *sizo, void **posi, int recNr, int sizRec)
 
int MEM_set_1recn (void *tabo, void *tabi, int recNr, int sizRec)
 

Detailed Description

Memory manipulations: swap, insert, delete, invert ..

=====================================================
List_functions_start:
MEM_alloc_tmp allocate mem for active function INLINE
MEM_ptr_mov move a pointer <dist> bytes INLINE
MEM_swap_int 2 int vertauschen
MEM_swap_2db 2 doubles vertauschen INLINE
MEM_swap_2vp swap 2 pointers INLINE
MEM_swap_2bit swap 2 bits
MEM_swap__ 2 structs vertauschen
MEM_chg_str change a part of a string in mem
MEM_ins_str insert s2 into s1 (s1 = s2 + s1)
MEM_ins_rec insert data into mem
MEM_ins_IndRec insert one integer into intArray
MEM_ins_nrec insert dataRecord(s) into table
MEM_chg_rec change a record in mem (change line; delete+insert)
MEM_del_str delete n chars out of string
MEM_del_IndRec delete 1 integer from intArray
MEM_del_DbRec delete 1 double in double-Array
MEM_del_ShRec delete 1 short in short-Array
MEM_del_nrec delete <delRecNr> records from table
MEM_inv_btab invert table of bytes; 1/2/3 --> 3/2/1
MEM_inv_itab invert table of intData; 1/2/3 --> 3/2/1
MEM_inv_dtab invert table of dbData; 1/2/3 --> 3/2/1
MEM_inv_rtab invert table of dataRecords; 1/2/3 --> 3/2/1
MEM_copy_tab copy <recNr> records of size <sizRec>
MEM_copy_oTab copy <recNr> records of size <sizRec>, set pointers
MEM_set_1recn write record <recNr> times
MEM_cmp__ compare memoryspaces (n bytes)
MEM_wri_spc write n chars from mem -> file
MEM_get_file read file -> mem
List_functions_end:
=====================================================
- see also:
memchr
memcmp
memccpy
memcpy
memmove
memset

Function Documentation

int MEM_chg_str ( char *  datStart,
long  maxSiz,
long  delSiz,
char *  insDat 
)
* MEM_chg_str change a part of a string in mem
*
* Input:
* datStart Startposition of string
* maxSiz max size of string starting at datStart
* delSiz how much bytes to delete at Pos datStart
* insDat data to insert (null-terminated) at datStart
*
* strcpy(cbuf, "1234567890");
* cp1 = strchr(cbuf, '5');
* il = sizeof(cbuf) - (cp1 - cbuf);
* MEM_chg_str (cp1, &il, 1, "AAA"); // 5 -> AAA
*
* see also MEM_chg_rec
*
int MEM_del_str ( char *  cp1,
int  sizDel 
)
* delete n chars out of string cp1 starting at pos cp1
* Input:
* cp1 startpos of string = startpos where to deleten
* ls nr of characters to delete
* Output:
* cp1
*
int MEM_ins_str ( int *  s2Siz,
char *  s1,
char *  s2,
int  maxlen 
)
int MEM_get_file ( char *  txbuf,
long *  fSiz,
char *  fnam 
)
* MEM_get_file read file -> mem
* Input:
* fSiz must have exact filesize; see OS_FilSiz.
* fnam file to copy -> txbuf
* Output:
* txbuf must have size *fSiz+1
* See UTX_str_file()
*
int MEM_wri_spc ( char *  fnam,
char *  data,
long  cNr 
)

MEM_wri_spc write n chars from mem -> file

int MEM_swap__ ( void *  stru1,
void *  stru2,
long  strSiz 
)
* MEM_swap__ 2 structs vertauschen
*
* MEM_swap__(&p1, &p2, sizeof(Point));
*
int MEM_swap_2bit ( int *  ii,
int  ib1,
int  ib2 
)

ib muessen Values sein (1, 2, 4, 8 usw.)

int MEM_ins_IndRec ( int *  iTab,
int *  recNr,
int  recPos,
int  reVal 
)
* insert one new record into indexTable at position recPos.
* Beispiel:
* In: recNr=3; iTab=0,1,2; recPos=0; reVal=3;
* Out: recNr=4; Tab=3,0,1,2;
*
int MEM_ins_rec ( void *  insPos,
long  movSiz,
void *  insDat,
long  insSiz 
)
* MEM_ins_rec insert data into mem
*
* insDat data to insert
* insSiz size of insDat
* insPos where to insert
* movSiz how much bytes to move from insPos to insPos+insSiz
*
int MEM_ins_nrec ( int *  recNr,
void *  recTab,
int  ipos,
void *  insDat,
int  insRecNr,
int  sizRec 
)
* insert records into table.
* insert data BEFORE Record with index ipos.
* insert dataBlock insDat BEFORE dataRecord Nr ipos into Table recTab
* recTab consists of *recNr records of size sizRec
*
* Input/Output:
* *recNr nr of records of table recTab;
* after exit recNr += insRecNr
* recTab table with *recNr records; each with a size of sizRec bytes.
* after exit record nr ipos is the firsdt record of insDat ..
*
* Input:
* ipos index in recTab of the first inserted record of insDat
* insDat data to insert; size = sizRec * insRecNr
* insRecNr nr of records to insert
* sizRec size of records (of recTab and insDat)
*
* Example insert 1 point p31 into 3. position (index nr 2) of pTab:
* MEM_ins_nrec (&recNr, pTab, 2, &p31, 1, sizeof(Point));
*
int MEM_chg_rec ( void *  datStart,
long *  datSiz,
void *  insDat,
long  insSiz,
void *  delPos,
long  delSiz 
)
* MEM_chg_rec change a record in mem (change line)
*
* Input:
* datStart Startposition des Datenblock
* datSiz Size Datenblock (zB ex strlen)
* insDat data to insert (len = insSiz)
* insSiz size of insDat
* delPos Position of old record (delete) and new record (insert)
* delSiz how much bytes to delete at Pos delPos
* Output:
* datSiz wird korrigiert
*
*
* strcpy(cbuf, "1234567890"); l1 = strlen(cbuf);
* MEM_chg_rec (cbuf, &l1, "AAA", 3, &cbuf[4], 1); // 5 -> AAA
*
* strcpy(cbuf, "1234567890"); l1 = strlen(cbuf);
* MEM_chg_rec (cbuf, &l1, "A", 1, &cbuf[4], 3); // 567 -> A
*
* see also MEM_chg_str
*
int MEM_del_IndRec ( int *  recNr,
void *  recTab,
int  ipos 
)
* MEM_del_IndRec delete 1 integer in intArray
* recNr is decremented
*
int MEM_del_DbRec ( int *  recNr,
void *  recTab,
int  ipos 
)
* MEM_del_DbRec delete 1 double in double-Array
* recNr is decremented
*
int MEM_del_ShRec ( int *  recNr,
void *  recTab,
int  ipos 
)
* MEM_del_ShRec delete 1 short in short-Array
* recNr is decremented
*
int MEM_del_nrec ( int *  recNr,
void *  recTab,
int  ipos,
int  delRecNr,
int  sizRec 
)
* delete <delRecNr> records from table.
* first Record to delete has index ipos.
* recTab consists of *recNr records of size sizRec
*
* Input/Output:
* *recNr nr of records of table recTab;
* after exit recNr -= delRecNr
* recTab table with *recNr records; each with a size of sizRec bytes.
*
* Input:
* ipos index in recTab of the first record to delete ..
* delRecNr nr of records to delete
* sizRec size of records of recTab
*
* Example delete the 3. point (index nr 2) out of pTab:
* MEM_del_nrec (&pNr, pTab, 2, 1, sizeof(Point));
*
int MEM_inv_btab ( int  recNr,
char *  recTab 
)

MEM_inv_btab invert table of bytes; 1/2/3 –> 3/2/1

int MEM_inv_itab ( int  recNr,
int *  recTab 
)

MEM_inv_itab invert table of intData; 1/2/3 –> 3/2/1

int MEM_inv_dtab ( int  recNr,
double *  recTab 
)

MEM_inv_dtab invert table of dbData; 1/2/3 –> 3/2/1

int MEM_inv_rtab ( int  recNr,
void *  recTab,
int  sizRec 
)
* MEM_inv_rtab invert table of dataRecords; 1/2/3 --> 3/2/1
* Example: invert table of <iptNr> Point's
* MEM_inv_rtab (iptNr, pTab, sizeof(Point));
*
int MEM_copy_tab ( void *  tabo,
void *  tabi,
int  recNr,
int  sizRec 
)

MEM_copy_tab copy <recNr> records of size <sizRec> Input: tabi: <recNr> records; each has size <sizRec>

int MEM_copy_oTab ( void **  poso,
long *  sizo,
void **  posi,
int  recNr,
int  sizRec 
)
* copy <recNr> records of size <sizRec> from <posi> to <poso>;
* reduce sizo and update <poso>
* poso pointer to next free position; is updated
* sizo size of free space in poso; is reduced
* posi pointer to data to be copied; is changed to new position poso !
* see also MEM_copy_tab
*
int MEM_set_1recn ( void *  tabo,
void *  tabi,
int  recNr,
int  sizRec 
)

MEM_set_1recn write record <recNr> times Input: tabi: one record of size <sizRec>