1: #include "parms.h"
   2: #include "structs.h"
   3: #include <sys/types.h>
   4: #include <sys/stat.h>
   5: 
   6: #ifdef  RCSIDENT
   7: static char rcsid[] = "$Header: gtext.c,v 1.8 87/07/01 13:47:24 paul Exp $";
   8: #endif	RCSIDENT
   9: 
  10: /*
  11:  *	get the text for a note/response
  12:  *
  13:  *	Calls unix editor with a unique file name
  14:  *	Also makes sure the returned text is of
  15:  *	appropriate size
  16:  *
  17:  *	Ray Essick 10/23/80
  18:  *	Modified : rbk	10/26/80
  19:  *	modified again:	rbe 12 nov 81	fix to version 7 and general shtuff
  20:  *	modified a third time to add insert-text for user
  21:  *		Ray Essick	December 1981
  22:  *	modified to add non-portable way of appending a signature file.
  23:  *		Rich $alz	July, 1985
  24:  *	did signatures the "right" way (better, at least) - LOCAL flag
  25:  *		Rich $alz	August, 1985
  26:  */
  27: 
  28: extern char hissig[];
  29: long    gettext (io, where, preface, editflag)
  30: struct io_f *io;
  31: struct daddr_f *where;                  /* where we left it */
  32: FILE * preface;                     /* text included in buffer */
  33: int     editflag;                   /* EDIT if want editor, else NOEDIT */
  34: {
  35:     FILE * scr, *fopen ();
  36:     register int    c;
  37:     long    count;
  38:     char    fn[20];                 /* scratch file name */
  39:     struct stat    sbuf;
  40: 
  41:     sprintf (fn, "/tmp/nf%d", getpid ());
  42:     x ((scr = fopen (fn, "w")) == NULL, "gettext: create scratch");
  43:     x (chmod (fn, 0666) < 0, "gettext: chmod tmp");
  44:     if (preface != NULL)
  45:     {
  46:     while ((c = getc (preface)) != EOF)
  47:         putc (c, scr);              /* move included text */
  48:     }
  49:     fclose (scr);
  50:     fflush (stdout);                    /* clean it out */
  51: 
  52:     if (editflag == EDIT)
  53:     {
  54: #ifndef FASTFORK
  55:     {
  56:         char    cmd[CMDLEN];            /* build editor call */
  57:         sprintf (cmd, "%s %s", hised, fn);
  58:         dounix (cmd, 1, 1);             /* get the text */
  59:     }
  60: #else
  61:     {
  62:         if (index (hised, ' ') != (char *) NULL)    /* use shell */
  63:         {
  64:         char    cmd[CMDLEN];
  65:         sprintf (cmd, "%s %s", hised, fn);
  66:         dounix (1, 1, DFLTSH, "-c", cmd, 0, 0);
  67:         }
  68:         else
  69:         {
  70:         dounix (1, 1, hised, fn, 0, 0, 0);  /* call his editor */
  71:         }
  72:     }
  73: #endif
  74:     }                           /* end of editflag test */
  75: 
  76:     if ((scr = fopen (fn, "r")) == NULL)        /* no text to read */
  77:     {
  78:     unlink (fn);                    /* might just be protections */
  79:     return ((long) 0);
  80:     }
  81: 
  82:     (void) fstat (fileno (scr), &sbuf);
  83:     if (sbuf.st_size > (off_t) 0 && hissig[0]
  84:      && io -> descr.d_stat & NETWRKD && !(io -> descr.d_stat & LOCAL))
  85:     {
  86:     c = askyn ("Add signature (y/n): ");
  87:     printf ("\r                      \r");
  88:     if (c == 'y')
  89:     {
  90:         FILE * siggy;
  91: 
  92:         if ((siggy = fopen (hissig, "r")) == NULL)
  93:         printf ("Can't find %s", hissig);
  94:         else
  95:         {
  96:         /* Flop to append mode, append, flip back to read */
  97:         freopen (fn, "a", scr);
  98:         while ((c = getc (siggy)) != EOF)
  99:             putc (c, scr);
 100:         fclose (siggy);
 101:         freopen (fn, "r", scr);
 102:         }
 103:     }
 104:     }
 105: 
 106:     count = pagein (io, scr, where);            /* move text in */
 107:     fclose (scr);                   /* close the scratch file and */
 108:     x (unlink (fn) < 0, "gettext: unlink");     /* unlink it */
 109:     return ((long) count);              /* chars moved */
 110: }

Defined functions

Defined variables

rcsid defined in line 7; never used
Last modified: 1987-07-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2539
Valid CSS Valid XHTML 1.0 Strict