~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to incl/buffer.h

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)buffer.h 19.1 (ESO-IPG) 02/25/03 13:49:26 */
 
2
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
3
.TYPE           Header
 
4
.NAME           buffer.h
 
5
.LANGUAGE       C
 
6
.AUTHOR         Francois Ochsenbein [ESO-IPG]
 
7
.CATEGORY       Buffer, Stack
 
8
.COMMENTS       Automatic processing of buffers.
 
9
.ENVIRONMENT
 
10
.VERSION 1.0    23-Jun-1986: Extracted from STESODEF.
 
11
.VERSION 2.0    15-Apr-1988: Changed Names
 
12
.VERSION 2.1    07-Apr-1989: Added BUF_SaveString
 
13
------------------------------------------------------------*/
 
14
 
 
15
#ifndef BUFFER_DEF
 
16
#define BUFFER_DEF      0
 
17
 
 
18
#ifndef _TEMPLATES_
 
19
#include <compiler.h>
 
20
#endif
 
21
 
 
22
/*===========================================================================
 
23
 *              BUFFER Structure
 
24
 *===========================================================================*/
 
25
 
 
26
typedef struct BUFFER_struct {
 
27
        char    *buf;           /* Position of buffer in memory         */
 
28
        int     allocated;      /* Presently available memory           */
 
29
        int     increment;      /* Increment unit for expansion         */
 
30
        int     used;           /* Presently used memory                */
 
31
        int     offset;         /* For "locate" or stacking facilities  */
 
32
    } BUFFER;
 
33
#define NULL_BUFFER             (BUFFER *)0
 
34
 
 
35
#if _TEMPLATES_
 
36
/*===========================================================================
 
37
 *              Function Templates
 
38
 *===========================================================================*/
 
39
BUFFER  *mm_bopen       (int size, int increment);
 
40
int     mm_bfree        (BUFFER *b);
 
41
int     mm_bexp         (BUFFER *b, int new_size);
 
42
char    *mm_bst         (BUFFER *b, char *record, int record_len);  /* Stack */
 
43
char    *mm_bunst       (BUFFER *b);                              /* Unstack */
 
44
char    *mm_bapp        (BUFFER *b, char *record, int length);    /* Append  */
 
45
char    *mm_ball        (BUFFER *b, int length);                 /* Allocate */
 
46
char    *mm_zfree       (BUFFER *b, int index, int item_len);   /* Free Item */
 
47
char    *mm_zindex      (BUFFER *b, int index, int item_len);   /* Find Item */
 
48
char    *mm_zloc        (BUFFER *b, int item_len);         /* Find Free Item */
 
49
 
 
50
#else
 
51
BUFFER  *mm_bopen();
 
52
char    *mm_ball(), *mm_bapp();
 
53
char    *mm_bst(), *mm_bunst();
 
54
char    *mm_zfree(), *mm_zindex(), *mm_zloc();
 
55
#endif
 
56
 
 
57
/*======================================================================*
 
58
 *              Macros dealing with Buffers
 
59
 *======================================================================*/
 
60
 
 
61
#define BUF_Init(type, incr)            {(char *)0, 0, sizeof(type)*incr, 0, 0}
 
62
#define BUF_Open(type, n, incr)         mm_bopen(sizeof(type)*(n), \
 
63
                                                sizeof(type)*incr)
 
64
#define BUF_Expand(b, type, n)          mm_bexp(b, sizeof(type)*n)
 
65
#define BUF_Close(b)                    mm_bfree(b)                     
 
66
#define BUF_Clear(b)                    (b)->used = 0, (b)->offset = 0
 
67
 
 
68
#define BUF_AllocateItems(b, type, n)   (type *)mm_ball(b, sizeof(type)*(n))
 
69
#define BUF_AllocateItem(b, type)       BUF_AllocateItems(b,type,1)
 
70
 
 
71
#define BUF_AppendItems(b, type, a, n)  (type *)mm_bapp(b, (char *)a, \
 
72
                                                sizeof(type)*(n))
 
73
#define BUF_AppendItem(b, type, a)      BUF_AppendItems(b,type,a,1)
 
74
#define BUF_AppendString(b, s)          BUF_AppendItems(b, char, s, strlen(s))
 
75
#define BUF_SaveString(b, s)            BUF_AppendItems(b, char, s, 1+strlen(s))
 
76
 
 
77
#define BUF_StackItem(b, type, a)       (type *)mm_bst(b, (char *)a, \
 
78
                                                sizeof(type))
 
79
#define BUF_StackString(b, s)           mm_bst(b, s, strlen(s))
 
80
 
 
81
#define BUF_UnstackItem(b, type)        (type *)mm_bunst(b)
 
82
#define BUF_Unstack(b)                  mm_bunst(b)
 
83
 
 
84
#define BUF_ItemPosition(b, type)       (type *)((b)->buf + (b)->offset)
 
85
#define BUF_Items(b,type)               ((b)->used - (b)->offset)/sizeof(type)
 
86
 
 
87
/*======================================================================*
 
88
 *              Macros dealing with SETs (arrays of structures)
 
89
 *======================================================================*/
 
90
 
 
91
#define SET_Init(type, incr)            BUF_Init(type, incr)
 
92
#define SET_Open(type, n, incr)         BUF_Open(type, n, incr)
 
93
#define SET_Close(b)                    BUF_Close(b)                    
 
94
 
 
95
#define SET_FindItem(b, type, i)        (type *)mm_zindex(b, i, sizeof(type))
 
96
#define SET_FreeItem(b, type, i)        (type *)mm_zfree(b, i, sizeof(type))
 
97
#define SET_FindFreeItem(b, type)       (type *)mm_zloc(b, sizeof(type))
 
98
 
 
99
#define SET_Item(b, type)               ((b)->offset / sizeof(type))
 
100
#define SET_Items(b, type)              ((b)->used   / sizeof(type))
 
101
 
 
102
#define SET_FirstItem(b, type)          (type *)((b)->buf)
 
103
#define SET_EndItem(b, type)            (type *)((b)->buf + (b)->used)
 
104
#define SET_LastItem(b, type)           (type *)((b)->buf + (b)->used - sizeof(type))
 
105
 
 
106
#endif