/* // Name: make_action // In: tag, the tag of the message. // command, the command that was send. // message, the trailing message (arguments). // c, the client that sent the message. // msg_is_quoted, wheater or no teh message contains quotes. // clients, all connected clients. // curr_topic, the current topic. // Out: The action that the client want to do in it's connection. // Purpose: Parses the command and does the proper action. */ int make_action(char* tag, char* command, char* message, clientconn_t *c, char msg_is_quoted, hash *clients, char *curr_topic) { if(strlen(tag)==0) { return 0; } if(strcmp(tag, "\r\n")==0) { client_write(c, "BAD No tag.\r\n", 13); return 0; } if(strlen(command)==0) { client_write(c, tag, strlen(tag)); client_write(c, " BAD No command.\r\n", 18); return 0; } if(msg_is_quoted && !msg_is_correctly_quoted(message, msg_is_quoted) && strcmp(command, "PRIVATE")) { return badly_formed(c, tag); } if(strcmp(command, "CAPABILITY")==0) { return capability(c, tag); } if(strcmp(command, "JOIN")==0) { return join(c, tag, clients); } if(strcmp(command, "NICK")==0) { return nick(c, tag, message, msg_is_quoted, clients); } if(strcmp(command,"QUIT")==0) { return quit(c, tag, clients); } if(!c->joined) { return not_joined(c, tag); } if(strcmp(command, "LEAVE")==0) { return leave(c, tag, clients); } if(strcmp(command, "TALK")==0) { return talk(c, tag, message, clients); } if(strcmp(command, "NAMES")==0) { return names(c, tag, clients); } if(strcmp(command, "TOPIC")==0) { return topic(c, tag, message, clients, curr_topic); } if(strcmp(command, "PRIVATE")==0) { return private(c, tag, message, clients); } if(strcmp(command, "WHOIS")==0) { return whois(c, tag, message, clients); } client_write(c, tag, strlen(tag)); client_write(c, " BAD Unkown command.\r\n", 22); return 0; }
// Evaluate/Update ResultMacro ResultMacroEval Macro_evalResultMacro( ResultPendingElem resultElem ) { // Lookup ResultMacro const ResultMacro *macro = &ResultMacroList[ resultElem.index ]; ResultMacroRecord *record = &ResultMacroRecordList[ resultElem.index ]; // Current Macro position var_uint_t pos = record->pos; // Length of combo being processed uint8_t comboLength = macro->guide[ pos ]; // Function Counter, used to keep track of the combo items processed var_uint_t funcCount = 0; // Combo Item Position within the guide var_uint_t comboItem = pos + 1; // Iterate through the Result Combo while ( funcCount < comboLength ) { // Assign TriggerGuide element (key type, state and scancode) ResultGuide *guide = (ResultGuide*)(¯o->guide[ comboItem ]); // Do lookup on capability function void (*capability)(TriggerMacro*, uint8_t, uint8_t, uint8_t*) = \ (void(*)(TriggerMacro*, uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func); // Call capability capability( resultElem.trigger, record->state, record->stateType, &guide->args ); // Increment counters funcCount++; comboItem += ResultGuideSize( (ResultGuide*)(¯o->guide[ comboItem ]) ); } // Move to next item in the sequence record->pos = comboItem; // If the ResultMacro is finished, remove if ( macro->guide[ comboItem ] == 0 ) { record->pos = 0; return ResultMacroEval_Remove; } // Otherwise leave the macro in the list return ResultMacroEval_DoNothing; }
void check_cpu(cpu_t *mcpu) /* This is the function to call to set the globals */ { const char *unknown_vendor = "NoVendorName"; const char *cyrix = "CyrixInstead"; long vendor_temp[3]; cpu_inf t; String::memset(mcpu->cpu_vendor, 0, 16); if (_is_cpuid_supported()) { mcpu->cpu_cpuid = TRUE; t.reg_eax = t.reg_ebx = t.reg_ecx = t.reg_edx = 0; _get_cpuid_info(0,&t); mcpu->cpuid_levels = t.reg_eax; vendor_temp[0] = t.reg_ebx; vendor_temp[1] = t.reg_edx; vendor_temp[2] = t.reg_ecx; String::memcpy(mcpu->cpu_vendor, vendor_temp, 12); if (mcpu->cpuid_levels > 0) { t.reg_eax = t.reg_ebx = t.reg_ecx = t.reg_edx = 0; _get_cpuid_info (1,&t); mcpu->cpu_family = ((t.reg_eax>>8) & 0xf); mcpu->cpu_model = ((t.reg_eax>>4) & 0xf); mcpu->cpu_stepping=(t.reg_eax & 0xf); mcpu->cpu_ext_family=((t.reg_eax>>20) & 0xff); mcpu->cpu_ext_model=((t.reg_eax>>16) & 0xf); switch(((t.reg_eax>>12)&0x7)) { case 0: String::strcpy(mcpu->dType, "Original"); break; case 1: String::strcpy(mcpu->dType, "OverDrive"); break; case 2: String::strcpy(mcpu->dType, "Dual"); break; } mcpu->cpu_fpu = (t.reg_edx & 1 ? TRUE : FALSE); mcpu->cpu_mmx = (t.reg_edx & 0x800000 ? TRUE: FALSE); capability(t,mcpu); } }
void cliFunc_capList( char* args ) { print( NL ); info_msg("Capabilities List "); printHex( CapabilitiesNum ); // Iterate through all of the capabilities and display them for ( var_uint_t cap = 0; cap < CapabilitiesNum; cap++ ) { print( NL "\t" ); printHex( cap ); print(" - "); // Display/Lookup Capability Name (utilize debug mode of capability) void (*capability)(TriggerMacro*, uint8_t, uint8_t, uint8_t*) = \ (void(*)(TriggerMacro*, uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func); capability( 0, 0xFF, 0xFF, 0 ); } }
TEST(ReachabilitySphere, convertToCapability) { Capability capability(CONE, 70.0, 55.0, 25.0); ReachabilitySphere sphere = createReachabilitySphereFromCapability(capability, 500); Capability testCapability = sphere.convertToCapability(); ASSERT_TRUE(testCapability.getType() == CONE); ASSERT_TRUE(std::abs(testCapability.getPhi() - capability.getPhi()) < 2.0); ASSERT_TRUE(std::abs(testCapability.getTheta() - capability.getTheta()) < 2.0); ASSERT_TRUE(std::abs(testCapability.getHalfOpeningAngle() - capability.getHalfOpeningAngle()) < 2.0); ASSERT_EQ(0.0, testCapability.getShapeFitError()); capability = Capability(CYLINDER_1, 70.0, 55.0, 25.0); sphere = createReachabilitySphereFromCapability(capability, 10000); testCapability = sphere.convertToCapability(); ASSERT_TRUE(testCapability.getType() == CYLINDER_1); ASSERT_TRUE(std::abs(testCapability.getPhi() - capability.getPhi()) < 2.0); ASSERT_TRUE(std::abs(testCapability.getTheta() - capability.getTheta()) < 2.0); ASSERT_TRUE(std::abs(testCapability.getHalfOpeningAngle() - capability.getHalfOpeningAngle()) < 2.0); // ASSERT_EQ(0.0, testCapability.getShapeFitError()); // TODO: improve PCA to get correct axis (for now SFE could be 0.0 but is higher) capability = Capability(CYLINDER_2, 70.0, 55.0, 25.0); sphere = createReachabilitySphereFromCapability(capability, 10000); testCapability = sphere.convertToCapability(); ASSERT_TRUE(testCapability.getType() == CYLINDER_2); ASSERT_TRUE(std::abs(testCapability.getPhi() - capability.getPhi()) < 2.0); ASSERT_TRUE(std::abs(testCapability.getTheta() - capability.getTheta()) < 2.0); ASSERT_TRUE(std::abs(testCapability.getHalfOpeningAngle() - capability.getHalfOpeningAngle()) < 2.0); // ASSERT_EQ(0.0, testCapability.getShapeFitError()); }
uint8_t Connect_receive_RemoteCapability( uint8_t byte, uint16_t *pending_bytes, uint8_t uart_num ) { // Check which byte in the packet we are at switch ( (*pending_bytes)-- ) { // Byte count always starts at 0xFFFF case 0xFFFF: // Device Id Connect_receive_RemoteCapabilityBuffer.id = byte; break; case 0xFFFE: // Capability Index Connect_receive_RemoteCapabilityBuffer.capabilityIndex = byte; break; case 0xFFFD: // State Connect_receive_RemoteCapabilityBuffer.state = byte; break; case 0xFFFC: // StateType Connect_receive_RemoteCapabilityBuffer.stateType = byte; break; case 0xFFFB: // Number of args Connect_receive_RemoteCapabilityBuffer.numArgs = byte; *pending_bytes = byte; break; default: // Args (# defined by previous byte) Connect_receive_RemoteCapabilityArgs[ Connect_receive_RemoteCapabilityBuffer.numArgs - *pending_bytes + 1 ] = byte; // If entire packet has been fully received if ( *pending_bytes == 0 ) { // Determine if this is the node to run the capability on // Conditions: Matches or broadcast (0xFF) if ( Connect_receive_RemoteCapabilityBuffer.id == 0xFF || Connect_receive_RemoteCapabilityBuffer.id == Connect_id ) { extern const Capability CapabilitiesList[]; // See generatedKeymap.h void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))( CapabilitiesList[ Connect_receive_RemoteCapabilityBuffer.capabilityIndex ].func ); capability( Connect_receive_RemoteCapabilityBuffer.state, Connect_receive_RemoteCapabilityBuffer.stateType, &Connect_receive_RemoteCapabilityArgs[2] ); } // If this is not the correct node, keep sending it in the same direction (doesn't matter if more nodes exist) // or if this is a broadcast if ( Connect_receive_RemoteCapabilityBuffer.id == 0xFF || Connect_receive_RemoteCapabilityBuffer.id != Connect_id ) { // Prepare outgoing packet Connect_receive_RemoteCapabilityBuffer.command = RemoteCapability; // Send to the other UART (not the one receiving the packet from uint8_t uart_direction = uart_num == UART_Master ? UART_Slave : UART_Master; // Lock Tx UART switch ( uart_direction ) { case UART_Master: uart_lockTx( UART_Master ); break; case UART_Slave: uart_lockTx( UART_Slave ); break; } // Send header uint8_t header[] = { 0x16, 0x01 }; Connect_addBytes( header, sizeof( header ), uart_direction ); // Send Remote Capability and arguments Connect_addBytes( (uint8_t*)&Connect_receive_RemoteCapabilityBuffer, sizeof( RemoteCapabilityCommand ), uart_direction ); Connect_addBytes( Connect_receive_RemoteCapabilityArgs, Connect_receive_RemoteCapabilityBuffer.numArgs, uart_direction ); // Unlock Tx UART switch ( uart_direction ) { case UART_Master: uart_unlockTx( UART_Master ); break; case UART_Slave: uart_unlockTx( UART_Slave ); break; } } } break; } // Check whether the scan codes have finished sending return *pending_bytes == 0 ? 1 : 0; }
void macroDebugShowResult( var_uint_t index ) { // Only proceed if the macro exists if ( index >= ResultMacroNum ) return; // Trigger Macro Show const ResultMacro *macro = &ResultMacroList[ index ]; print( NL ); info_msg("Result Macro Index: "); printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit) print( NL ); // Read the comboLength for combo in the sequence (sequence of combos) var_uint_t pos = 0; uint8_t comboLength = macro->guide[ pos++ ]; // Iterate through and interpret the guide while ( comboLength != 0 ) { // Function Counter, used to keep track of the combos processed var_uint_t funcCount = 0; // Iterate through the combo while ( funcCount < comboLength ) { // Assign TriggerGuide element (key type, state and scancode) ResultGuide *guide = (ResultGuide*)(¯o->guide[ pos ]); // Display Function Index printHex( guide->index ); print("|"); // Display Function Ptr Address printHex( (nat_ptr_t)CapabilitiesList[ guide->index ].func ); print("|"); // Display/Lookup Capability Name (utilize debug mode of capability) void (*capability)(TriggerMacro*, uint8_t, uint8_t, uint8_t*) = \ (void(*)(TriggerMacro*, uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func); capability( 0, 0xFF, 0xFF, 0 ); // Display Argument(s) print("("); for ( var_uint_t arg = 0; arg < CapabilitiesList[ guide->index ].argCount; arg++ ) { // Arguments are only 8 bit values printHex( (&guide->args)[ arg ] ); // Only show arg separator if there are args left if ( arg + 1 < CapabilitiesList[ guide->index ].argCount ) print(","); } print(")"); // Increment position pos += ResultGuideSize( guide ); // Increment function count funcCount++; // Only show combo separator if there are combos left in the sequence element if ( funcCount < comboLength ) print("+"); } // Read the next comboLength comboLength = macro->guide[ pos++ ]; // Only show sequence separator if there is another combo to process if ( comboLength != 0 ) print(";"); } /* XXX (HaaTa) Fix for ring-buffer record list ResultMacroRecord *record = &ResultMacroRecordList[ index ]; // Display current position print( NL "Position: " ); printInt16( (uint16_t)record->pos ); // Hopefully large enough :P (can't assume 32-bit) print(" "); printInt16( (uint16_t)record->prevPos ); // Display final trigger state/type print( NL "Final Trigger State (State/Type): " ); printHex( record->state ); print("/"); printHex( record->stateType ); */ }
void cliFunc_capSelect( char* args ) { // Parse code from argument char* curArgs; char* arg1Ptr; char* arg2Ptr = args; // Total number of args to scan (must do a lookup if a keyboard capability is selected) var_uint_t totalArgs = 2; // Always at least two args var_uint_t cap = 0; // Arguments used for keyboard capability function var_uint_t argSetCount = 0; uint8_t *argSet = (uint8_t*)args; // Process all args for ( var_uint_t c = 0; argSetCount < totalArgs; c++ ) { curArgs = arg2Ptr; CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); // Stop processing args if no more are found // Extra arguments are ignored if ( *arg1Ptr == '\0' ) break; // For the first argument, choose the capability if ( c == 0 ) switch ( arg1Ptr[0] ) { // Keyboard Capability case 'K': // Determine capability index cap = numToInt( &arg1Ptr[1] ); // Lookup the number of args totalArgs += CapabilitiesList[ cap ].argCount; continue; } // Because allocating memory isn't doable, and the argument count is arbitrary // The argument pointer is repurposed as the argument list (much smaller anyways) argSet[ argSetCount++ ] = (uint8_t)numToInt( arg1Ptr ); // Once all the arguments are prepared, call the keyboard capability function if ( argSetCount == totalArgs ) { // Indicate that the capability was called print( NL ); info_msg("K"); printInt8( cap ); print(" - "); printHex( argSet[0] ); print(" - "); printHex( argSet[1] ); print(" - "); printHex( argSet[2] ); print( "..." NL ); // Make sure this isn't the reload capability // If it is, and the remote reflash define is not set, ignore if ( flashModeEnabled_define == 0 ) for ( uint32_t cap = 0; cap < CapabilitiesNum; cap++ ) { if ( CapabilitiesList[ cap ].func == (const void*)Output_flashMode_capability ) { print( NL ); warn_print("flashModeEnabled not set, cancelling firmware reload..."); info_msg("Set flashModeEnabled to 1 in your kll configuration."); return; } } void (*capability)(TriggerMacro*, uint8_t, uint8_t, uint8_t*) = \ (void(*)(TriggerMacro*, uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func); capability( 0, argSet[0], argSet[1], &argSet[2] ); } } }
// RUN: %clang_cc1 -fsyntax-only -Wthread-safety -verify %s struct __attribute__((capability("thread role"))) ThreadRole {}; struct __attribute__((shared_capability("mutex"))) Mutex {}; struct NotACapability {}; int Test1 __attribute__((capability("test1"))); // expected-error {{'capability' attribute only applies to structs}} int Test2 __attribute__((shared_capability("test2"))); // expected-error {{'shared_capability' attribute only applies to structs}} int Test3 __attribute__((acquire_capability("test3"))); // expected-error {{'acquire_capability' attribute only applies to functions}} int Test4 __attribute__((try_acquire_capability("test4"))); // expected-error {{'try_acquire_capability' attribute only applies to functions}} int Test5 __attribute__((release_capability("test5"))); // expected-error {{'release_capability' attribute only applies to functions}} struct __attribute__((capability(12))) Test3 {}; // expected-error {{'capability' attribute requires a string}} struct __attribute__((shared_capability(Test2))) Test4 {}; // expected-error {{'shared_capability' attribute requires a string}} struct __attribute__((capability)) Test5 {}; // expected-error {{'capability' attribute takes one argument}} struct __attribute__((shared_capability("test1", 12))) Test6 {}; // expected-error {{'shared_capability' attribute takes one argument}} struct NotACapability BadCapability; struct ThreadRole GUI, Worker; void Func1(void) __attribute__((requires_capability(GUI))) {} void Func2(void) __attribute__((requires_shared_capability(Worker))) {} void Func3(void) __attribute__((requires_capability)) {} // expected-error {{'requires_capability' attribute takes at least 1 argument}} void Func4(void) __attribute__((requires_shared_capability)) {} // expected-error {{'requires_shared_capability' attribute takes at least 1 argument}} void Func5(void) __attribute__((requires_capability(1))) {} // expected-warning {{'requires_capability' attribute requires arguments that are class type or point to class type}} void Func6(void) __attribute__((requires_shared_capability(BadCapability))) {} // expected-warning {{'requires_shared_capability' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'struct NotACapability'}} void Func7(void) __attribute__((assert_capability(GUI))) {} void Func8(void) __attribute__((assert_shared_capability(GUI))) {}
void get_capabilities() { char buffer[2500] = ""; char *buf=buffer; termtype = getenv("TERM"); maxcolors = tgetnum("Co"); maxpairs = tgetnum("pa"); capability(&buf, "AF", &c_setfore); capability(&buf, "AB", &c_setback); capability(&buf, "op", &c_resetcolor); capability(&buf, "md", &c_bold); capability(&buf, "mh", &c_dim); capability(&buf, "mr", &c_reverse); capability(&buf, "mb", &c_blinking); capability(&buf, "so", &c_standstr); capability(&buf, "se", &c_exit_stand); capability(&buf, "me", &c_exit_attr); capability(&buf, "Ic", &c_inicolor_str); capability(&buf, "Yw", &c_clrnames); capability(&buf, "op", &c_opair); }