-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.h
105 lines (95 loc) · 3.22 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//@+leo-ver=4-thin
//@+node:leonardoce.20090629082550.192:@thin utils.h
//@@language c
#ifndef __UTILS_H
#define __UTILS_H
#define TRUE 1
#define FALSE 0
#define stricmp strcasecmp
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)>(y)?(x):(y))
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//@+others
//@+node:leonardoce.20090629082550.195:Asserzioni
/****f* framework/F_ASSERT
* NAME
* F_ASSERT
* FUNCTION
* Macro per il controllo delle asserzioni. Se la condizione passata fallisce
* viene riportato un errore indicando il nome del file sorgente e il numero
* di riga.
* EXAMPLE
* F_ASSERT(1!=3);
* SOURCE
*/
#define F_ASSERT(cond) Framework_Assert((cond), __FILE__, __LINE__)
void Framework_Assert(int condition, const char *fileName, int line);
/****/
//@-node:leonardoce.20090629082550.195:Asserzioni
//@+node:leonardoce.20090629082550.206:InputStream
typedef struct InputStream InputStream;
struct InputStream {
void *buffer;
int bufferLen;
int ptr;
};
InputStream *InputStream_NewForBuffer(void *buffer, int bufferLen);
InputStream *InputStream_NewForFile(const char *nomeFile);
ForthCell InputStream_ReadInt(InputStream *self);
int InputStream_Read(InputStream *self, void *buffer, int bufferLen);
void InputStream_Delete(InputStream *self);
int InputStream_Eof(InputStream *self);
char InputStream_ReadByte(InputStream *self);
//@nonl
//@-node:leonardoce.20090629082550.206:InputStream
//@+node:leonardoce.20090629082550.197:OutputStream
typedef struct OutputStream OutputStream;
struct OutputStream {
FILE *out;
};
OutputStream *OutputStream_NewForFile(const char *fileName);
void OutputStream_Write(OutputStream *self, void *buffer, int len);
void OutputStream_WriteInt(OutputStream *self, ForthCell i);
int OutputStream_Status(OutputStream *self);
void OutputStream_Delete(OutputStream *self);
void OutputStream_WriteString(OutputStream *self, const char *str);
//@nonl
//@-node:leonardoce.20090629082550.197:OutputStream
//@+node:leonardoce.20090629082550.196:DynamicVector
/****c* framework/DynamicVector
* NAME
* DynamicVector
* FUNCTION
* Implementa un vettore dinamico che contiene elementi di tipo (void *).
* NOTES
* Il buffer degli elementi e' tenuto in "elements" mentre "bufferSize" specifica
* la sua dimensione in elementi.
* "elementsCount" invece e' il numero di elementi fisicamente occupati.
* All'inizio il vettore ha posto per 10 elementi.
* Gli elementi, inizialmente e nelle nuove allocazioni, sono posti a NULL.
* SOURCE
*/
typedef struct DynamicVector DynamicVector;
struct DynamicVector {
void **elements;
int elementsCount;
int bufferSize;
};
DynamicVector *DynamicVector_New();
void DynamicVector_Delete(DynamicVector *self);
void *DynamicVector_Get(DynamicVector *self, int indexId);
void DynamicVector_Set(DynamicVector *self, int indexId, void *value);
void DynamicVector_SetCount(DynamicVector *self, int count);
int DynamicVector_Count(DynamicVector *self);
void DynamicVector_Append(DynamicVector *self, void *element);
void DynamicVector_Dump(DynamicVector *self);
void DynamicVector_Test();
/****/
//@-node:leonardoce.20090629082550.196:DynamicVector
//@-others
#endif
//@-node:leonardoce.20090629082550.192:@thin utils.h
//@-leo