static i4 yylex( FILE *input ) { char *pscan; if( yygetline( input ) != OK ) return( tEOF ); /* Unless the -C flag was specified, blank out all of the comments */ pscan = infile->yytext; while (pass_comments == FALSE && *pscan != EOS) { if (infile->yycomment == TRUE) { /* Look for the 'end comment' identifier */ if (STbcompare(pscan,2,ERx("*/"),2,FALSE) == 0) { /* Blank out the 'end comment' characters */ CMcpychar(ERx(" "), pscan); CMnext(pscan); CMcpychar(ERx(" "), pscan); /* Remember that the comment has ended */ infile->yycomment = FALSE; } /* Blank out non-whitespace characters of the comment */ else if (!CMwhite(pscan)) { CMcpychar(ERx(" "), pscan); } /* Whitespace chars are skipped, this lets \n thru */ } /* Look for the 'begin comment' identifier */ else if (STbcompare(pscan,2,ERx("/*"),2,FALSE) == 0) { /* Blank out the 'begin comment' characters */ CMcpychar(ERx(" "), pscan); CMnext(pscan); CMcpychar(ERx(" "), pscan); infile->yycomment = TRUE; } CMnext(pscan); /* Continue the scan with the next character */ } if( is_history(infile->yytext ) == OK) { return( tHISTORY ); } if( *infile->yytext == '#' ) return( tDIRECTIVE ); return( tSOURCE ); }
int main(void) { int exec_ret; while (1) { fputs("$", stdout); input = read_input(); if (input == NULL) { /* user entered ctrl+D, exit gracefully */ cleanup_and_exit(EXIT_SUCCESS); } if (strlen(input) > 0 && !is_blank(input) && input[0] != '|') { char *linecopy = strdup(input); struct commands *commands = parse_commands_with_pipes(input); /* add pipeline cmds & other commands to history */ if (commands->cmd_count > 1 || !is_history(input)) add_to_history(linecopy); free(linecopy); exec_ret = exec_commands(commands); cleanup_commands(commands); } free(input); /* get ready to exit */ if (exec_ret == -1) break; } cleanup_and_exit(EXIT_SUCCESS); return 0; }