home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xgen / part03 / parse_applica.c < prev    next >
C/C++ Source or Header  |  1989-06-29  |  3KB  |  151 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include  "application.h"
  4.  
  5. parse_app(file)
  6. char *file;
  7.  
  8. {
  9.     FILE *fp1, *fopen();
  10.     char buffer[STR_LEN] ;
  11.     char *bptr ;
  12.     char type[STR_LEN], name[STR_LEN];
  13.     char string1[STR_LEN],
  14.     string2[STR_LEN];
  15.     struct env_shell *header1,
  16.         *pres_shell,
  17.         *old_shell;
  18.     int C;
  19.     struct shell *app_shell;
  20.     struct shell *parse_shell();
  21.  
  22.  
  23.     /* open file input in command line*/
  24.     if (NULL == (fp1 = fopen( file, "r")))
  25.     {
  26.         fprintf(stderr, "Error: Can't find input file %s\n", file) ;
  27.         exit(-1) ;
  28.     }
  29.  
  30.     for(;;)
  31.     {
  32.         get_string(fp1, type, NULL, STR_LEN) ;
  33.  
  34.         /* if the type declaration is environment then 
  35.          *  parse the environment
  36.          */
  37.         if (! strcmp(type, "environment") == 0)
  38.         {
  39.             fprintf(stderr,"Error: expecting <environment>, got <%s>\n", type) ;
  40.             exit(-1) ;
  41.         }
  42.  
  43.         get_string(fp1, name, NULL, STR_LEN) ;
  44.  
  45. start:/* parse env options below */
  46.  
  47.         get_symbol(fp1, &C) ;
  48.  
  49.         if ( C != '{' )
  50.         {
  51.             ungetc( C, fp1);
  52.  
  53.             get_string(fp1, string1, ':', STR_LEN) ;
  54.  
  55.             get_symbol(fp1, &C) ;
  56.  
  57.             /*check the validity of the env options*/
  58.             if( strcmp(string1, "initialshells"))
  59.             {
  60.                 fprintf(stderr, "Error: No such option <%s> for environment <%s>. Ignored.\n",
  61.                     string1, name);
  62.                 goto start;
  63.             }
  64.  
  65.             get_string(fp1, buffer, NULL, STR_LEN) ;
  66.  
  67.             bptr = buffer ;
  68.  
  69.             /* Get rid of leading spaces */
  70.             while (*bptr != NULL && isspace(*bptr))
  71.                 bptr++ ;
  72.             header1 = (struct env_shell *)malloc(
  73.                 sizeof( struct env_shell));
  74.  
  75.             if (1 != sscanf(bptr, "%s", header1->name))
  76.             {
  77.                 fprintf(stderr, "Error parsing initialshells for <%s>\n",
  78.                     name) ;
  79.                 exit(-1) ;
  80.             }
  81.  
  82.             old_shell = header1;
  83.  
  84.             for(;;)
  85.             {
  86.                 /* Read past word already read */
  87.                 while (*bptr != NULL && ! isspace(*bptr))
  88.                     bptr++ ;
  89.                 /* Get rid of leading spaces */
  90.                 while (*bptr != NULL && isspace(*bptr))
  91.                     bptr++ ;
  92.  
  93.                 if (1 != sscanf(bptr, "%s", string2))
  94.                     break ;
  95.  
  96.                 /* create a linked list with the names
  97.                  * of the initial shells
  98.                  */
  99.                 pres_shell = (struct env_shell *)malloc(
  100.                     sizeof( struct env_shell));
  101.  
  102.                 strcpy( pres_shell->name, string2);
  103.  
  104.  
  105.                 old_shell->next = pres_shell;
  106.                 old_shell = pres_shell;
  107.             }
  108.             old_shell->next = NULL;
  109.  
  110.             goto start;
  111.         }
  112.         /*parse the environment shells*/
  113.  
  114.         while(1)
  115.         {
  116.             /* do the parsing until the closing bracket is 
  117.              * encountered
  118.              */
  119.             get_symbol(fp1, &C) ;
  120.  
  121.             if( C == '}' )
  122.             {
  123.                 /*          old_shell->next = NULL;*/
  124.                 break;
  125.             }
  126.  
  127.             ungetc( C, fp1);
  128.  
  129.             /* parse the shell and enter the shell address
  130.              * in the shell hash  tables
  131.              */
  132.  
  133.             app_shell = parse_shell( fp1 );
  134.  
  135.             enter_shell_descrip( app_shell, app_shell->name);
  136.         }
  137.  
  138.  
  139.         /* enter the initial shells of the environment in the hash
  140.          * table
  141.          */
  142.         enter_env_shells(name, header1);
  143.  
  144.         /* Check for EOF, which is appropriate here */
  145.         if (check_eof(fp1))
  146.             break ;
  147.     }
  148.  
  149.     fclose(fp1);
  150. }
  151.