"Fossies" - the Fresh Open Source Software Archive

Member "tnftp-20200705/libedit/prompt.c" (4 Jul 2020, 4917 Bytes) of package /linux/privat/tnftp-20200705.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "prompt.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 20151004_vs_20200705.

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