~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to text-utils/more.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
 
69
69
#ifndef XTABS
70
70
#define XTABS TAB3
71
 
#endif
 
71
#endif /* XTABS */
72
72
 
73
73
#define VI              "vi"    /* found on the user's path */
74
74
 
94
94
void do_shell (char *filename);
95
95
int  colon (char *filename, int cmd, int nlines);
96
96
int  expand (char **outbuf, char *inbuf);
97
 
void argscan(char *s,char *argv0);
 
97
void argscan(char *s);
98
98
void rdline (register FILE *f);
99
99
void copy_file(register FILE *f);
100
100
void search(char buf[], FILE *file, register int n);
113
113
void prbuf (register char *s, register int n);
114
114
void execute (char *filename, char *cmd, ...);
115
115
FILE *checkf (char *, int *);
116
 
int prepare_line_buffer(void);
 
116
void prepare_line_buffer(void);
117
117
 
118
118
#define TBUFSIZ 1024
119
119
#define LINSIZ  256     /* minimal Line buffer size */
121
121
#define RUBOUT  '\177'
122
122
#define ESC     '\033'
123
123
#define QUIT    '\034'
 
124
#define SCROLL_LEN      11
 
125
#define LINES_PER_PAGE  24
 
126
#define NUM_COLUMNS     80
 
127
#define TERMINAL_BUF    4096
 
128
#define INIT_BUF        80
 
129
#define SHELL_LINE      1000
 
130
#define COMMAND_BUF     200
124
131
 
125
132
struct termios  otty, savetty0;
126
133
long            file_pos, file_size;
127
134
int             fnum, no_intty, no_tty, slow_tty;
128
135
int             dum_opt, dlines;
129
136
void            onquit(int), onsusp(int), chgwinsz(int), end_it(int);
130
 
int             nscroll = 11;   /* Number of lines scrolled by 'd' */
131
 
int             fold_opt = 1;   /* Fold long lines */
132
 
int             stop_opt = 1;   /* Stop after form feeds */
133
 
int             ssp_opt = 0;    /* Suppress white space */
134
 
int             ul_opt = 1;     /* Underline as best we can */
 
137
int             nscroll = SCROLL_LEN;   /* Number of lines scrolled by 'd' */
 
138
int             fold_opt = 1;           /* Fold long lines */
 
139
int             stop_opt = 1;           /* Stop after form feeds */
 
140
int             ssp_opt = 0;            /* Suppress white space */
 
141
int             ul_opt = 1;             /* Underline as best we can */
135
142
int             promptlen;
136
 
int             Currline;       /* Line we are currently at */
 
143
int             Currline;               /* Line we are currently at */
137
144
int             startup = 1;
138
145
int             firstf = 1;
139
146
int             notell = 1;
140
147
int             docrterase = 0;
141
148
int             docrtkill = 0;
142
 
int             bad_so; /* True if overwriting does not turn off standout */
 
149
int             bad_so;                 /* True if overwriting does not turn
 
150
                                           off standout */
143
151
int             inwait, Pause, errors;
144
 
int             within; /* true if we are within a file,
145
 
                        false if we are between files */
 
152
int             within;                 /* true if we are within a file,
 
153
                                           false if we are between files */
146
154
int             hard, dumb, noscroll, hardtabs, clreol, eatnl;
147
 
int             catch_susp;     /* We should catch the SIGTSTP signal */
148
 
char            **fnames;       /* The list of file names */
149
 
int             nfiles;         /* Number of files left to process */
150
 
char            *shell;         /* The name of the shell to use */
151
 
int             shellp;         /* A previous shell command exists */
 
155
int             catch_susp;             /* We should catch the SIGTSTP signal */
 
156
char            **fnames;               /* The list of file names */
 
157
int             nfiles;                 /* Number of files left to process */
 
158
char            *shell;                 /* The name of the shell to use */
 
159
int             shellp;                 /* A previous shell command exists */
152
160
sigjmp_buf      restore;
153
 
char            *Line;          /* Line buffer */
154
 
size_t          LineLen;        /* size of Line buffer */
155
 
int             Lpp = 24;       /* lines per page */
156
 
