variant &operator = (variant const &other) { if (which() == other.which()) { static std::array<void(*)(variant &, variant const &), sizeof...(T)> const assign = {{ ©_assign<T>... }}; assign[which()](*this, other); } else { destroy_value(); try { m_which = other.m_which; copy_construct_value(other); } catch (...) { m_which = invalid_which; throw; } } return *this; }
int main(void) { if (!is_root()) { printf("Root privileges needed to get the hard disk info.\n"); return EXIT_SUCCESS; } char *df = which("df"); char *fdisk = which("fdisk"); char *cmd = NULL; char *path = NULL; cmd = calloc(55, sizeof(char)); sprintf(cmd, "%s -l | grep /dev/ | awk '{print $%d}'", fdisk, 2); path = get_cmd_output(cmd, 12); path = strip_end(path, ":"); hd = new_device(path); delete(&cmd); delete(&path); cmd = calloc(45, sizeof(char)); sprintf(cmd, "%s -P | awk '{print $%d}' | grep %s", df, 1, hd->name); path = get_cmd_output(cmd, 13); part = new_device(path); delete(&cmd); delete(&path); int fails = 0; Suite *s = hd_suite(); SRunner *sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL); fails = srunner_ntests_failed(sr); srunner_free(sr); return (fails == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }
int romanToInt(char* s) { int rlt = 0; while (*s) { int pre = which(*s++); if (*s && pre < which(*s)) rlt -= pre; else rlt += pre; } return rlt; }
// A version that doesn't require having MyStrings passed to it, in // case we find this easier to use... MyString which( const char* strFilename, const char* strAdditionalSearchDir ) { MyString file( strFilename ); if( strAdditionalSearchDir ) { MyString additionalSearch( strAdditionalSearchDir ); return which( file, additionalSearch ); } return which( file ); }
void NotifyList::MessageReceived (BMessage *msg) { switch (msg->what) { case M_NOTIFYLIST_RESIZE: { ClientWindow *cWin (vision_app->pClientWin()); cWin->DispatchMessage (msg, cWin->pCwDock()); break; } case M_THEME_FOREGROUND_CHANGE: { int16 which (msg->FindInt16 ("which")); bool refresh (false); switch (which) { case C_NOTIFYLIST_BACKGROUND: fActiveTheme->ReadLock(); SetViewColor (fActiveTheme->ForegroundAt (C_NOTIFYLIST_BACKGROUND)); fActiveTheme->ReadUnlock(); refresh = true; break; case C_NOTIFY_ON: case C_NOTIFY_OFF: case C_NOTIFYLIST_SELECTION: refresh = true; break; } if (refresh) Invalidate(); } break; case M_THEME_FONT_CHANGE: { int16 which (msg->FindInt16 ("which")); if (which == F_WINLIST) { fActiveTheme->ReadLock(); SetFont (&fActiveTheme->FontAt (F_WINLIST)); fActiveTheme->ReadUnlock(); Invalidate(); } } break; default: BListView::MessageReceived (msg); } }
/* * Resolve the trace path, throwing an error if it is not found. */ void trace_resolve_path(void) { trace_path = which("strace"); if (trace_path == NULL) { trace_path = which("dtruss"); use_dtruss = 1; } if (trace_path == NULL) errx(1, "strace (or dtruss) is not in your PATH"); }
int normalize_initialize(settings_t *settings) { int ret = 1; struct stat statbuf; if (settings) { if (which("normalize",settings->normalize_path, MAX_PATH_LEN) == 0) { ret = 0; } else { memset(&statbuf,0,sizeof(statbuf)); if (stat(NORMALIZE_PATH,&statbuf) || (!(statbuf.st_mode & S_IXUSR))) { fprintf(stderr,"Cannot find required program " "normalize.\nPlease install this program " "either from your vendor, or visit:\n\n%s\n", NORMALIZE_DOWNLOAD_SITE); } else { memcpy(settings->normalize_path,NORMALIZE_PATH, MIN(strlen(NORMALIZE_PATH),MAX_PATH_LEN-1)); ret = 0; } } } return ret; }
int main(int argc, char *argv[]) { char *path; int found = 0, foundall = 1; ARGBEGIN { case 'a': aflag = 1; break; default: usage(); } ARGEND if (!argc) usage(); if (!(path = getenv("PATH"))) enprintf(3, "$PATH is not set\n"); for (; *argv; argc--, argv++) { if (which(path, *argv)) { found = 1; } else { weprintf("%s: command not found.\n", *argv); foundall = 0; } } return found ? foundall ? 0 : 1 : 2; }
MainWindow::MainWindow(QWidget *parent): QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint) { active_index_ = -1; edit_index_ = -1; animation_id_ = 0; stats_ = new StatsDialog(); connect(this, SIGNAL(cycleReadySignal()), stats_, SLOT(cycleReady())); if (!which("firejail")) { QMessageBox::warning(this, tr("Firejail Tools"), tr("<br/><b>Firejail</b> sandbox not found.<br/><br/><br/>")); exit(1); } applications_init(); createTrayActions(); createLocalActions(); thread_ = new PidThread(); connect(thread_, SIGNAL(cycleReady()), this, SLOT(cycleReady())); setContextMenuPolicy(Qt::ActionsContextMenu); setToolTip(tr("Double click on an icon to open an application.\n" "Drag the launcher with the left mouse button.\n" "Use the right mouse button to open a context menu.")); setWindowTitle(tr("Firejail Tools")); }
virtual void prior(position_interface<types>& pos) { switch (which(pos)) { case commands::next: advance_prior<0>(pos); break; case commands::prior: advance_prior<1>(pos); break; case commands::inc: advance_prior<2>(pos); break; case commands::dec: advance_prior<3>(pos); break; case commands::out: advance_prior<4>(pos); break; case commands::in: advance_prior<5>(pos); break; case commands::begin: advance_prior<6>(pos); break; case commands::end: advance_prior<7>(pos); break; default: pos.prior(); break; } }
bool Attribute::operator==( const Attribute& other ) const { if( which() != other.which() ) return false; switch( which() ) { case 0: return boost::get< int >( *this ) == boost::get< int >( other ); case 1: return boost::get< string >( *this ) == boost::get< string >( other ); case 2: return boost::get< double >( *this ) == boost::get< double >( other ); case 3: return boost::get< Date >( *this ) == boost::get< Date >( other ); default: throw ActiveRecordException( "Unexpected Attribute type", __FILE__, __LINE__ ); } }
AggregateFunctionPtr createAggregateFunctionQuantile(const std::string & name, const DataTypes & argument_types, const Array & params) { /// Second argument type check doesn't depend on the type of the first one. Function<void>::assertSecondArg(argument_types); const DataTypePtr & argument_type = argument_types[0]; WhichDataType which(argument_type); #define DISPATCH(TYPE) \ if (which.idx == TypeIndex::TYPE) return std::make_shared<Function<TYPE>>(argument_type, params); FOR_NUMERIC_TYPES(DISPATCH) #undef DISPATCH #undef FOR_NUMERIC_TYPES if (which.idx == TypeIndex::Date) return std::make_shared<Function<DataTypeDate::FieldType>>(argument_type, params); if (which.idx == TypeIndex::DateTime) return std::make_shared<Function<DataTypeDateTime::FieldType>>(argument_type, params); if constexpr (SupportDecimal<Function>()) { if (which.idx == TypeIndex::Decimal32) return std::make_shared<Function<Decimal32>>(argument_type, params); if (which.idx == TypeIndex::Decimal64) return std::make_shared<Function<Decimal64>>(argument_type, params); if (which.idx == TypeIndex::Decimal128) return std::make_shared<Function<Decimal128>>(argument_type, params); } throw Exception("Illegal type " + argument_type->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); }
::OSStatus label_subevent_handler_t::handle_event(::EventHandlerCallRef /*next*/, ::EventRef event) { if (!callback_m) return noErr; assert (::GetEventClass(event) == kEventClassControl); label_subevent_t which(subevent_none_s); switch (::GetEventKind(event)) { case kEventControlClick: case kEventControlHit: which = subevent_mouse_down_s; break; case kEventControlTrackingAreaEntered: which = subevent_mouse_in_s; break; case kEventControlTrackingAreaExited: which = subevent_mouse_out_s; break; default: throw std::runtime_error("unknown case"); } callback_m(which); return noErr; }
void setup (void) { char *temp; struct passwd *pw; /* If we're running as root, seteuid to notes. */ pw = getpwnam (NOTES); notes_uid = pw->pw_uid; if (geteuid () == 0) seteuid (notes_uid); pw = getpwnam (ANON); anon_uid = pw->pw_uid; pw = getpwuid (geteuid ()); username = newts_strdup (pw->pw_name); euid = pw->pw_uid; fqdn = newts_get_fqdn (); tmpdir = newts_strdup ((temp = getenv ("TMPDIR")) ? temp : "/tmp"); shell = which ((temp = getenv ("SHELL")) ? temp : pw->pw_shell); endpwent (); /* FIXME: I should do something about the environment here. * * ... Namely, nuke it. */ }
void copy_construct_value(variant const &from) { static std::array<void(*)(variant &, variant const &), sizeof...(T)> const copy_constructors = {{ ©_construct<T>... }}; copy_constructors[which()](*this, from); }
void destroy_value() { static std::array<void(*)(variant &), sizeof...(T)> const destructors = {{ &destroy<T>... }}; destructors[which()](*this); }
int cmd_which (int argc,char **argv,struct sub_command* cmd) { if(argc==2) { char* str=which(argv[1]); printf("%s\n",str); s(str); } return 0; }
inline bool operator== (const ::Datagram::DatagramKey::Reader& a, const ::Datagram::DatagramKey::Reader& b) { if (a.getKey().which() != b.getKey().which()) return false; if (a.getKey().isContestKey()) { auto ac = a.getKey().getContestKey().getCreator(); auto bc = b.getKey().getContestKey().getCreator(); if (ac.which() != bc.which()) return false; if (ac.isAnonymous()) return bc.isAnonymous(); return ac.getSignature().getId() == bc.getSignature().getId() && ac.getSignature().getSignature() == bc.getSignature().getSignature(); } auto ad = a.getKey().getDecisionKey().getBalanceId(); auto bd = b.getKey().getDecisionKey().getBalanceId(); return ad.getAccountInstance() == bd.getAccountInstance() && ad.getCoinInstance() == bd.getCoinInstance(); }
int main () { good (); good (); good (); which (); return 0; }
/* * Opens the input data-feed. Given a feedname (path in the file system), * determine what type of input feed it is. Attempt to open * the feed. Hook up the appropriate read_, _stats, and (optional) _close * function pointers. Return errno on failure else set *fdp to the descriptor * and return 0. * * @param feedfname [in] The name of the input data-feed * @param fdp [out] The file-descriptor of the input data-feed * @param maxProdSize [in] The size, in bytes, of the largest expected * data-product * Returns (if INPUT_IS_SOCKET): * ENOENT gethostbyname() failure. * EAFNOSUPPORT AF_INET address-family not supported. * EMFILE No more file descriptors available for this process. * ENFILE No more file descriptors available for the system. * EACCES The process does not have appropriate privileges. * ENOBUFS Insufficient resources were available in the system to * perform the operation. * ENOMEM Insufficient memory was available to fulfill the request. * ENOSR There were insufficient STREAMS resources available for the * operation to complete. * EADDRNOTAVAIL The specified address is not available from the local * machine. * ECONNREFUSED The target address was not listening for connections or * refused the connection request. * EINTR The attempt to establish a connection was interrupted by * delivery of a signal that was caught; the connection will be * established asynchronously. * ENETUNREACH No route to the network is present. * EPROTOTYPE The specified address has a different type than the socket * bound to the specified peer address. * ETIMEDOUT The attempt to connect timed out before a connection was * made. * ECONNRESET Remote host reset the connection request. * EHOSTUNREACH The destination host cannot be reached (probably because the * host is down or a remote router cannot reach it). * ENETDOWN The local interface used to reach the destination is down. */ int open_feed(const char *feedfname, int *const fdp, const unsigned long maxProdSize) { extern char *rawfname; /* declared in main() module */ int status = ENOERR; #if NET if(INPUT_IS_SOCKET) { status = port_open(feedfname, (unsigned short) server_port, fdp); if(status != ENOERR) return status; if((status = initTheXbuf(read_file, maxProdSize)) != ENOERR) return status; feed_stats = file_stats; feed_close = file_close; } else /* dangling else */ #endif /* NET */ switch( which(feedfname) ) { #ifdef TTY case TTY : if((status = tty_open(feedfname, fdp)) != ENOERR) return status; if((status = initTheXbuf(read_tty, maxProdSize)) != ENOERR) return status; feed_stats = tty_stats; feed_close = tty_close; break; #endif /* TTY */ default : /* just treat it like a file */ if(*feedfname == '-' && feedfname[1] == 0) { /* use stdin */ *fdp = fileno(stdin); unotice("FILE stdin"); } else { if((status = file_open(feedfname, fdp)) != ENOERR) return status; } if((status = initTheXbuf(read_file, maxProdSize)) != ENOERR) return status; feed_stats = file_stats; feed_close = file_close; break; } if(rawfname != NULL) { (void) open_rawfile( rawfname ); } return status; }
variant(variant &&other) : m_which(other.m_which) { static std::array<void(*)(variant &, variant &&), sizeof...(T)> const move_constructors = {{ &move_construct<T>... }}; move_constructors[which()](*this, std::move(other)); }
/** * Detect if a character class occurs in a string * * @param str character vector * @param pattern character vector * @param omit_na single logical value * @return logical vector * * @version 0.3-1 (Bartek Tartanus, 2014-07-25) * * @version 0.3-1 (Marek Gagolewski, 2014-10-17) * using std::vector<int> to avoid mem-leaks * * @version 0.3-1 (Marek Gagolewski, 2014-11-04) * Issue #112: str_prepare_arg* retvals were not PROTECTed from gc * * @version 0.4-1 (Marek Gagolewski, 2014-12-04) * FR #122: omit_na arg added * * @version 1.0-3 (Marek Gagolewski, 2016-02-03) * FR #216: `negate` arg added */ SEXP stri_subset_charclass(SEXP str, SEXP pattern, SEXP omit_na, SEXP negate) { bool negate_1 = stri__prepare_arg_logical_1_notNA(negate, "negate"); bool omit_na1 = stri__prepare_arg_logical_1_notNA(omit_na, "omit_na"); PROTECT(str = stri_prepare_arg_string(str, "str")); PROTECT(pattern = stri_prepare_arg_string(pattern, "pattern")); R_len_t vectorize_length = stri__recycling_rule(true, 2, LENGTH(str), LENGTH(pattern)); STRI__ERROR_HANDLER_BEGIN(2) StriContainerUTF8 str_cont(str, vectorize_length); StriContainerCharClass pattern_cont(pattern, vectorize_length); // BT: this cannot be done with deque, because pattern is reused so i does not // go like 0,1,2...n but 0,pat_len,2*pat_len,1,pat_len+1 and so on // MG: agreed std::vector<int> which(vectorize_length); int result_counter = 0; for (R_len_t i = pattern_cont.vectorize_init(); i != pattern_cont.vectorize_end(); i = pattern_cont.vectorize_next(i)) { if (str_cont.isNA(i) || pattern_cont.isNA(i)) { if (omit_na1) which[i] = FALSE; else { which[i] = NA_LOGICAL; result_counter++; } continue; } const UnicodeSet* pattern_cur = &pattern_cont.get(i); R_len_t str_cur_n = str_cont.get(i).length(); const char* str_cur_s = str_cont.get(i).c_str(); UChar32 chr = 0; which[i] = FALSE; for (R_len_t j=0; j<str_cur_n; ) { U8_NEXT(str_cur_s, j, str_cur_n, chr); if (chr < 0) // invalid utf-8 sequence throw StriException(MSG__INVALID_UTF8); if (pattern_cur->contains(chr)) { which[i] = TRUE; break; } } if (negate_1) which[i] = !which[i]; if (which[i]) result_counter++; } SEXP ret; STRI__PROTECT(ret = stri__subset_by_logical(str_cont, which, result_counter)); STRI__UNPROTECT_ALL return ret; STRI__ERROR_HANDLER_END(;/* nothing special to be done on error */) }
int main() { std::tuple<int, bool, double, int> t(42, true, 3.14, 1337); int i = 0; auto var = get(i, t); if (var.which() == i) std::cout << "yay"; else std::cout << "nay"; }
autoButtonEditor ButtonEditor_create () { try { autoButtonEditor me = Thing_new (ButtonEditor); HyperPage_init (me.get(), U"Buttons", nullptr); which (me.get(), 1); return me; } catch (MelderError) { Melder_throw (U"Buttons window not created."); } }
auto apply_visitor(Visitor &&visitor) const { typedef typename std::decay<Visitor>::type clean_visitor; typedef typename clean_visitor::result_type result_type; static std::array<result_type(*)(variant const &, Visitor &), sizeof...(T)> const methods = {{ &apply_visitor_method_const<result_type, T, Visitor>... }}; return methods[which()](*this, visitor); }
void type_operator::propagate(contexts& ctxs) { // add check here for _kind valid in context for(auto it = begin(); it != end(); it++) { if(it->which()) { auto& op = boost::get<type_operator>(*it); op.propagate(ctxs); } else { auto& tv = boost::get<type_variable>(*it); tv.propagate(ctxs); } } }
void tButtonTest::keyPressEvent( QKeyEvent* e ) { if ( ( ( ( m_HAL.PlatformId() != ePlatformCassius ) && ( e->key() == tKeyMapping::PhysicalKeyOf( tKeyMapping::eKM_Navico_StbyAuto ) ) ) || e->key() == tKeyMapping::PhysicalKeyOf( tKeyMapping::eKM_MainWidget_NextPage ) || e->key() == tKeyMapping::PhysicalKeyOf( tKeyMapping::eKM_MainWidget_PrevPage ) ) && m_IsInKeymode == false ) { e->ignore(); return; } QHash<int, tButtonTestButton*>::const_iterator iter( m_KeyToButtonHash.find( ( int )e->key() ) ); if ( iter == m_KeyToButtonHash.end() ) { DbgPrintf( "Ignoring key event %d", e->key() ); e->ignore(); return; } tButtonTestButton* which( iter.value() ); if ( e->type() == QEvent::KeyPress ) { which->setDown( true ); if ( e->isAutoRepeat() == false ) { m_HAL.Buzzer()->KeyBeep(); } return; } else if ( e->type() == QEvent::KeyRelease ) { which->setDown( false ); return; } else if ( m_IgnoreKeys ) { // UI refreshed - allow parent to handle as well e->ignore(); return; } else { DbgPrintf( "Ignoring unknown event %d for key %d", e->type(), e->key() ); e->ignore(); return; } }
int main() { int a[100], T, i; a[0] = 0; a[1] = 1; for (i = 2; i < 100; i++) { a[i] = a[i - 2] + a[i - 1]; } scanf("%d", &T); int b[T]; for (i = 0; i < T; i++) { scanf("%d", &b[i]); printf("%d\n", which(a, b[i])); } }
static int run_man(struct subcommand *scp, int argc, char **argv) { char *berictl_rpath, *manpage, *prog; if (berictl_path != NULL && (berictl_rpath = which(berictl_path)) != NULL) { if (asprintf(&manpage, "%s.1", berictl_rpath) > 0) { if ((prog = which("mandoc")) != NULL) { execl(prog, prog, manpage, NULL); exit(1); } else if ((prog = which("nroff")) != NULL) { execl(prog, prog, "-S", "-Tascii", "-man", manpage, NULL); exit(1); } } free(berictl_rpath); free(manpage); } execlp("man", "man", "1", "berictl", NULL); exit(1); }
virtual void backward(position_interface<types>& pos) { int c = -1; do { prior(pos); switch (which(pos)) { case commands::begin: ++c; break; case commands::end: --c; break; } } while (c); }