Use getopts parser to find 'read' arrays (fixes #2073)
This commit is contained in:
parent
3104cec770
commit
256457c47a
|
@ -851,7 +851,8 @@ prop_checkArrayWithoutIndex6 = verifyTree checkArrayWithoutIndex "echo $PIPESTAT
|
||||||
prop_checkArrayWithoutIndex7 = verifyTree checkArrayWithoutIndex "a=(a b); a+=c"
|
prop_checkArrayWithoutIndex7 = verifyTree checkArrayWithoutIndex "a=(a b); a+=c"
|
||||||
prop_checkArrayWithoutIndex8 = verifyTree checkArrayWithoutIndex "declare -a foo; foo=bar;"
|
prop_checkArrayWithoutIndex8 = verifyTree checkArrayWithoutIndex "declare -a foo; foo=bar;"
|
||||||
prop_checkArrayWithoutIndex9 = verifyTree checkArrayWithoutIndex "read -r -a arr <<< 'foo bar'; echo \"$arr\""
|
prop_checkArrayWithoutIndex9 = verifyTree checkArrayWithoutIndex "read -r -a arr <<< 'foo bar'; echo \"$arr\""
|
||||||
prop_checkArrayWithoutIndex10= verifyTree checkArrayWithoutIndex "read -ra arr <<< 'foo bar'; echo \"$arr\""
|
prop_checkArrayWithoutIndex10 = verifyTree checkArrayWithoutIndex "read -ra arr <<< 'foo bar'; echo \"$arr\""
|
||||||
|
prop_checkArrayWithoutIndex11 = verifyNotTree checkArrayWithoutIndex "read -rpfoobar r; r=42"
|
||||||
checkArrayWithoutIndex params _ =
|
checkArrayWithoutIndex params _ =
|
||||||
doVariableFlowAnalysis readF writeF defaultMap (variableFlow params)
|
doVariableFlowAnalysis readF writeF defaultMap (variableFlow params)
|
||||||
where
|
where
|
||||||
|
|
|
@ -578,10 +578,14 @@ getModifiedVariableCommand base@(T_SimpleCommand id cmdPrefix (T_NormalWord _ (T
|
||||||
"builtin" ->
|
"builtin" ->
|
||||||
getModifiedVariableCommand $ T_SimpleCommand id cmdPrefix rest
|
getModifiedVariableCommand $ T_SimpleCommand id cmdPrefix rest
|
||||||
"read" ->
|
"read" ->
|
||||||
let params = map getLiteral rest
|
let fallback = catMaybes $ takeWhile isJust (reverse $ map getLiteral rest)
|
||||||
readArrayVars = getReadArrayVariables rest
|
in fromMaybe fallback $ do
|
||||||
in
|
parsed <- getGnuOpts flagsForRead rest
|
||||||
catMaybes $ takeWhile isJust (reverse params) ++ readArrayVars
|
case lookup "a" parsed of
|
||||||
|
Just (_, var) -> (:[]) <$> getLiteralArray var
|
||||||
|
Nothing -> return $ catMaybes $
|
||||||
|
map (getLiteral . snd . snd) $ filter (null . fst) parsed
|
||||||
|
|
||||||
"getopts" ->
|
"getopts" ->
|
||||||
case rest of
|
case rest of
|
||||||
opts:var:_ -> maybeToList $ getLiteral var
|
opts:var:_ -> maybeToList $ getLiteral var
|
||||||
|
@ -698,16 +702,6 @@ getModifiedVariableCommand base@(T_SimpleCommand id cmdPrefix (T_NormalWord _ (T
|
||||||
guard $ isVariableName name
|
guard $ isVariableName name
|
||||||
return (name, arg)
|
return (name, arg)
|
||||||
|
|
||||||
-- get all the array variables used in read, e.g. read -a arr
|
|
||||||
getReadArrayVariables args =
|
|
||||||
map (getLiteralArray . snd)
|
|
||||||
(filter (isArrayFlag . fst) (zip args (tail args)))
|
|
||||||
|
|
||||||
isArrayFlag x = case getLiteralString x of
|
|
||||||
Just ('-':'-':_) -> False
|
|
||||||
Just ('-':str) -> 'a' `elem` str
|
|
||||||
_ -> False
|
|
||||||
|
|
||||||
-- get the FLAGS_ variable created by a shflags DEFINE_ call
|
-- get the FLAGS_ variable created by a shflags DEFINE_ call
|
||||||
getFlagVariable (n:v:_) = do
|
getFlagVariable (n:v:_) = do
|
||||||
name <- getLiteralString n
|
name <- getLiteralString n
|
||||||
|
|
Loading…
Reference in New Issue