[9657] | 1 | /* $XConsortium: mlist.c,v 2.10 91/01/06 21:08:51 rws Exp $" */ |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * COPYRIGHT 1987 |
---|
| 5 | * DIGITAL EQUIPMENT CORPORATION |
---|
| 6 | * MAYNARD, MASSACHUSETTS |
---|
| 7 | * ALL RIGHTS RESERVED. |
---|
| 8 | * |
---|
| 9 | * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND |
---|
| 10 | * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. |
---|
| 11 | * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR |
---|
| 12 | * ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. |
---|
| 13 | * |
---|
| 14 | * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT |
---|
| 15 | * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN |
---|
| 16 | * ADDITION TO THAT SET FORTH ABOVE. |
---|
| 17 | * |
---|
| 18 | * |
---|
| 19 | * Permission to use, copy, modify, and distribute this software and its |
---|
| 20 | * documentation for any purpose and without fee is hereby granted, provided |
---|
| 21 | * that the above copyright notice appear in all copies and that both that |
---|
| 22 | * copyright notice and this permission notice appear in supporting |
---|
| 23 | * documentation, and that the name of Digital Equipment Corporation not be |
---|
| 24 | * used in advertising or publicity pertaining to distribution of the software |
---|
| 25 | * without specific, written prior permission. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | /* mlist.c -- functions to deal with message lists. */ |
---|
| 29 | |
---|
| 30 | #include "xmh.h" |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | /* Create a message list containing no messages. */ |
---|
| 34 | |
---|
| 35 | MsgList MakeNullMsgList() |
---|
| 36 | { |
---|
| 37 | MsgList mlist; |
---|
| 38 | mlist = XtNew(MsgListRec); |
---|
| 39 | mlist->nummsgs = 0; |
---|
| 40 | mlist->msglist = XtNew(Msg); |
---|
| 41 | mlist->msglist[0] = NULL; |
---|
| 42 | return mlist; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | /* Append a message to the given message list. */ |
---|
| 47 | |
---|
| 48 | void AppendMsgList(mlist, msg) |
---|
| 49 | MsgList mlist; |
---|
| 50 | Msg msg; |
---|
| 51 | { |
---|
| 52 | mlist->nummsgs++; |
---|
| 53 | mlist->msglist = |
---|
| 54 | (Msg *) XtRealloc((char *) mlist->msglist, |
---|
| 55 | (unsigned) (mlist->nummsgs + 1) * sizeof(Msg)); |
---|
| 56 | mlist->msglist[mlist->nummsgs - 1] = msg; |
---|
| 57 | mlist->msglist[mlist->nummsgs] = 0; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | /* Delete a message from a message list. */ |
---|
| 63 | |
---|
| 64 | void DeleteMsgFromMsgList(mlist, msg) |
---|
| 65 | MsgList mlist; |
---|
| 66 | Msg msg; |
---|
| 67 | { |
---|
| 68 | int i; |
---|
| 69 | for (i=0 ; i<mlist->nummsgs ; i++) { |
---|
| 70 | if (mlist->msglist[i] == msg) { |
---|
| 71 | mlist->nummsgs--; |
---|
| 72 | for (; i<mlist->nummsgs ; i++) |
---|
| 73 | mlist->msglist[i] = mlist->msglist[i+1]; |
---|
| 74 | return; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | /* Create a new messages list containing only the one given message. */ |
---|
| 82 | |
---|
| 83 | MsgList MakeSingleMsgList(msg) |
---|
| 84 | Msg msg; |
---|
| 85 | { |
---|
| 86 | MsgList result; |
---|
| 87 | result = MakeNullMsgList(); |
---|
| 88 | AppendMsgList(result, msg); |
---|
| 89 | return result; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /* We're done with this message list; free it's storage. */ |
---|
| 94 | |
---|
| 95 | void FreeMsgList(mlist) |
---|
| 96 | MsgList mlist; |
---|
| 97 | { |
---|
| 98 | XtFree((char *) mlist->msglist); |
---|
| 99 | XtFree((char *) mlist); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | /* Parse the given string into a message list. The string contains mh-style |
---|
| 105 | message numbers. This routine assumes those messages numbers refer to |
---|
| 106 | messages in the given toc. */ |
---|
| 107 | |
---|
| 108 | MsgList StringToMsgList(toc, str) |
---|
| 109 | Toc toc; |
---|
| 110 | char *str; |
---|
| 111 | { |
---|
| 112 | MsgList mlist; |
---|
| 113 | char *ptr; |
---|
| 114 | int first, second, i; |
---|
| 115 | Msg msg; |
---|
| 116 | mlist = MakeNullMsgList(); |
---|
| 117 | while (*str) { |
---|
| 118 | while (*str == ' ') |
---|
| 119 | str++; |
---|
| 120 | first = second = atoi(str); |
---|
| 121 | str++; |
---|
| 122 | for (ptr = str; *ptr >= '0' && *ptr <= '9'; ptr++) ; |
---|
| 123 | if (*ptr == '-') |
---|
| 124 | second = atoi(ptr + 1); |
---|
| 125 | if (first > 0) { |
---|
| 126 | for (i = first; i <= second; i++) { |
---|
| 127 | msg = TocMsgFromId(toc, i); |
---|
| 128 | if (msg) AppendMsgList(mlist, msg); |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | str = ptr; |
---|
| 132 | } |
---|
| 133 | return mlist; |
---|
| 134 | } |
---|