1: #ifndef lint
   2: static char sccsid[] = "@(#)imsg.c	5.3 (Berkeley) 1/6/86";
   3: #endif
   4: 
   5: #include "uucp.h"
   6: #include <ctype.h>
   7: 
   8: char Msync[2] = "\020";
   9: 
  10: /* to talk to both eunice and x.25 without also screwing up tcp/ip
  11:  * we must adaptively  choose what character to end the msg with
  12:  *
  13:  * The idea is that initially we send ....\000\n
  14:  * Then, after they have sent us a message, we use the first character
  15:  * they send.
  16:  */
  17: 
  18: int seenend = 0;
  19: char Mend = '\0';
  20: 
  21: /*
  22:  *	this is the initial read message routine -
  23:  *	used before a protocol is agreed upon.
  24:  *
  25:  *	return codes:
  26:  *		FAIL - no more messages
  27:  *		SUCCESS - message returned
  28:  */
  29: 
  30: imsg(amsg, fn)
  31: char *amsg;
  32: register int fn;
  33: {
  34:     register char *msg = amsg;
  35:     int foundsync = FAIL;
  36:     char c;
  37: 
  38:     DEBUG(5, "imsg looking for SYNC<", CNULL);
  39:     for (;;) {
  40:         if (read(fn, &c, 1) != 1)
  41:             return FAIL;
  42:         c &= 0177;
  43:         if (c == '\n' || c == '\r')
  44:             DEBUG(5, "%c", c);
  45:         else
  46:             DEBUG(5, (isprint(c) || isspace(c)) ? "%c" : "\\%o",
  47:                 c & 0377);
  48:         if (c == Msync[0]) {
  49:             DEBUG(5, ">\nimsg input<", CNULL);
  50:             msg = amsg;
  51:             foundsync = SUCCESS;
  52:             continue;
  53:         } else if (foundsync != SUCCESS)
  54:                 continue;
  55:         if (c == '\n' || c == '\0') {
  56:             if (!seenend) {
  57:                 Mend = c;
  58:                 seenend++;
  59:                 DEBUG(9, "\nUsing \\%o as End of message char\n", Mend);
  60:             }
  61:             break;
  62:         }
  63:         *msg++ = c;
  64:         fflush(stderr);
  65:     }
  66:     *msg = '\0';
  67:     DEBUG(5, ">got %d characters\n", strlen(amsg));
  68:     return foundsync;
  69: }
  70: 
  71: 
  72: /*
  73:  *	this is the initial write message routine -
  74:  *	used before a protocol is agreed upon.
  75:  *
  76:  *	return code:  always 0
  77:  */
  78: 
  79: omsg(type, msg, fn)
  80: register char *msg;
  81: char type;
  82: int fn;
  83: {
  84:     char buf[MAXFULLNAME];
  85:     register char *c;
  86: 
  87:     c = buf;
  88:     *c = '\0';  /* avoid pdp 11/23,40 auto-incr stack trap bug */
  89:     *c++ = Msync[0];
  90:     *c++ = type;
  91:     while (*msg)
  92:         *c++ = *msg++;
  93:     *c++ = '\0';
  94:     DEBUG(5, "omsg <%s>\n", buf);
  95:     if (seenend)
  96:         c[-1] = Mend;
  97:     else
  98:         *c++ = '\n';
  99:     write(fn, buf, (int)(c - buf));
 100:     return 0;
 101: }

Defined functions

imsg defined in line 30; used 7 times
omsg defined in line 79; used 16 times

Defined variables

Mend defined in line 19; used 3 times
Msync defined in line 8; used 2 times
sccsid defined in line 2; never used
seenend defined in line 18; used 3 times
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 667
Valid CSS Valid XHTML 1.0 Strict