I'm building a (very) minimal Unix shell, and I'm having some trouble resetting the input stream when a configuration file is provided. When the file is provided, my shell reads from the file until it reaches the EOF, as it should. At that point, I want to read input from stdin. However, my command parser functions such that it terminates when EOF is reached, so the shell fails to continue running once the configuration file is processed. I'd appreciate any guidance. Thanks!
EDIT: code for reference
while ((pcLine = readLine(pfInput)) != NULL)
{
oTokens = findTokens(pcLine);
if (oTokens != NULL)
{
/* Print command from configuration file. */
if (argc >= 2)
printf("%s\n", pcLine);
oCommand = newCommand(oTokens);
if (oCommand != NULL)
{
pcName = command_getName(oCommand);
if (strcmp(pcName, "setenv") == 0)
ish_setEnv(oCommand);
else if (strcmp(pcName, "unsetenv") == 0)
ish_unsetEnv(oCommand);
else if (strcmp(pcName, "cd") == 0)
ish_cd(oCommand);
else if (strcmp(pcName, "exit") == 0)
ish_exit(oCommand);
else
execute(oCommand);
freeCommand(oCommand);
}
}
free(pcLine);
}
I'm building a (very) minimal Unix shell, and I'm having some trouble resetting the input stream when a configuration file is provided. When the file is provided, my shell reads from the file until it reaches the EOF, as it should. At that point, I want to read input from stdin. However, my command parser functions such that it terminates when EOF is reached, so the shell fails to continue running once the configuration file is processed. I'd appreciate any guidance. Thanks!
EDIT: code for reference
while ((pcLine = readLine(pfInput)) != NULL)
{
oTokens = findTokens(pcLine);
if (oTokens != NULL)
{
/* Print command from configuration file. */
if (argc >= 2)
printf("%s\n", pcLine);
oCommand = newCommand(oTokens);
if (oCommand != NULL)
{
pcName = command_getName(oCommand);
if (strcmp(pcName, "setenv") == 0)
ish_setEnv(oCommand);
else if (strcmp(pcName, "unsetenv") == 0)
ish_unsetEnv(oCommand);
else if (strcmp(pcName, "cd") == 0)
ish_cd(oCommand);
else if (strcmp(pcName, "exit") == 0)
ish_exit(oCommand);
else
execute(oCommand);
freeCommand(oCommand);
}
}
free(pcLine);
}
0 commentaires:
Enregistrer un commentaire