mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-18 21:45:24 +00:00
Updated set of patches for external components
* Compatible with both MSVC and MinGW * dtl bugfix for recent DVI drivers * dvipost works for restricted users * new Aspell Windows port git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@15083 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e161bf59cf
commit
345e85dd06
@ -1,56 +1,6 @@
|
||||
diff -r -u dtl_orig/dt2dv.c dtl/dt2dv.c
|
||||
--- dtl_orig/dt2dv.c 1995-03-08 01:00:00.000000000 +0000
|
||||
+++ dtl/dt2dv.c 2006-03-02 19:05:02.000000000 +0000
|
||||
@@ -1,9 +1,11 @@
|
||||
/* dt2dv - convert human-readable "DTL" file to DVI format
|
||||
- this is intended to invert dv2dt version 0.6.0
|
||||
- - version 0.6.1 - 14:38 GMT +11 Thu 9 March 1995
|
||||
+ - version 0.6.2 - 27 July 2005
|
||||
- Geoffrey Tobin G.Tobin@ee.latrobe.edu.au
|
||||
- fixes: Michal Tomczak-Jaegermann ntomczak@vm.ucs.ualberta.ca
|
||||
Nelson H. F. Beebe beebe@math.utah.edu
|
||||
+ Angus Leeming leeming@lyx.org: Enable dt2dv to handle
|
||||
+ .dvi files containing strings longer than 1024 chars.
|
||||
- Reference: "The DVI Driver Standard, Level 0",
|
||||
by The TUG DVI Driver Standards Committee.
|
||||
Appendix A, "Device-Independent File Format".
|
||||
@@ -2223,7 +2225,7 @@
|
||||
/* transfer (length and) quoted string from dtl to dvi file, */
|
||||
/* return number of bytes written to dvi file. */
|
||||
{
|
||||
- U4 k, k2;
|
||||
+ U4 k, k2, lstr_maxsize;
|
||||
Lstring lstr;
|
||||
|
||||
if (debug)
|
||||
@@ -2232,12 +2234,13 @@
|
||||
fprintf (stderr, "(xfer_len_string) : entering xfer_len_string.\n");
|
||||
}
|
||||
|
||||
- init_Lstring (&lstr, LSIZE);
|
||||
-
|
||||
/* k[n] : length of special string */
|
||||
|
||||
k = get_unsigned (dtl);
|
||||
|
||||
+ lstr_maxsize = (k > LSIZE) ? k : LSIZE;
|
||||
+ init_Lstring (&lstr, lstr_maxsize);
|
||||
+
|
||||
if (debug)
|
||||
{
|
||||
PRINT_PROGNAME;
|
||||
@@ -2567,7 +2570,7 @@
|
||||
#ifdef HEX_CHECKSUM
|
||||
/* c[4] : (hexadecimal) checksum : I (gt) would prefer this */
|
||||
xfer_hex (4, dtl, dvi);
|
||||
-#else /NOT HEX_CHECKSUM */
|
||||
+#else /*NOT HEX_CHECKSUM */
|
||||
/* c[4] : checksum (octal, for comparison with tftopl's .pl file) */
|
||||
xfer_oct (4, dtl, dvi);
|
||||
#endif
|
||||
diff -r -u dtl_orig/Makefile dtl/Makefile
|
||||
--- dtl_orig/Makefile 1995-03-08 01:00:00.000000000 +0000
|
||||
+++ dtl/Makefile 2006-07-07 14:56:12.000000000 +0100
|
||||
diff -riwbBu -Xex dtl/Makefile dtl-modified/Makefile
|
||||
--- dtl/Makefile Tue Sep 19 23:59:17 2006
|
||||
+++ dtl-modified/Makefile Wed Jul 5 17:54:21 2006
|
||||
@@ -3,6 +3,14 @@
|
||||
# Thu 9 March 1995
|
||||
# Geoffrey Tobin
|
||||
@ -91,16 +41,13 @@ diff -r -u dtl_orig/Makefile dtl/Makefile
|
||||
MANDIR = /usr/local/man/man$(MANEXT)
|
||||
MANEXT = 1
|
||||
OBJS = dt2dv.o dv2dt.o
|
||||
@@ -40,7 +60,7 @@
|
||||
$(DITROFF) -man -Tascii $< | $(COL) >$@
|
||||
|
||||
.man.ps:
|
||||
- $(MAN2PS) < $< > $@
|
||||
+ $(MAN2PS) $< > $@
|
||||
@@ -44,23 +64,24 @@
|
||||
|
||||
#=======================================================================
|
||||
|
||||
@@ -48,19 +68,19 @@
|
||||
-all: dtl check doc
|
||||
+#all: dtl check doc
|
||||
+all: dtl check
|
||||
|
||||
doc: dt2dv.hlp dv2dt.hlp dt2dv.ps dv2dt.ps
|
||||
|
||||
@ -126,7 +73,7 @@ diff -r -u dtl_orig/Makefile dtl/Makefile
|
||||
-@diff hello.dtl hello2.dtl > hello.dif
|
||||
@if [ -s hello.dif ] ; \
|
||||
then echo ERROR: differences in hello.dif ; \
|
||||
@@ -69,11 +89,11 @@
|
||||
@@ -69,11 +90,11 @@
|
||||
|
||||
hello.dtl: hello.tex
|
||||
tex hello
|
||||
@ -142,7 +89,7 @@ diff -r -u dtl_orig/Makefile dtl/Makefile
|
||||
-@diff example.dtl example2.dtl > example.dif
|
||||
@if [ -s example.dif ] ; \
|
||||
then echo ERROR: differences in example.dif ; \
|
||||
@@ -82,11 +102,11 @@
|
||||
@@ -82,11 +103,11 @@
|
||||
|
||||
example.dtl: example.tex
|
||||
tex example
|
||||
@ -158,7 +105,7 @@ diff -r -u dtl_orig/Makefile dtl/Makefile
|
||||
-@diff tripvdu.dtl tripvdu2.dtl > tripvdu.dif
|
||||
@if [ -s tripvdu.dif ] ; \
|
||||
then echo ERROR: differences in tripvdu.dif ; \
|
||||
@@ -95,15 +115,15 @@
|
||||
@@ -95,15 +116,15 @@
|
||||
|
||||
tripvdu.dtl: tripvdu.tex
|
||||
tex tripvdu
|
||||
@ -180,9 +127,71 @@ diff -r -u dtl_orig/Makefile dtl/Makefile
|
||||
@if [ -s edited.dif ] ; \
|
||||
then echo ERROR : differences in edited.dif ; \
|
||||
else $(RM) edited.dif ; \
|
||||
diff -r -u dtl_orig/man2ps dtl/man2ps
|
||||
--- dtl_orig/man2ps 1993-05-10 02:00:00.000000000 +0100
|
||||
+++ dtl/man2ps 2006-07-07 15:03:12.000000000 +0100
|
||||
diff -riwbBu -Xex dtl/dt2dv.c dtl-modified/dt2dv.c
|
||||
--- dtl/dt2dv.c Wed Mar 8 00:00:00 1995
|
||||
+++ dtl-modified/dt2dv.c Sun Sep 17 21:51:04 2006
|
||||
@@ -1,9 +1,11 @@
|
||||
/* dt2dv - convert human-readable "DTL" file to DVI format
|
||||
- this is intended to invert dv2dt version 0.6.0
|
||||
- - version 0.6.1 - 14:38 GMT +11 Thu 9 March 1995
|
||||
+ - version 0.6.2 - 27 July 2005
|
||||
- Geoffrey Tobin G.Tobin@ee.latrobe.edu.au
|
||||
- fixes: Michal Tomczak-Jaegermann ntomczak@vm.ucs.ualberta.ca
|
||||
Nelson H. F. Beebe beebe@math.utah.edu
|
||||
+ Angus Leeming leeming@lyx.org: Enable dt2dv to handle
|
||||
+ .dvi files containing strings longer than 1024 chars.
|
||||
- Reference: "The DVI Driver Standard, Level 0",
|
||||
by The TUG DVI Driver Standards Committee.
|
||||
Appendix A, "Device-Independent File Format".
|
||||
@@ -1089,7 +1091,11 @@
|
||||
dinfo();
|
||||
status = 0;
|
||||
}
|
||||
+#if defined(__CYGWIN__) || defined(__MINGW32__)
|
||||
+ else if ( ! isprint (c & 0x7f) && ! isspace (c))
|
||||
+#else
|
||||
else if ( ! isprint (c) && ! isspace (c))
|
||||
+#endif
|
||||
{
|
||||
PRINT_PROGNAME;
|
||||
fprintf (stderr,
|
||||
@@ -2223,7 +2229,7 @@
|
||||
/* transfer (length and) quoted string from dtl to dvi file, */
|
||||
/* return number of bytes written to dvi file. */
|
||||
{
|
||||
- U4 k, k2;
|
||||
+ U4 k, k2, lstr_maxsize;
|
||||
Lstring lstr;
|
||||
|
||||
if (debug)
|
||||
@@ -2232,12 +2238,13 @@
|
||||
fprintf (stderr, "(xfer_len_string) : entering xfer_len_string.\n");
|
||||
}
|
||||
|
||||
- init_Lstring (&lstr, LSIZE);
|
||||
-
|
||||
/* k[n] : length of special string */
|
||||
|
||||
k = get_unsigned (dtl);
|
||||
|
||||
+ lstr_maxsize = (k > LSIZE) ? k : LSIZE;
|
||||
+ init_Lstring (&lstr, lstr_maxsize);
|
||||
+
|
||||
if (debug)
|
||||
{
|
||||
PRINT_PROGNAME;
|
||||
@@ -2567,7 +2574,7 @@
|
||||
#ifdef HEX_CHECKSUM
|
||||
/* c[4] : (hexadecimal) checksum : I (gt) would prefer this */
|
||||
xfer_hex (4, dtl, dvi);
|
||||
-#else /NOT HEX_CHECKSUM */
|
||||
+#else /*NOT HEX_CHECKSUM */
|
||||
/* c[4] : checksum (octal, for comparison with tftopl's .pl file) */
|
||||
xfer_oct (4, dtl, dvi);
|
||||
#endif
|
||||
diff -riwbBu -Xex dtl/man2ps dtl-modified/man2ps
|
||||
--- dtl/man2ps Tue Sep 19 23:59:23 2006
|
||||
+++ dtl-modified/man2ps Wed Sep 20 00:03:06 2006
|
||||
@@ -20,16 +20,16 @@
|
||||
esac
|
||||
|
||||
@ -193,14 +202,14 @@ diff -r -u dtl_orig/man2ps dtl/man2ps
|
||||
TROFF="groff $FORMAT"
|
||||
TROFF2PS="cat"
|
||||
-elif [ -x /usr/lib/lp/postscript/dpost ]
|
||||
+elif [ which dpost > /dev/null ]
|
||||
++elif [ which dpost > /dev/null ]
|
||||
then # Solaris 2.1
|
||||
TROFF="troff $FORMAT"
|
||||
TROFF2PS="/usr/lib/lp/postscript/dpost"
|
||||
else
|
||||
- echo "Cannot find troff-to-PostScript filter"
|
||||
+ echo "Cannot find troff-to-PostScript filter" >&2
|
||||
++ echo "Cannot find troff-to-PostScript filter" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Only in dtl: .svn
|
||||
|
||||
|
@ -1,83 +1,198 @@
|
||||
diff -riwbBu -Xex dvipost-1.1/dvi.c dvipost-1.1-modified/dvi.c
|
||||
--- dvipost-1.1/dvi.c Wed Mar 22 14:59:58 2006
|
||||
+++ dvipost-1.1-modified/dvi.c Wed May 31 11:27:44 2006
|
||||
@@ -502,8 +502,12 @@
|
||||
for (i = 0; i < pos_changed.dim; i++)
|
||||
{
|
||||
POS *p = pos_changed.tab + i;
|
||||
diff -riwbBu -Xex dvipost-1.1/dvi.c dvipost-1.1-modified/dvi.c
|
||||
--- dvipost-1.1/dvi.c Wed Mar 22 14:59:58 2006
|
||||
+++ dvipost-1.1-modified/dvi.c Wed May 31 11:27:44 2006
|
||||
@@ -502,8 +502,12 @@
|
||||
for (i = 0; i < pos_changed.dim; i++)
|
||||
{
|
||||
POS *p = pos_changed.tab + i;
|
||||
+ if (!p->type)
|
||||
+ dout_special(out, osstart);
|
||||
cmd_goto(out, p->end, cbcol);
|
||||
dout_putrule(out, p->end - p->beg, cbrule);
|
||||
cmd_goto(out, p->end, cbcol);
|
||||
dout_putrule(out, p->end - p->beg, cbrule);
|
||||
+ if (!p->type)
|
||||
+ dout_special(out, osend);
|
||||
}
|
||||
|
||||
dout_special(out, cbend);
|
||||
@@ -625,10 +629,9 @@
|
||||
mv_right(w);
|
||||
text_cnt++;
|
||||
|
||||
- if (!cbmode[page_stat]) return;
|
||||
-
|
||||
}
|
||||
|
||||
dout_special(out, cbend);
|
||||
@@ -625,10 +629,9 @@
|
||||
mv_right(w);
|
||||
text_cnt++;
|
||||
|
||||
- if (!cbmode[page_stat]) return;
|
||||
-
|
||||
+ if (!cbmode[page_stat] && !osmode[page_stat]) return;
|
||||
pos_add(&pos_changed, dvi_stat.v - text_height - cbexp,
|
||||
- dvi_stat.v + text_depth + cbexp);
|
||||
pos_add(&pos_changed, dvi_stat.v - text_height - cbexp,
|
||||
- dvi_stat.v + text_depth + cbexp);
|
||||
+ dvi_stat.v + text_depth + cbexp, cbmode[page_stat]);
|
||||
|
||||
if (cbframe)
|
||||
{
|
||||
diff -riwbBu -Xex dvipost-1.1/dvipost.h dvipost-1.1-modified/dvipost.h
|
||||
--- dvipost-1.1/dvipost.h Mon Nov 4 08:44:46 2002
|
||||
+++ dvipost-1.1-modified/dvipost.h Wed May 31 18:23:34 2006
|
||||
@@ -44,6 +44,7 @@
|
||||
typedef struct {
|
||||
int beg;
|
||||
int end;
|
||||
+ int type;
|
||||
} POS;
|
||||
|
||||
typedef struct {
|
||||
@@ -53,7 +54,7 @@
|
||||
} PosTab;
|
||||
|
||||
void pos_init (PosTab *pos);
|
||||
-void pos_add (PosTab *pos, int beg, int end);
|
||||
+void pos_add (PosTab *pos, int beg, int end, int type);
|
||||
|
||||
extern int process_dvi (const char *id, FILE *in, FILE *out);
|
||||
extern int dvipost (const char *iname, const char *oname);
|
||||
diff -riwbBu -Xex dvipost-1.1/main.c dvipost-1.1-modified/main.c
|
||||
--- dvipost-1.1/main.c Wed Nov 27 15:19:14 2002
|
||||
+++ dvipost-1.1-modified/main.c Fri Jul 7 17:55:24 2006
|
||||
@@ -24,7 +24,7 @@
|
||||
#define TEX_ACCEPT_OPTIONS 1
|
||||
#endif
|
||||
|
||||
-static char *version = "dvipost version 1.0\n\
|
||||
+static char *version = "dvipost version 1.1-modified\n\
|
||||
Dvipost is copyright (C) 2002 Erich Fruehstueck.\n";
|
||||
|
||||
#include "dvipost.h"
|
||||
@@ -32,7 +32,9 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
+#ifndef _WIN32
|
||||
#include <sys/wait.h>
|
||||
|
||||
if (cbframe)
|
||||
{
|
||||
diff -riwbBu -Xex dvipost-1.1/dvipost.c dvipost-1.1-modified/dvipost.c
|
||||
--- dvipost-1.1/dvipost.c Mon Nov 4 08:44:46 2002
|
||||
+++ dvipost-1.1-modified/dvipost.c Mon Sep 18 13:11:58 2006
|
||||
@@ -1,6 +1,7 @@
|
||||
/* dvi file post processing
|
||||
|
||||
$Copyright (C) 2002 Erich Fruehstueck
|
||||
+Modified version by LyX Team
|
||||
|
||||
Dvipost is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
@@ -18,13 +19,20 @@
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
-
|
||||
#include "dvipost.h"
|
||||
#include "dvi.h"
|
||||
+#if !defined(_MSC_VER)
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
+#else
|
||||
+#include "dirent.h"
|
||||
+#endif
|
||||
|
||||
char **tex_argv = NULL;
|
||||
int tex_argc = 0;
|
||||
@@ -233,17 +235,26 @@
|
||||
return stat;
|
||||
}
|
||||
|
||||
-static char *get_dvi_name (const char *arg)
|
||||
#include <sys/stat.h>
|
||||
|
||||
+#ifdef _WIN32
|
||||
+#include <windows.h>
|
||||
+#endif
|
||||
+
|
||||
int dvipost (const char *iname, const char *oname)
|
||||
{
|
||||
FILE *input, *tmp, *output;
|
||||
@@ -33,7 +41,19 @@
|
||||
|
||||
/* open temporary file
|
||||
*/
|
||||
+#ifndef _WIN32
|
||||
tmp = tmpfile();
|
||||
+#else
|
||||
+ /* create temporary file in Windows temp directory */
|
||||
+
|
||||
+ char tmppath[MAX_PATH-14];
|
||||
+ char tmpname[MAX_PATH];
|
||||
+
|
||||
+ GetTempPath(MAX_PATH-14, tmppath);
|
||||
+ GetTempFileName(tmppath, "dvp", 0, tmpname);
|
||||
+
|
||||
+ tmp = fopen(tmpname, "r+b");
|
||||
+#endif
|
||||
|
||||
if (!tmp)
|
||||
{
|
||||
@@ -57,8 +77,10 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
+#ifndef _WIN32
|
||||
iname = "<stdin>";
|
||||
input = stdin;
|
||||
+#endif
|
||||
}
|
||||
|
||||
/* check magic and process input
|
||||
@@ -94,6 +116,8 @@
|
||||
|
||||
/* copy file to output
|
||||
*/
|
||||
+
|
||||
+#ifndef _WIN32
|
||||
rewind(tmp);
|
||||
|
||||
if (oname && strcmp(oname, "-") != 0)
|
||||
@@ -113,23 +137,20 @@
|
||||
oname = "<stdout>";
|
||||
output = stdout;
|
||||
}
|
||||
+#endif
|
||||
|
||||
message(NOTE, "$!: Copy data to %s\n", oname);
|
||||
|
||||
- while ((c = getc(tmp)) != EOF)
|
||||
- putc(c, output);
|
||||
-
|
||||
+#ifndef _WIN32
|
||||
+ while ((c = getc(tmp)) != EOF) putc(c, output);
|
||||
fclose(tmp);
|
||||
+#else
|
||||
+ /* Copy file directly */
|
||||
+ fclose(tmp);
|
||||
+ CopyFile(tmpname, oname, FALSE);
|
||||
+ DeleteFile(tmpname);
|
||||
+#endif
|
||||
|
||||
- if (ferror(output))
|
||||
- {
|
||||
- fprintf(stderr, "%s: ", pname);
|
||||
- perror(oname);
|
||||
- stat = EXIT_FAILURE;
|
||||
- }
|
||||
- else stat = EXIT_SUCCESS;
|
||||
-
|
||||
- fclose(output);
|
||||
return stat;
|
||||
}
|
||||
diff -riwbBu -Xex dvipost-1.1/dvipost.h dvipost-1.1-modified/dvipost.h
|
||||
--- dvipost-1.1/dvipost.h Mon Nov 4 08:44:46 2002
|
||||
+++ dvipost-1.1-modified/dvipost.h Sun Sep 17 22:03:51 2006
|
||||
@@ -1,6 +1,7 @@
|
||||
/* postfilter
|
||||
|
||||
$Copyright (C) 2002 Erich Fruehstueck
|
||||
+Modified version by LyX Team
|
||||
|
||||
Dvipost is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
@@ -44,6 +45,7 @@
|
||||
typedef struct {
|
||||
int beg;
|
||||
int end;
|
||||
+ int type;
|
||||
} POS;
|
||||
|
||||
typedef struct {
|
||||
@@ -53,7 +55,7 @@
|
||||
} PosTab;
|
||||
|
||||
void pos_init (PosTab *pos);
|
||||
-void pos_add (PosTab *pos, int beg, int end);
|
||||
+void pos_add (PosTab *pos, int beg, int end, int type);
|
||||
|
||||
extern int process_dvi (const char *id, FILE *in, FILE *out);
|
||||
extern int dvipost (const char *iname, const char *oname);
|
||||
diff -riwbBu -Xex dvipost-1.1/main.c dvipost-1.1-modified/main.c
|
||||
--- dvipost-1.1/main.c Wed Nov 27 15:19:14 2002
|
||||
+++ dvipost-1.1-modified/main.c Sun Sep 17 21:56:42 2006
|
||||
@@ -24,15 +24,19 @@
|
||||
#define TEX_ACCEPT_OPTIONS 1
|
||||
#endif
|
||||
|
||||
-static char *version = "dvipost version 1.0\n\
|
||||
+static char *version = "dvipost version 1.1 with modifications by LyX Team (sep 2006)\n\
|
||||
Dvipost is copyright (C) 2002 Erich Fruehstueck.\n";
|
||||
|
||||
#include "dvipost.h"
|
||||
#include "dvi.h"
|
||||
+#if !defined(_MSC_VER)
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
+#ifndef _WIN32
|
||||
#include <sys/wait.h>
|
||||
+#endif
|
||||
|
||||
char **tex_argv = NULL;
|
||||
int tex_argc = 0;
|
||||
@@ -233,17 +237,26 @@
|
||||
return stat;
|
||||
}
|
||||
|
||||
-static char *get_dvi_name (const char *arg)
|
||||
+static char *get_dvi_name (char *arg)
|
||||
{
|
||||
char *p, *dvi;
|
||||
|
||||
{
|
||||
char *p, *dvi;
|
||||
|
||||
+#ifdef _WIN32
|
||||
+ int i;
|
||||
+
|
||||
@ -87,36 +202,36 @@ diff -riwbBu -Xex dvipost-1.1/main.c dvipost-1.1-modified/main.c
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
p = strrchr(arg, '/');
|
||||
|
||||
if (p && p[1])
|
||||
arg = p + 1;
|
||||
|
||||
- dvi = strcpy(xalloc(strlen(arg) + 4), arg);
|
||||
- p = strchr(dvi, '.');
|
||||
p = strrchr(arg, '/');
|
||||
|
||||
if (p && p[1])
|
||||
arg = p + 1;
|
||||
|
||||
- dvi = strcpy(xalloc(strlen(arg) + 4), arg);
|
||||
- p = strchr(dvi, '.');
|
||||
+ dvi = strcpy(xalloc(strlen(arg) + 5), arg);
|
||||
+ p = strrchr(dvi, '.');
|
||||
|
||||
if (p && strcmp(p, ".tex") == 0)
|
||||
*p = 0;
|
||||
@@ -267,14 +278,32 @@
|
||||
char *dviname;
|
||||
int flag;
|
||||
int i, n;
|
||||
|
||||
if (p && strcmp(p, ".tex") == 0)
|
||||
*p = 0;
|
||||
@@ -267,14 +280,32 @@
|
||||
char *dviname;
|
||||
int flag;
|
||||
int i, n;
|
||||
+#ifdef _WIN32
|
||||
+ char *cmd;
|
||||
+ char *qch;
|
||||
+ char *p;
|
||||
+#else
|
||||
int status;
|
||||
pid_t pid;
|
||||
int status;
|
||||
pid_t pid;
|
||||
+#endif
|
||||
time_t stamp;
|
||||
|
||||
tex_argv = xalloc((1 + argc) * sizeof(char*));
|
||||
tex_argv[0] = argv[0];
|
||||
tex_argc = 1;
|
||||
|
||||
time_t stamp;
|
||||
|
||||
tex_argv = xalloc((1 + argc) * sizeof(char*));
|
||||
tex_argv[0] = argv[0];
|
||||
tex_argc = 1;
|
||||
|
||||
+#ifdef _WIN32
|
||||
+ for (i=0; i < strlen(argv[0]); ++i) {
|
||||
+ if (argv[0][i] == '\\')
|
||||
@ -129,13 +244,13 @@ diff -riwbBu -Xex dvipost-1.1/main.c dvipost-1.1-modified/main.c
|
||||
+ *p = 0;
|
||||
+#endif
|
||||
+
|
||||
pname = strrchr(argv[0], '/');
|
||||
|
||||
if (pname == NULL) pname = argv[0];
|
||||
@@ -356,6 +385,34 @@
|
||||
fflush(stdout);
|
||||
|
||||
time(&stamp);
|
||||
pname = strrchr(argv[0], '/');
|
||||
|
||||
if (pname == NULL) pname = argv[0];
|
||||
@@ -356,6 +387,34 @@
|
||||
fflush(stdout);
|
||||
|
||||
time(&stamp);
|
||||
+#ifdef _WIN32
|
||||
+ for (i=0, n=0; i < tex_argc; ++i) {
|
||||
+ n += strlen(tex_argv[i]);
|
||||
@ -164,54 +279,82 @@ diff -riwbBu -Xex dvipost-1.1/main.c dvipost-1.1-modified/main.c
|
||||
+ system(cmd);
|
||||
+ xfree(cmd);
|
||||
+#else
|
||||
pid = fork();
|
||||
|
||||
if (pid == -1)
|
||||
@@ -368,6 +425,7 @@
|
||||
execvp(tex_argv[0], tex_argv);
|
||||
|
||||
waitpid(pid, &status, 0);
|
||||
pid = fork();
|
||||
|
||||
if (pid == -1)
|
||||
@@ -368,6 +427,7 @@
|
||||
execvp(tex_argv[0], tex_argv);
|
||||
|
||||
waitpid(pid, &status, 0);
|
||||
+#endif
|
||||
|
||||
if (dviname)
|
||||
return dvipost(dviname, dviname);
|
||||
diff -riwbBu -Xex dvipost-1.1/pos.c dvipost-1.1-modified/pos.c
|
||||
--- dvipost-1.1/pos.c Tue Oct 29 12:54:02 2002
|
||||
+++ dvipost-1.1-modified/pos.c Wed May 31 11:27:44 2006
|
||||
@@ -39,7 +39,7 @@
|
||||
pos->dim = 0;
|
||||
}
|
||||
|
||||
-void pos_add (PosTab *pos, int beg, int end)
|
||||
|
||||
if (dviname)
|
||||
return dvipost(dviname, dviname);
|
||||
diff -riwbBu -Xex dvipost-1.1/pos.c dvipost-1.1-modified/pos.c
|
||||
--- dvipost-1.1/pos.c Tue Oct 29 12:54:02 2002
|
||||
+++ dvipost-1.1-modified/pos.c Sun Sep 17 22:03:41 2006
|
||||
@@ -1,6 +1,7 @@
|
||||
/* position table
|
||||
|
||||
$Copyright (C) 2002 Erich Fruehstueck
|
||||
+Modified version by LyX Team
|
||||
|
||||
Dvipost is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
@@ -39,7 +40,7 @@
|
||||
pos->dim = 0;
|
||||
}
|
||||
|
||||
-void pos_add (PosTab *pos, int beg, int end)
|
||||
+void pos_add (PosTab *pos, int beg, int end, int type)
|
||||
{
|
||||
if (beg > end)
|
||||
{
|
||||
@@ -56,7 +56,7 @@
|
||||
{
|
||||
if (last->end < end) last->end = end;
|
||||
if (last->beg > beg) last->beg = beg;
|
||||
-
|
||||
{
|
||||
if (beg > end)
|
||||
{
|
||||
@@ -56,7 +57,7 @@
|
||||
{
|
||||
if (last->end < end) last->end = end;
|
||||
if (last->beg > beg) last->beg = beg;
|
||||
-
|
||||
+ if (last->type < type) last->type = type;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -64,5 +64,6 @@
|
||||
pos_expand(pos);
|
||||
pos->tab[pos->dim].beg = beg;
|
||||
pos->tab[pos->dim].end = end;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -64,5 +65,6 @@
|
||||
pos_expand(pos);
|
||||
pos->tab[pos->dim].beg = beg;
|
||||
pos->tab[pos->dim].end = end;
|
||||
+ pos->tab[pos->dim].type = type;
|
||||
pos->dim++;
|
||||
}
|
||||
diff -riwbBu -Xex dvipost-1.1/tfm.c dvipost-1.1-modified/tfm.c
|
||||
--- dvipost-1.1/tfm.c Sun Nov 3 09:52:04 2002
|
||||
+++ dvipost-1.1-modified/tfm.c Wed May 31 11:27:44 2006
|
||||
@@ -112,6 +112,8 @@
|
||||
{
|
||||
if (tfm_buf[n] == '\n')
|
||||
{
|
||||
pos->dim++;
|
||||
}
|
||||
diff -riwbBu -Xex dvipost-1.1/tfm.c dvipost-1.1-modified/tfm.c
|
||||
--- dvipost-1.1/tfm.c Sun Nov 3 09:52:04 2002
|
||||
+++ dvipost-1.1-modified/tfm.c Sun Sep 17 22:03:44 2006
|
||||
@@ -1,6 +1,7 @@
|
||||
/* tfm data
|
||||
|
||||
$Copyright (C) 2002 Erich Fruehstueck
|
||||
+Modified version by LyX Team
|
||||
|
||||
Dvipost is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
@@ -22,6 +23,11 @@
|
||||
#include "dvi.h"
|
||||
#include <ctype.h>
|
||||
|
||||
+#if defined(_MSC_VER)
|
||||
+#define popen _popen
|
||||
+#define pclose _pclose
|
||||
+#endif
|
||||
+
|
||||
static char tfm_buf[1024];
|
||||
static int tfm_err = 0;
|
||||
static int tfm_pos = 0;
|
||||
@@ -112,6 +118,8 @@
|
||||
{
|
||||
if (tfm_buf[n] == '\n')
|
||||
{
|
||||
+ if (n && tfm_buf[n-1] == '\r')
|
||||
+ n--;
|
||||
tfm_buf[n] = 0;
|
||||
break;
|
||||
}
|
||||
tfm_buf[n] = 0;
|
||||
break;
|
||||
}
|
||||
|
213
development/Win32/patches/msvc/aspell-setter-sep06.patch
Normal file
213
development/Win32/patches/msvc/aspell-setter-sep06.patch
Normal file
@ -0,0 +1,213 @@
|
||||
diff -riwbBu -Xex aspell-setter-sep06/common/config.cpp aspell-setter-sep06-modified/common/config.cpp
|
||||
--- aspell-setter-sep06/common/config.cpp Mon Dec 12 17:41:06 2005
|
||||
+++ aspell-setter-sep06-modified/common/config.cpp Sun Sep 17 20:55:02 2006
|
||||
@@ -78,6 +78,11 @@
|
||||
|
||||
namespace aspell {
|
||||
|
||||
+#ifdef WIN32PORT
|
||||
+ HKEY GetRegHive();
|
||||
+ aspell::String ReadRegString(HKEY type, aspell::String key, aspell::String name);
|
||||
+#endif
|
||||
+
|
||||
const char * const keyinfo_type_name[4] = {
|
||||
N_("string"), N_("integer"), N_("boolean"), N_("list")
|
||||
};
|
||||
@@ -642,20 +647,30 @@
|
||||
|
||||
} else if (strcmp(i, "home-dir") == 0) {
|
||||
|
||||
- //get the personal folder (e.g. "c:\My Documents")
|
||||
+ //get the personal folder
|
||||
+
|
||||
+ //get from registry
|
||||
+ HKEY hive;
|
||||
+ hive = GetRegHive();
|
||||
+ final_str = ReadRegString(hive, "Software\\Aspell", "Base Path");
|
||||
+
|
||||
+ //default location
|
||||
+ if (final_str == "") {
|
||||
char * dir = new char[MAX_PATH];
|
||||
LPITEMIDLIST items = 0;
|
||||
- HRESULT hand = SHGetSpecialFolderLocation(0, CSIDL_PERSONAL, &items);
|
||||
+ HRESULT hand = SHGetSpecialFolderLocation(0, CSIDL_APPDATA, &items);
|
||||
if ((NOERROR == hand) && items) {
|
||||
if (SHGetPathFromIDList(items, dir)) {
|
||||
for (char *ptr = dir; *ptr; ++ptr)
|
||||
if ('\\' == *ptr)
|
||||
*ptr = '/';
|
||||
final_str = dir;
|
||||
+ final_str.append("/Aspell");
|
||||
}
|
||||
CoTaskMemFree(items);
|
||||
}
|
||||
delete [] dir;
|
||||
+ }
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1394,20 +1409,6 @@
|
||||
return no_err;
|
||||
}
|
||||
|
||||
-#if defined(WIN32_USE_PERSONAL_DIR)
|
||||
-# define HOME_DIR "!home-dir"
|
||||
-# define PERSONAL "<lang>.pws"
|
||||
-# define REPL "<lang>.prepl"
|
||||
-#elif defined(ENABLE_WIN32_RELOCATABLE)
|
||||
-# define HOME_DIR "<prefix>"
|
||||
-# define PERSONAL "<lang>.pws"
|
||||
-# define REPL "<lang>.prepl"
|
||||
-#else
|
||||
-# define HOME_DIR "<$HOME|./>"
|
||||
-# define PERSONAL ".aspell.<lang>.pws"
|
||||
-# define REPL ".aspell.<lang>.prepl"
|
||||
-#endif
|
||||
-
|
||||
static const KeyInfo config_keys[] = {
|
||||
// the description should be under 50 chars
|
||||
{"actual-dict-dir", KeyInfoString, "<dict-dir^master>", 0}
|
||||
@@ -1484,7 +1485,7 @@
|
||||
, {"per-conf-path", KeyInfoString, "<home-dir/per-conf>", 0}
|
||||
, {"personal", KeyInfoString, PERSONAL,
|
||||
N_("personal dictionary file name")}
|
||||
- , {"personal-path", KeyInfoString, "<home-dir/personal>", 0}
|
||||
+ , {"personal-path", KeyInfoString, PERSONAL_DIR, 0}
|
||||
, {"prefix", KeyInfoString, PREFIX,
|
||||
N_("prefix directory")}
|
||||
, {"repl", KeyInfoString, REPL,
|
||||
@@ -1525,10 +1526,12 @@
|
||||
, {"warn", KeyInfoBool, "true",
|
||||
N_("enable warnings")}
|
||||
#ifdef WIN32PORT
|
||||
- , {"dict-subdir", KeyInfoString, "dicts",
|
||||
+ , {"dict-subdir", KeyInfoString, "Dictionaries",
|
||||
N_("sub directory for dictionaries")}
|
||||
, {"data-subdir", KeyInfoString, "data",
|
||||
N_("sub directory for other data")}
|
||||
+ , {"personal-subdir", KeyInfoString, "Personal",
|
||||
+ N_("sub directory for personal data")}
|
||||
#endif
|
||||
|
||||
//
|
||||
@@ -1587,5 +1590,53 @@
|
||||
config_impl_keys_begin,
|
||||
config_impl_keys_end);
|
||||
}
|
||||
+
|
||||
+#ifdef WIN32PORT
|
||||
+
|
||||
+ String ReadRegString(HKEY hive, String key, String name)
|
||||
+ {
|
||||
+
|
||||
+ // Reads a string from the Windows registry (used to get paths)
|
||||
+
|
||||
+ HKEY hKey;
|
||||
+ unsigned long lType;
|
||||
+ DWORD dwSize;
|
||||
+ unsigned char* szValue = NULL;
|
||||
+
|
||||
+ if (::RegOpenKeyEx(hive, key.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
||||
+ {
|
||||
+ if(::RegQueryValueEx(hKey, name.c_str(), NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS)
|
||||
+ {
|
||||
+ szValue = new unsigned char[dwSize + 1];
|
||||
+ ::RegQueryValueEx(hKey, name.c_str(), NULL, &lType, szValue, &dwSize);
|
||||
+ String RegistryReturn((char*)szValue);
|
||||
+ delete[] szValue;
|
||||
+ return RegistryReturn;
|
||||
+ } else {
|
||||
+ return "";
|
||||
+ }
|
||||
+ } else {
|
||||
+ return "";
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ HKEY GetRegHive()
|
||||
+ {
|
||||
+
|
||||
+ // Check whether Aspell is installed for the current user or for all users
|
||||
+
|
||||
+ String value;
|
||||
+
|
||||
+ if (ReadRegString(HKEY_LOCAL_MACHINE, "Software\\Aspell", "Dictionary Path") == "")
|
||||
+ {
|
||||
+ return HKEY_CURRENT_USER;
|
||||
+ } else {
|
||||
+ return HKEY_LOCAL_MACHINE;
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+#endif
|
||||
|
||||
}
|
||||
diff -riwbBu -Xex aspell-setter-sep06/common/vector.hpp aspell-setter-sep06-modified/common/vector.hpp
|
||||
--- aspell-setter-sep06/common/vector.hpp Thu Oct 13 09:42:54 2005
|
||||
+++ aspell-setter-sep06-modified/common/vector.hpp Sun Sep 17 19:50:46 2006
|
||||
@@ -50,10 +50,10 @@
|
||||
T * data_end() {return &*this->end();}
|
||||
|
||||
T * pbegin() {return &*this->begin();}
|
||||
- T * pend() {return &*this->end();}
|
||||
+ T * pend() {return &this->back()+1;}
|
||||
|
||||
const T * pbegin() const {return &*this->begin();}
|
||||
- const T * pend() const {return &*this->end();}
|
||||
+ const T * pend() const {return &this->back()+1;}
|
||||
|
||||
template <typename U>
|
||||
U * datap() {
|
||||
diff -riwbBu -Xex aspell-setter-sep06/win32/dirs.h aspell-setter-sep06-modified/win32/dirs.h
|
||||
--- aspell-setter-sep06/win32/dirs.h Thu Oct 13 13:29:34 2005
|
||||
+++ aspell-setter-sep06-modified/win32/dirs.h Sun Sep 17 20:26:26 2006
|
||||
@@ -1,16 +1,26 @@
|
||||
#ifndef dirs_h
|
||||
#define dirs_h
|
||||
|
||||
-#ifdef WIN32_USE_EXECUTABLE_DIR
|
||||
-# define DATA_DIR "<prefix/data-subdir>"
|
||||
-# define CONF_DIR "<prefix>"
|
||||
-# define DICT_DIR "<prefix/dict-subdir>"
|
||||
+# define DATA_DIR "<home-dir/data-subdir>"
|
||||
+# define CONF_DIR "<home-dir>"
|
||||
+# define DICT_DIR "<home-dir/dict-subdir>"
|
||||
+# define PERSONAL_DIR "<home-dir/personal>"
|
||||
+
|
||||
+#if defined(WIN32_USE_EXECUTABLE_DIR)
|
||||
+# define HOME_DIR "<prefix>"
|
||||
+# define PERSONAL "<personal-subdir>/<lang>.pws"
|
||||
+# define REPL "<personal-subdir>/<lang>.prepl"
|
||||
# define PREFIX "!prefix"
|
||||
+#elif defined(WIN32_USE_PERSONAL_DIR)
|
||||
+# define HOME_DIR "!home-dir"
|
||||
+# define PERSONAL "<personal-subdir>/<lang>.pws"
|
||||
+# define REPL "<personal-subdir>/<lang>.prepl"
|
||||
+# define PREFIX "<home-dir>"
|
||||
#else
|
||||
-# define DATA_DIR "aspell-win32/data"
|
||||
-# define CONF_DIR "aspell-win32"
|
||||
-# define DICT_DIR "dicts"
|
||||
-# define PREFIX "aspell-win32"
|
||||
+# define HOME_DIR "<$HOME|./>"
|
||||
+# define PERSONAL "<personal-subdir>/.aspell.<lang>.pws"
|
||||
+# define REPL "<personal-subdir>/.aspell.<lang>.prepl"
|
||||
+# define PREFIX "<home-dir>"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
diff -riwbBu -Xex aspell-setter-sep06/win32/settings.h aspell-setter-sep06-modified/win32/settings.h
|
||||
--- aspell-setter-sep06/win32/settings.h Wed Sep 6 10:51:16 2006
|
||||
+++ aspell-setter-sep06-modified/win32/settings.h Sun Sep 17 18:55:23 2006
|
||||
@@ -9,9 +9,6 @@
|
||||
/* Defined if curses like POSIX Functions should be used */
|
||||
#undef CURSES_ONLY
|
||||
|
||||
-/* Defined if win32 relocation should be used */
|
||||
-#define ENABLE_WIN32_RELOCATABLE 1
|
||||
-
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
600
development/Win32/patches/msvc/dirent.h
Normal file
600
development/Win32/patches/msvc/dirent.h
Normal file
@ -0,0 +1,600 @@
|
||||
/*
|
||||
* dirent.h - operating system independent dirent implementation
|
||||
*
|
||||
* Copyright (C) 1998-2002 Toni Ronkko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* ``Software''), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*
|
||||
* Aug 20, 2006, Toni Ronkko
|
||||
* Removed all remarks about MSVC 1.0, which is antiqued now. Simplified
|
||||
* comments by removing SGML tags.
|
||||
*
|
||||
* May 14 2002, Toni Ronkko
|
||||
* Embedded the function definitions directly to the header so that no source
|
||||
* modules must be included in the MS Visual C project for using the
|
||||
* interface. Removed all the dependencies to other projects so
|
||||
* that this very header can be used independently.
|
||||
*
|
||||
* May 28 1998, Toni Ronkko
|
||||
* First version.
|
||||
*/
|
||||
#ifndef DIRENT_H
|
||||
#define DIRENT_H
|
||||
#define DIRENT_H_INCLUDED
|
||||
|
||||
/* find out platform */
|
||||
#if defined(MSDOS) /* MS-DOS */
|
||||
#elif defined(__MSDOS__) /* Turbo C/Borland */
|
||||
# define MSDOS
|
||||
#elif defined(__DOS__) /* Watcom */
|
||||
# define MSDOS
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) /* MS-Windows */
|
||||
#elif defined(__NT__) /* Watcom */
|
||||
# define WIN32
|
||||
#elif defined(_WIN32) /* Microsoft */
|
||||
# define WIN32
|
||||
#elif defined(__WIN32__) /* Borland */
|
||||
# define WIN32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* See what kind of dirent interface we have unless autoconf has already
|
||||
* determinated that.
|
||||
*/
|
||||
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
|
||||
# if defined(_MSC_VER) /* Microsoft C/C++ */
|
||||
/* no dirent.h */
|
||||
# elif defined(__BORLANDC__) /* Borland C/C++ */
|
||||
# define HAVE_DIRENT_H
|
||||
# define VOID_CLOSEDIR
|
||||
# elif defined(__TURBOC__) /* Borland Turbo C */
|
||||
/* no dirent.h */
|
||||
# elif defined(__WATCOMC__) /* Watcom C/C++ */
|
||||
# define HAVE_DIRECT_H
|
||||
# elif defined(__apollo) /* Apollo */
|
||||
# define HAVE_SYS_DIR_H
|
||||
# elif defined(__hpux) /* HP-UX */
|
||||
# define HAVE_DIRENT_H
|
||||
# elif defined(__alpha) || defined(__alpha__) /* Alpha OSF1 */
|
||||
# error "not implemented"
|
||||
# elif defined(__sgi) /* Silicon Graphics */
|
||||
# define HAVE_DIRENT_H
|
||||
# elif defined(sun) || defined(_sun) /* Sun Solaris */
|
||||
# define HAVE_DIRENT_H
|
||||
# elif defined(__FreeBSD__) /* FreeBSD */
|
||||
# define HAVE_DIRENT_H
|
||||
# elif defined(__linux__) /* Linux */
|
||||
# define HAVE_DIRENT_H
|
||||
# elif defined(__GNUC__) /* GNU C/C++ */
|
||||
# define HAVE_DIRENT_H
|
||||
# else
|
||||
# error "not implemented"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* include proper interface headers */
|
||||
#if defined(HAVE_DIRENT_H)
|
||||
# include <dirent.h>
|
||||
# ifdef FREEBSD
|
||||
# define NAMLEN(dp) ((int)((dp)->d_namlen))
|
||||
# else
|
||||
# define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
|
||||
# endif
|
||||
|
||||
#elif defined(HAVE_NDIR_H)
|
||||
# include <ndir.h>
|
||||
# define NAMLEN(dp) ((int)((dp)->d_namlen))
|
||||
|
||||
#elif defined(HAVE_SYS_NDIR_H)
|
||||
# include <sys/ndir.h>
|
||||
# define NAMLEN(dp) ((int)((dp)->d_namlen))
|
||||
|
||||
#elif defined(HAVE_DIRECT_H)
|
||||
# include <direct.h>
|
||||
# define NAMLEN(dp) ((int)((dp)->d_namlen))
|
||||
|
||||
#elif defined(HAVE_DIR_H)
|
||||
# include <dir.h>
|
||||
# define NAMLEN(dp) ((int)((dp)->d_namlen))
|
||||
|
||||
#elif defined(HAVE_SYS_DIR_H)
|
||||
# include <sys/types.h>
|
||||
# include <sys/dir.h>
|
||||
# ifndef dirent
|
||||
# define dirent direct
|
||||
# endif
|
||||
# define NAMLEN(dp) ((int)((dp)->d_namlen))
|
||||
|
||||
#elif defined(MSDOS) || defined(WIN32)
|
||||
|
||||
/* figure out type of underlaying directory interface to be used */
|
||||
# if defined(WIN32)
|
||||
# define DIRENT_WIN32_INTERFACE
|
||||
# elif defined(MSDOS)
|
||||
# define DIRENT_MSDOS_INTERFACE
|
||||
# else
|
||||
# error "missing native dirent interface"
|
||||
# endif
|
||||
|
||||
/*** WIN32 specifics ***/
|
||||
# if defined(DIRENT_WIN32_INTERFACE)
|
||||
# include <windows.h>
|
||||
# if !defined(DIRENT_MAXNAMLEN)
|
||||
# define DIRENT_MAXNAMLEN (MAX_PATH)
|
||||
# endif
|
||||
|
||||
|
||||
/*** MS-DOS specifics ***/
|
||||
# elif defined(DIRENT_MSDOS_INTERFACE)
|
||||
# include <dos.h>
|
||||
|
||||
/* Borland defines file length macros in dir.h */
|
||||
# if defined(__BORLANDC__)
|
||||
# include <dir.h>
|
||||
# if !defined(DIRENT_MAXNAMLEN)
|
||||
# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
|
||||
# endif
|
||||
# if !defined(_find_t)
|
||||
# define _find_t find_t
|
||||
# endif
|
||||
|
||||
/* Turbo C defines ffblk structure in dir.h */
|
||||
# elif defined(__TURBOC__)
|
||||
# include <dir.h>
|
||||
# if !defined(DIRENT_MAXNAMLEN)
|
||||
# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
|
||||
# endif
|
||||
# define DIRENT_USE_FFBLK
|
||||
|
||||
/* MSVC */
|
||||
# elif defined(_MSC_VER)
|
||||
# if !defined(DIRENT_MAXNAMLEN)
|
||||
# define DIRENT_MAXNAMLEN (12)
|
||||
# endif
|
||||
|
||||
/* Watcom */
|
||||
# elif defined(__WATCOMC__)
|
||||
# if !defined(DIRENT_MAXNAMLEN)
|
||||
# if defined(__OS2__) || defined(__NT__)
|
||||
# define DIRENT_MAXNAMLEN (255)
|
||||
# else
|
||||
# define DIRENT_MAXNAMLEN (12)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/*** generic MS-DOS and MS-Windows stuff ***/
|
||||
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
|
||||
# define NAME_MAX DIRENT_MAXNAMLEN
|
||||
# endif
|
||||
# if NAME_MAX < DIRENT_MAXNAMLEN
|
||||
# error "assertion failed: NAME_MAX >= DIRENT_MAXNAMLEN"
|
||||
# endif
|
||||
|
||||
|
||||
/*
|
||||
* Substitute for real dirent structure. Note that d_name field is a
|
||||
* true character array although we have it copied in the implementation
|
||||
* dependent data. We could save some memory if we had declared d_name
|
||||
* as a pointer refering the name within implementation dependent data.
|
||||
* We have not done that since some code may rely on sizeof(d_name) to be
|
||||
* something other than four. Besides, directory entries are typically so
|
||||
* small that it takes virtually no time to copy them from place to place.
|
||||
*/
|
||||
typedef struct dirent {
|
||||
char d_name[NAME_MAX + 1];
|
||||
|
||||
/*** Operating system specific part ***/
|
||||
# if defined(DIRENT_WIN32_INTERFACE) /*WIN32*/
|
||||
WIN32_FIND_DATA data;
|
||||
# elif defined(DIRENT_MSDOS_INTERFACE) /*MSDOS*/
|
||||
# if defined(DIRENT_USE_FFBLK)
|
||||
struct ffblk data;
|
||||
# else
|
||||
struct _find_t data;
|
||||
# endif
|
||||
# endif
|
||||
} dirent;
|
||||
|
||||
/*
|
||||
* DIR substitute structure containing directory name. The name is
|
||||
* essential for the operation of rewinndir() function.
|
||||
*/
|
||||
typedef struct DIR {
|
||||
char *dirname; /* directory being scanned */
|
||||
dirent current; /* current entry */
|
||||
int dirent_filled; /* is current un-processed? */
|
||||
|
||||
/*** Operating system specific part ***/
|
||||
# if defined(DIRENT_WIN32_INTERFACE)
|
||||
HANDLE search_handle;
|
||||
# elif defined(DIRENT_MSDOS_INTERFACE)
|
||||
# endif
|
||||
} DIR;
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* prototypes of public dirent functions */
|
||||
static DIR *opendir (const char *dirname);
|
||||
static struct dirent *readdir (DIR *dirp);
|
||||
static int closedir (DIR *dirp);
|
||||
static void rewinddir (DIR *dirp);
|
||||
|
||||
/*
|
||||
* Implement dirent interface as static functions so that the user does not
|
||||
* need to change his project in any way to use dirent function. With this
|
||||
* it is sufficient to include this very header from source modules using
|
||||
* dirent functions and the functions will be pulled in automatically.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* use ffblk instead of _find_t if requested */
|
||||
#if defined(DIRENT_USE_FFBLK)
|
||||
# define _A_ARCH (FA_ARCH)
|
||||
# define _A_HIDDEN (FA_HIDDEN)
|
||||
# define _A_NORMAL (0)
|
||||
# define _A_RDONLY (FA_RDONLY)
|
||||
# define _A_SUBDIR (FA_DIREC)
|
||||
# define _A_SYSTEM (FA_SYSTEM)
|
||||
# define _A_VOLID (FA_LABEL)
|
||||
# define _dos_findnext(dest) findnext(dest)
|
||||
# define _dos_findfirst(name,flags,dest) findfirst(name,dest,flags)
|
||||
#endif
|
||||
|
||||
/* internal prototypes */
|
||||
static int _initdir (DIR *p);
|
||||
static const char *_getdirname (const struct dirent *dp);
|
||||
static void _setdirname (struct DIR *dirp);
|
||||
|
||||
|
||||
/*
|
||||
* Open directory stream DIRNAME for read and return pointer to the
|
||||
* internal working area that is used for retrieving individual directory
|
||||
* entries. The internal working area has no fields of your interest.
|
||||
*/
|
||||
static DIR *
|
||||
opendir(
|
||||
const char *dirname)
|
||||
{
|
||||
DIR *dirp;
|
||||
assert (dirname != NULL);
|
||||
|
||||
dirp = (DIR*)malloc (sizeof (struct DIR));
|
||||
if (dirp != NULL) {
|
||||
char *p;
|
||||
|
||||
/* allocate room for directory name */
|
||||
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
|
||||
if (dirp->dirname == NULL) {
|
||||
/* failed to duplicate directory name. errno set by malloc() */
|
||||
free (dirp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy directory name while appending directory separator and "*.*".
|
||||
* Directory separator is not appended if the name already ends with
|
||||
* drive or directory separator. Directory separator is assumed to be
|
||||
* '/' or '\' and drive separator is assumed to be ':'.
|
||||
*/
|
||||
strcpy (dirp->dirname, dirname);
|
||||
p = strchr (dirp->dirname, '\0');
|
||||
if (dirp->dirname < p &&
|
||||
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
|
||||
{
|
||||
strcpy (p++, "\\");
|
||||
}
|
||||
# ifdef DIRENT_WIN32_INTERFACE
|
||||
strcpy (p, "*"); /*scan files with and without extension in win32*/
|
||||
# else
|
||||
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
|
||||
# endif
|
||||
|
||||
/* open stream */
|
||||
if (_initdir (dirp) == 0) {
|
||||
/* initialization failed */
|
||||
free (dirp->dirname);
|
||||
free (dirp);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return dirp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Read a directory entry and return pointer to a structure containing the
|
||||
* name of the entry. Individual directory entries returned by this very
|
||||
* function include normal files, sub-directories, pseudo-directories "."
|
||||
* and ".." and also volume labels, hidden files and system files in MS-DOS
|
||||
* and MS-Windows. You might want to use stat(2) function to determinate
|
||||
* which one you are dealing with.
|
||||
*
|
||||
* The dirent structure contains several system dependent fields that
|
||||
* generally have no interest to you. The only interesting one is char
|
||||
* d_name[] that is also portable across different systems. The d_name
|
||||
* field contains the name of the directory entry without leading path.
|
||||
* While d_name is portable across different systems, the actual storage
|
||||
* capacity of d_name varies from system to system and there is no portable
|
||||
* way to find out it at compile time. Different systems define the
|
||||
* capacity of d_name with different macros and some systems do not define
|
||||
* capacity at all (besides actual declaration of the field). If you really
|
||||
* need to find out storage capacity of d_name then you might want to try
|
||||
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
|
||||
* there are many MS-DOS and MS-Windows implementations those do not define
|
||||
* it. There are also systems that declare d_name as "char d_name[1]" and
|
||||
* then allocate suitable amount of memory at run-time. Thanks to Alain
|
||||
* Decamps (Alain dot Decamps atsign advalvas dot be) for pointing it out to
|
||||
* me.
|
||||
*
|
||||
* This all leads to the fact that it is difficult to allocate space
|
||||
* for the directory names when the very same program is being compiled on
|
||||
* number of operating systems. Therefore I suggest that you always
|
||||
* allocate space for directory names dynamically.
|
||||
*/
|
||||
static struct dirent *
|
||||
readdir (DIR *dirp)
|
||||
{
|
||||
assert (dirp != NULL);
|
||||
if (dirp == NULL) {
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(DIRENT_WIN32_INTERFACE)
|
||||
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
|
||||
/* directory stream was opened/rewound incorrectly or it ended normally */
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (dirp->dirent_filled != 0) {
|
||||
/*
|
||||
* Directory entry has already been retrieved and there is no need to
|
||||
* retrieve a new one. Directory entry will be retrieved in advance
|
||||
* when the user calls readdir function for the first time. This is so
|
||||
* because real dirent has separate functions for opening and reading
|
||||
* the stream whereas Win32 and DOS dirents open the stream
|
||||
* automatically when we retrieve the first file. Therefore, we have to
|
||||
* save the first file when opening the stream and later we have to
|
||||
* return the saved entry when the user tries to read the first entry.
|
||||
*/
|
||||
dirp->dirent_filled = 0;
|
||||
} else {
|
||||
/* fill in entry and return that */
|
||||
#if defined(DIRENT_WIN32_INTERFACE)
|
||||
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
|
||||
/* Last file has been processed or an error occured */
|
||||
FindClose (dirp->search_handle);
|
||||
dirp->search_handle = INVALID_HANDLE_VALUE;
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
# elif defined(DIRENT_MSDOS_INTERFACE)
|
||||
if (_dos_findnext (&dirp->current.data) != 0) {
|
||||
/* _dos_findnext and findnext will set errno to ENOENT when no
|
||||
* more entries could be retrieved. */
|
||||
return NULL;
|
||||
}
|
||||
# endif
|
||||
|
||||
_setdirname (dirp);
|
||||
assert (dirp->dirent_filled == 0);
|
||||
}
|
||||
return &dirp->current;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Close directory stream opened by opendir() function. Close of the
|
||||
* directory stream invalidates the DIR structure as well as any previously
|
||||
* read directory entry.
|
||||
*
|
||||
* Usually, the function returns 0 on success and -1 on failure. However,
|
||||
* on some systems, the function has been declared to return void. If you
|
||||
* want to keep your code portable, it may be better to ignore the return
|
||||
* value altogether.
|
||||
*/
|
||||
static int
|
||||
closedir (DIR *dirp)
|
||||
{
|
||||
int retcode = 0;
|
||||
|
||||
/* make sure that dirp points to legal structure */
|
||||
assert (dirp != NULL);
|
||||
if (dirp == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* free directory name */
|
||||
if (dirp->dirname != NULL) {
|
||||
free (dirp->dirname);
|
||||
}
|
||||
|
||||
/* release search handle */
|
||||
#if defined(DIRENT_WIN32_INTERFACE)
|
||||
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
|
||||
if (FindClose (dirp->search_handle) == FALSE) {
|
||||
/* Unknown error */
|
||||
retcode = -1;
|
||||
errno = EBADF;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* clear dirp structure to make sure that it cannot be used anymore*/
|
||||
memset (dirp, 0, sizeof (*dirp));
|
||||
# if defined(DIRENT_WIN32_INTERFACE)
|
||||
dirp->search_handle = INVALID_HANDLE_VALUE;
|
||||
# endif
|
||||
|
||||
free (dirp);
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Rewind the directory stream to re-read the directory entries. If new
|
||||
* files or directories have been created since opendir(), then also these
|
||||
* new files will be available with readdir().
|
||||
*
|
||||
* Almost every dirent implementation ensures that rewinddir() updates its
|
||||
* internal caches to reflect the current directory structure on disk.
|
||||
* However, if you really depend on this feature, it may be better to close
|
||||
* and re-open the directory stream. I recall one particual dirent
|
||||
* interface, where rewinddir() did not update its internal cache.
|
||||
*
|
||||
* BUGS: If the current working directory is changed between opendir() and
|
||||
* rewinddir(), then the rewound directory stream may refer a non-existent
|
||||
* directory, or at worst case, to another directory.
|
||||
*/
|
||||
static void
|
||||
rewinddir (DIR *dirp)
|
||||
{
|
||||
/* make sure that dirp is legal */
|
||||
assert (dirp != NULL);
|
||||
if (dirp == NULL) {
|
||||
errno = EBADF;
|
||||
return;
|
||||
}
|
||||
assert (dirp->dirname != NULL);
|
||||
|
||||
/* close previous stream */
|
||||
#if defined(DIRENT_WIN32_INTERFACE)
|
||||
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
|
||||
if (FindClose (dirp->search_handle) == FALSE) {
|
||||
/* Unknown error */
|
||||
errno = EBADF;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* re-open previous stream */
|
||||
if (_initdir (dirp) == 0) {
|
||||
/* initialization failed but we cannot deal with error. User will notice
|
||||
* error later when she tries to retrieve first directory enty. */
|
||||
/*EMPTY*/;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Open native directory stream object and retrieve first file.
|
||||
* Be sure to close previous stream before opening new one.
|
||||
*/
|
||||
static int
|
||||
_initdir (DIR *dirp)
|
||||
{
|
||||
assert (dirp != NULL);
|
||||
assert (dirp->dirname != NULL);
|
||||
dirp->dirent_filled = 0;
|
||||
|
||||
# if defined(DIRENT_WIN32_INTERFACE)
|
||||
/* Open stream and retrieve first file */
|
||||
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
|
||||
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
|
||||
/* something went wrong but we don't know what. GetLastError() could
|
||||
* give us more information about the error, but then we should map
|
||||
* the error code into errno. */
|
||||
errno = ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
# elif defined(DIRENT_MSDOS_INTERFACE)
|
||||
if (_dos_findfirst (dirp->dirname,
|
||||
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
|
||||
&dirp->current.data) != 0)
|
||||
{
|
||||
/* _dos_findfirst and findfirst will set errno to ENOENT when no
|
||||
* more entries could be retrieved. */
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
/* initialize DIR and it's first entry */
|
||||
_setdirname (dirp);
|
||||
dirp->dirent_filled = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Return implementation dependent name of the current directory entry.
|
||||
*/
|
||||
static const char *
|
||||
_getdirname (const struct dirent *dp)
|
||||
{
|
||||
#if defined(DIRENT_WIN32_INTERFACE)
|
||||
return dp->data.cFileName;
|
||||
|
||||
#elif defined(DIRENT_USE_FFBLK)
|
||||
return dp->data.ff_name;
|
||||
|
||||
#else
|
||||
return dp->data.name;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Copy name of implementation dependent directory entry to the d_name field.
|
||||
*/
|
||||
static void
|
||||
_setdirname (struct DIR *dirp) {
|
||||
/* make sure that d_name is long enough */
|
||||
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
|
||||
|
||||
strncpy (dirp->current.d_name,
|
||||
_getdirname (&dirp->current),
|
||||
NAME_MAX);
|
||||
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
|
||||
}
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
|
||||
|
||||
#else
|
||||
# error "missing dirent interface"
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*DIRENT_H*/
|
Loading…
x
Reference in New Issue
Block a user