[This patch is good in terms of details (ChangeLog entry and so on), but I sort of wonder whether it is just adding hair and complication on top of code which is already too hairy and complicated. For an alternative approach, see the "gzip library" patch. -kingdon, 1997] Date: Mon, 24 Nov 1997 11:38:11 +0000 To: kingdon@cyclic.com From: Andy Piper Subject: CRLF patch Hope this is up to spec... andy Below are HACKING compliant (I hope) patches and descriptions for my beefed up CRLF change. Patches against 1.9.20. Rationale: LINES_CRLF_DEFINED *must* be defined on systems where the open mode of files matters (binary vs text) and where lines are crlf terminated. This patch makes configure detect the presence of CRLF systems and consequently defines LINES_CRLF_DEFINED. In order to compile the function convert_file must be in filesubr.c so the patch places a copy in the main src/filesubr.c. This does not affect the native NT port since src/filesubr.c is replaced (not used). It does not affect anything else since the function is only compiled in if LINES_CRLF_DEFINED is defined. The configure test is safe since the default is no (if the test fails for any reason). I have tested this on solaris 2.5.1/gcc and gnuwin32. autoconf 2.10. ChangeLog entry: Mon Nov 24 11:29:21 1997 * src/filesubr.c (convert_file): added from windows-NT/filesubr.c so that defining LINES_CRLF_DEFINED doesn't prevent compilation. * configure.in: add test for CRLF termination and define LINES_CRLF_DEFINED appropriately. * config.h.in: add LINES_CRLF_DEFINED undef for test in configure. *** src/filesubr.c 1997/11/24 11:15:15 1.1 --- src/filesubr.c 1997/11/24 11:21:17 *************** *** 879,881 **** --- 879,911 ---- return retval; } #endif /* SERVER_SUPPORT */ + + #ifdef LINES_CRLF_TERMINATED + /* Read data from INFILE, and copy it to OUTFILE. + Open INFILE using INFLAGS, and OUTFILE using OUTFLAGS. + This is useful for converting between CRLF and LF line formats. */ + void + convert_file (char *infile, int inflags, + char *outfile, int outflags) + { + int infd, outfd; + char buf[8192]; + int len; + + if ((infd = open (infile, inflags)) < 0) + error (1, errno, "couldn't read %s", infile); + if ((outfd = open (outfile, outflags, S_IWRITE)) < 0) + error (1, errno, "couldn't write %s", outfile); + + while ((len = read (infd, buf, sizeof (buf))) > 0) + if (write (outfd, buf, len) < 0) + error (1, errno, "error writing %s", outfile); + if (len < 0) + error (1, errno, "error reading %s", infile); + + if (close (outfd) < 0) + error (0, errno, "warning: couldn't close %s", outfile); + if (close (infd) < 0) + error (0, errno, "warning: couldn't close %s", infile); + } + #endif *** config.h.in 1997/11/20 13:09:23 1.1 --- config.h.in 1997/11/24 11:23:16 *************** *** 242,244 **** --- 242,247 ---- /* Define if you have the socket library (-lsocket). */ #undef HAVE_LIBSOCKET + + /* Define if your systems uses CR/LF to terminate text lines. */ + #undef LINES_CRLF_TERMINATED *** configure.in 1997/11/20 11:20:11 1.1 --- configure.in 1997/11/20 16:13:25 *************** *** 150,155 **** --- 150,179 ---- fi AC_MSG_RESULT($ccvs_cv_sys_working_fnmatch) + AC_MSG_CHECKING([for CR/LF line termination]) + AC_CACHE_VAL(ccvs_crlf_termination, + [AC_TRY_RUN([ + #include + + int main() + { + FILE* t; + t = fopen("testcrlf", "w"); + fprintf(t, "\n\n"); + fclose(t); + t = fopen("testcrlf", "rb"); + fseek(t, 0, SEEK_END); + fclose(t); + exit (ftell(t)==4 ? 0 : -1); + }], + ccvs_crlf_termination=yes, + ccvs_crlf_termination=no, + ccvs_crlf_termination=no)]) + if test $ccvs_crlf_termination = yes; then + AC_DEFINE(LINES_CRLF_TERMINATED) + fi + AC_MSG_RESULT($ccvs_crlf_termination) + # If we can't find connect, try looking in -lsocket, -lnsl, and -linet. # The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has # libsocket.so which has a bad implementation of gethostbyname (it ___ ____ Dr Andy Piper / _ \___ ________ _/ / Solutions_ (require 'disclaimer) / ___/ _ `/ __/ _ `/ / / _ `/\ \ / andyp@parallax.co.uk /_/ \_,_/_/ \_,_/_/_/\_,_//_\_\ boot /vmemacs