home *** CD-ROM | disk | FTP | other *** search
- /*
- * DO_LISTS.C
- *
- * (C) Copyright 1985-1990 by Matthew Dillon, All Rights Reserved.
- *
- * Global Routines: DO_SETLIST()
- * DO_LIST()
- * DO_SELECT()
- * DO_DEFER()
- *
- * Static Routines: None.
- *
- * LIST associated commands.
- *
- */
-
- #include <stdio.h>
- #include <string.h>
-
- #include "dmail.h"
-
- Prototype int do_setlist (char *str, int com);
- Prototype int do_rlist (char *garbage, int com);
- Prototype int do_list (char *garbage, int com);
- Prototype int do_select (char *str, int mode);
- Prototype int do_defer (char *garbage, int com);
-
- int
- do_setlist (char *str, int com)
- {
- int i, fw, idx, localecho = 1;
- int sac = 1;
-
- push_break();
- if (ac > sac && strcmp (av[sac], "-s") == 0) {
- ++sac;
- localecho = 0;
- }
- hold_load();
- if (ac > sac) {
- Listsize = 0;
- for (i = sac; i < ac; ++i) {
- fw = atoi(av[i]);
- if (fw > 4096)
- fw = 4096;
- if (fw < 0 || (*av[i] < '0' || *av[i] > '9'))
- fw = 20;
- else
- ++i;
- if (i >= ac)
- continue;
- idx = get_extra_ovr (av[i]);
- if (idx < 0) {
- printf ("To many entries, cannot load: %s\n", av[i]);
- fflush (stdout);
- continue;
- }
- header[Listsize] = idx;
- width[Listsize] = fw;
- ++Listsize;
- }
- }
- nohold_load();
- pop_break();
- if (localecho) {
- puts ("");
- printf ("Entry Width Field\n\n");
- for (i = 0; i < Listsize; ++i)
- printf ("%-6d %-5d %s\n", i, width[i], Find[header[i]].search);
- puts ("");
- }
- return (1);
- }
-
-
- /*
- * Pre-position # 0 > Current article
- * 1 - Read already
- */
-
- int
- do_rlist (char *garbage, int com)
- {
- int
- num = 20,
- istart = Current,
- iend = Current,
- dir = 1,
- try;
- char
- buf [64];
-
- if (av [1])
- num = atoi (av [1]);
-
- if (num < 0) {
- dir = -1;
- num = -num;
- }
-
- for (try = 0; try < 2 && num; ++try, (dir = -dir)) {
- int i;
- if (dir < 0) {
- for (i = Current; i >= 0 && num; --i) {
- if (Entry [i].no && !(Entry [i].status & ST_DELETED)) {
- istart = i;
- --num;
- }
- }
- }
- else {
- for (i = Current; i < Entries && num; ++i) {
- if (Entry [i].no && !(Entry [i].status & ST_DELETED)) {
- iend = i;
- --num;
- }
- }
- }
- }
-
- if (istart != iend) {
- sprintf (buf, "%d-%d", Entry [istart].no, Entry [iend].no);
- ac = 2;
- av[1] = buf;
- return do_list (NULL, 0);
- }
-
- return -1;
- }
-
- int
- do_list (char *garbage, int com)
- {
- int
- i,
- j;
- static char
- curr [10] = { " " };
-
- if (ac == 1) {
- av [1] = "all";
- ++ac;
- }
-
- if (push_base ()) {
- push_break ();
- pop_base ();
- PAGER ((char *) -1);
- pop_break ();
- return -1;
- }
-
- PAGER (0);
- FPAGER ("\n ");
- for (j = 0; j < Listsize; ++j) {
- if (width [j]) {
- sprintf (Puf, "%-*.*s",
- 2 + width [j],
- 2 + width [j],
- Find [header [j]].search);
- FPAGER (Puf);
- }
- }
-
- FPAGER ("\n");
- rewind_range (1);
- while (i = get_range ()) {
- i = indexof (i);
- if (Entry [i].no && ((Entry [i].status & ST_DELETED) == 0)) {
- curr [0] = (Entry [i].status & ST_TAG) ? 'T' : ' ';
- curr [1] = (i == Current) ? '>' : ' ';
- curr [2] = (Entry [i].status & ST_READ) ? 'r' : ' ';
- curr [3] = (Entry [i].status & ST_STORED) ? 'w' : ' ';
- sprintf (Puf, "%s%-3d", curr, Entry [i].no);
- FPAGER (Puf);
- for (j = 0; j < Listsize; ++j) {
- if (width [j]) {
- sprintf(Puf, " %-*.*s",
- width [j],
- width [j],
- Entry [i].fields [header [j]]);
- FPAGER (Puf);
- }
- }
- FPAGER ("\n");
- }
- }
-
- FPAGER ("\n");
- PAGER ((char *) -1);
- pop_base ();
- return 1;
- }
-
- int
- do_select (char *str, int mode)
- {
- int
- ret = 1,
- localecho = 1,
- avi = 1,
- scr;
-
- if (ac == 1)
- return 1;
-
- SelAll = 0;
-
- if (strcmp (av [avi], "-s") == 0) {
- localecho = 0;
- ++avi;
- --ac;
- }
-
- switch (ac) {
- case 2:
- SelAll = 1;
- if (localecho)
- puts ("SELECT ALL");
- ret = m_select (Nulav, mode);
- break;
-
- case 1:
- break;
-
- default:
- ret = m_select (av + avi, mode);
- scr = indexof (0);
- if (scr > 0 && localecho)
- printf ("%d Entries selected\n", Entry [scr].no);
- break;
- }
-
- if (ret < 0 && localecho) {
- puts ("Null field");
- return -1;
- }
-
- return 1;
- }
-
- int
- do_defer (char *garbage, int com)
- {
- register int
- i,
- j;
-
- push_break ();
- j = 1;
- for (i = 0; i < Entries; ++i) {
- if (Entry [i].no)
- Entry [i].no = (Entry [i].status & ST_READ) ? 0 : j++;
- }
- pop_break ();
- return 1;
- }
-