Permalink
Browse files

Make strbuf and callers use size_t instead of int

  • Loading branch information...
1 parent 6a2e6cf commit e808d4d86c6f54dc62019ab31ebe153e7230682b ec429 committed Jul 12, 2012
Showing with 35 additions and 34 deletions.
  1. +2 −2 bits.c
  2. +1 −1 bits.h
  3. +3 −3 buffer.c
  4. +1 −1 colour.c
  5. +1 −1 colour.h
  6. +6 −5 input.c
  7. +2 −2 input.h
  8. +1 −1 names.c
  9. +5 −5 strbuf.c
  10. +3 −3 strbuf.h
  11. +5 −5 ttyesc.c
  12. +5 −5 ttyesc.h
View
4 bits.c
@@ -8,13 +8,13 @@
#include "bits.h"
-int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour lc)
+int wordline(const char *msg, unsigned int x, char **out, size_t *l, size_t *i, colour lc)
{
if(!msg) return(x);
unsigned int tabx=x;
if(tabx*2>width)
tabx=8;
- int l2,i2;
+ size_t l2,i2;
char *word;
const char *ptr=msg;
colour cc=lc; // current colour
View
2 bits.h
@@ -24,7 +24,7 @@
char *strndup(const char *s, size_t size);
#endif
-int wordline(const char *msg, unsigned int x, char **out, int *l, int *i, colour lc); // prepares a string for printing, breaking lines in between words; returns new x
+int wordline(const char *msg, unsigned int x, char **out, size_t *l, size_t *i, colour lc); // prepares a string for printing, breaking lines in between words; returns new x
void crush(char **buf, unsigned int len);
void scrush(char **buf, unsigned int len);
char *mktag(char *fmt, char *from);
View
@@ -511,7 +511,7 @@ int render_line(int buf, int uline)
bufs[buf].lpl[uline]=0;
return(0);
}
- char *proc;int l,i;
+ char *proc;size_t l,i;
init_char(&proc, &l, &i);
char stamp[40];
struct tm *td=(utc?gmtime:localtime)(&bufs[buf].ts[uline]);
@@ -850,7 +850,7 @@ void in_update(iline inp)
else
{
int torem=floor((wwidth/4.0)*floor(((inp.left.i-(wwidth/2.0))*4.0/wwidth)+0.5));
- torem=min(torem, inp.left.i-3);
+ torem=min(torem, (int)inp.left.i-3);
int c=inp.left.i+4-torem;
char ll[max(3, c/4)+1];
snprintf(ll, max(3, c/4)+1, "%s", inp.left.data);
@@ -877,7 +877,7 @@ void in_update(iline inp)
char *highlight(const char *src)
{
- int l,i;char *rv;
+ size_t l,i;char *rv;
init_char(&rv, &l, &i);
while(*src)
{
View
@@ -13,7 +13,7 @@ int setcolour(colour c)
return(setcol(c.fore, c.back, c.hi, c.ul));
}
-int s_setcolour(colour c, char **rv, int *l, int *i)
+int s_setcolour(colour c, char **rv, size_t *l, size_t *i)
{
return(s_setcol(c.fore, c.back, c.hi, c.ul, rv, l, i));
}
View
@@ -22,7 +22,7 @@ colour;
#include "ttyesc.h"
int setcolour(colour); // wrapper for setcol
-int s_setcolour(colour, char **, int *, int *); // wrapper for s_setcol
+int s_setcolour(colour, char **, size_t *, size_t *); // wrapper for s_setcol
colour c_mirc(int, int);
int c_init(void);
View
11 input.c
@@ -14,7 +14,8 @@ int inputchar(iline *inp, int *state)
int c=getchar();
if((c==0)||(c==EOF)) // stdin is set to non-blocking, so this may happen
return(0);
- char *seq;int sl,si,mod=-1;
+ char *seq;size_t sl,si;
+ int mod=-1;
init_char(&seq, &sl, &si);
bool match=true;
while(match&&(mod<0))
@@ -95,12 +96,12 @@ int inputchar(iline *inp, int *state)
}
if(c=='\t') // tab completion of nicks
{
- int sp=max(inp->left.i-1, 0);
+ size_t sp=max(inp->left.i-1, 0);
while(sp>0 && !strchr(" \t", inp->left.data[sp-1]))
sp--;
name *curr=bufs[cbuf].nlist;
name *found=NULL;
- int count=0, mlen=0;
+ size_t count=0, mlen=0;
while(curr)
{
if((inp->left.i==sp) || (irc_strncasecmp(inp->left.data+sp, curr->data, inp->left.i-sp, bufs[cbuf].casemapping)==0))
@@ -109,7 +110,7 @@ int inputchar(iline *inp, int *state)
n_add(&found, curr->data, bufs[cbuf].casemapping);
if(old&&(old->data))
{
- int i;
+ size_t i;
for(i=0;i<mlen;i++)
{
if(irc_to_upper(curr->data[i], bufs[cbuf].casemapping)!=irc_to_upper(old->data[i], bufs[cbuf].casemapping))
@@ -144,7 +145,7 @@ int inputchar(iline *inp, int *state)
else if(found->next||(count>1))
{
char *fmsg;
- int i,l;
+ size_t i,l;
init_char(&fmsg, &i, &l);
while(found)
{
View
@@ -18,8 +18,8 @@
typedef struct
{
char *data;
- int l;
- int i;
+ size_t l;
+ size_t i;
}
ichar;
View
@@ -142,7 +142,7 @@ int i_match(name * list, const char *nm, bool pm, cmap casemapping)
char *data;
if(curr->icase)
{
- int l,i;
+ size_t l,i;
init_char(&data, &l, &i);
char *p=curr->data;
while(*p)
View
@@ -9,7 +9,7 @@
#include <stdlib.h>
#include "strbuf.h"
-void append_char(char **buf, int *l, int *i, char c)
+void append_char(char **buf, size_t *l, size_t *i, char c)
{
if(*buf)
{
@@ -38,15 +38,15 @@ void append_char(char **buf, int *l, int *i, char c)
}
}
-void append_str(char **buf, int *l, int *i, const char *str)
+void append_str(char **buf, size_t *l, size_t *i, const char *str)
{
while(str && *str) // not the most tremendously efficient implementation, but conceptually simple at least
{
append_char(buf, l, i, *str++);
}
}
-void init_char(char **buf, int *l, int *i)
+void init_char(char **buf, size_t *l, size_t *i)
{
*l=80;
*buf=(char *)malloc(*l);
@@ -57,7 +57,7 @@ void init_char(char **buf, int *l, int *i)
char * fgetl(FILE *fp)
{
char * lout;
- int l,i;
+ size_t l,i;
init_char(&lout, &l, &i);
signed int c;
while(!feof(fp))
@@ -76,7 +76,7 @@ char * fgetl(FILE *fp)
char *slurp(FILE *fp)
{
char *fout;
- int l,i;
+ size_t l,i;
init_char(&fout, &l, &i);
signed int c;
while(!feof(fp))
View
@@ -12,6 +12,6 @@
char *fgetl(FILE *); // gets a line of string data; returns a malloc-like pointer
char *slurp(FILE *); // gets an entire file of string data; returns a malloc-like pointer
-void init_char(char **buf, int *l, int *i); // initialises a string buffer in heap. *buf becomes a malloc-like pointer
-void append_char(char **buf, int *l, int *i, char c); // adds a character to a string buffer in heap (and realloc()s if needed)
-void append_str(char **buf, int *l, int *i, const char *str); // adds a string to a string buffer in heap (and realloc()s if needed)
+void init_char(char **buf, size_t *l, size_t *i); // initialises a string buffer in heap. *buf becomes a malloc-like pointer
+void append_char(char **buf, size_t *l, size_t *i, char c); // adds a character to a string buffer in heap (and realloc()s if needed)
+void append_str(char **buf, size_t*l, size_t *i, const char *str); // adds a string to a string buffer in heap (and realloc()s if needed)
View
@@ -43,7 +43,7 @@ int setcol(int fore, int back, bool hi, bool ul)
return(0);
}
-int s_setcol(int fore, int back, bool hi, bool ul, char **rv, int *l, int *i)
+int s_setcol(int fore, int back, bool hi, bool ul, char **rv, size_t *l, size_t *i)
{
if((fore<0)||(fore>7))
return(1);
@@ -74,7 +74,7 @@ int resetcol(void)
return(setcol(7, 0, false, false));
}
-int s_resetcol(char **rv, int *l, int *i)
+int s_resetcol(char **rv, size_t *l, size_t *i)
{
return(s_setcol(7, 0, false, false, rv, l, i));
}
@@ -102,7 +102,7 @@ int cls(void)
return(0);
}
-int s_cls(char **rv, int *l, int *i)
+int s_cls(char **rv, size_t *l, size_t *i)
{
const char *cl=clear_screen;
if(cl)
@@ -141,7 +141,7 @@ int clr(void)
return(0);
}
-int s_clr(char **rv, int *l, int *i)
+int s_clr(char **rv, size_t *l, size_t *i)
{
const char *cl=clr_eol;
if(cl)
@@ -177,7 +177,7 @@ int locate(int y, int x)
return(0);
}
-int s_locate(int y, int x, char **rv, int *l, int *i)
+int s_locate(int y, int x, char **rv, size_t *l, size_t *i)
{
const char *loc=tparm(cursor_address, y-1, x-1);
if(loc) append_str(rv, l, i, loc);
View
@@ -15,15 +15,15 @@
#include "bits.h"
int setcol(int fore, int back, bool hi, bool ul); // sets the text colour
-int s_setcol(int fore, int back, bool hi, bool ul, char **rv, int *l, int *i); // writes a setcol-like string with append_char (see bits.h)
+int s_setcol(int fore, int back, bool hi, bool ul, char **rv, size_t *l, size_t *i); // writes a setcol-like string with append_char (see bits.h)
int resetcol(void); // default setcol() values
-int s_resetcol(char **rv, int *l, int *i); // s_setcol to the colour set by resetcol
+int s_resetcol(char **rv, size_t *l, size_t *i); // s_setcol to the colour set by resetcol
int cls(void); // CLear Screen
-int s_cls(char **rv, int *l, int *i);
+int s_cls(char **rv, size_t *l, size_t *i);
int clr(void); // Clear Line to Right
-int s_clr(char **rv, int *l, int *i);
+int s_clr(char **rv, size_t *l, size_t *i);
int locate(int y, int x); // Set cursor position
-int s_locate(int y, int x, char **rv, int *l, int *i);
+int s_locate(int y, int x, char **rv, size_t *l, size_t *i);
int savepos(void); // Save cursor position
int restpos(void); // Restore cursor position
int settitle(const char *newtitle); // sets the window title if running in a term in a window system (eg. xterm)

0 comments on commit e808d4d

Please sign in to comment.