From: glenn@Software.Mitel.COM (Glenn Thrower)
Newsgroups: alt.guitar,alt.guitar.tab
Subject: Re: CHOPRO to ASCII Text conversion?
Date: 8 Oct 92 16:48:01 GMT
Organization: Mitel. Kanata (Ontario). Canada.
X-Newsreader: TIN [version 1.1 PL6]

Please ignore the previous post. That version had a couple of bugs in it.
This version should work better. Let me know if you find any problems with it.

Sorry for the previous post!!

This is version 1.3.1 of RECHORD, a C program that takes a input file in CHORDPRO
format and poutput a plain ascii file.
Remove the header and footer stuff and compile it, it should work.

Glenn

----------------------------------begin cut here------------------------
/*  Re-chord 1.3.1
    Written By: Glenn Thrower
  
    ver 1.0  June 16 1992
    ver 1.1  June 17 1992 - fixed bug in line with no notes
    ver 1.2  July 09 1992 - fixed bug caused by long lines
                          - fixed bug - comment lines were being printed
    ver 1.3   Oct 08 1992 - output to stdout instead of a file
                          - remove ansi specific code
    ver 1.3.1 Oct 08 1992 - fixed extra blank lines from being added
                          - redirected asking for filename to stderr 
                            instead of stdout so it can be seen when
                            re-directing output to file or printer.


 **********************************************************************
 *     Re-chord produces a standard ascii file from a lyrics file     *
 *     containing  chord indications and chorus delimiters.           *
 *     The file produced  contains  the lyrics of a song,  with the   *
 *     guitar chords appearing above the right words.                 *
 **********************************************************************/


#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define ext ".out"
#define C1 "{title:"
#define C2 "{t:"
#define C3 "{subtitle:"
#define C4 "{st:"
#define C5 "{start_of_chorus"
#define C5_1 "{soc"
#define C6 "{end_of_chorus"
#define C6_1 "{eoc"
#define C7 "["
#define C9 "{c:"
#define C10 "{comment:"

int lines, pos;
char e_b = ']';

