home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / twm / part01 / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-12  |  4.5 KB  |  167 lines

  1. /*****************************************************************************/
  2. /**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  3. /**                          Salt Lake City, Utah                           **/
  4. /**                                                                         **/
  5. /**                           All Rights Reserved                           **/
  6. /**                                                                         **/
  7. /**    Permission to use, copy, modify, and distribute this software and    **/
  8. /**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  9. /**    granted, provided that the above copyright notice appear  in  all    **/
  10. /**    copies and that both  that  copyright  notice  and  this  permis-    **/
  11. /**    sion  notice appear in supporting  documentation,  and  that  the    **/
  12. /**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  13. /**    city pertaining to distribution  of the software without  specif-    **/
  14. /**    ic, written prior permission.                                        **/
  15. /**                                                                         **/
  16. /**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  17. /**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  18. /**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  19. /**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  20. /**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  21. /**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  22. /**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  23. /**    FORMANCE OF THIS SOFTWARE.                                           **/
  24. /*****************************************************************************/
  25.  
  26. /***********************************************************************
  27.  *
  28.  * $Header: parse.c,v 1.13 88/04/15 07:09:29 tlastran Exp $
  29.  *
  30.  * parse the .twmrc file
  31.  *
  32.  * 17-Nov-87 Thomas E. LaStrange        File created
  33.  *
  34.  ***********************************************************************/
  35.  
  36. #ifndef lint
  37. static char RCSinfo[]=
  38. "$Header: parse.c,v 1.13 88/04/15 07:09:29 tlastran Exp $";
  39. #endif
  40.  
  41. #include <stdio.h>
  42. #include "twm.h"
  43. #include "menus.h"
  44. #include "util.h"
  45.  
  46. #define BUF_LEN 300
  47.  
  48. static FILE *twmrc;
  49. static int ptr = 0;
  50. static int len = 0;
  51. static char buff[BUF_LEN+1];
  52. extern int yylineno;
  53.  
  54. /***********************************************************************
  55.  *
  56.  *  Procedure:
  57.  *    ParseTwmrc - parse the .twmrc file
  58.  *
  59.  *  Inputs:
  60.  *    filename  - the filename to parse.  A NULL indicates $HOME/.twmrc
  61.  *
  62.  ***********************************************************************
  63.  */
  64.  
  65. void
  66. ParseTwmrc(filename)
  67. char *filename;
  68. {
  69.     char *home;
  70.     char init_file[200];
  71.  
  72.     InitMenus();
  73.     InitButtons();
  74.  
  75.     if (filename == NULL)
  76.     {
  77.     home = (char *)getenv("HOME");
  78.     strcpy(init_file, home);
  79.     strcat(init_file, "/.twmrc");
  80.     }
  81.     else
  82.     strcpy(init_file, filename);
  83.  
  84.     if ((twmrc = fopen(init_file, "r")) == NULL)
  85.     {
  86.     fprintf(stderr, "twm: couldn't open \"%s\"\n", init_file);
  87.         return;
  88.     }
  89.  
  90.     ptr = 0;
  91.     len = 0;
  92.     yylineno = 0;
  93.     ParseError = FALSE;
  94.  
  95.     yyparse();
  96.  
  97.     fclose(twmrc);
  98.  
  99.     if (ParseError)
  100.     {
  101.     fprintf(stderr, "twm: errors found in \"%s\", twm aborting\n",
  102.         init_file);
  103.     Done();
  104.     }
  105. }
  106.  
  107. /***********************************************************************
  108.  *
  109.  *  Procedure:
  110.  *    TwmInput - redefinition of the lex input routine
  111.  *
  112.  *  Returned Value:
  113.  *    the next input character
  114.  *
  115.  ***********************************************************************
  116.  */
  117.  
  118. char
  119. TwmInput()
  120. {
  121.     while (ptr == len)
  122.     {
  123.     if (fgets(buff, BUF_LEN, twmrc) == NULL)
  124.         return NULL;
  125.  
  126.     yylineno++;
  127.  
  128.     ptr = 0;
  129.     len = strlen(buff);
  130.     }
  131.     return (buff[ptr++]);
  132. }
  133.  
  134. /***********************************************************************
  135.  *
  136.  *  Procedure:
  137.  *    TwmUnput - redefinition of the lex unput routine
  138.  *
  139.  *  Inputs:
  140.  *    c    - the character to push back onto the input stream
  141.  *
  142.  ***********************************************************************
  143.  */
  144.  
  145. void
  146. TwmUnput(c)
  147. {
  148.     buff[--ptr] = c;
  149. }
  150.  
  151. /***********************************************************************
  152.  *
  153.  *  Procedure:
  154.  *    TwmOutput - redefinition of the lex output routine
  155.  *
  156.  *  Inputs:
  157.  *    c    - the character to print
  158.  *
  159.  ***********************************************************************
  160.  */
  161.  
  162. void
  163. TwmOutput(c)
  164. {
  165.     putchar(c);
  166. }
  167.