changeset 19:2c72092554fa

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 23 May 2010 18:31:43 +0300
parents 56848f781b4c
children ce32734b8bdd
files pwplib/convert.c pwplib/init.c pwplib/linuxcon.c pwplib/pwplib-unix.c pwplib/tty.c
diffstat 5 files changed, 165 insertions(+), 176 deletions(-) [+]
line wrap: on
line diff
--- a/pwplib/convert.c	Sat May 22 23:13:02 2010 +0300
+++ b/pwplib/convert.c	Sun May 23 18:31:43 2010 +0300
@@ -48,10 +48,9 @@
 
    if(!(colors&~7))
    {
-     char tmp[60];
-     int fgcols=(colors&1)?8:16,bgcols=(colors&2)?8:16;
-     sprintf(tmp,"; %i fg and %i bg colors\n",fgcols,bgcols);
-     pwpwrite(tmp);
+     int fgcols = (colors & 1) ? 8 : 16,
+         bgcols = (colors & 2) ? 8 : 16;
+     pwpwrite("; %i fg and %i bg colors\n", fgcols, bgcols);
    }else
    {
      pwpwrite("; monochrome\n");
--- a/pwplib/init.c	Sat May 22 23:13:02 2010 +0300
+++ b/pwplib/init.c	Sun May 23 18:31:43 2010 +0300
@@ -307,10 +307,7 @@
    if(pwplib.set.lang==NULL)
       pwplib.set.lang=pwp_get_locale();
    
-   {char buf[40];
-    sprintf(buf,"* using locale '%s'\n",pwplib.set.lang);
-    pwpwrite(buf);
-   }
+   pwpwrite("* using locale '%s'\n", pwplib.set.lang);
 
    if(!pwplib_initcore())
    {
--- a/pwplib/linuxcon.c	Sat May 22 23:13:02 2010 +0300
+++ b/pwplib/linuxcon.c	Sun May 23 18:31:43 2010 +0300
@@ -68,7 +68,7 @@
 
    if((majmin&~0x63)==4*256)
    {
-      char buf[20];
+      char buf[32];
       sprintf(buf,"/dev/vcsa%i",majmin&63);
       vcsa=open(buf,O_RDWR);
       if(vcsa>=0)return vcsa;
--- a/pwplib/pwplib-unix.c	Sat May 22 23:13:02 2010 +0300
+++ b/pwplib/pwplib-unix.c	Sun May 23 18:31:43 2010 +0300
@@ -25,15 +25,14 @@
 
 void pwpwrite(const char *fmt, ...)
 {
-  if(!pwplib.setup[SETUP_SHUTUP])
-  {
-     va_list ap;
-     va_start(ap, fmt);
-     vfprintf(stderr, fmt, ap);
-     va_end(ap);
+    if (!pwplib.setup[SETUP_SHUTUP]) {
+        va_list ap;
+        va_start(ap, fmt);
+        vfprintf(stderr, fmt, ap);
+        va_end(ap);
 
-     usleep(1000*pwplib.set.infodelay);
-  }
+        usleep(1000 * pwplib.set.infodelay);
+    }
 }
 
 /********************* timer  ******************************/
@@ -47,13 +46,13 @@
         SDL_Event event;
         if (SDL_PollEvent(&event) >= 0) {
             switch (event.type) {
-            case SDL_KEYDOWN:
-                if (event.key.keysym.sym == SDLK_ESCAPE)
-                    quit = 1;
-                break;
-            case SDL_QUIT:
-                quit = 1;
-                break;
+              case SDL_KEYDOWN:
+                  if (event.key.keysym.sym == SDLK_ESCAPE)
+                      quit = 1;
+                  break;
+              case SDL_QUIT:
+                  quit = 1;
+                  break;
             }
         }
         if (quit) {
@@ -62,12 +61,13 @@
             exit(1);
         }
         return (SDL_GetTicks() * TIMERHZ) / 1000;
-    } else
+    }
+    else
 #endif
     {
         struct timeval tod;
-        gettimeofday(&tod,NULL);
-        return (tod.tv_sec*TIMERHZ)+(tod.tv_usec*TIMERHZ/1000000);
+        gettimeofday(&tod, NULL);
+        return (tod.tv_sec * TIMERHZ) + (tod.tv_usec * TIMERHZ / 1000000);
     }
 }
 
