home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2650 < prev    next >
Internet Message Format  |  1991-02-01  |  14KB

  1. From: pc@ukc.ac.uk (R.P.A.Collinson)
  2. Newsgroups: comp.windows.x,comp.mail.mh,alt.sources
  3. Subject: Xmh patches for repl/forw style annotation (unofficial)
  4. Message-ID: <2485@ukc>
  5. Date: 2 Feb 91 01:03:55 GMT
  6.  
  7. These diffs allow you to see when you have replied or forwarded mail
  8. by making a note at the top of the source message(s). Regular mh does this
  9. and I have long wanted xmh to do this too. The diffs have been sent
  10. into MIT - who told me that they will use them but will not distribute
  11. them at this time.
  12.  
  13. I am unsure what news group(s) is/are appropriate so I am guessing -
  14. please forgive me if you consider this is unwarranted intrusion into
  15. your conversation.
  16.  
  17. The diffs permit the `standard' xmh release with X11R4 to annotate
  18. messages that have been replied to or forwarded. I have tested this ONLY
  19. with mh6.7 on a Sparc 1+ running SunOs 4.1 and OpenWindows2.
  20.  
  21. Annotation is controlled by resources - see the manual page.
  22.  
  23. Annotation will not SHOW if a currently displayed message is annotated.
  24.  
  25. Most of the work is done in a new file `anno.c', this also contains
  26. the theory of behaviour. Most of the other changes just insert code
  27. to call the appropriate code.
  28.  
  29. PS. If anyone has fixed the problem where xmh current message is not
  30. that the same as that shown by mhpath cur - then please let me know.
  31.  
  32. ------ patch away from here ------
  33. *** /dev/null    Wed Jan  2 22:32:51 1991
  34. --- anno.c    Sun Dec 23 21:14:56 1990
  35. ***************
  36. *** 0 ****
  37. --- 1,271 ----
  38. + /*
  39. +  *    anno.c
  40. +  *        - routines concerned with annotation
  41. +  *    File added by Peter Collinson, Hillside Systems
  42. +  *    pc@hillside.co.uk
  43. +  */
  44. + /*
  45. +  *    Background
  46. +  *    mh6.7 uses various environment variables to permit message
  47. +  *    annotation.
  48. +  *
  49. +  *    a) mhfolder
  50. +  *        contains the name of the folder to be annotated
  51. +  *    b) mhmessages
  52. +  *        space separated list of messages to annotate
  53. +  *    c) mhannotate
  54. +  *        text to use for annotation
  55. +  *    d) mhinplace
  56. +  *        1 to annotate inplace
  57. +  *        0 not to
  58. +  *
  59. +  *    Theory
  60. +  *    Add a character string to a Scrn containing the message list
  61. +  *    for annotation.
  62. +  *    When send is called push the various objects into the
  63. +  *    environment
  64. +  */
  65. + #include "xmh.h"
  66. + #include "tocintrnl.h"
  67. + static    int MheLookup();
  68. + static Scrn AnnoSearch();
  69. + static char *MakeEnv();
  70. + /*
  71. +  *    Given a message - create an annotation list and
  72. +  *    return it
  73. +  */
  74. + char *
  75. + AnnoMsgCreate(msg)
  76. +     Msg    msg;
  77. + {
  78. +     MsgListRec    ml;
  79. +     char    *AnnoCreate();
  80. +     ml.nummsgs = 1;
  81. +     ml.msglist = &msg;
  82. +     return (AnnoCreate(&ml));
  83. + }
  84. +     
  85. + /*
  86. +  *    given an mlist - create an annotation list
  87. +  *    and return it - the first element in the list is the
  88. +  *    name of the folder
  89. +  *    
  90. +  */
  91. + char *
  92. + AnnoCreate(mlist)
  93. +     MsgList mlist;
  94. + {
  95. +     char    *anno;
  96. +     char    *folder;
  97. +     int    bytes;
  98. +     register int d;
  99. +     register int i;
  100. +     char    *src;
  101. +     char    numbuf[16];
  102. +     if (mlist->nummsgs == 0)
  103. +         return (NULL);
  104. +     folder = mlist->msglist[0]->toc->foldername;
  105. +     anno = (char *)XtMalloc(512);
  106. +     bytes = 512;
  107. +     for (d = 0, src = app_resources.mail_path; anno[d++] = *src++;);
  108. +     anno[d-1] = '/';
  109. +     for (src = folder; anno[d++] = *src++;);
  110. +     d--;
  111. +     
  112. +     for (i = 0; i < mlist->nummsgs; i++)
  113. +     {
  114. +         (void) sprintf(numbuf, "%d", mlist->msglist[i]->msgid);
  115. +         
  116. +         if (d+16 > bytes)
  117. +         {    bytes += 512;
  118. +             anno = (char *)XtRealloc(anno, bytes);
  119. +         }
  120. +         /* add a space */
  121. +         anno[d++] = ' ';
  122. +         for (src = numbuf; anno[d++] = *src++;);
  123. +         d--;
  124. +     }
  125. +     anno[d] = '\0';
  126. +     return (anno);
  127. + }
  128. + /*
  129. +  *    We will need to add and delete four things from
  130. +  *    the environment. This could be done after the fork()
  131. +  *    but this means that we have to change the environment
  132. +  *    to be sure of not affecting any other programs
  133. +  *
  134. +  *    So the idea here is to copy the environment into our vector
  135. +  *    deleting the four things that we are interested in
  136. +  *    we then put OUR things in the first four string positions
  137. +  */
  138. + static    char    **our_env;    /* this points at our environment */
  139. + extern    char    **environ;    /* what the world sees */
  140. + typedef struct addenv
  141. + {    char    *add;
  142. +     int    len;
  143. + } Addenv;
  144. + static Addenv adde[] = 
  145. + {
  146. + {    "mhfolder=",    9    },
  147. + {    "mhmessages=",    11    },
  148. + {    "mhannotate=",    11    },
  149. + {    "mhinplace=",    10    },
  150. + {    NULL,    0    }
  151. + };
  152. + #define    MHE_FOLDER    0
  153. + #define    MHE_MESSAGES    1
  154. + #define MHE_ANNOTATE    2
  155. + #define    MHE_INPLACE    3
  156. + AnnoInitEnv()
  157. + {            
  158. +     register int    count;    /* number of things in the environment */
  159. +     register char    **pt;
  160. +     register char    **dst;
  161. +     char        inp[16];
  162. +     
  163. +     if (our_env)
  164. +         return;
  165. +     for (count = 0, pt = environ; *pt++; count++);
  166. +     our_env = (char **)XtMalloc((count+5)*sizeof (char **));
  167. +     our_env[0] = our_env[1] = our_env[2] = NULL;
  168. +     /* copy the environment into `our' environment */
  169. +     /* start at position 4 */
  170. +     dst = &our_env[4];
  171. +     for (pt = environ; *pt; pt++)
  172. +     {
  173. +         if (MheLookup(*pt))
  174. +             continue;
  175. +         *dst++ = *pt;
  176. +     }
  177. +     *dst = NULL;
  178. +     /*
  179. +      *    set up the inplace value
  180. +      */
  181. +     (void) sprintf(inp, "%s%d", adde[MHE_INPLACE].add, app_resources.annotate_in_place);
  182. +     our_env[MHE_INPLACE] = XtNewString(inp);
  183. + }
  184. + /*
  185. +  *    Look in the list of things we are dealing with
  186. +  *    to find a match in the environment
  187. +  */
  188. + static int
  189. + MheLookup(env)
  190. +     char    *env;
  191. + {
  192. +     register Addenv *ae;
  193. +     for (ae = adde; ae->add; ae++)
  194. +         if (strncmp(env, ae->add, ae->len) == 0)
  195. +             return(1);
  196. +     return 0;
  197. + }
  198. +     
  199. + /*
  200. +  *    Reset the environment to the standard
  201. +  */
  202. + AnnoEnvReset()
  203. + {
  204. +     environ = &our_env[4];
  205. + }
  206. +     
  207. + /*
  208. +  *    Set the environment to new values
  209. +  */
  210. + AnnoEnvSet(msg)
  211. +     Msg    msg;
  212. + {
  213. +     Scrn    scrn;
  214. +     char    *folder;
  215. +     char    *annotate;
  216. +     char    *s;
  217. +     char    *d;
  218. +     register i;
  219. +     Scrn    AnnoSearch();
  220. +     char    buf[512];
  221. +     
  222. +     if ((scrn = AnnoSearch(msg)) == NULL)
  223. +         return;
  224. +     switch (scrn->anno_type)
  225. +     {
  226. +     case ANrepl:
  227. +         annotate = "Replied";
  228. +         break;
  229. +     case ANforw:
  230. +         annotate = "Forwarded";
  231. +         break;
  232. +     default:        /* shouldn't happen */
  233. +         return;
  234. +     }
  235. +     for (i = 0; i < MHE_INPLACE; i++)
  236. +         if (our_env[i])
  237. +         {    XtFree(our_env[i]);
  238. +             our_env[i] = NULL;
  239. +         }
  240. +     /*
  241. +      *    Munge the annotation list
  242. +      *    we see it as
  243. +      *    folder-name number number
  244. +      */
  245. +     for (s = scrn->anno_list, d = buf; *s != ' '; *d++ = *s++);
  246. +     *d = '\0';
  247. +     s++;
  248. +     our_env[MHE_FOLDER] = MakeEnv(&adde[MHE_FOLDER], buf);
  249. +     our_env[MHE_MESSAGES] = MakeEnv(&adde[MHE_MESSAGES], s);
  250. +     our_env[MHE_ANNOTATE] = MakeEnv(&adde[MHE_ANNOTATE], annotate);
  251. +     environ = our_env;
  252. + }
  253. + static Scrn
  254. + AnnoSearch(msg)
  255. +     Msg    msg;
  256. + {
  257. +     register i;
  258. +     AnnoKind ak;
  259. +     
  260. +     if (msg->num_scrns == 0)
  261. +         return (NULL);
  262. +     for (i = 0; i < msg->num_scrns; i++)
  263. +     {
  264. +         if ((ak = msg->scrn[i]->anno_type) == ANrepl)
  265. +             return(msg->scrn[i]);
  266. +         else
  267. +         if (ak == ANforw)
  268. +             return(msg->scrn[i]);
  269. +     }
  270. +     return (NULL);
  271. + }
  272. +     
  273. + static char *
  274. + MakeEnv(ad, value)
  275. +     register Addenv    *ad;
  276. +     char    *value;
  277. + {
  278. +     char    buf[512];
  279. +     (void) sprintf(buf, "%s%s", ad->add, value);
  280. +     return (XtNewString(buf));
  281. + }
  282. *** Imakefile~    Wed Jan  2 22:36:59 1991
  283. --- Imakefile    Sun Dec 23 21:15:33 1990
  284. ***************
  285. *** 8,17 ****
  286.   
  287.              SRCS = bbox.c command.c compfuncs.c folder.c icon.c init.c \
  288.                     main.c menu.c mlist.c msg.c pick.c popup.c screen.c \
  289. !                   toc.c tocfuncs.c tocutil.c tsource.c util.c viewfuncs.c
  290.              OBJS = bbox.o command.o compfuncs.o folder.o icon.o init.o \
  291.                     main.o menu.o mlist.o msg.o pick.o popup.o screen.o \
  292. !                   toc.o tocfuncs.o tocutil.o tsource.o util.o viewfuncs.o
  293.   
  294.   
  295.   ComplexProgramTarget(xmh)
  296. --- 8,17 ----
  297.   
  298.              SRCS = bbox.c command.c compfuncs.c folder.c icon.c init.c \
  299.                     main.c menu.c mlist.c msg.c pick.c popup.c screen.c \
  300. !                   toc.c tocfuncs.c tocutil.c tsource.c util.c viewfuncs.c anno.c
  301.              OBJS = bbox.o command.o compfuncs.o folder.o icon.o init.o \
  302.                     main.o menu.o mlist.o msg.o pick.o popup.o screen.o \
  303. !                   toc.o tocfuncs.o tocutil.o tsource.o util.o viewfuncs.o anno.o
  304.   
  305.   
  306.   ComplexProgramTarget(xmh)
  307. *** compfuncs.c~    Wed Jan  2 22:39:07 1991
  308. --- compfuncs.c    Sun Dec 23 21:15:33 1990
  309. ***************
  310. *** 117,122 ****
  311. --- 117,124 ----
  312.   {
  313.       Scrn scrn;
  314.       Msg msg;
  315. +     char *AnnoCreate();
  316. +     
  317.       scrn = NewCompScrn();
  318.       msg = TocMakeNewMsg(DraftsFolder);
  319.       MsgLoadForward(scrn, msg, mlist);
  320. ***************
  321. *** 123,126 ****
  322. --- 125,133 ----
  323.       MsgSetTemporary(msg);
  324.       MsgSetScrnForComp(msg, scrn);
  325.       MapScrn(scrn);
  326. +     if (app_resources.annotate_forw) {
  327. +        scrn->anno_type = ANforw;
  328. +     scrn->anno_list = AnnoCreate(mlist);
  329. +     }
  330.   }
  331. *** globals.h~    Wed Jan  2 22:40:33 1991
  332. --- globals.h    Sun Dec 23 21:15:31 1990
  333. ***************
  334. *** 76,81 ****
  335. --- 76,84 ----
  336.       int        command_button_count;    /* number of buttons in command box */
  337.       int        app_defaults_version;    /* for sanity check */
  338.       char     *banner;        /* defaults to xmh version string */
  339. +     Boolean    annotate_repl;        /* true if we are to annotate reply sources */
  340. +     Boolean    annotate_forw;        /* true if we are to annotate forw sources */
  341. +     int        annotate_in_place;    /* 0 if don't annotate inplace, 1 otherwise */
  342.   } app_resources;
  343.   
  344.   ext char    *draftFile;    /* Filename of draft. */
  345. *** init.c~    Wed Jan  2 22:40:54 1991
  346. --- init.c    Sun Dec 23 21:15:31 1990
  347. ***************
  348. *** 124,129 ****
  349. --- 124,135 ----
  350.        offset(app_defaults_version), XtRImmediate, (XtPointer)0},
  351.       {"banner", "Banner", XtRString, sizeof(char *),
  352.        offset(banner), XtRString, "xmh    MIT X Consortium    R4"},
  353. +     {"annotateRepl", "AnnotateRepl", XtRBoolean, sizeof(Boolean),
  354. +      offset(annotate_repl), XtRImmediate, (XtPointer)False},
  355. +     {"annotateForw", "AnnotateForw", XtRBoolean, sizeof(Boolean),
  356. +      offset(annotate_forw), XtRImmediate, (XtPointer)False},
  357. +     {"annotateInPlace", "AnnotateInPlace", XtRInt, sizeof(int),
  358. +      offset(annotate_in_place), XtRImmediate, (XtPointer)1},
  359.   };
  360.   
  361.   #undef offset
  362. ***************
  363. *** 396,401 ****
  364. --- 402,413 ----
  365.       InitPick();
  366.       IconInit();
  367.       BBoxInit();
  368. +     /*
  369. +      *    Initialise annotations if required
  370. +      */
  371. +     if (app_resources.annotate_repl || app_resources.annotate_forw)
  372. +     AnnoInitEnv();
  373.   
  374.       XtAppAddActions( XtWidgetToApplicationContext(toplevel),
  375.               actions, XtNumber(actions));
  376. *** msg.c~    Wed Jan  2 22:41:05 1991
  377. --- msg.c    Sun Dec 23 21:15:32 1990
  378. ***************
  379. *** 731,736 ****
  380. --- 731,737 ----
  381.       }
  382.       (void) myfclose(from);
  383.       (void) myfclose(to);
  384. +     AnnoEnvSet(msg);
  385.       argv = MakeArgv(3);
  386.       argv[0] = "send";
  387.       argv[1] = "-push";
  388. ***************
  389. *** 737,742 ****
  390. --- 738,744 ----
  391.       argv[2] = str;
  392.       DoCommand(argv, (char *) NULL, (char *) NULL);
  393.       XtFree((char *) argv);
  394. +     AnnoEnvReset();
  395.   }
  396.   
  397.   
  398. *** screen.c~    Wed Jan  2 22:41:14 1991
  399. --- screen.c    Sun Dec 23 21:15:31 1990
  400. ***************
  401. *** 391,396 ****
  402. --- 391,398 ----
  403.       Scrn scrn;
  404.       scrn = CreateNewScrn(STcomp);
  405.       scrn->assocmsg = (Msg)NULL;
  406. +     scrn->anno_type = ANno;
  407. +     scrn->anno_list = NULL;
  408.       return scrn;
  409.   }
  410.   
  411. ***************
  412. *** 412,417 ****
  413. --- 414,423 ----
  414.       TocSetScrn((Toc) NULL, scrn);
  415.       MsgSetScrnForce((Msg) NULL, scrn);
  416.       lastInput.win = -1;
  417. +     if (scrn->anno_list) {
  418. +         XtFree(scrn->anno_list);
  419. +         scrn->anno_list = NULL;
  420. +     }
  421.       }
  422.   }
  423.   
  424. *** tocfuncs.c~    Wed Jan  2 22:41:25 1991
  425. --- tocfuncs.c    Sun Dec 23 21:15:32 1990
  426. ***************
  427. *** 651,656 ****
  428. --- 651,657 ----
  429.       Scrn    nscrn;
  430.       MsgList    mlist;
  431.       Msg        msg;
  432. +     char    *AnnoMsgCreate();
  433.   
  434.       if (toc == NULL) return;
  435.       mlist = CurMsgListOrCurMsg(toc);
  436. ***************
  437. *** 657,662 ****
  438. --- 658,667 ----
  439.       if (mlist->nummsgs) {
  440.       nscrn = NewCompScrn();
  441.       ScreenSetAssocMsg(nscrn, mlist->msglist[0]);
  442. +     if (app_resources.annotate_repl)
  443. +     {    nscrn->anno_type = ANrepl;
  444. +         nscrn->anno_list = AnnoMsgCreate(mlist->msglist[0]);
  445. +     }
  446.       msg = TocMakeNewMsg(DraftsFolder);
  447.       MsgSetTemporary(msg);
  448.       MsgLoadReply(msg, mlist->msglist[0]);
  449. *** viewfuncs.c~    Wed Jan  2 22:41:38 1991
  450. --- viewfuncs.c    Sun Dec 23 21:15:32 1990
  451. ***************
  452. *** 76,85 ****
  453. --- 76,90 ----
  454.       Scrn    scrn = (Scrn) client_data;
  455.       Msg        msg;
  456.       Scrn    nscrn;
  457. +     char    *AnnoMsgCreate();
  458.       
  459.       if (scrn->msg == NULL) return;
  460.       nscrn = NewCompScrn();
  461.       ScreenSetAssocMsg(nscrn, scrn->msg);
  462. +     if (app_resources.annotate_repl)
  463. +     {    nscrn->anno_type = ANrepl;
  464. +     nscrn->anno_list = AnnoMsgCreate(scrn->msg);
  465. +     }
  466.       msg = TocMakeNewMsg(DraftsFolder);
  467.       MsgSetTemporary(msg);
  468.       MsgLoadReply(msg, scrn->msg);
  469. *** xmh.h~    Wed Jan  2 22:41:57 1991
  470. --- xmh.h    Sun Dec 23 21:15:31 1990
  471. ***************
  472. *** 90,95 ****
  473. --- 90,101 ----
  474.       STpick
  475.   } ScrnKind;
  476.   
  477. + typedef enum {
  478. +     ANno,
  479. +     ANrepl,
  480. +     ANforw
  481. + } AnnoKind;
  482.   typedef struct _StackRec {
  483.       char        *data;
  484.       struct _StackRec    *next;
  485. ***************
  486. *** 119,124 ****
  487. --- 125,132 ----
  488.      Msg        assocmsg;    /* Associated message for reply, etc. */
  489.      Window    wait_window;    /* InputOnly window with busy cursor */
  490.      Stack    folder_stack;    /* Stack of folder names */
  491. +    AnnoKind    anno_type;    /* type of annotation */
  492. +    char    *    anno_list;    /* list of messages to annotate */
  493.   } ScrnRec, *Scrn;
  494.   
  495.   
  496. *** xmh.man~    Wed Jan  2 22:42:07 1991
  497. --- xmh.man    Mon Dec 24 12:02:12 1990
  498. ***************
  499. *** 921,926 ****
  500. --- 921,946 ----
  501.   
  502.   The following resources are defined:
  503.   .TP 8
  504. + .B AnnotateRepl
  505. + Permits annotation of messages that are being replied to.
  506. + This uses the standard 
  507. + .I mh
  508. + mechanism in 
  509. + .IR send .
  510. + Default is false.
  511. + .TP 8
  512. + .B AnnotateForw
  513. + Permits annotation of messages that are being forwarded.
  514. + This uses the standard
  515. + .I mh
  516. + mechanism in
  517. + .IR send .
  518. + Default is false.
  519. + .TP
  520. + .B AnnotateInPlace
  521. + When set to non-zero causes annotation to be done in place to preserve
  522. + links to the annotated message.
  523. + .TP 8
  524.   .B Banner
  525.   A short string that is the default label of the folder, Table of Contents,
  526.   and view.  The default is "xmh    MIT X Consortium    R4".
  527. ***************
  528. *** 1241,1243 ****
  529. --- 1261,1265 ----
  530.   Terry Weissman, Digital Western Research Laboratory
  531.   .br
  532.   modified by Donna Converse, MIT X Consortium
  533. + .br
  534. + Annotation code by Peter Collinson, Hillside Systems
  535.