Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
etherlabmaster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ICS Control System Infrastructure
etherlabmaster
Commits
ac873f53
Commit
ac873f53
authored
16 years ago
by
Florian Pose
Browse files
Options
Downloads
Patches
Plain Diff
Command abbreviation.
parent
a9c04c26
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tool/cmd_alias.cpp
+1
-1
1 addition, 1 deletion
tool/cmd_alias.cpp
tool/globals.h
+1
-1
1 addition, 1 deletion
tool/globals.h
tool/main.cpp
+68
-32
68 additions, 32 deletions
tool/main.cpp
with
70 additions
and
34 deletions
tool/cmd_alias.cpp
+
1
−
1
View file @
ac873f53
...
@@ -47,7 +47,7 @@ void command_alias(void)
...
@@ -47,7 +47,7 @@ void command_alias(void)
unsigned
int
numSlaves
,
i
;
unsigned
int
numSlaves
,
i
;
if
(
commandArgs
.
size
()
!=
1
)
{
if
(
commandArgs
.
size
()
!=
1
)
{
err
<<
"'"
<<
command
<<
"' takes exactly one argument!"
;
err
<<
"'"
<<
command
Name
<<
"' takes exactly one argument!"
;
throw
InvalidUsageException
(
err
);
throw
InvalidUsageException
(
err
);
}
}
...
...
This diff is collapsed.
Click to expand it.
tool/globals.h
+
1
−
1
View file @
ac873f53
...
@@ -21,7 +21,7 @@ enum Verbosity {
...
@@ -21,7 +21,7 @@ enum Verbosity {
Verbose
Verbose
};
};
extern
string
command
;
extern
string
command
Name
;
extern
int
slavePosition
;
extern
int
slavePosition
;
extern
int
domainIndex
;
extern
int
domainIndex
;
extern
vector
<
string
>
commandArgs
;
extern
vector
<
string
>
commandArgs
;
...
...
This diff is collapsed.
Click to expand it.
tool/main.cpp
+
68
−
32
View file @
ac873f53
...
@@ -20,7 +20,7 @@ string binaryBaseName;
...
@@ -20,7 +20,7 @@ string binaryBaseName;
unsigned
int
masterIndex
=
0
;
unsigned
int
masterIndex
=
0
;
int
slavePosition
=
-
1
;
int
slavePosition
=
-
1
;
int
domainIndex
=
-
1
;
int
domainIndex
=
-
1
;
string
command
;
string
command
Name
;
vector
<
string
>
commandArgs
;
vector
<
string
>
commandArgs
;
Verbosity
verbosity
=
Normal
;
Verbosity
verbosity
=
Normal
;
string
dataTypeStr
;
string
dataTypeStr
;
...
@@ -33,6 +33,7 @@ MasterDevice masterDev;
...
@@ -33,6 +33,7 @@ MasterDevice masterDev;
/*****************************************************************************/
/*****************************************************************************/
struct
Command
{
struct
Command
{
const
char
*
name
;
void
(
*
func
)(
void
);
void
(
*
func
)(
void
);
const
char
*
helpString
;
const
char
*
helpString
;
...
@@ -40,27 +41,20 @@ struct Command {
...
@@ -40,27 +41,20 @@ struct Command {
void
displayHelp
(
void
)
const
;
void
displayHelp
(
void
)
const
;
};
};
struct
CommandAlias
{
const
char
*
name
;
const
Command
*
command
;
};
/*****************************************************************************/
/*****************************************************************************/
#define COMMAND(name) \
#define COMMAND(name) \
void command_##name(void); \
void command_##name(void); \
extern const char *help_##name; \
extern const char *help_##name
const Command cmd_##name = {command_##name, help_##name};
#define INIT_COMMAND(name) {#name, command_##name, help_##name}
COMMAND
(
alias
);
COMMAND
(
alias
);
COMMAND
(
config
);
COMMAND
(
config
);
const
CommandAlias
commandAliases
[]
=
{
static
const
Command
commands
[]
=
{
{
"alias"
,
&
cmd_alias
},
INIT_COMMAND
(
alias
),
INIT_COMMAND
(
config
),
{
"config"
,
&
cmd_config
},
{
"conf"
,
&
cmd_config
},
{
"cf"
,
&
cmd_config
},
};
};
#if 0
#if 0
...
@@ -115,6 +109,7 @@ void printUsage()
...
@@ -115,6 +109,7 @@ void printUsage()
<<
" slaves Show slaves."
<<
endl
<<
" slaves Show slaves."
<<
endl
<<
" state Request slave states."
<<
endl
<<
" state Request slave states."
<<
endl
<<
" xml Generate slave information xmls."
<<
endl
<<
" xml Generate slave information xmls."
<<
endl
<<
"Commands can be generously abbreviated."
<<
endl
<<
"Global options:"
<<
endl
<<
"Global options:"
<<
endl
<<
" --master -m <master> Index of the master to use. Default: 0"
<<
" --master -m <master> Index of the master to use. Default: 0"
<<
endl
<<
endl
...
@@ -241,7 +236,7 @@ void getOptions(int argc, char **argv)
...
@@ -241,7 +236,7 @@ void getOptions(int argc, char **argv)
exit
(
!
helpRequested
);
exit
(
!
helpRequested
);
}
}
command
=
argv
[
optind
];
command
Name
=
argv
[
optind
];
while
(
++
optind
<
argc
)
while
(
++
optind
<
argc
)
commandArgs
.
push_back
(
string
(
argv
[
optind
]));
commandArgs
.
push_back
(
string
(
argv
[
optind
]));
}
}
...
@@ -271,7 +266,41 @@ int Command::execute() const
...
@@ -271,7 +266,41 @@ int Command::execute() const
void
Command
::
displayHelp
()
const
void
Command
::
displayHelp
()
const
{
{
cerr
<<
binaryBaseName
<<
" "
<<
command
<<
" "
<<
helpString
;
cerr
<<
binaryBaseName
<<
" "
<<
commandName
<<
" "
<<
helpString
;
}
/****************************************************************************/
bool
abbrevMatch
(
const
string
&
abb
,
const
string
&
full
)
{
unsigned
int
abbIndex
;
size_t
fullPos
=
0
;
for
(
abbIndex
=
0
;
abbIndex
<
abb
.
length
();
abbIndex
++
)
{
fullPos
=
full
.
find
(
abb
[
abbIndex
],
fullPos
);
if
(
fullPos
==
string
::
npos
)
return
false
;
}
return
true
;
}
/****************************************************************************/
list
<
const
Command
*>
getMatchingCommands
(
const
string
&
cmdStr
)
{
const
Command
*
cmd
,
*
endCmd
=
commands
+
sizeof
(
commands
)
/
sizeof
(
Command
);
list
<
const
Command
*>
res
;
// find matching commands
for
(
cmd
=
commands
;
cmd
<
endCmd
;
cmd
++
)
{
if
(
abbrevMatch
(
cmdStr
,
cmd
->
name
))
{
res
.
push_back
(
cmd
);
}
}
return
res
;
}
}
/****************************************************************************/
/****************************************************************************/
...
@@ -279,28 +308,35 @@ void Command::displayHelp() const
...
@@ -279,28 +308,35 @@ void Command::displayHelp() const
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
retval
=
0
;
int
retval
=
0
;
const
Command
Alias
*
alia
s
;
list
<
const
Command
*>
command
s
;
const
Command
Alias
*
endAlias
=
list
<
const
Command
*>::
const_iterator
ci
;
co
mmandAliases
+
sizeof
(
commandAliases
)
/
sizeof
(
CommandAlias
)
;
co
nst
Command
*
cmd
;
binaryBaseName
=
basename
(
argv
[
0
]);
binaryBaseName
=
basename
(
argv
[
0
]);
getOptions
(
argc
,
argv
);
getOptions
(
argc
,
argv
);
// search command alias in alias map
commands
=
getMatchingCommands
(
commandName
);
for
(
alias
=
commandAliases
;
alias
<
endAlias
;
alias
++
)
{
if
(
command
==
alias
->
name
)
if
(
commands
.
size
())
{
break
;
if
(
commands
.
size
()
==
1
)
{
}
cmd
=
commands
.
front
();
if
(
!
helpRequested
)
{
if
(
alias
<
endAlias
)
{
// command alias found
masterDev
.
setIndex
(
masterIndex
);
if
(
!
helpRequested
)
{
retval
=
cmd
->
execute
();
masterDev
.
setIndex
(
masterIndex
);
}
else
{
retval
=
alias
->
command
->
execute
();
cmd
->
displayHelp
();
}
}
else
{
}
else
{
alias
->
command
->
displayHelp
();
cerr
<<
"Ambigous command abbreviation! Matching:"
<<
endl
;
for
(
ci
=
commands
.
begin
();
ci
!=
commands
.
end
();
ci
++
)
{
cerr
<<
(
*
ci
)
->
name
<<
endl
;
}
cerr
<<
endl
;
printUsage
();
retval
=
1
;
}
}
}
else
{
// command not found
}
else
{
cerr
<<
"Unknown command "
<<
command
<<
"!"
<<
endl
<<
endl
;
cerr
<<
"Unknown command "
<<
command
Name
<<
"!"
<<
endl
<<
endl
;
printUsage
();
printUsage
();
retval
=
1
;
retval
=
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment