home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume4
/
xgen
/
part03
/
parse_applica.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-29
|
3KB
|
151 lines
#include <stdio.h>
#include <ctype.h>
#include "application.h"
parse_app(file)
char *file;
{
FILE *fp1, *fopen();
char buffer[STR_LEN] ;
char *bptr ;
char type[STR_LEN], name[STR_LEN];
char string1[STR_LEN],
string2[STR_LEN];
struct env_shell *header1,
*pres_shell,
*old_shell;
int C;
struct shell *app_shell;
struct shell *parse_shell();
/* open file input in command line*/
if (NULL == (fp1 = fopen( file, "r")))
{
fprintf(stderr, "Error: Can't find input file %s\n", file) ;
exit(-1) ;
}
for(;;)
{
get_string(fp1, type, NULL, STR_LEN) ;
/* if the type declaration is environment then
* parse the environment
*/
if (! strcmp(type, "environment") == 0)
{
fprintf(stderr,"Error: expecting <environment>, got <%s>\n", type) ;
exit(-1) ;
}
get_string(fp1, name, NULL, STR_LEN) ;
start:/* parse env options below */
get_symbol(fp1, &C) ;
if ( C != '{' )
{
ungetc( C, fp1);
get_string(fp1, string1, ':', STR_LEN) ;
get_symbol(fp1, &C) ;
/*check the validity of the env options*/
if( strcmp(string1, "initialshells"))
{
fprintf(stderr, "Error: No such option <%s> for environment <%s>. Ignored.\n",
string1, name);
goto start;
}
get_string(fp1, buffer, NULL, STR_LEN) ;
bptr = buffer ;
/* Get rid of leading spaces */
while (*bptr != NULL && isspace(*bptr))
bptr++ ;
header1 = (struct env_shell *)malloc(
sizeof( struct env_shell));
if (1 != sscanf(bptr, "%s", header1->name))
{
fprintf(stderr, "Error parsing initialshells for <%s>\n",
name) ;
exit(-1) ;
}
old_shell = header1;
for(;;)
{
/* Read past word already read */
while (*bptr != NULL && ! isspace(*bptr))
bptr++ ;
/* Get rid of leading spaces */
while (*bptr != NULL && isspace(*bptr))
bptr++ ;
if (1 != sscanf(bptr, "%s", string2))
break ;
/* create a linked list with the names
* of the initial shells
*/
pres_shell = (struct env_shell *)malloc(
sizeof( struct env_shell));
strcpy( pres_shell->name, string2);
old_shell->next = pres_shell;
old_shell = pres_shell;
}
old_shell->next = NULL;
goto start;
}
/*parse the environment shells*/
while(1)
{
/* do the parsing until the closing bracket is
* encountered
*/
get_symbol(fp1, &C) ;
if( C == '}' )
{
/* old_shell->next = NULL;*/
break;
}
ungetc( C, fp1);
/* parse the shell and enter the shell address
* in the shell hash tables
*/
app_shell = parse_shell( fp1 );
enter_shell_descrip( app_shell, app_shell->name);
}
/* enter the initial shells of the environment in the hash
* table
*/
enter_env_shells(name, header1);
/* Check for EOF, which is appropriate here */
if (check_eof(fp1))
break ;
}
fclose(fp1);
}