Added --no-preferences and --preferences options.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 14 Oct 2014 17:23:36 +0200
changeset 1364 ab2a726d83e8
parent 1363 97d15780a26b
child 1365 f3dfd72559a2
Added --no-preferences and --preferences options.
smalltalk.rc
--- a/smalltalk.rc	Thu Aug 14 23:50:42 2014 +0200
+++ b/smalltalk.rc	Tue Oct 14 17:23:36 2014 +0200
@@ -641,44 +641,85 @@
     "/
     "/ read saved configuration settings (if any)
     "/
-    'smalltalk.rc [info]: reading preferences ' infoPrint.
-    ( AbortOperationRequest , TerminateProcessRequest , Parser parseErrorSignal ) handle:[:ex |
-	'READ FAILED: ' errorPrint.
-	ex description errorPrintCR.
-	ex return.
-    ] do:[
-	"JV@2012-03-07: Try following settings files:
-	   $HOME/.smalltalk/settings.stx
-	   $HOME/.smalltalk/settings.rc
-	   $PWD/settings.stx
-	   $PWD/settings.rc
+    | idx |
+
+    idx := Smalltalk commandLineArguments indexOf: '--no-preferences'.
+    idx ~~ 0 ifTrue:[
+	Smalltalk commandLineArguments removeAtIndex: idx.
+    ] ifFalse:[
 
-	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 |
+	'smalltalk.rc [info]: reading preferences ' infoPrint.
+	( AbortOperationRequest , TerminateProcessRequest , Parser parseErrorSignal ) handle:[:ex |
+	    'READ FAILED: ' errorPrint.
+	    ex description errorPrintCR.
+	    ex return.
+	    1 halt.
+	] do:[
+	    "JV@2012-03-07: Try following settings files:
+	       $HOME/.smalltalk/settings.stx
+	       $HOME/.smalltalk/settings.rc
+	       $PWD/settings.stx
+	       $PWD/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 := nil.
+
+	    idx := Smalltalk commandLineArguments indexOf: '--preferences'.
+	    idx ~~ 0 ifTrue:[
+		| file |
 
-	files := {
-		    (Filename homeDirectory / '.smalltalk' / 'settings.stx') . "/ per-user settings file (new default?)
-		    (Filename homeDirectory / '.smalltalk' / 'settings.rc') .  "/ for backward compatibility with jv-branch
-		    (Smalltalk getSystemFileName: 'settings.stx') .            "/ old stx default
-		    (Smalltalk getSystemFileName: 'settings.rc') .             "/ for backward compatibility with jv-branch
-		 }.
-	continue := true.
-	files do:[:each|
-	    | eachFile |
+		Smalltalk commandLineArguments size <= idx ifTrue:[
+		    '' errorPrintCR.
+		    'smalltalk.rc [error]: --preferences requires an argument, none given' errorPrintCR.
+		    Smalltalk exit: 1.
+		].
+		file := (Smalltalk commandLineArguments at: idx + 1) asFilename.
+		file exists ifFalse:[
+		    '' errorPrintCR.
+		    ('smalltalk.rc [error]: preference file ''', file pathName,''' does not exist') errorPrintCR.
+		    Smalltalk exit: 1.
+		].
+		file isDirectory ifTrue:[
+		    '' errorPrintCR.
+		    ('smalltalk.rc [error]: preference file ''', file pathName,''' is not a regular file') errorPrintCR.
+		    Smalltalk exit: 1.
+		].
+		file isReadable ifFalse:[
+		    '' errorPrintCR.
+		    ('smalltalk.rc [error]: preference file ''', file pathName,''' is not a readable (check permissions)') errorPrintCR.
+		    Smalltalk exit: 1.
+		].
+		files := Array with: file.
+		Smalltalk commandLineArguments removeAtIndex: idx + 1.
+		Smalltalk commandLineArguments removeAtIndex: idx.
+	    ].
+	    files isNil ifTrue:[
+		files := {
+			    (Filename homeDirectory / '.smalltalk' / 'settings.stx') . "/ per-user settings file (new default?)
+			    (Filename homeDirectory / '.smalltalk' / 'settings.rc') .  "/ for backward compatibility with jv-branch
+			    (Smalltalk getSystemFileName: 'settings.stx') .            "/ old stx default
+			    (Smalltalk getSystemFileName: 'settings.rc') .             "/ for backward compatibility with jv-branch
+			 }.
+	    ].
+	    continue := true.
+	    files do:[:each|
+		| eachFile |
 
-	    (continue and:[each notNil and:[(eachFile := each asFilename) exists]]) ifTrue:[
-		continue := false.
-		eachFile pathName infoPrintCR.
-		eachFile fileIn.
-		UserPreferences current at:#settingsFilename put: eachFile pathName.
+		(continue and:[each notNil 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 ].
 	].
-	continue ifTrue:[ '(none found)' infoPrintCR ].
     ].
-
 ].
 !