/***************************************************************************** SET's Documentation Helper (SDH) Copyright(c) 1997 by Salvador Eduardo Tropea This program is used to automate the creation of .info, .txt, .html, .dvi and .ps files from one source file (.tx). See copyrigh file for details. Normally located in the root of the distribution. This file can be distributed under the terms of the GPL license. *****************************************************************************/ #include #include #include #include #include #include #include "ucdefs.h" /* returns: 1 => bad command line. 2 => Can't open input file. 3 => Hierarchy error. 4 => Can't create output 5 => Error when spawning 6 => Cross reference error */ //char *outf=NULL; char *inf=NULL; FILE *fi,*fo,*fo2; #define MAX_BL 800 char bl[MAX_BL]; char b2[MAX_BL]; int TopFound=0; int CurLevel=0; int KindOfLevel; int PutPoint=0; #define MAX_IND 4 char *IndexNames[MAX_IND]; char *FilesIndex[MAX_IND]; char *FilesIndexTXT[MAX_IND]; int IndexFound[MAX_IND]; int cantIndices=0; int makeClean=0; char *OutPathOrig=NULL; char OutPath[PATH_MAX]; #define MAX_SEARCH 10 char *SeachPaths[MAX_SEARCH]; int CantSearchs=0; char Include[PATH_MAX]; #define enc850 0 #define enc8859_1 1 int Encoding=enc8859_1; //#define DEBUG // Kind of numbers // The top isn't numbered and is special #define K_TOP 0 // Numbered chapters, sections, subsections and subsubsections #define K_NORMAL 1 // Unnumbered sections #define K_UNNUM 2 // Appendices with roman numbers?, I'll implement letters first #define K_ROMAN 3 #define F_INFO 1 #define F_TXT 2 #define F_HTML 4 #define F_DVI 8 #define F_PS 16 #define F_ALL 31 int outFormats=0; typedef struct { int Level; int Type; char *name; char *Number; } aNode; #define Inic_Nodes 100 #define Delta_Nodes 20 aNode *Nodes=NULL; int cantNodes=0; int cantAllocNodes=0; char *SearchNode(char *name); static void AccentsLine(); void PutCopy(void) { printf("SET's Documentation Helper (SDH)\n" "Copyright (c) 1997 by Salvador Eduardo Tropea\n\n"); } void PutHelp(int ret) { PutCopy(); printf("sdh -i input_file [-p] [-n \"name\" file file_txt] [-c] [-oihtdpa] [-I path]\n" " [-O path]\n\n" "in_file is the BASE name of the documentation (.tx)\n" "-p: Put X. instead of X in chapter numbers\n" "-n \"name\" file file_txt: for indices\n" "-c: clean, deletes intermediate files\n" "-oX: output format, i=.info h=.html t=.txt d=.dvi p=.ps a=ALL\n" "-I path: adds the path to the search paths\n" "-O path: output path\n" "\n"); if (ret) exit(ret); } void PutPathIn(char *name,char *path) { char *v; if (path) { strcpy(name,path); v=name+strlen(name)-1; if (*v!='/' && *v!='\\') { *(v+1)='/'; *(v+2)=0; } } else *name=0; } void ParseCommandLine(int argc, char *argv[]) { int i,OneMore,ThreeMore,j; if (argc<2) PutHelp(1); for (i=1; iCurLevel && (Level-CurLevel)>1) { printf("You are jumping from level %d to level %d!",CurLevel,Level); exit(3); } CurLevel=Level; } void ProcessLine(void) { int Level=GetLevel(); if (strncmp(bl,"@node",5)==0) { printf("Don't use @node, use @unnumbered instead\n"); exit(3); //AddNode(-1); } if (strncmp(bl,"@documentencoding",17)==0) { if (strstr(bl,"8859-1")) { Encoding=enc8859_1; } else if (strstr(bl,"850")) { Encoding=enc850; } } if (Level>=0) { AddNode(Level); return; } } void ReadLine(void) { fgets(bl,MAX_BL,fi); } void Rewind(void) { rewind(fi); } void ScanFile(void) { do { ReadLine(); AccentsLine(); ProcessLine(); } while (!feof(fi)); Rewind(); } #ifdef DEBUG void DumpNodes(void) { int i,j; for (i=0; i "); else for (;j>=0;--j) printf(" "); printf("%s Name: %s (%d)\n",Nodes[i].Number,Nodes[i].name,Nodes[i].Type); } } #else #define DumpNodes() #endif char *emptyStr=" "; char *ProxNodeOf(int i) { if ((i+1)=0) { nlev=Nodes[i].Level; name=nlev ? Nodes[i].name : "Top"; if (nlev>levant) { aprev[nlev]=prev; GenMenu(i,fo); GenMenu(i,fo2); } fprintf(fo2,"@node %s, %s, %s, %s\n",name,ProxNodeOf(i),aprev[nlev],up[nlev]); fprintf(fo,"@node_{%s, %s, %s, %s}\n",name,ProxNodeOf(i),aprev[nlev],up[nlev]); prev=name; aprev[nlev]=prev; up[nlev+1]=name; levant=nlev; i++; } fputs(bl,fo2); if (lev<0) HTMLPrep(bl,fo); else InsertNumber(bl,Nodes[i-1].Number,fo); } while (!feof(fi)); fclose(fo); fclose(fo2); Rewind(); } char *emptyStr2=""; void Numerate(void) { int num[2][6]; int i,lev,levant=0,type,sub,j; char b[80],b1[20]; memset(num,0,6*2*sizeof(int)); for (i=0; ilev); num[sub][lev]++; if (sub) sprintf(b,"%c",'A'+num[sub][1]-1); else sprintf(b,"%d",num[sub][1]); for (j=2; num[sub][j]; j++) { sprintf(b1,".%d",num[sub][j]); strcat(b,b1); } if (PutPoint && num[sub][2]==0) strcat(b,". "); else strcat(b,emptyStr); Nodes[i].Number=strdup(b); levant=lev; } } void GenerateCTX(void) { int i,nlev,curlev=0; CreateFile(".ctx"); for (i=1; icurlev) fputs("\n",fo); else if (nlev\n",fo); } while(--curlev>nlev); fprintf(fo,"@w{
  • %s%s}\n",Nodes[i].name,Nodes[i].Number,Nodes[i].name); curlev=nlev; } if (curlev) do { fputs("
  • \n",fo); } while(--curlev); fclose(fo); } void GenerateINFO(void) { int error; char s[6*PATH_MAX]; // No validate because makeinfo can't see through mitem{} (another weak point) sprintf(s,"makeinfo %s --no-split --fill-column 75 --no-validate -o %s%s.inf %s%s.num",Include,OutPath,inf,OutPath,inf); //sprintf(s,"makertf %s --no-split --fill-column 75 --no-validate -o %s%s.inf %s%s.num",Include,OutPath,inf,OutPath,inf); error=system(s); if (error) { printf("Failed executing:\n%s\n",s); exit(5); } } static void ConvASCII(unsigned char *s, unsigned char *e, FILE *f) { char **Table=Encoding==enc850 ? Conv850 : Conv8859_1; for (;s @w{",f); ConvASCII(start1,end1,f); fputs("} @*\n",f); } static void ConvertToTXT(char *s,FILE *f) { char *p; for (p=s; *p && *p!=':'; p++); if (!*p) return; #if 0 if (/*p[-1]=='>' || p[-1]=='<' || */*p=='/') return; else printf("%s",p); #endif for (p++; *p && ucisspace(*p); p++); if (!*p) return; ConvASCII(s,p,f); s=p; for (;*p && *p!='.'; p++); *p=0; fputs(SearchNode(s),f); fputs("\n",f); } int NextNode(FILE *f) { char *pos,*s; while (*bl!=31 && !feof(f)) { fgets(bl,MAX_BL,f); } if (feof(f)) return 0; do { fgets(bl,MAX_BL,f); } while (ucisspace(*bl) && !feof(f)); pos=strstr(bl,"Node:"); if (!pos) return 0; for (pos+=6; *pos && ucisspace(*pos); pos++); for (s=bl; *pos!=','; pos++,s++) *s=*pos; *s=0; return 1; } void GenerateIDX(int ForTXT) { char name[PATH_MAX],*n; FILE *f,*o; int i; void (*Convert)(char *s,FILE *f); Convert=ForTXT ? ConvertToTXT : ConvertToHTML; if (!cantIndices) return; memset(IndexFound,0,MAX_IND*sizeof(int)); f=OpenInFile(".inf"); if (!f) { printf("Can't open %s\n",name); exit(2); } *bl=0; do { if (NextNode(f)) { for (i=0; i