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

Annotation of src/lib/libedit/el.c, Revision 1.92.8.1

1.92.8.1! snj         1: /*     $NetBSD: el.c,v 1.92 2016/05/22 19:44:26 christos 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.
1.32      agc        18:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        19:  *    may be used to endorse or promote products derived from this software
                     20:  *    without specific prior written permission.
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     23:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     24:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     26:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32:  * SUCH DAMAGE.
                     33:  */
                     34:
1.29      christos   35: #include "config.h"
1.1       cgd        36: #if !defined(lint) && !defined(SCCSID)
1.2       lukem      37: #if 0
1.1       cgd        38: static char sccsid[] = "@(#)el.c       8.2 (Berkeley) 1/3/94";
1.2       lukem      39: #else
1.92.8.1! snj        40: __RCSID("$NetBSD: el.c,v 1.92 2016/05/22 19:44:26 christos Exp $");
1.2       lukem      41: #endif
1.1       cgd        42: #endif /* not lint && not SCCSID */
                     43:
                     44: /*
                     45:  * el.c: EditLine interface functions
                     46:  */
                     47: #include <sys/types.h>
                     48: #include <sys/param.h>
1.82      christos   49: #include <ctype.h>
1.84      christos   50: #include <langinfo.h>
                     51: #include <locale.h>
1.82      christos   52: #include <stdarg.h>
                     53: #include <stdlib.h>
1.1       cgd        54: #include <string.h>
1.75      christos   55:
1.1       cgd        56: #include "el.h"
1.81      christos   57: #include "parse.h"
1.89      christos   58: #include "read.h"
1.1       cgd        59:
                     60: /* el_init():
                     61:  *     Initialize editline and set default parameters.
                     62:  */
1.88      christos   63: EditLine *
1.19      lukem      64: el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
1.1       cgd        65: {
1.72      christos   66:     return el_init_fd(prog, fin, fout, ferr, fileno(fin), fileno(fout),
                     67:        fileno(ferr));
                     68: }
                     69:
1.88      christos   70: EditLine *
1.72      christos   71: el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
                     72:     int fdin, int fdout, int fderr)
                     73: {
1.67      christos   74:        EditLine *el = el_malloc(sizeof(*el));
1.1       cgd        75:
1.19      lukem      76:        if (el == NULL)
1.68      christos   77:                return NULL;
1.1       cgd        78:
1.19      lukem      79:        memset(el, 0, sizeof(EditLine));
1.1       cgd        80:
1.44      christos   81:        el->el_infile = fin;
1.19      lukem      82:        el->el_outfile = fout;
                     83:        el->el_errfile = ferr;
1.44      christos   84:
1.72      christos   85:        el->el_infd = fdin;
                     86:        el->el_outfd = fdout;
                     87:        el->el_errfd = fderr;
1.44      christos   88:
1.86      christos   89:        el->el_prog = wcsdup(ct_decode_string(prog, &el->el_scratch));
1.56      christos   90:        if (el->el_prog == NULL) {
1.36      christos   91:                el_free(el);
                     92:                return NULL;
                     93:        }
1.19      lukem      94:
                     95:        /*
                     96:          * Initialize all the modules. Order is important!!!
                     97:          */
                     98:        el->el_flags = 0;
1.59      christos   99:        if (setlocale(LC_CTYPE, NULL) != NULL){
                    100:                if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
1.56      christos  101:                        el->el_flags |= CHARSET_IS_UTF8;
                    102:        }
1.19      lukem     103:
1.64      christos  104:        if (terminal_init(el) == -1) {
1.36      christos  105:                el_free(el->el_prog);
1.25      christos  106:                el_free(el);
                    107:                return NULL;
                    108:        }
1.66      christos  109:        (void) keymacro_init(el);
1.19      lukem     110:        (void) map_init(el);
                    111:        if (tty_init(el) == -1)
                    112:                el->el_flags |= NO_TTY;
                    113:        (void) ch_init(el);
                    114:        (void) search_init(el);
                    115:        (void) hist_init(el);
                    116:        (void) prompt_init(el);
                    117:        (void) sig_init(el);
1.92.8.1! snj       118:        (void) literal_init(el);
1.89      christos  119:        if (read_init(el) == -1) {
                    120:                el_end(el);
                    121:                return NULL;
                    122:        }
1.68      christos  123:        return el;
1.19      lukem     124: }
1.1       cgd       125:
                    126:
                    127: /* el_end():
                    128:  *     Clean up.
                    129:  */
