Browse code

Clarify usage. Use integerValue in some strategic places.

Nat! authored on 12-06-2017 14:37:42
Showing 5 changed files
... ...
@@ -18,3 +18,4 @@ tests/compare-parse-speed-to-unarchive-speed.sh
18 18
 dependencies/
19 19
 .repos/
20 20
 mulle-configuration/
21
+addictions/
... ...
@@ -1,3 +1,7 @@
1
+## 1857
2
+
3
+* clarify usage
4
+ 
1 5
 ## 1856
2 6
 
3 7
 * add nexti/previ to for loop dictionary.
... ...
@@ -90,4 +90,17 @@ id   MulleScionZero;
90 90
    return( @"nil");
91 91
 }
92 92
 
93
+
94
++ (NSInteger)  integerValue
95
+{
96
+   return( 0);
97
+}
98
+
99
+
100
++ (BOOL)  boolValue
101
+{
102
+   return( NO);
103
+}
104
+
105
+
93 106
 @end
... ...
@@ -284,7 +284,7 @@ NSString  *MulleScionFilteredString( NSString *value,
284 284
       return( value);
285 285
    
286 286
    // if turned off, don't filter
287
-   mask = [[locals objectForKey:MulleScionCurrentFilterModeKey] unsignedIntegerValue];
287
+   mask = [[locals objectForKey:MulleScionCurrentFilterModeKey] integerValue];
288 288
    if( mask & bit)
289 289
    {
290 290
       filtered = [filter evaluateValue:(id) value
... ...
@@ -307,7 +307,7 @@ NSString  *MulleScionFilteredString( NSString *value,
307 307
       modeRover = [[locals objectForKey:MulleScionPreviousFilterModesKey] reverseObjectEnumerator];
308 308
       while( filter = [rover nextObject])
309 309
       {
310
-         mask = [[modeRover nextObject] unsignedIntegerValue];
310
+         mask = [[modeRover nextObject] integerValue];
311 311
          if( mask & bit)
312 312
          {
313 313
             filtered = [filter evaluateValue:value
... ...
@@ -1961,7 +1961,7 @@ done:
1961 1961
    TRACE_EVAL_CONT( self, otherValue);
1962 1962
    
1963 1963
    if( [value respondsToSelector:@selector( objectAtIndex:)])
1964
-      result = [value objectAtIndex:[otherValue unsignedIntegerValue]]; // must be a NSNumber or NSString (?)
1964
+      result = [value objectAtIndex:[otherValue integerValue]]; // must be a NSNumber or NSString (?)
1965 1965
    else
1966 1966
       if( [value respondsToSelector:@selector( objectForKey:)])
1967 1967
       {
... ...
@@ -2005,7 +2005,7 @@ done:
2005 2005
    
2006 2006
    if( [value respondsToSelector:@selector( objectAtIndex:)])
2007 2007
    {
2008
-      index = [otherValue unsignedIntegerValue];
2008
+      index = [otherValue integerValue];
2009 2009
       n     = [value count];
2010 2010
       while( index > n)
2011 2011
       {
... ...
@@ -42,11 +42,56 @@
42 42
 #import "NSFileHandle+MulleOutputFileHandle.h"
43 43
 
44 44
 
45
+static NSString  *processName( void);
46
+
47
+
48
+static void   usage( void)
49
+{
50
+   fprintf( stderr, "%s [options] <input> [datasource] [output] [arguments]\n", [processName() cString]);
51
+   fprintf( stderr,
52
+"options:\n"
53
+   "\t-w       : start webserver for /tmp/MulleScionDox\n"
54
+   "\t-z       : write compressed archive to outputfile\n"
55
+   "\t-Z       : write compressed keyed archive to outputfile (for IOS)\n"
56
+"input:\n"
57
+   "\t-        : Read template from stdin\n"
58
+   "\ttemplate : a MulleScion template path or URL\n"
59
+"datasource:\n"
60
+   "\t-        : Read data from stdin (only if input is not stdin already)\n"
61
+   "\tbundle   : a NSBundle. It's NSPrincipalClass will be used as the datasource\n"
62
+   "\tplist    : a property list path or URL as datasource, see: plist(5)\n"
63
+   "\args      : use arguments as datasource (see below)\n"
64
+   "\tnone     : empty datasource\n"
65
+"output:\n"
66
+   "\t-        : Write result to stdout\n"
67
+   "\tfile     : Write result to file\n"
68
+"arguments:\n"
69
+   "\tkey=value  : key/value pairs to be used as __ARGV__ contents\n"
70
+   "\t             (unless args as datasource was specified)\n"
71
+"Examples:\n"
72
+   "\techo '***{{ VALUE }}***' | mulle-scion - args - VALUE=\"VfL Bochum 1848\"\n"
73
+   "\techo '***{{ __ARGV__[ 0]}}***' | mulle-scion - none - \"VfL Bochum 1848\"\n"
74
+   );
75
+}
76
+
77
+
78
+
45 79
 static NSFileHandle  *outputStreamWithInfo( NSDictionary *info);
46 80
 static NSDictionary  *getInfoFromArguments( void);
47 81
 static id            acquirePropertyListOrDataSourceFromBundle( NSString *s);
48 82
 
49 83
 
84
+static NSString  *processName( void)
85
+{
86
+   NSArray        *arguments;
87
+   NSEnumerator   *rover;
88
+
89
+   arguments = [[NSProcessInfo processInfo] arguments];
90
+   rover     = [arguments objectEnumerator];
91
+   return( [[rover nextObject] lastPathComponent]);
92
+}
93
+
94
+
50 95
 @interface NSFileHandle ( MulleScionOutput) < MulleScionOutput >
51 96
 @end
52 97
 
... ...
@@ -249,40 +294,6 @@ static id   acquirePropertyListOrDataSourceFromBundle( NSString *s)
249 294
 }
250 295
 
251 296
 
252
-static NSString  *processName( void)
253
-{
254
-   NSArray        *arguments;
255
-   NSEnumerator   *rover;
256
-
257
-   arguments = [[NSProcessInfo processInfo] arguments];
258
-   rover     = [arguments objectEnumerator];
259
-   return( [[rover nextObject] lastPathComponent]);
260
-}
261
-
262
-
263
-static void   usage( void)
264
-{
265
-   fprintf( stderr, "%s [-w|-z] <-|template> [bundle|plist|-|'keyvalue'|'none'] [-|outputfile] [args|<key>[=value]]*\n", [processName() cString]);
266
-   fprintf( stderr, "v%s\n", MulleScionFrameworkVersion);
267
-   fprintf( stderr,
268
-   "\t-w       : start webserver for /tmp/MulleScionDox\n"
269
-   "\t-z       : write compressed archive to outputfile\n"
270
-   "\t-Z       : write compressed keyed archive to outputfile (for IOS)\n"
271
-   "\n"
272
-   "\ttemplate : a MulleScion template path or URL\n\n"
273
-   "\tbundle   : a NSBundle. It's NSPrincipalClass will be used as the datasource\n"
274
-   "\tplist    : a property list path or URL as datasource, see: plist(5)\n"
275
-   "\t'keyvalue' : use keyvalue arguments as datasource (see below)\n"
276
-   "\t'none'   : empty datasource\n"
277
-   "\targs     : arguments made available to the template via __ARGV__ (default)\n"
278
-   "\tkey      : key values as datasource contents (only with keyvalue)\n"
279
-   "\n"
280
-   "example:\n"
281
-   "\techo '***{{ VALUE }}***' | mulle-scion - args - VALUE=\"VfL Bochum 1848\"\n"
282
-   );
283
-}
284
-
285
-
286 297
 static NSDictionary  *getInfoFromEnumerator( NSEnumerator *rover)
287 298
 {
288 299
    NSArray               *argv;
... ...
@@ -307,7 +318,7 @@ static NSDictionary  *getInfoFromEnumerator( NSEnumerator *rover)
307 318
    if( ! [outputName length])
308 319
       outputName = @"-";
309 320
 
310
-   if( [plistName isEqualToString:@"keyvalue"])
321
+   if( [plistName isEqualToString:@"keyvalue"] || [plistName isEqualToString:@"args"])
311 322
    {
312 323
       plist = acquirePropertyListFromArgs( argv);
313 324
       argv  = [NSArray array];