main(argc, argv)
int argc;
char *argv[];

 {
  char line[500][255],temp[255],filename[20], outname[20],ch;
  FILE *infile;
  int w, y, z, i = 0, x = 0;

  if (argc < 2)
   {
     fprintf(stderr,"Please enter name of file to process: ");
     gets(filename);printf("\n");
   }
  else strcpy(filename,argv[1]);
  while((filename[0]!='\0')&&((infile = fopen(filename,"r"))==NULL))
   {
     perror("Error opening file ");
     printf("\nPlease re-enter or hit <CR> to exit\n");
     fflush(stdin);
     printf("\nFilename : ");
     gets(filename);
   }
  if(filename[0] != '\0')
   {
     rewind(infile);i=0;
     while (feof(infile) == 0)
      {
          x = 0;
        do
         {
           fscanf(infile,"%c",&ch);
           line[i][x] = ch;
           x=x+1;
         }
        while ( line[i][x-1] != '\n');
        line[i][x] = '\0'; 
        i = i + 1;
      }
     lines = i - 1;
     fclose(infile);
     i = -1;
     do
      {
        i = i + 1;outname[i] = filename[i];
      }
     while ((outname[i] != '.') && (outname[i] != '\0'));
     if (outname[i] == '.')
      {
        outname[i] = '\0';
      }
     strcat(outname,ext);
     i=0;pos = 0;w = 0;
     do
      {
        if(line[i][0] == '#')
         {
           i = i + 1;
           pos = 0;
	 }
        pos = 0;
        if(find(line[i],C1) == 0)
         {
           x = 0;
           do
            {
              temp[x] = line[i][pos+x];
              x = x + 1;
            }
           while(line[i][pos+x] != '\0');
           temp[x-2] = '\0';
           y = (80 - strlen(temp)) / 2; 
           for(z=0;z<y;z++) fprintf(stdout," ");
           fprintf(stdout,"%s\n",temp);
           i = i + 1;pos = 0;
         }
	pos = 0;
        if(find(line[i],C2) == 0)
         {
           x = 0;
           do
            {
              temp[x] = line[i][pos+x];
              x = x + 1;
            }
           while(line[i][pos+x] != '\0');
           temp[x-2] = '\0';
           y = (80 - strlen(temp)) / 2; 
           for(z=0;z<y;z++) fprintf(stdout," ");
           fprintf(stdout,"%s\n",temp);
           i = i + 1;pos = 0;
         }
	pos = 0;
         if(find(line[i],C3) == 0)
         {
           x = 0;
           do
            {
              temp[x] = line[i][pos+x];
              x = x + 1;
            }
           while(line[i][pos+x] != '\0');
           temp[x-2] = '\0';
           y = (80 - strlen(temp)) / 2; 
           for(z=0;z<y;z++) fprintf(stdout," ");
           fprintf(stdout,"%s\n\n",temp);
           i = i + 1;pos = 0;
         }
	pos = 0;
         if(find(line[i],C4) == 0)
         {
           x = 0;
           do
            {
              temp[x] = line[i][pos+x];
              x = x + 1;
            }
           while(line[i][pos+x] != '\0');
           temp[x-2] = '\0';
           y = (80 - strlen(temp)) / 2; 
           for(z=0;z<y;z++) fprintf(stdout," ");
           fprintf(stdout,"%s\n\n",temp);
           i = i + 1;pos = 0;
         }
	pos = 0;
         if(find(line[i],C5) == 0)
          {
            w = 1; i = i + 1;pos = 0;
            fprintf(stdout,"\n\n");
          }
	pos = 0;
         if(find(line[i],C5_1) == 0)
          {
            w = 1; i = i + 1;pos = 0;
            fprintf(stdout,"\n\n");
          }
	pos = 0;
         if(find(line[i],C6) == 0)
          {
            w = 0; i = i + 1;pos = 0;
            fprintf(stdout,"\n\n");
          }
	pos = 0;
         if(find(line[i],C6_1) == 0)
          {
            w = 0; i = i + 1;pos = 0;
            fprintf(stdout,"\n\n");
          }
	pos = 0;
         if(find(line[i],C9) == 0)
         {
           x = 0;
           do
            {
              if(islower(line[i][pos+x]) != 0)
                temp[x] = toupper(line[i][pos+x]);
              else temp[x] = line[i][pos+x];
              x = x + 1;
            }
           while(line[i][pos+x] != '\0');
           temp[x-2] = '\0';
           fprintf(stdout,"\n\n%s\n",temp);
           i = i + 1;pos = 0;
         }
	pos = 0;
         if(find(line[i],C10) == 0)
         {
           x = 0;
           do
            {
              if(islower(line[i][pos+x]) != 0)
                temp[x] = toupper(line[i][pos+x]);
              else temp[x] = line[i][pos+x];
              x = x + 1;
            }
           while(line[i][pos+x] != '\0');
           temp[x-2] = '\0';
           fprintf(stdout,"\n\n%s\n",temp);
           i = i + 1;pos = 0;
         }
	 pos = 0;z = 2;
           if(find(line[i],C7) == 0)
            {
               for(y=0;y<255;y++)
		 temp[y] = ' ';temp[y] = '\0';
               if(w == 1)
                 {
                    temp[0] = '|';
                    temp[1] = ' ';
		  }
               do
                {
                  if(w == 1)
                    temp[pos+1] = line[i][pos];
                  else 
                    temp[pos] = line[i][pos];
                  pos = pos + 1;z = z + 1;
                }
               while(line[i][pos] != e_b);
               do
                 {
                  if(find(line[i],C7) == 0)
                   {
                     y = z + 2;
                     do
                      {
                        if(w == 1)
                          temp[pos-z+1] = line[i][pos];
                        else
                          temp[pos-z] = line[i][pos];
                        pos = pos + 1;y = y + 1;
                      }
                    while((line[i][pos] != e_b) && (line[i][pos] != '\0'));
		     z = y;
                   }
                 }
               while(pos < (strlen(line[i])));  
               temp[pos] = '\0';
            fprintf(stdout,"\n%s",temp);
           }
         if((line[i][0] != '{') && (line[i][0] != '#'))
           {
           for(y=0;y<255;y++)
             temp[y] = ' ';temp[y] = '\0';
            x = 0;
            y = 0;
	    pos = 0;
	    do 
	     {
              if(w == 1)
	       {
                 temp[0] = '|';
                 temp[1] = ' ';
	       }
	      if(line[i][x] == '[')
              do
	       {
		 x = x + 1;
	       }
	      while(line[i][x] != e_b);
	      else
               {
                if(w == 1)       
                  temp[y+2] = line[i][x];
                else
                  temp[y+1] = line[i][x];
                y = y + 1;
	       }
              x = x + 1;
	     }
	    while(line[i][x] != '\0');
            if(w == 1)
              temp[y+1] = '\0';
            else temp[y] = '\0';
	    fprintf(stdout,"\n%s",temp);
          }
        i = i + 1; pos = 0; 
     }
     while(i<lines);
     fprintf(stdout,"\n");
   }  
}



int find(temp2,comm1)
char temp2[];
char comm1[];

{
  int b,c;

  b = 0; c = 0;
  do
  {
    if (temp2[pos] == comm1[b])
    {
      pos = pos + 1; b=b+1; c=1;
    }
    else
    {
      if (c==1)
      {
        c=0;b=0;
      }
      else
      {
        pos = pos + 1;b=0;
      }
    }
  }
  while((pos<strlen(temp2))&&(b<strlen(comm1)));
  if (b == strlen(comm1)) return(0);
  else return(1);
}          
----------------------------------end cut here------------------------------

--
______________________________________________________________________________

       _agN#0P0N#    #N#0P##PN#0N#   #N#0P##PN#0N#
     _dN0"      "    #~"""J##"""~#   #~"""J##"""~#
    g#0"                  ###             ###       glenn@Software.Mitel.COM
   j##     ______        :##:            :##:
   0##     "9##F"        0##             0##        Kanata,  Ontario, Canada
   `##k     d##          ##F             ##F
    `#Nh___g#N'        _d##L_          _d##L_
      """"""""        """""""         """""""
______________________________________________________________________________