~ubuntu-branches/debian/experimental/lftp/experimental

« back to all changes in this revision

Viewing changes to src/lftp_rl.c

  • Committer: Package Import Robot
  • Author(s): Noël Köthe
  • Date: 2015-08-21 16:06:22 UTC
  • mfrom: (1.1.20) (24.1.38 sid)
  • Revision ID: package-import@ubuntu.com-20150821160622-lckdmbiqx16wefgy
Tags: 4.6.4-1
new upstream release 2015-08-21

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * lftp - file transfer program
3
3
 *
4
 
 * Copyright (c) 1999-2001 by Alexander V. Lukyanov (lav@yars.free.net)
 
4
 * Copyright (c) 1996-2013 by Alexander V. Lukyanov (lav@yars.free.net)
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
 
/* $Id: lftp_rl.c,v 1.18 2008/11/27 05:56:38 lav Exp $ */
22
 
 
23
20
#include <config.h>
24
21
#include <stdio.h>
25
22
#include <readline/readline.h>
34
31
void lftp_add_history_nodups(const char *cmd_buf)
35
32
{
36
33
   HIST_ENTRY *temp;
 
34
   char ts[24];
 
35
   if(cmd_buf[0]==' ')
 
36
      return;
37
37
   using_history();
38
38
   temp=previous_history();
39
39
   if(temp==0 || strcmp(temp->line,cmd_buf))
40
40
      add_history(cmd_buf);
 
41
   sprintf(ts," %lld",(long long)time(0));
 
42
   add_history_time(ts);
41
43
   using_history();
42
44
}
43
45
 
78
80
   i = history_base + st->length - cnt;
79
81
   if(cnt == -1 || i < history_base) i = history_base;
80
82
 
81
 
   while((hist = history_get(i)))
82
 
      printf("%5d%c %s\n", i++, hist->data?'*':' ', hist->line);
 
83
   char ts_str[24];
 
84
   while((hist = history_get(i))) {
 
85
      ts_str[0]=0;
 
86
      if(hist->timestamp[0]) {
 
87
         time_t ts=atol(hist->timestamp+1);
 
88
         strftime(ts_str,sizeof(ts_str),"%Y-%m-%d %H:%M:%S",localtime(&ts));
 
89
      }
 
90
      printf("%5d%c %s  %s\n", i++, hist->data?'*':' ', ts_str, hist->line);
 
91
   }
83
92
}
84
93
 
85
94
void lftp_history_clear()
157
166
   rl_attempted_completion_function  =attempted_completion_function;
158
167
   rl_getc_function                  =getc_function;
159
168
   rl_completer_quote_characters     =completer_quote_characters;
160
 
   rl_completer_word_break_characters=completer_word_break_characters;
 
169
   rl_completer_word_break_characters=(char*)completer_word_break_characters;
161
170
   rl_filename_quote_characters      =filename_quote_characters;
162
171
   rl_filename_quoting_function      =filename_quoting_function;
163
 
   rl_filename_dequoting_function    =filename_dequoting_function;
164
 
   rl_char_is_quoted_p               =char_is_quoted_p;
 
172
   rl_filename_dequoting_function    =(rl_dequote_func_t*)filename_dequoting_function;
 
173
   rl_char_is_quoted_p               =(rl_linebuf_func_t*)char_is_quoted_p;
165
174
 
166
175
   rl_completion_display_matches_hook = lftp_rl_display_match_list;
 
176
 
 
177
   history_write_timestamps=1;
 
178
   history_comment_char=' ';
167
179
}
168
180
 
169
181
void lftp_rl_add_defun(const char *name,int (*func)(int,int),int key)
182
194
   rl_set_prompt(p);
183
195
}
184
196
 
185
 
extern char *get_lftp_home();
 
197
extern char *get_lftp_data_dir();
186
198
 
187
199
static char *lftp_history_file;
188
200
void lftp_rl_read_history()
190
202
   if(!lftp_history_file)
191
203
   {
192
204
      const char *add="/rl_history";
193
 
      const char *home=get_lftp_home();
 
205
      const char *home=get_lftp_data_dir();
194
206
      if(!home)
195
207
         return;
196
208
      lftp_history_file=(char*)malloc(strlen(home)+strlen(add)+1);
204
216
      return;
205
217
   write_history(lftp_history_file);
206
218
}
 
219
 
 
220
void lftp_rl_history_stifle(int s)
 
221
{
 
222
   if(s==0)
 
223
      unstifle_history();
 
224
   else
 
225
      stifle_history(s);
 
226
}