about summary refs log tree commit diff
path: root/generator
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-08-28 15:37:25 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-08-28 15:37:25 +0000
commit0df80cf3405dea1a2d3ed2b58977ac3b90872363 (patch)
tree3aa9658b90682f6824ac9df15226417593fe40e3 /generator
parent6e37355ed2771e42942fc9fcd3556b9f4fd97743 (diff)
downloadnetpbm-mirror-0df80cf3405dea1a2d3ed2b58977ac3b90872363.tar.gz
netpbm-mirror-0df80cf3405dea1a2d3ed2b58977ac3b90872363.tar.xz
netpbm-mirror-0df80cf3405dea1a2d3ed2b58977ac3b90872363.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3307 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r--generator/pamtris/boundaries.c45
-rw-r--r--generator/pamtris/framebuffer.c42
-rw-r--r--generator/pamtris/input.c78
-rw-r--r--generator/pamtris/triangle.c41
-rw-r--r--generator/pamtris/utils.c29
5 files changed, 131 insertions, 104 deletions
diff --git a/generator/pamtris/boundaries.c b/generator/pamtris/boundaries.c
index 9bd9928c..a25103a8 100644
--- a/generator/pamtris/boundaries.c
+++ b/generator/pamtris/boundaries.c
@@ -40,8 +40,8 @@ make_pos_fract(int32_t const quotient,
 
 
 void
-init_boundary_buffer(boundary_info * bi,
-                     int16_t         height) {
+init_boundary_buffer(boundary_info * const bi,
+                     int16_t         const height) {
     MALLOCARRAY_NOFAIL(bi->buffer, height * 2 * sizeof(int16_t));
 }
 
@@ -55,10 +55,10 @@ free_boundary_buffer(boundary_info * bi) {
 
 
 bool
-gen_triangle_boundaries(Xy              xy,
-                        boundary_info * bi,
-                        int16_t         width,
-                        int16_t         height) {
+gen_triangle_boundaries(Xy              const xy,
+                        boundary_info * const bi,
+                        int16_t         const width,
+                        int16_t         const height) {
 /*----------------------------------------------------------------------------
   Generate an entry in the boundary buffer for the boundaries of every
   VISIBLE row of a particular triangle. In case there is no such row,
@@ -71,8 +71,8 @@ gen_triangle_boundaries(Xy              xy,
   The return value indicates whether the middle vertex is to the left of the
   line connecting the top vertex to the bottom vertex or not.
 -----------------------------------------------------------------------------*/
-    int16_t leftmost_x = xy._[0][0];
-    int16_t rightmost_x = xy._[0][0];
+    int16_t leftmost_x;
+    int16_t rightmost_x;
     int mid_is_to_the_left;
     fract left_x;
     fract right_x;
@@ -97,8 +97,11 @@ gen_triangle_boundaries(Xy              xy,
     int32_t right_delta[2];
     int16_t* num_rows_ptr[2];
     int32_t y;
-    int32_t i = 0;
-    uint8_t k = 0;
+    int32_t i;
+    uint8_t k;
+
+    leftmost_x = xy._[0][0];   /* initial value */
+    rightmost_x = xy._[0][0];  /* initial value */
 
     bi->start_scanline = -1;
     bi->num_upper_rows = 0;
@@ -173,8 +176,8 @@ gen_triangle_boundaries(Xy              xy,
     gen_steps(&xy._[1][0], &xy._[2][0], &mid2bot_step, 1, mid2bot_delta);
 
     if (mid_is_to_the_left == 2) {
-        if (top2bot_step.negative_flag == true) {
-            if (top2mid_step.negative_flag == true) {
+        if (top2bot_step.negative_flag) {
+            if (top2mid_step.negative_flag) {
                 if (top2mid_step.q == top2bot_step.q) {
                     mid_is_to_the_left =
                         top2mid_step.r * top2bot_delta >
@@ -186,7 +189,7 @@ gen_triangle_boundaries(Xy              xy,
                 mid_is_to_the_left = 0;
             }
         } else {
-            if (top2mid_step.negative_flag == false) {
+            if (!top2mid_step.negative_flag) {
                 if (top2mid_step.q == top2bot_step.q) {
                     mid_is_to_the_left =
                         top2mid_step.r * top2bot_delta <
@@ -237,7 +240,7 @@ gen_triangle_boundaries(Xy              xy,
     i = 0;
     k = 0;
 
-    if (no_upper_part == true) {
+    if (no_upper_part) {
         k = 1;
 
         right_x.q = xy._[1][0];
@@ -247,7 +250,9 @@ gen_triangle_boundaries(Xy              xy,
     step_up(&right_x, right_step[k], 1, right_delta[k]);
 
     while (k < 2) {
-        int32_t end = xy._[k + 1][1] + k;
+        int32_t end;
+
+        end = xy._[k + 1][1] + k;  /* initial value */
 
         if (y < 0) {
             int32_t delta;
@@ -304,17 +309,17 @@ gen_triangle_boundaries(Xy              xy,
 
 
 void
-get_triangle_boundaries(uint16_t              row_index,
-                        int32_t *             left,
-                        int32_t *             right,
-                        const boundary_info * bi) {
+get_triangle_boundaries(uint16_t              const row_index,
+                        int32_t *             const left,
+                        int32_t *             const right,
+                        const boundary_info * const bi) {
 /*----------------------------------------------------------------------------
   Return the left and right boundaries for a given VISIBLE triangle row (the
   row index is relative to the first visible row). These values may be out of
   the horizontal limits of the frame buffer, which is necessary in order to
   compute correct attribute interpolations.
 -----------------------------------------------------------------------------*/
-    uint32_t i  = row_index << 1;
+    uint32_t const i  = row_index << 1;
 
     *left       = bi->buffer[i];
     *right      = bi->buffer[i + 1];
diff --git a/generator/pamtris/framebuffer.c b/generator/pamtris/framebuffer.c
index 81195779..03cd720c 100644
--- a/generator/pamtris/framebuffer.c
+++ b/generator/pamtris/framebuffer.c
@@ -63,7 +63,9 @@ set_tupletype(const char * const str,
 
         return 1;
     } else {
-        size_t len = strlen(str);
+        size_t len;
+
+        len = strlen(str);   /* initial value */
 
         if (len > 255) {
             return 0;
@@ -88,9 +90,9 @@ set_tupletype(const char * const str,
 int
 init_framebuffer(framebuffer_info * const fbi) {
 
-    uint8_t num_planes = fbi->num_attribs + 1;
+    uint8_t const num_planes = fbi->num_attribs + 1;
 
-    uint32_t elements = fbi->width * fbi->height;
+    uint32_t const elements = fbi->width * fbi->height;
 
     fbi->img.bytes = elements * (num_planes * sizeof(uint16_t));
     fbi->z.bytes = elements * sizeof(uint32_t);
@@ -100,8 +102,7 @@ init_framebuffer(framebuffer_info * const fbi) {
     fbi->z.buffer =
         calloc(fbi->z.bytes / sizeof(uint32_t), sizeof(uint32_t));
 
-    if(fbi->img.buffer == NULL || fbi->z.buffer == NULL)
-    {
+    if(fbi->img.buffer == NULL || fbi->z.buffer == NULL) {
         free(fbi->img.buffer);
         free(fbi->z.buffer);
 
@@ -171,11 +172,13 @@ realloc_image_buffer(int32_t            const new_maxval,
   performed: only the global variable "maxval" is changed. But the image
   buffer is nonetheless left in cleared state regardless.
 -----------------------------------------------------------------------------*/
-    uint8_t num_planes = fbi->num_attribs + 1;
+    uint8_t num_planes;
 
     pnm_freepamrow(fbi->pamrow);
     fbi->pamrow = NULL;
 
+    num_planes = fbi->num_attribs + 1;  /* initial value */
+
     if (new_num_attribs != fbi->num_attribs) {
         fbi->num_attribs = new_num_attribs;
         num_planes = fbi->num_attribs + 1;
@@ -184,7 +187,8 @@ realloc_image_buffer(int32_t            const new_maxval,
             fbi->width * fbi->height * (num_planes * sizeof(uint16_t));
 
         {
-            uint16_t* new_ptr = realloc(fbi->img.buffer, fbi->img.bytes);
+            uint16_t * const new_ptr =
+                realloc(fbi->img.buffer, fbi->img.bytes);
 
             if (new_ptr == NULL) {
                 free(fbi->img.buffer);
@@ -229,16 +233,17 @@ realloc_image_buffer(int32_t            const new_maxval,
 void
 print_framebuffer(framebuffer_info * const fbi) {
 
-    uint8_t num_planes = fbi->num_attribs + 1;
-    uint32_t i = 0;
-    uint32_t end = fbi->width * fbi->height;
+    uint8_t  const num_planes = fbi->num_attribs + 1;
+    uint32_t const end        = fbi->width * fbi->height;
+
+    uint32_t i;
 
     pnm_writepaminit(&fbi->outpam);
 
-    while (i != end) {
+    for (i = 0; i != end; ) {
         int j;
         for (j = 0; j < fbi->width; j++) {
-            uint32_t k = (i + j) * num_planes;
+            uint32_t const k = (i + j) * num_planes;
 
             unsigned int l;
 
@@ -286,19 +291,19 @@ draw_span(uint32_t           const base,
 
   This function does not perform any kind of bounds checking.
 -----------------------------------------------------------------------------*/
-    uint8_t num_planes = fbi->num_attribs + 1;
+    uint8_t const num_planes = fbi->num_attribs + 1;
 
     unsigned int i;
 
     /* Process each pixel in the span: */
 
     for (i = 0; i < length; i++) {
-        int32_t z = MAX_Z - attribs_start[fbi->num_attribs].q;
-        uint32_t z_mask = -(~(z - fbi->z.buffer[base + i]) >> 31);
-        uint32_t n_z_mask = ~z_mask;
+        int32_t  const z        = MAX_Z - attribs_start[fbi->num_attribs].q;
+        uint32_t const z_mask   = -(~(z - fbi->z.buffer[base + i]) >> 31);
+        uint32_t const n_z_mask = ~z_mask;
 
-        uint32_t j = base + i;
-        uint32_t k = j * num_planes;
+        uint32_t const j = base + i;
+        uint32_t const k = j * num_planes;
 
         unsigned int l;
 
@@ -327,4 +332,3 @@ draw_span(uint32_t           const base,
 
 
 
-
diff --git a/generator/pamtris/input.c b/generator/pamtris/input.c
index 93390da6..0b533270 100644
--- a/generator/pamtris/input.c
+++ b/generator/pamtris/input.c
@@ -131,7 +131,7 @@ next_token(char * const startPos) {
 
 
 static bool
-validate_string(const char * const target,
+string_is_valid(const char * const target,
                 const char * const srcBegin,
                 const char * const srcEnd) {
 
@@ -205,26 +205,33 @@ process_next_command(input_info           * const line,
 
     long int i_args[MAX_NUM_ATTRIBS];
         /* For storing potential integer arguments. */
-    char * strtol_end = NULL;
+    char * strtol_end;
         /* To compare against nt.end when checking for errors with strtol */
-    bool unrecognized_cmd = false;
+    bool unrecognized_cmd;
         /* To print out an error message in case an unrecognized command was
            given.
         */
-    bool unrecognized_arg = false;
+    bool unrecognized_arg;
         /* To print out an error message in case an unrecognized argument was
            given.
         */
-    bool break_out = false;
+    bool must_break_out;
         /* To break out of the below switch statement when an invalid argument
            is found.
         */
-    bool ok = false;
+    bool ok;
         /* Indicates whether the input line was OK so that we can print out a
            warning in case of excess arguments.
         */
 
-    if (state.initialized == false) {
+    /* initial values */
+    strtol_end = NULL;
+    unrecognized_cmd = false;
+    unrecognized_arg = false;
+    must_break_out = false;
+    ok = false;
+
+    if (!state.initialized) {
         init_state(&state);
         clear_attribs(&state, fbi->maxval, fbi->num_attribs);
 
@@ -243,7 +250,7 @@ process_next_command(input_info           * const line,
 
     switch (*nt.begin) {
     case 'm':
-        if (validate_string(CMD_SET_MODE, nt.begin, nt.end) == false) {
+        if (!string_is_valid(CMD_SET_MODE, nt.begin, nt.end)) {
             unrecognized_cmd = true;
 
             break;
@@ -261,7 +268,7 @@ process_next_command(input_info           * const line,
 
         switch(*nt.begin) {
         case 't':
-            if (validate_string(ARG_TRIANGLES, nt.begin, nt.end) == false) {
+            if (!string_is_valid(ARG_TRIANGLES, nt.begin, nt.end)) {
                 unrecognized_arg = true;
 
                 break;
@@ -275,7 +282,7 @@ process_next_command(input_info           * const line,
 
             break;
         case 's':
-            if (validate_string(ARG_STRIP, nt.begin, nt.end) == false) {
+            if (!string_is_valid(ARG_STRIP, nt.begin, nt.end)) {
                 unrecognized_arg = true;
 
                 break;
@@ -289,7 +296,7 @@ process_next_command(input_info           * const line,
 
             break;
         case 'f':
-            if (validate_string(ARG_FAN, nt.begin, nt.end) == false) {
+            if (!string_is_valid(ARG_FAN, nt.begin, nt.end)) {
                 unrecognized_arg = true;
 
                 break;
@@ -306,7 +313,7 @@ process_next_command(input_info           * const line,
             unrecognized_arg = true;
         }
 
-        if (unrecognized_arg == true) {
+        if (unrecognized_arg) {
             pm_errormsg("error: unrecognized drawing mode in line %lu.",
                         line->number);
         }
@@ -314,7 +321,7 @@ process_next_command(input_info           * const line,
         break;
     case 'a': {
         uint8_t i;
-        if (validate_string(CMD_SET_ATTRIBS, nt.begin, nt.end) == false) {
+        if (!string_is_valid(CMD_SET_ATTRIBS, nt.begin, nt.end)) {
             unrecognized_cmd = true;
 
             break;
@@ -328,7 +335,7 @@ process_next_command(input_info           * const line,
             if (*nt.begin == '\0' || strtol_end != nt.end) {
                 pm_errormsg(SYNTAX_ERROR, line->number);
 
-                break_out = true;
+                must_break_out = true;
 
                 break;
             }
@@ -337,13 +344,13 @@ process_next_command(input_info           * const line,
                 pm_errormsg("error: argument(s) out of bounds: line %lu.",
                             line->number);
 
-                break_out = true;
+                must_break_out = true;
 
                 break;
             }
         }
 
-        if (break_out == true)
+        if (must_break_out)
         {
             break;
         }
@@ -358,7 +365,7 @@ process_next_command(input_info           * const line,
     case 'v': {
         uint8_t i;
 
-        if (validate_string(CMD_VERTEX, nt.begin, nt.end) == false) {
+        if (!string_is_valid(CMD_VERTEX, nt.begin, nt.end)) {
             unrecognized_cmd = true;
 
             break;
@@ -372,7 +379,7 @@ process_next_command(input_info           * const line,
             if (*nt.begin == '\0' || strtol_end != nt.end) {
                 pm_errormsg(SYNTAX_ERROR, line->number);
 
-                break_out = true;
+                must_break_out = true;
 
                 break;
             }
@@ -383,7 +390,7 @@ process_next_command(input_info           * const line,
                         "error: coordinates out of bounds: line %lu.",
                         line->number);
 
-                    break_out = true;
+                    must_break_out = true;
 
                     break;
                 }
@@ -393,14 +400,14 @@ process_next_command(input_info           * const line,
                         "error: Z component out of bounds: line %lu.",
                         line->number);
 
-                    break_out = true;
+                    must_break_out = true;
 
                     break;
                 }
             }
         }
 
-        if (break_out == true)
+        if (must_break_out)
         {
             break;
         }
@@ -416,7 +423,7 @@ process_next_command(input_info           * const line,
 
         state.next++;
 
-        if (state.draw == false) {
+        if (!state.draw) {
             if (state.next == 3) {
                 state.draw = true;
             }
@@ -443,7 +450,7 @@ process_next_command(input_info           * const line,
 
     } break;
     case 'p':
-        if (validate_string(CMD_PRINT, nt.begin, nt.end) == false) {
+        if (!string_is_valid(CMD_PRINT, nt.begin, nt.end)) {
             unrecognized_cmd = true;
 
             break;
@@ -463,15 +470,14 @@ process_next_command(input_info           * const line,
 
         break;
     case 'c':
-        if (validate_string(CMD_CLEAR, nt.begin, nt.end) == false) {
+        if (!string_is_valid(CMD_CLEAR, nt.begin, nt.end)) {
             unrecognized_cmd = true;
 
             break;
         }
     case '*':
         if (*nt.begin == '*') {
-            if(nt.end - nt.begin > 1)
-            {
+            if(nt.end - nt.begin > 1) {
                 unrecognized_cmd = true;
 
                 break;
@@ -485,7 +491,7 @@ process_next_command(input_info           * const line,
 
             switch(*nt.begin) {
             case 'i':
-                if (validate_string("image", nt.begin, nt.end) == false) {
+                if (!string_is_valid("image", nt.begin, nt.end)) {
                     unrecognized_arg = true;
 
                     break;
@@ -495,7 +501,7 @@ process_next_command(input_info           * const line,
 
                 break;
             case 'd':
-                if (validate_string("depth", nt.begin, nt.end) == false) {
+                if (!string_is_valid("depth", nt.begin, nt.end)) {
                     unrecognized_arg = true;
 
                     break;
@@ -516,7 +522,7 @@ process_next_command(input_info           * const line,
                 unrecognized_arg = true;
             }
 
-            if (unrecognized_arg == true) {
+            if (unrecognized_arg) {
                 pm_errormsg("error: unrecognized argument: line %lu.",
                             line->number);
 
@@ -532,7 +538,7 @@ process_next_command(input_info           * const line,
     case 'r': {
         uint8_t i;
 
-        if (validate_string(CMD_RESET, nt.begin, nt.end) == false) {
+        if (!string_is_valid(CMD_RESET, nt.begin, nt.end)) {
             unrecognized_cmd = true;
 
             break;
@@ -546,13 +552,13 @@ process_next_command(input_info           * const line,
             if (*nt.begin == '\0' || nt.end != strtol_end) {
                 pm_errormsg(SYNTAX_ERROR, line->number);
 
-                break_out = true;
+                must_break_out = true;
 
                 break;
             }
         }
 
-        if (break_out == true) {
+        if (must_break_out) {
             break;
         }
 
@@ -603,7 +609,7 @@ process_next_command(input_info           * const line,
 
     } break;
     case 'q':
-        if (validate_string(CMD_QUIT, nt.begin, nt.end) == false) {
+        if (!string_is_valid(CMD_QUIT, nt.begin, nt.end)) {
             unrecognized_cmd = true;
 
             break;
@@ -617,13 +623,13 @@ process_next_command(input_info           * const line,
     }
 
     {
-        char next = *next_token(nt.end).begin;
+        char const next = *next_token(nt.end).begin;
 
-        if (unrecognized_cmd == true) {
+        if (unrecognized_cmd) {
             pm_errormsg("error: unrecognized command: line %lu.",
                         line->number);
         }
-        else if (ok == true && next != '\0') {
+        else if (ok && next != '\0') {
             pm_message(WARNING_EXCESS_ARGS, line->number);
         }
     }
diff --git a/generator/pamtris/triangle.c b/generator/pamtris/triangle.c
index f6a9aef5..1190e760 100644
--- a/generator/pamtris/triangle.c
+++ b/generator/pamtris/triangle.c
@@ -28,7 +28,7 @@ draw_partial_triangle(
     const boundary_info * const bi,
     framebuffer_info *    const fbi) {
 
-    uint8_t num_planes = fbi->num_attribs + 1;
+    uint8_t const num_planes = fbi->num_attribs + 1;
 
     fract * left_attribs;
     fract * right_attribs;
@@ -51,18 +51,19 @@ draw_partial_triangle(
     }
 
     {
-        int32_t row_delta = last_row_index - first_row_index;
-        int32_t row = first_row_index;
+        int32_t const row_delta = last_row_index - first_row_index;
+
+        int32_t row;
 
         int32_t left_boundary;
         int32_t right_boundary;
 
-        while (row <= last_row_index) {
+        for (row = first_row_index; row <= last_row_index; ) {
             get_triangle_boundaries(row, &left_boundary, &right_boundary, bi);
             {
-                int32_t column_delta = right_boundary - left_boundary;
-                int32_t start_column = left_boundary;
-                int32_t span_length = column_delta;
+                int32_t const column_delta = right_boundary - left_boundary;
+                int32_t start_column;
+                int32_t span_length;
 
                 fract   * attribs_start;
                 int32_t * attribs_begin;
@@ -74,6 +75,9 @@ draw_partial_triangle(
                 MALLOCARRAY(attribs_end,   num_planes);
                 MALLOCARRAY(attribs_steps, num_planes);
 
+                start_column = left_boundary;  /* initial value */
+                span_length = column_delta;    /* initial value */
+
                 fract_to_int32_array(left_attribs, attribs_begin, num_planes);
                 fract_to_int32_array(right_attribs, attribs_end, num_planes);
 
@@ -134,7 +138,7 @@ draw_degenerate_horizontal(Xy                 const xy,
                            int32_t            const mid2bot_delta,
                            framebuffer_info * const fbi) {
 
-    uint8_t num_planes = fbi->num_attribs + 1;
+    uint8_t const num_planes = fbi->num_attribs + 1;
 
     fract * attribs_left_bkup;
 
@@ -143,7 +147,7 @@ draw_degenerate_horizontal(Xy                 const xy,
     memcpy(attribs_left_bkup, attribs_left, num_planes * sizeof(fract));
 
     {
-        int16_t y = xy._[0][1];
+        int16_t const y = xy._[0][1];
 
         int16_t x[3];
         int16_t x_start[3];
@@ -173,7 +177,7 @@ draw_degenerate_horizontal(Xy                 const xy,
         span_length[2] = x[2] - x[1];
 
         for (i = 0; i < 3; i++) {
-            int32_t column_delta = span_length[i];
+            int32_t const column_delta = span_length[i];
 
             if (x_start[i] >= fbi->width || x_start[i] + span_length[i] < 0) {
                 continue;
@@ -209,7 +213,7 @@ draw_triangle(Xy                 const xy_input,
               boundary_info *    const bi,
               framebuffer_info * const fbi) {
 
-    uint8_t num_planes = fbi->num_attribs + 1;
+    uint8_t const num_planes = fbi->num_attribs + 1;
 
     Xy xy;
     int32_t * attribs[3];
@@ -237,9 +241,9 @@ draw_triangle(Xy                 const xy_input,
     sort3(index_array, y_array, x_array);
 
     {
-        uint8_t top = index_array[0];
-        uint8_t mid = index_array[1];
-        uint8_t bot = index_array[2];
+        uint8_t const top = index_array[0];
+        uint8_t const mid = index_array[1];
+        uint8_t const bot = index_array[2];
 
         bool mid_is_to_the_left;
 
@@ -258,9 +262,10 @@ draw_triangle(Xy                 const xy_input,
         if (bi->start_scanline == -1) {
             /* Triangle is completely out of the bounds of the framebuffer. */
         } else {
-            bool no_upper_part = (xy_sorted._[1][1] == xy_sorted._[0][1]);
+            bool const no_upper_part =
+                (xy_sorted._[1][1] == xy_sorted._[0][1]);
 
-            bool horizontal =
+            bool const horizontal =
                 (xy._[0][1] == xy._[1][1] && xy._[1][1] == xy._[2][1]);
                 /* We are dealing with a degenerate horizontal triangle */
 
@@ -295,7 +300,7 @@ draw_triangle(Xy                 const xy_input,
             MALLOCARRAY_NOFAIL(left_attribs, num_planes);
             MALLOCARRAY_NOFAIL(right_attribs, num_planes);
 
-            if (horizontal == false) {
+            if (!horizontal) {
                 top2mid_delta += !no_upper_part;
                 top2bot_delta += 1;
                 mid2bot_delta += no_upper_part;
@@ -396,7 +401,7 @@ draw_triangle(Xy                 const xy_input,
                     );
             } else {
                 if (bi->start_scanline > xy._[mid][1]) {
-                    int32_t delta = bi->start_scanline - xy._[mid][1];
+                    int32_t const delta = bi->start_scanline - xy._[mid][1];
 
                     multi_step_up(left_attribs, lower_left_attribs_steps,
                                   num_planes, delta, lower_left_delta);
diff --git a/generator/pamtris/utils.c b/generator/pamtris/utils.c
index 2ce42576..fb833aaf 100644
--- a/generator/pamtris/utils.c
+++ b/generator/pamtris/utils.c
@@ -33,12 +33,14 @@ step_up(fract *       const vars,
     unsigned int i;
 
     for (i = 0; i < elements; ++i) {
-        uint32_t negative_mask = -steps[i].negative_flag;
+        uint32_t const negative_mask = -steps[i].negative_flag;
+
         vars[i].q += steps[i].q;
         vars[i].r += steps[i].r;
 
         {
-            uint32_t overdiv_mask = -(((uint32_t)~(vars[i].r - div)) >> 31);
+            uint32_t const overdiv_mask =
+                -(((uint32_t)~(vars[i].r - div)) >> 31);
                 /*  = ~0 if var->r >= div; 0 otherwise. */
 
             vars[i].q += (negative_mask | 1) & overdiv_mask;
@@ -66,14 +68,14 @@ multi_step_up(fract *       const vars,
     unsigned int i;
 
     for (i = 0; i < elements; i++) {
-        uint32_t negative_mask = -steps[i].negative_flag;
+        uint32_t const negative_mask = -steps[i].negative_flag;
 
         vars[i].q += times * steps[i].q;
         vars[i].r += times * steps[i].r;
 
         if(vars[i].r >= div && div != 0) {
-            int32_t r_q = vars[i].r / div;
-            int32_t r_r = vars[i].r % div;
+            int32_t const r_q = vars[i].r / div;
+            int32_t const r_r = vars[i].r % div;
 
             vars[i].q += (-r_q & negative_mask) | (r_q & ~negative_mask);
                 /* = -r_q if the step is negative; r_q, otherwise. */
@@ -113,7 +115,7 @@ gen_steps(const int32_t * const begin,
         unsigned int i;
 
         for (i = 0; i < elements; i++) {
-            int32_t delta = end[i] - begin[i];
+            int32_t const delta = end[i] - begin[i];
 
             out[i].q = delta / div;
             out[i].r = abs(delta % div);
@@ -123,7 +125,7 @@ gen_steps(const int32_t * const begin,
         unsigned int i;
 
         for (i = 0; i < elements; i++) {
-            int32_t delta = end[i] - begin[i];
+            int32_t const delta = end[i] - begin[i];
 
             out[i].q = delta;
             out[i].r = 0;
@@ -169,7 +171,8 @@ swap(uint8_t * const a,
 /*----------------------------------------------------------------------------
   Swap the contents pointed to by a and b.
 -----------------------------------------------------------------------------*/
-    uint8_t temp = *a;
+    uint8_t const temp = *a;
+
     *a = *b;
     *b = temp;
 }
@@ -199,9 +202,13 @@ sort3(uint8_t *       const index_array,
   coordinate, but the last two indices are then sorted with regard to relative
   X coordinate.
 -----------------------------------------------------------------------------*/
-    uint8_t * ia = index_array;
-    const int32_t * ya = y_array;
-    const int32_t * xa = x_array;
+    uint8_t * const ia = index_array;
+
+    const int32_t * ya;
+    const int32_t * xa;
+
+    ya = y_array;  /* initial value */
+    xa = x_array;  /* initial value */
 
     if (ya[0] == ya[1] && ya[1] == ya[2]) {
         /* In case the vertices represent a degenerate horizontal triangle, we