Skip to content

Commit

Permalink
fix issue with ".c" in folder name
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Marklund <[email protected]>
  • Loading branch information
trollkarlen committed May 9, 2023
1 parent 811a8b7 commit c518dcb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/c2v.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import strings
import json
import time
import toml
import regex

const version = '0.3.1'

Expand Down Expand Up @@ -321,6 +322,7 @@ fn (mut c C2V) fn_decl(mut node Node, gen_types string) {
vprintln('')
return
}

if c.is_dir && c.cur_file.ends_with('/info.c') {
// TODO tmp doom hack
return
Expand Down Expand Up @@ -2062,6 +2064,10 @@ fn main() {
eprintln(' c2v file.c')
eprintln(' c2v wrapper file.h')
eprintln(' c2v folder/')
eprintln('')
eprintln('args:')
eprintln(' -keep_ast keep ast files')
eprintln(' -print_tree print the entire tree')
exit(1)
}
vprintln(os.args.str())
Expand Down Expand Up @@ -2103,6 +2109,7 @@ fn (mut c2v C2V) translate_file(path string) {
mut lines := []string{}
mut ast_path := path
ext := os.file_ext(path)

if path.contains('/src/') {
// Hack to fix 'doomtype.h' file not found
// TODO come up with a better solution
Expand All @@ -2114,20 +2121,25 @@ fn (mut c2v C2V) translate_file(path string) {
cmd := '${clang} ${additional_clang_flags} -w -Xclang -ast-dump=json -fsyntax-only -fno-diagnostics-color -c ${os.quoted_path(path)}'
vprintln('DA CMD')
vprintln(cmd)
mut re := regex.regex_opt('${ext}$') or { panic(err) }
out_ast := if c2v.is_dir {
os.getwd() + '/' + (os.dir(os.dir(path)) + '/${c2v.project_output_dirname}/' +
os.base(path.replace(ext, '.json')))
os.base(re.replace(path, '.json')))
} else {
// file.c => file.json
path.replace(ext, '.json')
vprintln(path)
re.replace(path, '.json')
}
out_ast_dir := os.dir(out_ast)
if c2v.is_dir && !os.exists(out_ast_dir) {
os.mkdir(out_ast_dir) or { panic(err) }
}
vprintln('running in path: ${os.abs_path('.')}')
vprintln('EXT=${ext} out_ast=${out_ast}')
vprintln('out_ast=${out_ast}')
clang_result := os.system('${cmd} > ${out_ast}')
vprintln('${cmd} > "${out_ast}"')
clang_result := os.system('${cmd} > "${out_ast}"')
vprintln('${clang_result}')
if clang_result != 0 {
eprintln('\nThe file ${path} could not be parsed as a C source file.')
exit(1)
Expand Down

0 comments on commit c518dcb

Please sign in to comment.