source: trunk/athena/bin/discuss/mclient/dspipe.c @ 8855

Revision 8855, 3.4 KB checked in by ghudson, 28 years ago (diff)
BSD -> ANSI string and memory functions
Line 
1/*
2 *
3 *      Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology
4 *      Developed by the MIT Student Information Processing Board (SIPB).
5 *      For copying information, see the file mit-copyright.h in this release.
6 *
7 */
8/*
9 *
10 * dspipe.c -- Program to pipe stdin into a Discuss meeting.
11 *
12 */
13
14#include <discuss/tfile.h>
15#include <discuss/interface.h>
16#include <discuss/dsc_et.h>
17#include <rpc.h>
18#include <sys/file.h>
19#include <stdio.h>
20#include <string.h>
21#include <fcntl.h>
22
23tfile unix_tfile();
24char *mktemp();
25
26#ifndef lint
27static char rcsid[] = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/discuss/mclient/dspipe.c,v 1.8 1996-09-19 22:31:29 ghudson Exp $";
28#endif
29
30main (argc,argv)
31int argc;
32char **argv;
33{
34        char *usr_mtg = "";
35        char *subject = "";
36        char *signature = "";
37        char mtg_name [100],host[70];
38        int result;
39        int fatal_err;
40        trn_nums result_trn;
41        char filename [40], buffer [512];
42        tfile tf;
43        int i,nread,d,exit_code;
44
45        init_dsc_err_tbl();
46        for (i = 1; i < argc; i++) {
47                if (*argv[i] == '-')
48                        switch (argv[i][1]) {
49                        case 'd':
50                        case 'a':
51                                continue;
52                               
53                        case 't':
54                                if (++i < argc)
55                                        subject = argv[i];
56                                continue;
57
58                        case 's':
59                                if (++i < argc)
60                                        signature = argv[i];
61                                continue;
62
63                        default:
64                                goto lusage;
65                        }
66                if (*usr_mtg != '\0')
67                        goto lusage; /* only one meeting name */
68               
69                usr_mtg = argv[i];
70        }
71       
72        if (*usr_mtg == '\0')
73                goto lusage;
74
75
76        (void) strcpy (filename, "/tmp/DSXXXXXX");
77        (void) mktemp (filename);
78
79        d = open (filename, O_RDWR | O_CREAT, 0700);
80        if (d < 0) {
81                (void) fprintf (stderr, "Cannot open temp file\n");
82                exit (1);
83        }
84
85        for (;;) {
86                nread = read (0, buffer, 512);
87                if (nread < 0) {
88                        (void) fprintf (stderr, "Cannot read stdin\n");
89                }
90                write (d, buffer, nread);
91                if (nread == 0)
92                        break;
93        }
94
95        lseek (d, 0, 0);        /* rewind temp */
96
97        tf = unix_tfile (d);
98
99        strcpy (host, "discuss@");
100        resolve_mtg (usr_mtg, &host[8], mtg_name);
101
102        init_rpc();
103        set_module (host, &fatal_err, &result);
104        if (fatal_err) {
105             (void) fprintf (stderr, "%s\n", error_message(result));
106             exit(1);
107        }
108        if (result) {
109             (void) fprintf (stderr, "Warning: %s\n", error_message(result));
110        }
111
112        if (signature[0] == '\0') {
113             add_trn (mtg_name, tf, subject, 0, &result_trn, &result);
114        } else {
115             if (get_server_version() < SERVER_2)
116                  add_trn (mtg_name, tf, subject, 0, &result_trn, &result);
117             else
118                  add_trn2(mtg_name, tf, subject, signature, 0, &result_trn, &result);
119        }
120                 
121        if (result != 0) {
122                (void) fprintf (stderr, "%s\n", error_message(result));
123                exit_code = 1;
124                goto bye;
125        }
126
127        (void) printf ("Transaction [%04d] added to %s\n", result_trn,
128                       mtg_name);
129        exit_code = 0;
130
131 bye:
132        (void) close (d);
133        tdestroy (tf);
134        (void) unlink (filename);
135
136        term_rpc();
137        exit (exit_code);
138
139 lusage:
140        (void) fprintf (stderr, "Usage: dspipe {mtgname} -t {topic} -s {signature}\n");
141        exit (1);
142}
143
144/*
145 *
146 * resolve_mtg:  Procedure to resolve a user meeting name into its host
147 *               an pathname.
148 *
149 */
150resolve_mtg (usr_string, host, mtg_name)
151char *usr_string,*host,*mtg_name;
152{
153        char *colon;
154        int host_len;
155
156        colon = strchr (usr_string, ':');
157
158        if (colon == 0) {
159                (void) strcpy (mtg_name, usr_string);
160                gethostname (host, 50);
161                return;
162        }
163
164        host_len = colon - usr_string;
165#ifdef POSIX
166      memmove (host, usr_string, host_len);
167#else
168        bcopy (usr_string, host, host_len);
169#endif
170        host [host_len] = '\0';
171        (void) strcpy (mtg_name, colon+1);
172        return;
173}
Note: See TracBrowser for help on using the repository browser.