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.
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.
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 1981-2006 Free Software Foundation Europe e.V.
+ 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
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation and included
+ in the file LICENSE.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+ Bacula® is a registered trademark of Kern Sibbald.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
* UTF-8
* If the top bit of a UTF-8 string is 0 (8 bits), then it
* is a normal ASCII character.
* UTF-8
* If the top bit of a UTF-8 string is 0 (8 bits), then it
* is a normal ASCII character.
extern "C" int tgetnum(const char *);
extern "C" char *tgetstr (const char*, char**);
extern "C" char *tgoto (const char *, int, int);
extern "C" int tgetnum(const char *);
extern "C" char *tgetstr (const char*, char**);
extern "C" char *tgoto (const char *, int, int);
+#elif HAVE_HPUX_OS
+#include <term.h>
+#elif HAVE_AIX_OS
+#include <curses.h>
+#include <term.h>
+#elif defined(__sgi)
+extern "C" int tgetent(char *, char *);
+extern "C" int tgetnum(char id[2]);
+extern "C" char *tgetstr(char id[2], char **);
+extern "C" char *tgoto(char *, int, int);
+#elif defined (__digital__) && defined (__unix__)
+extern "C" int tgetent(void *, const char *);
+extern "C" int tgetnum(const char *);
+extern "C" char *tgetstr (const char*, char**);
+extern "C" char *tgoto (const char *, int, int);
+
static const char *t_up = "\n"; /* scroll up character */
static const char *t_honk = "\007"; /* sound beep */
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 */
-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 */
-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 */
-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 */
-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 cl, cp;
static char *getnext(), *getprev();
static int first = 1;
static int mode_insert = 0;
- 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_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_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 */
' ','!','"','#','$','%','&','\047',
'(',')','*','+','\054','-','.','/',
' ','!','"','#','$','%','&','\047',
'(',')','*','+','\054','-','.','/',
- 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 */
char_map[10] = F_CSRDWN; /* ^J Down */
char_map[11] = F_CSRUP; /* ^K Up */
char_map[12] = F_CSRRGT; /* ^L Right */
- 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 */
- }
- }
+ 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 */
+ }
+ }
sprintf(buf, " func=%d len=%d\n\r", tstab->func, tstab->len);
sprintf(buf, " func=%d len=%d\n\r", tstab->func, tstab->len);
-/* printf("Add_smap tstab=%x len=%d func=%d tstab->next=%x\n\r", tstab, len,
- func, tstab->next); */
+/* printf("Add_smap tstab=%x len=%d func=%d tstab->next=%x\n\r", tstab, len,
+ func, tstab->next); */
- 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 (noline) { /* no line fetched yet */
- getnext(); /* getnext so getprev gets current */
- noline = 0; /* we now have line */
- }
- bstrncpy(curline, getprev(), sizeof(curline));
- prtcur(curline);
- break;
+ if (noline) { /* no line fetched yet */
+ getnext(); /* getnext so getprev gets current */
+ noline = 0; /* we now have line */
+ }
+ bstrncpy(curline, getprev(), sizeof(curline));
+ prtcur(curline);
+ break;
- noline = 0; /* mark line fetched */
- bstrncpy(curline, getnext(), sizeof(curline));
- prtcur(curline);
- break;
+ noline = 0; /* mark line fetched */
+ bstrncpy(curline, getnext(), sizeof(curline));
+ prtcur(curline);
+ break;
- delchr(1, curline, sizeof(curline)); /* delete one character */
- break;
- case F_CSRLFT: /* Backspace */
- backup(curline);
- break;
+ delchr(1, curline, sizeof(curline)); /* delete one character */
+ break;
+ case F_CSRLFT: /* Backspace */
+ backup(curline);
+ break;
- forward(curline, sizeof(curline));
- break;
- case F_ERSCHR: /* Rubout */
- backup(curline);
- delchr(1, curline, sizeof(curline));
- if (cp == 0) {
+ forward(curline, sizeof(curline));
+ break;
+ case F_ERSCHR: /* Rubout */
+ backup(curline);
+ delchr(1, curline, sizeof(curline));
+ if (cp == 0) {
- i = next_word(curline);
- while (i--) {
- forward(curline, sizeof(curline));
- }
- break;
+ i = next_word(curline);
+ while (i--) {
+ forward(curline, sizeof(curline));
+ }
+ break;
- 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 */
- 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 */
- 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;
- 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:
}
/* 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 */
- 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 */
while (del-- && cp > 0) {
cnt = char_count(cp, curline);
if ((i=cl-cp-cnt) > 0) {
while (del-- && cp > 0) {
cnt = char_count(cp, curline);
if ((i=cl-cp-cnt) > 0) {
/* backup to end of previous word - i.e. skip special chars */
for (i=ncp-1; i && !iswordc(*(ldb_buf+i)); i--) ;
/* backup to end of previous word - i.e. skip special chars */
for (i=ncp-1; i && !iswordc(*(ldb_buf+i)); i--) ;
lptr = (struct lstr *)pool; /* start at beginning of buffer */
}
while (lptr->len < newlen+PHDRL) { /* concatenate buffers */
lptr = (struct lstr *)pool; /* start at beginning of buffer */
}
while (lptr->len < newlen+PHDRL) { /* concatenate buffers */
if (lptr->len > newlen + 2 * PHDRL) { /* split buffer */
nptr = (struct lstr *)((char *)lptr + newlen + PHDRL);
/* Appropriate byte alignment - normally 2 byte, but on
if (lptr->len > newlen + 2 * PHDRL) { /* split buffer */
nptr = (struct lstr *)((char *)lptr + newlen + PHDRL);
/* Appropriate byte alignment - normally 2 byte, but on
static void
dump(struct lstr *ptr, char *msg)
{
printf("%s buf=%x nextl=%x prevl=%x len=%d used=%d\n",
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);
- t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |
- ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR);
+ t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |
+ ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR);
tcflush(0, TCIFLUSH);
if (tcsetattr(0, TCSANOW, &t) == -1) {
printf("Cannot tcsetattr()\n");
tcflush(0, TCIFLUSH);
if (tcsetattr(0, TCSANOW, &t) == -1) {
printf("Cannot tcsetattr()\n");
/* Defaults, the main program can override these */
signal(SIGQUIT, SIG_IGN);
signal(SIGHUP, SIG_IGN);
/* Defaults, the main program can override these */
signal(SIGQUIT, SIG_IGN);
signal(SIGHUP, SIG_IGN);
- signal(SIGWINCH, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- signal(SIGCHLD, SIG_IGN);
-// signal(SIGTSTP, SIG_IGN);
+ signal(SIGWINCH, SIG_IGN);
- t_width = tgetnum("co") - 1;
- t_height = tgetnum("li");
+ /* Note (char *)casting is due to really stupid compiler warnings */
+ t_width = tgetnum((char *)"co") - 1;
+ t_height = tgetnum((char *)"li");
- t_cm = (char *)tgetstr("cm", &term_buffer);
- t_cs = (char *)tgetstr("cl", &term_buffer); /* clear screen */
- t_cl = (char *)tgetstr("ce", &term_buffer); /* clear line */
- t_dl = (char *)tgetstr("dl", &term_buffer); /* delete line */
- t_il = (char *)tgetstr("al", &term_buffer); /* insert line */
- t_honk = (char *)tgetstr("bl", &term_buffer); /* beep */
- t_ti = (char *)tgetstr("ti", &term_buffer);
- t_te = (char *)tgetstr("te", &term_buffer);
- t_up = (char *)tgetstr("up", &term_buffer);
- t_do = (char *)tgetstr("do", &term_buffer);
- t_sf = (char *)tgetstr("sf", &term_buffer);
-
- num_stab = MAX_STAB; /* get default stab size */
+ t_cm = (char *)tgetstr((char *)"cm", &term_buffer);
+ t_cs = (char *)tgetstr((char *)"cl", &term_buffer); /* clear screen */
+ t_cl = (char *)tgetstr((char *)"ce", &term_buffer); /* clear line */
+ t_dl = (char *)tgetstr((char *)"dl", &term_buffer); /* delete line */
+ t_il = (char *)tgetstr((char *)"al", &term_buffer); /* insert line */
+ t_honk = (char *)tgetstr((char *)"bl", &term_buffer); /* beep */
+ t_ti = (char *)tgetstr((char *)"ti", &term_buffer);
+ t_te = (char *)tgetstr((char *)"te", &term_buffer);
+ t_up = (char *)tgetstr((char *)"up", &term_buffer);
+ t_do = (char *)tgetstr((char *)"do", &term_buffer);
+ t_sf = (char *)tgetstr((char *)"sf", &term_buffer);
+
+ 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);
/* Key bindings */
stab = (stab_t **)malloc(sizeof(stab_t *) * num_stab);
memset(stab, 0, sizeof(stab_t *) * num_stab);
/* Key bindings */
- kl = (char *)tgetstr("kl", &term_buffer);
- kr = (char *)tgetstr("kr", &term_buffer);
- ku = (char *)tgetstr("ku", &term_buffer);
- kd = (char *)tgetstr("kd", &term_buffer);
- kh = (char *)tgetstr("kh", &term_buffer);
- kb = (char *)tgetstr("kb", &term_buffer);
- kD = (char *)tgetstr("kD", &term_buffer);
- kI = (char *)tgetstr("kI", &term_buffer);
- kN = (char *)tgetstr("kN", &term_buffer);
- kP = (char *)tgetstr("kP", &term_buffer);
- kH = (char *)tgetstr("kH", &term_buffer);
- kE = (char *)tgetstr("kE", &term_buffer);
+ kl = (char *)tgetstr((char *)"kl", &term_buffer);
+ kr = (char *)tgetstr((char *)"kr", &term_buffer);
+ ku = (char *)tgetstr((char *)"ku", &term_buffer);
+ kd = (char *)tgetstr((char *)"kd", &term_buffer);
+ kh = (char *)tgetstr((char *)"kh", &term_buffer);
+ kb = (char *)tgetstr((char *)"kb", &term_buffer);
+ kD = (char *)tgetstr((char *)"kD", &term_buffer);
+ kI = (char *)tgetstr((char *)"kI", &term_buffer);
+ kN = (char *)tgetstr((char *)"kN", &term_buffer);
+ kP = (char *)tgetstr((char *)"kP", &term_buffer);
+ kH = (char *)tgetstr((char *)"kH", &term_buffer);
+ kE = (char *)tgetstr((char *)"kE", &term_buffer);
/* Send message to terminal - primitive routine */
void
t_sendl(const char *msg, int len)
/* Send message to terminal - primitive routine */
void
t_sendl(const char *msg, int len)