4 * This is just a little hack to copy standard input to a message in Aide>
6 * Copyright (c) 1987-2009 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #if TIME_WITH_SYS_TIME
28 # include <sys/time.h>
32 # include <sys/time.h>
42 #include "citadel_dirs.h"
51 * Simplified function to generate a message in our format
53 static void ap_make_message(FILE *fp, char *target_room, char *author, char *subject)
62 fprintf(fp, "Proom_aide");
64 fprintf(fp, "T%ld", (long)now);
66 fprintf(fp, "A%s", author);
68 fprintf(fp, "O%s", target_room);
70 if (strlen(subject) > 0) {
71 fprintf(fp, "U%s%c", subject, 0);
73 fprintf(fp, "N%s", NODENAME);
77 while (a = getc(stdin), a > 0) {
91 int main(int argc, char **argv)
94 char target_room[ROOMNAMELEN];
97 FILE *tempfp, *spoolfp;
103 char relhome[PATH_MAX]="";
104 char ctdldir[PATH_MAX]=CTDLDIR;
106 /* TODO: should we be able to calculate relative dirs? */
107 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
112 strcpy(target_room, "Aide");
113 strcpy(author, "Citadel");
115 for (i=1; i<argc; ++i) {
116 if (!strncasecmp(argv[i], "-r", 2)) {
117 strncpy(target_room, &argv[i][2], sizeof(target_room));
118 target_room[sizeof(target_room)-1] = 0;
120 else if (!strncasecmp(argv[i], "-a", 2)) {
121 strncpy(author, &argv[i][2], sizeof(author));
122 author[sizeof(author)-1] = 0;
124 else if (!strncasecmp(argv[i], "-s", 2)) {
125 strncpy(subject, &argv[i][2], sizeof(subject));
126 subject[sizeof(subject)-1] = 0;
128 fprintf(stderr, "%s: usage: %s "
129 "[-rTargetRoom] [-aAuthor] [-sSubject]\n",
135 snprintf(tempspool, sizeof tempspool,
142 tempfp = fopen(tempspool, "w+b");
144 if (tempfp == NULL) {
145 perror("cannot open temp file");
149 /* Generate a message from stdin */
150 ap_make_message(tempfp, target_room, author, subject);
152 /* Copy it to a new temp file in the spool directory */
155 spoolfp = fopen(tempspool, "wb");
156 if (spoolfp == NULL) {
157 perror("cannot open spool file");
160 while (ch = getc(tempfp), (ch >= 0)) {