char            *Clear;         /* clear screen */
157
 
char            *eraseln;       /* erase line */
158
 
char            *Senter, *Sexit;/* enter and exit standout mode */
 
161
char            *Line;                  /* Line buffer */
 
162
size_t          LineLen;                /* size of Line buffer */
 
163
int             Lpp = LINES_PER_PAGE;   /* lines per page */
 
164
char            *Clear;                 /* clear screen */
 
165
char            *eraseln;               /* erase line */
 
166
char            *Senter, *Sexit;        /* enter and exit standout mode */
159
167
char            *ULenter, *ULexit;      /* enter and exit underline mode */
160
 
char            *chUL;          /* underline character */
161
 
char            *chBS;          /* backspace character */
162
 
char            *Home;          /* go to home */
163
 
char            *cursorm;       /* cursor movement */
164
 
char            cursorhome[40]; /* contains cursor movement to home */
165
 
char            *EodClr;        /* clear rest of screen */
166
 
int             Mcol = 80;      /* number of columns */
167
 
int             Wrap = 1;       /* set if automargins */
168
 
int             soglitch;       /* terminal has standout mode glitch */
169
 
int             ulglitch;       /* terminal has underline mode glitch */
170
 
int             pstate = 0;     /* current UL state */
 
168
char            *chUL;                  /* underline character */
 
169
char            *chBS;                  /* backspace character */
 
170
char            *Home;                  /* go to home */
 
171
char            *cursorm;               /* cursor movement */
 
172
char            cursorhome[40];         /* contains cursor movement to home */
 
173
char            *EodClr;                /* clear rest of screen */
 
174
int             Mcol = NUM_COLUMNS;     /* number of columns */
 
175
int             Wrap = 1;               /* set if automargins */
 
176
int             soglitch;               /* terminal has standout mode glitch */
 
177
int             ulglitch;               /* terminal has underline mode glitch */
 
