projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added test-slocal.
[mmh]
/
uip
/
mhbuild.c
diff --git
a/uip/mhbuild.c
b/uip/mhbuild.c
index
bacec10
..
e8e7423
100644
(file)
--- a/
uip/mhbuild.c
+++ b/
uip/mhbuild.c
@@
-2,7
+2,9
@@
/*
* mhbuild.c -- expand/translate MIME composition files
*
/*
* mhbuild.c -- expand/translate MIME composition files
*
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
*/
#include <h/mh.h>
*/
#include <h/mh.h>
@@
-11,63
+13,65
@@
#include <h/md5.h>
#include <errno.h>
#include <signal.h>
#include <h/md5.h>
#include <errno.h>
#include <signal.h>
-#include <zotnet/mts/mts.h>
-#include <zotnet/tws/tws.h>
+#include <h/mts.h>
+#include <h/tws.h>
#include <h/mime.h>
#include <h/mhparse.h>
#include <h/mhcachesbr.h>
#include <h/mime.h>
#include <h/mhparse.h>
#include <h/mhcachesbr.h>
-
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
+#include <h/utils.h>
static struct swit switches[] = {
#define CHECKSW 0
{ "check", 0 },
#define NCHECKSW 1
{ "nocheck", 0 },
static struct swit switches[] = {
#define CHECKSW 0
{ "check", 0 },
#define NCHECKSW 1
{ "nocheck", 0 },
-#define EBCDICSW 2
+#define DIRECTIVES 2
+ { "directives", 0 },
+#define NDIRECTIVES 3
+ { "nodirectives", 0 },
+#define EBCDICSW 4
{ "ebcdicsafe", 0 },
{ "ebcdicsafe", 0 },
-#define NEBCDICSW 3
+#define NEBCDICSW 5
{ "noebcdicsafe", 0 },
{ "noebcdicsafe", 0 },
-#define HEADSW 4
+#define HEADSW 6
{ "headers", 0 },
{ "headers", 0 },
-#define NHEADSW 5
+#define NHEADSW 7
{ "noheaders", 0 },
{ "noheaders", 0 },
-#define LISTSW 6
+#define LISTSW 8
{ "list", 0 },
{ "list", 0 },
-#define NLISTSW 7
+#define NLISTSW 9
{ "nolist", 0 },
{ "nolist", 0 },
-#define SIZESW 8
+#define SIZESW 10
{ "realsize", 0 },
{ "realsize", 0 },
-#define NSIZESW 9
+#define NSIZESW 11
{ "norealsize", 0 },
{ "norealsize", 0 },
-#define RFC934SW 10
+#define RFC934SW 12
{ "rfc934mode", 0 },
{ "rfc934mode", 0 },
-#define NRFC934SW 11
+#define NRFC934SW 13
{ "norfc934mode", 0 },
{ "norfc934mode", 0 },
-#define VERBSW 12
+#define VERBSW 14
{ "verbose", 0 },
{ "verbose", 0 },
-#define NVERBSW 13
+#define NVERBSW 15
{ "noverbose", 0 },
{ "noverbose", 0 },
-#define RCACHESW 14
+#define RCACHESW 16
{ "rcache policy", 0 },
{ "rcache policy", 0 },
-#define WCACHESW 15
+#define WCACHESW 17
{ "wcache policy", 0 },
{ "wcache policy", 0 },
-#define VERSIONSW 16
+#define CONTENTIDSW 18
+ { "contentid", 0 },
+#define NCONTENTIDSW 19
+ { "nocontentid", 0 },
+#define VERSIONSW 20
{ "version", 0 },
{ "version", 0 },
-#define HELPSW 17
- { "help", 4 },
-#define DEBUGSW 18
+#define HELPSW 21
+ { "help", 0 },
+#define DEBUGSW 22
{ "debug", -5 },
{ NULL, 0 }
};
{ "debug", -5 },
{ NULL, 0 }
};
-extern int errno;
-
/* mhbuildsbr.c */
/* mhbuildsbr.c */
-extern int checksw;
extern char *tmp; /* directory to place temp files */
/* mhcachesbr.c */
extern char *tmp; /* directory to place temp files */
/* mhcachesbr.c */
@@
-82,6
+86,7
@@
int verbosw = 0;
int ebcdicsw = 0;
int listsw = 0;
int rfc934sw = 0;
int ebcdicsw = 0;
int listsw = 0;
int rfc934sw = 0;
+int contentidsw = 1;
/*
* Temporary files
/*
* Temporary files
@@
-92,17
+97,16
@@
static int unlink_infile = 0;
static char outfile[BUFSIZ];
static int unlink_outfile = 0;
static char outfile[BUFSIZ];
static int unlink_outfile = 0;
+static void unlink_done (int) NORETURN;
/* mhbuildsbr.c */
/* mhbuildsbr.c */
-CT build_mime (char *);
+CT build_mime (char *, int);
int output_message (CT, char *);
int output_message (CT, char *);
+int output_message_fp (CT, FILE *, char*);
/* mhlistsbr.c */
int list_all_messages (CT *, int, int, int, int);
/* mhlistsbr.c */
int list_all_messages (CT *, int, int, int, int);
-/* mhmisc.c */
-void set_endian (void);
-
/* mhfree.c */
void free_content (CT);
/* mhfree.c */
void free_content (CT);
@@
-110,13
+114,16
@@
void free_content (CT);
int
main (int argc, char **argv)
{
int
main (int argc, char **argv)
{
- int sizesw = 1, headsw = 1;
+ int sizesw = 1, headsw = 1, directives = 1;
int *icachesw;
char *cp, buf[BUFSIZ];
char buffer[BUFSIZ], *compfile = NULL;
char **argp, **arguments;
CT ct, cts[2];
int *icachesw;
char *cp, buf[BUFSIZ];
char buffer[BUFSIZ], *compfile = NULL;
char **argp, **arguments;
CT ct, cts[2];
- FILE *fp;
+ FILE *fp = NULL;
+ FILE *fp_out = NULL;
+
+ done=unlink_done;
#ifdef LOCALE
setlocale(LC_ALL, "");
#ifdef LOCALE
setlocale(LC_ALL, "");
@@
-150,10
+157,10
@@
main (int argc, char **argv)
case HELPSW:
snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
print_help (buf, switches, 1);
case HELPSW:
snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
print_help (buf, switches, 1);
- done (1);
+ done (0);
case VERSIONSW:
print_version(invo_name);
case VERSIONSW:
print_version(invo_name);
- done (1);
+ done (0);
case RCACHESW:
icachesw = &rcachesw;
case RCACHESW:
icachesw = &rcachesw;
@@
-195,6
+202,13
@@
main (int argc, char **argv)
headsw = 0;
continue;
headsw = 0;
continue;
+ case DIRECTIVES:
+ directives = 1;
+ continue;
+ case NDIRECTIVES:
+ directives = 0;
+ continue;
+
case LISTSW:
listsw++;
continue;
case LISTSW:
listsw++;
continue;
@@
-216,6
+230,13
@@
main (int argc, char **argv)
sizesw = 0;
continue;
sizesw = 0;
continue;
+ case CONTENTIDSW:
+ contentidsw = 1;
+ continue;
+ case NCONTENTIDSW:
+ contentidsw = 0;
+ continue;
+
case VERBSW:
verbosw++;
continue;
case VERBSW:
verbosw++;
continue;
@@
-233,11
+254,6
@@
main (int argc, char **argv)
compfile = cp;
}
compfile = cp;
}
- set_endian ();
-
- if ((cp = getenv ("MM_NOASK")) && !strcmp (cp, "1"))
- listsw = 0;
-
/*
* Check if we've specified an additional profile
*/
/*
* Check if we've specified an additional profile
*/
@@
-288,27
+304,25
@@
main (int argc, char **argv)
* Process the composition file from standard input.
*/
if (compfile[0] == '-' && compfile[1] == '\0') {
* Process the composition file from standard input.
*/
if (compfile[0] == '-' && compfile[1] == '\0') {
-
/* copy standard input to temporary file */
/* copy standard input to temporary file */
- strncpy (infile, m_scratch ("", invo_name), sizeof(infile));
- if ((fp = fopen (infile, "w")) == NULL)
- adios (infile, "unable to open");
+ strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile));
while (fgets (buffer, BUFSIZ, stdin))
fputs (buffer, fp);
fclose (fp);
unlink_infile = 1;
/* build the content structures for MIME message */
while (fgets (buffer, BUFSIZ, stdin))
fputs (buffer, fp);
fclose (fp);
unlink_infile = 1;
/* build the content structures for MIME message */
- ct = build_mime (infile);
+ ct = build_mime (infile, directives);
cts[0] = ct;
cts[1] = NULL;
/* output MIME message to this temporary file */
cts[0] = ct;
cts[1] = NULL;
/* output MIME message to this temporary file */
- strncpy (outfile, m_scratch ("", invo_name), sizeof(outfile));
+ strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile));
unlink_outfile = 1;
/* output the message */
unlink_outfile = 1;
/* output the message */
- output_message (ct, outfile);
+ output_message_fp (ct, fp_out, outfile);
+ fclose(fp_out);
/* output the temp file to standard output */
if ((fp = fopen (outfile, "r")) == NULL)
/* output the temp file to standard output */
if ((fp = fopen (outfile, "r")) == NULL)
@@
-332,16
+346,18
@@
main (int argc, char **argv)
*/
/* build the content structures for MIME message */
*/
/* build the content structures for MIME message */
- ct = build_mime (compfile);
+ ct = build_mime (compfile, directives);
cts[0] = ct;
cts[1] = NULL;
/* output MIME message to this temporary file */
cts[0] = ct;
cts[1] = NULL;
/* output MIME message to this temporary file */
- strncpy (outfile, m_scratch (compfile, invo_name), sizeof(outfile));
+ strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
+ sizeof(outfile));
unlink_outfile = 1;
/* output the message */
unlink_outfile = 1;
/* output the message */
- output_message (ct, outfile);
+ output_message_fp (ct, fp_out, outfile);
+ fclose(fp_out);
/*
* List the message info
/*
* List the message info
@@
-351,12
+367,13
@@
main (int argc, char **argv)
/* Rename composition draft */
snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));
/* Rename composition draft */
snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));
- if (rename (compfile, buffer) == NOTOK)
- adios (compfile, "unable to rename %s to", buffer);
+ if (rename (compfile, buffer) == NOTOK) {
+ adios (compfile, "unable to rename comp draft %s to", buffer);
+ }
/* Rename output file to take its place */
if (rename (outfile, compfile) == NOTOK) {
/* Rename output file to take its place */
if (rename (outfile, compfile) == NOTOK) {
- advise (outfile, "unable to rename %s to", compfile);
+ advise (outfile, "unable to rename output %s to", compfile);
rename (buffer, compfile);
done (1);
}
rename (buffer, compfile);
done (1);
}
@@
-364,12
+381,12
@@
main (int argc, char **argv)
free_content (ct);
done (0);
free_content (ct);
done (0);
- /* NOT REACHED */
+ return 1;
}
}
-void
-done (int status)
+static void
+unlink_done (int status)
{
/*
* Check if we need to remove stray
{
/*
* Check if we need to remove stray