-obj = main.obj video.obj vga.obj vbe.obj watdpmi.obj mouse.obj
+obj = main.obj video.obj vga.obj vbe.obj watdpmi.obj mouse.obj chkalloc.obj
bin = imgv.exe
#opt = -otexan
warn = -w=3
dbg = -d3
-def = -DNO_STDINT_H
!ifdef __UNIX__
inc = -Iimago/src
libimago = imago/imago.lib
!endif
libdir = libpath imago
+#def = -DCHECK_ALLOC
+
CC = wcc386
LD = wlink
CFLAGS = $(warn) $(dbg) $(opt) $(def) -zq -bt=dos $(inc)
src/filetga.obj src/filelbm.obj src/ftmodule.obj src/imago2.obj src/imago_gl.obj &
src/byteord.obj src/modules.obj $(libpng) $(zlib) $(jpeglib)
+inc = -I../src
!else
libpng = libpng\png.obj libpng\pngerror.obj libpng\pngget.obj libpng\pngmem.obj &
obj = src\conv.obj src\filejpeg.obj src\filepng.obj src\fileppm.obj src\filergbe.obj &
src\filetga.obj src\filelbm.obj src\ftmodule.obj src\imago2.obj src\imago_gl.obj &
src\byteord.obj src\modules.obj $(libpng) $(zlib) $(jpeglib)
+
+inc = -I..\src
!endif
alib = imago.lib
def = -DPNG_NO_SNPRINTF
CC = wcc386
-CFLAGS = $(dbg) $(opt) $(def) -zq -bt=dos -Ilibpng -Izlib -Ijpeglib
+CFLAGS = $(dbg) $(opt) $(def) -zq -bt=dos -Ilibpng -Izlib -Ijpeglib $(inc)
-$(alib): $(obj)
+$(alib): cflags.occ $(obj)
%write objects.lbc $(obj)
wlib -b -n $@ @objects
.c: src;libpng;jpeglib;zlib
+cflags.occ: Makefile
+ %write $@ $(CFLAGS)
+
.c.obj: .autodepend
- $(CC) -fo=$@ $(CFLAGS) $[*
+ $(CC) -fo=$@ @cflags.occ $[*
!ifdef __UNIX__
clean: .symbolic
rm -f $(obj)
rm -f objects.lbc
+ rm -f cflags.occ
rm -f $(alib)
!else
clean: .symbolic
del libpng\*.obj
del jpeglib\*.obj
del objects.lbc
+ del cflags.occ
del $(alib)
!endif
#include <jpeglib.h>
#include "imago2.h"
#include "ftmodule.h"
+#include "chkalloc.h"
#define INPUT_BUF_SIZE 512
#define OUTPUT_BUF_SIZE 512
return -1;
}
- if(!(scanlines = malloc(img->height * sizeof *scanlines))) {
+ if(!(scanlines = chk_malloc(img->height * sizeof *scanlines))) {
jpeg_destroy_decompress(&cinfo);
return -1;
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
- free(scanlines);
+ chk_free(scanlines);
return 0;
}
img = &tmpimg;
}
- if(!(scanlines = malloc(img->height * sizeof *scanlines))) {
+ if(!(scanlines = chk_malloc(img->height * sizeof *scanlines))) {
img_destroy(&tmpimg);
return -1;
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
- free(scanlines);
+ chk_free(scanlines);
img_destroy(&tmpimg);
return 0;
}
#include <png.h>
#include "imago2.h"
#include "ftmodule.h"
+#include "chkalloc.h"
static int check_file(struct img_io *io);
static int read_file(struct img_pixmap *img, struct img_io *io);
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_text(png, info, &txt, 1);
- if(!(rows = malloc(img->height * sizeof *rows))) {
+ if(!(rows = chk_malloc(img->height * sizeof *rows))) {
png_destroy_write_struct(&png, &info);
img_destroy(&tmpimg);
return -1;
png_write_end(png, info);
png_destroy_write_struct(&png, &info);
- free(rows);
+ chk_free(rows);
img_destroy(&tmpimg);
return 0;
}
buf = malloc(ptypelen > 120 ? ptypelen + 8 : 128);
sprintf(buf, "#?%s\n", programtype);
- if(io->write(buf, strlen(buf), io->uptr) < 0)
+ if(io->write(buf, strlen(buf), io->uptr) <= 0)
goto err;
/* The #? is to identify file type, the programtype is optional. */
if(info && (info->valid & RGBE_VALID_GAMMA)) {
sprintf(buf, "GAMMA=%g\n", info->gamma);
- if(io->write(buf, strlen(buf), io->uptr) < 0)
+ if(io->write(buf, strlen(buf), io->uptr) <= 0)
goto err;
}
if(info && (info->valid & RGBE_VALID_EXPOSURE)) {
sprintf(buf, "EXPOSURE=%g\n", info->exposure);
- if(io->write(buf, strlen(buf), io->uptr) < 0)
+ if(io->write(buf, strlen(buf), io->uptr) <= 0)
goto err;
}
strcpy(buf, "FORMAT=32-bit_rle_rgbe\n\n");
- if(io->write(buf, strlen(buf), io->uptr) < 0)
+ if(io->write(buf, strlen(buf), io->uptr) <= 0)
goto err;
sprintf(buf, "-Y %d +X %d\n", height, width);
- if(io->write(buf, strlen(buf), io->uptr) < 0)
+ if(io->write(buf, strlen(buf), io->uptr) <= 0)
goto err;
free(buf);
#include <stdlib.h>
#include <string.h>
#include "ftmodule.h"
+#include "chkalloc.h"
static struct list_node {
struct ftype_module *module;
{
struct list_node *node;
- if(!(node = malloc(sizeof *node))) {
+ if(!(node = chk_malloc(sizeof *node))) {
return -1;
}
#include <string.h>
#include "imago2.h"
#include "ftmodule.h"
+#include "chkalloc.h"
static int pixel_size(enum img_fmt fmt);
static size_t def_read(void *buf, size_t bytes, void *uptr);
void img_destroy(struct img_pixmap *img)
{
- free(img->pixels);
+ chk_free(img->pixels);
img->pixels = 0; /* just in case... */
img->width = img->height = 0xbadbeef;
- free(img->name);
+ chk_free(img->name);
}
struct img_pixmap *img_create(void)
{
struct img_pixmap *p;
- if(!(p = malloc(sizeof *p))) {
+ if(!(p = chk_malloc(sizeof *p))) {
return 0;
}
img_init(p);
void img_free(struct img_pixmap *img)
{
img_destroy(img);
- free(img);
+ chk_free(img);
}
int img_set_name(struct img_pixmap *img, const char *name)
{
char *tmp;
- if(!(tmp = malloc(strlen(name) + 1))) {
+ if(!(tmp = chk_malloc(strlen(name) + 1))) {
return -1;
}
strcpy(tmp, name);
void *newpix;
int pixsz = pixel_size(fmt);
- if(!(newpix = malloc(w * h * pixsz))) {
+ if(!(newpix = chk_malloc(w * h * pixsz))) {
return -1;
}
memset(newpix, 0, w * h * pixsz);
}
- free(img->pixels);
+ chk_free(img->pixels);
img->pixels = newpix;
img->width = w;
img->height = h;
void img_free_pixels(void *pix)
{
- free(pix);
+ chk_free(pix);
}
int img_load(struct img_pixmap *img, const char *fname)
#include "video.h"
#include "mouse.h"
#include "imago2.h"
+#include "chkalloc.h"
int switch_mode(int m);
int find_best_mode(int minx, int miny);
num = num_video_modes();
vmodes = video_modes();
- if(!(vmlist = malloc(num * sizeof *vmlist))) {
+ if(!(vmlist = chk_malloc(num * sizeof *vmlist))) {
fprintf(stderr, "failed to allocate video mode list\n");
return 1;
}
end:
img_destroy(&img);
- free(backbuf);
- free(vmlist);
+ chk_free(backbuf);
+ chk_free(vmlist);
if(cur_vm >= 0) {
set_text_mode();
}
cleanup_video();
+ chk_check();
return 0;
}
vmode = vmlist + m;
cur_vm = m;
- free(backbuf);
- if(!(backbuf = malloc(vmode->ysz * vmode->pitch))) {
+ chk_free(backbuf);
+ if(!(backbuf = chk_malloc(vmode->ysz * vmode->pitch))) {
fprintf(stderr, "failed to allocate back buffer\n");
return -1;
}
#ifndef UTIL_H_
#define UTIL_H_
+#if defined(__WATCOMC__) && __WATCOMC__ < 1200
+#define NO_STDINT_H
+#endif
#ifdef NO_STDINT_H
-
-#if __WATCOMC__ >= 1200
-#include <sys/types.h>
-#else
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef unsigned long uintptr_t;
-#endif
-
#else
#include <stdint.h>
#endif
#include "vbe.h"
#include "vga.h"
#include "util.h"
+#include "chkalloc.h"
#ifdef __WATCOMC__
#include <i86.h>
num_vmodes = 0;
max_modes = 256;
- if(!(vmodes = malloc(max_modes * sizeof *vmodes))) {
+ if(!(vmodes = chk_malloc(max_modes * sizeof *vmodes))) {
fprintf(stderr, "failed to allocate video modes list\n");
return -1;
}
if(num_vmodes >= max_modes) {
int newmax = max_modes ? (max_modes << 1) : 16;
- if(!(vmptr = realloc(vmodes, newmax * sizeof *vmodes))) {
+ if(!(vmptr = chk_realloc(vmodes, newmax * sizeof *vmodes))) {
fprintf(stderr, "failed to grow video mode list (%d)\n", newmax);
- free(vmodes);
+ chk_free(vmodes);
return -1;
}
vmodes = vmptr;
void cleanup_video(void)
{
- free(vmodes);
+ chk_free(vmodes);
}
struct video_mode *video_modes(void)
parm [ecx][eax][edx]
#endif /* __WATCOMC__ */
-
+
#define MSR_MTRRCAP 0xfe
#define MSR_MTRRDEFTYPE 0x2ff
int386(0x31, ®s, ®s);
}
-void dpmi_int(int inum, struct dpmi_real_regs *dregs)
+void dpmi_int(int inum, struct dpmi_regs *dregs)
{
union REGS regs = {0};