stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r321199 - /incubator/stdcxx/trunk/etc/config/src/NEWLINE.cpp
Date Fri, 14 Oct 2005 20:05:16 GMT
Author: sebor
Date: Fri Oct 14 13:05:10 2005
New Revision: 321199

URL: http://svn.apache.org/viewcvs?rev=321199&view=rev
Log:
2005-10-14  Martin Sebor  <sebor@roguewave.com>

	* NEWLINE.cpp: New test to determine the newline character sequence,
	or one of <CR>, <CR><LF>, or <LF>.

Added:
    incubator/stdcxx/trunk/etc/config/src/NEWLINE.cpp   (with props)

Added: incubator/stdcxx/trunk/etc/config/src/NEWLINE.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/NEWLINE.cpp?rev=321199&view=auto
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/NEWLINE.cpp (added)
+++ incubator/stdcxx/trunk/etc/config/src/NEWLINE.cpp Fri Oct 14 13:05:10 2005
@@ -0,0 +1,96 @@
+// checking for newline (CR or CR-LF)
+
+#include <stdio.h>
+
+int main ()
+{
+#if !defined (_RWSTD_USE_CONFIG)
+
+    printf ("/**/\n#undef _RWSTD_NEWLINE\n");
+
+#endif   // _RWSTD_USE_CONFIG
+
+    // determine the byte sequence that corresponds to the '\n'
+    // source character, i.e., one of
+    //   <CR>     -- Apple II and Mac OS
+    //   <LF>     -- UNIX systems
+    //   <CR><LF> -- CP/M, DOS, Windows
+    //   <LF><CR> -- unknown
+
+    char fname [256];
+    if (0 == tmpnam (fname))
+        return 1;
+
+    FILE *fp = fopen (fname, "w");
+    if (0 == fp)
+        return 2;
+
+    fprintf (fp, "%s", "a\nb");
+    fclose (fp);
+
+    fp = fopen (fname, "rb");
+    if (0 == fp)
+        return 3;
+
+    char buffer [32] = "";
+
+    size_t nbytes = fread (buffer, 1, sizeof buffer, fp);
+
+    fclose (fp);
+    remove (fname);
+
+    char *pc;
+
+    for (pc = buffer; *pc && *pc != '\n'; ++pc);
+
+    if ('\0' == *pc) {
+
+        for (pc = buffer; *pc && *pc != '\r'; ++pc);
+
+        if ('\0' == *pc) {
+
+#if 'A' == '\x41'   // ASCII
+
+            // no newline?
+            return 4;
+            
+
+#elif 'A' == '\xc1'   // EBCDIC
+
+            
+            for (pc = buffer; *pc && *pc != '\x15'; ++pc);
+
+            if ('\0' == *pc) {
+                // no newline?
+                return 4;
+            }
+
+            printf ("#define _RWSTD_NEWLINE \"\\x15\"\n");
+            printf ("#define _RWSTD_NEWLINE_NEL\n");
+
+#endif   // ASCII or EBCDIC
+
+        }
+        else {
+
+            printf ("#define _RWSTD_NEWLINE \"\\r\"\n");
+            printf ("#define _RWSTD_NEWLINE_CR\n");
+        }
+    }
+    else {
+        if ('\r' == pc [1]) {
+            printf ("#define _RWSTD_NEWLINE \"\\n\\r\"\n");
+            printf ("#define _RWSTD_NEWLINE_LF_CR\n");
+        }
+        if ('\r' == pc [-1]) {
+            printf ("#define _RWSTD_NEWLINE \"\\r\\n\"\n");
+            printf ("#define _RWSTD_NEWLINE_CR_LF\n");
+        }
+        else {
+            printf ("#define _RWSTD_NEWLINE \"\\n\"\n");
+            printf ("#define _RWSTD_NEWLINE_LF\n");
+        }
+    }
+
+    return 0;
+}

Propchange: incubator/stdcxx/trunk/etc/config/src/NEWLINE.cpp
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message