12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: AccessSDL.c /main/13 1996/09/30 11:22:14 cde-hp $ */
- /************************************<+>*************************************
- ****************************************************************************
- **
- ** File: AccessSDL.c
- **
- ** Project: Run Time Project File Access
- **
- ** Description: This body of code handles the access routines for the
- ** SDL files.
- **
- **
- ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
- **
- ** (c) Copyright 1993, 1994 Hewlett-Packard Company
- ** (c) Copyright 1993, 1994 International Business Machines Corp.
- ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
- ** (c) Copyright 1993, 1994 Novell, Inc.
- **
- **
- ****************************************************************************
- ************************************<+>*************************************/
- /*
- * system includes
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <X11/Xlib.h>
- #include <X11/Xresource.h>
- /*
- * Canvas Engine includes
- */
- #include "CanvasP.h"
- #include "CanvasSegP.h"
- /*
- * private includes
- */
- #include "bufioI.h"
- #include "CleanUpI.h"
- #include "CvStringI.h"
- #include "FontAttrI.h"
- #include "Access.h"
- #include "AccessP.h"
- #include "AccessSDLP.h"
- #include "AccessSDLI.h"
- #include "FormatUtilI.h"
- #include "FormatSDLI.h"
- #include "StringFuncsI.h"
- #include "UtilSDLI.h"
- #ifdef NLS16
- #endif
- /******** Private Defines ********/
- /******** End Private Defines ********/
- /******** Private Function Declarations ********/
- static int ProcessEntry (
- _DtHelpVolume vol,
- _DtCvSegment *p_seg,
- char *parent_key);
- /******** End Private Function Declarations ********/
- /******** Private Variable Declarations ********/
- static const char *IsoString = "ISO-8859-1";
- static const CESDLVolume DefaultSdlVolume =
- {
- NULL, /* _DtCvSegment *sdl_info; */
- NULL, /* _DtCvSegment *toss; */
- NULL, /* _DtCvSegment *loids; */
- NULL, /* _DtCvSegment *index; */
- NULL, /* _DtCvSegment *title; */
- NULL, /* _DtCvSegment *snb; */
- 0, /* short minor_no; */
- False, /* short title_processed; */
- };
- /******** Private Macro Declarations ********/
- /******************************************************************************
- * Private Functions
- ******************************************************************************/
- /******************************************************************************
- * Function: void FreeIds (
- *
- * Parameters:
- *
- * Return Value:
- *
- * errno Values:
- *
- * Purpose:
- *
- ******************************************************************************/
- static void
- FreeIds (
- _DtCvSegment *loids)
- {
- _DtCvSegment *p_seg;
- if (NULL == loids)
- return;
- p_seg = _DtCvContainerListOfSeg(loids);
- while (NULL != p_seg)
- {
- if (NULL != _SdlSegToSdlIdInfoPtr(p_seg))
- {
- if (NULL != _SdlSegToSdlIdInfoRssi(p_seg))
- free(_SdlSegToSdlIdInfoRssi(p_seg));
- free(_SdlSegToSdlIdInfoPtr(p_seg));
- }
- p_seg = p_seg->next_seg;
- }
- }
- /******************************************************************************
- * Function: void FreeTossInfo (
- *
- * Parameters:
- *
- * Return Value:
- *
- * errno Values:
- *
- * Purpose:
- *
- ******************************************************************************/
- static void
- FreeTossInfo (
- _DtCvSegment *toss)
- {
- _DtCvSegment *p_seg;
- SDLTossInfo *info;
- if (NULL == toss)
- return;
- p_seg = _DtCvContainerListOfSeg(toss);
- while (NULL != p_seg)
- {
- info = (SDLTossInfo *) _SdlSegTossInfo(p_seg);
- /* free the ssi */
- if (NULL != _SdlTossInfoPtrSsi(info))
- free(_SdlTossInfoPtrSsi(info));
- /* free the colj,colw or the enter, exit data */
- if (NULL != _SdlTossInfoPtrStr1(info))
- free(_SdlTossInfoPtrStr1(info));
- if (NULL != _SdlTossInfoPtrStr2(info))
- free(_SdlTossInfoPtrStr2(info));
- /* free the font strings */
- if (NULL != _DtHelpFontHintsColor(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsColor(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsXlfd(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsXlfd(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsXlfdb(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsXlfdb(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsXlfdi(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsXlfdi(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsXlfdib(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsXlfdib(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsTypeNam(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsTypeNam(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsTypeNamb(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsTypeNamb(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsTypeNami(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsTypeNami(_SdlTossInfoPtrFontSpecs(info)));
- if (NULL != _DtHelpFontHintsTypeNamib(_SdlTossInfoPtrFontSpecs(info)))
- free(_DtHelpFontHintsTypeNamib(_SdlTossInfoPtrFontSpecs(info)));
- free(info);
- p_seg = p_seg->next_seg;
- }
- }
- /******************************************************************************
- * Function: void FreeEntryInfo (
- *
- * Parameters:
- *
- * Return Value:
- *
- * errno Values:
- *
- * Purpose:
- *
- ******************************************************************************/
- static void
- FreeEntryInfo (
- _DtCvSegment *index)
- {
- _DtCvSegment *p_seg;
- SDLEntryInfo *info;
- if (NULL == index)
- return;
- p_seg = _DtCvContainerListOfSeg(index);
- while (NULL != p_seg)
- {
- info = _SdlSegToSdlEntryInfo(p_seg);
- if (NULL != info)
- {
- if (NULL != info->main)
- free(info->main);
- if (NULL != info->locs)
- free(info->locs);
- if (NULL != info->syns)
- free(info->syns);
- if (NULL != info->sort)
- free(info->sort);
- }
- if (_DtCvIsSegContainer(p_seg))
- FreeEntryInfo(p_seg);
- free(info);
- p_seg = p_seg->next_seg;
- }
- }
- /******************************************************************************
- * Function: int ProcessSubEntries (
- *
- * Parameters:
- *
- * Return Value:
- *
- * errno Values:
- *
- * Purpose:
- *
- ******************************************************************************/
- static int
- ProcessSubEntries (
- _DtHelpVolume vol,
- _DtCvSegment *p_seg,
- char *parent_key)
- {
- while (p_seg != NULL)
- {
- /*
- * the only sub containers of an entry that should have an non-null
- * internal pointer should be a sub <entry>.
- */
- if (_DtCvIsSegContainer(p_seg) && NULL != _SdlSegEntryInfo(p_seg)
- && ProcessEntry(vol, _DtCvContainerListOfSeg(p_seg),
- parent_key) == -1)
- return -1;
- p_seg = p_seg->next_seg;
- }
- return 0;
- }
- /******************************************************************************
- * Function: int AsciiKeyword (
- *
- * Parameters:
- * p_list The segment list to process for strings.
- * parent_str The string to append information onto.
- * This may be NULL.
- * str_size The malloc'ed size of the parent string.
- * Includes room for the null byte. If zero
- * and parent_str is non-null, then memory
- * must be malloc'ed and parent_str copied
- * into it. Otherwise, goodStr can just
- * reuse parent_str.
- *
- * Return Value:
- *
- * errno Values:
- *
- * Purpose:
- *
- ******************************************************************************/
- static char *
- AsciiKeyword (
- _DtCvSegment *p_list,
- char *parent_str,
- int *str_size)
- {
- int len = 0;
- int newLen;
- char *goodStr;
- /*
- * if a starting string has been passed in, use it.
- */
- if (NULL != parent_str)
- {
- /*
- * get the actual byte count.
- */
- len = strlen(parent_str) + 1;
- /*
- * is the starting value zero? If so, we have to copy it.
- */
- if (0 == *str_size)
- {
- parent_str = strdup(parent_str);
- if (NULL == parent_str)
- return NULL;
- *str_size = len;
- }
- }
- /*
- * start with the parent_string
- */
- goodStr = parent_str;
- while (p_list != NULL)
- {
- if (_DtCvIsSegString(p_list))
- {
- /*
- * get the number of characters in the next string.
- */
- newLen = _DtCvStrLen(_DtCvStringOfStringSeg(p_list),
- _DtCvIsSegWideChar(p_list));
- /*
- * if this is wide char string, multiply the count by
- * MB_CUR_MAX to get the maximum number of bytes this
- * string would take.
- */
- if (_DtCvIsSegWideChar(p_list))
- newLen = newLen * MB_CUR_MAX;
- /*
- * now add it to our previous size.
- */
- len += newLen;
- /*
- * are we starting from scratch?
- */
- if (goodStr == NULL)
- {
- /*
- * include a byte for the end-of-string character.
- */
- len++;
- /*
- * malloc the memory
- */
- goodStr = (char *) malloc (len);
- }
- else if (*str_size < len) /* does this have to grow? */
- goodStr = (char *) realloc (goodStr, len);
- if (goodStr == NULL)
- return NULL;
- /*
- * remember the absolute size of the memory for the string
- */
- if (*str_size < len)
- *str_size = len;
- if (_DtCvIsSegWideChar(p_list))
- {
- /*
- * back up to the insertion point.
- */
- len -= newLen;
- /*
- * transfer
- */
- newLen = wcstombs(&goodStr[len - 1],
- (wchar_t *) _DtCvStringOfStringSeg(p_list),
- newLen + 1);
- if ((size_t) -1 == newLen)
- {
- free(goodStr);
- return NULL;
- }
- len += newLen;
- }
- else
- strcpy(&goodStr[len - newLen - 1],
- (char *) _DtCvStringOfStringSeg(p_list));
- }
- /*
- * the only containers in an <entry> that should have a non-null
- * internal pointer should be a sub <entry>. Therefore, if null,
- * process since it could be a <key>, <sphrase>, etc.
- */
- else if (_DtCvIsSegContainer(p_list) &&
- NULL == _SdlSegEntryInfo(p_list))
- {
- goodStr = AsciiKeyword(_DtCvContainerListOfSeg(p_list), goodStr,
- str_size);
- if (goodStr == NULL)
- return NULL;
- len = strlen(goodStr) + 1;
- }
- p_list = p_list->next_seg;
- }
- return goodStr;
- }
- /******************************************************************************
- * Function: int ProcessLocations (
- *
- * Parameters:
- *
- * Return Value:
- *
- * errno Values:
- *
- * Purpose:
- *
- ******************************************************************************/
- static int
- ProcessLocations (
- char *locs,
- char ***list)
- {
- char **myList = NULL;
- char *nextLoc;
- while (locs != NULL && *locs != '\0')
- {
- locs = _DtHelpGetNxtToken(locs, &nextLoc);
- if (nextLoc == NULL)
- return -1;
- if (*nextLoc != '\0')
- {
- myList = (char **) _DtHelpCeAddPtrToArray ((void **) myList,
- (void *) nextLoc);
- if (myList == NULL)
- return -1;
- }
- }
- *list = myList;
- return 0;
- }
- /******************************************************************************
- * Function: int ProcessEntry (_DtHelpVolume vol)
- *
- * Parameters: vol Specifies the volume whose keywords need to be
- * loaded from disk. Once loaded, they can be
- * accessed through the fields of the volume structure.
- *
- * Return Value: 0 if successful, -1 if a failure occurs
- *
- * errno Values: CEErrorMalloc
- * CEErrorIllegalDatabaseFile
- * Specifies that the keyword file is
- * invalid or corrupt.
- * CEErrorMissingKeywordsRes
- * Specifies that the keyword file does
- * not contain the 'Keywords/keywords'
- * resource or the resource is NULL
- *
- *
- * Purpose: Load the keywords associated with a volume.
- *
- ******************************************************************************/
- static int
- ProcessEntry (
- _DtHelpVolume vol,
- _DtCvSegment *p_seg,
- char *parent_key)
- {
- int strSize;
- char **topics;
- char *nextKey = NULL;
- /* Now parse the string into the appropriate arrays. The string has the
- following syntax:
- <!ELEMENT entry - - ((%simple; | #PCDATA)*, entry*) >
- <!ATTLIST entry id ID #IMPLIED
- main IDREFS #IMPLIED
- locs IDREFS #IMPLIED
- syns IDREFS #IMPLIED
- sort CDATA #IMPLIED >
- */
- #define MAIN_STRINGS (_SdlSegToSdlEntryInfo(p_seg))->main
- #define LOCS_STRINGS (_SdlSegToSdlEntryInfo(p_seg))->locs
- while (p_seg != NULL)
- {
- strSize = 0;
- nextKey = AsciiKeyword(_DtCvContainerListOfSeg(p_seg),
- parent_key, &strSize);
- if (nextKey == NULL)
- return -1;
- /* We have the next keyword. Hang onto it and add it to the list
- once we get the array of topics. We don't add it yet because if
- there are no topics we want to throw it away. (Silently ignoring
- keywords which specify no topics is an undocumented feature.) */
- /* Now get the list of topics. */
- topics = NULL;
- if (NULL != FrmtPrivInfoPtr(p_seg) && NULL != _SdlSegEntryInfo(p_seg)
- && (ProcessLocations(MAIN_STRINGS, &topics) == -1 ||
- ProcessLocations(LOCS_STRINGS, &topics) == -1))
- {
- free(nextKey);
- return -1;
- }
- if (topics != NULL)
- {
- vol->keywords = (char **) _DtHelpCeAddPtrToArray (
- (void **) vol->keywords,
- (void *) nextKey);
- vol->keywordTopics = (char ***) _DtHelpCeAddPtrToArray (
- (void **) vol->keywordTopics,
- (void *) topics);
- /*
- * If we just malloc'ed ourselves out of existence...
- * stop here.
- */
- if (vol->keywords == 0 || vol->keywordTopics == 0)
- {
- if (vol->keywords != NULL)
- {
- free(nextKey);
- _DtHelpCeFreeStringArray (vol->keywords);
- _DtHelpCeFreeStringArray (topics);
- vol->keywords = NULL;
- }
- if (vol->keywordTopics)
- {
- char ***topicList;
- for (topicList = vol->keywordTopics; topicList; topicList++)
- _DtHelpCeFreeStringArray (*topicList);
- free (vol->keywordTopics);
- vol->keywordTopics = NULL;
- }
- return -1;
- }
- }
- if (_DtCvContainerListOfSeg(p_seg) != NULL &&
- ProcessSubEntries(vol,_DtCvContainerListOfSeg(p_seg),nextKey) == -1)
- return -1;
- if (topics == NULL)
- free (nextKey);
- p_seg = p_seg->next_seg;
- }
- return (0);
- }
- /******************************************************************************
- * Function: int MapPath (_DtCvSegment *cur_id, int level, char ***ret_ids)
- *
- * Parameters:
- *
- * Return Value: 0 if successful, -1 if failure.
- *
- * Memory: The memory returned in ret_ids is owned by the caller.
- *
- * Purpose: To come up with a path from the top of the volume to the
- * target id.
- *
- ******************************************************************************/
- static int
- MapPath (
- _DtCvSegment **cur_id,
- _DtCvSegment *target_el,
- int stop_lev,
- int lev_cnt,
- int hidden_no,
- char ***ret_ids)
- {
- _DtCvSegment *mySeg = *cur_id;
- int count = -1;
- int myLev;
- SDLIdInfo *info;
- while (mySeg != NULL)
- {
- /*
- * Does this match the target id?
- * And, is the element a child of the current path?
- */
- info = _SdlSegToSdlIdInfoPtr(mySeg);
- myLev = _SdlIdInfoPtrRlevel(info);
- if (target_el == mySeg && (myLev == -1 || myLev > stop_lev))
- {
- /*
- * matched the target id.
- * allocate memory and return.
- */
- count = 0;
- if (_SdlIdInfoPtrType(info) == SdlIdVirpage)
- {
- count++;
- lev_cnt++;
- }
- *ret_ids = (char **) malloc (sizeof(char *) * (lev_cnt + 1));
- if ((*ret_ids) == NULL)
- return -1;
- (*ret_ids)[lev_cnt] = NULL;
- if (_SdlIdInfoPtrType(info) == SdlIdVirpage)
- (*ret_ids)[lev_cnt - 1] = strdup(_DtCvContainerIdOfSeg(mySeg));
- return count;
- }
- else if (myLev != -1 && myLev != hidden_no
- && _SdlIdInfoPtrType(info) == SdlIdVirpage)
- {
- char *myId = _DtCvContainerIdOfSeg(mySeg);
- /*
- * If we've hit a virpage that is a sibling or an aunt
- * set the search pointer to this segment (since this
- * is where we want to start searching again) and return
- * a negative on the successful search.
- */
- if (myLev <= stop_lev)
- {
- *cur_id = mySeg;
- return -1;
- }
- /*
- * this virpage is a child of mine, so look at it's children
- * for the target id.
- */
- mySeg = mySeg->next_seg;
- count = MapPath(&mySeg, target_el, myLev, lev_cnt + 1, hidden_no,
- ret_ids);
- /*
- * successful response on finding the target id in the virpage's
- * children. Duplicate the virpage's id string and return to
- * my parent.
- */
- if (count != -1)
- {
- (*ret_ids)[lev_cnt] = strdup(myId);
- count++;
- return count;
- }
- }
- else /* did not match the target id and is not a virpage
- * or is a hidden virpage */
- mySeg = mySeg->next_seg;
- }
- *cur_id = mySeg;
- return -1;
- }
- /******************************************************************************
- * Semi-Private Functions
- ******************************************************************************/
- /*******************************************************************************
- * Function: CESDLVolume *_DtHelpCeGetSdlVolumePtr (_DtHelpVolumeHdl vol);
- *
- * Parameters: vol Specifies the loaded volume.
- *
- * Return Value: 0 if successful, -1 if a failure occurs
- *
- * errno Values: None
- *
- * Purpose: When the volume is no longer needed, it should be unloaded
- * with this call. Unloading it frees the memory (which means
- * any handles on the volume become invalid.)
- *
- ******************************************************************************/
- CESDLVolume *
- _DtHelpCeGetSdlVolumePtr (
- _DtHelpVolumeHdl volume)
- {
- _DtHelpVolume vol = (_DtHelpVolume) volume;
- if (vol != NULL)
- return ((CESDLVolume *) vol->vols.sdl_vol);
- return NULL;
- }
- /******************************************************************************
- * Semi-Public Functions
- ******************************************************************************/
- /*******************************************************************************
- * Function: void _DtHelpCeInitSdlVolume (_DtHelpVolume vol);
- *
- * Parameters: vol Specifies the loaded volume.
- *
- * Return Value: 0 if successful, -1 if a failure occurs
- *
- * errno Values: None
- *
- * Purpose: When the volume is no longer needed, it should be unloaded
- * with this call. Unloading it frees the memory (which means
- * any handles on the volume become invalid.)
- *
- ******************************************************************************/
- void
- _DtHelpCeInitSdlVolume (
- _DtHelpVolumeHdl volume)
- {
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (sdlVol != NULL)
- *sdlVol = DefaultSdlVolume;
- }
- /*******************************************************************************
- * Function: void _DtHelpCeOpenSdlVolume (_DtHelpVolume vol);
- *
- * Parameters: vol Specifies the loaded volume.
- *
- * Return Value: 0 if successful, -1 if a failure occurs
- *
- * errno Values: None
- *
- * Purpose: When the volume is no longer needed, it should be unloaded
- * with this call. Unloading it frees the memory (which means
- * any handles on the volume become invalid.)
- *
- ******************************************************************************/
- int
- _DtHelpCeOpenSdlVolume (
- _DtHelpVolumeHdl volume)
- {
- CESDLVolume *sdlVol;
- _DtHelpVolume vol = (_DtHelpVolume) volume;
- sdlVol = (CESDLVolume *) calloc (1, sizeof(CESDLVolume));
- if (sdlVol != NULL)
- {
- vol->vols.sdl_vol = (SdlVolumeHandle) sdlVol;
- _DtHelpCeInitSdlVolume(volume);
- if (_DtHelpCeFrmtSdlVolumeInfo(vol->volFile,
- vol, &(vol->check_time)) == 0)
- {
- vol->sdl_flag = True;
- return 0;
- }
- vol->vols.sdl_vol = NULL;
- free(sdlVol);
- }
- return -1;
- }
- /*******************************************************************************
- * Function: void _DtHelpCeCleanSdlVolume (_DtHelpVolume vol);
- *
- * Parameters: vol Specifies the loaded volume.
- *
- * Return Value: 0 if successful, -1 if a failure occurs
- *
- * errno Values: None
- *
- * Purpose: When the volume is no longer needed, it should be unloaded
- * with this call. Unloading it frees the memory (which means
- * any handles on the volume become invalid.)
- *
- ******************************************************************************/
- void
- _DtHelpCeCleanSdlVolume (
- _DtHelpVolumeHdl volume)
- {
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (sdlVol != NULL)
- {
- _DtHelpFreeSegments(sdlVol->snb , _DtCvFALSE, sdlVol->destroy_region,
- sdlVol->client_data);
- _DtHelpFreeSegments(sdlVol->title, _DtCvFALSE, sdlVol->destroy_region,
- sdlVol->client_data);
- /*
- * free the index information
- */
- FreeEntryInfo(sdlVol->index);
- _DtHelpFreeSegments(sdlVol->index, _DtCvFALSE, NULL, NULL);
- /*
- * free the toss information.
- */
- FreeTossInfo(sdlVol->toss);
- _DtHelpFreeSegments(sdlVol->toss , _DtCvFALSE, NULL, NULL);
- /*
- * free the ids
- */
- FreeIds(sdlVol->loids);
- _DtHelpFreeSegments(sdlVol->loids, _DtCvFALSE, NULL, NULL);
- /*
- * free the document information.
- */
- if (NULL != _SdlDocInfoPtrLanguage(sdlVol->sdl_info))
- free(_SdlDocInfoPtrLanguage(sdlVol->sdl_info));
- if (NULL != _SdlDocInfoPtrCharSet(sdlVol->sdl_info))
- free(_SdlDocInfoPtrCharSet(sdlVol->sdl_info));
- if (NULL != _SdlDocInfoPtrDocId(sdlVol->sdl_info))
- free(_SdlDocInfoPtrDocId(sdlVol->sdl_info));
- if (NULL != _SdlDocInfoPtrFirstPg(sdlVol->sdl_info))
- free(_SdlDocInfoPtrFirstPg(sdlVol->sdl_info));
- if (NULL != _SdlDocInfoPtrSdlDtd(sdlVol->sdl_info))
- free(_SdlDocInfoPtrSdlDtd(sdlVol->sdl_info));
- if (NULL != _SdlDocInfoPtrStamp(sdlVol->sdl_info))
- free(_SdlDocInfoPtrStamp(sdlVol->sdl_info));
- free(sdlVol->sdl_info);
- }
- }
- /*******************************************************************************
- * Function: int _DtHelpCeRereadSdlVolume (_DtHelpVolume vol);
- *
- * Parameters: vol Specifies the loaded volume.
- *
- * Return Value: 0 if successful, -1 if a failure occurs
- *
- * errno Values: None
- *
- * Purpose: When the volume is no longer needed, it should be unloaded
- * with this call. Unloading it frees the memory (which means
- * any handles on the volume become invalid.)
- *
- ******************************************************************************/
- int
- _DtHelpCeRereadSdlVolume (
- _DtHelpVolumeHdl volume)
- {
- _DtHelpCeCleanSdlVolume(volume);
- _DtHelpCeInitSdlVolume(volume);
- if (_DtHelpCeFrmtSdlVolumeInfo(_DtHelpCeGetVolumeName(volume),
- volume, NULL) == 0)
- return 0;
- return -1;
- }
- /*******************************************************************************
- * Function: void _DtHelpCeCloseSdlVolume (_DtHelpVolume vol);
- *
- * Parameters: vol Specifies the loaded volume.
- *
- * Return Value: 0 if successful, -1 if a failure occurs
- *
- * errno Values: None
- *
- * Purpose: When the volume is no longer needed, it should be unloaded
- * with this call. Unloading it frees the memory (which means
- * any handles on the volume become invalid.)
- *
- ******************************************************************************/
- void
- _DtHelpCeCloseSdlVolume (
- _DtHelpVolumeHdl volume)
- {
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (sdlVol != NULL)
- {
- _DtHelpCeCleanSdlVolume(volume);
- free(sdlVol);
- }
- }
- /*****************************************************************************
- * Function: Boolean _DtHelpCeGetSdlHomeTopicId (_DtHelpVolume vol,
- * char *target_id,
- * char *ret_name, int *ret_offset)
- *
- * Parameters: vol Specifies the loaded volume
- * target_id Specifies target location ID
- * ret_name Returns a null terminated string
- * containing a fully qualified path to
- * the file that contains 'target_id'.
- * ret_offset Returns the offset into 'ret_name'
- * to the topic that contains 'target_id'.
- *
- * Memory own by caller:
- * ret_name
- *
- * Returns: True if successful, False if a failure occurs
- *
- * errno Values: EINVAL Specifies an invalid parameter was
- * used.
- * CEErrorMalloc
- * CEErrorLocIdNotFound
- * Specifies that 'locId' was not
- * found.
- *
- * Purpose: Find which topic contains a specified locationID.
- *
- *****************************************************************************/
- char *
- _DtHelpCeGetSdlHomeTopicId (
- _DtHelpVolumeHdl volume)
- {
- _DtCvSegment *idSegs;
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (sdlVol->sdl_info != NULL)
- {
- /*
- * Was the first page topic declared in the header?
- */
- if (NULL != _SdlDocInfoPtrFirstPg(sdlVol->sdl_info))
- return (_SdlDocInfoPtrFirstPg(sdlVol->sdl_info));
- /*
- * have to search the list of ids for the home topic. This is a
- * bit of a kludge since we are looking for a specific string in
- * the rssi. But this is for backwards compatibility since the
- * Snapshot release of the help system were released with out
- * the first-page attribute and relied on _hometopic.
- *
- * Plus, first-page is #IMPLIED, which means that the parser
- * that generated this SDL document does not have to use this
- * attribute.
- */
- if (_DtHelpCeGetSdlVolIds(volume, -1, &idSegs) != 0)
- return NULL;
- while (idSegs != NULL)
- {
- if (SdlIdVirpage == _SdlSegToSdlIdInfoType(idSegs) &&
- _DtHelpCeStrCaseCmpLatin1(_SdlIdInfoPtrRssi(
- _SdlSegToSdlIdInfoPtr(idSegs)),
- "_hometopic") == 0)
- return _DtCvContainerIdOfSeg(idSegs);
- idSegs = idSegs->next_seg;
- }
- }
- return NULL;
- }
- /*****************************************************************************
- * Function: Boolean _DtHelpCeFindSdlId (_DtHelpVolume vol, char *target_id,
- * char *ret_name, int *ret_offset)
- *
- * Parameters: vol Specifies the loaded volume
- * target_id Specifies target location ID
- * ret_name Returns a null terminated string
- * containing a fully qualified path to
- * the file that contains 'target_id'.
- * ret_offset Returns the offset into 'ret_name'
- * to the topic that contains 'target_id'.
- *
- * Memory own by caller:
- * ret_name
- *
- * Returns: True if successful, False if a failure occurs
- *
- * errno Values: EINVAL Specifies an invalid parameter was
- * used.
- * CEErrorMalloc
- * CEErrorLocIdNotFound
- * Specifies that 'locId' was not
- * found.
- *
- * Purpose: Find which topic contains a specified locationID.
- *
- *****************************************************************************/
- int
- _DtHelpCeFindSdlId (
- _DtHelpVolumeHdl volume,
- char *target_id,
- int fd,
- char **ret_name,
- int *ret_offset )
- {
- _DtHelpVolume vol = (_DtHelpVolume) volume;
- _DtCvSegment *pEl;
- pEl = _DtHelpCeMapSdlIdToSegment(volume, target_id, fd);
- if (pEl != NULL)
- {
- if (ret_name != NULL)
- *ret_name = strdup(vol->volFile);
- *ret_offset = _SdlIdInfoPtrOffset(_SdlSegToSdlIdInfoPtr(pEl));
- return True;
- }
- return False;
- }
- /*****************************************************************************
- * Function: int _DtHelpCeGetSdlKeywordList (
- *
- * Parameters:
- *
- * Returns: 0 if successful, -1 if not.
- *
- * errno Values:
- *
- * Purpose: Get the KeywordList for an SDL volume.
- *
- *****************************************************************************/
- int
- _DtHelpCeGetSdlKeywordList (
- _DtHelpVolumeHdl volume)
- {
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (_DtHelpCeGetSdlVolIndex(volume) != 0 || NULL == sdlVol->index
- || NULL == _DtCvContainerListOfSeg(sdlVol->index))
- return -1;
- return(ProcessEntry(((_DtHelpVolume) volume),
- _DtCvContainerListOfSeg(sdlVol->index), NULL));
- }
- /*****************************************************************************
- * Function: int _DtHelpCeGetSdlVolumeAsciiAbstract(volume);
- *
- * Parameters:
- *
- * Returns: 0 if successful, -1 if not.
- *
- * errno Values:
- *
- * Purpose: Get the KeywordList for an SDL volume.
- *
- *****************************************************************************/
- char *
- _DtHelpCeGetSdlVolumeAsciiAbstract(
- _DtHelpVolumeHdl volume)
- {
- return(_DtHelpCeFrmtSdlVolumeAbstractToAscii(volume));
- }
- /*****************************************************************************
- * Function: int _DtHelpCeGetSdlIdPath(volume, target_id, ret_ids);
- *
- * Parameters:
- *
- * Returns: > 0 if successful, -1 if not.
- *
- * Memory: The memory returned is owned by the caller.
- *
- * Purpose: Get the list of location ids between the top and the
- * target_id.
- *
- *****************************************************************************/
- int
- _DtHelpCeGetSdlIdPath(
- _DtHelpVolumeHdl volume,
- char *target_id,
- char ***ret_ids)
- {
- _DtCvSegment *idSegs;
- _DtCvSegment *targetEl;
- int hiddenNo = -1;
- targetEl = _DtHelpCeMapSdlIdToSegment(volume, target_id, -1);
- if (targetEl == NULL)
- return -1;
- *ret_ids = NULL;
- if (_DtHelpCeGetSdlVolIds(volume, -1, &idSegs) != 0)
- return 0;
- if (_SdlVolumeMinorNumber(_DtHelpCeGetSdlVolumePtr(volume)) >= SDL_DTD_1_1)
- hiddenNo = 0;
- return (MapPath(&idSegs, targetEl, -1, 0, hiddenNo, ret_ids));
- }
- /*****************************************************************************
- * Function: _DtCvSegment *_DtHelpCeMapSdlIdToSegment(volume, target_id);
- *
- * Parameters:
- *
- * Returns: > 0 if successful, -1 if not.
- *
- * errno Values:
- *
- * Purpose: Get the list of location ids between the top and the
- * target_id.
- *
- *****************************************************************************/
- _DtCvSegment *
- _DtHelpCeMapSdlIdToSegment(
- _DtHelpVolumeHdl volume,
- const char *target_id,
- int fd)
- {
- int underScore = False;
- short minorNo;
- _DtCvSegment *idSegs;
- char *idString;
- char resStr[128] = "SDL-RESERVED-";
- minorNo = _SdlVolumeMinorNumber(_DtHelpCeGetSdlVolumePtr(volume));
- if (*target_id == '_')
- {
- /*
- * parsers generating SDL_DTD_1_0 and earlier put the special
- * access points (_hometopic, _abstract, _copyright, etc.) in
- * the SSI.
- */
- if (minorNo < SDL_DTD_1_1)
- underScore = True;
- else
- {
- target_id++;
- strcat(resStr, target_id);
- target_id = resStr;
- }
- }
- if (_DtHelpCeGetSdlVolIds(volume, fd, &idSegs) != 0)
- return NULL;
- while (idSegs != NULL)
- {
- if (underScore == True)
- idString = _SdlIdInfoPtrRssi(_SdlSegToSdlIdInfoPtr(idSegs));
- else
- idString = _DtCvContainerIdOfSeg(idSegs);
- if (idString != NULL &&
- _DtHelpCeStrCaseCmpLatin1(idString, target_id) == 0)
- return idSegs;
- idSegs = idSegs->next_seg;
- }
- return NULL;
- }
- /*****************************************************************************
- * Function: int _DtHelpCeMapIdToSdlTopicId(volume, target_id);
- *
- * Parameters:
- *
- * Returns: > 0 if successful, -1 if not.
- *
- * errno Values:
- *
- * Purpose: Get the id of the virpage containing the target_id.
- *
- *****************************************************************************/
- int
- _DtHelpCeMapIdToSdlTopicId(
- _DtHelpVolumeHdl volume,
- const char *target_id,
- char **ret_id)
- {
- int found = -1;
- _DtCvSegment *idList;
- _DtCvSegment *idSeg;
- SDLIdInfo *idInfo;
- if (_DtHelpCeGetSdlVolIds(volume, -1, &idList) == 0)
- {
- idSeg = _DtHelpCeMapSdlIdToSegment(volume, target_id, -1);
- if (idSeg != NULL)
- {
- while (found == -1 && idList != NULL)
- {
- idInfo = _SdlSegToSdlIdInfoPtr(idList);
- if (_SdlIdInfoPtrType(idInfo) == SdlIdVirpage)
- *ret_id = _DtCvContainerIdOfSeg(idList);
- if (idList == idSeg)
- found = 0;
- else
- idList = idList->next_seg;
- }
- }
- }
- return found;
- }
- /*****************************************************************************
- * Function: char * _DtHelpCeGetSdlVolCharSet(volume);
- *
- * Parameters:
- *
- * Returns: the pointer to the locale string. Null otherwise.
- *
- * errno Values:
- *
- * Purpose: Get the locale of the volume.
- *
- *****************************************************************************/
- const char *
- _DtHelpCeGetSdlVolCharSet(
- _DtHelpVolumeHdl volume)
- {
- const char *charSet = IsoString;
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (sdlVol->sdl_info != NULL &&
- NULL != _SdlDocInfoPtrLanguage(sdlVol->sdl_info))
- charSet = _SdlDocInfoPtrCharSet(sdlVol->sdl_info);
- return charSet;
- }
- /*****************************************************************************
- * Function: char * _DtHelpCeGetSdlVolLanguage(volume);
- *
- * Parameters:
- *
- * Returns: the pointer to the language used in the volume.
- *
- * errno Values:
- *
- * Purpose: Get the locale of the volume.
- *
- *****************************************************************************/
- char *
- _DtHelpCeGetSdlVolLanguage(
- _DtHelpVolumeHdl volume)
- {
- char *language = "C";
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (sdlVol->sdl_info != NULL &&
- NULL != _SdlDocInfoPtrLanguage(sdlVol->sdl_info))
- language = _SdlDocInfoPtrLanguage(sdlVol->sdl_info);
- return language;
- }
- /*****************************************************************************
- * Function: char * _DtHelpCeGetSdlVolumeLocale(volume);
- *
- * Parameters:
- *
- * Returns: the pointer to the locale string. Null otherwise.
- *
- * errno Values:
- *
- * Purpose: Get the locale of the volume.
- *
- *****************************************************************************/
- char *
- _DtHelpCeGetSdlVolumeLocale(
- _DtHelpVolumeHdl volume)
- {
- int langLen;
- char *locale;
- char *lang;
- const char *charSet;
- lang = _DtHelpCeGetSdlVolLanguage(volume);
- charSet = _DtHelpCeGetSdlVolCharSet(volume);
- langLen = strlen(lang);
- locale = (char *) malloc (langLen + strlen(charSet) + 2);
- if (locale != NULL)
- {
- strcpy(locale, lang);
- if (langLen != 0 && *charSet != '\0')
- {
- locale[langLen++] = '.';
- strcpy(&(locale[langLen]), charSet);
- }
- }
- return locale;
- }
- /*****************************************************************************
- * Function: int _DtHelpCeGetSdlDocStamp(volume, ret_doc, ret_time);
- *
- * Parameters:
- *
- * Returns: 0 if successful, -2 if the volume does not contain
- * one or the other, -1 if any other failure.
- *
- * Memory: The Caller owns the memory returned in ret_doc and ret_time.
- *
- * Purpose: Get the doc id and time stamp of a volume.
- *
- *****************************************************************************/
- int
- _DtHelpCeGetSdlDocStamp(
- _DtHelpVolumeHdl volume,
- char **ret_doc,
- char **ret_time)
- {
- int result = -1;
- char *docId = NULL;
- char *timestamp = NULL;
- CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume);
- if (sdlVol->sdl_info != NULL)
- {
- result = 0;
- if (NULL != _SdlDocInfoPtrDocId(sdlVol->sdl_info))
- docId = strdup(_SdlDocInfoPtrDocId(sdlVol->sdl_info));
- else
- result = -2;
- if (NULL != _SdlDocInfoPtrStamp(sdlVol->sdl_info))
- timestamp = strdup(_SdlDocInfoPtrStamp(sdlVol->sdl_info));
- else
- result = -2;
- }
- if (ret_doc != NULL)
- *ret_doc = docId;
- if (ret_time != NULL)
- *ret_time = timestamp;
- if (result == 0 && (docId == NULL || timestamp == NULL)) {
- free(docId); /* Incase only one of them is NULL */
- free(timestamp); /* " */
- return -1;
- }
- return result;
- }
- /*****************************************************************************
- * Function: int _DtHelpCeGetSdlTopicChildren(
- *
- * Parameters:
- *
- * Returns: pointer to the element, Null otherwise.
- *
- * errno Values:
- *
- * Purpose: Find the specified element.
- *
- *****************************************************************************/
- int
- _DtHelpCeGetSdlTopicChildren(
- _DtHelpVolumeHdl volume,
- char *target,
- char ***ret_ids)
- {
- int done = False;
- int count = 0;
- int segLev;
- _DtCvSegment *idSeg;
- SDLIdInfo *idInfo;
- /*
- * Find the target id.
- */
- idSeg = _DtHelpCeMapSdlIdToSegment(volume, target, -1);
- /*
- * save this level and start looking for its children at the next seg.
- */
- *ret_ids = NULL;
- if (idSeg != NULL)
- {
- idInfo = _SdlSegToSdlIdInfoPtr(idSeg);
- segLev = _SdlIdInfoPtrRlevel(idInfo) + 1;
- idSeg = idSeg->next_seg;
- }
- /*
- * process any virpage that has the correct level
- */
- while (idSeg != NULL && done == False)
- {
- idInfo = _SdlSegToSdlIdInfoPtr(idSeg);
- if (_SdlIdInfoPtrType(idInfo) == SdlIdVirpage)
- {
- /*
- * If greater, we're at the next sibling.
- */
- if (segLev > _SdlIdInfoPtrRlevel(idInfo))
- done = True;
- else if (segLev == _SdlIdInfoPtrRlevel(idInfo))
- {
- *ret_ids = (char **) _DtHelpCeAddPtrToArray( (void **) *ret_ids,
- (void *)(strdup(_DtCvContainerIdOfSeg(idSeg))));
- if ((*ret_ids) == NULL)
- return -1;
- count++;
- }
- }
- idSeg = idSeg->next_seg;
- }
- return count;
- }
|