void hero::increase_feeling_each(unit_map& units, hero_map& heros, hero& to, int inc) { int carry_to, descent_number; std::vector<unit*> adjusted; for (int i = 0; i < 2; i ++) { if (i == 0) { carry_to = increase_feeling(to, inc, descent_number); } else { carry_to = to.increase_feeling(*this, inc, descent_number); } unit* u = NULL; if (carry_to != FEELING_NONE) { game_events::show_relation_message(units, heros, i? to: *this, i? *this: to, carry_to); u = find_unit(units, *this); if (!u->is_artifical() && std::find(adjusted.begin(), adjusted.end(), u) == adjusted.end()) { u->adjust(); adjusted.push_back(u); } } if (descent_number != HEROS_INVALID_NUMBER) { u = find_unit(units, heros[descent_number]); if (u && !u->is_artifical() && std::find(adjusted.begin(), adjusted.end(), u) == adjusted.end()) { u->adjust(); adjusted.push_back(u); } } } }
bool unit_reader::read() { constexpr auto mask_normal = ~(ipa::stress | ipa::tone_start | ipa::tone_middle | ipa::tone_end); constexpr auto mask_nolength = ~(ipa::stress | ipa::tone_start | ipa::tone_middle | ipa::tone_end | ipa::length); while (true) switch (mState) { case need_phoneme: if (!mProsody->read()) return false; if (find_unit(mask_normal) || find_unit(mask_nolength)) { mState = have_unit; continue; } else if (mProsody->first.phoneme2 == ipa::unspecified) switch (mProsody->first.phoneme1.get(ipa::phoneme_type)) { case ipa::syllable_break: continue; case ipa::foot_break: case ipa::intonation_break: mState = have_phoneme; continue; } fprintf(stdout, "Phoneme /"); tts::write_explicit_feature(stdout, mProsody->first.phoneme1); if (mProsody->first.phoneme2 != ipa::unspecified) tts::write_explicit_feature(stdout, mProsody->first.phoneme2); fprintf(stdout, "/ is not supported.\n"); break; case have_phoneme: first.phoneme1 = mProsody->first.phoneme1; first.phoneme2 = mProsody->first.phoneme2; first.duration = mProsody->first.duration; mState = need_phoneme; return true; case have_unit: first.phoneme1 = ipa::unit | (mCurrentUnit << 8); ++mCurrentUnit; uint8_t offset = (mCurrentUnit == mLastUnit) ? mRemainingOffset : mUnits[mCurrentUnit].phoneme_start; mRemainingOffset -= offset; first.duration = css::time((mProsody->first.duration.value() * offset) / 100.0, mProsody->first.duration.units()); if (mCurrentUnit == mLastUnit) mState = need_phoneme; return true; } }
int PREFIX(fgetc) (const int * unit, char * c, gfc_charlen_type c_len) { int ret; gfc_unit * u = find_unit (*unit); if (u == NULL) return -1; fbuf_reset (u); if (u->mode == WRITING) { sflush (u->s); u->mode = READING; } memset (c, ' ', c_len); ret = sread (u->s, c, 1); unlock_unit (u); if (ret < 0) return ret; if (ret != 1) return -1; else return 0; }
void st_close (st_parameter_close *clp) { close_status status; gfc_unit *u; #if !HAVE_UNLINK_OPEN_FILE char * path; path = NULL; #endif library_start (&clp->common); status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED : find_option (&clp->common, clp->status, clp->status_len, status_opt, "Bad STATUS parameter in CLOSE statement"); if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK) { library_end (); return; } u = find_unit (clp->common.unit); if (u != NULL) { if (u->flags.status == STATUS_SCRATCH) { if (status == CLOSE_KEEP) generate_error (&clp->common, LIBERROR_BAD_OPTION, "Can't KEEP a scratch file on CLOSE"); #if !HAVE_UNLINK_OPEN_FILE path = (char *) gfc_alloca (u->file_len + 1); unpack_filename (path, u->file, u->file_len); #endif } else { if (status == CLOSE_DELETE) { #if HAVE_UNLINK_OPEN_FILE delete_file (u); #else path = (char *) gfc_alloca (u->file_len + 1); unpack_filename (path, u->file, u->file_len); #endif } } close_unit (u); #if !HAVE_UNLINK_OPEN_FILE if (path != NULL) unlink (path); #endif } /* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */ library_end (); }
void st_inquire (st_parameter_inquire *iqp) { gfc_unit *u; library_start (&iqp->common); if ((iqp->common.flags & IOPARM_INQUIRE_HAS_FILE) == 0) { u = find_unit (iqp->common.unit); inquire_via_unit (iqp, u); } else { u = find_file (iqp->file, iqp->file_len); if (u == NULL) inquire_via_filename (iqp); else inquire_via_unit (iqp, u); } if (u != NULL) unlock_unit (u); library_end (); }
// returns false if conflict is found. True if not, or solved. bool propagate_units(solver* s){ lit unit_lit; while(find_unit(s, &unit_lit)){ if(!propagate_decision(s,unit_lit,false)) return false; // CONFLICT if(s->tail == 0) return true; // SATISFIED } return true; }
void st_rewind (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_BAD_OPTION, "Cannot REWIND a file opened for DIRECT access"); else { /* 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; fbuf_reset (u); u->last_record = 0; if (sseek (u->s, 0, SEEK_SET) < 0) generate_error (&fpp->common, LIBERROR_OS, NULL); /* Handle special files like /dev/null differently. */ if (!is_special (u->s)) { /* We are rewinding so we are not at the end. */ u->endfile = NO_ENDFILE; } else { /* Set this for compatibilty with g77 for /dev/null. */ if (file_length (u->s) == 0 && stell (u->s) == 0) u->endfile = AT_ENDFILE; /* Future refinements on special files can go here. */ } u->current_record = 0; u->strm_pos = 1; u->read_bad = 0; } /* Update position for INQUIRE. */ u->flags.position = POSITION_REWIND; unlock_unit (u); } library_end (); }
static gfc_offset gf_ftell (int unit) { gfc_unit * u = find_unit (unit); if (u == NULL) return -1; int pos = fbuf_reset (u); if (pos != 0) sseek (u->s, pos, SEEK_CUR); gfc_offset ret = stell (u->s); unlock_unit (u); return ret; }
GFC_LOGICAL_8 isatty_l8 (int *unit) { gfc_unit *u; GFC_LOGICAL_8 ret = 0; u = find_unit (*unit); if (u != NULL) { ret = (GFC_LOGICAL_8) stream_isatty (u->s); unlock_unit (u); } return ret; }
void fseek_sub (int * unit, GFC_IO_INT * offset, int * whence, int * status) { gfc_unit * u = find_unit (*unit); ssize_t result = -1; if (u != NULL) { result = sseek(u->s, *offset, *whence); unlock_unit (u); } if (status) *status = (result < 0 ? -1 : 0); }
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 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; done: unlock_unit (u); } library_end (); }
void flush_i8 (GFC_INTEGER_8 *unit) { gfc_unit *us; /* flush all streams */ if (unit == NULL) { us = g.unit_root; recursive_flush(us); } else { us = find_unit(*unit); if (us != NULL) flush (us->s); } }
void flush_i8 (GFC_INTEGER_8 *unit) { gfc_unit *us; /* flush all streams */ if (unit == NULL) flush_all_units (); else { us = find_unit (*unit); if (us != NULL) { sflush (us->s); unlock_unit (us); } } }
void ttynam_sub (int *unit, char * name, gfc_charlen_type name_len) { gfc_unit *u; int nlen; int err = 1; u = find_unit (*unit); if (u != NULL) { err = stream_ttyname (u->s, name, name_len); if (err == 0) { nlen = strlen (name); memset (&name[nlen], ' ', name_len - nlen); } unlock_unit (u); } if (err != 0) memset (name, ' ', name_len); }
int PREFIX(fputc) (const int * unit, char * c, gfc_charlen_type c_len __attribute__((unused))) { ssize_t s; gfc_unit * u = find_unit (*unit); if (u == NULL) return -1; fbuf_reset (u); if (u->mode == READING) { sflush (u->s); u->mode = WRITING; } s = swrite (u->s, c, 1); unlock_unit (u); if (s < 0) return -1; return 0; }
void ttynam (char ** name, gfc_charlen_type * name_len, int unit) { gfc_unit *u; u = find_unit (unit); if (u != NULL) { *name = xmalloc (TTY_NAME_MAX); int err = stream_ttyname (u->s, *name, TTY_NAME_MAX); if (err == 0) { *name_len = strlen (*name); unlock_unit (u); return; } free (*name); unlock_unit (u); } *name_len = 0; *name = NULL; }
void st_flush (st_parameter_filepos *fpp) { gfc_unit *u; library_start (&fpp->common); u = find_unit (fpp->common.unit); if (u != NULL) { /* Make sure format buffer is flushed. */ if (u->flags.form == FORM_FORMATTED) fbuf_flush (u, u->mode); sflush (u->s); unlock_unit (u); } else /* FLUSH on unconnected unit is illegal: F95 std., 9.3.5. */ generate_error (&fpp->common, LIBERROR_BAD_OPTION, "Specified UNIT in FLUSH is not connected"); library_end (); }
void load_vars(const char *file) { const Unit_t *curr_unit = NULL; int ret = 0; /* to silence gcc 2.7.2.1 */ char *varname; InitPvc_t *pvc; LaneDestList_t *ltmp; int read_flag = 1; assert(file != NULL); Debug_unit(&load_unit, "Loading variables from file %s", file); yyin = fopen(file, "r"); if (!yyin) { Debug_unit(&load_unit, "Cannot open file %s: %s", file, strerror(errno)); return; } g_buf_index = 0; do { if (read_flag) ret = yylex(); else read_flag =1; switch(ret) { case END: Debug_unit(&load_unit, "EOF"); break; case UNIT: Debug_unit(&load_unit, "Got unit %s", g_return.stringgi); curr_unit = find_unit(g_return.stringgi); if (curr_unit == NULL) { Debug_unit(&load_unit, "Unknown unit %s", g_return.stringgi); } Debug_unit(&load_unit, "Got unit %s", g_return.stringgi); mem_free(&load_unit,g_return.stringgi); break; case VARNAME: varname = g_return.stringgi; Debug_unit(&load_unit, "Got variable name %s", varname); ret = yylex(); switch(ret) { case STRING: Debug_unit(&load_unit, "Variable is string: %s", g_return.stringgi); set_var_str(curr_unit, varname, g_return.stringgi); break; case BOOLEAN: Debug_unit(&load_unit, "Variable is boolean: %s", g_return.bool==BL_TRUE?"True":"False"); set_var_bool(curr_unit, varname, g_return.bool); break; case INTEGER: Debug_unit(&load_unit, "Variable is integer: %d", g_return.intti); set_var_int(curr_unit, varname, g_return.intti); break; case ATMADDRESS: Debug_unit(&load_unit, "Variable is atmaddress "); dump_atmaddr(g_return.atmaddress); set_var_addr(curr_unit, varname, g_return.atmaddress); break; case LANEDEST: Debug_unit(&load_unit, "Invalid variable value for %s", varname); mem_free(&load_unit, g_return.destaddr); break; case UNIT: Debug_unit(&load_unit, "Invalid variable value for %s", varname); mem_free(&load_unit, g_return.stringgi); break; case VCC: Debug_unit(&load_unit, "Variable is vcc"); pvc = (InitPvc_t *)mem_alloc(curr_unit, sizeof(InitPvc_t)); pvc->pvc = (LaneVcc_t *)mem_alloc(curr_unit, sizeof(LaneVcc_t)); pvc->pvc->port = g_return.vcc.port; pvc->pvc->vpi = g_return.vcc.vpi; pvc->pvc->vci = g_return.vcc.vci; pvc->address = NULL; pvc->lecid = 0; pvc->destinations = NULL; ret = yylex(); if (ret != ATMADDRESS) { Debug_unit(&load_unit, "Invalid atm_address for pvc %d,%d,%d", pvc->pvc->port, pvc->pvc->vpi, pvc->pvc->vci); switch(ret) { case UNIT: case STRING: case VARNAME: mem_free(&load_unit, g_return.stringgi); break; case LANEDEST: mem_free(&load_unit, g_return.destaddr); break; } } else { pvc->address = g_return.atmaddress; } ret = yylex(); if (ret != INTEGER) { Debug_unit(&load_unit, "Invalid lecid for pvc %d,%d,%d\n", pvc->pvc->port,pvc->pvc->vpi,pvc->pvc->vci); switch(ret) { case UNIT: case STRING: case VARNAME: mem_free(&load_unit, g_return.stringgi); break; case LANEDEST: mem_free(&load_unit, g_return.destaddr); break; case ATMADDRESS: mem_free(&load_unit, g_return.atmaddress); break; } } else { pvc->lecid = g_return.intti; } while((ret=yylex())==LANEDEST) { ltmp=(LaneDestList_t *)mem_alloc(&load_unit, sizeof(LaneDestList_t)); ltmp->addr = g_return.destaddr; ltmp->next = pvc->destinations; pvc->destinations = ltmp; } read_flag=0; set_var_vcc(curr_unit, varname, pvc); break; default: Debug_unit(&load_unit, "Invalid variable value for %s", varname); break; } break; case STRING: Debug_unit(&load_unit,"Invalid string placement %s",g_return.stringgi); mem_free(&load_unit, g_return.stringgi); break; case ATMADDRESS: Debug_unit(&load_unit, "Invalid atm address placement"); mem_free(&load_unit, g_return.atmaddress); break; case LANEDEST: Debug_unit(&load_unit, "Invalid lane destination placement"); mem_free(&load_unit, g_return.destaddr); break; case INTEGER: Debug_unit(&load_unit, "Invalid integer placement"); break; default: Debug_unit(&load_unit, "Invalid input"); break; } } while (ret != END); if (fclose(yyin) != 0) { Debug_unit(&load_unit, "Cannot close file %s: %s", file, strerror(errno)); } }
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 (); }
t_stat vax610_boot_parse (int32 flag, char *ptr) { char gbuf[CBUFSIZE], dbuf[CBUFSIZE], rbuf[CBUFSIZE]; char *slptr, *regptr; int32 i, r5v, unitno; DEVICE *dptr; UNIT *uptr; t_stat r; if (ptr && (*ptr == '/')) { /* handle "BOOT /R5:n DEV" format */ ptr = get_glyph (ptr, rbuf, 0); /* get glyph */ regptr = rbuf; ptr = get_glyph (ptr, gbuf, 0); /* get glyph */ } else { /* handle "BOOT DEV /R5:n" format */ regptr = get_glyph (ptr, gbuf, 0); /* get glyph */ if ((slptr = strchr (gbuf, '/'))) { /* found slash? */ regptr = strchr (ptr, '/'); /* locate orig */ *slptr = 0; /* zero in string */ } } /* parse R5 parameter value */ r5v = 0; if ((strncmp (regptr, "/R5:", 4) == 0) || (strncmp (regptr, "/R5=", 4) == 0) || (strncmp (regptr, "/r5:", 4) == 0) || (strncmp (regptr, "/r5=", 4) == 0)) { r5v = (int32) get_uint (regptr + 4, 16, LMASK, &r); if (r != SCPE_OK) return r; } else if (*regptr == '/') { r5v = (int32) get_uint (regptr + 1, 16, LMASK, &r); if (r != SCPE_OK) return r; } else if (*regptr != 0) return SCPE_ARG; if (gbuf[0]) { unitno = -1; for (i = 0; boot_tab[i].devname != NULL; i++) { if (memcmp (gbuf, boot_tab[i].devalias, strlen(boot_tab[i].devalias)) == 0) { sprintf(dbuf, "%s%s", boot_tab[i].devname, gbuf + strlen(boot_tab[i].devalias)); dptr = find_unit (dbuf, &uptr); if ((dptr == NULL) || (uptr == NULL)) return SCPE_ARG; unitno = (int32) (uptr - dptr->units); } if ((unitno == -1) && (memcmp (gbuf, boot_tab[i].devname, strlen(boot_tab[i].devname)) == 0)) { sprintf(dbuf, "%s%s", boot_tab[i].devname, gbuf + strlen(boot_tab[i].devname)); dptr = find_unit (dbuf, &uptr); if ((dptr == NULL) || (uptr == NULL)) return SCPE_ARG; unitno = (int32) (uptr - dptr->units); } if (unitno == -1) continue; R[0] = boot_tab[i].code | (('0' + unitno) << 24); R[1] = (sys_model ? 0x80 : 0xC0); R[2] = 0; R[3] = 0; R[4] = 0; R[5] = r5v; return SCPE_OK; } } else { R[0] = 0; R[1] = (sys_model ? 0x80 : 0xC0); R[2] = 0; R[3] = 0; R[4] = 0; R[5] = r5v; return SCPE_OK; } return SCPE_NOFNC; }
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 qopen(int *iunit, char *name, char *attribute, int name_l, int attr_l) #endif { #ifdef F77STRING char *name = f77name->str; char *attribute = f77attribute->str; int name_l = f77name->len; int attr_l = f77attribute->len; #endif int unit = find_unit(); Unit *u = units + unit; /* JRK: Style, declarations should be up here. */ int noChars; char oldfilename[327]; char matstr[16]; int mode, errSave; char *modes[4] = {"rb", "rb+", "wb", "wb+"}; char *tailback; struct stat buf; if (unit >= 0) { u->being_used = 1; get_fstr(name, name_l, u->fname, sizeof u->fname); u->write_only = 0; u->read_only = 0; u->pos = 0; get_fstr(attribute, attr_l, matstr, sizeof matstr); if (strncmp(matstr, "RO", 1) == 0){ mode = 0; u->attribute = UNIT_ATBUT_RO; u->read_only = 1; } if (strncmp(matstr, "NEW", 1) == 0){ get_fstr(name, name_l, oldfilename, sizeof u->fname); /* DNM 10/20/03: check for existence of file before making backup, and delete old backup first */ if (!getenv("IMOD_NO_IMAGE_BACKUP") && !stat(oldfilename, &buf)) { oldfilename[strlen(oldfilename) + 1] = 0x00; oldfilename[strlen(oldfilename)] = '~'; remove(oldfilename); errno = 0; if (rename(u->fname, oldfilename)) { errSave = errno; fprintf(stdout, "\nWARNING: qopen - Could not rename '%s' to '%s'" "\n", u->fname, oldfilename); if (errSave) fprintf(stdout, "WARNING: from system - %s\n", strerror(errSave)); } } mode = 3; u->attribute = UNIT_ATBUT_NEW; } if (strncmp(matstr, "OLD", 1) == 0){ mode = 1; u->attribute = UNIT_ATBUT_OLD; } if (strncmp(matstr, "SCRATCH", 1) == 0){ mode = 3; u->attribute = UNIT_ATBUT_SCRATCH; } errno = 0; u->fp = fopen(u->fname, modes[mode]); if (u->fp == NULL) { fprintf(stdout, "\nERROR: qopen - Could not open '%s'\n" , u->fname); errSave = errno; if (errSave) fprintf(stdout, "ERROR: from system - %s\n", strerror(errSave)); exit(3); } *iunit = unit + 1; /* Get the tail of the filename for other error messages */ u->tailName = strrchr(u->fname, '/'); tailback = strrchr(u->fname, '\\'); if (tailback > u->tailName) u->tailName = tailback; if (!u->tailName) u->tailName = &u->fname[0]; else u->tailName++; } else { *iunit = -1; } }
void st_close (st_parameter_close *clp) { close_status status; gfc_unit *u; #if !HAVE_UNLINK_OPEN_FILE char * path; path = NULL; #endif library_start (&clp->common); status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED : find_option (&clp->common, clp->status, clp->status_len, status_opt, "Bad STATUS parameter in CLOSE statement"); if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK) { library_end (); return; } u = find_unit (clp->common.unit); if (u != NULL) { if (close_share (u) < 0) generate_error (&clp->common, LIBERROR_OS, "Problem in CLOSE"); if (u->flags.status == STATUS_SCRATCH) { if (status == CLOSE_KEEP) generate_error (&clp->common, LIBERROR_BAD_OPTION, "Can't KEEP a scratch file on CLOSE"); #if !HAVE_UNLINK_OPEN_FILE path = strdup (u->filename); #endif } else { if (status == CLOSE_DELETE) { if (u->flags.readonly) generate_warning (&clp->common, "STATUS set to DELETE on CLOSE" " but file protected by READONLY specifier"); else { #if HAVE_UNLINK_OPEN_FILE remove (u->filename); #else path = strdup (u->filename); #endif } } } close_unit (u); #if !HAVE_UNLINK_OPEN_FILE if (path != NULL) { remove (path); free (path); } #endif } /* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */ library_end (); }
void st_backspace (st_parameter_filepos *fpp) { gfc_unit *u; library_start (&fpp->common); u = find_unit (fpp->common.unit); if (u == NULL) { generate_error (&fpp->common, LIBERROR_BAD_UNIT, NULL); goto done; } /* Direct access is prohibited, and so is unformatted stream access. */ if (u->flags.access == ACCESS_DIRECT) { generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT, "Cannot BACKSPACE a file opened for DIRECT access"); goto done; } if (u->flags.access == ACCESS_STREAM && u->flags.form == FORM_UNFORMATTED) { generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT, "Cannot BACKSPACE an unformatted stream file"); goto done; } /* Make sure format buffer is flushed and reset. */ if (u->flags.form == FORM_FORMATTED) { int pos = fbuf_reset (u); if (pos != 0) sseek (u->s, pos, SEEK_CUR); } /* Check for special cases involving the ENDFILE record first. */ if (u->endfile == AFTER_ENDFILE) { u->endfile = AT_ENDFILE; u->flags.position = POSITION_APPEND; sflush (u->s); } else { if (stell (u->s) == 0) { u->flags.position = POSITION_REWIND; goto done; /* Common special case */ } if (u->mode == WRITING) { /* If there are previously written bytes from a write with ADVANCE="no", add a record marker before performing the BACKSPACE. */ if (u->previous_nonadvancing_write) finish_last_advance_record (u); u->previous_nonadvancing_write = 0; unit_truncate (u, stell (u->s), &fpp->common); u->mode = READING; } if (u->flags.form == FORM_FORMATTED) formatted_backspace (fpp, u); else unformatted_backspace (fpp, u); u->flags.position = POSITION_UNSPECIFIED; u->endfile = NO_ENDFILE; u->current_record = 0; u->bytes_left = 0; } done: if (u != NULL) unlock_unit (u); library_end (); }
void hero::add_modification(unit_map& units, hero_map& heros, std::vector<team>& teams, const config& mod, unit* u, hero* leader) { foreach (const config &effect, mod.child_range("effect")) { const std::string &apply_to = effect["apply_to"]; if (apply_to == "loyalty") { int increase = effect["increase"].to_int(); if (increase) { increase_catalog(-1 * increase, *leader); if (!u->is_artifical()) { u->adjust(); } // play animation std::stringstream str; str << dgettext("wesnoth", "loyalty") << "\n"; std::vector<unit*> touchers; if (artifical* city = units.city_from_loc(u->get_location())) { touchers.push_back((unit*)(city)); } else { touchers.push_back(u); } unit_display::unit_touching(u->get_location(), touchers, increase, str.str()); } } else if (apply_to == "office") { artifical* selected_city = unit_2_artifical(u); status_ = hero_status_backing; side_ = selected_city->side() - 1; selected_city->finish_heros().push_back(this); std::vector<hero*>& wander_heros = selected_city->wander_heros(); wander_heros.erase(std::find(wander_heros.begin(), wander_heros.end(), this)); std::string message = _("Let me join in. I will do my best to maintenance our honor."); show_hero_message(this, selected_city, message, game_events::INCIDENT_RECOMMENDONESELF); map_location loc2(MAGIC_HERO, number_); game_events::fire("post_recommend", selected_city->get_location(), loc2); } else if (apply_to == "wande") { std::vector<hero*> captains; if (artifical* city = units.city_from_loc(u->get_location())) { // fresh/finish/reside troop if (u->is_city()) { for (int type = 0; type < 3; type ++) { std::vector<hero*>* list; if (type == 0) { list = &city->fresh_heros(); } else if (type == 1) { list = &city->finish_heros(); } else { list = &city->wander_heros(); } std::vector<hero*>::iterator i2 = std::find(list->begin(), list->end(), this); if (i2 != list->end()) { list->erase(i2); break; } } } else { std::vector<unit*>& reside_troops = city->reside_troops(); int index = 0; for (std::vector<unit*>::iterator i2 = reside_troops.begin(); i2 != reside_troops.end(); ++ i2, index ++) { if (*i2 != u) { continue; } u->replace_captains_internal(*this, captains); if (captains.empty()) { city->troop_go_out(index); } else { u->replace_captains(captains); } break; } } } else { // field troop u->replace_captains_internal(*this, captains); if (captains.empty()) { units.erase(u); } else { u->replace_captains(captains); } } // select one city in myself side artifical* to_city = units.city_from_cityno(leader->city_); to_city->wander_into(*this); } else if (apply_to == "communicate") { int increase = effect["increase"].to_int(); std::vector<std::pair<int, unit*> > pairs; for (hero_map::iterator i = heros.begin(); i != heros.end(); ++ i) { const hero& h = *i; if (h.side_ != side_ || h.number_ == number_) { continue; } unit* u = find_unit(units, h); if (u->is_city() && h.number_ == u->master().number_) { continue; } pairs.push_back(std::make_pair<size_t, unit*>(h.number_, u)); } if (increase && !pairs.empty()) { // display hero selection dialog gui2::thero_selection dlg(&teams, &units, heros, pairs, side_ + 1, ""); try { dlg.show(resources::screen->video()); } catch(twml_exception& e) { e.show(*resources::screen); return; } const std::set<size_t>& checked_pairs = dlg.checked_pairs(); if (dlg.get_retval() != gui2::twindow::OK || checked_pairs.empty()) { return; } hero& to = heros[pairs[*checked_pairs.begin()].first]; utils::string_map symbols; symbols["first"] = name(); symbols["second"] = to.name(); game_events::show_hero_message(&heros[214], NULL, vgettext("Feeling between $first and $second is increased.", symbols), game_events::INCIDENT_INVALID); // adjust troop if needed. increase_feeling_each(units, heros, to, increase); } } } }
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 (); }
// Adding a breakpoint. Returns a unique id for the breakpoint. int XDebugThreadBreakpoints::addBreakpoint(XDebugBreakpoint& bp) { auto const id = s_xdebug_breakpoints->m_nextBreakpointId; // php5 xdebug only accepts multiple breakpoints of the same type for // line breakpoints. A useful addition might be to allow multiple of all // types, but for now, multiple function or exception breakpoints results // in the most recent silently being used (matching php5 xdebug). switch (bp.type) { case BreakType::EXCEPTION: { // Remove duplicates then insert the name auto exceptionName = bp.exceptionName.toCppString(); auto iter = EXCEPTION_MAP.find(exceptionName); if (iter != EXCEPTION_MAP.end()) { XDEBUG_REMOVE_BREAKPOINT(iter->second); } EXCEPTION_MAP[exceptionName] = id; break; } // Attempt to find the unit/line combo case BreakType::LINE: { const Unit* unit = find_unit(bp.fileName); if (unit == nullptr) { UNMATCHED.insert(id); break; } // If the file/line combo is invalid, throw an error if (!phpAddBreakPointLine(unit, bp.line)) { throw XDebugServer::ERROR_BREAKPOINT_INVALID; } add_line_breakpoint(id, bp, unit); break; } // Try to find the breakpoint's function case BreakType::CALL: case BreakType::RETURN: { const Class* cls = nullptr; const Func* func = nullptr; if (bp.className.isNull()) { func = Unit::lookupFunc(bp.funcName.get()); } else { cls = Unit::lookupClass(bp.className.toString().get()); if (cls != nullptr) { func = cls->lookupMethod(bp.funcName.get()); } } // Either add the breakpoint or store it as unmatched. If the class // exists, we can verify that the method is valid. if (func != nullptr) { add_func_breakpoint(id, bp, func); } else if (!bp.className.isNull() && cls != nullptr) { throw XDebugServer::ERROR_BREAKPOINT_INVALID; } else { UNMATCHED.insert(id); } break; } } // Success, store the breakpoint and increment the id. BREAKPOINT_MAP[id] = bp; s_xdebug_breakpoints->m_nextBreakpointId++; return id; }
int main(int argc, char * argv[]) { char * filename; char * basedir; FILE *fd; char line[PATH_MAX]; if (argc < 3) { fprintf(stderr, "Usage: trFilelist synclist_filename basedir\n"); exit(-1); } filename = argv[1]; basedir = argv[2]; init_string_list(&file_list, 10); init_uint_list(&ino_list, 10); init_string_list(&dir_list, 100); init_string_list(&softlink_list, 10); init_string_list(&newdir_list, 100); get_dir_softlinks(filename, basedir); if ((fd = fopen(filename, "r")) == NULL) { fprintf(stderr, "Cannot open file -- %s \n", filename); return -1; } while (1) { /* for each line in the file */ char *pc; char fn[PATH_MAX]; struct stat st; int newdir_flag; if (fgets(line, PATH_MAX, fd)==NULL) break; strip(line); if (strlen(line) == 0) continue; /* skip blank line */ if (strcmp(line, ".")==0) continue; if (strcmp(line, "./")==0) continue; /* first we look for deleting entry */ if (strncmp(line, "deleting ", 9)==0) { /* deleting (directory) file_path */ char * p1, *p2, *pf; p1 = strstr(line, " "); /* the first space */ p2 = strstr(p1+1, " "); /* deleting directory filepath * 20070912 this is old */ pf = (p2) ? p2+1 : p1+1;/* it's always p1+1 */ newdir_flag = has_newdir(pf, &newdir_list); if ((has_sub_string(pf, &softlink_list)<0) && newdir_flag<0) { /* see comments above get_dir_softlinks() */ printf("deleting %s\n", pf); } else if (newdir_flag>=0) { /* temporary action */ /*** we can simply skip this block later. 20070912 ***/ /***/ fprintf(stderr, "CRITICAL ERROR: An old softlink has been changed to a directory!\n"); fprintf(stderr, " For now, we crash this code for human intervention\n"); fprintf(stderr, " line= %s\n", line); exit(-1); /***/ } continue; } /* the softlink case is indicated by -> */ pc= strstr(line, " -> "); if (pc) { *pc = '\0'; output_subs(line); printf("%s\n", line); continue; } /* if rsync's -H is turned on, the output may contain file => tar_hardlink_file (relative address) */ pc= strstr(line, " => "); if (pc) { *pc = '\0'; output_subs(line); printf("%s %s\n", line, pc+4); continue; } /* the rest of the entries should be valid paths */ sprintf(fn, "%s/%s", basedir, line); if (lstat(fn, &st)<0) continue; /* We skip this bad entry - (1) the header and tail lines (2) perhaps the file no longer exists */ /* is this a hardlink? */ if (st.st_nlink > 1) { int index; output_subs(line); if ((index = find_unit((unsigned int)st.st_ino, &ino_list))<0) { append_uint_list((unsigned int)st.st_ino, &ino_list); append_string_list(line, &file_list); /* relative path */ printf("%s\n", line); } else { printf("%s %s\n", line, file_list.str[index]); } continue; } /* all others */ output_subs(line); printf("%s\n", line); } /* end of one line */ fclose(fd); return 0; }