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
23 #include "ctdl_module.h"
29 #if TIME_WITH_SYS_TIME
30 # include <sys/time.h>
34 # include <sys/time.h>
44 #include "citadel_dirs.h"
53 * Simplified function to generate a message in our format
55 static void ap_make_message(FILE *fp, char *target_room, char *author, char *subject)
64 fprintf(fp, "Proom_aide");
66 fprintf(fp, "T%ld", (long)now);
68 fprintf(fp, "A%s", author);
70 fprintf(fp, "O%s", target_room);
72 if (strlen(subject) > 0) {
73 fprintf(fp, "U%s%c", subject, 0);
75 fprintf(fp, "N%s", NODENAME);
79 while (a = getc(stdin), a > 0) {
93 int main(int argc, char **argv)
96 char target_room[ROOMNAMELEN];
99 FILE *tempfp, *spoolfp;
105 char relhome[PATH_MAX]="";
106 char ctdldir[PATH_MAX]=CTDLDIR;
108 /* TODO: should we be able to calculate relative dirs? */
109 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
114 strcpy(target_room, "Aide");
115 strcpy(author, "Citadel");
117 for (i=1; i<argc; ++i) {
118 if (!strncasecmp(argv[i], "-r", 2)) {
119 strncpy(target_room, &argv[i][2], sizeof(target_room));
120 target_room[sizeof(target_room)-1] = 0;
122 else if (!strncasecmp(argv[i], "-a", 2)) {
123 strncpy(author, &argv[i][2], sizeof(author));
124 author[sizeof(author)-1] = 0;
126 else if (!strncasecmp(argv[i], "-s", 2)) {
127 strncpy(subject, &argv[i][2], sizeof(subject));
128 subject[sizeof(subject)-1] = 0;
130 fprintf(stderr, "%s: usage: %s "
131 "[-rTargetRoom] [-aAuthor] [-sSubject]\n",
137 snprintf(tempspool, sizeof tempspool,
144 tempfp = fopen(tempspool, "w+b");
146 if (tempfp == NULL) {
147 perror("cannot open temp file");
151 /* Generate a message from stdin */
152 ap_make_message(tempfp, target_room, author, subject);
154 /* Copy it to a new temp file in the spool directory */
157 spoolfp = fopen(tempspool, "wb");
158 if (spoolfp == NULL) {
159 perror("cannot open spool file");
162 while (ch = getc(tempfp), (ch >= 0)) {