]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/conio.c
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / console / conio.c
index e0a037a567fbb99974c6d2f9be543a6a9f9fe112..03860afbe02d70e4066ac76f5a4374dbb60f6d17 100755 (executable)
@@ -1,3 +1,21 @@
+/*
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2015 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
 /*
       Generalized console input/output handler
       A maintanable replacement for readline()
@@ -8,26 +26,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
@@ -46,6 +44,7 @@
 #include <signal.h>
 #include <string.h>
 #include <ctype.h>
+#define HAVE_CONIO 1
 #else
 
 /* We are in Bacula */
 
 #endif
 
-#include <termios.h>
+#ifdef HAVE_CONIO
+
+#include <curses.h>
+#include <term.h>
+
 #ifdef HAVE_SUN_OS
+#ifndef _TERM_H
 extern "C" int tgetent(void *, const char *);
 extern "C" int tgetnum(const char *);
 extern "C" char *tgetstr (const char*, char**);
+# Note: the following on older (Solaris 10) systems
+#  may need to be moved to after the #endif
 extern "C" char *tgoto (const char *, int, int);
-#elif HAVE_HPUX_OS
-#include <term.h>
+#endif
+#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
@@ -134,9 +141,9 @@ static char *kE;                             /* end */
  */
 typedef struct s_stab {
    struct s_stab *next;
+   char *str;
    int len;
    int func;
-   char *str;
 } stab_t;
 
 #define MAX_STAB 30
@@ -172,7 +179,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 */
 
 
@@ -441,9 +448,8 @@ input_char()
     }
     /* 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 */
+       t_gnc();   /*  - 0x20 = y */
+       t_gnc();   /*  - 0x20 = x */
        c = input_char();
     }
     return c;
@@ -613,8 +619,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 +632,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 +731,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);
@@ -858,13 +866,13 @@ putline(char *newl, int newlen)
        nptr->nextl->prevl = lptr;
        lptr->len += nptr->len;
    }
-   if (lptr->len > newlen + 2 * PHDRL) { /* split buffer */
+   if (lptr->len > newlen + 2 * PHDRL + 7) { /* 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 */
-       if (((long unsigned)nptr & 3) != 0) { /* test four byte alignment */
+       /* Appropriate byte alignment - for Intel 2 byte, but on
+          Sparc we need 8 byte alignment, so we always do 8 */
+       if (((long unsigned)nptr & 7) != 0) { /* test eight byte alignment */
            p = (char *)nptr;
-           nptr = (struct lstr *)((((long unsigned) p) & ~3) + 4);
+           nptr = (struct lstr *)((((long unsigned) p) & ~7) + 8);
        }
        nptr->len = lptr->len - ((char *)nptr - (char *)lptr);
        lptr->len -= nptr->len;
@@ -966,12 +974,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 +988,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 +1095,7 @@ t_send(const char *msg)
 void
 t_char(char c)
 {
-   write(1, &c, 1);
+   (void)write(1, &c, 1);
 }
 
 
@@ -1179,3 +1184,5 @@ static void asdell()
 {
    t_send(t_dl);
 }
+
+#endif