home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-A.06 / NETKIT-A / NetKit-A-0.06 / ytalk-3.0.1 / rc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-27  |  4.2 KB  |  217 lines

  1. /* rc.c -- read the .ytalkrc file */
  2.  
  3. /*               NOTICE
  4.  *
  5.  * Copyright (c) 1990,1992,1993 Britt Yenne.  All rights reserved.
  6.  * 
  7.  * This software is provided AS-IS.  The author gives no warranty,
  8.  * real or assumed, and takes no responsibility whatsoever for any 
  9.  * use or misuse of this software, or any damage created by its use
  10.  * or misuse.
  11.  * 
  12.  * This software may be freely copied and distributed provided that
  13.  * no part of this NOTICE is deleted or edited in any manner.
  14.  * 
  15.  */
  16.  
  17. /* Mail comments or questions to ytalk@austin.eds.com */
  18.  
  19. #include "header.h"
  20.  
  21. #define IS_WHITE(c)    ((c)==' ' || (c)=='\t' || (c)=='\n')
  22.  
  23. /* ---- local functions ---- */
  24.  
  25. static char *
  26. get_word(p)
  27.   char **p;
  28. {
  29.     register char *c, *out;
  30.  
  31.     c = *p;
  32.     while(IS_WHITE(*c))
  33.     c++;
  34.     if(*c == '\0')
  35.     return NULL;
  36.     out = c;
  37.     while(*c && !IS_WHITE(*c))
  38.     c++;
  39.     if(*c)
  40.     *(c++) = '\0';
  41.     *p = c;
  42.     return out;
  43. }
  44.  
  45. static int
  46. set_option(opt, value)
  47.   char *opt, *value;
  48. {
  49.     ylong mask = 0;
  50.     int set_it;
  51.  
  52.     if(strcmp(value, "true") == 0 || strcmp(value, "on") == 0)
  53.     set_it = 1;
  54.     else if(strcmp(value, "false") == 0 || strcmp(value, "off") == 0)
  55.     set_it = 0;
  56.     else
  57.     return -1;
  58.     
  59.     if(strcmp(opt, "scroll") == 0
  60.     || strcmp(opt, "scrolling") == 0
  61.     || strcmp(opt, "sc") == 0)
  62.     mask |= FL_SCROLL;
  63.  
  64.     if(strcmp(opt, "wrap") == 0
  65.     || strcmp(opt, "word-wrap") == 0
  66.     || strcmp(opt, "wordwrap") == 0
  67.     || strcmp(opt, "wrapping") == 0
  68.     || strcmp(opt, "ww") == 0)
  69.     mask |= FL_WRAP;
  70.  
  71.     if(strcmp(opt, "import") == 0
  72.     || strcmp(opt, "auto-import") == 0
  73.     || strcmp(opt, "autoimport") == 0
  74.     || strcmp(opt, "importing") == 0
  75.     || strcmp(opt, "aip") == 0
  76.     || strcmp(opt, "ai") == 0)
  77.     mask |= FL_IMPORT;
  78.  
  79.     if(strcmp(opt, "invite") == 0
  80.     || strcmp(opt, "auto-invite") == 0
  81.     || strcmp(opt, "autoinvite") == 0
  82.     || strcmp(opt, "aiv") == 0
  83.     || strcmp(opt, "av") == 0)
  84.     mask |= FL_INVITE;
  85.  
  86.     if(strcmp(opt, "ring") == 0
  87.     || strcmp(opt, "auto-ring") == 0
  88.     || strcmp(opt, "auto-rering") == 0
  89.     || strcmp(opt, "autoring") == 0
  90.     || strcmp(opt, "autorering") == 0
  91.     || strcmp(opt, "ar") == 0)
  92.     mask |= FL_RING;
  93.  
  94.     if(strcmp(opt, "xwin") == 0
  95.     || strcmp(opt, "xwindows") == 0
  96.     || strcmp(opt, "XWindows") == 0
  97.     || strcmp(opt, "Xwin") == 0
  98.     || strcmp(opt, "x") == 0
  99.     || strcmp(opt, "X") == 0)
  100.     mask |= FL_XWIN;
  101.  
  102.     if(strcmp(opt, "asides") == 0
  103.     || strcmp(opt, "aside") == 0
  104.     || strcmp(opt, "as") == 0)
  105.     mask |= FL_ASIDE;
  106.     
  107.     if(!mask)
  108.     return -1;
  109.  
  110.     if(set_it)
  111.     def_flags |= mask;
  112.     else
  113.     def_flags &= ~mask;
  114.  
  115.     return 0;
  116. }
  117.  
  118. static void
  119. read_rcfile(fname)
  120.   char *fname;
  121. {
  122.     FILE *fp;
  123.     char *buf, *ptr;
  124.     char *w, *arg1, *arg2, *arg3;
  125.     int line_no, errline;
  126.  
  127.     if((fp = fopen(fname, "r")) == NULL)
  128.     {
  129.     if(errno != ENOENT)
  130.         show_error(fname);
  131.     return;
  132.     }
  133.     buf = get_mem(BUFSIZ);
  134.  
  135.     line_no = errline = 0;
  136.     while(fgets(buf, BUFSIZ, fp) != NULL)
  137.     {
  138.     line_no++;
  139.     ptr = buf;
  140.     w = get_word(&ptr);
  141.     if(w == NULL || *w == '#')
  142.         continue;
  143.     
  144.     if(strcmp(w, "readdress") == 0)
  145.     {
  146.         arg1 = get_word(&ptr);
  147.         arg2 = get_word(&ptr);
  148.         arg3 = get_word(&ptr);
  149.         if(arg3 == NULL)
  150.         {
  151.         errline = line_no;
  152.         break;
  153.         }
  154.         readdress_host(arg1, arg2, arg3);
  155.     }
  156.     else if(strcmp(w, "set") == 0 || strcmp(w, "turn") == 0)
  157.     {
  158.         arg1 = get_word(&ptr);
  159.         arg2 = get_word(&ptr);
  160.         if(arg2 == NULL)
  161.         {
  162.         errline = line_no;
  163.         break;
  164.         }
  165.         if(set_option(arg1, arg2) < 0)
  166.         {
  167.         errline = line_no;
  168.         break;
  169.         }
  170.     }
  171.     else
  172.     {
  173.         errline = line_no;
  174.         break;
  175.     }
  176.     }
  177.     if(errline)
  178.     {
  179.     sprintf(errstr, "%s: syntax error at line %d", fname, errline);
  180.     errno = 0;
  181.     show_error(errstr);
  182.     }
  183.  
  184.     free(buf);
  185.     fclose(fp);
  186. }
  187.  
  188. /* ---- global functions ---- */
  189.  
  190. void
  191. read_ytalkrc()
  192. {
  193.     char *w;
  194.     yuser *u;
  195.     char fname[256];
  196.  
  197.     /* read the system ytalkrc file */
  198.  
  199. #ifdef SYSTEM_YTALKRC
  200.     read_rcfile(SYSTEM_YTALKRC);
  201. #endif
  202.  
  203.     /* read the user's ytalkrc file */
  204.  
  205.     if((w = (char *)getenv("HOME")) != NULL)
  206.     {
  207.     sprintf(fname, "%s/.ytalkrc", w);
  208.     read_rcfile(fname);
  209.     }
  210.  
  211.     /* set all default flags */
  212.  
  213.     for(u = user_list; u != NULL; u = u->unext)
  214.     if(!(u->flags & FL_LOCKED))
  215.         u->flags = def_flags;
  216. }
  217.