1.88      christos  130: void
1.19      lukem     131: el_end(EditLine *el)
1.1       cgd       132: {
                    133:
1.19      lukem     134:        if (el == NULL)
                    135:                return;
1.1       cgd       136:
1.19      lukem     137:        el_reset(el);
                    138:
1.64      christos  139:        terminal_end(el);
1.66      christos  140:        keymacro_end(el);
1.19      lukem     141:        map_end(el);
1.74      christos  142:        if (!(el->el_flags & NO_TTY))
                    143:                tty_end(el);
1.19      lukem     144:        ch_end(el);
1.92      christos  145:        read_end(el->el_read);
1.19      lukem     146:        search_end(el);
                    147:        hist_end(el);
                    148:        prompt_end(el);
                    149:        sig_end(el);
1.92.8.1! snj       150:        literal_end(el);
1.19      lukem     151:
1.67      christos  152:        el_free(el->el_prog);
1.90      christos  153:        el_free(el->el_visual.cbuff);
                    154:        el_free(el->el_visual.wbuff);
1.67      christos  155:        el_free(el->el_scratch.cbuff);
                    156:        el_free(el->el_scratch.wbuff);
                    157:        el_free(el->el_lgcyconv.cbuff);
                    158:        el_free(el->el_lgcyconv.wbuff);
                    159:        el_free(el);
1.19      lukem     160: }
1.1       cgd       161:
                    162:
                    163: /* el_reset():
                    164:  *     Reset the tty and the parser
                    165:  */
1.88      christos  166: void
1.19      lukem     167: el_reset(EditLine *el)
1.1       cgd       168: {
1.19      lukem     169:
                    170:        tty_cookedmode(el);
1.92      christos  171:        ch_reset(el);           /* XXX: Do we want that? */
1.1       cgd       172: }
                    173:
                    174:
                    175: /* el_set():
                    176:  *     set the editline parameters
                    177:  */
