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 (200 lines) | stat: -rwxr-xr-x 5,715 bytes parent folder | download | duplicates (2)
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

#############################################################################
##
## 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_info_what <- "typedef struct H5O_info_t \\{.*\\} H5O_info_t;"

H5Opublic_info_replace  <- "typedef struct H5O_info_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_info_t;"
fileReplace(H5Opublic_file, H5Opublic_info_what, H5Opublic_info_replace)

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


H5Lpublic_file <- "src_nocomments/H5Lpublic.h.nocomments"
H5Lpublic_what <- "typedef struct \\{.*\\} H5L_info_t;"
H5Lpublic_replace <- "typedef struct H5L_info_t {
    H5L_type_t          type;           
    hbool_t             corder_valid;   
    int64_t             corder;         
    H5T_cset_t          cset;           
    H5L_info_helper_t u;
} H5L_info_t;"
fileReplace(H5Lpublic_file, H5Lpublic_what, H5Lpublic_replace)


################################
### 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 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, "")