Skip to content
Browse files

Added various program options to the user interface.

+ A trailing slash is removed from the source path by the directory reader.
+ Added UI output of the processing time.
+ Added UI option to print lines to the console.
+ Changed read mode switch to radio group in the user interface.
+ Minor bugfix: Empty files are not read.
  • Loading branch information...
1 parent 0c896b0 commit ab074ffa3f81026640f44a727cf4b8a1945c1a9a @johnjohndoe committed Oct 12, 2010
Showing with 567 additions and 150 deletions.
  1. +4 −1 DirectoryReader.m
  2. +434 −94 English.lproj/MainMenu.xib
  3. +4 −2 FileReader.m
  4. +24 −7 LineReaderAppDelegate.h
  5. +101 −46 LineReaderAppDelegate.m
View
5 DirectoryReader.m
@@ -27,7 +27,10 @@ - (id)initWithPath:(NSString*)path {
if (!path || [path length] <= 0) {
return nil;
}
- m_path = path;
+ // Remove trailing slash if appended.
+ NSMutableString* mutablePath = [NSMutableString stringWithString:path];
+ [mutablePath replaceOccurrencesOfString:@"/" withString:@"" options:NSBackwardsSearch range:NSMakeRange([path length] - 1, 1)];
+ m_path = mutablePath;
}
return self;
}
View
528 English.lproj/MainMenu.xib
@@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="371"/>
+ <integer value="372"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1317,7 +1317,7 @@
<object class="NSWindowTemplate" id="972006081">
<int key="NSWindowStyleMask">15</int>
<int key="NSWindowBacking">2</int>
- <string key="NSWindowRect">{{781, 842}, {499, 160}}</string>
+ <string key="NSWindowRect">{{781, 737}, {499, 265}}</string>
<int key="NSWTFlags">1954021376</int>
<string key="NSWindowTitle">LineReader</string>
<string key="NSWindowClass">NSWindow</string>
@@ -1331,7 +1331,7 @@
<object class="NSTextField" id="231717339">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{20, 90}, {459, 22}}</string>
+ <string key="NSFrame">{{20, 195}, {459, 22}}</string>
<reference key="NSSuperview" ref="439893737"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="355415411">
@@ -1345,16 +1345,16 @@
</object>
<reference key="NSControlView" ref="231717339"/>
<bool key="NSDrawsBackground">YES</bool>
- <object class="NSColor" key="NSBackgroundColor">
+ <object class="NSColor" key="NSBackgroundColor" id="741515319">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">textBackgroundColor</string>
- <object class="NSColor" key="NSColor">
+ <object class="NSColor" key="NSColor" id="790798663">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
</object>
- <object class="NSColor" key="NSTextColor">
+ <object class="NSColor" key="NSTextColor" id="172872310">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">textColor</string>
@@ -1368,7 +1368,7 @@
<object class="NSTextField" id="1045706751">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{17, 120}, {108, 17}}</string>
+ <string key="NSFrame">{{17, 225}, {108, 17}}</string>
<reference key="NSSuperview" ref="439893737"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="183607361">
@@ -1397,7 +1397,7 @@
<object class="NSStepper" id="1013929455">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{463, 51}, {19, 27}}</string>
+ <string key="NSFrame">{{350, 155}, {19, 27}}</string>
<reference key="NSSuperview" ref="439893737"/>
<bool key="NSEnabled">YES</bool>
<object class="NSStepperCell" key="NSCell" id="372307018">
@@ -1409,51 +1409,191 @@
<bool key="NSAutorepeat">YES</bool>
</object>
</object>
- <object class="NSTextField" id="293172749">
+ <object class="NSTextField" id="449809172">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{17, 56}, {444, 17}}</string>
+ <string key="NSFrame">{{17, 161}, {230, 17}}</string>
<reference key="NSSuperview" ref="439893737"/>
<bool key="NSEnabled">YES</bool>
- <object class="NSTextFieldCell" key="NSCell" id="844018831">
+ <object class="NSTextFieldCell" key="NSCell" id="630023291">
<int key="NSCellFlags">68288064</int>
<int key="NSCellFlags2">71304192</int>
- <string key="NSContents">Count</string>
+ <string key="NSContents">Maximum numbers of lines:</string>
<reference key="NSSupport" ref="953681415"/>
- <reference key="NSControlView" ref="293172749"/>
- <bool key="NSDrawsBackground">YES</bool>
+ <reference key="NSControlView" ref="449809172"/>
<reference key="NSBackgroundColor" ref="685989597"/>
<reference key="NSTextColor" ref="249716613"/>
</object>
</object>
- <object class="NSTextField" id="449809172">
+ <object class="NSTextField" id="202252264">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{17, 56}, {368, 17}}</string>
+ <string key="NSFrame">{{255, 158}, {90, 22}}</string>
<reference key="NSSuperview" ref="439893737"/>
<bool key="NSEnabled">YES</bool>
- <object class="NSTextFieldCell" key="NSCell" id="630023291">
+ <object class="NSTextFieldCell" key="NSCell" id="2523817">
+ <int key="NSCellFlags">-1804468671</int>
+ <int key="NSCellFlags2">71304192</int>
+ <string key="NSContents"/>
+ <reference key="NSSupport" ref="953681415"/>
+ <reference key="NSControlView" ref="202252264"/>
+ <bool key="NSDrawsBackground">YES</bool>
+ <reference key="NSBackgroundColor" ref="741515319"/>
+ <reference key="NSTextColor" ref="172872310"/>
+ </object>
+ </object>
+ <object class="NSButton" id="196243322">
+ <reference key="NSNextResponder" ref="439893737"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{249, 47}, {128, 32}}</string>
+ <reference key="NSSuperview" ref="439893737"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSButtonCell" key="NSCell" id="865326817">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">134217728</int>
+ <string key="NSContents">Read lines</string>
+ <reference key="NSSupport" ref="953681415"/>
+ <reference key="NSControlView" ref="196243322"/>
+ <int key="NSButtonFlags">-2038284033</int>
+ <int key="NSButtonFlags2">129</int>
+ <string key="NSAlternateContents"/>
+ <string key="NSKeyEquivalent"/>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ </object>
+ <object class="NSMatrix" id="198904918">
+ <reference key="NSNextResponder" ref="439893737"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{253, 127}, {192, 17}}</string>
+ <reference key="NSSuperview" ref="439893737"/>
+ <bool key="NSEnabled">YES</bool>
+ <int key="NSNumRows">1</int>
+ <int key="NSNumCols">2</int>
+ <object class="NSMutableArray" key="NSCells">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSButtonCell" id="460734633">
+ <int key="NSCellFlags">-2080244224</int>
+ <int key="NSCellFlags2">0</int>
+ <string key="NSContents">Forwards</string>
+ <reference key="NSSupport" ref="953681415"/>
+ <reference key="NSControlView" ref="198904918"/>
+ <int key="NSButtonFlags">1211912703</int>
+ <int key="NSButtonFlags2">0</int>
+ <object class="NSButtonImageSource" key="NSAlternateImage" id="920884016">
+ <string key="NSImageName">NSRadioButton</string>
+ </object>
+ <string key="NSAlternateContents"/>
+ <string key="NSKeyEquivalent"/>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ <object class="NSButtonCell" id="806254077">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">0</int>
+ <string key="NSContents">Backwards</string>
+ <reference key="NSSupport" ref="953681415"/>
+ <reference key="NSControlView" ref="198904918"/>
+ <int key="NSTag">-1</int>
+ <int key="NSButtonFlags">1211912703</int>
+ <int key="NSButtonFlags2">0</int>
+ <reference key="NSAlternateImage" ref="920884016"/>
+ <int key="NSPeriodicDelay">400</int>
+ <int key="NSPeriodicInterval">75</int>
+ </object>
+ </object>
+ <string key="NSCellSize">{94, 17}</string>
+ <string key="NSIntercellSpacing">{4, 2}</string>
+ <int key="NSMatrixFlags">1151868928</int>
+ <string key="NSCellClass">NSActionCell</string>
+ <object class="NSButtonCell" key="NSProtoCell" id="645343484">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">0</int>
+ <string key="NSContents">Radio</string>
+ <reference key="NSSupport" ref="953681415"/>
+ <int key="NSButtonFlags">1211912703</int>
+ <int key="NSButtonFlags2">0</int>
+ <object class="NSImage" key="NSNormalImage">
+ <int key="NSImageFlags">549453824</int>
+ <string key="NSSize">{18, 18}</string>
+ <object class="NSMutableArray" key="NSReps">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="0"/>
+ <object class="NSBitmapImageRep">
+ <object class="NSData" key="NSTIFFRepresentation">
+ <bytes key="NS.bytes">TU0AKgAABRgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAADwRERGLJycnySsrK/A1NTXw
+IyMjyRwcHIsJCQk8AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFFRUVdVBQUOCoqKj/
+29vb//n5+f/6+vr/2tra/6qqqv9UVFTgHx8fdQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUZGRl5
+dXV198PDw//8/Pz////////////////////////////U1NT/fHx89yUlJXkAAAAFAAAAAAAAAAAAAAAA
+AAAAAxEREUZqamrmtbW1/+3t7f/+/v7//v7+//7+/v/9/f3//f39//39/f/39/f/xMTE/3d3d+YZGRlG
+AAAAAwAAAAAAAAAAAAAACkJCQqGtra3/xsbG/+vr6//y8vL/9fX1//X19f/z8/P/9fX1//Ly8v/u7u7/
+0tLS/6+vr/9KSkqhAAAACgAAAAAAAAAAAAAAF3h4eN2/v7//z8/P/93d3f/q6ur/7+/v/+/v7//w8PD/
+7e3t/+3t7f/i4uL/zs7O/8XFxf98fHzdAAAAFwAAAAAAAAADAAAAJKSkpPjOzs7/2dnZ/+Dg4P/i4uL/
+5eXl/+bm5v/n5+f/5eXl/+Li4v/e3t7/2tra/9DQ0P+srKz4AAAAJAAAAAMAAAADAAAALrCwsPrW1tb/
+3t7e/+Tk5P/p6en/6+vr/+zs7P/p6en/6+vr/+fn5//k5OT/4ODg/9nZ2f+zs7P6AAAALgAAAAMAAAAD
+AAAALp2dnezg4OD/5eXl/+rq6v/u7u7/8PDw//Dw8P/x8fH/8PDw/+7u7v/q6ur/5ubm/+Hh4f+ZmZns
+AAAALgAAAAMAAAADAAAAJG5ubs/l5eX/6enp/+/v7//y8vL/9vb2//r6+v/5+fn/9/f3//b29v/x8fH/
+6+vr/+Tk5P9ra2vPAAAAJAAAAAMAAAAAAAAAFy4uLpPCwsL67Ozs//Pz8//5+fn//v7+//7+/v/+/v7/
+/v7+//v7+//19fX/8PDw/8LCwvosLCyTAAAAFwAAAAAAAAAAAAAACgAAAENfX1/S5OTk/vn5+f/+/v7/
+///////////////////////////8/Pz/5ubm/l9fX9IAAABDAAAACgAAAAAAAAAAAAAAAwAAABcAAABl
+YmJi3NLS0v3////////////////////////////////V1dX9ZGRk3AAAAGUAAAAXAAAAAwAAAAAAAAAA
+AAAAAAAAAAUAAAAfAAAAZTMzM8KAgIDwv7+//O3t7f/t7e3/v7+//ICAgPAzMzPCAAAAZQAAAB8AAAAF
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAFwAAAEMAAAB3AAAAnwAAALMAAACzAAAAnwAAAHcAAABD
+AAAAFwAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAoAAAAXAAAAJAAAAC4AAAAu
+AAAAJAAAABcAAAAKAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQEAAAMAAAABABIAAAEB
+AAMAAAABABIAAAECAAMAAAAEAAAFugEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAERAAQAAAABAAAACAES
+AAMAAAABAAEAAAEVAAMAAAABAAQAAAEWAAMAAAABABIAAAEXAAQAAAABAAAFEAEcAAMAAAABAAEAAAFS
+AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
+ </object>
+ </object>
+ </object>
+ </object>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MCAwAA</bytes>
+ </object>
+ </object>
+ <reference key="NSAlternateImage" ref="920884016"/>
+ <int key="NSPeriodicDelay">400</int>
+ <int key="NSPeriodicInterval">75</int>
+ </object>
+ <reference key="NSSelectedCell" ref="460734633"/>
+ <reference key="NSBackgroundColor" ref="685989597"/>
+ <reference key="NSCellBackgroundColor" ref="790798663"/>
+ <reference key="NSFont" ref="953681415"/>
+ </object>
+ <object class="NSTextField" id="643441890">
+ <reference key="NSNextResponder" ref="439893737"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 128}, {230, 17}}</string>
+ <reference key="NSSuperview" ref="439893737"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="401592038">
<int key="NSCellFlags">68288064</int>
- <int key="NSCellFlags2">272630784</int>
- <string key="NSContents">Maximum numbers of lines to be read from each file:</string>
+ <int key="NSCellFlags2">71304192</int>
+ <string key="NSContents">Reading mode:</string>
<reference key="NSSupport" ref="953681415"/>
- <reference key="NSControlView" ref="449809172"/>
+ <reference key="NSControlView" ref="643441890"/>
<reference key="NSBackgroundColor" ref="685989597"/>
<reference key="NSTextColor" ref="249716613"/>
</object>
</object>
- <object class="NSButton" id="332168038">
+ <object class="NSButton" id="407726537">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{18, 18}, {200, 18}}</string>
+ <string key="NSFrame">{{253, 93}, {155, 18}}</string>
<reference key="NSSuperview" ref="439893737"/>
<bool key="NSEnabled">YES</bool>
- <object class="NSButtonCell" key="NSCell" id="64997876">
+ <object class="NSButtonCell" key="NSCell" id="744190511">
<int key="NSCellFlags">-2080244224</int>
<int key="NSCellFlags2">0</int>
- <string key="NSContents">Read file content backwards</string>
+ <string key="NSContents">Print lines to console</string>
<reference key="NSSupport" ref="953681415"/>
- <reference key="NSControlView" ref="332168038"/>
+ <reference key="NSControlView" ref="407726537"/>
<int key="NSButtonFlags">1211912703</int>
<int key="NSButtonFlags2">2</int>
<object class="NSCustomResource" key="NSNormalImage">
@@ -1469,8 +1609,40 @@
<int key="NSPeriodicInterval">25</int>
</object>
</object>
+ <object class="NSTextField" id="51049166">
+ <reference key="NSNextResponder" ref="439893737"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 10}, {47, 17}}</string>
+ <reference key="NSSuperview" ref="439893737"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="1064553064">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents">Status:</string>
+ <reference key="NSSupport" ref="953681415"/>
+ <reference key="NSControlView" ref="51049166"/>
+ <reference key="NSBackgroundColor" ref="685989597"/>
+ <reference key="NSTextColor" ref="249716613"/>
+ </object>
+ </object>
+ <object class="NSTextField" id="730307729">
+ <reference key="NSNextResponder" ref="439893737"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{66, 10}, {421, 17}}</string>
+ <reference key="NSSuperview" ref="439893737"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="399630089">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents">Status</string>
+ <reference key="NSSupport" ref="953681415"/>
+ <reference key="NSControlView" ref="730307729"/>
+ <reference key="NSBackgroundColor" ref="685989597"/>
+ <reference key="NSTextColor" ref="249716613"/>
+ </object>
+ </object>
</object>
- <string key="NSFrameSize">{499, 160}</string>
+ <string key="NSFrameSize">{499, 265}</string>
<reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1280, 1002}}</string>
@@ -1482,6 +1654,9 @@
<object class="NSCustomObject" id="755631768">
<string key="NSClassName">NSFontManager</string>
</object>
+ <object class="NSUserDefaultsController" id="334287552">
+ <bool key="NSSharedInstance">YES</bool>
+ </object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@@ -2167,14 +2342,6 @@
<int key="connectionID">532</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">sourcePathChanged:</string>
- <reference key="source" ref="976324537"/>
- <reference key="destination" ref="231717339"/>
- </object>
- <int key="connectionID">546</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: maxNumLines</string>
<reference key="source" ref="1013929455"/>
@@ -2191,52 +2358,100 @@
<int key="connectionID">557</int>
</object>
<object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">readLinesRequested:</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="196243322"/>
+ </object>
+ <int key="connectionID">575</int>
+ </object>
+ <object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
- <string key="label">value: maxNumLines</string>
- <reference key="source" ref="844018831"/>
+ <string key="label">selectedIndex: selectedReadMode</string>
+ <reference key="source" ref="198904918"/>
<reference key="destination" ref="976324537"/>
<object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="844018831"/>
+ <reference key="NSSource" ref="198904918"/>
<reference key="NSDestination" ref="976324537"/>
- <string key="NSLabel">value: maxNumLines</string>
+ <string key="NSLabel">selectedIndex: selectedReadMode</string>
+ <string key="NSBinding">selectedIndex</string>
+ <string key="NSKeyPath">selectedReadMode</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">609</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: printLines</string>
+ <reference key="source" ref="407726537"/>
+ <reference key="destination" ref="976324537"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="407726537"/>
+ <reference key="NSDestination" ref="976324537"/>
+ <string key="NSLabel">value: printLines</string>
<string key="NSBinding">value</string>
- <string key="NSKeyPath">maxNumLines</string>
+ <string key="NSKeyPath">printLines</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
- <int key="connectionID">558</int>
+ <int key="connectionID">613</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
- <string key="label">value: sourcePath</string>
- <reference key="source" ref="355415411"/>
+ <string key="label">value: status</string>
+ <reference key="source" ref="399630089"/>
<reference key="destination" ref="976324537"/>
<object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="355415411"/>
+ <reference key="NSSource" ref="399630089"/>
<reference key="NSDestination" ref="976324537"/>
- <string key="NSLabel">value: sourcePath</string>
+ <string key="NSLabel">value: status</string>
<string key="NSBinding">value</string>
- <string key="NSKeyPath">sourcePath</string>
+ <string key="NSKeyPath">status</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
- <int key="connectionID">559</int>
+ <int key="connectionID">623</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
- <string key="label">value: searchBackwards</string>
- <reference key="source" ref="332168038"/>
+ <string key="label">value: maxNumLines</string>
+ <reference key="source" ref="202252264"/>
<reference key="destination" ref="976324537"/>
<object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="332168038"/>
+ <reference key="NSSource" ref="202252264"/>
<reference key="NSDestination" ref="976324537"/>
- <string key="NSLabel">value: searchBackwards</string>
+ <string key="NSLabel">value: maxNumLines</string>
<string key="NSBinding">value</string>
- <string key="NSKeyPath">searchBackwards</string>
+ <string key="NSKeyPath">maxNumLines</string>
+ <object class="NSDictionary" key="NSOptions">
+ <string key="NS.key.0">NSContinuouslyUpdatesValue</string>
+ <boolean value="YES" key="NS.object.0"/>
+ </object>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
- <int key="connectionID">566</int>
+ <int key="connectionID">624</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: sourcePath</string>
+ <reference key="source" ref="355415411"/>
+ <reference key="destination" ref="976324537"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="355415411"/>
+ <reference key="NSDestination" ref="976324537"/>
+ <string key="NSLabel">value: sourcePath</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">sourcePath</string>
+ <object class="NSDictionary" key="NSOptions">
+ <string key="NS.key.0">NSContinuouslyUpdatesValue</string>
+ <boolean value="YES" key="NS.object.0"/>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">625</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
@@ -2795,10 +3010,15 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="1045706751"/>
<reference ref="231717339"/>
- <reference ref="1013929455"/>
- <reference ref="293172749"/>
+ <reference ref="51049166"/>
+ <reference ref="730307729"/>
<reference ref="449809172"/>
- <reference ref="332168038"/>
+ <reference ref="202252264"/>
+ <reference ref="1013929455"/>
+ <reference ref="198904918"/>
+ <reference ref="643441890"/>
+ <reference ref="407726537"/>
+ <reference ref="196243322"/>
</object>
<reference key="parent" ref="972006081"/>
</object>
@@ -3331,46 +3551,133 @@
<reference key="parent" ref="1013929455"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">551</int>
- <reference key="object" ref="293172749"/>
+ <int key="objectID">553</int>
+ <reference key="object" ref="449809172"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="844018831"/>
+ <reference ref="630023291"/>
</object>
<reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">552</int>
- <reference key="object" ref="844018831"/>
- <reference key="parent" ref="293172749"/>
+ <int key="objectID">554</int>
+ <reference key="object" ref="630023291"/>
+ <reference key="parent" ref="449809172"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">553</int>
- <reference key="object" ref="449809172"/>
+ <int key="objectID">567</int>
+ <reference key="object" ref="202252264"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="630023291"/>
+ <reference ref="2523817"/>
</object>
<reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">554</int>
- <reference key="object" ref="630023291"/>
- <reference key="parent" ref="449809172"/>
+ <int key="objectID">568</int>
+ <reference key="object" ref="2523817"/>
+ <reference key="parent" ref="202252264"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">571</int>
+ <reference key="object" ref="196243322"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="865326817"/>
+ </object>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">572</int>
+ <reference key="object" ref="865326817"/>
+ <reference key="parent" ref="196243322"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">576</int>
+ <reference key="object" ref="198904918"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="460734633"/>
+ <reference ref="645343484"/>
+ <reference ref="806254077"/>
+ </object>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">577</int>
+ <reference key="object" ref="460734633"/>
+ <reference key="parent" ref="198904918"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">579</int>
+ <reference key="object" ref="645343484"/>
+ <reference key="parent" ref="198904918"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">590</int>
+ <reference key="object" ref="806254077"/>
+ <reference key="parent" ref="198904918"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">591</int>
+ <reference key="object" ref="643441890"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="401592038"/>
+ </object>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">592</int>
+ <reference key="object" ref="401592038"/>
+ <reference key="parent" ref="643441890"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">601</int>
+ <reference key="object" ref="334287552"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">610</int>
+ <reference key="object" ref="407726537"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="744190511"/>
+ </object>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">611</int>
+ <reference key="object" ref="744190511"/>
+ <reference key="parent" ref="407726537"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">614</int>
+ <reference key="object" ref="51049166"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="1064553064"/>
+ </object>
+ <reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">564</int>
- <reference key="object" ref="332168038"/>
+ <int key="objectID">615</int>
+ <reference key="object" ref="1064553064"/>
+ <reference key="parent" ref="51049166"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">616</int>
+ <reference key="object" ref="730307729"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="64997876"/>
+ <reference ref="399630089"/>
</object>
<reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">565</int>
- <reference key="object" ref="64997876"/>
- <reference key="parent" ref="332168038"/>
+ <int key="objectID">617</int>
+ <reference key="object" ref="399630089"/>
+ <reference key="parent" ref="730307729"/>
</object>
</object>
</object>
@@ -3601,20 +3908,33 @@
<string>536.IBPluginDependency</string>
<string>549.IBPluginDependency</string>
<string>550.IBPluginDependency</string>
- <string>551.IBPluginDependency</string>
- <string>552.IBPluginDependency</string>
<string>553.IBPluginDependency</string>
<string>554.IBPluginDependency</string>
<string>56.IBPluginDependency</string>
<string>56.ImportedFromIB2</string>
- <string>564.IBPluginDependency</string>
- <string>565.IBPluginDependency</string>
+ <string>567.IBPluginDependency</string>
+ <string>568.IBPluginDependency</string>
<string>57.IBEditorWindowLastContentRect</string>
<string>57.IBPluginDependency</string>
<string>57.ImportedFromIB2</string>
<string>57.editorWindowContentRectSynchronizationRect</string>
+ <string>571.IBPluginDependency</string>
+ <string>572.IBPluginDependency</string>
+ <string>576.IBPluginDependency</string>
+ <string>577.IBPluginDependency</string>
+ <string>579.IBPluginDependency</string>
<string>58.IBPluginDependency</string>
<string>58.ImportedFromIB2</string>
+ <string>590.IBPluginDependency</string>
+ <string>591.IBPluginDependency</string>
+ <string>592.IBPluginDependency</string>
+ <string>601.IBPluginDependency</string>
+ <string>610.IBPluginDependency</string>
+ <string>611.IBPluginDependency</string>
+ <string>614.IBPluginDependency</string>
+ <string>615.IBPluginDependency</string>
+ <string>616.IBPluginDependency</string>
+ <string>617.IBPluginDependency</string>
<string>72.IBPluginDependency</string>
<string>72.ImportedFromIB2</string>
<string>73.IBPluginDependency</string>
@@ -3773,9 +4093,9 @@
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
- <string>{{403, 820}, {499, 160}}</string>
+ <string>{{404, 715}, {499, 265}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{403, 820}, {499, 160}}</string>
+ <string>{{404, 715}, {499, 265}}</string>
<integer value="1"/>
<string>{{33, 99}, {480, 360}}</string>
<string>{3.40282e+38, 3.40282e+38}</string>
@@ -3870,8 +4190,6 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3880,8 +4198,23 @@
<integer value="1"/>
<string>{{23, 794}, {245, 183}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
@@ -3925,7 +4258,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">566</int>
+ <int key="maxID">625</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3934,21 +4267,12 @@
<string key="className">LineReaderAppDelegate</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="actions">
- <string key="NS.key.0">sourcePathChanged:</string>
+ <string key="NS.key.0">readLinesRequested:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="outlets">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>m_sourcePath</string>
- <string>window</string>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>NSTextField</string>
- <string>NSWindow</string>
- </object>
+ <string key="NS.key.0">window</string>
+ <string key="NS.object.0">NSWindow</string>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
@@ -4058,6 +4382,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">NSController</string>
+ <string key="superclassName">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">AppKit.framework/Headers/NSController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSDocument</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="actions">
@@ -4476,6 +4808,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">NSUserDefaultsController</string>
+ <string key="superclassName">NSController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">AppKit.framework/Headers/NSUserDefaultsController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
View
6 FileReader.m
@@ -57,11 +57,12 @@ - (id)initWithFilePath:(NSString*)filePath {
/**
Reads the file forwards.
+ Empty lines are not returned.
@returns Another single line on each call or nil if the file end has been reached.
*/
- (NSString*)readLine {
- if (m_currentOffset >= m_totalFileLength) {
+ if (m_totalFileLength == 0 || m_currentOffset >= m_totalFileLength) {
return nil;
}
@@ -96,11 +97,12 @@ - (NSString*)readLine {
/**
Reads the file backwards.
+ Empty lines are returned as well.
@returns Another single line on each call or nil if the file end has been reached.
*/
- (NSString*)readLineBackwards {
- if (m_currentInset == 0 && m_chunkSize == 0) {
+ if (m_totalFileLength == 0 || m_currentInset == 0 && m_chunkSize == 0) {
return nil;
}
View
31 LineReaderAppDelegate.h
@@ -8,20 +8,37 @@
#import <Cocoa/Cocoa.h>
+/**
+ Enum for the selected read mode. Defined values are FORWARDS = 0 and BACKWARDS = 1.
+ */
+typedef enum { FORWARDS = 0, BACKWARDS = 1 } READ_MODE;
+
+
+
@interface LineReaderAppDelegate : NSObject <NSApplicationDelegate> {
- NSWindow* m_window; /**< Application window. */
- IBOutlet NSTextField* m_sourcePath; /**< Source path. */
- NSNumber* m_maxNumLines; /**< Maximum number of lines. */
- NSNumber* m_searchBackwards; /**< Search backwards if value is 1. */
- NSArray* m_directoryListing; /**< Collection of file paths. */
+ NSWindow* m_window; /**< Application window. */
+ NSString* m_sourcePath; /**< Source path. */
+ NSNumber* m_maxNumLines; /**< Maximum number of lines. */
+ NSNumber* m_selectedReadMode; /**< Selected read mode. See READ_MODE enum. */
+ NSNumber* m_printLines; /**< Option to print lines to the console. */
+ NSString* m_status; /**< Program status. */
+ NSArray* m_directoryListing; /**< Collection of file paths. */
}
@property (assign) IBOutlet NSWindow* window; /**< Property for the application window. */
@property (readwrite, assign) NSString* sourcePath; /**< Property for the source path. */
@property (readwrite, assign) NSNumber* maxNumLines; /**< Property for the maximum number of lines. */
-@property (readwrite, assign) NSNumber* searchBackwards; /**< Property for switch to search backwards. */
+@property (readwrite, assign) NSNumber* selectedReadMode; /**< Property for the selected read mode. */
+@property (readwrite, assign) NSNumber* printLines; /**< Property for the print lines option. */
+@property (readwrite, assign) NSString* status; /**< Property for the program status. */
+
+- (IBAction)readLinesRequested:(id)sender;
+
+// -----------------------------------------------------------------------------
+// Private functions.
+// -----------------------------------------------------------------------------
-- (IBAction)sourcePathChanged:(id)sender;
+- (void)processSource;
@end
View
147 LineReaderAppDelegate.m
@@ -25,43 +25,36 @@ - (id)init {
self = [super init];
if (self != nil) {
+ m_sourcePath = [NSString stringWithFormat:@"/tmp/"];
m_maxNumLines = [NSNumber numberWithInt:3];
- [self setSourcePath:[NSString stringWithFormat:@"/tmp/"]];
- m_searchBackwards = [NSNumber numberWithInt:1];
+ m_selectedReadMode = [NSNumber numberWithInt:BACKWARDS];
+ m_printLines = [NSNumber numberWithBool:NO];
+ m_status = [NSString stringWithFormat:@"Application started."];
+ m_directoryListing = nil;
}
return self;
}
+// -----------------------------------------------------------------------------
+// Properties.
+// -----------------------------------------------------------------------------
+
+
@synthesize window = m_window;
@synthesize maxNumLines = m_maxNumLines;
-@synthesize searchBackwards = m_searchBackwards;
-@dynamic sourcePath;
+@synthesize sourcePath = m_sourcePath;
+@synthesize selectedReadMode = m_selectedReadMode;
+@synthesize printLines = m_printLines;
+@synthesize status = m_status;
-/**
- Returns the source path stored in the text field.
- @returns The source path as a NSString.
- */
-- (NSString*)sourcePath {
- return [m_sourcePath stringValue];
-}
+// -----------------------------------------------------------------------------
+// Event functions.
+// -----------------------------------------------------------------------------
-/**
- Sets the text field with the source path.
- @param sourcePath The source path.
- */
-- (void)setSourcePath:(NSString*)sourcePath {
-
- m_sourcePath = [[NSTextField alloc] init];
- if (!sourcePath || [sourcePath length] <= 0) {
- [m_sourcePath setStringValue:@""];
- return;
- }
- [m_sourcePath setStringValue:sourcePath];
-}
/**
Sent by the default notification center after the application
@@ -73,51 +66,113 @@ - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
}
-
/**
- Reads a various number of lines from multiple files as found in the source path.
- The function is called whenever the source path changes.
+ The function is called whenever lines should be read.
@param sender The object calling this method.
*/
-- (IBAction)sourcePathChanged:(id)sender {
+- (IBAction)readLinesRequested:(id)sender {
- DirectoryReader* directoryReader = [[DirectoryReader alloc] initWithPath:[m_sourcePath stringValue]];
+ [self processSource];
+}
+
+
+
+// -----------------------------------------------------------------------------
+// Private functions.
+// -----------------------------------------------------------------------------
+
+
+
+/**
+ Reads a various number of lines from multiple files as
+ found in the source path. The lines can be read forwards
+ or backwards from the file.
+ */
+- (void)processSource {
+
+ int lineCount;
+ NSTimeInterval processingStarted = [NSDate timeIntervalSinceReferenceDate];
+
+ DirectoryReader* directoryReader = [[DirectoryReader alloc] initWithPath:m_sourcePath];
if (!directoryReader) {
return;
}
-
+
if ([directoryReader readDirectory:&m_directoryListing]) {
-
+
for (NSString* path in m_directoryListing) {
NSLog(@"File: %@", path); /* DEBUG LOG */
- int numLine = 0;
+ lineCount = 0;
FileReader* fileReader = [[FileReader alloc] initWithFilePath:path];
if (!fileReader) {
return;
}
NSString* line = nil;
- if ([m_searchBackwards boolValue]) {
- while (line = [fileReader readLineBackwards]) {
- numLine++;
- NSLog(@"%3.d: %@", numLine, line); /* DEBUG LOG */
- if (numLine >= [m_maxNumLines intValue]) {
+
+
+ if ([m_printLines boolValue]) {
+ // Print lines to console.
+ switch ([m_selectedReadMode intValue]) {
+ case FORWARDS:
+ while (line = [fileReader readLine]) {
+ lineCount++;
+ NSLog(@"%3.d: %@", lineCount, line);
+ if (lineCount >= [m_maxNumLines intValue]) {
+ break;
+ }
+ }
break;
- }
- }
+ case BACKWARDS:
+ while (line = [fileReader readLineBackwards]) {
+ lineCount++;
+ NSLog(@"%3.d: %@", lineCount, line);
+ if (lineCount >= [m_maxNumLines intValue]) {
+ break;
+ }
+ }
+ break;
+ default:
+ NSLog(@"Warning: Read mode not set correctly."); /* DEBUG LOG */
+ break;
+ }
}
else {
- while (line = [fileReader readLine]) {
- numLine++;
- NSLog(@"%3.d: %@", numLine, line); /* DEBUG LOG */
- if (numLine >= [m_maxNumLines intValue]) {
+ // Do not print lines to console.
+ switch ([m_selectedReadMode intValue]) {
+ case FORWARDS:
+ while (line = [fileReader readLine]) {
+ lineCount++;
+ if (lineCount >= [m_maxNumLines intValue]) {
+ break;
+ }
+ }
+ break;
+ case BACKWARDS:
+ while (line = [fileReader readLineBackwards]) {
+ lineCount++;
+ if (lineCount >= [m_maxNumLines intValue]) {
+ break;
+ }
+ }
+ break;
+ default:
+ NSLog(@"Warning: Read mode not set correctly."); /* DEBUG LOG */
break;
- }
- }
+ }
- }
+ }
+
}
}
+
+ NSTimeInterval processingEnded = [NSDate timeIntervalSinceReferenceDate];
+
+ if ([m_selectedReadMode intValue] == FORWARDS)
+ self.status = [NSString stringWithFormat:@"Processing %d lines forwards took %f seconds.", lineCount, (processingEnded - processingStarted)];
+ else
+ self.status = [NSString stringWithFormat:@"Processing %d lines backwards took %f seconds.", lineCount, (processingEnded - processingStarted)];
+
}
@end

0 comments on commit ab074ff

Please sign in to comment.
Something went wrong with that request. Please try again.