home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************
- * EasyGuide - adds features to make amigaguide building
- * easier. Compile with EasyGuide to generate
- * a standard guide file.
- *
- * Copyright:
- * EasyGuide is Copyright © 1995 Douglas M. Dyer,
- * all rights reserved.
- * (Im doing this to keep track of improvements)
- *
- * Distribution:
- * 100% Public Domain. Please improve it and
- * send me your modifications, I will then document
- * your change and create a new release. Also,
- * feel free to send me comments.
- *
- * Do not distribute your modifications, email them
- * to me and I will re-release it.
- *
- * Original Author:
- * Douglas M. Dyer, dyer@alx.sticomet.com
- *
- * Modifications:
- * Name Email/Description
- * Doug Dyer dyer@alx.sticomet.com
- * Initial writing
- *
- *
- * Features:
- * Emulate @{SMARTWRAP} without requiring v40 of
- * amigaguide. (you need to have @WORDWRAP in your file)
- *
- * Modify or extend a set of macros as seen fit.
- * The default macros are for headings.
- *
- * usage:
- * easyguide myguide.src myguide.guide
- *
- *********************************************************/
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- #define EGVERSION "1.0"
-
- static const char *VersionString = "\0$VER:" EGVERSION " " __AMIGADATE__;
- static const char *copyright = "Copyright © 1995 Douglas M. Dyer, All rights reserved";
-
- /* default wrap strings */
- #define I_BEGINWRAP "@BEGINWRAP"
- #define I_ENDWRAP "@ENDWRAP"
-
-
- #define BUFSIZE 512 /* file line size */
- #define MAXSIZE 100 /* macro size */
-
- /**********************************************************************
- * NOTE NOTE NOTE
- * To add a macro, do two things:
- * 1) add to the NUMMACROS define to include your macros
- * 2) using the usrMacro structure definition, add to the macroList array
- ***********************************************************************/
-
- /* number of macros defined */
- #define NUMMACROS 3
-
- /* now create the macro definitions */
- struct usrMacro{
- char identify[MAXSIZE]; /* macro name as seen in source file */
- char beginstring[MAXSIZE]; /* AG commands prior to heading string */
- char endstring[MAXSIZE]; /* AG commands after heading string */
- char underline[2]; /* "" = no underline. Supply any character (ie: "-") */
- char extra; /* used for underline to count spaces in heading macros */
- } macroList[] = {
-
- { "@HEADING",
- "\n@{BG FILL} @{FG HIGHLIGHT}@{I}",
- " @{UI}@{BG BACK}@{FG TEXT}\n",
- "~",
- 6 },
-
- { "@SUBHEADING",
- "@{FG SHINE}",
- "@{FG TEXT}\n",
- "",
- 0 },
-
- { "@SUBITEM",
- "@{B}",
- "@{UB}\n",
- "",
- 0 }
- };
-
- FILE *input, *output;
- char buffer[BUFSIZE];
-
- /***********************************************************
- * Main()
- *
- * You shouldn't have to mess with anything here,
- * just the macro definitions above. You can even
- * add them without modifying. Note, this code
- * is also not the cleanest thing :)
- ***********************************************************/
- main(int argc, char *argv[])
- {
- int bline = 0, cline=0;
- int wrapmode = 0;
- int headermode = 0;
- int offset, index;
-
-
- /* some startup initialization stuff */
-
- if (argc != 3) {
- fprintf(stderr,"Usage: %s <inputfile> <output guide file>\n");
- exit(0);
- }
-
- if ( (input = fopen(argv[1],"r")) == NULL) {
- fprintf(stderr,"Cannot read file %s\n",argv[1]);
- exit(0);
- }
-
- if ( (output = fopen(argv[2],"wc")) == NULL) {
- fprintf(stderr,"Cannot create file %s\n",argv[2]);
- fclose(input);
- exit(0);
- }
-
- /* loop on each line of amigaguide source */
- while (fgets (buffer,BUFSIZE,input) != NULL) {
- cline++;
-
- for (index=0;index<NUMMACROS;index++) {
- if (strnicmp(buffer, macroList[index].identify,
- strlen(macroList[index].identify)) == 0) {
- headermode = index+1;
- goto endwhile; /* continue inside of for... */
- }
- }
-
- if (strnicmp(buffer,I_BEGINWRAP,strlen(I_BEGINWRAP)) == 0) {
- if (wrapmode == 1) {
- fprintf(stderr,"@BEGINWRAP on line %d missing @ENDWRAP\n",bline);
- goto OUT;
- }
- bline = cline;
- wrapmode = 1;
- fprintf(output,"\n");
- continue;
- }
- else if (strnicmp(buffer,I_ENDWRAP,strlen(I_ENDWRAP)) == 0) {
- if (wrapmode == 0) {
- fprintf(stderr,"@ENDWRAP on line %d missing @BEGINWRAP\n",cline);
- goto OUT;
- }
-
- wrapmode = 0;
- fprintf(output,"\n");
- continue;
- }
-
- /* replace all newlines with spaces if needed */
- if (wrapmode && buffer[0] != '\n') {
- offset = strcspn(buffer,"\n");
- buffer[offset] = ' ';
- }
-
- /* do we need to insert a header? */
- if (headermode) {
- fprintf(output,macroList[headermode-1].beginstring);
- if (strlen(buffer)) buffer[strlen(buffer)-1]=0;
- }
-
- /* now output the actual string */
- fprintf(output,"%s",buffer);
-
- /* close up header? */
- if (headermode) {
- fprintf(output,macroList[headermode-1].endstring);
- if (strlen(macroList[headermode-1].underline) > 0) {
- for (index=strlen(buffer)+macroList[headermode-1].extra; index>0;index--)
- fprintf(output,macroList[headermode-1].underline);
- fprintf(output,"\n");
- }
-
- headermode = 0;
- }
-
- endwhile:
- } /* end of main loop */
-
-
- OUT:
- fclose(input);
- fclose(output);
- }
-