* Copyright (c) 1983 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
static char sccsid
[] = "@(#)timedc.c 2.7 (Berkeley) 11/20/88";
openlog("timedc", LOG_ODELAY
, LOG_AUTH
);
if (priv_resources() < 0) {
fprintf(stderr
, "Could not get priviledged 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
,