-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomptime.c
More file actions
194 lines (151 loc) · 3.59 KB
/
Copy pathcomptime.c
File metadata and controls
194 lines (151 loc) · 3.59 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* -MODULE----------------------------------------------------------------------
RapidBATCH
Copyright (C) 2008, 2009 by Phorward Software Technologies, Jan Max Meyer
http://www.phorward-software.com ++ mail@phorward-software.com
File: comptime.c
Author: Jan Max Meyer
Usage: Compile-time functions
----------------------------------------------------------------------------- */
/*
* Includes
*/
#include "rb_global.h"
/*
* Global variables
*/
struct srcfile
{
char* filename; /* Name of file */
char* content; /* File content */
};
static struct srcfile* all_incl;
static unsigned int all_incl_cnt;
#define SRCFILE_MALLOC_STEP 16 /* Hold 16 files in line */
/*
* Functions
*/
/* Free up this module */
/* Execution function to include a file */
static int include_file( char* filename, pboolean once )
{
unsigned int i;
char* src = (char*)NULL;
struct srcfile* sf = (struct srcfile*)NULL;
PROC( "include_file" );
PARMS( "filename", "%s", filename );
PARMS( "once", "%d", once );
for( i = 0; i < all_incl_cnt; i++ )
{
if( strcmp( all_incl[ i ].filename, filename ) == 0 )
{
MSG( "This file has already been included... check" );
if( once )
{
MSG( "once flag set - no more include of this file!" );
RETURN( 0 );
}
sf = &( all_incl[ i ] );
break;
}
}
if( !sf )
{
MSG( "File has not been included yet, mapping now" );
if( !pfiletostr( &src, filename ) )
{
MSG( "Printing file-not-found error" );
/*
rb_error( rb_comp_cur_pos(),
"include_not_found", "filename", filename,
(char*)NULL );
*/
fprintf( stderr, "Include file not found: %s\n", filename );
RETURN( 0 ); /* Compiler gets: All right ;) */
}
/* Put this file into cache */
if( !all_incl )
{
MSG( "Allocating new array" );
all_incl = (struct srcfile*)pmalloc( ( SRCFILE_MALLOC_STEP )
* sizeof( struct srcfile ) );
}
else if( all_incl_cnt % SRCFILE_MALLOC_STEP == 0 )
{
MSG( "Extending existing array" );
all_incl = (struct srcfile*)prealloc( (struct srcfile*)all_incl,
( all_incl_cnt + SRCFILE_MALLOC_STEP )
* sizeof( struct srcfile ) );
}
if( !all_incl )
{
OUTOFMEM;
RETURN( 1 );
}
/* Save pointers */
sf = &( all_incl[ all_incl_cnt++ ] );
sf->content = src;
if( !( sf->filename = pstrdup( filename ) ) )
{
OUTOFMEM;
RETURN( 1 );
}
}
rb_comp_compile( sf->filename, sf->content );
/* Number of errors does not matter here */
RETURN( 0 );
}
/*
* RapidBATCH Functions
*/
RB_FCT( include )
{
/*RBAUTOIMPORT function include v comptime*/
/*RBDOC
%%function
include( file )
%%desc:en
TODO
%%desc:ge
TODO
%%parm:en
str Relative or absolute file path to the file to be included.
%%parm:ge
str Der relative oder absolute Dateipfad zur einzubindenden Datei.
%%return:en
%%return:ge
%%notice:en
%%notice:ge
RBDOC*/
char* filename;
PROC( "include" );
RB_FCT_DUMP_PARMS();
filename = RB_PARM_VAL_GET_STR( RB_FCT_PARM_ACCESS( 0 ) );
PARMS( "filename", "%s", filename );
RETURN( include_file( filename, FALSE ) );
}
RB_FCT( include_once )
{
/*RBAUTOIMPORT function include_once v comptime*/
/*RBDOC
%%function
include_once( file )
%%desc:en
TODO
%%desc:ge
TODO
%%parm:en
str Relative or absolute file path to the file to be included.
%%parm:ge
str Der relative oder absolute Dateipfad zur einzubindenden Datei.
%%return:en
%%return:ge
%%notice:en
%%notice:ge
RBDOC*/
char* filename;
PROC( "include_once" );
RB_FCT_DUMP_PARMS();
filename = RB_PARM_VAL_GET_STR( RB_FCT_PARM_ACCESS( 0 ) );
PARMS( "filename", "%s", filename );
RETURN( include_file( filename, TRUE ) );
}