void ShellCompletionWriter::writeWrapperCompletions( const ModuleNameList &modules, const Options &options) { impl_->file_->writeLine("_" + impl_->binaryName_ + "_compl() {"); impl_->file_->writeLine("local i c m"); impl_->file_->writeLine("local IFS=$'\\n'\n"); impl_->file_->writeLine("COMPREPLY=()"); impl_->file_->writeLine("unset COMP_WORDS[0]"); impl_->file_->writeLine("for ((i=1;i<COMP_CWORD;++i)) ; do"); impl_->file_->writeLine("[[ \"${COMP_WORDS[i]}\" != -* ]] && break"); impl_->file_->writeLine("unset COMP_WORDS[i]"); impl_->file_->writeLine("done"); impl_->file_->writeLine("if (( i == COMP_CWORD )); then"); impl_->file_->writeLine("c=${COMP_WORDS[COMP_CWORD]}"); OptionsListWriter lister; lister.visitSection(options.rootSection()); std::string completions(lister.optionList()); for (ModuleNameList::const_iterator i = modules.begin(); i != modules.end(); ++i) { completions.append("\\n"); completions.append(*i); } impl_->file_->writeLine("COMPREPLY=( $(compgen -S ' ' -W $'" + completions + "' -- $c) )"); impl_->file_->writeLine("return 0"); impl_->file_->writeLine("fi"); impl_->file_->writeLine("m=${COMP_WORDS[i]}"); impl_->file_->writeLine("COMP_WORDS=( \"${COMP_WORDS[@]}\" )"); impl_->file_->writeLine("COMP_CWORD=$((COMP_CWORD-i))"); impl_->file_->writeLine("case \"$m\" in"); for (ModuleNameList::const_iterator i = modules.begin(); i != modules.end(); ++i) { const char *const name = i->c_str(); impl_->file_->writeLine(formatString("%s) %s ;;", name, impl_->completionFunctionName(name).c_str())); } impl_->file_->writeLine("esac }"); }
//============================================================================= //== Main program == //============================================================================= void sim(int argc, char *argv[]) { double lambda; // Mean arrival rate (cust/sec) double mu; // Mean service rate (cust/sec) double offered_load; // Create the simulation create("sim"); // Output usage if (argc != 2) { printf("Usage: 'offered_load' - offered_load between 0 and 1 \n"); return; } offered_load = atof(argv[1]); assert((offered_load > 0.0) && (offered_load < 1.0)); // CSIM initializations Server1 = facility("Server1"); Server2 = facility("Server2"); Server3 = facility("Server3"); Server4 = facility("Server4"); Server5 = facility("Server5"); Resp_table = table("Response time table"); // Parameter initializations mu = 1.0; lambda = offered_load * (double)5; // Output begin-of-simulation banner printf("*** BEGIN SIMULATION *** \n"); // Initiate generate function and hold for SIM_TIME generate(lambda, mu); hold(SIM_TIME); // Output results printf("============================================================= \n"); printf("== *** CSIM 5 x M/M/1 queueing system simulation *** == \n"); printf("============================================================= \n"); printf("= Lambda = %6.3f cust/sec \n", lambda); printf("= Mu (for each server) = %6.3f cust/sec \n", mu); printf("============================================================= \n"); printf("= Total CPU time = %6.3f sec \n", cputime()); printf("= Total sim time = %6.3f sec \n", clock); printf("= Total completions = %ld cust \n", (completions(Server1) + completions(Server2) + completions(Server3) + completions(Server4) + completions(Server5))); printf("=------------------------------------------------------------ \n"); printf("= >>> Simulation results - \n"); printf("=------------------------------------------------------------ \n"); printf("= Utilization 1 = %6.3f %% \n", 100.0 * util(Server1)); printf("= Mean num in system 1 = %6.3f cust \n", qlen(Server1)); printf("= Mean response time 1 = %6.3f sec \n", resp(Server1)); printf("= Mean service time 1 = %6.3f sec \n", serv(Server1)); printf("= Mean throughput 1 = %6.3f cust/sec \n", tput(Server1)); printf("=------------------------------------------------------------ \n"); printf("= Utilization 2 = %6.3f %% \n", 100.0 * util(Server2)); printf("= Mean num in system 2 = %6.3f cust \n", qlen(Server2)); printf("= Mean response time 2 = %6.3f sec \n", resp(Server2)); printf("= Mean service time 2 = %6.3f sec \n", serv(Server2)); printf("= Mean throughput 2 = %6.3f cust/sec \n", tput(Server2)); printf("=------------------------------------------------------------ \n"); printf("= Utilization 3 = %6.3f %% \n", 100.0 * util(Server3)); printf("= Mean num in system 3 = %6.3f cust \n", qlen(Server3)); printf("= Mean response time 3 = %6.3f sec \n", resp(Server3)); printf("= Mean service time 3 = %6.3f sec \n", serv(Server3)); printf("= Mean throughput 3 = %6.3f cust/sec \n", tput(Server3)); printf("=------------------------------------------------------------ \n"); printf("= Utilization 4 = %6.3f %% \n", 100.0 * util(Server4)); printf("= Mean num in system 4 = %6.3f cust \n", qlen(Server4)); printf("= Mean response time 4 = %6.3f sec \n", resp(Server4)); printf("= Mean service time 4 = %6.3f sec \n", serv(Server4)); printf("= Mean throughput 4 = %6.3f cust/sec \n", tput(Server4)); printf("=------------------------------------------------------------ \n"); printf("= Utilization 5 = %6.3f %% \n", 100.0 * util(Server5)); printf("= Mean num in system 5 = %6.3f cust \n", qlen(Server5)); printf("= Mean response time 5 = %6.3f sec \n", resp(Server5)); printf("= Mean service time 5 = %6.3f sec \n", serv(Server5)); printf("= Mean throughput 5 = %6.3f cust/sec \n", tput(Server5)); printf("=------------------------------------------------------------ \n"); printf("& Table mean for response time = %6.3f sec \n", table_mean(Resp_table)); printf("============================================================= \n"); // Output end-of-simulation banner printf("*** END SIMULATION *** \n"); getchar(); }