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: clear_hitwords
35 * (C) COPYRIGHT International Business Machines Corp. 1991,1995
37 * Licensed Materials - Property of IBM
38 * US Government Users Restricted Rights - Use, duplication or
39 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
41 /*********************** DTSRUTIL.C ***********************
42 * $XConsortium: dtsrutil.c /main/5 1996/08/12 13:18:30 cde-ibm $
44 * Set of utility functions for opera User Interfaces (UIs),
45 * although may also be used by Opera Engine (OE) itself.
46 * Function free_dittolist() replaced by macro call to free_llist().
47 * Ausapi wrapped aa_free_dittolist around free_llist().
48 * DtSearch renamed aa_free_dittolist to DtSearchFreeResults().
51 * Revision 2.4 1996/03/13 22:54:21 miker
52 * Changed char to UCHAR several places.
54 * Revision 2.3 1996/03/05 16:05:45 miker
55 * Added print_stems().
57 * Revision 2.2 1995/10/25 18:36:09 miker
58 * Renamed from uiutil.c. Added prolog.
61 * Revision 2.1 1995/09/22 22:19:47 miker
62 * Freeze DtSearch 0.1, AusText 2.1.8
64 * Revision 1.13 1995/09/05 19:17:28 miker
65 * Minor name and function changes for DtSearch. Made usrblk global.
72 /********#define DEBUG_CLEARREC*********/
73 /**********#define DEBUG_FAX***********/
74 #define PROGNAME "DTSRUTIL"
77 /************************************************/
81 /************************************************/
82 /* For debugging. Prints passed stems array to aa_stderr. */
83 void print_stems (int stemcount, void *stems, char *prefix)
89 fprintf (aa_stderr, "%s Stems array is empty.\n", prefix);
93 fprintf (aa_stderr, "%s stemct = %d:\n", prefix, stemcount);
94 for (i=0; i<stemcount; i++) {
95 cptr = (UCHAR *) stems + (i * DtSrMAXWIDTH_HWORD);
97 fputc ('\n', aa_stderr);
98 fprintf (aa_stderr, " #%d:'%c%s'",
99 i, (*cptr < 32) ? '~' : *cptr, cptr + 1);
101 fputc ('\n', aa_stderr);
104 } /* print_stems() */
107 /************************************************/
109 /* print_dittolist */
111 /************************************************/
112 /* Only for debugging in oe. Dumps first 10 list nodes. */
113 void print_dittolist (DtSrResult * dittolist, char *prefix)
121 if (dittolist == NULL) {
122 fprintf (aa_stderr, "%s Dittolist is empty.\n", prefix);
125 fprintf (aa_stderr, "%s First %d hits on dittolist at %p:\n",
126 prefix, maxcount, dittolist);
127 for (dit = dittolist; dit != NULL && maxcount-- > 0; dit = dit->link) {
128 if (dit->objdate == 0)
129 strcpy (datebuf, "0");
131 strftime (datebuf, sizeof (datebuf), "%y/%m/%d",
132 objdate2tm (dit->objdate));
134 " dbn=%d dba=%d:%ld prox=%d sz=%ld date=%s key='%s'\n",
135 dit->dbn, dit->dba >> 24, (long)dit->dba & 0xffffffL,
136 dit->proximity, (long)dit->objsize,
137 datebuf, dit->reckey);
139 if (dit->abstractp[0] != 0)
140 fprintf (aa_stderr, " abstract='%.50s'\n", dit->abstractp);
143 } /* print_dittolist() */
145 /************************************************/
147 /* get_hitlist_text */
149 /************************************************/
150 /* Converts dittolist into a single block of clean ascii text
151 * for use as a hitlist, or for printing out to hardcopy.
152 * Wraps lines intelligently to ensure no line is greater than maxlen.
153 * If maxlen == 0, no wrapping is performed.
154 * Returns static pointer to dynamically allocated buffer--
155 * if permanent copy is desired, caller must copy text
156 * to his own buffer before next call.
158 char *get_hitlist_text (int maxlen)
160 static char *text = NULL;
162 char *src, *targ, *eol;
167 if (usrblk.dittocount <= 0L) {
168 sprintf (sprintbuf, catgets (dtsearch_catd, MS_misc, 96,
169 "%s Hitlist is empty."), PROGNAME"96");
170 DtSearchAddMessage (sprintbuf);
173 if (maxlen > 0 && maxlen < DtSrMAX_DB_KEYSIZE + 7) {
174 sprintf (sprintbuf, PROGNAME "97 maxlen = %d is too small.", maxlen);
175 DtSearchAddMessage (sprintbuf);
179 /* Allocate enough memory for each item in ditto list */
180 mallocsz = usrblk.dittocount *
181 (usrblk.abstrbufsz + DtSrMAX_DB_KEYSIZE + 80L);
184 text = austext_malloc (mallocsz, PROGNAME "103", NULL);
186 /* Loop thru ditto list, creating text out of hitlist */
188 for (dit = usrblk.dittolist; dit != NULL; dit = dit->link) {
190 sprintf (targ, "%5d %-*s %s\n%n",
198 else /* (maxlen > 0) */
200 * We may have more text than can fit on one line.
201 * Wrap lines to fit within maxlen.
205 sprintf (targ, "%5d %-*s %n",
211 src = dit->abstractp;
213 while (targ < eol && *src != 0)
222 } /* end else (maxlen > 0) */
223 } /* end loop on dittolist */
225 *targ = 0; /* ...I don't know about you, but I always forget
228 if (usrblk.debug & USRDBG_UTIL)
229 fprintf (aa_stderr, PROGNAME "160 "
230 "get_hitlist_text(): mallocsz=%ld textlen=%ld\n",
231 mallocsz, strlen (text));
233 } /* get_hitlist_text() */
236 /****************************************/
238 /* print_usrblk_record */
240 /****************************************/
241 /* dumps out usrblk 'record' fields for debugging */
242 void print_usrblk_record (char *prefix)
244 fprintf (aa_stderr, "%s usrblk_record(): dba=%ld:%ld objkey='%s'\n"
245 " notesp=%p clearlen=%d cleartxt='%.30s'\n"
246 " #hitw=%d hitw=%p abstr='%.24s'\n",
248 (long)usrblk.dba >> 24, (long)usrblk.dba & 0xffffffL,
249 usrblk.objrec.or_objkey,
251 (int)usrblk.clearlen,
252 NULLORSTR (usrblk.cleartext),
253 (int)usrblk.hitwcount,
255 NULLORSTR (usrblk.abstrbuf));
257 } /* print_usrblk_record() */
260 /****************************************/
262 /* clear_usrblk_record */
264 /****************************************/
265 /* Clears and initializes all USRBLK fields that
266 * represent an opera record from vista, specifically
267 * objrec, notes, textblobs, clearlen, and cleartext.
268 * This function MUST NOT ALTER dba, hitwords, and hitwcount,
269 * because many callers require these things to remain untouched.
270 * If usrblk.objrec.or_objkey[0] == '\0',
271 * UI must presume that all record fields are invalid
272 * including usrblk.objfzkey and usrblk.abstract.
274 void clear_usrblk_record (void)
277 if (usrblk.cleartext != NULL) {
278 free (usrblk.cleartext);
279 usrblk.cleartext = NULL;
281 free_llist (&usrblk.notes);
282 usrblk.objrec.or_objkey[0] = '\0';
283 if (usrblk.abstrbufsz > 0)
284 usrblk.abstrbuf[0] = 0;
285 if (usrblk.debug & USRDBG_RETRVL)
286 print_usrblk_record (PROGNAME "600 clear: ");
288 } /* clear_usrblk_record() */
291 /************************************************/
295 /************************************************/
296 /* clears hitwcount and array in usrblk */
297 void clear_hitwords (void)
299 usrblk.hitwcount = 0;
300 if (usrblk.hitwords != NULL) {
301 free (usrblk.hitwords);
302 usrblk.hitwords = NULL;
305 } /* clear_hitwords() */
308 /*********************** DTSRUTIL.C ***********************/