]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/conio.c
First cut of bat rerun a Job from Jobs Run
[bacula/bacula] / bacula / src / console / conio.c
index e0a037a567fbb99974c6d2f9be543a6a9f9fe112..c04779667c5aa4ebbe7470f25399191278e9a6b4 100755 (executable)
@@ -1,3 +1,31 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 1981-2010 Free Software Foundation Europe e.V.
+             Yes, that is 1981 no error.
+
+   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 three of the GNU Affero 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
+   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 Affero 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.
+*/
 /*
       Generalized console input/output handler
       A maintanable replacement for readline()
@@ -8,26 +36,6 @@
       1981, so some of it is a bit old and could use a cleanup.
 
 */
-/*
-   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
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
-
-   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.
-
-   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.
-
- */
 
 /*
  * UTF-8
 
 #endif
 
-#include <termios.h>
-#ifdef HAVE_SUN_OS
+#include <curses.h>
+#include <term.h>
+
+#if defined(HAVE_SUN_OS)
+#if !defined(_TERM_H)
 extern "C" int tgetent(void *, const char *);
 extern "C" int tgetnum(const char *);
 extern "C" char *tgetstr (const char*, char**);
+#endif
 extern "C" char *tgoto (const char *, int, int);
-#elif HAVE_HPUX_OS
-#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);
-
-#else
-#include <termcap.h>
 #endif
 #include "func.h"
 
 
 /* From termios library */
-#ifdef HAVE_HPUX_OS
+#if defined(HAVE_HPUX_OS) || defined(HAVE_AIX_OS)
 static char *BC;
 static char *UP;
 #else
@@ -172,7 +184,7 @@ 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_insert = 1;
 static int mode_wspace = 1;           /* words separated by spaces */
 
 
@@ -613,8 +625,10 @@ input_line(char *string, int length)
 done:
    curline[cl++] = EOS;              /* terminate */
    bstrncpy(string,curline,length);           /* return line to caller */
-   /* Note, put line zaps curline */
-   putline(curline,cl);              /* save line for posterity */
+   /* Save non-blank lines. Note, put line zaps curline */
+   if (curline[0] != EOS) {
+      putline(curline,cl);            /* save line for posterity */
+   }
    return 0;                         /* give it to him/her */
 }
 
@@ -624,7 +638,7 @@ insert_space(char *curline, int curline_len)
 {
    int i;
 
-   if (cp > cl || cl+1 > curline_len) {
+   if (cp >= cl || cl+1 > curline_len) {
       return;
    }
    /* Note! source and destination overlap */
@@ -723,7 +737,7 @@ delchr(int del, char *curline, int line_len)
    if (cp > cl || del == 0) {
       return;
    }
-   while (del-- && cp > 0) {
+   while (del-- && cl > 0) {
       cnt = char_count(cp, curline);
       if ((i=cl-cp-cnt) > 0) {
          memcpy(&curline[cp], &curline[cp+cnt], i);
@@ -966,12 +980,8 @@ static void rawmode(FILE *input)
    /* Defaults, the main program can override these */
    signal(SIGQUIT, SIG_IGN);
    signal(SIGHUP, SIG_IGN);
-// signal(SIGSTOP, SIG_IGN);
    signal(SIGINT, sigintcatcher);
    signal(SIGWINCH, SIG_IGN);
-   signal(SIGQUIT, SIG_IGN);
-   signal(SIGCHLD, SIG_IGN);
-// signal(SIGTSTP, SIG_IGN);
 
    if (!termtype) {
       printf("Cannot get terminal type.\n");
@@ -984,39 +994,40 @@ static void rawmode(FILE *input)
       exit(1);
    }
    t_width = t_height = -1;
-   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");
    BC = NULL;
    UP = NULL;
-   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);
+   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 */
-   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);
 
    add_smap(kl, F_CSRLFT);
    add_smap(kr, F_CSRRGT);
@@ -1090,7 +1101,7 @@ t_send(const char *msg)
 void
 t_char(char c)
 {
-   write(1, &c, 1);
+   (void)write(1, &c, 1);
 }