Skip to content

Commit 086b26f

Browse files
committed
better document format code
add descriptions of: format op constants local vars code blocks to generally make navigating the format code easier. (Oh, and fix one incorrect indent). No code changes.
1 parent 3808a68 commit 086b26f

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

form.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/* form.h
22
*
3-
* Copyright (C) 1991, 1992, 1993, 2000, 2004 by Larry Wall and others
3+
* Copyright (C) 1991, 1992, 1993, 2000, 2004, 2011 by Larry Wall and others
44
*
55
* You may distribute under the terms of either the GNU General Public
66
* License or the Artistic License, as specified in the README file.
77
*
88
*/
99

10-
#define FF_END 0
11-
#define FF_LINEMARK 1
12-
#define FF_LITERAL 2
13-
#define FF_SKIP 3
14-
#define FF_FETCH 4
15-
#define FF_CHECKNL 5
16-
#define FF_CHECKCHOP 6
17-
#define FF_SPACE 7
18-
#define FF_HALFSPACE 8
19-
#define FF_ITEM 9
20-
#define FF_CHOP 10
21-
#define FF_LINEGLOB 11
22-
#define FF_DECIMAL 12
23-
#define FF_NEWLINE 13
24-
#define FF_BLANK 14
25-
#define FF_MORE 15
26-
#define FF_0DECIMAL 16
27-
#define FF_LINESNGL 17
10+
#define FF_END 0 /* tidy up, then return */
11+
#define FF_LINEMARK 1 /* start (or end) of a line */
12+
#define FF_LITERAL 2 /* append <arg> literal chars */
13+
#define FF_SKIP 3 /* skip <arg> chars in format */
14+
#define FF_FETCH 4 /* get next item and set field size to <arg> */
15+
#define FF_CHECKNL 5 /* find max len of item (up to \n) that fits field */
16+
#define FF_CHECKCHOP 6 /* like CHECKNL, but up to highest split point */
17+
#define FF_SPACE 7 /* append padding space (diff of field, item size) */
18+
#define FF_HALFSPACE 8 /* like FF_SPACE, but only append half as many */
19+
#define FF_ITEM 9 /* append a text item, while blanking ctrl chars */
20+
#define FF_CHOP 10 /* (for ^*) chop the current item */
21+
#define FF_LINEGLOB 11 /* process @* */
22+
#define FF_DECIMAL 12 /* do @##, ^##, where <arg>=(precision|flags) */
23+
#define FF_NEWLINE 13 /* delete trailing spaces, then append \n */
24+
#define FF_BLANK 14 /* for arg==0: do '~'; for arg>0 : do '~~' */
25+
#define FF_MORE 15 /* replace long end of string with '...' */
26+
#define FF_0DECIMAL 16 /* like FF_DECIMAL but for 0### */
27+
#define FF_LINESNGL 17 /* process ^* */

pp_ctl.c

