// File index: a list of all words and the lines on which they occur // This program requires .Net version 2.0. // Peter Sestoft (sestoft@itu.dk) 2001-11-30, 2003-08-11 // Compile GCollections.cs with // csc /t:module GCollections.cs // Then compile this file with // csc /addmodule:GCollections.netmodule FileIndex.cs using System; using System.IO; using System.Text.RegularExpressions; using GCollections; // For LinkedList class Fileindex { static void Main(String[] args) { if (args.Length != 1) Console.WriteLine("Usage: Fileindex \n"); else IndexFile(args[0]); } static void IndexFile(String filename) { TreeMap> index = new OTreeMap>(); Regex delim = new Regex("[^a-zA-Z0-9]+"); TextReader rd = new StreamReader(filename); int lineno = 0; String line; while (null != (line = rd.ReadLine())) { String[] res = delim.Split(line); lineno++; foreach (String s in res) if (s != "") { if (!index.Contains(s)) index[s] = new OTreeSet(); index[s].Add(lineno); } } rd.Close(); foreach (MapEntry> wordlist in index) { Console.Write("{0}: ", wordlist.Key); foreach (int ln in wordlist.Value) Console.Write(ln + " "); Console.WriteLine(); } } }