static void snapshotline(register uchar * l) { register int c; do { if ((c = *l++) == SDELIM && *l++ != SDELIM) return; out_putc(c); } while (c != '\n'); }
/* - regdump - dump a regexp onto stdout in vaguely comprehensible form */ void regdump( regexp *r ) { register char *s; register char op = EXACTLY; /* Arbitrary non-END op. */ register char *next; s = r->program + 1; while (op != END) { /* While that wasn't END last time... */ op = OP(s); out_printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */ next = regnext(s); if (next == NULL) /* Next ptr. */ out_printf("(0)"); else out_printf("(%d)", (s-r->program)+(next-s)); s += 3; if (op == ANYOF || op == ANYBUT || op == EXACTLY) { /* Literal string, where present. */ while (*s != '\0') { out_putc(*s); s++; } s++; } out_putc('\n'); } /* Header fields of interest. */ if (r->regstart != '\0') out_printf("start `%c' ", r->regstart); if (r->reganch) out_printf("anchored "); if (r->regmust != NULL) out_printf("must have \"%s\"", r->regmust); out_printf("\n"); }
static void escape_string(register char const *s) { register char c; for (;;) { switch ((c = *s++)) { case 0: return; case '\t': out_fputs("\\t"); break; case '\n': out_fputs("\\n"); break; case ' ': out_fputs("\\040"); break; case KDELIM: out_fputs("\\044"); break; case '\\': out_fputs("\\\\"); break; default: out_putc(c); break; } } }
void out_action ( char const * const action, char const * const target, char const * const command, char const * const out_d, char const * const err_d, int const exit_reason ) { /* Print out the action + target line, if the action is quiet the action * should be null. */ if ( action ) out_printf( "%s %s\n", action, target ); /* Print out the command executed if given -d+2. */ if ( DEBUG_EXEC ) { out_puts( command ); out_putc( '\n' ); } /* If the process expired, make user aware with an explicit message, but do * this only for non-quiet actions. */ if ( exit_reason == EXIT_TIMEOUT && action ) out_printf( "%ld second time limit exceeded\n", globs.timeout ); /* Print out the command output, if requested, or if the program failed, but * only output for non-quiet actions. */ if ( action || exit_reason != EXIT_OK ) { if ( out_d && ( ( globs.pipe_action & 1 /* STDOUT_FILENO */ ) || ( globs.pipe_action == 0 ) ) ) out_data( out_d ); if ( err_d && ( globs.pipe_action & 2 /* STDERR_FILENO */ ) ) err_data( err_d ); } out_flush(); err_flush(); }
static int expandline(void) { register int c = 0; char * tp; register int e, r; char const *tlim; enum markers matchresult; int orig_size; if (Gkvlen < KEYLENGTH+3) { Gkvlen = KEYLENGTH + 3; Gkeyval = xrealloc(Gkeyval, Gkvlen); } e = 0; r = -1; for (;;) { c = in_buffer_getc(); for (;;) { switch (c) { case EOF: goto uncache_exit; default: out_putc(c); r = 0; break; case '\n': out_putc(c); r = 2; goto uncache_exit; case KDELIM: r = 0; /* check for keyword */ /* first, copy a long enough string into keystring */ tp = Gkeyval; *tp++ = KDELIM; for (;;) { c = in_buffer_getc(); if (tp <= &Gkeyval[KEYLENGTH] && latin1_alpha(c)) *tp++ = c; else break; } *tp++ = c; *tp = '\0'; matchresult = trymatch(Gkeyval+1); if (matchresult==Nomatch) { tp[-1] = 0; out_fputs(Gkeyval); continue; /* last c handled properly */ } /* Now we have a keyword terminated with a K/VDELIM */ if (c==VDELIM) { /* try to find closing KDELIM, and replace value */ tlim = Gkeyval + Gkvlen; for (;;) { c = in_buffer_getc(); if (c=='\n' || c==KDELIM) break; *tp++ =c; if (tlim <= tp) { orig_size = Gkvlen; Gkvlen *= 2; Gkeyval = xrealloc(Gkeyval, Gkvlen); tlim = Gkeyval + Gkvlen; tp = Gkeyval + orig_size; } if (c==EOF) goto keystring_eof; } if (c!=KDELIM) { /* couldn't find closing KDELIM -- give up */ *tp = 0; out_fputs(Gkeyval); continue; /* last c handled properly */ } } /* * CVS will expand keywords that have * overlapping delimiters, eg "$Name$Id$". To * support that (mis)feature, push the closing * delimiter back on the input so that the * loop will resume processing starting with * it. */ if (c == KDELIM) in_buffer_ungetc(); /* now put out the new keyword value */ keyreplace(matchresult); e = 1; break; } break; } } keystring_eof: *tp = 0; out_fputs(Gkeyval); uncache_exit: return r + e; }
/* output the appropriate keyword value(s) */ static void keyreplace(enum markers marker) { const char *target_lockedby = NULL; // Not wired in yet char const *xxp; char *leader = NULL; char date_string[25]; uchar *kdelim_ptr = NULL; enum expand_mode exp = Gexpand; char const *sp = Keyword[(int)marker]; strftime(date_string, 25, "%Y/%m/%d %H:%M:%S", localtime(&Gversion->date)); if (exp != EXPANDKV) out_printf("%c%s", KDELIM, sp); if (exp != EXPANDKK) { if (exp != EXPANDKV) out_printf("%c%c", VDELIM, ' '); switch (marker) { case Author: out_fputs(Gversion->author); break; case Date: out_fputs(date_string); break; case Id: case Header: if (marker == Id ) escape_string(basefilename(Gfilename)); else escape_string(getfullRCSname()); out_printf(" %s %s %s %s", Gversion_number, date_string, Gversion->author, Gversion->state); if (target_lockedby && exp == EXPANDKKVL) out_printf(" %s", target_lockedby); break; case Locker: if (target_lockedby && exp == EXPANDKKVL) out_fputs(target_lockedby); break; case Log: case RCSfile: escape_string(basefilename(Gfilename)); break; case Revision: out_fputs(Gversion_number); break; case Source: escape_string(getfullRCSname()); break; case State: out_fputs(Gversion->state); break; default: break; } if (exp != EXPANDKV) out_putc(' '); } #if 0 /* Closing delimiter is processed again in expandline */ if (exp != EXPANDKV) out_putc(KDELIM); #endif if (marker == Log) { int c; size_t cs, cw, ls; /* * "Closing delimiter is processed again in expandline" * does not apply here, since we consume the input. */ if (exp != EXPANDKV) out_putc(KDELIM); sp = Glog; ls = strlen(Glog); if (sizeof(ciklog)-1<=ls && !memcmp(sp,ciklog,sizeof(ciklog)-1)) return; /* Back up to the start of the current input line */ int num_kdelims = 0; for (;;) { c = in_buffer_ungetc(); if (c == EOF) break; if (c == '\n') { in_buffer_getc(); break; } if (c == KDELIM) { num_kdelims++; /* It is possible to have multiple keywords on one line. Make sure we don't backtrack into some other keyword! */ if (num_kdelims > 2) { in_buffer_getc(); break; } kdelim_ptr = in_buffer_loc(); } } /* Copy characters before `$Log' into LEADER. */ xxp = leader = xmalloc(kdelim_ptr - in_buffer_loc()); for (cs = 0; ; cs++) { c = in_buffer_getc(); if (c == KDELIM) break; leader[cs] = c; } /* Convert traditional C or Pascal leader to ` *'. */ for (cw = 0; cw < cs; cw++) if (!latin1_whitespace(xxp[cw])) break; if (cw+1 < cs && xxp[cw+1] == '*' && (xxp[cw] == '/' || xxp[cw] == '(')) { size_t i = cw+1; for (;;) { if (++i == cs) { leader[cw] = ' '; break; } else if (!latin1_whitespace(xxp[i])) break; } } /* Skip `$Log ... $' string. */ do { c = in_buffer_getc(); } while (c != KDELIM); out_putc('\n'); out_awrite(xxp, cs); out_printf("Revision %s %s %s", Gversion_number, date_string, Gversion->author); /* Do not include state: it may change and is not updated. */ cw = cs; for (; cw && (xxp[cw-1]==' ' || xxp[cw-1]=='\t'); --cw) ; for (;;) { out_putc('\n'); out_awrite(xxp, cw); if (!ls) break; --ls; c = *sp++; if (c != '\n') { out_awrite(xxp+cw, cs-cw); do { out_putc(c); if (!ls) break; --ls; c = *sp++; } while (c != '\n'); } } free(leader); } }
static void out_awrite(char const *s, size_t len) { while (len--) out_putc(*s++); }
static int out_fputs(const char *s) { while (*s) out_putc(*s++); return 0; }