1.88      christos  178: int
1.86      christos  179: el_wset(EditLine *el, int op, ...)
1.1       cgd       180: {
1.44      christos  181:        va_list ap;
1.27      christos  182:        int rv = 0;
1.1       cgd       183:
1.19      lukem     184:        if (el == NULL)
1.68      christos  185:                return -1;
1.44      christos  186:        va_start(ap, op);
1.22      wiz       187:
1.19      lukem     188:        switch (op) {
                    189:        case EL_PROMPT:
1.51      christos  190:        case EL_RPROMPT: {
                    191:                el_pfunc_t p = va_arg(ap, el_pfunc_t);
1.52      christos  192:
1.56      christos  193:                rv = prompt_set(el, p, 0, op, 1);
1.52      christos  194:                break;
                    195:        }
                    196:
1.60      christos  197:        case EL_RESIZE: {
                    198:                el_zfunc_t p = va_arg(ap, el_zfunc_t);
                    199:                void *arg = va_arg(ap, void *);
                    200:                rv = ch_resizefun(el, p, arg);
                    201:                break;
                    202:        }
                    203:
1.73      christos  204:        case EL_ALIAS_TEXT: {
                    205:                el_afunc_t p = va_arg(ap, el_afunc_t);
                    206:                void *arg = va_arg(ap, void *);
                    207:                rv = ch_aliasfun(el, p, arg);
                    208:                break;
                    209:        }
                    210:
1.52      christos  211:        case EL_PROMPT_ESC:
                    212:        case EL_RPROMPT_ESC: {
                    213:                el_pfunc_t p = va_arg(ap, el_pfunc_t);
1.56      christos  214:                int c = va_arg(ap, int);
1.51      christos  215:
1.87      christos  216:                rv = prompt_set(el, p, (wchar_t)c, op, 1);
1.50      christos  217:                break;
1.51      christos  218:        }
1.13      simonb    219:
1.19      lukem     220:        case EL_TERMINAL:
1.64      christos  221:                rv = terminal_set(el, va_arg(ap, char *));
1.19      lukem     222:                break;
1.1       cgd       223:
1.19      lukem     224:        case EL_EDITOR:
1.87      christos  225:                rv = map_set_editor(el, va_arg(ap, wchar_t *));
1.1       cgd       226:                break;
                    227:
1.19      lukem     228:        case EL_SIGNAL:
1.44      christos  229:                if (va_arg(ap, int))
1.19      lukem     230:                        el->el_flags |= HANDLE_SIGNALS;
                    231:                else
                    232:                        el->el_flags &= ~HANDLE_SIGNALS;
1.1       cgd       233:                break;
                    234:
1.19      lukem     235:        case EL_BIND:
                    236:        case EL_TELLTC:
                    237:        case EL_SETTC:
                    238:        case EL_ECHOTC:
                    239:        case EL_SETTY:
                    240:        {
1.87      christos  241:                const wchar_t *argv[20];
1.19      lukem     242:                int i;
                    243:
1.70      christos  244:                for (i = 1; i < (int)__arraycount(argv); i++)
1.87      christos  245:                        if ((argv[i] = va_arg(ap, wchar_t *)) == NULL)
1.19      lukem     246:                                break;
                    247:
                    248:                switch (op) {
                    249:                case EL_BIND:
1.86      christos  250:                        argv[0] = L"bind";
1.19      lukem     251:                        rv = map_bind(el, i, argv);
                    252:                        break;
                    253:
                    254:                case EL_TELLTC:
1.86      christos  255:                        argv[0] = L"telltc";
1.64      christos  256:                        rv = terminal_telltc(el, i, argv);
1.19      lukem     257:                        break;
                    258:
                    259:                case EL_SETTC:
1.86      christos  260:                        argv[0] = L"settc";
1.64      christos  261:                        rv = terminal_settc(el, i, argv);
1.19      lukem     262:                        break;
                    263:
                    264:                case EL_ECHOTC:
1.86      christos  265:                        argv[0] = L"echotc";
1.64      christos  266:                        rv = terminal_echotc(el, i, argv);
1.19      lukem     267:                        break;
                    268:
                    269:                case EL_SETTY:
1.86      christos  270:                        argv[0] = L"setty";
1.19      lukem     271:                        rv = tty_stty(el, i, argv);
                    272:                        break;
                    273:
                    274:                default:
                    275:                        rv = -1;
1.20      christos  276:                        EL_ABORT((el->el_errfile, "Bad op %d\n", op));
1.19      lukem     277:                        break;
                    278:                }
1.1       cgd       279:                break;
1.19      lukem     280:        }
                    281:
                    282:        case EL_ADDFN:
                    283:        {
1.87      christos  284:                wchar_t *name = va_arg(ap, wchar_t *);
                    285:                wchar_t *help = va_arg(ap, wchar_t *);
1.44      christos  286:                el_func_t func = va_arg(ap, el_func_t);
1.1       cgd       287:
1.19      lukem     288:                rv = map_addfunc(el, name, help, func);
1.1       cgd       289:                break;
1.19      lukem     290:        }
                    291:
                    292:        case EL_HIST:
                    293:        {
1.44      christos  294:                hist_fun_t func = va_arg(ap, hist_fun_t);
1.67      christos  295:                void *ptr = va_arg(ap, void *);
1.1       cgd       296:
1.19      lukem     297:                rv = hist_set(el, func, ptr);
1.59      christos  298:                if (!(el->el_flags & CHARSET_IS_UTF8))
                    299:                        el->el_flags &= ~NARROW_HISTORY;
1.1       cgd       300:                break;
1.19      lukem     301:        }
1.1       cgd       302:
1.19      lukem     303:        case EL_EDITMODE:
1.44      christos  304:                if (va_arg(ap, int))
1.19      lukem     305:                        el->el_flags &= ~EDIT_DISABLED;
                    306:                else
                    307:                        el->el_flags |= EDIT_DISABLED;
                    308:                rv = 0;
1.1       cgd       309:                break;
1.13      simonb    310:
1.23      christos  311:        case EL_GETCFN:
                    312:        {
1.44      christos  313:                el_rfunc_t rc = va_arg(ap, el_rfunc_t);
1.89      christos  314:                rv = el_read_setfn(el->el_read, rc);
1.23      christos  315:                break;
                    316:        }
                    317:
1.24      christos  318:        case EL_CLIENTDATA:
1.44      christos  319:                el->el_data = va_arg(ap, void *);
1.24      christos  320:                break;
                    321:
1.34      christos  322:        case EL_UNBUFFERED:
1.44      christos  323:                rv = va_arg(ap, int);
1.34      christos  324:                if (rv && !(el->el_flags & UNBUFFERED)) {
                    325:                        el->el_flags |= UNBUFFERED;
                    326:                        read_prepare(el);
                    327:                } else if (!rv && (el->el_flags & UNBUFFERED)) {
                    328:                        el->el_flags &= ~UNBUFFERED;
                    329:                        read_finish(el);
                    330:                }
1.35      christos  331:                rv = 0;
                    332:                break;
                    333:
                    334:        case EL_PREP_TERM:
1.44      christos  335:                rv = va_arg(ap, int);
1.35      christos  336:                if (rv)
1.38      christos  337:                        (void) tty_rawmode(el);
1.35      christos  338:                else
1.38      christos  339:                        (void) tty_cookedmode(el);
1.34      christos  340:                rv = 0;
                    341:                break;
                    342:
1.44      christos  343:        case EL_SETFP:
                    344:        {
                    345:                FILE *fp;
                    346:                int what;
                    347:
                    348:                what = va_arg(ap, int);
                    349:                fp = va_arg(ap, FILE *);
                    350:
                    351:                rv = 0;
                    352:                switch (what) {
                    353:                case 0:
                    354:                        el->el_infile = fp;
                    355:                        el->el_infd = fileno(fp);
                    356:                        break;
                    357:                case 1:
                    358:                        el->el_outfile = fp;
1.61      christos  359:                        el->el_outfd = fileno(fp);
1.44      christos  360:                        break;
                    361:                case 2:
                    362:                        el->el_errfile = fp;
1.61      christos  363:                        el->el_errfd = fileno(fp);
1.44      christos  364:                        break;
                    365:                default:
                    366:                        rv = -1;
                    367:                        break;
                    368:                }
                    369:                break;
                    370:        }
                    371:
1.45      christos  372:        case EL_REFRESH:
                    373:                re_clear_display(el);
                    374:                re_refresh(el);
1.64      christos  375:                terminal__flush(el);
1.45      christos  376:                break;
                    377:
1.19      lukem     378:        default:
                    379:                rv = -1;
1.27      christos  380:                break;
1.1       cgd       381:        }
                    382:
1.44      christos  383:        va_end(ap);
1.68      christos  384:        return rv;
1.19      lukem     385: }
1.1       cgd       386:
                    387:
