Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
unique-xids
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
unique-xids
Commits
e6a88dab
Commit
e6a88dab
authored
Feb 20, 2013
by
Tollef Fog Heen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a bit of tab completion to varnishadm
parent
52d81477
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
1 deletion
+65
-1
varnishadm.c
bin/varnishadm/varnishadm.c
+65
-1
No files found.
bin/varnishadm/varnishadm.c
View file @
e6a88dab
...
...
@@ -193,6 +193,41 @@ static void send_line(char *l)
RL_EXIT
(
0
);
}
}
static
char
*
commands
[
256
];
static
char
*
command_generator
(
const
char
*
text
,
int
state
)
{
static
int
list_index
,
len
;
const
char
*
name
;
/* If this is a new word to complete, initialize now. This
includes saving the length of TEXT for efficiency, and
initializing the index variable to 0. */
if
(
!
state
)
{
list_index
=
0
;
len
=
strlen
(
text
);
}
while
((
name
=
commands
[
list_index
])
!=
NULL
)
{
list_index
++
;
if
(
strncmp
(
name
,
text
,
len
)
==
0
)
return
(
strdup
(
name
));
}
/* If no names matched, then return NULL. */
return
(
NULL
);
}
static
char
**
varnishadm_completion
(
const
char
*
text
,
int
start
,
int
end
)
{
char
**
matches
;
(
void
)
end
;
matches
=
(
char
**
)
NULL
;
if
(
start
==
0
)
matches
=
rl_completion_matches
(
text
,
command_generator
);
return
(
matches
);
}
#endif
/*
...
...
@@ -219,13 +254,42 @@ pass(int sock)
}
else
{
rl_callback_handler_install
(
""
,
send_line
);
}
rl_attempted_completion_function
=
varnishadm_completion
;
#endif
cli_write
(
sock
,
"banner
\n
"
);
fds
[
0
].
fd
=
sock
;
fds
[
0
].
events
=
POLLIN
;
fds
[
1
].
fd
=
0
;
fds
[
1
].
events
=
POLLIN
;
/* Grab the commands, for completion */
cli_write
(
sock
,
"help
\n
"
);
u
=
VCLI_ReadResult
(
fds
[
0
].
fd
,
&
status
,
&
answer
,
timeout
);
if
(
!
u
)
{
char
*
t
,
c
[
128
];
if
(
status
==
CLIS_COMMS
)
{
RL_EXIT
(
0
);
}
t
=
answer
;
i
=
0
;
while
(
*
t
)
{
if
(
sscanf
(
t
,
"%127s"
,
c
)
==
1
)
{
commands
[
i
++
]
=
strdup
(
c
);
while
(
*
t
!=
'\n'
&&
*
t
!=
'\0'
)
t
++
;
if
(
*
t
==
'\n'
)
t
++
;
}
else
{
/* what? */
fprintf
(
stderr
,
"Unknown command '%s' parsing "
"help output. Tab completion may be "
"broken
\n
"
,
t
);
break
;
}
}
}
cli_write
(
sock
,
"banner
\n
"
);
while
(
1
)
{
i
=
poll
(
fds
,
2
,
-
1
);
if
(
i
==
-
1
&&
errno
==
EINTR
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment