home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
MAKDOC12
/
MAKDOC.C
< prev
next >
Wrap
Text File
|
1992-02-17
|
17KB
|
626 lines
/*
;---------------------------------------------------------------------------
;
; File......... MakDoc.C
;
; Version...... 1.02
;
; Description.. TCXL help file documentor
; Creates an organized documented help file for use as
; a software manual based on the ascii version of the
; help file used to create the TCXL online help file.
; Also creates an include file for including in programs
; to identify the help.
;
; Author....... Preston Stroud
;
; Date......... December 1991
;
; Company...... The West Company
; 3910 Rouse Rd
; P.O. Box 1048
; Kinston, NC 28501
;
; Compiler..... MSC v6.00A
;
; Compile...... cl /AL /Gs /Ot MakDoc.c /link Tprnm6l.lib TCXLM6L.lib /ST:10000 /SE:756
;
; Include...... MakDoc.h.... constants, structures, and function prototypes
;
; NOTE: Both TCXL-DOX and TPRINT are needed to recompile program.
;---------------------------------------------------------------------------
; Changes:
;
; 02/17/92 1.02 PES Modified to look up the printer driver in the
; program execution path.
;
;---------------------------------------------------------------------------
*/
/*--- include files ------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <TCXLstr.h> /* TCXL string functions */
#include <TCXLfmt.h> /* TCXL conversion functions */
#include <TCXLinp.h> /* TCXL input system */
#include <TCXLcod.h> /* TCXL key codes */
#include <Tprint.h> /* TCXL printer control system */
#define MAINMODULE
#include "MakDoc.h"
/*--- compiler specific --------------------------------------------------*/
#ifdef TURBO
extern unsigned _stklen = 10000U;
#endif
/*
;---------------------------------------------------------------------------
; Function.. main()
; Purpose... main controlling module of program
; Date...... January 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
main(IntT argc, ChrP argv[])
{
Initialize(argv,argc);
MainProcess();
NormalExit();
}
/*
;---------------------------------------------------------------------------
; Function.. Initialize()
; Purpose... open file and init default values
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP Initialize(ChrP argv[], IntT argc)
{
IntT i,l, ok = YES;
ChrT msg[101],PrtFileName[81];
TcxlInit();
if( argc < 5 )
InfoExit();
/*--- open output file ---*/
data.firstindex = NULL;
data.start = NO;
data.end = NO;
data.head = YES;
data.currpage = 0;
data.currhelpnbr = 0;
data.currhelpname[0] = '\0';
strcpy(data.OutFileName, argv[3]); /* input file; TCXL ASCII help */
strcpy(data.HeaderFileName, argv[2]); /* header output for prog include*/
remove(data.HeaderFileName);
remove(data.OutFileName);
/*--- get path of execution program ---*/
i = strlen(argv[0]) -1 ;
while( (i != 0) && (argv[0][i] != '\\'))
{
argv[0][i] = '\0';
i--;
}
/*--- get printer file name ---*/
strcpy(PrtFileName,argv[0]);
switch( argv[4][0] )
{
case 'H': strcat(PrtFileName, "HPLJSII.PRT"); break;
case 'E': strcat(PrtFileName, "EPSON.PRT"); break;
case 'I':
default: strcat(PrtFileName, "IBMPRO.PRT"); break;
}
/*--- open input file ---*/
if( (data.fn = fopen(argv[1],"r")) == NULL )
ErrorExit("\nInput help file not found\n");
/*--- open header file ---*/
if( (data.hfn = fopen(data.HeaderFileName,"w")) == NULL )
ErrorExit("\nInput header file name not found\n");
/*--- initialize TCXL printer control system ---*/
PrInit(PrtFileName,7.5,10.0,4,2);
PrStart(data.OutFileName,10,6);
PrMargin('L',5);
/*--- format header / footer lines ---*/
PrintLN(BOLD CPI10 "~MMMM DDDD, YYYY~ ~hh:mm:ss~", HEADERLINE );
PrintLN( " ", HEADERLINE);
msg[0] = '\0';
for(i=5; i<argc; i++)
strcat(strcat(msg,argv[i])," ");
PrintCN(msg, HEADERLINE);
PrintLN(BOLD " ", HEADERLINE);
PrintCN(CPI10 "Page: ~####~", FOOTERLINE);
}
/*
;---------------------------------------------------------------------------
; Function.. MainProcess()
; Purpose... main process control block of program
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP MainProcess(NOARG)
{
LCL ChrP p = data.buff;
KeyT key;
while( ! feof(data.fn) )
{
/*--- check for user abort ---*/
if( kbhit() )
{
if( (key = KeyGetc()) == Key_Esc )
{
fclose(data.fn);
fclose(data.hfn);
NormalExit();
}
}
/*--- read data and process it ---*/
fgets(p, MAXDATALINE, data.fn);
if( !feof(data.fn) )
ProcessData();
}
/*--- print the summary (INDEX) ---*/
ProcessSummary();
/*--- close printer control system ---*/
PrStop();
PrRelease();
}
/*
;---------------------------------------------------------------------------
; Function.. ProcessData()
; Purpose... process the data line read;
; if start of help screen; put on new page
; if end of help screen; form feed
; if related help screens, allocate memory and put in index
; for summary
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP ProcessData(NOARG)
{
IntT ok = YES;
ChrP p;
/*--- check for beginning of help screen ---*/
if( strlen(data.buff) > 0 )
{
if( (p = strstr(data.buff,"*B")) != NULL )
{
if( data.head )
PrWritePage();
ok = FALSE;
data.start = TRUE;
data.end = FALSE;
data.head = FALSE;
ProcessStart();
}
/*--- check for help screen option page break ---*/
if( (p = strstr(data.buff,"*P")) != NULL )
{
ok = FALSE;
if( data.start )
{
if( PrRemainingLines() <= 10 )
PrWritePage();
else
PrBreaker(PAGEBREAK);
}
}
/*--- check for end of help screen ---*/
if( (p = strstr(data.buff,"*E")) != NULL )
{
ok = FALSE;
data.start = FALSE;
data.end = TRUE;
data.head = FALSE;
if( PrRemainingLines() <= 10 )
PrWritePage();
else
PrBreaker(HELPBREAK);
}
/*--- process referencing ---*/
if( (p = strstr(data.buff,"^")) != NULL )
ProcessRef();
}
/*--- check for data inbetween an end/start or at top ot help file ---*/
if( ok && (!data.start))
if( (!data.start) && (!data.head) )
ok = NO;
/*--- if everything ok, print out line ---*/
if( ok )
PrintLN(data.buff,NORMALLINE);
}
/*
;---------------------------------------------------------------------------
; Function.. ProcessSummary()
; Purpose... print out the summary of the help document
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP ProcessSummary(NOARG)
{
INDEXTYPE *iptr;
ChrT nbrstr[21];
fclose(data.fn);
fclose(data.hfn);
PrWritePage();
/*--- sort index ---*/
SortIndex();
/*--- print index ---*/
PrintLN(CPI10 " ",HEADERLINE);
PrintLN(" ",HEADERLINE);
/* Confirm Quit 6 30 */
PrintLN("INDEX PAGE HELP NBR",HEADERLINE);
PrintLN("────────────────────────────────────── ──── ────────",HEADERLINE);
PrZeroFooter();
iptr = data.firstindex;
/*--- print each entry in index ---*/
while(iptr != NULL)
{
Print( iptr->helpname, NORMALLINE );
PrCol(40);
cvtic(nbrstr,iptr->page,4);
Print(nbrstr, NORMALLINE);
PrCol(50);
cvtic(nbrstr,iptr->helpnbr,4);
Print( nbrstr, NORMALLINE);
PrSkipLines(1);
iptr = iptr->next;
}
PrWritePage();
}
/*
;---------------------------------------------------------------------------
; Function.. NormalExit()
; Purpose... normal exit routines
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP NormalExit(NOARG)
{
if( data.fn != NULL)
fclose(data.fn);
exit(0);
}
/*
;---------------------------------------------------------------------------
; Function.. ErrorExit()
; Purpose... error exit routine
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP ErrorExit(ChrP msg)
{
if( data.fn != NULL )
fclose(data.fn);
printf("\n%s\n",msg);
exit(0);
}
/*
;---------------------------------------------------------------------------
; Function.. InfoExit()
; Purpose... exit and display program operation instructions
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP InfoExit(NOARG)
{
printf("\n");
printf("USAGE:\n");
printf(" MAKDOC <input file> <output file 1> <output file 2> <printer> <text>\n");
printf(" <input file>..... TCXL ASCII help file\n");
printf(" <output file 1>.. include file for program with help identifiers\n");
printf(" <output file 2>.. program documentation manual\n");
printf(" <printer>........ (E)pson (I)BM PRO (H)ewlet Packerd Laser Jet\n");
printf(" <text>........... Page header text\n\n");
printf(" MAKDOC myprog.asc myprog.h myprog.doc E MY PROGRAM DOCUMENTATION Ver 2.1\n\n");
printf("AUTHOR:\n");
printf(" Preston Stroud\n");
printf(" P.O. Box 5036\n");
printf(" Kinston, NC 28501\n\n");
printf("NOTICE: (Version 1.01)\n");
printf(" This program has been placed into the public domain for usage by\n");
printf(" programmers using the Innovative Data Concepts, Inc. TesSeRact CXL\n");
printf(" User Interface Library. It is being distributed free of charge AS IS\n");
printf(" but I will consider enhancing the program. If you have any suggestions\n");
printf(" to make it more useful for you or others, please write or E-Mail on\n");
printf(" on the IDC BBS\n");
NormalExit();
}
/*
;---------------------------------------------------------------------------
; Function.. ProcessRef()
; Purpose... Process Referencing
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP ProcessRef(NOARG)
{
ChrT xname[MAXHELPNAME+1];
ChrP p;
IntT i,l;
xname[0] = '\0';
if( (p = strstr(data.buff,"^")) != NULL )
{
i=0;
p[0] = ' ';
p++;
l=strlen(p);
while ( ( p[0] != '^' ) && ( i < l ) && ( p[0] != '\0' ) )
{
xname[i++] = p[0];
p++;
}
xname[i] = '\0';
if( p[0] = '^' )
p[0] = ' ';
ProcessRef();
}
}
/*
;---------------------------------------------------------------------------
; Function.. PrBreaker()
; Purpose... print a breaker on the current page
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
; Param..... PAGEBREAK... perform a page break for the same help number
; HELPBREAK... perform a help break
;---------------------------------------------------------------------------
*/
LCL VOID CTYP PrBreaker(IntT breaktype )
{
switch( breaktype )
{
case HELPBREAK:
{
PrSkipLines(2);
PrintLN("══════════════════════════════════════════════════════════",NORMALLINE);
PrSkipLines(2);
break;
}
case PAGEBREAK:
{
PrSkipLines(3);
break;
}
default: break;
}
}
/*
;---------------------------------------------------------------------------
; Function.. ProcessStart()
; Purpose... process the start line of a help screen
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP ProcessStart(NOARG)
{
IntT i,l,j,ok = YES;
ChrT nbrstr[10];
ChrT xname[MAXHELPNAME+1];
ChrP p;
INDEXTYPE *iptr,*xptr;
/*--- get number of this help screen ---*/
l = strlen(data.buff);
if( l >= 4 )
{
j = 2;
i = 0;
while( (j < l) && (data.buff[j] != ',') && (i < 9) )
nbrstr[i++] = data.buff[j++];
nbrstr[i] = '\0';
data.currhelpnbr = cvtci(nbrstr);
}
else
ok = NO;
/*--- get actual name for this help screen ---*/
if( (p = strstr(data.buff,",")) != NULL )
{
p++;
strcpy(data.currhelpname,p);
if( strlen(data.currhelpname) > 1)
data.currhelpname[strlen(data.currhelpname)-1] = '\0';
}
else
ok = NO;
/*--- allocate memory and put data into new index record ---*/
if( ok )
{
if( (iptr = calloc(1, sizeof(INDEXTYPE))) == NULL )
ErrorExit("Failed to allocate memory for index name");
/*--- put data into new index record ---*/
iptr->next = NULL;
iptr->helpnbr = data.currhelpnbr;
data.currpage = CurrentPage();
iptr->page = data.currpage;
strcpy(iptr->helpname, data.currhelpname );
if( data.firstindex == NULL )
data.firstindex = iptr;
else
{
xptr = data.firstindex;
while( xptr->next != NULL )
xptr = xptr->next;
xptr->next = iptr;
}
/*--- print header data for this help screen ---*/
Print(data.currhelpname,NORMALLINE);
Print(" (",NORMALLINE);
cvtic(nbrstr,data.currhelpnbr,4);
Print(nbrstr,NORMALLINE);
Print(")",NORMALLINE);
PrSkipLines(2);
fputs("#define H_",data.hfn);
strcpy(xname,data.currhelpname);
strchg(xname,' ','_');
fputs(xname,data.hfn);
fputs(" ",data.hfn);
fputs(nbrstr,data.hfn);
fputs("\n",data.hfn);
}
}
/*
;---------------------------------------------------------------------------
; Function.. SortIndex()
; Purpose... sort the index in ascending order
; Date...... December 1991
; Author.... Preston E Stroud
; Company... The West Company, Kinston ACS
;---------------------------------------------------------------------------
*/
LCL VOID CTYP SortIndex(NOARG)
{
INDEXTYPE *iptr, *xptr, temp;
iptr = data.firstindex;
while( iptr != NULL )
{
xptr = iptr;
while (xptr != NULL)
{
if( strcmp(iptr->helpname, xptr->helpname) > 0 )
{
/*--- switch ---*/
strcpy(temp.helpname,iptr->helpname);
temp.page = iptr->page;
temp.helpnbr = iptr->helpnbr;
strcpy(iptr->helpname, xptr->helpname);
iptr->page = xptr->page;
iptr->helpnbr = xptr->helpnbr;
strcpy(xptr->helpname, temp.helpname);
xptr->page = temp.page;
xptr->helpnbr = temp.helpnbr;
}
xptr = xptr->next;
}
iptr = iptr->next;
}
}