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 >
Text File  |  1992-02-17  |  17KB  |  626 lines

  1.  
  2. /*
  3. ;---------------------------------------------------------------------------
  4. ;
  5. ; File......... MakDoc.C  
  6. ;
  7. ; Version...... 1.02
  8. ;
  9. ; Description.. TCXL help file documentor 
  10. ;               Creates an organized documented help file for use as
  11. ;               a software manual based on the ascii version of the 
  12. ;               help file used to create the TCXL online help file.
  13. ;               Also creates an include file for including in programs
  14. ;               to identify the help.
  15. ;
  16. ; Author....... Preston Stroud
  17. ;
  18. ; Date......... December 1991
  19. ;
  20. ; Company...... The West Company
  21. ;               3910 Rouse Rd
  22. ;               P.O. Box 1048
  23. ;               Kinston, NC 28501
  24. ;
  25. ; Compiler..... MSC v6.00A
  26. ;
  27. ; Compile...... cl /AL /Gs /Ot MakDoc.c /link Tprnm6l.lib TCXLM6L.lib /ST:10000 /SE:756
  28. ;
  29. ; Include...... MakDoc.h.... constants, structures, and function prototypes
  30. ;
  31. ; NOTE:  Both TCXL-DOX and TPRINT are needed to recompile program.
  32. ;---------------------------------------------------------------------------
  33. ; Changes:
  34. ;
  35. ; 02/17/92  1.02  PES  Modified to look up the printer driver in the 
  36. ;                      program execution path.
  37. ;
  38. ;---------------------------------------------------------------------------
  39. */
  40.  
  41.  
  42. /*--- include files ------------------------------------------------------*/
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47.  
  48. #include <TCXLstr.h>                   /* TCXL string functions         */
  49. #include <TCXLfmt.h>                   /* TCXL conversion functions     */
  50. #include <TCXLinp.h>                   /* TCXL input system             */
  51. #include <TCXLcod.h>                   /* TCXL key codes                */
  52.  
  53. #include <Tprint.h>                    /* TCXL printer control system   */
  54.  
  55. #define MAINMODULE
  56. #include "MakDoc.h"
  57.  
  58.  
  59. /*--- compiler specific --------------------------------------------------*/
  60.  
  61. #ifdef TURBO
  62. extern unsigned _stklen = 10000U;
  63. #endif
  64.  
  65.  
  66.  
  67. /*
  68. ;---------------------------------------------------------------------------
  69. ; Function.. main()
  70. ; Purpose... main controlling module of program
  71. ; Date...... January 1991
  72. ; Author.... Preston E Stroud
  73. ; Company... The West Company, Kinston ACS
  74. ;---------------------------------------------------------------------------
  75. */
  76.  
  77. main(IntT argc, ChrP argv[])
  78. {
  79.    Initialize(argv,argc);
  80.    MainProcess();
  81.    NormalExit();
  82. }
  83.  
  84.  
  85. /*
  86. ;---------------------------------------------------------------------------
  87. ; Function.. Initialize()
  88. ; Purpose... open file and init default values
  89. ; Date...... December 1991
  90. ; Author.... Preston E Stroud
  91. ; Company... The West Company, Kinston ACS
  92. ;---------------------------------------------------------------------------
  93. */
  94.  
  95. LCL VOID  CTYP  Initialize(ChrP argv[], IntT argc)
  96. {
  97.    IntT i,l, ok = YES;
  98.    ChrT msg[101],PrtFileName[81];
  99.  
  100.    TcxlInit();
  101.  
  102.    if( argc < 5 )
  103.       InfoExit();
  104.  
  105.    /*--- open output file ---*/
  106.  
  107.    data.firstindex = NULL;
  108.    data.start = NO;
  109.    data.end = NO;
  110.    data.head = YES;
  111.    data.currpage = 0;
  112.    data.currhelpnbr = 0;
  113.    data.currhelpname[0] = '\0';
  114.  
  115.    strcpy(data.OutFileName, argv[3]);     /* input file; TCXL ASCII help   */
  116.    strcpy(data.HeaderFileName, argv[2]);  /* header output for prog include*/
  117.    remove(data.HeaderFileName);
  118.    remove(data.OutFileName);
  119.  
  120.    /*--- get path of execution program ---*/
  121.  
  122.    i = strlen(argv[0]) -1 ;
  123.    while( (i != 0)  && (argv[0][i] != '\\'))
  124.    {
  125.       argv[0][i] = '\0';
  126.       i--;
  127.    }
  128.  
  129.    /*--- get printer file name ---*/
  130.  
  131.    strcpy(PrtFileName,argv[0]);
  132.    switch( argv[4][0] )
  133.    {
  134.       case 'H': strcat(PrtFileName, "HPLJSII.PRT"); break;
  135.       case 'E': strcat(PrtFileName, "EPSON.PRT"); break;
  136.       case 'I': 
  137.       default:  strcat(PrtFileName, "IBMPRO.PRT"); break;
  138.    }
  139.  
  140.    /*--- open input file ---*/
  141.  
  142.    if( (data.fn =  fopen(argv[1],"r")) == NULL )
  143.       ErrorExit("\nInput help file not found\n");
  144.  
  145.    /*--- open header file ---*/
  146.  
  147.    if( (data.hfn =  fopen(data.HeaderFileName,"w")) == NULL )
  148.       ErrorExit("\nInput header file name not found\n");
  149.  
  150.  
  151.    /*--- initialize TCXL printer control system ---*/
  152.  
  153.    PrInit(PrtFileName,7.5,10.0,4,2); 
  154.    PrStart(data.OutFileName,10,6);
  155.    PrMargin('L',5);
  156.  
  157.    /*--- format header / footer lines ---*/
  158.  
  159.    PrintLN(BOLD CPI10 "~MMMM DDDD, YYYY~                                   ~hh:mm:ss~", HEADERLINE );
  160.    PrintLN( " ", HEADERLINE);
  161.    msg[0] = '\0';
  162.    for(i=5; i<argc; i++)
  163.       strcat(strcat(msg,argv[i])," ");
  164.    PrintCN(msg, HEADERLINE);
  165.    PrintLN(BOLD " ", HEADERLINE);
  166.  
  167.    PrintCN(CPI10 "Page: ~####~", FOOTERLINE);
  168. }
  169.  
  170.  
  171. /*
  172. ;---------------------------------------------------------------------------
  173. ; Function.. MainProcess()
  174. ; Purpose... main process control block of program
  175. ; Date...... December 1991
  176. ; Author.... Preston E Stroud
  177. ; Company... The West Company, Kinston ACS
  178. ;---------------------------------------------------------------------------
  179. */
  180.  
  181. LCL VOID  CTYP  MainProcess(NOARG)
  182. {
  183.    LCL ChrP p = data.buff;
  184.    KeyT key;
  185.  
  186.    while( ! feof(data.fn) )
  187.    {
  188.       /*--- check for user abort ---*/
  189.       if( kbhit() )
  190.       {
  191.          if( (key = KeyGetc()) == Key_Esc )
  192.          {
  193.             fclose(data.fn);
  194.             fclose(data.hfn);
  195.             NormalExit();
  196.          }
  197.       }
  198.  
  199.       /*--- read data and process it ---*/
  200.  
  201.       fgets(p, MAXDATALINE, data.fn);
  202.       if( !feof(data.fn) )
  203.          ProcessData();
  204.    }
  205.  
  206.    /*--- print the summary (INDEX) ---*/
  207.  
  208.    ProcessSummary();
  209.  
  210.    /*--- close printer control system ---*/
  211.  
  212.    PrStop();
  213.    PrRelease();
  214. }
  215.  
  216.  
  217. /*
  218. ;---------------------------------------------------------------------------
  219. ; Function.. ProcessData()
  220. ; Purpose... process the data line read;
  221. ;            if start of help screen; put on new page
  222. ;            if end of help screen; form feed
  223. ;            if related help screens, allocate memory and put in index
  224. ;               for summary
  225. ; Date...... December 1991
  226. ; Author.... Preston E Stroud
  227. ; Company... The West Company, Kinston ACS
  228. ;---------------------------------------------------------------------------
  229. */
  230.  
  231. LCL VOID  CTYP  ProcessData(NOARG)
  232. {
  233.    IntT ok = YES;
  234.    ChrP p;
  235.  
  236.    /*--- check for beginning of help screen ---*/
  237.  
  238.    if( strlen(data.buff) > 0 )
  239.    {
  240.       if( (p = strstr(data.buff,"*B")) != NULL )
  241.       {
  242.          if( data.head )
  243.             PrWritePage();
  244.          ok = FALSE;
  245.          data.start = TRUE;
  246.          data.end = FALSE;
  247.          data.head = FALSE;
  248.          ProcessStart();
  249.       }
  250.  
  251.       /*--- check for help screen option page break ---*/
  252.  
  253.       if( (p = strstr(data.buff,"*P")) != NULL )
  254.       {
  255.          ok = FALSE;
  256.          if( data.start )
  257.          {
  258.             if(  PrRemainingLines() <= 10 )
  259.                PrWritePage();
  260.             else
  261.                PrBreaker(PAGEBREAK);
  262.          }
  263.       }
  264.  
  265.       /*--- check for end of help screen ---*/
  266.   
  267.       if( (p = strstr(data.buff,"*E")) != NULL )
  268.       {
  269.          ok = FALSE;
  270.          data.start = FALSE;
  271.          data.end = TRUE;
  272.          data.head = FALSE;
  273.          if(  PrRemainingLines() <= 10 )
  274.             PrWritePage();
  275.          else
  276.             PrBreaker(HELPBREAK);
  277.       }
  278.  
  279.       /*--- process referencing ---*/
  280.  
  281.       if( (p = strstr(data.buff,"^")) != NULL )
  282.          ProcessRef();
  283.    }
  284.  
  285.    /*--- check for data inbetween an end/start or at top ot help file ---*/
  286.  
  287.    if( ok && (!data.start))
  288.       if( (!data.start) && (!data.head) )
  289.          ok = NO;
  290.  
  291.    /*--- if everything ok, print out line ---*/
  292.  
  293.    if( ok )
  294.       PrintLN(data.buff,NORMALLINE);
  295.  
  296. }
  297.  
  298.  
  299. /*
  300. ;---------------------------------------------------------------------------
  301. ; Function.. ProcessSummary()
  302. ; Purpose... print out the summary of the help document
  303. ; Date...... December 1991
  304. ; Author.... Preston E Stroud
  305. ; Company... The West Company, Kinston ACS
  306. ;---------------------------------------------------------------------------
  307. */
  308.  
  309. LCL VOID  CTYP  ProcessSummary(NOARG)
  310. {
  311.    INDEXTYPE *iptr;
  312.    ChrT nbrstr[21];
  313.  
  314.    fclose(data.fn);
  315.    fclose(data.hfn);
  316.  
  317.    PrWritePage();
  318.  
  319.    /*--- sort index ---*/
  320.  
  321.    SortIndex();
  322.  
  323.    /*--- print index ---*/
  324.  
  325.    PrintLN(CPI10 " ",HEADERLINE);
  326.    PrintLN(" ",HEADERLINE);
  327.          /* Confirm Quit                              6        30 */
  328.    PrintLN("INDEX                                   PAGE  HELP NBR",HEADERLINE);
  329.    PrintLN("──────────────────────────────────────  ────  ────────",HEADERLINE);
  330.  
  331.    PrZeroFooter();
  332.  
  333.    iptr = data.firstindex;
  334.  
  335.    /*--- print each entry in index ---*/
  336.  
  337.    while(iptr != NULL)
  338.    {
  339.       Print( iptr->helpname, NORMALLINE );
  340.       PrCol(40);
  341.       cvtic(nbrstr,iptr->page,4);
  342.       Print(nbrstr, NORMALLINE);
  343.       PrCol(50);
  344.       cvtic(nbrstr,iptr->helpnbr,4);
  345.       Print( nbrstr, NORMALLINE);
  346.       PrSkipLines(1);
  347.       iptr = iptr->next;
  348.    }
  349.    PrWritePage();
  350. }
  351.  
  352.  
  353. /*
  354. ;---------------------------------------------------------------------------
  355. ; Function.. NormalExit()
  356. ; Purpose... normal exit routines
  357. ; Date...... December 1991
  358. ; Author.... Preston E Stroud
  359. ; Company... The West Company, Kinston ACS
  360. ;---------------------------------------------------------------------------
  361. */
  362.  
  363. LCL VOID  CTYP  NormalExit(NOARG)
  364. {
  365.    if( data.fn != NULL)
  366.       fclose(data.fn);
  367.    exit(0);
  368. }
  369.  
  370.  
  371. /*
  372. ;---------------------------------------------------------------------------
  373. ; Function.. ErrorExit()
  374. ; Purpose... error exit routine
  375. ; Date...... December 1991
  376. ; Author.... Preston E Stroud
  377. ; Company... The West Company, Kinston ACS
  378. ;---------------------------------------------------------------------------
  379. */
  380.  
  381. LCL VOID  CTYP  ErrorExit(ChrP msg)
  382. {
  383.    if( data.fn != NULL )
  384.       fclose(data.fn);
  385.    printf("\n%s\n",msg);
  386.    exit(0);
  387. }
  388.  
  389.  
  390. /*
  391. ;---------------------------------------------------------------------------
  392. ; Function.. InfoExit()
  393. ; Purpose... exit and display program operation instructions
  394. ; Date...... December 1991
  395. ; Author.... Preston E Stroud
  396. ; Company... The West Company, Kinston ACS
  397. ;---------------------------------------------------------------------------
  398. */
  399.  
  400. LCL VOID  CTYP  InfoExit(NOARG)
  401. {
  402.    printf("\n");
  403.    printf("USAGE:\n");
  404.    printf("   MAKDOC <input file> <output file 1> <output file 2> <printer> <text>\n");
  405.    printf("      <input file>..... TCXL ASCII help file\n");
  406.    printf("      <output file 1>.. include file for program with help identifiers\n");
  407.    printf("      <output file 2>.. program documentation manual\n");
  408.    printf("      <printer>........ (E)pson (I)BM PRO (H)ewlet Packerd Laser Jet\n");
  409.    printf("      <text>........... Page header text\n\n");
  410.    printf("   MAKDOC myprog.asc myprog.h myprog.doc E MY PROGRAM DOCUMENTATION Ver 2.1\n\n");
  411.    printf("AUTHOR:\n");
  412.    printf("   Preston Stroud\n");
  413.    printf("   P.O. Box 5036\n");
  414.    printf("   Kinston, NC  28501\n\n");
  415.    printf("NOTICE: (Version 1.01)\n");
  416.    printf("   This program has been placed into the public domain for usage by\n");
  417.    printf("   programmers using the Innovative Data Concepts, Inc. TesSeRact CXL\n");
  418.    printf("   User Interface Library.  It is being distributed free of charge AS IS\n");
  419.    printf("   but I will consider enhancing the program.  If you have any suggestions\n");
  420.    printf("   to make it more useful for you or others, please write or E-Mail on\n");
  421.    printf("   on the IDC BBS\n");
  422.    NormalExit();
  423. }
  424.  
  425.  
  426. /*
  427. ;---------------------------------------------------------------------------
  428. ; Function.. ProcessRef()
  429. ; Purpose... Process Referencing
  430. ; Date...... December 1991
  431. ; Author.... Preston E Stroud
  432. ; Company... The West Company, Kinston ACS
  433. ;---------------------------------------------------------------------------
  434. */
  435.  
  436. LCL VOID  CTYP  ProcessRef(NOARG)
  437. {
  438.    ChrT xname[MAXHELPNAME+1];
  439.    ChrP p;
  440.    IntT i,l;
  441.  
  442.    xname[0] = '\0';
  443.    if( (p = strstr(data.buff,"^")) != NULL )
  444.    {
  445.       i=0;
  446.       p[0] = ' ';
  447.       p++;
  448.       l=strlen(p);
  449.       while ( ( p[0] != '^' ) && ( i < l ) && ( p[0] != '\0' ) )
  450.       {
  451.          xname[i++] = p[0];
  452.          p++;
  453.       }
  454.       xname[i] = '\0';
  455.       if( p[0] = '^' )
  456.          p[0] = ' ';
  457.  
  458.       ProcessRef();
  459.    }
  460. }
  461.  
  462.  
  463. /*
  464. ;---------------------------------------------------------------------------
  465. ; Function.. PrBreaker()
  466. ; Purpose... print a breaker on the current page
  467. ; Date...... December 1991
  468. ; Author.... Preston E Stroud
  469. ; Company... The West Company, Kinston ACS
  470. ; Param..... PAGEBREAK... perform a page break for the same help number
  471. ;            HELPBREAK... perform a help break
  472. ;---------------------------------------------------------------------------
  473. */
  474.  
  475. LCL VOID  CTYP  PrBreaker(IntT breaktype )
  476. {
  477.    switch( breaktype )
  478.    {
  479.       case HELPBREAK:
  480.          {
  481.             PrSkipLines(2);
  482.             PrintLN("══════════════════════════════════════════════════════════",NORMALLINE);
  483.             PrSkipLines(2);
  484.             break;
  485.          }
  486.       case PAGEBREAK:
  487.          {
  488.             PrSkipLines(3);
  489.             break;
  490.          }
  491.       default: break;
  492.    }
  493. }
  494.  
  495.  
  496. /*
  497. ;---------------------------------------------------------------------------
  498. ; Function.. ProcessStart()
  499. ; Purpose... process the start line of a help screen
  500. ; Date...... December 1991
  501. ; Author.... Preston E Stroud
  502. ; Company... The West Company, Kinston ACS
  503. ;---------------------------------------------------------------------------
  504. */
  505.  
  506. LCL VOID  CTYP  ProcessStart(NOARG)
  507. {
  508.    IntT i,l,j,ok = YES;
  509.    ChrT nbrstr[10];
  510.    ChrT xname[MAXHELPNAME+1];
  511.    ChrP p;
  512.    INDEXTYPE *iptr,*xptr;
  513.  
  514.    /*--- get number of this help screen ---*/
  515.  
  516.    l = strlen(data.buff);
  517.    if( l >= 4 )
  518.    {
  519.       j = 2;
  520.       i = 0;
  521.       while( (j < l) && (data.buff[j] != ',') && (i < 9) )
  522.          nbrstr[i++] = data.buff[j++];
  523.       nbrstr[i] = '\0';
  524.       data.currhelpnbr = cvtci(nbrstr);
  525.    }
  526.    else
  527.       ok = NO;
  528.  
  529.    /*--- get actual name for this help screen ---*/
  530.  
  531.    if( (p = strstr(data.buff,",")) != NULL )
  532.    {
  533.       p++;
  534.       strcpy(data.currhelpname,p);
  535.       if( strlen(data.currhelpname) > 1)
  536.          data.currhelpname[strlen(data.currhelpname)-1] = '\0';
  537.    }
  538.    else
  539.       ok = NO;
  540.  
  541.    /*--- allocate memory and put data into new index record ---*/
  542.  
  543.    if( ok )
  544.    {
  545.       if( (iptr = calloc(1, sizeof(INDEXTYPE))) == NULL )
  546.          ErrorExit("Failed to allocate memory for index name");
  547.  
  548.       /*--- put data into new index record ---*/
  549.  
  550.       iptr->next = NULL;
  551.       iptr->helpnbr = data.currhelpnbr;
  552.       data.currpage = CurrentPage();
  553.       iptr->page = data.currpage;
  554.       strcpy(iptr->helpname, data.currhelpname );
  555.  
  556.       if( data.firstindex == NULL )
  557.          data.firstindex = iptr;
  558.       else
  559.       {
  560.          xptr = data.firstindex;
  561.          while( xptr->next != NULL )
  562.             xptr = xptr->next;
  563.          xptr->next = iptr;
  564.       }
  565.  
  566.       /*--- print header data for this help screen ---*/
  567.  
  568.       Print(data.currhelpname,NORMALLINE);
  569.       Print("  (",NORMALLINE);
  570.       cvtic(nbrstr,data.currhelpnbr,4);
  571.       Print(nbrstr,NORMALLINE);
  572.       Print(")",NORMALLINE);
  573.       PrSkipLines(2);
  574.  
  575.       fputs("#define H_",data.hfn);
  576.       strcpy(xname,data.currhelpname);
  577.       strchg(xname,' ','_');
  578.       fputs(xname,data.hfn);
  579.       fputs(" ",data.hfn);
  580.       fputs(nbrstr,data.hfn);
  581.       fputs("\n",data.hfn);
  582.    }
  583. }
  584.  
  585.  
  586. /*
  587. ;---------------------------------------------------------------------------
  588. ; Function.. SortIndex()
  589. ; Purpose... sort the index in ascending order
  590. ; Date...... December 1991
  591. ; Author.... Preston E Stroud
  592. ; Company... The West Company, Kinston ACS
  593. ;---------------------------------------------------------------------------
  594. */
  595.  
  596. LCL VOID  CTYP  SortIndex(NOARG)
  597. {
  598.    INDEXTYPE *iptr, *xptr, temp;
  599.  
  600.    iptr = data.firstindex;
  601.    while( iptr != NULL )
  602.    {
  603.       xptr = iptr;
  604.       while (xptr != NULL)
  605.       {
  606.          if( strcmp(iptr->helpname, xptr->helpname) > 0 )
  607.          {
  608.             /*--- switch ---*/
  609.             strcpy(temp.helpname,iptr->helpname);
  610.             temp.page = iptr->page;
  611.             temp.helpnbr = iptr->helpnbr;
  612.  
  613.             strcpy(iptr->helpname, xptr->helpname);
  614.             iptr->page = xptr->page;
  615.             iptr->helpnbr = xptr->helpnbr;
  616.  
  617.             strcpy(xptr->helpname, temp.helpname);
  618.             xptr->page = temp.page;
  619.             xptr->helpnbr = temp.helpnbr;
  620.          }
  621.          xptr = xptr->next;
  622.       }
  623.       iptr = iptr->next;
  624.    }
  625. }
  626.