File: history.c

package info (click to toggle)
kbtin 1.0.17-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 2,216 kB
  • sloc: ansic: 18,124; sh: 7,640; perl: 142; makefile: 137
file content (115 lines) | stat: -rw-r--r-- 3,210 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*********************************************************************/
/* file: history.c - functions for the history stuff                 */
/*                             TINTIN III                            */
/*          (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t             */
/*                     coded by peter unold 1992                     */
/*********************************************************************/
#include "tintin.h"
#include "protos/print.h"
#include "protos/parse.h"
#include "protos/utils.h"

static void insert_history(char *buffer);

extern char *history[HISTORY_SIZE];

/************************/
/* the #history command */
/************************/
void history_command(char *arg, struct session *ses)
{
    int i;

    for (i = HISTORY_SIZE - 1; i >= 0; i--)
        if (history[i])
            tintin_printf(ses, "%2d %s ", i, history[i]);
    prompt(NULL);
}



void do_history(char *buffer, struct session *ses)
{
    char result[BUFFER_SIZE], *cptr;

    if (!ses->verbatim && *(cptr=space_out(buffer)))
    {

        if (*cptr == '!')
        {
            if (*(cptr + 1) == '!')
            {
                if (history[0])
                {
                    strcpy(result, history[0]);
                    strcat(result, cptr + 2);
                    strcpy(buffer, result);
                }
            }
            else if (isadigit(*(cptr + 1)))
            {
                int i = atoi(cptr + 1);

                if (i >= 0 && i < HISTORY_SIZE && history[i])
                {
                    strcpy(result, history[i]);
                    strcat(result, cptr + 2);
                    strcpy(buffer, result);
                }
            }
            else
            {
                int i;

                for (i = 0; i < HISTORY_SIZE && history[i]; i++)
                    if (is_abrev(cptr + 1, history[i]))
                    {
                        strcpy(buffer, history[i]);
                        break;
                    }
            }

        }
    }
    insert_history(buffer);
}

/***********************************************/
/* insert buffer into a session`s history list */
/***********************************************/
static void insert_history(char *buffer)
{
    int i;

    if (history[HISTORY_SIZE - 1])
        SFREE(history[HISTORY_SIZE - 1]);

    for (i = HISTORY_SIZE - 1; i > 0; i--)
        history[i] = history[i - 1];

    history[0] = mystrdup(buffer);
}

#if 0
/************************************************************/
/* do all the parse stuff for !XXXX history commands        */
/************************************************************/
struct session* parse_history(char *command, char *arg, struct session *ses)
{
    if ((*(command + 1) == '!' || !*(command + 1)) && history[0])
        return parse_input(history[0],1,ses); /* we're already not in verbatim */

    else if (isadigit(*(command + 1)))
    {
        int i = atoi(command + 1);

        if (i >= 0 && i < HISTORY_SIZE && history[i])
        {
            return parse_input(history[i],1,ses);
        }
    }
    tintin_eprintf(ses, "#HISTORY: I DON'T REMEMBER THAT COMMAND.");

    return ses;
}
#endif