int main(int argc, string argv[]) { stream istr, ostr; string itags[MaxBodyFields]; initparam(argv, defv); new_field(&LinkField, IntType, LinkTag); /* use int's worth of space */ new_field(&LinkField + 1, NULL, NULL); layout_body(bodytags, Precision, NDIM); istr = stropen(getparam("in"), "r"); get_history(istr); if (! get_snap(istr, &btab, &nbody, &tnow, itags, TRUE)) error("%s: snapshot input failed\n", getargv0()); if (! set_member(itags, PosTag)) error("%s: %s data missing\n", getargv0(), PosTag); if (getbparam("subkey") && ! set_member(itags, KeyTag)) error("%s: %s data missing\n", getargv0(), KeyTag); findobj(getdparam("bcrit"), getiparam("nmin"), getbparam("subkey")); ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tnow, set_union(itags, set_cons(KeyTag, NULL))); strclose(ostr); return (0); }
bool InputForm::Init() { field = (FIELD **)calloc(choices*2+1, sizeof(FIELD *)); for (int i = 0; i < choices; ++i) { field[2*i] = new_field(1, 30, 4+i*2, 2, 02, 02); field[2*i+1] = new_field(1, 20, 4+i*2, 30, 02, 02); set_field_back(field[2*i+1], A_UNDERLINE); field_opts_off(field[2*i+1], O_AUTOSKIP); set_field_buffer(field[2*i], 0, itemNames[i].c_str()); set_field_back(field[2*i], O_EDIT); } field[choices*2] = NULL; form = new_form(field); scale_form(form, &formRows, &formCols); win = newwin(formRows+8, formCols+20, LINES/2-formRows/2 -6, COLS/2-10-formCols/2); keypad(win, TRUE); set_form_win(form, win); set_form_sub(form, derwin(win, formRows, formCols, 2, 2)); box(win, 0, 0); wattron(win, COLOR_PAIR(1)); mvwprintw(win, 0, formCols/2+8-title.size()/2, "%s", title.c_str()); wattroff(win, COLOR_PAIR(1)); post_form(form); panel = new_panel(win); switchOkCancle(); update_panels(); doupdate(); form_driver(form, REQ_NEXT_FIELD); return true; }
void create_device_name_form(void) { fields[0] = new_field(1, 32, 1, 1, 0, 0); if (!fields[0]) fatal_error("cannot create field"); field_opts_off(fields[0], O_ACTIVE); field_opts_off(fields[0], O_EDIT); set_field_fore(fields[0], attr_textbox); set_field_back(fields[0], attr_textbox); set_field_buffer(fields[0], 0, _("Device name:")); fields[1] = new_field(1, 32, 2, 1, 0, 0); if (!fields[1]) fatal_error("cannot create field"); field_opts_off(fields[1], O_AUTOSKIP); field_opts_off(fields[1], O_NULLOK); field_opts_off(fields[1], O_STATIC); set_field_fore(fields[1], attr_textfield); set_field_back(fields[1], attr_textfield); set_field_buffer(fields[1], 0, mixer_device_name); form = new_form(fields); if (!form) fatal_error("cannot create form"); if (!create()) return; post_form(form); }
int main(int argc, string argv[]) { string prog, itags[MaxBodyFields]; stream xstr, ostr; int nold = -1; initparam(argv, defv); exprs[0] = getparam("group"); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE); xstr = execmap(prog); if (get_tag_ok(xstr, "History")) skip_item(xstr); get_history(xstr); ostr = stropen(getparam("out"), "w"); put_history(ostr); new_field(&GroupField, IntType, "Group"); new_field(&GroupField + 1, NULL, NULL); layout_body(btags, Precision, NDIM); while (get_snap(xstr, &bodytab, &nbody, &tbody, itags, FALSE)) { snaptrak(); put_snap(ostr, &traktab, &ntrak, &tbody, otags); if (ntrak != nold) eprintf("[%s: wrote %d groups at t = %f]\n", getprog(), ntrak, tbody); nold = ntrak; } strclose(ostr); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getprog(), prog); return (0); }
void InitResizeMOSAIC () { resizeWindow = CreateCenteredBoxedTitledWindow (RESIZE_height, RESIZE_width, "RESIZE"); resizePanel = new_panel (resizeWindow); mvwaddstr (resizeWindow, 1, 1, "New height"); mvwaddstr (resizeWindow, 2, 1, "New width"); /* MAKING OF FORM */ FIELD **fields = (FIELD **) malloc (3 * sizeof (FIELD *)); fields[0] = new_field (1, 3, 0, 0, 0, 0); set_field_back (fields[0], A_BOLD); field_opts_off (fields[0], O_PASSOK); set_field_just (fields[0], JUSTIFY_LEFT); set_field_type (fields[0], TYPE_INTEGER, 0, 1, 999); fields[1] = new_field (1, 3, 1, 0, 0, 0); set_field_back (fields[1], A_BOLD); field_opts_off (fields[1], O_PASSOK); set_field_just (fields[1], JUSTIFY_LEFT); set_field_type (fields[1], TYPE_INTEGER, 0, 1, 999); fields[2] = NULL; // the FORM itself, WINDOW and post it! resize_form = new_form (fields); // subwindow: inside the box WINDOW *subwindow = derwin (resizeWindow, 2, 3, 1, 12); set_form_win (resize_form, subwindow); set_form_sub (resize_form, subwindow); post_form (resize_form); touchwin (resizeWindow); }
int main(int argc, string argv[]) { string prog, itags[MaxBodyFields], otags[MaxBodyFields]; stream xstr, ostr; bodyptr btab = NULL; int nbody; real tnow; initparam(argv, defv); exprs[0] = getparam("weight"); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE); xstr = execmap(prog); if (get_tag_ok(xstr, "History")) skip_item(xstr); get_history(xstr); ostr = stropen(getparam("out"), "w"); put_history(ostr); new_field(&WeightField, RealType, "Weight"); new_field(&WeightField + 1, NULL, NULL); while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE)) { snaprect(btab, nbody); del_tag(otags, itags, "Weight"); put_snap(ostr, &btab, &nbody, &tnow, otags); } strclose(ostr); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getargv0(), prog); return (0); }
int main(int argc, char *argv[]) { if(argc != 2) { usage(argv); exit(1); } char *e; size_t L = (int)strtoul(argv[1], &e, 10); if(*e != '\0') { usage(argv); exit(2); } _Complex float *b = new_field(L); _Complex float *x = new_field(L); _Complex float *u = new_links(L); rand_links(L, u); rand_field(L, b); zero_field(L, x); cg(L, x, b, u); free(b); free(x); free(u); return 0; }
/* * add a field to the form */ void wdg_input_add(wdg_t *wo, size_t x, size_t y, const char *caption, char *buf, size_t len, size_t lines) { WDG_WO_EXT(struct wdg_input_handle, ww); ww->nfields += 2; WDG_SAFE_REALLOC(ww->fields, ww->nfields * sizeof(FIELD *)); /* remember the pointer to the real buffer (to be used in consolidate) */ WDG_SAFE_REALLOC(ww->buffers, (ww->nfields/2 + 1) * sizeof(char *)); ww->buffers[ww->nfields/2 - 1] = buf; ww->buffers[ww->nfields/2] = NULL; /* create the caption */ ww->fields[ww->nfields - 2] = new_field(1, strlen(caption), y, x, 0, 0); set_field_buffer(ww->fields[ww->nfields - 2], 0, caption); field_opts_off(ww->fields[ww->nfields - 2], O_ACTIVE); set_field_fore(ww->fields[ww->nfields - 2], COLOR_PAIR(wo->focus_color)); /* and the modifiable field */ ww->fields[ww->nfields - 1] = new_field(lines, len, y, x + strlen(caption) + 2, 0, 0); set_field_back(ww->fields[ww->nfields - 1], A_UNDERLINE); field_opts_off(ww->fields[ww->nfields - 1], O_WRAP); set_field_buffer(ww->fields[ww->nfields - 1], 0, buf); set_field_fore(ww->fields[ww->nfields - 1], COLOR_PAIR(wo->window_color)); /* null terminate the array */ WDG_SAFE_REALLOC(ww->fields, (ww->nfields + 1) * sizeof(FIELD *)); ww->fields[ww->nfields] = NULL; }
/* * Solves lapl(u) x = b, for x, given b, using Conjugate Gradient */ void cg(latparams lp, field **x, field **b, link **g) { size_t L = lp.L; int max_iter = 100; float tol = 1e-9; /* Temporary fields needed for CG */ field **r = new_field(lp); field **p = new_field(lp); field **Ap = new_field(lp); /* Initial residual and p-vector */ lapl(lp, r, x, g); xmy(lp, b, r); xeqy(lp, p, r); /* Initial r-norm and b-norm */ float rr = xdotx(lp, r); float bb = xdotx(lp, b); double t_lapl = 0; int iter = 0; for(iter=0; iter<max_iter; iter++) { printf(" %6d, res = %+e\n", iter, rr/bb); if(sqrt(rr/bb) < tol) break; double t = stop_watch(0); lapl(lp, Ap, p, g); t_lapl += stop_watch(t); float pAp = xdoty(lp, p, Ap); float alpha = rr/pAp; axpy(lp, alpha, p, x); axpy(lp, -alpha, Ap, r); float r1r1 = xdotx(lp, r); float beta = r1r1/rr; xpay(lp, r, beta, p); rr = r1r1; } /* Recompute residual after convergence */ lapl(lp, r, x, g); xmy(lp, b, r); rr = xdotx(lp, r); double beta_fp = 50*((double)L*L*L)/(t_lapl/(double)iter)*1e-9; double beta_io = 40*((double)L*L*L)/(t_lapl/(double)iter)*1e-9; printf(" Converged after %6d iterations, res = %+e\n", iter, rr/bb); printf(" Time in lapl(): %+6.3e sec/call, %4.2e Gflop/s, %4.2e GB/s\n", t_lapl/(double)iter, beta_fp, beta_io); del_field(r); del_field(p); del_field(Ap); return; }
int main(int argc, string argv[]) { string prog, coords, itags[MaxBodyFields], otags[MaxBodyFields]; stream xstr, ostr; bodyptr btab = NULL, bp; int nbody; real tnow; vector cmpos, cmvel, cmacc; initparam(argv, defv); exprs[0] = getparam("weight"); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE); xstr = execmap(prog); if (get_tag_ok(xstr, "History")) skip_item(xstr); get_history(xstr); ostr = stropen(getparam("out"), "w"); put_history(ostr); coords = getparam("coords"); new_field(&WeightField, RealType, "Weight"); new_field(&WeightField + 1, NULL, NULL); while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE, NULL)) { if (scanopt(coords, PosTag) && set_member(itags, PosTag)) { snapcmpos(cmpos, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Pos(bp), Pos(bp), cmpos); } eprintf("[%s: centroid position: %f,%f,%f]\n", getprog(), cmpos[0], cmpos[1], cmpos[2]); } if (scanopt(coords, VelTag) && set_member(itags, VelTag)) { snapcmvel(cmvel, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Vel(bp), Vel(bp), cmvel); } eprintf("[%s: centroid velocity: %f,%f,%f]\n", getprog(), cmvel[0], cmvel[1], cmvel[2]); } if (scanopt(coords, AccTag) && set_member(itags, AccTag)) { snapcmacc(cmacc, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Acc(bp), Acc(bp), cmacc); } eprintf("[%s: cen. acceleration: %f,%f,%f]\n", getprog(), cmacc[0], cmacc[1], cmacc[2]); } del_tag(otags, itags, "Weight"); put_snap(ostr, &btab, &nbody, &tnow, otags); } strclose(ostr); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getprog(), prog); return (0); }
/* * Solves lapl(u) x = b, for x, given b, using Conjugate Gradient */ void cg(size_t L, _Complex float *x, _Complex float *b, _Complex float *u) { int max_iter = 100; float tol = 1e-6; /* Temporary fields needed for CG */ _Complex float *r = new_field(L); _Complex float *p = new_field(L); _Complex float *Ap = new_field(L); /* Initial residual and p-vector */ lapl(L, r, x, u); xmy(L, b, r); xeqy(L, p, r); /* Initial r-norm and b-norm */ float rr = xdotx(L, r); float bb = xdotx(L, b); double t_lapl = 0; int iter = 0; for(iter=0; iter<max_iter; iter++) { printf(" %6d, res = %+e\n", iter, rr/bb); if(sqrt(rr/bb) < tol) break; double t = stop_watch(0); lapl(L, Ap, p, u); t_lapl += stop_watch(t); float pAp = xdoty(L, p, Ap); float alpha = rr/pAp; axpy(L, alpha, p, x); axpy(L, -alpha, Ap, r); float r1r1 = xdotx(L, r); float beta = r1r1/rr; xpay(L, r, beta, p); rr = r1r1; } /* Recompute residual after convergence */ lapl(L, r, x, u); xmy(L, b, r); rr = xdotx(L, r); double beta_fp = 34*L*L/(t_lapl/(double)iter)*1e-9; double beta_io = 32*L*L/(t_lapl/(double)iter)*1e-9; printf(" Converged after %6d iterations, res = %+e\n", iter, rr/bb); printf(" Time in lapl(): %+6.3e sec/call, %4.2e Gflop/s, %4.2e GB/s\n", t_lapl/(double)iter, beta_fp, beta_io); free(r); free(p); free(Ap); return; }
/* * Creates a new field at y, and sets the field's text to str. * Sets the value of pField to point to the new field. */ void ListBox::createField(FIELD **pField, int y, std::string str) { *pField = new_field(1, getWidth() - 2, y, 0, 0, 0); set_field_buffer(*pField, 0, str.data()); set_field_back(*pField, A_NORMAL); field_opts_off(*pField, O_AUTOSKIP); field_opts_on(*pField, O_BLANK); }
/* * Field functions (form_field_new(3x)) */ static VALUE rbncurs_m_new_field(VALUE dummy, VALUE height, VALUE width, VALUE toprow, VALUE leftcol, VALUE offscreen, VALUE nbuffers) { return wrap_field(new_field(NUM2INT(height), NUM2INT(width), NUM2INT(toprow), NUM2INT(leftcol), NUM2INT(offscreen), NUM2INT(nbuffers))); }
/** * etchtype_get_field_by_name() * works as in the java binding, in that if the type does not include * a field with that name, a new field is created and added to the type. * @return a non-disposable reference to the requested field, or null */ etch_field* etchtype_get_field_by_name (etch_type* type, const wchar_t* name) { etch_type_impl* impl = (etch_type_impl*) type->impl; etch_field* field = etchtype_get_key_by_name(impl->fieldmap, name); if (NULL == field) field = etchtype_add_field (type, new_field(name)); return field; }
EIGEN_MAKE_ALIGNED_OPERATOR_NEW inline SignedDistanceField(std::string frame, double resolution, double x_size, double y_size, double z_size, float OOB_value) : initialized_(true), locked_(false) { frame_ = frame; VoxelGrid::VoxelGrid<float> new_field(resolution, x_size, y_size, z_size, OOB_value); distance_field_ = new_field; }
static void fields(node_t * sym) { int follow[] = {INT, CONST, '}', IF, 0}; node_t *sty = SYM_TYPE(sym); if (!first_decl(token)) { error("expect type name or qualifiers"); return; } struct vector *v = vec_new(); do { node_t *basety = specifiers(NULL, NULL); for (;;) { node_t *field = new_field(); if (token->id == ':') { bitfield(field); FIELD_TYPE(field) = basety; } else { node_t *ty = NULL; struct token *id = NULL; declarator(&ty, &id, NULL); attach_type(&ty, basety); if (token->id == ':') bitfield(field); FIELD_TYPE(field) = ty; if (id) { for (int i = 0; i < vec_len(v); i++) { node_t *f = vec_at(v, i); if (FIELD_NAME(f) && !strcmp(FIELD_NAME(f), id->name)) { errorf(id->src, "redefinition of '%s'", id->name); break; } } FIELD_NAME(field) = id->name; AST_SRC(field) = id->src; } } vec_push(v, field); if (token->id != ',') break; expect(','); ensure_field(field, vec_len(v), false); } match(';', follow); ensure_field(vec_tail(v), vec_len(v), isstruct(sty) && !first_decl(token)); } while (first_decl(token)); TYPE_FIELDS(sty) = (node_t **) vtoa(v); set_typesize(sty); }
int main(int argc, char *argv[]) { if(argc != 4) { usage(argv); exit(1); } char *e; size_t L = (int)strtoul(argv[1], &e, 10); if(*e != '\0') { usage(argv); exit(2); } size_t Sy = (int)strtoul(argv[2], &e, 10); if(*e != '\0') { usage(argv); exit(2); } size_t Sx = (int)strtoul(argv[3], &e, 10); if(*e != '\0') { usage(argv); exit(2); } latparams lp = init_latparams(L, Sy, Sx); field **b = new_field(lp); field **x = new_field(lp); link **g = new_links(lp); rand_links(lp, g); rand_field(lp, b); zero_field(lp, x); cg(lp, x, b, g); del_field(b); del_field(x); del_links(g); return 0; }
void init_term_gui(void) { /* Fix ESC key */ set_escdelay(25); initscr(); start_color(); cbreak(); noecho(); if (can_change_color()) { init_color(XS_COLOR_BLUE, 43, 180, 349); init_color(XS_COLOR_RED, 886, 27, 124); init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, XS_COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, XS_COLOR_BLUE); } else{ init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, COLOR_BLUE); } /* int max_rows; */ /* int max_cols; */ /* getmaxyx(stdscr, max_rows, max_cols); */ show_recent_apps(); prepare_for_new_results(False); mvprintw(0, 0, "$"); mvwprintw(window, MAX_Y - 2, 0, "Loading paths..."); refresh(); field[0] = new_field( 1, // columns 20, // width 0, // pos y 2, // pos x 0, 0 ); /* Hide cursor */ curs_set(0); set_field_fore(field[0], COLOR_PAIR(XS_COLOR_PAIR_2)); field[1] = NULL; form = new_form(field); post_form(form); wrefresh(window); }
static FIELD * make_label(int frow, int fcol, NCURSES_CONST char *label) { FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0); if (f) { set_field_buffer(f, 0, label); set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE)); } return (f); }
field<C,R> get_section_impl(uint32_t from, uint32_t to, uint32_t upper, uint32_t lower) { assert(C == to - from + 1 && R == lower - upper + 1); is_vec new_field(C * R); for (uint32_t i = 0; i < R; ++i) { std::copy(this->begin() + (from + i * Columns), this->begin() + (to + i * Columns) + 1, std::begin(new_field) + (i * C)); } return field<C, R>{std::move(new_field)}; }
/* * Create a field and fill the buffer with the string representation of val. * This field can be visited by the cursor, it also dynamicaly resize (in buffer * length). * @param longest_key_len What is the longest length of a label field, this * information is used to place the field on the x axis * @param val The json object representation to print in the field buffer */ static FIELD* render_field(int longest_key_len, struct json_object *val) { FIELD *result; result = new_field(1, 30, cur_y, longest_key_len, 0, 0); if (result) { field_opts_off(result, O_AUTOSKIP); field_opts_off(result, O_STATIC); set_field_buffer(result, 0, json_object_get_string(val)); } return result; }
/* * Create a field and fill the buffer with label_str. This field cannot be * modified nor visited by the cursor. * @param longest_key_len What is the longest length of a label field, this * information is used to place the field on the x axis * @param label_str The string to fill the label buffer with */ static FIELD* render_label(int longest_key_len, const char *label_str) { FIELD *result; result = new_field(1, longest_key_len-4, cur_y, cur_x, 0, 0); if (result) { field_opts_on(result, O_VISIBLE); field_opts_off(result, O_EDIT); field_opts_off(result, O_ACTIVE); set_field_buffer(result, 0, label_str); } return result; }
int main() { FIELD *f1[2]; FORM *frm1; chtype ch; int error; HOOK fptr=getbuf; initscr(); f1[0]=new_field(24,80,0,0,1,1); assert(f1[0]!=NULL); f1[1]=NULL; frm1=new_form(f1); assert(frm1!=NULL); set_field_fore(f1[0],A_REVERSE); field_opts_off(f1[0],O_STATIC); //set_field_buffer(f1[0],0,"Sajid"); set_field_type(f1[0],TYPE_ALPHA,80); set_field_term(f1[0],fptr); post_form(frm1); wrefresh(stdscr); keypad(stdscr,TRUE); while((ch=getch())!=KEY_F(3)) { switch(ch) { case KEY_LEFT: error=form_driver(frm1,REQ_PREV_CHAR); if(error==E_REQUEST_DENIED) form_driver(frm1,REQ_SCR_BCHAR); break; case KEY_RIGHT: form_driver(frm1,REQ_NEXT_CHAR); break; default: form_driver(frm1,ch); break; } } unpost_form(frm1); free_form(frm1); free_field(f1[0]); getch(); printw(ptr); endwin(); }
/* * Define each field with an extra one, for reflecting "actual" text. */ static FIELD * make_field(int frow, int fcol, int rows, int cols) { FIELD *f = new_field(rows, cols, frow, fcol, o_value, 1); if (f) { FieldAttrs *ptr; set_field_back(f, A_UNDERLINE); /* * If -j and -d options are combined, -j loses. It is documented in * "Character User Interface Programming", page 12-15 that setting * O_STATIC off makes the form library ignore justification. */ set_field_just(f, j_value); if (d_option) { if (has_colors()) { set_field_fore(f, (chtype) COLOR_PAIR(2)); set_field_back(f, A_UNDERLINE | COLOR_PAIR(3)); } else { set_field_fore(f, A_BOLD); } /* * The field_opts_off() call dumps core with Solaris curses, * but that is a known bug in Solaris' form library -TD */ field_opts_off(f, O_STATIC); set_max_field(f, m_value); } /* * The userptr is used in edit_field.c's inactive_field(). */ ptr = (FieldAttrs *) field_userptr(f); if (ptr == 0) { ptr = typeCalloc(FieldAttrs, 1); ptr->background = field_back(f); } set_field_userptr(f, (void *) ptr); if (t_value) set_field_buffer(f, 0, t_value); } return (f); }
LIB_FIELD& DIALOG_SPICE_MODEL::getLibField( int aFieldType ) { const wxString& spiceField = NETLIST_EXPORTER_PSPICE::GetSpiceFieldName( (SPICE_FIELD) aFieldType ); auto fieldIt = std::find_if( m_libfields->begin(), m_libfields->end(), [&]( const LIB_FIELD& f ) { return f.GetName() == spiceField; } ); // Found one, so return it if( fieldIt != m_libfields->end() ) return *fieldIt; // Create a new field with requested name LIB_FIELD new_field( m_libfields->size() ); m_libfields->front().Copy( &new_field ); new_field.SetName( spiceField ); m_libfields->push_back( new_field ); return m_libfields->back(); }
void create_input_form() { delete_input_form(); keypad(input_window, TRUE); url_field[0] = new_field(1, input_cols - (FIELD_START + 1), 0, 0, 0, 0); url_field[1] = NULL; set_field_back(url_field[0], A_REVERSE); field_opts_off(url_field[0], O_AUTOSKIP); field_opts_off(url_field[0], O_STATIC); set_max_field(url_field[0], FIELD_BUF_SIZE); url_form = new_form(url_field); set_form_win(url_form, input_window); set_form_sub(url_form, derwin(input_window, 1, input_cols - (FIELD_START + 1), 0, FIELD_START)); post_form(url_form); wrefresh(input_window); }
static void brsh_init(void) { /* handle window resize */ signal(SIGWINCH, &resized_); /* initalize curses */ initscr(); cbreak(); noecho(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); /* enable cursor keys and others */ /* create the output window */ win_output = newwin(LINES - g_brsh_input_display_lines - 1, COLS, 0, 0); scrollok(win_output, TRUE); /* create the input field */ fld_input = new_field(g_brsh_input_display_lines, COLS, LINES - g_brsh_input_display_lines, 0, g_brsh_input_maximum_lines - g_brsh_input_display_lines, 1); static FIELD *fields[2] = { NULL, NULL }; /* not sure if it needs this to hang around or not, so we'll make it static anyway */ fields[0] = fld_input; frm_input = new_form(fields); post_form(frm_input); /* draw a line */ move(LINES - g_brsh_input_display_lines - 1, 0); for (int i = 0; i < COLS; i++) addch(ACS_HLINE); if (g_brsh_show_instructions) mvprintw(LINES - g_brsh_input_display_lines - 1, COLS - 15, " F1 = Help "); refresh(); move(LINES - g_brsh_input_display_lines, 0); /* post welcome banner */ brsh_print(BRSH_NAME " " BRSH_VERSION "\n"); }
void game_init(SDL_Surface *screen) { init_genrand(time(0)); f = new_field(10, 20); rs = get_ars_rotation_system(); memset(key_time, 0, sizeof(int[8])); if(f == NULL) exit(-1); block_color[0x00] = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); block_color[0x01] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0x00); block_color[0x02] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0xFF); block_color[0x03] = SDL_MapRGB(screen->format, 0xFF, 0x80, 0x00); block_color[0x04] = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF); block_color[0x05] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0xFF); block_color[0x06] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00); block_color[0x07] = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0x00); block_color[0xFE] = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF); block_color[0xFF] = SDL_MapRGB(screen->format, 0x40, 0x40, 0x40); pieces[0] = &rs->I; pieces[1] = &rs->T; pieces[2] = &rs->L; pieces[3] = &rs->J; pieces[4] = &rs->S; pieces[5] = &rs->Z; pieces[6] = &rs->O; history[0] = 4; history[1] = 5; history[2] = 4; history[3] = 5; next_piece = pieces[genrand_int31()%4]; game_next_piece(); }
int main(int argc, char *argv[]) { // Initial values WINDOW *title_win; // Title window pointer FORM *title_form; int row, col; // Start screen initscr(); clear(); noecho(); cbreak(); if (has_colors() == TRUE) // Test if terminal has color start_color(); getmaxyx(stdscr, row, col); // Check if terminal is a proper size if (row < MIN_HEIGHT || col < MIN_WIDTH) { char term_size_err1[] = "Your terminal is too small!"; char term_size_err2[] = "Resize and try again."; mvprintw(row / 2 - 1, (col - strlen(term_size_err1)) / 2, "%s", term_size_err1); mvprintw(row / 2 , (col - strlen(term_size_err2)) / 2, "%s", term_size_err2); getch(); endwin(); return 0; } // Header header(col); // Staffs staff(row, col); refresh(); // Title Window int startx = (col - TITLE_WINDOW_WIDTH) / 2; int starty = (row - TITLE_WINDOW_HEIGHT) / 2; title_win = title_info_win(TITLE_WINDOW_HEIGHT, TITLE_WINDOW_WIDTH, starty, startx); keypad(title_win, true); int x_mins[8] = { WIN_X_BUFFER + strlen("Project Title: "), WIN_X_BUFFER + strlen("Song Title: "), WIN_X_BUFFER + strlen("Artist: "), WIN_X_BUFFER + strlen("Tabbed by: "), WIN_X_BUFFER + strlen("Email: "), WIN_X_BUFFER + strlen("Number of Strings: "), WIN_X_BUFFER + strlen("Tuning: (1)"), TITLE_WINDOW_WIDTH - WIN_X_BUFFER - strlen("OK") - strlen("CANCEL") - 9, }; /* Input fields for windows */ fields[0] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[0] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER , x_mins[0], 0, 0); fields[1] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[1] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 4 , x_mins[1], 0, 0); fields[2] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[2] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 6 , x_mins[2], 0, 0); fields[3] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[3] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 8 , x_mins[3], 0, 0); fields[4] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[4] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 10, x_mins[4], 0, 0); fields[5] = new_field(1, 1 , WIN_Y_BUFFER + WIN_HEADER + 14, x_mins[5], 0, 0); int i; for (i = 0; i < strings; i++) fields[6 + i] = new_field(1, 2, WIN_Y_BUFFER + WIN_HEADER + 16, x_mins[6] + i * 6, 0, 0); for (i = 0; i < 8 - strings; i++) fields[6 + strings + i] = NULL; for (i = 0; i < 12; i++) { // Needs to be able to change with string change set_field_back(fields[i], A_UNDERLINE); field_opts_off(fields[i], O_AUTOSKIP); } /* Create the title window form */ set_form_win(title_form, title_win); title_form = new_form(fields); post_form(title_form); refresh(); int movements[8][2] = { {WIN_Y_BUFFER + WIN_HEADER , x_mins[0]}, {WIN_Y_BUFFER + WIN_HEADER + 4 , x_mins[1]}, {WIN_Y_BUFFER + WIN_HEADER + 6 , x_mins[2]}, {WIN_Y_BUFFER + WIN_HEADER + 8 , x_mins[3]}, {WIN_Y_BUFFER + WIN_HEADER + 10 , x_mins[4]}, {WIN_Y_BUFFER + WIN_HEADER + 14 , x_mins[5]}, {WIN_Y_BUFFER + WIN_HEADER + 16 , x_mins[6]}, {WIN_Y_BUFFER + WIN_HEADER + 20 , x_mins[7]}, }; int y, x; wmove(title_win, movements[0][0], movements[0][1]); wrefresh(title_win); while (true) { ch = wgetch(title_win); getyx(title_win, y, x); if (ch == KEY_UP) { if (y == movements[7][0]) move(movements[6][0], movements[6][1]); else if (y == movements[6][0] && x == movements[6][1]) { form_driver(title_form, REQ_PREV_FIELD); form_driver(title_form, REQ_END_LINE); } else if (y != movements[7][0] && y != movements[6][0]){ form_driver(title_form, REQ_PREV_FIELD); form_driver(title_form, REQ_END_LINE); } } else if (ch == KEY_DOWN) { if (y == movements[6][0]) move(movements[7][0], movements[7][1]); else if (y != movements[7][0] && y != movements[6][0]){ form_driver(title_form, REQ_NEXT_FIELD); form_driver(title_form, REQ_END_LINE); } } else if (ch == KEY_LEFT) { if (y == movements[6][0]) { form_driver(title_form, REQ_PREV_FIELD); form_driver(title_form, REQ_END_LINE); } else if (y == movements[7][0] && x == (movements[7][1] + BUTTON_WIDTH)){ // Is at CANCEL button move(movements[7][0], movements[7][1]); } } else if (ch == KEY_RIGHT) { if (y == movements[6][0]) { form_driver(title_form, REQ_NEXT_FIELD); form_driver(title_form, REQ_END_LINE); } else if (y == movements[7][0] && x == movements[7][1]) { // Is at OK button move(movements[7][0], movements[7][1] + BUTTON_WIDTH); } } else if (ch == '\n' && y == movements[7][0]) { if (x == movements[7][1]) { // OK continue; } else { // CANCEL clear(); endwin(); break; } /* ch is a letter, number or special char */ } else if (((ch >= 'a'&& ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch >= 33 && ch <= 46) || ch == ' ' || ch == 64)) { form_driver(title_form, ch); } } getch(); destroy_win(title_win); clear(); refresh(); getch(); endwin(); return 0; }
int kullanici_onayla() { FIELD *field[3]; FORM *my_form; int ch; touchwin(ana_win); wrefresh(ana_win); init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_WHITE, COLOR_BLUE); /*calisma yili 4 karakter*/ field[0] = new_field(1, 10, 18, 42, 0, 0); /*firma 2 karakter*/ field[1] = new_field(1, 10, 20, 42, 0, 0); field[2] = NULL; set_field_fore(field[0], COLOR_PAIR(1)); set_field_fore(field[1], COLOR_PAIR(1)); /*geri plan rengi olsun*/ set_field_back(field[0], COLOR_PAIR(2)); set_field_back(field[1], COLOR_PAIR(2)); /* set_field_type(field[0], TYPE_INTEGER); set_field_type(field[1], TYPE_INTEGER); */ field_opts_off(field[0], O_AUTOSKIP); field_opts_off(field[1], O_AUTOSKIP); /*sifre alani olan ikinci field password biçiminde olmali/ field_opts_off(field[1], O_PUBLIC); /*geri plan rengi olmasin*/ /* set_field_back(field[0], A_UNDERLINE); set_field_back(field[1], A_UNDERLINE); */ my_form = new_form(field); post_form(my_form); refresh(); set_current_field(my_form, field[0]); mvprintw(18, 25, _("User name :") ); mvprintw(20, 25, _("Password :"******"This application under GPL license.") ); attroff(A_BLINK); attroff(A_BOLD); attron(A_BOLD); mvprintw(LINES-3, 5, _("F2-> Begin ESC-> Cancel") ); mvprintw(18, 5, _("F5-> Settings") ); attroff(A_BOLD); mvprintw(7,3, _(" Acik ")); mvprintw(8,3," _| _| _| "); mvprintw(9,3," _|_|_| _| _|_| _|_|_|_| _|_|_| _|_| _|_| "); mvprintw(10,3," _| _|_| _| _|_|_|_| _| _| _| _| _|_|_|_| "); mvprintw(11,3," _| _|_| _| _| _| _| _| _| _| "); mvprintw(12,3," _| _|_|_| _| _|_|_| _|_| _| _| _| _|_|_| "); refresh(); while((ch = getch()) ) { switch(ch) { case 8: /*KEY_BACKSPACE hatali kod vermekte 8 dogru olandir konsolda 8 xterm key_backspace*/ form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case KEY_BACKSPACE: form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case 9: /*TAB tusuna basýlmasý durumunda sonraki field konumlan*/ form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case 10: /*ENTER tuþuna basýlmasý durumunda sonraki feild gececek*/ form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_DC: /*del tusu*/ form_driver(my_form,REQ_DEL_CHAR); break; case KEY_HOME: form_driver(my_form,REQ_BEG_LINE); break; case KEY_END: form_driver(my_form,REQ_END_LINE); break; case KEY_DOWN: form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_LEFT: form_driver(my_form,REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form,REQ_RIGHT_CHAR); break; case 27: /*esc durumunda*/ unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); endwin(); exit(0); break; case KEY_F(5): /*ayarlara gecis*/ ayarlar(); unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); endwin(); exit (0); break; case KEY_F(2): /*f2 durumunda*/ form_driver(my_form, REQ_PREV_FIELD); strcpy(query, "select kullanici, sifre, haklar from kullanicilar"); if ( pgsql_sorgula(query) ==1 ) { mesaj(sql_sorgulama_hatasi); return 1;} for (i=0;i<pgsql_row_miktar;i++) { sprintf(kullanici,"%s", pgsql_kayit_field() ); sprintf(sifre,"%s", pgsql_kayit_field() ); sprintf(haklar,"%s", pgsql_kayit_field() ); if ( strcmp(g_strstrip(field_buffer(field[0],0)), kullanici) ==NULL ) { if ( (sifre_kripto_coz( g_strstrip(field_buffer(field[1],0)) , sifre) == 0) || (strcmp(g_strstrip(field_buffer(field[1],0)), sifre) == NULL ) ) { //kullanýcý root ise haklar full olmalý //databaseden degistirme ihtimali olabilir if ( strstr( kullanici, "root") ) {sprintf(haklar,"%s", "1111111111111111111111111111111111111111111111111111111111111111");} beep(); unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); touchwin(ana_win); wrefresh(ana_win); return; } else { set_field_buffer(field[0],0," "); set_field_buffer(field[1],0," "); refresh(); //beep sesi beep(); } } } break; default: form_driver(my_form, ch); break; } } return 0; /*son*/ }