Annotation of GNUtools/emacs/etc/cvtmail.c, revision 1.1

1.1     ! root        1: /* Copyright (C) 1985 Free Software Foundation
        !             2: 
        !             3: This file is part of GNU Emacs.
        !             4: 
        !             5: GNU Emacs is free software; you can redistribute it and/or modify
        !             6: it under the terms of the GNU General Public License as published by
        !             7: the Free Software Foundation; either version 1, or (at your option)
        !             8: any later version.
        !             9: 
        !            10: GNU Emacs is distributed in the hope that it will be useful,
        !            11: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            13: GNU General Public License for more details.
        !            14: 
        !            15: You should have received a copy of the GNU General Public License
        !            16: along with GNU Emacs; see the file COPYING.  If not, write to
        !            17: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
        !            18: 
        !            19: /* cvtmail:
        !            20:  * Program to convert oldstyle goslings emacs mail directories into
        !            21:  * gnu-rmail format.  Program expects a directory called Messages to
        !            22:  * exist in your home directory, containing individual mail messages in
        !            23:  * separate files in the standard gosling emacs mail reader format.
        !            24:  *
        !            25:  * Program takes one argument: an output file.  THis file will contain
        !            26:  * all the messages in Messages directory, in berkeley mail format.
        !            27:  * If no output file is mentioned, messages are put in ~/OMAIL.
        !            28:  *
        !            29:  * In order to get rmail to read the messages, the resulting file must
        !            30:  * be mv'ed to ~/mbox, and then have rmail invoked on them.
        !            31:  * 
        !            32:  * Author: Larry Kolodney, 1985
        !            33: 
        !            34:  * RMS, 2 Sept 85: Removed fix maximums on file name sizes.
        !            35:  */
        !            36: 
        !            37: 
        !            38: #include <stdio.h>
        !            39: 
        !            40: 
        !            41: main (argc, argv)
        !            42:      int argc;
        !            43:      char *argv[];
        !            44: {
        !            45:   char *hd;
        !            46:   char *md;
        !            47:   char *mdd;
        !            48:   char *mfile;
        !            49:   char *cf;
        !            50:   int cflen;
        !            51:   FILE *mddf;
        !            52:   FILE *mfilef;
        !            53:   FILE *cff;
        !            54:   char pre[10], post[100];
        !            55:   char name[14];
        !            56:   int c;
        !            57: 
        !            58:   hd = (char *) getenv ("HOME");
        !            59: 
        !            60:   md = (char *) xmalloc (strlen (hd) + 10);
        !            61:   strcpy (md, hd);
        !            62:   strcat (md, "/Messages");
        !            63: 
        !            64:   mdd = (char *) xmalloc (strlen (md) + 11);
        !            65:   strcpy (mdd, md);
        !            66:   strcat (mdd, "/Directory");
        !            67: 
        !            68:   cflen = 100;
        !            69:   cf = (char *) xmalloc (cflen);
        !            70: 
        !            71:   mddf = fopen (mdd, "r");
        !            72:   if (argc > 1)
        !            73:     mfilef = fopen (argv[1], "w");
        !            74:   else
        !            75:     {
        !            76:       mfile = (char *) xmalloc (strlen (hd) + 7);
        !            77:       strcpy (mfile, hd);
        !            78:       strcat (mfile, "/OMAIL");
        !            79:       mfilef = fopen (mfile, "w");
        !            80:     }
        !            81:   skip_to_lf (mddf);
        !            82:   while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF)
        !            83:     {
        !            84:       if (cflen < strlen (md) + strlen (name) + 2)
        !            85:        {
        !            86:          cflen = strlen (md) + strlen (name) + 2;
        !            87:          cf = (char *) xrealloc (cf, cflen);
        !            88:        }
        !            89:       strcpy (cf, md);
        !            90:       strcat (cf,"/");
        !            91:       strcat (cf, name);
        !            92:       cff = fopen (cf, "r");
        !            93:       while ((c = getc(cff)) != EOF)
        !            94:        putc (c, mfilef);
        !            95:       putc ('\n', mfilef);
        !            96:       skip_to_lf (mddf);
        !            97:      fclose (cff);
        !            98:     }
        !            99:   fclose (mddf);
        !           100:   fclose (mfilef);    
        !           101:   return 0;
        !           102: }
        !           103: 
        !           104: skip_to_lf (stream)
        !           105:      FILE *stream;
        !           106: {
        !           107:   register int c;
        !           108:   while ((c = getc(stream)) != '\n')
        !           109:     ;
        !           110: }
        !           111: 
        !           112: int
        !           113: xmalloc (size)
        !           114:      int size;
        !           115: {
        !           116:   int result = malloc (size);
        !           117:   if (!result)
        !           118:     fatal ("virtual memory exhausted", 0);
        !           119:   return result;
        !           120: }
        !           121: 
        !           122: int
        !           123: xrealloc (ptr, size)
        !           124:      char *ptr;
        !           125:      int size;
        !           126: {
        !           127:   int result = realloc (ptr, size);
        !           128:   if (!result)
        !           129:     fatal ("virtual memory exhausted");
        !           130:   return result;
        !           131: }
        !           132: 
        !           133: /* Print error message and exit.  */
        !           134: 
        !           135: fatal (s1, s2)
        !           136:      char *s1, *s2;
        !           137: {
        !           138:   error (s1, s2);
        !           139:   exit (1);
        !           140: }
        !           141: 
        !           142: error (s1, s2)
        !           143:      char *s1, *s2;
        !           144: {
        !           145:   printf ("cvtmail: ");
        !           146:   printf (s1, s2);
        !           147:   printf ("\n");
        !           148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.