]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/progs/next.c
Replaced use of snprintf() with memcpy()/memmove().
[nmh] / docs / historical / mh-jun-1982 / progs / next.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #include "../mh.h"
9 #include <stdio.h>
10 #include <strings.h>
11
12 int glbtype;
13 int header = 1;
14 struct msgs *mp;
15
16 struct swit switches[] = {
17 "header", 0, /* 0 */
18 "noheader", 0, /* 1 */
19 "help", 4, /* 2 */
20 0, 0
21 };
22
23
24 /*ARGSUSED*/
25 main(argc, argv)
26 char *argv[];
27 {
28 char *maildir, *vec[20], *folder;
29 register char *cp;
30 int next;
31 int vecp;
32 char **ap;
33 char *arguments[50], **argp;
34 extern char _sobuf[];
35
36 invo_name = argv[0];
37 setbuf(stdout, _sobuf);
38 #ifdef NEWS
39 m_news();
40 #endif
41 next = glbtype;
42 folder = 0; vecp = 2;
43 cp = r1bindex(argv[0], '/');
44 if((cp = m_find(cp)) != NULL) {
45 ap = brkstring(cp = getcpy(cp), " ", "\n");
46 ap = copyip(ap, arguments);
47 } else
48 ap = arguments;
49 VOID copyip(argv+1, ap);
50 argp = arguments;
51 while(cp = *argp++) {
52 if(*cp == '-')
53 switch(smatch(++cp, switches)) {
54 case -2:ambigsw(cp, switches); /* ambiguous */
55 goto leave;
56 /* unknown */
57 case -1:vec[vecp++] = --cp; continue;
58 case 0: header = 1; continue; /* -header */
59 case 1: header = 0; continue; /* -noheader */
60 case 2: if(next > 0) /* -help */
61 help("next [+folder] [switches] [switches for \"type\" ]", switches);
62 else
63 help("prev [+folder] [switches] [switches for \"type\" ]", switches);
64 goto leave;
65 }
66 if(*cp == '+') {
67 if(folder) {
68 fprintf(stderr, "Only one folder at a time.\n");
69 goto leave;
70 } else
71 folder = path(cp+1, TFOLDER);
72 } else {
73 fprintf(stderr, "Bad arg: %s\n", cp);
74 fprintf(stderr, "Usage: %s [+folder] [-l.switches]\n",
75 next>0? "next" : "prev");
76 goto leave;
77 }
78 }
79 vec[vecp] = 0;
80 if(!m_find("path")) free(path("./", TFOLDER));
81 if(!folder)
82 folder = m_getfolder();
83 maildir = m_maildir(folder);
84 if(chdir(maildir) < 0) {
85 fprintf(stderr, "Can't chdir to: ");
86 perror(maildir);
87 goto leave;
88 }
89 if(!(mp = m_gmsg(folder))) {
90 fprintf(stderr, "Can't read folder!?\n");
91 goto leave;
92 }
93 if(mp->hghmsg == 0) {
94 fprintf(stderr, "No messages in \"%s\".\n", folder);
95 goto leave;
96 }
97 if(!m_convert(next > 0 ? "next" : "prev"))
98 goto leave;
99 m_replace(pfolder, folder);
100 if(mp->lowsel != mp->curmsg)
101 m_setcur(mp->lowsel);
102 vec[1] = m_name(mp->lowsel);
103 if(header)
104 printf("(Message %s:%s)\n", folder, vec[1]);
105 VOID fflush(stdout);
106 vec[0] = r1bindex(showproc, '/');
107 m_update();
108 putenv("mhfolder", folder);
109 execv(showproc, vec);
110 perror("Can't exec type");
111 leave:
112 m_update();
113 done(0);
114 }