]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/Extras/anno.cc
Replaced use of snprintf() with memcpy()/memmove().
[nmh] / docs / historical / mh-jun-1982 / Extras / anno.cc
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
10 /* anno [+folder] [msgs] [switches] -component component [-text [text]]
11 *
12 * prepends Component: <<date stamp>>
13 * text
14 */
15
16 int fout;
17 struct msgs *mp;
18 int inplace; /* preserve links in anno */
19
20 struct swit switches[] {
21 "all", -3, /* 0 */
22 "component", 0, /* 1 */
23 "inplace", 0, /* 2 */
24 "noinplace", 0, /* 3 */
25 "text", 0, /* 4 */
26 "help", 4, /* 5 */
27 0, 0
28 };
29
30 main(argc, argv)
31 char *argv[];
32 {
33 register int i, msgnum;
34 register char *cp, *ap;
35 char *folder, *maildir, *msgs[128], *component, *text;
36 char *arguments[50], **argp;
37 int msgp;
38
39 fout = dup(1);
40 #ifdef NEWS
41 m_news();
42 #endif
43 folder = msgp = component = text = 0;
44 ap = cp = argv[0];
45 while(*cp)
46 if(*cp++ == '/')
47 ap = cp;
48 if((cp = m_find(ap)) != -1) {
49 ap = brkstring(cp = getcpy(cp), " ", "\n");
50 ap = copyip(ap, arguments);
51 } else
52 ap = arguments;
53 copyip(argv+1, ap);
54 argp = arguments;
55 while(cp = *argp++) {
56 if(*cp == '-')
57 switch(smatch(++cp, switches)) {
58 case -2:ambigsw(cp, switches); /* ambiguous */
59 goto leave;
60 /* unknown */
61 case -1:printf("anno: -%s unknown\n", cp);
62 goto leave;
63 /* -all */
64 case 0: printf("\"-all\" changed to \"all\"\n");
65 goto leave;
66 /* -component */
67 case 1: if(component) {
68 printf("Only one component.\n");
69 goto leave;
70 }
71 if(!(component = *argp++)) {
72 printf("anno: Missing argument for %s switch\n", argp[-2]);
73 goto leave;
74 }
75 continue;
76 case 2: inplace = 1; continue; /* -inplace */
77 case 3: inplace = 0; continue; /* -noinplace */
78 case 4: if(text) { /* -text */
79 printf("Only one text switch.\n");
80 goto leave;
81 }
82 text = *argp++; continue;
83 case 5: /* -help */
84 help("anno [+folder] [msgs] [switches] -component component [-text [text]]", switches);
85 goto leave;
86 }
87 if(*cp == '+')
88 if(folder) {
89 printf("Only one folder at a time.\n");
90 goto leave;
91 } else
92 folder = cp + 1;
93 else
94 msgs[msgp++] = cp;
95 }
96 if(!component) {
97 usage:
98 printf("usage: anno [+folder] [msgs] [switches] -component component [-text [text]] \n");
99 goto leave;
100 }
101 if(!msgp)
102 msgs[msgp++] = "cur";
103 if(!folder)
104 folder = m_getfolder();
105 maildir = m_maildir(folder);
106 if(chdir(maildir) < 0) {
107 printf("Can't chdir to: "); flush();
108 perror(maildir);
109 goto leave;
110 }
111 if(!(mp = m_gmsg(folder))) {
112 printf("Can't read folder!?\n");
113 goto leave;
114 }
115 if(mp->hghmsg == 0) {
116 printf("No messages in \"%s\".\n", folder);
117 goto leave;
118 }
119 for(msgnum = 0; msgnum < msgp; msgnum++)
120 if(!m_convert(msgs[msgnum]))
121 goto leave;
122 if(mp->numsel == 0) {
123 printf("anno: feta cheese and garlic\n"); /* never get here */
124 goto leave;
125 }
126 m_replace("folder", folder);
127 if(mp->lowsel != mp->curmsg)
128 m_setcur(mp->lowsel);
129 for(i = mp->lowsel; i <= mp->hghsel; i++)
130 if(mp->msgstats[i] & SELECTED)
131 annotate(m_name(i), component, text ? text : "");
132 leave:
133 m_update();
134 flush();
135 }
136
137
138 /*
139 * if(*cp == '\"' )
140 * if(astrp > 1)
141 * goto usage;
142 * else
143 * if(!(ap = rmquote(cp + 1)))
144 * goto usage;
145 * astrings[astrp++] = ap;
146 *rmquote(cp)
147 *char *cp;
148 *{
149 * int i;
150 *
151 * if(cp[i = length(cp) -1] != '\"') {
152 * printf("rmquote: string doesn't end with \"\n");
153 * return(0);
154 * }
155 * cp[i] = 0;
156 * return(cp);
157 *}
158 if(*cp == '=' ) {
159 if(astrp > 1)
160 goto usage;
161 else
162 astrings[astrp++] = cp + 1;