Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseArg関数の実装 #242

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions OpenRTM_aist/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1729,13 +1729,7 @@ def shutdownLogger(self):
def initORB(self):
self._rtcout.RTC_TRACE("Manager.initORB()")
try:
tmp_args = self.createORBOptions().split("\"")
args = []
for i, tmp_arg in enumerate(tmp_args):
if i % 2 == 0:
args.extend(tmp_arg.strip().split(" "))
else:
args.append(tmp_arg)
args = OpenRTM_aist.parseArgs(self.createORBOptions())

args.insert(0, "manager")
argv = OpenRTM_aist.toArgv(args)
Expand Down
87 changes: 87 additions & 0 deletions OpenRTM_aist/StringUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,90 @@ def getFileList(dir, ext, filelist=None):
if os.path.isfile(f):
filelist.append(f)
return filelist


##
# @if jp
# @brief 文字列を引数として解釈する
#
# @param args 文字列
# @return 引数リスト
#
#
#
# @else
# @brief Parse string as argument list
#
# @param args
# @return
#
#
# @endif
def parseArgs(args):
inArg = False
inEscape = False
inDquote = False
inSquote = False

ret = []
anArg = ""

for i in range(0, len(args)):
if args[i] == " " or args[i] == "\t":
if inEscape or inDquote or inSquote:
anArg += args[i]
continue
if not inArg:
continue
if inArg:
ret.append(anArg)
anArg = ""
inArg = False
continue
inArg = True

if args[i] == "\\":
if inEscape:
anArg += args[i]
inEscape = not inEscape
continue

if args[i] == "\"":
if inEscape:
inEscape = False
if inSquote:
anArg += "\\"
anArg += args[i]
continue

if inSquote:
anArg += args[i]
continue

inDquote = not inDquote
continue

if args[i] == "\'":
if inEscape:
inEscape = False
if inSquote:
anArg += "\\"
anArg += args[i]
continue

if inDquote:
anArg += args[i]
continue

inSquote = not inSquote
continue

if inEscape:
inEscape = False
if inDquote or inSquote:
anArg += "\\"

anArg += args[i]

ret.append(anArg)
return ret