2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * COMPONENT_NAME: austext
26 * FUNCTIONS: DtSearchAddMessage
27 * DtSearchFreeMessages
34 * (C) COPYRIGHT International Business Machines Corp. 1995
36 * Licensed Materials - Property of IBM
37 * US Government Users Restricted Rights - Use, duplication or
38 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
40 /********************** MSGS.C *****************************
41 * $XConsortium: msgs.c /main/4 1996/05/07 13:40:27 drk $
43 * Handles access to global ausapi_msglist for DtSearch.
46 * Revision 2.2 1995/10/26 14:35:04 miker
49 * Revision 2.1 1995/09/22 21:19:23 miker
50 * Freeze DtSearch 0.1, AusText 2.1.8
53 #define PROGNAME "MSGS"
55 /****************************************/
57 /* DtSearchHasMessages */
59 /****************************************/
60 int DtSearchHasMessages (void)
61 { return (ausapi_msglist != NULL); }
64 /****************************************/
66 /* DtSearchFreeMessages */
68 /****************************************/
69 void DtSearchFreeMessages (void)
70 { free_llist (&ausapi_msglist); }
73 /****************************************/
75 /* DtSearchAddMessage */
77 /****************************************/
78 /* Mallocs space for new message and appends copy of passed msg
79 * to end of global msglist. This function allocates memory
80 * for the messages--THE CALLER MUST FREE THE MESSAGES,
81 * preferably using DtSearchFreeMessages() (free_llist()).
82 * DtSearchAddMessage() was formerly called append_msglist() in msgutil.c.
84 void DtSearchAddMessage (char *msg)
88 new = austext_malloc (strlen(msg) + sizeof(LLIST) + 2,
91 new->data = new + 1; /* hop over exactly 1 LLIST structure */
92 strcpy (new->data, msg);
93 for ( pp = &ausapi_msglist; *pp != NULL; pp = &((*pp)->link) ) ;
96 } /* DtSearchAddMessage() */
99 /****************************************/
101 /* DtSearchGetMessages */
103 /****************************************/
105 * DtSearchGetMessages was formerly flatmessages().
106 * Copies all msgs in ausapi_msglist into single, flat text buffer.
108 char *DtSearchGetMessages (void)
113 static char *flatbuf = NULL;
114 static size_t flatbufsz = 0L;
116 /* Since function is often used as an arg in printf,
117 * be sure to return something safe when there are no msgs.
119 if (ausapi_msglist == NULL)
122 /* First Pass: Get the total length.
123 * including room for inserted \n's.
125 for (llptr = ausapi_msglist; llptr != NULL; llptr = llptr->link)
126 totlen += strlen(llptr->data) + 2;
127 if (totlen > flatbufsz) {
130 flatbuf = austext_malloc (totlen + 4, PROGNAME"73", NULL);
134 /* Second Pass: Copy the messages into the flat buffer.
135 * Make sure there are no less than 2 \n's at end of each msg--
136 * one to terminate msg (it may already be in the original
137 * msg string) and an added one to separate from the next msg.
140 for (llptr = ausapi_msglist; llptr != NULL; llptr = llptr->link) {
141 src = (char *) llptr->data;
145 if (*(--src) != '\n')
149 /* Overlay the last two \n so the whole string won't end.
150 * This prevents ugly spacing problems when function
151 * is used directly in information dialog boxes. It also
152 * means regular writes to stdout etc will usually have to
153 * insert their own final \n.
157 } /* DtSearchGetMessages() */
159 /********************** MSGS.C *****************************/