]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/BufFileInput.cpp
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / Pccts / h / BufFileInput.cpp
diff --git a/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/BufFileInput.cpp b/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/BufFileInput.cpp
new file mode 100644 (file)
index 0000000..99d08a4
--- /dev/null
@@ -0,0 +1,100 @@
+// FILE:        BufFileInput.cpp\r
+// AUTHOR:      Alexey Demakov (AVD) demakov@kazbek.ispras.ru\r
+// CREATION:    26-JAN-1998\r
+// DESCRIPTION: File Input Stream with lookahead for Scanner.\r
+//   See file BufFileInput.h for details\r
+\r
+// Change History:\r
+//\r
+//   22-Jun-1998    assert.h -> PCCTS_ASSERT_H\r
+//                  string.h -> PCCTS_STRING_H\r
+//\r
+//   28-May-1998    Add virtual destructor to release buffer.\r
+//\r
+//                  Add dummy definition for ANTLRTokenType\r
+//                  to allow compilation without knowing\r
+//                  token type codes.\r
+//\r
+//                  Manfred Kogler (km@cast.uni-linz.ac.at)\r
+//                  (1.33MR14)\r
+//\r
+//   20-Jul-1998    MR14a - Reorder initialization list for ctor.\r
+//\r
+\r
+enum ANTLRTokenType {TER_HATES_CPP=0, SO_DO_OTHERS=9999 };\r
+\r
+#include "pcctscfg.h"\r
+#include "pccts_assert.h"\r
+#include "pccts_string.h"\r
+\r
+PCCTS_NAMESPACE_STD\r
+\r
+#include "BufFileInput.h"\r
+\r
+BufFileInput::BufFileInput( FILE *f, int buf_size )\r
+: input( f ),\r
+  buf( new int[buf_size] ),\r
+  size( buf_size ),\r
+  start( 0 ),\r
+  len( 0 )\r
+{\r
+}\r
+\r
+BufFileInput::~BufFileInput()\r
+{\r
+  delete [] buf;\r
+}\r
+\r
+int BufFileInput::nextChar( void )\r
+{\r
+    if( len > 0 )\r
+    {\r
+        // get char from buffer\r
+        int c = buf[start];\r
+\r
+        if( c != EOF )\r
+        {\r
+            start++; start %= size;\r
+            len--;\r
+        }\r
+        return c;\r
+    } else {\r
+        // get char from file\r
+        int c = getc( input );\r
+\r
+        if( c == EOF )\r
+        {\r
+            // if EOF - put it in the buffer as indicator\r
+            buf[start] = EOF;\r
+            len++;\r
+        }\r
+        return c;\r
+    }\r
+}\r
+\r
+int BufFileInput::lookahead( char* s )\r
+{\r
+    int l = strlen( s );\r
+\r
+    assert( 0 < l && l <= size );\r
+\r
+    while( len < l )\r
+    {\r
+        int c = getc( input );\r
+\r
+        buf[ (start+len) % size ] = c;\r
+\r
+        len++;\r
+\r
+        if( c == EOF ) return 0;\r
+    }\r
+\r
+    for( int i = 0; i < l; i++ )\r
+    {\r
+        if( s[i] != buf[ (start+i) % size ] ) return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+// End of file BufFileInput.cpp\r
+\r