summaryrefslogtreecommitdiff
path: root/src-3.0/GF/Command
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-06-24 13:58:04 +0000
committeraarne <aarne@cs.chalmers.se>2008-06-24 13:58:04 +0000
commit239f310eb560763c215400a41af7e21fa0f2d51f (patch)
treeafad2f258975e34b40e2e60ead2436ef98c38411 /src-3.0/GF/Command
parent223480bb77d5a86f3a9dcb2f02fcafbd89de453a (diff)
cp1251 coding ; trying to recognize the coding flag in grammar
Diffstat (limited to 'src-3.0/GF/Command')
-rw-r--r--src-3.0/GF/Command/Abstract.hs4
-rw-r--r--src-3.0/GF/Command/Commands.hs23
2 files changed, 20 insertions, 7 deletions
diff --git a/src-3.0/GF/Command/Abstract.hs b/src-3.0/GF/Command/Abstract.hs
index 23f76fa82..16905c2f9 100644
--- a/src-3.0/GF/Command/Abstract.hs
+++ b/src-3.0/GF/Command/Abstract.hs
@@ -60,4 +60,8 @@ isFlag o opts = elem o [x | OFlag x _ <- opts]
prOpt :: Option -> String
prOpt (OOpt i) = i ----
+mkOpt :: String -> Option
+mkOpt = OOpt
+
+
diff --git a/src-3.0/GF/Command/Commands.hs b/src-3.0/GF/Command/Commands.hs
index 68e2c5526..b5ba99f6f 100644
--- a/src-3.0/GF/Command/Commands.hs
+++ b/src-3.0/GF/Command/Commands.hs
@@ -32,6 +32,8 @@ import Data.Maybe
import qualified Data.Map as Map
import System.Cmd
+import Debug.Trace
+
type CommandOutput = ([Tree],String) ---- errors, etc
data CommandInfo = CommandInfo {
@@ -343,7 +345,7 @@ allCommands pgf = Map.fromList [
"ps -from_utf8 \"jag ?r h?r\" | p -- parser in LangSwe in UTF8 terminal",
"ps -to_devanagari -to_utf8 \"A-p\" -- show Devanagari in UTF8 terminal"
],
- exec = \opts -> return . fromString . stringOps opts . toString,
+ exec = \opts -> return . fromString . stringOps (map prOpt opts) . toString,
options = stringOpOptions
}),
("q", emptyCommandInfo {
@@ -497,11 +499,18 @@ allCommands pgf = Map.fromList [
(abstractName pgf ++ ": " ++ showTree t) :
[lang ++ ": " ++ linear opts lang t | lang <- optLangs opts]
- unlex opts lang = stringOps (exceptUTF8 opts) where
- exceptUTF8 = if isUTF8 then filter ((/="to_UTF8") . prOpt) else id
- isUTF8 = case lookFlag pgf lang "coding" of
- Just "utf8" -> True
- _ -> False
+-- logic of coding in unlexing:
+-- - If lang has no coding flag, or -to_utf8 is not in opts, just opts are used.
+-- - If lang has flag coding=utf8, -to_utf8 is ignored.
+-- - If lang has coding=other, and -to_utf8 is in opts, from_other is applied first.
+
+ unlex opts lang = {- trace (unwords optsC) $ -} stringOps optsC where
+ optsC = case lookFlag pgf lang "coding" of
+ Just "utf8" -> filter (/="to_utf8") $ map prOpt opts
+ Just other | isOpt "to_utf8" opts ->
+ let cod = ("from_" ++ other)
+ in cod : filter (/=cod) (map prOpt opts)
+ _ -> map prOpt opts
optRestricted opts = restrictPGF (hasLin pgf (mkCId (optLang opts))) pgf
@@ -536,7 +545,7 @@ allCommands pgf = Map.fromList [
[lookupMorpho (buildMorpho pgf (mkCId la)) s | la <- optLangs opts]
-- ps -f -g s returns g (f s)
- stringOps opts s = foldr app s (reverse (map prOpt opts)) where
+ stringOps opts s = foldr app s (reverse opts) where
app f = maybe id id (stringOp f)
stringOpOptions = [