/usr/share/doc/cxref-doc/examples/latex.c.src.html is in cxref-doc 1.6e-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- This HTML file generated by cxref (version 1.6e). -->
<!-- cxref program (c) Andrew M. Bishop 1995-2014. -->
<!--
Cxref: ./cxref -warn-xref -xref -O../doc/example -Ncxref -latex -html-src -rtf -sgml latex.c
CPP : /build/cxref-rFY1Z7/cxref-1.6e/cpp/cxref-cpp -cxref-cpp-defines /build/cxref-rFY1Z7/cxref-1.6e/cpp/cxref-cpp.defines -lang-c -C -dD -dI
-->
<HTML>
<HEAD>
<TITLE>Source File latex.c</TITLE>
<LINK rel="stylesheet" href="cxref.css" type="text/css">
</HEAD>
<BODY>
<pre>
<a name="line1">1 |</a> /***************************************
<a name="line2">2 |</a> $Header: /home/amb/CVS/cxref/src/latex.c,v 1.40 2004-06-26 18:50:36 amb Exp $
<a name="line3">3 |</a>
<a name="line4">4 |</a> C Cross Referencing & Documentation tool. Version 1.6.
<a name="line5">5 |</a>
<a name="line6">6 |</a> Writes the Latex output.
<a name="line7">7 |</a> ******************/ /******************
<a name="line8">8 |</a> Written by Andrew M. Bishop
<a name="line9">9 |</a>
<a name="line10">10 |</a> This file Copyright 1995,96,97,98,2001,04 Andrew M. Bishop
<a name="line11">11 |</a> It may be distributed under the GNU Public License, version 2, or
<a name="line12">12 |</a> any higher version. See section COPYING of the GNU Public license
<a name="line13">13 |</a> for conditions under which this file may be redistributed.
<a name="line14">14 |</a> ***************************************/
<a name="line15">15 |</a>
<a name="line16">16 |</a> #include <stdlib.h>
<a name="line17">17 |</a> #include <stdio.h>
<a name="line18">18 |</a> #include <string.h>
<a name="line19">19 |</a> #include <sys/types.h>
<a name="line20">20 |</a> #include <sys/stat.h>
<a name="line21">21 |</a> #include <unistd.h>
<a name="line22">22 |</a>
<a name="line23">23 |</a> #ifndef min
<a name="line24">24 |</a> #define min(x,y) ( (x) < (y) ? (x) : (y) )
<a name="line25">25 |</a> #endif
<a name="line26">26 |</a>
<a name="line27">27 |</a> #include "version.h"
<a name="line28">28 |</a> #include "memory.h"
<a name="line29">29 |</a> #include "datatype.h"
<a name="line30">30 |</a> #include "cxref.h"
<a name="line31">31 |</a>
<a name="line32">32 |</a> /*+ The name of the output tex file that includes each of the others. +*/
<a name="line33">33 |</a> #define LATEX_FILE ".tex"
<a name="line34">34 |</a> #define LATEX_FILE_BACKUP ".tex~"
<a name="line35">35 |</a>
<a name="line36">36 |</a> /*+ The name of the output tex file that contains the appendix. +*/
<a name="line37">37 |</a> #define LATEX_APDX ".apdx"
<a name="line38">38 |</a>
<a name="line39">39 |</a> /*+ The comments are to be inserted verbatim. +*/
<a name="line40">40 |</a> extern int option_verbatim_comments;
<a name="line41">41 |</a>
<a name="line42">42 |</a> /*+ The name of the directory for the output. +*/
<a name="line43">43 |</a> extern char* option_odir;
<a name="line44">44 |</a>
<a name="line45">45 |</a> /*+ The base name of the file for the output. +*/
<a name="line46">46 |</a> extern char* option_name;
<a name="line47">47 |</a>
<a name="line48">48 |</a> /*+ The information about the cxref run, +*/
<a name="line49">49 |</a> extern char *run_command, /*+ the command line options. +*/
<a name="line50">50 |</a> *run_cpp_command; /*+ the cpp command and options. +*/
<a name="line51">51 |</a>
<a name="line52">52 |</a> /*+ The built-in style sheets. +*/
<a name="line53">53 |</a> extern char *latex_fonts_style,*latex_page_style,*latex_cxref_style;
<a name="line54">54 |</a>
<a name="line55">55 |</a> /* Local functions */
<a name="line56">56 |</a>
<a name="line57">57 |</a> static void WriteLatexFilePart(File file);
<a name="line58">58 |</a> static void WriteLatexInclude(Include inc);
<a name="line59">59 |</a> static void WriteLatexSubInclude(Include inc,int depth);
<a name="line60">60 |</a> static void WriteLatexDefine(Define def);
<a name="line61">61 |</a> static void WriteLatexTypedef(Typedef type);
<a name="line62">62 |</a> static void WriteLatexStructUnion(StructUnion su,int depth);
<a name="line63">63 |</a> static void WriteLatexVariable(Variable var);
<a name="line64">64 |</a> static void WriteLatexFunction(Function func);
<a name="line65">65 |</a>
<a name="line66">66 |</a> static void WriteLatexDocument(char* name,int appendix);
<a name="line67">67 |</a> static void WriteLatexTemplate(char* name);
<a name="line68">68 |</a>
<a name="line69">69 |</a> static char* latex(char* c,int verbatim);
<a name="line70">70 |</a>
<a name="line71">71 |</a> /*+ The output file for the latex. +*/
<a name="line72">72 |</a> static FILE* of;
<a name="line73">73 |</a>
<a name="line74">74 |</a> /*+ The name of the file. +*/
<a name="line75">75 |</a> static char *filename;
<a name="line76">76 |</a>
<a name="line77">77 |</a> /*+ Counts the lines in a table to insert breaks. +*/
<a name="line78">78 |</a> static int countlines=0;
<a name="line79">79 |</a>
<a name="line80">80 |</a>
<a name="line81">81 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line82">82 |</a> Write a Latex file for a complete File structure and all components.
<a name="line83">83 |</a>
<a name="line84">84 |</a> File file The File structure to output.
<a name="line85">85 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line86">86 |</a>
<a name="line87">87 |</a> void WriteLatexFile(File file)
<a name="line88">88 |</a> {
<a name="line89">89 |</a> char* ofile;
<a name="line90">90 |</a>
<a name="line91">91 |</a> filename=file->name;
<a name="line92">92 |</a>
<a name="line93">93 |</a> /* Write the including file. */
<a name="line94">94 |</a>
<a name="line95">95 |</a> WriteLatexDocument(file->name,0);
<a name="line96">96 |</a>
<a name="line97">97 |</a> /* Open the file */
<a name="line98">98 |</a>
<a name="line99">99 |</a> ofile=ConcatStrings(4,option_odir,"/",file->name,LATEX_FILE);
<a name="line100">100 |</a>
<a name="line101">101 |</a> of=fopen(ofile,"w");
<a name="line102">102 |</a> if(!of)
<a name="line103">103 |</a> {
<a name="line104">104 |</a> struct stat stat_buf;
<a name="line105">105 |</a> int i,ofl=strlen(ofile);
<a name="line106">106 |</a>
<a name="line107">107 |</a> for(i=strlen(option_odir)+1;i<ofl;i++)
<a name="line108">108 |</a> if(ofile[i]=='/')
<a name="line109">109 |</a> {
<a name="line110">110 |</a> ofile[i]=0;
<a name="line111">111 |</a> if(stat(ofile,&stat_buf))
<a name="line112">112 |</a> mkdir(ofile,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
<a name="line113">113 |</a> ofile[i]='/';
<a name="line114">114 |</a> }
<a name="line115">115 |</a>
<a name="line116">116 |</a> of=fopen(ofile,"w");
<a name="line117">117 |</a> }
<a name="line118">118 |</a>
<a name="line119">119 |</a> if(!of)
<a name="line120">120 |</a> {fprintf(stderr,"cxref: Failed to open the LaTeX output file '%s'\n",ofile);exit(1);}
<a name="line121">121 |</a>
<a name="line122">122 |</a> /* Write out a header. */
<a name="line123">123 |</a>
<a name="line124">124 |</a> fputs("% This LaTeX file generated by cxref (version " CXREF_VERSION ").\n",of);
<a name="line125">125 |</a> fputs("% cxref program " CXREF_COPYRIGHT ".\n",of);
<a name="line126">126 |</a> fputs("\n",of);
<a name="line127">127 |</a> fprintf(of,"%% Cxref: %s %s\n",run_command,file->name);
<a name="line128">128 |</a> fprintf(of,"%% CPP : %s\n",run_cpp_command);
<a name="line129">129 |</a> fputs("\n",of);
<a name="line130">130 |</a>
<a name="line131">131 |</a> /*+ The file structure is broken into its components and they are each written out. +*/
<a name="line132">132 |</a>
<a name="line133">133 |</a> WriteLatexFilePart(file);
<a name="line134">134 |</a>
<a name="line135">135 |</a> if(file->includes)
<a name="line136">136 |</a> {
<a name="line137">137 |</a> Include inc =file->includes;
<a name="line138">138 |</a> fprintf(of,"\n\\subsection*{Included Files}\n\n");
<a name="line139">139 |</a> do{
<a name="line140">140 |</a> if(inc!=file->includes)
<a name="line141">141 |</a> fprintf(of,"\\medskip\n");
<a name="line142">142 |</a> WriteLatexInclude(inc);
<a name="line143">143 |</a> }
<a name="line144">144 |</a> while((inc=inc->next));
<a name="line145">145 |</a> }
<a name="line146">146 |</a>
<a name="line147">147 |</a> if(file->defines)
<a name="line148">148 |</a> {
<a name="line149">149 |</a> Define def =file->defines;
<a name="line150">150 |</a> fprintf(of,"\n\\subsection*{Preprocessor definitions}\n\n");
<a name="line151">151 |</a> do{
<a name="line152">152 |</a> if(def!=file->defines)
<a name="line153">153 |</a> fprintf(of,"\\medskip\n");
<a name="line154">154 |</a> WriteLatexDefine(def);
<a name="line155">155 |</a> }
<a name="line156">156 |</a> while((def=def->next));
<a name="line157">157 |</a> }
<a name="line158">158 |</a>
<a name="line159">159 |</a> if(file->typedefs)
<a name="line160">160 |</a> {
<a name="line161">161 |</a> Typedef type=file->typedefs;
<a name="line162">162 |</a> fprintf(of,"\n\\subsection{Type definitions}\n\n");
<a name="line163">163 |</a> do{
<a name="line164">164 |</a> WriteLatexTypedef(type);
<a name="line165">165 |</a> }
<a name="line166">166 |</a> while((type=type->next));
<a name="line167">167 |</a> }
<a name="line168">168 |</a>
<a name="line169">169 |</a> if(file->variables)
<a name="line170">170 |</a> {
<a name="line171">171 |</a> int any_to_mention=0;
<a name="line172">172 |</a> Variable var=file->variables;
<a name="line173">173 |</a>
<a name="line174">174 |</a> do{
<a name="line175">175 |</a> if(var->scope&(GLOBAL|LOCAL|EXTERNAL|EXTERN_F))
<a name="line176">176 |</a> any_to_mention=1;
<a name="line177">177 |</a> }
<a name="line178">178 |</a> while((var=var->next));
<a name="line179">179 |</a>
<a name="line180">180 |</a> if(any_to_mention)
<a name="line181">181 |</a> {
<a name="line182">182 |</a> int first_ext=1,first_local=1;
<a name="line183">183 |</a> Variable var=file->variables;
<a name="line184">184 |</a> fprintf(of,"\n\\subsection{Variables}\n\n");
<a name="line185">185 |</a> do{
<a name="line186">186 |</a> if(var->scope&GLOBAL)
<a name="line187">187 |</a> WriteLatexVariable(var);
<a name="line188">188 |</a> }
<a name="line189">189 |</a> while((var=var->next));
<a name="line190">190 |</a> var=file->variables;
<a name="line191">191 |</a> do{
<a name="line192">192 |</a> if(var->scope&(EXTERNAL|EXTERN_F) && !(var->scope&GLOBAL))
<a name="line193">193 |</a> {
<a name="line194">194 |</a> if(first_ext)
<a name="line195">195 |</a> {fprintf(of,"\n\\subsubsection{External Variables}\n\n"); first_ext=0;}
<a name="line196">196 |</a> else
<a name="line197">197 |</a> fprintf(of,"\\medskip\n");
<a name="line198">198 |</a> WriteLatexVariable(var);
<a name="line199">199 |</a> }
<a name="line200">200 |</a> }
<a name="line201">201 |</a> while((var=var->next));
<a name="line202">202 |</a> var=file->variables;
<a name="line203">203 |</a> do{
<a name="line204">204 |</a> if(var->scope&LOCAL)
<a name="line205">205 |</a> {
<a name="line206">206 |</a> if(first_local)
<a name="line207">207 |</a> {fprintf(of,"\n\\subsubsection{Local Variables}\n\n"); first_local=0;}
<a name="line208">208 |</a> else
<a name="line209">209 |</a> fprintf(of,"\\medskip\n");
<a name="line210">210 |</a> WriteLatexVariable(var);
<a name="line211">211 |</a> }
<a name="line212">212 |</a> }
<a name="line213">213 |</a> while((var=var->next));
<a name="line214">214 |</a> }
<a name="line215">215 |</a> }
<a name="line216">216 |</a>
<a name="line217">217 |</a> if(file->functions)
<a name="line218">218 |</a> {
<a name="line219">219 |</a> Function func=file->functions;
<a name="line220">220 |</a> fprintf(of,"\n\\subsection{Functions}\n\n");
<a name="line221">221 |</a> do{
<a name="line222">222 |</a> if(func->scope&(GLOBAL|EXTERNAL))
<a name="line223">223 |</a> WriteLatexFunction(func);
<a name="line224">224 |</a> }
<a name="line225">225 |</a> while((func=func->next));
<a name="line226">226 |</a> func=file->functions;
<a name="line227">227 |</a> do{
<a name="line228">228 |</a> if(func->scope&LOCAL)
<a name="line229">229 |</a> WriteLatexFunction(func);
<a name="line230">230 |</a> }
<a name="line231">231 |</a> while((func=func->next));
<a name="line232">232 |</a> }
<a name="line233">233 |</a>
<a name="line234">234 |</a> fclose(of);
<a name="line235">235 |</a>
<a name="line236">236 |</a> /* Clear the memory in latex() */
<a name="line237">237 |</a>
<a name="line238">238 |</a> latex(NULL,0); latex(NULL,0); latex(NULL,0); latex(NULL,0);
<a name="line239">239 |</a> }
<a name="line240">240 |</a>
<a name="line241">241 |</a>
<a name="line242">242 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line243">243 |</a> Write a File structure out.
<a name="line244">244 |</a>
<a name="line245">245 |</a> File file The File to output.
<a name="line246">246 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line247">247 |</a>
<a name="line248">248 |</a> static void WriteLatexFilePart(File file)
<a name="line249">249 |</a> {
<a name="line250">250 |</a> int i;
<a name="line251">251 |</a>
<a name="line252">252 |</a> fprintf(of,"\\markboth{File %s}{File %s}\n",latex(file->name,0),latex(file->name,0));
<a name="line253">253 |</a> fprintf(of,"\\section{File %s}\n",latex(file->name,0));
<a name="line254">254 |</a> fprintf(of,"\\label{file_%s}\n\n",file->name);
<a name="line255">255 |</a>
<a name="line256">256 |</a> if(file->comment)
<a name="line257">257 |</a> {
<a name="line258">258 |</a> if(option_verbatim_comments)
<a name="line259">259 |</a> fprintf(of,"\\begin{verbatim}\n%s\n\\end{verbatim}\n\n",latex(file->comment,1));
<a name="line260">260 |</a> else
<a name="line261">261 |</a> {
<a name="line262">262 |</a> char *rcs1=strstr(file->comment,"$Header"),*rcs2=NULL;
<a name="line263">263 |</a> if(rcs1)
<a name="line264">264 |</a> {
<a name="line265">265 |</a> rcs2=strstr(&rcs1[1],"$");
<a name="line266">266 |</a> if(rcs2)
<a name="line267">267 |</a> {
<a name="line268">268 |</a> rcs2[0]=0;
<a name="line269">269 |</a> fprintf(of,"{\\bf RCS %s}\n\n",latex(&rcs1[1],0));
<a name="line270">270 |</a> fprintf(of,"\\smallskip\n");
<a name="line271">271 |</a> rcs2[0]='$';
<a name="line272">272 |</a> }
<a name="line273">273 |</a> }
<a name="line274">274 |</a> if(rcs2)
<a name="line275">275 |</a> fprintf(of,"%s\n\n",latex(&rcs2[2],0));
<a name="line276">276 |</a> else
<a name="line277">277 |</a> fprintf(of,"%s\n\n",latex(file->comment,0));
<a name="line278">278 |</a> }
<a name="line279">279 |</a> }
<a name="line280">280 |</a>
<a name="line281">281 |</a> if(file->inc_in->n)
<a name="line282">282 |</a> {
<a name="line283">283 |</a> int i;
<a name="line284">284 |</a>
<a name="line285">285 |</a> if(file->comment)
<a name="line286">286 |</a> fprintf(of,"\\medskip\n");
<a name="line287">287 |</a> fprintf(of,"\\begin{cxreftabii}\nIncluded in:");
<a name="line288">288 |</a> for(i=0;i<file->inc_in->n;i++)
<a name="line289">289 |</a> {/* Allow a break in every 8 (or so) items to allow the table to break over the page. */
<a name="line290">290 |</a> if(min(i,file->inc_in->n-i)%8 == 4)
<a name="line291">291 |</a> fprintf(of,"\\cxreftabbreak{cxreftabii}\n");
<a name="line292">292 |</a> fprintf(of,"\\ & %s & \\cxreffile{%s}\\\\\n",latex(file->inc_in->s[i],0),file->inc_in->s[i]);
<a name="line293">293 |</a> }
<a name="line294">294 |</a> fprintf(of,"\\end{cxreftabii}\n\n");
<a name="line295">295 |</a> }
<a name="line296">296 |</a>
<a name="line297">297 |</a> if(file->f_refs->n || file->v_refs->n)
<a name="line298">298 |</a> {
<a name="line299">299 |</a> int tabcount=0;
<a name="line300">300 |</a> fprintf(of,"\\smallskip\n");
<a name="line301">301 |</a> fprintf(of,"\\begin{cxreftabiii}\n");
<a name="line302">302 |</a>
<a name="line303">303 |</a> if(file->f_refs->n)
<a name="line304">304 |</a> {
<a name="line305">305 |</a> int others=0;
<a name="line306">306 |</a>
<a name="line307">307 |</a> fprintf(of,"Refs Func:");
<a name="line308">308 |</a>
<a name="line309">309 |</a> for(i=0;i<file->f_refs->n;i++)
<a name="line310">310 |</a> if(file->f_refs->s2[i])
<a name="line311">311 |</a> {
<a name="line312">312 |</a> fprintf(of,"\\ & %s() & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(file->f_refs->s1[i],0),latex(file->f_refs->s2[i],0),file->f_refs->s1[i],file->f_refs->s2[i]);
<a name="line313">313 |</a> if(++tabcount%8 == 4)
<a name="line314">314 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line315">315 |</a> }
<a name="line316">316 |</a> else
<a name="line317">317 |</a> others++;
<a name="line318">318 |</a>
<a name="line319">319 |</a> if(others)
<a name="line320">320 |</a> {
<a name="line321">321 |</a> fprintf(of,"\\ & \\cxreftabiiispan{");
<a name="line322">322 |</a> for(i=0;i<file->f_refs->n;i++)
<a name="line323">323 |</a> if(!file->f_refs->s2[i])
<a name="line324">324 |</a> fprintf(of,--others?"%s(), ":"%s()",latex(file->f_refs->s1[i],0));
<a name="line325">325 |</a> fprintf(of,"} &\\\\\n");
<a name="line326">326 |</a> }
<a name="line327">327 |</a> }
<a name="line328">328 |</a>
<a name="line329">329 |</a> if(file->v_refs->n)
<a name="line330">330 |</a> {
<a name="line331">331 |</a> int others=0;
<a name="line332">332 |</a>
<a name="line333">333 |</a> fprintf(of,"Refs Var:");
<a name="line334">334 |</a>
<a name="line335">335 |</a> for(i=0;i<file->v_refs->n;i++)
<a name="line336">336 |</a> if(file->v_refs->s2[i])
<a name="line337">337 |</a> {
<a name="line338">338 |</a> fprintf(of,"\\ & %s & %s & \\cxrefvar{%s}{%s}\\\\\n",latex(file->v_refs->s1[i],0),latex(file->v_refs->s2[i],0),file->v_refs->s1[i],file->v_refs->s2[i]);
<a name="line339">339 |</a> if(++tabcount%8 == 4)
<a name="line340">340 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line341">341 |</a> }
<a name="line342">342 |</a> else
<a name="line343">343 |</a> others++;
<a name="line344">344 |</a>
<a name="line345">345 |</a> if(others)
<a name="line346">346 |</a> {
<a name="line347">347 |</a> fprintf(of,"\\ & \\cxreftabiiispan{");
<a name="line348">348 |</a> for(i=0;i<file->v_refs->n;i++)
<a name="line349">349 |</a> if(!file->v_refs->s2[i])
<a name="line350">350 |</a> fprintf(of,--others?" %s,":" %s",latex(file->v_refs->s1[i],0));
<a name="line351">351 |</a> fprintf(of,"} &\\\\\n");
<a name="line352">352 |</a> }
<a name="line353">353 |</a> }
<a name="line354">354 |</a>
<a name="line355">355 |</a> fprintf(of,"\\end{cxreftabiii}\n\n");
<a name="line356">356 |</a> }
<a name="line357">357 |</a> }
<a name="line358">358 |</a>
<a name="line359">359 |</a>
<a name="line360">360 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line361">361 |</a> Write an Include structure out.
<a name="line362">362 |</a>
<a name="line363">363 |</a> Include inc The Include structure to output.
<a name="line364">364 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line365">365 |</a>
<a name="line366">366 |</a> static void WriteLatexInclude(Include inc)
<a name="line367">367 |</a> {
<a name="line368">368 |</a> if(inc->comment)
<a name="line369">369 |</a> fprintf(of,"%s\n\n\\smallskip\n",latex(inc->comment,0));
<a name="line370">370 |</a>
<a name="line371">371 |</a> fprintf(of,"\\begin{cxreftabi}\n"); countlines=1;
<a name="line372">372 |</a>
<a name="line373">373 |</a> if(inc->scope==LOCAL)
<a name="line374">374 |</a> fprintf(of,"{\\stt \\#include \"%s\"} &\\cxreffile{%s}\\\\\n",latex(inc->name,0),inc->name);
<a name="line375">375 |</a> else
<a name="line376">376 |</a> fprintf(of,"{\\stt \\#include <%s>} &\\\\\n",latex(inc->name,0));
<a name="line377">377 |</a>
<a name="line378">378 |</a> if(inc->includes)
<a name="line379">379 |</a> WriteLatexSubInclude(inc->includes,1);
<a name="line380">380 |</a>
<a name="line381">381 |</a> fprintf(of,"\\end{cxreftabi}\n\n");
<a name="line382">382 |</a> }
<a name="line383">383 |</a>
<a name="line384">384 |</a>
<a name="line385">385 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line386">386 |</a> Write an Sub Include structure out. (An include structure that is included from another file.)
<a name="line387">387 |</a>
<a name="line388">388 |</a> Include inc The Include structure to output.
<a name="line389">389 |</a>
<a name="line390">390 |</a> int depth The depth of the include hierarchy.
<a name="line391">391 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line392">392 |</a>
<a name="line393">393 |</a> static void WriteLatexSubInclude(Include inc,int depth)
<a name="line394">394 |</a> {
<a name="line395">395 |</a> while(inc)
<a name="line396">396 |</a> {
<a name="line397">397 |</a> if(countlines++%8==4)
<a name="line398">398 |</a> fprintf(of,"\\cxreftabbreak{cxreftabi}\n");
<a name="line399">399 |</a>
<a name="line400">400 |</a> fprintf(of,"\\hspace*{%3.1fin}",0.2*depth);
<a name="line401">401 |</a>
<a name="line402">402 |</a> if(inc->scope==LOCAL)
<a name="line403">403 |</a> fprintf(of,"{\\stt \\#include \"%s\"} &\\cxreffile{%s}\\\\\n",latex(inc->name,0),inc->name);
<a name="line404">404 |</a> else
<a name="line405">405 |</a> fprintf(of,"{\\stt \\#include <%s>} &\\\\\n",latex(inc->name,0));
<a name="line406">406 |</a>
<a name="line407">407 |</a> if(inc->includes)
<a name="line408">408 |</a> WriteLatexSubInclude(inc->includes,depth+1);
<a name="line409">409 |</a>
<a name="line410">410 |</a> inc=inc->next;
<a name="line411">411 |</a> }
<a name="line412">412 |</a> }
<a name="line413">413 |</a>
<a name="line414">414 |</a>
<a name="line415">415 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line416">416 |</a> Write a Define structure out.
<a name="line417">417 |</a>
<a name="line418">418 |</a> Define def The Define structure to output.
<a name="line419">419 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line420">420 |</a>
<a name="line421">421 |</a> static void WriteLatexDefine(Define def)
<a name="line422">422 |</a> {
<a name="line423">423 |</a> int i;
<a name="line424">424 |</a> int pargs=0;
<a name="line425">425 |</a>
<a name="line426">426 |</a> if(def->comment)
<a name="line427">427 |</a> fprintf(of,"%s\n\n\\smallskip\n",latex(def->comment,0));
<a name="line428">428 |</a>
<a name="line429">429 |</a> fprintf(of,"{\\stt \\#define %s",latex(def->name,0));
<a name="line430">430 |</a>
<a name="line431">431 |</a> if(def->value)
<a name="line432">432 |</a> fprintf(of," %s",latex(def->value,0));
<a name="line433">433 |</a>
<a name="line434">434 |</a> if(def->args->n)
<a name="line435">435 |</a> {
<a name="line436">436 |</a> fprintf(of,"( ");
<a name="line437">437 |</a> for(i=0;i<def->args->n;i++)
<a name="line438">438 |</a> fprintf(of,i?", %s":"%s",latex(def->args->s1[i],0));
<a name="line439">439 |</a> fprintf(of," )");
<a name="line440">440 |</a> }
<a name="line441">441 |</a> fprintf(of,"}\n\n");
<a name="line442">442 |</a>
<a name="line443">443 |</a> for(i=0;i<def->args->n;i++)
<a name="line444">444 |</a> if(def->args->s2[i])
<a name="line445">445 |</a> pargs=1;
<a name="line446">446 |</a>
<a name="line447">447 |</a> if(pargs)
<a name="line448">448 |</a> {
<a name="line449">449 |</a> fprintf(of,"\\smallskip\n");
<a name="line450">450 |</a> fprintf(of,"\\begin{cxrefarglist}\n");
<a name="line451">451 |</a> for(i=0;i<def->args->n;i++)
<a name="line452">452 |</a> fprintf(of,"\\cxrefargitem{%s} %s\n",latex(def->args->s1[i],0),def->args->s2[i]?latex(def->args->s2[i],0):"\\ ");
<a name="line453">453 |</a> fprintf(of,"\\end{cxrefarglist}\n\n");
<a name="line454">454 |</a> }
<a name="line455">455 |</a> }
<a name="line456">456 |</a>
<a name="line457">457 |</a>
<a name="line458">458 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line459">459 |</a> Write a Typedef structure out.
<a name="line460">460 |</a>
<a name="line461">461 |</a> Typedef type The Typedef structure to output.
<a name="line462">462 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line463">463 |</a>
<a name="line464">464 |</a> static void WriteLatexTypedef(Typedef type)
<a name="line465">465 |</a> {
<a name="line466">466 |</a> if(type->type)
<a name="line467">467 |</a> fprintf(of,"\n\\subsubsection{Typedef %s}\n",latex(type->name,0));
<a name="line468">468 |</a> else
<a name="line469">469 |</a> fprintf(of,"\n\\subsubsection{Type %s}\n",latex(type->name,0));
<a name="line470">470 |</a>
<a name="line471">471 |</a> if(!strncmp("enum",type->name,4))
<a name="line472">472 |</a> fprintf(of,"\\label{type_enum_%s_%s}\n\n",&type->name[5],filename);
<a name="line473">473 |</a> else if(!strncmp("union",type->name,5))
<a name="line474">474 |</a> fprintf(of,"\\label{type_union_%s_%s}\n\n",&type->name[6],filename);
<a name="line475">475 |</a> else if(!strncmp("struct",type->name,6))
<a name="line476">476 |</a> fprintf(of,"\\label{type_struct_%s_%s}\n\n",&type->name[7],filename);
<a name="line477">477 |</a> else
<a name="line478">478 |</a> fprintf(of,"\\label{type_%s_%s}\n\n",type->name,filename);
<a name="line479">479 |</a>
<a name="line480">480 |</a> if(type->comment)
<a name="line481">481 |</a> fprintf(of,"%s\n\n\\smallskip\n",latex(type->comment,0));
<a name="line482">482 |</a>
<a name="line483">483 |</a> if(type->type)
<a name="line484">484 |</a> fprintf(of,"{\\stt typedef %s}\n\n",latex(type->type,0));
<a name="line485">485 |</a>
<a name="line486">486 |</a> if(type->sutype)
<a name="line487">487 |</a> {
<a name="line488">488 |</a> fprintf(of,"\\smallskip\n");
<a name="line489">489 |</a> fprintf(of,"\\begin{cxreftabiia}\n"); countlines=0;
<a name="line490">490 |</a> WriteLatexStructUnion(type->sutype,0);
<a name="line491">491 |</a> fprintf(of,"\\end{cxreftabiia}\n\n");
<a name="line492">492 |</a> }
<a name="line493">493 |</a> else
<a name="line494">494 |</a> if(type->typexref)
<a name="line495">495 |</a> {
<a name="line496">496 |</a> fprintf(of,"\\smallskip\n");
<a name="line497">497 |</a> fprintf(of,"\\begin{cxreftabii}\n");
<a name="line498">498 |</a> if(type->typexref->type)
<a name="line499">499 |</a> fprintf(of,"See:& Typedef %s & \\cxreftype{%s}{%s}\\\\\n",latex(type->typexref->name,0),type->typexref->name,filename);
<a name="line500">500 |</a> else if(!strncmp("enum",type->typexref->name,4))
<a name="line501">501 |</a> fprintf(of,"See:& Type %s & \\cxreftype{enum_%s}{%s}\\\\\n",latex(type->typexref->name,0),&type->typexref->name[5],filename);
<a name="line502">502 |</a> else if(!strncmp("union",type->typexref->name,5))
<a name="line503">503 |</a> fprintf(of,"See:& Type %s & \\cxreftype{union_%s}{%s}\\\\\n",latex(type->typexref->name,0),&type->typexref->name[6],filename);
<a name="line504">504 |</a> else if(!strncmp("struct",type->typexref->name,6))
<a name="line505">505 |</a> fprintf(of,"See:& Type %s & \\cxreftype{struct_%s}{%s}\\\\\n",latex(type->typexref->name,0),&type->typexref->name[7],filename);
<a name="line506">506 |</a> fprintf(of,"\\end{cxreftabii}\n\n");
<a name="line507">507 |</a> }
<a name="line508">508 |</a> }
<a name="line509">509 |</a>
<a name="line510">510 |</a>
<a name="line511">511 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line512">512 |</a> Write a structure / union structure out.
<a name="line513">513 |</a>
<a name="line514">514 |</a> StructUnion su The structure / union to write.
<a name="line515">515 |</a>
<a name="line516">516 |</a> int depth The current depth within the structure.
<a name="line517">517 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line518">518 |</a>
<a name="line519">519 |</a> static void WriteLatexStructUnion(StructUnion su, int depth)
<a name="line520">520 |</a> {
<a name="line521">521 |</a> int i;
<a name="line522">522 |</a> char* splitsu=NULL;
<a name="line523">523 |</a>
<a name="line524">524 |</a> splitsu=strstr(su->name,"{...}");
<a name="line525">525 |</a> if(splitsu) splitsu[-1]=0;
<a name="line526">526 |</a>
<a name="line527">527 |</a> if(countlines++%8==4)
<a name="line528">528 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiia}\n");
<a name="line529">529 |</a> fprintf(of,"\\hspace*{%3.1fin}",0.2*depth);
<a name="line530">530 |</a>
<a name="line531">531 |</a> if(depth && su->comment && !su->comps)
<a name="line532">532 |</a> fprintf(of,"{\\stt %s;} & %s \\\\\n",latex(su->name,0),latex(su->comment,0));
<a name="line533">533 |</a> else if(!depth || su->comps)
<a name="line534">534 |</a> fprintf(of,"{\\stt %s} &\\\\\n",latex(su->name,0));
<a name="line535">535 |</a> else
<a name="line536">536 |</a> fprintf(of,"{\\stt %s;} &\\\\\n",latex(su->name,0));
<a name="line537">537 |</a>
<a name="line538">538 |</a> if(!depth || su->comps)
<a name="line539">539 |</a> {
<a name="line540">540 |</a> fprintf(of,"\\hspace*{%3.1fin}",0.1+0.2*depth);
<a name="line541">541 |</a> fprintf(of,"{\\stt \\{} &\\\\\n");
<a name="line542">542 |</a>
<a name="line543">543 |</a> for(i=0;i<su->n_comp;i++)
<a name="line544">544 |</a> WriteLatexStructUnion(su->comps[i],depth+1);
<a name="line545">545 |</a>
<a name="line546">546 |</a> fprintf(of,"\\hspace*{%3.1fin}",0.1+0.2*depth);
<a name="line547">547 |</a> fprintf(of,"{\\stt \\}} &\\\\\n");
<a name="line548">548 |</a> if(splitsu)
<a name="line549">549 |</a> {
<a name="line550">550 |</a> fprintf(of,"\\hspace*{%3.1fin}",0.1+0.2*depth);
<a name="line551">551 |</a> if(depth && su->comment)
<a name="line552">552 |</a> fprintf(of,"{\\stt %s;} & %s \\\\\n",splitsu[5]?latex(&splitsu[6],0):"",latex(su->comment,0));
<a name="line553">553 |</a> else
<a name="line554">554 |</a> fprintf(of,"{\\stt %s;} &\\\\\n",splitsu[5]?latex(&splitsu[6],0):"");
<a name="line555">555 |</a> }
<a name="line556">556 |</a> }
<a name="line557">557 |</a>
<a name="line558">558 |</a> if(splitsu) splitsu[-1]=' ';
<a name="line559">559 |</a> }
<a name="line560">560 |</a>
<a name="line561">561 |</a>
<a name="line562">562 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line563">563 |</a> Write a Variable structure out.
<a name="line564">564 |</a>
<a name="line565">565 |</a> Variable var The Variable structure to output.
<a name="line566">566 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line567">567 |</a>
<a name="line568">568 |</a> static void WriteLatexVariable(Variable var)
<a name="line569">569 |</a> {
<a name="line570">570 |</a> int i;
<a name="line571">571 |</a>
<a name="line572">572 |</a> if(var->scope&GLOBAL)
<a name="line573">573 |</a> fprintf(of,"\n\\subsubsection{Variable %s}\n",latex(var->name,0));
<a name="line574">574 |</a> else
<a name="line575">575 |</a> fprintf(of,"{\\bf %s}\n",latex(var->name,0));
<a name="line576">576 |</a>
<a name="line577">577 |</a> fprintf(of,"\\label{var_%s_%s}\n\n",var->name,filename);
<a name="line578">578 |</a>
<a name="line579">579 |</a> if(var->comment)
<a name="line580">580 |</a> fprintf(of,"%s\n\n\\smallskip\n",latex(var->comment,0));
<a name="line581">581 |</a>
<a name="line582">582 |</a> fprintf(of,"{\\stt ");
<a name="line583">583 |</a>
<a name="line584">584 |</a> if(var->scope&LOCAL)
<a name="line585">585 |</a> fprintf(of,"static ");
<a name="line586">586 |</a> else
<a name="line587">587 |</a> if(!(var->scope&GLOBAL) && var->scope&(EXTERNAL|EXTERN_F))
<a name="line588">588 |</a> fprintf(of,"extern ");
<a name="line589">589 |</a>
<a name="line590">590 |</a> fprintf(of,"%s}\n\n",latex(var->type,0));
<a name="line591">591 |</a>
<a name="line592">592 |</a> if(var->scope&(GLOBAL|LOCAL))
<a name="line593">593 |</a> {
<a name="line594">594 |</a> if(var->incfrom || var->used->n || var->visible->n)
<a name="line595">595 |</a> {
<a name="line596">596 |</a> fprintf(of,"\\smallskip\n");
<a name="line597">597 |</a> fprintf(of,"\\begin{cxreftabiii}\n");
<a name="line598">598 |</a>
<a name="line599">599 |</a> if(var->incfrom)
<a name="line600">600 |</a> fprintf(of,"Inc. from:& %s & \\ & \\cxrefvar{%s}{%s}\\\\\n",latex(var->incfrom,0),var->name,var->incfrom);
<a name="line601">601 |</a>
<a name="line602">602 |</a> for(i=0;i<var->visible->n;i++)
<a name="line603">603 |</a> {
<a name="line604">604 |</a> if(min(i,var->visible->n+var->used->n-i)%8 == 4)
<a name="line605">605 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line606">606 |</a> if(i==0) fprintf(of,"Visible in:");
<a name="line607">607 |</a> if(var->visible->s1[i][0]=='$' && !var->visible->s1[i][1])
<a name="line608">608 |</a> fprintf(of,"\\ & %s & \\ & \\cxreffile{%s}\\\\\n",latex(var->visible->s2[i],0),var->visible->s2[i]);
<a name="line609">609 |</a> else
<a name="line610">610 |</a> fprintf(of,"\\ & %s() & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(var->visible->s1[i],0),latex(var->visible->s2[i],0),var->visible->s1[i],var->visible->s2[i]);
<a name="line611">611 |</a> }
<a name="line612">612 |</a>
<a name="line613">613 |</a> for(i=0;i<var->used->n;i++)
<a name="line614">614 |</a> {
<a name="line615">615 |</a> if(min(i,var->visible->n+var->used->n-i)%8 == 4)
<a name="line616">616 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line617">617 |</a> if(i==0) fprintf(of,"Used in:");
<a name="line618">618 |</a> if(var->used->s1[i][0]=='$' && !var->used->s1[i][1])
<a name="line619">619 |</a> fprintf(of,"\\ & %s & \\ & \\cxreffile{%s}\\\\\n",latex(var->used->s2[i],0),var->used->s2[i]);
<a name="line620">620 |</a> else
<a name="line621">621 |</a> if(var->scope&LOCAL)
<a name="line622">622 |</a> fprintf(of,"\\ & %s() & \\ & \\cxreffunc{%s}{%s}\\\\\n",latex(var->used->s1[i],0),var->used->s1[i],var->used->s2[i]);
<a name="line623">623 |</a> else
<a name="line624">624 |</a> fprintf(of,"\\ & %s() & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(var->used->s1[i],0),latex(var->used->s2[i],0),var->used->s1[i],var->used->s2[i]);
<a name="line625">625 |</a> }
<a name="line626">626 |</a>
<a name="line627">627 |</a> fprintf(of,"\\end{cxreftabiii}\n\n");
<a name="line628">628 |</a> }
<a name="line629">629 |</a> }
<a name="line630">630 |</a> else
<a name="line631">631 |</a> if(var->scope&(EXTERNAL|EXTERN_F) && var->defined)
<a name="line632">632 |</a> {
<a name="line633">633 |</a> fprintf(of,"\\smallskip\n");
<a name="line634">634 |</a> fprintf(of,"\\begin{cxreftabiii}\n");
<a name="line635">635 |</a> fprintf(of,"Defined in:& %s & \\ & \\cxrefvar{%s}{%s}\\\\\n",latex(var->defined,0),var->name,var->defined);
<a name="line636">636 |</a> fprintf(of,"\\end{cxreftabiii}\n\n");
<a name="line637">637 |</a> }
<a name="line638">638 |</a> }
<a name="line639">639 |</a>
<a name="line640">640 |</a>
<a name="line641">641 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line642">642 |</a> Write a Function structure out.
<a name="line643">643 |</a>
<a name="line644">644 |</a> Function func The Function structure to output.
<a name="line645">645 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line646">646 |</a>
<a name="line647">647 |</a> static void WriteLatexFunction(Function func)
<a name="line648">648 |</a> {
<a name="line649">649 |</a> int i,pret,pargs;
<a name="line650">650 |</a> char* comment2=NULL,*type;
<a name="line651">651 |</a>
<a name="line652">652 |</a> if(func->scope&(GLOBAL|EXTERNAL))
<a name="line653">653 |</a> fprintf(of,"\n\\subsubsection{Global Function %s()}\n",latex(func->name,0));
<a name="line654">654 |</a> else
<a name="line655">655 |</a> fprintf(of,"\n\\subsubsection{Local Function %s()}\n",latex(func->name,0));
<a name="line656">656 |</a> fprintf(of,"\\label{func_%s_%s}\n\n",func->name,filename);
<a name="line657">657 |</a>
<a name="line658">658 |</a> if(func->comment)
<a name="line659">659 |</a> {
<a name="line660">660 |</a> if(option_verbatim_comments)
<a name="line661">661 |</a> fprintf(of,"\\begin{verbatim}\n%s\n\\end{verbatim}\n\n",latex(func->comment,1));
<a name="line662">662 |</a> else
<a name="line663">663 |</a> {
<a name="line664">664 |</a> comment2=strstr(func->comment,"\n\n");
<a name="line665">665 |</a> if(comment2)
<a name="line666">666 |</a> comment2[0]=0;
<a name="line667">667 |</a> fprintf(of,"%s\n\n",latex(func->comment,0));
<a name="line668">668 |</a> fprintf(of,"\\smallskip\n");
<a name="line669">669 |</a> }
<a name="line670">670 |</a> }
<a name="line671">671 |</a>
<a name="line672">672 |</a> fprintf(of,"{\\stt ");
<a name="line673">673 |</a>
<a name="line674">674 |</a> if(func->scope&LOCAL)
<a name="line675">675 |</a> fprintf(of,"static ");
<a name="line676">676 |</a> if(func->scope&INLINED)
<a name="line677">677 |</a> fprintf(of,"inline ");
<a name="line678">678 |</a>
<a name="line679">679 |</a> if((type=strstr(func->type,"()")))
<a name="line680">680 |</a> type[0]=0;
<a name="line681">681 |</a> fprintf(of,"%s ( ",latex(func->type,0));
<a name="line682">682 |</a>
<a name="line683">683 |</a> for(i=0;i<func->args->n;i++)
<a name="line684">684 |</a> fprintf(of,i?", %s":"%s",latex(func->args->s1[i],0));
<a name="line685">685 |</a>
<a name="line686">686 |</a> if(type)
<a name="line687">687 |</a> {fprintf(of," %s}\n\n",&type[1]);type[0]='(';}
<a name="line688">688 |</a> else
<a name="line689">689 |</a> fprintf(of," )}\n\n");
<a name="line690">690 |</a>
<a name="line691">691 |</a> pret =strncmp("void ",func->type,5) && func->cret;
<a name="line692">692 |</a> for(pargs=0,i=0;i<func->args->n;i++)
<a name="line693">693 |</a> pargs = pargs || ( strcmp("void",func->args->s1[i]) && func->args->s2[i] );
<a name="line694">694 |</a>
<a name="line695">695 |</a> if(pret || pargs)
<a name="line696">696 |</a> {
<a name="line697">697 |</a> fprintf(of,"\\smallskip\n");
<a name="line698">698 |</a> fprintf(of,"\\begin{cxrefarglist}\n");
<a name="line699">699 |</a> if(pret)
<a name="line700">700 |</a> fprintf(of,"\\cxrefargitem{%s} %s\n",latex(func->type,0),func->cret?latex(func->cret,0):"\\ ");
<a name="line701">701 |</a> if(pargs)
<a name="line702">702 |</a> for(i=0;i<func->args->n;i++)
<a name="line703">703 |</a> fprintf(of,"\\cxrefargitem{%s} %s\n",latex(func->args->s1[i],0),func->args->s2[i]?latex(func->args->s2[i],0):"\\ ");
<a name="line704">704 |</a> fprintf(of,"\\end{cxrefarglist}\n\n");
<a name="line705">705 |</a> }
<a name="line706">706 |</a>
<a name="line707">707 |</a> if(comment2)
<a name="line708">708 |</a> {
<a name="line709">709 |</a> fprintf(of,"\\smallskip\n");
<a name="line710">710 |</a> fprintf(of,"%s\n\n",latex(&comment2[2],0));
<a name="line711">711 |</a> comment2[0]='\n';
<a name="line712">712 |</a> }
<a name="line713">713 |</a>
<a name="line714">714 |</a> if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n)
<a name="line715">715 |</a> {
<a name="line716">716 |</a> int tabcount=func->protofile?1:0;
<a name="line717">717 |</a> fprintf(of,"\\smallskip\n");
<a name="line718">718 |</a> fprintf(of,"\\begin{cxreftabiii}\n");
<a name="line719">719 |</a>
<a name="line720">720 |</a> if(func->protofile)
<a name="line721">721 |</a> fprintf(of,"Prototype:& %s & \\ & \\cxreffile{%s}\\\\\n",latex(func->protofile,0),func->protofile);
<a name="line722">722 |</a>
<a name="line723">723 |</a> if(func->incfrom)
<a name="line724">724 |</a> fprintf(of,"Inc. from:& %s & \\ & \\cxreffunc{%s}{%s}\\\\\n",latex(func->incfrom,0),func->name,func->incfrom);
<a name="line725">725 |</a>
<a name="line726">726 |</a> if(func->calls->n)
<a name="line727">727 |</a> {
<a name="line728">728 |</a> int others=0;
<a name="line729">729 |</a>
<a name="line730">730 |</a> fprintf(of,"Calls:");
<a name="line731">731 |</a>
<a name="line732">732 |</a> for(i=0;i<func->calls->n;i++)
<a name="line733">733 |</a> if(func->calls->s2[i])
<a name="line734">734 |</a> {
<a name="line735">735 |</a> fprintf(of,"\\ & %s() & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(func->calls->s1[i],0),latex(func->calls->s2[i],0),func->calls->s1[i],func->calls->s2[i]);
<a name="line736">736 |</a> if(++tabcount%8 == 4)
<a name="line737">737 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line738">738 |</a> }
<a name="line739">739 |</a> else
<a name="line740">740 |</a> others++;
<a name="line741">741 |</a>
<a name="line742">742 |</a> if(others)
<a name="line743">743 |</a> {
<a name="line744">744 |</a> fprintf(of,"\\ & \\cxreftabiiispan{");
<a name="line745">745 |</a> for(i=0;i<func->calls->n;i++)
<a name="line746">746 |</a> if(!func->calls->s2[i])
<a name="line747">747 |</a> fprintf(of,--others?" %s(),":" %s()",latex(func->calls->s1[i],0));
<a name="line748">748 |</a> fprintf(of,"} &\\\\\n");
<a name="line749">749 |</a> }
<a name="line750">750 |</a> }
<a name="line751">751 |</a>
<a name="line752">752 |</a> if(func->called->n)
<a name="line753">753 |</a> {
<a name="line754">754 |</a> fprintf(of,"Called by:");
<a name="line755">755 |</a>
<a name="line756">756 |</a> for(i=0;i<func->called->n;i++)
<a name="line757">757 |</a> {
<a name="line758">758 |</a> fprintf(of,"\\ & %s() & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(func->called->s1[i],0),latex(func->called->s2[i],0),func->called->s1[i],func->called->s2[i]);
<a name="line759">759 |</a> if(++tabcount%8 == 4)
<a name="line760">760 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line761">761 |</a> }
<a name="line762">762 |</a> }
<a name="line763">763 |</a>
<a name="line764">764 |</a> if(func->used->n)
<a name="line765">765 |</a> {
<a name="line766">766 |</a> fprintf(of,"Used in:");
<a name="line767">767 |</a>
<a name="line768">768 |</a> for(i=0;i<func->used->n;i++)
<a name="line769">769 |</a> {
<a name="line770">770 |</a> if(func->used->s1[i][0]=='$' && !func->used->s1[i][1])
<a name="line771">771 |</a> fprintf(of,"\\ & %s & \\ & \\cxreffile{%s}\\\\\n",latex(func->used->s2[i],0),func->used->s2[i]);
<a name="line772">772 |</a> else
<a name="line773">773 |</a> fprintf(of,"\\ & %s() & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(func->used->s1[i],0),latex(func->used->s2[i],0),func->used->s1[i],func->used->s2[i]);
<a name="line774">774 |</a> if(++tabcount%8 == 4)
<a name="line775">775 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line776">776 |</a> }
<a name="line777">777 |</a> }
<a name="line778">778 |</a>
<a name="line779">779 |</a> if(func->f_refs->n)
<a name="line780">780 |</a> {
<a name="line781">781 |</a> int others=0;
<a name="line782">782 |</a>
<a name="line783">783 |</a> fprintf(of,"Refs Func:");
<a name="line784">784 |</a>
<a name="line785">785 |</a> for(i=0;i<func->f_refs->n;i++)
<a name="line786">786 |</a> if(func->f_refs->s2[i])
<a name="line787">787 |</a> {
<a name="line788">788 |</a> fprintf(of,"\\ & %s() & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(func->f_refs->s1[i],0),latex(func->f_refs->s2[i],0),func->f_refs->s1[i],func->f_refs->s2[i]);
<a name="line789">789 |</a> if(++tabcount%8 == 4)
<a name="line790">790 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line791">791 |</a> }
<a name="line792">792 |</a> else
<a name="line793">793 |</a> others++;
<a name="line794">794 |</a>
<a name="line795">795 |</a> if(others)
<a name="line796">796 |</a> {
<a name="line797">797 |</a> fprintf(of,"\\ & \\cxreftabiiispan{");
<a name="line798">798 |</a> for(i=0;i<func->f_refs->n;i++)
<a name="line799">799 |</a> if(!func->f_refs->s2[i])
<a name="line800">800 |</a> fprintf(of,--others?" %s(),":" %s()",latex(func->f_refs->s1[i],0));
<a name="line801">801 |</a> fprintf(of,"} &\\\\\n");
<a name="line802">802 |</a> }
<a name="line803">803 |</a> }
<a name="line804">804 |</a>
<a name="line805">805 |</a> if(func->v_refs->n)
<a name="line806">806 |</a> {
<a name="line807">807 |</a> int others=0;
<a name="line808">808 |</a>
<a name="line809">809 |</a> fprintf(of,"Refs Var:");
<a name="line810">810 |</a>
<a name="line811">811 |</a> for(i=0;i<func->v_refs->n;i++)
<a name="line812">812 |</a> if(func->v_refs->s2[i])
<a name="line813">813 |</a> {
<a name="line814">814 |</a> fprintf(of,"\\ & %s & %s & \\cxrefvar{%s}{%s}\\\\\n",latex(func->v_refs->s1[i],0),latex(func->v_refs->s2[i],0),func->v_refs->s1[i],func->v_refs->s2[i]);
<a name="line815">815 |</a> if(++tabcount%8 == 4)
<a name="line816">816 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiii}\n");
<a name="line817">817 |</a> }
<a name="line818">818 |</a> else
<a name="line819">819 |</a> others++;
<a name="line820">820 |</a>
<a name="line821">821 |</a> if(others)
<a name="line822">822 |</a> {
<a name="line823">823 |</a> fprintf(of,"\\ & \\cxreftabiiispan{");
<a name="line824">824 |</a> for(i=0;i<func->v_refs->n;i++)
<a name="line825">825 |</a> if(!func->v_refs->s2[i])
<a name="line826">826 |</a> fprintf(of,--others?" %s,":" %s",latex(func->v_refs->s1[i],0));
<a name="line827">827 |</a> fprintf(of,"} &\\\\\n");
<a name="line828">828 |</a> }
<a name="line829">829 |</a> }
<a name="line830">830 |</a>
<a name="line831">831 |</a> fprintf(of,"\\end{cxreftabiii}\n\n");
<a name="line832">832 |</a> }
<a name="line833">833 |</a> }
<a name="line834">834 |</a>
<a name="line835">835 |</a>
<a name="line836">836 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line837">837 |</a> Write out a file that will include the current information.
<a name="line838">838 |</a>
<a name="line839">839 |</a> char* name The name of the file (without the LaTeX extension).
<a name="line840">840 |</a>
<a name="line841">841 |</a> int appendix set to non-zero if the appendix file is to be added, else a normal source file.
<a name="line842">842 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line843">843 |</a>
<a name="line844">844 |</a> static void WriteLatexDocument(char* name,int appendix)
<a name="line845">845 |</a> {
<a name="line846">846 |</a> FILE *in,*out;
<a name="line847">847 |</a> char line[256];
<a name="line848">848 |</a> int seen=0;
<a name="line849">849 |</a> char *inc_file,*ofile,*ifile;
<a name="line850">850 |</a>
<a name="line851">851 |</a> inc_file=ConcatStrings(4,"\\input{",name,LATEX_FILE,"}\n");
<a name="line852">852 |</a> ifile=ConcatStrings(4,option_odir,"/",option_name,LATEX_FILE);
<a name="line853">853 |</a> ofile=ConcatStrings(4,option_odir,"/",option_name,LATEX_FILE_BACKUP);
<a name="line854">854 |</a>
<a name="line855">855 |</a> in =fopen(ifile,"r");
<a name="line856">856 |</a> if(!in)
<a name="line857">857 |</a> {
<a name="line858">858 |</a> WriteLatexTemplate(ifile);
<a name="line859">859 |</a> in =fopen(ifile,"r");
<a name="line860">860 |</a> }
<a name="line861">861 |</a>
<a name="line862">862 |</a> out=fopen(ofile,"w");
<a name="line863">863 |</a>
<a name="line864">864 |</a> if(!out)
<a name="line865">865 |</a> {fprintf(stderr,"cxref: Failed to open the main LaTeX output file '%s'\n",ofile);exit(1);}
<a name="line866">866 |</a>
<a name="line867">867 |</a> while(fgets(line,256,in))
<a name="line868">868 |</a> {
<a name="line869">869 |</a> if(!strcmp(inc_file,line) ||
<a name="line870">870 |</a> (line[0]=='%' && !strcmp(inc_file,line+1)) ||
<a name="line871">871 |</a> (line[0]=='%' && line[1]==' ' && !strcmp(inc_file,line+2)))
<a name="line872">872 |</a> {seen=1;break;}
<a name="line873">873 |</a> if(line[0]=='%' && !strcmp("% End-Of-Source-Files\n",line))
<a name="line874">874 |</a> {
<a name="line875">875 |</a> if(appendix)
<a name="line876">876 |</a> {
<a name="line877">877 |</a> fputs(line,out);
<a name="line878">878 |</a> fputs("\n",out);
<a name="line879">879 |</a> fputs("% Appendix\n",out);
<a name="line880">880 |</a> fputs("\n",out);
<a name="line881">881 |</a> fputs("\\appendix\n",out);
<a name="line882">882 |</a> fputs("\\markboth{Appendix}{Appendix}\n",out);
<a name="line883">883 |</a> fputs(inc_file,out);
<a name="line884">884 |</a> }
<a name="line885">885 |</a> else
<a name="line886">886 |</a> {
<a name="line887">887 |</a> fputs(inc_file,out);
<a name="line888">888 |</a> fputs("\n",out);
<a name="line889">889 |</a> fputs(line,out);
<a name="line890">890 |</a> }
<a name="line891">891 |</a> }
<a name="line892">892 |</a> else
<a name="line893">893 |</a> fputs(line,out);
<a name="line894">894 |</a> }
<a name="line895">895 |</a>
<a name="line896">896 |</a> fclose(in);
<a name="line897">897 |</a> fclose(out);
<a name="line898">898 |</a>
<a name="line899">899 |</a> if(!seen)
<a name="line900">900 |</a> {
<a name="line901">901 |</a> unlink(ifile);
<a name="line902">902 |</a> rename(ofile,ifile);
<a name="line903">903 |</a> }
<a name="line904">904 |</a> else
<a name="line905">905 |</a> unlink(ofile);
<a name="line906">906 |</a> }
<a name="line907">907 |</a>
<a name="line908">908 |</a>
<a name="line909">909 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line910">910 |</a> Write out the standard template for the main LaTeX file.
<a name="line911">911 |</a> This sets up the page styles, and includes markers for the start and end of included source code.
<a name="line912">912 |</a>
<a name="line913">913 |</a> char* name The name of the file to write the template to.
<a name="line914">914 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line915">915 |</a>
<a name="line916">916 |</a> static void WriteLatexTemplate(char* name)
<a name="line917">917 |</a> {
<a name="line918">918 |</a> FILE *template;
<a name="line919">919 |</a> struct stat stat_buf;
<a name="line920">920 |</a> char* fname;
<a name="line921">921 |</a>
<a name="line922">922 |</a> template=fopen(name,"w");
<a name="line923">923 |</a>
<a name="line924">924 |</a> if(!template)
<a name="line925">925 |</a> {fprintf(stderr,"cxref: Failed to open the main LaTeX output file '%s'\n",name);exit(1);}
<a name="line926">926 |</a>
<a name="line927">927 |</a> fputs("% This LaTeX file generated by cxref (version " CXREF_VERSION ").\n",template);
<a name="line928">928 |</a> fputs("% cxref program " CXREF_COPYRIGHT "\n",template);
<a name="line929">929 |</a> fputs("\n",template);
<a name="line930">930 |</a> fputs("\\documentclass{report}\n",template);
<a name="line931">931 |</a> fputs("\\usepackage{fonts,page,cxref}\n",template);
<a name="line932">932 |</a> fputs("\\pagestyle{myheadings}\n",template);
<a name="line933">933 |</a> fputs("\n",template);
<a name="line934">934 |</a> fputs("\\begin{document}\n",template);
<a name="line935">935 |</a> fputs("\n",template);
<a name="line936">936 |</a> fputs("% Contents (Optional, either here or at end)\n",template);
<a name="line937">937 |</a> fputs("\n",template);
<a name="line938">938 |</a> fputs("\\markboth{Contents}{Contents}\n",template);
<a name="line939">939 |</a> fputs("\\tableofcontents\n",template);
<a name="line940">940 |</a> fputs("\n",template);
<a name="line941">941 |</a> fputs("\\chapter{Source Files}\n",template);
<a name="line942">942 |</a> fputs("\n",template);
<a name="line943">943 |</a> fputs("% Begin-Of-Source-Files\n",template);
<a name="line944">944 |</a> fputs("\n",template);
<a name="line945">945 |</a> fputs("% End-Of-Source-Files\n",template);
<a name="line946">946 |</a> fputs("\n",template);
<a name="line947">947 |</a> fputs("% Contents (Optional, either here or at beginning)\n",template);
<a name="line948">948 |</a> fputs("\n",template);
<a name="line949">949 |</a> fputs("%\\markboth{Contents}{Contents}\n",template);
<a name="line950">950 |</a> fputs("%\\tableofcontents\n",template);
<a name="line951">951 |</a> fputs("\n",template);
<a name="line952">952 |</a> fputs("\\end{document}\n",template);
<a name="line953">953 |</a>
<a name="line954">954 |</a> fclose(template);
<a name="line955">955 |</a>
<a name="line956">956 |</a> fname=ConcatStrings(2,option_odir,"/fonts.sty");
<a name="line957">957 |</a> if(stat(fname,&stat_buf))
<a name="line958">958 |</a> {
<a name="line959">959 |</a> FILE* file=fopen(fname,"w");
<a name="line960">960 |</a> if(!file)
<a name="line961">961 |</a> {fprintf(stderr,"cxref: Cannot write the LaTeX style file '%s'\n",fname);exit(1);}
<a name="line962">962 |</a> fputs(latex_fonts_style,file);
<a name="line963">963 |</a> fclose(file);
<a name="line964">964 |</a> }
<a name="line965">965 |</a>
<a name="line966">966 |</a> fname=ConcatStrings(2,option_odir,"/page.sty");
<a name="line967">967 |</a> if(stat(fname,&stat_buf))
<a name="line968">968 |</a> {
<a name="line969">969 |</a> FILE* file=fopen(fname,"w");
<a name="line970">970 |</a> if(!file)
<a name="line971">971 |</a> {fprintf(stderr,"cxref: Cannot write the LaTeX style file '%s'\n",fname);exit(1);}
<a name="line972">972 |</a> fputs(latex_page_style,file);
<a name="line973">973 |</a> fclose(file);
<a name="line974">974 |</a> }
<a name="line975">975 |</a>
<a name="line976">976 |</a> fname=ConcatStrings(2,option_odir,"/cxref.sty");
<a name="line977">977 |</a> if(stat(fname,&stat_buf))
<a name="line978">978 |</a> {
<a name="line979">979 |</a> FILE* file=fopen(fname,"w");
<a name="line980">980 |</a> if(!file)
<a name="line981">981 |</a> {fprintf(stderr,"cxref: Cannot write the LaTeX style file '%s'\n",fname);exit(1);}
<a name="line982">982 |</a> fputs(latex_cxref_style,file);
<a name="line983">983 |</a> fclose(file);
<a name="line984">984 |</a> }
<a name="line985">985 |</a> }
<a name="line986">986 |</a>
<a name="line987">987 |</a>
<a name="line988">988 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line989">989 |</a> Write out the appendix information.
<a name="line990">990 |</a>
<a name="line991">991 |</a> StringList files The list of files to write.
<a name="line992">992 |</a>
<a name="line993">993 |</a> StringList2 funcs The list of functions to write.
<a name="line994">994 |</a>
<a name="line995">995 |</a> StringList2 vars The list of variables to write.
<a name="line996">996 |</a>
<a name="line997">997 |</a> StringList2 types The list of types to write.
<a name="line998">998 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line999">999 |</a>
<a name="line1000">1000 |</a> void WriteLatexAppendix(StringList files,StringList2 funcs,StringList2 vars,StringList2 types)
<a name="line1001">1001 |</a> {
<a name="line1002">1002 |</a> char* ofile;
<a name="line1003">1003 |</a> int i;
<a name="line1004">1004 |</a>
<a name="line1005">1005 |</a> filename=NULL;
<a name="line1006">1006 |</a>
<a name="line1007">1007 |</a> /* Write the bits to the including file. */
<a name="line1008">1008 |</a>
<a name="line1009">1009 |</a> WriteLatexDocument(ConcatStrings(2,option_name,LATEX_APDX),1);
<a name="line1010">1010 |</a>
<a name="line1011">1011 |</a> /* Open the file */
<a name="line1012">1012 |</a>
<a name="line1013">1013 |</a> ofile=ConcatStrings(5,option_odir,"/",option_name,LATEX_APDX,LATEX_FILE);
<a name="line1014">1014 |</a>
<a name="line1015">1015 |</a> of=fopen(ofile,"w");
<a name="line1016">1016 |</a>
<a name="line1017">1017 |</a> if(!of)
<a name="line1018">1018 |</a> {fprintf(stderr,"cxref: Failed to open the LaTeX appendix file '%s'\n",ofile);exit(1);}
<a name="line1019">1019 |</a>
<a name="line1020">1020 |</a> /* Write out a header. */
<a name="line1021">1021 |</a>
<a name="line1022">1022 |</a> fputs("% This LaTeX file generated by cxref (version " CXREF_VERSION ").\n",of);
<a name="line1023">1023 |</a> fputs("% cxref program " CXREF_COPYRIGHT "\n",of);
<a name="line1024">1024 |</a> fputs("\n",of);
<a name="line1025">1025 |</a> fprintf(of,"%% Cxref: %s\n",run_command);
<a name="line1026">1026 |</a> fputs("\n",of);
<a name="line1027">1027 |</a>
<a name="line1028">1028 |</a> /* Write the file structure out */
<a name="line1029">1029 |</a>
<a name="line1030">1030 |</a> fprintf(of,"\\chapter{Cross References}\n");
<a name="line1031">1031 |</a>
<a name="line1032">1032 |</a> /* Write out the appendix of files. */
<a name="line1033">1033 |</a>
<a name="line1034">1034 |</a> if(files->n)
<a name="line1035">1035 |</a> {
<a name="line1036">1036 |</a> fprintf(of,"\n\\section{Files}\n");
<a name="line1037">1037 |</a> fprintf(of,"\\label{appendix_file}\n\n");
<a name="line1038">1038 |</a> fprintf(of,"\\begin{cxreftabiib}\n");
<a name="line1039">1039 |</a> for(i=0;i<files->n;i++)
<a name="line1040">1040 |</a> {
<a name="line1041">1041 |</a> if(min(i,files->n-i)%8 == 4)
<a name="line1042">1042 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiib}\n");
<a name="line1043">1043 |</a> fprintf(of,"%s & \\ & \\cxreffile{%s}\\\\\n",latex(files->s[i],0),files->s[i]);
<a name="line1044">1044 |</a> }
<a name="line1045">1045 |</a> fprintf(of,"\\end{cxreftabiib}\n\n");
<a name="line1046">1046 |</a> }
<a name="line1047">1047 |</a>
<a name="line1048">1048 |</a> /* Write out the appendix of functions. */
<a name="line1049">1049 |</a>
<a name="line1050">1050 |</a> if(funcs->n)
<a name="line1051">1051 |</a> {
<a name="line1052">1052 |</a> fprintf(of,"\n\\section{Global Functions}\n");
<a name="line1053">1053 |</a> fprintf(of,"\\label{appendix_func}\n\n");
<a name="line1054">1054 |</a> fprintf(of,"\\begin{cxreftabiib}\n");
<a name="line1055">1055 |</a> for(i=0;i<funcs->n;i++)
<a name="line1056">1056 |</a> {
<a name="line1057">1057 |</a> if(min(i,funcs->n-i)%8 == 4)
<a name="line1058">1058 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiib}\n");
<a name="line1059">1059 |</a> fprintf(of,"%s & %s & \\cxreffunc{%s}{%s}\\\\\n",latex(funcs->s1[i],0),latex(funcs->s2[i],0),funcs->s1[i],funcs->s2[i]);
<a name="line1060">1060 |</a> }
<a name="line1061">1061 |</a> fprintf(of,"\\end{cxreftabiib}\n\n");
<a name="line1062">1062 |</a> }
<a name="line1063">1063 |</a>
<a name="line1064">1064 |</a> /* Write out the appendix of variables. */
<a name="line1065">1065 |</a>
<a name="line1066">1066 |</a> if(vars->n)
<a name="line1067">1067 |</a> {
<a name="line1068">1068 |</a> fprintf(of,"\n\\section{Global Variables}\n");
<a name="line1069">1069 |</a> fprintf(of,"\\label{appendix_var}\n\n");
<a name="line1070">1070 |</a> fprintf(of,"\\begin{cxreftabiib}\n");
<a name="line1071">1071 |</a> for(i=0;i<vars->n;i++)
<a name="line1072">1072 |</a> {
<a name="line1073">1073 |</a> if(min(i,vars->n-i)%8 == 4)
<a name="line1074">1074 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiib}\n");
<a name="line1075">1075 |</a> fprintf(of,"%s & %s & \\cxrefvar{%s}{%s}\\\\\n",latex(vars->s1[i],0),latex(vars->s2[i],0),vars->s1[i],vars->s2[i]);
<a name="line1076">1076 |</a> }
<a name="line1077">1077 |</a> fprintf(of,"\\end{cxreftabiib}\n\n");
<a name="line1078">1078 |</a> }
<a name="line1079">1079 |</a>
<a name="line1080">1080 |</a> /* Write out the appendix of types. */
<a name="line1081">1081 |</a>
<a name="line1082">1082 |</a> if(types->n)
<a name="line1083">1083 |</a> {
<a name="line1084">1084 |</a> fprintf(of,"\n\\section{Defined Types}\n");
<a name="line1085">1085 |</a> fprintf(of,"\\label{appendix_type}\n\n");
<a name="line1086">1086 |</a> fprintf(of,"\\begin{cxreftabiib}\n");
<a name="line1087">1087 |</a> for(i=0;i<types->n;i++)
<a name="line1088">1088 |</a> {
<a name="line1089">1089 |</a> if(min(i,types->n-i)%8 == 4)
<a name="line1090">1090 |</a> fprintf(of,"\\cxreftabbreak{cxreftabiib}\n");
<a name="line1091">1091 |</a> if(!strncmp("enum",types->s1[i],4))
<a name="line1092">1092 |</a> fprintf(of,"%s & %s & \\cxreftype{enum_%s}{%s}\\\\\n",latex(types->s1[i],0),latex(types->s2[i],0),&types->s1[i][5],types->s2[i]);
<a name="line1093">1093 |</a> else
<a name="line1094">1094 |</a> if(!strncmp("union",types->s1[i],5))
<a name="line1095">1095 |</a> fprintf(of,"%s & %s & \\cxreftype{union_%s}{%s}\\\\\n",latex(types->s1[i],0),latex(types->s2[i],0),&types->s1[i][6],types->s2[i]);
<a name="line1096">1096 |</a> else
<a name="line1097">1097 |</a> if(!strncmp("struct",types->s1[i],6))
<a name="line1098">1098 |</a> fprintf(of,"%s & %s & \\cxreftype{struct_%s}{%s}\\\\\n",latex(types->s1[i],0),latex(types->s2[i],0),&types->s1[i][7],types->s2[i]);
<a name="line1099">1099 |</a> else
<a name="line1100">1100 |</a> fprintf(of,"%s & %s & \\cxreftype{%s}{%s}\\\\\n",latex(types->s1[i],0),latex(types->s2[i],0),types->s1[i],types->s2[i]);
<a name="line1101">1101 |</a> }
<a name="line1102">1102 |</a> fprintf(of,"\\end{cxreftabiib}\n\n");
<a name="line1103">1103 |</a> }
<a name="line1104">1104 |</a>
<a name="line1105">1105 |</a> fclose(of);
<a name="line1106">1106 |</a>
<a name="line1107">1107 |</a> /* Clear the memory in latex(,0) */
<a name="line1108">1108 |</a>
<a name="line1109">1109 |</a> latex(NULL,0); latex(NULL,0); latex(NULL,0); latex(NULL,0);
<a name="line1110">1110 |</a> }
<a name="line1111">1111 |</a>
<a name="line1112">1112 |</a>
<a name="line1113">1113 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line1114">1114 |</a> Delete the latex file and main file reference that belong to the named file.
<a name="line1115">1115 |</a>
<a name="line1116">1116 |</a> char *name The name of the file to delete.
<a name="line1117">1117 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line1118">1118 |</a>
<a name="line1119">1119 |</a> void WriteLatexFileDelete(char *name)
<a name="line1120">1120 |</a> {
<a name="line1121">1121 |</a> FILE *in,*out;
<a name="line1122">1122 |</a> char line[256];
<a name="line1123">1123 |</a> int seen=0;
<a name="line1124">1124 |</a> char *inc_file,*ofile,*ifile;
<a name="line1125">1125 |</a>
<a name="line1126">1126 |</a> ofile=ConcatStrings(4,option_odir,"/",name,LATEX_FILE);
<a name="line1127">1127 |</a> unlink(ofile);
<a name="line1128">1128 |</a>
<a name="line1129">1129 |</a> inc_file=ConcatStrings(4,"\\input{",name,LATEX_FILE,"}\n");
<a name="line1130">1130 |</a> ifile=ConcatStrings(4,option_odir,"/",option_name,LATEX_FILE);
<a name="line1131">1131 |</a> ofile=ConcatStrings(4,option_odir,"/",option_name,LATEX_FILE_BACKUP);
<a name="line1132">1132 |</a>
<a name="line1133">1133 |</a> in =fopen(ifile,"r");
<a name="line1134">1134 |</a> out=fopen(ofile,"w");
<a name="line1135">1135 |</a>
<a name="line1136">1136 |</a> if(in && !out)
<a name="line1137">1137 |</a> {fprintf(stderr,"cxref: Failed to open the main LaTeX output file '%s'\n",ofile);fclose(in);}
<a name="line1138">1138 |</a> else if(in)
<a name="line1139">1139 |</a> {
<a name="line1140">1140 |</a> while(fgets(line,256,in))
<a name="line1141">1141 |</a> {
<a name="line1142">1142 |</a> if(!strcmp(inc_file,line) ||
<a name="line1143">1143 |</a> (line[0]=='%' && !strcmp(inc_file,line+1)) ||
<a name="line1144">1144 |</a> (line[0]=='%' && line[1]==' ' && !strcmp(inc_file,line+2)))
<a name="line1145">1145 |</a> seen=1;
<a name="line1146">1146 |</a> else
<a name="line1147">1147 |</a> fputs(line,out);
<a name="line1148">1148 |</a> }
<a name="line1149">1149 |</a>
<a name="line1150">1150 |</a> fclose(in);
<a name="line1151">1151 |</a> fclose(out);
<a name="line1152">1152 |</a>
<a name="line1153">1153 |</a> if(seen)
<a name="line1154">1154 |</a> {
<a name="line1155">1155 |</a> unlink(ifile);
<a name="line1156">1156 |</a> rename(ofile,ifile);
<a name="line1157">1157 |</a> }
<a name="line1158">1158 |</a> else
<a name="line1159">1159 |</a> unlink(ofile);
<a name="line1160">1160 |</a> }
<a name="line1161">1161 |</a> else if(out)
<a name="line1162">1162 |</a> {
<a name="line1163">1163 |</a> fclose(out);
<a name="line1164">1164 |</a> unlink(ofile);
<a name="line1165">1165 |</a> }
<a name="line1166">1166 |</a> }
<a name="line1167">1167 |</a>
<a name="line1168">1168 |</a>
<a name="line1169">1169 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line1170">1170 |</a> Make the input string safe to output as LaTeX ( not #, $, %, &, \, ^, _, {, }, <, > or ~ ).
<a name="line1171">1171 |</a>
<a name="line1172">1172 |</a> char* latex Returns a safe LaTeX string.
<a name="line1173">1173 |</a>
<a name="line1174">1174 |</a> char* c A non-safe LaTeX string.
<a name="line1175">1175 |</a>
<a name="line1176">1176 |</a> int verbatim Set to true inside a verbatim environment.
<a name="line1177">1177 |</a>
<a name="line1178">1178 |</a> The function can only be called four times in each fprintf() since it returns one of only four static strings.
<a name="line1179">1179 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line1180">1180 |</a>
<a name="line1181">1181 |</a> static char* latex(char* c,int verbatim)
<a name="line1182">1182 |</a> {
<a name="line1183">1183 |</a> static char safe[4][256],*malloced[4]={NULL,NULL,NULL,NULL};
<a name="line1184">1184 |</a> static int which=0;
<a name="line1185">1185 |</a> int copy=0,skip=0;
<a name="line1186">1186 |</a> int i=0,j=0,delta=13,len=256-delta;
<a name="line1187">1187 |</a> char* ret;
<a name="line1188">1188 |</a>
<a name="line1189">1189 |</a> which=(which+1)%4;
<a name="line1190">1190 |</a> ret=safe[which];
<a name="line1191">1191 |</a>
<a name="line1192">1192 |</a> safe[which][0]=0;
<a name="line1193">1193 |</a>
<a name="line1194">1194 |</a> if(malloced[which])
<a name="line1195">1195 |</a> {Free(malloced[which]);malloced[which]=NULL;}
<a name="line1196">1196 |</a>
<a name="line1197">1197 |</a> if(c)
<a name="line1198">1198 |</a> {
<a name="line1199">1199 |</a> i=CopyOrSkip(c,"latex",&copy,&skip);
<a name="line1200">1200 |</a>
<a name="line1201">1201 |</a> while(1)
<a name="line1202">1202 |</a> {
<a name="line1203">1203 |</a> for(;j<len && c[i];i++)
<a name="line1204">1204 |</a> {
<a name="line1205">1205 |</a> if(copy)
<a name="line1206">1206 |</a> {ret[j++]=c[i]; if(c[i]=='\n') copy=0;}
<a name="line1207">1207 |</a> else if(skip)
<a name="line1208">1208 |</a> { if(c[i]=='\n') skip=0;}
<a name="line1209">1209 |</a> else if(verbatim)
<a name="line1210">1210 |</a> ret[j++]=c[i];
<a name="line1211">1211 |</a> else
<a name="line1212">1212 |</a> switch(c[i])
<a name="line1213">1213 |</a> {
<a name="line1214">1214 |</a> case '<':
<a name="line1215">1215 |</a> case '>':
<a name="line1216">1216 |</a> ret[j++]='$';
<a name="line1217">1217 |</a> ret[j++]=c[i];
<a name="line1218">1218 |</a> ret[j++]='$';
<a name="line1219">1219 |</a> break;
<a name="line1220">1220 |</a> case '\\':
<a name="line1221">1221 |</a> strcpy(&ret[j],"$\\backslash$");j+=12;
<a name="line1222">1222 |</a> break;
<a name="line1223">1223 |</a> case '~':
<a name="line1224">1224 |</a> strcpy(&ret[j],"$\\sim$");j+=6;
<a name="line1225">1225 |</a> break;
<a name="line1226">1226 |</a> case '^':
<a name="line1227">1227 |</a> strcpy(&ret[j],"$\\wedge$");j+=8;
<a name="line1228">1228 |</a> break;
<a name="line1229">1229 |</a> case '#':
<a name="line1230">1230 |</a> case '$':
<a name="line1231">1231 |</a> case '%':
<a name="line1232">1232 |</a> case '&':
<a name="line1233">1233 |</a> case '_':
<a name="line1234">1234 |</a> case '{':
<a name="line1235">1235 |</a> case '}':
<a name="line1236">1236 |</a> ret[j++]='\\';
<a name="line1237">1237 |</a> ret[j++]=c[i];
<a name="line1238">1238 |</a> break;
<a name="line1239">1239 |</a> default:
<a name="line1240">1240 |</a> ret[j++]=c[i];
<a name="line1241">1241 |</a> }
<a name="line1242">1242 |</a> if(c[i]=='\n')
<a name="line1243">1243 |</a> i+=CopyOrSkip(c+i,"latex",&copy,&skip);
<a name="line1244">1244 |</a> }
<a name="line1245">1245 |</a>
<a name="line1246">1246 |</a> if(c[i]) /* Not finished */
<a name="line1247">1247 |</a> {
<a name="line1248">1248 |</a> if(malloced[which])
<a name="line1249">1249 |</a> malloced[which]=Realloc(malloced[which],len+delta+256);
<a name="line1250">1250 |</a> else
<a name="line1251">1251 |</a> {malloced[which]=Malloc(len+delta+256); strncpy(malloced[which],ret,(unsigned)j);}
<a name="line1252">1252 |</a> ret=malloced[which];
<a name="line1253">1253 |</a> len+=256;
<a name="line1254">1254 |</a> }
<a name="line1255">1255 |</a> else
<a name="line1256">1256 |</a> {ret[j]=0; break;}
<a name="line1257">1257 |</a> }
<a name="line1258">1258 |</a> }
<a name="line1259">1259 |</a>
<a name="line1260">1260 |</a> return(ret);
<a name="line1261">1261 |</a> }
</pre>
</BODY>
</HTML>
|