/* ** curl tool main function. */ int main(int argc, char *argv[]) { CURLcode result = CURLE_OK; struct GlobalConfig global; memset(&global, 0, sizeof(global)); main_checkfds(); #if defined(HAVE_SIGNAL) && defined(SIGPIPE) (void)signal(SIGPIPE, SIG_IGN); #endif /* Initialize memory tracking */ memory_tracking_init(); /* Initialize the curl library - do not call any libcurl functions before this point */ result = main_init(&global); if(!result) { /* Start our curl operation */ result = operate(&global, argc, argv); #ifdef __SYMBIAN32__ if(global.showerror) tool_pressanykey(); #endif /* Perform the main cleanup */ main_free(&global); } #ifdef __NOVELL_LIBC__ if(getenv("_IN_NETWARE_BASH_") == NULL) tool_pressanykey(); #endif #ifdef __VMS vms_special_exit(res, vms_show); #else return (int)result; #endif }
int main(string arg) { string *usernames = explode(arg, " "); object *users = map(usernames, "find_player", "/single/simul_efun"); int arg_count = usernames && sizeof(usernames); int i; if (!arg_count) { return error_out(usage()); } for (i = 0; i < arg_count; i++) { if (users[i]) { operate(users[i]); } else { MESSAGE_D->tell(previous_object(), "Could not find user " + usernames[i] + "\n"); } } return 1; }
int fitNewEquation(float* L, int start, int end, int R, char* op) { int i; if (start==end) { if(L[start] == R) return 1; else return 0; } for (i=1 ; i<4 ; i++) { int temp = L[start+1]; L[start+1] = operate(L[start], L[start+1], op[i]); if(fitNewEquation(L, start+1, end, R, op)) { L[start+1] = temp; printf("%.0f %c %.0f\n", L[start], op[i], L[start+1]); return 1; } L[start+1] = temp; } return 0; }
void datalogProgram ::expression(parameter& myParam){ if (tokens.at(vecIndex).getTokenType() == LEFT_PAREN){ string Value; stringstream ss; ss << tokens.at(vecIndex).getText(); ss >> Value; match(LEFT_PAREN); parameter leftSide; param(leftSide); Value += leftSide.textValue; string op; operate(op); Value += op; parameter rightSide; param(rightSide); Value += rightSide.textValue; string endValue; ss << tokens.at(vecIndex).getText(); ss >> endValue; Value += endValue; match(RIGHT_PAREN); }
void testServiceRegistry::loadTest() { art::AssertHandler ah; std::vector<fhicl::ParameterSet> pss; fhicl::ParameterSet ps; std::string typeName("DummyService"); ps.addParameter("service_type", typeName); int value = 2; ps.addParameter("value", value); pss.push_back(ps); art::ServiceToken token(art::ServiceRegistry::createSet(pss)); art::ServiceRegistry::Operate operate(token); art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value() == 2); }
int main() { char word[MAXWORD]; double ans; while(getword(word, MAXWORD) != EOF) { if ( isdigit(*word) || ( *word == '-' && isdigit(*(word+1)) ) ) push(atof(word)); else operate(word); } ans = pop(); if (!is_empty()) { fprintf(stderr, "Error: Improper postfix expression\n"); exit(6); } printf("\nAnswer = %f\n\n", ans); return 0; }
void execute() { operate(); } // should be called periodically to execute stuff in between (Sound, Video)
int main(int argc, char *argv[]) { typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator; std::cout << "main:: initialize" << std::endl; // AlgoInit(); // Copied from example stand-alone program in Message Logger July 18, 2007 std::string const kProgramName = argv[0]; int rc = 0; try { // A. Instantiate a plug-in manager first. edm::AssertHandler ah; // B. Load the message service plug-in. Forget this and bad things happen! // In particular, the job hangs as soon as the output buffer fills up. // That's because, without the message service, there is no mechanism for // emptying the buffers. boost::shared_ptr<edm::Presence> theMessageServicePresence; theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()-> makePresence("MessageServicePresence").release()); // C. Manufacture a configuration and establish it. std::string config = "import FWCore.ParameterSet.Config as cms\n" "process = cms.Process('TEST')\n" "process.maxEvents = cms.untracked.PSet(\n" " input = cms.untracked.int32(5)\n" ")\n" "process.source = cms.Source('EmptySource')\n" "process.JobReportService = cms.Service('JobReportService')\n" "process.InitRootHandlers = cms.Service('InitRootHandlers')\n" // "process.MessageLogger = cms.Service('MessageLogger')\n" "process.m1 = cms.EDProducer('IntProducer',\n" " ivalue = cms.int32(11)\n" ")\n" "process.out = cms.OutputModule('PoolOutputModule',\n" " fileName = cms.untracked.string('testStandalone.root')\n" ")\n" "process.p = cms.Path(process.m1)\n" "process.e = cms.EndPath(process.out)\n"; boost::shared_ptr<std::vector<edm::ParameterSet> > pServiceSets; boost::shared_ptr<edm::ParameterSet> params_; edm::makeParameterSets(config, params_, pServiceSets); // D. Create the services. edm::ServiceToken tempToken(edm::ServiceRegistry::createSet(*pServiceSets.get())); // E. Make the services available. edm::ServiceRegistry::Operate operate(tempToken); // END Copy from example stand-alone program in Message Logger July 18, 2007 std::cout << "main::initialize DDL parser" << std::endl; DDCompactView cpv; DDLParser myP(cpv);// = DDLParser::instance(); // std::cout << "main:: about to start parsing field configuration..." << std::endl; // FIPConfiguration dp2; // dp2.readConfig("Geometry/CMSCommonData/data/FieldConfiguration.xml"); // myP->parse(dp2); std::cout << "main::about to start parsing main configuration... " << std::endl; FIPConfiguration dp(cpv); dp.readConfig("DetectorDescription/Parser/test/cmsIdealGeometryXML.xml"); myP.parse(dp); std::cout << "main::completed Parser" << std::endl; std::cout << std::endl << std::endl << "main::Start checking!" << std::endl << std::endl; DDCheckMaterials(std::cout); // cpv.setRoot(DDLogicalPart(DDName("cms:World"))); std::cout << "edge size of produce graph:" << cpv.writeableGraph().edge_size() << std::endl; DDExpandedView ev(cpv); std::cout << "== got the epv ==" << std::endl; // for now just count! std::ofstream plist("plist.out"); int numPhysParts(0); while ( ev.next() ) { ++numPhysParts; plist << ev.geoHistory() << std::endl; } plist.close(); std::cout << "Traversing the tree went to " << numPhysParts << " nodes, or \"PhysicalParts\" in online db terms." << std::endl; cpv.writeableGraph().clear(); // cpv.clear(); std::cout << "cleared DDCompactView. " << std::endl; } catch (DDException& e) { std::cerr << "DDD-PROBLEM:" << std::endl << e << std::endl; } // Deal with any exceptions that may have been thrown. catch (cms::Exception& e) { std::cout << "cms::Exception caught in " << kProgramName << "\n" << e.explainSelf(); rc = 1; } catch (std::exception& e) { std::cout << "Standard library exception caught in " << kProgramName << "\n" << e.what(); rc = 1; } catch (...) { std::cout << "Unknown exception caught in " << kProgramName; rc = 2; } return rc; }
int main(int argc, char *argv[]) { using Graph = DDCompactView::Graph; using adjl_iterator = Graph::const_adj_iterator; // Copied from example stand-alone program in Message Logger July 18, 2007 std::string const kProgramName = argv[0]; int rc = 0; try { // A. Instantiate a plug-in manager first. edm::AssertHandler ah; // B. Load the message service plug-in. Forget this and bad things happen! // In particular, the job hangs as soon as the output buffer fills up. // That's because, without the message service, there is no mechanism for // emptying the buffers. std::shared_ptr<edm::Presence> theMessageServicePresence; theMessageServicePresence = std::shared_ptr<edm::Presence>(edm::PresenceFactory::get()-> makePresence("MessageServicePresence").release()); // C. Manufacture a configuration and establish it. std::string config = "import FWCore.ParameterSet.Config as cms\n" "process = cms.Process('TEST')\n" "process.maxEvents = cms.untracked.PSet(\n" " input = cms.untracked.int32(5)\n" ")\n" "process.source = cms.Source('EmptySource')\n" "process.JobReportService = cms.Service('JobReportService')\n" "process.InitRootHandlers = cms.Service('InitRootHandlers')\n" // "process.MessageLogger = cms.Service('MessageLogger')\n" "process.m1 = cms.EDProducer('IntProducer',\n" " ivalue = cms.int32(11)\n" ")\n" "process.out = cms.OutputModule('PoolOutputModule',\n" " fileName = cms.untracked.string('testStandalone.root')\n" ")\n" "process.p = cms.Path(process.m1)\n" "process.e = cms.EndPath(process.out)\n"; // D. Create the services. std::unique_ptr<edm::ParameterSet> params; edm::makeParameterSets(config, params); edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params))); // E. Make the services available. edm::ServiceRegistry::Operate operate(tempToken); // END Copy from example stand-alone program in Message Logger July 18, 2007 std::cout << "main::initialize DDL parser" << std::endl; DDCompactView cpv; DDLParser myP(cpv);// = DDLParser::instance(); // std::cout << "main:: about to start parsing field configuration..." << std::endl; // FIPConfiguration dp2; // dp2.readConfig("Geometry/CMSCommonData/data/FieldConfiguration.xml"); // myP->parse(dp2); std::cout << "main::about to start parsing main configuration... " << std::endl; FIPConfiguration dp(cpv); dp.readConfig("DetectorDescription/Parser/test/cmsIdealGeometryXML.xml"); myP.parse(dp); std::cout << "main::completed Parser" << std::endl; std::cout << std::endl << std::endl << "main::Start checking!" << std::endl << std::endl; DDCheckMaterials(std::cout); // cpv.setRoot(DDLogicalPart(DDName("cms:World"))); std::cout << "edge size of produce graph:" << cpv.graph().edge_size() << std::endl; const auto& gt = cpv.graph(); adjl_iterator git = gt.begin(); adjl_iterator gend = gt.end(); Graph::index_type i=0; for (; git != gend; ++git) { const DDLogicalPart & ddLP = gt.nodeData(git); std::cout << ++i << " P " << ddLP.name() << std::endl; if (!git->empty()) { auto cit = git->begin(); auto cend = git->end(); for (; cit != cend; ++cit) { const DDLogicalPart & ddcurLP = gt.nodeData(cit->first); std::cout << ++i << " c--> " << gt.edgeData(cit->second)->copyno() << " " << ddcurLP.name() << std::endl; } } } } // Deal with any exceptions that may have been thrown. catch (cms::Exception& e) { std::cout << "cms::Exception caught in " << kProgramName << "\n" << e.explainSelf(); rc = 1; } catch (std::exception& e) { std::cout << "Standard library exception caught in " << kProgramName << "\n" << e.what(); rc = 1; } catch (...) { std::cout << "Unknown exception caught in " << kProgramName; rc = 2; } return rc; }
static int eval_expression_go(struct _asm_context *asm_context, struct _var *var, struct _operator *last_operator) { char token[TOKENLEN]; int token_type; struct _var var_stack[3]; int var_stack_ptr = 1; struct _operator operator; int last_token_was_op = -1; #ifdef DEBUG printf("Enter eval_expression_go, var=%d/%f/%d\n", var_get_int32(var), var_get_float(var), var_get_type(var)); #endif memcpy(&operator, last_operator, sizeof(struct _operator)); VAR_COPY(&var_stack[0], var); while(1) { #ifdef DEBUG printf("eval_expression> going to grab a token\n"); #endif token_type = tokens_get(asm_context, token, TOKENLEN); #ifdef DEBUG printf("eval_expression> token=%s var_stack_ptr=%d\n", token, var_stack_ptr); #endif // Issue 15: Return an error if a stack is full with noe operator. if (var_stack_ptr == 3 && operator.operation == OPER_UNSET) { return -1; } if (token_type == TOKEN_QUOTED) { if (token[0] == '\\') { int e = tokens_escape_char(asm_context, (unsigned char *)token); if (e == 0) return -1; if (token[e+1] != 0) { print_error("Quoted literal too long.", asm_context); return -1; } sprintf(token, "%d", token[e]); } else { if (token[1]!=0) { print_error("Quoted literal too long.", asm_context); return -1; } sprintf(token, "%d", token[0]); } token_type = TOKEN_NUMBER; } // Open and close parenthesis if (IS_TOKEN(token,'(')) { if (last_token_was_op == 0 && operator.operation != OPER_UNSET) { operate(&var_stack[var_stack_ptr-2], &var_stack[var_stack_ptr-1], last_operator); var_stack_ptr--; operator.operation = OPER_UNSET; VAR_COPY(var, &var_stack[var_stack_ptr-1]); tokens_push(asm_context, token, token_type); return 0; } if (operator.operation == OPER_UNSET && var_stack_ptr == 2) { // This is probably the x(r12) case.. so this is actually okay VAR_COPY(var, &var_stack[var_stack_ptr-1]); tokens_push(asm_context, token, token_type); return 0; } struct _var paren_var; struct _operator paren_operator; paren_operator.precedence = PREC_UNSET; paren_operator.operation = OPER_UNSET; memset(&paren_var, 0, sizeof(struct _var)); if (eval_expression_go(asm_context, &paren_var, &paren_operator) != 0) { return -1; } last_token_was_op = 0; #ifdef DEBUG printf("Paren got back %d/%f/%d\n", var_get_int32(&paren_var), var_get_float(&paren_var), var_get_type(&paren_var)); #endif VAR_COPY(&var_stack[var_stack_ptr++], &paren_var); token_type = tokens_get(asm_context, token, TOKENLEN); if (!(token[1] == 0 && token[0] == ')')) { print_error("No matching ')'", asm_context); return -1; } continue; } if (IS_TOKEN(token,')')) { tokens_push(asm_context, token, token_type); break; } // End of expression if (IS_TOKEN(token,',') || IS_TOKEN(token,']') || token_type == TOKEN_EOF || IS_TOKEN(token,'.')) { tokens_push(asm_context, token, token_type); break; } if (token_type == TOKEN_EOL) { //asm_context->tokens.line++; tokens_push(asm_context, token, token_type); break; } // Read number if (token_type == TOKEN_NUMBER) { last_token_was_op = 0; if (var_stack_ptr == 3) { print_error_unexp(token, asm_context); return -1; } var_set_int(&var_stack[var_stack_ptr++], atoll(token)); } else if (token_type == TOKEN_FLOAT) { if (var_stack_ptr == 3) { print_error_unexp(token, asm_context); return -1; } var_set_float(&var_stack[var_stack_ptr++], atof(token)); } else if (token_type == TOKEN_SYMBOL) { last_token_was_op = 1; struct _operator operator_prev; memcpy(&operator_prev, &operator, sizeof(struct _operator)); if (get_operator(token, &operator) == -1) { print_error_unexp(token, asm_context); return -1; } // Issue 15: 2015-July-21 mkohn - If operator is ~ then reverse // the next number. if (operator.operation == OPER_NOT) { int64_t num; if (parse_unary(asm_context, &num, OPER_NOT) != 0) { return -1; } if (var_stack_ptr == 3) { print_error_unexp(token, asm_context); return -1; } var_set_int(&var_stack[var_stack_ptr++], num); memcpy(&operator, &operator_prev, sizeof(struct _operator)); last_token_was_op = 0; continue; } // Stack pointer probably shouldn't be less than 2 if (var_stack_ptr == 0) { printf("Error: Unexpected operator '%s' at %s:%d\n", token, asm_context->tokens.filename, asm_context->tokens.line); return -1; } #ifdef DEBUG printf("TOKEN %s: precedence %d %d\n", token, last_operator->precedence, operator.precedence); #endif if (last_operator->precedence == PREC_UNSET) { memcpy(last_operator, &operator, sizeof(struct _operator)); } else if (last_operator->precedence > operator.precedence) { if (eval_expression_go(asm_context, &var_stack[var_stack_ptr-1], &operator) == -1) { return -1; } } else { operate(&var_stack[var_stack_ptr-2], &var_stack[var_stack_ptr-1], last_operator); var_stack_ptr--; memcpy(last_operator, &operator, sizeof(struct _operator)); } } else { if (asm_context->pass != 1) { print_error_unexp(token, asm_context); } return -1; } } #ifdef DEBUG printf("going to leave operation=%d\n", last_operator->operation); PRINT_STACK() #endif if (last_operator->operation != OPER_UNSET) { operate(&var_stack[var_stack_ptr-2], &var_stack[var_stack_ptr-1], last_operator); var_stack_ptr--; } VAR_COPY(var, &var_stack[var_stack_ptr-1]); return 0; }
void subf(stack * st) { operate(st, 5); }
void divf(stack * st) { operate(st, 7); }
ObStatManager & ObStatManager::subtract(const ObStatManager &minuend) { return operate(minuend, subop); }
int main(int argc,char *argv[]) { int rport=DEF_PORT,tport=1024,arg=0; int sock; int sc_reuseaddr=1,temp; unsigned char help=0; unsigned char option=0; socklen_t length; socklen_t clength; struct sockaddr_in server; struct sockaddr_in client; fd_set ready; struct hostent *gethostbyname(); pid_t root; char *chstr=NULL; int msgsock=0; prm=RadarParmMake(); fit=FitMake(); OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"rp",'i',&rport); OptionAdd(&opt,"tp",'i',&tport); OptionAdd(&opt,"eh",'t',&errhost); OptionAdd(&opt,"ep",'i',&errport); OptionAdd(&opt,"c",'t',&chstr); arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } if (chstr !=NULL) { if (tolower(chstr[0])=='a') channel=1; if (tolower(chstr[0])=='b') channel=2; } if (errhost==NULL) errhost=derrhost; errsock=TCPIPMsgOpen(errhost,errport); sprintf(errbuf,"Started (version %s.%s) listening on port %d for control program, and on port %d for clients", MAJOR_VERSION,MINOR_VERSION,rport,tport); ErrLog(errsock,taskname,errbuf); signal(SIGCHLD,SIG_IGN); signal(SIGPIPE,SIG_IGN); root=getpid(); sock=socket(AF_INET,SOCK_STREAM,0); /* create our listening socket */ if (sock<0) { perror("opening stream socket"); exit(1); } /* set socket options */ temp=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sc_reuseaddr, sizeof(sc_reuseaddr)); /* name and bind socket to an address and port number */ server.sin_family=AF_INET; server.sin_addr.s_addr=INADDR_ANY; if (rport !=0) server.sin_port=htons(rport); else server.sin_port=0; if (bind(sock,(struct sockaddr *) &server,sizeof(server))) { perror("binding stream socket"); exit(1); } /* Find out assigned port number and print it out */ length=sizeof(server); if (getsockname(sock,(struct sockaddr *) &server,&length)) { perror("getting socket name"); exit(1); } listen(sock,5); /* mark our socket willing to accept connections */ do { /* block until someone wants to attach to us */ FD_ZERO(&ready); FD_SET(sock,&ready); if (select(sock+1,&ready,0,0,NULL) < 0) { perror("while testing for connections"); continue; } /* Accept the connection from the client */ fprintf(stdout,"Accepting a new connection...\n"); clength=sizeof(client); msgsock=accept(sock,(struct sockaddr *) &client,&clength); if (msgsock==-1) { perror("accept"); continue; } if (fork() == 0) { close(sock); operate(root,msgsock,tport); exit(0); } close (msgsock); } while(1); return 0; }
/****************************************************************************** * FUNCTION NAME: binary_data_handler * DESCRIPTION: handle the recived binary data * PARAMETER: r_data :recived data struct * RETURNS: used sized * modification history * -------------------- * 2013/06/30, Q.Bryan create this function ******************************************************************************/ U8 binary_data_handler(void* bin) { CMD_PKG* cmd_ptr = (CMD_PKG*)bin; operate(cmd_ptr->dev_id,cmd_ptr->op_type,0); return sizeof(CMD_PKG); }
/****************************************************************************** * FUNCTION NAME: consultation_handler * DESCRIPTION: consultation with server * PARAMETER: r_data :recived data struct * RETURNS: used sized * modification history * -------------------- * 2013/08/22, Q.Bryan create this function ******************************************************************************/ U8 consultation_handler(void* bin) { CMD_PKG* cmd_ptr = (CMD_PKG*)bin; operate(cmd_ptr->dev_id,cmd_ptr->op_type,0); return sizeof(CMD_PKG); }
void testServiceRegistry::externalServiceTest() { art::AssertHandler ah; { std::unique_ptr<DummyService> dummyPtr(new DummyService); dummyPtr->value_ = 2; art::ServiceToken token(art::ServiceRegistry::createContaining(dummyPtr)); { art::ServiceRegistry::Operate operate(token); art::ServiceHandle<DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value_ == 2); } { std::vector<fhicl::ParameterSet> pss; fhicl::ParameterSet ps; std::string typeName("DummyService"); ps.addParameter("service_type", typeName); int value = 2; ps.addParameter("value", value); pss.push_back(ps); art::ServiceToken token(art::ServiceRegistry::createSet(pss)); art::ServiceToken token2(art::ServiceRegistry::createContaining(dummyPtr, token, art::serviceregistry::kOverlapIsError)); art::ServiceRegistry::Operate operate(token2); art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value() == 2); } } { std::unique_ptr<DummyService> dummyPtr(new DummyService); std::shared_ptr<art::serviceregistry::ServiceWrapper<DummyService> > wrapper(new art::serviceregistry::ServiceWrapper<DummyService>(dummyPtr)); art::ServiceToken token(art::ServiceRegistry::createContaining(wrapper)); wrapper->get().value_ = 2; { art::ServiceRegistry::Operate operate(token); art::ServiceHandle<DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value_ == 2); } { std::vector<fhicl::ParameterSet> pss; fhicl::ParameterSet ps; std::string typeName("DummyService"); ps.addParameter("service_type", typeName); int value = 2; ps.addParameter("value", value); pss.push_back(ps); art::ServiceToken token(art::ServiceRegistry::createSet(pss)); art::ServiceToken token2(art::ServiceRegistry::createContaining(dummyPtr, token, art::serviceregistry::kOverlapIsError)); art::ServiceRegistry::Operate operate(token2); art::ServiceHandle<testserviceregistry::DummyService> dummy; CPPUNIT_ASSERT(dummy); CPPUNIT_ASSERT(dummy.isAvailable()); CPPUNIT_ASSERT(dummy->value() == 2); } } }
void adds(stack *st) { operate(st, 8); }
int main() { try { edmplugin::PluginManager::configure(edmplugin::standard::config()); std::string config = "import FWCore.ParameterSet.Config as cms\n" "process = cms.Process('edmFileUtil')\n" "process.InitRootHandlers = cms.Service('InitRootHandlers')\n" "process.SiteLocalConfigService = cms.Service('SiteLocalConfigService')\n"; //create the services std::unique_ptr<edm::ParameterSet> params; edm::makeParameterSets(config, params); edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params))); //make the services available edm::ServiceRegistry::Operate operate(tempToken); { edm::FileLocator fl("", false); const char * lfn[] = { "/store/group/bha/bho", "/bha/bho", "bha", "file:bha", "file:/bha/bho", "/castor/cern.ch/cms/bha/bho", "rfio:/castor/cern.ch/cms/bha/bho", "rfio:/bha/bho" }; int nfile=8; std::cout << "lfn2pfn" << std::endl; for (int i=0; i<nfile; ++i) std::cout << lfn[i] << " -> " << fl.pfn(lfn[i]) << std::endl; std::cout << "pfn2lfn" << std::endl; for (int i=0; i<nfile; ++i) std::cout << lfn[i] << " -> " << fl.lfn(lfn[i]) << std::endl; } { std::string CMSSW_BASE(std::getenv("CMSSW_BASE")); std::string CMSSW_RELEASE_BASE(std::getenv("CMSSW_RELEASE_BASE")); std::string file_name("/src/FWCore/Catalog/test/override_catalog.xml"); std::string full_file_name = boost::filesystem::exists((CMSSW_BASE+file_name).c_str()) ? CMSSW_BASE+file_name : CMSSW_RELEASE_BASE+file_name; edm::FileLocator fl(("trivialcatalog_file:"+full_file_name+"?protocol=override").c_str(), false); const char * lfn[] = { "/store/unmerged/relval/CMSSW_3_8_0_pre3/RelValZTT/GEN-SIM-DIGI-RAW-HLTDEBUG/START38_V2-v1/0666/80EC0BCD-D279-DF11-B1DB-0030487C90EE.root", "/store/group/bha/bho", "/bha/bho", "bha", "file:bha", "file:/bha/bho", "/castor/cern.ch/cms/bha/bho", "rfio:/castor/cern.ch/cms/bha/bho", "rfio:/bha/bho" }; int nfile=9; std::cout << "lfn2pfn" << std::endl; for (int i=0; i<nfile; ++i) std::cout << lfn[i] << " -> " << fl.pfn(lfn[i]) << std::endl; std::cout << "pfn2lfn" << std::endl; for (int i=0; i<nfile; ++i) std::cout << lfn[i] << " -> " << fl.lfn(lfn[i]) << std::endl; } } catch (cms::Exception const & e) { std::cout << e.what() << std::endl; return 1; } catch (...) { std::cout << "got a problem..." << std::endl; return 1; } return 0; }
// arguments: # of bins and range for histogram to be tested DQMQualityTest(int NBINS, float XMIN, float XMAX) { // Process each file given as argument. edm::ParameterSet emptyps; std::vector<edm::ParameterSet> emptyset; edm::ServiceToken services(edm::ServiceRegistry::createSet(emptyset)); edm::ServiceRegistry::Operate operate(services); //dbe_ = edm::Service<DQMStore>().operator->(); DQMStore* dbe_ = new DQMStore(emptyps); xmin_ = XMIN; xmax_ = XMAX; // distribution: gaussian w/ parameters: mean, sigma mean = (xmin_ + xmax_)/2.0; sigma = (xmax_ - xmin_)/6.0; // reference histogram dbe_->setCurrentFolder("/Reference"); my_ref = dbe_->book1D("my_ref", "reference histo", NBINS, XMIN, XMAX); // test histogram dbe_->setCurrentFolder("/"); my_test = dbe_->book1D("my_test", "test histo", NBINS, XMIN, XMAX); dbe_->setCurrentFolder("/"); // Chi2-based test chi2_test_ = new Comp2RefChi2("my_chi2"); // Kolmogorov-based test ks_test_ = new Comp2RefKolmogorov("my_kolm"); // contents within x-range test xrange_test_ = new ContentsXRange("my_xrange"); // set allowed range to [10, 90]% of nominal xrange_test_->setAllowedXRange(0.1*xmin_, 0.9*xmax_); // contents within y-range test yrange_test_ = new ContentsYRange("my_yrange"); // set allowed range to [0, 40] entries yrange_test_->setAllowedYRange(0, 40); // check for dead channels deadChan_test_ = new DeadChannel("deadChan"); // set threshold for dead channel (default: 0) deadChan_test_->setThreshold(0); // check for noisy channels noisyChan_test_ = new NoisyChannel("noisyChan"); // set tolerance for noisy channel noisyChan_test_->setTolerance(0.30); // set # of neighboring channels for calculating average (default: 1) noisyChan_test_->setNumNeighbors(2); // Mean-within-expected-value test meanNear_test_ = new MeanWithinExpected("meanNear"); // set expected mean value meanNear_test_->setExpectedMean(mean); // use RMS of distribution to judge if mean near expected value meanNear_test_->useRMS(); // // emu_test_ = new AllContentWithinFixedRange("Ricks_test"); // MostProbableLandau //poMPLandau_test_ = new MostProbableLandau( "mplandau"); //poMPLandau_test_->setXMin( xmin_); //poMPLandau_test_->setXMax( xmax_); //poMPLandau_test_->setMostProbable( dLandauMP_); //poMPLandau_test_->setSigma( dLandauSigma_); // equality test for histograms equalH_test_ = new Comp2RefEqualH("my_histo_equal"); // equality test for integers // equalInt_test_ = new Comp2RefEqualInt("my_int_equal"); // init }
vmain() { register int c, cnt, i; char esave[TUBECOLS]; char *oglobp; char d; line *addr; int ind, nlput; int shouldpo = 0; int onumber, olist, (*OPline)(), (*OPutchar)(); vch_mac = VC_NOTINMAC; /* * If we started as a vi command (on the command line) * then go process initial commands (recover, next or tag). */ if (initev) { oglobp = globp; globp = initev; hadcnt = cnt = 0; i = tchng; addr = dot; goto doinit; } /* * NB: * * The current line is always in the line buffer linebuf, * and the cursor at the position cursor. You should do * a vsave() before moving off the line to make sure the disk * copy is updated if it has changed, and a getDOT() to get * the line back if you mung linebuf. The motion * routines in ex_vwind.c handle most of this. */ for (;;) { /* * Decode a visual command. * First sync the temp file if there has been a reasonable * amount of change. Clear state for decoding of next * command. */ TSYNC(); vglobp = 0; vreg = 0; hold = 0; seenprompt = 1; wcursor = 0; Xhadcnt = hadcnt = 0; Xcnt = cnt = 1; splitw = 0; if (i = holdupd) { if (state == VISUAL) ignore(peekkey()); holdupd = 0; /* if (LINE(0) < ZERO) { vclear(); vcnt = 0; i = 3; } */ if (state != VISUAL) { vcnt = 0; vsave(); vrepaint(cursor); } else if (i == 3) vredraw(WTOP); else vsync(WTOP); vfixcurs(); } /* * Gobble up counts and named buffer specifications. */ for (;;) { looptop: #ifdef MDEBUG if (trace) fprintf(trace, "pc=%c",peekkey()); #endif if (isdigit(peekkey()) && peekkey() != '0') { hadcnt = 1; cnt = vgetcnt(); forbid (cnt <= 0); } if (peekkey() != '"') break; ignore(getkey()), c = getkey(); /* * Buffer names be letters or digits. * But not '0' as that is the source of * an 'empty' named buffer spec in the routine * kshift (see ex_temp.c). */ forbid (c == '0' || !isalpha(c) && !isdigit(c)); vreg = c; } reread: /* * Come to reread from below after some macro expansions. * The call to map allows use of function key pads * by performing a terminal dependent mapping of inputs. */ #ifdef MDEBUG if (trace) fprintf(trace,"pcb=%c,",peekkey()); #endif op = getkey(); maphopcnt = 0; do { /* * Keep mapping the char as long as it changes. * This allows for double mappings, e.g., q to #, * #1 to something else. */ c = op; op = map(c,arrows); #ifdef MDEBUG if (trace) fprintf(trace,"pca=%c,",c); #endif /* * Maybe the mapped to char is a count. If so, we have * to go back to the "for" to interpret it. Likewise * for a buffer name. */ if ((isdigit(c) && c!='0') || c == '"') { ungetkey(c); goto looptop; } if (!value(REMAP)) { c = op; break; } if (++maphopcnt > 256) error("Infinite macro loop"); } while (c != op); /* * Begin to build an image of this command for possible * later repeat in the buffer workcmd. It will be copied * to lastcmd by the routine setLAST * if/when completely specified. */ lastcp = workcmd; if (!vglobp) *lastcp++ = c; /* * First level command decode. */ switch (c) { /* * ^L Clear screen e.g. after transmission error. */ /* * ^R Retype screen, getting rid of @ lines. * If in open, equivalent to ^L. * On terminals where the right arrow key sends * ^L we make ^R act like ^L, since there is no * way to get ^L. These terminals (adm31, tvi) * are intelligent so ^R is useless. Soroc * will probably foul this up, but nobody has * one of them. */ case CTRL(l): case CTRL(r): if (c == CTRL(l) || (KR && *KR==CTRL(l))) { vclear(); vdirty(0, vcnt); } if (state != VISUAL) { /* * Get a clean line, throw away the * memory of what is displayed now, * and move back onto the current line. */ vclean(); vcnt = 0; vmoveto(dot, cursor, 0); continue; } vredraw(WTOP); /* * Weird glitch -- when we enter visual * in a very small window we may end up with * no lines on the screen because the line * at the top is too long. This forces the screen * to be expanded to make room for it (after * we have printed @'s ick showing we goofed). */ if (vcnt == 0) vrepaint(cursor); vfixcurs(); continue; /* * $ Escape just cancels the current command * with a little feedback. */ case ESCAPE: beep(); continue; /* * @ Macros. Bring in the macro and put it * in vmacbuf, point vglobp there and punt. */ case '@': c = getesc(); if (c == 0) continue; if (c == '@') c = lastmac; if (isupper(c)) c = tolower(c); forbid(!islower(c)); lastmac = c; vsave(); CATCH char tmpbuf[BUFSIZ]; regbuf(c,tmpbuf,sizeof(vmacbuf)); macpush(tmpbuf, 1); ONERR lastmac = 0; splitw = 0; getDOT(); vrepaint(cursor); continue; ENDCATCH vmacp = vmacbuf; goto reread; /* * . Repeat the last (modifying) open/visual command. */ case '.': /* * Check that there was a last command, and * take its count and named buffer unless they * were given anew. Special case if last command * referenced a numeric named buffer -- increment * the number and go to a named buffer again. * This allows a sequence like "1pu.u.u... * to successively look for stuff in the kill chain * much as one does in EMACS with C-Y and M-Y. */ forbid (lastcmd[0] == 0); if (hadcnt) lastcnt = cnt; if (vreg) lastreg = vreg; else if (isdigit(lastreg) && lastreg < '9') lastreg++; vreg = lastreg; cnt = lastcnt; hadcnt = lasthad; vglobp = lastcmd; goto reread; /* * ^U Scroll up. A count sticks around for * future scrolls as the scroll amount. * Attempt to hold the indentation from the * top of the screen (in logical lines). * * BUG: A ^U near the bottom of the screen * on a dumb terminal (which can't roll back) * causes the screen to be cleared and then * redrawn almost as it was. In this case * one should simply move the cursor. */ case CTRL(u): if (hadcnt) vSCROLL = cnt; cnt = vSCROLL; if (state == VISUAL) ind = vcline, cnt += ind; else ind = 0; vmoving = 0; vup(cnt, ind, 1); vnline(NOSTR); continue; /* * ^D Scroll down. Like scroll up. */ case CTRL(d): #ifdef TRACE if (trace) fprintf(trace, "before vdown in ^D, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol)); #endif if (hadcnt) vSCROLL = cnt; cnt = vSCROLL; if (state == VISUAL) ind = vcnt - vcline - 1, cnt += ind; else ind = 0; vmoving = 0; vdown(cnt, ind, 1); #ifdef TRACE if (trace) fprintf(trace, "before vnline in ^D, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol)); #endif vnline(NOSTR); #ifdef TRACE if (trace) fprintf(trace, "after vnline in ^D, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol)); #endif continue; /* * ^E Glitch the screen down (one) line. * Cursor left on same line in file. */ case CTRL(e): if (state != VISUAL) continue; if (!hadcnt) cnt = 1; /* Bottom line of file already on screen */ forbid(lineDOL()-lineDOT() <= vcnt-1-vcline); ind = vcnt - vcline - 1 + cnt; vdown(ind, ind, 1); vnline(cursor); continue; /* * ^Y Like ^E but up */ case CTRL(y): if (state != VISUAL) continue; if (!hadcnt) cnt = 1; forbid(lineDOT()-1<=vcline); /* line 1 already there */ ind = vcline + cnt; vup(ind, ind, 1); vnline(cursor); continue; /* * m Mark position in mark register given * by following letter. Return is * accomplished via ' or `; former * to beginning of line where mark * was set, latter to column where marked. */ case 'm': /* * Getesc is generally used when a character * is read as a latter part of a command * to allow one to hit rubout/escape to cancel * what you have typed so far. These characters * are mapped to 0 by the subroutine. */ c = getesc(); if (c == 0) continue; /* * Markreg checks that argument is a letter * and also maps ' and ` to the end of the range * to allow '' or `` to reference the previous * context mark. */ c = markreg(c); forbid (c == 0); vsave(); names[c - 'a'] = (*dot &~ 01); ncols[c - 'a'] = cursor; anymarks = 1; continue; /* * ^F Window forwards, with 2 lines of continuity. * Count repeats. */ case CTRL(f): vsave(); if (vcnt > 2) { addr = dot + (vcnt - vcline) - 2 + (cnt-1)*basWLINES; forbid(addr > dol); dot = addr; vcnt = vcline = 0; } vzop(0, 0, '+'); continue; /* * ^B Window backwards, with 2 lines of continuity. * Inverse of ^F. */ case CTRL(b): vsave(); if (one + vcline != dot && vcnt > 2) { addr = dot - vcline - 2 + (cnt-1)*basWLINES; forbid (addr <= zero); dot = addr; vcnt = vcline = 0; } vzop(0, 0, '^'); continue; /* * z Screen adjustment, taking a following character: * z<CR> current line to top * z<NL> like z<CR> * z- current line to bottom * also z+, z^ like ^F and ^B. * A preceding count is line to use rather * than current line. A count between z and * specifier character changes the screen size * for the redraw. * */ case 'z': if (state == VISUAL) { i = vgetcnt(); if (i > 0) vsetsiz(i); c = getesc(); if (c == 0) continue; } vsave(); vzop(hadcnt, cnt, c); continue; /* * Y Yank lines, abbreviation for y_ or yy. * Yanked lines can be put later if no * changes intervene, or can be put in named * buffers and put anytime in this session. */ case 'Y': ungetkey('_'); c = 'y'; break; /* * J Join lines, 2 by default. Count is number * of lines to join (no join operator sorry.) */ case 'J': forbid (dot == dol); if (cnt == 1) cnt = 2; if (cnt > (i = dol - dot + 1)) cnt = i; vsave(); vmacchng(1); setLAST(); cursor = strend(linebuf); vremote(cnt, join, 0); notenam = "join"; vmoving = 0; killU(); vreplace(vcline, cnt, 1); if (!*cursor && cursor > linebuf) cursor--; if (notecnt == 2) notecnt = 0; vrepaint(cursor); continue; /* * S Substitute text for whole lines, abbrev for c_. * Count is number of lines to change. */ case 'S': ungetkey('_'); c = 'c'; break; /* * O Create a new line above current and accept new * input text, to an escape, there. * A count specifies, for dumb terminals when * slowopen is not set, the number of physical * line space to open on the screen. * * o Like O, but opens lines below. */ case 'O': case 'o': vmacchng(1); voOpen(c, cnt); continue; /* * C Change text to end of line, short for c$. */ case 'C': if (*cursor) { ungetkey('$'), c = 'c'; break; } goto appnd; /* * ~ Switch case of letter under cursor */ case '~': { char mbuf[4]; setLAST(); mbuf[0] = 'r'; mbuf[1] = *cursor; mbuf[2] = cursor[1]==0 ? 0 : ' '; mbuf[3] = 0; if (isalpha(mbuf[1])) mbuf[1] ^= ' '; /* toggle the case */ macpush(mbuf, 1); } continue; /* * A Append at end of line, short for $a. */ case 'A': operate('$', 1); appnd: c = 'a'; /* fall into ... */ /* * a Appends text after cursor. Text can continue * through arbitrary number of lines. */ case 'a': if (*cursor) { if (state == HARDOPEN) putchar(*cursor); cursor++; } goto insrt; /* * I Insert at beginning of whitespace of line, * short for ^i. */ case 'I': operate('^', 1); c = 'i'; /* fall into ... */ /* * R Replace characters, one for one, by input * (logically), like repeated r commands. * * BUG: This is like the typeover mode of many other * editors, and is only rarely useful. Its * implementation is a hack in a low level * routine and it doesn't work very well, e.g. * you can't move around within a R, etc. */ case 'R': /* fall into... */ /* * i Insert text to an escape in the buffer. * Text is arbitrary. This command reminds of * the i command in bare teco. */ case 'i': insrt: /* * Common code for all the insertion commands. * Save for redo, position cursor, prepare for append * at command and in visual undo. Note that nothing * is doomed, unless R when all is, and save the * current line in a the undo temporary buffer. */ vmacchng(1); setLAST(); vcursat(cursor); prepapp(); vnoapp(); doomed = c == 'R' ? 10000 : 0; if(FIXUNDO) vundkind = VCHNG; vmoving = 0; CP(vutmp, linebuf); /* * If this is a repeated command, then suppress * fake insert mode on dumb terminals which looks * ridiculous and wastes lots of time even at 9600B. */ if (vglobp) hold = HOLDQIK; vappend(c, cnt, 0); continue; /* * ^? An attention, normally a ^?, just beeps. * If you are a vi command within ex, then * two ATTN's will drop you back to command mode. */ case ATTN: beep(); if (initev || peekkey() != ATTN) continue; /* fall into... */ /* * ^\ A quit always gets command mode. */ case QUIT: /* * Have to be careful if we were called * g/xxx/vi * since a return will just start up again. * So we simulate an interrupt. */ if (inglobal) onintr(); /* fall into... */ #ifdef notdef /* * q Quit back to command mode, unless called as * vi on command line in which case dont do it */ case 'q': /* quit */ if (initev) { vsave(); CATCH error("Q gets ex command mode, :q leaves vi"); ENDCATCH splitw = 0; getDOT(); vrepaint(cursor); continue; } #endif /* fall into... */ /* * Q Is like q, but always gets to command mode * even if command line invocation was as vi. */ case 'Q': vsave(); /* * If we are in the middle of a macro, throw away * the rest and fix up undo. * This code copied from getbr(). */ if (vmacp) { vmacp = 0; if (inopen == -1) /* don't screw up undo for esc esc */ vundkind = VMANY; inopen = 1; /* restore old setting now that macro done */ } return; /* * ZZ Like :x */ case 'Z': forbid(getkey() != 'Z'); oglobp = globp; globp = "x"; vclrech(0); goto gogo; /* * P Put back text before cursor or before current * line. If text was whole lines goes back * as whole lines. If part of a single line * or parts of whole lines splits up current * line to form many new lines. * May specify a named buffer, or the delete * saving buffers 1-9. * * p Like P but after rather than before. */ case 'P': case 'p': vmoving = 0; #ifdef notdef forbid (!vreg && value(UNDOMACRO) && inopen < 0); #endif /* * If previous delete was partial line, use an * append or insert to put it back so as to * use insert mode on intelligent terminals. */ if (!vreg && DEL[0]) { forbid ((DEL[0] & (QUOTE|TRIM)) == OVERBUF); vglobp = DEL; ungetkey(c == 'p' ? 'a' : 'i'); goto reread; } /* * If a register wasn't specified, then make * sure there is something to put back. */ forbid (!vreg && unddol == dol); /* * If we just did a macro the whole buffer is in * the undo save area. We don't want to put THAT. */ forbid (vundkind == VMANY && undkind==UNDALL); vsave(); vmacchng(1); setLAST(); i = 0; if (vreg && partreg(vreg) || !vreg && pkill[0]) { /* * Restoring multiple lines which were partial * lines; will leave cursor in middle * of line after shoving restored text in to * split the current line. */ i++; if (c == 'p' && *cursor) cursor++; } else { /* * In whole line case, have to back up dot * for P; also want to clear cursor so * cursor will eventually be positioned * at the beginning of the first put line. */ cursor = 0; if (c == 'P') { dot--, vcline--; c = 'p'; } } killU(); /* * The call to putreg can potentially * bomb since there may be nothing in a named buffer. * We thus put a catch in here. If we didn't and * there was an error we would end up in command mode. */ addr = dol; /* old dol */ CATCH vremote(1, vreg ? putreg : put, vreg); ONERR if (vreg == -1) { splitw = 0; if (op == 'P') dot++, vcline++; goto pfixup; } ENDCATCH splitw = 0; nlput = dol - addr + 1; if (!i) { /* * Increment undap1, undap2 to make up * for their incorrect initialization in the * routine vremote before calling put/putreg. */ if (FIXUNDO) undap1++, undap2++; vcline++; nlput--; /* * After a put want current line first line, * and dot was made the last line put in code * run so far. This is why we increment vcline * above and decrease dot here. */ dot -= nlput - 1; } #ifdef TRACE if (trace) fprintf(trace, "vreplace(%d, %d, %d), undap1=%d, undap2=%d, dot=%d\n", vcline, i, nlput, lineno(undap1), lineno(undap2), lineno(dot)); #endif vreplace(vcline, i, nlput); if (state != VISUAL) { /* * Special case in open mode. * Force action on the screen when a single * line is put even if it is identical to * the current line, e.g. on YP; otherwise * you can't tell anything happened. */ vjumpto(dot, cursor, '.'); continue; } pfixup: vrepaint(cursor); vfixcurs(); continue; /* * ^^ Return to previous file. * Like a :e #, and thus can be used after a * "No Write" diagnostic. */ case CTRL(^): forbid (hadcnt); vsave(); ckaw(); oglobp = globp; if (value(AUTOWRITE)) globp = "e! #"; else globp = "e #"; goto gogo; /* * ^] Takes word after cursor as tag, and then does * tag command. Read ``go right to''. */ case CTRL(]): grabtag(); oglobp = globp; globp = "tag"; goto gogo; /* * & Like :& */ case '&': oglobp = globp; globp = "&"; goto gogo; /* * ^G Bring up a status line at the bottom of * the screen, like a :file command. * * BUG: Was ^S but doesn't work in cbreak mode */ case CTRL(g): oglobp = globp; globp = "file"; gogo: addr = dot; vsave(); goto doinit; #ifdef SIGTSTP /* * ^Z: suspend editor session and temporarily return * to shell. Only works with Berkeley/IIASA process * control in kernel. */ case CTRL(z): forbid(dosusp == 0 || !ldisc); vsave(); oglobp = globp; globp = "stop"; goto gogo; #endif /* * : Read a command from the echo area and * execute it in command mode. */ case ':': forbid (hadcnt); vsave(); i = tchng; addr = dot; if (readecho(c)) { esave[0] = 0; goto fixup; } getDOT(); /* * Use the visual undo buffer to store the global * string for command mode, since it is idle right now. */ oglobp = globp; strcpy(vutmp, genbuf+1); globp = vutmp; doinit: esave[0] = 0; fixech(); /* * Have to finagle around not to lose last * character after this command (when run from ex * command mode). This is clumsy. */ d = peekc; ungetchar(0); if (shouldpo) { /* * So after a "Hit return..." ":", we do * another "Hit return..." the next time */ pofix(); shouldpo = 0; } CATCH /* * Save old values of options so we can * notice when they change; switch into * cooked mode so we are interruptible. */ onumber = value(NUMBER); olist = value(LIST); OPline = Pline; OPutchar = Putchar; #ifndef CBREAK vcook(); #endif commands(1, 1); if (dot == zero && dol > zero) dot = one; #ifndef CBREAK vraw(); #endif ONERR #ifndef CBREAK vraw(); #endif copy(esave, vtube[WECHO], TUBECOLS); ENDCATCH fixol(); Pline = OPline; Putchar = OPutchar; ungetchar(d); globp = oglobp; /* * If we ended up with no lines in the buffer, make * a line, and don't consider the buffer changed. */ if (dot == zero) { fixzero(); sync(); } splitw = 0; /* * Special case: did list/number options change? */ if (onumber != value(NUMBER)) setnumb(value(NUMBER)); if (olist != value(LIST)) setlist(value(LIST)); fixup: /* * If a change occurred, other than * a write which clears changes, then * we should allow an undo even if . * didn't move. * * BUG: You can make this wrong by * tricking around with multiple commands * on one line of : escape, and including * a write command there, but its not * worth worrying about. */ if (FIXUNDO && tchng && tchng != i) vundkind = VMANY, cursor = 0; /* * If we are about to do another :, hold off * updating of screen. */ if (vcnt < 0 && Peekkey == ':') { getDOT(); shouldpo = 1; continue; } shouldpo = 0; /* * In the case where the file being edited is * new; e.g. if the initial state hasn't been * saved yet, then do so now. */ if (unddol == truedol) { vundkind = VNONE; Vlines = lineDOL(); if (!inglobal) savevis(); addr = zero; vcnt = 0; if (esave[0] == 0) copy(esave, vtube[WECHO], TUBECOLS); } /* * If the current line moved reset the cursor position. */ if (dot != addr) { vmoving = 0; cursor = 0; } /* * If current line is not on screen or if we are * in open mode and . moved, then redraw. */ i = vcline + (dot - addr); if (i < 0 || i >= vcnt && i >= -vcnt || state != VISUAL && dot != addr) { if (state == CRTOPEN) vup1(); if (vcnt > 0) vcnt = 0; vjumpto(dot, (char *) 0, '.'); } else { /* * Current line IS on screen. * If we did a [Hit return...] then * restore vcnt and clear screen if in visual */ vcline = i; if (vcnt < 0) { vcnt = -vcnt; if (state == VISUAL) vclear(); else if (state == CRTOPEN) { vcnt = 0; } } /* * Limit max value of vcnt based on $ */ i = vcline + lineDOL() - lineDOT() + 1; if (i < vcnt) vcnt = i; /* * Dirty and repaint. */ vdirty(0, LINES); vrepaint(cursor); } /* * If in visual, put back the echo area * if it was clobberred. */ if (state == VISUAL) { int sdc = destcol, sdl = destline; splitw++; vigoto(WECHO, 0); for (i = 0; i < TUBECOLS - 1; i++) { if (esave[i] == 0) break; vputchar(esave[i]); } splitw = 0; vgoto(sdl, sdc); } continue; /* * u undo the last changing command. */ case 'u': vundo(1); continue; /* * U restore current line to initial state. */ case 'U': vUndo(); continue; fonfon: beep(); vmacp = 0; inopen = 1; /* might have been -1 */ continue; } /* * Rest of commands are decoded by the operate * routine. */ operate(c, cnt); } }
void mulf(stack * st) { operate(st, 6); }
ObStatManager & ObStatManager::add(const ObStatManager &augend) { return operate(augend, addop); }
int main(int argc, char* argv[]) { gErrorIgnoreLevel = kError; // Add options here boost::program_options::options_description desc("Allowed options"); desc.add_options() ("help,h", "print help message") ("file,f", boost::program_options::value<std::vector<std::string> >(), "data file (-f or -F required)") ("Files,F", boost::program_options::value<std::string>(), "text file containing names of data files, one per line") ("catalog,c", boost::program_options::value<std::string>(), "catalog") ("decodeLFN,d", "Convert LFN to PFN") ("uuid,u", "Print uuid") ("adler32,a", "Print adler32 checksum.") ("allowRecovery", "Allow root to auto-recover corrupted files") ("JSON,j", "JSON output format. Any arguments listed below are ignored") ("ls,l", "list file content") ("print,P", "Print all") ("verbose,v", "Verbose printout") ("printBranchDetails,b", "Call Print()sc for all branches") ("tree,t", boost::program_options::value<std::string>(), "Select tree used with -P and -b options") ("events,e", "Print list of all Events, Runs, and LuminosityBlocks in the file sorted by run number, luminosity block number, and event number. Also prints the entry numbers and whether it is possible to use fast copy with the file.") ("eventsInLumis","Print how many Events are in each LuminosityBlock."); // What trees do we require for this to be a valid collection? std::vector<std::string> expectedTrees; expectedTrees.push_back(edm::poolNames::metaDataTreeName()); expectedTrees.push_back(edm::poolNames::eventTreeName()); boost::program_options::positional_options_description p; p.add("file", -1); boost::program_options::variables_map vm; try { boost::program_options::store(boost::program_options::command_line_parser(argc, argv). options(desc).positional(p).run(), vm); } catch (boost::program_options::error const& x) { std::cerr << "Option parsing failure:\n" << x.what() << "\n\n"; std::cerr << desc << "\n"; return 1; } boost::program_options::notify(vm); if (vm.count("help")) { std::cout << desc << "\n"; return 1; } int rc = 0; try { std::auto_ptr<edm::SiteLocalConfig> slcptr(new edm::service::SiteLocalConfigService(edm::ParameterSet())); boost::shared_ptr<edm::serviceregistry::ServiceWrapper<edm::SiteLocalConfig> > slc(new edm::serviceregistry::ServiceWrapper<edm::SiteLocalConfig>(slcptr)); edm::ServiceToken slcToken = edm::ServiceRegistry::createContaining(slc); edm::ServiceRegistry::Operate operate(slcToken); std::vector<std::string> in = (vm.count("file") ? vm["file"].as<std::vector<std::string> >() : std::vector<std::string>()); if (vm.count("Files")) { std::ifstream ifile(vm["Files"].as<std::string>().c_str()); std::istream_iterator<std::string> beginItr(ifile); if (ifile.fail()) { std::cout << "File '" << vm["Files"].as<std::string>() << "' not found, not opened, or empty\n"; return 1; } std::istream_iterator<std::string> endItr; copy(beginItr, endItr, back_inserter(in)); } if (in.empty()) { std::cout << "Data file(s) not set.\n"; std::cout << desc << "\n"; return 1; } std::string catalogIn = (vm.count("catalog") ? vm["catalog"].as<std::string>() : std::string()); bool decodeLFN = vm.count("decodeLFN"); bool uuid = vm.count("uuid"); bool adler32 = vm.count("adler32"); bool allowRecovery = vm.count("allowRecovery"); bool json = vm.count("JSON"); bool more = !json; bool verbose = more && (vm.count("verbose") > 0 ? true : false); bool events = more && (vm.count("events") > 0 ? true : false); bool eventsInLumis = more && (vm.count("eventsInLumis") > 0 ? true : false); bool ls = more && (vm.count("ls") > 0 ? true : false); bool tree = more && (vm.count("tree") > 0 ? true : false); bool print = more && (vm.count("print") > 0 ? true : false); bool printBranchDetails = more && (vm.count("printBranchDetails") > 0 ? true : false); bool onlyDecodeLFN = decodeLFN && !(uuid || adler32 || allowRecovery || json || events || tree || ls || print || printBranchDetails); std::string selectedTree = tree ? vm["tree"].as<std::string>() : edm::poolNames::eventTreeName().c_str(); if (events||eventsInLumis) { try { edmplugin::PluginManager::configure(edmplugin::standard::config()); } catch(std::exception& e) { std::cout << "exception caught in EdmFileUtil while configuring the PluginManager\n" << e.what(); return 1; } edm::RootAutoLibraryLoader::enable(); } edm::InputFileCatalog catalog(in, catalogIn, true); std::vector<std::string> const& filesIn = catalog.fileNames(); if (json) { std::cout << '[' << std::endl; } // now run.. // Allow user to input multiple files for(unsigned int j = 0; j < in.size(); ++j) { // We _only_ want the LFN->PFN conversion. No need to open the file, // just check the catalog and move on if (onlyDecodeLFN) { std::cout << filesIn[j] << std::endl; continue; } // open a data file if (!json) std::cout << in[j] << "\n"; std::string const& lfn = in[j]; TFile *tfile = edm::openFileHdl(filesIn[j]); if (tfile == 0) return 1; std::string const& pfn = filesIn[j]; if (verbose) std::cout << "ECU:: Opened " << pfn << std::endl; std::string datafile = decodeLFN ? pfn : lfn; // First check that this file is not auto-recovered // Stop the job unless specified to do otherwise bool isRecovered = tfile->TestBit(TFile::kRecovered); if (isRecovered) { if (allowRecovery) { if (!json) { std::cout << pfn << " appears not to have been closed correctly and has been autorecovered \n"; std::cout << "Proceeding anyway\n"; } } else { std::cout << pfn << " appears not to have been closed correctly and has been autorecovered \n"; std::cout << "Stopping. Use --allowRecovery to try ignoring this\n"; return 1; } } else { if (verbose) std::cout << "ECU:: Collection not autorecovered. Continuing\n"; } // Ok. Do we have the expected trees? for (unsigned int i = 0; i < expectedTrees.size(); ++i) { TTree *t = (TTree*) tfile->Get(expectedTrees[i].c_str()); if (t == 0) { std::cout << "Tree " << expectedTrees[i] << " appears to be missing. Not a valid collection\n"; std::cout << "Exiting\n"; return 1; } else { if (verbose) std::cout << "ECU:: Found Tree " << expectedTrees[i] << std::endl; } } if (verbose) std::cout << "ECU:: Found all expected trees\n"; std::ostringstream auout; if (adler32) { unsigned int const EDMFILEUTILADLERBUFSIZE = 10*1024*1024; // 10MB buffer char buffer[EDMFILEUTILADLERBUFSIZE]; size_t bufToRead = EDMFILEUTILADLERBUFSIZE; uint32_t a = 1, b = 0; size_t fileSize = tfile->GetSize(); tfile->Seek(0, TFile::kBeg); for (size_t offset = 0; offset < fileSize; offset += EDMFILEUTILADLERBUFSIZE) { // true on last loop if (fileSize - offset < EDMFILEUTILADLERBUFSIZE) bufToRead = fileSize - offset; tfile->ReadBuffer((char*)buffer, bufToRead); cms::Adler32(buffer, bufToRead, a, b); } uint32_t adler32sum = (b << 16) | a; if (json) { auout << ",\"adler32sum\":" << adler32sum; } else { auout << ", " << std::hex << adler32sum << " adler32sum"; } } if (uuid) { TTree *paramsTree = (TTree*)tfile->Get(edm::poolNames::metaDataTreeName().c_str()); if (json) { auout << ",\"uuid\":\"" << edm::getUuid(paramsTree) << '"'; } else { auout << ", " << edm::getUuid(paramsTree) << " uuid"; } } // Ok. How many events? int nruns = edm::numEntries(tfile, edm::poolNames::runTreeName()); int nlumis = edm::numEntries(tfile, edm::poolNames::luminosityBlockTreeName()); int nevents = edm::numEntries(tfile, edm::poolNames::eventTreeName()); if (json) { if (j > 0) std::cout << ',' << std::endl; std::cout << "{\"file\":\"" << datafile << '"' << ",\"runs\":" << nruns << ",\"lumis\":" << nlumis << ",\"events\":" << nevents << ",\"bytes\":" << tfile->GetSize() << auout.str() << '}' << std::endl; } else { std::cout << datafile << " (" << nruns << " runs, " << nlumis << " lumis, " << nevents << " events, " << tfile->GetSize() << " bytes" << auout.str() << ")" << std::endl; } if (json) { // Remainder of arguments not supported in JSON yet. continue; } // Look at the collection contents if (ls) { if (tfile != 0) tfile->ls(); } // Print out each tree if (print) { TTree *printTree = (TTree*)tfile->Get(selectedTree.c_str()); if (printTree == 0) { std::cout << "Tree " << selectedTree << " appears to be missing. Could not find it in the file.\n"; std::cout << "Exiting\n"; return 1; } edm::printBranchNames(printTree); } if (printBranchDetails) { TTree *printTree = (TTree*)tfile->Get(selectedTree.c_str()); if (printTree == 0) { std::cout << "Tree " << selectedTree << " appears to be missing. Could not find it in the file.\n"; std::cout << "Exiting\n"; return 1; } edm::longBranchPrint(printTree); } // Print out event lists if (events) { edm::printEventLists(tfile); } if(eventsInLumis) { edm::printEventsInLumis(tfile); } tfile->Close(); } if (json) { std::cout << ']' << std::endl; } } catch (cms::Exception const& e) { std::cout << "cms::Exception caught in " <<"EdmFileUtil" << '\n' << e.explainSelf(); rc = 1; } catch (std::exception const& e) { std::cout << "Standard library exception caught in " << "EdmFileUtil" << '\n' << e.what(); rc = 1; } catch (...) { std::cout << "Unknown exception caught in " << "EdmFileUtil"; rc = 2; } return rc; }
void /*ARGSUSED*/ dolet(Char **v, struct command *t) { Char *p; Char *vp, c, op; bool hadsub; int subscr; v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; vp = p; if (letter(*p)) for (; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) stderror(ERR_NAME | ERR_VARBEGIN); if ((p - vp) > MAXVARLEN) stderror(ERR_NAME | ERR_VARTOOLONG); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p == 0 && *v) p = *v++; if ((op = *p) != '\0') *p++ = 0; else stderror(ERR_NAME | ERR_ASSIGN); if (*p == '\0' && *v == NULL) stderror(ERR_NAME | ERR_ASSIGN); vp = Strsave(vp); if (op == '=') { c = '='; p = xset(p, &v); } else { c = *p++; if (any("+-", c)) { if (c != op || *p) stderror(ERR_NAME | ERR_UNKNOWNOP); p = Strsave(STR1); } else { if (any("<>", op)) { if (c != op) stderror(ERR_NAME | ERR_UNKNOWNOP); c = *p++; stderror(ERR_NAME | ERR_SYNTAX); } if (c != '=') stderror(ERR_NAME | ERR_UNKNOWNOP); p = xset(p, &v); } } if (op == '=') if (hadsub) asx(vp, subscr, p); else set(vp, p); else if (hadsub) { struct varent *gv = getvx(vp, subscr); asx(vp, subscr, operate(op, gv->vec[subscr - 1], p)); } else set(vp, operate(op, value(vp), p)); if (eq(vp, STRpath)) { exportpath(adrof(STRpath)->vec); dohash(NULL, NULL); } free(vp); if (c != '=') free(p); } while ((p = *v++) != NULL); }
void FileMgr::operate(const char* pattern, bool dirs, OperateCB cb, InternalOperateCB cb2) { // exactly one of these should be set WTON_ASSERT(cb == NULL || cb2 == NULL); WTON_ASSERT(cb || cb2); String pat(pattern); if (pat.endsWith("\\")) { pat = pat.substr(0, pat.len() - 1); } String ipath; // we'll be gentle, promise! char* sz = const_cast<char*>(pat.cStr()); bool wild = false; char* dir = NULL; while (*sz) { if (*sz == '/' || *sz == '\\') { if (wild) { *sz = 0; gSzs.push_back(sz); gCBs.push_back(cb); gCB2s.push_back(cb2); // recurse wildcard dirs to expand them operate(pat.cStr(), true, NULL, internalOperateCB); gSzs.pop_back(); gCBs.pop_back(); gCB2s.pop_back(); *sz = '\\'; return; } *sz = '\\'; dir = sz; } else if (*sz == '*') wild = true; ++sz; } #ifdef WTON_PC const char* qpat = pat.cStr(); WIN32_FIND_DATA data; // FindFirstFileEx ? HANDLE hResult = FindFirstFile(qpat, &data); if (hResult == INVALID_HANDLE_VALUE) return; if (dir) { *dir = 0; ipath = pat; *dir = '\\'; } do { // TODO: support .dotfiles if (startsWith(data.cFileName, ".")) continue; if (dirs == ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)) { String fullname(dir ? strCat(ipath, "\\", data.cFileName) : data.cFileName); if (dirs) { fullname += "\\"; } operateFile(fullname, cb, cb2); } } while (FindNextFile(hResult, &data)); FindClose(hResult); #else unused(dir); DIR* pdir; dirent* dent; pat.replace("\\", "/"); int pos = pat.find_last_of('/'); String patternn(pat.substr(pos + 1)); int pos2 = patternn.find('*'); String startPat, endPat; if (pos2 != String::npos) { startPat = patternn.substr(0, pos2); endPat = patternn.substr(pos2+1); } else { startPat = endPat = patternn; } pat = pat.substr(0, pos+1); WTON_ASSERT(pat[0] != '.' || pat[1] != '/', pat); pdir = opendir (strCat("./", pat.cStr())); if (pdir != NULL) { while ((dent = readdir (pdir))) { String name(dent->d_name); // TODO: support .dotfiles if (name.startsWith(".")) continue; String fullpath(strCat(pat, name)); bool entDir; { struct stat foo; int ret = stat(fullpath.cStr(), &foo); WTON_ASSERT(ret == 0); entDir = S_ISDIR(foo.st_mode); } if (dirs == entDir) { if (dirs) { fullpath += "/"; } if (name.startsWith(startPat.cStr()) && name.endsWith(endPat.cStr())) { operateFile(fullpath, cb, cb2); } } } (void) closedir (pdir); } else { // this just means the fixed path doesn't exist } #endif }
int main(int argc, char *argv[]) { char prefix[32] = {0}; while( gets(prefix) ) { int len = strlen(prefix); int i = len; double stack[30] = { 0 }, va = 0; int top = -1; while(--i >= 0) { while( i >= 0 && prefix[i] != ' ') i--; if( i > 0) // find one space { if( isdigit(prefix[i+1]) || isdigit(prefix[i+2])) { stack[++top] = atof(prefix + i + 1); } else { if(top >= 1 && operate(stack[top],stack[top -1],prefix[i + 1],&va) ) { stack[--top] = va; } else { printf("ERROR\n"); break; } } } else // no space , end! { if( isdigit(prefix[0]) || isdigit(prefix[1]) ) { if( top == -1) { printf("%.1f\n",atof(prefix)); } else { printf("ERROR\n"); } } else // the first length = 1 { if(top == 1 && operate(stack[1],stack[0],prefix[0],&va)) { printf("%.1f\n",va); } else { printf("ERROR\n"); } } } } }// while (gets) return 0; }
int intoperator (char *fname) { int ainf, asup, binf, bsup, op; int sa[2], sb[2], flag[1]; int cinf, csup, f; int ma, na, ma2, na2; int mb, nb, mb2, nb2; int r, s; int p, q, t, u; int rt; CheckRhs (5, 5); CheckLhs (2, 3); GetRhsVar (1, "d", &na, &ma, &ainf); GetRhsVar (2, "d", &na2, &ma2, &asup); GetRhsVar (3, "c", &t, &u, &op); GetRhsVar (4, "d", &nb, &mb, &binf); GetRhsVar (5, "d", &nb2, &mb2, &bsup); if (*cstk (op) == 'k' || *cstk (op) == 'y') { r = na * nb; s = ma * mb; } else { if (na * ma == 1) { r = nb; s = mb; } else if (nb * mb == 1 || (na == nb && ma == mb)) { r = na; s = ma; } else if (ma == nb) { r = na; s = mb; } else { r = 0; s = 0; } } p = 1; q = 1; CreateVar (6, "d", &r, &s, &cinf); CreateVar (7, "d", &r, &s, &csup); CreateVar (8, "i", &p, &q, &f); sa[0] = na; sa[1] = ma; sb[0] = nb; sb[1] = mb; if (r * s != 0) { if (nb2 * mb2 == 0) { operate (stk (ainf), stk (asup), sa, stk (binf), NULL, sb, *cstk (op), stk (cinf), stk (csup), flag); } else if (na2 * ma2 == 0) { operate (stk (ainf), NULL, sa, stk (binf), stk (bsup), sb, *cstk (op), stk (cinf), stk (csup), flag); } else { operate (stk (ainf), stk (asup), sa, stk (binf), stk (bsup), sb, *cstk (op), stk (cinf), stk (csup), flag); } } else { flag[0] = -1; } *istk (f) = flag[0]; LhsVar (1) = 6; LhsVar (2) = 7; LhsVar (3) = 8; return 0; }
/*ARGSUSED*/ void dolet(Char **v, struct command *dummy) { Char *p; Char *vp, c, op; int hadsub; int subscr; USE(dummy); v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; vp = p; if (letter(*p)) for (; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) stderror(ERR_NAME | ERR_VARBEGIN); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p == 0 && *v) p = *v++; if ((op = *p) != 0) *p++ = 0; else stderror(ERR_NAME | ERR_ASSIGN); /* * if there is no expression after the '=' then print a "Syntax Error" * message - strike */ if (*p == '\0' && *v == NULL) stderror(ERR_NAME | ERR_ASSIGN); vp = Strsave(vp); cleanup_push(vp, xfree); if (op == '=') { c = '='; p = xset(p, &v); } else { c = *p++; if (any("+-", c)) { if (c != op || *p) stderror(ERR_NAME | ERR_UNKNOWNOP); p = Strsave(STR1); } else { if (any("<>", op)) { if (c != op) stderror(ERR_NAME | ERR_UNKNOWNOP); stderror(ERR_NAME | ERR_SYNTAX); } if (c != '=') stderror(ERR_NAME | ERR_UNKNOWNOP); p = xset(p, &v); } } cleanup_push(p, xfree); if (op == '=') { if (hadsub) asx(vp, subscr, p); else setv(vp, p, VAR_READWRITE); cleanup_ignore(p); } else if (hadsub) { struct varent *gv = getvx(vp, subscr); Char *val; val = operate(op, gv->vec[subscr - 1], p); cleanup_push(val, xfree); asx(vp, subscr, val); cleanup_ignore(val); cleanup_until(val); } else { Char *val; val = operate(op, varval(vp), p); cleanup_push(val, xfree); setv(vp, val, VAR_READWRITE); cleanup_ignore(val); cleanup_until(val); } update_vars(vp); cleanup_until(vp); } while ((p = *v++) != NULL); }
int main(int argc,char *argv[]) { int arg; int sock; socklen_t length; socklen_t clength; int sc_reuseaddr=1,temp; struct sockaddr_in server; struct sockaddr_in master; struct sockaddr_in client; fd_set ready; int port=0; unsigned char help=0; unsigned char option=0; int remote_port=0; char chost[256]; char *host=NULL; char *file=NULL; char *log=NULL; char *dflog=LOG_FILE; char *dffile=PORT_ID_FILE; int status=0; FILE *fp; struct hostent *hp,*gethostbyname(); struct hostent *cname; pid_t root; OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"l",'i',&port); OptionAdd(&opt,"f",'t',&file); OptionAdd(&opt,"lf",'t',&log); arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } if (argc-arg<2) { OptionPrintInfo(stderr,errstr); exit(-1); } host=argv[argc-2]; remote_port=atoi(argv[argc-1]); if (file==NULL) file=dffile; if (log==NULL) log=dflog; /* get the address and port of the master server */ master.sin_family=AF_INET; hp=gethostbyname(host); if (hp==0) { fprintf(stderr,"%s: unknown host0,\n",host); exit(2); } memcpy(&master.sin_addr,hp->h_addr,hp->h_length); master.sin_port=htons(remote_port); sock=socket(AF_INET,SOCK_STREAM,0); /* create our listening socket */ if (sock<0) { perror("opening stream socket"); exit(1); } /* set socket options */ temp=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sc_reuseaddr, sizeof(sc_reuseaddr)); /* name and bind socket to an address and port number */ server.sin_family=AF_INET; server.sin_addr.s_addr=INADDR_ANY; if (port !=0) server.sin_port=htons(port); else server.sin_port=0; if (bind(sock,(struct sockaddr *) &server,sizeof(server))) { perror("binding stream socket"); exit(1); } /* Find out assigned port number and print it out */ length=sizeof(server); if (getsockname(sock,(struct sockaddr *) &server,&length)) { perror("getting socket name"); exit(1); } fprintf(stdout,"Connected to host : %s:%d\n",host,remote_port); fprintf(stdout,"Socket has port #%d\n",ntohs(server.sin_port)); if (port==0) { fp=fopen(file,"w"); fprintf(fp,"%d\n",ntohs(server.sin_port)); fclose(fp); fprintf(stdout,"Recorded port number in file:%s\n",file); } fprintf(stdout,"Recording log in file:%s\n",log); root=getpid(); fprintf(stdout,"Root PID is %d\n",root); /* if socket gets broken by the client we have to trap the SIGPIPE * signal */ signal(SIGPIPE,SIG_IGN); signal(SIGCHLD,SIG_IGN); /* the heart of the program */ listen(sock,5); /* mark our socket willing to accept connections */ do { /* block until someone wants to attach to us */ FD_ZERO(&ready); FD_SET(sock,&ready); if (select(sock+1,&ready,0,0,NULL) < 0) { perror("while testing for connections"); continue; } /* Accept the connection from the client */ fprintf(stdout,"Accepting a new connection...\n"); clength=sizeof(client); msgout_sock=accept(sock,(struct sockaddr *) &client,&clength); if (msgout_sock==-1) { perror("accept"); continue; } cname=gethostbyaddr((char *) &client.sin_addr, sizeof (client.sin_addr),AF_INET); if ((cname !=NULL) && (cname->h_name !=NULL)) sprintf(chost,"[%s (%s)]",cname->h_name,inet_ntoa(client.sin_addr)); else sprintf(chost,"[%s]",inet_ntoa(client.sin_addr)); msgin_sock=socket(AF_INET,SOCK_STREAM,0); if (msgin_sock<0) { perror("opening stream socket to master"); close(msgout_sock); continue; } /* Make the sockets non-blocking */ if ((status=fcntl(msgout_sock,F_GETFL))==-1) { close(msgin_sock); close(msgout_sock); msgout_sock=-1; msgin_sock=-1; continue; } status|=O_NONBLOCK; if ((status=fcntl(msgout_sock,F_SETFL,status))==-1) { close(msgin_sock); close(msgout_sock); msgin_sock=-1; msgout_sock=-1; continue; } fprintf(stdout,"Getting fcntl block...\n"); if ((status=fcntl(msgin_sock,F_GETFL))==-1) { close(msgin_sock); close(msgout_sock); msgin_sock=-1; msgout_sock=-1; continue; } fprintf(stdout,"Making the socket non-blocking...\n"); status|=O_NONBLOCK; if ((status=fcntl(msgin_sock,F_SETFL,status))==-1) { close(msgin_sock); close(msgout_sock); msgin_sock=-1; msgout_sock=-1; continue; } fprintf(stdout,"Connecting socket to server...\n"); if ((connect(msgin_sock,(struct sockaddr *) &master, sizeof(master)) ==-1) && (errno !=EINPROGRESS)) { perror("connecting to the master server"); close(msgin_sock); close(msgout_sock); msgin_sock=-1; continue; } /* Connection to master server established */ fprintf(stdout,"Creating child process...\n"); if (fork() == 0) { close(sock); operate(root,msgin_sock,msgout_sock,chost,log); } fprintf(stderr,"closing the root files\n"); close(msgin_sock); /* close the new socket in the parent so */ close(msgout_sock); /* that only the child has these files open */ } while(1); return 0; }