* Copyright (c) 1983 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
static char sccsid
[] = "@(#)timedc.c 2.10 (Berkeley) 3/5/91";
openlog("timedc", LOG_ODELAY
, LOG_AUTH
);
if (priv_resources() < 0) {
fprintf(stderr
, "Could not get privileged resources\n");
if (c
== (struct cmd
*)-1) {
printf("?Ambiguous command\n");
printf("?Invalid command\n");
if (c
->c_priv
&& getuid()) {
printf("?Privileged command\n");
(*c
->c_handler
)(argc
, argv
);
fromatty
= isatty(fileno(stdin
));
top
= setjmp(toplevel
) == 0;
(void) signal(SIGINT
, intr
);
if (fgets(cmdline
, sizeof(cmdline
), stdin
) == 0)
if (c
== (struct cmd
*)-1) {
printf("?Ambiguous command\n");
printf("?Invalid command\n");
if (c
->c_priv
&& getuid()) {
printf("?Privileged command\n");
(*c
->c_handler
)(margc
, margv
);
register struct cmd
*c
, *found
;
register int nmatches
, longest
;
extern struct cmd cmdtab
[];
for (c
= cmdtab
; c
< &cmdtab
[NCMDS
]; c
++) {
for (q
= name
; *q
== *p
++; q
++)
if (*q
== 0) /* exact match? */
if (!*q
) { /* the name was a prefix */
if (q
- name
> longest
) {
} else if (q
- name
== longest
)
return((struct cmd
*)-1);
* Slice a string up into argc/argv.
register char **argp
= margv
;
for (cp
= cmdline
; *cp
;) {
while (*cp
!= '\0' && !isspace(*cp
))
#define HELPINDENT (sizeof ("directory"))
extern struct cmd cmdtab
[];
int columns
, width
= 0, lines
;
printf("Commands may be abbreviated. Commands are:\n\n");
for (c
= cmdtab
; c
< &cmdtab
[NCMDS
]; c
++) {
int len
= strlen(c
->c_name
);
width
= (width
+ 8) &~ 7;
lines
= (NCMDS
+ columns
- 1) / columns
;
for (i
= 0; i
< lines
; i
++) {
for (j
= 0; j
< columns
; j
++) {
c
= cmdtab
+ j
* lines
+ i
;
if (c
+ lines
>= &cmdtab
[NCMDS
]) {
if (c
== (struct cmd
*)-1)
printf("?Ambiguous help command %s\n", arg
);
else if (c
== (struct cmd
*)0)
printf("?Invalid help command %s\n", arg
);
printf("%-*s\t%s\n", HELPINDENT
,