[xiph-commits] r17650 - websites/celt-codec.org/squishyball

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Nov 25 07:28:45 PST 2010


Author: xiphmont
Date: 2010-11-25 07:28:45 -0800 (Thu, 25 Nov 2010)
New Revision: 17650

Modified:
   websites/celt-codec.org/squishyball/mincurses.c
   websites/celt-codec.org/squishyball/tty.c
Log:
move a few formatting calls out of mincurses
Add buffering to mincurses writes



Modified: websites/celt-codec.org/squishyball/mincurses.c
===================================================================
--- websites/celt-codec.org/squishyball/mincurses.c	2010-11-25 15:23:36 UTC (rev 17649)
+++ websites/celt-codec.org/squishyball/mincurses.c	2010-11-25 15:28:45 UTC (rev 17650)
@@ -47,6 +47,13 @@
 #include <errno.h>
 #include <poll.h>
 
+#include "mincurses.h"
+
+#define FIFO_SIZE    160
+#define BUFF_SIZE    160
+
+/***************************** INPUT SIDE *******************************/
+
 struct tinfo_fkeys {
   unsigned offset;
   chtype code;
@@ -58,8 +65,6 @@
 extern const struct tinfo_fkeys _nc_tinfo_fkeys[];
 #endif
 
-#include "mincurses.h"
-
 /* In ncurses, all the keybindings are tied to the SP. Calls into the
    keybinding code all require the SP be set. Low level SP
    management/creation is not exposed, and the high level entry points
@@ -67,7 +72,6 @@
    this reason, we duplicate some code. */
 
 typedef struct tries TRIES;
-#define FIFO_SIZE    200
 
 struct tries {
   TRIES    *child;
@@ -238,6 +242,8 @@
   return ch;
 }
 
+/***************************** OUTPUT SIDE ******************************/
+
 TTY orig;
 TTY term;
 
@@ -245,39 +251,51 @@
 static int initted=0;
 static int cursor_line_offset=0;
 static int panel_lines=0;
+static char outbuf[BUFF_SIZE];
+static int buf_fill=0;
 
-int min_putchar(int c){
-  while(1){
-    unsigned char ch = c;
+int min_flush(){
+  int len = buf_fill;
+  char *b = outbuf;
+  while(len){
     int ret;
     errno=0;
-    ret=write(outfd,&ch,1);
+    ret=write(outfd,b,len);
     if(ret<=0){
       if(ret==0 || errno==EINTR)continue;
       return EOF;
     }else{
-      return c;
-      break;
+      b+=ret;
+      len-=ret;
     }
   }
+  return 0;
 }
 
+int min_putchar(int c){
+  outbuf[buf_fill]=c;
+  buf_fill++;
+  if(buf_fill==BUFF_SIZE)
+    return min_flush();
+  return 0;
+}
+
 int min_putp(const char *str){
   return tputs(str, 1, min_putchar);
 }
 
 int min_write(const char *str,int len){
+  int ret=0;
   while(len){
-    int ret;
-    errno=0;
-    ret=write(outfd,str,len);
-    if(ret<=0){
-      if(ret==0 || errno==EINTR)continue;
-      return EOF;
-    }else{
-      str+=ret;
-      len-=ret;
+    int bytes = (buf_fill+len>BUFF_SIZE ? BUFF_SIZE-buf_fill : len);
+    memcpy(outbuf+buf_fill,str,bytes);
+    buf_fill+=bytes;
+    if(buf_fill==BUFF_SIZE){
+      ret=min_flush();
+      if(ret)return ret;
     }
+    str+=bytes;
+    len-=bytes;
   }
   return 0;
 }
@@ -287,8 +305,8 @@
   return min_write(str,len);
 }
 
-/* relative-line cursor addressing; no idea where the cursor actually
-   is absolutely */
+/************** high level operations ***********************/
+
 void min_mvcur(int x, int y){
   int yoff = y - cursor_line_offset;
 
@@ -334,11 +352,6 @@
   }
 }
 
-void resetup_term(void){
-  SET_TTY(outfd,&term);
-  cur_term->Nttyb = term;
-}
-
 extern void _nc_init_acs(void);
 int min_init_panel(int pl){
   int ret = OK;
@@ -374,6 +387,7 @@
     panel_lines=pl;
     insert_lines(panel_lines);
     initted=1;
+    min_flush();
   }
   return ret;
 }
@@ -385,6 +399,7 @@
       min_putp(tparm(delete_line,panel_lines));
     }
     min_showcur();
