]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/progs/adrformat.c
Replaced use of snprintf() with memcpy()/memmove().
[nmh] / docs / historical / mh-jun-1982 / progs / adrformat.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 <stdio.h>
9 #include "../mh.h"
10 #include "../adrparse.h"
11 #include <ctype.h>
12
13 extern char *sprintf();
14
15 char *
16 adrformat(mp,hostname)
17 register struct mailname *mp;
18 register char *hostname;
19 {
20 static char buf[512];
21 register char *tp, *cp, *sp;
22
23 for(tp = buf, cp = mp->m_text;*cp ;cp++ ) {
24 if(cp == mp->m_at) {
25 if(*cp == '@') {
26 if(cp[-1] != ' ')
27 *tp++ = ' ';
28 *tp++ = 'a';
29 *tp++ = 't';
30 if(cp[1] != ' ')
31 *tp++ = ' ';
32 continue;
33 }
34 }
35 if((cp == mp->m_hs) && (*mp->m_at != '!')){
36 if(sp = stdhost(mp->m_hnum)) {
37 while(*sp)
38 *tp++ = islower(*sp) ?
39 toupper(*sp++) : *sp++;
40 cp = mp->m_he;
41 continue;
42 } else {
43 fprintf(stderr, "adrformat: bad host!?\n");
44 return NULL;
45 }
46 }
47 *tp++ = *cp;
48 }
49 if(mp->m_nohost)
50 VOID sprintf(tp, " at %s", !mp->m_at? mp->m_host: hostname);
51 /* This probably only needs "hostname" unconditionally */
52 else
53 *tp = 0;
54 return buf;
55 }
56
57
58 char *
59 stdhost(num)
60 long num;
61 {
62 register struct hosts *hp;
63
64 for(hp = hosts.nh_next; hp; hp = hp->nh_next)
65 if(num == hp->nh_num)
66 return hp->nh_name;
67 return 0;
68 }