@@ -75,33 +75,30 @@
 
 void pwp_fatalsignal(int n)
 {
-   char buf[40];
-
-   pwpwrite("* pwplib shutting down\n");
+    pwpwrite("* pwplib shutting down\n");
 
 #ifdef DRIVE_SDL
-   if (sdl_init) {
-      sdl_init = 0;
-      SDL_Quit();
-   }
+    if (sdl_init) {
+        sdl_init = 0;
+        SDL_Quit();
+    }
 #endif
 
-   pwplib_shutdown();
+    pwplib_shutdown();
 
-   sprintf(buf,"* died to signal %d\n",n);
-   pwpwrite(buf);
-   
-   exit(1);
+    pwpwrite("* died to signal %d\n", n);
+
+    exit(1);
 }
 
 /******************** initialization *********************/
 
 int pwplib_initcore()
 {
-   int sdl_flags = 0;
-   pwplib_init_common();
+    int sdl_flags = 0;
+    pwplib_init_common();
 
-   /*** set signals ***/
+   /*** setup signals, etc ***/
 
 #ifdef DRIVE_SDL
 #ifdef DRIVE_VIDEO
@@ -110,201 +107,203 @@
 #ifdef DRIVE_AUDIO
     sdl_flags |= SDL_INIT_AUDIO;
 #endif
-   /* With SDL, we let it handle the signals */
-    if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_EVENTTHREAD | /* SDL_INIT_NOPARACHUTE | */ sdl_flags) != 0)
-    {
+    /* With SDL, we let it handle the signals */
+    if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_EVENTTHREAD | sdl_flags) != 0) {
         pwpwrite("* SDL could not be initialized.\n");
         sdl_init = 0;
     } else
         sdl_init = 1;
 #endif
 
-   if (!sdl_init) {
-       signal(SIGTERM,pwp_fatalsignal);
-       signal(SIGINT,pwp_fatalsignal);
-       signal(SIGQUIT,pwp_fatalsignal);
-       signal(SIGKILL,pwp_fatalsignal);
-       signal(SIGSEGV,pwp_fatalsignal);
-   }
+    if (!sdl_init) {
+        signal(SIGTERM, pwp_fatalsignal);
+        signal(SIGINT, pwp_fatalsignal);
+        signal(SIGQUIT, pwp_fatalsignal);
+        signal(SIGKILL, pwp_fatalsignal);
+        signal(SIGSEGV, pwp_fatalsignal);
+    }
 
    /*** video ***/
 
 #   ifdef DRIVE_VIDEO
 
 #   ifdef DRIVE_SDL
-   if(sdl_init && pwp_SDL_init())
-   {
-   }
-   else
+    if (sdl_init && pwp_SDL_init())
+    {
+    }
+    else
 #   endif
 #   ifdef DRIVE_PVP
-   if(pwplib.setup[SETUP_PVP])
-     pvp_init();
-   else
+    if (pwplib.setup[SETUP_PVP])
+        pvp_init();
+    else
 #   endif
-   if(!pwplib.setup[SETUP_NOVIDEO])
-   {
-     tty_init();
-   }
+    if (!pwplib.setup[SETUP_NOVIDEO])
+    {
+        tty_init();
+    }
 #   endif
 
    /*** audio ***/
 #  ifdef DRIVE_AUDIO
-   if(!pwplib.setup[SETUP_NOSOUND])
-   {
-      int snd=0;
+    if (!pwplib.setup[SETUP_NOSOUND])
+    {
+        int snd = 0;
 #ifdef DRIVE_SDL
-        if(!snd) { if(sdl_init && pwp_sdlaudio_init())snd++; }
+        if (!snd)
+        {
+            if (sdl_init && pwp_sdlaudio_init())
+                snd++;
+        }
 #endif
 
 #ifdef DRIVE_OSS
-        if(!snd) { if(oss_init())snd++; }
+        if (!snd)
+        {
+            if (oss_init())
+                snd++;
+        }
 #endif
 
 #ifdef DRIVE_HPUX
-        if(!snd) { if(hpuxsnd_init())snd++; }
+        if (!snd)
+        {
+            if (hpuxsnd_init())
+                snd++;
+        }
 #endif
 
-        if(!snd)
-        pwpwrite("* couldn't init sound. going silent.\n");
+        if (!snd)
+            pwpwrite("* couldn't init sound. going silent.\n");
 
-   }
-   else
-     pwpwrite("* no sound, as requested\n");
+    }
+    else
+        pwpwrite("* no sound, as requested\n");
 #  endif
 
    /*** fallbacks - remove? ***/
 
