DOS logger now redirects stdout/stderr instead of providing a new
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Tue, 4 Oct 2016 03:19:10 +0000 (06:19 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Tue, 4 Oct 2016 03:19:10 +0000 (06:19 +0300)
logging function

src/dos/gfx.c
src/dos/logger.c
src/dos/logger.h
src/dos/main.c
src/dos/music.c

index 558646b..a07d77a 100644 (file)
@@ -7,7 +7,6 @@
 #include <limits.h>
 #include "vbe.h"
 #include "dpmi.h"
-#include "logger.h"
 
 #define REALPTR(s, o)  (void*)(((uint32_t)(s) << 4) + (uint32_t)(o))
 #define VBEPTR(x)              REALPTR(((x) & 0xffff0000) >> 16, (x) & 0xffff)
@@ -36,15 +35,15 @@ void *set_video_mode(int xsz, int ysz, int bpp)
                        return 0;
                }
 
-               printlog("VBE Version: %x.%x\n", vbe_info->version >> 8, vbe_info->version & 0xff);
+               printf("VBE Version: %x.%x\n", vbe_info->version >> 8, vbe_info->version & 0xff);
                if(vbe_info->version < 0x200) {
                        fprintf(stderr, "This program requires VBE 2.0 or greater. Try running UniVBE\n");
                        return 0;
                }
 
-               printlog("Graphics adapter: %s, %s (%s)\n", VBEPTR(vbe_info->oem_vendor_name_ptr),
+               printf("Graphics adapter: %s, %s (%s)\n", VBEPTR(vbe_info->oem_vendor_name_ptr),
                                VBEPTR(vbe_info->oem_product_name_ptr), VBEPTR(vbe_info->oem_product_rev_ptr));
-               printlog("Video memory: %dkb\n", vbe_info->total_mem << 6);
+               printf("Video memory: %dkb\n", vbe_info->total_mem << 6);
 
                modes = VBEPTR(vbe_info->vid_mode_ptr);
        }
@@ -78,7 +77,7 @@ void *set_video_mode(int xsz, int ysz, int bpp)
        /* attempt to set 8 bits of color per component in palettized modes */
        /*if(bpp <= 8) {
                pal_bits = vbe_set_palette_bits(8);
-               printlog("palette bits per color primary: %d\n", pal_bits);
+               printf("palette bits per color primary: %d\n", pal_bits);
        }
        */
 
index 73860e3..f7e9256 100644 (file)
@@ -1,46 +1,21 @@
-/*
-colcycle - color cycling image viewer
-Copyright (C) 2016  John Tsiombikas <nuclear@member.fsf.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include <stdio.h>
-#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
 #include "logger.h"
 
-#define LOGFNAME       "demo.log"
-
-static FILE *logfile;
-
-void logger_output(FILE *fp)
+int init_logger(const char *fname)
 {
-       if(logfile) fclose(logfile);
-       logfile = fp;
-}
-
-void printlog(const char *fmt, ...)
-{
-       va_list ap;
-
-       if(!logfile) {
-               if(!(logfile = fopen(LOGFNAME, "w"))) {
-                       return;
-               }
-               setvbuf(logfile, 0, _IOLBF, 0);
+       int fd;
+       if((fd = open(fname, O_WRONLY)) == -1) {
+               fprintf(stderr, "init_logger: failed to open %s: %s\n", fname, strerror(errno));
+               return -1;
        }
 
-       va_start(ap, fmt);
-       vfprintf(logfile, fmt, ap);
-       va_end(ap);
+       close(1);
+       close(2);
+       dup(fd);
+       dup(fd);
+       return 0;
 }
index 249b989..9ef9a85 100644 (file)
@@ -1,31 +1,11 @@
-/*
-colcycle - color cycling image viewer
-Copyright (C) 2016  John Tsiombikas <nuclear@member.fsf.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #ifndef LOGGER_H_
 #define LOGGER_H_
 
-#include <stdio.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-void logger_output(FILE *fp);
-void printlog(const char *fmt, ...);
+int init_logger(const char *fname);
 
 #ifdef __cplusplus
 }
index 10492fe..53b8888 100644 (file)
@@ -7,6 +7,7 @@
 #include "mouse.h"
 #include "timer.h"
 #include "gfx.h"
+#include "logger.h"
 
 static int quit;
 static int use_mouse;
@@ -16,6 +17,8 @@ int main(int argc, char **argv)
 {
        fbsize = fb_width * fb_height * fb_bpp / CHAR_BIT;
 
+       init_logger("demo.log");
+
        init_timer(100);
        kb_init(32);
 
index 4005a79..5f3b84a 100644 (file)
@@ -1,7 +1,6 @@
 #include <stdlib.h>
 #include "music.h"
 #include "mikmod.h"
-#include "logger.h"
 
 static void update_callback(void);
 
@@ -32,11 +31,11 @@ static int init(void)
        MD_RegisterPlayer(update_callback);
 
        if(!MD_Init()) {
-               printlog("mikmod init failed: %s\n", myerr);
+               fprintf(stderr, "mikmod init failed: %s\n", myerr);
                return -1;
        }
-       printlog("using mikmod driver %s\n", md_driver->Name);
-       printlog(" %d bits, %s, %s mixing at %d Hz\n", md_mode & DMODE_16BITS ? 16 : 8,
+       printf("using mikmod driver %s\n", md_driver->Name);
+       printf(" %d bits, %s, %s mixing at %d Hz\n", md_mode & DMODE_16BITS ? 16 : 8,
                        md_mode & DMODE_STEREO ? "stereo" : "mono",
                        md_mode & DMODE_INTERP ? "interpolated" : "normal",
                        md_mixfreq);
@@ -55,20 +54,20 @@ int music_open(const char *fname)
        }
 
        if(!(mod = ML_LoadFN((const signed char*)fname))) {
-               printlog("failed to load music: %s: %s\n", fname, myerr);
+               fprintf(stderr, "failed to load music: %s: %s\n", fname, myerr);
                return -1;
        }
 
        MP_Init(mod);
        md_numchn = mod->numchn;
-       printlog("opened module %s (%d channels)\n", fname, md_numchn);
+       printf("opened module %s (%d channels)\n", fname, md_numchn);
        return 0;
 }
 
 void music_close(void)
 {
        if(mod) {
-               printlog("shutting down music playback\n");
+               printf("shutting down music playback\n");
                music_stop();
                ML_Free(mod);
                mod = 0;