Back to index

tetex-bin  3.0
Defines | Functions | Variables
dialog.c File Reference
#include "dialog.h"

Go to the source code of this file.

Defines

#define __DIALOG_MAIN__

Functions

int main (int argc, char *argv[])
void Usage (char *name)
void init_dialog (void)
void attr_clear (WINDOW *win, int height, int width, chtype attr)
void print_autowrap (WINDOW *win, char *prompt, int width, int y, int x)
void print_button (WINDOW *win, char *label, int y, int x, int selected)
void draw_box (WINDOW *win, int y, int x, int height, int width, chtype box, chtype border)

Variables

static char * backtitle = NULL
int separate_output = 0

Define Documentation

#define __DIALOG_MAIN__

Definition at line 87 of file dialog.c.


Function Documentation

void attr_clear ( WINDOW win,
int  height,
int  width,
chtype  attr 
)

Definition at line 435 of file dialog.c.

{
/* ifdef HAVE_NCURSES
  wattrset(win, attr);    Set window to attribute 'attr'
  werase(win);
else */
  int i, j;

  wattrset(win, attr);    /* Set window to attribute 'attr' */
  for (i = 0; i < height; i++) {
    wmove(win, i, 0);
    for (j = 0; j < width; j++)
      waddch(win, ' ');
  }
  touchwin(win);
/* endif */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_box ( WINDOW win,
int  y,
int  x,
int  height,
int  width,
chtype  box,
chtype  border 
)

Definition at line 556 of file dialog.c.

{
  int i, j;

  wattrset(win, 0);
  for (i = 0; i < height; i++) {
    wmove(win, y + i, x);
    for (j = 0; j < width; j++)
      if (!i && !j)
        waddch(win, border | ACS_ULCORNER);
      else if (i == height-1 && !j)
        waddch(win, border | ACS_LLCORNER);
      else if (!i && j == width-1)
        waddch(win, box | ACS_URCORNER);
      else if (i == height-1 && j == width-1)
        waddch(win, box | ACS_LRCORNER);
      else if (!i)
        waddch(win, border | ACS_HLINE);
      else if (i == height-1)
        waddch(win, box | ACS_HLINE);
      else if (!j)
        waddch(win, border | ACS_VLINE);
      else if (j == width-1)
        waddch(win, box | ACS_VLINE);
      else
        waddch(win, box | ' ');
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 370 of file dialog.c.

{
  int i;
  
#ifdef HAVE_NCURSES
  if (parse_rc() == -1)    /* Read the configuration file */
    exit(-1);
#endif

  initscr();     /* Init curses */
  keypad(stdscr, TRUE);
  cbreak();
  noecho();

#ifdef HAVE_NCURSES
  if (use_colors || use_shadow)    /* Set up colors */
    color_setup();
#endif

  /* Set screen to screen attribute */
  attr_clear(stdscr, LINES, COLS, screen_attr);

  /* Display background title if it exists ... - SLH */
  if (backtitle != NULL)
  {
    wattrset(stdscr, screen_attr);
    wmove(stdscr, 0, 1);
    waddstr(stdscr,backtitle);
    wmove(stdscr, 1, 1);
    for(i=1; i<COLS-1; i++)
      waddch(stdscr, ACS_HLINE);
  }
  
  wnoutrefresh(stdscr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 98 of file dialog.c.

{
  int offset = 0, clear_screen = 0, end_common_opts = 0, retval;
  char *title = NULL;
  
#if defined(LOCALE)
  (void) setlocale(LC_ALL, "");
#endif

  if (argc < 2) {
    Usage(argv[0]);
    exit(-1);
  }
  else if (!strcmp(argv[1], "--create-rc")) {
#ifdef HAVE_NCURSES
    if (argc != 3) {
      Usage(argv[0]);
      exit(-1);
    }
    create_rc(argv[2]);
    return 0;
#else
    fprintf(stderr, "\nThis option is currently unsupported on your system.\n");
    return -1;
#endif
  }

  while (offset < argc-1 && !end_common_opts) {    /* Common options */
    if (!strcmp(argv[offset+1], "--title")) {
      if (argc-offset < 3 || title != NULL) {    /* No two "--title" please! */
        Usage(argv[0]);
        exit(-1);
      }
      else {
        title = argv[offset+2];
        offset += 2;
      }
    }
    else if (!strcmp(argv[offset+1], "--backtitle" ))
    {
      if (backtitle != NULL)
      {
        Usage(argv[0]);
        exit(-1);
      }
      else
      {
       backtitle = argv[offset+2];
       offset += 2;
      }
    }
    else if (!strcmp(argv[offset+1], "--separate-output" ))
    {
       separate_output = 1;
       offset++;
    }
    else if (!strcmp(argv[offset+1], "--clear")) {
      if (clear_screen) {    /* Hey, "--clear" can't appear twice! */
        Usage(argv[0]);
        exit(-1);
      }
      else if (argc == 2) {    /* we only want to clear the screen */
        init_dialog();
        refresh();    /* init_dialog() will clear the screen for us */
        endwin();
        return 0;
      }
      else {
        clear_screen = 1;
        offset++;
      }
    }
    else    /* no more common options */
      end_common_opts = 1;
  }

  if (argc-1 == offset) {    /* no more options */
    Usage(argv[0]);
    exit(-1);
  }

  /* Box options */

  if (!strcmp(argv[offset+1], "--yesno")) {
    if (argc-offset != 5) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_yesno(title, argv[offset+2], atoi(argv[offset+3]),
                          atoi(argv[offset+4]));

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }
  else if (!strcmp(argv[offset+1], "--msgbox")) {
    if (argc-offset != 5) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_msgbox(title, argv[offset+2], atoi(argv[offset+3]),
                           atoi(argv[offset+4]), 1);

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }
  else if (!strcmp(argv[offset+1], "--infobox")) {
    if (argc-offset != 5) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_msgbox(title, argv[offset+2], atoi(argv[offset+3]),
                           atoi(argv[offset+4]), 0);

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }
  else if (!strcmp(argv[offset+1], "--textbox")) {
    if (argc-offset != 5) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_textbox(title, argv[offset+2], atoi(argv[offset+3]),
                            atoi(argv[offset+4]));

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }
  else if (!strcmp(argv[offset+1], "--menu")) {
    if (argc-offset < 8 || ((argc-offset) % 2)) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_menu(title, argv[offset+2], atoi(argv[offset+3]),
                         atoi(argv[offset+4]), atoi(argv[offset+5]),
                         (argc-offset-6)/2, argv+offset + 6);

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }
  else if (!strcmp(argv[offset+1], "--checklist")) {
    if (argc-offset < 9 || ((argc-offset-6) % 3)) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_checklist(title, argv[offset+2], atoi(argv[offset+3]),
                              atoi(argv[offset+4]), atoi(argv[offset+5]),
                              (argc-offset-6)/3, argv+offset + 6);

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }
  else if (!strcmp(argv[offset+1], "--radiolist")) {
    if (argc-offset < 9 || ((argc-offset-6) % 3)) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_radiolist(title, argv[offset+2], atoi(argv[offset+3]),
                              atoi(argv[offset+4]), atoi(argv[offset+5]),
                              (argc-offset-6)/3, argv+offset + 6);

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }
  else if (!strcmp(argv[offset+1], "--guage")) {
      if (argc-offset != 6) {
         Usage(argv[0]);
         exit(-1);
      }
      init_dialog();
      retval = dialog_guage(title,  argv[offset+2],
                         atoi(argv[offset+3]), atoi(argv[offset+4]),
                         atoi(argv[offset+5]));
      
      if (clear_screen) {    /* clear screen before exit */
         attr_clear(stdscr, LINES, COLS, screen_attr);
         refresh();
      }
      endwin();
      return retval;
  }
  else if (!strcmp(argv[offset+1], "--inputbox")) {
    if (argc-offset < 5 || argc-offset > 6) {
      Usage(argv[0]);
      exit(-1);
    }
    init_dialog();
    retval = dialog_inputbox(title, argv[offset+2], atoi(argv[offset+3]),
                             atoi(argv[offset+4]),
                          (argc-offset == 6) ? argv[offset+5] : (char *)NULL);

    if (clear_screen) {    /* clear screen before exit */
      attr_clear(stdscr, LINES, COLS, screen_attr);
      refresh();
    }
    endwin();
    return retval;
  }

  Usage(argv[0]);
  exit(-1);
}

Here is the call graph for this function:

void print_autowrap ( WINDOW win,
char *  prompt,
int  width,
int  y,
int  x 
)

Definition at line 461 of file dialog.c.

{
  int first = 1, cur_x, cur_y;
  char tempstr[MAX_LEN+1], *word, *tempptr, *tempptr1;

  strcpy(tempstr, prompt);
  if ((strstr(tempstr, "\\n") != NULL) ||
      (strchr(tempstr, '\n') != NULL)) {    /* Prompt contains "\n" or '\n' */
    word = tempstr;
    cur_y = y;
    wmove(win, cur_y, x);
    while (1) {
      tempptr = strstr(word, "\\n");
      tempptr1 = strchr(word, '\n');
      if (tempptr == NULL && tempptr1 == NULL)
        break;
      else if (tempptr == NULL) {    /* No more "\n" */
        tempptr = tempptr1;
        tempptr[0] = '\0';
      }
      else if (tempptr1 == NULL) {    /* No more '\n' */
        tempptr[0] = '\0';
        tempptr++;
      }
      else {    /* Prompt contains both "\n" and '\n' */
        if (strlen(tempptr)-2 < strlen(tempptr1)-1) {
          tempptr = tempptr1;
          tempptr[0] = '\0';
        }
        else {
          tempptr[0] = '\0';
          tempptr++;
        }
      }

      waddstr(win, word);
      word = tempptr + 1;
      wmove(win, ++cur_y, x);
    }
    waddstr(win, word);
  }
  else if (strlen(tempstr) <= width-x*2) {    /* If prompt is short */
    wmove(win, y, (width - strlen(tempstr)) / 2);
    waddstr(win, tempstr);
  }
  else {
    cur_x = x;
    cur_y = y;
    /* Print prompt word by word, wrap around if necessary */
    while ((word = strtok(first ? tempstr : NULL, " ")) != NULL) {
      if (first)    /* First iteration */
        first = 0;
      if (cur_x+strlen(word) > width) {    /* wrap around to next line */
        cur_y++;
        cur_x = x;
      }
      wmove(win, cur_y, cur_x);
      waddstr(win, word);
      getyx(win, cur_y, cur_x);
      cur_x++;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void print_button ( WINDOW win,
char *  label,
int  y,
int  x,
int  selected 
)

Definition at line 530 of file dialog.c.

{
  int i, temp;

  wmove(win, y, x);
  wattrset(win, selected ? button_active_attr : button_inactive_attr);
  waddstr(win, "<");
  temp = strspn(label, " ");
  label += temp;
  wattrset(win, selected ? button_label_active_attr : button_label_inactive_attr);
  for (i = 0; i < temp; i++)
    waddch(win, ' ');
  wattrset(win, selected ? button_key_active_attr : button_key_inactive_attr);
  waddch(win, label[0]);
  wattrset(win, selected ? button_label_active_attr : button_label_inactive_attr);
  waddstr(win, label+1);
  wattrset(win, selected ? button_active_attr : button_inactive_attr);
  waddstr(win, ">");
  wmove(win, y, x+temp+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Usage ( char *  name)

Definition at line 340 of file dialog.c.

{
  fprintf(stderr, "\
\ndialog version 0.3, by Savio Lam (lam836@cs.cuhk.hk).\
\n  patched to version %s by Stuart Herbert (S.Herbert@shef.ac.uk)\
\n\
\n* Display dialog boxes from shell scripts *\
\n\
\nUsage: %s --clear\
\n       %s --create-rc <file>\
\n       %s [--title <title>] [--separate-output] [--backtitle <backtitle>] [--clear] <Box options>\
\n\
\nBox options:\
\n\
\n  --yesno     <text> <height> <width>\
\n  --msgbox    <text> <height> <width>\
\n  --infobox   <text> <height> <width>\
\n  --inputbox  <text> <height> <width> [<init>]\
\n  --textbox   <file> <height> <width>\
\n  --menu      <text> <height> <width> <menu height> <tag1> <item1>...\
\n  --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
\n  --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
\n  --guage     <text> <height> <width> <percent>\n", VERSION, name, name, name);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* backtitle = NULL [static]

Definition at line 95 of file dialog.c.

Definition at line 96 of file dialog.c.