]> git.webhop.me Git - msgbox.git/commitdiff
msgbox: fix sizeof(int)
authorsatbaby <crashdvb@googlemail.com>
Mon, 24 Dec 2012 15:43:04 +0000 (16:43 +0100)
committersatbaby <crashdvb@googlemail.com>
Mon, 24 Dec 2012 15:43:04 +0000 (16:43 +0100)
io.c
io.h
msgbox.c
msgbox.h
text.c
text.h
txtform.c

diff --git a/io.c b/io.c
index b4cdaa29dc55e08be985f158c8bc6144e4b2fd36..c450459e4882c8c887d636995e39140d5bf660ea 100644 (file)
--- a/io.c
+++ b/io.c
@@ -15,6 +15,7 @@
 #include <sys/dir.h>
 #include <sys/stat.h>
 #include <linux/input.h>
+#include "msgbox.h"
 
 #include "io.h"
 
@@ -23,7 +24,7 @@
 extern int instance;
 struct input_event ev;
 static unsigned short rccode=-1;
-static int rc;
+static int rc = 0;
 
 int InitRC(void)
 {
diff --git a/io.h b/io.h
index d7914d4f4e97f11216121e42e03dc12704738ca8..1619ae7d013df3b78184e782816612294bbe4b66 100644 (file)
--- a/io.h
+++ b/io.h
@@ -7,5 +7,6 @@
 int InitRC(void);
 int CloseRC(void);
 int RCKeyPressed(void);
+int GetRCCode(void);
 
 #endif
index 1b3c52cc6aea83674a00d974625ea6f61fe7d31a..3ec7bcbf3437c8f738edf6671f4f6ae6ab1c5f15 100644 (file)
--- a/msgbox.c
+++ b/msgbox.c
@@ -38,17 +38,16 @@ static char spres[][5]={"","_crt","_lcd"};
 
 char *line_buffer=NULL, *title=NULL;
 int size=24, type=0, timeout=0, refresh=3, flash=0, selection=0, tbuttons=0, buttons=0, bpline=3, echo=0, absolute=0, mute=1, header=1, cyclic=1;
-char *butmsg[16];
 int rbutt[16],hide=0,radius=10;
 
 // Misc
-char NOMEM[]="msgbox <Out of memory>\n";
+const char NOMEM[]="msgbox <Out of memory>\n";
 char TMP_FILE[64]="/tmp/msgbox.tmp";
 unsigned char *lfb = 0, *lbb = 0, *obb = 0, *hbb = 0, *ibb = 0;
 unsigned char nstr[BUFSIZE]="";
 unsigned char *trstr;
 unsigned rc,sc[8]={'a','o','u','A','O','U','z','d'}, tc[8]={0xE4,0xF6,0xFC,0xC4,0xD6,0xDC,0xDF,0xB0};
-char INST_FILE[]="/tmp/rc.locked";
+const char INST_FILE[]="/tmp/rc.locked";
 int instance=0;
 
 int get_instance(void)
@@ -66,10 +65,9 @@ int rval=0;
 
 void put_instance(int pval)
 {
-FILE *fh;
-
        if(pval)
        {
+               FILE *fh;
                if((fh=fopen(INST_FILE,"w"))!=NULL)
                {
                        fputc(pval,fh);
@@ -82,7 +80,7 @@ FILE *fh;
        }
 }
 
-static void quit_signal(int sig)
+static void quit_signal()
 {
        put_instance(get_instance()-1);
        printf("msgbox Version %.2f killed\n",M_VERSION);
@@ -92,13 +90,11 @@ static void quit_signal(int sig)
 int Read_Neutrino_Cfg(char *entry)
 {
 FILE *nfh;
-char tstr [512], *cfptr=NULL;
 int rv=-1;
 
        if((nfh=fopen(NCF_FILE,"r"))!=NULL)
        {
-               tstr[0]=0;
-
+               char tstr [512]={0}, *cfptr=NULL;
                while((!feof(nfh)) && ((strstr(tstr,entry)==NULL) || ((cfptr=strchr(tstr,'='))==NULL)))
                {
                        fgets(tstr,500,nfh);
@@ -322,7 +318,7 @@ FILE *xfh;
                if((xfh=fopen(msg,"r"))!=NULL)
                {
                        fclose(xfh);
-                       strcpy(TMP_FILE,msg);
+                       snprintf(TMP_FILE,sizeof(TMP_FILE),"%s",msg);
                }
                else
                {
@@ -388,11 +384,10 @@ void ShowUsage(void)
 
 int main (int argc, char **argv)
 {
-int index,index2,tv,found=0, spr;
+int index=0,tv=0,found=0, spr=0;
 int dloop=1, rcc=-1, cupd=0;
-char rstr[BUFSIZE], *rptr, *aptr;
-time_t tm1,tm2;
-unsigned int alpha;
+char rstr[BUFSIZE]={0}, *rptr=NULL, *aptr=NULL;
+time_t tm1=0,tm2=0;
 //clock_t tk1=0;
 FILE *fh;
 
index c3bc57e55f1e569dcdc8d80f18e30288c95075c4..ef50388c6df52e50831adf36f24e62255c95117e 100644 (file)
--- a/msgbox.h
+++ b/msgbox.h
@@ -124,7 +124,7 @@ extern unsigned char rd[],gn[],bl[],tr[];
 
 int startx, starty, sx, ex, sy, ey, debounce, rblock;
 extern unsigned sc[8], tc[8];
-extern char *butmsg[MAX_BUTTONS];
+char *butmsg[MAX_BUTTONS];
 extern int buttons,selection;
 extern int instance;
 int get_instance(void);
diff --git a/text.c b/text.c
index fb90e07233c6b3007b942bffb3fab09b96137c67..a54cbf3011ed0812a3440b25af89876d130f0454 100644 (file)
--- a/text.c
+++ b/text.c
@@ -14,7 +14,7 @@ int TABULATOR=72;
 FT_Error MyFaceRequester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *aface)
 {
        FT_Error result;
-
+       request_data=request_data;//for unused request_data
        result = FT_New_Face(library, face_id, 0, aface);
 
        if(result) printf("msgbox <Font \"%s\" failed>\n", (char*)face_id);
@@ -70,8 +70,9 @@ int RenderChar(FT_ULong currentchar, int sx, int sy, int ex, int color)
 
                if(color != -1) /* don't render char, return charwidth only */
                {
-                       if(sx + sbit->xadvance >= ex) return -1; /* limit to maxwidth */
-
+                       if(sx + sbit->xadvance >= ex){
+                               return -1; /* limit to maxwidth */
+                       }
                        for(row = 0; row < sbit->height; row++)
                        {
                                for(pitch = 0; pitch < sbit->pitch; pitch++)
@@ -101,9 +102,9 @@ int RenderChar(FT_ULong currentchar, int sx, int sy, int ex, int color)
  * GetStringLen
  ******************************************************************************/
 
-int GetStringLen(int sx, unsigned char *string, int size)
+int GetStringLen(int sx, char *string, int size)
 {
-int i, found;
+unsigned int i = 0;
 int stringlen = 0;
 
        //reset kerning
@@ -142,8 +143,8 @@ int stringlen = 0;
                                        }
                                        else
                                        {
-                                               found=0;
-                                               for(i=0; i<sizeof(sc) && !found; i++)
+                                               int found=0;
+                                               for(i=0; i<sizeof(sc)/sizeof(sc[0]) && !found; i++)
                                                {
                                                        if(*string==sc[i])
                                                        {
@@ -185,13 +186,13 @@ void CatchTabs(char *text)
 
 int RenderString(char *string, int sx, int sy, int maxwidth, int layout, int size, int color)
 {
-       int stringlen, ex, charwidth,i,found;
-       char rstr[BUFSIZE], *rptr=rstr, rc;
+       int stringlen = 0, ex = 0, charwidth = 0,found = 0;
+       unsigned int i = 0;
+       char rstr[BUFSIZE]={0}, *rptr=rstr, rc=' ';
        int varcolor=color;
 
        //set size
-       
-               strcpy(rstr,string);
+               snprintf(rstr,sizeof(rstr),"%s",string);
 
                desc.width = desc.height = size;
                TABULATOR=3*size;
@@ -225,11 +226,10 @@ int RenderString(char *string, int sx, int sy, int maxwidth, int layout, int siz
                                ++rptr;
                                rc=*rptr;
                                found=0;
-                               for(i=0; i<sizeof(sc) && !found; i++)
+                               for(i=0; i< sizeof(sc)/sizeof(sc[0]) && !found; i++)
                                {
                                        if(rc==sc[i])
                                        {
-                                               rc=tc[i];
                                                found=1;
                                        }
                                }
@@ -247,7 +247,7 @@ int RenderString(char *string, int sx, int sy, int maxwidth, int layout, int siz
                                                case 'Y': varcolor=YELLOW; break;
                                                case 'B': varcolor=BLUE1; break;
                                                case 'S': varcolor=color; break;
-                                               case 't':                               
+                                               case 't':
                                                        sx=TABULATOR*((int)(sx/TABULATOR)+1);
                                                        break;
                                                case 'T':
diff --git a/text.h b/text.h
index a28cac142d4d488a8239f5c80e4b15b2f61f82be..a76a0caf4d195cdd139782fd0e9ca3d0c9c3133f 100644 (file)
--- a/text.h
+++ b/text.h
@@ -6,7 +6,7 @@
 
 FT_Error MyFaceRequester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *aface);
 int RenderString(char *string, int sx, int sy, int maxwidth, int layout, int size, int color);
-int GetStringLen(int sx, unsigned char *string, int size);
+int GetStringLen(int sx, char *string, int size);
 void CatchTabs(char *text);
 
 #endif
index 4933d2710e49b2c6ebcd3c186f800efd9ca40591..ffa3529dce8b913ff733eec2c1e8a6b98314f553 100644 (file)
--- a/txtform.c
+++ b/txtform.c
 int fh_txt_trans(const char *name, int xs, int xw, int ys, int dy, int size, int line, int *cut, int *x, int *y, int plot)
 {
 char tstr[BUFSIZE],rstr[BUFSIZE],*tptr;
-int loop=1, j, first, slen, cnt=0;
+int loop=1, j, slen, cnt=0;
 FILE *fh;
 int just, color=CMCT;
 
        if(!(fh=fopen(name,"rb")))      return(FH_ERROR_FILE);
 
-       first=(line==0);
        *x=0;
        *y=0;
        while((loop>0) && (fgets(tstr, sizeof(tstr), fh)))
@@ -65,10 +64,6 @@ int just, color=CMCT;
                                if(loop>=line)
                                {
                                        RenderString(rstr, xs, ys, xw, just, size, color);
-                                       if(strlen(rstr))
-                                       {
-                                               first=0;
-                                       }
                                        ys+=dy;
                                }
                        }