include directive paths problem fix 2

This commit is contained in:
Rob1103 2023-04-05 19:26:29 +02:00
parent f460bc7f1a
commit 6768e1d930

View file

@ -156,11 +156,11 @@ var srcLanguages = map[string]int{
".c": 0, ".c": 0,
".cpp": 0, ".cpp": 0,
".cc": 0, ".cc": 0,
".S": 0, //".S": 0,
".s": 0, //".s": 0,
".asm": 0, //".asm": 0,
".py": 0, //".py": 0,
".go": 0, //".go": 0,
} }
func filterSourcesFiles(sourceFiles []string) []string { func filterSourcesFiles(sourceFiles []string) []string {
@ -176,9 +176,10 @@ func filterSourcesFiles(sourceFiles []string) []string {
return filterSrcFiles return filterSrcFiles
} }
// conformIncDirAndCopyFile conforms all the include directives from a C/C++ source file so that no // conformIncDirAndCopyFile conforms all the user-defined include directives from a C/C++ source
// directive contains a path to a header file but the header file name only (i.e., the last element // file so that none of these directives contains a path to a header file but the header file name
// of the path). It also copies the content of the source file in the same way as CopyFileContents. // only (i.e., the last element of the path). It also copies the content of the source file in the
// same way as CopyFileContents.
// //
// It returns an error if any, otherwise it returns nil. // It returns an error if any, otherwise it returns nil.
func conformIncDirAndCopyFile(sourcePath, destPath string) (err error) { func conformIncDirAndCopyFile(sourcePath, destPath string) (err error) {
@ -188,20 +189,20 @@ func conformIncDirAndCopyFile(sourcePath, destPath string) (err error) {
return err return err
} }
// Find include directives using regexp // Find user-defined include directives using regexp
var re = regexp.MustCompile(`(.*)(#include)(.*)(<|")(.*)(>|")(.*)`) var re = regexp.MustCompile(`(.*)(#include)(.*)(")(.*)(")(.*)`)
for index := range fileLines { for index := range fileLines {
for _, match := range re.FindAllStringSubmatch(fileLines[index], -1) { for _, match := range re.FindAllStringSubmatch(fileLines[index], -1) {
// Only interested in include directives containing a path to a header file // Only interested in user-defined directives containing a path to a header file
if !strings.Contains(match[0], "/") { if !strings.Contains(match[0], "/") {
continue continue
} }
// Replace the path by its last element // Replace the path by its last element
for i := 1; i < len(match); i++ { for i := 1; i < len(match); i++ {
if match[i] == "<" || match[i] == "\"" { if match[i] == "\"" {
match[i+1] = filepath.Base(match[i+1]) match[i+1] = filepath.Base(match[i+1])
fileLines[index] = strings.Join(match[1:], "") + "\n" fileLines[index] = strings.Join(match[1:], "") + "\n"
break break