diff anagram/agcore/textfile.h @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/anagram/agcore/textfile.h	Sat Dec 22 17:52:45 2007 -0500
@@ -0,0 +1,53 @@
+/*
+ * AnaGram, A System for Syntax Directed Programming
+ * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
+ * See the file COPYING for license and usage terms.
+ *
+ * textfile.h
+ */
+
+#ifndef TEXTFILE_H
+#define TEXTFILE_H
+
+#include "agarray.h"
+#include "agstring.h"
+#include "cint.h"
+#include "search.h"
+
+class text_file {
+public:
+  AgString name;           /* name of file */
+  AgString text;           /* body of file */
+  AgArray<int> lx;           /* array of line indices */
+  unsigned width;          /* length of longest line? */
+  unsigned stringLength;
+  int truncated;
+  int readFlags;
+
+  // Constructors
+
+  text_file(void) : lx(), width(0) {}
+  text_file(const char *);
+  text_file(const AgString s);
+  text_file(const char *, int flags /* = O_TEXT|O_RDONLY */);
+  text_file(const AgString s, int flags /* = O_TEXT|O_RDONLY */);
+
+  text_file(const text_file &t);
+
+  text_file &operator = (const text_file &t);
+  void find_lines(void);
+  void read_file(int flags);
+  void read_file();
+  cint size() const { return cint(width, lx.size()); }
+  operator char * (void) const { return text.pointer(); }
+  operator unsigned char * (void) const {
+    return (unsigned char *) text.pointer();
+  }
+  char *line(const unsigned ln) const { return text.pointer() + lx[ln]; }
+
+  SearchProcess searchProcess;
+  int findNext(cint &loc, AgString s);
+  int findPrev(cint &loc, AgString s);
+};
+
+#endif /* TEXTFILE_H */