178
int             pstate = 0;             /* current UL state */
171
179
static int      magic(FILE *, char *);
172
180
struct {
173
181
    long chrctr, line;
178
186
# include <ncurses.h>
179
187
#elif defined(HAVE_NCURSES_NCURSES_H)
180
188
# include <ncurses/ncurses.h>
181
 
#endif
 
189
#endif /* HAVE_NCURSES_H */
182
190
 
183
191
#if defined(HAVE_NCURSES_H) || defined(HAVE_NCURSES_NCURSES_H)
184
192
# include <term.h>                      /* include after <curses.h> */
185
193
 
186
 
static void
187
 
my_putstring(char *s) {
188
 
        tputs (s, 1, putchar);          /* putp(s); */
 
194
#define TERM_AUTO_RIGHT_MARGIN    "am"
 
195
#define TERM_CEOL                 "xhp"
 
196
#define TERM_CLEAR                "clear"
 
197
#define TERM_CLEAR_TO_LINE_END    "el"
 
198
#define TERM_CLEAR_TO_SCREEN_END  "ed"
 
199
#define TERM_COLS                 "cols"
 
200
#define TERM_CURSOR_ADDRESS       "cup"
 
201
#define TERM_EAT_NEW_LINE         "xenl"
 
202
#define TERM_ENTER_UNDERLINE      "smul"
 
203
#define TERM_EXIT_STANDARD_MODE   "rmso"
 
204
#define TERM_EXIT_UNDERLINE       "rmul"
 
205
#define TERM_HARD_COPY            "hc"
 
206
#define TERM_HOME                 "home"
 
207
#define TERM_LINE_DOWN            "cud1"
 
208
#define TERM_LINES                "lines"
 
209
#define TERM_OVER_STRIKE          "os"
 
210
#define TERM_PAD_CHAR             "pad"
 
211
#define TERM_STANDARD_MODE        "smso"
 
212
#define TERM_STD_MODE_GLITCH      "xmc"
 
213
#define TERM_UNDERLINE_CHAR       "uc"
 
214
#define TERM_UNDERLINE            "ul"
 
215
 
 
216
static void my_putstring(char *s) {
 
217
        tputs (s, fileno(stdout), putchar);             /* putp(s); */
189
218
}
190
219
 
191
 
static void
192
 
my_setupterm(char *term, int fildes, int *errret) {
 
220
static void my_setupterm(char *term, int fildes, int *errret) {
193
221
     setupterm(term, fildes, errret);
194
222
}
195
223
 
196
 
static int
197
 
my_tgetnum(char *s, char *ss) {
198
 
     return tigetnum(ss);
199
 
}
200
 
 
201
 
static int
202
 
my_tgetflag(char *s, char *ss) {
203
 
     return tigetflag(ss);
204
 
}
205
 
 
206
 
static char *
207
 
my_tgetstr(char *s, char *ss) {
208
 
     return tigetstr(ss);
209
 
}
210
 
 
211
 
static char *
212
 
my_tgoto(char *cap, int col, int row) {
 
224
static int my_tgetnum(char *s) {
 
225
     return tigetnum(s);
 
226
}
 
227
 
 
228
static int my_tgetflag(char *s) {
 
229
     return tigetflag(s);
 
230
}
 
231
 
 
232
static char *my_tgetstr(char *s) {
 
233
     return tigetstr(s);
 
234
}
 
235
 
 
236
static char *my_tgoto(char *cap, int col, int row) {
213
237
     return tparm(cap, col, row);
214
238
}
215
239
 
217
241
 
218
242
#include <termcap.h>
219
243
 
220
 
char termbuffer[4096];
221
 
char tcbuffer[4096];
 
244
#define TERM_AUTO_RIGHT_MARGIN    "am"
 
245
#define TERM_CEOL                 "xs"
 
246
#define TERM_CLEAR                "cl"
 
247
#define TERM_CLEAR_TO_LINE_END    "ce"
 
248
#define TERM_CLEAR_TO_SCREEN_END  "cd"
 
249
#define TERM_COLS                 "co"
 
250
#define TERM_CURSOR_ADDRESS       "cm"
 
251
#define TERM_EAT_NEW_LINE         "xn"
 
252
#define TERM_ENTER_UNDERLINE      "us"
 
253
#define TERM_EXIT_STANDARD_MODE   "se"
 
254
#define TERM_EXIT_UNDERLINE       "ue"
 
255
#define TERM_HARD_COPY            "hc"
 
256
#define TERM_HOME                 "ho"
 
257
#define TERM_LINE_DOWN            "le"
 
258
#define TERM_LINES                "li"
 
259
#define TERM_OVER_STRIKE          "os"
 
260
#define TERM_PAD_CHAR             "pc"
 
261
#define TERM_STANDARD_MODE        "so"
 
262
#define TERM_STD_MODE_GLITCH      "sg"
 
263
#define TERM_UNDERLINE_CHAR       "uc"
 
264
#define TERM_UNDERLINE            "ul"
 
265
 
 
266
char termbuffer[TERMINAL_BUF];
 
267
char tcbuffer[TERMINAL_BUF];
222
268
char *strbuf = termbuffer;
223
269
 
224
 
static void
225
 
my_putstring(char *s) {
226
 
     tputs (s, 1, putchar);
 
270
static void my_putstring(char *s) {
 
271
     tputs (s, fileno(stdout), putchar);
227
272
}
228
273
 
229
 
static void
230
 
my_setupterm(char *term, int fildes, int *errret) {
 
274
static void my_setupterm(char *term, int fildes, int *errret) {
231
275
     *errret = tgetent(tcbuffer, term);
232
276
}
233
277
 
234
 
static int
235
 
my_tgetnum(char *s, char *ss) {
 
278
static int my_tgetnum(char *s) {
236
279
     return tgetnum(s);
237
280
}
238
281
 
239
 
static int
240
 
my_tgetflag(char *s, char *ss) {
 
282
static int my_tgetflag(char *s) {
241
283
     return tgetflag(s);
242
284
}
243
285
 
244
 
static char *
245
 
my_tgetstr(char *s, char *ss) {
 
286
static char *my_tgetstr(char *s) {
246
287
     return tgetstr(s, &strbuf);
247
288
}
248
289
 
249
 
static char *
250
 
my_tgoto(char *cap, int col, int row) {
 
290
static char *my_tgoto(char *cap, int col, int row) {
251
291
     return tgoto(cap, col, row);
252
292
}
253
293
 
254
294
#endif /* HAVE_LIBTERMCAP */
255
295
 
256
 
static void
257
 
idummy(int *kk) {}
258
 
 
259
 
static void
260
 
Fdummy(FILE **ff) {}
261
 
 
262
 
static void
263
 
usage(char *s) {
264
 
        char *p = strrchr(s, '/');
265
 
        fprintf(stderr,
266
 
                _("usage: %s [-dflpcsu] [+linenum | +/pattern] name1 name2 ...\n"),
267
 
                p ? p + 1 : s);
 
296
static void __attribute__ ((__noreturn__)) usage(FILE *out)
 
297
{
 
298
     fprintf(out,
 
299
            _("Usage: %s [options] file...\n\n"),
 
300
               program_invocation_short_name);
 
301
     fprintf(out,
 
302
            _("Options:\n"
 
303
              "  -d        display help instead of ring bell\n"
 
304
              "  -f        count logical, rather than screen lines\n"
 
305
              "  -l        suppress pause after form feed\n"
 
306
              "  -p        suppress scroll, clean screen and disblay text\n"
 
307
              "  -c        suppress scroll, display text and clean line ends\n"
 
308
              "  -u        suppress underlining\n"
 
309
              "  -s        squeeze multiple blank lines into one\n"
 
310
              "  -NUM      specify the number of lines per screenful\n"
 
311
              "  +NUM      display file beginning from line number NUM\n"
 
312
              "  +/STRING  display file beginning from search string match\n"
 
313
              "  -V        output version information and exit\n"));
 
314
       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
268
315
}
269
316
 
270
317
int main(int argc, char **argv) {
278
325
    int         srchopt = 0;
279
326
    int         clearit = 0;
280
327
    int         initline = 0;
281
 
    char        initbuf[80];
 
328
    char        initbuf[INIT_BUF];
282
329
 
283
330
    setlocale(LC_ALL, "");
284
331
    bindtextdomain(PACKAGE, LOCALEDIR);
285
332
    textdomain(PACKAGE);
286
 
    
287
 
    /* avoid gcc complaints about register variables that
288
 
       may be clobbered by a longjmp, by forcing our variables here
289
 
       to be non-register */
290
 
    Fdummy(&f); idummy(&left); idummy(&prnames);
291
 
    idummy(&initopt); idummy(&srchopt); idummy(&initline);
292
333
 
293
334
    nfiles = argc;
294
335
    fnames = argv;
295
336
    setlocale(LC_ALL, "");
296
337
    initterm ();
297
 
    if (prepare_line_buffer()) {
298
 
        fprintf(stderr, _("failed to initialize line buffer\n"));
299
 
        exit(1);
300
 
    }
 
338
 
 
339
    /* Auto set no scroll on when binary is called page */
 
340
    if (!(strcmp(program_invocation_short_name, "page")))
 
341
       noscroll++;
 
342
 
 
343
    prepare_line_buffer();
 
344
 
301
345
    nscroll = Lpp/2 - 1;
302
346
    if (nscroll <= 0)
303
347
        nscroll = 1;
304
 
    if((s = getenv("MORE")) != NULL) argscan(s,argv[0]);
 
348
 
 
349
    if ((s = getenv("MORE")) != NULL)
 
350
            argscan(s);
 
351
 
305
352
    while (--nfiles > 0) {
306
353
        if ((ch = (*++fnames)[0]) == '-') {
307
 
            argscan(*fnames+1,argv[0]);
 
354
            argscan(*fnames+1);
308
355
        }
309
356
        else if (ch == '+') {
310
357
            s = *fnames;
311
358
            if (*++s == '/') {
312
359
                srchopt++;
313
 
                for (++s, p = initbuf; p < initbuf + 79 && *s != '\0';)
 
360
                for (++s, p = initbuf; p < initbuf + (INIT_BUF - 1) && *s != '\0';)
314
361
                    *p++ = *s++;
315
362
                *p = '\0';
316
363
            }
339
386
    left = dlines;
340
387
    if (nfiles > 1)
341
388
        prnames++;
342
 
    if (!no_intty && nfiles == 0) {
343
 
        usage(argv[0]);
344
 
        exit(1);
345
 
    }
 
389
    if (!no_intty && nfiles == 0)
 
390
        usage(stderr);
346
391
    else
347
392
        f = stdin;
348
393
    if (!no_tty) {
350
395
        signal(SIGINT, end_it);
351
396
#ifdef SIGWINCH
352
397
        signal(SIGWINCH, chgwinsz);
353
 
#endif
 
398
#endif /* SIGWINCH */
354
399
        if (signal (SIGTSTP, SIG_IGN) == SIG_DFL) {
355
400
            signal(SIGTSTP, onsusp);
356
401
            catch_susp++;
447
492
        firstf = 0;
448
493
    }
449
494
    reset_tty ();
450
 
    exit(0);
 
495
    exit(EXIT_SUCCESS);
451
496
}
452
497
 
453
 
void argscan(char *s, char *argv0) {
 
498
void argscan(char *s) {
454
499
        int seen_num = 0;
455
500
 
456
501
        while (*s != '\0') {
488
533
                        break;
489
534
                  case '-': case ' ': case '\t':
490
535
                        break;
 
536
                  case 'V':
 
537
                        printf(_("more (%s)\n"), PACKAGE_STRING);
 
538
                        exit(EXIT_SUCCESS);
 
539
                        break;
491
540
                  default:
492
 
                        fprintf(stderr,
493
 
                                _("%s: unknown option \"-%c\"\n"), argv0, *s);
494
 
                        usage(argv0);
495
 
                        exit(1);
 
541
                        warnx(_("unknown option -%s"), s);
 
542
                        usage(stderr);
496
543
                        break;
497
544
                }
498
545
                s++;
657
704
** Come here if a quit signal is received
658
705
*/
659
706
 
660
 
void onquit(int dummy) {
 
707
void onquit(int dummy __attribute__ ((__unused__)))
 
708
{
661
709
    signal(SIGQUIT, SIG_IGN);
662
710
    if (!inwait) {
663
711
        putchar ('\n');
680
728
*/
681
729
 
682
730
#ifdef SIGWINCH
683
 
void chgwinsz(int dummy) {
 
731
void chgwinsz(int dummy __attribute__ ((__unused__)))
 
732
{
684
733
    struct winsize win;
685
734
 
686
 
    (void) signal(SIGWINCH, SIG_IGN);
 
735
    signal(SIGWINCH, SIG_IGN);
687
736
    if (ioctl(fileno(stdout), TIOCGWINSZ, &win) != -1) {
688
737
        if (win.ws_row != 0) {
689
738
            Lpp = win.ws_row;
697
746
    }
698
747
    (void) signal(SIGWINCH, chgwinsz);
699
748
}
700
 
#endif
 
749
#endif /* SIGWINCH */
701
750
 
702
751
/*
703
752
** Clean up terminal state and exit. Also come here if interrupt signal received
704
753
*/
705
754
 
706
 
void end_it (int dummy) {
 
755
void end_it (int dummy __attribute__ ((__unused__)))
 
756
{
707
757
    reset_tty ();
708
758
    if (clreol) {
709
759
        putchar ('\r');
716
766
    }
717
767
    else
718
768
        putcerr('\n');
719
 
    _exit(0);
 
769
    _exit(EXIT_SUCCESS);
720
770
}
721
771
 
722
772
void copy_file(register FILE *f) {
728
778
 
729
779
#define ringbell()      putcerr('\007')
730
780
 
731
 
/* See whether the last component of the path name "path" is equal to the
732
 
** string "string"
733
 
*/
734
 
 
735
 
static int tailequ (char *path, register char *string)
736
 
{
737
 
        register char *tail;
738
 
 
739
 
        tail = path + strlen(path);
740
 
        while (--tail >= path)
741
 
                if (*tail == '/')
742
 
                        break;
743
 
        ++tail;
744
 
        while (*tail++ == *string++)
745
 
                if (*tail == '\0')
746
 
                        return(1);
747
 
        return(0);
748
 
}
749
 
 
750
781
static void prompt (char *filename)
751
782
{
752
783
    if (clreol)
781
812
    inwait++;
782
813
}
783
814
 
784
 
int prepare_line_buffer(void)
 
815
void prepare_line_buffer(void)
785
816
{
786
817
    char *nline;
787
818
    size_t nsz = Mcol * 4;
788
819
 
789
820
    if (LineLen >= nsz)
790
 
        return 0;
 
821
        return;
791
822
 
792
823
    if (nsz < LINSIZ)
793
824
        nsz = LINSIZ;
794
825
 
795
 
    nline = realloc(Line, nsz);
796
 
    if (nline) {
797
 
        Line = nline;
798
 
        LineLen = nsz;
799
 
        return 0;
800
 
    }
801
 
 
802
 
    /* error() uses siglongjmp(), we want to return from this
803
 
     * function when the Line buffer is initilized first time in main()
804
 
     */
805
 
    if (Line)
806
 
        error(_("out of memory"));
807
 
    return -1;
 
826
    nline = xrealloc(Line, nsz);
 
827
    Line = nline;
 
828
    LineLen = nsz;
808
829
}
809
830
 
810
831
/*
819
840
    static int colflg;
820
841
 
821
842
#ifdef HAVE_WIDECHAR
822
 
    int i;
 
843
    size_t i;
823
844
    wchar_t wc;
824
845
    int wc_width;
825
846
    mbstate_t state, state_bak;         /* Current status of the stream. */
831
852
    long file_pos_bak = Ftell (f);
832
853
 
833
854
    memset (&state, '\0', sizeof (mbstate_t));
834
 
#endif
 
855
#endif /* HAVE_WIDECHAR */
835
856
 
836
857
    prepare_line_buffer();
837
858
 
894
915
            c = Getc (f);
895
916
            continue;
896
917
        }
897
 
#endif 
 
918
#endif /* HAVE_WIDECHAR */
898
919
        if (c == EOF) {
899
920
            if (p > Line) {
900
921
                *p = '\0';
923
944
                        continue;
924
945
                }
925
946
        }
926
 
#endif
 
947
#endif /* 0 */
927
948
        if (c == '\t') {
928
949
            if (!hardtabs || (column < promptlen && !hard)) {
929
950
                if (hardtabs && eraseln && !dumb) {
990
1011
                      column += wc_width;
991
1012
                }
992
1013
            } else
993
 
#endif
 
1014
#endif /* HAVE_WIDECHAR */
994
1015
              {
995
1016
                if (isprint(c))
996
1017
                   column++;
1145
1166
 
1146
1167
static int lastcmd, lastarg, lastp;
1147
1168
static int lastcolon;
1148
 
char shell_line[1000];
 
1169
char shell_line[SHELL_LINE];
1149
1170
 
1150
1171
/*
1151
1172
** Read a command and do it. A command consists of an optional integer
1161
1182
    register int c;
1162
1183
    char colonch;
1163
1184
    int done;
1164
 
    char comchar, cmdbuf[80];
 
1185
    char comchar, cmdbuf[INIT_BUF];
1165
1186
 
1166
1187
#define ret(val) retval=val;done++;break
1167
1188
 
1512
1533
 
1513
1534
void do_shell (char *filename)
1514
1535
{
1515
 
        char cmdbuf[200];
 
1536
        char cmdbuf[COMMAND_BUF];
1516
1537
        int rc;
1517
1538
        char *expanded;
1518
1539
 
1669
1690
        
1670
1691
            execvp (cmd, args);
1671
1692
            putserr(_("exec failed\n"));
1672
 
            exit (1);
 
1693
            exit (EXIT_FAILURE);
1673
1694
        }
1674
1695
        if (id > 0) {
1675
1696
            signal (SIGINT, SIG_IGN);
1746
1767
 
1747
1768
#ifdef do_SIGTTOU
1748
1769
retry:
1749
 
#endif
 
1770
#endif /* do_SIGTTOU */
1750
1771
    no_tty = tcgetattr(fileno(stdout), &otty);
1751
1772
    if (!no_tty) {      
1752
1773
        docrterase = (otty.c_cc[VERASE] != 255);
1760
1781
             */
1761
1782
            if ((tgrp = tcgetpgrp(fileno(stdout))) < 0) {
1762
1783
                perror("tcgetpgrp");
1763
 
                exit(1);
 
1784
                exit(EXIT_FAILURE);
1764
1785
            }
1765
1786
            if (tgrp != getpgrp(0)) {
1766
1787
                kill(0, SIGTTOU);
1767
1788
                goto retry;
1768
1789
            }
1769
1790
        }
1770
 
#endif
 
1791
#endif /* do_SIGTTOU */
1771
1792
        if ((term = getenv("TERM")) == 0) {
1772
1793
            dumb++; ul_opt = 0;
1773
1794
        }
1778
1799
        else {
1779
1800
#ifdef TIOCGWINSZ
1780
1801
            if (ioctl(fileno(stdout), TIOCGWINSZ, &win) < 0) {
1781
 
#endif
1782
 
                Lpp = my_tgetnum("li","lines");
1783
 
                Mcol = my_tgetnum("co","cols");
 
1802
#endif /* TIOCGWINSZ */
 
1803
                Lpp = my_tgetnum(TERM_LINES);
 
1804
                Mcol = my_tgetnum(TERM_COLS);
1784
1805
#ifdef TIOCGWINSZ
1785
1806
            } else {
1786
1807
                if ((Lpp = win.ws_row) == 0)
1787
 
                    Lpp = my_tgetnum("li","lines");
 
1808
                    Lpp = my_tgetnum(TERM_LINES);
1788
1809
                if ((Mcol = win.ws_col) == 0)
1789
 
                    Mcol = my_tgetnum("co","cols");
 
1810
                    Mcol = my_tgetnum(TERM_COLS);
1790
1811
            }
1791
 
#endif
1792
 
            if ((Lpp <= 0) || my_tgetflag("hc","hc")) {
 
1812
#endif /* TIOCGWINSZ */
 
1813
            if ((Lpp <= 0) || my_tgetflag(TERM_HARD_COPY)) {
1793
1814
                hard++; /* Hard copy terminal */
1794
 
                Lpp = 24;
 
1815
                Lpp = LINES_PER_PAGE;
1795
1816
            }
1796
1817
 
1797
 
            if (my_tgetflag("xn","xenl"))
 
1818
            if (my_tgetflag(TERM_EAT_NEW_LINE))
1798
1819
                eatnl++; /* Eat newline at last column + 1; dec, concept */
1799
1820
            if (Mcol <= 0)
1800
 
                Mcol = 80;
 
1821
                Mcol = NUM_COLUMNS;
1801
1822
 
1802
 
            if (tailequ (fnames[0], "page"))
1803
 
                noscroll++;
1804
 
            Wrap = my_tgetflag("am","am");
1805
 
            bad_so = my_tgetflag ("xs","xhp");
1806
 
            eraseln = my_tgetstr("ce","el");
1807
 
            Clear = my_tgetstr("cl","clear");
1808
 
            Senter = my_tgetstr("so","smso");
1809
 
            Sexit = my_tgetstr("se","rmso");
1810
 
            if ((soglitch = my_tgetnum("sg","xmc")) < 0)
 
1823
            Wrap = my_tgetflag(TERM_AUTO_RIGHT_MARGIN);
 
1824
            bad_so = my_tgetflag (TERM_CEOL);
 
1825
            eraseln = my_tgetstr(TERM_CLEAR_TO_LINE_END);
 
1826
            Clear = my_tgetstr(TERM_CLEAR);
 
1827
            Senter = my_tgetstr(TERM_STANDARD_MODE);
 
1828
            Sexit = my_tgetstr(TERM_EXIT_STANDARD_MODE);
 
1829
            if ((soglitch = my_tgetnum(TERM_STD_MODE_GLITCH)) < 0)
1811
1830
                soglitch = 0;
1812
1831
 
1813
1832
            /*
1818
1837
             *  isn't available, settle for standout sequence.
1819
1838
             */
1820
1839
 
1821
 
            if (my_tgetflag("ul","ul") || my_tgetflag("os","os"))
 
1840
            if (my_tgetflag(TERM_UNDERLINE) || my_tgetflag(TERM_OVER_STRIKE))
1822
1841
                ul_opt = 0;
1823
 
            if ((chUL = my_tgetstr("uc","uc")) == NULL )
 
1842
            if ((chUL = my_tgetstr(TERM_UNDERLINE_CHAR)) == NULL )
1824
1843
                chUL = "";
1825
 
            if (((ULenter = my_tgetstr("us","smul")) == NULL ||
1826
 
                 (ULexit = my_tgetstr("ue","rmul")) == NULL) && !*chUL) {
 
1844
            if (((ULenter = my_tgetstr(TERM_ENTER_UNDERLINE)) == NULL ||
 
1845
                 (ULexit = my_tgetstr(TERM_EXIT_UNDERLINE)) == NULL) && !*chUL) {
1827
1846
                if ((ULenter = Senter) == NULL || (ULexit = Sexit) == NULL) {
1828
1847
                        ULenter = "";
1829
1848
                        ULexit = "";
1833
1852
                ulglitch = 0;
1834
1853
            }
1835
1854
 
1836
 
            if ((padstr = my_tgetstr("pc","pad")) != NULL)
 
1855
            if ((padstr = my_tgetstr(TERM_PAD_CHAR)) != NULL)
1837
1856
                PC = *padstr;
1838
 
            Home = my_tgetstr("ho","home");
 
1857
            Home = my_tgetstr(TERM_HOME);
1839
1858
            if (Home == 0 || *Home == '\0') {
1840
 
                if ((cursorm = my_tgetstr("cm","cup")) != NULL) {
 
1859
                if ((cursorm = my_tgetstr(TERM_CURSOR_ADDRESS)) != NULL) {
1841
1860
                    const char *t = (const char *)my_tgoto(cursorm, 0, 0);
1842
1861
                    xstrncpy(cursorhome, t, sizeof(cursorhome));
1843
1862
                    Home = cursorhome;
1844
1863
                }
1845
1864
            }
1846
 
            EodClr = my_tgetstr("cd","ed");
1847
 
            if ((chBS = my_tgetstr("le","cub1")) == NULL)
 
1865
            EodClr = my_tgetstr(TERM_CLEAR_TO_SCREEN_END);
 
1866
            if ((chBS = my_tgetstr(TERM_LINE_DOWN)) == NULL)
1848
1867
                chBS = "\b";
1849
1868
 
1850
1869
        }
1944
1963
                    }
1945
1964
                  }
1946
1965
                else
1947
 
#endif
 
1966
#endif /* HAVE_WIDECHAR */
1948
1967
                  {
1949
1968
                    --promptlen;
1950
1969
                    ERASEONECOLUMN
2106
2125
    if (no_tty)
2107
2126
        return;
2108
2127
    if (pstate) {
2109
 
        tputs(ULexit, 1, ourputch);     /* putchar - if that isnt a macro */
 
2128
        tputs(ULexit, fileno(stdout), ourputch);        /* putchar - if that isnt a macro */
2110
2129
        fflush(stdout);
2111
2130
        pstate = 0;
2112
2131
    }
2124
2143
    prepare_line_buffer();
2125
2144
 
2126
2145
    p = Line;
2127
 
    while ((c = Getc (f)) != '\n' && c != EOF && p - Line < LineLen - 1)
 
2146
    while ((c = Getc (f)) != '\n' && c != EOF && (size_t) (p - Line) < LineLen - 1)
2128
2147
        *p++ = c;
2129
2148
    if (c == '\n')
2130
2149
        Currline++;
2133
2152
 
2134
2153
/* Come here when we get a suspend signal from the terminal */
2135
2154
 
2136
 
void onsusp (int dummy) {
 
2155
void onsusp (int dummy __attribute__ ((__unused__)))
 
2156
{
2137
2157
    sigset_t signals, oldmask;
2138
2158
 
2139
2159
    /* ignore SIGTTOU so we don't get stopped if csh grabs the tty */