home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume37 / ulayers / part03 < prev    next >
Encoding:
Text File  |  1993-05-29  |  28.5 KB  |  1,138 lines

  1. Newsgroups: comp.sources.misc
  2. From: david@bdt.com (David Beckemeyer)
  3. Subject: v37i091:  ulayers - Unix/X client to MacLayers, Part03/03
  4. Message-ID: <1993May29.181146.21923@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9f38e589243d64c0a181ea62267e4ea4
  6. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Sat, 29 May 1993 18:11:46 GMT
  9. Approved: kent@sparky.imd.sterling.com
  10.  
  11. Submitted-by: david@bdt.com (David Beckemeyer)
  12. Posting-number: Volume 37, Issue 91
  13. Archive-name: ulayers/part03
  14. Environment: UNIX, X11, PTY
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  conf.h dial.c makefile numbers.c reply.sh term.c
  21. #   ul_numbers ulayers.h ulterm.cmdtool ulterm.xterm
  22. # Wrapped by kent@sparky on Sat May 29 13:04:06 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 3 (of 3)."'
  26. if test -f 'conf.h' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'conf.h'\"
  28. else
  29.   echo shar: Extracting \"'conf.h'\" \(996 characters\)
  30.   sed "s/^X//" >'conf.h' <<'END_OF_FILE'
  31. X#ifndef CONF_INCLUDED
  32. X#define CONF_INCLUDED
  33. X
  34. X/* Are we running on a Sequent? (untested) */
  35. X#undef SEQUENT
  36. X
  37. X/* The path to the directory where UUCP locks are found */
  38. X#define LOCK_DIR        "/usr/spool/locks"
  39. X
  40. X/* Use the new SVR4 lock format? */
  41. X#undef  SVR4_LOCKS
  42. X/* Do the lock files use ASCII encoded PID's? */
  43. X#define ASCII_PID
  44. X/* Do wse have usleep()? */
  45. X#define USLEEP
  46. X
  47. X/* if no usleep(), shall we use gettimeofday()? */ 
  48. X#undef GETTIMEOFDAY
  49. X
  50. X/* Define this if you are only going to be using xterm windows */
  51. X#undef XTERM_TITLE
  52. X
  53. X/* The path to the Modem and Port databases */
  54. X#define LIB_DIR "/usr/local/lib/ulayers"
  55. X
  56. X/* Use V7 (BSD) style TTY ioctls? */
  57. X#undef V7TTY
  58. X
  59. X/* If you param.h doesn't have MAXPID, set the maximum legal PID */
  60. X/* #define MAX_PID 30000 */
  61. X
  62. X/* Dialing sequence meta-charcaters */
  63. X#define PAUSE_CHAR '~'        /* pause */
  64. X#define CR_CHAR '!'        /* return */
  65. X#define CTRL_CHAR '^'        /* control */
  66. X#define ESC_CHAR '|'        /* ESC */
  67. X#define BRK_CHAR '%'        /* BREAK */
  68. X
  69. X#endif
  70. END_OF_FILE
  71.   if test 996 -ne `wc -c <'conf.h'`; then
  72.     echo shar: \"'conf.h'\" unpacked with wrong size!
  73.   fi
  74.   # end of 'conf.h'
  75. fi
  76. if test -f 'dial.c' -a "${1}" != "-c" ; then 
  77.   echo shar: Will not clobber existing file \"'dial.c'\"
  78. else
  79.   echo shar: Extracting \"'dial.c'\" \(7260 characters\)
  80.   sed "s/^X//" >'dial.c' <<'END_OF_FILE'
  81. X/*
  82. X * The routines that dial the modem and listen for the return codes.
  83. X */
  84. X
  85. X#define HZ    60
  86. X
  87. X#include <stdio.h>
  88. X#include <sys/types.h>
  89. X#include <sys/times.h>
  90. X#include <sys/time.h>
  91. X#include "conf.h"
  92. X
  93. X#define ESC    '\033'
  94. X
  95. X#define MODEMS "ul_modems"
  96. X#define PORTS "ul_ports"
  97. X
  98. X/* C Libs */
  99. Xextern char *strtok();
  100. X
  101. X/* Default Dialer configuration (minimum Hayes) */
  102. Xstatic char *DefInitStr = "!~ATE1V1X1Q0S2=255S12=255!";
  103. Xstatic char *DefConnectStr = "CONNECT";
  104. Xstatic char *DefDialPrefix = "~~ATDT";
  105. Xstatic char *DefDialSuffix = "!";
  106. X
  107. Xstatic char *InitStr;
  108. Xstatic char *ConnectStr;
  109. Xstatic char *DialPrefix;
  110. Xstatic char *DialSuffix;
  111. X
  112. X/*
  113. X * Get the dial string ready, send it to the modem.  The parameter is not
  114. X * the actual entry number, it is an index into the queue.
  115. X */
  116. X
  117. Xvoid
  118. Xdial_it(port, modem, number)
  119. Xchar *port, *modem, *number;
  120. X{
  121. X    char s[100], *strcpy(), *strcat(), *strchr();
  122. X    void send_str();
  123. X
  124. X    /*
  125. X     * Setup for this port/modem
  126. X     */
  127. X    SetupPort(port, modem);
  128. X
  129. X    /*
  130. X     * Send the modem init string
  131. X     */
  132. X    send_str(InitStr, 1);
  133. X
  134. X    /*
  135. X     * Create the string to be sent to the modem.
  136. X     */
  137. X    s[0] = '\0';
  138. X    strcpy(s, DialPrefix);
  139. X    strcat(s, number);
  140. X    strcat(s, DialSuffix);
  141. X#ifdef DEBUG
  142. X    fprintf(stderr, "raw dial string: \"%s\"\n", s);
  143. X#endif /* DEBUG */
  144. X
  145. X
  146. X    send_str(s, 1);
  147. X    return;
  148. X}
  149. X
  150. X/*
  151. X * Send a string to the modem.  Performs all the character synonym
  152. X * translations.
  153. X */
  154. X
  155. Xvoid
  156. Xsend_str(s, slow)
  157. Xchar *s;
  158. Xint slow;
  159. X{
  160. X    int skip, has_pause;
  161. X    char *strchr();
  162. X    unsigned int sleep();
  163. X    static void do_pause();
  164. X                    /* empty string? */
  165. X    if (s == NULL || *s == '\0')
  166. X        return;
  167. X
  168. X                    /* contains a pause? */
  169. X    has_pause = 0;
  170. X    if (strchr(s, '~'))
  171. X        has_pause++;
  172. X
  173. X    /*
  174. X     * Change the character synonyms to their real values.  Writes
  175. X     * the characters to the modem.  To remove the special meaning
  176. X     * of one of the characters, prepend a "\" to it.
  177. X     */
  178. X    skip = 0;
  179. X    while (*s) {
  180. X                    /* send the literal character */
  181. X        if (skip) {
  182. X            skip = 0;
  183. X            tty_putc(*s);
  184. X            tty_flush();
  185. X            if (slow)
  186. X                do_pause();
  187. X#ifdef DEBUG
  188. X            fprintf(stderr, "send_str: \"%c\", %02x, %03o, %d\n", *s, *s, *s, *s);
  189. X#endif /* DEBUG */
  190. X            s++;
  191. X            continue;
  192. X        }
  193. X                    /* turn off the special meaning */
  194. X        if (*s == '\\') {
  195. X            skip++;
  196. X            s++;
  197. X            continue;
  198. X        }
  199. X                    /* pause synonym */
  200. X        if (*s == PAUSE_CHAR) {
  201. X            sleep(1);
  202. X            s++;
  203. X            continue;
  204. X        }
  205. X                    /* carriage return synonym */
  206. X        if (*s == CR_CHAR)
  207. X            *s = '\r';
  208. X                    /* 2 character control sequence */
  209. X        if (*s == CTRL_CHAR) {
  210. X            s++;
  211. X                    /* premature EOF? */
  212. X            if (*s == '\0')
  213. X                break;
  214. X                    /* upper and lower case */
  215. X            if (*s > '_')
  216. X                *s -= 96;
  217. X            else
  218. X                *s -= 64;
  219. X        }
  220. X                    /* escape synonym */
  221. X        if (*s == ESC_CHAR)
  222. X            *s = ESC;
  223. X                    /* modem break synonym */
  224. X        if (*s == BRK_CHAR) {
  225. X            tty_break();
  226. X            sleep(1);
  227. X            s++;
  228. X            continue;
  229. X        }
  230. X
  231. X        tty_putc(*s);
  232. X#ifdef DEBUG
  233. X        fprintf(stderr, "send_str: \"%c\", %02x, %03o, %d\n", *s, *s, *s, *s);
  234. X#endif /* DEBUG */
  235. X        /*
  236. X         * Because the pause char makes the timing critical, we
  237. X         * wait until the buffer is clear before we continue.
  238. X         */
  239. X        if (has_pause || slow)
  240. X            tty_flush();
  241. X        if (slow)
  242. X            do_pause();
  243. X        s++;
  244. X    }
  245. X    return;
  246. X}
  247. X
  248. X/*
  249. X * Read the result codes coming back from the modem.  Test for the 
  250. X * "connect" string.
  251. X */
  252. X
  253. Xint rc_index;
  254. X
  255. Xread_codes()
  256. X{
  257. X    int i;
  258. X    static int match();
  259. X    char c;
  260. X    static char rc_buf[512];
  261. X                    /* search for key words */
  262. X    for (; rc_index<511; rc_index++) {
  263. X        if ((i = getc_line(45)) <= 0) {
  264. X#ifdef DEBUG
  265. X            fprintf(stderr, "getc_line: returns error\n");
  266. X#endif
  267. X            break;
  268. X        }
  269. X        c = i & 0x7f;
  270. X#ifdef DEBUG
  271. X        fprintf(stderr, "read_codes: \"%c\", %02x, %03o, %d\n", c, c, c, c);
  272. X#endif /* DEBUG */
  273. X                    /* no NULLs please */
  274. X        if (c == '\0') {
  275. X            if (rc_index)
  276. X                rc_index--;
  277. X            continue;
  278. X        }
  279. X        rc_buf[rc_index] = c;
  280. X        rc_buf[rc_index+1] = '\0';
  281. X                    /* the connect strings */
  282. X        if (match(rc_buf, ConnectStr))
  283. X            return(0);
  284. X    }
  285. X                    /* ran out of buffer? */
  286. X    return(-1);
  287. X}
  288. X
  289. X/*
  290. X * Test for a match between two character strings.  A non-zero return code
  291. X * means that s2 was found at the end of s1.
  292. X */
  293. X
  294. Xstatic int
  295. Xmatch(s1, s2)
  296. Xchar *s1, *s2;
  297. X{
  298. X    register int i;
  299. X    int skip, diff;
  300. X    char new[40];
  301. X                    /* if no string to match */
  302. X    if (*s2 == '\0')
  303. X        return(0);
  304. X                    /* translate synonyms */
  305. X    i = 0;
  306. X    skip = 0;
  307. X    while (*s2) {
  308. X                    /* literal character */
  309. X        if (skip) {
  310. X            skip = 0;
  311. X            new[i++] = *s2;
  312. X            s2++;
  313. X            continue;
  314. X        }
  315. X                    /* turn off the special meaning */
  316. X        if (*s2 == '\\') {
  317. X            skip++;
  318. X            s2++;
  319. X            continue;
  320. X        }
  321. X                    /* carriage return synonym */
  322. X        if (*s2 == CR_CHAR)
  323. X            *s2 = '\r';
  324. X
  325. X                    /* 2 character control sequence */
  326. X        if (*s2 == CTRL_CHAR) {
  327. X            s2++;
  328. X            if (*s2 == '\0')
  329. X                break;
  330. X            if (*s2 > '_')
  331. X                *s2 -= 96;
  332. X            else
  333. X                *s2 -= 64;
  334. X        }
  335. X                    /* escape synonym */
  336. X        if (*s2 == ESC_CHAR)
  337. X            *s2 = ESC;
  338. X
  339. X        new[i++] = *s2;
  340. X        s2++;
  341. X    }
  342. X    new[i] = '\0';
  343. X
  344. X    diff = strlen(s1) - strlen(new);
  345. X                    /* is it possible? */
  346. X    if (diff < 0)
  347. X        return(0);
  348. X                    /* test it out */
  349. X    if (!strcmp(&s1[diff], new))
  350. X        return(1);
  351. X    return(0);
  352. X}
  353. X
  354. X/*
  355. X * Apparently some modems can't take input at the rated speed while
  356. X * in the command mode.  Therefore, a 0.10 sec pause a required between
  357. X * characters.
  358. X */
  359. X
  360. Xstatic void
  361. Xdo_pause()
  362. X{
  363. X#ifdef USLEEP
  364. X    usleep(100000);
  365. X#else /* USLEEP */
  366. X                /* Hey! I know these routines are a hack */
  367. X#ifdef GETTIMEOFDAY
  368. X    struct timeval tv;
  369. X    struct timezone tz;
  370. X    double t1;
  371. X
  372. X    gettimeofday(&tv, &tz);
  373. X    t1 = tv.tv_sec + (tv.tv_usec / 1000000.0);
  374. X    do
  375. X        gettimeofday(&tv, &tz);
  376. X    while ((tv.tv_sec + (tv.tv_usec / 1000000.0) - t1) < 0.1);
  377. X#else /* GETTIMEOFDAY */
  378. X    struct tms t;
  379. X    long t1;
  380. X
  381. X    t1 = times(&t);
  382. X    while ((times(&t) - t1) < HZ/10)
  383. X        ;
  384. X#endif /* GETTIMEOFDAY */
  385. X#endif /* USLEEP */
  386. X    return;
  387. X}
  388. X
  389. X
  390. Xstatic
  391. XSetupPort(port, modem)
  392. Xchar *port, *modem;
  393. X{
  394. X    char fname[512], line[512];
  395. X    FILE *fp;
  396. X    char *p;
  397. X    char modemname[64];
  398. X
  399. Xstatic char Init[64], Connect[64], Prefix[64], Suffix[64];
  400. X
  401. X    /* Assume defaults */
  402. X    InitStr = DefInitStr;
  403. X    ConnectStr = DefConnectStr;
  404. X    DialPrefix = DefDialPrefix;
  405. X    DialSuffix = DefDialSuffix;
  406. X
  407. X    /* see if explicit modem specified */
  408. X    if (!modem) {
  409. X        /* no modem specified, open ports database */
  410. X        sprintf(fname, "%s/%s", LIB_DIR, PORTS);
  411. X        fp = fopen(fname, "r");
  412. X        if (!fp)
  413. X            return;
  414. X        p = 0;
  415. X        while (fgets(line, 512, fp)) {
  416. X            if (line[0] == '#' || line[0] == '\n')
  417. X                continue;
  418. X            p = strtok(line, ":");
  419. X            if (!p)
  420. X                continue;
  421. X            if (strcmp(p, port) == 0) {
  422. X                p = strtok((char *)0, ":\n");
  423. X                if (p)
  424. X                    break;    /* Found a modem entry */
  425. X            }
  426. X            p = 0;
  427. X        }
  428. X        fclose(fp);
  429. X        /* not found */
  430. X        if (!p)
  431. X            return;
  432. X
  433. X        strcpy(modemname, p);
  434. X        modem = modemname;
  435. X
  436. X    }
  437. X    /* Open modems database */
  438. X    sprintf(fname, "%s/%s", LIB_DIR, MODEMS);
  439. X    fp = fopen(fname, "r");
  440. X    if (!fp)
  441. X        return;
  442. X    while (fgets(line, 512, fp)) {
  443. X        if (line[0] == '#' || line[0] == '\n')
  444. X            continue;
  445. X        p = strtok(line, ":");
  446. X        if (!p)
  447. X            continue;
  448. X        if (strcmp(modem, p) == 0) {
  449. X            /* Found the modem entry */
  450. X            p = strtok((char *)0, ":");
  451. X            if (!p)
  452. X                break;
  453. X            strcpy(Init, p);
  454. X            p = strtok((char *)0, ":");
  455. X            if (!p)
  456. X                break;
  457. X            strcpy(Prefix, p);
  458. X            p = strtok((char *)0, ":");
  459. X            if (!p)
  460. X                break;
  461. X            strcpy(Suffix, p);
  462. X            p = strtok((char *)0, ":\n");
  463. X            if (!p)
  464. X                break;
  465. X            strcpy(Connect, p);
  466. X            InitStr = Init;
  467. X            DialPrefix = Prefix;
  468. X            DialSuffix = Suffix;
  469. X            ConnectStr = Connect;
  470. X            break;
  471. X        }
  472. X    }
  473. X    fclose(fp);
  474. X}
  475. X
  476. X            
  477. END_OF_FILE
  478.   if test 7260 -ne `wc -c <'dial.c'`; then
  479.     echo shar: \"'dial.c'\" unpacked with wrong size!
  480.   fi
  481.   # end of 'dial.c'
  482. fi
  483. if test -f 'makefile' -a "${1}" != "-c" ; then 
  484.   echo shar: Will not clobber existing file \"'makefile'\"
  485. else
  486.   echo shar: Extracting \"'makefile'\" \(1609 characters\)
  487.   sed "s/^X//" >'makefile' <<'END_OF_FILE'
  488. X#                   Makefile for ulayers 0.1
  489. X
  490. XBIN    = /usr/local/bin
  491. XMANDIR = /usr/local/manl
  492. X
  493. XVERS   = 1.0
  494. XPGM    = ulayers
  495. XPGM2   = ulslave
  496. XPGM3   = ulterm
  497. XMS     = l
  498. X#
  499. X# CONFIGURATION
  500. X#
  501. X# Add a -DUSG if on System V to CFLAGS.
  502. X# See conf.h for other compile-time options.
  503. X#
  504. XCFLAGS = -O
  505. XCFILES = ulayers.c startup.c connect.c term.c dial.c numbers.c
  506. XOFILES = ulayers.o startup.o connect.o term.o dial.o numbers.o
  507. XDIST   = README ulayers.1 CHANGES $(CFILES) makefile ulayers.h conf.h \
  508. X     ulslave.c ulterm.xterm ulterm.cmdtool reply.sh \
  509. X     ul_ports ul_modems ul_numbers
  510. X
  511. Xall: $(PGM) $(PGM2) $(PGM3)
  512. X
  513. X$(PGM): $(OFILES)
  514. X    $(CC) $(CFLAGS) -o $(PGM) $(OFILES)
  515. X
  516. X$(OFILES): ulayers.h
  517. X
  518. X$(PGM2): ulslave.o
  519. X    $(CC) $(CFLAGS) -o $(PGM2) ulslave.o
  520. X
  521. X$(PGM3):
  522. X    @echo "You must copy either ulterm.xterm or ulterm.cmdtool"
  523. X    @echo "to 'ulterm' or write your own 'ulterm' script."
  524. X    @exit 1
  525. X
  526. Xinstallsetuid: $(PGM) $(PGM2) $(PGM3) $(PGM4)
  527. X    rm -f $(BIN)/$(PGM)
  528. X    install -c -s -o root -g daemon -m 4711 $(PGM) $(BIN)/$(PGM)
  529. X    install -c -s $(PGM2) $(BIN)/$(PGM2)
  530. X    install -c $(PGM3) $(BIN)/$(PGM3)
  531. X    @reply.sh
  532. X
  533. Xinstallnosetuid: $(PGM) $(PGM2) $(PGM3) $(PGM4)
  534. X    rm -f $(BIN)/$(PGM)
  535. X    install -c -s $(PGM) $(BIN)/$(PGM)
  536. X    install -c -s $(PGM2) $(BIN)/$(PGM2)
  537. X    install -c $(PGM3) $(BIN)/$(PGM3)
  538. X    @reply.sh
  539. X
  540. Xmanpage: ulayers.1
  541. X    rm -f $(MANDIR)/$(PGM).$(MS)
  542. X    cp ulayers.1 $(MANDIR)/$(PGM).$(MS)
  543. X    chmod 664 $(MANDIR)/$(PGM).$(MS)
  544. X
  545. Xclean:
  546. X    rm -f a.out core $(PGM) $(PGM2) *.o
  547. X
  548. Xtar:
  549. X    tar cvf ulayers.tar $(DIST)
  550. X
  551. Xshar:
  552. X    shar $(DIST) >ulayers.shar
  553. X
  554. Xnetshar:
  555. X    shar -F -a -n ulayers_$(VERS) -L 30 -o ulayers.shar $(DIST)
  556. X
  557. XDIST:
  558. X    echo $(DIST) >DIST
  559. END_OF_FILE
  560.   if test 1609 -ne `wc -c <'makefile'`; then
  561.     echo shar: \"'makefile'\" unpacked with wrong size!
  562.   fi
  563.   # end of 'makefile'
  564. fi
  565. if test -f 'numbers.c' -a "${1}" != "-c" ; then 
  566.   echo shar: Will not clobber existing file \"'numbers.c'\"
  567. else
  568.   echo shar: Extracting \"'numbers.c'\" \(1752 characters\)
  569.   sed "s/^X//" >'numbers.c' <<'END_OF_FILE'
  570. X#include <stdio.h>
  571. X#include "ulayers.h"
  572. X
  573. Xextern char *getenv(), *strtok(), *malloc();
  574. X
  575. X#define UL_NUMBERS ".ul_numbers"
  576. X/* #define UL_MODEMS ".ul_modems" */
  577. X
  578. Xstruct dial_entry {
  579. X    struct dial_entry *d_next;
  580. X    char    d_system[16];
  581. X    char    d_phone[16];
  582. X    char    d_baud[16];
  583. X    char    d_port[16];
  584. X};
  585. X
  586. Xstruct dial_entry *d_head, *d_tail;
  587. X
  588. XReadStartup()
  589. X{
  590. X    char fname[512];
  591. X    char *home;
  592. X
  593. X    home = getenv("HOME");
  594. X    if (!home)
  595. X        home = ".";
  596. X    sprintf(fname, "%s/%s", home, UL_NUMBERS);
  597. X    ReadNumbers(fname);
  598. X
  599. X#ifdef UL_MODEMS
  600. X    sprintf(fname, "%s/%s", home, UL_MODEMS);
  601. X    ReadModems(fname);
  602. X#endif
  603. X}
  604. X
  605. XReadNumbers(f)
  606. Xchar *f;
  607. X{
  608. X    FILE *fp;
  609. X    char line[512];
  610. X    char *sys, *num, *set, *port;
  611. X    struct dial_entry *d;
  612. X
  613. X    fp = fopen(f, "r");
  614. X    if (!fp)
  615. X        return;
  616. X    while (fgets(line, 512, fp)) {
  617. X        if (line[0] == '#')
  618. X            continue;
  619. X        sys = strtok(line, "\t ");
  620. X        if (!sys)
  621. X            continue;
  622. X        set = strtok((char *)0, "\t ");
  623. X        if (!set)
  624. X            continue;
  625. X        port = strtok((char *)0, "\t \n");
  626. X        if (!port)
  627. X            continue;
  628. X        num = strtok((char *)0, "\t \n");
  629. X        d = (struct dial_entry *)malloc(sizeof(struct dial_entry));
  630. X        if (!d)
  631. X            return;
  632. X
  633. X        strcpy(d->d_system, sys);
  634. X        if (num)
  635. X            strcpy(d->d_phone, num);
  636. X        else
  637. X            d->d_phone[0] = 0;
  638. X        strcpy(d->d_baud, set);
  639. X        strcpy(d->d_port, port);
  640. X        if (d_tail)
  641. X            d_tail->d_next = d;
  642. X        else
  643. X            d_head = d;
  644. X        d_tail = d;
  645. X        d->d_next = 0;
  646. X    }
  647. X    fclose(fp);
  648. X}
  649. X
  650. XGetNumber(s, flag)
  651. Xchar *s;
  652. Xint flag;
  653. X{
  654. X    struct dial_entry *d;
  655. Xstatic struct dial_entry *dot;
  656. X
  657. X    if (flag)
  658. X        d = d_head;
  659. X    else
  660. X        d = dot;
  661. X    while (d) {
  662. X        if (strcmp(d->d_system, s) == 0) {
  663. X            ServerPort = d->d_port;
  664. X            TtySpeed = d->d_baud;
  665. X            if (d->d_phone[0])
  666. X                ServerNumber = d->d_phone;
  667. X            else
  668. X                ServerNumber = 0;
  669. X            dot = d->d_next;
  670. X            return(0);
  671. X        }
  672. X        d = d->d_next;
  673. X    }
  674. X    dot = 0;
  675. X    return(-1);
  676. X}
  677. END_OF_FILE
  678.   if test 1752 -ne `wc -c <'numbers.c'`; then
  679.     echo shar: \"'numbers.c'\" unpacked with wrong size!
  680.   fi
  681.   # end of 'numbers.c'
  682. fi
  683. if test -f 'reply.sh' -a "${1}" != "-c" ; then 
  684.   echo shar: Will not clobber existing file \"'reply.sh'\"
  685. else
  686.   echo shar: Extracting \"'reply.sh'\" \(1151 characters\)
  687.   sed "s/^X//" >'reply.sh' <<'END_OF_FILE'
  688. Xecho
  689. Xecho "The author would like to receive a mail message reporting"
  690. Xecho "that you are using Ulayers."
  691. Xecho "Type "n" if you already sent or don't want to send such message."
  692. Xecho
  693. Xecho "Shall I send a mail to david@bdt.com ? "
  694. X
  695. Xset ans = "y"
  696. Xread ans
  697. X
  698. Xif test "$ans" != "n" -a "$ans" != "N" -a "$ans" != "no"
  699. Xthen
  700. X    echo
  701. X    echo "Sending a NewUser report to the author..."
  702. X    if [ -r /usr/ucb/mail ] ; then
  703. X        /usr/ucb/mail -s "ULAYERS NewUser" david@bdt.com << END
  704. XUlayers Version `./ulayers -v 2> /dev/null`
  705. X---------------------
  706. XPackage installed on `date 2> /dev/null`:
  707. X   User         - $USER / $LOGNAME / `logname 2> /dev/null`
  708. X   Architecture - `arch 2> /dev/null`
  709. X   Uname/UUname - `uname -a 2> /dev/null`
  710. XEND
  711. X    else
  712. X        mail david@bdt.com << END
  713. XUlayers Version `./ulayers -v 2>/dev/null`
  714. X---------------------
  715. XPackage installed on `date 2> /dev/null`:
  716. X    
  717. X   User         - $USER / $LOGNAME / `logname 2> /dev/null` 
  718. X   Architecture - `arch 2> /dev/null`
  719. X   Uname/UUname - `uname -a 2> /dev/null`
  720. XEND
  721. X    fi
  722. Xelse
  723. X    echo
  724. X    echo "No message was sent."
  725. X    echo "You won't automaticaly receive upgrades..."
  726. Xfi
  727. X
  728. Xecho
  729. END_OF_FILE
  730.   if test 1151 -ne `wc -c <'reply.sh'`; then
  731.     echo shar: \"'reply.sh'\" unpacked with wrong size!
  732.   fi
  733.   chmod +x 'reply.sh'
  734.   # end of 'reply.sh'
  735. fi
  736. if test -f 'term.c' -a "${1}" != "-c" ; then 
  737.   echo shar: Will not clobber existing file \"'term.c'\"
  738. else
  739.   echo shar: Extracting \"'term.c'\" \(5002 characters\)
  740.   sed "s/^X//" >'term.c' <<'END_OF_FILE'
  741. X/********                    term.c
  742. X*********
  743. X*********     This is a quick & dirty implementation of the
  744. X*********     MacLayers protocol client-side for Unix.  It
  745. X*********     Basically is an emulation of the MacLayers
  746. X*********     Macintosh application for Unix, except that
  747. X*********     Ulayers is a bare-bones program, a far cry
  748. X*********     from the polished and professional MacLayers.
  749. X*********
  750. X*********     The hacks to produce Ulayers were made by me,
  751. X*********     David Beckemeyer david@bdt.com.  Essentially
  752. X*********     the entire credit for this goes to the original
  753. X*********     authors however, and all the contributors
  754. X*********     copyright messages appear below.  On the
  755. X*********     the other hand, the "real" Maclayers authors
  756. X*********     are not to blame for the shoddy hacks I made
  757. X*********     to their code either, and so I'm putting my
  758. X*********     here because I'm sure they don't want their
  759. X*********     name associatyed with this mess!
  760. X*********
  761. X*********     Most of the code for Ulayers came straight from
  762. X*********     the Unix-side of the MacLayers implementation,
  763. X*********     the copyright messages to which follow:
  764. X*********
  765. X*********    Layers - MacLayers Multiwindow BSD Socket Driver
  766. X*********
  767. X*********          Dave Trissel oakhill!davet
  768. X*********
  769. X********* The sockets handling portion of this control module is based 
  770. X********* upon 'screen' by Oliver Laumann whose copyright remains below. 
  771. X********* The rest is
  772. X *
  773. X *             Copyright (C) 1989 by David W. Trissel
  774. X *
  775. X *              Not derived from licensed software.
  776. X *
  777. X * Permission is granted to freely use, copy, modify, and redistribute
  778. X * this software, provided that no attempt is made to gain profit from it,
  779. X * the author is not construed to be liable for any results of using the
  780. X * software, alterations are clearly marked as such, and this notice is
  781. X * not modified.
  782. X *
  783. X */
  784. X
  785. X
  786. X/* Copyright (c) 1987,1988 Oliver Laumann, Technical University of Berlin.
  787. X * Not derived from licensed software.
  788. X *
  789. X * Permission is granted to freely use, copy, modify, and redistribute
  790. X * this software, provided that no attempt is made to gain profit from it,
  791. X * the author is not construed to be liable for any results of using the
  792. X * software, alterations are clearly marked as such, and this notice is
  793. X * not modified.
  794. X *
  795. X *    Modified by Patrick Wolfe (pat@kai.com, kailand!pat)
  796. X *    Do whatever you want with (my modifications of) this program, but
  797. X *    don't claim you wrote them, don't try to make money from them, and
  798. X *    don't remove this notice.
  799. X */
  800. X#include <stdio.h>
  801. X#include <sgtty.h>
  802. X#include <signal.h>
  803. X#include <errno.h>
  804. X#include <ctype.h>
  805. X#include <pwd.h>
  806. X#include <nlist.h>
  807. X#include <fcntl.h>
  808. X#include <sys/types.h>
  809. X#include <sys/time.h>
  810. X#include <sys/file.h>
  811. X#include <sys/wait.h>
  812. X#include <sys/socket.h>
  813. X#include <utmp.h>
  814. X#ifndef USG
  815. X#include <sys/un.h>
  816. X#endif
  817. X#include <sys/stat.h>
  818. X#include <sys/dir.h>
  819. X#include <sys/ioctl.h>
  820. X
  821. X#include "ulayers.h"
  822. X
  823. Xextern int errno;
  824. X
  825. Xstatic char *TermArgs[4];
  826. X
  827. X#define ULTERM "ulterm"
  828. X
  829. XStartTerm(f, chan)
  830. Xint f, chan;
  831. X{
  832. X    int tf, lpid, rr, i;
  833. X    int DevTty;
  834. X    char buf[32], pidbuf[16], ascchan[4];
  835. X    char *ulterm, *getenv();
  836. X
  837. X    DO DEBUG("StartTerm() pty = %d, chan = %d\n", f, chan);
  838. X
  839. X    if ((DevTty = open ("/dev/tty", O_RDWR|O_NDELAY)) == -1)
  840. X                Msg (errno, "/dev/tty");
  841. X    ulterm = getenv("ULTERM");
  842. X    if (ulterm == 0)
  843. X        ulterm = ULTERM;
  844. X    switch ((lpid = fork())) {
  845. X    case -1:
  846. X        DO DEBUG("fork failed\n");
  847. X        return(-1);
  848. X        /* NOT REACHED */
  849. X    case 0:
  850. X        /* child */
  851. X        setuid(getuid());
  852. X        DO DEBUG("child %d running uid = %d\n", getpid(), getuid());
  853. X
  854. X#ifdef USG
  855. X    setpgrp();
  856. X#else
  857. X#ifdef TIOCNOTTY
  858. X        ioctl (DevTty, TIOCNOTTY, (char *)0);
  859. X#else
  860. X        setpgrp(0, 0);
  861. X#endif
  862. X#endif
  863. X    sprintf(ascchan, "%d", chan);
  864. X        DO DEBUG("executing: %s %s\n", ulterm, TtyName);
  865. X        TermArgs[0] = ulterm;
  866. X        TermArgs[1] = TtyName;
  867. X        TermArgs[2] = ascchan;
  868. X        TermArgs[3] = NULL;
  869. X        execvp(ulterm, TermArgs);
  870. X        perror("execvp failed");
  871. X        exit(1);
  872. X        break;
  873. X
  874. X    default:
  875. X        /* parent */
  876. X        signal(SIGALRM, SIG_IGN);
  877. X        /* wait for ACK from slave */
  878. X        tf = 0;
  879. X    i = 0;
  880. X    do {
  881. X            rr = read(f, buf, 16);
  882. X            if (rr > 0) {
  883. X        strncpy(pidbuf+i, buf, rr);
  884. X        i += rr;
  885. X        pidbuf[i] = 0;
  886. X        if (buf[rr-1] == 'T') {
  887. X                DO DEBUG("Slave reports '%s'\n", pidbuf);
  888. X            pidbuf[--i] = 0;
  889. X            return(atoi(pidbuf));
  890. X        }
  891. X        }
  892. X        else if (rr < 0) {
  893. X                DO DEBUG("read xterm startup error %d\n", errno);
  894. X#ifdef USG
  895. X                if (errno != EIO && errno != EAGAIN) {
  896. X#else
  897. X                if (errno != EIO && errno != EWOULDBLOCK) {
  898. X
  899. X#endif
  900. X                    alarm(0);
  901. X                    kill(lpid, SIGTERM);
  902. X                    return(-1);
  903. X                }
  904. X            }
  905. X            sleep(1);
  906. X        } while (++tf < 12);
  907. X        DO DEBUG("Slave TIMEOUT!\n");
  908. X    return(-1);
  909. X    }
  910. X    /* NOT REACHED */
  911. X}
  912. END_OF_FILE
  913.   if test 5002 -ne `wc -c <'term.c'`; then
  914.     echo shar: \"'term.c'\" unpacked with wrong size!
  915.   fi
  916.   # end of 'term.c'
  917. fi
  918. if test -f 'ul_numbers' -a "${1}" != "-c" ; then 
  919.   echo shar: Will not clobber existing file \"'ul_numbers'\"
  920. else
  921.   echo shar: Extracting \"'ul_numbers'\" \(358 characters\)
  922.   sed "s/^X//" >'ul_numbers' <<'END_OF_FILE'
  923. X#
  924. X# Phone number database for Ulayers
  925. X#
  926. X# This file should reside in your home directory and be called .ul_numbers
  927. X#
  928. X# Syntax:
  929. X#    system    baud    port    phone-number
  930. X#
  931. X# E.g.:
  932. X#    netcom 19200-N    /dev/cua1    865-9004
  933. Xnetcom    19200-N-8-1    /dev/cua1    865-9004
  934. Xwesco    19200-N-8-1    /dev/cua1    746-8783
  935. Xhoptoad    19200-N-8-1    /dev/cua0    14152215909
  936. Xhoney    19200-N-8-1    /dev/cua1    9306840
  937. END_OF_FILE
  938.   if test 358 -ne `wc -c <'ul_numbers'`; then
  939.     echo shar: \"'ul_numbers'\" unpacked with wrong size!
  940.   fi
  941.   # end of 'ul_numbers'
  942. fi
  943. if test -f 'ulayers.h' -a "${1}" != "-c" ; then 
  944.   echo shar: Will not clobber existing file \"'ulayers.h'\"
  945. else
  946.   echo shar: Extracting \"'ulayers.h'\" \(3765 characters\)
  947.   sed "s/^X//" >'ulayers.h' <<'END_OF_FILE'
  948. X/*
  949. X * Derived from Maclayers layers.h which is:
  950. X *
  951. X *            Copyright (C) 1989 by David W. Trissel 
  952. X *
  953. X *  Not derived from licensed software.
  954. X *
  955. X * Permission is granted to freely use, copy, modify, and redistribute
  956. X * this software, provided that no attempt is made to gain profit from it,
  957. X * the author is not construed to be liable for any results of using the
  958. X * software, alterations are clearly marked as such, and this notice is
  959. X * not modified.
  960. X *
  961. X */
  962. X
  963. X#include "conf.h"
  964. X
  965. X#define HOSTPROTOCOL    2           /* current host protocol */
  966. X
  967. X#define MAXPCHAN    7           /* maximum layers supported */
  968. X
  969. X#define MAXSTR      200
  970. X#define MAXARGS     64
  971. X#define MAXLINE     1024
  972. X#define IOSIZE      800         /* data gulp handling size */
  973. X
  974. X/* WARNING - packet sizes must be insured to never match the ESCAPE char */
  975. X#define ESCAPE      '}'         /* datalink escape character */
  976. X
  977. X#define EXITNORMAL              0       /* normal exit - connection succeeded */
  978. X#define EXITNOMACLAYERS         1       /* MacLayers server error */
  979. X#define EXITABNORMAL            2       /* something wrong generic error */
  980. X#define EXITSIGQUIT             3       /* TERM or QUIT signal got us */
  981. X#define EXITSIGHUP              4       /* HUP signal got us */
  982. X#define ATTRSIZE     15 
  983. X
  984. X#define DO      if (Dflag)      /* for debugging */
  985. X
  986. X/* Shape structure passed between MacLayers and ourselves */
  987. Xstruct Shape
  988. X{   short   worigv;                         /* verical window bit origin */
  989. X    short   worigh;                         /* horizontal window bit origin */
  990. X    short   wlines;                         /* window height */
  991. X    short   wchars;                         /* window width */
  992. X    short   wfont;                          /* window font size */
  993. X    short   wattr;                          /* window attributes */
  994. X};
  995. X
  996. Xstruct Kbuff
  997. X  { struct Kbuff * next;            /* next buffer in chain (or NULL) */
  998. X    int         size;               /* size of data in this buffer */
  999. X    int         offset;             /* start of first data in buffer */
  1000. X    unsigned char text[IOSIZE];     /* text buffer itself */
  1001. X  };
  1002. X            /* World layer definition */
  1003. Xstruct Layer {
  1004. X    int     chan;       /* channel represented by this layer */
  1005. X    int     allocated;      /* layer allocated */
  1006. X    int     ptyfd;          /* psuedo tty */
  1007. X    int     ptymask;    /* mask for pty descriptor */
  1008. X    int     lpid;       /* layer head process ID */
  1009. X    struct Kbuff *kbuff;        /* keyboard input buffers */
  1010. X    struct Shape shape;     /* Shape structure to/from MacLayers */
  1011. X    char    tty[MAXSTR];        /* psuedo tty ID */
  1012. X    };
  1013. X
  1014. X/* miscelaneous common data */
  1015. Xextern  int Dflag;              /* debug dump indicator flag */
  1016. Xextern  int Serverversion;          /* server's version number */
  1017. Xextern  int Protocollevel;          /* effective protocol level */
  1018. Xextern  int Serverlevel;            /* server's protocol level */
  1019. Xextern  int TtyMask;            /* Serial link mask */
  1020. Xextern  int TtyFd;              /* Serial link handle */
  1021. Xextern    int flowctl;        /* Flow control indicater */
  1022. Xextern  char    PtyName[32], TtyName[32];
  1023. Xextern char *OldMode, *NewMode;
  1024. Xextern  int Abortonmsg;
  1025. Xextern struct Layer World[MAXPCHAN]; /* all layer< structures */
  1026. Xextern  char    *ServerPort;
  1027. Xextern    char    *TtySpeed;
  1028. Xextern     char    *ServerNumber;
  1029. Xextern    char    *ModemName;
  1030. Xextern     char    *ServerName;
  1031. X#define Wa_shell    0x01                    /* window is a shell */
  1032. X
  1033. X
  1034. Xextern void DEBUG();
  1035. Xextern int OpenPTY();
  1036. Xextern char *Filename();
  1037. Xextern int SetTTY();
  1038. Xextern int InitConnect();
  1039. X
  1040. Xextern void FQuit(/* exitcode */);
  1041. Xextern void ReceiveQuit();
  1042. Xextern void ReceiveNew(/* chanid, shape */);
  1043. Xextern void ReceiveDelete(/* chanid */);
  1044. Xextern void ReceiveReshape(/*chanid, shape */);
  1045. END_OF_FILE
  1046.   if test 3765 -ne `wc -c <'ulayers.h'`; then
  1047.     echo shar: \"'ulayers.h'\" unpacked with wrong size!
  1048.   fi
  1049.   # end of 'ulayers.h'
  1050. fi
  1051. if test -f 'ulterm.cmdtool' -a "${1}" != "-c" ; then 
  1052.   echo shar: Will not clobber existing file \"'ulterm.cmdtool'\"
  1053. else
  1054.   echo shar: Extracting \"'ulterm.cmdtool'\" \(549 characters\)
  1055.   sed "s/^X//" >'ulterm.cmdtool' <<'END_OF_FILE'
  1056. X#!/bin/sh
  1057. X#
  1058. X# This is an example Layers terminal startup command.
  1059. X#
  1060. X# Layers executes this script with two arguments, the name of
  1061. X# the PTY that ulslave should use and the channel number.
  1062. X# The job of this module is to start up a terminal emulator,
  1063. X# running the ulslave program.
  1064. X#
  1065. X# This sample module starts cmdtool.  You could write your own
  1066. X# to start ulslave using another emulator, on a separate tty
  1067. X# or virtual console.
  1068. X#
  1069. Xif [ $# -ne 2 ] ; then
  1070. X    echo "usage: ulterm pty chan"
  1071. X    exit 1
  1072. Xfi
  1073. XSLAVE=ulslave
  1074. XTITLE="Layer $2"
  1075. Xexec cmdtool $SLAVE $1
  1076. END_OF_FILE
  1077.   if test 549 -ne `wc -c <'ulterm.cmdtool'`; then
  1078.     echo shar: \"'ulterm.cmdtool'\" unpacked with wrong size!
  1079.   fi
  1080.   chmod +x 'ulterm.cmdtool'
  1081.   # end of 'ulterm.cmdtool'
  1082. fi
  1083. if test -f 'ulterm.xterm' -a "${1}" != "-c" ; then 
  1084.   echo shar: Will not clobber existing file \"'ulterm.xterm'\"
  1085. else
  1086.   echo shar: Extracting \"'ulterm.xterm'\" \(584 characters\)
  1087.   sed "s/^X//" >'ulterm.xterm' <<'END_OF_FILE'
  1088. X#!/bin/sh
  1089. X#
  1090. X# This is an example Layers terminal startup command.
  1091. X#
  1092. X# Layers executes this script with two arguments, the name of
  1093. X# the PTY that ulslave should use and the channel number.
  1094. X# The job of this module is to start up a terminal emulator,
  1095. X# running the ulslave program.
  1096. X#
  1097. X# This sample module starts xterm.  You could write your own
  1098. X# to start ulslave using another emulator, on a separate tty
  1099. X# or virtual console.
  1100. X#
  1101. Xif [ $# -ne 2 ] ; then
  1102. X    echo "usage: ulterm pty chan"
  1103. X    exit 1
  1104. Xfi
  1105. XSLAVE=ulslave
  1106. XTITLE="Layer $2"
  1107. Xexec xterm -ut -geometry 80x25 -title "$TITLE" -e $SLAVE $1
  1108. END_OF_FILE
  1109.   if test 584 -ne `wc -c <'ulterm.xterm'`; then
  1110.     echo shar: \"'ulterm.xterm'\" unpacked with wrong size!
  1111.   fi
  1112.   chmod +x 'ulterm.xterm'
  1113.   # end of 'ulterm.xterm'
  1114. fi
  1115. echo shar: End of archive 3 \(of 3\).
  1116. cp /dev/null ark3isdone
  1117. MISSING=""
  1118. for I in 1 2 3 ; do
  1119.     if test ! -f ark${I}isdone ; then
  1120.     MISSING="${MISSING} ${I}"
  1121.     fi
  1122. done
  1123. if test "${MISSING}" = "" ; then
  1124.     echo You have unpacked all 3 archives.
  1125.     rm -f ark[1-9]isdone
  1126. else
  1127.     echo You still must unpack the following archives:
  1128.     echo "        " ${MISSING}
  1129. fi
  1130. exit 0
  1131. exit 0 # Just in case...
  1132.