- settings reading improved - searches also ~/.smalltalk/settings.stx
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 03 May 2012 16:23:07 +0200
changeset 1246 357edb85942f
parent 1245 6e4abfc9dbd5
child 1247 92421cd53801
- settings reading improved - searches also ~/.smalltalk/settings.stx (most users/newbies expect saved settings to be user-wide - some more tooling still required) - added support for rc.d directory to allow for distribution-specific customization
smalltalk.rc
--- a/smalltalk.rc	Thu May 03 09:45:21 2012 +0200
+++ b/smalltalk.rc	Thu May 03 16:23:07 2012 +0200
@@ -568,18 +568,83 @@
 ('smalltalk.rc [info]: reading ''' , file , '''...') infoPrintCR.
 Smalltalk fileIn:file.
 
+!
+
+"JV@2012-05-03: Search system path for rc.d directories, collect all *.rc files
+and then file them in a lexical order"
+
+| rcDFiles |
+
+rcDFiles := SortedCollection sortBlock:[:a :b|a baseName < b baseName].
+
+Smalltalk realSystemPath ? #() do:[:syspath|
+    | rcD |
+
+    rcD := syspath asFilename / 'rc.d'.
+    rcD exists ifTrue:[
+	rcD directoryContentsAsFilenames do:[:each|
+	    each suffix = 'rc' ifTrue:[ rcDFiles add: each]
+	].
+    ].
+].
+
+rcDFiles do:[:each|
+    'smalltalk.rc [info]: reading ' infoPrint.
+    each baseName infoPrint.
+    '...' infoPrint.
+    ( AbortOperationRequest , TerminateProcessRequest , Parser parseErrorSignal ) handle:[:ex |
+	'FAILED: ' errorPrint.
+	ex description errorPrintCR.
+	ex return.
+    ] do:[
+	each fileIn.
+	'OK' infoPrintCR.
+    ].
+].
+
+!
+
 Screen notNil ifTrue:[
     "/
     "/ read saved configuration settings (if any)
     "/
-    'smalltalk.rc [info]: reading ''settings.stx''...' infoPrintCR.
-    AbortOperationRequest handle:[:ex |
-	ex return
+    'smalltalk.rc [info]: reading preferences ' infoPrint.
+    ( AbortOperationRequest , TerminateProcessRequest , Parser parseErrorSignal ) handle:[:ex |
+	'READ FAILED: ' errorPrint.
+	ex description errorPrintCR.
+	ex return.
     ] do:[
-	(Smalltalk fileIn:'settings.stx') ifTrue:[
-	    'smalltalk.rc [info]: loaded preferences from ''settings.stx''' infoPrintCR.
-	]
-    ]
+	"JV@2012-03-07: Try following settings files:
+	   $PWD/settings.stx
+	   $PWD/settings.rc
+	   $HOME/.smalltalk/settings.stx
+	   $HOME/.smalltalk/settings.rc
+
+	in that order. Whichever is found, it is read and the rest
+	is not used. Also, path to the file which has beed read is
+	stored in 'UserPreferences current at:#settingsFilename'
+	"
+	| files continue |
+
+	files := Array
+		    with: (Smalltalk getSystemFileName: 'settings.stx')            "/ old stx default
+		    with: (Smalltalk getSystemFileName: 'settings.rc')             "/ for backward compatibility with jv-branch
+		    with: (Filename homeDirectory / '.smalltalk' / 'settings.stx') "/ per-user settings file (new default?)
+		    with: (Filename homeDirectory / '.smalltalk' / 'settings.rc') . "/ for backward compatibility with jv-branch
+	continue := true.
+	files do:[:each|
+	    | eachFile |
+
+	    (continue and:[(eachFile := each asFilename) exists]) ifTrue:[
+		continue := false.
+		eachFile pathName infoPrintCR.
+		eachFile fileIn.
+		UserPreferences current at:#settingsFilename put: eachFile pathName.
+	    ].
+	].
+	continue ifTrue:[ '(none found)' infoPrintCR ].
+    ].
+
 ].
 !