summarylogtreecommitdiffstats
path: root/0011-Detect-GCC-include-directories.patch
blob: 195825ffd539f985bc067bca5bbf1b7f06906edd (plain)
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
From bb148b21408cea86a506d39bbd6bf094496f631b Mon Sep 17 00:00:00 2001
From: Sergei Litvin <litvindev@gmail.com>
Date: Fri, 20 Jan 2017 19:16:13 +0300
Subject: [PATCH 11/33] Detect GCC include directories

---
 src/main.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src/main.c b/src/main.c
index 2c4b27b..e18721a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2141,6 +2141,67 @@ void mainSetLanguage(char *inFileName, int *outLanguage) {
 	}
 }
 
+
+static int getLineFromFile(FILE *ff, char *tt, int ttsize, int *outI) {
+	int i,c,res;
+	i = 0;
+	c = getc(ff);
+	while ((c>=0 && c<=' ') || c=='\n' || c=='\t') c=getc(ff);
+	if (c==EOF) {
+	  res = EOF;
+	  goto fini;
+	}
+	while (c!=EOF && c!='\n') {
+	  if (i < ttsize-1)	  tt[i++]=c;
+	  c=getc(ff);
+	}
+	res = 'A';
+ fini:
+	tt[i] = 0;
+	*outI  = i;
+	return(res);
+}
+
+static void getAndProcessGccOptions() {
+	char tt[MAX_OPTION_LEN];
+	int len,c,isActiveSect;
+	char *ttt, *lang;
+	FILE *ff;
+	struct stat stt;
+	if (LANGUAGE(LAN_C) || LANGUAGE(LAN_YACC)) {
+	  lang = "c";
+	}
+	else if (LANGUAGE(LAN_CCC)) {
+	  lang = "c++";
+	}
+	else {
+	  return;
+	}
+	isActiveSect = 0;
+	ttt = crTmpFileName_st();
+	assert(strlen(ttt)+1 < MAX_FILE_NAME_SIZE);
+	sprintf(tmpBuff, "LANG=C cpp -v -x %s -o /dev/null /dev/null >%s 2>&1", lang, ttt);
+	system(tmpBuff);
+	ff = fopen(ttt,"r");
+	if (ff==NULL) return;
+	while (getLineFromFile(ff,tt,MAX_OPTION_LEN,&len) != EOF) {
+		if (strncmp(tt,"#include <...> search starts here:",34)==0) {
+			isActiveSect = 1;
+		}
+		else if (strncmp(tt,"End of search list.",19)==0) {
+			isActiveSect = 0;
+			break;
+		}
+		else if (	 isActiveSect
+					 && statb(tt,&stt) == 0
+					 && (stt.st_mode & S_IFMT) == S_IFDIR) {
+			mainAddStringListOption(&s_opt.includeDirs, tt);
+		}
+	}
+	fclose(ff);
+	removeFile(ttt);
+}
+
 void getAndProcessXrefrcOptions(char *dffname, char *dffsect,char *project) {
 	int dfargc; 
 	char **dfargv;
@@ -2232,6 +2293,7 @@ static void mainFileProcessingInitialisations(
 	struct stat 	dffstat;
 	char 			*fileName;
 	int				lc;
+	S_stringList	*tmpIncludeDirs;
 
 	fileName = s_input_file_name;
 	mainSetLanguage(fileName,  outLanguage);
@@ -2287,7 +2349,11 @@ static void mainFileProcessingInitialisations(
 		}
 		//& setPredefinedFileEnvVariables(fileName);
 		reInitCwd(dffname, dffsect);
+		tmpIncludeDirs = s_opt.includeDirs;
+		s_opt.includeDirs = NULL;
 		getAndProcessXrefrcOptions(dffname, dffsect, dffsect);
+		getAndProcessGccOptions();
+		LIST_APPEND(S_stringList, s_opt.includeDirs, tmpIncludeDirs);
 		if (s_opt.taskRegime != RegimeEditServer && s_input_file_name == NULL) {
 			*outInputIn = 0;
 			goto fini;
-- 
2.18.0