home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume39 / cwish / part01 / header.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  6.6 KB  |  248 lines

  1. /*---------------------------------------------------------------------------*
  2.  *
  3.  *                  wish - windowing user friendly shell
  4.  *                  ------------------------------------
  5.  *
  6.  *               Copyright (c) 1988-1993 Hellmuth Michaelis
  7.  *
  8.  *                  Eggerstedtstr. 28
  9.  *                  22765 Hamburg
  10.  *                  Germany
  11.  *
  12.  *                  Tel:    +49 / 40 / 384298    (private)
  13.  *                  Tel:    +49 / 40 / 55903-170 (at work)
  14.  *                  e-mail: hm@hcshh.hcs.de
  15.  *
  16.  *                          --------oOo--------
  17.  *
  18.  *   This program is free software; you can redistribute it and/or modify
  19.  *   it under the terms of the GNU General Public License as published by
  20.  *   the Free Software Foundation; either version 2 of the License, or
  21.  *   (at your option) any later version.
  22.  *
  23.  *   This program is distributed in the hope that it will be useful,
  24.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26.  *   GNU General Public License for more details.
  27.  *
  28.  *   You should have received a copy of the GNU General Public License
  29.  *   along with this program; if not, write to the Free Software
  30.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  *
  32.  *---------------------------------------------------------------------------*
  33.  *
  34.  *    Last Edit-Date: [Mon Aug 30 19:50:08 1993]
  35.  *
  36.  *    -hm    converting to curses and multiwindows
  37.  *    -hm    separation line in attribs window
  38.  *    -hm    vt220 support
  39.  *    -hm    show time in header
  40.  *    -hm    hpterm / zero pointers in hpux 9.0
  41.  *
  42.  *----------------------------------------------------------------------------*/
  43.  
  44. #include "wish.h"
  45.  
  46. /*---------------------------------------------------------------------------*
  47.  *    print a horizontal separation line based on delimiter-character
  48.  *---------------------------------------------------------------------------*/
  49. void sepaline(WINDOW *window)     
  50. {
  51.     int i = COLS;
  52.     unsigned char delim;
  53.     
  54.     if(window == cmnd_w)
  55.         wmove(window, 2, 0);
  56.     else if(window == attr_w)
  57.         wmove(window, 0, 0);
  58.     else
  59.         return;
  60.  
  61.     if(opt_delimiter)
  62.     {
  63.         delim = opt_delimiter;        
  64.     }
  65.     else if(enter_alt_charset_mode && exit_alt_charset_mode &&
  66.         *enter_alt_charset_mode && *exit_alt_charset_mode)
  67.     {
  68.         wattron(window, A_ALTCHARSET);
  69.         switch(termtype)
  70.         {
  71.             case TERM_HP:    /* HEWLETT-PACKARD Terminals (2392,700/9x etc) */
  72.                 delim = ';';
  73.                 break;
  74.     
  75.             case TERM_VT2:    /* DEC VT220 / 320 */
  76.             case TERM_VT3:
  77.             case TERM_PCVT:
  78.                 delim = 'q';
  79.                 break;
  80.     
  81.             case TERM_HPX:    /* X11 HEWLETT-PACKARD */
  82.                 delim = '-';
  83.                 break;
  84.     
  85.             default:    /* everything else */
  86.                 delim = DEFDELIMCH;
  87.                 break;
  88.         }
  89.     }
  90.     else
  91.     {
  92.         delim = DEFDELIMCH;
  93.     }
  94.         
  95.     while(i--)
  96.         waddch(window, delim);
  97.  
  98.     if(enter_alt_charset_mode && exit_alt_charset_mode && !opt_delimiter &&
  99.        *enter_alt_charset_mode && *exit_alt_charset_mode)
  100.     {
  101.         wattroff(window, A_ALTCHARSET);
  102.     }
  103. }    
  104.  
  105. /*---------------------------------------------------------------------------*
  106.  *    print error string in header-line
  107.  *---------------------------------------------------------------------------*/
  108. void error(char *str)
  109. {
  110.     extern int errno;
  111.     extern char *sys_errlist[];
  112.     extern int sys_nerr;
  113.  
  114.     int i;
  115.  
  116.     if(str == NULL)
  117.     {
  118.         if(errno && (errno <= sys_nerr))
  119.             strcpy(errorline, sys_errlist[errno]);
  120.         else
  121.             strcpy(errorline, "Unknown Error, call your guru ...");
  122.     }
  123.     strcpy(errorline, str);        
  124.  
  125.     i = strlen(errorline);
  126.     while(i++ < COLS)
  127.         strcat(errorline," ");
  128.  
  129.     wmove(cmnd_w, C_HEAD, 0);
  130.     wattron(cmnd_w, A_REVERSE);
  131.     waddstr(cmnd_w, errorline);
  132.     wattroff(cmnd_w, A_REVERSE);
  133.     wmove(cmnd_w, C_LINE, curcol());
  134.     suspend_time();
  135.     errorflag = 1;
  136. }
  137.  
  138. /*---------------------------------------------------------------------------*
  139.  *    clear error string and rewrite "normal" header
  140.  *---------------------------------------------------------------------------*/
  141. void clrerror(void)
  142. {
  143.     if(errorflag)                /* error-string in header ? */
  144.     {
  145.         resume_time();
  146.         errorflag = 0;            /* reset error-flag */        
  147.         wmove(cmnd_w, C_HEAD, 0);    /* headerline pos */
  148.         wclrtoeol(cmnd_w);        /* clear old */
  149.         header();            /* rewrite header */
  150.         wmove(cmnd_w, C_LINE, curcol());
  151.     }
  152. }    
  153.  
  154. /*---------------------------------------------------------------------------*
  155.  *    fatal, irrecoverable error
  156.  *---------------------------------------------------------------------------*/
  157. void fatal(char *str)
  158. {
  159.     free_list();        /* free memory */
  160.     fini_flabels();        /* fk-labels to normal */
  161.     endwin();        /* exit curses */
  162.     fprintf(stderr,"\n\n\t *** Wish Fatal Error: ***\n\t *** [%s] ***\n\n",str);
  163.     exit(1);
  164. }
  165.  
  166. /*---------------------------------------------------------------------------*
  167.  *    print headerline centered in display
  168.  *---------------------------------------------------------------------------*/
  169. void header(void)
  170. {
  171.     int p,q;
  172.  
  173.     wmove(cmnd_w, C_HEAD, 0);
  174.  
  175.     if(errorflag)
  176.     {
  177.         wattron(cmnd_w, A_REVERSE);
  178.         waddstr(cmnd_w, errorline);
  179.         wattroff(cmnd_w, A_REVERSE);
  180.     }
  181.     else
  182.     {
  183.         wattron(cmnd_w, A_REVERSE);
  184.         if((COLS+1) > 80)
  185.         {
  186.             p = (COLS+1) - 80;
  187.             p /= 2;
  188.             q = p;
  189.             while(q--)
  190.                 waddch(cmnd_w, SPACE);
  191.             waddstr(cmnd_w, headerline);
  192.             q = p;
  193.             while(q--)
  194.             waddch(cmnd_w, SPACE);
  195.         }
  196.         else
  197.         {
  198.             waddstr(cmnd_w, headerline);
  199.         }
  200.         wattroff(cmnd_w, A_REVERSE);
  201.     }
  202.     sepaline(cmnd_w);
  203.     wmove(cmnd_w, C_LINE, curcol());
  204. }
  205.  
  206. /*---------------------------------------------------------------------------*
  207.  *    display the attribute window, init if required
  208.  *---------------------------------------------------------------------------*/
  209. void attribs(int flag)
  210. {
  211.     if(!opt_attrib)
  212.         return;
  213.         
  214.     if(flag)    /* rewrite static data ?? */
  215.     {
  216.         sepaline(attr_w);
  217.  
  218.         wmove(attr_w, 1, PS_SIZE);
  219.         wattron(attr_w, A_REVERSE);
  220.         waddstr(attr_w, ST_SIZE);
  221.         wattroff(attr_w, A_REVERSE);
  222.  
  223.         wmove(attr_w, 1, PS_USER);
  224.         wattron(attr_w, A_REVERSE);
  225.         waddstr(attr_w, ST_USER);
  226.         wattroff(attr_w, A_REVERSE);
  227.         
  228.         wmove(attr_w, 1, PS_GRUP);
  229.         wattron(attr_w, A_REVERSE);
  230.         waddstr(attr_w, ST_GRUP);
  231.         wattroff(attr_w, A_REVERSE);
  232.  
  233.         wmove(attr_w, 1, PS_DATE);
  234.         wattron(attr_w, A_REVERSE);
  235.         waddstr(attr_w, ST_DATE);
  236.         wattroff(attr_w, A_REVERSE);
  237.     }
  238.     mvwaddstr(attr_w, 1, PP_PERM, cur_file->oprm);              /* permissions */
  239.     if(cur_file->oislnk)                          /* a link ?? */
  240.         mvwaddch(attr_w, 1, PP_PERM, 'l');              /*     yes ! */
  241.     mvwprintw(attr_w, 1, PP_SIZE, "%-9d",cur_file->osiz);          /* filesize */
  242.     mvwaddstr(attr_w, 1, PP_USER, user_from_uid(cur_file->ousr, 8));  /* user */
  243.     mvwaddstr(attr_w, 1, PP_GRUP, group_from_gid(cur_file->ogrp, 8)); /* group */
  244.     mvwaddstr(attr_w, 1, PP_DATE, cur_file->odat);                    /* date */
  245. }
  246.  
  247. /*---------------------------------- EOF -------------------------------------*/
  248.