static int select_list(expression_type parent_type, struct selection *selection, const freesasa_structure *structure, const expression *expr) { int resr, resl; expression *left, *right; if (expr == NULL) return fail_msg("NULL expression"); left = expr->left; right = expr->right; switch(expr->type) { case E_PLUS: if (left == NULL || right == NULL) return fail_msg("NULL expression"); resl = select_list(parent_type, selection, structure, left); resr = select_list(parent_type, selection, structure, right); if (resl == FREESASA_WARN || resr == FREESASA_WARN) return FREESASA_WARN; break; case E_RANGE: if (left == NULL || right == NULL) return fail_msg("NULL expression"); return select_range(E_RANGE, parent_type, selection, structure, left, right); case E_RANGE_OPEN_L: if (left != NULL || right == NULL) return fail_msg("NULL expression"); return select_range(E_RANGE_OPEN_L, parent_type, selection, structure, left, right); case E_RANGE_OPEN_R: if (left == NULL || right != NULL) return fail_msg("NULL expression"); return select_range(E_RANGE_OPEN_R, parent_type, selection, structure, left, right); case E_ID: case E_NUMBER: if (is_valid_id(parent_type, expr) == FREESASA_SUCCESS) select_id(parent_type, selection, structure, expr->value); else return freesasa_warn("select: %s: '%s' invalid %s", e_str(parent_type), expr->value, e_str(expr->type)); break; default: return freesasa_fail("select: parse error (expression: '%s %s')", e_str(parent_type), e_str(expr->type)); } return FREESASA_SUCCESS; }
/* If yesToAll and/or noToAll are NULL, then those prompts not displayed */ int select_yn (char *prompt, char *yes, char *no, char *yesToAll, char *noToAll) { int len; int ret; int xPrompt; int listSize; char *yesno[4]; char screenbuf[512]; /* fill in yes/no/yestoall/notoall struct & get its size */ listSize = 2; yesno[0] = yes; yesno[1] = no; if (yesToAll != NULL) { yesno[listSize] = yesToAll; listSize++; } if (noToAll != NULL) { yesno[listSize] = noToAll; listSize++; } /* Draw a box */ len = strlen (prompt); xord = 40 - (len / 2) - 1; if (xord < 1) { xord = 1; } xord1 = xord + len + 1; if (xord1 > 80) { xord1 = 80; } gettext(xord, 22-listSize, xord1 + 1, 25, screenbuf); /* at 20 for yes/no, 19 for yes/no/yestoall or yes/no/notoall, 18 for all 4 */ box (xord, 22-listSize, xord1, 25); /* Display the prompt, and do the y/n selection */ gotoxy (xord + 1, 23-listSize); cputs (prompt); gotoxy (35, 24-listSize); ret = select_list (listSize, yesno); puttext(xord, 22-listSize, xord1 + 1, 25, screenbuf); return (ret); }
void Parser::query_stmt() { match("SELECT"); select_list(); match("FROM"); match("ID"); where_clause(); match(";"); }
const Query &query_stmt() { if (lookahead == SELECT) { // query_stmt -> SELECT select_list FROM id where_clause SEMICOLON vector<string> columns; match(SELECT); select_list(columns); match(FROM); string table_id = id(); Expr where = where_clause(); match(SEMICOLON); return Query(table_id, columns, where); } else { throw ParseError("Syntax error"); } }
void Parser::select_stmt(string id) { match(SELECT); select_list(); match(FROM); from_list(); //TODO SELECT vector<Column> cols; vector<string> names; map<string, string>::iterator it; for (it = aliass.begin(); it != aliass.end(); it++) { names.push_back(it->first); string view = from_lists[select_lists[it->second]]; cols.push_back(views[view].getColumn(it->second)); } views[id].select(cols, names); }
void ft_which_key(char *k, t_list **list, t_env *envir) { if (*(int*)k == 27) { restore_term(envir); exit(EXIT_SUCCESS); } else if (*(int*)k == 10) ft_enter(list, envir); else if (ft_strcmp(k, tgetstr("ku", NULL)) == 0) { ft_dprintf(ENT, "%s\n", k); move_curse(*list, 1); } else if (ft_strcmp(k, tgetstr("kd", NULL)) == 0) move_curse(*list, 0); else if (ft_strcmp(k, " ") == 0) select_list(*list); else if ((ft_strcmp(k, "\177") == 0) || *(int*)k == 2117294875) ft_del(list); }
int *is_space(t_list *list, int *index, int *coords) { select_list(list, index[0]); if (index[0] == index[3]) { index[0] = 1; index[1] = 1; index[2] = 1; } else { if (index[1] == coords[2] - 2) { index[2]++; index[1] = 1; } else index[1]++; index[0]++; } coords = print_list(list, index[0]); return (coords); }
/* Called recursively, the selection is built as we cover the expression tree */ static int select_atoms(struct selection* selection, const expression *expr, const freesasa_structure *structure) { int warn = 0, err = 0, n, ret; struct selection *sl, *sr; assert(selection); assert(structure); n = selection->size; /* this should only happen if memory allocation failed during parsing */ if (expr == NULL) return fail_msg("NULL expression"); switch (expr->type) { case E_SELECTION: assert(expr->value != NULL); selection->name = expr->value; return select_atoms(selection,expr->left,structure); break; case E_SYMBOL: case E_NAME: case E_RESN: case E_RESI: case E_CHAIN: return select_list(expr->type,selection,structure,expr->left); break; case E_AND: case E_OR: { sl = selection_new(n); sr = selection_new(n); if (sl != NULL && sr != NULL) { if ((ret = select_atoms(sl,expr->left,structure))) { if (ret == FREESASA_WARN) ++warn; if (ret == FREESASA_FAIL) ++err; } if ((ret = select_atoms(sr,expr->right,structure))) { if (ret == FREESASA_WARN) ++warn; if (ret == FREESASA_FAIL) ++err; } selection_join(selection,sl,sr,expr->type); } else { ++err; } selection_free(sl); selection_free(sr); if (err) return fail_msg("error joining selections"); break; } case E_NOT: { ret = select_atoms(selection,expr->right,structure); if (ret == FREESASA_WARN) ++warn; if (ret == FREESASA_FAIL) return FREESASA_FAIL; if (selection_not(selection)) return FREESASA_FAIL; break; } case E_ID: case E_NUMBER: case E_PLUS: case E_RANGE: /* these four are handled by the RESN,SYMBOL,ETC */ default: return fail_msg("parser error"); } if (warn) return FREESASA_WARN; return FREESASA_SUCCESS; }