-   if(pwplib.dump_rast==pwplib_dummy && pwplib.dump_attr!=pwplib_dummy)
-      pwplib.dump_rast=pwplib_dump_rast_plain;
+    if (pwplib.dump_rast == pwplib_dummy && pwplib.dump_attr != pwplib_dummy)
+        pwplib.dump_rast = pwplib_dump_rast_plain;
 
    /*** timer ***/
 
-   if(pwplib.setup[SETUP_BPS]|pwplib.setup[SETUP_FPS])
-   {
-      char tmp[100];
-      sprintf(tmp,"non-realtime output (bps=%d fps=%d)\n",
-        pwplib.setup[SETUP_BPS],pwplib.setup[SETUP_FPS]);
-      pwpwrite(tmp);
-
-      pwplib.timerfunc=pwp_timer_nrt;
-      pwplib.timer_counter=0;
-   }
+    if (pwplib.setup[SETUP_BPS] | pwplib.setup[SETUP_FPS])
+    {
+        pwpwrite("non-realtime output (bps=%d fps=%d)\n", pwplib.setup[SETUP_BPS], pwplib.setup[SETUP_FPS]);
+        pwplib.timerfunc = pwp_timer_nrt;
+        pwplib.timer_counter = 0;
+    }
     else
-      pwplib.timerfunc=pwp_unix_tod;
+        pwplib.timerfunc = pwp_unix_tod;
 
    /*** hmmm ***/
 
-   if(pwplib.setup[SETUP_HALVE])
-      pwplib.videobuf.height<<=1;
+    if (pwplib.setup[SETUP_HALVE])
+        pwplib.videobuf.height <<= 1;
 
-     /* only allow if smaller than original? */
+    /* only allow if smaller than original? */
 
-   if(pwplib.setup[SETUP_USERHEIGHT])
-      pwplib.videobuf.height=pwplib.setup[SETUP_USERHEIGHT];
-   if(pwplib.setup[SETUP_USERWIDTH])
-      pwplib.videobuf.width=pwplib.setup[SETUP_USERWIDTH];
+    if (pwplib.setup[SETUP_USERHEIGHT])
+        pwplib.videobuf.height = pwplib.setup[SETUP_USERHEIGHT];
+    if (pwplib.setup[SETUP_USERWIDTH])
+        pwplib.videobuf.width = pwplib.setup[SETUP_USERWIDTH];
 
    /*** done ***/
-   
+
 #   ifdef DRIVE_VIDEO
-   if(!pwplib.setup[SETUP_NOVIDEO])
-   {char tmp[100];
-   sprintf(tmp,"* pwplib now controls a %d x %d framebuffer\n",
-      pwplib.videobuf.width,pwplib.videobuf.height);
-   pwpwrite(tmp);
-   }
+    if (!pwplib.setup[SETUP_NOVIDEO])
+    {
+        pwpwrite("* pwplib now controls a %d x %d framebuffer\n", pwplib.videobuf.width, pwplib.videobuf.height);
+    }
 #  endif
 
-   return 1;
+    return 1;
 }
 
 /************************************/
 
