home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2765 / Diffs < prev   
Text File  |  1991-02-14  |  14KB  |  558 lines

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