[BACK]Return to prompt.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libedit

Annotation of src/lib/libedit/prompt.c, Revision 1.9

1.9     ! christos    1: /*     $NetBSD: prompt.c,v 1.8 2001/01/10 07:45:41 jdolecek Exp $      */
1.2       lukem       2:
1.1       cgd         3: /*-
                      4:  * Copyright (c) 1992, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to Berkeley by
                      8:  * Christos Zoulas of Cornell University.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed by the University of
                     21:  *     California, Berkeley and its contributors.
                     22:  * 4. Neither the name of the University nor the names of its contributors
                     23:  *    may be used to endorse or promote products derived from this software
                     24:  *    without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  */
                     38:
1.9     ! christos   39: #include "config.h"
1.1       cgd        40: #if !defined(lint) && !defined(SCCSID)
1.2       lukem      41: #if 0
1.1       cgd        42: static char sccsid[] = "@(#)prompt.c   8.1 (Berkeley) 6/4/93";
1.2       lukem      43: #else
1.9     ! christos   44: __RCSID("$NetBSD: prompt.c,v 1.8 2001/01/10 07:45:41 jdolecek Exp $");
1.2       lukem      45: #endif
1.1       cgd        46: #endif /* not lint && not SCCSID */
                     47:
                     48: /*
                     49:  * prompt.c: Prompt printing functions
                     50:  */
                     51: #include <stdio.h>
                     52: #include "el.h"
                     53:
1.7       lukem      54: private char   *prompt_default(EditLine *);
                     55: private char   *prompt_default_r(EditLine *);
1.1       cgd        56:
                     57: /* prompt_default():
                     58:  *     Just a default prompt, in case the user did not provide one
                     59:  */
                     60: private char *
                     61: /*ARGSUSED*/
1.7       lukem      62: prompt_default(EditLine *el)
1.1       cgd        63: {
1.7       lukem      64:        static char a[3] = {'?', ' ', '\0'};
                     65:
                     66:        return (a);
1.1       cgd        67: }
                     68:
1.7       lukem      69:
1.6       lukem      70: /* prompt_default_r():
                     71:  *     Just a default rprompt, in case the user did not provide one
                     72:  */
                     73: private char *
                     74: /*ARGSUSED*/
1.7       lukem      75: prompt_default_r(EditLine *el)
1.6       lukem      76: {
1.7       lukem      77:        static char a[1] = {'\0'};
                     78:
                     79:        return (a);
1.6       lukem      80: }
                     81:
1.1       cgd        82:
                     83: /* prompt_print():
                     84:  *     Print the prompt and update the prompt position.
                     85:  *     We use an array of integers in case we want to pass
                     86:  *     literal escape sequences in the prompt and we want a
                     87:  *     bit to flag them
                     88:  */
                     89: protected void
1.7       lukem      90: prompt_print(EditLine *el, int op)
                     91: {
                     92:        el_prompt_t *elp;
                     93:        char *p;
                     94:
                     95:        if (op == EL_PROMPT)
                     96:                elp = &el->el_prompt;
                     97:        else
                     98:                elp = &el->el_rprompt;
                     99:        p = (elp->p_func) (el);
                    100:        while (*p)
1.8       jdolecek  101:                re_putc(el, *p++, 1);
1.7       lukem     102:
                    103:        elp->p_pos.v = el->el_refresh.r_cursor.v;
                    104:        elp->p_pos.h = el->el_refresh.r_cursor.h;
                    105: }
1.1       cgd       106:
                    107:
                    108: /* prompt_init():
                    109:  *     Initialize the prompt stuff
                    110:  */
1.5       simonb    111: protected int
1.7       lukem     112: prompt_init(EditLine *el)
1.1       cgd       113: {
1.7       lukem     114:
                    115:        el->el_prompt.p_func = prompt_default;
                    116:        el->el_prompt.p_pos.v = 0;
                    117:        el->el_prompt.p_pos.h = 0;
                    118:        el->el_rprompt.p_func = prompt_default_r;
                    119:        el->el_rprompt.p_pos.v = 0;
                    120:        el->el_rprompt.p_pos.h = 0;
                    121:        return (0);
                    122: }
1.1       cgd       123:
                    124:
                    125: /* prompt_end():
                    126:  *     Clean up the prompt stuff
                    127:  */
                    128: protected void
1.5       simonb    129: /*ARGSUSED*/
1.7       lukem     130: prompt_end(EditLine *el)
1.1       cgd       131: {
1.7       lukem     132: }
1.1       cgd       133:
                    134:
                    135: /* prompt_set():
                    136:  *     Install a prompt printing function
                    137:  */
1.5       simonb    138: protected int
1.7       lukem     139: prompt_set(EditLine *el, el_pfunc_t prf, int op)
                    140: {
                    141:        el_prompt_t *p;
                    142:
1.6       lukem     143:        if (op == EL_PROMPT)
1.7       lukem     144:                p = &el->el_prompt;
1.6       lukem     145:        else
1.7       lukem     146:                p = &el->el_rprompt;
                    147:        if (prf == NULL) {
                    148:                if (op == EL_PROMPT)
                    149:                        p->p_func = prompt_default;
                    150:                else
                    151:                        p->p_func = prompt_default_r;
                    152:        } else
                    153:                p->p_func = prf;
                    154:        p->p_pos.v = 0;
                    155:        p->p_pos.h = 0;
                    156:        return (0);
                    157: }
1.4       lukem     158:
                    159:
                    160: /* prompt_get():
                    161:  *     Retrieve the prompt printing function
                    162:  */
1.5       simonb    163: protected int
1.7       lukem     164: prompt_get(EditLine *el, el_pfunc_t *prf, int op)
                    165: {
                    166:
                    167:        if (prf == NULL)
                    168:                return (-1);
                    169:        if (op == EL_PROMPT)
                    170:                *prf = el->el_prompt.p_func;
                    171:        else
                    172:                *prf = el->el_rprompt.p_func;
                    173:        return (0);
                    174: }

CVSweb <webmaster@jp.NetBSD.org>