1.10      lukem     388: /* el_get():
                    389:  *     retrieve the editline parameters
                    390:  */
1.88      christos  391: int
1.86      christos  392: el_wget(EditLine *el, int op, ...)
1.10      lukem     393: {
1.42      christos  394:        va_list ap;
1.19      lukem     395:        int rv;
1.10      lukem     396:
1.42      christos  397:        if (el == NULL)
                    398:                return -1;
                    399:
                    400:        va_start(ap, op);
                    401:
1.19      lukem     402:        switch (op) {
                    403:        case EL_PROMPT:
1.51      christos  404:        case EL_RPROMPT: {
                    405:                el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
1.56      christos  406:                rv = prompt_get(el, p, 0, op);
                    407:                break;
                    408:        }
                    409:        case EL_PROMPT_ESC:
                    410:        case EL_RPROMPT_ESC: {
                    411:                el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
1.87      christos  412:                wchar_t *c = va_arg(ap, wchar_t *);
1.51      christos  413:
                    414:                rv = prompt_get(el, p, c, op);
1.19      lukem     415:                break;
1.51      christos  416:        }
1.10      lukem     417:
1.19      lukem     418:        case EL_EDITOR:
1.87      christos  419:                rv = map_get_editor(el, va_arg(ap, const wchar_t **));
1.10      lukem     420:                break;
                    421:
1.19      lukem     422:        case EL_SIGNAL:
1.42      christos  423:                *va_arg(ap, int *) = (el->el_flags & HANDLE_SIGNALS);
1.19      lukem     424:                rv = 0;
1.10      lukem     425:                break;
                    426:
1.19      lukem     427:        case EL_EDITMODE:
1.42      christos  428:                *va_arg(ap, int *) = !(el->el_flags & EDIT_DISABLED);
1.19      lukem     429:                rv = 0;
1.10      lukem     430:                break;
                    431:
1.19      lukem     432:        case EL_TERMINAL:
1.64      christos  433:                terminal_get(el, va_arg(ap, const char **));
1.33      christos  434:                rv = 0;
1.10      lukem     435:                break;
                    436:
1.42      christos  437:        case EL_GETTC:
1.19      lukem     438:        {
1.42      christos  439:                static char name[] = "gettc";
                    440:                char *argv[20];
1.19      lukem     441:                int i;
1.10      lukem     442:
1.82      christos  443:                for (i = 1; i < (int)__arraycount(argv); i++)
1.42      christos  444:                        if ((argv[i] = va_arg(ap, char *)) == NULL)
1.19      lukem     445:                                break;
                    446:
1.69      christos  447:                argv[0] = name;
                    448:                rv = terminal_gettc(el, i, argv);
1.10      lukem     449:                break;
                    450:        }
1.13      simonb    451:
1.23      christos  452:        case EL_GETCFN:
1.89      christos  453:                *va_arg(ap, el_rfunc_t *) = el_read_getfn(el->el_read);
1.24      christos  454:                rv = 0;
                    455:                break;
                    456:
                    457:        case EL_CLIENTDATA:
1.42      christos  458:                *va_arg(ap, void **) = el->el_data;
1.34      christos  459:                rv = 0;
                    460:                break;
                    461:
                    462:        case EL_UNBUFFERED:
1.71      christos  463:                *va_arg(ap, int *) = (el->el_flags & UNBUFFERED) != 0;
1.23      christos  464:                rv = 0;
                    465:                break;
1.19      lukem     466:
1.44      christos  467:        case EL_GETFP:
                    468:        {
                    469:                int what;
                    470:                FILE **fpp;
                    471:
                    472:                what = va_arg(ap, int);
                    473:                fpp = va_arg(ap, FILE **);
                    474:                rv = 0;
                    475:                switch (what) {
                    476:                case 0:
                    477:                        *fpp = el->el_infile;
                    478:                        break;
                    479:                case 1:
                    480:                        *fpp = el->el_outfile;
                    481:                        break;
                    482:                case 2:
                    483:                        *fpp = el->el_errfile;
                    484:                        break;
                    485:                default:
                    486:                        rv = -1;
                    487:                        break;
                    488:                }
                    489:                break;
                    490:        }
1.19      lukem     491:        default:
                    492:                rv = -1;
1.44      christos  493:                break;
1.19      lukem     494:        }
1.42      christos  495:        va_end(ap);
1.10      lukem     496:
1.68      christos  497:        return rv;
1.19      lukem     498: }
1.10      lukem     499:
                    500:
