File: FindAndReplace.R

package info (click to toggle)
r-cran-hdf5r 1.3.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,344 kB
  • sloc: ansic: 85,341; sh: 51; python: 32; makefile: 13
file content (263 lines) | stat: -rwxr-xr-x 7,894 bytes parent folder | download
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

#############################################################################
##
## Copyright 2016 Novartis Institutes for BioMedical Research Inc.
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
#############################################################################




## we replace nested struct definition by unnested ones
## the nested definitions are written into HelperStructs.h


fileReplace <- function(filename, what, replace, fixed=FALSE) {
    if(!file.exists(filename)) {
        stop(paste("File", filename, "does not exist"))
    }
    L <- readLines(filename)
    L <- paste(L, collapse="\n")

    ## collapse multiple spaces to single space
    replace <- paste(replace, collapse="\n")

    ## check if it can be found
    if(!grepl(what, L, fixed=fixed)) {
        stop(paste("In File:", filename, "\nCould not find:\n", what, "\n\nTo be replaced with:\n", replace))
    }

    L <- gsub(what, replace, L, fixed=fixed)
    cat(c(L, ""), file=filename, collapse="\n")
}

################################
### Replace H5F_info2_t
################################

H5Fpublic_what <- "typedef struct H5F_info2_t \\{.*\\} H5F_info2_t;"

H5Fpublic_replace <- "typedef struct H5F_info2_t {
    H5F_info2_super_t super;
    H5F_info2_free_t free;
    H5F_info2_sohm_t sohm;
} H5F_info2_t;"

H5Fpublic_file <- "src_nocomments/H5Fpublic.h.nocomments"
fileReplace(H5Fpublic_file, H5Fpublic_what, H5Fpublic_replace)


################################
### Replace H5F_info1_t
################################


H5Fpublic_what <- "typedef struct H5F_info1_t \\{.*\\} H5F_info1_t;"
H5Fpublic_replace <- "typedef struct H5F_info1_t {
    hsize_t		super_ext_size;	
    H5F_info1_helper_t sohm;
} H5F_info1_t;"
H5Fpublic_file <- "src_nocomments/H5Fpublic.h.nocomments"
fileReplace(H5Fpublic_file, H5Fpublic_what, H5Fpublic_replace)




################################
### Replace H5O_hdfr_info_t
################################


## do the same for the other 2 structs in H5Opublic.h.nocomments
H5Opublic_file <- "src_nocomments/H5Opublic.h.nocomments"
H5Opublic_hdr_info_what <- "typedef struct H5O_hdr_info_t \\{.*\\} H5O_hdr_info_t;"

H5Opublic_hdr_info_replace <- "typedef struct H5O_hdr_info_t {
    unsigned version;		
    unsigned nmesgs;		
    unsigned nchunks;		
    unsigned flags;             
    H5O_hdr_info_helper_space_t space;
    H5O_hdr_info_helper_msg_t  mesg;
} H5O_hdr_info_t;"
fileReplace(H5Opublic_file, H5Opublic_hdr_info_what, H5Opublic_hdr_info_replace)


################################
### Replace H5O_info_t
################################

H5Opublic_file <- "src_nocomments/H5Opublic.h.nocomments"
H5Opublic_native_info_what <- "typedef struct H5O_native_info_t \\{.*\\} H5O_native_info_t;"

H5Opublic_native_info_replace  <- "typedef struct H5O_native_info_t {
    H5O_hdr_info_t      hdr;            
    H5O_info_helper_t meta_size;
} H5O_native_info_t;"
fileReplace(H5Opublic_file, H5Opublic_native_info_what, H5Opublic_native_info_replace)


H5Opublic_info1_what <- "typedef struct H5O_info1_t \\{.*\\} H5O_info1_t;"

H5Opublic_info1_replace  <- "typedef struct H5O_info1_t {
    unsigned long       fileno;
    haddr_t             addr;
    H5O_type_t          type;
    unsigned            rc;
    time_t              atime;
    time_t              mtime;
    time_t              ctime;
    time_t              btime;
    hsize_t             num_attrs;
    H5O_hdr_info_t      hdr;
    H5O_info_helper_t meta_size;
} H5O_info1_t;"
fileReplace(H5Opublic_file, H5Opublic_info1_what, H5Opublic_info1_replace)

################################
### Replace H5L_info_t
################################

