Skip to content

Commit

Permalink
now use C99 stdint.h and stdbool.h
Browse files Browse the repository at this point in the history
  • Loading branch information
brouhaha committed Aug 26, 2002
1 parent e1ff187 commit be48040
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 124 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# t2p: build a PDF file out of one or more TIFF Class F Group 4 files
# Makefile
# $Id: Makefile,v 1.9 2002/01/30 00:55:53 eric Exp $
# $Id: Makefile,v 1.10 2002/08/25 22:03:55 eric Exp $
# Copyright 2001 Eric Smith <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
Expand All @@ -25,7 +25,7 @@ YACC = bison
YFLAGS = -d -v

SRCS = bitblt.c bitblt_test.c t2p.c semantics.c
HDRS = type.h bitblt.h t2p.h semantics.h
HDRS = bitblt.h t2p.h semantics.h
MISC = Makefile scanner.l parser.y

TARGETS = t2p bitblt_test
Expand Down
49 changes: 25 additions & 24 deletions bitblt.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "type.h"
#include "bitblt.h"


#define DIV_ROUND_UP(count,pow2) (((count) - 1) / (pow2) + 1)


static const u8 bit_reverse_byte [0x100] =
static const uint8_t bit_reverse_byte [0x100] =
{
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
Expand Down Expand Up @@ -47,7 +48,7 @@ static const u8 bit_reverse_byte [0x100] =
};


