Browse code

add environment includes and better environment queries

Nat! authored on 14/06/2017 16:39:05
Showing 7 changed files
... ...
@@ -39,7 +39,7 @@ FIND_PACKAGE( ZLIB REQUIRED)
39 39
 message( STATUS "FOUNDATION_LIBRARY is ${FOUNDATION_LIBRARY}")
40 40
 message( STATUS "ZLIB_LIBRARIES is ${ZLIB_LIBRARIES}")
41 41
 
42
-add_definitions( -DPROJECT_VERSION=1857)
42
+add_definitions( -DPROJECT_VERSION=1858)
43 43
 
44 44
 
45 45
 add_library( MulleScion STATIC
... ...
@@ -1,6 +1,6 @@
1 1
 Pod::Spec.new do |s|
2 2
   s.name             = "MulleScion"
3
-  s.version          = '1857'
3
+  s.version          = '1858'
4 4
   s.summary          = "MulleScion a modern Template library for ObjC."
5 5
   s.description      = <<-DESC
6 6
                        MulleScion is indeed a modern Template library for ObjC.
... ...
@@ -1963,7 +1963,7 @@
1963 1963
 			baseConfigurationReference = 413C51611CC284CA00F62468 /* Debug.xcconfig */;
1964 1964
 			buildSettings = {
1965 1965
 				CLANG_WARN_INT_CONVERSION = YES;
1966
-				CURRENT_PROJECT_VERSION = 1857;
1966
+				CURRENT_PROJECT_VERSION = 1858;
1967 1967
 				DYLIB_COMPATIBILITY_VERSION = 1848.0;
1968 1968
 				DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
1969 1969
 				GCC_OPTIMIZATION_LEVEL = 0;
... ...
@@ -1995,7 +1995,7 @@
1995 1995
 			baseConfigurationReference = 413C516B1CC284CA00F62468 /* Release.xcconfig */;
1996 1996
 			buildSettings = {
1997 1997
 				CLANG_WARN_INT_CONVERSION = YES;
1998
-				CURRENT_PROJECT_VERSION = 1857;
1998
+				CURRENT_PROJECT_VERSION = 1858;
1999 1999
 				DYLIB_COMPATIBILITY_VERSION = 1848.0;
2000 2000
 				DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
2001 2001
 				GCC_PREPROCESSOR_DEFINITIONS = (
... ...
@@ -2064,7 +2064,7 @@
2064 2064
 			baseConfigurationReference = 413C516B1CC284CA00F62468 /* Release.xcconfig */;
2065 2065
 			buildSettings = {
2066 2066
 				CLANG_WARN_INT_CONVERSION = YES;
2067
-				CURRENT_PROJECT_VERSION = 1857;
2067
+				CURRENT_PROJECT_VERSION = 1858;
2068 2068
 				DYLIB_COMPATIBILITY_VERSION = 1848.0;
2069 2069
 				DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
2070 2070
 				GCC_PREPROCESSOR_DEFINITIONS = (
... ...
@@ -47,7 +47,7 @@
47 47
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48 48
       launchStyle = "0"
49 49
       useCustomWorkingDirectory = "YES"
50
-      customWorkingDirectory = "/Volumes/Source/srcM/MulleScion/tests"
50
+      customWorkingDirectory = "/Volumes/Source/srcO/MulleObjC-master/MulleObjCFoundation"
51 51
       ignoresPersistentStateOnLaunch = "NO"
52 52
       debugDocumentVersioning = "YES"
53 53
       debugServiceExtension = "internal"
... ...
@@ -64,7 +64,7 @@
64 64
       </BuildableProductRunnable>
65 65
       <CommandLineArguments>
66 66
          <CommandLineArgument
67
-            argument = "commands/define/define-1.scion none"
67
+            argument = "&apos;/Volumes/Source/srcO/MulleObjC-master/MulleObjCFoundation/templates/__wrapper.scion&apos; args &apos;dox/HOWTO_DEPENDENCIES.md&apos; PUBLISHER=&apos;mulle-nat&apos; PUBLISHER_TAP=&apos;mulle-kybernetik/software&apos; PUBLISHER_FULLNAME=&apos;Mulle kybernetiK&apos; COMMENT=&apos;DO NOT EDIT THIS. EDIT THE TEMPLATE &quot;templates/dox/HOWTO_DEPENDENCIES.md.scion&quot;&apos; TEMPLATE_FILE=&apos;templates/dox/HOWTO_DEPENDENCIES.md.scion&apos;"
68 68
             isEnabled = "YES">
69 69
          </CommandLineArgument>
70 70
       </CommandLineArguments>
... ...
@@ -1,3 +1,12 @@
1
+## 1858
2
+
3
+There is an option that allows specifying includes via the environment like
4
+so:
5
+`MULLESCION_ALLOW_GETENV_INCLUDES="YES" MY_INCLUDE="foo.scion" mulle-scion bar.scion none`
6
+and then in `bar.scion` use `{% includes MY_INCLUDE %}`. This looks obscure,
7
+but I needed it to wrap code around existing templates.
8
+* MULLESCION_.. environment variables now are of the YES/NO variety.
9
+
1 10
 ## 1857
2 11
 
3 12
 * fix missing menu due to change of root dox
... ...
@@ -134,12 +134,13 @@ typedef struct _parser
134 134
 
135 135
 enum
136 136
 {
137
-   MULLESCION_VERBATIM_INCLUDE_HASHBANG = 0x01,
137
+   MULLESCION_ALLOW_GETENV_INCLUDES     = 0x01,
138 138
    MULLESCION_NO_HASHBANG               = 0x02,
139
-   MULLESCION_DUMP_MACROS               = 0x04,
139
+   MULLESCION_VERBATIM_INCLUDE_HASHBANG = 0x04,
140 140
    MULLESCION_DUMP_COMMANDS             = 0x08,
141 141
    MULLESCION_DUMP_EXPRESSIONS          = 0x10,
142
-   MULLESCION_DUMP_FILE_INCLUDES        = 0x20
142
+   MULLESCION_DUMP_FILE_INCLUDES        = 0x20,
143
+   MULLESCION_DUMP_MACROS               = 0x40
143 144
 };
144 145
 
145 146
 static void   parser_skip_after_newline( parser *p);
... ...
@@ -158,6 +159,33 @@ static void   parser_skip_initial_hashbang_line_if_present( parser *p)
158 158
 }
159 159
 
160 160
 
161
+static int   getenv_yes_no_default( char *name, int default_value)
162
+{
163
+   char   *s;
164
+
165
+   s = getenv( name);
166
+   if( ! s)
167
+      return( default_value);
168
+
169
+   switch( *s)
170
+   {
171
+   case 'f' :
172
+   case 'F' :
173
+   case 'n' :
174
+   case 'N' :
175
+   case '0' : return( 0);
176
+   }
177
+
178
+   return( 1);
179
+}
180
+
181
+
182
+static inline int  getenv_yes_no( char *name)
183
+{
184
+   return( getenv_yes_no_default( name, 0));
185
+}
186
+
187
+
161 188
 static void   parser_init( parser *p, unsigned char *buf, size_t len)
162 189
 {
163 190
    memset( p, 0, sizeof( parser));
... ...
@@ -168,12 +196,13 @@ static void   parser_init( parser *p, unsigned char *buf, size_t len)
168 168
       p->lineNumber = 1;
169 169
    }
170 170
 
171
-   p->environment |= getenv( "MULLESCION_DUMP_MACROS") ? MULLESCION_DUMP_MACROS : 0;
172
-   p->environment |= getenv( "MULLESCION_VERBATIM_INCLUDE_HASHBANG") ? MULLESCION_VERBATIM_INCLUDE_HASHBANG : 0;
173
-   p->environment |= getenv( "MULLESCION_NO_HASHBANG") ? MULLESCION_NO_HASHBANG : 0;
174
-   p->environment |= getenv( "MULLESCION_DUMP_COMMANDS") ? MULLESCION_DUMP_COMMANDS : 0;
175
-   p->environment |= getenv( "MULLESCION_DUMP_EXPRESSIONS") ? MULLESCION_DUMP_EXPRESSIONS : 0;
176
-   p->environment |= getenv( "MULLESCION_DUMP_FILE_INCLUDES") ? MULLESCION_DUMP_FILE_INCLUDES : 0;
171
+   p->environment |= getenv_yes_no( "MULLESCION_ALLOW_GETENV_INCLUDES") ? MULLESCION_ALLOW_GETENV_INCLUDES : 0;
172
+   p->environment |= getenv_yes_no( "MULLESCION_NO_HASHBANG") ? MULLESCION_NO_HASHBANG : 0;
173
+   p->environment |= getenv_yes_no( "MULLESCION_VERBATIM_INCLUDE_HASHBANG") ? MULLESCION_VERBATIM_INCLUDE_HASHBANG : 0;
174
+   p->environment |= getenv_yes_no( "MULLESCION_DUMP_COMMANDS") ? MULLESCION_DUMP_COMMANDS : 0;
175
+   p->environment |= getenv_yes_no( "MULLESCION_DUMP_EXPRESSIONS") ? MULLESCION_DUMP_EXPRESSIONS : 0;
176
+   p->environment |= getenv_yes_no( "MULLESCION_DUMP_FILE_INCLUDES") ? MULLESCION_DUMP_FILE_INCLUDES : 0;
177
+   p->environment |= getenv_yes_no( "MULLESCION_DUMP_MACROS") ? MULLESCION_DUMP_MACROS : 0;
177 178
 }
178 179
 
179 180
 
... ...
@@ -2224,7 +2253,8 @@ static MulleScionObject * NS_RETURNS_RETAINED  _parser_do_includes( parser *p, B
2224 2224
    NSString               *converter;
2225 2225
    SEL                    sel;
2226 2226
    NSString               *s;
2227
-
2227
+   char                   *env;
2228
+   
2228 2229
    if( p->inMacro)
2229 2230
       parser_error( p, "no including or extending in macro");
2230 2231
 
... ...
@@ -2245,19 +2275,30 @@ retry:
2245 2245
          converter = nil;
2246 2246
          goto retry;
2247 2247
       }
2248
-
2248
+   
2249
+      if( p->environment & MULLESCION_ALLOW_GETENV_INCLUDES)
2250
+      {
2251
+         env = getenv( [converter cString]);
2252
+         if( env)
2253
+         {
2254
+            fileName = [NSString stringWithCString:env];
2255
+            goto env_string;
2256
+         }
2257
+      }
2258
+         
2249 2259
       //
2250 2260
       // markdown -> markdownedData or some other variety
2251 2261
       // (rarely useful)
2252 2262
       sel = NSSelectorFromString( converter);
2253 2263
       if( ! [NSData instancesRespondToSelector:sel])
2254
-         parser_error( p, "converter method \"%s\" not found on NSData", [converter cString]);
2264
+         parser_error( p, "unknown converter method \"%s\" (hint: use quoted strings for filenames)", [converter cString]);
2255 2265
    }
2256 2266
 
2257 2267
    fileName = parser_do_string( p);
2258 2268
    if( ! [fileName length])
2259 2269
       parser_error( p, "a filename was expected as a quoted string");
2260 2270
 
2271
+env_string:
2261 2272
    if( p->environment & MULLESCION_DUMP_FILE_INCLUDES)
2262 2273
       fprintf( stderr, "-> opening \"%s\"\n", [fileName UTF8String]);
2263 2274
    
... ...
@@ -42,12 +42,14 @@
42 42
 #import "NSFileHandle+MulleOutputFileHandle.h"
43 43
 
44 44
 
45
+// all C strings
45 46
 #ifndef DEBUG
46
-# define DOCUMENT_ROOT "/usr/local/share/mulle-scion/dox"  // C string!
47
+# define DOCUMENT_ROOT "/usr/local/share/mulle-scion/dox"
47 48
 #else
48 49
 # define DOCUMENT_ROOT "/Volumes/Source/srcM/MulleScion/dox"
49 50
 #endif
50
-
51
+#define SERVER_HOST "127.0.0.1"
52
+#define SERVER_PORT "18048"
51 53
 
52 54
 static NSString  *processName( void);
53 55
 
... ...
@@ -460,7 +462,7 @@ static int   _archive_main( int argc, char *argv[], BOOL keyed)
460 460
  static char    *default_options[] =
461 461
 {
462 462
    "document_root", DOCUMENT_ROOT,
463
-   "listening_ports", "127.0.0.1:18048",
463
+   "listening_ports", SERVER_HOST ":" SERVER_PORT,
464 464
    "num_threads", "1",
465 465
    "index_files", "index.scion,index.html,index.htm,index.cgi,index.shtml,index.php,index.lp",
466 466
    NULL
... ...
@@ -503,6 +505,9 @@ static int   main_www( int argc, char *argv[])
503 503
    if( ! plist)
504 504
       plist = [NSDictionary dictionary];
505 505
 
506
+#if __APPLE__
507
+   system( "(sleep 1 ; open http://" SERVER_HOST ":" SERVER_PORT ") &");
508
+#endif
506 509
    mulle_mongoose_main( plist, default_options);
507 510
    return( 0);
508 511
 }