1*27916d7cSchristos /* $NetBSD: hist.h,v 1.23 2017/09/01 10:19:10 christos Exp $ */ 22543e3e6Slukem 36dc2f1dbScgd /*- 46dc2f1dbScgd * Copyright (c) 1992, 1993 56dc2f1dbScgd * The Regents of the University of California. All rights reserved. 66dc2f1dbScgd * 76dc2f1dbScgd * This code is derived from software contributed to Berkeley by 86dc2f1dbScgd * Christos Zoulas of Cornell University. 96dc2f1dbScgd * 106dc2f1dbScgd * Redistribution and use in source and binary forms, with or without 116dc2f1dbScgd * modification, are permitted provided that the following conditions 126dc2f1dbScgd * are met: 136dc2f1dbScgd * 1. Redistributions of source code must retain the above copyright 146dc2f1dbScgd * notice, this list of conditions and the following disclaimer. 156dc2f1dbScgd * 2. Redistributions in binary form must reproduce the above copyright 166dc2f1dbScgd * notice, this list of conditions and the following disclaimer in the 176dc2f1dbScgd * documentation and/or other materials provided with the distribution. 18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors 196dc2f1dbScgd * may be used to endorse or promote products derived from this software 206dc2f1dbScgd * without specific prior written permission. 216dc2f1dbScgd * 226dc2f1dbScgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 236dc2f1dbScgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 246dc2f1dbScgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 256dc2f1dbScgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 266dc2f1dbScgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 276dc2f1dbScgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 286dc2f1dbScgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 296dc2f1dbScgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 306dc2f1dbScgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 316dc2f1dbScgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 326dc2f1dbScgd * SUCH DAMAGE. 336dc2f1dbScgd * 346dc2f1dbScgd * @(#)hist.h 8.1 (Berkeley) 6/4/93 356dc2f1dbScgd */ 366dc2f1dbScgd 376dc2f1dbScgd /* 386dc2f1dbScgd * el.hist.c: History functions 396dc2f1dbScgd */ 406dc2f1dbScgd #ifndef _h_el_hist 416dc2f1dbScgd #define _h_el_hist 426dc2f1dbScgd 430aefc7f9Schristos typedef int (*hist_fun_t)(void *, HistEventW *, int, ...); 446dc2f1dbScgd 456dc2f1dbScgd typedef struct el_history_t { 460594af80Schristos wchar_t *buf; /* The history buffer */ 4700ff7cacSjdolecek size_t sz; /* Size of history buffer */ 480594af80Schristos wchar_t *last; /* The last character */ 496dc2f1dbScgd int eventno; /* Event we are looking for */ 50a13cd756Schristos void *ref; /* Argument for history fcns */ 516dc2f1dbScgd hist_fun_t fun; /* Event access */ 520aefc7f9Schristos HistEventW ev; /* Event cookie */ 536dc2f1dbScgd } el_history_t; 546dc2f1dbScgd 550b9ae3fdSchristos #define HIST_FUN_INTERNAL(el, fn, arg) \ 56a7db9a79Schristos ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \ 57a7db9a79Schristos fn, arg)) == -1) ? NULL : (el)->el_history.ev.str) 580b9ae3fdSchristos #define HIST_FUN(el, fn, arg) \ 590b9ae3fdSchristos (((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \ 600b9ae3fdSchristos HIST_FUN_INTERNAL(el, fn, arg)) 616dc2f1dbScgd 626dc2f1dbScgd #define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL) 636dc2f1dbScgd #define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL) 646dc2f1dbScgd #define HIST_LAST(el) HIST_FUN(el, H_LAST, NULL) 656dc2f1dbScgd #define HIST_PREV(el) HIST_FUN(el, H_PREV, NULL) 6639f224afSchristos #define HIST_SET(el, num) HIST_FUN(el, H_SET, num) 6795b0e87bSchristos #define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname) 6895b0e87bSchristos #define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname) 69*27916d7cSchristos #define HIST_SAVE_FP(el, fp) HIST_FUN(el, H_SAVE_FP, fp) 70*27916d7cSchristos #define HIST_NSAVE_FP(el, n, fp) HIST_FUN(el, H_NSAVE_FP, n, fp) 716dc2f1dbScgd 72a2d6b270Schristos libedit_private int hist_init(EditLine *); 73a2d6b270Schristos libedit_private void hist_end(EditLine *); 74a2d6b270Schristos libedit_private el_action_t hist_get(EditLine *); 75a2d6b270Schristos libedit_private int hist_set(EditLine *, hist_fun_t, void *); 76a2d6b270Schristos libedit_private int hist_command(EditLine *, int, const wchar_t **); 77a2d6b270Schristos libedit_private int hist_enlargebuf(EditLine *, size_t, size_t); 78a2d6b270Schristos libedit_private wchar_t *hist_convert(EditLine *, int, void *); 796dc2f1dbScgd 806dc2f1dbScgd #endif /* _h_el_hist */ 81