# note that this is very brittle; 
# we do it in this order as otherwise the regexp is too greedy
# and identifies the start of H5L_info2_t struct with the 
# end of H5L_info1_t struct and deletes too much of the file
H5Lpublic_info2_file <- "src_nocomments/H5Lpublic.h.nocomments"
H5Lpublic_info2_what <- "typedef struct {
    H5L_type_t          type;           
    hbool_t             corder_valid;   
    int64_t             corder;         
    H5T_cset_t          cset;           
    union {
        H5O_token_t     token;          
        size_t          val_size;       
    } u;
} H5L_info2_t;"
H5Lpublic_info2_replace <- "typedef struct H5L_info2_t {
    H5L_type_t          type;           
    hbool_t             corder_valid;   
    int64_t             corder;         
    H5T_cset_t          cset;           
    H5L_info2_helper_t u;
} H5L_info2_t;"
fileReplace(H5Lpublic_info2_file, H5Lpublic_info2_what, H5Lpublic_info2_replace, fixed=TRUE)

H5Lpublic_info1_file <- "src_nocomments/H5Lpublic.h.nocomments"
H5Lpublic_info1_what <- "typedef struct {
    H5L_type_t          type;           
    hbool_t             corder_valid;   
    int64_t             corder;         
    H5T_cset_t          cset;           
    union {
        haddr_t         address;        
        size_t          val_size;       
    } u;
} H5L_info1_t;"
H5Lpublic_info1_replace <- "typedef struct H5L_info1_t {
    H5L_type_t          type;           
    hbool_t             corder_valid;   
    int64_t             corder;         
    H5T_cset_t          cset;           
    H5L_info1_helper_t u;
} H5L_info1_t;"
fileReplace(H5Lpublic_info1_file, H5Lpublic_info1_what, H5Lpublic_info1_replace, fixed=TRUE)



################################
### Replace H5C_cache_incr_mode
################################


H5Cpublic_file <- "src_nocomments/H5Cpublic.h.nocomments"
H5Cpublic_what <- "enum H5C_cache_incr_mode
{
    H5C_incr__off,
    H5C_incr__threshold
};

enum H5C_cache_flash_incr_mode
{
     H5C_flash_incr__off,
     H5C_flash_incr__add_space
};

enum H5C_cache_decr_mode
{
    H5C_decr__off,
    H5C_decr__threshold,
    H5C_decr__age_out,
    H5C_decr__age_out_with_threshold
};"
H5Cpublic_replace <- "typedef enum H5C_cache_incr_mode
{
    H5C_incr__off,
    H5C_incr__threshold
} H5C_cache_incr_mode;

typedef enum H5C_cache_flash_incr_mode
{
     H5C_flash_incr__off,
     H5C_flash_incr__add_space
} H5C_cache_flash_incr_mode;

typedef enum H5C_cache_decr_mode
{
    H5C_decr__off,
    H5C_decr__threshold,
    H5C_decr__age_out,
    H5C_decr__age_out_with_threshold
} H5C_cache_decr_mode;"
fileReplace(H5Cpublic_file, H5Cpublic_what, H5Cpublic_replace, fixed=TRUE)



################################
### Replace H5Rpublic
################################


H5Rpublic_file <- "src_nocomments/H5Rpublic.h.nocomments"
H5Rpublic_what <- "typedef struct {
    union {
        uint8_t __data[H5R_REF_BUF_SIZE];       
        int64_t align;                          
    } u;
} H5R_ref_t;"
H5Rpublic_replace <- "typedef struct H5R_ref_t {
    H5R_ref_helper_t u;
} H5R_ref_t;"

fileReplace(H5Rpublic_file, H5Rpublic_what, H5Rpublic_replace, fixed=TRUE)



################################
### Replace H5FD_free_t
################################

## delete something in H5FD
H5FDpublic_file <- "src_nocomments/H5FDpublic.h.nocomments"
H5FDpublic_what <- "typedef struct H5FD_free_t \\{.*\\} H5FD_free_t;"
H5FDpublic_replace <- ""
fileReplace(H5FDpublic_file, H5FDpublic_what, H5FDpublic_replace)

################################
### Replace H5FD_file_image_callbacks_t
################################
H5FDpublic_what <- "typedef struct \\{.*\\} H5FD_file_image_callbacks_t;"
fileReplace(H5FDpublic_file, H5FDpublic_what, "")