Debian Codegraph @

doc/man/ivman/Man.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 #include <ctype.h>
38 #include "Man.h"
39
40 /////////////////////////////////////////////////////////////////////////////
41 //
42 // Class: Item
43 //
44 /////////////////////////////////////////////////////////////////////////////
45
46 Language Item::curLanguage = ALL;
47
48 Item::Item()
49 {
50 language = curLanguage;
51
52 next = NULL;
53 }
54
55 SbBool
56 Item::hasNextToWrite()
57 {
58 Item *item;
59
60 for (item = next; item != NULL; item = item->next)
61 if (item->language == ALL || item->language == Writer::getLanguage())
62 return TRUE;
63
64 return FALSE;
65 }
66
67 int
68 Item::getNumPreTabChars() const
69 {
70 return -1; // No need to set up tab
71 }
72
73 /////////////////////////////////////////////////////////////////////////////
74 //
75 // Class: ItemList
76 //
77 /////////////////////////////////////////////////////////////////////////////
78
79 SbBool
80 ItemList::isEmpty() const
81 {
82 SbBool empty = TRUE;
83
84 for (Item *item = first; item != NULL; item = item->next) {
85 if (item->language == ALL || item->language == Writer::getLanguage()) {
86 empty = FALSE;
87 break;
88 }
89 }
90
91 return empty;
92 }
93
94 void
95 ItemList::add(Item *item, SbBool append)
96 {
97 if (last == NULL)
98 first = last = item;
99
100 else if (append) {
101 // Add to end of list
102 last->next = item;
103 last = item;
104 }
105
106 else {
107 // Add to start of list
108 item->next = first;
109 first = item;
110 }
111 }
112
113 #define MIN_TAB_CHARS 20
114 #define MAX_TAB_CHARS 30
115
116 void
117 ItemList::write(SbBool runIn)
118 {
119 Item *item;
120
121 // For on-line pages, tab stop depends on longest line before the
122 // tab. For the book version, just use a fixed tab stop.
123 if (Writer::isForBook())
124 Writer::setTab(16);
125
126 else {
127 int numTabChars = -1, maxTabChars = -1, n;
128
129 // Compute pre-tab length
130 for (item = first; item != NULL; item = item->next) {
131 if (item->language == ALL ||
132 item->language == Writer::getLanguage()) {
133
134 n = item->getNumPreTabChars();
135
136 if (n >= 0) {
137
138 // Add 2 characters (to get a couple of spaces)
139 n += 2;
140
141 // Compute maximum number of tab chars
142 if (n > maxTabChars)
143 maxTabChars = n;
144
145 // Compute real tab length (ignoring tabs that will
146 // break to the next line anyway)
147 if (n < MAX_TAB_CHARS && n > numTabChars)
148 numTabChars = n;
149 }
150 }
151 }
152
153 // Make sure tab value is within range
154 if (maxTabChars >= 0) {
155 if (numTabChars < 20)
156 numTabChars = 20;
157 else if (numTabChars > 30)
158 numTabChars = 30;
159 }
160 Writer::setTab(numTabChars);
161 }
162
163 for (item = first; item != NULL; item = item->next)
164 if (item->language == ALL || item->language == Writer::getLanguage())
165 item->write(runIn);
166
167 if (runIn)
168 Writer::space(.75);
169 }
170
171 int
172 ItemList::getNum() const
173 {
174 Item *item;
175 int num = 0;
176
177 for (item = first; item != NULL; item = item->next)
178 num++;
179
180 return num;
181 }
182
183 /////////////////////////////////////////////////////////////////////////////
184 //
185 // Class: Inherit
186 //
187 /////////////////////////////////////////////////////////////////////////////
188
189 Inherit::Inherit(const SbName &name)
190 {
191 className = name;
192 }
193
194 SbBool
195 Inherit::read()
196 {
197 // This should never be called, since it is not read in.
198 Reader::error("Inherit::read called - internal error");
199 return FALSE;
200 }
201
202 void
203 Inherit::write(SbBool)
204 {
205 Writer::write(className);
206 if (hasNextToWrite())
207 Writer::write(" > ");
208 else
209 Writer::write("\n");
210 }
211
212 /////////////////////////////////////////////////////////////////////////////
213 //
214 // Class: Include
215 //
216 /////////////////////////////////////////////////////////////////////////////
217
218 SbBool
219 Include::read()
220 {
221 if (! Reader::readString(file)) {
222 Reader::error("INCLUDE string");
223 return FALSE;
224 }
225 return TRUE;
226 }
227
228 void
229 Include::write(SbBool)
230 {
231 Writer::setFont(Writer::FIXED_ROMAN);
232 if (Writer::getLanguage() == C)
233 Writer::write("#include <Inventor_c/");
234 else
235 Writer::write("#include <Inventor/");
236 Writer::write(file);
237 Writer::write(">\n");
238
239 if (hasNextToWrite())
240 Writer::breakLine();
241 else
242 Writer::space();
243 }
244
245 /////////////////////////////////////////////////////////////////////////////
246 //
247 // Class: Typedef
248 //
249 /////////////////////////////////////////////////////////////////////////////
250
251 SbBool
252 Typedef::read()
253 {
254 if (! Reader::readString(type) ||
255 ! Reader::readName(name) ||
256 ! Reader::readString(extra)) {
257 Reader::error("TYPEDEF spec");
258 return FALSE;
259 }
260 return TRUE;
261 }
262
263 void
264 Typedef::write(SbBool)
265 {
266 Writer::indentForTab();
267 Writer::setFont(Writer::CODE_ROMAN);
268 Writer::write("typedef ");
269 Writer::write(type);
270 Writer::tab();
271 Writer::setFont(Writer::CODE_BOLD);
272 Writer::write(name);
273 Writer::setFont(Writer::CODE_ROMAN);
274 Writer::write(extra);
275 Writer::write("\n");
276 if (hasNextToWrite())
277 Writer::breakLine();
278 else
279 Writer::space();
280 }
281
282 int
283 Typedef::getNumPreTabChars() const
284 {
285 return strlen("typedef ") + type.getLength();
286 }
287
288 /////////////////////////////////////////////////////////////////////////////
289 //
290 // Class: Define
291 //
292 /////////////////////////////////////////////////////////////////////////////
293
294 SbBool
295 Define::read()
296 {
297 if (! Reader::readBracketed(definition)) {
298 Reader::error("DEFINE string");
299 return FALSE;
300 }
301 return TRUE;
302 }
303
304 void
305 Define::write(SbBool)
306 {
307 Writer::setFont(Writer::CODE_ROMAN);
308 Writer::write("#define ");
309 Writer::write(definition);
310 Writer::write("\n");
311 if (hasNextToWrite())
312 Writer::breakLine();
313 else
314 Writer::space();
315 }
316
317 /////////////////////////////////////////////////////////////////////////////
318 //
319 // Class: EnumDef
320 //
321 /////////////////////////////////////////////////////////////////////////////
322
323 SbBool
324 EnumDef::read()
325 {
326 if (! Reader::readName(name) ||
327 ! Reader::readString(description)) {
328 Reader::error("ENUM definition pair");
329 return FALSE;
330 }
331 return TRUE;
332 }
333
334 void
335 EnumDef::write(SbBool)
336 {
337 Writer::indentForTab();
338 Writer::setFont(Writer::CODE_BOLD);
339 if (Writer::getLanguage() == C)
340 Writer::write(ClassDef::getCurClass()->getCEnumPrefix());
341 else {
342 Writer::write(ClassDef::getCurClass()->getName());
343 Writer::write("::");
344 }
345 Writer::write(name);
346 Writer::setFont(Writer::TEXT_ROMAN);
347 Writer::tab();
348 Writer::writeBracketed(description);
349 Writer::breakLine();
350 }
351
352 int
353 EnumDef::getNumPreTabChars() const
354 {
355 int classLength;
356
357 if (Writer::getLanguage() == C)
358 classLength = ClassDef::getCurClass()->getCEnumPrefix().getLength();
359 else
360 classLength = ClassDef::getCurClass()->getName().getLength() + 2;
361
362 return classLength + name.getLength();
363 }
364
365 /////////////////////////////////////////////////////////////////////////////
366 //
367 // Class: Enum
368 //
369 /////////////////////////////////////////////////////////////////////////////
370
371 SbBool
372 Enum::read()
373 {
374 EnumDef *def;
375 int c;
376
377 if (! Reader::readName(name)) {
378 Reader::error("ENUM name");
379 return FALSE;
380 }
381
382 // Read name, description pairs within braces
383 Reader::skipWhiteSpace();
384 if (Reader::get() != OPEN_CHAR) {
385 Reader::error("ENUM definition list");
386 return FALSE;
387 }
388
389 while (TRUE) {
390
391 // Read the next definition pair. There has to be at least 1.
392 def = new EnumDef;
393 if (! def->read())
394 return FALSE;
395 defs.add(def);
396
397 // See if the list is ending
398 Reader::skipWhiteSpace();
399 if ((c = Reader::get()) == CLOSE_CHAR)
400 break;
401 else if (c != SEP_CHAR) {
402 Reader::error("ENUM definition list");
403 return FALSE;
404 }
405 }
406
407 return TRUE;
408 }
409
410 void
411 Enum::write(SbBool)
412 {
413 Writer::setBaseIndent(0.0);
414 Writer::setFont(Writer::CODE_ROMAN);
415 Writer::write("enum ");
416 Writer::setFont(Writer::CODE_BOLD);
417 if (Writer::getLanguage() == C)
418 Writer::write(ClassDef::getCurClass()->getName());
419 Writer::write(name);
420 Writer::setFont(Writer::CODE_ROMAN);
421 Writer::write(" {\n");
422
423 Writer::setBaseIndent(0.5);
424 defs.write();
425 Writer::setBaseIndent(0.0);
426
427 Writer::setFont(Writer::CODE_ROMAN);
428 Writer::write("}\n");
429 Writer::space();
430 }
431
432 /////////////////////////////////////////////////////////////////////////////
433 //
434 // Class: Field
435 //
436 /////////////////////////////////////////////////////////////////////////////
437
438 SbBool
439 Field::read()
440 {
441 if (! readStuff()) {
442 Reader::error("FIELD spec");
443 return FALSE;
444 }
445 return TRUE;
446 }
447
448 SbBool
449 Field::readStuff()
450 {
451 return (Reader::readName(name) &&
452 Reader::readBracketed(description));
453 }
454
455 void
456 Field::write(SbBool runIn)
457 {
458 if (runIn) {
459 Writer::setFont(Writer::CODE_ROMAN);
460 Writer::write(name);
461 if (hasNextToWrite())
462 Writer::write(", ");
463 else
464 Writer::write("\n");
465 }
466
467 else {
468 Writer::indentForTab();
469 Writer::setFont(Writer::CODE_ROMAN);
470 Writer::write(type);
471 Writer::tab();
472 Writer::setFont(Writer::CODE_BOLD);
473 Writer::write(name);
474 Writer::write("\n");
475
476 // Write the description only if we're not writing the synopsis
477 // and there is a non-empty description:
478 if (! Writer::getInSynopsis() && ! ! description)
479 Writer::writeDescription(description);
480
481 else {
482 if (hasNextToWrite())
483 Writer::breakLine();
484 else
485 Writer::space();
486 }
487 }
488 }
489
490 int
491 Field::getNumPreTabChars() const
492 {
493 return type.getLength();
494 }
495
496 /////////////////////////////////////////////////////////////////////////////
497 //
498 // Class: Input
499 //
500 /////////////////////////////////////////////////////////////////////////////
501
502 Input::Input()
503 {
504 }
505
506 SbBool
507 Input::read()
508 {
509 if (! readStuff()) {
510 Reader::error("INPUT spec");
511 return FALSE;
512 }
513 return TRUE;
514 }
515
516 /////////////////////////////////////////////////////////////////////////////
517 //
518 // Class: Output
519 //
520 /////////////////////////////////////////////////////////////////////////////
521
522 Output::Output()
523 {
524 }
525
526 SbBool
527 Output::read()
528 {
529 if (! readStuff()) {
530 Reader::error("OUTPUT spec");
531 return FALSE;
532 }
533 return TRUE;
534 }
535
536 void
537 Output::write(SbBool runIn)
538 {
539 if (runIn) {
540 Writer::setFont(Writer::CODE_ROMAN);
541 Writer::write(name);
542 if (hasNextToWrite())
543 Writer::write(", ");
544 else
545 Writer::write("\n");
546 }
547 else {
548 Writer::indentForTab();
549 Writer::setFont(Writer::CODE_ROMAN);
550 Writer::write("(");
551 Writer::write(type);
552 Writer::write(")");
553 Writer::tab();
554 Writer::setFont(Writer::CODE_BOLD);
555 Writer::write(name);
556 Writer::setFont(Writer::CODE_ROMAN);
557 Writer::write("\n");
558
559 // Write the description only if we're not writing the synopsis
560 // and there is a non-empty description:
561 if (! Writer::getInSynopsis() && ! ! description)
562 Writer::writeDescription(description);
563
564 else {
565 if (hasNextToWrite())
566 Writer::breakLine();
567 else
568 Writer::space();
569 }
570 }
571 }
572
573 int
574 Output::getNumPreTabChars() const
575 {
576 return type.getLength() + 2; // 2 parentheses
577 }
578
579 /////////////////////////////////////////////////////////////////////////////
580 //
581 // Class: Part
582 //
583 /////////////////////////////////////////////////////////////////////////////
584
585 SbBool
586 Part::read()
587 {
588 if (! Reader::readName(name) ||
589 ! Reader::readBracketed(description)) {
590 Reader::error("PART spec");
591 return FALSE;
592 }
593 return TRUE;
594 }
595
596 void
597 Part::write(SbBool runIn)
598 {
599 if (runIn) {
600 Writer::setFont(Writer::CODE_ROMAN);
601 Writer::write(name);
602 if (hasNextToWrite())
603 Writer::write(", ");
604 else
605 Writer::write("\n");
606 }
607 else {
608 Writer::indentForTab();
609 Writer::setFont(Writer::CODE_ROMAN);
610 Writer::write("(");
611 Writer::write(type);
612 Writer::write(")");
613 Writer::tab();
614 Writer::setFont(Writer::CODE_BOLD);
615 Writer::write(name);
616 Writer::setFont(Writer::CODE_ROMAN);
617 Writer::write("\n");
618
619 // Write the description only if we're not writing the synopsis
620 // and there is a non-empty description:
621 if (! Writer::getInSynopsis() && ! ! description)
622 Writer::writeDescription(description);
623
624 else {
625 if (hasNextToWrite())
626 Writer::breakLine();
627 else
628 Writer::space();
629 }
630 }
631 }
632
633 int
634 Part::getNumPreTabChars() const
635 {
636 return type.getLength() + 2; // 2 parentheses
637 }
638
639 /////////////////////////////////////////////////////////////////////////////
640 //
641 // Class: Method
642 //
643 /////////////////////////////////////////////////////////////////////////////
644
645 Method::Method()
646 {
647 skipThis = FALSE;
648 }
649
650 Method::~Method()
651 {
652 }
653
654 SbBool
655 Method::read()
656 {
657 // Method definitions can get very complicated, so we just read
658 // the C method name and then read the rest as a big string until
659 // the description (starting with an OPEN_CHAR) is hit.
660 if (! Reader::readName(cName) ||
661 ! Reader::readUpTo(OPEN_CHAR, full) ||
662 ! Reader::readBracketed(description) ||
663 ! parse()) {
664 Reader::error("METHOD spec");
665 return FALSE;
666 }
667 return TRUE;
668 }
669
670 SbBool
671 Method::parse()
672 {
673 int i, nest, endOfName;
674 const char *str = full.getString();
675
676 type = REGULAR;
677 isHidden = isStatic = isVirtual = isFriend = isConst = FALSE;
678
679 // Find the last close parenthesis
680 for (i = full.getLength() - 1; i >= 0; --i) {
681 if (str[i] == ')')
682 break;
683 }
684
685 // If none, error
686 if (i < 0)
687 return FALSE;
688
689 // Back up to the matching open paren, skipping nested parens
690 nest = 1;
691 for (--i ; i >= 0; --i) {
692 if (str[i] == ')')
693 nest++;
694 else if (str[i] == '(' && --nest == 0)
695 break;
696 }
697
698 // If none, error
699 if (i < 0)
700 return FALSE;
701
702 // The word before this paren is the name of the method. Skip over
703 // spaces between the name and the paren.
704 for (--i ; i >= 0; --i)
705 if (! isspace(str[i]))
706 break;
707
708 if (i < 0)
709 return FALSE;
710
711 endOfName = i;
712
713 // Get the name. Assume for now it begins at the previous white
714 // space, unless it contains alphanumeric characters, in which
715 // case, stop if there's a non-alphanumeric (or ~) character
716 // before it.
717 // (There may be a '*' or a '&' without a space.)
718 SbBool endsInAlNum = isalnum(str[i]);
719
720 if (endsInAlNum) {
721 for (--i; i >= 0; --i) {
722 if (! (isalnum(str[i]) || str[i] == '~'))
723 break;
724 }
725 }
726 else {
727 for (--i; i >= 0; --i) {
728 if (isspace(str[i]))
729 break;
730 }
731 }
732
733 name = full.getSubString(i + 1, endOfName).getString();
734
735 // See if it's a constructor or destructor
736 if (name == ClassDef::getCurClass()->getName())
737 type = CONSTRUCTOR;
738 else if (name.getString()[0] == '~' &&
739 name.getString() + 1 == ClassDef::getCurClass()->getName())
740 type = DESTRUCTOR;
741
742 // See if it's an operator
743 else {
744 int j, prevEnd;
745
746 // Skip over space before name
747 for (j = i; j >= 0; --j)
748 if (isalnum(str[j]))
749 break;
750 prevEnd = j;
751
752 // Get word previous to that
753 for (; j >= 0; --j)
754 if (! isalnum(str[j]))
755 break;
756
757 if (j > 0 && j < prevEnd &&
758 full.getSubString(j + 1, prevEnd) == "operator") {
759 type = OPERATOR;
760
761 // In the C version, operators get translated into method
762 // names, using correspondences stolen from "ncbind".
763 if (Writer::getLanguage() == C) {
764 static const char *opNames[][2] = {
765 { "+", "Add" },
766 { "-", "Sub" },
767 { "+=", "AddTo" },
768 { "-=", "SubFrom" },
769 { "*", "Mult" },
770 { "*=", "MultBy" },
771 { "/", "Div" },
772 { "/=", "DivBy" },
773 { "%", "Modulo" },
774 { "==", "IsEq" },
775 { "!=", "IsNEq" },
776 { "<", "IsLT" },
777 { ">", "IsGT" },
778 { "<=", "IsLEq" },
779 { ">=", "IsGEq" },
780 { "new", "New" },
781 { "delete", "Del" },
782 { "^", "Exp" },
783 { "&", "And" },
784 { "|", "Or" },
785 { "~", "Xor" },
786 { "!", "Not" },
787 { "=", "Copy" },
788 { "%=", "ModBy" },
789 { "^=", "ExpBy" },
790 { "&=", "AndBy" },
791 { "|=", "OrBy" },
792 { "<<", "ShiftLeft" },
793 { ">>", "ShiftRight" },
794 { ">>=", "ShiftRightBy" },
795 { "<<=", "ShiftLeftBy" },
796 { "&&", "AndIs" },
797 { "||", "OrIs" },
798 { "++", "Inc" },
799 { "--", "Dec" },
800 { ",", "FuckIfIKnow" },
801 { "->*", "FuckIfIKnow" },
802 { "->", "Indirect" },
803 { "()", "Invoke" },
804 { "[]", "GetEl" },
805 };
806
807 #define NUM_OP_NAMES (sizeof(opNames) / sizeof(opNames[0]))
808
809 size_t op;
810 for (op = 0; op < NUM_OP_NAMES; op++) {
811 if (name == opNames[op][0]) {
812 name = opNames[op][1];
813 break;
814 }
815 }
816 if (op == NUM_OP_NAMES)
817 name = "UnknownOperator";
818 }
819
820 else {
821 SbString n = "operator ";
822 n += name.getString();
823 name = n;
824 }
825 i = j;
826 }
827 }
828
829 // Save the stuff before and after the name
830 if (i > 0)
831 pre = full.getSubString(0, i).getString();
832 post = full.getSubString(endOfName + 1).getString();
833
834 // Figure out whether it is static, virtual, friend
835 const char *s = pre.getString();
836
837 while (TRUE) {
838 while (isspace(*s))
839 s++;
840
841 if (strlen(s) > 6 && ! strncmp(s, "static", 6) && isspace(s[6])) {
842 isStatic = TRUE;
843 s += 7;
844 }
845 else if (strlen(s) > 6 && ! strncmp(s, "friend", 6) && isspace(s[6])) {
846 isFriend = TRUE;
847 s += 7;
848 }
849 else if (strlen(s) > 6 && ! strncmp(s, "hidden", 6) && isspace(s[6])) {
850 isHidden = TRUE;
851 s += 7;
852 }
853 else if (strlen(s) > 7 && ! strncmp(s, "virtual",7) && isspace(s[7])) {
854 isVirtual = TRUE;
855 s += 8;
856 }
857 else
858 break;
859 }
860 // Remove stuff we just found
861 pre = s;
862
863 // Figure out whether it is const
864 s = post.getString() + post.getLength() - 1;
865
866 while (s >= post.getString() && isspace(*s))
867 s--;
868
869 if (s - post.getString() >= 4 && ! strncmp(s - 4, "const", 5)) {
870 isConst = TRUE;
871 post.deleteSubString((s - post.getString()) - 4);
872 }
873
874 // Clean up pre and post
875 Reader::cleanString(pre, TRUE, FALSE);
876 Reader::cleanString(post, TRUE);
877
878 // Deal with the C method name. If it is "", it is the same as the
879 // regular name, with the first character capitalized.
880 if (Writer::getLanguage() == C) {
881 if (! cName ) {
882 // Leave cName empty if this is a constructor/destructor:
883 if (type != CONSTRUCTOR && type != DESTRUCTOR) {
884 SbString n;
885 char startChar[2];
886 startChar[0] = toupper(name.getString()[0]);
887 startChar[1] = '\0';
888 n = startChar;
889 n += name.getString() + 1;
890 cName = n;
891 }
892 }
893
894 // Otherwise, convert first character to upper case if necessary
895 else if (islower(cName.getString()[0])) {
896 SbString n;
897 char startChar[2];
898 startChar[0] = toupper(cName.getString()[0]);
899 startChar[1] = '\0';
900 n = startChar;
901 n += cName.getString() + 1;
902 cName = n;
903 }
904
905 // If it is just white space, this method should be ignored in C
906 else {
907 for (s = cName.getString(); *s!= '\0'; s++)
908 if (! isspace(*s))
909 break;
910 if (*s == '\0')
911 language = C_PLUS_PLUS;
912 }
913 }
914
915 return TRUE;
916 }
917
918 void
919 Method::write(SbBool runIn)
920 {
921 if (runIn) {
922 Writer::setFont(Writer::CODE_ROMAN);
923 writeName();
924 if (hasNextToWrite())
925 Writer::write(", ");
926 else
927 Writer::write("\n");
928 }
929 else {
930 Writer::indentForTab();
931 Writer::setFont(Writer::CODE_ROMAN);
932
933 //
934 // Stuff before name
935 //
936
937 if (Writer::getLanguage() == C) {
938 if (type == CONSTRUCTOR) {
939 Writer::write(ClassDef::getCurClass()->getName());
940 Writer::write(" *");
941 }
942 else if (type == DESTRUCTOR)
943 Writer::write("void");
944 }
945 else {
946 if (isStatic)
947 Writer::write("static ");
948 if (isVirtual)
949 Writer::write("virtual ");
950 if (isFriend)
951 Writer::write("friend ");
952 }
953
954 Writer::write(pre);
955 Writer::tab();
956 Writer::setFont(Writer::CODE_BOLD);
957
958 //
959 // Name
960 //
961
962 writeName();
963
964 //
965 // Stuff after name
966 //
967
968 Writer::setFont(Writer::CODE_ROMAN);
969
970 if (Writer::getLanguage() == C) {
971 // Assume first character of "post" is the open paren. If this
972 // is not a static method, add a "this" argument as the first
973 // one. Make it a const pointer if the method is const.
974 if (isStatic || type == CONSTRUCTOR)
975 Writer::write(post);
976 else {
977 Writer::write("(");
978 if (isConst)
979 Writer::write("const ");
980 Writer::write(ClassDef::getCurClass()->getCPrefix());
981 if (post.getString()[1] == ')')
982 Writer::write(" *this");
983 else
984 Writer::write(" *this, ");
985 Writer::write(post.getString() + 1);
986 }
987 }
988
989 else
990 Writer::write(post);
991
992
993 if (Writer::getLanguage() == C_PLUS_PLUS && isConst)
994 Writer::write(" const");
995 Writer::write("\n");
996
997 // Write the description only if we're not writing the synopsis
998 // and there is a non-empty description:
999 if (! Writer::getInSynopsis() && ! ! description)
1000 Writer::writeDescription(description);
1001
1002 else {
1003 if (hasNextToWrite())
1004 Writer::breakLine();
1005 else
1006 Writer::space();
1007 }
1008 }
1009 }
1010
1011 void
1012 Method::writeName()
1013 {
1014 if (Writer::getLanguage() == C) {
1015 Writer::write(ClassDef::getCurClass()->getCPrefix());
1016 if (type == CONSTRUCTOR && !cName)
1017 Writer::write("Create");
1018 else if (type == DESTRUCTOR && !cName)
1019 Writer::write("Delete");
1020 else
1021 Writer::write(cName);
1022 }
1023
1024 else
1025 Writer::write(name);
1026 }
1027
1028 int
1029 Method::getNumPreTabChars() const
1030 {
1031 int num = 0;
1032
1033 if (Writer::getLanguage() == C) {
1034 if (type == CONSTRUCTOR)
1035 num += ClassDef::getCurClass()->getName().getLength() + 2; // "* "
1036 else if (type == DESTRUCTOR)
1037 num += 4; // "void"
1038 }
1039 else {
1040 if (isStatic)
1041 num += strlen("static ");
1042 if (isVirtual)
1043 num += strlen("virtual ");
1044 if (isFriend)
1045 num += strlen("friend ");
1046 }
1047
1048 return num + pre.getLength();
1049 }
1050
1051 /////////////////////////////////////////////////////////////////////////////
1052 //
1053 // Class: Macro
1054 //
1055 /////////////////////////////////////////////////////////////////////////////
1056
1057 SbBool
1058 Macro::read()
1059 {
1060 if (! Reader::readName(name) ||
1061 ! Reader::readUpTo(OPEN_CHAR, arguments) ||
1062 ! Reader::readBracketed(description)) {
1063 Reader::error("MACRO spec");
1064 return FALSE;
1065 }
1066
1067 return TRUE;
1068 }
1069
1070 void
1071 Macro::write(SbBool runIn)
1072 {
1073 if (runIn) {
1074 Writer::setFont(Writer::CODE_ROMAN);
1075 Writer::write(name);
1076 if (hasNextToWrite())
1077 Writer::write(", ");
1078 else
1079 Writer::write("\n");
1080 }
1081 else {
1082 Writer::setFont(Writer::CODE_BOLD);
1083
1084 // The name may contain an openParen and part of the first argument.
1085 // Strip the name off the front and write the rest with the arguments.
1086 const char *n = name.getString();
1087 char *c = (char *)n;
1088 int len = strlen(n);
1089 int i;
1090 for (i=0; i<len; c++, i++) {
1091 if (*c == '(') {
1092
1093 // Found a paren. Change the paren to an end of string
1094 // character, write out the name, change the paren back
1095 // and write the rest of the name out.
1096 *c = '\0';
1097 Writer::write(n);
1098 *c = '(';
1099 Writer::write(c);
1100 Writer::write(" ");
1101 break;
1102 }
1103 }
1104 if (i == len)
1105 Writer::write(name);
1106
1107 Writer::setFont(Writer::CODE_ROMAN);
1108 Writer::write(arguments);
1109 Writer::write("\n");
1110
1111 // Write the description only if we're not writing the synopsis
1112 // and there is a non-empty description:
1113 if (! Writer::getInSynopsis() && ! ! description)
1114 Writer::writeDescription(description);
1115
1116 else {
1117 if (hasNextToWrite())
1118 Writer::breakLine();
1119 else
1120 Writer::space();
1121 }
1122 }
1123 }
1124
1125 /////////////////////////////////////////////////////////////////////////////
1126 //
1127 // Class: ActionName
1128 //
1129 /////////////////////////////////////////////////////////////////////////////
1130
1131 SbBool
1132 ActionName::read()
1133 {
1134 if (! Reader::readName(name)) {
1135 Reader::error("ACTION name");
1136 return FALSE;
1137 }
1138 return TRUE;
1139 }
1140
1141 void
1142 ActionName::write(SbBool)
1143 {
1144 Writer::write(name);
1145 if (hasNextToWrite())
1146 Writer::write(", ");
1147 else
1148 Writer::write("\n");
1149 }
1150
1151 /////////////////////////////////////////////////////////////////////////////
1152 //
1153 // Class: Action
1154 //
1155 /////////////////////////////////////////////////////////////////////////////
1156
1157 SbBool
1158 Action::read()
1159 {
1160 ActionName *name;
1161 int c;
1162
1163 while (TRUE) {
1164
1165 // Read action names. There has to be at least 1.
1166 name = new ActionName;
1167 if (! name->read())
1168 return FALSE;
1169 names.add(name);
1170
1171 // See if the list is ending
1172 Reader::skipWhiteSpace();
1173 if ((c = Reader::get()) != SEP_CHAR) {
1174 Reader::putBack(c);
1175 break;
1176 }
1177 }
1178
1179 if (! Reader::readBracketed(description)) {
1180 Reader::error("ACTION description");
1181 return FALSE;
1182 }
1183
1184 return TRUE;
1185 }
1186
1187 void
1188 Action::write(SbBool)
1189 {
1190 Writer::setFont(Writer::CODE_BOLD);
1191 names.write();
1192 Writer::writeDescription(description);
1193 }
1194
1195 /////////////////////////////////////////////////////////////////////////////
1196 //
1197 // Class: Misc
1198 //
1199 /////////////////////////////////////////////////////////////////////////////
1200
1201 SbBool
1202 Misc::read()
1203 {
1204 return (Reader::readName(name) &&
1205 Reader::readBracketed(description));
1206 }
1207
1208 void
1209 Misc::write(SbBool)
1210 {
1211 Writer::startSection(name.getString());
1212 Writer::writeBracketed(description);
1213 }
1214
1215 /////////////////////////////////////////////////////////////////////////////
1216 //
1217 // Class: Also
1218 //
1219 /////////////////////////////////////////////////////////////////////////////
1220
1221 SbBool
1222 Also::read()
1223 {
1224 if (! Reader::readBracketed(list)) {
1225 Reader::error("ALSO list");
1226 return FALSE;
1227 }
1228 return TRUE;
1229 }
1230
1231 void
1232 Also::write(SbBool)
1233 {
1234 if (! Writer::isForBook())
1235 Writer::setFont(Writer::CODE_BOLD);
1236 Writer::writeBracketed(list);
1237 Writer::write("\n");
1238 }
1239
1240 /////////////////////////////////////////////////////////////////////////////
1241 //
1242 // Class: DraggerResource
1243 //
1244 /////////////////////////////////////////////////////////////////////////////
1245
1246 const SbName &
1247 DraggerResource::getPartDefName(int which) const
1248 {
1249 DraggerResourcePartDef *p = (DraggerResourcePartDef *) parts.first;
1250 int curNum = 0;
1251 while( p != NULL && curNum < which) {
1252 p = (DraggerResourcePartDef *) p->next;
1253 curNum++;
1254 }
1255 if (p)
1256 return p->name;
1257 else {
1258 fprintf(stderr,"Error getting the %dth part that uses the dragger\n",
1259 which);
1260 fprintf(stderr,"resource name %s\n", name.getString());
1261 }
1262 static SbName empty("");
1263 return empty;
1264 }
1265
1266 SbBool
1267 DraggerResource::read()
1268 {
1269 // Read name, description pairs within braces
1270 Reader::skipWhiteSpace();
1271 if (Reader::get() != OPEN_CHAR) {
1272 Reader::error("DRAGGER RESOURCE");
1273 return FALSE;
1274 }
1275
1276 // Read one resource name, followed by the sep char
1277 if (! Reader::readName(name)) {
1278 Reader::error("DRAGGER RESOURCE DraggerResource::name");
1279 return FALSE;
1280 }
1281 if (Reader::get() != SEP_CHAR) {
1282 Reader::error("DRAGGER RESOURCE name needs comma after it");
1283 return FALSE;
1284 }
1285
1286 // Read one or more parts, followed by sep char
1287 while (TRUE) {
1288 int c;
1289
1290 // Read the next definition pair. There has to be at least 1.
1291 DraggerResourcePartDef *part = new DraggerResourcePartDef;
1292 if (! part->read())
1293 return FALSE;
1294 parts.add(part);
1295
1296 // List ends with SEP_CHAR
1297 Reader::skipWhiteSpace();
1298 if ((c = Reader::get()) == SEP_CHAR)
1299 break;
1300 else
1301 Reader::putBack(c);
1302 }
1303
1304 // Read one default geometry (appearance), followed by sep char
1305 if (! Reader::readString(defaultGeom)) {
1306 Reader::error("DRAGGER RESOURCE DraggerResource::defaultGeom");
1307 return FALSE;
1308 }
1309 if (Reader::get() != SEP_CHAR) {
1310 Reader::error("DRAGGER RESOURCE defaultGeom needs comma after it");
1311 return FALSE;
1312 }
1313
1314 // Read one description.
1315 if (! Reader::readString(description)) {
1316 Reader::error("DRAGGER RESOURCE DraggerResource::description");
1317 return FALSE;
1318 }
1319
1320 // That should be it.
1321 Reader::skipWhiteSpace();
1322 if (Reader::get() != CLOSE_CHAR) {
1323 Reader::error("DRAGGER RESOURCE missing close character");
1324 return FALSE;
1325 }
1326
1327 return TRUE;
1328 }
1329
1330 void
1331 DraggerResource::write(SbBool)
1332 {
1333 Writer::setFont(Writer::TEXT_ROMAN);
1334
1335 Writer::setIndent(0, 0);
1336 Writer::setTab(18);
1337 Writer::write("Resource:");
1338 Writer::tab();
1339 Writer::setFont(Writer::CODE_BOLD);
1340 Writer::write(name);
1341 Writer::write("\n");
1342 Writer::breakLine();
1343
1344 Writer::setFont(Writer::TEXT_ROMAN);
1345 Writer::setIndent(0, 0);
1346 Writer::setTab(18);
1347 if (parts.getNum() == 1)
1348 Writer::write("Part:");
1349 else Writer::write("Parts:");
1350 parts.write();
1351
1352 Writer::setIndent(0, 0);
1353 Writer::setTab(18);
1354 Writer::write("Appearance:");
1355 Writer::tab();
1356 Writer::writeBracketed(defaultGeom);
1357 Writer::breakLine();
1358
1359 Writer::setIndent(20, 0);
1360 Writer::setTab(18);
1361 Writer::write("Description:");
1362 Writer::tab();
1363 Writer::writeBracketed(description);
1364 Writer::space();
1365 }
1366
1367 int
1368 DraggerResource::getNumPreTabChars() const
1369 {
1370 // Return the length of the longest word between
1371 // Resource, Part, Description, and Appearance.
1372 return strlen("Description:");
1373 }
1374
1375 DraggerResource::DraggerResource() {} // quiet the compiler
1376
1377 /////////////////////////////////////////////////////////////////////////////
1378 //
1379 // Class: DraggerResourcePartDef
1380 //
1381 /////////////////////////////////////////////////////////////////////////////
1382
1383 SbBool
1384 DraggerResourcePartDef::read()
1385 {
1386 if (! Reader::readName(name)) {
1387 Reader::error("DRAGGER RESOURCE DraggerResourcePartDef::name");
1388 return FALSE;
1389 }
1390 return TRUE;
1391 }
1392
1393 void
1394 DraggerResourcePartDef::write(SbBool)
1395 {
1396 Writer::tab();
1397 Writer::write(name);
1398 Writer::write("\n");
1399 Writer::breakLine();
1400 }