content
stringlengths
19
48.2k
/* * hip_sadb_get_usage() * * Retrieve bytes and use time for the SADB entry matching the given SPI. */ int hip_sadb_get_usage(__u32 spi, __u64 *bytes, struct timeval *usetime) { hip_sadb_entry *entry = hip_sadb_lookup_spi(spi); if (!entry) { return(-1); } pthread_mutex_lock(&entry->rw_lock); *bytes = entry->bytes; usetime->tv_sec = entry->usetime.tv_sec; usetime->tv_usec = entry->usetime.tv_usec; pthread_mutex_unlock(&entry->rw_lock); return(0); }
/** * Very basic update/fetch with data verification of multiple records, with * varying record size and IOD type. */ static void io_manyrec(void **state) { test_arg_t *arg = *state; daos_obj_id_t oid; oid = dts_oid_gen(dts_obj_class, 0, arg->myrank); print_message("Insert(e=0)/lookup(e=0)/verify complex kv records:\n"); print_message("DAOS_IOD_ARRAY:SCM\n"); io_manyrec_internal(state, oid, IO_SIZE_SCM, DAOS_IOD_ARRAY, "io_manyrec_scm_array dkey", "io_manyrec_scm_array akey"); print_message("DAOS_IOD_ARRAY:NVME\n"); io_manyrec_internal(state, oid, IO_SIZE_NVME, DAOS_IOD_ARRAY, "io_manyrec_nvme_array dkey", "io_manyrec_array akey"); print_message("DAOS_IOD_SINGLE:SCM\n"); io_manyrec_internal(state, oid, IO_SIZE_SCM, DAOS_IOD_SINGLE, "io_manyrec_scm_single dkey", "io_manyrec_scm_single akey"); print_message("DAOS_IOD_SINGLE:NVME\n"); io_manyrec_internal(state, oid, IO_SIZE_NVME, DAOS_IOD_SINGLE, "io_manyrec_nvme_single dkey", "io_manyrec_nvme_single akey"); }
/* * Swap the contents of two buffers. */ void buffer_swap(struct buffer *one, struct buffer *two) { struct buffer tmp; tmp = *one; *one = *two; *two = tmp; }
#include <stdio.h> int main( void ) { static char stack[ 1 << 20 ]; int count = 0; int top = 0; int c; while ( ( c = fgetc( stdin ) ) != '\n' ) { if ( c == '(' ) { stack[ top++ ] = '('; } else { if ( top > 0 ) { count++; top--; } } } printf( "%d\n", count * 2 ); return 0; }
/****************************************************************************** * Top contributors (to current version): * Andrew Reynolds * * This file is part of the cvc5 project. * * Copyright (c) 2009-2023 by the authors listed in the file AUTHORS * in the top-level source directory and their institutional affiliations. * All rights reserved. See the file COPYING in the top-level source * directory for licensing information. * **************************************************************************** * * The flex smt2 parser. */ #include "cvc5parser_public.h" #ifndef CVC5__PARSER__SMT2__SMT2_PARSER_H #define CVC5__PARSER__SMT2__SMT2_PARSER_H #include <cvc5/cvc5.h> #include "parser/flex_parser.h" #include "parser/smt2/smt2.h" #include "parser/smt2/smt2_cmd_parser.h" #include "parser/smt2/smt2_lexer_new.h" #include "parser/smt2/smt2_term_parser.h" namespace cvc5 { namespace parser { /** * Flex-based smt2 parser. It maintains a lexer, a state, a term parser and a * command parser. The latter two are used for parsing terms and commands. The * command parser depends on the term parser. */ class Smt2Parser : public FlexParser { public: Smt2Parser(Solver* solver, SymbolManager* sm, bool isStrict = false, bool isSygus = false); virtual ~Smt2Parser() {} /** Set the logic */ void setLogic(const std::string& logic) override; protected: /** * Parse and return the next command. Will initialize the logic to "ALL" * or the forced logic if no logic is set prior to this point and a command * is read that requires initializing the logic. */ std::unique_ptr<Command> parseNextCommand() override; /** * Parse and return the next expression. Requires setting the logic * beforehand. */ Term parseNextExpression() override; /** The lexer */ Smt2LexerNew d_slex; /** The state */ Smt2State d_state; /** Term parser */ Smt2TermParser d_termParser; /** Command parser */ Smt2CmdParser d_cmdParser; }; } // namespace parser } // namespace cvc5 #endif /* CVC5__PARSER__SMT2_H */
// ChaCha20/Poly1305 Test Vector 1, RFC 7539 // <http://tools.ietf.org/html/rfc7539#section-2.8.2> // ChaCha20/Poly1305 Test Vector 2, RFC 7539 // <http://tools.ietf.org/html/rfc7539#appendix-A.5> const ChaChaTestVector kChaCha20Vectors[] = { {0, {0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, 0x74, 0x2e}, {0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7}, {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f}, {0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47}, {0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2, 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe, 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6, 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12, 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b, 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29, 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36, 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c, 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58, 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94, 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc, 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d, 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b, 0x61, 0x16, 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a, 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91}, false, false}, {1, {0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x64, 0x72, 0x61, 0x66, 0x74, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20, 0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x69, 0x78, 0x20, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x2c, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f, 0x62, 0x73, 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x61, 0x74, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69, 0x6e, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72, 0x69, 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x75, 0x73, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20, 0x61, 0x73, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x69, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6d, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x74, 0x68, 0x61, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x2f, 0xe2, 0x80, 0x9c, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x69, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x2f, 0xe2, 0x80, 0x9d}, {0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x91}, {0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a, 0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0, 0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09, 0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0}, {0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, {0x64, 0xa0, 0x86, 0x15, 0x75, 0x86, 0x1a, 0xf4, 0x60, 0xf0, 0x62, 0xc7, 0x9b, 0xe6, 0x43, 0xbd, 0x5e, 0x80, 0x5c, 0xfd, 0x34, 0x5c, 0xf3, 0x89, 0xf1, 0x08, 0x67, 0x0a, 0xc7, 0x6c, 0x8c, 0xb2, 0x4c, 0x6c, 0xfc, 0x18, 0x75, 0x5d, 0x43, 0xee, 0xa0, 0x9e, 0xe9, 0x4e, 0x38, 0x2d, 0x26, 0xb0, 0xbd, 0xb7, 0xb7, 0x3c, 0x32, 0x1b, 0x01, 0x00, 0xd4, 0xf0, 0x3b, 0x7f, 0x35, 0x58, 0x94, 0xcf, 0x33, 0x2f, 0x83, 0x0e, 0x71, 0x0b, 0x97, 0xce, 0x98, 0xc8, 0xa8, 0x4a, 0xbd, 0x0b, 0x94, 0x81, 0x14, 0xad, 0x17, 0x6e, 0x00, 0x8d, 0x33, 0xbd, 0x60, 0xf9, 0x82, 0xb1, 0xff, 0x37, 0xc8, 0x55, 0x97, 0x97, 0xa0, 0x6e, 0xf4, 0xf0, 0xef, 0x61, 0xc1, 0x86, 0x32, 0x4e, 0x2b, 0x35, 0x06, 0x38, 0x36, 0x06, 0x90, 0x7b, 0x6a, 0x7c, 0x02, 0xb0, 0xf9, 0xf6, 0x15, 0x7b, 0x53, 0xc8, 0x67, 0xe4, 0xb9, 0x16, 0x6c, 0x76, 0x7b, 0x80, 0x4d, 0x46, 0xa5, 0x9b, 0x52, 0x16, 0xcd, 0xe7, 0xa4, 0xe9, 0x90, 0x40, 0xc5, 0xa4, 0x04, 0x33, 0x22, 0x5e, 0xe2, 0x82, 0xa1, 0xb0, 0xa0, 0x6c, 0x52, 0x3e, 0xaf, 0x45, 0x34, 0xd7, 0xf8, 0x3f, 0xa1, 0x15, 0x5b, 0x00, 0x47, 0x71, 0x8c, 0xbc, 0x54, 0x6a, 0x0d, 0x07, 0x2b, 0x04, 0xb3, 0x56, 0x4e, 0xea, 0x1b, 0x42, 0x22, 0x73, 0xf5, 0x48, 0x27, 0x1a, 0x0b, 0xb2, 0x31, 0x60, 0x53, 0xfa, 0x76, 0x99, 0x19, 0x55, 0xeb, 0xd6, 0x31, 0x59, 0x43, 0x4e, 0xce, 0xbb, 0x4e, 0x46, 0x6d, 0xae, 0x5a, 0x10, 0x73, 0xa6, 0x72, 0x76, 0x27, 0x09, 0x7a, 0x10, 0x49, 0xe6, 0x17, 0xd9, 0x1d, 0x36, 0x10, 0x94, 0xfa, 0x68, 0xf0, 0xff, 0x77, 0x98, 0x71, 0x30, 0x30, 0x5b, 0xea, 0xba, 0x2e, 0xda, 0x04, 0xdf, 0x99, 0x7b, 0x71, 0x4d, 0x6c, 0x6f, 0x2c, 0x29, 0xa6, 0xad, 0x5c, 0xb4, 0x02, 0x2b, 0x02, 0x70, 0x9b, 0xee, 0xad, 0x9d, 0x67, 0x89, 0x0c, 0xbb, 0x22, 0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38}, false, false}};
/*! \fn u_int16_t simptcp_get_dport (const char *buffer) * \brief renvoi la valeur du champ dport (destination port) du PDU SimpTCP * \param buffer pointeur sur PDU simptcp * \return numero de port destination du PDU */ u_int16_t simptcp_get_dport (const char *buffer) { #if __DEBUG__ #endif return ntohs(((const simptcp_generic_header *)buffer)->dport); }
/* Check that pre ARMv4 compilation still works. */ /* { dg-do compile } */ /* { dg-options "-marm -march=armv3 -O2 -fno-forward-propagate" } */ /* { dg-require-effective-target arm_arm_ok } */ typedef short v16u16 __attribute__ ((vector_size (16))); typedef unsigned v16u32 __attribute__ ((vector_size (16))); typedef long long v16u64 __attribute__ ((vector_size (16))); unsigned foo (int u16_0, unsigned u32_0, int u64_0, int u16_1, unsigned u64_1, v16u16 v16u16_0, v16u32 v16u32_0, v16u64 v16u64_0, v16u16 v16u16_1, v16u32 v16u32_1, v16u64 v16u64_1) { v16u16_1[3] -= v16u32_0[0]; v16u16_0 -= (v16u16) v16u32_0; return u16_0 + u32_0 + u64_0 + u16_1 + v16u16_0[0] + v16u16_0[2] + v16u16_0[3] + v16u16_0[4] + v16u16_0[5] + v16u32_0[0] + v16u32_0[1] + v16u32_0[3] + v16u64_0[1] + v16u16_1[2] + v16u16_1[3] + v16u16_1[5] + v16u16_1[7] + v16u32_1[0] + v16u32_1[3] + v16u64_1[0] + v16u64_1[1]; }
/****************************************************************************** * Top contributors (to current version): * Andrew Reynolds, Aina Niemetz * * This file is part of the cvc5 project. * * Copyright (c) 2009-2023 by the authors listed in the file AUTHORS * in the top-level source directory and their institutional affiliations. * All rights reserved. See the file COPYING in the top-level source * directory for licensing information. * **************************************************************************** * * A technique for synthesizing candidate rewrites of the form t1 = t2, * where t1 and t2 are subterms of the input. */ #ifndef CVC5__PREPROCESSING__PASSES__SYNTH_REW_RULES_H #define CVC5__PREPROCESSING__PASSES__SYNTH_REW_RULES_H #include "preprocessing/preprocessing_pass.h" namespace cvc5::internal { namespace preprocessing { namespace passes { /** * This class rewrites the input assertions into a sygus conjecture over a * grammar whose terms are "abstractions" of the subterms of * assertionsToPreprocess. In detail, assume our input was * bvadd( bvlshr( bvadd( a, 4 ), 1 ), b ) = 1 * This class constructs this grammar: * A -> T1 | T2 | T3 | T4 | Tv * T1 -> bvadd( T2, Tv ) | x | y * T2 -> bvlshr( T3, T4 ) | x | y * T3 -> bvadd( Tv, T5 ) | x | y * T4 -> 1 | x | y * T5 -> 4 | x | y * Tv -> x | y * Notice that this grammar generates all subterms of the input where leaves * are replaced by the variables x and/or y. The number of variable constructors * (x and y in this example) used in this construction is configurable via * sygus-rr-synth-input-nvars. The default for this value is 3, the * justification is that this covers most of the interesting rewrites while * not being too inefficient. * * Also notice that currently, this grammar construction admits terms that * do not necessarily match any in the input. For example, the above grammar * admits bvlshr( x, x ), which is not matchable with a subterm of the input. * * Notice that Booleans are treated specially unless the option * --sygus-rr-synth-input-bool is enabled, since we do not by default want to * generate purely propositional rewrites. In particular, we allocate only * one Boolean variable (to ensure that no sygus type is non-empty). * * It then rewrites the input into the negated sygus conjecture * forall x : ( BV_n x BV_n ) -> BV_n. false * where x has the sygus grammar restriction A from above. This conjecture can * then be processed using --sygus-rr-synth in the standard way, which will * cause candidate rewrites to be printed on the output stream. If multiple * types are present, then we generate a conjunction of multiple synthesis * conjectures, which we enumerate terms for in parallel. */ class SynthRewRulesPass : public PreprocessingPass { public: SynthRewRulesPass(PreprocessingPassContext* preprocContext); static std::vector<TypeNode> getGrammarsFrom( const std::vector<Node>& assertions, uint64_t nvars); protected: static std::map<TypeNode, TypeNode> constructTopLevelGrammar( const std::vector<Node>& assertions, uint64_t nvars); PreprocessingPassResult applyInternal( AssertionPipeline* assertionsToPreprocess) override; }; } // namespace passes } // namespace preprocessing } // namespace cvc5::internal #endif /* CVC5__PREPROCESSING__PASSES__SYNTH_REW_RULES_H */
/*TODO: correct with BitScanForward on windows and the built-in functions on Linux*/ static inline bl_u8 bl_u8_get_bit_idx (bl_u8 non_zero_pow2) { static const bl_u8 bruijn_seq = 0x17; static const bl_u8 bruijn_seq_cycle_inv[8] = { 0, 1, 2, 4, 7, 3, 6, 5, }; bl_assert (non_zero_pow2 && bl_has_one_or_zero_bits_set (non_zero_pow2)); return bruijn_seq_cycle_inv[((bl_u8)(non_zero_pow2 * bruijn_seq)) >> 5]; }
/** * Calculates the Sun's equatorial coordinates RA, Dec and also its distance * * @param jd Julian Day Number * @param RA Right Ascension * @param dec Declination * @param r Distance */ void astro_sunRADec(double jd, double *RA, double *dec, double *r) { double lon, obl_ecl, x, y, z; astro_sunpos(jd, &lon, r); x = *r * cosd(lon); y = *r * sind(lon); obl_ecl = 23.4393 - 3.563E-7 * astro_days_since_2000(jd); z = y * sind(obl_ecl); y = y * cosd(obl_ecl); *RA = atan2d(y, x); *dec = atan2d(z, sqrt(x * x + y * y)); }
// we should get one line of data, but it may be in multiple chunks static int xread2line(int fd, char *buf, int len) { int i, total = 0; len--; while (total<len && (i = xread(fd, buf, len-total))) { total += i; if (buf[total-1] == '\n') break; } if (total>=len) error_exit("overflow"); while (total--) if (buf[total]=='\r' || buf[total]=='\n') buf[total] = 0; else break; if (toys.optflags & FLAG_v) fprintf(stderr, "%s\n", toybuf); return total+1; }
// Do not call from an ISR unless modify it to use ISR specific Timer APIs void LedOrangeOn_AutoOff(void) { if( OLedTimerId == NULL ) { LedOrangeOn(); OLedTimerId = xTimerCreate("OLedTimer", 200, pdFALSE, ( void * ) 0, OLedTimerCB); if( OLedTimerId == NULL ) printf("Fail to create timer!!! \r\n"); else if( xTimerStart( OLedTimerId, 0 ) != pdPASS ) printf("Fail to start orange led timer!!! \r\n"); } else { LedOrangeOff(); vTaskDelay( configTICK_RATE_HZ/10 ); LedOrangeOn(); if( xTimerReset( OLedTimerId, 0 ) != pdPASS ) printf("Fail to reset orange led timer!!! \r\n"); } }
// distance - funtion to get the distance between present centroid and datapoint // @param DataPoint * - pointer to DataPoint structure from which distance needs to be calculated // @param Centroid * - pointer to Centroid struct from which distance is being calculated long long int distance (const DataPoint * datapoint, const Centroid * centroid) { long long int sum = 0; return sum; }
/* call function to change client state and set corresponding ewmh properties */ static void clientstate(struct Client *c, int state, long int flag) { struct Client *f; switch (state) { case ABOVE: if (c == NULL || c->state == Minimized || c->state == Tiled || c->isfullscreen) break; if (clientabove(c, flag)) ewmhsetstate(c); break; case BELOW: if (c == NULL || c->state == Minimized || c->state == Tiled || c->isfullscreen) break; if (clientbelow(c, flag)) ewmhsetstate(c); break; case STICK: if (c == NULL || c->state == Minimized || c->state == Tiled || c->isfullscreen) break; if (clientstick(c, flag)) { ewmhsetwmdesktop(c); ewmhsetstate(c); } break; case MAXIMIZE: if (c == NULL || c->state == Minimized || c->isfullscreen) break; if (clienttile(c, flag)) { ewmhsetwmdesktop(c); ewmhsetstate(c); } break; case SHADE: if (c == NULL || c->state == Minimized || c->isfullscreen) break; if (clientshade(c, flag)) { tabfocus(c->seltab); ewmhsetstate(c); } break; case FULLSCREEN: if (c == NULL || c->state == Minimized) break; if (clientfullscreen(c, flag)) { tabfocus(c->seltab); ewmhsetstate(c); } break; case HIDE: if (c == NULL) break; if (clientminimize(c, flag)) { f = (c->state == Minimized) ? getnextfocused(c) : c; clientfocus(f); if (f != NULL) tabfocus(f->seltab); ewmhsetwmdesktop(c); ewmhsetstate(c); } break; case FOCUS: if (c != NULL && c->state == Minimized) break; if (clientfocus(c)) { ewmhsetcurrentdesktop(selmon->seldesk->n); ewmhsetstate(c); if (c != NULL) { tabfocus(c->seltab); } } break; } if (focused != prevfocused) { ewmhsetstate(prevfocused); } }
#include<stdio.h> #include<string.h> int main() { char str1[255]; int ctr[26] = {0}; int ctrl[26] = {0}; scanf("%s", &str1); int len1 = strlen(str1); for(int j = 0; j < len1; j++){ if(str1[j] >= 'A' && str1[j] <= 'Z'){ ++ctr[str1[j] - 'A']; } } char str2[255]; scanf("%s", &str2); int len2 = strlen(str2); for(int j = 0; j < len2; j++){ if(str2[j] >= 'A' && str2[j] <= 'Z'){ ++ctr[str2[j] - 'A']; } } char last[255]; scanf("%s", &last); int lens = strlen (last); for(int i = 0; i < lens; i++){ if(last[i] >= 'A' && last[i] <= 'Z'){ ++ctrl[last[i] - 'A']; } } int flag = 1; for(int i = 0; i < 26; i++){ if(ctr[i] != ctrl[i]){ flag = 0; break; } } if(flag == 1){ printf("YES\n"); }else{ printf("NO\n"); } }
/* * Get the glyph index of a given glyph name. * * Note: * This method uses driver specific objects to do the translation. * * A return value of 0 means `undefined character code'. * * Examples: * index = face.name_index glyph_name * */ static VALUE ft_face_name_index(VALUE self, VALUE glyph_name) { FT_Face *face; Data_Get_Struct(self, FT_Face, face); return INT2FIX(FT_Get_Name_Index(*face, RSTRING_PTR(glyph_name))); }
/* * Write an empty hiber_info to the swap signature block, which is * guaranteed to not match any valid hib. */ int hibernate_clear_signature(void) { union hibernate_info blank_hiber_info; union hibernate_info hib; memset(&blank_hiber_info, 0, sizeof(union hibernate_info)); if (get_hibernate_info(&hib, 0)) return (1); DPRINTF("clearing hibernate signature block location: %lld\n", hib.sig_offset); if (hibernate_block_io(&hib, hib.sig_offset, DEV_BSIZE, (vaddr_t)&blank_hiber_info, 1)) printf("Warning: could not clear hibernate signature\n"); return (0); }
/*====================================================================* * * void func (char * buffer, size_t length, size_t extent, unsigned start, flag_t flags); * * read from ifp and write to ofp; modify marked c language comment lines * to creaate clear section breaks and standard program annotations; * * replace occurances of [/@...@] and [ @...@/] comments with standard * length bars; * * delete empty lines at the start of the file; append one empty line to the * end of the file if missing; remove redundant empty lines elsewhere; insert * an empty line before and after cmassoc comment blocks; * *. Motley Tools by Charles Maier; *: Copyright (c) 2001-2006 by Charles Maier Associates Limited; *; Licensed under the Internet Software Consortium License; * *--------------------------------------------------------------------*/ void function (struct _column_ columns [], struct _column_ outputs [], flag_t flags) { struct _column_ * column; struct _record_ * record; struct _record_ one; struct _record_ two; char ** vector; char * string; one.next = & two; two.next = & one; record = & two; for (string = record->buffer; fgets (string, BUFFER_SIZE, stdin); string = record->buffer) { vector = record->vector; for (* vector++ = string; (* string) && ((string - record->buffer) < (BUFFER_SIZE -1)); string++) { if (isspace (* string) && ((vector - record->vector) < (VECTOR_SIZE -1))) { * vector++ = string + 1; * string = (char) (0); } } * vector = (char *) (0); for (column = columns; ~ column->number; column++) { if (strcmp (record->vector [column->number], column->string)) { break; } } if (! ~ column->number) { for (column = outputs; ~ column->number; column++) { printf ("%4lu %s:%s\n", (long unsigned) (column->number), column->string, record->vector [column->number]); } printf ("\n"); } record = record->next; } return; }
/* On platforms where long double is as wide as double. */ long double hypotl (long double x, long double y) { #ifdef _LDBL_EQ_DBL return hypot(x, y); #else long double z; z = __ieee754_hypotl (x, y); if (_LIB_VERSION == _IEEE_) return z; if ((! finitel (z)) && finitel (x) && finitel (y)) { struct exception exc; exc.type = OVERFLOW; exc.name = "hypotl"; exc.err = 0; exc.arg1 = x; exc.arg2 = y; if (_LIB_VERSION == _SVID_) exc.retval = HUGE; else { #ifndef HUGE_VAL #define HUGE_VAL inf double inf = 0.0; SET_HIGH_WORD (inf, 0x7ff00000); #endif exc.retval = HUGE_VAL; } if (_LIB_VERSION == _POSIX_) errno = ERANGE; else if (! matherr (& exc)) errno = ERANGE; if (exc.err != 0) errno = exc.err; return (long double) exc.retval; } return z; #endif }
/** * Initialize the display input device subsystem */ void lv_indev_init(void) { #if LV_INDEV_READ_PERIOD != 0 lv_task_create(indev_proc_task, LV_INDEV_READ_PERIOD, LV_TASK_PRIO_MID, NULL); #endif lv_indev_reset(NULL); }
/** * Reads integers from the indicated file into the provided array. * * Returns the number of integers read. */ size_t read_integers(const char *const filename, int *integer_array, const size_t integer_array_size) { FILE *file; size_t next_index = 0; file = fopen(filename, "r"); if (file) { while (next_index < integer_array_size && fscanf(file, "%d", &integer_array[next_index]) != EOF) { next_index++; } fclose(file); } return next_index; }
/** * * @brief Test integer types library * * @return TC_PASS or TC_FAIL */ int stdintTest(void) { TC_PRINT("Testing stdint.h library ...\n"); if (unsignedInt + unsignedByte + 1u != 0) { return TC_FAIL; } return TC_PASS; }
/* * This function is used to terminate current application returning an 'EXIT_FAILURE' * displaying a specified error message. * * @param *error_msg -> An error message. */ void exit_failure(char *error_msg) { fprintf(stderr, "%s", error_msg); exit(EXIT_FAILURE); }
// SPDX-License-Identifier: GPL-2.0-only /* * Interrupt bottom half (BH). * * Copyright (c) 2017-2020, Silicon Laboratories, Inc. * Copyright (c) 2010, ST-Ericsson */ #include <linux/gpio/consumer.h> #include <net/mac80211.h> #include "bh.h" #include "wfx.h" #include "hwio.h" #include "traces.h" #include "hif_rx.h" #include "hif_api_cmd.h" static void device_wakeup(struct wfx_dev *wdev) { int max_retry = 3; if (!wdev->pdata.gpio_wakeup) return; if (gpiod_get_value_cansleep(wdev->pdata.gpio_wakeup) > 0) return; if (wfx_api_older_than(wdev, 1, 4)) { gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1); if (!completion_done(&wdev->hif.ctrl_ready)) usleep_range(2000, 2500); return; } for (;;) { gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1); // completion.h does not provide any function to wait // completion without consume it (a kind of // wait_for_completion_done_timeout()). So we have to emulate // it. if (wait_for_completion_timeout(&wdev->hif.ctrl_ready, msecs_to_jiffies(2))) { complete(&wdev->hif.ctrl_ready); return; } else if (max_retry-- > 0) { // Older firmwares have a race in sleep/wake-up process. // Redo the process is sufficient to unfreeze the // chip. dev_err(wdev->dev, "timeout while wake up chip\n"); gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 0); usleep_range(2000, 2500); } else { dev_err(wdev->dev, "max wake-up retries reached\n"); return; } } } static void device_release(struct wfx_dev *wdev) { if (!wdev->pdata.gpio_wakeup) return; gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 0); } static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf) { struct sk_buff *skb; struct hif_msg *hif; size_t alloc_len; size_t computed_len; int release_count; int piggyback = 0; WARN(read_len > round_down(0xFFF, 2) * sizeof(u16), "%s: request exceed WFx capability", __func__); // Add 2 to take into account piggyback size alloc_len = wdev->hwbus_ops->align_size(wdev->hwbus_priv, read_len + 2); skb = dev_alloc_skb(alloc_len); if (!skb) return -ENOMEM; if (wfx_data_read(wdev, skb->data, alloc_len)) goto err; piggyback = le16_to_cpup((__le16 *)(skb->data + alloc_len - 2)); _trace_piggyback(piggyback, false); hif = (struct hif_msg *)skb->data; WARN(hif->encrypted & 0x3, "encryption is unsupported"); if (WARN(read_len < sizeof(struct hif_msg), "corrupted read")) goto err; computed_len = le16_to_cpu(hif->len); computed_len = round_up(computed_len, 2); if (computed_len != read_len) { dev_err(wdev->dev, "inconsistent message length: %zu != %zu\n", computed_len, read_len); print_hex_dump(KERN_INFO, "hif: ", DUMP_PREFIX_OFFSET, 16, 1, hif, read_len, true); goto err; } if (!(hif->id & HIF_ID_IS_INDICATION)) { (*is_cnf)++; if (hif->id == HIF_CNF_ID_MULTI_TRANSMIT) release_count = ((struct hif_cnf_multi_transmit *)hif->body)->num_tx_confs; else release_count = 1; WARN(wdev->hif.tx_buffers_used < release_count, "corrupted buffer counter"); wdev->hif.tx_buffers_used -= release_count; } _trace_hif_recv(hif, wdev->hif.tx_buffers_used); if (hif->id != HIF_IND_ID_EXCEPTION && hif->id != HIF_IND_ID_ERROR) { if (hif->seqnum != wdev->hif.rx_seqnum) dev_warn(wdev->dev, "wrong message sequence: %d != %d\n", hif->seqnum, wdev->hif.rx_seqnum); wdev->hif.rx_seqnum = (hif->seqnum + 1) % (HIF_COUNTER_MAX + 1); } skb_put(skb, le16_to_cpu(hif->len)); // wfx_handle_rx takes care on SKB livetime wfx_handle_rx(wdev, skb); if (!wdev->hif.tx_buffers_used) wake_up(&wdev->hif.tx_buffers_empty); return piggyback; err: if (skb) dev_kfree_skb(skb); return -EIO; } static int bh_work_rx(struct wfx_dev *wdev, int max_msg, int *num_cnf) { size_t len; int i; int ctrl_reg, piggyback; piggyback = 0; for (i = 0; i < max_msg; i++) { if (piggyback & CTRL_NEXT_LEN_MASK) ctrl_reg = piggyback; else if (try_wait_for_completion(&wdev->hif.ctrl_ready)) ctrl_reg = atomic_xchg(&wdev->hif.ctrl_reg, 0); else ctrl_reg = 0; if (!(ctrl_reg & CTRL_NEXT_LEN_MASK)) return i; // ctrl_reg units are 16bits words len = (ctrl_reg & CTRL_NEXT_LEN_MASK) * 2; piggyback = rx_helper(wdev, len, num_cnf); if (piggyback < 0) return i; if (!(piggyback & CTRL_WLAN_READY)) dev_err(wdev->dev, "unexpected piggyback value: ready bit not set: %04x\n", piggyback); } if (piggyback & CTRL_NEXT_LEN_MASK) { ctrl_reg = atomic_xchg(&wdev->hif.ctrl_reg, piggyback); complete(&wdev->hif.ctrl_ready); if (ctrl_reg) dev_err(wdev->dev, "unexpected IRQ happened: %04x/%04x\n", ctrl_reg, piggyback); } return i; } static void tx_helper(struct wfx_dev *wdev, struct hif_msg *hif) { int ret; void *data; bool is_encrypted = false; size_t len = le16_to_cpu(hif->len); WARN(len < sizeof(*hif), "try to send corrupted data"); hif->seqnum = wdev->hif.tx_seqnum; wdev->hif.tx_seqnum = (wdev->hif.tx_seqnum + 1) % (HIF_COUNTER_MAX + 1); data = hif; WARN(len > wdev->hw_caps.size_inp_ch_buf, "%s: request exceed WFx capability: %zu > %d\n", __func__, len, wdev->hw_caps.size_inp_ch_buf); len = wdev->hwbus_ops->align_size(wdev->hwbus_priv, len); ret = wfx_data_write(wdev, data, len); if (ret) goto end; wdev->hif.tx_buffers_used++; _trace_hif_send(hif, wdev->hif.tx_buffers_used); end: if (is_encrypted) kfree(data); } static int bh_work_tx(struct wfx_dev *wdev, int max_msg) { struct hif_msg *hif; int i; for (i = 0; i < max_msg; i++) { hif = NULL; if (wdev->hif.tx_buffers_used < wdev->hw_caps.num_inp_ch_bufs) { if (try_wait_for_completion(&wdev->hif_cmd.ready)) { WARN(!mutex_is_locked(&wdev->hif_cmd.lock), "data locking error"); hif = wdev->hif_cmd.buf_send; } else { hif = wfx_tx_queues_get(wdev); } } if (!hif) return i; tx_helper(wdev, hif); } return i; } /* In SDIO mode, it is necessary to make an access to a register to acknowledge * last received message. It could be possible to restrict this acknowledge to * SDIO mode and only if last operation was rx. */ static void ack_sdio_data(struct wfx_dev *wdev) { u32 cfg_reg; config_reg_read(wdev, &cfg_reg); if (cfg_reg & 0xFF) { dev_warn(wdev->dev, "chip reports errors: %02x\n", cfg_reg & 0xFF); config_reg_write_bits(wdev, 0xFF, 0x00); } } static void bh_work(struct work_struct *work) { struct wfx_dev *wdev = container_of(work, struct wfx_dev, hif.bh); int stats_req = 0, stats_cnf = 0, stats_ind = 0; bool release_chip = false, last_op_is_rx = false; int num_tx, num_rx; device_wakeup(wdev); do { num_tx = bh_work_tx(wdev, 32); stats_req += num_tx; if (num_tx) last_op_is_rx = false; num_rx = bh_work_rx(wdev, 32, &stats_cnf); stats_ind += num_rx; if (num_rx) last_op_is_rx = true; } while (num_rx || num_tx); stats_ind -= stats_cnf; if (last_op_is_rx) ack_sdio_data(wdev); if (!wdev->hif.tx_buffers_used && !work_pending(work)) { device_release(wdev); release_chip = true; } _trace_bh_stats(stats_ind, stats_req, stats_cnf, wdev->hif.tx_buffers_used, release_chip); } /* * An IRQ from chip did occur */ void wfx_bh_request_rx(struct wfx_dev *wdev) { u32 cur, prev; control_reg_read(wdev, &cur); prev = atomic_xchg(&wdev->hif.ctrl_reg, cur); complete(&wdev->hif.ctrl_ready); queue_work(system_highpri_wq, &wdev->hif.bh); if (!(cur & CTRL_NEXT_LEN_MASK)) dev_err(wdev->dev, "unexpected control register value: length field is 0: %04x\n", cur); if (prev != 0) dev_err(wdev->dev, "received IRQ but previous data was not (yet) read: %04x/%04x\n", prev, cur); } /* * Driver want to send data */ void wfx_bh_request_tx(struct wfx_dev *wdev) { queue_work(system_highpri_wq, &wdev->hif.bh); } /* * If IRQ is not available, this function allow to manually poll the control * register and simulate an IRQ ahen an event happened. * * Note that the device has a bug: If an IRQ raise while host read control * register, the IRQ is lost. So, use this function carefully (only duing * device initialisation). */ void wfx_bh_poll_irq(struct wfx_dev *wdev) { ktime_t now, start; u32 reg; WARN(!wdev->poll_irq, "unexpected IRQ polling can mask IRQ"); start = ktime_get(); for (;;) { control_reg_read(wdev, &reg); now = ktime_get(); if (reg & 0xFFF) break; if (ktime_after(now, ktime_add_ms(start, 1000))) { dev_err(wdev->dev, "time out while polling control register\n"); return; } udelay(200); } wfx_bh_request_rx(wdev); } void wfx_bh_register(struct wfx_dev *wdev) { INIT_WORK(&wdev->hif.bh, bh_work); init_completion(&wdev->hif.ctrl_ready); init_waitqueue_head(&wdev->hif.tx_buffers_empty); } void wfx_bh_unregister(struct wfx_dev *wdev) { flush_work(&wdev->hif.bh); }
/** * Create a native pointer property to store the native pointer and its type info. * * @return true - if property was just created with specified value, * false - otherwise, if property existed before the call, it's value was updated */ bool ecma_create_native_pointer_property (ecma_object_t *obj_p, void *native_p, void *info_p) { ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER); ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); bool is_new = (property_p == NULL); ecma_native_pointer_t *native_pointer_p; if (is_new) { ecma_property_value_t *value_p; value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, &property_p); ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY (property_p); native_pointer_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_t)); ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p); } else { ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p); native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value); } native_pointer_p->data_p = native_p; native_pointer_p->info_p = info_p; return is_new; }
/* Note that the caller is responsible to free memory */ char *Function4a(const char *arg1, const char *arg2) { strncpy(last_function_called, "Function4a", MAXLAST); size_t narg1 = strlen(arg1); size_t narg2 = strlen(arg2); char *out = malloc(narg1 + narg2 + 1); sprintf(out, "%s%s", arg1, arg2); return out; }
/* * The only thing _pam_set_credentials_unix() does is initialization of * UNIX group IDs. * * Well, everybody but me on linux-pam is convinced that it should not * initialize group IDs, so I am not doing it but don't say that I haven't * warned you. -- AOY */ int pam_sm_setcred (pam_handle_t *pamh, int flags, int argc, const char **argv) { int retval; const void *pretval = NULL; unsigned long long ctrl; D(("called.")); ctrl = _set_ctrl(pamh, flags, NULL, NULL, NULL, argc, argv); retval = PAM_SUCCESS; D(("recovering return code from auth call")); if (on(UNIX_LIKE_AUTH, ctrl) && pam_get_data(pamh, "unix_setcred_return", &pretval) == PAM_SUCCESS && pretval) { retval = *(const int *)pretval; pam_set_data(pamh, "unix_setcred_return", NULL, NULL); D(("recovered data indicates that old retval was %d", retval)); } return retval; }
/* *---------------------------------------------------------------------- * * ConfigurePanedWindow -- * * This function is called to process an argv/argc list in conjunction * with the Tk option database to configure (or reconfigure) a paned * window widget. * * Results: * The return value is a standard Tcl result. If TCL_ERROR is returned, * then the interp's result contains an error message. * * Side effects: * Configuration information, such as colors, border width, etc. get set * for pwPtr; old resources get freed, if there were any. * *---------------------------------------------------------------------- */ static int ConfigurePanedWindow( Tcl_Interp *interp, PanedWindow *pwPtr, int objc, Tcl_Obj *const objv[]) { Tk_SavedOptions savedOptions; int typemask = 0; if (Tk_SetOptions(interp, (char *) pwPtr, pwPtr->optionTable, objc, objv, pwPtr->tkwin, &savedOptions, &typemask) != TCL_OK) { Tk_RestoreSavedOptions(&savedOptions); return TCL_ERROR; } Tk_FreeSavedOptions(&savedOptions); PanedWindowWorldChanged(pwPtr); if (typemask & GEOMETRY) { ComputeGeometry(pwPtr); } return TCL_OK; }
/* * Dump everything we know about pArchive. * * This will only print the records that we have seen so far. If the * application hasn't caused us to scan through all of the records in * the archive, then this won't be very interesting. This will never * show any records for streaming-mode archives. */ void Nu_DebugDumpAll(NuArchive* pArchive) { Assert(pArchive != NULL); printf("*Archive pathname: '%s'\n", pArchive->archivePathnameUNI); printf("*Archive type: %d\n", pArchive->archiveType); printf("*Header offset: %ld (junk offset=%ld)\n", pArchive->headerOffset, pArchive->junkOffset); printf("*Num records: %u orig, %u copy, %u new\n", Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet), Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet), Nu_RecordSet_GetNumRecords(&pArchive->newRecordSet)); printf("*NuRecordIdx seed: %u NuRecordIdx next: %u\n", pArchive->recordIdxSeed, pArchive->nextRecordIdx); Nu_DebugDumpMH(&pArchive->masterHeader); printf(" *ORIG record set (x-ref with COPY):\n"); Nu_DebugDumpRecordSet(pArchive, &pArchive->origRecordSet, &pArchive->copyRecordSet); printf(" *NEW record set:\n"); Nu_DebugDumpRecordSet(pArchive, &pArchive->newRecordSet, NULL); if (!Nu_RecordSet_GetLoaded(&pArchive->origRecordSet) && !Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) { printf("*** DEBUG: original records not loaded yet? ***\n"); } }
#include<stdio.h> int main() { int n, a[11][11]; scanf("%d",&n); a[1][1]=a[1][2]=a[1][3]=a[1][4]=a[1][5]=a[1][6]=a[1][7]=a[1][8]=a[1][9]=a[1][10]=1; a[2][1]=a[3][1]=a[4][1]=a[5][1]=a[6][1]=a[7][1]=a[8][1]=a[9][1]=a[10][1]=1; for(int i=2; i<=n; i++) { for(int j=2; j<=i; j++) { a[i][j] = a[i-1][j] + a[i][j-1]; a[j][i] =a[i][j]; } } printf("%d\n",a[n][n]); return 0; }
/** ******************************************************************************* ** \brief Clear spi status. ** ** \param [in] u8Channel Spi channel ** \arg SpiCh4 Spi channel 4 ** \arg SpiCh5 Spi channel 5 ** \arg SpiCh6 Spi channel 6 ** ** \param [in] enStatus Spi status ** \arg SpiOverrunError Spi overrun error flag ** \arg SpiRxFull Spi rx buffer full flag ** \arg SpiTxEmpty Spi tx buffer empty flag ** \arg SpiTxIdle Spi tx bus idle flag ** \arg SpiCsErrIntFlag Spi cs error interrupt flag ** \arg SpiSerialTimerIntFlag Spi serial timer interrupt flag ** ** \retval Ok Process successfully done ** \retval ErrorInvalidParameter If one of following conditions are met: ** - Get instance data fail ** - enStatus is invalid ** ******************************************************************************/ en_result_t Spi_ClrStatus(uint8_t u8Channel, en_spi_status_t enStatus) { en_result_t enRet = Ok; stc_spi_instance_data_t *pstcInst = NULL; M0P_MSC_SPI_TypeDef *pstcSPI = NULL; ASSERT(IS_VALID_STAT(enStatus)); pstcInst = SpiGetInternDataPtr(u8Channel); DEBUG_CHECK_INST(pstcInst); if ((NULL == pstcInst) || (NULL == pstcInst->pstcInstance)) { return ErrorInvalidParameter; } pstcSPI = pstcInst->pstcInstance; switch (enStatus) { case SpiOverrunError: pstcSPI->SR_f.RECLR = TRUE; break; case SpiRxFull: case SpiTxEmpty: case SpiTxIdle: break; case SpiCsErrIntFlag: pstcSPI->EACR_f.CSER = FALSE; break; case SpiSerialTimerIntFlag: pstcSPI->EACR_f.TIF = FALSE; break; default: enRet = ErrorInvalidParameter; break; } return enRet; }
/* call a control on the local node */ NTSTATUS ctdbd_control_local(struct ctdbd_connection *conn, uint32 opcode, uint64_t srvid, uint32_t flags, TDB_DATA data, TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int *cstatus) { return ctdbd_control(conn, CTDB_CURRENT_NODE, opcode, srvid, flags, data, mem_ctx, outdata, cstatus); }
// displaying the array s and related information int gshow(char message[1024]){ system("clear"); int i=-1,j=-1,k,l; printf("\n"); printf("\nNETOWRK BATTLESHIP V 1.0.1 Beta (c) Paul George For GCI LABS\n"); for (i=-1;i<10;i++){ for(j=-1;j<10;j++){ if(i==-1&&j==-1){ printf(" x\\y "); } else if (i==-1){ printf(" %2d ",j+1); } else if(j==-1){ printf(" %2d ",i+1); } else{ status(home[i][j]); } } printf("\n"); } printf("ships remaing to attack: %2d",placescheckaway()); printf("\tships left : %2d",placescheckhome()); printf("\n"); for (i=-1;i<10;i++){ for(j=-1;j<10;j++){ if(i==-1&&j==-1){ printf(" x\\y "); } else if (i==-1){ printf(" %2d ",j+1); } else if(j==-1){ printf(" %2d ",i+1); } else{ status(away[i][j]); } } printf("\n"); } puts(message); }
#include <stdio.h> #define MAX 2000001 int A[MAX],B[MAX],C[MAX]; void ShowData(int n) { int i; for (i = 1; i <= n ; i++){ printf("%u", B[i]); if(i<n)printf(" "); } printf("\n"); } void CountingSort( int n) { int i, j, k; for (i=0;i<=MAX;i++) C[i] = 0; for (j=1;j<=n;j++){ scanf("%d",&A[j]); C[A[j]]++; } for (i=1;i<=MAX;i++) { C[i] += C[i-1]; } for (j=n;j>0;j--) { B[C[A[j]]] = A[j]; C[A[j]]--; } } int main(void) { int i,n; scanf("%d",&n); CountingSort(n); ShowData(n); return 0; }
/** * AT server print all commands to AT device */ void rt_at_server_print_all_cmd(void) { rt_size_t i = 0; at_server_printfln("Commands list : "); for (i = 0; i < cmd_num; i++) { at_server_printf("%s", cmd_table[i].name); if (cmd_table[i].args_expr) { at_server_printfln("%s", cmd_table[i].args_expr); } else { at_server_printf("%c%c", AT_CMD_CR, AT_CMD_LF); } } }
/** * Idle function for unassigned brokers * If \p timeout_ms is not RD_POLL_INFINITE the serve loop will be exited * regardless of state after this long (approximately). */ static void rd_kafka_broker_ua_idle (rd_kafka_broker_t *rkb, int timeout_ms) { int initial_state = rkb->rkb_state; rd_ts_t abs_timeout; if (rd_kafka_terminating(rkb->rkb_rk)) timeout_ms = 1; else if (timeout_ms == RD_POLL_INFINITE) timeout_ms = rkb->rkb_blocking_max_ms; abs_timeout = rd_timeout_init(timeout_ms); do { rd_kafka_broker_toppars_serve(rkb); rd_kafka_broker_serve(rkb, abs_timeout); } while (!rd_kafka_broker_terminating(rkb) && (int)rkb->rkb_state == initial_state && !rd_timeout_expired(rd_timeout_remains(abs_timeout))); }
/*-------------------------------------------------------------------------------------- Inputs the unformatted message to the socket ----------------------------------------------------------------------------------------*/ int cef_client_message_input ( CefT_Client_Handle fhdl, unsigned char* msg, size_t len ) { CefT_Connect* conn = (CefT_Connect*) fhdl; if (len > 0) { if (conn->ai) { sendto (conn->sock, msg, len , 0, conn->ai->ai_addr, conn->ai->ai_addrlen); } else { #if 0 slen = send (conn->sock, msg, len, 0); #else int res = 0; unsigned char* p = msg; size_t slen = len; RSEND:; while( slen > 0 ){ while( 1 ){ res = send (conn->sock, p, slen, 0); if( errno != EINTR ) { break; } } if( res < 0 ){ if( errno == EAGAIN || errno == EWOULDBLOCK ){ while(1){ fd_set fds, writefds; int n; struct timeval timeout; int rcount; rcount = 0; timeout.tv_sec = 0; timeout.tv_usec = 1000; FD_ZERO(&writefds); FD_SET(conn->sock, &writefds); memcpy(&fds, &writefds, sizeof(fds)); n = select(conn->sock+1, NULL, &fds, NULL, &timeout); if (n > 0 ) { if (FD_ISSET(conn->sock, &fds)) { goto RSEND; } } rcount ++; if (rcount > 2){ fprintf(stderr, "[%s](%d): ########### SOCKET is Busy((slen=%zu, res=%d, %s) \n", __FUNCTION__, __LINE__, slen, res, strerror (errno)); return(-1); } } } else{ fprintf(stderr, "[%s](2): ########### ERROR=%s \n", __FUNCTION__, strerror (errno)); close (conn->sock); conn->sock = -1; return (res); } } if(res > 0){ slen -= res; p += res; } } #endif } } return (1); }
/** Updates the control's info. * This is useful for a program that may be idle for a period of time. * @param ctl An initialized control handle. * @ingroup libtinyalsa-mixer */ void mixer_ctl_update(struct mixer_ctl *ctl) { struct mixer_ctl_group *grp; if (!ctl) return; grp = ctl->grp; grp->ops->ioctl(grp->data, SNDRV_CTL_IOCTL_ELEM_INFO, &ctl->info); }
/** * Read and word from an open file stream * A word means a group of letters Aa-Zz or numbers 0-9 * @param file The file stream to read from * @return A pointer to the read word */ char * readWord(FILE * file) { char temp[255] = { '\0' }; int i = 0; char c; while ((c = fgetc(file)) != EOF) { if (isLetterOrNumber(c)) { temp[i++] = c; temp[i] = '\0'; } else { if (strlen(temp) == 0) { continue; } else { break; } } } if (strlen(temp) == 0) { return NULL; } char * word = (char *)malloc(strlen(temp)); strcpy(word, temp); return word; }
/* * Store svc_ctx for processing during RNG_RPT * Return BCME_OK only when svc is added */ static int wl_cfgnan_update_ranging_svc_inst(nan_ranging_inst_t *ranging_inst, nan_svc_info_t *svc) { int ret = BCME_OK; int i = 0; for (i = 0; i < MAX_SUBSCRIBES; i++) { if (ranging_inst->svc_idx[i] == svc) { WL_DBG(("SVC Ctx for ranging already present, " " Duplication not supported: sub_id: %d\n", svc->svc_id)); ret = BCME_UNSUPPORTED; goto done; } } for (i = 0; i < MAX_SUBSCRIBES; i++) { if (ranging_inst->svc_idx[i]) { continue; } else { WL_DBG(("Adding SVC Ctx for ranging..svc_id %d\n", svc->svc_id)); ranging_inst->svc_idx[i] = svc; ranging_inst->num_svc_ctx++; ret = BCME_OK; goto done; } } if (i == MAX_SUBSCRIBES) { WL_ERR(("wl_cfgnan_update_ranging_svc_inst: " "No resource to hold Ref SVC ctx..svc_id %d\n", svc->svc_id)); ret = BCME_NORESOURCE; goto done; } done: return ret; }
// domain died, presume it's dead on all cpu's, not just mostly dead static void qos_kill_thread(int domid) { int cpu; for (cpu=0; cpu<NCPU; cpu++) { cpu_qos_data[cpu]->domain_info[indexof(domid)].in_use = 0; } }
/**************************************************************************** * Name: tiva_gpioread * * Description: * Read one or zero from the selected GPIO pin * ****************************************************************************/ bool tiva_gpioread(pinconfig_t pinconfig) { unsigned int dio; dio = (pinconfig->gpio & GPIO_DIO_MASK) >> GPIO_DIO_SHIFT; return (getreg32(TIVA_GPIO_DIN) & (1 << dio)) != 0; }
//***************************************************************************** // //! \brief Returns the address of the specified DAC12_A data buffer for the DMA //! module. //! //! Returns the address of the specified memory buffer. This can be used in //! conjunction with the DMA to obtain the data directly from memory. //! //! \param baseAddress is the base address of the DAC12_A module. //! \param submoduleSelect decides which DAC12_A sub-module to configure. //! Valid values are: //! - \b DAC12_A_SUBMODULE_0 //! - \b DAC12_A_SUBMODULE_1 //! //! \return The address of the specified memory buffer // //***************************************************************************** uint32_t DAC12_A_getDataBufferMemoryAddressForDMA (uint32_t baseAddress, uint8_t submoduleSelect) { assert(submoduleSelect <= DAC12_A_SUBMODULE_1); return ( baseAddress + submoduleSelect + OFS_DAC12_0DAT ); }
// This is a generic function, which // doesn't span the entire range of HFROSC settings. // It only adjusts the trim, which can span a hundred MHz or so. // This function does not check the legality of the PLL settings // at all, and it is quite possible to configure invalid PLL settings // this way. // It returns the actual measured CPU frequency. uint32_t PRCI_set_hfrosctrim_for_f_cpu(uint32_t f_cpu, PRCI_freq_target target ) { uint32_t hfrosctrim = 0; uint32_t hfroscdiv = 4; uint32_t prev_trim = 0; uint32_t desired_hfrosc_freq = (f_cpu/ 16); PRCI_use_hfrosc(hfroscdiv, hfrosctrim); uint32_t cpu_freq = PRCI_measure_mcycle_freq(3000, RTC_FREQ); cpu_freq = PRCI_measure_mcycle_freq(3000, RTC_FREQ); uint32_t prev_freq = cpu_freq; while ((cpu_freq < desired_hfrosc_freq) && (hfrosctrim < 0x1F)){ prev_trim = hfrosctrim; prev_freq = cpu_freq; hfrosctrim ++; PRCI_use_hfrosc(hfroscdiv, hfrosctrim); cpu_freq = PRCI_measure_mcycle_freq(3000, RTC_FREQ); } if (prev_freq > desired_hfrosc_freq){ PRCI_use_pll(0, 0, 1, 31, 1, 1, hfroscdiv, prev_trim); cpu_freq = PRCI_measure_mcycle_freq(1000, RTC_FREQ); return cpu_freq; } if (cpu_freq < desired_hfrosc_freq){ PRCI_use_pll(0, 0, 1, 31, 1, 1, hfroscdiv, prev_trim); cpu_freq = PRCI_measure_mcycle_freq(1000, RTC_FREQ); return cpu_freq; } switch(target) { case(PRCI_FREQ_CLOSEST): if ((desired_hfrosc_freq - prev_freq) < (cpu_freq - desired_hfrosc_freq)) { PRCI_use_pll(0, 0, 1, 31, 1, 1, hfroscdiv, prev_trim); } else { PRCI_use_pll(0, 0, 1, 31, 1, 1, hfroscdiv, hfrosctrim); } break; case(PRCI_FREQ_UNDERSHOOT): PRCI_use_pll(0, 0, 1, 31, 1, 1, hfroscdiv, prev_trim); break; default: PRCI_use_pll(0, 0, 1, 31, 1, 1, hfroscdiv, hfrosctrim); } cpu_freq = PRCI_measure_mcycle_freq(1000, RTC_FREQ); return cpu_freq; }
#include <stdio.h> #include <string.h> char a[1000][1001]; char r[16][1000][1001]; typedef struct { int x, y; } point; point rcoords[16][2]; int fill(int rc, int x1, int y1, int x2, int y2) { int i; if (x1 == x2) { for (i = y1; i <= y2; i++) r[rc][x1][i] = '#'; } else if (y1 == y2) { for (i = x1; i <= x2; i++) r[rc][i][y1] = '#'; } } int inters(int x1, int y11, int y12, int x21, int x22, int y2, int *x, int *y) { // puts("inters"); if (!(x21 <= x1 && x1 <= x22)) return 0; if (!(y11 <= y2 && y2 <= y12)) return 0; *x = x1; *y = y2; return 1; } int main() { int n, m; scanf("%d%d", &n, &m); int i; for (i = 0; i < n; i++) scanf("%s", a[i]); int vn = 0, vx[1000], vy1[1000], vy2[1000], hn = 0, hy[1000], hx1[1000], hx2[1000]; int x, y; for (x = 0; x < n; x++) { // printf("x = %d\n", x); y = 0; while (y < m) { while (y < m && a[x][y] == '.') y++; if (y >= m) break; vx[vn] = x; vy1[vn] = y; while (y < m && a[x][y] == '#') y++; vy2[vn] = y-1; if (vy2[vn]-vy1[vn]+1 < 3) continue; // printf("%d %d %d\n", vx[vn], vy1[vn], vy2[vn]); vn++; } } for (y = 0; y < m; y++) { x = 0; // printf("y = %d\n", y); while (x < n) { // printf("x = %d\n", x); while (x < n && a[x][y] == '.') x++; if (x >= n) break; hy[hn] = y; hx1[hn] = x; while (x < n && a[x][y] == '#') x++; hx2[hn] = x-1; if (hx2[hn]-hx1[hn]+1 < 3) continue; // printf("h %d %d %d\n", hy[hn], hx1[hn], hx2[hn]); hn++; } } // printf("%d %d\n", hn, vn); if (hn > 4) { for (i = 2; i <= 3; i++) { hy[i] = hy[hn-(4-i)]; hx1[i] = hx1[hn-(4-i)]; hx2[i] = hx2[hn-(4-i)]; } hn = 4; } if (vn > 4) { for (i = 2; i <= 3; i++) { vx[i] = vx[vn-(4-i)]; vy1[i] = vy1[vn-(4-i)]; vy2[i] = vy2[vn-(4-i)]; } vn = 4; } // puts("!"); int i1, i2, j1, j2; int rc = 0; memset(r, '.', sizeof(r)); for (i1 = 0; i1 < vn; i1++) for (i2 = i1; i2 < vn; i2++) for (j1 = 0; j1 < hn; j1++) for (j2 = j1; j2 < hn; j2++) { // printf("i,j: %d %d %d %d", i1, i2, j1, j2); int x1, y1, x2, y2, x3, y3, x4, y4; int b1 = inters(vx[i1], vy1[i1], vy2[i1], hx1[j1], hx2[j1], hy[j1], &x1, &y1); int b2 = inters(vx[i2], vy1[i2], vy2[i2], hx1[j1], hx2[j1], hy[j1], &x2, &y2); int b3 = inters(vx[i1], vy1[i1], vy2[i1], hx1[j2], hx2[j2], hy[j2], &x3, &y3); int b4 = inters(vx[i2], vy1[i2], vy2[i2], hx1[j2], hx2[j2], hy[j2], &x4, &y4); if (!(b1 && b2 && b3 && b4)) continue; if (y1 != y2 || x2-x1 < 2) continue; if (x1 != x3 || y3-y1 < 2) continue; if (x2 != x4 || y4-y2 < 2) continue; if (y3 != y4 || x4-x3 < 2) continue; fill(rc, x1, y1, x2, y2); fill(rc, x2, y2, x4, y4); fill(rc, x3, y3, x4, y4); fill(rc, x1, y1, x3, y3); point coords[2] = {{x1, y1}, {x4, y4}}; memcpy(rcoords[rc], coords, sizeof(coords)); /* for (x = 0; x < n; x++) { for (y = 0; y < m; y++) putchar(r[rc][x][y]); putchar('\n'); } */ rc++; } // puts("!!"); int j; for (i = 0; i < rc; i++) for (j = i; j < rc; j++) { int f = 1; for (x = 0; x < n && f; x++) { for (y = 0; y < m && f; y++) { if (r[i][x][y] == '#' || r[j][x][y] == '#') { if (a[x][y] != '#') f = 0; } else if (a[x][y] != '.') f = 0; } } if (f) { puts("YES"); printf("%d %d %d %d\n", rcoords[i][0].x+1, rcoords[i][0].y+1, rcoords[i][1].x+1, rcoords[i][1].y+1); printf("%d %d %d %d\n", rcoords[j][0].x+1, rcoords[j][0].y+1, rcoords[j][1].x+1, rcoords[j][1].y+1); return 0; } } puts("NO"); return 0; }
#include<stdio.h> int main(){ int two,one,i,j,k,l,n,m,ans; scanf("%d%d",&n,&m); two = n/2; one = n%2; while((two+one)%m!=0 && two!=0){ two = two-1; one = one+2; } if(two!=0) printf("%d\n",two+one); else{ if(one%m==0) printf("%d\n",one); else printf("%d\n",-1); } return 0; }
/*! Won't compile unless ScopedOnly is false */ void Commit() { static_assert(!ScopedOnly); m_previous.reset(); }
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<stdarg.h> #include<malloc.h> int main() { char RF[128]; int AF, i; while(scanf("%s", RF) != EOF){ i = 0; AF = 0; while(1){ if(RF[i] == 'M') { AF += 1000; i++; } else if(RF[i] == 'D') { if(RF[i+1] == 'M') { AF += 500; i += 2; } else { AF += 500; i++; } } else if(RF[i] == 'C') { if(RF[i+1] == 'D') { AF += 400; i += 2; } else if(RF[i+1] == 'M') { AF += 900; i += 2; } else { AF += 100; i++; } } else if(RF[i] == 'L') { if(RF[i+1] == 'C') { AF += 50; i += 2; } else if(RF[i+1] == 'D') { AF += 450; i += 2; } else if(RF[i+1] == 'M') { AF += 950; i += 2; } else { AF += 50; i++; } } else if(RF[i] == 'X') { if(RF[i+1] == 'L') { AF += 40; i += 2; } else if(RF[i+1] == 'C') { AF += 90; i += 2; } else if(RF[i+1] == 'D') { AF += 490; i += 2; } else if(RF[i+1] == 'M') { AF += 990; i += 2; } else { AF += 10; i++; } } else if(RF[i] == 'V') { if(RF[i+1] == 'X') { AF += 5; i += 2; } else if(RF[i+1] == 'L') { AF += 45; i += 2; } else if(RF[i+1] == 'C') { AF += 95; i += 2; } else if(RF[i+1] == 'D') { AF += 495; i += 2; } else if(RF[i+1] == 'M') { AF += 995; i += 2; } else { AF += 5; i++; } } else if(RF[i] == 'I') { if(RF[i+1] == 'V') { AF += 4; i += 2; } else if(RF[i+1] == 'X') { AF += 9; i += 2; } else if(RF[i+1] == 'L') { AF += 49; i += 2; } else if(RF[i+1] == 'C') { AF += 99; i += 2; } else if(RF[i+1] == 'D') { AF += 499; i += 2; } else if(RF[i+1] == 'M') { AF += 999; i += 2; } else { AF++; i++; } } else break; } printf("%d\n", AF); } return 0; }
/** * Decompresses an LZW compressed file. * TODO: Document exact details from spec. * * @param lzw The initialised LZW decompressor. * @return LZW_OKAY if successful, otherwise the error encountered. */ enum lzw_error lzw_decompress(struct lzw_decompressor *lzw) { assert(lzw); GUARD_ANY(lzw); int cur_code; struct dict_entry *cur_entry; read_next_code(lzw, &cur_code); GUARD_ANY(lzw); cur_entry = lookup_code(lzw, cur_code); GUARD(!cur_entry, LZW_INVALID_FORMAT_ERROR, lzw); lzw->error = write_next(lzw, cur_entry); GUARD_ANY(lzw); int last_code = cur_code; struct dict_entry *last_entry; while (read_next_code(lzw, &cur_code)) { assert(!lzw_has_error(lzw->error)); cur_entry = lookup_code(lzw, cur_code); last_entry = lookup_code(lzw, last_code); assert(last_entry); if (cur_entry) { assert(cur_entry->bytes); lzw->error = write_next(lzw, cur_entry); GUARD_ANY(lzw); struct dict_entry *new_entry; lzw->error = append_byte_and_add_to_dict( lzw, last_entry, cur_entry->bytes[0], &new_entry ); GUARD_ANY(lzw); last_code = cur_code; } else { assert(last_entry->bytes); struct dict_entry *new_entry; lzw->error = append_byte_and_add_to_dict( lzw, last_entry, last_entry->bytes[0], &new_entry ); GUARD_ANY(lzw); lzw->error = write_next(lzw, new_entry); GUARD_ANY(lzw); } } GUARD_ANY(lzw); return lzw->error; }
//creates and returns an elementwise copy of a node. uses malloc. struct node* copyNode(struct node* myNode) { struct node* copy = nodeAlloc(); copy->col = myNode->col; copy->row = myNode->row; copy->right = myNode->right; copy->down = myNode->down; copy->value = myNode->value; return copy; }
/* Enables or disables the specified interrupts */ static void ams_pmu_set_irq(enum ams_irq reg, char enable) { if (reg & AMS_IRQ_FREEFALL) { u8 val = ams_pmu_get_register(AMS_FF_ENABLE); if (enable) val |= 0x80; else val &= ~0x80; ams_pmu_set_register(AMS_FF_ENABLE, val); } if (reg & AMS_IRQ_SHOCK) { u8 val = ams_pmu_get_register(AMS_SHOCK_ENABLE); if (enable) val |= 0x80; else val &= ~0x80; ams_pmu_set_register(AMS_SHOCK_ENABLE, val); } if (reg & AMS_IRQ_GLOBAL) { u8 val = ams_pmu_get_register(AMS_CONTROL); if (enable) val |= 0x80; else val &= ~0x80; ams_pmu_set_register(AMS_CONTROL, val); } }
/**************************************************************************** * Name: can_mbfree * * Description: * Free one mailbox * * Input Parameters: * priv - A pointer to the private data structure for this CAN peripheral * mbndx - Index of the mailbox to be freed * * Returned Value: * None * * Assumptions: * The caller has exclusive access to the can data structures * ****************************************************************************/ static void can_mbfree(struct sam_can_s *priv, int mbndx) { uint8_t bit; DEBUGASSERT(priv && (unsigned)mbndx < SAM_CAN_NMAILBOXES); can_putreg(priv, SAM_CAN_IDR_OFFSET, CAN_INT_MB(mbndx)); can_putreg(priv, SAM_CAN_MNMR_OFFSET(mbndx), 0); bit = (1 << mbndx); DEBUGASSERT((priv->freemb & bit) != 0); DEBUGASSERT((priv->txmbset & bit) != 0); priv->freemb &= ~bit; priv->txmbset &= ~bit; }