Files
bash/CWRU/old/histctl.def
T
2011-12-03 12:52:47 -05:00

111 lines
3.2 KiB
Modula-2

This file is histctl.def, from which is created histctl.c.
It implements the builtin "histctl" in Bash.
Copyright (C) 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
$PRODUCES histctl.c
$BUILTIN histctl
$FUNCTION histctl_builtin
$DEPENDS_ON HISTORY
$SHORT_DOC histctl [-cC] [-iI space|dups|both|none]
Control how lines are saved into the command history. An option
of -c enables command-oriented history, in which all lines of a
compound command are saved as a single history entry. The -i
option permits certain lines to be discarded without being stored
in the history: SPACE means to ignore lines beginning with a space;
DUPS means to ignore lines the same as the last command entered
into the history; BOTH enables SPACE and DUPS; and NONE means to
store all lines.
$END
#include "../shell.h"
#if defined (HISTORY)
#include "bashgetopt.h"
#include "../bashhist.h"
#define HIGNORE_NONE 0x0
#define HIGNORE_SPACE 0x01
#define HIGNORE_DUPS 0x02
#define HIGNORE_BOTH (HIGNORE_SPACE | HIGNORE_DUPS)
int
histctl_builtin (list)
WORD_LIST *list;
{
int opt;
char *spec;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "CcI:i:")) != -1)
{
switch (opt)
{
case 'c':
command_oriented_history++;
break;
case 'C':
command_oriented_history = 0;
break;
case 'i':
spec = list_optarg;
if (strcmp (spec, "none") == 0)
history_control = HIGNORE_NONE;
else if (strcmp (spec, "space") == 0)
history_control |= HIGNORE_SPACE;
else if (strcmp (spec, "dups") == 0)
history_control |= HIGNORE_DUPS;
else if (strcmp (spec, "both") == 0)
history_control |= HIGNORE_BOTH;
else
{
builtin_error ("invalid argument to -i: %s", spec);
builtin_error ("usage: histctl [-cC] [-iI space|dups|both|none]");
return (EX_USAGE);
}
break;
case 'I':
spec = list_optarg;
if (strcmp (spec, "none") == 0)
history_control = HIGNORE_NONE;
else if (strcmp (spec, "space") == 0)
history_control &= ~HIGNORE_SPACE;
else if (strcmp (spec, "dups") == 0)
history_control &= ~HIGNORE_DUPS;
else if (strcmp (spec, "both") == 0)
history_control &= ~HIGNORE_BOTH;
else
{
builtin_error ("invalid argument to -I: %s", spec);
builtin_error ("usage: histctl [-cC] [-iI space|dups|both|none]");
return (EX_USAGE);
}
break;
default:
report_bad_option ();
builtin_error ("usage: histctl [-cC] [-iI space|dups|both|none]");
return (EX_USAGE);
}
}
return (EXECUTION_SUCCESS);
}
#endif /* HISTORY */