1 /*
2 * Copyright (C) 1991, NEC Corporation.
3 */
4 #ifndef lint
5 static char rcsid[]=
6 "$Id: hint.c,v 2.10 1994/04/19 10:16:41 uchida Exp $ (NEC)";
7 #endif
8
9 #include <stdio.h>
10 #include "plain2.h"
11 /*
12 * Hint to determine the type of text block
13 */
14 struct hintStr {
15 char *beginstr;
16 char *endstr;
17 short type;
18 } hintStr[] = {
19 #ifdef PICTURE
20 { "[[P", "]]P", TB_PICTURE },
21 #endif
22 { "[[T", "]]T", TB_TABLE },
23 { "[[E", "]]E", TB_EXAMPLE },
24 { "[[R", "]]R", TB_RAW },
25 { "[[N", "]]N", TB_CENTER },
26 { "[[A", "]]A", TB_RIGHT }, /* Adjust right */
27 { "[[C", "]]C", TB_COMMENT }, /* comment out */
28 { "", "", 0}};
checkIfHint(s,which)29 checkIfHint(s, which)
30 char *s;
31 int which;
32 {
33 struct hintStr *hp;
34 hp = hintStr;
35 while (*hp->beginstr) {
36 if (which == 0) {
37 if (strncmp(s, hp->beginstr,
38 strlen(hp->beginstr)) == 0) {
39 return hp->type;
40 }
41 }
42 else {
43 if (strncmp(s, hp->endstr,
44 strlen(hp->endstr)) == 0) {
45 return hp->type;
46 }
47 }
48 hp++;
49 }
50 return 0;
51 }
hint(begin,end)52 hint(begin, end)
53 int begin;
54 int end;
55 {
56 int i, l, rbegin;
57 int tbType;
58 struct textBlock *tbp;
59 l = begin;
60 while (l < end) {
61 if (tbType = checkIfHint(texts[l]->body, 0)) {
62 rbegin = l;
63 l++;
64 while (l < end) {
65 if (checkIfHint(texts[l]->body, 1) == tbType){
66 l++;
67 tbp = newTextBlock(rbegin, l, tbType);
68 tbType = 0;
69 tbp->hinted = 1;
70 for (i = rbegin; i < l; i++)
71 texts[i]->block = tbp;
72 break;
73 }
74 else
75 l++;
76 }
77 if (tbType) {
78 /* Can't find end of hint region*/
79 fprintf(stderr, "WARNING: can't find matching %s at line %d\n", texts[rbegin]->body, rbegin);
80 }
81
82 }
83 else
84 l++;
85 }
86 }
87