From 5eaf8edcf7dbbd371c9384680bb31ccb02b8ed82 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 1 May 2005 09:26:28 +0000 Subject: [PATCH] - Fix sign extension problem in lex.c that reads UTF-8 with Chinese characters incorrectly. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1971 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/console/conio.c | 530 ++++++++++++++++++------------------- bacula/src/filed/job.c | 4 +- bacula/src/lib/edit.c | 92 +++---- bacula/src/lib/lex.c | 4 +- bacula/src/lib/lex.h | 2 +- bacula/src/version.h | 6 +- 6 files changed, 320 insertions(+), 318 deletions(-) diff --git a/bacula/src/console/conio.c b/bacula/src/console/conio.c index 140a79ad31..e0a037a567 100755 --- a/bacula/src/console/conio.c +++ b/bacula/src/console/conio.c @@ -2,15 +2,15 @@ Generalized console input/output handler A maintanable replacement for readline() - Updated for Bacula, Kern Sibbald, December MMIII + Updated for Bacula, Kern Sibbald, December MMIII This code is in part derived from code that I wrote in 1981, so some of it is a bit old and could use a cleanup. */ /* - Copyright (C) 1981-2004 Kern Sibbald and John Walker - Yes, that is 1981 no error. + Copyright (C) 1981-2005 Kern Sibbald + Yes, that is 1981 no error. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -39,7 +39,7 @@ */ -#ifdef TEST_PROGRAM +#ifdef TEST_PROGRAM #include #include #include @@ -94,33 +94,33 @@ static void add_smap(char *str, int func); static const char *t_up = "\n"; /* scroll up character */ static const char *t_honk = "\007"; /* sound beep */ -static char *t_il; /* insert line */ -static char *t_dl; /* delete line */ -static char *t_cs; /* clear screen */ -static char *t_cl; /* clear line */ -static int t_width = 79; /* terminal width */ -static int t_height = 24; /* terminal height */ -static int linsdel_ok = 0; /* set if term has line insert & delete fncs */ - -static char *t_cm; /* cursor positioning */ -static char *t_ti; /* init sequence */ -static char *t_te; /* end sequence */ -static char *t_do; /* down one line */ -static char *t_sf; /* scroll screen one line up */ +static char *t_il; /* insert line */ +static char *t_dl; /* delete line */ +static char *t_cs; /* clear screen */ +static char *t_cl; /* clear line */ +static int t_width = 79; /* terminal width */ +static int t_height = 24; /* terminal height */ +static int linsdel_ok = 0; /* set if term has line insert & delete fncs */ + +static char *t_cm; /* cursor positioning */ +static char *t_ti; /* init sequence */ +static char *t_te; /* end sequence */ +static char *t_do; /* down one line */ +static char *t_sf; /* scroll screen one line up */ /* Keypad and Function Keys */ -static char *kl; /* left key */ -static char *kr; /* right */ -static char *ku; /* up */ -static char *kd; /* down */ -static char *kh; /* home */ -static char *kb; /* backspace */ -static char *kD; /* delete key */ -static char *kI; /* insert */ -static char *kN; /* next page */ -static char *kP; /* previous page */ -static char *kH; /* home */ -static char *kE; /* end */ +static char *kl; /* left key */ +static char *kr; /* right */ +static char *ku; /* up */ +static char *kd; /* down */ +static char *kh; /* home */ +static char *kb; /* backspace */ +static char *kD; /* delete key */ +static char *kI; /* insert */ +static char *kN; /* next page */ +static char *kP; /* previous page */ +static char *kH; /* home */ +static char *kE; /* end */ #ifndef EOS #define EOS '\0' /* end of string terminator */ @@ -141,8 +141,8 @@ typedef struct s_stab { #define MAX_STAB 30 -static stab_t **stab = NULL; /* array of stabs by length */ -static int num_stab; /* size of stab array */ +static stab_t **stab = NULL; /* array of stabs by length */ +static int num_stab; /* size of stab array */ static bool old_term_params_set = false; static struct termios old_term_params; @@ -151,48 +151,48 @@ static struct termios old_term_params; preceded by a header defined by the lstr structure */ -struct lstr { /* line pool structure */ - struct lstr *prevl; /* link to previous line */ - struct lstr *nextl; /* link to next line */ - long len; /* length of line+header */ - char used; /* set if line valid */ - char line; /* line is actually varying length */ +struct lstr { /* line pool structure */ + struct lstr *prevl; /* link to previous line */ + struct lstr *nextl; /* link to next line */ + long len; /* length of line+header */ + char used; /* set if line valid */ + char line; /* line is actually varying length */ }; #ifdef unix -#define POOLEN 128000 /* bytes in line pool */ +#define POOLEN 128000 /* bytes in line pool */ #else -#define POOLEN 500 /* bytes in line pool */ +#define POOLEN 500 /* bytes in line pool */ #endif -char pool[POOLEN]; /* line pool */ +char pool[POOLEN]; /* line pool */ #define PHDRL ((int)sizeof(struct lstr)) /* length of line header */ -static struct lstr *lptr; /* current line pointer */ -static struct lstr *slptr; /* store line pointer */ +static struct lstr *lptr; /* current line pointer */ +static struct lstr *slptr; /* store line pointer */ static int cl, cp; static char *getnext(), *getprev(); static int first = 1; static int mode_insert = 0; -static int mode_wspace = 1; /* words separated by spaces */ +static int mode_wspace = 1; /* words separated by spaces */ static short char_map[600]= { - 0, F_SOL, /* ^a Line start */ + 0, F_SOL, /* ^a Line start */ F_PRVWRD, /* ^b Previous word */ F_BREAK, /* ^C break */ - F_DELCHR, /* ^D Delete character */ F_EOL, /* ^e End of line */ - F_CSRRGT, /* ^f Right */ F_TABBAK, /* ^G Back tab */ - F_CSRLFT, /* ^H Left */ F_TAB, /* ^I Tab */ - F_CSRDWN, /* ^J Down */ F_DELEOL, /* ^K kill to eol */ + F_DELCHR, /* ^D Delete character */ F_EOL, /* ^e End of line */ + F_CSRRGT, /* ^f Right */ F_TABBAK, /* ^G Back tab */ + F_CSRLFT, /* ^H Left */ F_TAB, /* ^I Tab */ + F_CSRDWN, /* ^J Down */ F_DELEOL, /* ^K kill to eol */ F_CLRSCRN,/* ^L clear screen */ F_RETURN, /* ^M Carriage return */ F_RETURN, /* ^N enter line */ F_CONCAT, /* ^O Concatenate lines */ - F_CSRUP, /* ^P cursor up */ F_TINS, /* ^Q Insert character mode */ - F_PAGUP, /* ^R Page up */ F_CENTER, /* ^S Center text */ + F_CSRUP, /* ^P cursor up */ F_TINS, /* ^Q Insert character mode */ + F_PAGUP, /* ^R Page up */ F_CENTER, /* ^S Center text */ F_PAGDWN, /* ^T Page down */ F_DELSOL, /* ^U delete to start of line */ F_DELWRD, /* ^V Delete word */ F_PRVWRD, /* ^W Previous word */ F_NXTMCH, /* ^X Next match */ F_DELEOL, /* ^Y Delete to end of line */ - F_BACKGND,/* ^Z Background */ 0x1B, /* ^[=ESC escape */ + F_BACKGND,/* ^Z Background */ 0x1B, /* ^[=ESC escape */ F_TENTRY, /* ^\ Entry mode */ F_PASTECB,/* ^]=paste clipboard */ - F_HOME, /* ^^ Home */ F_ERSLIN, /* ^_ Erase line */ + F_HOME, /* ^^ Home */ F_ERSLIN, /* ^_ Erase line */ ' ','!','"','#','$','%','&','\047', '(',')','*','+','\054','-','.','/', @@ -269,15 +269,15 @@ void con_init(FILE *input) */ void con_set_zed_keys(void) { - char_map[1] = F_NXTWRD; /* ^A Next Word */ - char_map[2] = F_SPLIT; /* ^B Split line */ - char_map[3] = F_EOI; /* ^C Quit */ - char_map[4] = F_DELCHR; /* ^D Delete character */ - char_map[5] = F_EOF; /* ^E End of file */ - char_map[6] = F_INSCHR; /* ^F Insert character */ - char_map[7] = F_TABBAK; /* ^G Back tab */ - char_map[8] = F_CSRLFT; /* ^H Left */ - char_map[9] = F_TAB; /* ^I Tab */ + char_map[1] = F_NXTWRD; /* ^A Next Word */ + char_map[2] = F_SPLIT; /* ^B Split line */ + char_map[3] = F_EOI; /* ^C Quit */ + char_map[4] = F_DELCHR; /* ^D Delete character */ + char_map[5] = F_EOF; /* ^E End of file */ + char_map[6] = F_INSCHR; /* ^F Insert character */ + char_map[7] = F_TABBAK; /* ^G Back tab */ + char_map[8] = F_CSRLFT; /* ^H Left */ + char_map[9] = F_TAB; /* ^I Tab */ char_map[10] = F_CSRDWN; /* ^J Down */ char_map[11] = F_CSRUP; /* ^K Up */ char_map[12] = F_CSRRGT; /* ^L Right */ @@ -344,18 +344,18 @@ static unsigned do_smap(unsigned c) for ( ;; ) { found = 0; for (i=len-1; inext) { - if (strncmp(str, tstab->str, len) == 0) { - if (len == tstab->len) { - return tstab->func; - } - found = 1; - break; /* found possibility continue searching */ - } - } + for (tstab=stab[i]; tstab; tstab=tstab->next) { + if (strncmp(str, tstab->str, len) == 0) { + if (len == tstab->len) { + return tstab->func; + } + found = 1; + break; /* found possibility continue searching */ + } + } } if (!found) { - return len==1?c:0; + return len==1?c:0; } /* found partial match, so get next character and retry */ str[len++] = t_gnc(); @@ -372,19 +372,19 @@ static void dump_stab() for (i=0; inext) { - for (j=0; jlen; j++) { - c = tstab->str[j]; - if (c < 0x20 || c > 0x7F) { + for (j=0; jlen; j++) { + c = tstab->str[j]; + if (c < 0x20 || c > 0x7F) { sprintf(buf, " 0x%x ", c); - t_send(buf); - } else { - buf[0] = c; - buf[1] = 0; - t_sendl(buf, 1); - } - } + t_send(buf); + } else { + buf[0] = c; + buf[1] = 0; + t_sendl(buf, 1); + } + } sprintf(buf, " func=%d len=%d\n\r", tstab->func, tstab->len); - t_send(buf); + t_send(buf); } } } @@ -419,7 +419,7 @@ static void add_smap(char *str, int func) tstab->next = stab[tstab->len-1]; stab[tstab->len-1] = tstab; /* printf("Add_smap tstab=%x len=%d func=%d tstab->next=%x\n\r", tstab, len, - func, tstab->next); */ + func, tstab->next); */ } @@ -431,19 +431,19 @@ input_char() { unsigned c; - if ((c=t_gnc()) <= 599) { /* IBM generates codes up to 260 */ - c = do_smap(c); - } else if (c > 1000) { /* stuffed function */ - c -= 1000; /* convert back to function code */ + if ((c=t_gnc()) <= 599) { /* IBM generates codes up to 260 */ + c = do_smap(c); + } else if (c > 1000) { /* stuffed function */ + c -= 1000; /* convert back to function code */ } if (c <= 0) { - t_honk_horn(); + t_honk_horn(); } /* if we got a screen size escape sequence, read height, width */ if (c == F_SCRSIZ) { int y, x; - y = t_gnc() - 0x20; /* y */ - x = t_gnc() - 0x20; /* x */ + y = t_gnc() - 0x20; /* y */ + x = t_gnc() - 0x20; /* x */ c = input_char(); } return c; @@ -455,167 +455,167 @@ input_char() int input_line(char *string, int length) { - char curline[2000]; /* edit buffer */ + char curline[2000]; /* edit buffer */ int noline; unsigned c; int more; int i; if (first) { - poolinit(); /* build line pool */ + poolinit(); /* build line pool */ first = 0; } - noline = 1; /* no line fetched yet */ + noline = 1; /* no line fetched yet */ for (cl=cp=0; cl cp) - cl = cp; - break; + t_clrline(0, t_width); + if (cl > cp) + cl = cp; + break; case F_NXTWRD: - i = next_word(curline); - while (i--) { - forward(curline, sizeof(curline)); - } - break; + i = next_word(curline); + while (i--) { + forward(curline, sizeof(curline)); + } + break; case F_PRVWRD: - i = prev_word(curline); - while (i--) { - backup(curline); - } - break; + i = prev_word(curline); + while (i--) { + backup(curline); + } + break; case F_DELWRD: - delchr(next_word(curline), curline, sizeof(curline)); /* delete word */ - break; - case F_NXTMCH: /* Ctl-X */ - if (cl==0) { - *string = EOS; /* terminate string */ - return(c); /* give it to him */ - } - /* Note fall through */ + delchr(next_word(curline), curline, sizeof(curline)); /* delete word */ + break; + case F_NXTMCH: /* Ctl-X */ + if (cl==0) { + *string = EOS; /* terminate string */ + return(c); /* give it to him */ + } + /* Note fall through */ case F_DELLIN: case F_ERSLIN: - while (cp > 0) { - backup(curline); /* backup to beginning of line */ - } - t_clrline(0, t_width); /* erase line */ - cp = 0; - cl = 0; /* reset cursor counter */ + while (cp > 0) { + backup(curline); /* backup to beginning of line */ + } + t_clrline(0, t_width); /* erase line */ + cp = 0; + cl = 0; /* reset cursor counter */ t_char(' '); - t_char(0x8); - break; + t_char(0x8); + break; case F_SOL: - while (cp > 0) { - backup(curline); - } - break; + while (cp > 0) { + backup(curline); + } + break; case F_EOL: - while (cp < cl) { - forward(curline, sizeof(curline)); - } - while (cp > cl) { - backup(curline); - } - break; - case F_TINS: /* toggle insert mode */ - mode_insert = !mode_insert; /* flip bit */ - break; + while (cp < cl) { + forward(curline, sizeof(curline)); + } + while (cp > cl) { + backup(curline); + } + break; + case F_TINS: /* toggle insert mode */ + mode_insert = !mode_insert; /* flip bit */ + break; default: - if (c > 255) { /* function key hit */ - if (cl==0) { /* if first character then */ - *string = EOS; /* terminate string */ - return c; /* return it */ - } - t_honk_horn(); /* complain */ - } else { - if ((c & 0xC0) == 0xC0) { - if ((c & 0xFC) == 0xFC) { - more = 5; - } else if ((c & 0xF8) == 0xF8) { - more = 4; - } else if ((c & 0xF0) == 0xF0) { - more = 3; - } else if ((c & 0xE0) == 0xE0) { - more = 2; - } else { - more = 1; - } - } else { - more = 0; - } - if (mode_insert) { - insert_space(curline, sizeof(curline)); - } - curline[cp++] = c; /* store character in line being built */ - t_char(c); /* echo character to terminal */ - while (more--) { - c= input_char(); - insert_hole(curline, sizeof(curline)); - curline[cp++] = c; /* store character in line being built */ - t_char(c); /* echo character to terminal */ - } - if (cp > cl) { - cl = cp; /* keep current length */ - curline[cp] = 0; - } - } - break; - } /* end switch */ + if (c > 255) { /* function key hit */ + if (cl==0) { /* if first character then */ + *string = EOS; /* terminate string */ + return c; /* return it */ + } + t_honk_horn(); /* complain */ + } else { + if ((c & 0xC0) == 0xC0) { + if ((c & 0xFC) == 0xFC) { + more = 5; + } else if ((c & 0xF8) == 0xF8) { + more = 4; + } else if ((c & 0xF0) == 0xF0) { + more = 3; + } else if ((c & 0xE0) == 0xE0) { + more = 2; + } else { + more = 1; + } + } else { + more = 0; + } + if (mode_insert) { + insert_space(curline, sizeof(curline)); + } + curline[cp++] = c; /* store character in line being built */ + t_char(c); /* echo character to terminal */ + while (more--) { + c= input_char(); + insert_hole(curline, sizeof(curline)); + curline[cp++] = c; /* store character in line being built */ + t_char(c); /* echo character to terminal */ + } + if (cp > cl) { + cl = cp; /* keep current length */ + curline[cp] = 0; + } + } + break; + } /* end switch */ } /* If we fall through here rather than goto done, the line is too long simply return what we have now. */ done: - curline[cl++] = EOS; /* terminate */ - bstrncpy(string,curline,length); /* return line to caller */ + curline[cl++] = EOS; /* terminate */ + bstrncpy(string,curline,length); /* return line to caller */ /* Note, put line zaps curline */ - putline(curline,cl); /* save line for posterity */ - return 0; /* give it to him/her */ + putline(curline,cl); /* save line for posterity */ + return 0; /* give it to him/her */ } /* Insert a space at the current cursor position */ @@ -671,12 +671,12 @@ forward(char *str, int str_len) } else { t_char(str[cp]); if ((str[cp] & 0xC0) == 0xC0) { - cp++; - while ((str[cp] & 0xC0) == 0x80) { - t_char(str[cp]); - cp++; - } - cp--; + cp++; + while ((str[cp] & 0xC0) == 0x80) { + t_char(str[cp]); + cp++; + } + cp--; } } cp++; @@ -693,8 +693,8 @@ char_count(int cptr, char *str) if ((str[cptr] & 0xC0) == 0xC0) { cptr++; while ((str[cptr] & 0xC0) == 0x80) { - cnt++; - cptr++; + cnt++; + cptr++; } } return cnt; @@ -726,18 +726,18 @@ delchr(int del, char *curline, int line_len) while (del-- && cp > 0) { cnt = char_count(cp, curline); if ((i=cl-cp-cnt) > 0) { - memcpy(&curline[cp], &curline[cp+cnt], i); + memcpy(&curline[cp], &curline[cp+cnt], i); } cl -= cnt; curline[cl] = EOS; t_clrline(0, t_width); i = 0; while (cl > cp) { - forward(curline, line_len); - i++; + forward(curline, line_len); + i++; } while (i--) { - backup(curline); + backup(curline); } } } @@ -775,23 +775,23 @@ prev_word(char *ldb_buf) { int ncp, i; - if (cp == 0) /* if at begin of line stop now */ - return 0; - if (cp > cl) /* if past eol start at eol */ - ncp=cl+1; + if (cp == 0) /* if at begin of line stop now */ + return 0; + if (cp > cl) /* if past eol start at eol */ + ncp=cl+1; else - ncp = cp; + ncp = cp; /* backup to end of previous word - i.e. skip special chars */ for (i=ncp-1; i && !iswordc(*(ldb_buf+i)); i--) ; - if (i == 0) { /* at beginning of line? */ - return cp; /* backup to beginning */ + if (i == 0) { /* at beginning of line? */ + return cp; /* backup to beginning */ } /* now move back through word to beginning of word */ for ( ; i && iswordc(*(ldb_buf+i)); i--) ; - ncp = i+1; /* position to first char of word */ + ncp = i+1; /* position to first char of word */ if (i==0 && iswordc(*ldb_buf)) /* check for beginning of line */ - ncp = 0; - return cp-ncp; /* return count */ + ncp = 0; + return cp-ncp; /* return count */ } /* Display new current line */ @@ -824,7 +824,7 @@ poolinit() static char * getnext() { - do { /* find next used line */ + do { /* find next used line */ lptr = lptr->nextl; } while (!lptr->used); return (char *)&lptr->line; @@ -834,7 +834,7 @@ getnext() static char * getprev() { - do { /* find previous used line */ + do { /* find previous used line */ lptr = lptr->prevl; } while (!lptr->used); return (char *)&lptr->line; @@ -843,17 +843,17 @@ getprev() static void putline(char *newl, int newlen) { - struct lstr *nptr; /* points to next line */ + struct lstr *nptr; /* points to next line */ char *p; - lptr = slptr; /* get ptr to last line stored */ - lptr = lptr->nextl; /* advance pointer */ + lptr = slptr; /* get ptr to last line stored */ + lptr = lptr->nextl; /* advance pointer */ if ((char *)lptr-pool+newlen+PHDRL > POOLEN) { /* not enough room */ - lptr->used = 0; /* delete line */ + lptr->used = 0; /* delete line */ lptr = (struct lstr *)pool; /* start at beginning of buffer */ } while (lptr->len < newlen+PHDRL) { /* concatenate buffers */ - nptr = lptr->nextl; /* point to next line */ + nptr = lptr->nextl; /* point to next line */ lptr->nextl = nptr->nextl; /* unlink it from list */ nptr->nextl->prevl = lptr; lptr->len += nptr->len; @@ -861,10 +861,10 @@ putline(char *newl, int newlen) if (lptr->len > newlen + 2 * PHDRL) { /* split buffer */ nptr = (struct lstr *)((char *)lptr + newlen + PHDRL); /* Appropriate byte alignment - normally 2 byte, but on - sparc we need 4 byte alignment, so we always do 4 */ + sparc we need 4 byte alignment, so we always do 4 */ if (((long unsigned)nptr & 3) != 0) { /* test four byte alignment */ - p = (char *)nptr; - nptr = (struct lstr *)((((long unsigned) p) & ~3) + 4); + p = (char *)nptr; + nptr = (struct lstr *)((((long unsigned) p) & ~3) + 4); } nptr->len = lptr->len - ((char *)nptr - (char *)lptr); lptr->len -= nptr->len; @@ -875,20 +875,20 @@ putline(char *newl, int newlen) nptr->used = 0; } memcpy(&lptr->line,newl,newlen); - lptr->used = 1; /* mark line used */ - slptr = lptr; /* save as stored line */ + lptr->used = 1; /* mark line used */ + slptr = lptr; /* save as stored line */ } -#ifdef DEBUGOUT +#ifdef DEBUGOUT static void dump(struct lstr *ptr, char *msg) { printf("%s buf=%x nextl=%x prevl=%x len=%d used=%d\n", - msg,ptr,ptr->nextl,ptr->prevl,ptr->len,ptr->used); + msg,ptr,ptr->nextl,ptr->prevl,ptr->len,ptr->used); if (ptr->used) printf("line=%s\n",&ptr->line); } -#endif /* DEBUGOUT */ +#endif /* DEBUGOUT */ /* Honk horn on terminal */ @@ -916,7 +916,7 @@ t_delete_line() static void t_clrline(int pos, int width) { - asclrl(pos, width); /* clear to end of line */ + asclrl(pos, width); /* clear to end of line */ } /* Helper function to add string preceded by @@ -924,7 +924,7 @@ t_clrline(int pos, int width) static void add_esc_smap(const char *str, int func) { char buf[1000]; - buf[0] = 0x1B; /* esc */ + buf[0] = 0x1B; /* esc */ bstrncpy(buf+1, str, sizeof(buf)-1); add_smap(buf, func); } @@ -953,11 +953,11 @@ static void rawmode(FILE *input) t.c_cc[VMIN] = 1; /* satisfy read after 1 char */ t.c_cc[VTIME] = 0; t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK | - ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR); + ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR); t.c_iflag |= IGNBRK; t.c_oflag |= ONLCR; t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON | - NOFLSH | TOSTOP); + NOFLSH | TOSTOP); tcflush(0, TCIFLUSH); if (tcsetattr(0, TCSANOW, &t) == -1) { printf("Cannot tcsetattr()\n"); @@ -1000,7 +1000,7 @@ static void rawmode(FILE *input) t_do = (char *)tgetstr("do", &term_buffer); t_sf = (char *)tgetstr("sf", &term_buffer); - num_stab = MAX_STAB; /* get default stab size */ + num_stab = MAX_STAB; /* get default stab size */ stab = (stab_t **)malloc(sizeof(stab_t *) * num_stab); memset(stab, 0, sizeof(stab_t *) * num_stab); @@ -1083,7 +1083,7 @@ t_send(const char *msg) if (msg == NULL) { return; } - t_sendl(msg, strlen(msg)); /* faster than one char at time */ + t_sendl(msg, strlen(msg)); /* faster than one char at time */ } /* Send single character to terminal - primitive routine - */ @@ -1094,7 +1094,7 @@ t_char(char c) } -static int brkflg = 0; /* set on user break */ +static int brkflg = 0; /* set on user break */ /* Routine to return true if user types break */ int usrbrk() @@ -1134,12 +1134,12 @@ static void asclrl(int pos, int width) int i; if (t_cl) { - t_send(t_cl); /* use clear to eol function */ + t_send(t_cl); /* use clear to eol function */ return; } if (pos==1 && linsdel_ok) { - t_delete_line(); /* delete line */ - t_insert_line(); /* reinsert it */ + t_delete_line(); /* delete line */ + t_insert_line(); /* reinsert it */ return; } for (i=1; i<=width-pos+1; i++) @@ -1171,7 +1171,7 @@ static void asclrs() static void asinsl() { t_clrline(0, t_width); - t_send(t_il); /* insert before */ + t_send(t_il); /* insert before */ } /* ASDELL -- Delete line at cursor */ diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index c999ef191e..6f0d401ba4 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -549,10 +549,12 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese POOLMEM *fn; FILE *ffd; char buf[1000]; + int ch; int stat; p = (char *)fname; - switch (*p) { + ch = (uint8_t)*p; + switch (ch) { case '|': p++; /* skip over | */ fn = get_pool_memory(PM_FNAME); diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index 526af060f8..23fda7737e 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -45,7 +45,7 @@ uint64_t str_to_uint64(char *str) p++; } while (B_ISDIGIT(*p)) { - value = value * 10 + *p - '0'; + value = B_TIMES10(value) + *p - '0'; p++; } return value; @@ -89,16 +89,16 @@ char *edit_uint64_with_commas(uint64_t val, char *buf) */ char mbuf[50]; mbuf[sizeof(mbuf)-1] = 0; - int i = sizeof(mbuf)-2; /* edit backward */ + int i = sizeof(mbuf)-2; /* edit backward */ if (val == 0) { mbuf[i--] = '0'; } else { while (val != 0) { mbuf[i--] = "0123456789"[val%10]; - val /= 10; + val /= 10; } } - strcpy(buf, &mbuf[i+1]); + bstrncpy(buf, &mbuf[i+1], sizeof(buf)); return add_commas(buf, buf); } @@ -114,13 +114,13 @@ char *edit_uint64(uint64_t val, char *buf) */ char mbuf[50]; mbuf[sizeof(mbuf)-1] = 0; - int i = sizeof(mbuf)-2; /* edit backward */ + int i = sizeof(mbuf)-2; /* edit backward */ if (val == 0) { mbuf[i--] = '0'; } else { while (val != 0) { mbuf[i--] = "0123456789"[val%10]; - val /= 10; + val /= 10; } } strcpy(buf, &mbuf[i+1]); @@ -135,17 +135,17 @@ char *edit_int64(int64_t val, char *buf) char mbuf[50]; bool negative = false; mbuf[sizeof(mbuf)-1] = 0; - int i = sizeof(mbuf)-2; /* edit backward */ + int i = sizeof(mbuf)-2; /* edit backward */ if (val == 0) { mbuf[i--] = '0'; } else { if (val < 0) { - negative = true; - val = -val; + negative = true; + val = -val; } while (val != 0) { mbuf[i--] = "0123456789"[val%10]; - val /= 10; + val /= 10; } } if (negative) { @@ -166,14 +166,14 @@ static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_l /* * Look for modifier by walking back looking for the first - * space or digit. + * space or digit. */ strip_trailing_junk(str); len = strlen(str); for (i=0; i 0) { - val = val - (utime_t)times * mult[i]; + val = val - (utime_t)times * mult[i]; bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":""); - bstrncat(buf, mybuf, buf_len); + bstrncat(buf, mybuf, buf_len); } } if (val == 0 && strlen(buf) == 0) { @@ -301,7 +301,7 @@ char *edit_utime(utime_t val, char *buf, int buf_len) /* * Convert a size in bytes to uint64_t * Returns 0: if error - 1: if OK, and value stored in value + 1: if OK, and value stored in value */ int size_to_uint64(char *str, int str_len, uint64_t *value) { @@ -310,13 +310,13 @@ int size_to_uint64(char *str, int str_len, uint64_t *value) char mod_str[20]; char num_str[50]; static const char *mod[] = {"*", "k", "kb", "m", "mb", "g", "gb", NULL}; /* first item * not used */ - const int64_t mult[] = {1, /* byte */ - 1024, /* kilobyte */ - 1000, /* kb kilobyte */ - 1048576, /* megabyte */ - 1000000, /* mb megabyte */ - 1073741824, /* gigabyte */ - 1000000000}; /* gb gigabyte */ + const int64_t mult[] = {1, /* byte */ + 1024, /* kilobyte */ + 1000, /* kb kilobyte */ + 1048576, /* megabyte */ + 1000000, /* mb megabyte */ + 1073741824, /* gigabyte */ + 1000000000}; /* gb gigabyte */ if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) { return 0; @@ -325,11 +325,11 @@ int size_to_uint64(char *str, int str_len, uint64_t *value) mod_len = strlen(mod_str); for (i=0; mod[i]; i++) { if (strncasecmp(mod_str, mod[i], mod_len) == 0) { - break; + break; } } if (mod[i] == NULL) { - i = 0; /* no modifier found, assume 1 */ + i = 0; /* no modifier found, assume 1 */ } Dmsg2(900, "str=%s: mult=%d\n", str, mult[i]); errno = 0; @@ -362,7 +362,7 @@ bool is_a_number(const char *n) } if (digit_seen && (*n == 'e' || *n == 'E') && (B_ISDIGIT(n[1]) || ((n[1]=='-' || n[1] == '+') && B_ISDIGIT(n[2])))) { - n += 2; /* skip e- or e+ or e digit */ + n += 2; /* skip e- or e+ or e digit */ while (B_ISDIGIT(*n)) { n++; } } return digit_seen && *n==0; @@ -398,7 +398,7 @@ bool is_name_valid(char *name, POOLMEM **msg) /* Restrict the characters permitted in the Volume name */ for (p=name; *p; p++) { if (B_ISALPHA(*p) || B_ISDIGIT(*p) || strchr(accept, (int)(*p))) { - continue; + continue; } if (msg) { Mmsg(msg, _("Illegal character \"%c\" in name.\n"), *p); @@ -446,7 +446,7 @@ char *add_commas(char *val, char *buf) *q-- = *p--; for ( ; nc; nc--) { for (i=0; i < 3; i++) { - *q-- = *p--; + *q-- = *p--; } *q-- = ','; } @@ -467,7 +467,7 @@ int main(int argc, char *argv[]) strcpy(buf, str[i]); if (!duration_to_utime(buf, &val)) { printf("Error return from duration_to_utime for in=%s\n", str[i]); - continue; + continue; } edit_utime(val, outval); printf("in=%s val=%" lld " outval=%s\n", str[i], val, outval); diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index 714b0f8a42..9f98b6c476 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -8,7 +8,7 @@ */ /* - Copyright (C) 2000-2004 Kern Sibbald + Copyright (C) 2000-2005 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -183,7 +183,7 @@ int lex_get_char(LEX *lf) lf->line_no++; lf->col_no = 0; } - lf->ch = lf->line[lf->col_no]; + lf->ch = (uint8_t)lf->line[lf->col_no]; if (lf->ch == 0) { lf->ch = L_EOL; } else { diff --git a/bacula/src/lib/lex.h b/bacula/src/lib/lex.h index 68113338fe..e293a3a70a 100644 --- a/bacula/src/lib/lex.h +++ b/bacula/src/lib/lex.h @@ -9,7 +9,7 @@ * */ /* - Copyright (C) 2000-2004 Kern Sibbald + Copyright (C) 2000-2005 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as diff --git a/bacula/src/version.h b/bacula/src/version.h index 2e73fb83aa..37904b89d2 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #undef VERSION -#define VERSION "1.37.15" -#define BDATE "30 April 2005" -#define LSMDATE "30Apr05" +#define VERSION "1.37.16" +#define BDATE "01 May 2005" +#define LSMDATE "01May05" /* Debug flags */ #undef DEBUG -- 2.39.5