void load_level(int lvl_nb) { char fname[100]; FILE *lev; unsigned iLin, iCol, x, y; char c; sprintf(fname, PATH"lvls/level-%d.lvl", lvl_nb); lev = fopen(fname, "r"); if(lev == NULL) { printf("Cannot open %s\n", fname); fflush(stdout); quit_stuff(); } for(iCol = 0; iCol < MAX_HEI; iCol++) { for(iLin = 0; iLin < MAX_LEN; iLin++) { c = getc(lev); if(c == '#') ground[iCol][iLin] = WALL; else ground[iCol][iLin] = GROUND; } getc(lev); /* This should be a \n */ } find_empty(&x, &y); ground[x][y] = BONUS; timeout[x][y] = rnd_max(45) + 5; find_empty(&x, &y); ground[x][y] = MALUS; timeout[x][y] = rnd_max(45) + 5; find_empty(&x, &y); ground[x][y] = MALUS; timeout[x][y] = rnd_max(45) + 5; find_empty(&x, &y); ground[x][y] = MALUS; timeout[x][y] = rnd_max(45) + 5; fclose(lev); free_snake(); /* Then the snake */ snake = malloc(sizeof(Snake)); snake->x = 9; snake->y = 13; snake->next = NULL; add_head(10, 13); add_head(11, 13); add_head(12, 13); add_head(13, 13); }
//初始化 snake_body *init_snake(int x,int y,int node_size) { snake_body *snake = (snake_body*)malloc(sizeof(snake_body)); snake->head = NULL; snake->tail = NULL; snake->node_size = node_size; snake->x = x; snake->y = y; snake->length = 0; snake->direction = DOWN; add_head(snake,DOWN); add_head(snake,DOWN); add_head(snake,DOWN); return snake; }
static void olock_free(resource *r) { struct object_lock *q, *l = (struct object_lock *) r; node *n; DBG("olock: Freeing %p\n", l); switch (l->state) { case OLOCK_STATE_FREE: break; case OLOCK_STATE_LOCKED: case OLOCK_STATE_EVENT: rem_node(&l->n); n = HEAD(l->waiters); if (n->next) { DBG("olock: -> %p becomes locked\n", n); q = SKIP_BACK(struct object_lock, n, n); rem_node(n); add_tail_list(&q->waiters, &l->waiters); q->state = OLOCK_STATE_EVENT; add_head(&olock_list, n); ev_schedule(olock_event); } break; case OLOCK_STATE_WAITING: rem_node(&l->n); break; default: ASSERT(0); }
struct key_suscription *get_suscription(int sender_id, int console) { CPOSITION it; struct key_suscription *s; it = get_head_position(&t[console].suscribers); while(it != NULL) { s = (struct key_suscription *)get_next(&it); if(s->taskid == sender_id) return s; } s = (struct key_suscription *)malloc(sizeof(struct key_suscription)); if(s == NULL) return NULL; s->susc = 0; s->taskid = sender_id; s->port = 0; add_head(&t[console].suscribers, s); return s; }
/* No params, just use curDir */ void move() { int nx, ny; switch (curDir) { case RIGHT: nx = snake->x+1; ny = snake->y; break; case LEFT: nx = ((int)(snake->x))-1; ny = snake->y; break; case UP: nx = snake->x; ny = ((int)(snake->y))-1; break; case DOWN: nx = snake->x; ny = snake->y+1; break; } if(nx < 0) nx = MAX_LEN; if(nx > MAX_LEN) nx = 0; if(ny < 0) ny = MAX_HEI; if(ny > MAX_HEI) ny = 0; add_head(nx, ny); check_collisions(); if(!no_pop) pop_tail(); else no_pop--; }
//移动 void move(snake_body *snake) { //添头 add_head(snake,snake->direction); //去尾 delete_tail(snake); }
void klist_add_head(struct klist_node * n, struct klist * k) { #if defined(__VMKLNX__) VMK_ASSERT(vmk_PreemptionIsEnabled() == VMK_FALSE); #endif klist_node_init(k, n); add_head(k, n); }
int main(int argc, char** argv) { LinkedList tmp_ll = init_linkedlist(); tmp_ll = add_head(tmp_ll, 14); tmp_ll = add_head(tmp_ll, 17); print_linkedlist(tmp_ll); /* tmp_ll = add_head(tmp_ll, 13); tmp_ll = add_head(tmp_ll, 14); tmp_ll = remove_head(tmp_ll); tmp_ll = add_tail(tmp_ll, 17); tmp_ll = remove_tail(tmp_ll);*/ tmp_ll = empty_linkedlist(tmp_ll); print_linkedlist(tmp_ll); return EXIT_SUCCESS; }
void pad(node **head, unsigned pad_count) { while(pad_count) { add_head(head, 0); pad_count--; } }
static struct queue_buffer_s* allocate_buffer_space_front(struct queue_buffer *qb) { if (qb->unused_head != NULL) { struct queue_buffer_s *buf = qb->unused_head; qb->unused_head = qb->unused_head->next; add_head(&qb->used_head, buf); return buf; } return NULL; }
int SList::add_unique( const char *data ) { Node *q = find( data ); if( q == NULL ) { // No node with this data exists yet. // Add it. add_head( data ); return 1; } return 0; }
void queue_buffer_pop_front(struct queue_buffer* qb, void* item_out) { struct queue_buffer_s *i = qb->used_head; ASSERT(i != NULL); if (item_out != NULL) { memcpy(item_out, i->data, qb->buffer_size); } qb->used_head = i->next; add_head(&qb->unused_head, i); --qb->queue_size; }
buffer *new_buffer(void) { buffer *b = alloc_buffer(cur_buffer); if (b) { clear_buffer(b); if (cur_buffer) add(&b->b_node, &cur_buffer->b_node); else add_head(&buffers, &b->b_node); cur_buffer = b; } return b; }
int sum_carry(node **h3, node *h1, node *h2) { int cp = 0, s = 0, c =0; if(!h1 || !h2) return 0; cp = sum_carry(h3, h1->next, h2->next); s = cp + h1->data + h2->data; c = s/10; s = s%10; add_head(h3, s); return c; }
line_desc *alloc_line_desc(buffer * const b) { block_signals(); line_desc_pool *ldp; for(ldp = (line_desc_pool *)b->line_desc_pool_list.head; ldp->ldp_node.next; ldp = (line_desc_pool *)ldp->ldp_node.next) { assert_line_desc_pool(ldp); if (ldp->free_list.head->next) { line_desc * const ld = (line_desc *)ldp->free_list.head; rem(&ld->ld_node); if (!ldp->free_list.head->next) { rem(&ldp->ldp_node); add_tail(&b->line_desc_pool_list, &ldp->ldp_node); } ldp->allocated_items++; ld->line = NULL; ld->line_len = 0; if (do_syntax) ld->highlight_state.state = -1; release_signals(); return ld; } } /* No chances, all pools are full. Let's allocate a new one, using the standard pool size, and let's put it at the start of the list, so that it is always scanned first. */ if (ldp = alloc_line_desc_pool(0)) { add_head(&b->line_desc_pool_list, &ldp->ldp_node); line_desc * const ld = (line_desc *)ldp->free_list.head; rem(&ld->ld_node); ldp->allocated_items = 1; if (do_syntax) ld->highlight_state.state = -1; release_signals(); return ld; } release_signals(); return NULL; }
int main(int argc, char **argv) { t_lists lists; int i; i = 1; if (argc == 1) { ft_putendl("non"); return (0); } while (argv[i++]) lists = add_head(&lists, argv[i]); lists = add_end(&lists, "end list"); print_list(&lists); return (0); }
void queue_buffer_free(struct queue_buffer* qb, void* item) { struct queue_buffer_s *prev = NULL; struct queue_buffer_s *i = qb->used_head; for(; i != NULL; i = i->next) { if ( i->data == item ){ if (prev == NULL) { qb->used_head = qb->used_head->next; } else { prev->next = i->next; } add_head(&qb->unused_head, i); --qb->queue_size; return; } prev = i; } /* should never happen */ ASSERT(0); }
node * sum_fw() { int count_h1, count_h2; node *h3 = NULL; int c; // count H1 and H2 count_h1 = count(H1); count_h2 = count(H2); if(count_h1 > count_h2) pad(&H2, count_h1 - count_h2); else if (count_h2 > count_h1) pad(&H1, count_h2-count_h1); c = sum_carry(&h3, H1, H2); if (c) add_head(&h3, c); return h3; }
void clear_buffer(buffer * const b) { if (!b) return; block_signals(); free_buffer_contents(b); line_desc * const ld = alloc_line_desc(b); add_head(&b->line_desc_list, &ld->ld_node); if (do_syntax) { ld->highlight_state.state = 0; ld->highlight_state.stack = NULL; ld->highlight_state.saved_s[0] = 0; } b->num_lines = 1; reset_position_to_sof(b); assert_buffer(b); release_signals(); }
//--------------------------------------------------------------------------------------- void TableLayouter::layout_in_box() { LOMSE_LOG_DEBUG(Logger::k_layout, string("")); //AWARE: This method is invoked to layout a page. If there are more pages to //layout, it will be invoked more times. Therefore, this method must not initialize //anything. All initializations must be done in 'prepare_to_start_layout()'. //layout_in_box() method must always continue laying out from current state. set_cursor_and_available_space(); add_head(); //TO_FIX: It is assumed that head always fit in current page if (m_bodyLayouter) { m_bodyLayouter->set_origin(m_pageCursor); if (!is_body_row_ready()) prepare_body_row(); if (!is_body_row_ready()) { //problem or empty body. Terminate table laying out set_layout_is_finished(true); return; } //loop to add rows while(is_body_row_ready() && enough_space_in_box()) { add_body_row(); prepare_body_row(); } } bool fMoreRows = (m_bodyLayouter && m_bodyLayouter->is_row_ready()); set_layout_is_finished( !fMoreRows ); }
void free_line_desc(buffer * const b, line_desc * const ld) { /* We scan the pool list in order to find where the given line descriptor lives. */ line_desc_pool *ldp; for(ldp = (line_desc_pool *)b->line_desc_pool_list.head; ldp->ldp_node.next; ldp = (line_desc_pool *)ldp->ldp_node.next) { assert_line_desc_pool(ldp); if (ld >= ldp->pool && (do_syntax && ld < ldp->pool + ldp->size || !do_syntax && ld < (line_desc*)((no_syntax_line_desc *)ldp->pool + ldp->size))) break; } assert(ldp->ldp_node.next != NULL); block_signals(); add_head(&ldp->free_list, &ld->ld_node); if (--ldp->allocated_items == 0) { rem(&ldp->ldp_node); free_line_desc_pool(ldp); } release_signals(); }
void queue_buffer_pop_back(struct queue_buffer* qb, void* item_out) { struct queue_buffer_s *i = qb->used_head; struct queue_buffer_s *prev = NULL; ASSERT(i != NULL); while (i->next != NULL) { prev = i; i = i->next; } if (item_out != NULL) { memcpy(item_out, i->data, qb->buffer_size); } add_head(&qb->unused_head, i); if (prev != NULL) { prev->next = NULL; } else { qb->used_head = NULL; } --qb->queue_size; }
static int reply(struct protocol_head *head, struct sockaddr_in *addr, uint8_t result) { if (result == RESULT_OK) { ++process_pkg_succ_count; } else { ++process_pkg_fail_count; } head->result = result; char buf[head->echo_len + 10]; char *p = buf; int left = head->echo_len + 10; NEG_RET_LN(add_head(head, (void **)&p, &left)); NEG_RET_LN(send_udp_pkg(buf, p - buf, addr)); return 0; }
void push(C& x) { add_head(x); };
void snake::move(){ add_head(remove_tail()); object* h=body[(head+2)%maximum]; int nx=h->getx()+dx; int ny=h->gety()+dy; int nz=h->getz(); int side=0; if(nx<0){ side=3; switch(_map->get_s_r(nz,side)){ case 0: set_direction(0,1); nx=ny; ny=0; break; case 1: set_direction(-1,0); ny=ny; nx=M_SIZE-1; break; case 2: set_direction(0,-1); nx=M_SIZE-1-ny; ny=M_SIZE-1; break; case 3: set_direction(1,0); ny=M_SIZE-1-ny; nx=0; break; } nz=_map->get_f_r(nz,side); _map->rotate(side); }else if(ny<0){ side=0; switch(_map->get_s_r(nz,side)){ case 0: set_direction(0,1); nx=M_SIZE-1-nx; ny=0; break; case 1: set_direction(-1,0); ny=M_SIZE-1-nx; nx=M_SIZE-1; break; case 2: ny=M_SIZE-1; break; case 3: set_direction(1,0); ny=nx; nx=0; break; } nz=_map->get_f_r(nz,side); _map->rotate(side); }else if(nx==M_SIZE){ side=1; switch(_map->get_s_r(nz,side)){ case 0: set_direction(0,1); nx=M_SIZE-1-ny; ny=0; break; case 1: set_direction(-1,0); ny=M_SIZE-1-ny; nx=M_SIZE-1; break; case 2: set_direction(0,-1); nx=ny; ny=M_SIZE-1; break; case 3: set_direction(1,0); ny=ny; nx=0; break; } nz=_map->get_f_r(nz,side); _map->rotate(side); }else if(ny==M_SIZE){ side=2; switch(_map->get_s_r(nz,side)){ case 0: set_direction(0,1); nx=nx; ny=0; break; case 1: set_direction(-1,0); ny=nx; nx=M_SIZE-1; break; case 2: set_direction(0,-1); nx=M_SIZE-1-nx; ny=M_SIZE-1; break; case 3: set_direction(1,0); ny=M_SIZE-1-nx; nx=0; break; } nz=_map->get_f_r(nz,side); _map->rotate(side); }else{ } body[head==maximum-1?0:(head+1)]->setpos(nx,ny,nz); }
void Ring<C>::move_to_head(RingIterator<C> it) { C& Cmin = (*it); it->remove(); add_head(Cmin); }
char *alloc_chars(buffer * const b, const int64_t len) { if (!len || !b) return NULL; assert_buffer(b); block_signals(); char_pool *cp; for(cp = (char_pool *)b->char_pool_list.head; cp->cp_node.next; cp = (char_pool *)cp->cp_node.next) { assert_char_pool(cp); /* We try to allocate before the first used character, or after the last used character. If we succeed with a pool which is not the head of the list, we move it to the head in order to optimize the next try. */ if (cp->first_used >= len) { cp->first_used -= len; b->free_chars -= len; if (cp != (char_pool *)b->char_pool_list.head) { rem(&cp->cp_node); add_head(&b->char_pool_list, &cp->cp_node); } release_signals(); return cp->pool + cp->first_used; } else if (cp->size - cp->last_used > len) { cp->last_used += len; b->free_chars -= len; if (cp != (char_pool *)b->char_pool_list.head) { rem(&cp->cp_node); add_head(&b->char_pool_list, &cp->cp_node); } release_signals(); return cp->pool + cp->last_used - len + 1; } } /* If no free space has been found, we allocate a new pool which is guaranteed to contain at least len characters. The pool is added to the head of the list. */ if (cp = alloc_char_pool(len)) { add_head(&b->char_pool_list, &cp->cp_node); cp->last_used = len - 1; b->allocated_chars += cp->size; b->free_chars += cp->size - len; release_signals(); return cp->pool; } release_signals(); return NULL; }
/** * klist_add_head - Initialize a klist_node and add it to front. * @n: node we're adding. * @k: klist it's going on. */ void klist_add_head(struct klist_node *n, struct klist *k) { klist_node_init(k, n); add_head(k, n); }
int main(int argc, char **argv) { char *locale = setlocale(LC_ALL, ""); for(int i = 0; i < 256; i++) localised_up_case[i] = toupper(i); if (locale) { struct re_pattern_buffer re_pb; struct re_registers re_reg; memset(&re_pb, 0, sizeof re_pb); memset(&re_reg, 0, sizeof re_reg); re_pb.translate = localised_up_case; re_compile_pattern(LOCALE_REGEX, strlen(LOCALE_REGEX), &re_pb); if (re_search(&re_pb, locale, strlen(locale), 0, strlen(locale), &re_reg) >= 0) { if (re_reg.start[1] >= 0) io_utf8 = true; } free(re_reg.start); free(re_reg.end); } bool no_config = false; char *macro_name = NULL, *key_bindings_name = NULL, *menu_conf_name = NULL, *startup_prefs_name = DEF_PREFS_NAME; char * const skiplist = calloc(argc, 1); if (!skiplist) exit(1); /* We need this many flags. */ for(int i = 1; i < argc; i++) { if (argv[i][0] == '-' && (!strcmp(&argv[i][1], "h") || !strcmp(&argv[i][1], "-help" "\0" VERSION_STRING))) { puts(ARG_HELP); exit(0); } /* Special arguments start with two dashes. If we find one, we cancel its entry in argv[], so that it will be skipped when opening the specified files. The only exception is +N for skipping to the N-th line. */ if (argv[i][0] == '-' && argv[i][1] == '-') { if (!argv[i][2]) i++; /* You can use "--" to force the next token to be a filename */ else if (!strcmp(&argv[i][2], "noconfig") || !strcmp(&argv[i][2], "no-config")) { no_config = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "noansi") || !strcmp(&argv[i][2], "no-ansi")) { ansi = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "no-syntax")) { do_syntax = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "prefs")) { if (i < argc-1) { startup_prefs_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "ansi")) { ansi = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "utf8")) { io_utf8 = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "no-utf8")) { io_utf8 = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "macro")) { if (i < argc-1) { macro_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "keys")) { if (i < argc-1) { key_bindings_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "menus")) { if (i < argc-1) { menu_conf_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } } } #ifdef NE_TEST /* Dump the builtin menu and key bindings to compare to doc/default.menus and doc/default.keys. */ int dump_config(void); dump_config(); #endif /* Unless --noconfig was specified, we try to configure the menus and the keyboard. Note that these functions can exit() on error. */ if (!no_config) { get_menu_configuration(menu_conf_name); get_key_bindings(key_bindings_name); } /* If we cannot even create a buffer, better go... */ if (!new_buffer()) exit(1); /* Now that key_bindings are loaded, try to fix up the message for NOT_FOUND. */ { char *repeat_last_keystroke, *new_not_found; if ((repeat_last_keystroke = find_key_strokes(REPEATLAST_A, 1))) { if ((new_not_found = malloc(39+strlen(repeat_last_keystroke)))) { strcat(strcat(strcpy(new_not_found, "Not Found. (RepeatLast with "), repeat_last_keystroke), " to wrap.)"); error_msg[NOT_FOUND] = new_not_found; } free(repeat_last_keystroke); } } clear_buffer(cur_buffer); /* The INT_MAX clip always exists, and it is used by the Through command. */ clip_desc * const cd = alloc_clip_desc(INT_MAX, 0); if (!cd) exit(1); add_head(&clips, &cd->cd_node); /* General terminfo and cursor motion initalization. From here onwards, we cannot exit() lightly. */ term_init(); /* We will be always using the last line for the status bar. */ set_terminal_window(ne_lines-1); /* We read in all the key capabilities. */ read_key_capabilities(); /* Some initializations of other modules... */ re_set_syntax( RE_CONTEXT_INDEP_ANCHORS | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE | RE_NEWLINE_ALT | RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES ); bool first_file = true; load_virtual_extensions(); load_auto_prefs(cur_buffer, startup_prefs_name); buffer *stdin_buffer = NULL; if (!isatty(fileno(stdin))) { first_file = false; const int error = load_fd_in_buffer(cur_buffer, fileno(stdin)); print_error(error); stdin_buffer = cur_buffer; if (!(freopen("/dev/tty", "r", stdin))) { fprintf(stderr, "Cannot reopen input tty\n"); abort(); } } /* The terminal is prepared for interactive I/O. */ set_interactive_mode(); clear_entire_screen(); /* This function sets fatal_code() as signal interrupt handler for all the dangerous signals (SIGILL, SIGSEGV etc.). */ set_fatal_code(); if (argc > 1) { /* The first file opened does not need a NEWDOC_A action. Note that file loading can be interrupted (wildcarding can sometimes produce unwanted results). */ uint64_t first_line = 0, first_col = 0; bool binary = false, skip_plus = false, read_only = false; stop = false; for(int i = 1; i < argc && !stop; i++) { if (argv[i] && !skiplist[i]) { if (argv[i][0] == '+' && !skip_plus) { /* looking for "+", or "+N" or "+N,M" */ uint64_t tmp_l = INT64_MAX, tmp_c = 0; char *d; errno = 0; if (argv[i][1]) { if (isdigit((unsigned char)argv[i][1])) { tmp_l = strtoll(argv[i]+1, &d, 10); if (!errno) { if (*d) { /* separator between N and M */ if (isdigit((unsigned char)d[1])) { tmp_c = strtoll(d+1, &d, 10); if (*d) errno = ERANGE; } else errno = ERANGE; } } } else errno = ERANGE; } if (!errno) { first_line = tmp_l; first_col = tmp_c; } else { skip_plus = true; i--; } } else if (!strcmp(argv[i], "--binary")) { binary = true; } else if (!strcmp(argv[i], "--read-only") || !strcmp(argv[i], "--readonly") || !strcmp(argv[i], "--ro")) { read_only = true; } else { if (!strcmp(argv[i], "-") && stdin_buffer) { stdin_buffer->opt.binary = binary; if (read_only) stdin_buffer->opt.read_only = read_only; if (first_line) do_action(stdin_buffer, GOTOLINE_A, first_line, NULL); if (first_col) do_action(stdin_buffer, GOTOCOLUMN_A, first_col, NULL); stdin_buffer = NULL; } else { if (!strcmp(argv[i], "--")) i++; if (!first_file) do_action(cur_buffer, NEWDOC_A, -1, NULL); else first_file = false; cur_buffer->opt.binary = binary; if (i < argc) do_action(cur_buffer, OPEN_A, 0, str_dup(argv[i])); if (first_line) do_action(cur_buffer, GOTOLINE_A, first_line, NULL); if (first_col) do_action(cur_buffer, GOTOCOLUMN_A, first_col, NULL); if (read_only) cur_buffer->opt.read_only = read_only; } first_line = first_col = 0; skip_plus = binary = read_only = false; } } } free(skiplist); /* This call makes current the first specified file. It is called only if more than one buffer exist. */ if (get_nth_buffer(1)) do_action(cur_buffer, NEXTDOC_A, -1, NULL); } /* We delay updates. In this way the macro activity does not cause display activity. */ reset_window(); delay_update(); if (macro_name) do_action(cur_buffer, MACRO_A, -1, str_dup(macro_name)); else if (first_file) { /* If there is no file to load, and no macro to execute, we display the "NO WARRANTY" message. */ about(); } while(true) { /* If we are displaying the "NO WARRANTY" info, we should not refresh the window now */ if (!displaying_info) { refresh_window(cur_buffer); if (cur_buffer->opt.automatch) automatch_bracket(cur_buffer, true); } draw_status_bar(); move_cursor(cur_buffer->cur_y, cur_buffer->cur_x); int c = get_key_code(); if (window_changed_size) { print_error(do_action(cur_buffer, REFRESH_A, 0, NULL)); window_changed_size = displaying_info = false; cur_buffer->automatch.shown = 0; } if (c == INVALID_CHAR) continue; /* Window resizing. */ const input_class ic = CHAR_CLASS(c); if (displaying_info) { refresh_window(cur_buffer); displaying_info = false; } if (cur_buffer->automatch.shown) automatch_bracket(cur_buffer, false); switch(ic) { case INVALID: print_error(INVALID_CHARACTER); break; case ALPHA: print_error(do_action(cur_buffer, INSERTCHAR_A, c, NULL)); break; case TAB: print_error(do_action(cur_buffer, INSERTTAB_A, 1, NULL)); break; case RETURN: print_error(do_action(cur_buffer, INSERTLINE_A, -1, NULL)); break; case COMMAND: if (c < 0) c = -c - 1; if (key_binding[c]) print_error(execute_command_line(cur_buffer, key_binding[c])); break; default: break; } } }
Errcode open_wndo(Wndo **pw, WndoInit *wi) /* * Open a window. Returns window in *pw. * (pw == NULL is valid input, but should only be used by * open_wscreen()). */ { Errcode err; Wndo *w = NULL; Wscreen *ws; Boolean was_mouse; LONG allocsize; LONG ydotsize; LONG ptrsize; SHORT screen_wndo; SHORT is_backdrop; SHORT max_wins; was_mouse = hide_mouse(); is_backdrop = wi->flags & WNDO_BACKDROP; screen_wndo = (pw == NULL); ws = wi->screen; max_wins = ws->max_wins; if(screen_wndo) { w = &ws->wndo; w->type = RT_ROOTWNDO; w->cmap = ws->viscel->cmap; w->W_rastid = NULL_RASTID; } else { *pw = NULL; if(!is_backdrop) { if(ws->num_wins >= max_wins) { err = Err_tomany_wins; goto error; } --max_wins; /* these windows can't be behind backdrops */ } if((w = pj_zalloc(sizeof(Wndo) + wi->extrabuf)) == NULL) goto nomem_error; w->type = RT_WINDOW; w->rasts = ws->wndo.rasts; w->cmap = ws->wndo.cmap; if(is_backdrop) w->W_rastid = NULL_RASTID; /* the initial null raster */ else { w->W_rastid = get_newid(ws); w->rasts[w->W_rastid] = &(w->behind); } } if(wi->cursor == NULL) w->cursor = ws->cursor; else w->cursor = wi->cursor; w->W_screen = ws; /* must get to here ok if window is allocated */ /* move in raster header fields from root screen raster */ w->aspect_dx = ws->viscel->aspect_dx; w->aspect_dy = ws->viscel->aspect_dy; w->pdepth = ws->viscel->pdepth; copy_rectfields(wi,w); /* copy in rectangle fields for initial size */ /* none too small */ if(w->width < WNDO_MINWIDTH) w->width = WNDO_MINWIDTH; if(w->height < WNDO_MINHEIGHT) w->height = WNDO_MINHEIGHT; #ifdef DOESNTWORK /* no window ports bigger than screen !! */ /* this should be a and cliprects type of clip to get common rect * if needed */ sclip_rect((Rectangle *)&(w->RECTSTART), (Rectangle *)&(ws->viscel->RECTSTART)); #endif /* DOESNTWORK */ /* load cliprect variables for window port position and size */ w->W_xmax = w->x + w->width; w->W_ymax = w->y + w->height; /* increase width and height of window to be the maximum size * requested if greater than port size */ if(wi->maxw > w->width) w->width = wi->maxw; if(wi->maxh > w->height) w->height = wi->maxh; /* initialize and copy in window maxsize rectangle fields to behind rast * the width and height for both shall NEVER be changed until window is * closed */ copy_rasthdr(ws->viscel,&w->behind); copy_rectfields(w,&w->behind); if(is_backdrop) { if((err = pj_open_nullrast(&w->behind)) < 0) /* dummy backup area */ goto error; } else { if((err = pj_open_bytemap((Rasthdr *)&w->behind,(Bytemap *)&w->behind)) < 0) goto error; } /* size of one column array of ydots */ ydotsize = (w->height /* one byte for each dot */ + (w->height & 1) /* even word size */ + sizeof(Cliphead)); /* cliphead for range and freelist */ /* size of all ydots buffers */ allocsize = (ydotsize * ((max_wins * 2) - 1)); /* size of pointer array for ydots */ /* size of pointer array */ ptrsize = w->width * sizeof(PTR); if((w->ydots = pj_malloc(allocsize + ptrsize)) == NULL) goto nomem_error; w->free_ydots = link_free_clips(OPTR(w->ydots,ptrsize),ydotsize,allocsize); w->ydots[0] = get_free_clip(&w->free_ydots); NEXTX(w->ydots[0]) = w->width; free_init_ydots(w); /* allocate vchanes */ if((w->vchanges = pj_malloc(w->height * sizeof(SHORT))) == NULL) goto nomem_error; pj_stuff_words(w->height,w->vchanges,w->height); w->lib = get_window_lib(); /******** add window to screen ********/ if(screen_wndo) { add_head(&ws->wilist,&w->W_node); build_all_clips(ws,0); ++ws->num_wins; return(0); } w->flags |= wi->flags & ~(WNDO_NOCLEAR); if(is_backdrop) { #ifdef WASTHISWAY insert_before(&(w->W_node),&(ws->wndo.W_node)); #endif if( (wi->over != NULL) && (find_header(&(wi->over->W_node)) == &(ws->wilist))) { insert_before(&(w->W_node),&(wi->over->W_node)); } else { add_head(&ws->wilist,&w->W_node); } build_all_clips(ws,1); if(!(wi->flags & WNDO_NOCLEAR)) pj_set_rast((Raster *)w, 0); /* clear window */ } else { ++ws->num_wins; if( (wi->over != NULL) && (find_header(&(wi->over->W_node)) == &(ws->wilist))) { insert_before(&(w->W_node),&(wi->over->W_node)); } else { add_head(&ws->wilist,&w->W_node); } build_all_clips(ws,1); if(wi->flags & WNDO_NOCLEAR) { /* only blit in parts that are backups */ blit_behind(w,blit_saveonly); } else { pj_set_rast(&w->behind,0); /* clear backup raster */ blit_behind(w,pj__swaprect); /* swap window raster onto screen */ } } *pw = w; err = Success; goto done; nomem_error: err = Err_no_memory; error: _close_wndo(w); done: if(was_mouse) show_mouse(); return(err); }