home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / mush5.7 / part06 / mush.h < prev   
Encoding:
C/C++ Source or Header  |  1987-09-17  |  17.5 KB  |  468 lines

  1. /* @(#)mush.h    (c) copyright 1986 (Dan Heller) */
  2.  
  3. #define VERSION "Mail User's Shell (Vers 5.7) Sun Sep  6 19:10:48 PDT 1987"
  4.  
  5. #include "config.h"
  6.  
  7. #ifdef CURSES
  8. #include <curses.h>
  9. #else CURSES
  10. #include <stdio.h>
  11. #endif /* CURSES */
  12.  
  13. #include <ctype.h>
  14. #include <errno.h>
  15. #include <setjmp.h>
  16. #include "strings.h"
  17.  
  18. #ifdef SUNTOOL
  19. #    include <suntool/tool_hs.h>
  20. #else  SUNTOOL
  21. #    include <sys/types.h>
  22. #    include <signal.h>
  23. #    ifndef SYSV
  24. #        include <sys/time.h>
  25. #     include <sys/ioctl.h>   /* for ltchars */
  26. #    else
  27. #        include <time.h>
  28. #        include <fcntl.h>
  29. #    endif /* SYSV */
  30. #endif /* SUNTOOL */
  31.  
  32. #include <sys/stat.h>
  33. #include <sys/file.h>
  34.  
  35. #ifdef SUNTOOL
  36. #    include <suntool/gfxsw.h>
  37. #    include <suntool/panel.h>
  38. #    include <suntool/ttysw.h>
  39. #    include <suntool/ttytlsw.h>
  40. #    include <suntool/menu.h>
  41. #    include <suntool/icon_load.h>
  42. #endif /* SUNTOOL */
  43.  
  44. /* if no maximum number of files can be found, we'll use getdtablesize() */
  45. #ifdef _NFILE
  46. #    define MAXFILES _NFILE
  47. #else
  48. #ifdef NOFILE
  49. #    define MAXFILES NOFILE
  50. #endif
  51. #endif
  52.  
  53. #ifndef CTRL
  54. #define CTRL(c)        ('c' & 037)
  55. #endif
  56.  
  57. #define ESC         '\033'
  58.  
  59. #define NO_STRING    ""
  60. #ifdef  NULL
  61. #undef  NULL
  62. #endif /*  NULL */
  63. #define NULL        (char *)0
  64. #define NULL_FILE    (FILE *)0
  65. #define DUBL_NULL    (char **)0
  66. #define TRPL_NULL    (char ***)0
  67. #ifdef putchar
  68. #undef putchar
  69. #endif /* putchar */
  70. #define putchar(c)    fputc(c, stdout)
  71. #define bell()         fputc('\007', stderr)
  72.  
  73. #define on_intr() \
  74.     turnoff(glob_flags, WAS_INTR), oldint = signal(SIGINT, interrupt), \
  75.     oldquit = signal(SIGQUIT, interrupt)
  76.  
  77. #define off_intr() \
  78.     turnoff(glob_flags, WAS_INTR), (void) signal(SIGINT, oldint), \
  79.     (void) signal(SIGQUIT, oldquit)
  80.  
  81. /* Don't flush input when setting echo or cbreak modes (allow typeahead) */
  82. #ifdef TIOCSETN
  83. #define stty(fd, sgttybuf)    (ioctl(fd, TIOCSETN, sgttybuf))
  84. #endif /* TIOCSETN */
  85.  
  86. #ifndef CURSES
  87. /* if curses is not defined, simulate the same tty based macros */
  88. struct sgttyb _tty;
  89.  
  90. #define crmode()   (_tty.sg_flags |= CBREAK,  stty(0, &_tty))
  91. #define nocrmode() (_tty.sg_flags &= ~CBREAK, stty(0, &_tty))
  92. #define echo()     (_tty.sg_flags |= ECHO,    stty(0, &_tty))
  93. #define noecho()   (_tty.sg_flags &= ~ECHO,   stty(0, &_tty))
  94. #define savetty()  (void) gtty(0, &_tty)
  95. #endif /* ~CURSES */
  96.  
  97. #define echo_on()    \
  98.     if (_tty.sg_flags && isoff(glob_flags, ECHO_FLAG)) echo(), nocrmode()
  99. #define echo_off()    \
  100.     if (_tty.sg_flags && isoff(glob_flags, ECHO_FLAG)) noecho(), crmode()
  101.  
  102. #define strdup(dst, src) (xfree (dst), dst = savestr(src))
  103. #define Debug        if (debug) printf
  104.  
  105. #ifdef SYSV
  106. #define L_SET    0
  107. #define F_OK    000
  108. #define R_OK    004
  109. #define W_OK    002
  110. #define E_OK    001
  111. #define u_long  ulong_t
  112. #define vfork   fork
  113. #define SIGCHLD SIGCLD
  114. #endif /*  SYSV */
  115.  
  116. #if !defined(SUNTOOL) && !defined(CURSES)
  117.  
  118. #define TRUE          1
  119. #define FALSE          0
  120. #define print          printf
  121. #define wprint          printf
  122. #define print_more      printf
  123.  
  124. #endif /* SUNTOOL && !CURSES */
  125.  
  126. #ifndef max
  127. #define max(a,b) (((a) > (b)) ? (a) : (b))
  128. #define min(a,b) (((a) < (b)) ? (a) : (b))
  129. #endif /*  max */
  130.  
  131. #if defined(CURSES) && !defined(SUNTOOL)
  132. #define wprint printf
  133. #endif /* !SUNTOOL && CURSES */
  134.  
  135. #if defined(CURSES) || defined(SUNTOOL)
  136. #define print_more      turnon(glob_flags, CONT_PRNT), print
  137. void print();        /* printf to window or curses or tty accordingly */
  138. #endif /* CURSES || SUNTOOL */
  139.  
  140. #ifdef  SUNTOOL
  141.  
  142. #define NO_ITEM          (Panel_item)0
  143. #define NO_EVENT      (struct inputevent *)0
  144. #define TIME_OUT      60           /* sleep 60 secs between mailchecks */
  145. #define PIX_OR          PIX_SRC ^ PIX_DST
  146. #define ID           event.ie_code
  147. #define l_width(font)      fonts[font]->pf_defaultsize.x /* width of letter */
  148. #define l_height(font)      fonts[font]->pf_defaultsize.y /* height of letter */
  149. #define Clrtoeol(w,x,y,f) pw_text(w, x, y, PIX_SRC, fonts[f], blank)
  150.  
  151. #define highlight(win,x,y,font,s) \
  152.     pw_text(win,x,y, PIX_SRC, fonts[font],s), \
  153.     pw_text(win,x+1,y, \
  154.     (ison(glob_flags, REV_VIDEO))? PIX_NOT(PIX_SRC): PIX_SRC|PIX_DST, \
  155.     fonts[font],s)
  156.  
  157. /* Fonts */
  158. #define FONTDIR          "/usr/lib/fonts/fixedwidthfonts"
  159. #define DEFAULT          0
  160. #define SMALL           1
  161. #define LARGE           2
  162. #define MAX_FONTS      3
  163.  
  164. #endif /* SUNTOOL */
  165.  
  166. /* bits and pieces */
  167. #define turnon(flg,val)   ((flg) |= ((u_long)1 << ((u_long)(val)-1L)))
  168. #define turnoff(flg,val)  ((flg) &= ~((u_long)1 << ((u_long)(val)-1L)))
  169. #define ison(flg,val)     ((u_long)(flg) & ((u_long)1 << ((u_long)(val)-1L)))
  170. #define isoff(flg,val)    (!ison((flg), (val)))
  171. #define set_isread(n)      \
  172.     if (ison(msg[n].m_flags, UNREAD)) \
  173.         turnon(glob_flags, DO_UPDATE), turnoff(msg[n].m_flags, UNREAD)
  174.  
  175. /* msg lists represented by bits */
  176. #define clear_msg_list(list)      (void) bzero(list, (msg_cnt+7)/8)
  177. #define msg_bit(list, n)    ((list[(n) / 8] >> ((n) % 8)) & 1)
  178. #define set_msg_bit(list, n)    (list[(n) / 8] |= (1 << ((n) % 8)))
  179. #define unset_msg_bit(list, n)  (list[(n) / 8] &= ~(1 << ((n) % 8)))
  180. #define bput(S1, S2, Len, op)                   \
  181.         {                         \
  182.             register char *s1 = S1, *s2 = S2;         \
  183.             register int len = Len;             \
  184.             while(len--)                 \
  185.             *s2++ op *s1++;             \
  186.         }
  187. #define bitput(m1,m2,len,op)    bput(m1, m2, (((len)+7)/8), op)
  188.  
  189. /* convenience and/or readability */
  190. #define when          break;case
  191. #define otherwise      break;default
  192. #define lower(c)      (isupper(c)? tolower(c): c)
  193. #define Lower(c)      (c = lower(c))
  194. #define upper(c)      (islower(c)? toupper(c): c)
  195. #define Upper(c)      (c = upper(c))
  196. #define skipspaces(n)     for(p += (n); *p == ' ' || *p == '\t'; ++p)
  197. #define skipdigits(n)     for(p += (n); isdigit(*p); ++p)
  198.  
  199. #define NO_FLG        0
  200.  
  201. /* various flags */
  202. long   glob_flags;    /* global boolean flags thruout the whole program */
  203. #define DO_UPDATE   1    /* check for changes to avoid unnecessary copyback */
  204. #define REV_VIDEO   2    /* reverse video for curses or toolmode */
  205. #define CONT_PRNT   3    /* continue to print (maybe a printf) without a '\n' */
  206. #define DO_SHELL    4    /* run a shell even if no mail? (true if tool) */
  207. #define DO_PIPE     5    /* true if commands are piping to another command */
  208. #define IS_PIPE     6    /* true if commands' "input" is piped from another */
  209. #define IGN_SIGS    7    /* true if catch() should not longjump */
  210. #define IGN_BANG    8    /* ignore ! as a history reference (see source()) */
  211. #define ECHO_FLAG   9    /* if true, echo|cbreak is ON, don't echo typing (-e) */
  212. #define IS_GETTING 10    /* true if we're getting input for a letter */
  213. #define PRE_CURSES 11    /* true if curses will be run, but hasn't started yet */
  214. #define READ_ONLY  12    /* -r passed to folder() (or main) setting read only */
  215. #define REDIRECT   13    /* true if stdin is being redirected */
  216. #define WAS_INTR   14    /* catch interrupts, set this flag (signals.c) */
  217. #define WARNING    15   /* if set, various warning messages may be printed */
  218. #define NEW_MAIL   17   /* new mail has arrived; user is busy or in icon mode */
  219.  
  220. #define VERBOSE        1       /* verbose flag for sendmail */
  221. #define INCLUDE        2       /* include msg in response */
  222. #define INCLUDE_H    3    /* include msg with header */
  223. #define EDIT        4    /* enter editor by defualt on mailing */
  224. #define SIGN        5    /* auto-include ~/.signature in mail */
  225. #define DO_FORTUNE    6    /* add a fortune at end of msgs */
  226.  
  227. /* msg flags */
  228. #define NO_HEADER    7    /* don't print header of message (top, write) */
  229. #define DELETE        8
  230. #define OLD            9
  231. #define UNREAD        10
  232. #define UPDATE_STATUS    11    /* change status of msg when copyback */
  233. #define NO_PAGE        12    /* don't page this message */
  234. #define INDENT        13    /* indent included msg with string */
  235. #define NO_IGNORE    14    /* don't ignore headers */
  236. #define PRESERVE    15      /* preserve in mailbox unless deleted */
  237. #define TOP        15    /* just print the top of the message */
  238. #define FORWARD        16    /* Forward messages into the message buffer */
  239.  
  240. #define    MAXMSGS_BITS    MAXMSGS/sizeof(char)    /* number of bits for bitmap */
  241.  
  242. struct msg {
  243.     u_long m_flags;
  244.     long   m_offset;               /* offset in tempfile of msg */
  245.     long   m_size;                 /* number of bytes in msg */
  246.     int    m_lines;                /* number of lines in msg */
  247. } msg[MAXMSGS];
  248.  
  249. struct options {
  250.     char *option;
  251.     char *value;
  252.     struct options *next;
  253. } *set_options, *aliases, *ignore_hdr, *functions, *fkeys, *own_hdrs;
  254. #ifdef CURSES
  255. struct options *bindings;
  256. #endif /* CURSES */
  257.  
  258. struct cmd {
  259.     char *command;
  260.     int (*func)();
  261. };
  262. extern struct cmd ucb_cmds[];
  263. extern struct cmd cmds[], hidden_cmds[];
  264. #ifdef SUNTOOL
  265. extern struct cmd fkey_cmds[];
  266. #endif /* SUNTOOL */
  267.  
  268. FILE
  269.     *tmpf,        /* temporary holding place for all mail */
  270.     *open_file(),    /* open a file or program for write/append */
  271.     *popen();        /* this should be in stdio.h */
  272.  
  273. extern char
  274.     *sys_errlist[],    /* system's list of global error messages */
  275. #ifdef SUNTOOL
  276.     *font_files[],     /* the names of the files fonts are kept in */
  277.     *alt_fonts[],     /* fonts to use if first ones don't work */
  278. #endif /* SUNTOOL */
  279.     **environ;        /* user's environment variables */
  280.  
  281. extern int errno;    /* global system error number */
  282. jmp_buf jmpbuf;        /* longjmp to jmpbuf on sigs (not in tool) */
  283.  
  284. char
  285.     debug,        /* debug causes various print statements in code */
  286.     tempfile[40],    /* path to filename of temporary file */
  287.     msg_list[MAXMSGS_BITS],    /* MAXMSGS bits of boolean storage */
  288.     *cmd_help,        /* filename of location for "command -?" commands. */
  289.     *login,        /* login name of user */
  290.     *mailfile,        /* path to filename of current mailfile */
  291.     *ourname[MAX_HOST_NAMES],    /* the name and aliases of the current host */
  292.     *prompt,        /* the prompt string -- may have %d */
  293.     *escape,        /* the escape character when without editor */
  294.     *editor,         /* string describing editor to use (default vi) */
  295.     *hdrs_only,        /* true if -H flag was given --set to args */
  296.     *hdr_format,    /* set to the header format string; referenced a lot */
  297.     *visual,         /* string describing visual editor to use */
  298.     *pager,         /* string describing pager to use (default more) */
  299.     *argv_to_string(),    /* convert a vector of strings into one string */
  300.     **make_command(),    /* build a command vector (argv) */
  301.     **mk_argv(),    /* given a string, make a vector */
  302.     *itoa(),        /* return a string representation of a number */
  303.     *lcase_strcpy(),    /* just like strcpy, but convert all chars to lower */
  304.     *variable_stuff(),    /* return information about variables */
  305.     *no_newln(),    /* remove newline and extra whitespace - return end */
  306.     *savestr(),        /* strcpy arg into malloc-ed memory; return address */
  307.     *date_to_string(),    /* returns a string described by parse_date() */
  308.     *msg_date(),    /* return a string of the date of a message */
  309.     *parse_date(),    /* parse an ascii date, and return message-id str */
  310.     *Time(),        /* returns string expression of time (takes args) */
  311.     *do_range(),    /* parse a string converting to a "range" of numbers */
  312.     *getpath(),        /* static char returning path (expanding ~, +, %, #) */
  313.     *compose_hdr(),    /* returns a formatted line describing passed msg # */
  314.     *my_atoi(),     /* do an atoi, but return the last char parsed */
  315.     *do_set(),        /* set/unset an option, alias, ignored-hdr */
  316.     *reply_to(),    /* who do we reply to when responding */
  317.     *cc_to(),         /* when responding, return str which is the cc-list */
  318.     *subject_to(),      /* when responding, return str which is the subject */
  319.     *header_field(),    /* the line in msg described by arg (message header) */
  320.     *alias_to_address(),/* convert a name[list] to "real" names */
  321.     *set_header(),     /* [interactive] proc to set/display to/subject/cc */
  322.     *getenv(), *prog_name;
  323.  
  324. int
  325.     last_msg_cnt,    /* when checking for new mail, save the last msg_cnt */
  326.     msg_cnt,        /* total number of messages */
  327.     crt,        /* min number of lines msg contains to invoke pager */
  328.     current_msg,    /* the current message we're dealing with */
  329.     exec_pid,        /* pid of a command that has been "exec"ed */
  330.     hist_no,        /* command's history number */
  331.     iscurses;        /* if we're running curses */
  332.     istool,        /* argv[0] == "xxxxtool", ranges from 0 to 2 */
  333.     n_array[128],    /* array of message numbers in the header window */
  334.     screen,        /* number of headers window can handle */
  335.  
  336.     quit(), cleanup(), catch(), do_alias(), respond(), cd(), sh(), stop(),
  337.     folder(), save_msg(), delete(), do_mail(), lpr(), alts(), set(), do_hdrs(),
  338.     rm_edfile(), pick(), save_opts(), preserve(), sort(), readmsg(),
  339.     do_pick(), print_help(), folders(), question_mark(), do_from(), my_stty(),
  340.     do_version(), disp_hist(), source(), do_echo(), sigchldcatcher(), ls(),
  341.     nopenfiles(), Setenv(), Unsetenv(), Printenv(), bus_n_seg(), msg_flags(),
  342.     toggle_debug(), stop_start(), interrupt();
  343.  
  344. long
  345.     still_more,        /* there is still more message to display */
  346.     spool_size,        /* size of sppol mail regardless of current folder */
  347.     last_size,        /* the lastsize of the mailfile since last check */
  348.     time();        /* satisfy lint */
  349.  
  350. void
  351.     xfree(), free_vec(), error(), getmail(), mail_status(),
  352.     file_to_fp(), init(), display_msg(), c_more();
  353.     /* printf(), fclose(), fflush(), fputs(), fputc() */
  354. #ifndef CURSES
  355. struct sgttyb _tty;            /* tty characteristics */
  356. #endif /* CURSES */
  357. #ifdef TIOCGLTC
  358. struct ltchars ltchars;            /* tty character settings */
  359. #endif /* TIOCGLTC */
  360.  
  361. #ifdef CURSES
  362.  
  363. #define STANDOUT(y,x,s) standout(), mvaddstr(y,x,s), standend()
  364. #define redraw()    clearok(curscr, TRUE), wrefresh(curscr)
  365.  
  366. int
  367.     curses_init(),    /* interpret commands via the curses interface */
  368.     bind_it();        /* bind chars or strings to functions */
  369. #endif /* CURSES */
  370.  
  371. #ifdef SUNTOOL
  372. void
  373.     lock_cursors(), unlock_cursors(), scroll_win(),
  374.     set_fkeys(), set_key(), toggle_opt(), help_opt();
  375.  
  376. char
  377.     *rite(),        /* rite a char to msg_win: return string if c == '\n' */
  378.     *find_key(),    /* pass x,y coords to find which function key assoc. */
  379.     *key_set_to(),    /* pass fkey string, return string describing func */
  380.     *panel_get(),          /* returns what has been typed in a panel item */
  381.     *tool_help,        /* help for tool-related things (sometimes, overlap) */
  382.     blank[128];        /* use to clear to end of line */
  383.  
  384. int
  385.     time_out,        /* time out interval to wait for new mail */
  386.     rootfd,        /* the root window's fd */
  387.     parentfd,        /* the parent's window fd */
  388.     getting_opts,    /* true if getting/setting opts from msg_win */
  389.     curfont,        /* the current font to use for mail message window */
  390.     total_fonts,    /* total number of fonts available */
  391.     get_hdr_field,    /* bitmask of header fields to be gotten */
  392.  
  393.     msg_io(), msgwin_handlesigwinch(), hdr_io(), hdrwin_handlesigwinch(),
  394.     sigchldcatcher(), sigtermcatcher(), sigwinchcatcher(), do_sort(),
  395.     do_compose(), do_edit(), read_mail(), delete_mail(), respond_mail(),
  396.     do_hdr(), display_hdrs(), print_sigwinch(), p_set_opts(),
  397.     tool_mgmt(), do_help(), text_done(), msg_num_done(), do_lpr(),
  398.     toolquit(), change_font(), do_clear(), do_update(),
  399.     file_dir(), do_file_dir(), do_send(), abort_mail(), check_new_mail(),
  400.     fkey_cmd(), fkey_settings();
  401.  
  402. struct tchars  tchars;            /* more tty character settings */
  403.  
  404. struct tool *tool;      /* main tool structure */
  405. struct toolsw
  406.     *panel_sw,        /* main panel subwindow */
  407.     *hdr_sw,         /* subwindow for message headers */
  408.     *hdr_panel_sw,    /* panel for headers */
  409.     *tty_sw,         /* subwindow which forks a shell (usually editor) */
  410.     *print_sw,         /* subwindow for print statements */
  411.     *msg_sw;         /* main subwindow to display messages and more */
  412.  
  413. struct pixwin
  414.     *msg_win,        /* main pixwin for message display and more */
  415.     *hdr_win,        /* pixwin for message headers */
  416.     *print_win;        /* pixwin for printing messages ( print() ) */
  417.  
  418. struct pr_pos txt;               /* current position of text written */
  419. struct rect msg_rect, hdr_rect;         /* sizes of the main and hdr rects */
  420. struct pixfont *fonts[MAX_FONTS];    /* array of fonts */
  421.  
  422. Panel
  423.     main_panel,        /* the main panel dealing with generic items */
  424.     hdr_panel;        /* panel which contains message header specific items */
  425.  
  426. Panel_item
  427.     abort_item,        /* abort mail in progress */
  428.     alias_item,        /* set/view/change current mail aliases */
  429.     cd_item,        /* changes file_item to cd (for cd-ing) */
  430.     comp_item,        /* compose a letter */
  431.     delete_item,    /* delete/undelete messages */
  432.     edit_item,        /* edit a message */
  433.     font_item,        /* choose which font to use */
  434.     folder_item,    /* change folders */
  435.     file_item,         /* text item for files or directories (forlder/cd) */
  436.     hdr_display,    /* format message headers are displayed */
  437.     help_item,        /* choose this to get various help */
  438.     ignore_item,    /* set/view/change message headers to be ignored */
  439.     input_item,        /* text item to get values for set/unsetting values */
  440.     msg_num_item,    /* text item to explicity state which message to read */
  441.     next_scr,        /* display the next screenful of message headers */
  442.     option_item,    /* set/view/unset mail options */
  443.     prev_scr,        /* display the previous screen of messages */
  444.     print_item,        /* send current message to the printer */
  445.     quit_item,        /* quit tool/close to icon */
  446.     read_item,        /* read the current message */
  447.     respond_item,    /* respond to messages */
  448.     save_item,        /* saves messages; uses text item input_item */
  449.     send_item,        /* when composing letter, this will send it off */
  450.     sort_item,        /* sort routine... */
  451.     sub_hdr_item[6],    /* display items that just sit there and give help */
  452.     update_item;    /* commit changes to folder */
  453.  
  454. struct itimerval mail_timer;    /* frequency to check for new mail */
  455.  
  456.             /* mouse symbols and data */
  457. /* left, middle and right mouse pixrects */
  458. struct cursor
  459.     l_cursor, m_cursor, r_cursor, coffee, read_cursor, write_cursor,
  460.     main_cursor, checkmark;
  461.  
  462. struct pixrect *msg_pix; /* pixrect holding text of a message */
  463. extern struct pixrect mouse_left, mouse_middle, mouse_right;
  464. extern struct pixrect dn_arrow, up_arrow, cycle, shade_50;
  465.  
  466. extern struct icon mail_icon;
  467. #endif /* SUNTOOL */
  468.