int main() { unit_flags f; f.status = STATUS_UNSPECIFIED; new_unit (&f); return 0; }
static void already_open (gfc_unit * u, unit_flags * flags) { if (ioparm.file == NULL) { edit_modes (u, flags); return; } /* If the file is connected to something else, close it and open a new unit. */ if (!compare_file_filename (u->s, ioparm.file, ioparm.file_len)) { if (close_unit (u)) { generate_error (ERROR_OS, "Error closing file in OPEN statement"); return; } new_unit (flags); return; } edit_modes (u, flags); }
editor_action* mouse_action_unit::up_left(editor_display& disp, int x, int y) { if (!click_) return NULL; click_ = false; map_location hex = disp.hex_clicked_on(x, y); if (!disp.get_map().on_board(hex)) { return NULL; } unit_type type = unit_palette_.selected_fg_item(); // Does this serve a purpose other than making sure the type is built? // (Calling unit_types.build_unit_type(type) would now accomplish that // with less overhead.) const std::string& type_id = type.id(); const unit_type *new_unit_type = unit_types.find(type_id); if (!new_unit_type) { //TODO rewrite the error message. ERR_ED << "create unit dialog returned inexistent or unusable unit_type id '" << type_id << "'" << std::endl; return NULL; } const unit_type &ut = *new_unit_type; unit_race::GENDER gender = ut.genders().front(); unit new_unit(ut, disp.viewing_side(), true, gender); editor_action* action = new editor_action_unit(hex, new_unit); return action; }
struct nsa_token * create_unit(struct nsa_parser *p,const char *s,struct nsa_token *t) { const char *n = nsa_trim_morph(p->context, s); struct nsa_hash_data *d = hash_find(p->context->step_index, (unsigned char *)n); if (d) { struct nsa_token *tu = new_token(); struct nsa_unit *u = new_unit(); List *l = list_create(LIST_SINGLE); list_add(l,t); if (d->continuations) d = check_continuations(d,p,&n,l); u->name = (char *)npool_copy((unsigned char *)n,p->pool); u->cands = d->cands; tu->type = NSA_T_UNIT; if (t) { struct nsa_token *lt; int i; tu->children = new_children(list_len(l)); for (i = 0, lt = list_first(l); lt; lt = list_next(l),++i) tu->children[i] = lt; } tu->d.u = u; list_free(l,NULL); return tu; } else return t; }
static int gen_play(lua_State *lstate) { GEN *gen; if (lua_gettop(lstate) == 2) { lua_pop(lstate, 1); } getfield(lstate, "intern"); gen = (GEN *)lua_touserdata(lstate, -1); gen->running = 1; if (active_gens == NULL) active_gens = new_unit(); link_unit((MASH_UNIT *)gen, active_gens); lua_pop(lstate, 2); return 0; }
static void already_open (st_parameter_open *opp, gfc_unit * u, unit_flags * flags) { if ((opp->common.flags & IOPARM_OPEN_HAS_FILE) == 0) { edit_modes (opp, u, flags); return; } /* If the file is connected to something else, close it and open a new unit. */ if (!compare_file_filename (u, opp->file, opp->file_len)) { #if !HAVE_UNLINK_OPEN_FILE char *path = NULL; if (u->file && u->flags.status == STATUS_SCRATCH) { path = (char *) gfc_alloca (u->file_len + 1); unpack_filename (path, u->file, u->file_len); } #endif if (sclose (u->s) == FAILURE) { unlock_unit (u); generate_error (&opp->common, LIBERROR_OS, "Error closing file in OPEN statement"); return; } u->s = NULL; if (u->file) free_mem (u->file); u->file = NULL; u->file_len = 0; #if !HAVE_UNLINK_OPEN_FILE if (path != NULL) unlink (path); #endif u = new_unit (opp, u, flags); if (u != NULL) unlock_unit (u); return; } edit_modes (opp, u, flags); }
static void *flac_thread(void *arg) { FLAC_FEED *feed; feed = (FLAC_FEED *)arg; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_mutex_lock(&(feed->base.thread_lock)); if (feeds == NULL) feeds = new_unit(); link_unit((MASH_UNIT *)feed, feeds); feed->base.running = 1; while (feed->base.running) { FLAC__stream_decoder_process_single(feed->decoder); pthread_cond_wait(&(feed->base.data_ready), &(feed->base.thread_lock)); } pthread_mutex_unlock(&(feed->base.thread_lock)); return NULL; }
unit get_advanced_unit(const unit &u, const std::string& advance_to) { const unit_type *new_type = unit_types.find(advance_to); if (!new_type) { throw game::game_error("Could not find the unit being advanced" " to: " + advance_to); } unit new_unit(u); new_unit.set_experience(new_unit.experience() - new_unit.max_experience()); new_unit.advance_to(*new_type); new_unit.heal_all(); new_unit.set_state(unit::STATE_POISONED, false); new_unit.set_state(unit::STATE_SLOWED, false); new_unit.set_state(unit::STATE_PETRIFIED, false); new_unit.set_user_end_turn(false); new_unit.set_hidden(false); return new_unit; }
unit_ptr get_advanced_unit(const unit &u, const std::string& advance_to) { const unit_type *new_type = unit_types.find(advance_to); if (!new_type) { throw game::game_error("Could not find the unit being advanced" " to: " + advance_to); } unit_ptr new_unit(new unit(u)); new_unit->set_experience(new_unit->experience_overflow()); new_unit->advance_to(*new_type); new_unit->heal_fully(); new_unit->set_state(unit::STATE_POISONED, false); new_unit->set_state(unit::STATE_SLOWED, false); new_unit->set_state(unit::STATE_PETRIFIED, false); new_unit->set_user_end_turn(false); new_unit->set_hidden(false); return new_unit; }
static void *vorbis_thread(void *arg) { int res, n; char *oggbuf; time_t now; VORBIS_FEED *feed; feed = (VORBIS_FEED *)arg; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_mutex_lock(&(feed->base.thread_lock)); if (vorbis_synthesis_init(&(feed->vd), &(feed->vi)) != 0) { logmsg("vorbis init failed\n"); return NULL; } feed->base.running = 1; if (feeds == NULL) feeds = new_unit(); link_unit((MASH_UNIT *)feed, feeds); vorbis_block_init(&(feed->vd), &(feed->vb)); while (feed->base.running) { while (1) { res = ogg_sync_pageout(&(feed->oy), &(feed->og)); if (res == 0) break; if (res < 0) { logmsg("missing data\n"); continue; } res = ogg_stream_pagein(&(feed->os), &(feed->og)); if (res < 0) { ogg_stream_reset(&(feed->os)); ogg_stream_init(&(feed->os), ogg_page_serialno(&(feed->og))); now = time(NULL); logmsg("%s: bad ogg page\n", ctime(&now)); continue; } process_vorbis_packets(feed); } pthread_cond_wait(&(feed->base.data_ready), &(feed->base.thread_lock)); oggbuf = ogg_sync_buffer(&(feed->oy), BLOCKSIZE); n = read(feed->base.sock, oggbuf, BLOCKSIZE); ogg_sync_wrote(&(feed->oy), n); } pthread_mutex_unlock(&(feed->base.thread_lock)); return NULL; }
void unit_creator::add_unit(const config &cfg, const vconfig* vcfg) { config temp_cfg(cfg); temp_cfg["side"] = team_.side(); const std::string& id =(cfg)["id"]; bool animate = temp_cfg["animate"].to_bool(); temp_cfg.remove_attribute("animate"); unit_ptr recall_list_element = team_.recall_list().find_if_matches_id(id); if ( !recall_list_element ) { //make the new unit unit_ptr new_unit(new unit(temp_cfg, true, vcfg)); map_location loc = find_location(temp_cfg, new_unit.get()); if ( loc.valid() ) { //add the new unit to map board_->units().replace(loc, *new_unit); LOG_NG << "inserting unit for side " << new_unit->side() << "\n"; post_create(loc,*(board_->units().find(loc)),animate); } else if ( add_to_recall_ ) { //add to recall list team_.recall_list().add(new_unit); DBG_NG << "inserting unit with id=["<<id<<"] on recall list for side " << new_unit->side() << "\n"; preferences::encountered_units().insert(new_unit->type_id()); } } else { //get unit from recall list map_location loc = find_location(temp_cfg, recall_list_element.get()); if ( loc.valid() ) { board_->units().replace(loc, *recall_list_element); LOG_NG << "inserting unit from recall list for side " << recall_list_element->side()<< " with id="<< id << "\n"; post_create(loc,*(board_->units().find(loc)),animate); //if id is not empty, delete units with this ID from recall list team_.recall_list().erase_if_matches_id( id); } else if ( add_to_recall_ ) { LOG_NG << "wanted to insert unit on recall list, but recall list for side " << (cfg)["side"] << "already contains id=" <<id<<"\n"; return; } } }
static void already_open (st_parameter_open *opp, gfc_unit * u, unit_flags * flags) { if ((opp->common.flags & IOPARM_OPEN_HAS_FILE) == 0) { edit_modes (opp, u, flags); return; } /* If the file is connected to something else, close it and open a new unit. */ if (!compare_file_filename (u, opp->file, opp->file_len)) { if (sclose (u->s) == -1) { unlock_unit (u); generate_error (&opp->common, LIBERROR_OS, "Error closing file in OPEN statement"); return; } u->s = NULL; #if !HAVE_UNLINK_OPEN_FILE if (u->filename && u->flags.status == STATUS_SCRATCH) remove (u->filename); #endif free (u->filename); u->filename = NULL; u = new_unit (opp, u, flags); if (u != NULL) unlock_unit (u); return; } edit_modes (opp, u, flags); }
void new_unit(int x, int y, int type, int player) { new_unit(x, y, type, player, 1); }
void st_open (void) { unit_flags flags; gfc_unit *u = NULL; library_start (); /* Decode options. */ flags.access = (ioparm.access == NULL) ? ACCESS_UNSPECIFIED : find_option (ioparm.access, ioparm.access_len, access_opt, "Bad ACCESS parameter in OPEN statement"); flags.action = (ioparm.action == NULL) ? ACTION_UNSPECIFIED : find_option (ioparm.action, ioparm.action_len, action_opt, "Bad ACTION parameter in OPEN statement"); flags.blank = (ioparm.blank == NULL) ? BLANK_UNSPECIFIED : find_option (ioparm.blank, ioparm.blank_len, blank_opt, "Bad BLANK parameter in OPEN statement"); flags.delim = (ioparm.delim == NULL) ? DELIM_UNSPECIFIED : find_option (ioparm.delim, ioparm.delim_len, delim_opt, "Bad DELIM parameter in OPEN statement"); flags.pad = (ioparm.pad == NULL) ? PAD_UNSPECIFIED : find_option (ioparm.pad, ioparm.pad_len, pad_opt, "Bad PAD parameter in OPEN statement"); flags.form = (ioparm.form == NULL) ? FORM_UNSPECIFIED : find_option (ioparm.form, ioparm.form_len, form_opt, "Bad FORM parameter in OPEN statement"); flags.position = (ioparm.position == NULL) ? POSITION_UNSPECIFIED : find_option (ioparm.position, ioparm.position_len, position_opt, "Bad POSITION parameter in OPEN statement"); flags.status = (ioparm.status == NULL) ? STATUS_UNSPECIFIED : find_option (ioparm.status, ioparm.status_len, status_opt, "Bad STATUS parameter in OPEN statement"); if (ioparm.unit < 0) generate_error (ERROR_BAD_OPTION, "Bad unit number in OPEN statement"); if (flags.position != POSITION_UNSPECIFIED && flags.access == ACCESS_DIRECT) generate_error (ERROR_BAD_OPTION, "Cannot use POSITION with direct access files"); if (flags.position == POSITION_UNSPECIFIED) flags.position = POSITION_ASIS; if (ioparm.library_return != LIBRARY_OK) { library_end (); return; } u = find_unit (ioparm.unit); if (u == NULL) new_unit (&flags); else already_open (u, &flags); library_end (); }
void st_open (st_parameter_open *opp) { unit_flags flags; gfc_unit *u = NULL; GFC_INTEGER_4 cf = opp->common.flags; unit_convert conv; library_start (&opp->common); /* Decode options. */ flags.access = !(cf & IOPARM_OPEN_HAS_ACCESS) ? ACCESS_UNSPECIFIED : find_option (&opp->common, opp->access, opp->access_len, access_opt, "Bad ACCESS parameter in OPEN statement"); flags.action = !(cf & IOPARM_OPEN_HAS_ACTION) ? ACTION_UNSPECIFIED : find_option (&opp->common, opp->action, opp->action_len, action_opt, "Bad ACTION parameter in OPEN statement"); flags.blank = !(cf & IOPARM_OPEN_HAS_BLANK) ? BLANK_UNSPECIFIED : find_option (&opp->common, opp->blank, opp->blank_len, blank_opt, "Bad BLANK parameter in OPEN statement"); flags.delim = !(cf & IOPARM_OPEN_HAS_DELIM) ? DELIM_UNSPECIFIED : find_option (&opp->common, opp->delim, opp->delim_len, delim_opt, "Bad DELIM parameter in OPEN statement"); flags.pad = !(cf & IOPARM_OPEN_HAS_PAD) ? PAD_UNSPECIFIED : find_option (&opp->common, opp->pad, opp->pad_len, pad_opt, "Bad PAD parameter in OPEN statement"); flags.decimal = !(cf & IOPARM_OPEN_HAS_DECIMAL) ? DECIMAL_UNSPECIFIED : find_option (&opp->common, opp->decimal, opp->decimal_len, decimal_opt, "Bad DECIMAL parameter in OPEN statement"); flags.encoding = !(cf & IOPARM_OPEN_HAS_ENCODING) ? ENCODING_UNSPECIFIED : find_option (&opp->common, opp->encoding, opp->encoding_len, encoding_opt, "Bad ENCODING parameter in OPEN statement"); flags.async = !(cf & IOPARM_OPEN_HAS_ASYNCHRONOUS) ? ASYNC_UNSPECIFIED : find_option (&opp->common, opp->asynchronous, opp->asynchronous_len, async_opt, "Bad ASYNCHRONOUS parameter in OPEN statement"); flags.round = !(cf & IOPARM_OPEN_HAS_ROUND) ? ROUND_UNSPECIFIED : find_option (&opp->common, opp->round, opp->round_len, round_opt, "Bad ROUND parameter in OPEN statement"); flags.sign = !(cf & IOPARM_OPEN_HAS_SIGN) ? SIGN_UNSPECIFIED : find_option (&opp->common, opp->sign, opp->sign_len, sign_opt, "Bad SIGN parameter in OPEN statement"); flags.form = !(cf & IOPARM_OPEN_HAS_FORM) ? FORM_UNSPECIFIED : find_option (&opp->common, opp->form, opp->form_len, form_opt, "Bad FORM parameter in OPEN statement"); flags.position = !(cf & IOPARM_OPEN_HAS_POSITION) ? POSITION_UNSPECIFIED : find_option (&opp->common, opp->position, opp->position_len, position_opt, "Bad POSITION parameter in OPEN statement"); flags.status = !(cf & IOPARM_OPEN_HAS_STATUS) ? STATUS_UNSPECIFIED : find_option (&opp->common, opp->status, opp->status_len, status_opt, "Bad STATUS parameter in OPEN statement"); /* First, we check wether the convert flag has been set via environment variable. This overrides the convert tag in the open statement. */ conv = get_unformatted_convert (opp->common.unit); if (conv == GFC_CONVERT_NONE) { /* Nothing has been set by environment variable, check the convert tag. */ if (cf & IOPARM_OPEN_HAS_CONVERT) conv = find_option (&opp->common, opp->convert, opp->convert_len, convert_opt, "Bad CONVERT parameter in OPEN statement"); else conv = compile_options.convert; } /* We use big_endian, which is 0 on little-endian machines and 1 on big-endian machines. */ switch (conv) { case GFC_CONVERT_NATIVE: case GFC_CONVERT_SWAP: break; case GFC_CONVERT_BIG: conv = big_endian ? GFC_CONVERT_NATIVE : GFC_CONVERT_SWAP; break; case GFC_CONVERT_LITTLE: conv = big_endian ? GFC_CONVERT_SWAP : GFC_CONVERT_NATIVE; break; default: internal_error (&opp->common, "Illegal value for CONVERT"); break; } flags.convert = conv; if (flags.position != POSITION_UNSPECIFIED && flags.access == ACCESS_DIRECT) generate_error (&opp->common, LIBERROR_BAD_OPTION, "Cannot use POSITION with direct access files"); if (flags.access == ACCESS_APPEND) { if (flags.position != POSITION_UNSPECIFIED && flags.position != POSITION_APPEND) generate_error (&opp->common, LIBERROR_BAD_OPTION, "Conflicting ACCESS and POSITION flags in" " OPEN statement"); notify_std (&opp->common, GFC_STD_GNU, "Extension: APPEND as a value for ACCESS in OPEN statement"); flags.access = ACCESS_SEQUENTIAL; flags.position = POSITION_APPEND; } if (flags.position == POSITION_UNSPECIFIED) flags.position = POSITION_ASIS; if ((opp->common.flags & IOPARM_LIBRETURN_MASK) == IOPARM_LIBRETURN_OK) { if ((opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT)) opp->common.unit = get_unique_unit_number(opp); else if (opp->common.unit < 0) { u = find_unit (opp->common.unit); if (u == NULL) /* Negative unit and no NEWUNIT-created unit found. */ generate_error (&opp->common, LIBERROR_BAD_OPTION, "Bad unit number in OPEN statement"); } if (u == NULL) u = find_or_create_unit (opp->common.unit); if (u->s == NULL) { u = new_unit (opp, u, &flags); if (u != NULL) unlock_unit (u); } else already_open (opp, u, &flags); } if ((opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT) && (opp->common.flags & IOPARM_LIBRETURN_MASK) == IOPARM_LIBRETURN_OK) *opp->newunit = opp->common.unit; library_end (); }
void st_endfile (st_parameter_filepos *fpp) { gfc_unit *u; library_start (&fpp->common); u = find_unit (fpp->common.unit); if (u != NULL) { if (u->flags.access == ACCESS_DIRECT) { generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT, "Cannot perform ENDFILE on a file opened " "for DIRECT access"); goto done; } if (u->flags.access == ACCESS_SEQUENTIAL && u->endfile == AFTER_ENDFILE) { generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT, "Cannot perform ENDFILE on a file already " "positioned after the EOF marker"); goto done; } /* If there are previously written bytes from a write with ADVANCE="no", add a record marker before performing the ENDFILE. */ if (u->previous_nonadvancing_write) finish_last_advance_record (u); u->previous_nonadvancing_write = 0; if (u->current_record) { st_parameter_dt dtp; dtp.common = fpp->common; memset (&dtp.u.p, 0, sizeof (dtp.u.p)); dtp.u.p.current_unit = u; next_record (&dtp, 1); } unit_truncate (u, stell (u->s), &fpp->common); u->endfile = AFTER_ENDFILE; if (0 == stell (u->s)) u->flags.position = POSITION_REWIND; } else { if (fpp->common.unit < 0) { generate_error (&fpp->common, LIBERROR_BAD_OPTION, "Bad unit number in statement"); return; } u = find_or_create_unit (fpp->common.unit); if (u->s == NULL) { /* Open the unit with some default flags. */ st_parameter_open opp; unit_flags u_flags; memset (&u_flags, '\0', sizeof (u_flags)); u_flags.access = ACCESS_SEQUENTIAL; u_flags.action = ACTION_READWRITE; /* Is it unformatted? */ if (!(fpp->common.flags & (IOPARM_DT_HAS_FORMAT | IOPARM_DT_LIST_FORMAT | IOPARM_DT_IONML_SET))) u_flags.form = FORM_UNFORMATTED; else u_flags.form = FORM_UNSPECIFIED; u_flags.delim = DELIM_UNSPECIFIED; u_flags.blank = BLANK_UNSPECIFIED; u_flags.pad = PAD_UNSPECIFIED; u_flags.decimal = DECIMAL_UNSPECIFIED; u_flags.encoding = ENCODING_UNSPECIFIED; u_flags.async = ASYNC_UNSPECIFIED; u_flags.round = ROUND_UNSPECIFIED; u_flags.sign = SIGN_UNSPECIFIED; u_flags.status = STATUS_UNKNOWN; u_flags.convert = GFC_CONVERT_NATIVE; opp.common = fpp->common; opp.common.flags &= IOPARM_COMMON_MASK; u = new_unit (&opp, u, &u_flags); if (u == NULL) return; u->endfile = AFTER_ENDFILE; } } done: unlock_unit (u); library_end (); }