yshell - // if one is needed. cout << prompt <<...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <cstdlib> #include <iostream> #include <string> #include <utility> using namespace std; #include "commands.h" #include "trace.h" #include "inode.h" #include "util.h" // // scan_options // Options analysis: The only option is -Dflags. // void scan_options (int argc, char **argv) { opterr = 0; for (;;) { int option = getopt (argc, argv, "D:"); if (option == EOF) break; switch (option) { case 'D': traceflags::setflags (optarg); break; default: complain() << "-" << (char) option << ": invalid option" << endl; break; } } if (optind < argc) { complain() << "operands not permitted" << endl; } } // // main - // Main program which loops reading commands until end of file. // int main (int argc, char **argv) { scan_options (argc, argv); bool need_echo = want_echo(); commands cmdmap; string prompt = "%"; inode_state state; for (;;) { try { // Read a line, break at EOF, and echo print the prompt
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // if one is needed. cout << prompt << " "; string line; getline (cin, line); if (cin.eof()) { if (need_echo) cout << "^D"; cout << endl; TRACE ('y', "EOF"); break; } if (need_echo) cout << line << endl; // Split the line into words and lookup the appropriate // function. Complain or call it. wordvec words = split (line, " \t"); TRACE ('y', "words = " << words); function fn = cmdmap[words[0]]; if (fn == NULL) { throw yshell_exn (words[0] + ": no such function"); } fn (state, words); }catch (yshell_exn exn) { // If there is a problem discovered in any function, an // exn is thrown and printed here. complain() << exn.what() << endl; } } return exit_status_message(); } RCSC(yshell_cc, "$Id: yshell.cc,v 1.24 2009-01-12 12:34:56-08 - - $")...
View Full Document

This note was uploaded on 01/26/2010 for the course CMPS 109 taught by Professor Bailey,d during the Spring '08 term at University of California, Santa Cruz.

Page1 / 2

yshell - // if one is needed. cout << prompt <<...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online