1.1       cgd       501: /* el_line():
                    502:  *     Return editing info
                    503:  */
1.88      christos  504: const LineInfoW *
1.86      christos  505: el_wline(EditLine *el)
1.1       cgd       506: {
1.19      lukem     507:
1.86      christos  508:        return (const LineInfoW *)(void *)&el->el_line;
1.1       cgd       509: }
                    510:
                    511:
                    512: /* el_source():
                    513:  *     Source a file
                    514:  */
1.88      christos  515: int
1.19      lukem     516: el_source(EditLine *el, const char *fname)
1.1       cgd       517: {
1.19      lukem     518:        FILE *fp;
                    519:        size_t len;
1.77      christos  520:        ssize_t slen;
1.27      christos  521:        char *ptr;
1.64      christos  522:        char *path = NULL;
1.87      christos  523:        const wchar_t *dptr;
1.64      christos  524:        int error = 0;
1.19      lukem     525:
                    526:        fp = NULL;
                    527:        if (fname == NULL) {
1.29      christos  528: #ifdef HAVE_ISSETUGID
1.19      lukem     529:                if (issetugid())
1.68      christos  530:                        return -1;
1.92.8.1! snj       531:
        !           532:                if ((fname = getenv("EDITRC")) == NULL) {
        !           533:                        static const char elpath[] = "/.editrc";
        !           534:                        size_t plen = sizeof(elpath);
        !           535:
        !           536:                        if ((ptr = getenv("HOME")) == NULL)
        !           537:                                return -1;
        !           538:                        plen += strlen(ptr);
        !           539:                        if ((path = el_malloc(plen * sizeof(*path))) == NULL)
        !           540:                                return -1;
        !           541:                        (void)snprintf(path, plen, "%s%s", ptr,
        !           542:                                elpath + (*ptr == '\0'));
        !           543:                        fname = path;
        !           544:                }
1.27      christos  545: #else
                    546:                /*
                    547:                 * If issetugid() is missing, always return an error, in order
                    548:                 * to keep from inadvertently opening up the user to a security
                    549:                 * hole.
                    550:                 */
1.68      christos  551:                return -1;
1.27      christos  552: #endif
1.19      lukem     553:        }
1.92.8.1! snj       554:        if (fname[0] == '\0')
        !           555:                return -1;
        !           556:
1.19      lukem     557:        if (fp == NULL)
                    558:                fp = fopen(fname, "r");
1.64      christos  559:        if (fp == NULL) {
                    560:                el_free(path);
1.68      christos  561:                return -1;
1.64      christos  562:        }
1.19      lukem     563:
1.77      christos  564:        ptr = NULL;
                    565:        len = 0;
                    566:        while ((slen = getline(&ptr, &len, fp)) != -1) {
1.63      christos  567:                if (*ptr == '\n')
                    568:                        continue;       /* Empty line. */
1.77      christos  569:                if (slen > 0 && ptr[--slen] == '\n')
                    570:                        ptr[slen] = '\0';
                    571:
1.56      christos  572:                dptr = ct_decode_string(ptr, &el->el_scratch);
                    573:                if (!dptr)
                    574:                        continue;
1.55      christos  575:                /* loop until first non-space char or EOL */
1.85      christos  576:                while (*dptr != '\0' && iswspace(*dptr))
1.56      christos  577:                        dptr++;
                    578:                if (*dptr == '#')
1.55      christos  579:                        continue;   /* ignore, this is a comment line */
1.64      christos  580:                if ((error = parse_line(el, dptr)) == -1)
                    581:                        break;
1.1       cgd       582:        }
1.76      christos  583:        free(ptr);
1.1       cgd       584:
1.64      christos  585:        el_free(path);
1.19      lukem     586:        (void) fclose(fp);
1.68      christos  587:        return error;
1.1       cgd       588: }
                    589:
                    590:
                    591: /* el_resize():
                    592:  *     Called from program when terminal is resized
                    593:  */
