commit a11017aa7984f2b32d413ad89b016072fe0c8e92
parent dce0a8f7aa66846b68bd2bfad24dab6fa7ccd776
Author: Frederic Cambus <fred@statdns.com>
Date: Thu, 1 Nov 2018 09:51:56 +0100
Stop abusing C++ style comments, and remove useless comments
Diffstat:
14 files changed, 77 insertions(+), 97 deletions(-)
diff --git a/src/drawchar.c b/src/drawchar.c
@@ -15,7 +15,6 @@
#include "drawchar.h"
-// shared method for drawing characters
void drawchar(gdImagePtr im, const unsigned char *font_data, uint32_t bits,
uint32_t height, uint32_t column, uint32_t row,
uint32_t background, uint32_t foreground, unsigned char character) {
diff --git a/src/drawchar.h b/src/drawchar.h
@@ -16,7 +16,6 @@
#ifndef DRAWCHAR_H
#define DRAWCHAR_H
-// prototypes
void drawchar(gdImagePtr im, const unsigned char *font_data, uint32_t bits,
uint32_t height, uint32_t column, uint32_t row,
uint32_t background, uint32_t foreground, unsigned char character);
diff --git a/src/fonts.c b/src/fonts.c
@@ -139,7 +139,7 @@ void alSelectFont(struct fontStruct *fontData, int font) {
fontData->height = 16;
break;
default:
- // in all other cases use the standard DOS font
+ /* in all other cases use the standard DOS font */
fontData->font_data = font_pc_80x25;
fontData->width = 9;
fontData->height = 16;
diff --git a/src/fonts.h b/src/fonts.h
@@ -25,8 +25,6 @@ struct fontStruct {
void alSelectFont(struct fontStruct *fontData, int font);
-// Binary font and image data.
-
const unsigned char font_pc_80x25[4096];
const unsigned char font_pc_80x50[2048];
const unsigned char font_pc_baltic[4096];
diff --git a/src/init.c b/src/init.c
@@ -25,7 +25,7 @@ ansilove_init(struct ansilove_ctx *ctx, struct ansilove_options *options) {
memset(ctx, 0, sizeof(*ctx));
memset(options, 0, sizeof(*options));
- // default to 8 if bits option is not specified
+ /* default to 8 if bits option is not specified */
options->bits = 8;
return 0;
diff --git a/src/loaders/artworx.c b/src/loaders/artworx.c
@@ -33,25 +33,23 @@ int ansilove_artworx(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // libgd image pointers
+ /* libgd image pointers */
gdImagePtr canvas;
- // create ADF instance
+ /* create ADF instance */
canvas = gdImageCreate(640, (((ctx->length - ADF_HEADER_LENGTH) / 2) / 80) * 16);
-
- // error output
if (!canvas) {
ctx->error = ANSILOVE_GD_ERROR;
return -1;
}
- // ADF color palette array
+ /* ADF color palette array */
uint32_t adf_colors[16] = { 0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63 };
uint32_t loop;
uint32_t index;
- // process ADF palette
+ /* process ADF palette */
for (loop = 0; loop < 16; loop++) {
index = (adf_colors[loop] * 3) + 1;
gdImageColorAllocate(canvas, (ctx->buffer[index] << 2 | ctx->buffer[index] >> 4),
@@ -61,7 +59,7 @@ int ansilove_artworx(struct ansilove_ctx *ctx, struct ansilove_options *options)
gdImageColorAllocate(canvas, 0, 0, 0);
- // process ADF
+ /* process ADF */
uint32_t column = 0, row = 0;
uint32_t character, attribute, foreground, background;
loop = ADF_HEADER_LENGTH;
@@ -84,6 +82,6 @@ int ansilove_artworx(struct ansilove_ctx *ctx, struct ansilove_options *options)
loop += 2;
}
- // create output file
+ /* create output file */
return output(ctx, options, canvas);
}
diff --git a/src/loaders/binary.c b/src/loaders/binary.c
@@ -28,19 +28,18 @@ int ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // some type declarations
struct fontStruct fontData;
- // font selection
+ /* font selection */
alSelectFont(&fontData, options->font);
- // libgd image pointers
+ /* libgd image pointers */
gdImagePtr canvas;
- // Default to 160 columns if columns option wasn't set
+ /* Default to 160 columns if columns option wasn't set */
options->columns = options->columns ? options->columns : 160;
- // allocate buffer image memory
+ /* allocate buffer image memory */
canvas = gdImageCreate(options->columns * options->bits,
((ctx->length / 2) / options->columns * fontData.height));
@@ -49,10 +48,10 @@ int ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // allocate black color
+ /* allocate black color */
gdImageColorAllocate(canvas, 0, 0, 0);
- // allocate color palette
+ /* allocate color palette */
uint32_t colors[16];
for (int i = 0; i < 16; i++) {
@@ -61,7 +60,7 @@ int ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options)
binary_palette[i*3+2]);
}
- // process binary
+ /* process binary */
uint32_t character, attribute, background, foreground;
uint32_t loop = 0;
int32_t column = 0, row = 0;
@@ -92,6 +91,6 @@ int ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
}
- // create output image
+ /* create output image */
return output(ctx, options, canvas);
}
diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c
@@ -34,20 +34,20 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // extract relevant part of the IDF header, 16-bit endian unsigned short
+ /* extract relevant part of the IDF header, 16-bit endian unsigned short */
uint32_t x2 = (ctx->buffer[9] << 8) + ctx->buffer[8];
- // libgd image pointers
+ /* libgd image pointers */
gdImagePtr canvas;
uint32_t loop = 12;
uint32_t index;
uint32_t colors[16];
- // process IDF
+ /* process IDF */
uint32_t idf_sequence_length, idf_sequence_loop, i = 0;
- // dynamically allocated memory buffer for IDF data
+ /* dynamically allocated memory buffer for IDF data */
unsigned char *idf_buffer;
idf_buffer = malloc(2);
@@ -56,7 +56,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
while (loop < ctx->length - IDF_HEADER_LENGTH) {
memcpy(&idf_data, ctx->buffer+loop, 2);
- // RLE compressed data
+ /* RLE compressed data */
if (idf_data == 1) {
memcpy(&idf_data_length, ctx->buffer+loop+2, 2);
@@ -64,7 +64,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
for (idf_sequence_loop = 0; idf_sequence_loop < idf_sequence_length; idf_sequence_loop++)
{
- // reallocate IDF buffer memory
+ /* reallocate IDF buffer memory */
idf_buffer = realloc(idf_buffer, i + 2);
if (idf_buffer == NULL) {
ctx->error = ANSILOVE_MEMORY_ERROR;
@@ -79,7 +79,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
loop += 4;
} else {
- // reallocate IDF buffer memory
+ /* reallocate IDF buffer memory */
idf_buffer = realloc(idf_buffer, i + 2);
if (idf_buffer == NULL) {
ctx->error = ANSILOVE_MEMORY_ERROR;
@@ -88,7 +88,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // normal character
+ /* normal character */
idf_buffer[i] = ctx->buffer[loop];
idf_buffer[i+1] = ctx->buffer[loop + 1];
i += 2;
@@ -96,10 +96,10 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
loop += 2;
}
- // create IDF instance
+ /* create IDF instance */
canvas = gdImageCreate((x2 + 1) * 8, i / 2 / 80 * 16);
- // error output
+ /* error output */
if (!canvas) {
ctx->error = ANSILOVE_GD_ERROR;
free(idf_buffer);
@@ -107,7 +107,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
gdImageColorAllocate(canvas, 0, 0, 0);
- // process IDF palette
+ /* process IDF palette */
for (loop = 0; loop < 16; loop++) {
index = (loop * 3) + ctx->length - 48;
colors[loop] = gdImageColorAllocate(canvas, (ctx->buffer[index] << 2 | ctx->buffer[index] >> 4),
@@ -115,7 +115,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
(ctx->buffer[index + 2] << 2 | ctx->buffer[index + 2] >> 4));
}
- // render IDF
+ /* render IDF */
uint32_t column = 0, row = 0;
uint32_t character, attribute, foreground, background;
@@ -136,13 +136,12 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
column++;
}
- // create output file
+ /* create output file */
if (output(ctx, options, canvas) != 0) {
free(idf_buffer);
return -1;
}
- // free memory
free(idf_buffer);
return 0;
diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c
@@ -19,7 +19,7 @@
#include "fonts.h"
#include "output.h"
-// Character structure
+/* Character structure */
struct pcbChar {
uint32_t column;
uint32_t row;
@@ -37,28 +37,26 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // some type declarations
struct fontStruct fontData;
uint32_t loop, structIndex;
- // font selection
+ /* font selection */
alSelectFont(&fontData, options->font);
- // libgd image pointers
+ /* libgd image pointers */
gdImagePtr canvas;
- // process PCBoard
unsigned char character, current_character, next_character;
uint32_t background = 0, foreground = 7;
uint32_t column = 0, row = 0, columnMax = 0, rowMax = 0;
- // PCB buffer structure array definition
+ /* PCB buffer structure array definition */
struct pcbChar *pcboard_buffer;
- // PCB buffer dynamic memory allocation
+ /* PCB buffer dynamic memory allocation */
pcboard_buffer = malloc(sizeof (struct pcbChar));
- // reset loop
+ /* reset loop */
loop = 0;
structIndex = 0;
@@ -71,37 +69,37 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
column = 0;
}
- // CR + LF
+ /* CR + LF */
if (current_character == 13 && next_character == 10) {
row++;
column = 0;
loop++;
}
- // LF
+ /* LF */
if (current_character == 10) {
row++;
column = 0;
}
- // Tab
+ /* Tab */
if (current_character == 9)
column += 8;
- // Sub
+ /* Sub */
if (current_character == 26)
break;
- // PCB sequence
+ /* PCB sequence */
if (current_character == 64 && next_character == 88) {
- // set graphics rendition
+ /* set graphics rendition */
background = ctx->buffer[loop+2];
foreground = ctx->buffer[loop+3];
loop += 3;
}
else if (current_character == 64 && next_character == 67 &&
ctx->buffer[loop+2] == 'L' && ctx->buffer[loop+3] == 'S') {
- // erase display
+ /* erase display */
column = 0;
row = 0;
@@ -111,7 +109,7 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
loop += 4;
} else if (current_character == 64 && next_character == 80 && ctx->buffer[loop+2] == 'O'
&& ctx->buffer[loop+3] == 'S' && ctx->buffer[loop+4] == ':') {
- // cursor position
+ /* cursor position */
if (ctx->buffer[loop+6] == '@')
{
column = ((ctx->buffer[loop+5])-48)-1;
@@ -123,14 +121,14 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
loop += 6;
}
} else if (current_character != 10 && current_character != 13 && current_character != 9) {
- // record number of columns and lines used
+ /* record number of columns and lines used */
if (column > columnMax)
columnMax = column;
if (row > rowMax)
rowMax = row;
- // reallocate structure array memory
+ /* reallocate structure array memory */
pcboard_buffer = realloc(pcboard_buffer, (structIndex + 1) * sizeof (struct pcbChar));
if (pcboard_buffer == NULL) {
ctx->error = ANSILOVE_MEMORY_ERROR;
@@ -139,7 +137,7 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // write current character in pcbChar structure
+ /* write current character in pcbChar structure */
pcboard_buffer[structIndex].column = column;
pcboard_buffer[structIndex].row = row;
pcboard_buffer[structIndex].background = pcb_colors[background];
@@ -154,7 +152,7 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
columnMax++;
rowMax++;
- // allocate buffer image memory
+ /* allocate buffer image memory */
canvas = gdImageCreate(80 * options->bits, (rowMax)*fontData.height);
if (!canvas) {
@@ -163,11 +161,11 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // allocate black color and create background canvas
+ /* allocate black color and create background canvas */
gdImageColorAllocate(canvas, 0, 0, 0);
gdImageFill(canvas, 0, 0, 0);
- // allocate color palette
+ /* allocate color palette */
uint32_t colors[16];
for (int i = 0; i < 16; i++) {
@@ -176,12 +174,11 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
ansi_palette[i*3+2]);
}
- // the last value of loop tells us how many items are stored in there
uint32_t pcbBufferItems = structIndex;
- // render PCB
+ /* render PCB */
for (loop = 0; loop < pcbBufferItems; loop++) {
- // grab our chars out of the structure
+ /* grab our chars out of the structure */
column = pcboard_buffer[loop].column;
row = pcboard_buffer[loop].row;
background = pcboard_buffer[loop].background;
@@ -192,13 +189,12 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
column, row, colors[background], colors[foreground], character);
}
- // create output image
+ /* create output image */
if (output(ctx, options, canvas) != 0) {
free(pcboard_buffer);
return -1;
}
- // free memory
free(pcboard_buffer);
return 0;
diff --git a/src/loaders/tundra.c b/src/loaders/tundra.c
@@ -41,29 +41,28 @@ int ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // some type declarations
struct fontStruct fontData;
char tundra_version;
options->columns = options->columns ? options->columns : 80;
int32_t columns = options->columns;
- // font selection
+ /* font selection */
alSelectFont(&fontData, options->font);
- // libgd image pointers
+ /* libgd image pointers */
gdImagePtr canvas;
- // extract tundra header
+ /* extract tundra header */
tundra_version = ctx->buffer[0];
- // need to add check for "TUNDRA24" string in the header
+ /* XXX: add check for "TUNDRA24" string in the header */
if (tundra_version != TUNDRA_VERSION) {
ctx->error = ANSILOVE_FORMAT_ERROR;
return -1;
}
- // read tundra file a first time to find the image size
+ /* read tundra file a first time to find the image size */
uint32_t cursor, character, background = 0, foreground = 0;
uint32_t loop = TUNDRA_HEADER_LENGTH;
int32_t column = 0, row = 1;
@@ -114,7 +113,7 @@ int ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
- // allocate buffer image memory
+ /* allocate buffer image memory */
canvas = gdImageCreateTrueColor(columns * options->bits,
row * fontData.height);
@@ -123,7 +122,7 @@ int ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // process tundra
+ /* process tundra */
column = 0;
row = 0;
@@ -203,6 +202,6 @@ int ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options)
loop++;
}
- // create output image
+ /* create output image */
return output(ctx, options, canvas);
}
diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c
@@ -51,13 +51,13 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
return -1;
}
- // allocate black color
+ /* allocate black color */
gdImageColorAllocate(canvas, 0, 0, 0);
uint32_t colors[16];
uint32_t offset = 11;
- // palette
+ /* palette */
if ((xbin_flags & 1) == 1) {
uint32_t loop;
uint32_t index;
@@ -79,11 +79,11 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
}
- // font
+ /* font */
if ((xbin_flags & 2) == 2) {
uint32_t numchars = (xbin_flags & 0x10 ? 512 : 256);
- // allocate memory to contain the XBin font
+ /* allocate memory to contain the XBin font */
font_data_xbin = (unsigned char *)malloc(xbin_fontsize * numchars);
if (font_data_xbin == NULL) {
ctx->error = ANSILOVE_MEMORY_ERROR;
@@ -95,14 +95,14 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
offset += (xbin_fontsize * numchars);
} else {
- // using default 80x25 font
+ /* using default 80x25 font */
font_data = font_pc_80x25;
}
uint32_t column = 0, row = 0, foreground, background;
int32_t character, attribute;
- // read compressed xbin
+ /* read compressed xbin */
if ((xbin_flags & 4) == 4) {
while (offset < ctx->length && row != xbin_height) {
uint32_t ctype = ctx->buffer[offset] & 0xC0;
@@ -113,13 +113,13 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
offset++;
while (counter--) {
- // none
+ /* none */
if (ctype == 0) {
character = ctx->buffer[offset];
attribute = ctx->buffer[offset + 1];
offset += 2;
}
- // char
+ /* char */
else if (ctype == 0x40) {
if (character == -1) {
character = ctx->buffer[offset];
@@ -128,7 +128,7 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
attribute = ctx->buffer[offset];
offset++;
}
- // attr
+ /* attr */
else if (ctype == 0x80) {
if (attribute == -1) {
attribute = ctx->buffer[offset];
@@ -137,7 +137,7 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
character = ctx->buffer[offset];
offset++;
}
- // both
+ /* both */
else {
if (character == -1) {
character = ctx->buffer[offset];
@@ -163,7 +163,7 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
}
} else {
- // read uncompressed xbin
+ /* read uncompressed xbin */
while (offset < ctx->length && row != xbin_height) {
if (column == xbin_width) {
column = 0;
@@ -183,14 +183,13 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
}
- // create output file
+ /* create output file */
if (output(ctx, options, canvas) != 0) {
free(font_data_xbin);
font_data = NULL;
return -1;
}
- // nuke garbage
free(font_data_xbin);
return 0;
diff --git a/src/loadfile.c b/src/loadfile.c
@@ -29,15 +29,12 @@ ansilove_loadfile(struct ansilove_ctx *ctx, char *input) {
return -1;
}
- // load input file
fd = open(input, O_RDONLY);
-
if (fd == -1) {
ctx->error = ANSILOVE_FILE_READ_ERROR;
return -1;
}
- // get the file size (bytes)
if (fstat(fd, &st) == -1) {
ctx->error = ANSILOVE_FILE_READ_ERROR;
close(fd);
@@ -46,7 +43,7 @@ ansilove_loadfile(struct ansilove_ctx *ctx, char *input) {
ctx->length = st.st_size;
- // mmap input file into memory
+ /* mmap input file into memory */
ctx->buffer = mmap(NULL, ctx->length, PROT_READ, MAP_PRIVATE, fd, 0);
if (ctx->buffer == MAP_FAILED) {
ctx->error = ANSILOVE_MEMORY_ERROR;
@@ -54,7 +51,6 @@ ansilove_loadfile(struct ansilove_ctx *ctx, char *input) {
return -1;
}
- // close input file, we don't need it anymore
close(fd);
return 0;
diff --git a/src/output.c b/src/output.c
@@ -15,9 +15,9 @@
#include "output.h"
int output(struct ansilove_ctx *ctx, struct ansilove_options *options, gdImagePtr im_Source) {
- // XXX Error handling
- // XXX The caller must invoke gdFree()
- // XXX Allow combining DOS aspect ratio and Retina
+ /* XXX Error handling */
+ /* XXX The caller must invoke gdFree() */
+ /* XXX Allow combining DOS aspect ratio and Retina */
if (!options->scale_factor && !options->dos) {
ctx->png.buffer = gdImagePngPtr(im_Source, &ctx->png.length);
@@ -41,7 +41,6 @@ int output(struct ansilove_ctx *ctx, struct ansilove_options *options, gdImagePt
} else {
gdImagePtr im_Retina;
- // make the Retina image scale_factor as large as im_Source
im_Retina = gdImageCreate(im_Source->sx * options->scale_factor,
im_Source->sy * options->scale_factor);
@@ -53,7 +52,7 @@ int output(struct ansilove_ctx *ctx, struct ansilove_options *options, gdImagePt
gdImageCopyResized(im_Retina, im_Source, 0, 0, 0, 0,
im_Retina->sx, im_Retina->sy, im_Source->sx, im_Source->sy);
- // create retina output image
+ /* create retina output image */
gdImageDestroy(im_Source);
ctx->png.buffer = gdImagePngPtr(im_Retina, &ctx->png.length);
}
diff --git a/src/output.h b/src/output.h
@@ -18,7 +18,6 @@ struct ansilove_options;
#ifndef OUTPUT_H
#define OUTPUT_H
-// prototypes
int output(struct ansilove_ctx *, struct ansilove_options *, gdImagePtr);
#endif /* OUTPUT_H */