-const char*pwplogo=
-"\033[2J\033[H\n"
-"   \033[36;46mMMmmmmmmMM\033[0m\n"
-"       \033[36;46mMM\033[0m\n"
-"    \033[31;41mxxxxxxxxxxxx\033[0m\n"
-"    \033[31;41mxxxxxxxxxxxxxxxxxxx\033[0m\n"
-"   \033[31;41mxxxxxxxxx\033[0m\n"
-"   \033[33;43mZZZZZ\033[34;44m....\033[0m        %%%%%%%%%  %%%        %%%  %%%%%%%%%\n"
-"  \033[37;47m@@@@\033[34;44m......\033[0m        %%%%%%%%%. %%%....... %%%. %%%%%%%%%....\n"
-"  \033[37;47m@@@@\033[34;44m....\033[37mo\033[34m.\033[0m   .....%%%   %%%  %%%   %%%  %%%  %%%   %%%\n"
-" \033[37;47m@@@@@@@\033[34;44m....\033[0m        %%%   %%%  %%%   %%%  %%%  %%%   %%%\n"
-" \033[37;47m@@@@@@@@@@@\033[0m        %%%%  %%%  %%%   %%%  %%%  %%%%  %%%\n"
-" \033[37;47m@@@@@@@@@@@@@\033[0m      %%%%  %%%  %%%   %%%  %%%  %%%%  %%%\n"
-" \033[37;47m@@@@@@@@@@@@@@@\033[0m    %%%%%%%%%  %%%   %%%  %%%  %%%%%%%%%\n"
-"  \033[37;47m@@@@\033[0m              %%%%%%%%%  %%%   %%%  %%%  %%%%%%%%%\n"
-"  \033[37;47m@@@@@@\033[0m            %%%        %%%%% %%%  %%%  %%%\n"
-"  \033[37;47m@@@@@@@@@@\033[0m  \033[31;41mxx\033[0m    %%%        %%%%% %%%  %%%  %%%\n"
-"  \033[37;47m@@@@@@@@@@@@@@\033[0m    %%%        %%%%% %%%% %%%  %%%\n"
-"   \033[37;47m@@@@@@@@@@@\033[0m      %%%        %%%%% %%%% %%%  %%%\n"
-"   \033[37;47m@@@@@@@@@\033[0m   .....%%%....... %%%%%%%%%%%%%%. %%%..........\n"
-"     \033[37;47m@@@@@\033[0m          %%%        %%%%%%%%%%%%%%  %%%\n"
-"     \033[37;47m@@@@\033[0m\n\n";
+const char *pwplogo =
+    "\033[2J\033[H\n"
+    "   \033[36;46mMMmmmmmmMM\033[0m\n"
+    "       \033[36;46mMM\033[0m\n"
+    "    \033[31;41mxxxxxxxxxxxx\033[0m\n"
+    "    \033[31;41mxxxxxxxxxxxxxxxxxxx\033[0m\n"
+    "   \033[31;41mxxxxxxxxx\033[0m\n"
+    "   \033[33;43mZZZZZ\033[34;44m....\033[0m        %%%%%%%%%  %%%        %%%  %%%%%%%%%\n"
+    "  \033[37;47m@@@@\033[34;44m......\033[0m        %%%%%%%%%. %%%....... %%%. %%%%%%%%%....\n"
+    "  \033[37;47m@@@@\033[34;44m....\033[37mo\033[34m.\033[0m   .....%%%   %%%  %%%   %%%  %%%  %%%   %%%\n"
+    " \033[37;47m@@@@@@@\033[34;44m....\033[0m        %%%   %%%  %%%   %%%  %%%  %%%   %%%\n"
+    " \033[37;47m@@@@@@@@@@@\033[0m        %%%%  %%%  %%%   %%%  %%%  %%%%  %%%\n"
+    " \033[37;47m@@@@@@@@@@@@@\033[0m      %%%%  %%%  %%%   %%%  %%%  %%%%  %%%\n"
+    " \033[37;47m@@@@@@@@@@@@@@@\033[0m    %%%%%%%%%  %%%   %%%  %%%  %%%%%%%%%\n"
+    "  \033[37;47m@@@@\033[0m              %%%%%%%%%  %%%   %%%  %%%  %%%%%%%%%\n"
+    "  \033[37;47m@@@@@@\033[0m            %%%        %%%%% %%%  %%%  %%%\n"
+    "  \033[37;47m@@@@@@@@@@\033[0m  \033[31;41mxx\033[0m    %%%        %%%%% %%%  %%%  %%%\n"
+    "  \033[37;47m@@@@@@@@@@@@@@\033[0m    %%%        %%%%% %%%% %%%  %%%\n"
+    "   \033[37;47m@@@@@@@@@@@\033[0m      %%%        %%%%% %%%% %%%  %%%\n"
+    "   \033[37;47m@@@@@@@@@\033[0m   .....%%%....... %%%%%%%%%%%%%%. %%%..........\n"
+    "     \033[37;47m@@@@@\033[0m          %%%        %%%%%%%%%%%%%%  %%%\n"
+    "     \033[37;47m@@@@\033[0m\n\n";
 
 
 void pwplib_startup()
 {
-  if(!pwplib.setup[SETUP_SHUTUP])
-  {
-     pwpwrite("starting up.... 2sec delay for ^C");
-     sleep(2);
-  }
+    if (!pwplib.setup[SETUP_SHUTUP])
+    {
+        pwpwrite("starting up.... 2sec delay for ^C");
+        sleep(2);
+    }
 
-  /* send initstuff? */
+    /* send initstuff? */
 }
 
 void pwplib_end()
 {
-  if(pwplib.setup[SETUP_SHUTUP])return;
+    if (pwplib.setup[SETUP_SHUTUP])
+        return;
 
-  pwplib_shutdown();
-  sleep(2);
+    pwplib_shutdown();
+    sleep(2);
 
-  fputs(pwplogo,stderr);
-  pwpwrite("shutting down multimedia subsystems\n"  
-           "operation finished - support pwp\n\n\n");
+    fputs(pwplogo, stderr);
+    pwpwrite("shutting down multimedia subsystems\n" "operation finished - support pwp\n\n\n");
 }
 
 /***************************************************************/
 
