static void proc_line(struct prln_ctx_s ctx, char *line, size_t llen) { struct dt_dt_s d; char *sp = NULL; char *ep = NULL; do { d = dt_io_find_strpdt2(line, ctx.ndl, &sp, &ep, ctx.fromz); /* check if line matches */ if (!dt_unk_p(d) && ctx.sed_mode_p) { __io_write(line, sp - line, stdout); dt_io_write(d, ctx.ofmt, ctx.outz, '\0'); llen -= (ep - line); line = ep; } else if (!dt_unk_p(d)) { dt_io_write(d, ctx.ofmt, ctx.outz, '\n'); break; } else if (ctx.sed_mode_p) { line[llen] = '\n'; __io_write(line, llen + 1, stdout); break; } else { /* obviously unmatched, warn about it in non -q mode */ if (!ctx.quietp) { dt_io_warn_strpdt(line); } break; } } while (1); return; }
static void proc_line(struct prln_ctx_s ctx, char *line, size_t llen) { char *osp = NULL; char *oep = NULL; /* check if line matches, * there's currently no way to specify NEEDLE */ for (char *lp = line, *sp, *ep; ; lp = ep, osp = sp, oep = ep) { struct dt_dt_s d = dt_io_find_strpdt2(lp, ctx.ndl, &sp, &ep, ctx.fromz); bool unkp = dt_unk_p(d); if (unkp) { /* just plain nothing */ break; } else if (ctx.z != NULL) { /* promote to zone ctx.z */ d = dtz_enrichz(d, ctx.z); } /* otherwise */ if (dexpr_matches_p(ctx.root, d)) { if (ctx.invert_match_p) { /* nothing must match */ return; } else if (!ctx.only_matching_p) { sp = line; ep = line + llen; } /* make sure we finish the line */ *ep++ = '\n'; __io_write(sp, ep - sp, stdout); return; } } if (ctx.invert_match_p) { /* no match but invert_match select, print line */ if (!ctx.only_matching_p) { osp = line; oep = line + llen; } else if (osp == NULL || oep == NULL) { /* no date in line and only-matching is active * bugger off */ return; } /* finish the line and bugger off */ *oep++ = '\n'; __io_write(osp, oep - osp, stdout); } return; }
static int proc_line(const struct mass_add_clo_s *clo, char *line, size_t llen) { struct dt_dt_s d; char *sp = NULL; char *ep = NULL; int rc = 0; do { /* check if line matches, */ d = dt_io_find_strpdt2( line, llen, clo->gra, &sp, &ep, clo->fromz); if (!dt_unk_p(d)) { if (UNLIKELY(d.fix) && !clo->quietp) { rc = 2; } /* perform addition now */ d = dadd_add(d, clo->st.durs, clo->st.ndurs); if (clo->hackz == NULL && clo->fromz != NULL) { /* fixup zone */ d = dtz_forgetz(d, clo->fromz); } if (clo->sed_mode_p) { __io_write(line, sp - line, stdout); dt_io_write(d, clo->ofmt, clo->z, '\0'); llen -= (ep - line); line = ep; } else { dt_io_write(d, clo->ofmt, clo->z, '\n'); break; } } else if (clo->sed_mode_p) { line[llen] = '\n'; __io_write(line, llen + 1, stdout); break; } else { /* obviously unmatched, warn about it in non -q mode */ if (!clo->quietp) { dt_io_warn_strpdt(line); rc = 2; } break; } } while (1); return rc; }
static int proc_line(struct prln_ctx_s ctx, char *line, size_t llen) { struct dt_dt_s d; char *sp = NULL; char *ep = NULL; int rc = 0; do { /* check if line matches, */ d = dt_io_find_strpdt2( line, llen, ctx.ndl, &sp, &ep, ctx.fromz); if (!dt_unk_p(d)) { if (UNLIKELY(d.fix) && !ctx.quietp) { rc = 2; } /* perform addition now */ d = dround(d, ctx.st->durs, ctx.st->ndurs, ctx.nextp); if (ctx.hackz == NULL && ctx.fromz != NULL) { /* fixup zone */ d = dtz_forgetz(d, ctx.fromz); } if (ctx.sed_mode_p) { __io_write(line, sp - line, stdout); dt_io_write(d, ctx.ofmt, ctx.outz, '\0'); llen -= (ep - line); line = ep; } else { dt_io_write(d, ctx.ofmt, ctx.outz, '\n'); break; } } else if (ctx.sed_mode_p) { line[llen] = '\n'; __io_write(line, llen + 1, stdout); break; } else { /* obviously unmatched, warn about it in non -q mode */ if (!ctx.quietp) { dt_io_warn_strpdt(line); rc = 2; } break; } } while (1); return rc; }
static int mass_add_d(const struct mass_add_clo_s *clo) { /* read lines from stdin * interpret as durations * add to reference date * output */ size_t lno = 0; struct dt_dt_s d; struct __strpdtdur_st_s st = __strpdtdur_st_initialiser(); int rc = 0; for (char *line; prchunk_haslinep(clo->pctx); lno++) { size_t llen; int has_dur_p = 1; llen = prchunk_getline(clo->pctx, &line); /* check for durations on this line */ do { if (dt_io_strpdtdur(&st, line) < 0) { has_dur_p = 0; } } while (__strpdtdur_more_p(&st)); /* finish with newline again */ line[llen] = '\n'; if (has_dur_p) { if (UNLIKELY(clo->rd.fix) && !clo->quietp) { rc = 2; } /* perform addition now */ d = dadd_add(clo->rd, st.durs, st.ndurs); if (clo->hackz == NULL && clo->fromz != NULL) { /* fixup zone */ d = dtz_forgetz(d, clo->fromz); } /* no sed mode here */ dt_io_write(d, clo->ofmt, clo->z, '\n'); } else if (clo->sed_mode_p) { __io_write(line, llen + 1, stdout); } else if (!clo->quietp) { line[llen] = '\0'; dt_io_warn_strpdt(line); rc = 2; } /* just reset the ndurs slot */ st.ndurs = 0; } /* free associated duration resources */ __strpdtdur_free(&st); return rc; }
/* Write up to N chars from BUF to COOKIE. Return how many chars were written or -1 for error. */ static ssize_t writeio (void *cookie, const char *buf, size_t n) { mach_msg_type_number_t wrote; error_t err; if (err = __io_write ((io_t) cookie, buf, n, -1, &wrote)) return __hurd_fail (err); return wrote; }
error_t _hurd_fd_write (struct hurd_fd *fd, const void *buf, size_t *nbytes, loff_t offset) { error_t err; mach_msg_type_number_t wrote; error_t writefd (io_t port) { return __io_write (port, buf, *nbytes, offset, &wrote); } err = HURD_FD_PORT_USE (fd, _hurd_ctty_output (port, ctty, writefd)); if (! err) *nbytes = wrote; return err; }
You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <ansidecl.h> #include <stdarg.h> #include <stdio.h> #include <string.h> #include <hurd.h> static ssize_t DEFUN(pwrite, (cookie, buf, n), PTR cookie AND CONST char *buf AND size_t n) { error_t error = __io_write ((io_t) cookie, buf, n, -1, &n); if (error) return __hurd_fail (error); return n; } /* Write formatted output to PORT, a Mach port supporting the i/o protocol, according to the format string FORMAT, using the argument list in ARG. */ int DEFUN(vpprintf, (port, format, arg), io_t port AND CONST char *format AND va_list arg) { int done; FILE f;