(BWDIC!) Rewrite variable handling..
[s-mailx.git] / cmd1.c
blob66d97436012ae2b906ffccd23d4d126930634fa2
1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ User commands.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
6 */
7 /*
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
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.
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.
35 #undef n_FILE
36 #define n_FILE cmd1
38 #ifndef HAVE_AMALGAMATION
39 # include "nail.h"
40 #endif
42 static int _screen;
44 /* Prepare and print "[Message: xy]:" intro */
45 static void _show_msg_overview(FILE *obuf, struct message *mp, int msg_no);
47 /* ... And place the extracted date in `date' */
48 static void _parse_from_(struct message *mp, char date[FROM_DATEBUF]);
50 /* Print out the header of a specific message
51 * __hprf: handle *headline*
52 * __subject: return -1 if Subject: yet seen, otherwise smalloc()d Subject:
53 * __putindent: print out the indenting in threaded display */
54 static void _print_head(size_t yetprinted, size_t msgno, FILE *f,
55 bool_t threaded);
56 static void __hprf(size_t yetprinted, char const *fmt, size_t msgno,
57 FILE *f, bool_t threaded, char const *attrlist);
58 static char * __subject(struct message *mp, bool_t threaded,
59 size_t yetprinted);
60 static int __putindent(FILE *fp, struct message *mp, int maxwidth);
62 static int _dispc(struct message *mp, char const *a);
64 /* Shared `z' implementation */
65 static int a_cmd_scroll(char const *arg, bool_t onlynew);
67 /* Shared `headers' implementation */
68 static int _headers(int msgspec);
70 /* Show the requested messages */
71 static int _type1(int *msgvec, bool_t doign, bool_t dopage, bool_t dopipe,
72 bool_t dodecode, char *cmd, ui64_t *tstats);
74 /* Pipe the requested messages */
75 static int _pipe1(char *str, int doign);
77 static void
78 _show_msg_overview(FILE *obuf, struct message *mp, int msg_no)
80 char const *cpre = "", *csuf = "";
81 NYD_ENTER;
83 #ifdef HAVE_COLOUR
84 if (pstate & PS_COLOUR_ACTIVE) {
85 struct n_colour_pen *cpen;
87 if ((cpen = n_colour_pen_create(n_COLOUR_ID_VIEW_MSGINFO, NULL)) != NULL){
88 struct str const *sp;
90 if ((sp = n_colour_pen_to_str(cpen)) != NULL)
91 cpre = sp->s;
92 if ((sp = n_colour_reset_to_str()) != NULL)
93 csuf = sp->s;
96 #endif
97 fprintf(obuf, _("%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
98 cpre, msg_no, (ul_i)mp->m_lines, (ul_i)mp->m_size, csuf);
99 NYD_LEAVE;
102 static void
103 _parse_from_(struct message *mp, char date[FROM_DATEBUF]) /* TODO line pool */
105 FILE *ibuf;
106 int hlen;
107 char *hline = NULL;
108 size_t hsize = 0;
109 NYD_ENTER;
111 if ((ibuf = setinput(&mb, mp, NEED_HEADER)) != NULL &&
112 (hlen = readline_restart(ibuf, &hline, &hsize, 0)) > 0)
113 extract_date_from_from_(hline, hlen, date);
114 if (hline != NULL)
115 free(hline);
116 NYD_LEAVE;
119 static void
120 _print_head(size_t yetprinted, size_t msgno, FILE *f, bool_t threaded)
122 enum {attrlen = 14};
123 char attrlist[attrlen +1], *cp;
124 char const *fmt;
125 NYD_ENTER;
127 if ((cp = ok_vlook(attrlist)) != NULL) {
128 if (strlen(cp) == attrlen) {
129 memcpy(attrlist, cp, attrlen +1);
130 goto jattrok;
132 n_err(_("*attrlist* is not of the correct length, using builtin\n"));
135 if (ok_blook(bsdcompat) || ok_blook(bsdflags)) {
136 char const bsdattr[attrlen +1] = "NU *HMFAT+-$~";
137 memcpy(attrlist, bsdattr, sizeof bsdattr);
138 } else if (env_blook("SYSV3", FAL0)) {
139 char const bsdattr[attrlen +1] = "NU *HMFAT+-$~";
140 memcpy(attrlist, bsdattr, sizeof bsdattr);
141 OBSOLETE(_("*SYSV3*: please use *bsdcompat* or *bsdflags*, "
142 "or set *attrlist*"));
143 } else {
144 char const pattr[attrlen +1] = "NUROSPMFAT+-$~";
145 memcpy(attrlist, pattr, sizeof pattr);
148 jattrok:
149 if ((fmt = ok_vlook(headline)) == NULL) {
150 fmt = ((ok_blook(bsdcompat) || ok_blook(bsdheadline))
151 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
152 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
155 __hprf(yetprinted, fmt, msgno, f, threaded, attrlist);
156 NYD_LEAVE;
159 static void
160 __hprf(size_t yetprinted, char const *fmt, size_t msgno, FILE *f,
161 bool_t threaded, char const *attrlist)
163 char buf[16], datebuf[FROM_DATEBUF], cbuf[8], *cp, *subjline;
164 char const *datefmt, *date, *name, *fp n_COLOUR( COMMA *colo_tag );
165 int i, n, s, wleft, subjlen;
166 struct message *mp;
167 time_t datet;
168 n_COLOUR( struct n_colour_pen *cpen_new COMMA *cpen_cur COMMA *cpen_bas; )
169 enum {
170 _NONE = 0,
171 _ISDOT = 1<<0,
172 _ISADDR = 1<<1,
173 _ISTO = 1<<2,
174 _IFMT = 1<<3,
175 _LOOP_MASK = (1<<4) - 1,
176 _SFMT = 1<<4
177 } flags = _NONE;
178 NYD_ENTER;
179 UNUSED(buf);
181 if ((mp = message + msgno - 1) == dot)
182 flags = _ISDOT;
183 datet = mp->m_time;
184 date = NULL;
185 n_COLOUR( colo_tag = NULL; )
187 datefmt = ok_vlook(datefield);
188 jredo:
189 if (datefmt != NULL) {
190 fp = hfield1("date", mp);/* TODO use m_date field! */
191 if (fp == NULL) {
192 datefmt = NULL;
193 goto jredo;
195 datet = rfctime(fp);
196 date = fakedate(datet);
197 fp = ok_vlook(datefield_markout_older);
198 i = (*datefmt != '\0');
199 if (fp != NULL)
200 i |= (*fp != '\0') ? 2 | 4 : 2; /* XXX no magics */
202 /* May we strftime(3)? */
203 if (i & (1 | 4))
204 memcpy(&time_current.tc_local, localtime(&datet),
205 sizeof time_current.tc_local);
207 if ((i & 2) && (datet > time_current.tc_time + DATE_SECSDAY ||
208 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
209 (datet + _6M < time_current.tc_time))) {
210 #undef _6M
211 if ((datefmt = (i & 4) ? fp : NULL) == NULL) {
212 memset(datebuf, ' ', FROM_DATEBUF); /* xxx ur */
213 memcpy(datebuf + 4, date + 4, 7);
214 datebuf[4 + 7] = ' ';
215 memcpy(datebuf + 4 + 7 + 1, date + 20, 4);
216 datebuf[4 + 7 + 1 + 4] = '\0';
217 date = datebuf;
219 n_COLOUR( colo_tag = n_COLOUR_TAG_SUM_OLDER; )
220 } else if ((i & 1) == 0)
221 datefmt = NULL;
222 } else if (datet == (time_t)0 && !(mp->m_flag & MNOFROM)) {
223 /* TODO eliminate this path, query the FROM_ date in setptr(),
224 * TODO all other codepaths do so by themselves ALREADY ?????
225 * TODO assert(mp->m_time != 0);, then
226 * TODO ALSO changes behaviour of datefield_markout_older */
227 _parse_from_(mp, datebuf);
228 date = datebuf;
229 } else
230 date = fakedate(datet);
232 flags |= _ISADDR;
233 name = name1(mp, 0);
234 if (name != NULL && ok_blook(showto) && is_myname(skin(name))) {
235 if ((cp = hfield1("to", mp)) != NULL) {
236 name = cp;
237 flags |= _ISTO;
240 if (name == NULL) {
241 name = "";
242 flags &= ~_ISADDR;
244 if (flags & _ISADDR)
245 name = ok_blook(showname) ? realname(name) : prstr(skin(name));
247 subjline = NULL;
249 /* Detect the width of the non-format characters in *headline*;
250 * like that we can simply use putc() in the next loop, since we have
251 * already calculated their column widths (TODO it's sick) */
252 wleft = subjlen = scrnwidth;
254 for (fp = fmt; *fp != '\0'; ++fp) {
255 if (*fp == '%') {
256 if (*++fp == '-')
257 ++fp;
258 else if (*fp == '+')
259 ++fp;
260 if (digitchar(*fp)) {
261 n = 0;
263 n = 10*n + *fp - '0';
264 while (++fp, digitchar(*fp));
265 subjlen -= n;
267 if (*fp == 'i')
268 flags |= _IFMT;
270 if (*fp == '\0')
271 break;
272 } else {
273 #ifdef HAVE_WCWIDTH
274 if (mb_cur_max > 1) {
275 wchar_t wc;
276 if ((s = mbtowc(&wc, fp, mb_cur_max)) == -1)
277 n = s = 1;
278 else if ((n = wcwidth(wc)) == -1)
279 n = 1;
280 } else
281 #endif
282 n = s = 1;
283 subjlen -= n;
284 wleft -= n;
285 while (--s > 0)
286 ++fp;
290 /* Walk *headline*, producing output TODO not (really) MB safe */
291 #ifdef HAVE_COLOUR
292 if (flags & _ISDOT)
293 colo_tag = n_COLOUR_TAG_SUM_DOT;
294 cpen_bas = n_colour_pen_create(n_COLOUR_ID_SUM_HEADER, colo_tag);
295 n_colour_pen_put(cpen_new = cpen_cur = cpen_bas, f);
296 #endif
298 for (fp = fmt; *fp != '\0'; ++fp) {
299 char c;
301 if ((c = *fp & 0xFF) != '%') {
302 #ifdef HAVE_COLOUR
303 if ((cpen_new = cpen_bas) != cpen_cur)
304 n_colour_pen_put(cpen_cur = cpen_new, f);
305 #endif
306 putc(c, f);
307 continue;
310 flags &= _LOOP_MASK;
311 n = 0;
312 s = 1;
313 if ((c = *++fp) == '-') {
314 s = -1;
315 ++fp;
316 } else if (c == '+')
317 ++fp;
318 if (digitchar(*fp)) {
320 n = 10*n + *fp - '0';
321 while (++fp, digitchar(*fp));
324 if ((c = *fp & 0xFF) == '\0')
325 break;
326 n *= s;
328 cbuf[1] = '\0';
329 switch (c) {
330 case '%':
331 goto jputcb;
332 case '>':
333 case '<':
334 if (flags & _ISDOT) {
335 n_COLOUR( cpen_new = n_colour_pen_create(n_COLOUR_ID_SUM_DOTMARK,
336 colo_tag); );
337 if (options & OPT_UNICODE) {
338 if (c == '>')
339 /* 25B8;BLACK RIGHT-POINTING SMALL TRIANGLE: â–¸ */
340 cbuf[1] = (char)0x96, cbuf[2] = (char)0xB8;
341 else
342 /* 25C2;BLACK LEFT-POINTING SMALL TRIANGLE: â—‚ */
343 cbuf[1] = (char)0x97, cbuf[2] = (char)0x82;
344 c = (char)0xE2;
345 cbuf[3] = '\0';
347 } else
348 c = ' ';
349 goto jputcb;
350 case '$':
351 #ifdef HAVE_SPAM
352 if (n == 0)
353 n = 5;
354 if (UICMP(32, ABS(n), >, wleft))
355 n = (n < 0) ? -wleft : wleft;
356 snprintf(buf, sizeof buf, "%u.%02u",
357 (mp->m_spamscore >> 8), (mp->m_spamscore & 0xFF));
358 n = fprintf(f, "%*s", n, buf);
359 wleft = (n >= 0) ? wleft - n : 0;
360 break;
361 #else
362 c = '?';
363 goto jputcb;
364 #endif
365 case 'a':
366 c = _dispc(mp, attrlist);
367 jputcb:
368 #ifdef HAVE_COLOUR
369 if (cpen_new == cpen_cur)
370 cpen_new = cpen_bas;
371 if (cpen_new != cpen_cur)
372 n_colour_pen_put(cpen_cur = cpen_new, f);
373 #endif
374 if (UICMP(32, ABS(n), >, wleft))
375 n = (n < 0) ? -wleft : wleft;
376 cbuf[0] = c;
377 n = fprintf(f, "%*s", n, cbuf);
378 wleft = (n >= 0) ? wleft - n : 0;
379 #ifdef HAVE_COLOUR
380 if ((cpen_new = cpen_bas) != cpen_cur)
381 n_colour_pen_put(cpen_cur = cpen_new, f);
382 #endif
383 break;
384 case 'd':
385 if (datefmt != NULL) {
386 i = strftime(datebuf, sizeof datebuf, datefmt,
387 &time_current.tc_local);
388 if (i != 0)
389 date = datebuf;
390 else
391 n_err(_("Ignored date format, it excesses the target "
392 "buffer (%lu bytes)\n"), (ul_i)sizeof(datebuf));
393 datefmt = NULL;
395 if (n == 0)
396 n = 16;
397 if (UICMP(32, ABS(n), >, wleft))
398 n = (n < 0) ? -wleft : wleft;
399 n = fprintf(f, "%*.*s", n, n, date);
400 wleft = (n >= 0) ? wleft - n : 0;
401 break;
402 case 'e':
403 if (n == 0)
404 n = 2;
405 if (UICMP(32, ABS(n), >, wleft))
406 n = (n < 0) ? -wleft : wleft;
407 n = fprintf(f, "%*u", n, (threaded == 1 ? mp->m_level : 0));
408 wleft = (n >= 0) ? wleft - n : 0;
409 break;
410 case 'f':
411 if (n == 0) {
412 n = 18;
413 if (s < 0)
414 n = -n;
416 i = ABS(n);
417 if (i > wleft) {
418 i = wleft;
419 n = (n < 0) ? -wleft : wleft;
421 if (flags & _ISTO) /* XXX tr()! */
422 i -= 3;
423 n = fprintf(f, "%s%s", ((flags & _ISTO) ? "To " : ""),
424 colalign(name, i, n, &wleft));
425 if (n < 0)
426 wleft = 0;
427 else if (flags & _ISTO)
428 wleft -= 3;
429 break;
430 case 'i':
431 if (threaded) {
432 #ifdef HAVE_COLOUR
433 cpen_new = n_colour_pen_create(n_COLOUR_ID_SUM_THREAD, colo_tag);
434 if (cpen_new != cpen_cur)
435 n_colour_pen_put(cpen_cur = cpen_new, f);
436 #endif
437 n = __putindent(f, mp, MIN(wleft, scrnwidth - 60));
438 wleft = (n >= 0) ? wleft - n : 0;
439 #ifdef HAVE_COLOUR
440 if ((cpen_new = cpen_bas) != cpen_cur)
441 n_colour_pen_put(cpen_cur = cpen_new, f);
442 #endif
444 break;
445 case 'l':
446 if (n == 0)
447 n = 4;
448 if (UICMP(32, ABS(n), >, wleft))
449 n = (n < 0) ? -wleft : wleft;
450 if (mp->m_xlines) {
451 n = fprintf(f, "%*ld", n, mp->m_xlines);
452 wleft = (n >= 0) ? wleft - n : 0;
453 } else {
454 n = ABS(n);
455 wleft -= n;
456 while (n-- != 0)
457 putc(' ', f);
459 break;
460 case 'm':
461 if (n == 0) {
462 n = 3;
463 if (threaded)
464 for (i = msgCount; i > 999; i /= 10)
465 ++n;
467 if (UICMP(32, ABS(n), >, wleft))
468 n = (n < 0) ? -wleft : wleft;
469 n = fprintf(f, "%*lu", n, (ul_i)msgno);
470 wleft = (n >= 0) ? wleft - n : 0;
471 break;
472 case 'o':
473 if (n == 0)
474 n = -5;
475 if (UICMP(32, ABS(n), >, wleft))
476 n = (n < 0) ? -wleft : wleft;
477 n = fprintf(f, "%*lu", n, (ul_i)mp->m_xsize);
478 wleft = (n >= 0) ? wleft - n : 0;
479 break;
480 case 'S':
481 flags |= _SFMT;
482 /*FALLTHRU*/
483 case 's':
484 if (n == 0)
485 n = subjlen - 2;
486 if (n > 0 && s < 0)
487 n = -n;
488 if (subjlen > wleft)
489 subjlen = wleft;
490 if (UICMP(32, ABS(n), >, subjlen))
491 n = (n < 0) ? -subjlen : subjlen;
492 if (flags & _SFMT)
493 n -= (n < 0) ? -2 : 2;
494 if (n == 0)
495 break;
496 if (subjline == NULL)
497 subjline = __subject(mp, (threaded && (flags & _IFMT)), yetprinted);
498 if (subjline == (char*)-1) {
499 n = fprintf(f, "%*s", n, "");
500 wleft = (n >= 0) ? wleft - n : 0;
501 } else {
502 n = fprintf(f, ((flags & _SFMT) ? "\"%s\"" : "%s"),
503 colalign(subjline, ABS(n), n, &wleft));
504 if (n < 0)
505 wleft = 0;
507 break;
508 case 'T': { /* Message recipient flags */
509 /* We never can reuse "name" since it's the full name */
510 struct name const *np = lextract(hfield1("to", mp), GTO | GSKIN);
511 c = ' ';
512 i = 0;
513 j_A_redo:
514 for (; np != NULL; np = np->n_flink) {
515 switch (is_mlist(np->n_name, FAL0)) {
516 case MLIST_SUBSCRIBED: c = 'S'; goto jputcb;
517 case MLIST_KNOWN: c = 'L'; goto jputcb;
518 case MLIST_OTHER:
519 default: break;
522 if (i != 0)
523 goto jputcb;
524 ++i;
525 np = lextract(hfield1("cc", mp), GCC | GSKIN);
526 goto j_A_redo;
528 case 't':
529 if (n == 0) {
530 n = 3;
531 if (threaded)
532 for (i = msgCount; i > 999; i /= 10)
533 ++n;
535 if (UICMP(32, ABS(n), >, wleft))
536 n = (n < 0) ? -wleft : wleft;
537 n = fprintf(f, "%*lu",
538 n, (threaded ? (ul_i)mp->m_threadpos : (ul_i)msgno));
539 wleft = (n >= 0) ? wleft - n : 0;
540 break;
541 default:
542 if (options & OPT_D_V)
543 n_err(_("Unkown *headline* format: \"%%%c\"\n"), c);
544 c = '?';
545 goto jputcb;
548 if (wleft <= 0)
549 break;
552 #ifdef HAVE_COLOUR
553 n_colour_reset(f);
554 #endif
555 putc('\n', f);
557 if (subjline != NULL && subjline != (char*)-1)
558 free(subjline);
559 NYD_LEAVE;
562 static char *
563 __subject(struct message *mp, bool_t threaded, size_t yetprinted)
565 struct str in, out;
566 char *rv = (char*)-1, *ms;
567 NYD_ENTER;
569 if ((ms = hfield1("subject", mp)) == NULL)
570 goto jleave;
572 in.l = strlen(in.s = ms);
573 mime_fromhdr(&in, &out, TD_ICONV | TD_ISPR);
574 rv = ms = out.s;
576 if (!threaded || mp->m_level == 0)
577 goto jleave;
579 /* In a display thread - check wether this message uses the same
580 * Subject: as it's parent or elder neighbour, suppress printing it if
581 * this is the case. To extend this a bit, ignore any leading Re: or
582 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
583 ms = subject_re_trim(ms);
585 for (; (mp = prev_in_thread(mp)) != NULL && yetprinted-- > 0;) {
586 char *os;
588 if (visible(mp) && (os = hfield1("subject", mp)) != NULL) {
589 struct str oout;
590 int x;
592 in.l = strlen(in.s = os);
593 mime_fromhdr(&in, &oout, TD_ICONV | TD_ISPR);
594 x = asccasecmp(ms, subject_re_trim(oout.s));
595 free(oout.s);
597 if (!x) {
598 free(out.s);
599 rv = (char*)-1;
601 break;
604 jleave:
605 NYD_LEAVE;
606 return rv;
609 static int
610 __putindent(FILE *fp, struct message *mp, int maxwidth)/* XXX no magic consts */
612 struct message *mq;
613 int *us, indlvl, indw, i, important = MNEW | MFLAGGED;
614 char *cs;
615 NYD_ENTER;
617 if (mp->m_level == 0 || maxwidth == 0) {
618 indw = 0;
619 goto jleave;
622 cs = ac_alloc(mp->m_level);
623 us = ac_alloc(mp->m_level * sizeof *us);
625 i = mp->m_level - 1;
626 if (mp->m_younger && UICMP(32, i + 1, ==, mp->m_younger->m_level)) {
627 if (mp->m_parent && mp->m_parent->m_flag & important)
628 us[i] = mp->m_flag & important ? 0x2523 : 0x2520;
629 else
630 us[i] = mp->m_flag & important ? 0x251D : 0x251C;
631 cs[i] = '+';
632 } else {
633 if (mp->m_parent && mp->m_parent->m_flag & important)
634 us[i] = mp->m_flag & important ? 0x2517 : 0x2516;
635 else
636 us[i] = mp->m_flag & important ? 0x2515 : 0x2514;
637 cs[i] = '\\';
640 mq = mp->m_parent;
641 for (i = mp->m_level - 2; i >= 0; --i) {
642 if (mq) {
643 if (UICMP(32, i, >, mq->m_level - 1)) {
644 us[i] = cs[i] = ' ';
645 continue;
647 if (mq->m_younger) {
648 if (mq->m_parent && (mq->m_parent->m_flag & important))
649 us[i] = 0x2503;
650 else
651 us[i] = 0x2502;
652 cs[i] = '|';
653 } else
654 us[i] = cs[i] = ' ';
655 mq = mq->m_parent;
656 } else
657 us[i] = cs[i] = ' ';
660 --maxwidth;
661 for (indlvl = indw = 0; (ui8_t)indlvl < mp->m_level && indw < maxwidth;
662 ++indlvl) {
663 if (indw < maxwidth - 1)
664 indw += (int)putuc(us[indlvl], cs[indlvl] & 0xFF, fp);
665 else
666 indw += (int)putuc(0x21B8, '^', fp);
668 indw += putuc(0x25B8, '>', fp);
670 ac_free(us);
671 ac_free(cs);
672 jleave:
673 NYD_LEAVE;
674 return indw;
677 static int
678 _dispc(struct message *mp, char const *a)
680 int i = ' ';
681 NYD_ENTER;
683 if ((mp->m_flag & (MREAD | MNEW)) == MREAD)
684 i = a[3];
685 if ((mp->m_flag & (MREAD | MNEW)) == (MREAD | MNEW))
686 i = a[2];
687 if (mp->m_flag & MANSWERED)
688 i = a[8];
689 if (mp->m_flag & MDRAFTED)
690 i = a[9];
691 if ((mp->m_flag & (MREAD | MNEW)) == MNEW)
692 i = a[0];
693 if (!(mp->m_flag & (MREAD | MNEW)))
694 i = a[1];
695 if (mp->m_flag & MSPAM)
696 i = a[12];
697 if (mp->m_flag & MSPAMUNSURE)
698 i = a[13];
699 if (mp->m_flag & MSAVED)
700 i = a[4];
701 if (mp->m_flag & MPRESERVE)
702 i = a[5];
703 if (mp->m_flag & (MBOX | MBOXED))
704 i = a[6];
705 if (mp->m_flag & MFLAGGED)
706 i = a[7];
707 if (mb.mb_threaded == 1 && mp->m_collapsed > 0)
708 i = a[11];
709 if (mb.mb_threaded == 1 && mp->m_collapsed < 0)
710 i = a[10];
711 NYD_LEAVE;
712 return i;
715 static int
716 a_cmd_scroll(char const *arg, bool_t onlynew){
717 long l;
718 char *eptr;
719 bool_t isabs;
720 int msgspec, size, maxs;
721 NYD2_ENTER;
723 msgspec = onlynew ? -1 : 0;
724 size = screensize();
725 maxs = msgCount / size;
727 switch(*arg){
728 case '\0':
729 ++_screen;
730 goto jfwd;
731 case '$':
732 if(arg[1] != '\0')
733 goto jerr;
734 if(_screen == maxs)
735 goto jerrfwd;
736 _screen = maxs;
737 break;
738 case '+':
739 if(arg[1] == '\0')
740 ++_screen;
741 else{
742 isabs = FAL0;
744 ++arg;
745 if(0){
746 case '1': case '2': case '3': case '4': case '5':
747 case '6': case '7': case '8': case '9': case '0':
748 isabs = TRU1;
750 l = strtol(arg, &eptr, 10);
751 if(*eptr != '\0')
752 goto jerr;
753 if(l > maxs - (isabs ? 0 : _screen))
754 goto jerrfwd;
755 _screen = isabs ? (int)l : _screen + l;
757 jfwd:
758 if(_screen > maxs){
759 jerrfwd:
760 _screen = maxs;
761 printf(_("On last screenful of messages\n"));
763 break;
765 case '-':
766 if(arg[1] == '\0')
767 --_screen;
768 else{
769 ++arg;
770 l = strtol(arg, &eptr, 10);
771 if(*eptr != '\0')
772 goto jerr;
773 if(l > _screen)
774 goto jerrbwd;
775 _screen -= l;
777 if(_screen < 0){
778 jerrbwd:
779 _screen = 0;
780 printf(_("On first screenful of messages\n"));
782 if(msgspec == -1)
783 msgspec = -2;
784 break;
785 default:
786 jerr:
787 n_err(_("Unrecognized scrolling command \"%s\"\n"), arg);
788 size = 1;
789 goto jleave;
792 size = _headers(msgspec);
793 jleave:
794 NYD2_LEAVE;
795 return size;
798 static int
799 _headers(int msgspec) /* TODO rework v15 */
801 struct n_sigman sm;
802 bool_t volatile isrelax;
803 ui32_t volatile flag;
804 int g, k, mesg, size, lastg = 1;
805 struct message *mp, *mq, *lastmq = NULL;
806 enum mflag fl = MNEW | MFLAGGED;
807 NYD_ENTER;
809 time_current_update(&time_current, FAL0);
811 flag = 0;
812 isrelax = FAL0;
813 n_SIGMAN_ENTER_SWITCH(&sm, n_SIGMAN_ALL) {
814 case 0:
815 break;
816 default:
817 goto jleave;
820 #ifdef HAVE_COLOUR
821 if (options & OPT_INTERACTIVE)
822 n_colour_env_create(n_COLOUR_CTX_SUM, FAL0);
823 #endif
825 size = screensize();
826 if (_screen < 0)
827 _screen = 0;
828 #if 0 /* FIXME original code path */
829 k = _screen * size;
830 #else
831 if (msgspec <= 0)
832 k = _screen * size;
833 else
834 k = msgspec;
835 #endif
836 if (k >= msgCount)
837 k = msgCount - size;
838 if (k < 0)
839 k = 0;
841 if (mb.mb_threaded == 0) {
842 g = 0;
843 mq = message;
844 for (mp = message; PTRCMP(mp, <, message + msgCount); ++mp)
845 if (visible(mp)) {
846 if (g % size == 0)
847 mq = mp;
848 if (mp->m_flag & fl) {
849 lastg = g;
850 lastmq = mq;
852 if ((msgspec > 0 && PTRCMP(mp, ==, message + msgspec - 1)) ||
853 (msgspec == 0 && g == k) ||
854 (msgspec == -2 && g == k + size && lastmq) ||
855 (msgspec < 0 && g >= k && (mp->m_flag & fl) != 0))
856 break;
857 g++;
859 if (lastmq && (msgspec == -2 ||
860 (msgspec == -1 && PTRCMP(mp, ==, message + msgCount)))) {
861 g = lastg;
862 mq = lastmq;
864 _screen = g / size;
866 mp = mq;
867 mesg = (int)PTR2SIZE(mp - message);
868 if (PTRCMP(dot, !=, message + msgspec - 1)) { /* TODO really?? */
869 for (mq = mp; PTRCMP(mq, <, message + msgCount); ++mq)
870 if (visible(mq)) {
871 setdot(mq);
872 break;
876 srelax_hold();
877 isrelax = TRU1;
878 for (; PTRCMP(mp, <, message + msgCount); ++mp) {
879 ++mesg;
880 if (!visible(mp))
881 continue;
882 if (UICMP(32, flag++, >=, size))
883 break;
884 _print_head(0, mesg, stdout, 0);
885 srelax();
887 srelax_rele();
888 isrelax = FAL0;
889 } else { /* threaded */
890 g = 0;
891 mq = threadroot;
892 for (mp = threadroot; mp; mp = next_in_thread(mp))
893 if (visible(mp) &&
894 (mp->m_collapsed <= 0 ||
895 PTRCMP(mp, ==, message + msgspec - 1))) {
896 if (g % size == 0)
897 mq = mp;
898 if (mp->m_flag & fl) {
899 lastg = g;
900 lastmq = mq;
902 if ((msgspec > 0 && PTRCMP(mp, ==, message + msgspec - 1)) ||
903 (msgspec == 0 && g == k) ||
904 (msgspec == -2 && g == k + size && lastmq) ||
905 (msgspec < 0 && g >= k && (mp->m_flag & fl) != 0))
906 break;
907 g++;
909 if (lastmq && (msgspec == -2 ||
910 (msgspec == -1 && PTRCMP(mp, ==, message + msgCount)))) {
911 g = lastg;
912 mq = lastmq;
914 _screen = g / size;
915 mp = mq;
916 if (PTRCMP(dot, !=, message + msgspec - 1)) { /* TODO really?? */
917 for (mq = mp; mq; mq = next_in_thread(mq))
918 if (visible(mq) && mq->m_collapsed <= 0) {
919 setdot(mq);
920 break;
924 srelax_hold();
925 isrelax = TRU1;
926 while (mp) {
927 if (visible(mp) &&
928 (mp->m_collapsed <= 0 ||
929 PTRCMP(mp, ==, message + msgspec - 1))) {
930 if (UICMP(32, flag++, >=, size))
931 break;
932 _print_head(flag - 1, PTR2SIZE(mp - message + 1), stdout,
933 mb.mb_threaded);
934 srelax();
936 mp = next_in_thread(mp);
938 srelax_rele();
939 isrelax = FAL0;
942 if (!flag) {
943 printf(_("No more mail.\n"));
944 if (pstate & (PS_HOOK_MASK | PS_ROBOT))
945 flag = !flag;
948 n_sigman_cleanup_ping(&sm);
949 jleave:
950 if (isrelax)
951 srelax_rele();
952 n_COLOUR( n_colour_env_gut((sm.sm_signo != SIGPIPE) ? stdout : NULL); )
953 NYD_LEAVE;
954 n_sigman_leave(&sm, n_SIGMAN_VIPSIGS_NTTYOUT);
955 return !flag;
958 static int
959 _type1(int *msgvec, bool_t doign, bool_t dopage, bool_t dopipe,
960 bool_t dodecode, char *cmd, ui64_t *tstats)
962 struct n_sigman sm;
963 ui64_t mstats[1];
964 int rv = 1, *ip;
965 struct message *mp;
966 char const *cp;
967 FILE * volatile obuf;
968 bool_t volatile isrelax = FAL0;
969 NYD_ENTER;
970 {/* C89.. */
971 enum sendaction const action = ((dopipe && ok_blook(piperaw))
972 ? SEND_MBOX : dodecode
973 ? SEND_SHOW : doign
974 ? SEND_TODISP : SEND_TODISP_ALL);
975 bool_t const volatile formfeed = (dopipe && ok_blook(page));
976 obuf = stdout;
978 n_SIGMAN_ENTER_SWITCH(&sm, n_SIGMAN_ALL) {
979 case 0:
980 break;
981 default:
982 goto jleave;
985 if (dopipe) {
986 if ((cp = ok_vlook(SHELL)) == NULL)
987 cp = XSHELL;
988 if ((obuf = Popen(cmd, "w", cp, NULL, 1)) == NULL) {
989 n_perr(cmd, 0);
990 obuf = stdout;
992 } else if ((options & OPT_TTYOUT) && (dopage ||
993 ((options & OPT_INTERACTIVE) && (cp = ok_vlook(crt)) != NULL))) {
994 size_t nlines = 0;
996 if (!dopage) {
997 for (ip = msgvec; *ip && PTRCMP(ip - msgvec, <, msgCount); ++ip) {
998 mp = message + *ip - 1;
999 if (!(mp->m_have & HAVE_BODY))
1000 if (get_body(mp) != OKAY)
1001 goto jcleanup_leave;
1002 nlines += mp->m_lines + 1; /* Message info XXX and PARTS... */
1006 /* >= not <: we return to the prompt */
1007 if (dopage || UICMP(z, nlines, >=,
1008 (*cp != '\0' ? atoi(cp) : realscreenheight))) {
1009 if ((obuf = n_pager_open()) == NULL)
1010 obuf = stdout;
1012 #ifdef HAVE_COLOUR
1013 if ((options & OPT_INTERACTIVE) &&
1014 (action == SEND_TODISP || action == SEND_TODISP_ALL ||
1015 action == SEND_SHOW))
1016 n_colour_env_create(n_COLOUR_CTX_VIEW, obuf != stdout);
1017 #endif
1019 #ifdef HAVE_COLOUR
1020 else if ((options & OPT_INTERACTIVE) &&
1021 (action == SEND_TODISP || action == SEND_TODISP_ALL))
1022 n_colour_env_create(n_COLOUR_CTX_VIEW, FAL0);
1023 #endif
1025 /*TODO unless we have our signal manager special care must be taken */
1026 srelax_hold();
1027 isrelax = TRU1;
1028 for (ip = msgvec; *ip && PTRCMP(ip - msgvec, <, msgCount); ++ip) {
1029 mp = message + *ip - 1;
1030 touch(mp);
1031 setdot(mp);
1032 uncollapse1(mp, 1);
1033 if (!dopipe && ip != msgvec)
1034 fprintf(obuf, "\n");
1035 if (action != SEND_MBOX)
1036 _show_msg_overview(obuf, mp, *ip);
1037 sendmp(mp, obuf, (doign ? ignore : NULL), NULL, action, mstats);
1038 srelax();
1039 if (formfeed) /* TODO a nicer way to separate piped messages! */
1040 putc('\f', obuf);
1041 if (tstats != NULL)
1042 tstats[0] += mstats[0];
1044 srelax_rele();
1045 isrelax = FAL0;
1047 rv = 0;
1048 jcleanup_leave:
1049 n_sigman_cleanup_ping(&sm);
1050 jleave:
1051 if (isrelax)
1052 srelax_rele();
1053 n_COLOUR( n_colour_env_gut((sm.sm_signo != SIGPIPE) ? obuf : NULL); )
1054 if (obuf != stdout)
1055 n_pager_close(obuf);
1057 NYD_LEAVE;
1058 n_sigman_leave(&sm, n_SIGMAN_VIPSIGS_NTTYOUT);
1059 return rv;
1062 static int
1063 _pipe1(char *str, int doign)
1065 ui64_t stats[1];
1066 char *cmd;
1067 int *msgvec, rv = 1;
1068 bool_t needs_list;
1069 NYD_ENTER;
1071 if ((cmd = laststring(str, &needs_list, TRU1)) == NULL) {
1072 cmd = ok_vlook(cmd);
1073 if (cmd == NULL || *cmd == '\0') {
1074 n_err(_("Variable *cmd* not set\n"));
1075 goto jleave;
1079 msgvec = salloc((msgCount + 2) * sizeof *msgvec);
1081 if (!needs_list) {
1082 *msgvec = first(0, MMNORM);
1083 if (*msgvec == 0) {
1084 if (pstate & (PS_HOOK_MASK | PS_ROBOT)) {
1085 rv = 0;
1086 goto jleave;
1088 puts(_("No messages to pipe."));
1089 goto jleave;
1091 msgvec[1] = 0;
1092 } else if (getmsglist(str, msgvec, 0) < 0)
1093 goto jleave;
1094 if (*msgvec == 0) {
1095 if (pstate & (PS_HOOK_MASK | PS_ROBOT)) {
1096 rv = 0;
1097 goto jleave;
1099 printf("No applicable messages.\n");
1100 goto jleave;
1103 printf(_("Pipe to: \"%s\"\n"), cmd);
1104 stats[0] = 0;
1105 if ((rv = _type1(msgvec, doign, FAL0, TRU1, FAL0, cmd, stats)) == 0)
1106 printf("\"%s\" %" PRIu64 " bytes\n", cmd, stats[0]);
1107 jleave:
1108 NYD_LEAVE;
1109 return rv;
1112 FL int
1113 c_cmdnotsupp(void *v) /* TODO -> lex.c */
1115 NYD_ENTER;
1116 UNUSED(v);
1117 n_err(_("The requested feature is not compiled in\n"));
1118 NYD_LEAVE;
1119 return 1;
1122 FL int
1123 c_headers(void *v)
1125 int rv;
1126 NYD_ENTER;
1128 rv = print_header_group((int*)v);
1129 NYD_LEAVE;
1130 return rv;
1133 FL int
1134 print_header_group(int *vector)
1136 int rv;
1137 NYD_ENTER;
1139 assert(vector != NULL && vector != (void*)-1);
1140 rv = _headers(vector[0]);
1141 NYD_LEAVE;
1142 return rv;
1145 FL int
1146 c_scroll(void *v)
1148 int rv;
1149 NYD_ENTER;
1151 rv = a_cmd_scroll(v, FAL0);
1152 NYD_LEAVE;
1153 return rv;
1156 FL int
1157 c_Scroll(void *v)
1159 int rv;
1160 NYD_ENTER;
1162 rv = a_cmd_scroll(v, TRU1);
1163 NYD_LEAVE;
1164 return rv;
1167 FL int
1168 c_from(void *v)
1170 struct n_sigman sm;
1171 int *msgvec = v, *ip, n;
1172 char *cp;
1173 FILE * volatile obuf;
1174 bool_t volatile isrelax;
1175 NYD_ENTER;
1177 time_current_update(&time_current, FAL0);
1179 obuf = stdout;
1180 isrelax = FAL0;
1181 n_SIGMAN_ENTER_SWITCH(&sm, n_SIGMAN_ALL) {
1182 case 0:
1183 break;
1184 default:
1185 goto jleave;
1188 if (options & OPT_INTERACTIVE) {
1189 if ((cp = ok_vlook(crt)) != NULL) {
1190 for (n = 0, ip = msgvec; *ip != 0; ++ip)
1191 ++n;
1192 if (n > (*cp == '\0' ? screensize() : atoi(cp)) + 3 &&
1193 (obuf = n_pager_open()) == NULL)
1194 obuf = stdout;
1196 n_COLOUR( n_colour_env_create(n_COLOUR_CTX_SUM, obuf != stdout); )
1199 /* Update dot before display so that the dotmark etc. are correct */
1200 for (ip = msgvec; *ip != 0; ++ip)
1202 if (--ip >= msgvec)
1203 setdot(message + *ip - 1);
1205 srelax_hold();
1206 isrelax = TRU1;
1207 for (n = 0, ip = msgvec; *ip != 0; ++ip) { /* TODO join into _print_head() */
1208 _print_head((size_t)n++, (size_t)*ip, obuf, mb.mb_threaded);
1209 srelax();
1211 srelax_rele();
1212 isrelax = FAL0;
1214 n_sigman_cleanup_ping(&sm);
1215 jleave:
1216 if (isrelax)
1217 srelax_rele();
1218 n_COLOUR( n_colour_env_gut((sm.sm_signo != SIGPIPE) ? obuf : NULL); )
1219 if (obuf != stdout)
1220 n_pager_close(obuf);
1221 NYD_LEAVE;
1222 n_sigman_leave(&sm, n_SIGMAN_VIPSIGS_NTTYOUT);
1223 return 0;
1226 FL void
1227 print_headers(size_t bottom, size_t topx, bool_t only_marked)
1229 struct n_sigman sm;
1230 bool_t volatile isrelax;
1231 size_t printed;
1232 NYD_ENTER;
1234 time_current_update(&time_current, FAL0);
1236 isrelax = FAL0;
1237 n_SIGMAN_ENTER_SWITCH(&sm, n_SIGMAN_ALL) {
1238 case 0:
1239 break;
1240 default:
1241 goto jleave;
1244 #ifdef HAVE_COLOUR
1245 if (options & OPT_INTERACTIVE)
1246 n_colour_env_create(n_COLOUR_CTX_SUM, FAL0);
1247 #endif
1249 srelax_hold();
1250 isrelax = TRU1;
1251 for (printed = 0; bottom <= topx; ++bottom) {
1252 struct message *mp = message + bottom - 1;
1253 if (only_marked) {
1254 if (!(mp->m_flag & MMARK))
1255 continue;
1256 } else if (!visible(mp))
1257 continue;
1258 _print_head(printed++, bottom, stdout, FAL0);
1259 srelax();
1261 srelax_rele();
1262 isrelax = FAL0;
1264 n_sigman_cleanup_ping(&sm);
1265 jleave:
1266 if (isrelax)
1267 srelax_rele();
1268 n_COLOUR( n_colour_env_gut((sm.sm_signo != SIGPIPE) ? stdout : NULL); )
1269 NYD_LEAVE;
1270 n_sigman_leave(&sm, n_SIGMAN_VIPSIGS_NTTYOUT);
1273 FL int
1274 c_pdot(void *v)
1276 NYD_ENTER;
1277 UNUSED(v);
1278 printf("%d\n", (int)PTR2SIZE(dot - message + 1));
1279 NYD_LEAVE;
1280 return 0;
1283 FL int
1284 c_more(void *v)
1286 int *msgvec = v, rv;
1287 NYD_ENTER;
1289 rv = _type1(msgvec, TRU1, TRU1, FAL0, FAL0, NULL, NULL);
1290 NYD_LEAVE;
1291 return rv;
1294 FL int
1295 c_More(void *v)
1297 int *msgvec = v, rv;
1298 NYD_ENTER;
1300 rv = _type1(msgvec, FAL0, TRU1, FAL0, FAL0, NULL, NULL);
1301 NYD_LEAVE;
1302 return rv;
1305 FL int
1306 c_type(void *v)
1308 int *msgvec = v, rv;
1309 NYD_ENTER;
1311 rv = _type1(msgvec, TRU1, FAL0, FAL0, FAL0, NULL, NULL);
1312 NYD_LEAVE;
1313 return rv;
1316 FL int
1317 c_Type(void *v)
1319 int *msgvec = v, rv;
1320 NYD_ENTER;
1322 rv = _type1(msgvec, FAL0, FAL0, FAL0, FAL0, NULL, NULL);
1323 NYD_LEAVE;
1324 return rv;
1327 FL int
1328 c_show(void *v)
1330 int *msgvec = v, rv;
1331 NYD_ENTER;
1333 rv = _type1(msgvec, FAL0, FAL0, FAL0, TRU1, NULL, NULL);
1334 NYD_LEAVE;
1335 return rv;
1338 FL int
1339 c_pipe(void *v)
1341 char *str = v;
1342 int rv;
1343 NYD_ENTER;
1345 rv = _pipe1(str, 1);
1346 NYD_LEAVE;
1347 return rv;
1350 FL int
1351 c_Pipe(void *v)
1353 char *str = v;
1354 int rv;
1355 NYD_ENTER;
1357 rv = _pipe1(str, 0);
1358 NYD_LEAVE;
1359 return rv;
1362 FL int
1363 c_top(void *v)
1365 int *msgvec = v, *ip, c, topl, lines, empty_last;
1366 struct message *mp;
1367 char *cp, *linebuf = NULL;
1368 size_t linesize = 0;
1369 FILE *ibuf;
1370 NYD_ENTER;
1372 topl = 5;
1373 cp = ok_vlook(toplines);
1374 if (cp != NULL) {
1375 topl = atoi(cp);
1376 if (topl < 0 || topl > 10000)
1377 topl = 5;
1380 /* XXX Colours of `top' only for message and part info lines */
1381 #ifdef HAVE_COLOUR
1382 if (options & OPT_INTERACTIVE)
1383 n_colour_env_create(n_COLOUR_CTX_VIEW, FAL0);
1384 #endif
1385 empty_last = 1;
1386 for (ip = msgvec; *ip != 0 && UICMP(z, PTR2SIZE(ip - msgvec), <, msgCount);
1387 ++ip) {
1388 mp = message + *ip - 1;
1389 touch(mp);
1390 setdot(mp);
1391 pstate |= PS_DID_PRINT_DOT;
1392 if (!empty_last)
1393 printf("\n");
1394 _show_msg_overview(stdout, mp, *ip);
1395 if (mp->m_flag & MNOFROM)
1396 /* XXX c_top(): coloured output? */
1397 printf("From %s %s\n", fakefrom(mp), fakedate(mp->m_time));
1398 if ((ibuf = setinput(&mb, mp, NEED_BODY)) == NULL) { /* XXX use TOP */
1399 v = NULL;
1400 break;
1402 c = mp->m_lines;
1403 for (lines = 0; lines < c && UICMP(32, lines, <=, topl); ++lines) {
1404 if (readline_restart(ibuf, &linebuf, &linesize, 0) < 0)
1405 break;
1406 puts(linebuf);
1408 for (cp = linebuf; *cp != '\0' && blankchar(*cp); ++cp)
1410 empty_last = (*cp == '\0');
1414 n_COLOUR( n_colour_env_gut(stdout); )
1415 if (linebuf != NULL)
1416 free(linebuf);
1417 NYD_LEAVE;
1418 return (v != NULL);
1421 FL int
1422 c_stouch(void *v)
1424 int *msgvec = v, *ip;
1425 NYD_ENTER;
1427 for (ip = msgvec; *ip != 0; ++ip) {
1428 setdot(message + *ip - 1);
1429 dot->m_flag |= MTOUCH;
1430 dot->m_flag &= ~MPRESERVE;
1431 pstate |= PS_DID_PRINT_DOT;
1433 NYD_LEAVE;
1434 return 0;
1437 FL int
1438 c_mboxit(void *v)
1440 int *msgvec = v, *ip;
1441 NYD_ENTER;
1443 if (pstate & PS_EDIT) {
1444 n_err(_("`mbox' can only be used in a system mailbox\n")); /* TODO */
1445 goto jleave;
1448 for (ip = msgvec; *ip != 0; ++ip) {
1449 setdot(message + *ip - 1);
1450 dot->m_flag |= MTOUCH | MBOX;
1451 dot->m_flag &= ~MPRESERVE;
1452 pstate |= PS_DID_PRINT_DOT;
1454 jleave:
1455 NYD_LEAVE;
1456 return 0;
1459 FL int
1460 c_folders(void *v)
1462 char dirname[PATH_MAX], *name, **argv = v;
1463 char const *cmd;
1464 int rv = 1;
1465 NYD_ENTER;
1467 if (*argv) {
1468 name = expand(*argv);
1469 if (name == NULL)
1470 goto jleave;
1471 } else if (!getfold(dirname, sizeof dirname)) {
1472 n_err(_("No value set for \"folder\"\n"));
1473 goto jleave;
1474 } else
1475 name = dirname;
1477 if ((cmd = ok_vlook(LISTER)) == NULL)
1478 cmd = XLISTER;
1479 run_command(cmd, 0, COMMAND_FD_PASS, COMMAND_FD_PASS, name, NULL, NULL,
1480 NULL);
1481 jleave:
1482 NYD_LEAVE;
1483 return rv;
1486 /* s-it-mode */