1.88      christos  594: void
1.19      lukem     595: el_resize(EditLine *el)
1.1       cgd       596: {
1.19      lukem     597:        int lins, cols;
                    598:        sigset_t oset, nset;
                    599:
                    600:        (void) sigemptyset(&nset);
                    601:        (void) sigaddset(&nset, SIGWINCH);
                    602:        (void) sigprocmask(SIG_BLOCK, &nset, &oset);
                    603:
                    604:        /* get the correct window size */
1.64      christos  605:        if (terminal_get_size(el, &lins, &cols))
                    606:                terminal_change_size(el, lins, cols);
1.1       cgd       607:
1.19      lukem     608:        (void) sigprocmask(SIG_SETMASK, &oset, NULL);
1.9       christos  609: }
1.14      lukem     610:
1.9       christos  611:
                    612: /* el_beep():
                    613:  *     Called from the program to beep
                    614:  */
1.88      christos  615: void
1.19      lukem     616: el_beep(EditLine *el)
1.9       christos  617: {
1.19      lukem     618:
1.64      christos  619:        terminal_beep(el);
1.1       cgd       620: }
1.10      lukem     621:
                    622:
                    623: /* el_editmode()
                    624:  *     Set the state of EDIT_DISABLED from the `edit' command.
                    625:  */
1.91      christos  626: libedit_private int
1.10      lukem     627: /*ARGSUSED*/
1.87      christos  628: el_editmode(EditLine *el, int argc, const wchar_t **argv)
1.10      lukem     629: {
1.87      christos  630:        const wchar_t *how;
1.10      lukem     631:
1.19      lukem     632:        if (argv == NULL || argc != 2 || argv[1] == NULL)
1.68      christos  633:                return -1;
1.10      lukem     634:
1.19      lukem     635:        how = argv[1];
1.86      christos  636:        if (wcscmp(how, L"on") == 0) {
1.19      lukem     637:                el->el_flags &= ~EDIT_DISABLED;
1.39      christos  638:                tty_rawmode(el);
1.86      christos  639:        } else if (wcscmp(how, L"off") == 0) {
1.39      christos  640:                tty_cookedmode(el);
1.19      lukem     641:                el->el_flags |= EDIT_DISABLED;
1.39      christos  642:        }
1.19      lukem     643:        else {
1.85      christos  644:                (void) fprintf(el->el_errfile, "edit: Bad value `%ls'.\n",
1.56      christos  645:                    how);
1.68      christos  646:                return -1;
1.19      lukem     647:        }
1.68      christos  648:        return 0;
1.19      lukem     649: }

CVSweb <webmaster@jp.NetBSD.org>