home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / misc / PGPAmi26ui.lha / PGPAmiga / contrib / PGPMore / source / PGPMore.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-24  |  3.9 KB  |  105 lines

  1. /*
  2.  *      $Filename: PGPMore.c $
  3.  *      $Revision: 1.3 $
  4.  *      $Date: 1994/03/11 13:10:37 $
  5.  *
  6.  *      Copyright (C) 1993 by Peter Simons <simons@peti.GUN.de>
  7.  *
  8.  *      This program is free software; you can redistribute it and/or
  9.  *      modify it under the terms of the GNU General Public License as
  10.  *      published by the Free Software Foundation; either version 2 of
  11.  *      the License, or (at your option) any later version.
  12.  *
  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 GNU
  16.  *      General Public License for more details.
  17.  *
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  *
  23.  *      $Id: PGPMore.c,v 1.3 1994/03/11 13:10:37 simons Exp simons $
  24.  *
  25.  */
  26.  
  27. /**************************** includes ********************/
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <dos/dos.h>
  31. #include <dos/dostags.h>
  32. #include <proto/dos.h>
  33. #include <proto/exec.h>
  34.  
  35. #include "PGPMore_rev.h"
  36.  
  37. /**************************** prototypes ******************/
  38.  
  39. /**************************** defines, macros *************/
  40. #define LINEBUFSIZE 4096
  41. #define BEGIN     "-----BEGIN PGP MESSAGE----"
  42. #define END       "-----END PGP MESSAGE----"
  43. #define BEGINSIG  "-----BEGIN PGP SIGNED MESSAGE----"
  44. #define ENDSIG    "-----END PGP SIGNATURE----"
  45. #define MARKBEGIN "======== BEGIN OF PGP BLOCK ========\n"
  46. #define MARKEND   "======== END OF PGP BLOCK ========\n"
  47.  
  48. /**************************** global variables ************/
  49. static const char __RCSId[] = "$Id: PGPMore.c,v 1.3 1994/03/11 13:10:37 simons Exp simons $";
  50. static const char __OSVer[] = VERSTAG;
  51.  
  52. /**************************** program *********************/
  53. int main(int argc, char **argv)
  54. {
  55.         BPTR pipe, input = Input(), output = Output();
  56.         STRPTR linebuffer, pipename, cmdbuffer;
  57.         LONG rc = 0;
  58.  
  59.         if (argc != 1) {
  60.                 Printf(VERS " -- written by Peter Simons <simons@peti.GUN.de>\n");
  61.                 Printf("Usage: %s <[infile] >[outfile]\n", argv[0]);
  62.                 return 0;
  63.         }
  64.  
  65.         if (!(linebuffer = AllocVec(LINEBUFSIZE+(512*2), 0L))) {
  66.                 Printf("Couldn't allocate my buffers!\n");
  67.                 return 20;
  68.         }
  69.         pipename = linebuffer+LINEBUFSIZE;
  70.         cmdbuffer = pipename+512;
  71.         sprintf(pipename, "T:PGPMore.%ld", FindTask(NULL));
  72.         sprintf(cmdbuffer, "PGP <%s -f", pipename);
  73.  
  74.         Flush(input); Flush(output);    /* initialize stdio for buffered access */
  75.  
  76.         while (!rc && FGets(input, linebuffer, LINEBUFSIZE-1)) {
  77.                 if (!strncmp(linebuffer, BEGIN, strlen(BEGIN)) || !strncmp(linebuffer, BEGINSIG, strlen(BEGINSIG)) ) {
  78.                         FPuts(output, MARKBEGIN);
  79.                         if (pipe = Open(pipename, MODE_NEWFILE)) {
  80.                                 FPuts(pipe, linebuffer);
  81.                                 while (FGets(input, linebuffer, LINEBUFSIZE-1)) {
  82.                                         FPuts(pipe, linebuffer);
  83.                                         if (!strncmp(linebuffer, END, strlen(END)) || !strncmp(linebuffer, ENDSIG, strlen(ENDSIG)) )
  84.                                                 break;
  85.                                 }
  86.                                 Close(pipe);
  87.                                 Flush(output);
  88.                                 System(cmdbuffer, NULL);
  89.                                 Flush(output);
  90.                                 FPuts(output, MARKEND);
  91.                         }
  92.                         else
  93.                                 FPuts(output, "Can't open temporary file!\n");
  94.                 }
  95.                 else
  96.                         FPuts(output, linebuffer);
  97.         }
  98.  
  99.         DeleteFile(pipename);
  100.         FreeVec(linebuffer);
  101.  
  102.         return rc;
  103. }
  104.  
  105.