home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume3 / pcmail / part05 / deskutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  4.8 KB  |  198 lines

  1. /*++
  2. /* NAME
  3. /*    deskutil 3
  4. /* SUMMARY
  5. /*    utility functions
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    mailsh
  10. /* SYNOPSIS
  11. /*    #include "mailsh.h"
  12. /*
  13. /*    void patience()
  14. /*
  15. /*    int when()
  16. /*
  17. /*    int delete()
  18. /*
  19. /*    int unspool()
  20. /*
  21. /*    int print()
  22. /*
  23. /*    int save()
  24. /*
  25. /*    char *tstamp(ltime)
  26. /*    long *ltime()
  27. /* DESCRIPTION
  28. /*    tstamp() converts absolute time to a string. If called with
  29. /*    recent time argument (less than 100 days ago) the string will
  30. /*    be of the form "Sun Apr 17 12:50", otherwise "Sun Apr 17  1988".
  31. /*
  32. /*      delete() gives the user another chance before a message is deleted.
  33. /*
  34. /*      unspool() actually deletes a message. As a side effect it destroys
  35. /*      the current mail box display so that the next display will
  36. /*    reflect the actual status of the spool directory.
  37. /*    The affected message and meta file names are taken from the
  38. /*    global "message" and "commant" string variables.
  39. /*
  40. /*    print() copies a pager file to the printer.
  41. /*
  42. /*    save() asks where the pager file should be saved.
  43. /*
  44. /*    when() should be called after the user has entered a mail destination
  45. /*    address. It informs the user that messages are not sent right away, 
  46. /*    but after selection of the Network option in the main menu.
  47. /*
  48. /*    patience() prints a 'one moment please' message in the middle
  49. /*    screen window. As a side effect, the current pager file is set
  50. /*    to none.
  51. /* FILES
  52. /*      mail header files in the spool directory
  53. /* SEE ALSO
  54. /*      pager(3), pager(5), kbdinp(3)
  55. /* AUTHOR(S)
  56. /*      W.Z. Venema
  57. /*      Eindhoven University of Technology
  58. /*      Department of Mathematics and Computer Science
  59. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  60. /* CREATION DATE
  61. /*    Tue May 12 15:35:20 GMT+1:00 1987
  62. /* LAST MODIFICATION
  63. /*    Mon Apr  4 23:38:26 MET 1988
  64. /* VERSION/RELEASE
  65. /*    1.3
  66. /*--*/
  67.  
  68. #include <errno.h>
  69.  
  70. #include "defs.h"
  71. #include "pager.h"
  72. #include "mailsh.h"
  73. #include "screen.h"
  74. #include "status.h"
  75.  
  76. hidden int save_desk();
  77.  
  78. /* patience - say this will take some time */
  79.  
  80. public void patience()
  81. {
  82.     static char *m_wait[] = {
  83.     "",
  84.     "One moment please...",
  85.     0,
  86.     };
  87.  
  88.     register File *pp = open_pager();        /* create pager file */
  89.  
  90.     mesg_pager(pp,m_wait);            /* write pager file */
  91.     ds_pager();                    /* show om middle window */
  92.     close_pager(pp);                /* forget pager file */
  93. }
  94.  
  95. /* delete - user wants to delete a message; ask for confirmation */
  96.  
  97. public int delete()
  98. {
  99.     static Screen screen[] = {
  100.     ESCCR,    "Enter",    unspool,int_error,
  101.     0,    0,        0,
  102.     "Press ESC to cancel. Confirm with ENTER",
  103.     };
  104.  
  105.     return(kbdinp(screen)|S_REDRAW);
  106. }
  107.  
  108. /* unspool - actually delete a message; force mail box display rebuild */
  109.  
  110. public int unspool()
  111. {
  112.     if (((chmod(message,0666) || unlink(message)) && errno != ENOENT)
  113.     || ((chmod(comment,0666) || unlink(comment)) && errno != ENOENT)) {
  114.     errdisp(E_UNLINK);            /* notify user of problem */
  115.     return(S_REDRAW);            /* say screen has changed */
  116.     } else {
  117.     junk_desk();                /* say mail box has changed */
  118.     return(S_BREAK);            /* no more work to do */
  119.     }
  120. }
  121.  
  122. /* print - print pager display on default printer */
  123.  
  124. public int print()
  125. {
  126.     return(pr_pager() ? (errdisp(E_PRINTERR),S_REDRAW) : 0);
  127. }
  128.  
  129. /* save - ask where pager display should be copied to */
  130.  
  131. public int save()
  132. {
  133.     static Screen screen[] = {
  134.     STRING,    0,              save_desk,int_error,
  135.     0,    0,              0,
  136.     "Press ESC to cancel. Save to file:",
  137.     };
  138.  
  139.     kbdinp(screen);            /* prompt for file name, then copy */
  140.     return(S_REDRAW);            /* force screen repaint */
  141. }
  142.  
  143. /* save_desk - copy pager file to ordinary file */
  144.  
  145. hidden int save_desk(to)
  146. char *to;
  147. {
  148.     if (cp_pager(to)) {            /* if file copy failed */
  149.     unlink(to);            /* remove that file */
  150.     errdisp(E_WRITERR);        /* notify the user */
  151.     return(S_BREAK|S_REDRAW);    /* redisplay, terminate caller */
  152.     } else {
  153.     junk_file();            /* say file display maybe outdated */
  154.     return(S_BREAK);        /* terminate caller */
  155.     }
  156. }
  157.  
  158. /* when - say when mail will actually be sent */
  159.  
  160. public int when()
  161. {
  162.     static char *msg[] = {
  163.     "",
  164.     "To send messages through the network, use the Network",
  165.     "option in the main menu.",
  166.     0,
  167.     };
  168.     File *pp = open_pager();            /* open new pager file */
  169.  
  170.     mesg_pager(pp,msg);                /* fill pager file */
  171.     ds_pager();                    /* display the file */
  172.     close_pager(pp);                /* forget pager file */
  173.     return(0);                    /* don't care value */
  174. }
  175.  
  176. /* tstamp - time format as produced by the ls(1) command */
  177.  
  178. public char *tstamp(ltime)
  179. long *ltime;
  180. {
  181.     static char buf[25];
  182.  
  183.     /*
  184.     * Output from asctime() is of the form
  185.     *    "Sun Apr 17 13:34:35 1988"
  186.     * Depending on how recent the time in question is, we
  187.     * supress the time or year field.
  188.     */
  189.  
  190.     (void) strcpy(buf,asctime(localtime(ltime)));
  191.     if (time((long *)0)-*ltime > 60L*60L*24L*100L) {
  192.     buf[24] = '\0';                /* remove the \n */
  193.     (void) strcpy(buf+11,buf+19);        /* old file, show year */
  194.     } else
  195.     buf[16] = '\0';                /* recent, show time */
  196.     return(buf);
  197. }
  198.