-int pwplib_init(int argc,char**argv)
+int pwplib_init(int argc, char **argv)
 {
-   int i=0,quit=0;
+    int i = 0, quit = 0;
 
-   pwplib.argc=argc;
-   pwplib.argv=argv;
+    pwplib.argc = argc;
+    pwplib.argv = argv;
 
-   pwplib_getopts();
+    pwplib_getopts();
 
-   if(pwplib.setup[SETUP_WANTHELP])
-   {
-      printhelp();
-      exit(0);
-      pwplib.setup[SETUP_SHUTUP]++;
-   }
+    if (pwplib.setup[SETUP_WANTHELP])
+    {
+        printhelp();
+        exit(0);
+        pwplib.setup[SETUP_SHUTUP]++;
+    }
 
-   if(!pwplib.setup[SETUP_SHUTUP])
-   {
-      fputs(pwplogo,stderr);
-      pwpwrite("pwplib " PWPLIB_VERSION " initializing..\n\nrun with --help for some options\n\n");
-   }
-   
-   {char buf[40];
-    sprintf(buf,"* using locale '%s'\n",pwplib.set.lang);
-    pwpwrite(buf);
-   }
+    if (!pwplib.setup[SETUP_SHUTUP])
+    {
+        fputs(pwplogo, stderr);
+        pwpwrite("pwplib " PWPLIB_VERSION " initializing..\n\nrun with --help for some options\n\n");
+    }
+
+    pwpwrite("* using locale '%s'\n", pwplib.set.lang);
 
-   if(!pwplib_initcore())
-   {
-      pwpwrite("initialization failed!\n");
-      return 0;
-   }
+    if (!pwplib_initcore())
+    {
+        pwpwrite("initialization failed!\n");
+        return 0;
+    }
 
-   if(pwplib.setup[SETUP_WANTHELP])
-      return 0;
+    if (pwplib.setup[SETUP_WANTHELP])
+        return 0;
 
-   return 1;
+    return 1;
 }
--- a/pwplib/tty.c	Sat May 22 23:13:02 2010 +0300
+++ b/pwplib/tty.c	Sun May 23 18:31:43 2010 +0300
@@ -236,22 +236,16 @@
 
      case(TTY_VT2XX):
 #ifdef DRIVE_TTY_VT2XX
-        {
-          char buf[40];
-          sprintf(buf,"vt220/compatible (vt%d)\n",pwp_tty.minor);
-          pwpwrite(buf);
-        }
+        pwpwrite("vt220/compatible (vt%d)\n",pwp_tty.minor);
         tty_vt2xx_init();
         break;
 #endif
      case(TTY_VT1XX):
         pwpwrite("vt100/compatible");
-        if(pwp_tty.minor>=200)
-        {  char buf[40];
-           sprintf(buf," (a vt%d wannabe)\n",pwp_tty.minor);
-           pwpwrite(buf);
-        }
-         else pwpwrite("\n");
+        if (pwp_tty.minor>=200)
+            pwpwrite(" (a vt%d wannabe)\n",pwp_tty.minor);
+        else
+            pwpwrite("\n");
         tty_vt1xx_init();
         break;