WSLUA_METAMETHOD Columns__newindex(lua_State *L) { /* Sets the text of a specific column */ #define WSLUA_ARG_Columns__newindex_COLUMN 2 /* The name of the column to set */ #define WSLUA_ARG_Columns__newindex_TEXT 3 /* The text for the column */ Columns cols = checkColumns(L,1); const struct col_names_t* cn; const char* colname; const char* text; if (!cols) return 0; if (cols->expired) { luaL_error(L,"expired column"); return 0; } colname = luaL_checkstring(L,WSLUA_ARG_Columns__newindex_COLUMN); text = luaL_checkstring(L,WSLUA_ARG_Columns__newindex_TEXT); for(cn = colnames; cn->name; cn++) { if( g_str_equal(cn->name,colname) ) { col_add_str(cols->cinfo, cn->id, text); return 0; } } WSLUA_ARG_ERROR(Columns__newindex,COLUMN,"the column name must be a valid column"); }
bool TicTacToeGame::isGameOver() const { displayBoard(); bool bGameOver = checkColumns(); bGameOver |= checkRows(); bGameOver |= checkDiagonals(); return bGameOver; }
void KTreeWidgetSearchLine::addTreeWidget(QTreeWidget *tw) { if (tw) { connectTreeWidget(tw); k->treeWidgets.append(tw); setEnabled(!k->treeWidgets.isEmpty()); checkColumns(); } }
static int Columns_gc(lua_State* L) { Columns cols = checkColumns(L,1); if (!cols) return 0; if (!cols->expired) cols->expired = TRUE; else g_free(cols); return 0; }
void KTreeWidgetSearchLine::setTreeWidgets(const QList<QTreeWidget *> &tw) { foreach (QTreeWidget* treeWidget, k->treeWidgets) disconnectTreeWidget(treeWidget); k->treeWidgets = tw; foreach (QTreeWidget* treeWidget, k->treeWidgets) connectTreeWidget(treeWidget); checkColumns(); setEnabled(!k->treeWidgets.isEmpty()); }
void checkColumns_returns_winner_if_one_exists(CuTest *tc) { int board[4][4]; ct_initialize(4, 4, board); board[0][1] = 1; board[1][1] = 1; board[2][1] = 1; board[3][1] = 1; int answer = checkColumns(4, 4, board, 4); CuAssertIntEquals_Msg(tc, "Player 1.", 1, answer); }
void KTreeWidgetSearchLine::removeTreeWidget(QTreeWidget *tw) { if (tw) { int idx = k->treeWidgets.indexOf(tw); if (idx != -1) { k->treeWidgets.removeAt(idx); checkColumns(); disconnectTreeWidget(tw); setEnabled(!k->treeWidgets.isEmpty()); } } }
bool DFSBoard::tryFillRow(int nowr){//is vector copy by reference? vector<int> fillStart; printf("fillRow%d\n", nowr); if(!getPreviousFillStart(fillStart, nowr)) return false; BackupBoard(original[nowr]); bool isSuccess = false; do{ FillRowbyFillStart(nowr, fillStart); if(checkColumns()){//check available isSuccess = true; } } while(!isSuccess && getNextFillStart(nowr, fillStart)); lastfillStart[nowr] = fillStart; return isSuccess; }
WSLUA_METAMETHOD Columns__index(lua_State *L) { /* Gets a specific Column. */ Columns cols = checkColumns(L,1); const struct col_names_t* cn; const char* colname = luaL_checkstring(L,2); if (!cols) { Column c = (Column)g_malloc(sizeof(struct _wslua_col_info)); c->cinfo = NULL; c->col = col_name_to_id(colname); c->expired = FALSE; PUSH_COLUMN(L,c); return 1; } if (cols->expired) { luaL_error(L,"expired column"); return 0; } if (!colname) return 0; for(cn = colnames; cn->name; cn++) { if( g_str_equal(cn->name,colname) ) { Column c = (Column)g_malloc(sizeof(struct _wslua_col_info)); c->cinfo = cols->cinfo; c->col = col_name_to_id(colname); c->expired = FALSE; PUSH_COLUMN(L,c); return 1; } } return 0; }
int handle_command(int sock, char *cmd, struct config_params *p, TableHeader* record_tables) { char *username_str; char *password_str; char *gettable_str; char *getkey_str; char *settable_str; char *setkey_str; char *setrecord_str; char *metada; char feedback[800]; char message[MAX_CONFIG_LINE_LEN]; struct timeval t1, t2; gettimeofday(&t1, NULL); sprintf(message , "Processing command '%s'\n", cmd); char *cmd_str=strtok(cmd," "); //Authentication if (strcmp(cmd_str,"AUTH")==0){ username_str=strtok(NULL," "); password_str=strtok(NULL," "); p->status_auth = authentication_check(p,username_str,password_str); if (p->status_auth == -1) { sprintf(feedback , "error %d" , ERR_AUTHENTICATION_FAILED); //sends an error message with the number of the error. } else sprintf(feedback , "ok"); //If the authentication was succesfull it sends to the client library an "ok". } //Get else if (strcmp(cmd_str,"GET")==0){ if(p->status_auth == 0 ) { gettable_str=strtok(NULL," "); getkey_str=strtok(NULL," "); if(table_parser(gettable_str) == 0 && key_parser(getkey_str) == 0) { Table* tmp; tmp = find_table(gettable_str,record_tables); if (tmp == NULL) sprintf(feedback , "error %d" , ERR_TABLE_NOT_FOUND); //If it couldn't find the table it sends an error. else { Key* temp; temp = find_key(getkey_str,tmp); if (temp == NULL) sprintf(feedback , "error %d" , ERR_KEY_NOT_FOUND); //If it couldn't find the key it sends an error. else { unsigned char inRec = *(temp->record.metadata); if(p->concurrency == 0) //If there is no concurrency, there is no metada to be compared. inRec = 0; sprintf(feedback , "%d %s", inRec , temp->record.value); } } } else sprintf(feedback , "error %d" , ERR_INVALID_PARAM); } else sprintf(feedback , "error %d" , ERR_NOT_AUTHENTICATED); //If not authenticated it sends an error. } //Set else if (strcmp(cmd_str,"SET")==0){ if(p->status_auth == 0){ settable_str=strtok(NULL," "); setkey_str=strtok(NULL," "); metada = strtok(NULL," "); setrecord_str=strtok(NULL,""); erase_space_ends(setrecord_str); if (table_parser(settable_str) == 0 && key_parser(setkey_str) == 0 && value_parser(setrecord_str) == 0){ struct storage_record value; strcpy(value.value , setrecord_str); Table* tmp; if(p->concurrency == 1){ pthread_mutex_lock(&locker);//mutex lock } tmp = find_table(settable_str,record_tables); if (tmp == NULL) sprintf(feedback , "error %d" , ERR_TABLE_NOT_FOUND); else { //Check the string to see if the columns and values are valid if (checkColumns(tmp, setrecord_str) != 0 && strcmp(setrecord_str , "NULL") != 0) { sprintf(feedback , "error %d" , ERR_INVALID_PARAM); } else { Key* temp; temp = find_key(setkey_str,tmp); if (temp == NULL){ if (strcmp(setrecord_str , "NULL") == 0) sprintf(feedback , "error %d" , ERR_KEY_NOT_FOUND); else { if(tmp->numRec < MAX_RECORDS_PER_TABLE) { add_key(setkey_str, value, tmp); if(p->concurrency == 1) pthread_mutex_unlock(&locker);//unlock strcpy(feedback , "added 1"); //sends back that is adding a new key. } else sprintf(feedback , "error %d" , ERR_UNKNOWN); } } else if (strcmp(setrecord_str , "NULL") == 0){ delete_key(temp,tmp); if(p->concurrency == 1) pthread_mutex_unlock(&locker);//unlock strcpy(feedback , "del"); //sends back that is deleting a key. } else{ unsigned char inRec = *(temp->record.metadata); if(inRec == atoi(metada) || atoi(metada) == 0) { ///If record sent from client has same metada of record from server. strcpy(temp->record.value , value.value); inRec++; *(temp->record.metadata) = inRec; if(p->concurrency == 1) pthread_mutex_unlock(&locker);//unlock sprintf(feedback , "updt %d",inRec); //sends back that is updating a key. } else sprintf(feedback , "error %d" , ERR_TRANSACTION_ABORT); } } } if(p->concurrency == 1) pthread_mutex_unlock(&locker);//unlock in case it wasn't unlocked } else sprintf(feedback , "error %d" , ERR_INVALID_PARAM); //If key or value are invalid parameters it sends an error. } else sprintf(feedback , "error %d" , ERR_NOT_AUTHENTICATED); } ///Query else if(strcmp(cmd_str,"QUE")==0){ if(p->status_auth == 0){ char *table; table = strtok(NULL , " "); Table *temp; temp = find_table(table , record_tables); if(temp != NULL){ char *predicates_line; predicates_line = strtok(NULL,""); ///Copy of the current line that wasn't parsed. strcpy(feedback , query_parsing(temp , predicates_line)); } else ///Table not find sprintf(feedback , "error %d" , ERR_TABLE_NOT_FOUND); } else ///Not authenticated. sprintf(feedback , "error %d" , ERR_NOT_AUTHENTICATED); } if (LOGGING == 1 || LOGGING == 2) logger(log_file , message); gettimeofday(&t2, NULL); elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000000.0; elapsedTime += (t2.tv_sec - t1.tv_sec); //printf("%.5f - Server\n" , elapsedTime); ///Used for measuring the performance. // For now, just send back the command to the client. sendall(sock, feedback, strlen(feedback)); sendall(sock, "\n", 1); return 0; }