void radio_tx_command(void) { unsigned int value; if( radio_tx_buffer.packets_rxd ) { unsigned int length = command_length( &radio_tx_buffer ); while( length-- ) { buffer_pop(&value, &radio_tx_buffer); radio_send_byte( (char) value ); } } }
/** * @brief is_variable_assignment is called when the user command is of the form var = something * (provided var is not an internal or external command) * This function searches the var_list and if it finds exiting variable with the same name, * then the corresponding structure of the variable is updated; * else, a new variable structure is created and is added to varlist * * @param cmd The command being processed * * @return YES, if cmd is indeed of the form 'x = something'; else NO */ int is_variable_assignment(command_t cmd) { int len = command_length(cmd); if(len > 2) { if(!strcmp(cmd->next->string,"=")) { struct variable* v = search_variable(cmd->string); if(cmd->next->next->string[0] == '"') { if(v == NULL) { struct variable* v = malloc(sizeof(struct variable)); v->string = malloc(strlen(cmd->next->next->string) + 1); strcpy(v->string, cmd->next->next->string + 1); v->string[strlen(cmd->next->next->string) - 2] = '\0'; v->next = var_list; v->name = malloc(sizeof(strlen(cmd->string) + 1)); strcpy(v->name, cmd->string); var_list = v; return YES; } else { v->string = malloc(sizeof(strlen(cmd->next->next->string) + 1)); strcpy(v->string,cmd->next->next->string + 1); v->string[strlen(cmd->next->next->string) - 2] = '\0'; return YES; } } else { return NO; } } else { return NO; } } else { return NO; } }
/** * @brief this function is used to implement "export var" command * * @param cmd The command being processed * * @return YES, if cmd is of form 'export var'; else NO */ int is_export(command_t cmd) { if(!strcmp(cmd->string, "export")) { if(command_length(cmd) != 2) { printf("improper usage of export command\n"); return YES; } else { struct variable* v = search_variable(cmd->next->string); if(v == NULL) { printf("no such variable\n"); } else { if(!strcmp(v->string,"")) { printf("sorry, kavach can only export strings and not integers :( \n"); } else { setenv(v->name,v->string,1); } } } return YES; } else { return NO; } }