summaryrefslogtreecommitdiff
path: root/Build/source/texk/detex/detex-PATCHES/patch-04-kpathsea
blob: f30d6f81d1224fb5f8e65f9a936ad8fa4d39b716 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
diff -ur detex-2.8.orig/detex.l detex-2.8/detex.l
--- detex-2.8.orig/detex.l	2010-06-11 23:26:08.000000000 +0200
+++ detex-2.8/detex.l	2010-06-12 00:15:05.785339097 +0200
@@ -49,6 +49,23 @@
  */
 
 #include "detex.h"
+
+#ifdef KPATHSEA
+
+#include <c-auto.h>
+#include <kpathsea/c-auto.h>
+#include <kpathsea/config.h>
+#include <kpathsea/c-memstr.h>
+#include <kpathsea/c-pathmx.h>
+#include <kpathsea/c-std.h>
+#include <kpathsea/tex-file.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#else /* KPATHSEA */
+
 #ifdef HAVE_STRING_H
 #include <string.h>
 #define	index	strchr
@@ -59,10 +76,15 @@
 #ifndef MAXPATHLEN
 #include <sys/param.h>
 #endif
+#define PATH_MAX MAXPATHLEN
 #ifdef OS2
 #include <stdlib.h>
 #endif
 
+#endif /* KPATHSEA */
+
+#undef IGNORE
+
 #define	LaBEGIN		if (fLatex) BEGIN
 #define	IGNORE		if (fSpace && !fWord) putchar(' ')
 #define	SPACE		if (!fWord) putchar(' ')
@@ -77,7 +99,9 @@
 void IncludeFile(char *sbFile);
 void InputFile(char *sbFile);
 void SetEnvIgnore(const char *sbEnvList);
+#ifndef KPATHSEA
 void SetInputPaths(void);
+#endif
 void Warning(const char *sb1, const char *sb2); 
 int BeginEnv(const char *sbEnv);
 int EndEnv(const char *sbEnv);
@@ -85,6 +109,7 @@
 int SeparateList(char *sbList, char *rgsbList[] ,char chSep, int csbMax);
 FILE *TexOpen(char *sbFile);
 char *SafeMalloc(int cch, const char *sbMessage);
+#ifndef KPATHSEA
 char *getenv();
 #ifndef NO_MALLOC_DECL
 char	*malloc();
@@ -93,12 +118,16 @@
 void	yyless(int);
 void	OS2UsageExit(void);
 #endif
+#endif /* KPATHSEA */
 
 char	*rgsbEnvIgnore[MAXENVS];	/* list of environments ignored */
 char	*rgsbIncList[MAXINCLIST];	/* list of includeonly files */
 char	*rgsbInputPaths[MAXINPUTPATHS];	/* list of input paths in order */
 char	sbCurrentEnv[CCHMAXENV];	/* current environment being ignored */
 char	*sbProgName;			/* name we were invoked with */
+#ifndef NOFILE /* might be defined in <sys/param.h> */
+#define NOFILE 256
+#endif
 FILE	*rgfp[NOFILE+1];		/* stack of input/include files */
 int	cfp = 0;			/* count of files in stack */
 int	cOpenBrace = 0;			/* count of `{' in <LaMacro> and <LaMacro2> */
@@ -400,6 +429,9 @@
 	_splitpath (rgsbArgs[0], drive, dir, fname, ext);
 	sbProgName = strlwr(fname);
 #else
+#ifdef KPATHSEA
+	kpse_set_program_name (rgsbArgs[0], NULL);
+#endif
 	if ((sbProgName = rindex(rgsbArgs[0], '/')) != NULL)
 	    sbProgName++;
 	else
@@ -407,9 +439,11 @@
 #endif
 	if (strcmp("delatex",sbProgName) == 0)
 	    fLatex = 1;
-	
+
+#ifndef KPATHSEA
 	/* set rgsbInputPaths for use with TexOpen() */
 	SetInputPaths();
+#endif
 
 	/* process command line options */
 	while (iArgs < cArgs && *(pch = rgsbArgs[iArgs]) == CHOPT) {
@@ -644,7 +678,7 @@
 int
 InList(char *sbFile)
 {
-	char	*pch, sbBase[MAXPATHLEN];
+	char	*pch, sbBase[PATH_MAX];
 	int	i;
 
 	if (csbIncList == 0)	/* no list */
@@ -659,6 +693,7 @@
 	return(0);
 }
 
+#ifndef KPATHSEA
 /******
 ** SetInputPaths -- sets rgsbInputPaths to the values indicated by the
 **	TEXINPUTS environment variable if set or else DEFAULTINPUTS.  If
@@ -702,6 +737,7 @@
 	    ErrorExit("TEXINPUTS environment variable has too many paths");
 #endif
 }
+#endif
 
 /******
 ** SeparateList -- takes a chSep separated list sbList, replaces the
@@ -738,10 +774,12 @@
 FILE *
 TexOpen(char *sbFile)
 {
-	char	*pch, *sbNew;
+	char	*sbNew;
+#ifndef KPATHSEA
+	char	*pch;
 	FILE	*fp;
 	int	iPath;
-	static char	sbFullPath[MAXPATHLEN];
+	static char	sbFullPath[PATH_MAX];
 
 	for (iPath = 0; iPath < csbInputPaths; iPath++) {
 #ifdef OS2
@@ -788,7 +826,15 @@
 	    if ((fp = fopen(sbFullPath, "r")) != NULL)
 		return(fp);
 	}
-	return((FILE *)NULL);
+	return NULL;
+#else
+	sbNew = kpse_find_file (sbFile, kpse_tex_format, false);
+
+	if (sbNew == NULL)
+	    return NULL;
+
+	return fopen (sbNew, "r");
+#endif
 }
 
 /******