LCOV - differential code coverage report
Current view: top level - src/tools/pg_bsd_indent - io.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 64.9 % 291 189 102 189
Current Date: 2024-04-14 14:21:10 Functions: 75.0 % 12 9 3 9
Baseline: 16@8cea358b128 Branches: 49.6 % 280 139 141 139
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 64.9 % 291 189 102 189
Function coverage date bins:
(240..) days: 75.0 % 12 9 3 9
Branch coverage date bins:
(240..) days: 49.6 % 280 139 141 139

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-
                                  2                 :                :  * Copyright (c) 1985 Sun Microsystems, Inc.
                                  3                 :                :  * Copyright (c) 1980, 1993
                                  4                 :                :  *  The Regents of the University of California.  All rights reserved.
                                  5                 :                :  * All rights reserved.
                                  6                 :                :  *
                                  7                 :                :  * Redistribution and use in source and binary forms, with or without
                                  8                 :                :  * modification, are permitted provided that the following conditions
                                  9                 :                :  * are met:
                                 10                 :                :  * 1. Redistributions of source code must retain the above copyright
                                 11                 :                :  *    notice, this list of conditions and the following disclaimer.
                                 12                 :                :  * 2. Redistributions in binary form must reproduce the above copyright
                                 13                 :                :  *    notice, this list of conditions and the following disclaimer in the
                                 14                 :                :  *    documentation and/or other materials provided with the distribution.
                                 15                 :                :  * 3. Neither the name of the University nor the names of its contributors
                                 16                 :                :  *    may be used to endorse or promote products derived from this software
                                 17                 :                :  *    without specific prior written permission.
                                 18                 :                :  *
                                 19                 :                :  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                                 20                 :                :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                                 21                 :                :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                                 22                 :                :  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                                 23                 :                :  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                                 24                 :                :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                                 25                 :                :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                                 26                 :                :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                                 27                 :                :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                                 28                 :                :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                                 29                 :                :  * SUCH DAMAGE.
                                 30                 :                :  */
                                 31                 :                : 
                                 32                 :                : #if 0
                                 33                 :                : #ifndef lint
                                 34                 :                : static char sccsid[] = "@(#)io.c   8.1 (Berkeley) 6/6/93";
                                 35                 :                : #endif /* not lint */
                                 36                 :                : #endif
                                 37                 :                : 
                                 38                 :                : #include "c.h"
                                 39                 :                : 
                                 40                 :                : #include <ctype.h>
                                 41                 :                : #include <err.h>
                                 42                 :                : #include <stdio.h>
                                 43                 :                : #include <stdlib.h>
                                 44                 :                : #include <string.h>
                                 45                 :                : #include "indent_globs.h"
                                 46                 :                : #include "indent.h"
                                 47                 :                : 
                                 48                 :                : int         comment_open;
                                 49                 :                : static int  paren_target;
                                 50                 :                : 
                                 51                 :                : static char *lookahead_buf; /* malloc'd buffer, or NULL initially */
                                 52                 :                : static char *lookahead_buf_end; /* end+1 of allocated space */
                                 53                 :                : static char *lookahead_start;   /* => next char for fill_buffer() to fetch */
                                 54                 :                : static char *lookahead_ptr; /* => next char for lookahead() to fetch */
                                 55                 :                : static char *lookahead_end; /* last+1 valid char in lookahead_buf */
                                 56                 :                : static char *lookahead_bp_save; /* lookahead position in bp_save, if any */
                                 57                 :                : 
                                 58                 :                : static int pad_output(int current, int target);
                                 59                 :                : 
                                 60                 :                : void
  427 tgl@sss.pgh.pa.us          61                 :CBC         355 : dump_line(void)
                                 62                 :                : {               /* dump_line is the routine that actually
                                 63                 :                :                  * effects the printing of the new source. It
                                 64                 :                :                  * prints the label section, followed by the
                                 65                 :                :                  * code section with the appropriate nesting
                                 66                 :                :                  * level, followed by any comments */
                                 67                 :                :     int cur_col,
                                 68                 :            355 :                 target_col = 1;
                                 69                 :                :     static int  not_first_line;
                                 70                 :                : 
                                 71         [ +  + ]:            355 :     if (ps.procname[0]) {
                                 72                 :             22 :     ps.ind_level = 0;
                                 73                 :             22 :     ps.procname[0] = 0;
                                 74                 :                :     }
                                 75   [ +  +  +  +  :            355 :     if (s_code == e_code && s_lab == e_lab && s_com == e_com) {
                                              +  + ]
                                 76         [ -  + ]:             54 :     if (suppress_blanklines > 0)
  427 tgl@sss.pgh.pa.us          77                 :UBC           0 :         suppress_blanklines--;
                                 78                 :                :     else {
  427 tgl@sss.pgh.pa.us          79                 :CBC          54 :         ps.bl_line = true;
                                 80                 :             54 :         n_real_blanklines++;
                                 81                 :                :     }
                                 82                 :                :     }
                                 83         [ +  - ]:            301 :     else if (!inhibit_formatting) {
                                 84                 :            301 :     suppress_blanklines = 0;
                                 85                 :            301 :     ps.bl_line = false;
                                 86   [ -  +  -  - ]:            301 :     if (prefix_blankline_requested && not_first_line) {
  427 tgl@sss.pgh.pa.us          87         [ #  # ]:UBC           0 :         if (swallow_optional_blanklines) {
                                 88         [ #  # ]:              0 :         if (n_real_blanklines == 1)
                                 89                 :              0 :             n_real_blanklines = 0;
                                 90                 :                :         }
                                 91                 :                :         else {
                                 92         [ #  # ]:              0 :         if (n_real_blanklines == 0)
                                 93                 :              0 :             n_real_blanklines = 1;
                                 94                 :                :         }
                                 95                 :                :     }
  427 tgl@sss.pgh.pa.us          96         [ +  + ]:CBC         354 :     while (--n_real_blanklines >= 0)
                                 97                 :             53 :         putc('\n', output);
                                 98                 :            301 :     n_real_blanklines = 0;
                                 99         [ +  + ]:            301 :     if (ps.ind_level == 0)
                                100                 :            161 :         ps.ind_stmt = 0;    /* this is a class A kludge. dont do
                                101                 :                :                  * additional statement indentation if we are
                                102                 :                :                  * at bracket level 0 */
                                103                 :                : 
                                104   [ +  +  +  + ]:            301 :     if (e_lab != s_lab || e_code != s_code)
                                105                 :            240 :         ++code_lines;   /* keep count of lines with code */
                                106                 :                : 
                                107                 :                : 
                                108         [ +  + ]:            301 :     if (e_lab != s_lab) {   /* print lab, if any */
                                109         [ -  + ]:             16 :         if (comment_open) {
  427 tgl@sss.pgh.pa.us         110                 :UBC           0 :         comment_open = 0;
                                111                 :              0 :         fprintf(output, ".*/\n");
                                112                 :                :         }
  427 tgl@sss.pgh.pa.us         113   [ +  -  -  +  :CBC          16 :         while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
                                              -  + ]
  427 tgl@sss.pgh.pa.us         114                 :UBC           0 :         e_lab--;
  427 tgl@sss.pgh.pa.us         115                 :CBC          16 :         *e_lab = '\0';
                                116                 :             16 :         cur_col = pad_output(1, compute_label_target());
                                117   [ +  +  +  + ]:             16 :         if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0
                                118         [ +  + ]:             13 :                     || strncmp(s_lab, "#endif", 6) == 0)) {
                                119                 :              4 :         char *s = s_lab;
                                120         [ -  + ]:              4 :         if (e_lab[-1] == '\n') e_lab--;
                                121                 :             22 :         do putc(*s++, output);
                                122   [ +  +  +  -  :             22 :         while (s < e_lab && 'a' <= *s && *s<='z');
                                              +  - ]
                                123   [ +  -  -  +  :              4 :         while ((*s == ' ' || *s == '\t') && s < e_lab)
                                              -  - ]
  427 tgl@sss.pgh.pa.us         124                 :UBC           0 :             s++;
  427 tgl@sss.pgh.pa.us         125         [ -  + ]:CBC           4 :         if (s < e_lab)
  427 tgl@sss.pgh.pa.us         126         [ #  # ]:UBC           0 :             fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */",
                                127         [ #  # ]:              0 :                 (int)(e_lab - s), s);
                                128                 :                :         }
  427 tgl@sss.pgh.pa.us         129                 :CBC          12 :         else fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab);
                                130                 :             16 :         cur_col = count_spaces(cur_col, s_lab);
                                131                 :                :     }
                                132                 :                :     else
                                133                 :            285 :         cur_col = 1;    /* there is no label section */
                                134                 :                : 
                                135                 :            301 :     ps.pcase = false;
                                136                 :                : 
                                137         [ +  + ]:            301 :     if (s_code != e_code) { /* print code section, if any */
                                138                 :                :         char *p;
                                139                 :                : 
                                140         [ -  + ]:            226 :         if (comment_open) {
  427 tgl@sss.pgh.pa.us         141                 :UBC           0 :         comment_open = 0;
                                142                 :              0 :         fprintf(output, ".*/\n");
                                143                 :                :         }
  427 tgl@sss.pgh.pa.us         144                 :CBC         226 :         target_col = compute_code_target();
                                145                 :                :         {
                                146                 :                :         int i;
                                147                 :                : 
                                148         [ +  + ]:            244 :         for (i = 0; i < ps.p_l_follow; i++)
                                149         [ +  + ]:             18 :             if (ps.paren_indents[i] >= 0)
                                150                 :             11 :             ps.paren_indents[i] = -(ps.paren_indents[i] + target_col);
                                151                 :                :         }
                                152                 :            226 :         cur_col = pad_output(cur_col, target_col);
                                153         [ +  + ]:           2864 :         for (p = s_code; p < e_code; p++)
                                154         [ -  + ]:           2638 :         if (*p == (char) 0200)
  427 tgl@sss.pgh.pa.us         155                 :UBC           0 :             fprintf(output, "%d", target_col * 7);
                                156                 :                :         else
  427 tgl@sss.pgh.pa.us         157                 :CBC        2638 :             putc(*p, output);
                                158                 :            226 :         cur_col = count_spaces(cur_col, s_code);
                                159                 :                :     }
                                160         [ +  + ]:            301 :     if (s_com != e_com) {       /* print comment, if any */
                                161                 :             81 :         int target = ps.com_col;
                                162                 :             81 :         char *com_st = s_com;
                                163                 :                : 
                                164                 :             81 :         target += ps.comment_delta;
                                165         [ +  + ]:            113 :         while (*com_st == '\t') /* consider original indentation in
                                166                 :                :                      * case this is a box comment */
                                167                 :             32 :         com_st++, target += tabsize;
                                168         [ -  + ]:             81 :         while (target <= 0)
  427 tgl@sss.pgh.pa.us         169         [ #  # ]:UBC           0 :         if (*com_st == ' ')
                                170                 :              0 :             target++, com_st++;
                                171         [ #  # ]:              0 :         else if (*com_st == '\t')
                                172                 :              0 :             target = tabsize * (1 + (target - 1) / tabsize) + 1, com_st++;
                                173                 :                :         else
                                174                 :              0 :             target = 1;
  427 tgl@sss.pgh.pa.us         175         [ -  + ]:CBC          81 :         if (cur_col > target) {  /* if comment can't fit on this line,
                                176                 :                :                      * put it on next line */
  427 tgl@sss.pgh.pa.us         177                 :UBC           0 :         putc('\n', output);
                                178                 :              0 :         cur_col = 1;
                                179                 :              0 :         ++ps.out_lines;
                                180                 :                :         }
  427 tgl@sss.pgh.pa.us         181   [ +  -  +  + ]:CBC          90 :         while (e_com > com_st && isspace((unsigned char)e_com[-1]))
                                182                 :              9 :         e_com--;
                                183                 :             81 :         (void)pad_output(cur_col, target);
                                184                 :             81 :         fwrite(com_st, e_com - com_st, 1, output);
                                185                 :             81 :         ps.comment_delta = ps.n_comment_delta;
                                186                 :             81 :         ++ps.com_lines; /* count lines with comments */
                                187                 :                :     }
                                188         [ -  + ]:            301 :     if (ps.use_ff)
  427 tgl@sss.pgh.pa.us         189                 :UBC           0 :         putc('\014', output);
                                190                 :                :     else
  427 tgl@sss.pgh.pa.us         191                 :CBC         301 :         putc('\n', output);
                                192                 :            301 :     ++ps.out_lines;
                                193   [ +  +  +  + ]:            301 :     if (ps.just_saw_decl == 1 && blanklines_after_declarations) {
                                194                 :              2 :         prefix_blankline_requested = 1;
                                195                 :              2 :         ps.just_saw_decl = 0;
                                196                 :                :     }
                                197                 :                :     else
                                198                 :            299 :         prefix_blankline_requested = postfix_blankline_requested;
                                199                 :            301 :     postfix_blankline_requested = 0;
                                200                 :                :     }
                                201                 :            355 :     ps.decl_on_line = ps.in_decl;   /* if we are in the middle of a
                                202                 :                :                      * declaration, remember that fact for
                                203                 :                :                      * proper comment indentation */
                                204                 :                :     /* next line should be indented if we have not completed this stmt, and
                                205                 :                :      * either we are not in a declaration or we are in an initialization
                                206                 :                :      * assignment; but not if we're within braces in an initialization,
                                207                 :                :      * because that scenario is handled by other rules. */
  372                           208         [ +  + ]:            410 :     ps.ind_stmt = ps.in_stmt &&
                                209   [ +  +  +  +  :             55 :     (!ps.in_decl || (ps.block_init && ps.block_init_level <= 0));
                                              +  + ]
  427                           210                 :            355 :     ps.use_ff = false;
                                211                 :            355 :     ps.dumped_decl_indent = 0;
                                212                 :            355 :     *(e_lab = s_lab) = '\0';    /* reset buffers */
                                213                 :            355 :     *(e_code = s_code) = '\0';
                                214                 :            355 :     *(e_com = s_com = combuf + 1) = '\0';
                                215                 :            355 :     ps.ind_level = ps.i_l_follow;
                                216                 :            355 :     ps.paren_level = ps.p_l_follow;
                                217         [ +  + ]:            355 :     if (ps.paren_level > 0)
                                218                 :             14 :     paren_target = -ps.paren_indents[ps.paren_level - 1];
                                219                 :            355 :     not_first_line = 1;
                                220                 :            355 : }
                                221                 :                : 
                                222                 :                : int
                                223                 :            254 : compute_code_target(void)
                                224                 :                : {
                                225                 :            254 :     int target_col = ps.ind_size * ps.ind_level + 1;
                                226                 :                : 
                                227         [ +  + ]:            254 :     if (ps.paren_level)
                                228         [ -  + ]:             14 :     if (!lineup_to_parens)
  427 tgl@sss.pgh.pa.us         229                 :UBC           0 :         target_col += continuation_indent
                                230         [ #  # ]:              0 :         * (2 * continuation_indent == ps.ind_size ? 1 : ps.paren_level);
  427 tgl@sss.pgh.pa.us         231         [ -  + ]:CBC          14 :     else if (lineup_to_parens_always)
  427 tgl@sss.pgh.pa.us         232                 :UBC           0 :         target_col = paren_target;
                                233                 :                :     else {
                                234                 :                :         int w;
  427 tgl@sss.pgh.pa.us         235                 :CBC          14 :         int t = paren_target;
                                236                 :                : 
                                237         [ -  + ]:             14 :         if ((w = count_spaces(t, s_code) - max_col) > 0
  427 tgl@sss.pgh.pa.us         238         [ #  # ]:UBC           0 :             && count_spaces(target_col, s_code) <= max_col) {
                                239                 :              0 :         t -= w + 1;
                                240         [ #  # ]:              0 :         if (t > target_col)
                                241                 :              0 :             target_col = t;
                                242                 :                :         }
                                243                 :                :         else
  427 tgl@sss.pgh.pa.us         244                 :CBC          14 :         target_col = t;
                                245                 :                :     }
                                246         [ -  + ]:            240 :     else if (ps.ind_stmt)
  427 tgl@sss.pgh.pa.us         247                 :UBC           0 :     target_col += continuation_indent;
  427 tgl@sss.pgh.pa.us         248                 :CBC         254 :     return target_col;
                                249                 :                : }
                                250                 :                : 
                                251                 :                : int
                                252                 :             22 : compute_label_target(void)
                                253                 :                : {
                                254                 :                :     return
                                255                 :             26 :     ps.pcase ? (int) (case_ind * ps.ind_size) + 1
                                256         [ +  + ]:             40 :     : *s_lab == '#' ? 1
                                257         [ +  + ]:             18 :     : ps.ind_size * (ps.ind_level - label_offset) + 1;
                                258                 :                : }
                                259                 :                : 
                                260                 :                : /*
                                261                 :                :  * Read data ahead of what has been collected into in_buffer.
                                262                 :                :  *
                                263                 :                :  * Successive calls get further and further ahead, until we hit EOF.
                                264                 :                :  * Call lookahead_reset() to rescan from just beyond in_buffer.
                                265                 :                :  *
                                266                 :                :  * Lookahead is automatically reset whenever fill_buffer() reads beyond
                                267                 :                :  * the lookahead buffer, i.e., you can't use this for "look behind".
                                268                 :                :  *
                                269                 :                :  * The standard pattern for potentially multi-line lookahead is to call
                                270                 :                :  * lookahead_reset(), then enter a loop that scans forward from buf_ptr
                                271                 :                :  * to buf_end, then (if necessary) calls lookahead() to read additional
                                272                 :                :  * characters from beyond the end of the current line.
                                273                 :                :  */
                                274                 :                : int
                                275                 :            306 : lookahead(void)
                                276                 :                : {
                                277                 :                :     /* First read whatever's in bp_save area */
                                278   [ -  +  -  - ]:            306 :     if (lookahead_bp_save != NULL && lookahead_bp_save < be_save)
  427 tgl@sss.pgh.pa.us         279                 :UBC           0 :     return (unsigned char) *lookahead_bp_save++;
                                280                 :                :     /* Else, we have to examine and probably fill the main lookahead buffer */
  427 tgl@sss.pgh.pa.us         281         [ +  + ]:CBC         480 :     while (lookahead_ptr >= lookahead_end) {
                                282                 :            174 :     int     i = getc(input);
                                283                 :                : 
                                284         [ -  + ]:            174 :     if (i == EOF)
  427 tgl@sss.pgh.pa.us         285                 :UBC           0 :         return i;
  427 tgl@sss.pgh.pa.us         286         [ -  + ]:CBC         174 :     if (i == '\0')
  427 tgl@sss.pgh.pa.us         287                 :UBC           0 :         continue;       /* fill_buffer drops nulls, and so do we */
                                288                 :                : 
  427 tgl@sss.pgh.pa.us         289         [ +  + ]:CBC         174 :     if (lookahead_end >= lookahead_buf_end) {
                                290                 :                :         /* Need to allocate or enlarge lookahead_buf */
                                291                 :                :         char       *new_buf;
                                292                 :                :         size_t  req;
                                293                 :                : 
                                294         [ +  - ]:              6 :         if (lookahead_buf == NULL) {
                                295                 :              6 :         req = 64;
                                296                 :              6 :         new_buf = malloc(req);
                                297                 :                :         } else {
  427 tgl@sss.pgh.pa.us         298                 :UBC           0 :         req = (lookahead_buf_end - lookahead_buf) * 2;
                                299                 :              0 :         new_buf = realloc(lookahead_buf, req);
                                300                 :                :         }
  427 tgl@sss.pgh.pa.us         301         [ -  + ]:CBC           6 :         if (new_buf == NULL)
  427 tgl@sss.pgh.pa.us         302                 :UBC           0 :         errx(1, "too much lookahead required");
  427 tgl@sss.pgh.pa.us         303                 :CBC           6 :         lookahead_start = new_buf + (lookahead_start - lookahead_buf);
                                304                 :              6 :         lookahead_ptr = new_buf + (lookahead_ptr - lookahead_buf);
                                305                 :              6 :         lookahead_end = new_buf + (lookahead_end - lookahead_buf);
                                306                 :              6 :         lookahead_buf = new_buf;
                                307                 :              6 :         lookahead_buf_end = new_buf + req;
                                308                 :                :     }
                                309                 :                : 
                                310                 :            174 :     *lookahead_end++ = i;
                                311                 :                :     }
                                312                 :            306 :     return (unsigned char) *lookahead_ptr++;
                                313                 :                : }
                                314                 :                : 
                                315                 :                : /*
                                316                 :                :  * Reset so that lookahead() will again scan from just beyond what's in
                                317                 :                :  * in_buffer.
                                318                 :                :  */
                                319                 :                : void
                                320                 :             32 : lookahead_reset(void)
                                321                 :                : {
                                322                 :                :     /* Reset the main lookahead buffer */
                                323                 :             32 :     lookahead_ptr = lookahead_start;
                                324                 :                :     /* If bp_save isn't NULL, we need to scan that first */
                                325                 :             32 :     lookahead_bp_save = bp_save;
                                326                 :             32 : }
                                327                 :                : 
                                328                 :                : /*
                                329                 :                :  * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
                                330                 :                :  *
                                331                 :                :  * All rights reserved
                                332                 :                :  *
                                333                 :                :  *
                                334                 :                :  * NAME: fill_buffer
                                335                 :                :  *
                                336                 :                :  * FUNCTION: Reads one line of input into in_buffer,
                                337                 :                :  * sets up buf_ptr and buf_end to point to the line's start and end+1.
                                338                 :                :  * (Note that the buffer does not get null-terminated.)
                                339                 :                :  *
                                340                 :                :  * HISTORY: initial coding  November 1976   D A Willcox of CAC 1/7/77 A
                                341                 :                :  * Willcox of CAC   Added check for switch back to partly full input
                                342                 :                :  * buffer from temporary buffer
                                343                 :                :  *
                                344                 :                :  */
                                345                 :                : void
                                346                 :            390 : fill_buffer(void)
                                347                 :                : {               /* this routine reads stuff from the input */
                                348                 :                :     char *p;
                                349                 :                :     int i;
                                350                 :            390 :     FILE *f = input;
                                351                 :                : 
                                352         [ +  + ]:            390 :     if (bp_save != NULL) {  /* there is a partly filled input buffer left */
                                353                 :             38 :     buf_ptr = bp_save;  /* do not read anything, just switch buffers */
                                354                 :             38 :     buf_end = be_save;
                                355                 :             38 :     bp_save = be_save = NULL;
                                356                 :             38 :     lookahead_bp_save = NULL;
                                357         [ +  - ]:             38 :     if (buf_ptr < buf_end)
                                358                 :             38 :         return;     /* only return if there is really something in
                                359                 :                :                  * this buffer */
                                360                 :                :     }
                                361                 :            352 :     for (p = in_buffer;;) {
                                362         [ +  + ]:           4973 :     if (p >= in_buffer_limit) {
                                363                 :             38 :         int size = (in_buffer_limit - in_buffer) * 2 + 10;
                                364                 :             38 :         int offset = p - in_buffer;
                                365                 :             38 :         in_buffer = realloc(in_buffer, size);
                                366         [ -  + ]:             38 :         if (in_buffer == NULL)
  427 tgl@sss.pgh.pa.us         367                 :UBC           0 :         errx(1, "input line too long");
  427 tgl@sss.pgh.pa.us         368                 :CBC          38 :         p = in_buffer + offset;
                                369                 :             38 :         in_buffer_limit = in_buffer + size - 2;
                                370                 :                :     }
                                371         [ +  + ]:           4973 :     if (lookahead_start < lookahead_end) {
                                372                 :            174 :         i = (unsigned char) *lookahead_start++;
                                373                 :                :     } else {
                                374                 :           4799 :         lookahead_start = lookahead_ptr = lookahead_end = lookahead_buf;
                                375         [ +  + ]:           4799 :         if ((i = getc(f)) == EOF) {
                                376                 :             18 :         *p++ = ' ';
                                377                 :             18 :         *p++ = '\n';
                                378                 :             18 :         had_eof = true;
                                379                 :             18 :         break;
                                380                 :                :         }
                                381                 :                :     }
                                382         [ +  - ]:           4955 :     if (i != '\0')
                                383                 :           4955 :         *p++ = i;
                                384         [ +  + ]:           4955 :     if (i == '\n')
                                385                 :            334 :         break;
                                386                 :                :     }
                                387                 :            352 :     buf_ptr = in_buffer;
                                388                 :            352 :     buf_end = p;
                                389   [ +  +  +  +  :            352 :     if (p - in_buffer > 2 && p[-2] == '/' && p[-3] == '*') {
                                              +  - ]
                                390   [ -  +  -  - ]:             54 :     if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
  427 tgl@sss.pgh.pa.us         391                 :UBC           0 :         fill_buffer();  /* flush indent error message */
                                392                 :                :     else {
  427 tgl@sss.pgh.pa.us         393                 :CBC          54 :         int         com = 0;
                                394                 :                : 
                                395                 :             54 :         p = in_buffer;
                                396   [ +  +  +  + ]:            106 :         while (*p == ' ' || *p == '\t')
                                397                 :             52 :         p++;
                                398   [ +  +  +  - ]:             54 :         if (*p == '/' && p[1] == '*') {
                                399                 :             31 :         p += 2;
                                400   [ +  +  -  + ]:             62 :         while (*p == ' ' || *p == '\t')
                                401                 :             31 :             p++;
                                402   [ -  +  -  -  :             31 :         if (p[0] == 'I' && p[1] == 'N' && p[2] == 'D' && p[3] == 'E'
                                        -  -  -  - ]
  427 tgl@sss.pgh.pa.us         403   [ #  #  #  # ]:UBC           0 :             && p[4] == 'N' && p[5] == 'T') {
                                404                 :              0 :             p += 6;
                                405   [ #  #  #  # ]:              0 :             while (*p == ' ' || *p == '\t')
                                406                 :              0 :             p++;
                                407         [ #  # ]:              0 :             if (*p == '*')
                                408                 :              0 :             com = 1;
                                409         [ #  # ]:              0 :             else if (*p == 'O') {
                                410         [ #  # ]:              0 :             if (*++p == 'N')
                                411                 :              0 :                 p++, com = 1;
                                412   [ #  #  #  # ]:              0 :             else if (*p == 'F' && *++p == 'F')
                                413                 :              0 :                 p++, com = 2;
                                414                 :                :             }
                                415   [ #  #  #  # ]:              0 :             while (*p == ' ' || *p == '\t')
                                416                 :              0 :             p++;
                                417   [ #  #  #  #  :              0 :             if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com) {
                                        #  #  #  # ]
                                418   [ #  #  #  #  :              0 :             if (s_com != e_com || s_lab != e_lab || s_code != e_code)
                                              #  # ]
                                419                 :              0 :                 dump_line();
                                420         [ #  # ]:              0 :             if (!(inhibit_formatting = com - 1)) {
                                421                 :              0 :                 n_real_blanklines = 0;
                                422                 :              0 :                 postfix_blankline_requested = 0;
                                423                 :              0 :                 prefix_blankline_requested = 0;
                                424                 :              0 :                 suppress_blanklines = 1;
                                425                 :                :             }
                                426                 :                :             }
                                427                 :                :         }
                                428                 :                :         }
                                429                 :                :     }
                                430                 :                :     }
  427 tgl@sss.pgh.pa.us         431         [ -  + ]:CBC         352 :     if (inhibit_formatting) {
  427 tgl@sss.pgh.pa.us         432                 :UBC           0 :     p = in_buffer;
                                433                 :                :     do
                                434                 :              0 :         putc(*p, output);
                                435         [ #  # ]:              0 :     while (*p++ != '\n');
                                436                 :                :     }
                                437                 :                : }
                                438                 :                : 
                                439                 :                : /*
                                440                 :                :  * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
                                441                 :                :  *
                                442                 :                :  * All rights reserved
                                443                 :                :  *
                                444                 :                :  *
                                445                 :                :  * NAME: pad_output
                                446                 :                :  *
                                447                 :                :  * FUNCTION: Writes tabs and spaces to move the current column up to the desired
                                448                 :                :  * position.
                                449                 :                :  *
                                450                 :                :  * ALGORITHM: Put tabs and/or blanks into pobuf, then write pobuf.
                                451                 :                :  *
                                452                 :                :  * PARAMETERS: current      integer     The current column
                                453                 :                :  *             target       integer     The desired column
                                454                 :                :  *
                                455                 :                :  * RETURNS: Integer value of the new column.  (If current >= target, no action is
                                456                 :                :  * taken, and current is returned.
                                457                 :                :  *
                                458                 :                :  * GLOBALS: None
                                459                 :                :  *
                                460                 :                :  * CALLS: write (sys)
                                461                 :                :  *
                                462                 :                :  * CALLED BY: dump_line
                                463                 :                :  *
                                464                 :                :  * HISTORY: initial coding  November 1976   D A Willcox of CAC
                                465                 :                :  *
                                466                 :                :  */
                                467                 :                : static int
  427 tgl@sss.pgh.pa.us         468                 :CBC         323 : pad_output(int current, int target)
                                469                 :                :                     /* writes tabs and blanks (if necessary) to
                                470                 :                :                  * get the current output position up to the
                                471                 :                :                  * target column */
                                472                 :                :     /* current: the current column value */
                                473                 :                :     /* target: position we want it at */
                                474                 :                : {
                                475                 :                :     int curr;           /* internal column pointer */
                                476                 :                : 
                                477         [ +  + ]:            323 :     if (current >= target)
                                478                 :            154 :     return (current);   /* line is already long enough */
                                479                 :            169 :     curr = current;
                                480         [ +  + ]:            169 :     if (use_tabs) {
                                481                 :                :     int tcur;
                                482                 :                : 
                                483         [ +  + ]:            458 :     while ((tcur = tabsize * (1 + (curr - 1) / tabsize) + 1) <= target) {
                                484         [ -  + ]:            298 :         putc((!postgres_tab_rules ||
  427 tgl@sss.pgh.pa.us         485         [ #  # ]:UBC           0 :           tcur != curr + 1 ||
                                486         [ #  # ]:              0 :           target >= tcur + tabsize) ? '\t' : ' ', output);
  427 tgl@sss.pgh.pa.us         487                 :CBC         298 :         curr = tcur;
                                488                 :                :     }
                                489                 :                :     }
                                490         [ +  + ]:            319 :     while (curr++ < target)
                                491                 :            150 :     putc(' ', output);  /* pad with final blanks */
                                492                 :                : 
                                493                 :            169 :     return (target);
                                494                 :                : }
                                495                 :                : 
                                496                 :                : /*
                                497                 :                :  * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
                                498                 :                :  *
                                499                 :                :  * All rights reserved
                                500                 :                :  *
                                501                 :                :  *
                                502                 :                :  * NAME: count_spaces
                                503                 :                :  *
                                504                 :                :  * FUNCTION: Find out where printing of a given string will leave the current
                                505                 :                :  * character position on output.
                                506                 :                :  *
                                507                 :                :  * ALGORITHM: Run thru input string and add appropriate values to current
                                508                 :                :  * position.
                                509                 :                :  *
                                510                 :                :  * RETURNS: Integer value of position after printing "buffer" starting in column
                                511                 :                :  * "current".
                                512                 :                :  *
                                513                 :                :  * HISTORY: initial coding  November 1976   D A Willcox of CAC
                                514                 :                :  *
                                515                 :                :  */
                                516                 :                : int
                                517                 :            503 : count_spaces_until(int cur, char *buffer, char *end)
                                518                 :                : /*
                                519                 :                :  * this routine figures out where the character position will be after
                                520                 :                :  * printing the text in buffer starting at column "current"
                                521                 :                :  */
                                522                 :                : {
                                523                 :                :     char *buf;      /* used to look thru buffer */
                                524                 :                : 
                                525   [ +  +  +  + ]:           5939 :     for (buf = buffer; *buf != '\0' && buf != end; ++buf) {
                                526   [ +  +  -  + ]:           5436 :     switch (*buf) {
                                527                 :                : 
                                528                 :              3 :     case '\n':
                                529                 :                :     case 014:       /* form feed */
                                530                 :              3 :         cur = 1;
                                531                 :              3 :         break;
                                532                 :                : 
                                533                 :            248 :     case '\t':
                                534                 :            248 :         cur = tabsize * (1 + (cur - 1) / tabsize) + 1;
                                535                 :            248 :         break;
                                536                 :                : 
  427 tgl@sss.pgh.pa.us         537                 :UBC           0 :     case 010:       /* backspace */
                                538                 :              0 :         --cur;
                                539                 :              0 :         break;
                                540                 :                : 
  427 tgl@sss.pgh.pa.us         541                 :CBC        5185 :     default:
                                542                 :           5185 :         ++cur;
                                543                 :           5185 :         break;
                                544                 :                :     }           /* end of switch */
                                545                 :                :     }               /* end of for loop */
                                546                 :            503 :     return (cur);
                                547                 :                : }
                                548                 :                : 
                                549                 :                : int
                                550                 :            278 : count_spaces(int cur, char *buffer)
                                551                 :                : {
                                552                 :            278 :     return (count_spaces_until(cur, buffer, NULL));
                                553                 :                : }
                                554                 :                : 
                                555                 :                : void
  427 tgl@sss.pgh.pa.us         556                 :UBC           0 : diag4(int level, const char *msg, int a, int b)
                                557                 :                : {
                                558         [ #  # ]:              0 :     if (level)
                                559                 :              0 :     found_err = 1;
                                560         [ #  # ]:              0 :     if (output == stdout) {
                                561         [ #  # ]:              0 :     fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
                                562                 :              0 :     fprintf(stdout, msg, a, b);
                                563                 :              0 :     fprintf(stdout, " */\n");
                                564                 :                :     }
                                565                 :                :     else {
                                566         [ #  # ]:              0 :     fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
                                567                 :              0 :     fprintf(stderr, msg, a, b);
                                568                 :              0 :     fprintf(stderr, "\n");
                                569                 :                :     }
                                570                 :              0 : }
                                571                 :                : 
                                572                 :                : void
                                573                 :              0 : diag3(int level, const char *msg, int a)
                                574                 :                : {
                                575         [ #  # ]:              0 :     if (level)
                                576                 :              0 :     found_err = 1;
                                577         [ #  # ]:              0 :     if (output == stdout) {
                                578         [ #  # ]:              0 :     fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
                                579                 :              0 :     fprintf(stdout, msg, a);
                                580                 :              0 :     fprintf(stdout, " */\n");
                                581                 :                :     }
                                582                 :                :     else {
                                583         [ #  # ]:              0 :     fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
                                584                 :              0 :     fprintf(stderr, msg, a);
                                585                 :              0 :     fprintf(stderr, "\n");
                                586                 :                :     }
                                587                 :              0 : }
                                588                 :                : 
                                589                 :                : void
                                590                 :              0 : diag2(int level, const char *msg)
                                591                 :                : {
                                592         [ #  # ]:              0 :     if (level)
                                593                 :              0 :     found_err = 1;
                                594         [ #  # ]:              0 :     if (output == stdout) {
                                595         [ #  # ]:              0 :     fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
                                596                 :              0 :     fprintf(stdout, "%s", msg);
                                597                 :              0 :     fprintf(stdout, " */\n");
                                598                 :                :     }
                                599                 :                :     else {
                                600         [ #  # ]:              0 :     fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
                                601                 :              0 :     fprintf(stderr, "%s", msg);
                                602                 :              0 :     fprintf(stderr, "\n");
                                603                 :                :     }
                                604                 :              0 : }
                                605                 :                : 
        

Generated by: LCOV version 2.1-beta2-3-g6141622