+
+/*
+ * Return "simple" name from a file name,
+ * strip leading directories.
+ */
+char *
+sname(s)
+ register char *s;
+{
+ register char *p = s;
+
+ while (*s)
+ if (*s++ == '/')
+ p = s;
+ return (p);
+}
+
+extern char chartab[];
+static char partab[0200];
+
+/*
+ * do a write to the remote machine with the correct parity
+ * we are doing 8 bit wide output, so we just generate a character
+ * with the right parity and output it.
+ */
+pwrite(fd, buf, n)
+ int fd;
+ char *buf;
+ register int n;
+{
+ register int i;
+ register char *bp = buf;
+
+ for (i = 0, bp = buf; i < n; i++, bp++) {
+ *bp = partab[(*bp) & 0177];
+ }
+ write(fd, buf, n);
+}
+
+/*
+ * build a parity table with the right high-order bit
+ * copy an even-parity table and doctor it
+ */
+setparity()
+{
+ int i;
+ char *parity;
+
+ if (value(PARITY) == NOSTR)
+ value(PARITY) = "even";
+
+ parity = value(PARITY);
+
+ for (i = 0; i < 0200; i++)
+ partab[i] = chartab[i];
+
+ if (equal(parity, "odd")) {
+ for (i = 0; i < 0200; i++)
+ partab[i] ^= 0200; /* reverse bit 7 */
+ }
+ else if (equal(parity, "none") || equal(parity, "zero")) {
+ for (i = 0; i < 0200; i++)
+ partab[i] &= ~0200; /* turn off bit 7 */
+ }
+ else if (equal(parity, "one")) {
+ for (i = 0; i < 0200; i++)
+ partab[i] |= 0200; /* turn on bit 7 */
+ }
+ else if (equal(parity, "even")) {
+ /* table is already even parity */
+ }
+ else {
+ fprintf(stderr, "parity value %s unknown\n", PA);
+ fflush(stderr);
+ }
+}