7979#include < sys/types.h>
8080#include < stdio.h>
8181
82+ static NSString *debugKey = @" NSPathUtilities" ;
83+
8284NSMutableDictionary * GNUstepConfig (NSDictionary *newConfig);
8385
8486void GNUstepUserConfig (NSMutableDictionary *config, NSString *userName);
@@ -954,14 +956,38 @@ static void ExtractValuesFromConfig(NSDictionary *config)
954956 conf = [[NSMutableDictionary alloc ] initWithCapacity: 32 ];
955957
956958 /* Now we source the configuration file if it exists */
957- #if !OPTION_NO_ENVIRONMENT
958959 file = [[[NSProcessInfo processInfo ] environment ]
959960 objectForKey: @" GNUSTEP_CONFIG_FILE" ];
961+ if (file)
962+ {
963+ #if OPTION_NO_ENVIRONMENT
964+ if (GSDebugSet (debugKey))
965+ {
966+ fprintf (stderr, " Ignored '%s ' (from GNUSTEP_CONFIG_FILE"
967+ " environment variable) because gnustep-base was"
968+ " configured/built with OPTION_NO_ENVIRONMENT.\n " ,
969+ [file UTF8String ]);
970+ }
971+ file = nil ;
972+ #else
973+ if (GSDebugSet (debugKey))
974+ {
975+ fprintf (stderr, " Using '%s ' (from GNUSTEP_CONFIG_FILE"
976+ " environment variable) as configuration file.\n " ,
977+ [file UTF8String ]);
978+ }
960979#endif
980+ }
961981 if (file == nil )
962982 {
963983 fromEnvironment = NO ;
964984 file = @GNUSTEP_TARGET_CONFIG_FILE ;
985+ if (GSDebugSet (debugKey))
986+ {
987+ fprintf (stderr, " Using '%s ' (configure/build time default"
988+ " for gnustep-base) as configuration file.\n " ,
989+ [file UTF8String ]);
990+ }
965991 }
966992
967993 /*
@@ -986,6 +1012,13 @@ static void ExtractValuesFromConfig(NSDictionary *config)
9861012 path = GSPrivateSymbolPath (c);
9871013 // Remove library name from path
9881014 path = [path stringByDeletingLastPathComponent ];
1015+ if (GSDebugSet (debugKey))
1016+ {
1017+ fprintf (stderr, " Config file location is relative."
1018+ " Forming absolute path from gnustep-base library"
1019+ " location '%s ' with '%s '.\n " ,
1020+ [path UTF8String ], [file UTF8String ]);
1021+ }
9891022 if ([file hasPrefix: @" ./" ] == YES )
9901023 {
9911024 file = [file substringFromIndex: 2 ];
@@ -1030,17 +1063,34 @@ static void ExtractValuesFromConfig(NSDictionary *config)
10301063#endif
10311064 }
10321065
1033- if (bareDirectory == YES )
1066+ if (bareDirectory)
10341067 {
10351068 /* Set the directory name, but don't try to read file.
10361069 */
10371070 gnustepConfigPath = RETAIN (file);
1071+ if (GSDebugSet (debugKey))
1072+ {
1073+ fprintf (stderr, " Config base path '%s ' with no config"
1074+ " file to read.\n " , [file UTF8String ]);
1075+ }
10381076 }
10391077 else
10401078 {
10411079 gnustepConfigPath
10421080 = RETAIN ([file stringByDeletingLastPathComponent ]);
1043- ParseConfigurationFile (file, conf, nil );
1081+ if (GSDebugSet (debugKey))
1082+ {
1083+ fprintf (stderr, " Config base path '%s ' with master"
1084+ " config file '%s ' to read.\n " ,
1085+ [gnustepConfigPath UTF8String ],
1086+ [[file lastPathComponent ] UTF8String ]);
1087+ }
1088+ if (ParseConfigurationFile (file, conf, nil )
1089+ && GSDebugSet (debugKey))
1090+ {
1091+ fprintf (stderr, " Configuration contained '%s '\n " ,
1092+ [[conf descriptionInStringsFileFormat ] UTF8String ]);
1093+ }
10441094 }
10451095
10461096 /* Merge in any values from property lists in the
@@ -1072,10 +1122,23 @@ static void ExtractValuesFromConfig(NSDictionary *config)
10721122 * setting GNUSTEP_USER_CONFIG_FILE to be an empty string.
10731123 * If they simply don't define it at all, we assign a default.
10741124 */
1075- if ([conf objectForKey: @" GNUSTEP_USER_CONFIG_FILE" ] == nil )
1125+ if ([conf objectForKey: @" GNUSTEP_USER_CONFIG_FILE" ])
1126+ {
1127+ if (GSDebugSet (debugKey))
1128+ {
1129+ fprintf (stderr, " Using GNUSTEP_USER_CONFIG_FILE"
1130+ " from master config file.\n " );
1131+ }
1132+ }
1133+ else
10761134 {
10771135 [conf setObject: @GNUSTEP_TARGET_USER_CONFIG_FILE
10781136 forKey: @" GNUSTEP_USER_CONFIG_FILE" ];
1137+ if (GSDebugSet (debugKey))
1138+ {
1139+ fprintf (stderr, " Using GNUSTEP_USER_CONFIG_FILE"
1140+ " (configure/build time default for gnustep-base)\n " );
1141+ }
10791142 }
10801143 if (config != nil )
10811144 {
@@ -1130,23 +1193,37 @@ static void ExtractValuesFromConfig(NSDictionary *config)
11301193
11311194 if (userName != nil )
11321195 {
1133- NSString *file;
1134- NSString *home;
1135- NSString *path;
1196+ NSString *file;
1197+ NSString *home;
1198+ NSString *path;
1199+ NSMutableDictionary *dict;
11361200
1137- file = RETAIN ( [config objectForKey: @" GNUSTEP_USER_CONFIG_FILE" ]) ;
1201+ file = [config objectForKey: @" GNUSTEP_USER_CONFIG_FILE" ];
11381202 if ([file length ] > 0 )
11391203 {
11401204 home = NSHomeDirectoryForUser (userName);
11411205 path = [home stringByAppendingPathComponent: file];
1142- ParseConfigurationFile (path, config, userName);
1206+ if (GSDebugSet (debugKey))
1207+ {
1208+ fprintf (stderr, " Trying user config from '%s ' in '%s '\n " ,
1209+ [file UTF8String ], [home UTF8String ]);
1210+ }
1211+ dict = [NSMutableDictionary new ];
1212+ if (ParseConfigurationFile (path, dict, userName))
1213+ {
1214+ /* Don't let the user file override the GNUSTEP_USER_CONFIG_FILE
1215+ * variable ... that would be silly/pointless.
1216+ */
1217+ [dict removeObjectForKey: @" GNUSTEP_USER_CONFIG_FILE" ];
1218+ [config addEntriesFromDictionary: dict];
1219+ if (GSDebugSet (debugKey))
1220+ {
1221+ fprintf (stderr, " User configuration contained '%s '\n " ,
1222+ [[dict descriptionInStringsFileFormat ] UTF8String ]);
1223+ }
1224+ }
1225+ RELEASE (dict);
11431226 }
1144- /*
1145- * We don't let the user config file override the GNUSTEP_USER_CONFIG_FILE
1146- * variable ... that would be silly/pointless.
1147- */
1148- [config setObject: file forKey: @" GNUSTEP_USER_CONFIG_FILE" ];
1149- RELEASE (file);
11501227 }
11511228}
11521229
@@ -1347,6 +1424,10 @@ static void ShutdownPathUtilities(void)
13471424
13481425 if ([MGR () isReadableFileAtPath: fileName] == NO )
13491426 {
1427+ if (GSDebugSet (debugKey))
1428+ {
1429+ fprintf (stderr, " No readable file at '%s '\n " , [fileName UTF8String ]);
1430+ }
13501431 return NO ;
13511432 }
13521433
0 commit comments