void reverse_bits (u8 *p, int byte_count)
void reverse_bits (uint8_t *p, int byte_count)
{
while (byte_count--)
{
Expand All @@ -69,7 +70,7 @@ static word_type bit_reverse_word (word_type d)
static word_type *temp_buffer;
static word_type temp_buffer_size;

static void realloc_temp_buffer (u32 size)
static void realloc_temp_buffer (uint32_t size)
{
if (size <= temp_buffer_size)
return;
Expand Down Expand Up @@ -121,8 +122,8 @@ static inline word_type pixel_range_mask (int left, int right)
Bitmap *create_bitmap (Rect *rect)
{
Bitmap *bitmap;
u32 width = rect_width (rect);
u32 height = rect_height (rect);
uint32_t width = rect_width (rect);
uint32_t height = rect_height (rect);

if ((width <= 0) || (height <= 0))
return (NULL);
Expand All @@ -147,7 +148,7 @@ void free_bitmap (Bitmap *bitmap)
free (bitmap);
}

boolean get_pixel (Bitmap *bitmap, Point coord)
bool get_pixel (Bitmap *bitmap, Point coord)
{
word_type *p;
int w,b;
Expand All @@ -165,7 +166,7 @@ boolean get_pixel (Bitmap *bitmap, Point coord)
return (((*p) & pixel_mask (b)) != 0);
}

void set_pixel (Bitmap *bitmap, Point coord, boolean value)
void set_pixel (Bitmap *bitmap, Point coord, bool value)
{
word_type *p;
int w,b;
Expand All @@ -189,7 +190,7 @@ void set_pixel (Bitmap *bitmap, Point coord, boolean value)

/* modifies rect1 to be the intersection of rect1 and rect2;
returns true if intersection is non-null */
static boolean clip_rect (Rect *rect1, Rect *rect2)
static bool clip_rect (Rect *rect1, Rect *rect2)
{
if (rect1->min.y > rect2->max.y)
goto empty;
Expand Down Expand Up @@ -223,12 +224,12 @@ static boolean clip_rect (Rect *rect1, Rect *rect2)
static void blt_background (Bitmap *dest_bitmap,
Rect dest_rect)
{
u32 y;
uint32_t y;
word_type *rp;
u32 left_bit, left_word;
u32 right_bit, right_word;
uint32_t left_bit, left_word;
uint32_t right_bit, right_word;
word_type left_mask, right_mask;
s32 word_count;
int32_t word_count;

/* This function requires a non-null dest rect */
assert (dest_rect.min.x < dest_rect.max.x);
Expand Down Expand Up @@ -289,7 +290,7 @@ static void blt_background (Bitmap *dest_bitmap,
/* use Duff's Device for the full words */
if (word_count)
{
s32 i = word_count;
int32_t i = word_count;
switch (i % 8)
{
while (i > 0)
Expand Down Expand Up @@ -323,7 +324,7 @@ static void blt (Bitmap *src_bitmap,
Bitmap *dest_bitmap,
Rect *dest_rect)
{
s32 y;
int32_t y;
word_type *rp;

/* This function requires a non-null src rect */
Expand Down Expand Up @@ -402,18 +403,18 @@ Bitmap *bitblt (Bitmap *src_bitmap,
{
Rect sr, dr; /* src and dest rects, clipped to visible portion of
dest rect */
u32 drw, drh; /* dest rect width, height - gets adjusted */
uint32_t drw, drh; /* dest rect width, height - gets adjusted */
Point src_point, dest_point;

/* dest coordinates: */
u32 x0, x1, x2, x3;
u32 y0, y1, y2, y3;
uint32_t x0, x1, x2, x3;
uint32_t y0, y1, y2, y3;

{
sr = * src_rect;

u32 srw = rect_width (& sr);
u32 srh = rect_height (& sr);
uint32_t srw = rect_width (& sr);
uint32_t srh = rect_height (& sr);

if ((srw < 0) || (srh < 0))
goto done; /* the source rect is empty! */
Expand Down Expand Up @@ -595,7 +596,7 @@ Bitmap *bitblt (Bitmap *src_bitmap,
src_point.x < src_rect->max.x;
src_point.x++)
{
boolean a;
bool a;

dest_point.x = dest_min->x + src_point.x - src_rect->min.x;

Expand All @@ -616,7 +617,7 @@ Bitmap *bitblt (Bitmap *src_bitmap,
src_point.x < src_rect->max.x;
src_point.x++)
{
boolean a, b, c;
bool a, b, c;

dest_point.x = dest_min->x + src_point.x - src_rect->min.x;

Expand All @@ -639,7 +640,7 @@ void flip_h (Bitmap *src)
word_type *rp; /* row pointer */
word_type *p1; /* work src ptr */
word_type *p2; /* work dest ptr */
s32 y;
int32_t y;
int shift1, shift2;

realloc_temp_buffer ((src->row_words + 1) * sizeof (word_type));
Expand Down Expand Up @@ -713,7 +714,7 @@ void rot_180 (Bitmap *src) /* combination of flip_h and flip_v */
/* "in-place" transformations - will allocate new memory and free old */
void transpose (Bitmap *src)
{
u32 new_row_words = DIV_ROUND_UP (rect_height (& src->rect), 32);
uint32_t new_row_words = DIV_ROUND_UP (rect_height (& src->rect), 32);
word_type *new_bits;

new_bits = calloc (1, new_row_words * rect_width (& src->rect) * sizeof (word_type));
Expand Down
18 changes: 9 additions & 9 deletions bitblt.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
typedef struct Point
{
s32 x;
s32 y;
int32_t x;
int32_t y;
} Point;

typedef struct Rect
Expand All @@ -10,18 +10,18 @@ typedef struct Rect
Point max;
} Rect;

static inline s32 rect_width (Rect *r)
static inline int32_t rect_width (Rect *r)
{
return (r->max.x - r->min.x);
}

static inline s32 rect_height (Rect *r)
static inline int32_t rect_height (Rect *r)
{
return (r->max.y - r->min.y);
}


typedef u32 word_type;
typedef uint32_t word_type;
#define BITS_PER_WORD (8 * sizeof (word_type))
#define ALL_ONES (~ 0U)

Expand All @@ -30,7 +30,7 @@ typedef struct Bitmap
{
word_type *bits;
Rect rect;
u32 row_words;
uint32_t row_words;
} Bitmap;


Expand All @@ -43,8 +43,8 @@ typedef struct Bitmap
Bitmap *create_bitmap (Rect *rect);
void free_bitmap (Bitmap *bitmap);

boolean get_pixel (Bitmap *bitmap, Point coord);
void set_pixel (Bitmap *bitmap, Point coord, boolean value);
bool get_pixel (Bitmap *bitmap, Point coord);
void set_pixel (Bitmap *bitmap, Point coord, bool value);


Bitmap *bitblt (Bitmap *src_bitmap,
Expand All @@ -68,4 +68,4 @@ void rot_90 (Bitmap *src); /* transpose + flip_h */
void rot_270 (Bitmap *src); /* transpose + flip_v */


void reverse_bits (u8 *p, int byte_count);
void reverse_bits (uint8_t *p, int byte_count);
3 changes: 2 additions & 1 deletion bitblt_test.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "type.h"
#include "bitblt.h"


Expand Down
5 changes: 3 additions & 2 deletions parser.y
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%{
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "type.h"
#include "semantics.h"
%}

Expand Down Expand Up @@ -186,7 +187,7 @@ pdf_file_attributes:

output_file_clause:
FILE_KEYWORD STRING { output_set_file ($2); }
pdf_file_attributes ';'
pdf_file_attributes ';' ;

label_clause:
LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
Expand Down
5 changes: 3 additions & 2 deletions scanner.l
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
$Id: scanner.l,v 1.15 2002/01/02 02:17:24 eric Exp $
$Id: scanner.l,v 1.16 2002/08/25 22:02:31 eric Exp $
*/

%option case-insensitive
%option noyywrap

%{
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "type.h"
#include "semantics.h"
#include "parser.tab.h"

Expand Down
31 changes: 16 additions & 15 deletions semantics.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "type.h"
#include "semantics.h"
#include "parser.tab.h"
#include "t2p.h"


typedef struct
{
boolean has_page_size;
bool has_page_size;
page_size_t page_size;

boolean has_rotation;
bool has_rotation;
int rotation;

boolean has_crop;
bool has_crop;
crop_t crop;
} input_modifiers_t;

Expand Down Expand Up @@ -57,7 +58,7 @@ typedef struct output_context_t
bookmark_t *first_bookmark;
bookmark_t *last_bookmark;

boolean has_page_label;
bool has_page_label;
page_label_t page_label;
} output_context_t;

Expand Down Expand Up @@ -432,9 +433,9 @@ static char *get_input_file (input_context_t *context)
exit (2);
}

static boolean get_input_rotation (input_context_t *context,
input_modifier_type_t type,
int *rotation)
static bool get_input_rotation (input_context_t *context,
input_modifier_type_t type,
int *rotation)
{
for (; context; context = context->parent)
{
Expand All @@ -452,9 +453,9 @@ static boolean get_input_rotation (input_context_t *context,
return (0); /* default */
}

static boolean get_input_page_size (input_context_t *context,
input_modifier_type_t type,
page_size_t *page_size)
static bool get_input_page_size (input_context_t *context,
input_modifier_type_t type,
page_size_t *page_size)
{
for (; context; context = context->parent)
{
Expand Down Expand Up @@ -510,7 +511,7 @@ void dump_input_tree (void)
for (i = image->range.first; i <= image->range.last; i++)
{
input_modifier_type_t parity = (i % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;
boolean has_rotation, has_page_size;
bool has_rotation, has_page_size;
int rotation;
page_size_t page_size;

Expand Down Expand Up @@ -571,9 +572,9 @@ static inline int range_count (range_t range)
}


boolean parse_spec_file (char *fn)
bool parse_spec_file (char *fn)
{
boolean result = 0;
bool result = 0;

yyin = fopen (fn, "r");
if (! yyin)
Expand Down Expand Up @@ -617,7 +618,7 @@ boolean parse_spec_file (char *fn)
}


boolean process_specs (void)
bool process_specs (void)
{
input_image_t *image = NULL;
output_page_t *page = NULL;
Expand Down
4 changes: 2 additions & 2 deletions semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ void output_pages (range_t range);


/* functions to be called from main program: */
boolean parse_spec_file (char *fn);
boolean process_specs (void);
bool parse_spec_file (char *fn);
bool process_specs (void);
Loading

0 comments on commit be48040

Please sign in to comment.