home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / slip / cslip-2.6 / tip / remote.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-06  |  4.4 KB  |  191 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#)remote.c    5.5 (Berkeley) 6/1/90";
  22. #endif /* not lint */
  23.  
  24. # include "tip.h"
  25.  
  26. /*
  27.  * Attributes to be gleened from remote host description
  28.  *   data base.
  29.  */
  30. static char **caps[] = {
  31.     &AT,  &DV,  &CM,  &CU,  &EL,  &IE,  &OE,  &PN,  &PR,
  32.     &DI,  &ES,  &EX,  &FO,  &RC,  &RE,  &PA,  &SA,  &DA,
  33.     &SM,  &ST,  &LS, &CC
  34. };
  35.  
  36. static char *capstrings[] = {
  37.     "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
  38.     "di", "es", "ex", "fo", "rc", "re", "pa", "sa", "da",
  39.     "sm", "st", "ls", "cc", 0
  40. };
  41.  
  42. char *rgetstr();
  43.  
  44. static
  45. getremcap(host)
  46.     register char *host;
  47. {
  48.     int stat;
  49.     char tbuf[BUFSIZ];
  50.     static char buf[BUFSIZ/2];
  51.     char *bp = buf;
  52.     register char **p, ***q;
  53.  
  54.     if ((stat = rgetent(tbuf, host)) <= 0) {
  55.         if (DV ||
  56.             host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) {
  57.             CU = DV;
  58.             HO = host;
  59.             HW = 1;
  60.             DU = 0;
  61.             if (!BR)
  62.                 BR = DEFBR;
  63.             FS = DEFFS;
  64.             return;
  65.         }
  66.         fprintf(stderr, stat == 0 ?
  67.             "tip: unknown host %s\n" :
  68.             "tip: can't open host description file\n", host);
  69.         exit(3);
  70.     }
  71.  
  72.     for (p = capstrings, q = caps; *p != NULL; p++, q++)
  73.         if (**q == NULL)
  74.             **q = rgetstr(*p, &bp);
  75.     if (!BR && (BR = rgetnum("br")) < 0)
  76.         BR = DEFBR;
  77.     if ((FS = rgetnum("fs")) < 0)
  78.         FS = DEFFS;
  79.     if (DU < 0)
  80.         DU = 0;
  81.     else
  82.         DU = rgetflag("du");
  83.     if (DV == NOSTR) {
  84.         fprintf(stderr, "%s: missing device spec\n", host);
  85.         exit(3);
  86.     }
  87.     if (DU && CU == NOSTR)
  88.         CU = DV;
  89.     if (DU && PN == NOSTR) {
  90.         fprintf(stderr, "%s: missing phone number\n", host);
  91.         exit(3);
  92.     }
  93.     if (ST)
  94.         ++slip;
  95.  
  96.     HD = rgetflag("hd");
  97.  
  98.     /*
  99.      * This effectively eliminates the "hw" attribute
  100.      *   from the description file
  101.      */
  102.     if (!HW)
  103.         HW = (CU == NOSTR) || (DU && equal(DV, CU));
  104.     HO = host;
  105.     /*
  106.      * see if uppercase mode should be turned on initially
  107.      */
  108.     if (rgetflag("ra"))
  109.         boolean(value(RAISE)) = 1;
  110.     if (rgetflag("ec"))
  111.         boolean(value(ECHOCHECK)) = 1;
  112.     if (rgetflag("be"))
  113.         boolean(value(BEAUTIFY)) = 1;
  114.     if (rgetflag("nb"))
  115.         boolean(value(BEAUTIFY)) = 0;
  116.     if (rgetflag("sc"))
  117.         boolean(value(SCRIPT)) = 1;
  118.     if (rgetflag("tb"))
  119.         boolean(value(TABEXPAND)) = 1;
  120.     if (rgetflag("vb"))
  121.         boolean(value(VERBOSE)) = 1;
  122.     if (rgetflag("nv"))
  123.         boolean(value(VERBOSE)) = 0;
  124.     if (rgetflag("ta"))
  125.         boolean(value(TAND)) = 1;
  126.     if (rgetflag("nt"))
  127.         boolean(value(TAND)) = 0;
  128.     if (rgetflag("rw"))
  129.         boolean(value(RAWFTP)) = 1;
  130.     if (rgetflag("hd"))
  131.         boolean(value(HALFDUPLEX)) = 1;
  132.     if (rgetflag("li"))
  133.         boolean(value(LINESYNC)) = 1;
  134.     if (rgetflag("dt"))
  135.         boolean(value(DTRHUP)) =1;
  136.     if (rgetflag("fc"))
  137.         boolean(value(HWFC)) = 1;
  138.     if (RE == NOSTR)
  139.         RE = (char *)"tip.record";
  140.     if (EX == NOSTR)
  141.         EX = (char *)"\t\n\b\f";
  142.     if (ES != NOSTR)
  143.         vstring("es", ES);
  144.     if (FO != NOSTR)
  145.         vstring("fo", FO);
  146.     if (PR != NOSTR)
  147.         vstring("pr", PR);
  148.     if (RC != NOSTR)
  149.         vstring("rc", RC);
  150.     if ((DL = rgetnum("dl")) < 0)
  151.         DL = 0;
  152.     if ((CL = rgetnum("cl")) < 0)
  153.         CL = 0;
  154.     if ((ET = rgetnum("et")) < 0)
  155.         ET = 10;
  156. }
  157.  
  158. char *
  159. getremote(host)
  160.     char *host;
  161. {
  162.     register char *cp;
  163.     static char *next;
  164.     static int lookedup = 0;
  165.  
  166.     if (!lookedup) {
  167.         if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
  168.             fprintf(stderr, "tip: no host specified\n");
  169.             exit(3);
  170.         }
  171.         getremcap(host);
  172.         next = DV;
  173.         lookedup++;
  174.     }
  175.     /*
  176.      * We return a new device each time we're called (to allow
  177.      *   a rotary action to be simulated)
  178.      */
  179.     if (next == NOSTR)
  180.         return (NOSTR);
  181.     if ((cp = index(next, ',')) == NULL) {
  182.         DV = next;
  183.         next = NOSTR;
  184.     } else {
  185.         *cp++ = '\0';
  186.         DV = next;
  187.         next = cp;
  188.     }
  189.     return (DV);
  190. }
  191.