* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* Henry Spencer of the University of Toronto.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)engine.c 8.4 (Berkeley) 3/19/94
* The matching engine and friends. This file is #included by regexec.c
* after suitable #defines of a variety of macros used herein, so that
* different state representations can be used without duplicating masses
/* another structure passed up and down to avoid zillions of parameters */
regmatch_t
*pmatch
; /* [nsub+1] (0 element unused) */
char *offp
; /* offsets work from here */
char *beginp
; /* start of string -- virtual NUL precedes */
char *endp
; /* end of string -- virtual NUL here */
char *coldp
; /* can be no match starting before here */
char **lastpos
; /* [nplus+1] */
states st
; /* current states */
states fresh
; /* states for a fresh start */
states tmp
; /* temporary */
states empty
; /* empty set of states */
/* ========= begin header generated by ./mkh ========= */
static int matcher
__P((struct re_guts
*g
, char *string
, size_t nmatch
, regmatch_t pmatch
[], int eflags
));
static char *dissect
__P((struct match
*m
, char *start
, char *stop
, sopno startst
, sopno stopst
));
static char *backref
__P((struct match
*m
, char *start
, char *stop
, sopno startst
, sopno stopst
, sopno lev
));
static char *fast
__P((struct match
*m
, char *start
, char *stop
, sopno startst
, sopno stopst
));
static char *slow
__P((struct match
*m
, char *start
, char *stop
, sopno startst
, sopno stopst
));
static states step
__P((struct re_guts
*g
, sopno start
, sopno stop
, states bef
, int ch
, states aft
));
#define CODEMAX (BOL+5) /* highest code used */
#define NONCHAR(c) ((c) > CHAR_MAX)
#define NNONCHAR (CODEMAX-CHAR_MAX)
static void print
__P((struct match
*m
, char *caption
, states st
, int ch
, FILE *d
));
static void at
__P((struct match
*m
, char *title
, char *start
, char *stop
, sopno startst
, sopno stopst
));
static char *pchar
__P((int ch
));
/* ========= end header generated by ./mkh ========= */
#define SP(t, s, c) print(m, t, s, c, stdout)
#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
#define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); }
#define SP(t, s, c) /* nothing */
#define AT(t, p1, p2, s1, s2) /* nothing */
#define NOTE(s) /* nothing */
- matcher - the actual matching engine
== static int matcher(register struct re_guts *g, char *string, \
== size_t nmatch, regmatch_t pmatch[], int eflags);
static int /* 0 success, REG_NOMATCH failure */
matcher(g
, string
, nmatch
, pmatch
, eflags
)
register struct re_guts
*g
;
register struct match
*m
= &mv
;
const register sopno gf
= g
->firststate
+1; /* +1 for OEND */
const register sopno gl
= g
->laststate
;
/* simplify the situation where possible */
if (eflags
®_STARTEND
) {
start
= string
+ pmatch
[0].rm_so
;
stop
= string
+ pmatch
[0].rm_eo
;
stop
= start
+ strlen(start
);
/* prescreening; this does wonders for this rather slow code */
for (dp
= start
; dp
< stop
; dp
++)
if (*dp
== g
->must
[0] && stop
- dp
>= g
->mlen
&&
memcmp(dp
, g
->must
, (size_t)g
->mlen
) == 0)
if (dp
== stop
) /* we didn't find g->must */
/* this loop does only one repetition except for backrefs */
endp
= fast(m
, start
, stop
, gf
, gl
);
if (endp
== NULL
) { /* a miss */
if (nmatch
== 0 && !g
->backrefs
)
break; /* no further info needed */
assert(m
->coldp
!= NULL
);
endp
= slow(m
, m
->coldp
, stop
, gf
, gl
);
assert(m
->coldp
< m
->endp
);
if (nmatch
== 1 && !g
->backrefs
)
break; /* no further info needed */
/* oh my, he wants the subexpressions... */
m
->pmatch
= (regmatch_t
*)malloc((m
->g
->nsub
+ 1) *
for (i
= 1; i
<= m
->g
->nsub
; i
++)
m
->pmatch
[i
].rm_so
= m
->pmatch
[i
].rm_eo
= -1;
if (!g
->backrefs
&& !(m
->eflags
®_BACKR
)) {
dp
= dissect(m
, m
->coldp
, endp
, gf
, gl
);
if (g
->nplus
> 0 && m
->lastpos
== NULL
)
m
->lastpos
= (char **)malloc((g
->nplus
+1) *
if (g
->nplus
> 0 && m
->lastpos
== NULL
) {
dp
= backref(m
, m
->coldp
, endp
, gf
, gl
, (sopno
)0);
/* uh-oh... we couldn't find a subexpression-level match */
assert(g
->backrefs
); /* must be back references doing it */
assert(g
->nplus
== 0 || m
->lastpos
!= NULL
);
if (dp
!= NULL
|| endp
<= m
->coldp
)
endp
= slow(m
, m
->coldp
, endp
-1, gf
, gl
);
/* try it on a shorter possibility */
for (i
= 1; i
<= m
->g
->nsub
; i
++) {
assert(m
->pmatch
[i
].rm_so
== -1);
assert(m
->pmatch
[i
].rm_eo
== -1);
dp
= backref(m
, m
->coldp
, endp
, gf
, gl
, (sopno
)0);
assert(dp
== NULL
|| dp
== endp
);
if (dp
!= NULL
) /* found a shorter one */
/* despite initial appearances, there is no match here */
start
= m
->coldp
+ 1; /* recycle starting later */
/* fill in the details if requested */
pmatch
[0].rm_so
= m
->coldp
- m
->offp
;
pmatch
[0].rm_eo
= endp
- m
->offp
;
assert(m
->pmatch
!= NULL
);
for (i
= 1; i
< nmatch
; i
++)
pmatch
[i
] = m
->pmatch
[i
];
free((char *)m
->lastpos
);
- dissect - figure out what matched what, no back references
== static char *dissect(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
static char * /* == stop (success) always */
dissect(m
, start
, stop
, startst
, stopst
)
register struct match
*m
;
register sopno ss
; /* start sop of current subRE */
register sopno es
; /* end sop of current subRE */
register char *sp
; /* start of string matched by it */
register char *stp
; /* string matched by it cannot pass here */
register char *rest
; /* start of rest of string */
register char *tail
; /* string unmatched by rest of RE */
register sopno ssub
; /* start sop of subsubRE */
register sopno esub
; /* end sop of subsubRE */
register char *ssp
; /* start of string matched by subsubRE */
register char *sep
; /* end of string matched by subsubRE */
register char *oldssp
; /* previous ssp */
AT("diss", start
, stop
, startst
, stopst
);
for (ss
= startst
; ss
< stopst
; ss
= es
) {
/* identify end of subRE */
switch (OP(m
->g
->strip
[es
])) {
es
+= OPND(m
->g
->strip
[es
]);
while (OP(m
->g
->strip
[es
]) != O_CH
)
es
+= OPND(m
->g
->strip
[es
]);
/* figure out what it matched */
switch (OP(m
->g
->strip
[ss
])) {
/* cases where length of match is hard to find */
/* how long could this one be? */
rest
= slow(m
, sp
, stp
, ss
, es
);
assert(rest
!= NULL
); /* it did match */
/* could the rest match the rest? */
tail
= slow(m
, rest
, stop
, es
, stopst
);
/* no -- try a shorter match for this one */
assert(stp
>= sp
); /* it did work */
if (slow(m
, sp
, rest
, ssub
, esub
) != NULL
) {
dp
= dissect(m
, sp
, rest
, ssub
, esub
);
/* how long could this one be? */
rest
= slow(m
, sp
, stp
, ss
, es
);
assert(rest
!= NULL
); /* it did match */
/* could the rest match the rest? */
tail
= slow(m
, rest
, stop
, es
, stopst
);
/* no -- try a shorter match for this one */
assert(stp
>= sp
); /* it did work */
for (;;) { /* find last match of innards */
sep
= slow(m
, ssp
, rest
, ssub
, esub
);
if (sep
== NULL
|| sep
== ssp
)
break; /* failed or matched null */
oldssp
= ssp
; /* on to next try */
/* last successful match */
assert(sep
== rest
); /* must exhaust substring */
assert(slow(m
, ssp
, sep
, ssub
, esub
) == rest
);
dp
= dissect(m
, ssp
, sep
, ssub
, esub
);
/* how long could this one be? */
rest
= slow(m
, sp
, stp
, ss
, es
);
assert(rest
!= NULL
); /* it did match */
/* could the rest match the rest? */
tail
= slow(m
, rest
, stop
, es
, stopst
);
/* no -- try a shorter match for this one */
assert(stp
>= sp
); /* it did work */
esub
= ss
+ OPND(m
->g
->strip
[ss
]) - 1;
assert(OP(m
->g
->strip
[esub
]) == OOR1
);
for (;;) { /* find first matching branch */
if (slow(m
, sp
, rest
, ssub
, esub
) == rest
)
break; /* it matched all of it */
/* that one missed, try next one */
assert(OP(m
->g
->strip
[esub
]) == OOR1
);
assert(OP(m
->g
->strip
[esub
]) == OOR2
);
esub
+= OPND(m
->g
->strip
[esub
]);
if (OP(m
->g
->strip
[esub
]) == OOR2
)
assert(OP(m
->g
->strip
[esub
]) == O_CH
);
dp
= dissect(m
, sp
, rest
, ssub
, esub
);
i
= OPND(m
->g
->strip
[ss
]);
assert(0 < i
&& i
<= m
->g
->nsub
);
m
->pmatch
[i
].rm_so
= sp
- m
->offp
;
i
= OPND(m
->g
->strip
[ss
]);
assert(0 < i
&& i
<= m
->g
->nsub
);
m
->pmatch
[i
].rm_eo
= sp
- m
->offp
;
- backref - figure out what matched what, figuring in back references
== static char *backref(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst, sopno lev);
static char * /* == stop (success) or NULL (failure) */
backref(m
, start
, stop
, startst
, stopst
, lev
)
register struct match
*m
;
sopno lev
; /* PLUS nesting level */
register sopno ss
; /* start sop of current subRE */
register char *sp
; /* start of string matched by it */
register sopno ssub
; /* start sop of subsubRE */
register sopno esub
; /* end sop of subsubRE */
register char *ssp
; /* start of string matched by subsubRE */
register regoff_t offsave
;
AT("back", start
, stop
, startst
, stopst
);
/* get as far as we can with easy stuff */
for (ss
= startst
; !hard
&& ss
< stopst
; ss
++)
switch (OP(s
= m
->g
->strip
[ss
])) {
if (sp
== stop
|| *sp
++ != (char)OPND(s
))
cs
= &m
->g
->sets
[OPND(s
)];
if (sp
== stop
|| !CHIN(cs
, *sp
++))
if ( (sp
== m
->beginp
&& !(m
->eflags
®_NOTBOL
)) ||
(sp
< m
->endp
&& *(sp
-1) == '\n' &&
(m
->g
->cflags
®_NEWLINE
)) )
if ( (sp
== m
->endp
&& !(m
->eflags
®_NOTEOL
)) ||
(sp
< m
->endp
&& *sp
== '\n' &&
(m
->g
->cflags
®_NEWLINE
)) )
if (( (sp
== m
->beginp
&& !(m
->eflags
®_NOTBOL
)) ||
(sp
< m
->endp
&& *(sp
-1) == '\n' &&
(m
->g
->cflags
®_NEWLINE
)) ||
(sp
< m
->endp
&& ISWORD(*sp
)) )
if (( (sp
== m
->endp
&& !(m
->eflags
®_NOTEOL
)) ||
(sp
< m
->endp
&& *sp
== '\n' &&
(m
->g
->cflags
®_NEWLINE
)) ||
(sp
< m
->endp
&& !ISWORD(*sp
)) ) &&
(sp
> m
->beginp
&& ISWORD(*(sp
-1))) )
case OOR1
: /* matches null but needs to skip */
} while (OP(s
= m
->g
->strip
[ss
]) != O_CH
);
/* note that the ss++ gets us past the O_CH */
default: /* have to make a choice */
if (!hard
) { /* that was it! */
ss
--; /* adjust for the for's final increment */
AT("hard", sp
, stop
, ss
, stopst
);
case OBACK_
: /* the vilest depths */
assert(0 < i
&& i
<= m
->g
->nsub
);
if (m
->pmatch
[i
].rm_eo
== -1)
assert(m
->pmatch
[i
].rm_so
!= -1);
len
= m
->pmatch
[i
].rm_eo
- m
->pmatch
[i
].rm_so
;
assert(stop
- m
->beginp
>= len
);
return(NULL
); /* not enough left to match */
ssp
= m
->offp
+ m
->pmatch
[i
].rm_so
;
if (memcmp(sp
, ssp
, len
) != 0)
while (m
->g
->strip
[ss
] != SOP(O_BACK
, i
))
return(backref(m
, sp
+len
, stop
, ss
+1, stopst
, lev
));
case OQUEST_
: /* to null or not */
dp
= backref(m
, sp
, stop
, ss
+1, stopst
, lev
);
return(backref(m
, sp
, stop
, ss
+OPND(s
)+1, stopst
, lev
));
assert(m
->lastpos
!= NULL
);
assert(lev
+1 <= m
->g
->nplus
);
return(backref(m
, sp
, stop
, ss
+1, stopst
, lev
+1));
if (sp
== m
->lastpos
[lev
]) /* last pass matched null */
return(backref(m
, sp
, stop
, ss
+1, stopst
, lev
-1));
dp
= backref(m
, sp
, stop
, ss
-OPND(s
)+1, stopst
, lev
);
return(backref(m
, sp
, stop
, ss
+1, stopst
, lev
-1));
case OCH_
: /* find the right one, if any */
assert(OP(m
->g
->strip
[esub
]) == OOR1
);
for (;;) { /* find first matching branch */
dp
= backref(m
, sp
, stop
, ssub
, esub
, lev
);
/* that one missed, try next one */
if (OP(m
->g
->strip
[esub
]) == O_CH
)
return(NULL
); /* there is none */
assert(OP(m
->g
->strip
[esub
]) == OOR2
);
esub
+= OPND(m
->g
->strip
[esub
]);
if (OP(m
->g
->strip
[esub
]) == OOR2
)
assert(OP(m
->g
->strip
[esub
]) == O_CH
);
case OLPAREN
: /* must undo assignment if rest fails */
assert(0 < i
&& i
<= m
->g
->nsub
);
offsave
= m
->pmatch
[i
].rm_so
;
m
->pmatch
[i
].rm_so
= sp
- m
->offp
;
dp
= backref(m
, sp
, stop
, ss
+1, stopst
, lev
);
m
->pmatch
[i
].rm_so
= offsave
;
case ORPAREN
: /* must undo assignment if rest fails */
assert(0 < i
&& i
<= m
->g
->nsub
);
offsave
= m
->pmatch
[i
].rm_eo
;
m
->pmatch
[i
].rm_eo
= sp
- m
->offp
;
dp
= backref(m
, sp
, stop
, ss
+1, stopst
, lev
);
m
->pmatch
[i
].rm_eo
= offsave
;
- fast - step through the string at top speed
== static char *fast(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
static char * /* where tentative match ended, or NULL */
fast(m
, start
, stop
, startst
, stopst
)
register struct match
*m
;
register states st
= m
->st
;
register states fresh
= m
->fresh
;
register states tmp
= m
->tmp
;
register char *p
= start
;
register int c
= (start
== m
->beginp
) ? OUT
: *(start
-1);
register int lastc
; /* previous c */
register char *coldp
; /* last p after which no match was underway */
st
= step(m
->g
, startst
, stopst
, st
, NOTHING
, st
);
c
= (p
== m
->endp
) ? OUT
: *p
;
/* is there an EOL and/or BOL between lastc and c? */
if ( (lastc
== '\n' && m
->g
->cflags
®_NEWLINE
) ||
(lastc
== OUT
&& !(m
->eflags
®_NOTBOL
)) ) {
if ( (c
== '\n' && m
->g
->cflags
®_NEWLINE
) ||
(c
== OUT
&& !(m
->eflags
®_NOTEOL
)) ) {
flagch
= (flagch
== BOL
) ? BOLEOL
: EOL
;
st
= step(m
->g
, startst
, stopst
, st
, flagch
, st
);
/* how about a word boundary? */
if ( (flagch
== BOL
|| (lastc
!= OUT
&& !ISWORD(lastc
))) &&
(c
!= OUT
&& ISWORD(c
)) ) {
if ( (lastc
!= OUT
&& ISWORD(lastc
)) &&
(flagch
== EOL
|| (c
!= OUT
&& !ISWORD(c
))) ) {
if (flagch
== BOW
|| flagch
== EOW
) {
st
= step(m
->g
, startst
, stopst
, st
, flagch
, st
);
if (ISSET(st
, stopst
) || p
== stop
)
break; /* NOTE BREAK OUT */
/* no, we must deal with this character */
st
= step(m
->g
, startst
, stopst
, tmp
, c
, st
);
assert(EQ(step(m
->g
, startst
, stopst
, st
, NOTHING
, st
), st
));
- slow - step through the string more deliberately
== static char *slow(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
static char * /* where it ended */
slow(m
, start
, stop
, startst
, stopst
)
register struct match
*m
;
register states st
= m
->st
;
register states empty
= m
->empty
;
register states tmp
= m
->tmp
;
register char *p
= start
;
register int c
= (start
== m
->beginp
) ? OUT
: *(start
-1);
register int lastc
; /* previous c */
register char *matchp
; /* last p at which a match ended */
AT("slow", start
, stop
, startst
, stopst
);
st
= step(m
->g
, startst
, stopst
, st
, NOTHING
, st
);
c
= (p
== m
->endp
) ? OUT
: *p
;
/* is there an EOL and/or BOL between lastc and c? */
if ( (lastc
== '\n' && m
->g
->cflags
®_NEWLINE
) ||
(lastc
== OUT
&& !(m
->eflags
®_NOTBOL
)) ) {
if ( (c
== '\n' && m
->g
->cflags
®_NEWLINE
) ||
(c
== OUT
&& !(m
->eflags
®_NOTEOL
)) ) {
flagch
= (flagch
== BOL
) ? BOLEOL
: EOL
;
st
= step(m
->g
, startst
, stopst
, st
, flagch
, st
);
/* how about a word boundary? */
if ( (flagch
== BOL
|| (lastc
!= OUT
&& !ISWORD(lastc
))) &&
(c
!= OUT
&& ISWORD(c
)) ) {
if ( (lastc
!= OUT
&& ISWORD(lastc
)) &&
(flagch
== EOL
|| (c
!= OUT
&& !ISWORD(c
))) ) {
if (flagch
== BOW
|| flagch
== EOW
) {
st
= step(m
->g
, startst
, stopst
, st
, flagch
, st
);
if (EQ(st
, empty
) || p
== stop
)
break; /* NOTE BREAK OUT */
/* no, we must deal with this character */
st
= step(m
->g
, startst
, stopst
, tmp
, c
, st
);
assert(EQ(step(m
->g
, startst
, stopst
, st
, NOTHING
, st
), st
));
- step - map set of states reachable before char to set reachable after
== static states step(register struct re_guts *g, sopno start, sopno stop, \
== register states bef, int ch, register states aft);
== #define BOLEOL (BOL+2)
== #define NOTHING (BOL+3)
== #define CODEMAX (BOL+5) // highest code used
== #define NONCHAR(c) ((c) > CHAR_MAX)
== #define NNONCHAR (CODEMAX-CHAR_MAX)
step(g
, start
, stop
, bef
, ch
, aft
)
register struct re_guts
*g
;
sopno start
; /* start state within strip */
sopno stop
; /* state after stop state within strip */
register states bef
; /* states reachable before */
int ch
; /* character or NONCHAR code */
register states aft
; /* states already known reachable after */
register onestate here
; /* note, macros know this name */
for (pc
= start
, INIT(here
, pc
); pc
!= stop
; pc
++, INC(here
)) {
/* only characters can match */
assert(!NONCHAR(ch
) || ch
!= (char)OPND(s
));
if (ch
== BOL
|| ch
== BOLEOL
)
if (ch
== EOL
|| ch
== BOLEOL
)
if (!NONCHAR(ch
) && CHIN(cs
, ch
))
case OBACK_
: /* ignored here */
case OPLUS_
: /* forward, this is just an empty */
case O_PLUS
: /* both forward and back */
i
= ISSETBACK(aft
, OPND(s
));
if (!i
&& ISSETBACK(aft
, OPND(s
))) {
/* oho, must reconsider loop body */
case OQUEST_
: /* two branches, both forward */
case O_QUEST
: /* just an empty */
case OLPAREN
: /* not significant here */
case OCH_
: /* mark the first two branches */
assert(OP(g
->strip
[pc
+OPND(s
)]) == OOR2
);
case OOR1
: /* done a branch, find the O_CH */
if (ISSTATEIN(aft
, here
)) {
OP(s
= g
->strip
[pc
+look
]) != O_CH
;
case OOR2
: /* propagate OCH_'s marking */
if (OP(g
->strip
[pc
+OPND(s
)]) != O_CH
) {
assert(OP(g
->strip
[pc
+OPND(s
)]) == OOR2
);
case O_CH
: /* just empty */
default: /* ooooops... */
- print - print a set of states
== static void print(struct match *m, char *caption, states st, \
print(m
, caption
, st
, ch
, d
)
register struct re_guts
*g
= m
->g
;
if (!(m
->eflags
®_TRACE
))
fprintf(d
, "%s", caption
);
fprintf(d
, " %s", pchar(ch
));
for (i
= 0; i
< g
->nstates
; i
++)
fprintf(d
, "%s%d", (first
) ? "\t" : ", ", i
);
- at - print current situation
== static void at(struct match *m, char *title, char *start, char *stop, \
== sopno startst, sopno stopst);
at(m
, title
, start
, stop
, startst
, stopst
)
if (!(m
->eflags
®_TRACE
))
printf("%s %s-", title
, pchar(*start
));
printf("%s ", pchar(*stop
));
printf("%ld-%ld\n", (long)startst
, (long)stopst
);
#define PCHARDONE /* never again */
- pchar - make a character printable
== static char *pchar(int ch);
* Is this identical to regchar() over in debug.c? Well, yes. But a
* duplicate here avoids having a debugging-capable regexec.o tied to
* a matching debug.o, and this is convenient. It all disappears in
* the non-debug compilation anyway, so it doesn't matter much.
static char * /* -> representation */
if (isprint(ch
) || ch
== ' ')
sprintf(pbuf
, "\\%o", ch
);