home *** CD-ROM | disk | FTP | other *** search
- /* vi:tabstop=4:shiftwidth=4:smartindent
- *
- * history.c - Lists the history list, either the whole list
- * or the last n.
- *
- */
-
- #include <stdio.h>
- #include <history.h>
- #include "psh.h"
-
- int sh_history(int argc, char **argv)
- {
- int i, j;
- int first = 0;
- HIST_ENTRY **hlist;
-
- /* If there were args, then try to read the number
- */
- if (argc > 1)
- {
- if ((sscanf(argv[1], "%d", &first) != 1) || (first >= 0))
- {
- fprintf(stderr, "Usage: history -n\n");
- return 1;
- }
- }
-
- /* Read the history list
- */
- hlist = history_list();
- if (hlist == NULL)
- {
- printf("No history stored\n");
- }
- else
- {
- /* Read the list length
- */
- for (j=0; hlist[j]; j++);
-
- /* Print the list
- */
- first = (first == 0) ? first : j+first;
- for (i=first; hlist[i]; i++)
- {
- printf("%5d %s\n", history_base + i, hlist[i]->line);
- }
- }
- return 0;
- }
-