-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarry-hpp.R
More file actions
70 lines (51 loc) · 1.56 KB
/
barry-hpp.R
File metadata and controls
70 lines (51 loc) · 1.56 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
line78 <- paste(rep("/", 78), collapse = "")
unfolder <- function(txt, rel = "include/barry/") {
heads <- which(grepl("^\\s*#include \"", txt))
if (!length(heads))
return(txt)
fns <- gsub("^[^\"]+\"|\"$", "", txt[heads])
head_start <- sprintf(
"/*%s\n%1$s//\n\n Start of -%%s-\n\n%s//\n%1$s*/\n\n",
line78,
line78
)
head_end <- sprintf(
"/*%s\n%1$s//\n\n End of -%%s-\n\n%s//\n%1$s*/\n\n",
line78,
line78
)
new_src <- txt
for (h in rev(1L:length(fns)))
{
loc <- heads[h]
fn <- paste0(rel, fns[h])
tmp_lines <- readLines(fn, warn = FALSE)
# Extracting relative path
sub_rel <- gsub("[^/]+$", "", fns[h])
tmp_lines <- unfolder(tmp_lines, rel = paste0(rel, "/", sub_rel))
# Getting the filename
new_src <- c(
new_src[1:(loc - 1)],
sprintf(head_start, fn),
tmp_lines,
sprintf(head_end, fn),
new_src[(loc + 1):length(new_src)]
)
}
return(new_src)
}
rel <- "include/barry/"
# Barry core
src <- readLines(paste0(rel, "barry.hpp"), warn = FALSE)
src_new <- unfolder(src, rel)
writeLines(src_new, "barry.hpp")
# # Geese core
# rel <- "include/barry/models/"
# src <- readLines(paste0(rel, "geese.hpp"), warn = FALSE)
# src_new <- unfolder(src, rel)
# writeLines(src_new, "geese.hpp")
# DEFM core
rel <- "include/barry/models/"
src <- readLines(paste0(rel, "defm.hpp"), warn = FALSE)
src_new <- unfolder(src, rel)
writeLines(src_new, "defm.hpp")