TEST(StringTest, Case) { CString x = CS("xx"); CString X = CS("XX"); EXPECT_EQ(X, x.AsUpper()); EXPECT_EQ(x, X.AsLower()); }
int main(int argc, char **argv) { vector<const Row*> table; CapabilityController controller(table); TestStrategyControllable RRM("RRM"); BarBased TWS("TWS"); TestStrategyControllable CAL("CAL"); TestStrategyControllable CS("CS"); RRM.start(); CAL.start(); TWS.start(); CS.start(); map<const ICapability*, const IStrategyCommandFactory*> tws_capabilites; TestStrategyCommand shutdown_command("Shutdown"); SimpleCommandFactory shutdown_factory(shutdown_command); TestStrategyCommand tws_a_command("TWS to A!"); SimpleCommandFactory tws_a_factory(tws_a_command); tws_capabilites[&TestCapability::A] = &tws_a_factory; TestStrategyCommand tws_b_command("TWS to B!"); SimpleCommandFactory tws_b_factory(tws_b_command); tws_capabilites[&TestCapability::B] = &tws_b_factory; tws_capabilites[&TestCapability::Shutdown] = &shutdown_factory; vector<const IStrategyControllable*> tws_prereqs; tws_prereqs.push_back(&RRM); tws_prereqs.push_back(&CAL); Row tws_row(TWS, tws_capabilites, tws_prereqs); table.push_back(&tws_row); map<const ICapability*, const IStrategyCommandFactory*> cal_capabilites; TestStrategyCommand cal_a_command("CAL to A!"); SimpleCommandFactory cal_a_factory(cal_a_command); cal_capabilites[&TestCapability::A] = &cal_a_factory; TestStrategyCommand cal_b_command("CAL to B!"); SimpleCommandFactory cal_b_factory(cal_b_command); cal_capabilites[&TestCapability::B] = &cal_b_factory; cal_capabilites[&TestCapability::Shutdown] = &shutdown_factory; vector<const IStrategyControllable*> cal_prereqs; cal_prereqs.push_back(&RRM); Row cal_row(CAL, cal_capabilites, cal_prereqs); table.push_back(&cal_row); map<const ICapability*, const IStrategyCommandFactory*> cs_capabilites; TestStrategyCommand cs_a_command("CS to A!"); SimpleCommandFactory cs_a_factory(cs_a_command); cs_capabilites[&TestCapability::A] = &cs_a_factory; TestStrategyCommand cs_b_command("CS to B!"); SimpleCommandFactory cs_b_factory(cs_b_command); cs_capabilites[&TestCapability::B] = &cs_b_factory; cs_capabilites[&TestCapability::Shutdown] = &shutdown_factory; vector<const IStrategyControllable*> cs_prereqs; cs_prereqs.push_back(&RRM); cs_prereqs.push_back(&CAL); Row cs_row(CS, cs_capabilites, cs_prereqs); table.push_back(&cs_row); map<const ICapability*, const IStrategyCommandFactory*> rrm_capabilites; TestStrategyCommand rrm_a_command("RRM to A!"); SimpleCommandFactory rrm_a_factory(rrm_a_command); rrm_capabilites[&TestCapability::A] = &rrm_a_factory; TestStrategyCommand rrm_b_command("RRM to B!"); SimpleCommandFactory rrm_b_factory(rrm_b_command); rrm_capabilites[&TestCapability::B] = &rrm_b_factory; rrm_capabilites[&TestCapability::Shutdown] = &shutdown_factory; vector<const IStrategyControllable*> rrm_prereqs; Row rrm_row(RRM, rrm_capabilites, rrm_prereqs); table.push_back(&rrm_row); Thread::sleep(500); ChangeAt change_at_bar(ChangeAt::END_OF_BAR); TestStrategyChangeParameters params_bar(change_at_bar); cout << endl << "**********************" << endl; cout << "main: Asking for change to Capability A at end of bar" << endl; controller.changeCapability(TestCapability::A, params_bar); ChangeAt change_at_frame(ChangeAt::END_OF_FRAME); TestStrategyChangeParameters params_frame(change_at_frame); cout << endl << "**********************" << endl; cout << "main: Asking for change to Capability B at end of frame" << endl; controller.changeCapability(TestCapability::B, params_frame); ChangeAt change_at_now(ChangeAt::IMMEDIATE); TestStrategyChangeParameters params_now(change_at_now); cout << endl << "**********************" << endl; cout << "main: Asking for immediate shutdown" << endl; controller.changeCapability(TestCapability::Shutdown, params_now); RRM.join(); CAL.join(); TWS.join(); CS.join(); }
void weight_init(void) { double temp[64]; int i, z, x; #if USE_MMX_ASM const double dv_weight_bias_factor = (double)(1UL << DV_WEIGHT_BIAS); #endif W[0] = 1.0; W[1] = CS(4) / (4.0 * CS(7) * CS(2)); W[2] = CS(4) / (2.0 * CS(6)); W[3] = 1.0 / (2 * CS(5)); W[4] = 7.0 / 8.0; W[5] = CS(4) / CS(3); W[6] = CS(4) / CS(2); W[7] = CS(4) / CS(1); for (i=0;i<64;i++) temp[i] = 1.0; weight_88_inverse_float(temp); for (i=0;i<64;i++) { #if !USE_MMX_ASM dv_weight_inverse_88_matrix[i] = (dv_coeff_t)rint(temp[i]); #else /* If we're using MMX assembler, fold weights into the iDCT prescale */ preSC[i] *= temp[i] * (16.0 / dv_weight_bias_factor); #endif } for (z=0;z<4;z++) { for (x=0;x<8;x++) { dv_weight_inverse_248_matrix[z*8+x] = 1.0 / (W[x] * W[2*z] / 2); dv_weight_inverse_248_matrix[(z+4)*8+x] = 1.0 / (W[x] * W[2*z] / 2); } } dv_weight_inverse_248_matrix[0] = 4.0; }
#define CS(NAME, LABEL) B_CS_##NAME = 1u << CS_##NAME, CROSSTABS_STATS CROSSTABS_CELLS #undef CS B_CS_STATS_ALL = (1u << N_CROSSTABS_STATS) - 1, B_CS_CELLS_ALL = (1u << N_CROSSTABS_CELLS) - 1, B_CS_STATS_DEFAULT = B_CS_CHISQ, B_CS_CELL_DEFAULT = B_CS_COUNT | B_CS_ROW | B_CS_COLUMN | B_CS_TOTAL, B_CS_NONE }; static const struct checkbox_entry_item stats[] = { #define CS(NAME, LABEL) {#NAME, LABEL}, CROSSTABS_STATS \ CS(NONE, N_("None")) #undef CS }; static const struct checkbox_entry_item cells[] = { #define CS(NAME, LABEL) {#NAME, LABEL}, CROSSTABS_CELLS \ CS(NONE, N_("None")) #undef CS }; static void on_format_clicked (PsppireDialogActionCrosstabs *cd) { int ret;
cellInfo_t sql_eval( sqlInfo_t *db, Expr expr, tableInfo_t * table, cellInfo_t * row, int index, int total, sqlData_t * params, cellInfo_t * aggregate ) { value_t stack[ 64 ]; int sp; int i; static char buffer[ 16384 ]; // FIX ME: this is the source of bugs static int size = 0; int top = size; for ( i=0,sp=0; expr[ i ] != OP_END; ) { op_t op = READ_OP; switch( op ) { case OP_PUSH_INTEGER: stack[ sp++ ].i = READ_INT; break; case OP_PUSH_STRING: stack[ sp++ ].s = READ_STRING; break; case OP_PUSH_COLUMN: stack[ sp++ ].p = table->columns + READ_OP; break; case OP_PUSH_COLUMN_VAL: stack[ sp++ ].i = row[ READ_OP ].integer; break; case OP_PUSH_STRING_PARAM: stack[ sp++ ].s = params[ READ_OP ].payload.string; break; case OP_PUSH_INTEGER_PARAM: stack[ sp++ ].i = params[ READ_OP ].payload.integer; break; case OP_ROWINDEX: stack[ sp++ ].i = (row - table->rows) / table->column_count; break; case OP_ROWNUMBER: stack[ sp++ ].i = index; break; case OP_ROWTOTAL: stack[ sp++ ].i = total; break; case OP_ROWCOUNT: stack[ sp++ ].i = table->row_count; break; case OP_SYS_TIME: stack[ sp++ ].i = Sys_Milliseconds(); break; case OP_SUBTRACT: LVALUE.i = LEFT_OPERAND.i - RIGHT_OPERAND.i; sp--; break; case OP_ADD: LVALUE.i = LEFT_OPERAND.i + RIGHT_OPERAND.i; sp--; break; case OP_DIVIDE: LVALUE.i = LEFT_OPERAND.i / RIGHT_OPERAND.i; sp--; break; case OP_MULTIPLY: LVALUE.i = LEFT_OPERAND.i * RIGHT_OPERAND.i; sp--; break; case OP_MODULUS: LVALUE.i = LEFT_OPERAND.i % RIGHT_OPERAND.i; sp--; break; case OP_LOGICAL_AND: LVALUE.i = LEFT_OPERAND.i && RIGHT_OPERAND.i; sp--; break; case OP_LOGICAL_OR: LVALUE.i = LEFT_OPERAND.i || RIGHT_OPERAND.i; sp--; break; case OP_BITWISE_AND: LVALUE.i = LEFT_OPERAND.i & RIGHT_OPERAND.i; sp--; break; case OP_BITWISE_OR: LVALUE.i = LEFT_OPERAND.i | RIGHT_OPERAND.i; sp--; break; case OP_GT: LVALUE.i = LEFT_OPERAND.i > RIGHT_OPERAND.i; sp--; break; case OP_LT: LVALUE.i = LEFT_OPERAND.i < RIGHT_OPERAND.i; sp--; break; case OP_GE: LVALUE.i = LEFT_OPERAND.i >= RIGHT_OPERAND.i; sp--; break; case OP_LE: LVALUE.i = LEFT_OPERAND.i <= RIGHT_OPERAND.i; sp--; break; case OP_EQ: LVALUE.i = LEFT_OPERAND.i == RIGHT_OPERAND.i; sp--; break; case OP_NE: LVALUE.i = LEFT_OPERAND.i != RIGHT_OPERAND.i; sp--; break; case OP_ATOI: if (stack[ sp-1 ].s) { stack[ sp-1 ].i = atoi( stack[ sp-1 ].s ); } else { stack[ sp-1 ].i = -1; } break; case OP_LIKE: LVALUE.i = Q_stricmp( LEFT_OPERAND.s, RIGHT_OPERAND.s ) == 0; sp--; break; case OP_MATCH: LVALUE.i = Com_Filter( RIGHT_OPERAND.s, LEFT_OPERAND.s, 0 ); sp--; break; case OP_NOTLIKE: LVALUE.i = Q_stricmp( LEFT_OPERAND.s, RIGHT_OPERAND.s ) != 0; sp--; break; case OP_INT_MIN: LVALUE.i = (LEFT_OPERAND.i<RIGHT_OPERAND.i)?LEFT_OPERAND.i:RIGHT_OPERAND.i; sp--; break; case OP_INT_MAX: LVALUE.i = (LEFT_OPERAND.i>RIGHT_OPERAND.i)?LEFT_OPERAND.i:RIGHT_OPERAND.i; sp--; break; case OP_ABS: stack[ sp-1 ].i = abs( stack[ sp-1 ].i ); break; case OP_UMINUS: stack[ sp-1 ].i = -stack[ sp-1 ].i; break; case OP_NOT: stack[ sp-1 ].i = !(stack[ sp-1 ].i); break; case OP_REMOVE: { int p = READ_OP; int n = min( params[ p ].payload.integer, stack[ sp-1 ].i ); params[ p ].payload.integer -= n; stack[ sp-1 ].i = n; } break; case OP_ASSIGN_INT_TO_COLUMN: { columnInfo_t * c = (columnInfo_t*)LEFT_OPERAND.p; ASSERT( c->num >= 0 && c->num < table->column_count ); if ( row[ c->num ].integer != RIGHT_OPERAND.i ) { table->modified |= (1<<c->num); } LVALUE.i = row[ c->num ].integer = RIGHT_OPERAND.i; sp--; } break; case OP_ASSIGN_STRING_TO_COLUMN: { // a string is being inserted into a table. this string is expected to remain // constant throughout the life of the table. strings stored in tables do not // change. string cells can not be modified with an 'UPDATE' command columnInfo_t * c = (columnInfo_t*)LEFT_OPERAND.p; cellInfo_t * cell = row + c->num; const char * o = cell->string; ASSERT( c->format == STRING ); //ASSERT( cell->string == 0 ); // help!! if ( abs(RIGHT_OPERAND.i) < 0x10000 ) { // can't figure out data type for cases like: INSERT INTO missions VALUES(7,'wealth',500); 3rd column in text // so trying to guess LVALUE.s = cell->string = sql_alloc_string( db, fn( RIGHT_OPERAND.i, FN_PLAIN ) ); sp--; } else { LVALUE.s = cell->string = sql_alloc_string( db, RIGHT_OPERAND.s ); sp--; } if ( Q_stricmp( o, cell->string ) ) { table->modified |= (1<<c->num); } } break; case OP_ASSIGN_CS_TO_ROW: { row_cs( db, table, row, stack[ sp-1 ].s ); } break; case OP_COUNT: (*aggregate).integer++; break; case OP_MAX: { int v = stack[ sp-1 ].i; (*aggregate).integer = (index==0)?v:max( (*aggregate).integer, v ); } break; case OP_MIN: { int v = stack[ sp-1 ].i; (*aggregate).integer = (index==0)?v:min( (*aggregate).integer, v ); } break; case OP_SUM: (*aggregate).integer += stack[ sp-1 ].i; break; case OP_FORMAT: { char * s = buffer + size; int flags = READ_INT; size += fn_buffer( s, stack[ sp-1 ].i, flags ); stack[ sp-1 ].s = s; } break; case OP_CONCAT: { LVALUE.s = concat( LEFT_OPERAND.s, RIGHT_OPERAND.s, buffer, sizeof(buffer), &size ); sp--; } break; case OP_COLLAPSE: { char * s = buffer + size; size += concat2( s, sizeof(buffer)-size, stack, sp ); stack[ 0 ].s = s; sp = 1; } break; case OP_CVAR: { stack[ sp-1 ].s = Cvar_VariableString( stack[ sp-1 ].s ); } break; case OP_ACCESS_TABLE: { tableInfo_t * table; columnInfo_t * c; table = find_table( db, LEFT_OPERAND.s ); // allow table access outside current db if ( !table ) { table = find_table( sql_getclientdb(), LEFT_OPERAND.s ); if ( !table ) { table = find_table( sql_getserverdb(), LEFT_OPERAND.s ); if ( !table ) { table = find_table( sql_getcommondb(), LEFT_OPERAND.s ); } } } #ifdef DEVELOPER if ( !table ) { Com_Error( ERR_FATAL, "table '%s' does not exist.\n\n%s", LEFT_OPERAND.s, CURRENT_STMT ); } #endif c = find_column( table, RIGHT_OPERAND.s ); #ifdef DEVELOPER if ( !c ) { Com_Error( ERR_FATAL, "column '%s' expected on table '%s'.\n\n%s\n", RIGHT_OPERAND.s, LEFT_OPERAND.s, CURRENT_STMT ); } #endif LVALUE.p = table; sp--; stack[ sp++ ].p = c; } break; case OP_LOOKUP_I: { tableInfo_t * t = stack[ sp-3 ].p; columnInfo_t * c = stack[ sp-2 ].p; cellInfo_t k; int index; k.integer = stack[ sp-1 ].i; if ( !c->index ) { sql_create_index( db, t, c ); } #ifdef DEVELOPER if ( !c->index ) { Com_Error( ERR_FATAL, "index needed for column '%s' on table '%s'.\n\n%s", c->name, t->name, CURRENT_STMT ); } if ( c->format != INTEGER ) { Com_Error( ERR_FATAL, "expecting column '%s' on table '%s' to be integer, not string.\n\n%s", c->name, t->name, CURRENT_STMT ); } #endif if ( t->last_changed != t->last_indexed ) sql_table_reindex( t ); index = search_index_i( c->index, t->row_count, t->rows, t->column_count, c->num, k ); LVALUE.i = (index>=0)?c->index[ index ]:index; sp--; } break; case OP_ACCESS_ROW_I: { tableInfo_t * t = stack[ sp-3 ].p; int r = stack[ sp-2 ].i; columnInfo_t * c = find_column( t, stack[ sp-1 ].s ); #ifdef DEVELOPER if ( !t ) { Com_Error( ERR_FATAL, "table '%s' does not exist.\n\n%s", stack[sp-3].s, CURRENT_STMT ); } if ( !c ) { Com_Error( ERR_FATAL, "could not find column '%s' on table '%s' in statement:\n\n%s", stack[ sp-1 ].s, stack[sp-3].s, CURRENT_STMT ); } #endif sp -= 3; if ( r < 0 ) { stack[ sp++ ].i = -1; } else { int cell = (t->column_count*r) + c->num; if ( c->format == STRING ) { stack[ sp++ ].i = atoi( t->rows[ cell ].string ); } else { stack[ sp++ ].i = t->rows[ cell ].integer; } } } break; case OP_LOOKUP_S: { tableInfo_t * t = stack[ sp-3 ].p; columnInfo_t * c = stack[ sp-2 ].p; cellInfo_t k; int index; k.string = stack[ sp-1 ].s; if ( !c->index ) { sql_create_index( db, t, c ); } #ifdef DEVELOPER if ( !c->index ) { Com_Error( ERR_FATAL, "index needed for column '%s' on table '%s'.\n\n%s", c->name, t->name, CURRENT_STMT ); } if ( c->format != STRING ) { Com_Error( ERR_FATAL, "expecting column '%s' on table '%s' to be string, not integer.\n\n%s", c->name, t->name, CURRENT_STMT ); } #endif if ( t->last_changed != t->last_indexed ) sql_table_reindex( t ); index = search_index_s( c->index, t->row_count, t->rows, t->column_count, c->num, k ); LVALUE.i = (index>=0)?c->index[ index ]:index; sp--; } break; case OP_ACCESS_ROW_S: { tableInfo_t * t = stack[ sp-3 ].p; int r = stack[ sp-2 ].i; columnInfo_t * c = find_column( t, stack[ sp-1 ].s ); #ifdef DEVELOPER if ( !t ) { Com_Error( ERR_FATAL, "table does not exist.\n\n%s", CURRENT_STMT ); } if ( !c ) { Com_Error( ERR_FATAL, "invalid column for table '%s' in statement:\n\n%s", t->name, CURRENT_STMT ); } #endif sp -= 3; stack[ sp++ ].s = (r>=0)?t->rows[ (t->column_count*r) + c->num ].string:"???"; } break; case OP_PUSH_GS: { int offset = READ_INT; stack[ sp++ ].i = db->gs[ offset ]; } break; case OP_PUSH_GS_OFFSET: { int offset = READ_INT; stack[ sp-1 ].i = db->gs[ offset + stack[ sp-1 ].i ]; } break; case OP_PUSH_PS_CLIENT: { int offset = READ_INT; stack[ sp++ ].i = db->ps[ offset ]; } break; case OP_PUSH_PS_CLIENT_OFFSET: { int offset = READ_INT; stack[ sp-1 ].i = db->ps[ offset + stack[ sp-1 ].i ]; } break; case OP_IFTHENELSE: { int c = stack[ sp-1 ].i; value_t a = stack[ sp-2 ]; value_t b = stack[ sp-3 ]; sp -= 3; stack[ sp++ ] = (c)?b:a; } break; case OP_SHADER: { ASSERT( db->shader ); stack[ sp-1 ].i = db->shader( stack[ sp-1 ].s ); } break; case OP_SOUND: { ASSERT( db->sound ); stack[ sp-1 ].i = db->sound( stack[ sp-1 ].s ); } break; case OP_MODEL: { ASSERT( db->model ); stack[ sp-1 ].i = db->model( stack[ sp-1 ].s ); } break; case OP_PORTRAIT: { ASSERT( db->portrait ); stack[ sp-1 ].i = db->portrait( stack[ sp-1 ].s ); } break; case OP_PUSH_INTEGER_GLOBAL: { const char * global_id = READ_STRING; ASSERT( db->global_int ); stack[ sp++ ].i = db->global_int( global_id ); } break; // recursive integer call case OP_EVAL: { const char * s = stack[ sp-1 ].s; int r; switch ( SWITCHSTRING(s) ) { case 0: case CS('0',0,0,0): r = 0; break; case CS('1',0,0,0): r = 1; break; default: { Expr e; parseInfo_t pi = { 0 }; char tmp[ SQL_STMT_ALLOC ]; sqlStack_t* save = db->stmt_buffer.c; db->stmt_buffer.c = (sqlStack_t*)tmp; db->stmt_buffer.c->top = sizeof(sqlStack_t); pi.db = db; e = parse_expression( &s, &pi ); ASSERT( pi.rt == INTEGER ); ASSERT( pi.more == 0 ); r = sql_eval( db, e, table, row, index, total, params, aggregate ).integer; db->stmt_buffer.c = save; } break; } stack[ sp-1 ].i = r; } break; // recursive string call case OP_PRINT: { const char * s = stack[ sp-1 ].s; Expr e; parseInfo_t pi = { 0 }; char tmp[ SQL_STMT_ALLOC ]; sqlStack_t* save = db->stmt_buffer.c; db->stmt_buffer.c = (sqlStack_t*)tmp; db->stmt_buffer.c->top = sizeof(sqlStack_t); pi.db = db; pi.flags = PARSE_STRINGLITERAL; e = parse_expression( &s, &pi ); ASSERT( pi.rt == STRING ); ASSERT( pi.more == 0 ); stack[ sp-1 ].s = sql_eval( db, e, table, row, index, total, params, aggregate ).string; db->stmt_buffer.c = save; } break; // execute a precompiled expression, returns string case OP_RUN: { int index = stack[ sp-1 ].i; if ( index < 0 || index >= db->stmts_byindex_count || !db->stmts_byindex[ index ] ) { stack[ sp-1 ].s = "???"; break; } stack[ sp-1 ].s = sql_eval( db, ((formatInfo_t*)db->stmts_byindex[ index ])->print, 0, 0, 0, 0, 0, 0 ).string; size += strlen(stack[ sp-1 ].s) + 1; } break; case OP_RND: { LVALUE.i = Rand_NextInt32InRange( &db->rand, LEFT_OPERAND.i, RIGHT_OPERAND.i ); sp--; } break; #if DEVELOPER default: { Com_Error(ERR_FATAL, "invalid sql op code: '%d'.\n", op ); } break; #endif } #ifdef DEVELOPER db->ops++; #endif } ASSERT( size <= sizeof(buffer) ); // stack overflow size = top; if ( sp == 0 ) { cellInfo_t c; c.integer = 0; return c; } ASSERT( sp == 1 ); return *(cellInfo_t*)stack; }
/* arg # is "string" */ #define A1_STR 0x100 #define A2_STR 0x200 #define A3_STR 0x400 #ifdef __MSC__ #define CS(x) #else #define CS(x) [x] = #endif struct atax { int typ; char *name; } atax[GCC_ATYP_MAX] = { CS(ATTR_NONE) { 0, NULL }, CS(ATTR_COMPLEX) { 0, NULL }, CS(ATTR_BASETYP) { 0, NULL }, CS(ATTR_QUALTYP) { 0, NULL }, CS(ATTR_STRUCT) { 0, NULL }, CS(GCC_ATYP_ALIGNED) { A_0ARG|A_1ARG, "aligned" }, CS(GCC_ATYP_PACKED) { A_0ARG|A_1ARG, "packed" }, CS(GCC_ATYP_SECTION) { A_1ARG|A1_STR, "section" }, CS(GCC_ATYP_TRANSP_UNION) { A_0ARG, "transparent_union" }, CS(GCC_ATYP_UNUSED) { A_0ARG, "unused" }, CS(GCC_ATYP_DEPRECATED) { A_0ARG, "deprecated" }, CS(GCC_ATYP_MAYALIAS) { A_0ARG, "may_alias" }, CS(GCC_ATYP_MODE) { A_1ARG|A1_NAME, "mode" }, CS(GCC_ATYP_NORETURN) { A_0ARG, "noreturn" }, CS(GCC_ATYP_FORMAT) { A_3ARG|A1_NAME, "format" }, CS(GCC_ATYP_NONNULL) { A_MANY, "nonnull" },
SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf, const QString& inputMRL ) : QVLCDialog( parent, _p_intf ) { setWindowTitle( qtr( "Stream Output" ) ); setWindowRole( "vlc-stream-output" ); /* UI stuff */ ui.setupUi( this ); ui.inputBox->setMRL( inputMRL ); ui.helpEdit->setPlainText( qtr("This dialog will allow you to stream or " "convert your media for use locally, on your private network, " "or on the Internet.\n" "You should start by checking that source matches what you want " "your input to be and then press the \"Next\" " "button to continue.\n") ); ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n" "This is automatically generated " "when you change the above settings,\n" "but you can change it manually." ) ) ; #if 0 /* This needs Qt4.5 to be cool */ ui.destTab->setTabsClosable( true ); #else closeTabButton = new QToolButton( this ); ui.destTab->setCornerWidget( closeTabButton ); closeTabButton->hide(); closeTabButton->setAutoRaise( true ); closeTabButton->setIcon( QIcon( ":/toolbar/clear" ) ); BUTTONACT( closeTabButton, closeTab() ); #endif CONNECT( ui.destTab, currentChanged( int ), this, tabChanged( int ) ); ui.destTab->setTabIcon( 0, QIcon( ":/buttons/playlist/playlist_add" ) ); ui.destBox->addItem( qtr( "File" ) ); ui.destBox->addItem( "HTTP" ); ui.destBox->addItem( "MS-WMSP (MMSH)" ); ui.destBox->addItem( "RTSP" ); ui.destBox->addItem( "RTP / MPEG Transport Stream" ); ui.destBox->addItem( "RTP Audio/Video Profile" ); ui.destBox->addItem( "UDP (legacy)" ); ui.destBox->addItem( "IceCast" ); BUTTONACT( ui.addButton, addDest() ); // /* Connect everything to the updateMRL function */ #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() ); #define CT( x ) CONNECT( ui.x, textChanged( const QString& ), this, updateMRL() ); #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() ); #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() ); /* Misc */ CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup ); CB( localOutput ); CB( transcodeBox ); CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() ); okButton = new QPushButton( qtr( "&Stream" ) ); QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) ); okButton->setDefault( true ); ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole ); ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole ); BUTTONACT( okButton, ok() ); BUTTONACT( cancelButton, cancel() ); BUTTONACT( ui.nextButton, next() ); BUTTONACT( ui.nextButton2, next() ); BUTTONACT( ui.prevButton, prev() ); BUTTONACT( ui.prevButton2, prev() ); #undef CC #undef CS #undef CT #undef CB }
void CharacterStreamTest::test_next() { CS("AB"); CPPUNIT_ASSERT(cs.next() == 'A'); CPPUNIT_ASSERT(cs.next() == 'B'); CPPUNIT_ASSERT(cs.next() == Chars::END_OF_FILE); }
void CharacterStreamTest::test_nextStr() { CS("ABCDE"); CPPUNIT_ASSERT(cs.nextStr(3) == "ABC"); CPPUNIT_ASSERT(cs.nextStr(3) == "DE"); CPPUNIT_ASSERT(cs.nextStr(1) == Strings::EMPTY); }
void CharacterStreamTest::test_readLNUM() { CS("003215"); CPPUNIT_ASSERT(cs.readLNUM() == "003215"); CPPUNIT_ASSERT(!cs.hasNext()); }
void CharacterStreamTest::test_hasNext() { CS("A"); CPPUNIT_ASSERT(cs.hasNext()); cs.next(); CPPUNIT_ASSERT(!cs.hasNext()); }
int main(int argc, char* argv[]) { Env = TEnv(argc, argv, TNotify::StdNotify); Env.PrepArgs(TStr::Fmt("cesna. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm())); TExeTm ExeTm; Try TStr OutFPrx = Env.GetIfArgPrefixStr("-o:", "", "Output Graph data prefix"); const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "./1912.edges", "Input edgelist file name"); const TStr LabelFNm = Env.GetIfArgPrefixStr("-l:", "", "Input file name for node names (Node ID, Node label) "); const TStr AttrFNm = Env.GetIfArgPrefixStr("-a:", "./1912.nodefeat", "Input node attribute file name"); const TStr ANameFNm = Env.GetIfArgPrefixStr("-n:", "./1912.nodefeatnames", "Input file name for node attribute names"); int OptComs = Env.GetIfArgPrefixInt("-c:", 10, "The number of communities to detect (-1: detect automatically)"); const int MinComs = Env.GetIfArgPrefixInt("-mc:", 3, "Minimum number of communities to try"); const int MaxComs = Env.GetIfArgPrefixInt("-xc:", 20, "Maximum number of communities to try"); const int DivComs = Env.GetIfArgPrefixInt("-nc:", 5, "How many trials for the number of communities"); const int NumThreads = Env.GetIfArgPrefixInt("-nt:", 4, "Number of threads for parallelization"); const double AttrWeight = Env.GetIfArgPrefixFlt("-aw:", 0.5, "We maximize (1 - aw) P(Network) + aw * P(Attributes)"); const double LassoWeight = Env.GetIfArgPrefixFlt("-lw:", 1.0, "Weight for l-1 regularization on learning the logistic model parameters"); const double StepAlpha = Env.GetIfArgPrefixFlt("-sa:", 0.05, "Alpha for backtracking line search"); const double StepBeta = Env.GetIfArgPrefixFlt("-sb:", 0.3, "Beta for backtracking line search"); const double MinFeatFrac = Env.GetIfArgPrefixFlt("-mf:", 0.0, "If the fraction of nodes with positive values for an attribute is smaller than this, we ignore that attribute"); #ifndef NOMP omp_set_num_threads(NumThreads); #endif PUNGraph G; TIntStrH NIDNameH; TStrHash<TInt> NodeNameH; TVec<TFltV> Wck; TVec<TIntV> EstCmtyVV; if (InFNm.IsStrIn(".ungraph")) { TFIn GFIn(InFNm); G = TUNGraph::Load(GFIn); } else { G = TAGMUtil::LoadEdgeListStr<PUNGraph>(InFNm, NodeNameH); NIDNameH.Gen(NodeNameH.Len()); for (int s = 0; s < NodeNameH.Len(); s++) { NIDNameH.AddDat(s, NodeNameH.GetKey(s)); } } if (LabelFNm.Len() > 0) { TSsParser Ss(LabelFNm, ssfTabSep); while (Ss.Next()) { if (Ss.Len() > 0) { NIDNameH.AddDat(Ss.GetInt(0), Ss.GetFld(1)); } } } printf("Graph: %d Nodes %d Edges\n", G->GetNodes(), G->GetEdges()); //load attribute TIntV NIDV; G->GetNIdV(NIDV); THash<TInt, TIntV> RawNIDAttrH, NIDAttrH; TIntStrH RawFeatNameH, FeatNameH; if (ANameFNm.Len() > 0) { TSsParser Ss(ANameFNm, ssfTabSep); while (Ss.Next()) { if (Ss.Len() > 0) { RawFeatNameH.AddDat(Ss.GetInt(0), Ss.GetFld(1)); } } } TCesnaUtil::LoadNIDAttrHFromNIDKH(NIDV, AttrFNm, RawNIDAttrH, NodeNameH); TCesnaUtil::FilterLowEntropy(RawNIDAttrH, NIDAttrH, RawFeatNameH, FeatNameH, MinFeatFrac); TExeTm RunTm; TCesna CS(G, NIDAttrH, 10, 10); if (OptComs == -1) { printf("finding number of communities\n"); OptComs = CS.FindComs(NumThreads, MaxComs, MinComs, DivComs, "", false, 0.1, StepAlpha, StepBeta); } CS.NeighborComInit(OptComs); CS.SetWeightAttr(AttrWeight); CS.SetLassoCoef(LassoWeight); if (NumThreads == 1 || G->GetEdges() < 1000) { CS.MLEGradAscent(0.0001, 1000 * G->GetNodes(), "", StepAlpha, StepBeta); } else { CS.MLEGradAscentParallel(0.0001, 1000, NumThreads, "", StepAlpha, StepBeta); } CS.GetCmtyVV(EstCmtyVV, Wck); TAGMUtil::DumpCmtyVV(OutFPrx + "cmtyvv.txt", EstCmtyVV, NIDNameH); FILE* F = fopen((OutFPrx + "weights.txt").CStr(), "wt"); if (FeatNameH.Len() == Wck[0].Len()) { fprintf(F, "#"); for (int k = 0; k < FeatNameH.Len(); k++) { fprintf(F, "%s", FeatNameH[k].CStr()); if (k < FeatNameH.Len() - 1) { fprintf(F, "\t"); } } fprintf(F, "\n"); } for (int c = 0; c < Wck.Len(); c++) { for (int k = 0; k < Wck[c].Len(); k++) { fprintf(F, "%f", Wck[c][k].Val); if (k < Wck[c].Len() - 1) { fprintf(F, "\t"); } } fprintf(F, "\n"); } fclose(F); Catch printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr()); return 0; }
SW(xt) { CSR(5,) CS(0, DO(xn, cd(kK(x)[xn-i-1]))) //repool in reverse, attempt to maintain order } if(x->c > 0) R x; #ifdef DEBUG DO(kreci, if(x==krec[i]){krec[i]=0; break; }) #endif SW(xt) { CS(7, DO(-2+TYPE_SEVEN_SIZE,cd(kV(x)[2+i]))) //-4 special trick: don't recurse on V members. assumes sizeof S==K==V. (don't free CONTeXT or DEPTH) } #ifdef DEBUG if(0)R 0; //for viewing K that have been over-freed #endif //assumes seven_type x->k is < PG I o=((size_t)x)&(PG-1);//file-mapped? 1: I k=sz(xt,xn), r=lsz(k); //assert file-maps have sizeof(V)==o and unpooled blocks never do (reasonable) //in 32-bit Linux: sizeof(V)==4 but file-maps have o==8 //in 64-bit Linux: sizeof(V)==8 and file-maps have o==8 if(o==8 || r>KP_MAX){ //(file-mapped or really big) do not go back into pool. I res=munmap(((V)x)-o,k+o); if(res)R UE; if(r>KP_MAX) mUsed -= (k+o); } else repool(x,r);
/// inlineFuctions - Walk all call sites in all functions supplied by /// client. Inline as many call sites as possible. Delete completely /// inlined functions. void BasicInlinerImpl::inlineFunctions() { // Scan through and identify all call sites ahead of time so that we only // inline call sites in the original functions, not call sites that result // from inlining other functions. std::vector<CallSite> CallSites; for (std::vector<Function *>::iterator FI = Functions.begin(), FE = Functions.end(); FI != FE; ++FI) { Function *F = *FI; for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) { CallSite CS(cast<Value>(I)); if (CS && CS.getCalledFunction() && !CS.getCalledFunction()->isDeclaration()) CallSites.push_back(CS); } } DEBUG(dbgs() << ": " << CallSites.size() << " call sites.\n"); // Inline call sites. bool Changed = false; do { Changed = false; for (unsigned index = 0; index != CallSites.size() && !CallSites.empty(); ++index) { CallSite CS = CallSites[index]; if (Function *Callee = CS.getCalledFunction()) { // Eliminate calls that are never inlinable. if (Callee->isDeclaration() || CS.getInstruction()->getParent()->getParent() == Callee) { CallSites.erase(CallSites.begin() + index); --index; continue; } InlineCost IC = CA.getInlineCost(CS, NeverInline); if (IC.isAlways()) { DEBUG(dbgs() << " Inlining: cost=always" <<", call: " << *CS.getInstruction()); } else if (IC.isNever()) { DEBUG(dbgs() << " NOT Inlining: cost=never" <<", call: " << *CS.getInstruction()); continue; } else { int Cost = IC.getValue(); if (Cost >= (int) BasicInlineThreshold) { DEBUG(dbgs() << " NOT Inlining: cost = " << Cost << ", call: " << *CS.getInstruction()); continue; } else { DEBUG(dbgs() << " Inlining: cost = " << Cost << ", call: " << *CS.getInstruction()); } } // Inline InlineFunctionInfo IFI(0, TD); if (InlineFunction(CS, IFI)) { Callee->removeDeadConstantUsers(); if (Callee->isDefTriviallyDead()) DeadFunctions.insert(Callee); Changed = true; CallSites.erase(CallSites.begin() + index); --index; } } } } while (Changed); // Remove completely inlined functions from module. for(SmallPtrSet<Function *, 8>::iterator I = DeadFunctions.begin(), E = DeadFunctions.end(); I != E; ++I) { Function *D = *I; Module *M = D->getParent(); M->getFunctionList().remove(D); } }
TEST(StringTest, Split) { EXPECT_EQ("a", CS("a b c").Token(0)); EXPECT_EQ("b", CS("a b c").Token(1)); EXPECT_EQ("", CS("a b c").Token(100)); EXPECT_EQ("b c", CS("a b c").Token(1, true)); EXPECT_EQ("c", CS("a c").Token(1)); EXPECT_EQ("", CS("a c").Token(1, false, " ", true)); EXPECT_EQ("c", CS("a c").Token(1, false, " ")); EXPECT_EQ(" c", CS("a c").Token(1, false, " ")); EXPECT_EQ("c", CS("a c").Token(1, false, " ")); EXPECT_EQ("b c", CS("a (b c) d").Token(1, false, " ", false, "(", ")")); EXPECT_EQ("(b c)", CS("a (b c) d").Token(1, false, " ", false, "(", ")", false)); EXPECT_EQ("d", CS("a (b c) d").Token(2, false, " ", false, "(", ")", false)); VCString vexpected; VCString vresult; vexpected.push_back("a"); vexpected.push_back("b"); vexpected.push_back("c"); CS("a b c").Split(" ", vresult); EXPECT_EQ(vexpected, vresult); MCString mexpected = { {"a","b"}, {"c","d"} }; MCString mresult; CS("a=x&c=d&a=b").URLSplit(mresult); EXPECT_EQ(mexpected, mresult) << "URLSplit"; }
// INSERT INTO "commodities_events" VALUES(7, 5, 3, 400, 600); // INSERT INTO contacts(player,npc) VALUES(?,?); stmtInfo_t * sql_insert_parse( sqlInfo_t * db, const char ** s ) { columnInfo_t * c[ MAX_COLUMNS_PER_TABLE ]; int i,count=0; tableInfo_t * table; insertInfo_t * insert; char * n; // 'INTO' parse_temp( s ); n = parse_temp( s ); if ( db->create_filter ) { if ( Q_stricmp( n, db->create_filter ) ) { return 0; } } switch ( CS(n[0],n[1],n[2],0) ) { case CS('s','v','_',0): if ( db->memory_tag == TAG_SQL_CLIENT && !db->create_filter ) return 0; n += 3; break; case CS('c','l','_',0): if ( db->memory_tag == TAG_SQL_SERVER && !db->create_filter ) return 0; n += 3; break; case CS('b','g','_',0): n += 3; break; } table = find_table( db, n ); if ( !table ) return 0; ASSERT( table ); insert = sql_calloc_stmt( db, sizeof(insertInfo_t) ); insert->stmt.type = SQL_INSERT; insert->stmt.table = table; // parse column names if ( parse_tofirstparam( s ) ) { do { char * name = parse_temp( s ); c[ count ] = find_column( table, name ); #ifdef DEVELOPER if ( c[ count ] == 0 ) { Com_Error( ERR_FATAL, "column '%s' does not exist on table '%s'.\n", name, table->name ); } #endif count++; } while( parse_tonextparam( s ) ); } else { for ( i=0; i<table->column_count; i++ ) c[ count++ ] = &table->columns[ i ]; } // skip VALUES keyword switch ( SWITCHSTRING( parse_temp( s ) ) ) { case CS('s','e','l','e'): { insert->select = (selectInfo_t*)sql_select_parse( db, s ); for ( i=0; i<count; i++ ) { insert->columns[ i ] = (char)c[ i ]->num; } ASSERT( count == insert->select->column_count ); } break; case CS('v','a','l','u'): { parseInfo_t pi = { 0 }; pi.db = db; pi.params = insert->stmt.params; pi.table = insert->stmt.table; pi.flags = PARSE_ASSIGN_TO_COLUMN; pi.more = 1; // parse column assignments if ( parse_tofirstparam( s ) ) { for ( i=0; pi.more; i++ ) { pi.column = c[ i ]->num; insert->values_expr[ i ] = parse_expression( s, &pi ); } insert->values_count = i; } ASSERT( insert->values_count == count ); } break; case CS('r','o','w','s'): { cellInfo_t * row; parseInfo_t pi = { 0 }; Expr e; pi.db = db; pi.params = insert->stmt.params; pi.table = insert->stmt.table; pi.more = 1; if ( parse_tofirstparam( s ) ) { while ( pi.more ) { row = sql_insert_begin( db, table ); for ( i=0; i<table->column_count; i++ ) { int top = db->stmt_buffer.c->top; e = parse_expression( s, &pi ); row[ i ] = sql_eval( db, e, table, 0,0,1, 0, 0 ); if ( table->columns[ i ].format == STRING ) { row[ i ].string = sql_alloc_string( db, row[ i ].string ); } db->stmt_buffer.c->top = top; } sql_insert_done( db, table ); } } return 0; } break; } return &insert->stmt; }
TEST(StringTest, NamedFormat) { MCString m = { {"a","b"} }; EXPECT_EQ("{xbyb", CString::NamedFormat(CS("\\{x{a}y{a}"), m)); }
#define M_NULL "NULL", ssl_mac_null, 0 /* flags: FIPS, exportable, nonstandard, reserved */ #define F_FIPS_STD 1, 0, 0, 0 #define F_FIPS_NSTD 1, 0, 1, 0 #define F_NFIPS_STD 0, 0, 0, 0 #define F_NFIPS_NSTD 0, 0, 1, 0 /* i.e., trash */ #define F_EXPORT 0, 1, 0, 0 /* i.e., trash */ static const SSLCipherSuiteInfo suiteInfo[] = { /* <------ Cipher suite --------------------> <auth> <KEA> <bulk cipher> <MAC> <FIPS> */ { 0, CS_(TLS_AES_128_GCM_SHA256), S_ANY, K_ANY, C_AESGCM, B_128, M_AEAD_128, F_FIPS_STD, A_ANY }, { 0, CS_(TLS_CHACHA20_POLY1305_SHA256), S_ANY, K_ANY, C_CHACHA20, B_256, M_AEAD_128, F_NFIPS_STD, A_ANY }, { 0, CS_(TLS_AES_256_GCM_SHA384), S_ANY, K_ANY, C_AESGCM, B_256, M_AEAD_128, F_NFIPS_STD, A_ANY }, { 0, CS(RSA_WITH_AES_128_GCM_SHA256), S_RSA, K_RSA, C_AESGCM, B_128, M_AEAD_128, F_FIPS_STD, A_RSAD }, { 0, CS(DHE_RSA_WITH_CHACHA20_POLY1305_SHA256), S_RSA, K_DHE, C_CHACHA20, B_256, M_AEAD_128, F_NFIPS_STD, A_RSAS }, { 0, CS(DHE_RSA_WITH_CAMELLIA_256_CBC_SHA), S_RSA, K_DHE, C_CAMELLIA, B_256, M_SHA, F_NFIPS_STD, A_RSAS }, { 0, CS(DHE_DSS_WITH_CAMELLIA_256_CBC_SHA), S_DSA, K_DHE, C_CAMELLIA, B_256, M_SHA, F_NFIPS_STD, A_DSA }, { 0, CS(DHE_RSA_WITH_AES_256_CBC_SHA256), S_RSA, K_DHE, C_AES, B_256, M_SHA256, F_FIPS_STD, A_RSAS }, { 0, CS(DHE_RSA_WITH_AES_256_CBC_SHA), S_RSA, K_DHE, C_AES, B_256, M_SHA, F_FIPS_STD, A_RSAS }, { 0, CS(DHE_DSS_WITH_AES_256_CBC_SHA), S_DSA, K_DHE, C_AES, B_256, M_SHA, F_FIPS_STD, A_DSA }, { 0, CS(DHE_DSS_WITH_AES_256_CBC_SHA256), S_DSA, K_DHE, C_AES, B_256, M_SHA256, F_FIPS_STD, A_DSA }, { 0, CS(RSA_WITH_CAMELLIA_256_CBC_SHA), S_RSA, K_RSA, C_CAMELLIA, B_256, M_SHA, F_NFIPS_STD, A_RSAD }, { 0, CS(RSA_WITH_AES_256_CBC_SHA256), S_RSA, K_RSA, C_AES, B_256, M_SHA256, F_FIPS_STD, A_RSAD }, { 0, CS(RSA_WITH_AES_256_CBC_SHA), S_RSA, K_RSA, C_AES, B_256, M_SHA, F_FIPS_STD, A_RSAD }, { 0, CS(DHE_RSA_WITH_CAMELLIA_128_CBC_SHA), S_RSA, K_DHE, C_CAMELLIA, B_128, M_SHA, F_NFIPS_STD, A_RSAS }, { 0, CS(DHE_DSS_WITH_CAMELLIA_128_CBC_SHA), S_DSA, K_DHE, C_CAMELLIA, B_128, M_SHA, F_NFIPS_STD, A_DSA }, { 0, CS(DHE_DSS_WITH_RC4_128_SHA), S_DSA, K_DHE, C_RC4, B_128, M_SHA, F_NFIPS_STD, A_DSA },
uschar * rfc2047_decode2(uschar *string, BOOL lencheck, uschar *target, int zeroval, int *lenptr, int *sizeptr, uschar **error) { int ptr = 0; int size = Ustrlen(string); size_t dlen; uschar *dptr, *yield; uschar *mimeword, *q1, *q2, *endword; *error = NULL; mimeword = decode_mimeword(string, lencheck, &q1, &q2, &endword, &dlen, &dptr); if (mimeword == NULL) { if (lenptr != NULL) *lenptr = size; return string; } /* Scan through the string, decoding MIME words and copying intermediate text, building the result as we go. The result may be longer than the input if it is translated into a multibyte code such as UTF-8. That's why we use the dynamic string building code. */ yield = store_get(++size); while (mimeword != NULL) { #if HAVE_ICONV iconv_t icd = (iconv_t)(-1); #endif if (mimeword != string) yield = string_cat(yield, &size, &ptr, string, mimeword - string); /* Do a charset translation if required. This is supported only on hosts that have the iconv() function. Translation errors set error, but carry on, using the untranslated data. If there is more than one error, the message passed back refers to the final one. We use a loop to cater for the case of long strings - the RFC puts limits on the length, but it's best to be robust. */ #if HAVE_ICONV *q1 = 0; if (target != NULL && strcmpic(target, mimeword+2) != 0) { icd = iconv_open(CS target, CS(mimeword+2)); if (icd == (iconv_t)(-1)) { *error = string_sprintf("iconv_open(\"%s\", \"%s\") failed: %s%s", target, mimeword+2, strerror(errno), (errno == EINVAL)? " (maybe unsupported conversion)" : ""); } } *q1 = '?'; #endif while (dlen > 0) { uschar *tptr = NULL; /* Stops compiler warning */ int tlen = -1; #if HAVE_ICONV uschar tbuffer[256]; uschar *outptr = tbuffer; size_t outleft = sizeof(tbuffer); /* If translation is required, go for it. */ if (icd != (iconv_t)(-1)) { (void)iconv(icd, (ICONV_ARG2_TYPE)(&dptr), &dlen, CSS &outptr, &outleft); /* If outptr has been adjusted, there is some output. Set up to add it to the output buffer. The function will have adjusted dptr and dlen. If iconv() stopped because of an error, we'll pick it up next time when there's no output. If there is no output, we expect there to have been a translation error, because we know there was at least one input byte. We leave the value of tlen as -1, which causes the rest of the input to be copied verbatim. */ if (outptr > tbuffer) { tptr = tbuffer; tlen = outptr - tbuffer; } else { DEBUG(D_any) debug_printf("iconv error translating \"%.*s\" to %s: " "%s\n", endword + 2 - mimeword, mimeword, target, strerror(errno)); } } #endif /* No charset translation is happening or there was a translation error; just set up the original as the string to be added, and mark it all used. */ if (tlen == -1) { tptr = dptr; tlen = dlen; dlen = 0; } /* Deal with zero values; convert them if requested. */ if (zeroval != 0) { int i; for (i = 0; i < tlen; i++) if (tptr[i] == 0) tptr[i] = zeroval; } /* Add the new string onto the result */ yield = string_cat(yield, &size, &ptr, tptr, tlen); } #if HAVE_ICONV if (icd != (iconv_t)(-1)) iconv_close(icd); #endif /* Update string past the MIME word; skip any white space if the next thing is another MIME word. */ string = endword + 2; mimeword = decode_mimeword(string, lencheck, &q1, &q2, &endword, &dlen, &dptr); if (mimeword != NULL) { uschar *s = string; while (isspace(*s)) s++; if (s == mimeword) string = s; } } /* Copy the remaining characters of the string, zero-terminate it, and return the length as well if requested. */ yield = string_cat(yield, &size, &ptr, string, Ustrlen(string)); yield[ptr] = 0; if (lenptr != NULL) *lenptr = ptr; if (sizeptr != NULL) *sizeptr = size; return yield; }
unsigned int Buffer::getReadableSize() const { DO_RETURN_R(CS(_u_content_size, _u_read_pos)); }
#define B_128 128, 128, 128 #define B_3DES 192, 156, 112 #define B_SJ 96, 80, 80 #define B_DES 64, 56, 56 #define B_56 128, 56, 56 #define B_40 128, 40, 40 #define B_0 0, 0, 0 #define M_AEAD_128 "AEAD", ssl_mac_aead, 128 #define M_SHA256 "SHA256", ssl_hmac_sha256, 256 #define M_SHA "SHA1", ssl_mac_sha, 160 #define M_MD5 "MD5", ssl_mac_md5, 128 #define M_NULL "NULL", ssl_mac_null, 0 static const SSLCipherSuiteInfo suiteInfo[] = { {0,CS(TLS_RSA_WITH_AES_128_GCM_SHA256), S_RSA, K_RSA, C_AESGCM, B_128, M_AEAD_128, 1, 0, 0, }, {0,CS(TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA), S_RSA, K_DHE, C_CAMELLIA, B_256, M_SHA, 0, 0, 0, }, {0,CS(TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA), S_DSA, K_DHE, C_CAMELLIA, B_256, M_SHA, 0, 0, 0, }, {0,CS(TLS_DHE_RSA_WITH_AES_256_CBC_SHA256), S_RSA, K_DHE, C_AES, B_256, M_SHA256, 1, 0, 0, }, {0,CS(TLS_DHE_RSA_WITH_AES_256_CBC_SHA), S_RSA, K_DHE, C_AES, B_256, M_SHA, 1, 0, 0, }, {0,CS(TLS_DHE_DSS_WITH_AES_256_CBC_SHA), S_DSA, K_DHE, C_AES, B_256, M_SHA, 1, 0, 0, }, {0,CS(TLS_RSA_WITH_CAMELLIA_256_CBC_SHA), S_RSA, K_RSA, C_CAMELLIA, B_256, M_SHA, 0, 0, 0, }, {0,CS(TLS_RSA_WITH_AES_256_CBC_SHA256), S_RSA, K_RSA, C_AES, B_256, M_SHA256, 1, 0, 0, }, {0,CS(TLS_RSA_WITH_AES_256_CBC_SHA), S_RSA, K_RSA, C_AES, B_256, M_SHA, 1, 0, 0, }, {0,CS(TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA), S_RSA, K_DHE, C_CAMELLIA, B_128, M_SHA, 0, 0, 0, }, {0,CS(TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA), S_DSA, K_DHE, C_CAMELLIA, B_128, M_SHA, 0, 0, 0, }, {0,CS(TLS_DHE_DSS_WITH_RC4_128_SHA), S_DSA, K_DHE, C_RC4, B_128, M_SHA, 0, 0, 0, }, {0,CS(TLS_DHE_RSA_WITH_AES_128_CBC_SHA256), S_RSA, K_DHE, C_AES, B_128, M_SHA256, 1, 0, 0, }, {0,CS(TLS_DHE_RSA_WITH_AES_128_GCM_SHA256), S_RSA, K_DHE, C_AESGCM, B_128, M_AEAD_128, 1, 0, 0, },
static void fast_intxx(struct proc *p, int intrno) { struct trapframe *tf = p->p_md.md_regs; /* * handle certain interrupts directly by pushing the interrupt * frame and resetting registers, but only if user said that's ok * (i.e. not revectored.) Otherwise bump to 32-bit user handler. */ struct vm86_struct *u_vm86p; struct { u_short ip, cs; } ihand; u_long ss, sp; /* * Note: u_vm86p points to user-space, we only compute offsets * and don't deref it. is_revectored() above does copyin() to * get stuff from it */ u_vm86p = (struct vm86_struct *)p->p_addr->u_pcb.vm86_userp; /* * If user requested special handling, return to user space with * indication of which INT was requested. */ if (is_bitset(intrno, &u_vm86p->int_byuser[0])) goto vector; /* * If it's interrupt 0x21 (special in the DOS world) and the * sub-command (in AH) was requested for special handling, * return to user mode. */ if (intrno == 0x21 && is_bitset(V86_AH(tf), &u_vm86p->int21_byuser[0])) goto vector; /* * Fetch intr handler info from "real-mode" IDT based at addr 0 in * the user address space. */ if (copyin((caddr_t)(intrno * sizeof(ihand)), &ihand, sizeof(ihand))) goto bad; /* * Otherwise, push flags, cs, eip, and jump to handler to * simulate direct INT call. */ ss = SS(tf) << 4; sp = SP(tf); putword(ss, sp, get_vflags_short(p)); putword(ss, sp, CS(tf)); putword(ss, sp, IP(tf)); SP(tf) = sp; IP(tf) = ihand.ip; CS(tf) = ihand.cs; return; vector: vm86_return(p, VM86_MAKEVAL(VM86_INTx, intrno)); return; bad: vm86_return(p, VM86_UNKNOWN); return; }
/* * Init32BitTask - load and initialize the 32-bit application */ bool Init32BitTask( HINSTANCE thishandle, HINSTANCE prevhandle, LPSTR cmdline, int cmdshow ) { WORD i,amount,bytes_read,j; WORD sel; int handle; tiny_ret_t rc; DWORD size,currsize,curroff,minmem,maxmem; DWORD relsize,exelen; struct wstart_vars __far *dataptr; void __far *aliasptr; DWORD __far *relptr; struct fpu_area __far *fpuptr; rex_exe exe; exe_data exedat; char file[128]; DWORD flags; version_info vi; DWORD file_header_size; bool tried_global_compact; DWORD save_maxmem; dpmi_mem_block adata; flags = GetWinFlags(); /* * verify that we are running on a 32-bit DPMI */ _fDPMIGetVersion( &vi ); if( !(vi.flags & VERSION_80386) ) { MessageBox( NULL, "Not running on a 386 DPMI implementation",MsgTitle, MB_OK | MB_ICONHAND | MB_TASKMODAL ); return( false ); } /* * get exe to load */ GetModuleFileName( thishandle, file, 128 ); rc = _fTinyOpen( file, TIO_READ ); if( TINY_ERROR( rc ) ) { return( Fini( 2, (char _FAR *)"Error opening file", (char _FAR *)file) ); } handle = TINY_INFO( rc ); _TinySeek( handle, 0x38, TIO_SEEK_START ); _fTinyRead( handle, &exelen, sizeof( DWORD ) ); _TinySeek( handle, exelen, TIO_SEEK_START ); /* * check if we are being run by the debugger. When the debugger * sees the 'DEADBEEF' bytes at the start of the code segment * (see begin.asm), it swaps them to be BEEFDEAD. The debugger * then tells us to go, and if we see that we have BEEFDEAD, * we execute a breakpoint just before we call our 32-bit code. * Then the debugger traces a single instruction and it looks to * the user like the start of his/her code is the start of * the application. */ if( deadbeef == 0xBEEFDEAD ) { InDebugger = 0; } else { InDebugger = 1; } DPL = (CS() & 0x03) << 5; /* our privilege level */ /* * validate header signature */ _fTinyRead( handle, &exe, sizeof( rex_exe ) ); // BreakPoint(); if( !(exe.sig[0] == 'M' && exe.sig[1] == 'Q') ) { return( Fini( 1,(char _FAR *)"Invalid EXE" ) ); } file_header_size = (DWORD) exe.file_header * 16L; /* * exe.one is supposed to always contain a 1 for a .REX file. * However, to allow relocation tables bigger than 64K, the * we extended the linker to have the .one field contain the * number of full 64K chunks of relocations, minus 1. */ file_header_size += (exe.one-1)*0x10000L*16L; /* * get exe data - data start and stack start */ _TinySeek( handle, exelen + file_header_size + (long)exe.initial_eip, TIO_SEEK_START ); _fTinyRead( handle, &exedat, sizeof( exe_data ) ); /* * get file size */ size = (long) exe.file_size2 * 512L; if( exe.file_size1 > 0 ) { size += (long) exe.file_size1 - 512L; } /* * get stack size */ StackSize = Align4K( exe.initial_esp - ((exedat.stackstart+15) & ~15ul) ); if( StackSize < 0x1000 ) { StackSize = 0x1000; } /* * get minimum/maximum amounts of heap, then add in exe size * to get total area */ // BreakPoint(); minmem = (DWORD) exe.min_data *(DWORD) 4096L; if( exe.max_data == (WORD)-1 ) { maxmem = 4096L; } else { maxmem = (DWORD) exe.max_data*4096L; } minmem = Align4K( minmem + size + 0x10000ul ); maxmem = Align4K( maxmem + size + 0x10000ul ); if( minmem > maxmem ) { maxmem = minmem; } /* * get memory to load file */ tried_global_compact = false; save_maxmem = maxmem; while( (i = _DPMIGet32( &adata, maxmem )) != 0 ) { if( maxmem == minmem ) { if( tried_global_compact ) { return( Fini( 3, (char _FAR *)"Not enough memory for application\n(minimum ", dwordToStr( minmem ),(char _FAR *)" required)" )); } /* * GlobalCompact(-1) causes Windows to unfragment its * memory. This might give us a chance to get a linear * chunk big enough */ GlobalCompact( GlobalCompact( 0 ) ); maxmem = save_maxmem; tried_global_compact = true; } else if( maxmem < 64L * 1024L ) { maxmem = minmem; } else { maxmem -= 64L * 1024L; if( maxmem < minmem ) { /* 09-aug-93 */ maxmem = minmem; } } } DataHandle = adata.handle; BaseAddr = adata.linear + 0x10000ul; #if FLAT i = InitFlatAddrSpace( BaseAddr, 0L ); #else i = InitFlatAddrSpace( BaseAddr, maxmem ); #endif BaseAddr = 0L; if( i ) { DPMIFreeMemoryBlock( DataHandle ); return( Fini( 2,(char _FAR *)"Allocation error ", dwordToStr( i ) ) ); } SaveSP = BaseAddr + StackSize; CodeLoadAddr = SaveSP; MyDataSelector = DataSelector; GetDataSelectorInfo(); CodeEntry.off = exe.initial_eip + CodeLoadAddr + sizeof( exe_data ); /* * this builds a collection of LDT selectors that are ready for * allocation */ if( InitSelectorCache() != 0 ) { return( Fini( 1,(char _FAR *)outOfSelectors) ); } /* * read the exe into memory */ currsize = size - file_header_size; _TinySeek( handle, exelen + file_header_size, TIO_SEEK_START ); i = _DPMIGetAliases( CodeLoadAddr, (LPDWORD)&aliasptr, 0 ); if( i ) { return( Fini( 3,(char _FAR *)"Error ", dwordToStr( i ), (char _FAR *)" getting alias for read" ) ); } dataptr = aliasptr; sel = ((DWORD)dataptr) >> 16; curroff = CodeLoadAddr; while( currsize != 0 ) { if( currsize >= (DWORD) READSIZE ) { amount = READSIZE; } else { amount = (WORD) currsize; } rc = _fTinyRead( handle, dataptr, amount ); bytes_read = TINY_INFO( rc ); if( bytes_read != amount ) { return( Fini( 1,(char _FAR *)"Read error" ) ); } currsize -= (DWORD) amount; curroff += (DWORD) amount; DPMISetSegmentBaseAddress( sel, DataSelectorBase + curroff ); } EDataAddr = curroff; // 03-jan-95 DPMISetSegmentBaseAddress( sel, DataSelectorBase ); relptr = (DWORD __far *)aliasptr; // point to 32-bit stack area /* * get and apply relocation table */ relsize = sizeof( DWORD ) * (DWORD) exe.reloc_cnt; { DWORD realsize; WORD kcnt; realsize = file_header_size - (DWORD) exe.first_reloc; kcnt = realsize / (0x10000L*sizeof(DWORD)); relsize += kcnt * (0x10000L*sizeof(DWORD)); } if( relsize != 0 ) { _TinySeek( handle, exelen + (DWORD)exe.first_reloc, TIO_SEEK_START ); if( StackSize >= (DWORD) READSIZE ) { amount = READSIZE; } else { amount = (WORD) StackSize; } while( relsize != 0L ) { if( relsize < (DWORD)amount ) { amount = (WORD) relsize; } rc = _fTinyRead( handle, relptr, amount ); bytes_read = TINY_INFO( rc ); if( bytes_read != amount ) { return( Fini( 1,(char _FAR *)"Relocation read error" ) ); } CodeRelocate( relptr, amount/sizeof(DWORD) ); relsize -= (DWORD) amount; } } _TinyClose( handle ); /* initialize emulator 8087 save area 20-oct-94 */ fpuptr = (struct fpu_area __far *)((char __far *)aliasptr + FPU_AREA); _fmemset( fpuptr, 0, sizeof(struct fpu_area) ); fpuptr->control_word = 0x033F; fpuptr->tag_word = 0xFFFF; /* * set dataptr to special area in data segment of 32-bit app */ curroff = exedat.datastart; if( exe.reloc_cnt != 0 ) curroff += CodeLoadAddr; DPMISetSegmentBaseAddress( sel, DataSelectorBase + curroff ); /* * insert command line parms */ dataptr->thishandle = (WORD)thishandle; dataptr->prevhandle = (WORD)prevhandle; dataptr->cmdline = (DWORD) cmdline; dataptr->cmdshow = cmdshow; dataptr->_no87 = _no87; /* * set hardware selectors for screen memory */ dataptr->_A000H = (WORD) &_A000H; dataptr->_B000H = (WORD) &_B000H; dataptr->_B800H = (WORD) &_B800H; dataptr->_C000H = (WORD) &_C000H; dataptr->_D000H = (WORD) &_D000H; dataptr->_E000H = (WORD) &_E000H; dataptr->_F000H = (WORD) &_F000H; /* * ptrs to some data areas */ dataptr->CodeSelectorBase.seg = (WORD) FP_SEG( &CodeSelectorBase ); dataptr->CodeSelectorBase.off = (DWORD) FP_OFF( &CodeSelectorBase ); dataptr->DataSelectorBase.seg = (WORD) FP_SEG( &DataSelectorBase ); dataptr->DataSelectorBase.off = (DWORD) FP_OFF( &DataSelectorBase ); dataptr->_32BitCallBackAddr.seg = (WORD) FP_SEG( &_32BitCallBackAddr ); dataptr->_32BitCallBackAddr.off = (DWORD) FP_OFF( &_32BitCallBackAddr ); dataptr->_DLLEntryAddr.seg = (WORD) FP_SEG( &_DLLEntryAddr ); dataptr->_DLLEntryAddr.off = (DWORD) FP_OFF( &_DLLEntryAddr ); dataptr->_WEPAddr.seg = (WORD) FP_SEG( &_WEPAddr ); dataptr->_WEPAddr.off = (DWORD) FP_OFF( &_WEPAddr ); dataptr->_16BitCallBackAddr = &__CallBack; /* * insert glue routines into data area of caller */ for( j = 0; j < MaxGlueRoutines; j++ ) { dataptr->gluertns[j].seg = (WORD) FP_SEG( Glue[j].rtn ); dataptr->gluertns[j].off = (DWORD) FP_OFF( Glue[j].rtn ); } _DPMIFreeAlias( sel ); /* * check for FPU and WGod */ if( flags & WF_80x87 ) { Has87 = true; } else { Has87 = false; } if( CheckWin386Debug() == WGOD_VERSION ) { // BreakPoint(); HasWGod = true; if( !Has87 ) { EMUInit(); EMURegister( CodeEntry.seg, SaveSP - StackSize + FPU_AREA ); } } else { HasWGod = false; } return( true ); } /* Init32BitTask */
/* * Handle a GP fault that occurred while in VM86 mode. Things that are easy * to handle here are done here (much more efficient than trapping to 32-bit * handler code and then having it restart VM86 mode). */ void vm86_gpfault(struct proc *p, int type) { struct trapframe *tf = p->p_md.md_regs; union sigval sv; /* * we want to fetch some stuff from the current user virtual * address space for checking. remember that the frame's * segment selectors are real-mode style selectors. */ u_long cs, ip, ss, sp; u_char tmpbyte; int trace; cs = CS(tf) << 4; ip = IP(tf); ss = SS(tf) << 4; sp = SP(tf); trace = tf->tf_eflags & PSL_T; /* * For most of these, we must set all the registers before calling * macros/functions which might do a vm86_return. */ tmpbyte = getbyte(cs, ip); IP(tf) = ip; switch (tmpbyte) { case CLI: /* simulate handling of IF */ clr_vif(p); break; case STI: /* simulate handling of IF. * XXX the i386 enables interrupts one instruction later. * code here is wrong, but much simpler than doing it Right. */ set_vif(p); break; case INTxx: /* try fast intxx, or return to 32bit mode to handle it. */ tmpbyte = getbyte(cs, ip); IP(tf) = ip; fast_intxx(p, tmpbyte); break; case INTO: if (tf->tf_eflags & PSL_V) fast_intxx(p, 4); break; case PUSHF: putword(ss, sp, get_vflags_short(p)); SP(tf) = sp; break; case IRET: IP(tf) = getword(ss, sp); CS(tf) = getword(ss, sp); case POPF: set_vflags_short(p, getword(ss, sp)); SP(tf) = sp; break; case OPSIZ: tmpbyte = getbyte(cs, ip); IP(tf) = ip; switch (tmpbyte) { case PUSHF: putdword(ss, sp, get_vflags(p) & ~PSL_VM); SP(tf) = sp; break; case IRET: IP(tf) = getdword(ss, sp); CS(tf) = getdword(ss, sp); case POPF: set_vflags(p, getdword(ss, sp) | PSL_VM); SP(tf) = sp; break; default: IP(tf) -= 2; goto bad; } break; case LOCK: default: IP(tf) -= 1; goto bad; } if (trace && tf->tf_eflags & PSL_VM) { sv.sival_int = 0; trapsignal(p, SIGTRAP, T_TRCTRAP, TRAP_TRACE, sv); } return; bad: vm86_return(p, VM86_UNKNOWN); return; }
// // Function: insertPoolFrees() // // Description: // This function takes a list of alloca instructions and inserts code to // unregister them at every unwind and return instruction. // // Inputs: // PoolRegisters - The list of calls to poolregister() inserted for stack // objects. // ExitPoints - The list of instructions that can cause the function to // return. // Context - The LLVM Context in which to insert instructions. // void RegisterStackObjPass::insertPoolFrees (const std::vector<CallInst *> & PoolRegisters, const std::vector<Instruction *> & ExitPoints, LLVMContext * Context) { // List of alloca instructions we create to store the pointers to be // deregistered. std::vector<AllocaInst *> PtrList; // List of pool handles; this is a parallel array to PtrList std::vector<Value *> PHList; // The infamous void pointer type PointerType * VoidPtrTy = getVoidPtrType(*Context); // // Create alloca instructions for every registered alloca. These will hold // a pointer to the registered stack objects and will be referenced by // poolunregister(). // for (unsigned index = 0; index < PoolRegisters.size(); ++index) { // // Take the first element off of the worklist. // CallInst * CI = PoolRegisters[index]; CallSite CS(CI); // // Get the pool handle and allocated pointer from the poolregister() call. // Value * PH = CS.getArgument(0); Value * Ptr = CS.getArgument(1); // // Create a place to store the pointer returned from alloca. Initialize it // with a null pointer. // BasicBlock & EntryBB = CI->getParent()->getParent()->getEntryBlock(); Instruction * InsertPt = &(EntryBB.front()); AllocaInst * PtrLoc = new AllocaInst (VoidPtrTy, Ptr->getName() + ".st", InsertPt); Value * NullPointer = ConstantPointerNull::get(VoidPtrTy); new StoreInst (NullPointer, PtrLoc, InsertPt); // // Store the registered pointer into the memory we allocated in the entry // block. // new StoreInst (Ptr, PtrLoc, CI); // // Record the alloca that stores the pointer to deregister. // Record the pool handle with it. // PtrList.push_back (PtrLoc); PHList.push_back (PH); } // // For each point where the function can exit, insert code to deregister all // stack objects. // for (unsigned index = 0; index < ExitPoints.size(); ++index) { // // Take the first element off of the worklist. // Instruction * Return = ExitPoints[index]; // // Deregister each registered stack object. // for (unsigned i = 0; i < PtrList.size(); ++i) { // // Get the location holding the pointer and the pool handle associated // with it. // AllocaInst * PtrLoc = PtrList[i]; Value * PH = PHList[i]; // // Generate a load instruction to get the registered pointer. // LoadInst * Ptr = new LoadInst (PtrLoc, "", Return); // // Create the call to poolunregister(). // std::vector<Value *> args; args.push_back (PH); args.push_back (Ptr); CallInst::Create (StackFree, args, "", Return); } } // // Lastly, promote the allocas we created into LLVM virtual registers. // PromoteMemToReg(PtrList, *DT); }
void _dv_weight_init(void) { double temp[64]; double temp_postsc[64]; int i, z, x; #if ARCH_X86 || ARCH_X86_64 const double dv_weight_bias_factor = (double)(1UL << DV_WEIGHT_BIAS); #endif W[0] = 1.0; W[1] = CS(4) / (4.0 * CS(7) * CS(2)); W[2] = CS(4) / (2.0 * CS(6)); W[3] = 1.0 / (2 * CS(5)); W[4] = 7.0 / 8.0; W[5] = CS(4) / CS(3); W[6] = CS(4) / CS(2); W[7] = CS(4) / CS(1); for (i = 0; i < 64; i++) { temp[i] = 1.0; } weight_88_inverse_float(temp); for (i=0;i<64;i++) { #if (!ARCH_X86) && (!ARCH_X86_64) dv_weight_inverse_88_matrix[i] = (dv_coeff_t)rint(temp[i]); #else /* If we're using MMX assembler, fold weights into the iDCT prescale */ preSC[i] *= temp[i] * (16.0 / dv_weight_bias_factor); #endif } postscale88_init(temp_postsc); for (i = 0; i < 64; i++) { temp[i] = 1.0; } weight_88_float(temp); for (i=0;i<64;i++) { #if BRUTE_FORCE_DCT_88 dv_weight_88_matrix[i] = temp[i]; #else /* If we're not using brute force(tm), fold weights into the DCT postscale */ postSC88[i]= int_val(temp_postsc[i] * temp[i] * 32768.0 * 2.0); #endif } postSC88[63] = temp[63] * 32768 * 2.0; postscale248_init(temp_postsc); for (i = 0; i < 64; i++) { temp[i] = 1.0; } weight_248_float(temp); for (i=0;i<64;i++) { #if BRUTE_FORCE_DCT_248 dv_weight_248_matrix[i] = temp[i]; #else /* If we're not using brute force(tm), fold weights into the DCT postscale */ postSC248[i]= int_val(temp_postsc[i]* temp[i] * 32768.0 * 2.0); #endif } for (z=0;z<4;z++) { for (x=0;x<8;x++) { dv_weight_inverse_248_matrix[z*8+x] = 2.0 / (W[x] * W[2*z]); dv_weight_inverse_248_matrix[(z+4)*8+x] = 2.0 / (W[x] * W[2*z]); } } dv_weight_inverse_248_matrix[0] = 4.0; }