Evaluation eval(const Evaluation& x, const Evaluation& y) const { typedef MathToolbox<Evaluation> Toolbox; #ifndef NDEBUG if (!applies(x,y)) { OPM_THROW(NumericalProblem, "Attempt to get tabulated value for (" << x << ", " << y << ") on a table of extend " << xMin() << " to " << xMax() << " times " << yMin() << " to " << yMax()); }; #endif Evaluation alpha = xToI(x); Evaluation beta = yToJ(y); unsigned i = std::max(0U, std::min(static_cast<unsigned>(numX()) - 2, static_cast<unsigned>(Toolbox::value(alpha)))); unsigned j = std::max(0U, std::min(static_cast<unsigned>(numY()) - 2, static_cast<unsigned>(Toolbox::value(beta)))); alpha -= i; beta -= j; // bi-linear interpolation const Evaluation& s1 = getSamplePoint(i, j)*(1.0 - alpha) + getSamplePoint(i + 1, j)*alpha; const Evaluation& s2 = getSamplePoint(i, j + 1)*(1.0 - alpha) + getSamplePoint(i + 1, j + 1)*alpha; return s1*(1.0 - beta) + s2*beta; }
bool SetBrushFaceAttributesTool::performCopy(const InputState& inputState, const bool applyToBrush) { if (!applies(inputState)) return false; MapDocumentSPtr document = lock(m_document); const Model::BrushFaceList& selectedFaces = document->selectedBrushFaces(); if (selectedFaces.size() != 1) return false; const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Model::BrushFace* source = selectedFaces.front(); Model::BrushFace* targetFace = Model::hitToFace(hit); Model::Brush* targetBrush = targetFace->brush(); const Model::BrushFaceList targetList = applyToBrush ? targetBrush->faces() : Model::BrushFaceList(1, targetFace); const Transaction transaction(document); document->deselectAll(); document->select(targetList); if (copyAttributes(inputState)) document->setFaceAttributes(source->attribs()); else document->setTexture(source->texture()); document->deselectAll(); document->select(source); return true; }
void process(void) { struct s_command *cp; SPACE tspace; size_t oldpsl = 0; char *p; p = NULL; for (linenum = 0; mf_fgets(&PS, REPLACE);) { pd = 0; top: cp = prog; redirect: while (cp != NULL) { if (!applies(cp)) { cp = cp->next; continue; } switch (cp->code) { case '{': cp = cp->u.c; goto redirect; case 'a': if (appendx >= appendnum) if ((appends = realloc(appends, sizeof(struct s_appends) * (appendnum *= 2))) == NULL) err(1, "realloc"); appends[appendx].type = AP_STRING; appends[appendx].s = cp->t; appends[appendx].len = strlen(cp->t); appendx++; break; case 'b': cp = cp->u.c; goto redirect; case 'c': pd = 1; psl = 0; if (cp->a2 == NULL || lastaddr || lastline()) (void)fprintf(outfile, "%s", cp->t); break; case 'd': pd = 1; goto new; case 'D': if (pd) goto new; if (psl == 0 || (p = memchr(ps, '\n', psl)) == NULL) { pd = 1; goto new; } else { psl -= (p + 1) - ps; memmove(ps, p + 1, psl); goto top; } case 'g': cspace(&PS, hs, hsl, REPLACE); break; case 'G': cspace(&PS, "\n", 1, APPEND); cspace(&PS, hs, hsl, APPEND); break; case 'h': cspace(&HS, ps, psl, REPLACE); break; case 'H': cspace(&HS, "\n", 1, APPEND); cspace(&HS, ps, psl, APPEND); break; case 'i': (void)fprintf(outfile, "%s", cp->t); break; case 'l': lputs(ps, psl); break; case 'n': if (!nflag && !pd) OUT(); flush_appends(); if (!mf_fgets(&PS, REPLACE)) exit(0); pd = 0; break; case 'N': flush_appends(); cspace(&PS, "\n", 1, APPEND); if (!mf_fgets(&PS, APPEND)) exit(0); break; case 'p': if (pd) break; OUT(); break; case 'P': if (pd) break; if ((p = memchr(ps, '\n', psl)) != NULL) { oldpsl = psl; psl = p - ps; } OUT(); if (p != NULL) psl = oldpsl; break; case 'q': if (!nflag && !pd) OUT(); flush_appends(); exit(0); case 'r': if (appendx >= appendnum) if ((appends = realloc(appends, sizeof(struct s_appends) * (appendnum *= 2))) == NULL) err(1, "realloc"); appends[appendx].type = AP_FILE; appends[appendx].s = cp->t; appends[appendx].len = strlen(cp->t); appendx++; break; case 's': sdone |= substitute(cp); break; case 't': if (sdone) { sdone = 0; cp = cp->u.c; goto redirect; } break; case 'w': if (pd) break; if (cp->u.fd == -1 && (cp->u.fd = open(cp->t, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) err(1, "%s", cp->t); if (write(cp->u.fd, ps, psl) != (ssize_t)psl || write(cp->u.fd, "\n", 1) != 1) err(1, "%s", cp->t); break; case 'x': /* * If the hold space is null, make it empty * but not null. Otherwise the pattern space * will become null after the swap, which is * an abnormal condition. */ if (hs == NULL) cspace(&HS, "", 0, REPLACE); tspace = PS; PS = HS; HS = tspace; break; case 'y': if (pd || psl == 0) break; do_tr(cp->u.y); break; case ':': case '}': break; case '=': (void)fprintf(outfile, "%lu\n", linenum); } cp = cp->next; } /* for all cp */
int check_su_auth (const char *actual_id, const char *wanted_id, bool su_to_root) { int posn, endline; const char field[] = ":"; FILE *authfile_fd; char temp[1024]; char *to_users; char *from_users; char *action; if (!(authfile_fd = fopen (SUAUTHFILE, "r"))) { int err = errno; /* * If the file doesn't exist - default to the standard su * behaviour (no access control). If open fails for some * other reason - maybe someone is trying to fool us with * file descriptors limit etc., so deny access. --marekm */ if (ENOENT == err) { return NOACTION; } SYSLOG ((LOG_ERR, "could not open/read config file '%s': %s\n", SUAUTHFILE, strerror (err))); return DENY; } while (fgets (temp, sizeof (temp), authfile_fd) != NULL) { lines++; if (temp[endline = strlen (temp) - 1] != '\n') { SYSLOG ((LOG_ERR, "%s, line %d: line too long or missing newline", SUAUTHFILE, lines)); continue; } while (endline > 0 && (temp[endline - 1] == ' ' || temp[endline - 1] == '\t' || temp[endline - 1] == '\n')) endline--; temp[endline] = '\0'; posn = 0; while (temp[posn] == ' ' || temp[posn] == '\t') posn++; if (temp[posn] == '\n' || temp[posn] == '#' || temp[posn] == '\0') { continue; } if (!(to_users = strtok (temp + posn, field)) || !(from_users = strtok ((char *) NULL, field)) || !(action = strtok ((char *) NULL, field)) || strtok ((char *) NULL, field)) { SYSLOG ((LOG_ERR, "%s, line %d. Bad number of fields.\n", SUAUTHFILE, lines)); continue; } if (!applies (wanted_id, to_users)) continue; if (!applies (actual_id, from_users)) continue; if (!strcmp (action, "DENY")) { SYSLOG ((su_to_root ? LOG_WARN : LOG_NOTICE, "DENIED su from '%s' to '%s' (%s)\n", actual_id, wanted_id, SUAUTHFILE)); fputs (_("Access to su to that account DENIED.\n"), stderr); fclose (authfile_fd); return DENY; } else if (!strcmp (action, "NOPASS")) { SYSLOG ((su_to_root ? LOG_NOTICE : LOG_INFO, "NO password asked for su from '%s' to '%s' (%s)\n", actual_id, wanted_id, SUAUTHFILE)); fputs (_("Password authentication bypassed.\n"),stderr); fclose (authfile_fd); return NOPWORD; } else if (!strcmp (action, "OWNPASS")) { SYSLOG ((su_to_root ? LOG_NOTICE : LOG_INFO, "su from '%s' to '%s': asking for user's own password (%s)\n", actual_id, wanted_id, SUAUTHFILE)); fputs (_("Please enter your OWN password as authentication.\n"), stderr); fclose (authfile_fd); return OWNPWORD; } else { SYSLOG ((LOG_ERR, "%s, line %d: unrecognised action!\n", SUAUTHFILE, lines)); } } fclose (authfile_fd); return NOACTION; }
void process(void) { struct s_command *cp; SPACE tspace; size_t len, oldpsl; char *p; oldpsl = 0; for (linenum = 0; mf_fgets(&PS, REPLACE);) { pd = 0; top: cp = prog; redirect: while (cp != NULL) { if (!applies(cp)) { cp = cp->next; continue; } switch (cp->code) { case '{': cp = cp->u.c; goto redirect; case 'a': if (appendx >= appendnum) { appends = xrealloc(appends, sizeof(struct s_appends) * (appendnum * 2)); appendnum *= 2; } appends[appendx].type = AP_STRING; appends[appendx].s = cp->t; appends[appendx].len = strlen(cp->t); appendx++; break; case 'b': cp = cp->u.c; goto redirect; case 'c': pd = 1; psl = 0; if (cp->a2 == NULL || lastaddr) (void)printf("%s", cp->t); break; case 'd': pd = 1; goto new; case 'D': if (psl == 0) pd = 1; if (pd) goto new; if ((p = memchr(ps, '\n', psl - 1)) == NULL) { pd = 1; goto new; } else { psl -= (p + 1) - ps; memmove(ps, p + 1, psl); goto top; } case 'g': cspace(&PS, hs, hsl, REPLACE); break; case 'G': if (hs == NULL) cspace(&HS, "\n", 1, REPLACE); cspace(&PS, hs, hsl, 0); break; case 'h': cspace(&HS, ps, psl, REPLACE); break; case 'H': cspace(&HS, ps, psl, 0); break; case 'i': (void)printf("%s", cp->t); break; case 'l': lputs(ps); break; case 'n': if (!nflag && !pd) OUT(ps) flush_appends(); if (!mf_fgets(&PS, REPLACE)) exit(0); pd = 0; break; case 'N': flush_appends(); if (!mf_fgets(&PS, 0)) { if (!nflag && !pd) OUT(ps) exit(0); } break; case 'p': if (pd) break; OUT(ps) break; case 'P': if (pd) break; if ((p = memchr(ps, '\n', psl - 1)) != NULL) { oldpsl = psl; psl = (p + 1) - ps; } OUT(ps) if (p != NULL) psl = oldpsl; break; case 'q': if (!nflag && !pd) OUT(ps) flush_appends(); exit(0); case 'r': if (appendx >= appendnum) { appends = xrealloc(appends, sizeof(struct s_appends) * (appendnum * 2)); appendnum *= 2; } appends[appendx].type = AP_FILE; appends[appendx].s = cp->t; appends[appendx].len = strlen(cp->t); appendx++; break; case 's': sdone |= substitute(cp); break; case 't': if (sdone) { sdone = 0; cp = cp->u.c; goto redirect; } break; case 'w': if (pd) break; if (cp->u.fd == -1 && (cp->u.fd = open(cp->t, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) err(FATAL, "%s: %s", cp->t, strerror(errno)); if ((size_t)write(cp->u.fd, ps, psl) != psl) err(FATAL, "%s: %s", cp->t, strerror(errno)); break; case 'x': if (hs == NULL) cspace(&HS, "\n", 1, REPLACE); tspace = PS; PS = HS; HS = tspace; break; case 'y': if (pd) break; for (p = ps, len = psl; --len; ++p) *p = cp->u.y[(int)*p]; break; case ':': case '}': break; case '=': (void)printf("%lu\n", linenum); } cp = cp->next; } /* for all cp */