home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / utilities / text / easyguide / easyguide.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-21  |  4.9 KB  |  201 lines

  1. /*********************************************************
  2. * EasyGuide - adds features to make amigaguide building
  3. *          easier.  Compile with EasyGuide to generate
  4. *          a standard guide file.
  5. *
  6. * Copyright:
  7. *    EasyGuide is Copyright © 1995 Douglas M. Dyer,
  8. *    all rights reserved.
  9. *    (Im doing this to keep track of improvements)
  10. *
  11. * Distribution:
  12. *    100% Public Domain.  Please improve it and
  13. *    send me your modifications, I will then document
  14. *    your change and create a new release. Also,
  15. *    feel free to send me comments.
  16. *
  17. *    Do not distribute your modifications, email them
  18. *    to me and I will re-release it.
  19. *
  20. * Original Author:
  21. *    Douglas M. Dyer, dyer@alx.sticomet.com
  22. *
  23. * Modifications:
  24. *    Name        Email/Description
  25. *    Doug Dyer    dyer@alx.sticomet.com
  26. *            Initial writing
  27. *
  28. *
  29. * Features:
  30. *    Emulate @{SMARTWRAP} without requiring v40 of 
  31. *    amigaguide. (you need to have @WORDWRAP in your file)
  32. *
  33. *    Modify or extend a set of macros as seen fit.
  34. *    The default macros are for headings.
  35. *
  36. * usage: 
  37. *    easyguide myguide.src myguide.guide
  38. *
  39. *********************************************************/
  40.  
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <stdlib.h>
  44.  
  45. #define EGVERSION "1.0"
  46.  
  47. static const char *VersionString = "\0$VER:" EGVERSION " " __AMIGADATE__;
  48. static const char *copyright = "Copyright © 1995 Douglas M. Dyer, All rights reserved";
  49.  
  50. /* default wrap strings */
  51. #define I_BEGINWRAP    "@BEGINWRAP"
  52. #define I_ENDWRAP    "@ENDWRAP"
  53.  
  54.  
  55. #define BUFSIZE 512    /* file line size */
  56. #define MAXSIZE 100    /* macro size */
  57.  
  58. /**********************************************************************
  59. * NOTE NOTE NOTE 
  60. * To add a macro, do two things:
  61. * 1) add to the NUMMACROS define to include your macros
  62. * 2) using the usrMacro structure definition, add to the macroList array
  63. ***********************************************************************/ 
  64.  
  65. /* number of macros defined */
  66. #define NUMMACROS     3
  67.  
  68. /* now create the macro definitions */
  69. struct usrMacro{
  70.     char identify[MAXSIZE];        /* macro name as seen in source file */
  71.     char beginstring[MAXSIZE];    /* AG commands prior to heading string */
  72.     char endstring[MAXSIZE];    /* AG commands after heading string */
  73.     char underline[2];        /* "" = no underline. Supply any character (ie: "-") */
  74.     char extra;            /* used for underline to count spaces in heading macros */
  75. } macroList[] = {
  76.  
  77. { "@HEADING",
  78.     "\n@{BG FILL}     @{FG HIGHLIGHT}@{I}",
  79.     " @{UI}@{BG BACK}@{FG TEXT}\n",
  80.     "~",
  81.     6 },
  82.  
  83. { "@SUBHEADING",
  84.     "@{FG SHINE}",
  85.     "@{FG TEXT}\n",
  86.     "",
  87.     0 },
  88.  
  89. { "@SUBITEM",
  90.     "@{B}",
  91.     "@{UB}\n",
  92.     "",
  93.     0 }
  94. };
  95.  
  96. FILE *input, *output;
  97. char buffer[BUFSIZE];
  98.  
  99. /***********************************************************
  100. * Main()
  101. *
  102. *     You shouldn't have to mess with anything here,
  103. *    just the macro definitions above.  You can even
  104. *    add them without modifying. Note, this code
  105. *    is also not the cleanest thing :)
  106. ***********************************************************/
  107. main(int argc, char *argv[])
  108. {
  109. int bline = 0, cline=0;
  110. int wrapmode = 0;
  111. int headermode = 0;
  112. int offset, index;
  113.  
  114.  
  115. /* some startup initialization stuff */
  116.  
  117. if (argc != 3) {
  118.     fprintf(stderr,"Usage: %s <inputfile> <output guide file>\n");
  119.     exit(0);
  120. }
  121.  
  122. if ( (input = fopen(argv[1],"r")) == NULL) {
  123.     fprintf(stderr,"Cannot read file %s\n",argv[1]);
  124.     exit(0);
  125. }
  126.  
  127. if ( (output = fopen(argv[2],"wc")) == NULL) {
  128.     fprintf(stderr,"Cannot create file %s\n",argv[2]);
  129.     fclose(input);
  130.     exit(0);
  131. }
  132.  
  133. /* loop on each line of amigaguide source */
  134. while (fgets (buffer,BUFSIZE,input) != NULL) {
  135.     cline++;
  136.  
  137.     for (index=0;index<NUMMACROS;index++) {
  138.         if (strnicmp(buffer, macroList[index].identify,
  139.                 strlen(macroList[index].identify)) == 0) {
  140.             headermode = index+1;
  141.             goto endwhile; /* continue inside of for... */
  142.         }
  143.     }
  144.  
  145.     if (strnicmp(buffer,I_BEGINWRAP,strlen(I_BEGINWRAP)) == 0) {
  146.         if (wrapmode == 1) {
  147.             fprintf(stderr,"@BEGINWRAP on line %d missing @ENDWRAP\n",bline);
  148.             goto OUT;
  149.         }
  150.         bline = cline;
  151.         wrapmode = 1;
  152.         fprintf(output,"\n");
  153.         continue;
  154.     }
  155.     else if (strnicmp(buffer,I_ENDWRAP,strlen(I_ENDWRAP)) == 0) {
  156.         if (wrapmode == 0) {
  157.             fprintf(stderr,"@ENDWRAP on line %d missing @BEGINWRAP\n",cline);
  158.             goto OUT;
  159.         }
  160.  
  161.         wrapmode = 0;
  162.         fprintf(output,"\n");
  163.         continue;
  164.     }
  165.  
  166.      /* replace all newlines with spaces if needed */
  167.     if (wrapmode && buffer[0] != '\n') {
  168.         offset = strcspn(buffer,"\n");
  169.         buffer[offset] = ' ';        
  170.     }
  171.  
  172.     /* do we need to insert a header? */
  173.     if (headermode) {
  174.         fprintf(output,macroList[headermode-1].beginstring);
  175.         if (strlen(buffer)) buffer[strlen(buffer)-1]=0;
  176.     }
  177.  
  178.     /* now output the actual string */
  179.     fprintf(output,"%s",buffer);
  180.  
  181.     /* close up header? */
  182.     if (headermode) {
  183.         fprintf(output,macroList[headermode-1].endstring);
  184.         if (strlen(macroList[headermode-1].underline) > 0) {
  185.             for (index=strlen(buffer)+macroList[headermode-1].extra; index>0;index--)
  186.                 fprintf(output,macroList[headermode-1].underline);
  187.             fprintf(output,"\n");
  188.         }
  189.  
  190.         headermode = 0;
  191.     }
  192.  
  193. endwhile:
  194. } /* end of main loop */
  195.  
  196.  
  197. OUT:
  198. fclose(input);
  199. fclose(output);
  200. }
  201.