+27-27
Original file line numberDiff line numberDiff line change
@@ -523,23 +523,23 @@ PP(pp_formline)
523523
{
524524
dVAR; dSP; dMARK; dORIGMARK;
525525
register SV * const tmpForm = *++MARK;
526-
SV *formsv;
527-
register U32 *fpc;
528-
register char *t;
529-
const char *f;
526+
SV *formsv; /* contains text of original format */
527+
register U32 *fpc; /* format ops program counter */
528+
register char *t; /* current append position in target string */
529+
const char *f; /* current position in format string */
530530
register I32 arg;
531-
register SV *sv = NULL;
532-
const char *item = NULL;
533-
I32 itemsize = 0;
534-
I32 fieldsize = 0;
535-
I32 lines = 0;
536-
bool chopspace = (strchr(PL_chopset, ' ') != NULL);
537-
const char *chophere = NULL;
538-
char *linemark = NULL;
531+
register SV *sv = NULL; /* current item */
532+
const char *item = NULL;/* string value of current item */
533+
I32 itemsize = 0; /* length of current item, possibly truncated */
534+
I32 fieldsize = 0; /* width of current field */
535+
I32 lines = 0; /* number of lines that have been output */
536+
bool chopspace = (strchr(PL_chopset, ' ') != NULL); /* does $: have space */
537+
const char *chophere = NULL; /* where to chop current item */
538+
char *linemark = NULL; /* pos of start of line in output */
539539
NV value;
540-
bool gotsome = FALSE;
540+
bool gotsome = FALSE; /* seen at least one non-blank item on this line */
541541
STRLEN len;
542-
STRLEN fudge;
542+
STRLEN fudge; /* estimate of output size in bytes */
543543
bool item_is_utf8 = FALSE;
544544
bool targ_is_utf8 = FALSE;
545545
SV * nsv = NULL;
@@ -848,7 +848,7 @@ PP(pp_formline)
848848
const int ch = *t++ = *s++;
849849
if (iscntrl(ch))
850850
#else
851-
if ( !((*t++ = *s++) & ~31) )
851+
if ( !((*t++ = *s++) & ~31) )
852852
#endif
853853
t[-1] = ' ';
854854
}
@@ -4918,17 +4918,17 @@ S_doparseform(pTHX_ SV *sv)
49184918
STRLEN len;
49194919
register char *s = SvPV(sv, len);
49204920
register char *send;
4921-
register char *base = NULL;
4922-
register I32 skipspaces = 0;
4923-
bool noblank = FALSE;
4924-
bool repeat = FALSE;
4925-
bool postspace = FALSE;
4921+
register char *base = NULL; /* start of current field */
4922+
register I32 skipspaces = 0; /* number of contiguous spaces seen */
4923+
bool noblank = FALSE; /* ~ or ~~ seen on this line */
4924+
bool repeat = FALSE; /* ~~ seen on this line */
4925+
bool postspace = FALSE; /* a text field may need right padding */
49264926
U32 *fops;
49274927
register U32 *fpc;
4928-
U32 *linepc = NULL;
4928+
U32 *linepc = NULL; /* position of last FF_LINEMARK */
49294929
register I32 arg;
4930-
bool ischop;
4931-
bool unchopnum = FALSE;
4930+
bool ischop; /* it's a ^ rather than a @ */
4931+
bool unchopnum = FALSE; /* at least one @ (i.e. non-chop) num field seen */
49324932
int maxops = 12; /* FF_LINEMARK + FF_END + 10 (\0 without preceding \n) */
49334933
MAGIC *mg = NULL;
49344934
SV *sv_copy;
@@ -5061,7 +5061,7 @@ S_doparseform(pTHX_ SV *sv)
50615061

50625062
base = s - 1;
50635063
*fpc++ = FF_FETCH;
5064-
if (*s == '*') {
5064+
if (*s == '*') { /* @* or ^* */
50655065
s++;
50665066
*fpc++ = 2; /* skip the @* or ^* */
50675067
if (ischop) {
@@ -5070,7 +5070,7 @@ S_doparseform(pTHX_ SV *sv)
50705070
} else
50715071
*fpc++ = FF_LINEGLOB;
50725072
}
5073-
else if (*s == '#' || (*s == '.' && s[1] == '#')) {
5073+
else if (*s == '#' || (*s == '.' && s[1] == '#')) { /* @###, ^### */
50745074
arg = ischop ? 512 : 0;
50755075
base = s - 1;
50765076
while (*s == '#')
@@ -5103,7 +5103,7 @@ S_doparseform(pTHX_ SV *sv)
51035103
*fpc++ = (U16)arg;
51045104
unchopnum |= ! ischop;
51055105
}
5106-
else {
5106+
else { /* text field */
51075107
I32 prespace = 0;
51085108
bool ismore = FALSE;
51095109

@@ -5130,7 +5130,7 @@ S_doparseform(pTHX_ SV *sv)
51305130
*fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
51315131

51325132
if (prespace)
5133-
*fpc++ = (U16)prespace;
5133+
*fpc++ = (U16)prespace; /* add SPACE or HALFSPACE */
51345134
*fpc++ = FF_ITEM;
51355135
if (ismore)
51365136
*fpc++ = FF_MORE;

0 commit comments

Comments
 (0)