+    min_flush();
     SET_TTY(outfd,&orig);
     initted=0;
   }
@@ -446,21 +461,6 @@
     return 1;
 }
 
-void min_fill(char *buf,char c,int cols){
-  int i;
-  for(i=0;i<cols;i++)
-    buf[i]=c;
-  buf[i]=0;
-}
-
-void min_printover(char *buf,int pos, char *s){
-  int len = strlen(buf);
-  int len2 = strlen(s);
-  int i;
-  for(i=0; i+pos<len && i<len2; i++)
-    buf[i+pos]=s[i];
-}
-
 int min_fg(int c){
   if(set_a_foreground){
     min_putp(tparm(set_a_foreground,c));
@@ -483,32 +483,3 @@
   if(b!=-1) min_bg(b);
 }
 
-void min_hline(char *s,int textcolor){
-  int pos=0,last=0;
-
-  while(s[pos]){
-    /* draw line */
-    while(s[pos] && s[pos]=='_')pos++;
-    if(pos>last){
-      if(!min_gfxmode()){
-	for(;last<pos;last++)
-	  min_putchar(ACS_HLINE);
-	min_textmode();
-      }else{
-	min_write(s+last,pos-last);
-      }
-    }
-
-    /* draw text */
-    while(s[pos] && s[pos]!='_')pos++;
-    if(pos>last){
-      if(textcolor>=0)
-	min_fg(textcolor);
-      min_write(s+last,pos-last);
-      if(textcolor>=0)
-	min_color(-1,-1);
-      last = pos;
-    }
-  }
-}
-

Modified: websites/celt-codec.org/squishyball/tty.c
===================================================================
--- websites/celt-codec.org/squishyball/tty.c	2010-11-25 15:23:36 UTC (rev 17649)
+++ websites/celt-codec.org/squishyball/tty.c	2010-11-25 15:28:45 UTC (rev 17650)
@@ -21,181 +21,58 @@
  *
  */
 
-/* Encapsulate the curses/terminfo calls for presenting a little panel
-   display at the bottom of a terminal window. */
-
 #define _GNU_SOURCE
-#define _LARGEFILE_SOURCE
-#define _LARGEFILE64_SOURCE
-#define _FILE_OFFSET_BITS 64
-
-#ifndef _REENTRANT
-# define _REENTRANT
-#endif
-
+#include <ncurses.h>
+#include <curses.h>
+#include <term.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <math.h>
+#include <errno.h>
 #include "mincurses.h"
-#include "tty.h"
 
+void fill(char *buf,char c,int cols){
+  int i;
+  for(i=0;i<cols;i++)
+    buf[i]=c;
+  buf[i]=0;
+}
 
+void printover(char *buf,int pos, char *s){
+  int len = strlen(buf);
+  int len2 = strlen(s);
+  int i;
+  for(i=0; i+pos<len && i<len2; i++)
+    buf[i+pos]=s[i];
+}
 
-#if 0
-void terminal_paint_ui(){
-  int cols = columns;
+void printhline(char *s,int textcolor){
+  int pos=0,last=0;
 
-  char topline[cols+1];
-  char botline[cols+1];
-  char dmabuf[cols+1];
-  char diskbuf[cols+1];
-  char hwbuf[cols+1];
-  char linebuf[cols+1];
-
-  int barchoice=-1;
-  int barcols = cols - 25, barpad=0;
-  int barlength=0;
-  int i=0;
-
-  topline[0]='\0';
-  botline[0]='\0';
-  dmabuf[0]='\0';
-  diskbuf[0]='\0';
-  hwbuf[0]='\0';
-  linebuf[0]='\0';
-
-  /* construct the top line */
-  //snprintf(dmabuf,cols+1," DMA buffer: %3d%% ",(int)rint(dma_percent));
-  //snprintf(diskbuf,cols+1," Disk buffer: %3d%% ",(int)rint(disk_percent));
-  //snprintf(hwbuf,cols+1," %s ",device);
-  //fill(topline,'_',cols);
-  //print_into(topline,3,dmabuf);
-  //print_into(topline,5+strlen(dmabuf),diskbuf);
-  //print_into(topline,columns - strlen(hwbuf)-3,hwbuf);
-
-  /* print the top line */
-  //cursor_to(0,0);
-  //print_hline(topline,-1);
-
-  /* blank next line (useful if coming back after SIGSTOP) */
-  //cursor_to(0,1);
-  //clear_line();
-
-  /* bargraphs */
-
-  for(i=0;i<channels;i++){
-    cursor_to(barpad,2+i);
-    clear_to_cursor();
-    snprintf(linebuf,cols+1,"%2d: [",i);
-    putp(linebuf);
-
-    if(barchoice>=0){
-      /* determine bar lengths */
-      int rms_pos = barpos(barchoice,rms_dB[i]);
-      int peak_pos = barpos(barchoice,peak_dB[i]);
-
-      if(peak_pos>barlength)peak_pos=barlength;
-      if(rms_pos>peak_pos)rms_pos=peak_pos;
-
-      /* color the bargraph */
-      if(rms_pos){
-	color(COLOR_BLACK,COLOR_WHITE);
-	fwrite(bargraphs[barchoice],1,rms_pos,stdout);
+  while(s[pos]){
+    /* draw line */
+    while(s[pos] && s[pos]=='_')pos++;
+    if(pos>last){
+      if(!min_gfxmode()){
+	for(;last<pos;last++)
+	  min_putchar(ACS_HLINE);
+	min_textmode();
+      }else{
+	min_write(s+last,pos-last);
       }
-      if(peak_pos-rms_pos>0){
-	color(COLOR_BLACK,COLOR_CYAN);
-	fwrite(bargraphs[barchoice]+rms_pos,1,peak_pos-rms_pos,stdout);
-      }
-      if(barlength-peak_pos>0){
-	color(COLOR_CYAN,COLOR_BLACK);
-	fwrite(bargraphs[barchoice]+peak_pos,1,barlength-peak_pos,stdout);
-      }
-
-      /* the RMS indicator is always normal colors */
-      unset_attributes();
     }
 
-    if(weight){
-      snprintf(linebuf,cols+1,"] %+6.1fdBA,",(double)rms_dB[i]);
-    }else{
-      snprintf(linebuf,cols+1,"] %+6.1fdB, ",(double)rms_dB[i]);
+    /* draw text */
+    while(s[pos] && s[pos]!='_')pos++;
+    if(pos>last){
+      if(textcolor>=0)
+	min_fg(textcolor);
+      min_write(s+last,pos-last);
+      if(textcolor>=0)
+	min_color(-1,-1);
+      last = pos;
     }
-    putp(linebuf);
-
-    /* the peak indicator may read a number or CLIP */
-    if(peak_clip[i]){
-      color(COLOR_RED,-1);
-      putp("**CLIP**");
-      color(-1,-1);
-    }else{
-      snprintf(linebuf,cols+1,"%+6.1fdB",(double)peak_hold_dB[i]);
-      putp(linebuf);
-    }
-    if(barpad + barcols < columns) clear_line();
   }
-
-  /* blank next line (useful if coming back after SIGSTOP) */
-  cursor_to(0,channels+2);
-  clear_line();
-
-  /* construct the bottom line */
-  fill(botline,'_',cols);
-  {
-    int x=3;
-    if(paused){
-      print_into(botline,x," PAUSED ");
-      x+=10;
-    }
-    if(hold){
-      print_into(botline,x," HOLD ");
-      x+=8;
-    }
-    if(dma_once_overrun){
-      print_into(botline,x," DMA OVERRUN ");
-      x+=16;
-    }
-    if(disk_once_overrun){
-      print_into(botline,x," DISK OVERRUN ");
-      x+=17;
-    }
-  }
-
-  /* print the bottom line */
-  cursor_to(0,channels+3);
-  print_hline(botline,COLOR_RED);
-  fflush(stdout);
 }
-
-void terminal_main_loop(int quiet){
-  int i;
-  int exiting=0;
-
-  while(!exiting){
-    char buf;
-    if(!quiet){
-      resetup_term();
-      terminal_paint_ui();
-    }
-    read(STDIN_FILENO,&buf,1);
-
-    if(!quiet){
-      switch(buf){
-      case 'p':
-	paused = !paused;
-	break;
-      case 'h':
-	hold = !hold;
-	break;
-      case ' ':
-	dma_once_overrun=0;
-	disk_once_overrun=0;
-	for(i=0;i<channels;i++){
-	  peak_clip[i]=0;
-	  peak_hold_dB[i]=peak_dB[i];
-	}
-	break;
-      case 'q':case 'Q':
-	exiting=1;
-	break;
-      }
-    }
-  }
-}
-#endif



More information about the commits mailing list