home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / ytalk-3.0 / part01 / rc.c < prev    next >
C/C++ Source or Header  |  1993-08-20  |  4KB  |  192 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.     u_long mask = 0L;
  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_IMPORT;
  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(!mask)
  103.     return -1;
  104.  
  105.     if(set_it)
  106.     def_flags |= mask;
  107.     else
  108.     def_flags &= ~mask;
  109.  
  110.     return 0;
  111. }
  112.  
  113. /* ---- global functions ---- */
  114.  
  115. void
  116. read_ytalkrc()
  117. {
  118.     FILE *fp;
  119.     char *buf, *ptr;
  120.     char *w, *arg1, *arg2, *arg3;
  121.     int line_no, errline;
  122.     yuser *u;
  123.  
  124.     if((w = getenv("HOME")) == NULL)
  125.     return;
  126.     buf = get_mem(BUFSIZ);
  127.     sprintf(buf, "%s/.ytalkrc", w);
  128.     if((fp = fopen(buf, "r")) == NULL)
  129.     {
  130.     if(errno != ENOENT)
  131.         show_error(buf);
  132.     free(buf);
  133.     return;
  134.     }
  135.  
  136.     line_no = errline = 0;
  137.     while(fgets(buf, BUFSIZ, fp) != NULL)
  138.     {
  139.     line_no++;
  140.     ptr = buf;
  141.     w = get_word(&ptr);
  142.     if(w == NULL || *w == '#')
  143.         continue;
  144.     
  145.     if(strcmp(w, "readdress") == 0)
  146.     {
  147.         arg1 = get_word(&ptr);
  148.         arg2 = get_word(&ptr);
  149.         arg3 = get_word(&ptr);
  150.         if(arg3 == NULL)
  151.         {
  152.         errline = line_no;
  153.         break;
  154.         }
  155.         readdress_host(arg1, arg2, arg3);
  156.     }
  157.     else if(strcmp(w, "set") == 0 || strcmp(w, "turn") == 0)
  158.     {
  159.         arg1 = get_word(&ptr);
  160.         arg2 = get_word(&ptr);
  161.         if(arg2 == NULL)
  162.         {
  163.         errline = line_no;
  164.         break;
  165.         }
  166.         if(set_option(arg1, arg2) < 0)
  167.         {
  168.         errline = line_no;
  169.         break;
  170.         }
  171.     }
  172.     else
  173.     {
  174.         errline = line_no;
  175.         break;
  176.     }
  177.     }
  178.     if(errline)
  179.     {
  180.     sprintf(errstr, ".ytalkrc: syntax error at line %d", errline);
  181.     errno = 0;
  182.     show_error(errstr);
  183.     }
  184.  
  185.     free(buf);
  186.     fclose(fp);
  187.  
  188.     for(u = user_list; u != NULL; u = u->unext)
  189.     if(!(u->flags & FL_LOCKED))
  190.         u->flags = def_flags;
  191. }
  192.