[Freeciv-Dev] (PR#8652) Cleanup sys-includes
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8652 >
The attached script matches the used functions with the included files
and reports missing and unneeded includes. The attached patch fixes
the most obvious problems for common/ (the old one) and ai/.
Without objections I will apply the patch soon.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"The Internet is really just a series of bottlenecks
joined by high speed networks."
-- Sam Wilson
import sys, re, os, c_comment_striper
a='''
accept
bind
bindtextdomain
connect
dcgettext
dcngettext
gethostbyaddr
gethostbyname
gethostname
getpwuid
inet_addr
inet_aton
inet_ntoa
listen
localeconv
recvfrom
remove
select
sendto
setlocale
setsockopt
signal
socket
textdomain
'''
inc2func={}
inc2func["<assert.h>"]="assert"
inc2func["<math.h>"]="pow"
inc2func["<string.h>"]="memcpy,memmove,memset,"+"strcasecmp,strcat,strchr,strcmp,strcoll,strcpy,strerror,strlen,strncasecmp,strncmp,strspn,strstr,strtok"
inc2func["<stdio.h>"]="sprintf,sscanf,vfprintf,vsnprintf,fopen,fclose,printf,fprintf,fscanf,fcntl,fdopen,feof,ferror,fflush,fgets,fwrite,printf,putchar,puts,remove"
inc2func["<unistd.h>"]="read,write,usleep,close,geteuid,getuid"
inc2func["<stdlib.h>"]="abort,exit,malloc,calloc,realloc,qsort,getenv"
inc2func["<time.h>"]="time,clock"
inc2func["<sys/time.h>"]="gettimeofday"
inc2func["<sys/types.h>"]="opendir,readdir,closedir"
inc2func["<dirent.h>"]="opendir,readdir,closedir"
inc2func["<stdarg.h>"]="my_vsnprintf"
inc2func['"mem.h"']="free" # Really in stdlib.h but mem.h includes it
inc2func['"log.h"']="freelog"
inc2func['"map.h"']="map_get_city"
for i in inc2func.keys():
inc2func[i]=inc2func[i].split(",")
def uniq(x):
a={}
for i in x:
a[i]=1
return a.keys()
for file in sys.stdin.readlines():
file=file[:-1]
(head, tail)=os.path.split(file)
actual_includes=[]
print file
for line in open(file).readlines():
mo=re.search('#include (["<].*[">])', line)
if mo:
actual_includes.append(mo.group(1))
if actual_includes:
actual_includes.remove("<config.h>")
#print actual_includes
content=open(file).read()
content=c_comment_striper.strip_c_comment(content)
required_includes=[]
for i in inc2func.keys():
for j in inc2func[i]:
t=" "+j+"("
if content.find(t)!=-1:
required_includes.append((i,j))
#print required_includes
for i in required_includes:
if i[0] not in actual_includes:
print " need %s because of %s"%i
compact_required_includes=map(lambda x:x[0],required_includes)
for i in actual_includes:
if i not in compact_required_includes:
if i[0]=='<':
print " %s isn't needed"%i
Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.19
diff -u -u -r1.19 advdiplomacy.c
--- ai/advdiplomacy.c 10 Apr 2004 01:40:16 -0000 1.19
+++ ai/advdiplomacy.c 2 May 2004 11:42:17 -0000
@@ -16,9 +16,6 @@
#endif
#include <assert.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include "aisupport.h"
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.106
diff -u -u -r1.106 advdomestic.c
--- ai/advdomestic.c 25 Feb 2004 20:23:49 -0000 1.106
+++ ai/advdomestic.c 2 May 2004 11:42:17 -0000
@@ -15,7 +15,6 @@
#include <config.h>
#endif
-#include <stdio.h>
#include <string.h>
#include "city.h"
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.164
diff -u -u -r1.164 advmilitary.c
--- ai/advmilitary.c 29 Apr 2004 19:59:21 -0000 1.164
+++ ai/advmilitary.c 2 May 2004 11:42:18 -0000
@@ -15,7 +15,7 @@
#include <config.h>
#endif
-#include <stdio.h>
+#include <assert.h>
#include <string.h>
#include "combat.h"
Index: ai/aiair.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiair.c,v
retrieving revision 1.24
diff -u -u -r1.24 aiair.c
--- ai/aiair.c 25 Feb 2004 20:23:49 -0000 1.24
+++ ai/aiair.c 2 May 2004 11:42:18 -0000
@@ -15,6 +15,8 @@
#include <config.h>
#endif
+#include <assert.h>
+
#include "combat.h"
#include "log.h"
#include "map.h"
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.150
diff -u -u -r1.150 aicity.c
--- ai/aicity.c 22 Apr 2004 23:07:07 -0000 1.150
+++ ai/aicity.c 2 May 2004 11:42:19 -0000
@@ -16,8 +16,6 @@
#endif
#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include "city.h"
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.24
diff -u -u -r1.24 aidata.c
--- ai/aidata.c 1 May 2004 03:22:11 -0000 1.24
+++ ai/aidata.c 2 May 2004 11:42:19 -0000
@@ -15,9 +15,6 @@
#include <config.h>
#endif
-#include <stdio.h>
-#include <string.h>
-
#include "aisupport.h"
#include "city.h"
#include "game.h"
Index: ai/aidiplomat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidiplomat.c,v
retrieving revision 1.33
diff -u -u -r1.33 aidiplomat.c
--- ai/aidiplomat.c 25 Feb 2004 20:23:49 -0000 1.33
+++ ai/aidiplomat.c 2 May 2004 11:42:19 -0000
@@ -16,9 +16,6 @@
#endif
#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "city.h"
#include "combat.h"
Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.87
diff -u -u -r1.87 aihand.c
--- ai/aihand.c 20 Sep 2003 19:24:54 -0000 1.87
+++ ai/aihand.c 2 May 2004 11:42:19 -0000
@@ -15,9 +15,7 @@
#include <config.h>
#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <assert.h>
#include "city.h"
#include "game.h"
Index: ai/aihunt.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihunt.c,v
retrieving revision 1.2
diff -u -u -r1.2 aihunt.c
--- ai/aihunt.c 1 May 2004 03:31:44 -0000 1.2
+++ ai/aihunt.c 2 May 2004 11:42:20 -0000
@@ -15,6 +15,8 @@
#include <config.h>
#endif
+#include <assert.h>
+
#include "city.h"
#include "combat.h"
#include "game.h"
Index: ai/aitech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitech.c,v
retrieving revision 1.43
diff -u -u -r1.43 aitech.c
--- ai/aitech.c 14 Feb 2004 02:21:25 -0000 1.43
+++ ai/aitech.c 2 May 2004 11:42:20 -0000
@@ -15,7 +15,6 @@
#include <config.h>
#endif
-#include <stdio.h>
#include <string.h>
#include "game.h"
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.102
diff -u -u -r1.102 aitools.c
--- ai/aitools.c 29 Apr 2004 19:59:21 -0000 1.102
+++ ai/aitools.c 2 May 2004 11:42:20 -0000
@@ -15,8 +15,7 @@
#include <config.h>
#endif
-#include <stdio.h>
-#include <stdlib.h>
+#include <assert.h>
#include "city.h"
#include "combat.h"
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.313
diff -u -u -r1.313 aiunit.c
--- ai/aiunit.c 2 May 2004 10:42:55 -0000 1.313
+++ ai/aiunit.c 2 May 2004 11:42:22 -0000
@@ -16,9 +16,7 @@
#endif
#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <math.h>
#include "city.h"
#include "combat.h"
Index: common/capability.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capability.c,v
retrieving revision 1.11
diff -u -u -r1.11 capability.c
--- common/capability.c 14 Nov 2002 09:15:01 -0000 1.11
+++ common/capability.c 2 May 2004 11:42:22 -0000
@@ -15,7 +15,6 @@
#include <config.h>
#endif
-#include <stdlib.h>
#include <string.h>
#include "shared.h" /* TRUE, FALSE */
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.164
diff -u -u -r1.164 capstr.c
--- common/capstr.c 14 Apr 2004 11:19:44 -0000 1.164
+++ common/capstr.c 2 May 2004 11:42:22 -0000
@@ -16,7 +16,6 @@
#endif
#include <stdlib.h> /* getenv() */
-#include <string.h>
#include "connection.h" /* MAX_LEN_CAPSTR */
#include "support.h"
Index: common/combat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/combat.c,v
retrieving revision 1.40
diff -u -u -r1.40 combat.c
--- common/combat.c 19 Apr 2004 12:17:15 -0000 1.40
+++ common/combat.c 2 May 2004 11:42:22 -0000
@@ -17,7 +17,6 @@
#include <assert.h>
#include <math.h>
-#include <stdio.h>
#include "log.h"
#include "map.h"
Index: common/connection.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/connection.c,v
retrieving revision 1.37
diff -u -u -r1.37 connection.c
--- common/connection.c 14 Jan 2004 11:58:12 -0000 1.37
+++ common/connection.c 2 May 2004 11:42:23 -0000
@@ -18,6 +18,7 @@
#include <assert.h>
#include <errno.h>
#include <string.h>
+#include <time.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
Index: common/diptreaty.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.c,v
retrieving revision 1.19
diff -u -u -r1.19 diptreaty.c
--- common/diptreaty.c 4 Nov 2003 10:21:56 -0000 1.19
+++ common/diptreaty.c 2 May 2004 11:42:23 -0000
@@ -15,9 +15,6 @@
#include <config.h>
#endif
-#include <stdio.h>
-#include <stdlib.h>
-
#include "game.h"
#include "log.h"
#include "mem.h"
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.4
diff -u -u -r1.4 effects.c
--- common/effects.c 28 Nov 2003 17:37:21 -0000 1.4
+++ common/effects.c 2 May 2004 11:42:23 -0000
@@ -15,7 +15,6 @@
#endif
#include <assert.h>
-#include <string.h>
#include "effects.h"
#include "game.h"
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.178
diff -u -u -r1.178 game.c
--- common/game.c 10 Apr 2004 23:05:51 -0000 1.178
+++ common/game.c 2 May 2004 11:42:23 -0000
@@ -16,9 +16,6 @@
#endif
#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "capstr.h"
#include "city.h"
Index: common/government.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.c,v
retrieving revision 1.41
diff -u -u -r1.41 government.c
--- common/government.c 30 Jun 2003 20:53:24 -0000 1.41
+++ common/government.c 2 May 2004 11:42:23 -0000
@@ -16,8 +16,6 @@
#endif
#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
#include "game.h"
#include "log.h"
Index: common/idex.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/idex.c,v
retrieving revision 1.10
diff -u -u -r1.10 idex.c
--- common/idex.c 11 Dec 2002 10:39:41 -0000 1.10
+++ common/idex.c 2 May 2004 11:42:23 -0000
@@ -33,7 +33,6 @@
#endif
#include <assert.h>
-#include <stdlib.h>
#include "city.h"
#include "hash.h"
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.36
diff -u -u -r1.36 improvement.c
--- common/improvement.c 25 Feb 2004 20:23:49 -0000 1.36
+++ common/improvement.c 2 May 2004 11:42:23 -0000
@@ -16,7 +16,6 @@
#endif
#include <assert.h>
-#include <string.h>
#include "game.h"
#include "log.h"
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.165
diff -u -u -r1.165 map.c
--- common/map.c 20 Apr 2004 20:10:37 -0000 1.165
+++ common/map.c 2 May 2004 11:42:24 -0000
@@ -16,9 +16,7 @@
#endif
#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <string.h> /* strlen */
#include "city.h"
#include "fcintl.h"
Index: common/nation.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.c,v
retrieving revision 1.37
diff -u -u -r1.37 nation.c
--- common/nation.c 15 Sep 2003 16:51:07 -0000 1.37
+++ common/nation.c 2 May 2004 11:42:24 -0000
@@ -20,8 +20,6 @@
#endif
#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
#include "fcintl.h"
#include "game.h"
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.137
diff -u -u -r1.137 player.c
--- common/player.c 25 Feb 2004 16:13:29 -0000 1.137
+++ common/player.c 2 May 2004 11:42:24 -0000
@@ -16,8 +16,6 @@
#endif
#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
#include "city.h"
#include "fcintl.h"
Index: common/registry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/registry.c,v
retrieving revision 1.61
diff -u -u -r1.61 registry.c
--- common/registry.c 16 Apr 2004 17:08:27 -0000 1.61
+++ common/registry.c 2 May 2004 11:42:25 -0000
@@ -150,7 +150,6 @@
#include <assert.h>
#include <stdarg.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.70
diff -u -u -r1.70 tech.c
--- common/tech.c 31 Jan 2004 17:52:41 -0000 1.70
+++ common/tech.c 2 May 2004 11:42:25 -0000
@@ -16,15 +16,15 @@
#endif
#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h> /* exit */
#include <string.h>
#include "fcintl.h"
#include "game.h"
#include "log.h"
+#include "mem.h" /* free */
#include "player.h"
-#include "shared.h" /* ARRAY_SIZE */
+#include "shared.h" /* ARRAY_SIZE */
#include "support.h"
#include "tech.h"
Index: common/terrain.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.c,v
retrieving revision 1.5
diff -u -u -r1.5 terrain.c
--- common/terrain.c 23 Feb 2004 05:31:20 -0000 1.5
+++ common/terrain.c 2 May 2004 11:42:25 -0000
@@ -15,7 +15,10 @@
#include <config.h>
#endif
+#include <assert.h>
+
#include "map.h"
+#include "mem.h" /* free */
#include "rand.h"
#include "shared.h"
#include "support.h"
Index: common/worklist.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/worklist.c,v
retrieving revision 1.17
diff -u -u -r1.17 worklist.c
--- common/worklist.c 29 Nov 2003 11:37:00 -0000 1.17
+++ common/worklist.c 2 May 2004 11:42:25 -0000
@@ -15,8 +15,6 @@
#include <config.h>
#endif
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include "city.h"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8652) Cleanup sys-includes,
Raimar Falke <=
|
|