CCDFUtil.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $XConsortium: CCDFUtil.c /main/7 1996/11/01 10:10:08 drk $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: CCDFUtil.c
  28. **
  29. ** Project: Un*x Desktop Help
  30. **
  31. **
  32. ** Description: Semi private format utility functions for
  33. ** formatting CCDF
  34. **
  35. **
  36. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  37. **
  38. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  39. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  40. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  41. ** (c) Copyright 1993, 1994 Novell, Inc.
  42. **
  43. **
  44. ****************************************************************************
  45. ************************************<+>*************************************/
  46. /*
  47. * system includes
  48. */
  49. #include <errno.h>
  50. #include <limits.h>
  51. #include <string.h>
  52. #include <ctype.h>
  53. #include <stdlib.h>
  54. #include <stdio.h>
  55. #include <X11/Xos.h>
  56. #ifdef X_NOT_STDC_ENV
  57. extern int errno;
  58. #endif
  59. /*
  60. * Canvas Engine includes
  61. */
  62. #include "CanvasP.h"
  63. /*
  64. * private includes
  65. */
  66. #include "bufioI.h"
  67. #include "CanvasError.h"
  68. #include "CCDFUtilI.h"
  69. #include "FontAttrI.h"
  70. #include "CvStringI.h"
  71. #include "FormatUtilI.h"
  72. #include "StringFuncsI.h"
  73. #ifdef NLS16
  74. #endif
  75. /******** Private Function Declarations ********/
  76. static int GetCmdData(
  77. BufFilePtr in_file,
  78. char *in_buf,
  79. int in_size,
  80. char **in_ptr,
  81. int cur_mb_len,
  82. int allowed,
  83. int strip,
  84. int *ret_size,
  85. int *ret_max,
  86. char **ret_string );
  87. /******** End Private Function Declarations ********/
  88. /******************************************************************************
  89. *
  90. * Private variables and defines.
  91. *
  92. *****************************************************************************/
  93. #define MIN_GROW 16
  94. #define REALLOC_INCR 10
  95. #define CMD_NOT_ALLOWED -1000
  96. typedef struct {
  97. char *cmd;
  98. int type;
  99. int significant;
  100. } FormatCmds;
  101. static const FormatCmds CcdfFormatCmds[] =
  102. {
  103. { "abbrev" , CCDF_ABBREV_CMD , 2 },
  104. { "angle" , CCDF_FONT_CMD , 2 },
  105. { "characterset", CCDF_FONT_CMD , 1 },
  106. { "figure" , CCDF_FIGURE_CMD , 1 },
  107. { "graphic" , CCDF_GRAPHIC_CMD , 1 },
  108. { "id" , CCDF_ID_CMD , 1 },
  109. { "label" , CCDF_LABEL_CMD , 2 },
  110. { "link" , CCDF_LINK_CMD , 2 },
  111. { "newline" , CCDF_NEWLINE_CMD , 1 },
  112. { "paragraph" , CCDF_PARAGRAPH_CMD, 1 },
  113. { "size" , CCDF_FONT_CMD , 2 },
  114. { "spacing" , CCDF_FONT_CMD , 2 },
  115. { "title" , CCDF_TITLE_CMD , 2 },
  116. { "topic" , CCDF_TOPIC_CMD , 2 },
  117. { "type" , CCDF_FONT_CMD , 2 },
  118. { "weight" , CCDF_FONT_CMD , 1 },
  119. { "0x" , CCDF_OCTAL_CMD , 2 },
  120. /* always leave this one as the last entry */
  121. { "/" , CCDF_FORMAT_END , 1 }
  122. };
  123. /******************************************************************************
  124. *
  125. * Semi Public variables.
  126. *
  127. *****************************************************************************/
  128. /******************************************************************************
  129. *
  130. * Private Functions
  131. *
  132. *****************************************************************************/
  133. /******************************************************************************
  134. * Function: static int GetCmdData (FILE *in_file, char *in_buf, int in_size,
  135. * char **in_ptr, int allowed, int strip,
  136. * int *ret_size, int *ret_max, char **ret_string)
  137. *
  138. * Parameters:
  139. * in_file Specifies a stream to read from.
  140. * in_buf Specifies the buffer where new information
  141. * is placed.
  142. * in_size Specifies the maximum size of 'in_buf'.
  143. * in_ptr Specifies the pointer into 'in_buf' to
  144. * start processing.
  145. * Returns the new location in 'in_buf' to
  146. * continue processing.
  147. * allowed Specifies the formatting commands allowed
  148. * in the data.
  149. * strip Specifies the formatting commands to strip.
  150. * from the data.
  151. * ret_size Specifies the current size of
  152. * 'ret_string'.
  153. * Returns the new size of 'ret_string'.
  154. * ret_max Specifies the current maximum size of
  155. * 'ret_string'
  156. * Returns the new size of 'ret_string'.
  157. * ret_string Returns the data found.
  158. *
  159. *
  160. * Returns: 0 if successful, -1 if errors.
  161. *
  162. * errno Values:
  163. * read (2) Errors set via a read call.
  164. * EINVAL
  165. * CEErrorMalloc
  166. * CEErrorIllegalInfo
  167. * CEErrorReadEmpty
  168. *
  169. *
  170. * Purpose: Gets a string containing font change tags
  171. * Incoming source:
  172. * "data with font change tags </>"
  173. *
  174. *****************************************************************************/
  175. static int
  176. GetCmdData(
  177. BufFilePtr in_file,
  178. char *in_buf,
  179. int in_size,
  180. char **in_ptr,
  181. int cur_mb_len,
  182. int allowed,
  183. int strip,
  184. int *ret_size,
  185. int *ret_max,
  186. char **ret_string )
  187. {
  188. int size;
  189. int fontType;
  190. int charSize = 1;
  191. int result = 0;
  192. char *myBufPtr = *in_ptr;
  193. char *tmpPtr;
  194. int skipString = False;
  195. int endToken;
  196. int stripCmd;
  197. if (!ret_string)
  198. skipString = True;
  199. while (!result)
  200. {
  201. if (cur_mb_len != 1)
  202. charSize = mblen(myBufPtr, cur_mb_len);
  203. if (charSize == 1)
  204. {
  205. /*
  206. * Do we need to read more information?
  207. */
  208. if (((int) strlen (myBufPtr)) < 3 &&
  209. _DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size) == -1)
  210. return -1;
  211. switch (*myBufPtr)
  212. {
  213. case '<':
  214. /*
  215. * Go to the next character.
  216. */
  217. myBufPtr++;
  218. endToken = True;
  219. stripCmd = False;
  220. /*
  221. * end token
  222. */
  223. if (*myBufPtr == '/')
  224. {
  225. *in_ptr = myBufPtr;
  226. return _DtHelpCeGetCcdfEndMark (in_file, in_buf,
  227. in_ptr, in_size,cur_mb_len);
  228. }
  229. fontType = _DtHelpCeGetCcdfFontType (myBufPtr);
  230. if (fontType == -1)
  231. {
  232. switch (_DtCvToLower (*myBufPtr))
  233. {
  234. /*
  235. * <0xff>
  236. */
  237. case '0':
  238. if ((!skipString &&
  239. _DtHelpCeAddOctalToBuf (
  240. myBufPtr,
  241. ret_string, ret_size,
  242. ret_max, 0) == -1)
  243. ||
  244. _DtHelpCeGetCcdfEndMark (in_file, in_buf,
  245. &myBufPtr,in_size,cur_mb_len) == -1)
  246. return -1;
  247. endToken = False;
  248. break;
  249. /*
  250. * <abbrev>
  251. */
  252. case 'a':
  253. myBufPtr++;
  254. if (_DtCvToLower (*myBufPtr) == 'b')
  255. {
  256. if (CCDF_NOT_ALLOW_CMD (allowed,
  257. CCDF_ABBREV_CMD))
  258. {
  259. errno = CMD_NOT_ALLOWED;
  260. return -1;
  261. }
  262. else if (CCDF_NOT_ALLOW_CMD (strip,
  263. CCDF_ABBREV_CMD))
  264. stripCmd = True;
  265. }
  266. else
  267. {
  268. errno = CEErrorFormattingCmd;
  269. return -1;
  270. }
  271. break;
  272. /*
  273. * <figure>
  274. */
  275. case 'f':
  276. if (CCDF_NOT_ALLOW_CMD (allowed,
  277. CCDF_FIGURE_CMD))
  278. {
  279. errno = CMD_NOT_ALLOWED;
  280. return -1;
  281. }
  282. else if (CCDF_NOT_ALLOW_CMD (strip,
  283. CCDF_FIGURE_CMD))
  284. stripCmd = True;
  285. break;
  286. /*
  287. * <graphic>
  288. */
  289. case 'g':
  290. if (CCDF_NOT_ALLOW_CMD (allowed,
  291. CCDF_GRAPHIC_CMD))
  292. {
  293. errno = CMD_NOT_ALLOWED;
  294. return -1;
  295. }
  296. if (_DtHelpCeGetCcdfEndMark (in_file, in_buf,
  297. &myBufPtr,in_size,cur_mb_len) == -1)
  298. return -1;
  299. endToken = False;
  300. break;
  301. /*
  302. * <id>
  303. */
  304. case 'i':
  305. if (CCDF_NOT_ALLOW_CMD (allowed,
  306. CCDF_ID_CMD))
  307. {
  308. errno = CMD_NOT_ALLOWED;
  309. return -1;
  310. }
  311. else if (CCDF_NOT_ALLOW_CMD (strip,
  312. CCDF_ID_CMD))
  313. stripCmd = True;
  314. break;
  315. /*
  316. * <label>
  317. * <link>
  318. */
  319. case 'l':
  320. myBufPtr++;
  321. if (_DtCvToLower (*myBufPtr) == 'a')
  322. {
  323. if (CCDF_NOT_ALLOW_CMD (allowed,
  324. CCDF_LABEL_CMD))
  325. {
  326. errno = CMD_NOT_ALLOWED;
  327. return -1;
  328. }
  329. else if (CCDF_NOT_ALLOW_CMD (strip,
  330. CCDF_LABEL_CMD))
  331. stripCmd = True;
  332. }
  333. else if (_DtCvToLower (*myBufPtr) == 'i')
  334. {
  335. if (CCDF_NOT_ALLOW_CMD (allowed,
  336. CCDF_LINK_CMD))
  337. {
  338. errno = CMD_NOT_ALLOWED;
  339. return -1;
  340. }
  341. else if (CCDF_NOT_ALLOW_CMD (strip,
  342. CCDF_LINK_CMD))
  343. stripCmd = True;
  344. }
  345. else
  346. {
  347. errno = CEErrorFormattingCmd;
  348. return -1;
  349. }
  350. break;
  351. /*
  352. * <newline>
  353. */
  354. case 'n':
  355. if (CCDF_NOT_ALLOW_CMD (allowed,
  356. CCDF_NEWLINE_CMD))
  357. {
  358. errno = CMD_NOT_ALLOWED;
  359. return -1;
  360. }
  361. if (_DtHelpCeGetCcdfEndMark (in_file, in_buf,
  362. &myBufPtr,in_size,cur_mb_len) == -1)
  363. return -1;
  364. endToken = False;
  365. break;
  366. /*
  367. * <paragraph>
  368. */
  369. case 'p':
  370. if (CCDF_NOT_ALLOW_CMD (allowed,
  371. CCDF_PARAGRAPH_CMD))
  372. {
  373. errno = CMD_NOT_ALLOWED;
  374. return -1;
  375. }
  376. else if (CCDF_NOT_ALLOW_CMD (strip,
  377. CCDF_PARAGRAPH_CMD))
  378. stripCmd = True;
  379. break;
  380. /*
  381. * <title>
  382. * <topic>
  383. */
  384. case 't':
  385. myBufPtr++;
  386. if (_DtCvToLower (*myBufPtr) == 'o')
  387. {
  388. if (CCDF_NOT_ALLOW_CMD (allowed,
  389. CCDF_TOPIC_CMD))
  390. {
  391. errno = CMD_NOT_ALLOWED;
  392. return -1;
  393. }
  394. else if (CCDF_NOT_ALLOW_CMD (strip,
  395. CCDF_TOPIC_CMD))
  396. stripCmd = True;
  397. }
  398. else if (_DtCvToLower (*myBufPtr) == 'i')
  399. {
  400. if (CCDF_NOT_ALLOW_CMD (allowed,
  401. CCDF_TITLE_CMD))
  402. {
  403. errno = CMD_NOT_ALLOWED;
  404. return -1;
  405. }
  406. else if (CCDF_NOT_ALLOW_CMD (strip,
  407. CCDF_TITLE_CMD))
  408. stripCmd = True;
  409. }
  410. else
  411. {
  412. errno = CEErrorFormattingCmd;
  413. return -1;
  414. }
  415. break;
  416. default:
  417. errno = CEErrorFormattingCmd;
  418. return -1;
  419. }
  420. }
  421. else if (CCDF_NOT_ALLOW_CMD (allowed, CCDF_FONT_CMD))
  422. {
  423. errno = CMD_NOT_ALLOWED;
  424. return -1;
  425. }
  426. else if (CCDF_NOT_ALLOW_CMD (strip, CCDF_FONT_CMD))
  427. stripCmd = True;
  428. if (endToken)
  429. {
  430. /*
  431. * This is a <token>....</token> construct.
  432. * pass over the <token> part.
  433. */
  434. if (_DtHelpCeGetCcdfEndMark (in_file, in_buf,
  435. &myBufPtr, in_size,cur_mb_len) == -1 ||
  436. GetCmdData (in_file, in_buf, in_size,
  437. &myBufPtr, cur_mb_len, allowed, strip,
  438. ret_size, ret_max, ret_string) == -1)
  439. return -1;
  440. }
  441. break;
  442. case ' ':
  443. case '\n':
  444. /*
  445. * Put a space in the segment
  446. */
  447. if (!skipString)
  448. {
  449. tmpPtr = " ";
  450. result = _DtHelpCeAddCharToBuf (&tmpPtr,
  451. ret_string, ret_size, ret_max, MIN_GROW);
  452. }
  453. myBufPtr++;
  454. break;
  455. case '\\':
  456. myBufPtr++;
  457. /*
  458. * Save the escaped character
  459. */
  460. if (!skipString)
  461. result = _DtHelpCeAddCharToBuf (&myBufPtr,
  462. ret_string, ret_size, ret_max, MIN_GROW);
  463. else
  464. myBufPtr++;
  465. break;
  466. default:
  467. /*
  468. * Put the information in the buffer
  469. */
  470. result = _DtHelpCeStrcspn (myBufPtr, "<\\\n ",
  471. cur_mb_len, &size);
  472. /*
  473. * If _DtHelpCeStrcspn found an invalid character
  474. * we don't want to quit yet. Allow another pass
  475. * to try to read another buffer of information.
  476. */
  477. result = 0;
  478. if (!skipString && size)
  479. result = _DtHelpCeAddStrToBuf (&myBufPtr,
  480. ret_string, ret_size, ret_max, size, 0);
  481. else
  482. myBufPtr += size;
  483. }
  484. }
  485. else if (charSize > 1)
  486. {
  487. result = _DtHelpCeStrcspn (myBufPtr, "<\\\n ", cur_mb_len, &size);
  488. /*
  489. * If _DtHelpCeStrcspn found an invalid character
  490. * we don't want to quit yet. Allow another pass
  491. * to try to read another buffer of information.
  492. */
  493. result = 0;
  494. if (!skipString && size)
  495. result = _DtHelpCeAddStrToBuf (&myBufPtr,
  496. ret_string, ret_size, ret_max, size, 0);
  497. else
  498. myBufPtr += size;
  499. }
  500. else /* if (charSize < 1) */
  501. {
  502. if (*myBufPtr == '\0' || ((int) strlen (in_buf)) < cur_mb_len)
  503. result = _DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size);
  504. else
  505. {
  506. errno = CEErrorIllegalInfo;
  507. result = -1;
  508. }
  509. }
  510. }
  511. return result;
  512. }
  513. /******************************************************************************
  514. * Function: int GetTitleCmd (FILE *in_file, char in_buf, int in_size,
  515. * char **in_ptr, char **ret_string)
  516. *
  517. * Parameters:
  518. * in_file Specifies a stream to read from.
  519. * in_buf Specifies the buffer where new information
  520. * is placed.
  521. * in_size Specifies the maximum size of 'in_buf'.
  522. * in_ptr Specifies the pointer into 'in_buf' to
  523. * start processing.
  524. * Returns the new location in 'in_buf' to
  525. * continue processing.
  526. * ret_string Returns the data found.
  527. *
  528. * Returns: 0 if successful, -1 if errors
  529. *
  530. * errno Values:
  531. * read (2) Errors set via a read call.
  532. * EINVAL
  533. * CEErrorIllegalInfo
  534. * CEErrorReadEmpty
  535. *
  536. * Purpose: Determine if the next formatting command is
  537. * <ABBREV ...>.
  538. * Returns the data found between <ABBREV> and its ending </>.
  539. *
  540. * Note: The only formatting command allowed between <ABBREV> and
  541. * its </> is the <NEWLINE> command. And it is stripped.
  542. *
  543. *****************************************************************************/
  544. static int
  545. GetTitleCmd(
  546. BufFilePtr in_file,
  547. char *in_buf,
  548. int in_size,
  549. int cur_mb_len,
  550. char **in_ptr,
  551. char **ret_string )
  552. {
  553. int result;
  554. int junkSize = 0;
  555. int junkMax = 0;
  556. /*
  557. * null the return string
  558. */
  559. if (ret_string)
  560. *ret_string = NULL;
  561. /*
  562. * check for the token
  563. */
  564. result = _DtHelpCeCheckNextCcdfCmd ("ti", in_file, in_buf, in_size, cur_mb_len, in_ptr);
  565. if (result != 0)
  566. {
  567. if (result == -2)
  568. errno = CEErrorMissingTitleCmd;
  569. return -1;
  570. }
  571. if (_DtHelpCeGetCcdfEndMark(in_file,in_buf,in_ptr,in_size,cur_mb_len) != 0)
  572. return -1;
  573. result = GetCmdData (in_file, in_buf, in_size, in_ptr, cur_mb_len,
  574. (CCDF_NEWLINE_CMD | CCDF_GRAPHIC_CMD |
  575. CCDF_LINK_CMD | CCDF_FONT_CMD | CCDF_ID_CMD),
  576. (CCDF_NEWLINE_CMD | CCDF_GRAPHIC_CMD |
  577. CCDF_LINK_CMD | CCDF_FONT_CMD | CCDF_ID_CMD),
  578. &junkSize, &junkMax, ret_string);
  579. if (result == -1 && errno == CMD_NOT_ALLOWED)
  580. errno = CEErrorTitleSyntax;
  581. return result;
  582. }
  583. /******************************************************************************
  584. *
  585. * Semi Public Functions
  586. *
  587. *****************************************************************************/
  588. /******************************************************************************
  589. * Function: int _DtHelpCeGetCcdfEndMark (FILE *file, char *buffer,
  590. * char **buf_ptr, int buf_size, int flag)
  591. *
  592. * Parameters:
  593. * file Specifies a stream to read from.
  594. * buffer Specifies the buffer where new information
  595. * is placed.
  596. * buf_ptr Specifies the pointer into 'buffer' to
  597. * start processing.
  598. * Returns the new location in 'buffer' to
  599. * continue processing.
  600. * buf_size Specifies the maximum size of 'buffer'.
  601. *
  602. *
  603. * Return Value: 0 if successful, -1 if a failure occurs
  604. *
  605. * errno Values:
  606. * read (2) Errors set via a read call.
  607. * EINVAL
  608. * CEErrorIllegalInfo
  609. * CEErrorReadEmpty
  610. *
  611. * Purpose: Find the end of tag marker '>'.
  612. *
  613. ******************************************************************************/
  614. int
  615. _DtHelpCeGetCcdfEndMark (
  616. BufFilePtr file,
  617. char *buffer,
  618. char **buf_ptr,
  619. int buf_size,
  620. int cur_mb_len)
  621. {
  622. int len;
  623. int result;
  624. char *ptr;
  625. int done = False;
  626. ptr = *buf_ptr;
  627. do
  628. {
  629. /*
  630. * Find the end of marker or end of topic
  631. */
  632. result = _DtHelpCeStrcspn (ptr, "\\>", cur_mb_len, &len);
  633. ptr += len;
  634. if (result == 0)
  635. {
  636. /*
  637. * found either a backslash or the end marker,
  638. * update the pointer and if it was the '>'
  639. * say we're done.
  640. */
  641. if (*ptr == '>')
  642. done = True;
  643. else
  644. ptr++;
  645. ptr++;
  646. }
  647. else /* result == -1 || result == 1 */
  648. {
  649. /*
  650. * nothing here - get the next buffer and keep looking
  651. * unless getting the next buffer has problems/eof
  652. */
  653. if (((int) strlen(ptr)) >= cur_mb_len)
  654. {
  655. errno = CEErrorIllegalInfo;
  656. return -1;
  657. }
  658. if (_DtHelpCeGetNxtBuf (file, buffer, &ptr, buf_size) == -1)
  659. return -1;
  660. }
  661. } while (!done);
  662. *buf_ptr = ptr;
  663. return 0;
  664. }
  665. /******************************************************************************
  666. * Function: int _DtHelpCeGetCcdfStrParam (FILE *in_file, char *in_buf,
  667. * int in_size, char **in_ptr, int flag,
  668. * int eat_escape, Boolean ignore_quotes,
  669. * int less_test, char **ret_string)
  670. *
  671. * Parameters:
  672. * in_file Specifies a stream to read from.
  673. * in_buf Specifies the buffer where new information
  674. * is placed.
  675. * in_size Specifies the maximum size of 'in_buf'.
  676. * in_ptr Specifies the pointer into 'in_buf' to
  677. * start processing.
  678. * Returns the new location in 'in_buf' to
  679. * continue processing.
  680. * flag Specifies whether the routine returns
  681. * a -1 if '>' is the next token.
  682. * eat_secape Specifies whether the backslash is not
  683. * placed in the returned string.
  684. * True - it is skipped.
  685. * False - it is saved in 'ret_string'.
  686. * ignore_quotes Specifies whether quotes are to be included
  687. * in the returned string.
  688. * less_test Specifies whether the routine should
  689. * stop when it finds a '<' character.
  690. * ret_string If NULL, throws the information away.
  691. * Otherwise, returns the string found.
  692. *
  693. * Returns: 0 if successful, -1 if errors, 1 if 'flag' is false and
  694. * the next token is '>'.
  695. *
  696. * errno Values:
  697. * read (2) Errors set via a read call.
  698. * EINVAL
  699. * CEErrorMalloc
  700. * CEErrorIllegalInfo
  701. * CEErrorReadEmpty
  702. *
  703. * Purpose: Skip the rest of the current token.
  704. * Get the next token. A token is defined as being one or
  705. * more strings between single or double quotes,
  706. * or a string bounded by spaces or ended by the
  707. * end token '>'.
  708. *
  709. *****************************************************************************/
  710. int
  711. _DtHelpCeGetCcdfStrParam(
  712. BufFilePtr in_file,
  713. char *in_buf,
  714. int in_size,
  715. int cur_mb_len,
  716. char **in_ptr,
  717. _DtCvValue flag,
  718. _DtCvValue eat_escape,
  719. _DtCvValue ignore_quotes,
  720. _DtCvValue less_test,
  721. char **ret_string )
  722. {
  723. int copySize;
  724. int result = 0;
  725. int spnResult;
  726. int stringSize = 0;
  727. int stringMax = 0;
  728. char *stringPtr = NULL;
  729. char *myBufPtr;
  730. char *mySpace;
  731. int done = False;
  732. int singleQuotes = False;
  733. int doubleQuotes = False;
  734. int skipString = False;
  735. int testMB = False;
  736. if (cur_mb_len != 1)
  737. testMB = True;
  738. /*
  739. * do we want to skip the string or read it.
  740. */
  741. if (!ret_string)
  742. skipString = True;
  743. /*
  744. * skip to the next parameter or > character. If flag is true,
  745. * we want another parameter, so error if the > character is found.
  746. */
  747. if (_DtHelpCeSkipToNextCcdfToken (in_file, in_buf, in_size, cur_mb_len, in_ptr, flag) != 0)
  748. return -1;
  749. myBufPtr = *in_ptr;
  750. /*
  751. * see if there is another parameter
  752. */
  753. if (_DtCvFALSE == flag && *myBufPtr == '>')
  754. return 1;
  755. /*
  756. * Initialize the global buffer.
  757. */
  758. if (_DtCvFALSE == ignore_quotes &&
  759. (!testMB || mblen (myBufPtr, cur_mb_len) == 1))
  760. {
  761. if (*myBufPtr == '\"')
  762. {
  763. doubleQuotes = True;
  764. myBufPtr++;
  765. }
  766. else if (*myBufPtr == '\'')
  767. {
  768. singleQuotes = True;
  769. myBufPtr++;
  770. }
  771. }
  772. while (!done)
  773. {
  774. spnResult = _DtHelpCeStrcspn (myBufPtr, " <>\'\"\\\n",
  775. cur_mb_len, &copySize);
  776. /*
  777. * Either skip the string or place it in storage
  778. */
  779. if (skipString)
  780. myBufPtr += copySize;
  781. else if (_DtHelpCeAddStrToBuf (&myBufPtr, &stringPtr, &stringSize,
  782. &stringMax, copySize, 0) == -1)
  783. return -1;
  784. /*
  785. * If spnResult is non-zero, read the next buffer of information
  786. */
  787. if (spnResult)
  788. {
  789. if (spnResult == -1 && ((int)strlen(myBufPtr)) >= cur_mb_len)
  790. {
  791. errno = CEErrorIllegalInfo;
  792. return -1;
  793. }
  794. if (_DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size) == -1)
  795. return -1;
  796. }
  797. /*
  798. * Otherwise _DtHelpCeStrcspn stopped at a character we want
  799. */
  800. else
  801. {
  802. switch (*myBufPtr)
  803. {
  804. case '\\':
  805. if (_DtCvTRUE == eat_escape || skipString)
  806. myBufPtr++;
  807. else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
  808. &stringSize, &stringMax, MIN_GROW) == -1)
  809. return -1;
  810. if (*myBufPtr == '\0' && _DtHelpCeGetNxtBuf(in_file,
  811. in_buf,&myBufPtr,in_size) == -1)
  812. return -1;
  813. if (skipString)
  814. myBufPtr++;
  815. else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
  816. &stringSize, &stringMax, MIN_GROW) == -1)
  817. return -1;
  818. break;
  819. case '\n':
  820. if (!doubleQuotes && !singleQuotes)
  821. done = True;
  822. else if (skipString)
  823. myBufPtr++;
  824. else
  825. {
  826. mySpace = " ";
  827. if (_DtHelpCeAddCharToBuf (&mySpace, &stringPtr,
  828. &stringSize, &stringMax, MIN_GROW) == -1)
  829. return -1;
  830. }
  831. break;
  832. case '<':
  833. if (_DtCvTRUE == less_test)
  834. done = True;
  835. else if (skipString)
  836. myBufPtr++;
  837. else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
  838. &stringSize, &stringMax, MIN_GROW) == -1)
  839. return -1;
  840. break;
  841. case '>':
  842. case ' ':
  843. if (!doubleQuotes && !singleQuotes)
  844. done = True;
  845. else if (skipString)
  846. myBufPtr++;
  847. else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
  848. &stringSize, &stringMax, MIN_GROW) == -1)
  849. return -1;
  850. break;
  851. case '\'':
  852. if (_DtCvFALSE == ignore_quotes && singleQuotes)
  853. done = True;
  854. else if (skipString)
  855. myBufPtr++;
  856. else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
  857. &stringSize, &stringMax, MIN_GROW) == -1)
  858. return -1;
  859. break;
  860. case '\"':
  861. if (_DtCvFALSE == ignore_quotes && doubleQuotes)
  862. done = True;
  863. else if (skipString)
  864. myBufPtr++;
  865. else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
  866. &stringSize, &stringMax, MIN_GROW) == -1)
  867. return -1;
  868. break;
  869. }
  870. }
  871. }
  872. if (skipString)
  873. {
  874. if (stringPtr)
  875. free (stringPtr);
  876. }
  877. else
  878. *ret_string = stringPtr;
  879. *in_ptr = myBufPtr;
  880. return result;
  881. } /* End _DtHelpCeGetCcdfStrParam */
  882. /******************************************************************************
  883. * Function: int _DtHelpCeGetCcdfValueParam (FILE *in_file, char *in_buf,
  884. * int in_size, char **in_ptr,
  885. * int flag, int *ret_value)
  886. *
  887. * Parameters:
  888. * in_file Specifies a stream to read from.
  889. * in_buf Specifies the buffer where new information
  890. * is placed.
  891. * in_size Specifies the maximum size of 'in_buf'.
  892. * in_ptr Specifies the pointer into 'in_buf' to
  893. * start processing.
  894. * Returns the new location in 'in_buf' to
  895. * continue processing.
  896. * flag Specifies whether the routine returns
  897. * a -2 if '>' is the next token.
  898. * ret_value Returns the atoi conversion
  899. * of the string found.
  900. *
  901. * Returns: 0 if successful, -1 if errors, -2 if 'flag' is True and
  902. * the next token is '>'.
  903. *
  904. * errno Values:
  905. * read (2) Errors set via a read call.
  906. * EINVAL
  907. * CEErrorMalloc
  908. * CEErrorIllegalInfo
  909. * CEErrorFormattingValue
  910. * CEErrorReadEmpty
  911. *
  912. * Purpose: Get then next numeric parameter.
  913. *
  914. *****************************************************************************/
  915. int
  916. _DtHelpCeGetCcdfValueParam(
  917. BufFilePtr in_file,
  918. char *in_buf,
  919. int in_size,
  920. char **in_ptr,
  921. _DtCvValue flag,
  922. int cur_mb_len,
  923. int *ret_value )
  924. {
  925. int done = False;
  926. char *myBufPtr;
  927. char *stringPtr = NULL;
  928. int stringSize = 0;
  929. int stringMax = 0;
  930. int result = 0;
  931. int spnResult = 0;
  932. int copySize;
  933. if (_DtHelpCeSkipToNextCcdfToken (in_file, in_buf, in_size,
  934. cur_mb_len, in_ptr, _DtCvTRUE) != 0)
  935. return -1;
  936. myBufPtr = *in_ptr;
  937. while (!done)
  938. {
  939. spnResult = _DtHelpCeStrcspn (myBufPtr, " >\n", cur_mb_len, &copySize);
  940. if (_DtHelpCeAddStrToBuf (&myBufPtr, &stringPtr, &stringSize,
  941. &stringMax, copySize, 0) == -1)
  942. return -1;
  943. /*
  944. * _DtHelpCeStrcspn stopped at a character we want
  945. */
  946. if (spnResult == 0)
  947. done = True;
  948. else if (((int)strlen(myBufPtr)) >= cur_mb_len)
  949. {
  950. errno = CEErrorIllegalInfo;
  951. return -1;
  952. }
  953. else if (_DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size) == -1)
  954. return -1;
  955. }
  956. if (stringPtr != NULL && *stringPtr != '\0')
  957. {
  958. *ret_value = atoi(stringPtr);
  959. free (stringPtr);
  960. }
  961. else
  962. {
  963. errno = CEErrorFormattingValue;
  964. result = -1;
  965. }
  966. *in_ptr = myBufPtr;
  967. if (result != -1 && _DtCvTRUE == flag && *myBufPtr == '>')
  968. return -2;
  969. return result;
  970. }
  971. /******************************************************************************
  972. * Function: int _DtHelpCeSkipToNextCcdfToken (FILE *read_file, char *read_buf,
  973. * int read_size, char **src_ptr, int flag)
  974. *
  975. * Parameters:
  976. * read_file Specifies a stream to read from.
  977. * read_buf Specifies the buffer where new information
  978. * is placed.
  979. * read_size Specifies the maximum size of 'read_buf'.
  980. * src_ptr Specifies the pointer into 'read_buf' to
  981. * start processing.
  982. * Returns the new location in 'read_buf' to
  983. * continue processing.
  984. * flag Specifies whether the routine returns
  985. * a 1 if '>' is the next token.
  986. * Returns:
  987. * -1 If problems encountered finding the next token.
  988. * 0 If no problems encountered finding the next token.
  989. * 1 If flag is true and the next token is a > character.
  990. *
  991. * errno Values:
  992. * read (2) Errors set via a read call.
  993. * EINVAL
  994. * CEErrorReadEmpty
  995. * CEErrorIllegalInfo
  996. *
  997. * Purpose: Move 'src_ptr' to the next occurrance of a > character
  998. * or the first character after the next space.
  999. *
  1000. *****************************************************************************/
  1001. int
  1002. _DtHelpCeSkipToNextCcdfToken (
  1003. BufFilePtr read_file,
  1004. char *read_buf,
  1005. int read_size,
  1006. int cur_mb_len,
  1007. char **src_ptr,
  1008. _DtCvValue flag )
  1009. {
  1010. int len;
  1011. int result;
  1012. char *srcPtr = *src_ptr;
  1013. /*
  1014. * Skip the rest of the alphanumeric string.
  1015. */
  1016. do
  1017. {
  1018. /*
  1019. * _DtHelpCeStrcspn returns 0 for 'found a character'
  1020. */
  1021. result = _DtHelpCeStrcspn (srcPtr, " >\n", cur_mb_len, &len);
  1022. srcPtr = srcPtr + len;
  1023. if (result)
  1024. {
  1025. if (result == -1 && ((int)strlen(srcPtr)) >= cur_mb_len)
  1026. {
  1027. errno = CEErrorIllegalInfo;
  1028. return -1;
  1029. }
  1030. if (_DtHelpCeGetNxtBuf(read_file, read_buf,&srcPtr,read_size) == -1)
  1031. return -1;
  1032. }
  1033. } while (result);
  1034. /*
  1035. * Now skip the blanks and end of lines
  1036. */
  1037. do
  1038. {
  1039. /*
  1040. * _DtHelpCeStrspn returns 0 for 'found a character'
  1041. */
  1042. result = _DtHelpCeStrspn (srcPtr, " \n", cur_mb_len, &len);
  1043. srcPtr = srcPtr + len;
  1044. if (result)
  1045. {
  1046. if (result == -1 && ((int)strlen(srcPtr)) >= cur_mb_len)
  1047. {
  1048. errno = CEErrorIllegalInfo;
  1049. return -1;
  1050. }
  1051. if (_DtHelpCeGetNxtBuf(read_file,read_buf,&srcPtr,read_size) == -1)
  1052. return -1;
  1053. }
  1054. } while (result);
  1055. *src_ptr = srcPtr;
  1056. if (_DtCvTRUE == flag && *srcPtr == '>')
  1057. {
  1058. errno = CEErrorFormattingOption;
  1059. return 1;
  1060. }
  1061. return 0;
  1062. }
  1063. /******************************************************************************
  1064. * Function: int _DtHelpCeGetCcdfTopicCmd (void *dpy, FILE *in_file, char *in_buf,
  1065. * char **in_ptr, int in_size,
  1066. * char **ret_charSet)
  1067. *
  1068. * Parameters:
  1069. * in_file Specifies a stream to read from.
  1070. * in_buf Specifies the buffer where new information
  1071. * is placed.
  1072. * in_ptr Specifies the pointer into 'in_buf' to
  1073. * start processing.
  1074. * Returns the new location in 'in_buf' to
  1075. * continue processing.
  1076. * in_size Specifies the maximum size of 'in_buf'.
  1077. * ret_charSet Returns the characters set if specified.
  1078. *
  1079. * Returns: 0 if successful, -1 if errors.
  1080. *
  1081. * errno Values:
  1082. * read (2) Errors set via a read call.
  1083. * EINVAL
  1084. * CEErrorMalloc
  1085. * CEErrorIllegalInfo
  1086. * CEErrorReadEmpty
  1087. *
  1088. *
  1089. * Purpose: Checks for the <TOPIC> command and returns the charset
  1090. * if specified.
  1091. *
  1092. *****************************************************************************/
  1093. int
  1094. _DtHelpCeGetCcdfTopicCmd (
  1095. void *dpy,
  1096. BufFilePtr in_file,
  1097. char *in_buf,
  1098. char **in_ptr,
  1099. int in_size,
  1100. int cur_mb_len,
  1101. char **ret_charSet )
  1102. {
  1103. char *mycharSet = NULL;
  1104. /*
  1105. * null the return values
  1106. */
  1107. if (ret_charSet)
  1108. *ret_charSet = NULL;
  1109. /*
  1110. * check for <TOPIC charset string>
  1111. */
  1112. if (_DtHelpCeCheckNextCcdfCmd ("to",in_file,in_buf,in_size,cur_mb_len,in_ptr) == 0)
  1113. {
  1114. /*
  1115. * The <TOPIC> command and it's attributes must be in 1-byte charset.
  1116. */
  1117. if (_DtHelpCeSkipToNextCcdfToken(in_file, in_buf, in_size, 1,
  1118. in_ptr, _DtCvFALSE) == -1)
  1119. return -1;
  1120. /*
  1121. * charset string
  1122. */
  1123. if (_DtCvToLower (**in_ptr) == 'c')
  1124. {
  1125. if (_DtHelpCeGetCcdfStrParam (in_file, in_buf, in_size,
  1126. 1, in_ptr, True, False, False, False, &mycharSet) == -1)
  1127. return -1;
  1128. if (_DtHelpCeGetCcdfEndMark(in_file,in_buf,in_ptr,in_size,1) == -1)
  1129. {
  1130. if (mycharSet)
  1131. free (mycharSet);
  1132. return -1;
  1133. }
  1134. }
  1135. else if (**in_ptr != '>')
  1136. {
  1137. errno = CEErrorTopicSyntax;
  1138. return -1;
  1139. }
  1140. else
  1141. {
  1142. /*
  1143. * skip the end token
  1144. */
  1145. *in_ptr = *in_ptr + 1;
  1146. }
  1147. }
  1148. else
  1149. {
  1150. errno = CEErrorMissingTopicCmd;
  1151. return -1;
  1152. }
  1153. if (ret_charSet)
  1154. *ret_charSet = mycharSet;
  1155. else if (mycharSet)
  1156. free (mycharSet);
  1157. return 0;
  1158. }
  1159. /******************************************************************************
  1160. * Function: int _DtHelpCeCheckNextCcdfCmd (char *token, FILE *in_file, char in_buf,
  1161. * int in_size, char **in_ptr)
  1162. *
  1163. * Parameters:
  1164. * token Specifies the syntax to look for.
  1165. * <token ....> data </>
  1166. * in_file Specifies a stream to read from.
  1167. * in_buf Specifies the buffer where new information
  1168. * is placed.
  1169. * in_size Specifies the maximum size of 'in_buf'.
  1170. * in_ptr Specifies the pointer into 'in_buf' to
  1171. * start processing.
  1172. * Returns the new location in 'in_buf' to
  1173. * continue processing.
  1174. *
  1175. * Returns: 0 if successful, -1 if errors, -2 if token not found.
  1176. *
  1177. * errno Values:
  1178. * read (2) Errors set via a read call.
  1179. * EINVAL
  1180. * CEErrorIllegalInfo
  1181. * CEErrorReadEmpty
  1182. *
  1183. * Purpose: Determine if the next formatting command is
  1184. * <'token' ...>.
  1185. *
  1186. * Note: 'token' must be a lower case string.
  1187. *
  1188. *****************************************************************************/
  1189. int
  1190. _DtHelpCeCheckNextCcdfCmd(
  1191. char *token,
  1192. BufFilePtr in_file,
  1193. char *in_buf,
  1194. int in_size,
  1195. int cur_mb_len,
  1196. char **in_ptr )
  1197. {
  1198. int result = 0;
  1199. int len = strlen (token);
  1200. char *str;
  1201. /*
  1202. * check for the token
  1203. */
  1204. while (len > 0 && result > -1)
  1205. {
  1206. if (**in_ptr == '\0' &&
  1207. _DtHelpCeGetNxtBuf(in_file, in_buf, in_ptr, in_size) == -1)
  1208. return -1;
  1209. if (cur_mb_len == 1 || mblen (*in_ptr, cur_mb_len) == 1)
  1210. {
  1211. if ((isspace (**in_ptr) || **in_ptr == '\n'))
  1212. *in_ptr = *in_ptr + 1;
  1213. else if (**in_ptr == '<')
  1214. {
  1215. if (((int)strlen(*in_ptr)) < (len + 1) &&
  1216. _DtHelpCeGetNxtBuf (in_file, in_buf,
  1217. in_ptr, in_size) == -1)
  1218. return -1;
  1219. for (str = *in_ptr + 1; len > 0; len--, str++, token++)
  1220. {
  1221. if (_DtCvToLower (*str) != *token)
  1222. return -2;
  1223. }
  1224. result = 0;
  1225. }
  1226. else
  1227. result = -2;
  1228. }
  1229. else
  1230. result = -2;
  1231. }
  1232. return result;
  1233. }
  1234. /*****************************************************************************
  1235. * Function: int _DtHelpCeGetCcdfTopicAbbrev (void *dpy, FILE *file, char *buffer,
  1236. * char **buf_ptr, int buf_size, int strip,
  1237. * char **ret_title, char **ret_charSet,
  1238. * char **ret_abbrev)
  1239. *
  1240. * Parameters:
  1241. * dpy Specifies the display connection as a void.
  1242. * Do it this way to prevent the terminal
  1243. * functions from having to know about Xlib.
  1244. * Terminal/Access Functions should pass NULL
  1245. * to this routine.
  1246. * file Specifies the stream of the open file.
  1247. * buffer The buffer holding the current information.
  1248. * buf_ptr Specifies the pointer into 'buffer' to
  1249. * start processing.
  1250. * Returns the new location in 'buffer' to
  1251. * continue processing.
  1252. * buf_size The size of buffer.
  1253. * ret_title Returns a null terminated string
  1254. * containing the title if found.
  1255. * ret_charSet Returns a null terminated string
  1256. * containing the character set if found.
  1257. * ret_abbrev Returns a null terminated string
  1258. * containing the abbreviated title if found.
  1259. *
  1260. * Memory own by caller:
  1261. * ret_name
  1262. * ret_charSet
  1263. * ret_abbrev
  1264. *
  1265. * Returns: 0 if successful, -2 if <TOPIC> not found, otherwise -1.
  1266. *
  1267. * errno Values:
  1268. * read (2) Errors set via a read call.
  1269. * EINVAL
  1270. * CEErrorMalloc
  1271. * CEErrorIllegalInfo
  1272. * CEErrorReadEmpty
  1273. *
  1274. * Purpose: Find the title and abbreviated title of a topic.
  1275. *
  1276. *****************************************************************************/
  1277. int
  1278. _DtHelpCeGetCcdfTopicAbbrev (
  1279. void *dpy,
  1280. BufFilePtr file,
  1281. char *buffer,
  1282. char **buf_ptr,
  1283. int buf_size,
  1284. int cur_mb_len,
  1285. char **ret_title,
  1286. char **ret_charSet,
  1287. char **ret_abbrev )
  1288. {
  1289. /*
  1290. * NULL the entries.
  1291. */
  1292. if (ret_title)
  1293. *ret_title = NULL;
  1294. if (ret_abbrev)
  1295. *ret_abbrev = NULL;
  1296. /*
  1297. * check for <TOPIC charset string>
  1298. */
  1299. if (_DtHelpCeGetCcdfTopicCmd (dpy,
  1300. file,
  1301. buffer,
  1302. buf_ptr,
  1303. buf_size,
  1304. cur_mb_len,
  1305. ret_charSet) == -1
  1306. ||
  1307. /* Must have a <TITLE> token*/
  1308. GetTitleCmd(file, buffer, buf_size, cur_mb_len,buf_ptr,ret_title) == -1
  1309. ||
  1310. /* check for the <ABBREV> token */
  1311. _DtHelpCeGetCcdfAbbrevCmd (file, buffer, buf_size, cur_mb_len,buf_ptr, ret_abbrev) == -1)
  1312. return -1;
  1313. return 0;
  1314. }
  1315. /*****************************************************************************
  1316. * Function: int _DtHelpCeSkipCcdfAbbrev (FILE *file, char *buffer, int buf_size,
  1317. * char **buf_ptr)
  1318. *
  1319. * Parameters:
  1320. * file Specifies the stream of the open file.
  1321. * buffer The buffer holding the current information.
  1322. * buf_size The size of buffer.
  1323. * buf_ptr Specifies the pointer into 'buffer' to
  1324. * start processing.
  1325. * Returns the new location in 'buffer' to
  1326. * continue processing.
  1327. *
  1328. * Returns: 0 if successful, otherwise -1.
  1329. *
  1330. * errno Values:
  1331. * read (2) Errors set via a read call.
  1332. * EINVAL
  1333. * CEErrorMalloc
  1334. * CEErrorIllegalInfo
  1335. * CEErrorReadEmpty
  1336. *
  1337. * Purpose: Skip the <ABBREV> command
  1338. *
  1339. *****************************************************************************/
  1340. int
  1341. _DtHelpCeSkipCcdfAbbrev (
  1342. BufFilePtr file,
  1343. char *buffer,
  1344. char **buf_ptr,
  1345. int buf_size,
  1346. int cur_mb_len)
  1347. {
  1348. /*
  1349. * check for the <ABBREV> token and skip its data.
  1350. */
  1351. return _DtHelpCeGetCcdfAbbrevCmd(file, buffer, buf_size, cur_mb_len,buf_ptr, NULL);
  1352. }
  1353. /******************************************************************************
  1354. * Function: int _DtHelpCeGetCcdfAbbrevCmd (FILE *in_file, char *in_buf, int in_size,
  1355. * char **in_ptr, char **ret_string)
  1356. *
  1357. * Parameters:
  1358. * in_file Specifies a stream to read from.
  1359. * in_buf Specifies the buffer where new information
  1360. * is placed.
  1361. * in_size Specifies the maximum size of 'in_buf'.
  1362. * in_ptr Specifies the pointer into 'in_buf' to
  1363. * start processing.
  1364. * Returns the new location in 'in_buf' to
  1365. * continue processing.
  1366. * ret_string Returns the data found.
  1367. *
  1368. * Returns: 0 if successful, -1 if errors
  1369. *
  1370. * errno Values:
  1371. * read (2) Errors set via a read call.
  1372. * EINVAL
  1373. * CEErrorIllegalInfo
  1374. * CEErrorReadEmpty
  1375. *
  1376. * Purpose: Determine if the next formatting command is
  1377. * <ABBREV ...>.
  1378. * Returns the data found between <ABBREV> and its ending </>.
  1379. *
  1380. * Note: The only formatting command allowed between <ABBREV> and
  1381. * its </> is the <NEWLINE> command. And it is stripped.
  1382. *
  1383. *****************************************************************************/
  1384. int
  1385. _DtHelpCeGetCcdfAbbrevCmd(
  1386. BufFilePtr in_file,
  1387. char *in_buf,
  1388. int in_size,
  1389. int cur_mb_len,
  1390. char **in_ptr,
  1391. char **ret_string )
  1392. {
  1393. int result;
  1394. int junkSize = 0;
  1395. int junkMax = 0;
  1396. /*
  1397. * null the return string
  1398. */
  1399. if (ret_string)
  1400. *ret_string = NULL;
  1401. /*
  1402. * check for the token
  1403. */
  1404. result = _DtHelpCeCheckNextCcdfCmd ("ab", in_file, in_buf, in_size, cur_mb_len, in_ptr);
  1405. if (result == -2)
  1406. result = 0;
  1407. else if (result == 0 &&
  1408. _DtHelpCeGetCcdfEndMark(in_file,in_buf,in_ptr,in_size,cur_mb_len) != -1)
  1409. {
  1410. result = GetCmdData (in_file, in_buf, in_size, in_ptr, cur_mb_len,
  1411. CCDF_NEWLINE_CMD, CCDF_NEWLINE_CMD,
  1412. &junkSize, &junkMax, ret_string);
  1413. if (result == -1 && errno == CMD_NOT_ALLOWED)
  1414. errno = CEErrorAbbrevSyntax;
  1415. }
  1416. else
  1417. result = -1;
  1418. return result;
  1419. }
  1420. /******************************************************************************
  1421. * Function: int _DtHelpCeGetCcdfCmd (int current, char *buffer,
  1422. * char **buf_ptr, FILE *my_file,
  1423. * int size, int allowed, int flag )
  1424. *
  1425. * Parameters: current Specifies the current formatting command.
  1426. * buffer Specifies the buffer to use for input.
  1427. * buf_ptr Specifies the current position into 'buffer'.
  1428. * my_file Specifies the file stream to read from.
  1429. * size Specifies the maximum size of the input buffer.
  1430. * allowed Specifies the commands allowed at this time.
  1431. * flag Specifies the flag to use for
  1432. * _DtHelpCeGetNxtBuf. No longer used.
  1433. *
  1434. * Returns
  1435. * -1 If errors reading the file or the command is not
  1436. * allowed
  1437. * > 0 The formmatting command.
  1438. *
  1439. * errno Values:
  1440. *
  1441. * Purpose: Determine if the string pointed to by 'ptr' is a formatting
  1442. * command.
  1443. *
  1444. *****************************************************************************/
  1445. int
  1446. _DtHelpCeGetCcdfCmd (
  1447. int current,
  1448. char *buffer,
  1449. char **buf_ptr,
  1450. BufFilePtr my_file,
  1451. int size,
  1452. int allowed)
  1453. {
  1454. int i = -1;
  1455. int j = 1;
  1456. int different;
  1457. int my_error = 0;
  1458. char firstChar;
  1459. char *myPtr;
  1460. /*
  1461. * always allow the end of formatting command
  1462. */
  1463. allowed = allowed | CCDF_FORMAT_END;
  1464. /*
  1465. * set the pointer to the current position in the input buffer
  1466. */
  1467. myPtr = *buf_ptr;
  1468. if (*myPtr == '\0' &&
  1469. _DtHelpCeGetNxtBuf(my_file, buffer, &myPtr, size) == -1)
  1470. return -1;
  1471. firstChar = _DtCvToLower (*myPtr);
  1472. do {
  1473. i++;
  1474. different = firstChar - CcdfFormatCmds[i].cmd[0];
  1475. if (!different && CcdfFormatCmds[i].significant > 1)
  1476. {
  1477. if (((int)strlen(myPtr)) < CcdfFormatCmds[i].significant &&
  1478. _DtHelpCeGetNxtBuf (my_file, buffer, &myPtr, size) == -1)
  1479. return -1;
  1480. j = 1;
  1481. do {
  1482. different = _DtCvToLower(myPtr[j]) - CcdfFormatCmds[i].cmd[j];
  1483. j++;
  1484. } while (!different && j < CcdfFormatCmds[i].significant);
  1485. }
  1486. } while (different && CcdfFormatCmds[i].type != CCDF_FORMAT_END);
  1487. /*
  1488. * update the passed in pointer
  1489. */
  1490. *buf_ptr = myPtr;
  1491. /*
  1492. * check to see if the formatting command is valid
  1493. */
  1494. if (different)
  1495. errno = CEErrorFormattingCmd;
  1496. else if (!different && CCDF_NOT_ALLOW_CMD (allowed, CcdfFormatCmds[i].type))
  1497. {
  1498. my_error = -1;
  1499. switch (current)
  1500. {
  1501. case CCDF_ABBREV_CMD:
  1502. errno = CEErrorAbbrevSyntax;
  1503. break;
  1504. case CCDF_FIGURE_CMD:
  1505. errno = CEErrorFigureSyntax;
  1506. break;
  1507. case CCDF_FONT_CMD:
  1508. errno = CEErrorFontSyntax;
  1509. break;
  1510. case CCDF_GRAPHIC_CMD:
  1511. errno = CEErrorGraphicSyntax;
  1512. break;
  1513. case CCDF_ID_CMD:
  1514. errno = CEErrorIdSyntax;
  1515. break;
  1516. case CCDF_LABEL_CMD:
  1517. errno = CEErrorLabelSyntax;
  1518. break;
  1519. case CCDF_LINK_CMD:
  1520. errno = CEErrorLinkSyntax;
  1521. break;
  1522. case CCDF_NEWLINE_CMD:
  1523. errno = CEErrorNewLineSyntax;
  1524. break;
  1525. case CCDF_OCTAL_CMD:
  1526. errno = CEErrorOctalSyntax;
  1527. break;
  1528. case CCDF_PARAGRAPH_CMD:
  1529. errno = CEErrorParagraphSyntax;
  1530. break;
  1531. case CCDF_TITLE_CMD:
  1532. errno = CEErrorTitleSyntax;
  1533. break;
  1534. case CCDF_TOPIC_CMD:
  1535. errno = CEErrorTopicSyntax;
  1536. break;
  1537. }
  1538. }
  1539. if (different || my_error)
  1540. return -1;
  1541. return CcdfFormatCmds[i].type;
  1542. }
  1543. /******************************************************************************
  1544. * Function: int _DtHelpCeGetCcdfFontType (char *code)
  1545. *
  1546. * Parameters: code Specifies the character set to initialize
  1547. * data and flags. The caller must ensure that
  1548. * there is enough of the code string available
  1549. * to make the determination.
  1550. *
  1551. * Return Value: int Returns the font resource to change.
  1552. * -1 if unknown font change type.
  1553. *
  1554. * Purpose: Determines if the code is a font change specification.
  1555. *
  1556. *****************************************************************************/
  1557. int
  1558. _DtHelpCeGetCcdfFontType (char *code)
  1559. {
  1560. char my2Char;
  1561. char myChar = _DtCvToLower (*code);
  1562. code++;
  1563. my2Char = _DtCvToLower (*code);
  1564. switch (myChar)
  1565. {
  1566. /*
  1567. * <angle string>
  1568. */
  1569. case 'a':
  1570. if (my2Char == 'n')
  1571. return _CEFONT_ANGLE;
  1572. break;
  1573. /*
  1574. * <charset string>
  1575. */
  1576. case 'c': return _CEFONT_CHAR_SET;
  1577. /*
  1578. * <type string>
  1579. */
  1580. case 't':
  1581. if (my2Char == 'y')
  1582. return _CEFONT_TYPE;
  1583. break;
  1584. /*
  1585. * <weight string>
  1586. */
  1587. case 'w': return _CEFONT_WEIGHT;
  1588. /*
  1589. * <size string>
  1590. * <spacing string>
  1591. */
  1592. case 's':
  1593. if (my2Char == 'i')
  1594. return _CEFONT_SIZE;
  1595. if (my2Char == 'p')
  1596. return _CEFONT_SPACING;
  1597. }
  1598. return -1;
  1599. }