 /* MPTool   -  First Step : 04/09/97
                Last Modif : 06/05/98
         by HEINRICH Patrick
    Nothing but a working version ;)
    Frozen : V1.0 (Major Update:)     */

#include        <stdio.h>
#include        <string.h>
#include        <stdlib.h>
#include        <dos/dos.h>
#include        <exec/exec.h>
#include        <proto/dos.h>
#include        <proto/exec.h>

#define         VER     "1.00"

/*==============================GLOBAL VARIABLES==============================*/

    int    i;
    int    filetot=0;
    int    dirtot=0;
 
  
    long   mpduration=0;
    long   mptotsize=0;

    int    mptot=0;
    int    wavetot=0;

    int    com=0;
    int    readTAG=0;
    int    deepscan=0;
    int    removewaveheader=0;
    int    normallist=0;
    int    removeTAG=0;
    int    recursiv=0;
    int    symbol=0;
    int    TAGit=0;
    int    finalsumup=0;
    int    forcemode=0;
    int    cleanit=0;

    long bytes_read;
    long buffersize=4096;
    unsigned char * tempo=NULL;


    struct FileHandle * ForceIn;
    struct FileHandle * ForceOut;
    struct FileHandle * ForceHeadOut;


/*================================PROTOTYPES==================================*/

    void AnalyseOption(char * start, char * options);
    void Genre(int number, char * genrestring);
    void GenreList(void);
    int  GetMinute(long size, int kbps);
    int  GetSecond(long size, int kbps);
    void GetTag(int start, int length, char * TAG, char * PARTTAG);
    void GetTagNS(int start, int length, char * TAG, char * PARTTAG);
    void IsMPEG(char * filename, long size);
    int  LimitedRead(int maxchar, char * temp);
    void ListIt(char* startstring);
    void main(int argc, char *argv[]);
    void PrintHelp(char * WhereIsMPTool);
    int  ReadTAGFromFile(struct FileHandle *FileTag);
    int  WriteTAGToFile(struct FileHandle *FileToTag);


/*============================================================================*/


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

{

    printf("\n %c[42;31mMP%c[41;32mTool%c[0m V%s '98 by %c[0;32m·HEINRICH Patrick·%c[0m \n",27,27,27,VER,27,27);
    printf("\n Registered to : %c[0;33mEverybody%c[0m \n\n",27,27);

    if (argc==1) {printf(" %s -h for help and options.\n\n",argv[0]);exit(0);}

    AnalyseOption(argv[0],argv[1]);

    if (forcemode==1)
        {
        ForceIn=(struct FileHandle *) Open(argv[2],MODE_OLDFILE);
        ForceOut=(struct FileHandle *) Open(argv[3],MODE_NEWFILE);
        if (argc==5) ForceHeadOut=(struct FileHandle *) Open(argv[4],MODE_NEWFILE);

        printf(" working on file %s\n",argv[2]);
        if (argc==5) printf(" writing header in file %s\n",argv[4]);

        tempo=calloc(buffersize,sizeof(unsigned char));
        if (tempo==NULL)
                           {
                           printf("\n Not enough memory for forcemodemode\n\n");
                           Close(ForceIn);
                           Close(ForceOut);
                           }
        tempo[0]=0;
        
        while ( (tempo[0]!=255) && ((bytes_read=Read(ForceIn, tempo, 1))==1) )
        {
        if ( (argc==5) && (tempo[0]!=255) ) Write(ForceHeadOut, tempo,1);
        }

        printf(" header cut !! now writing file %s\n\n",argv[3]);
        Write(ForceOut, tempo,1);

        while ((bytes_read=Read(ForceIn, tempo, buffersize))==buffersize)

        {
        Write(ForceOut, tempo, buffersize);
        }

        Write(ForceOut, tempo, bytes_read);


        free(tempo);
        Close(ForceIn);
        Close(ForceOut);
        if (argc==5) Close(ForceHeadOut);
        exit(0);
        }

    if (argc==3)

        {
        printf("\n ===========================[MPTool]===['98·TMG·]===============================\n\n");
        printf(" MPTool was started from %s\n",argv[2]);
        }
        printf("\n ===========================[MPTool]===['98·TMG·]===============================\n\n");


    for (i=2;i<argc;i++) {ListIt(argv[i]);}


    if (finalsumup==0)

    {
    printf("\n ===========================[MPTool]===['98·TMG·]===============================\n");
    if (argc==3) printf("\n %s \n",argv[2]);
    printf("\n                         %12i MPEG Files (MPEG or WAVE header)\n",mptot);
    printf("                         %12i Files\n",filetot);
    printf("                         %12i Directories\n",dirtot);
    printf("                         %12i MPEG Files with a #WAVE header\n",wavetot);
    if (mptotsize/(1024*1024) >= 2)
    printf("\n                         %12d MB of MPEG",mptotsize/(1024*1024));
    printf("\n                         %12d KB of MPEG\n",mptotsize/1024);
    printf("                         %12d bytes of MPEG\n",mptotsize);
    printf("\n                             %02i:%02i:%02i Total Duration of the listed files\n",(mpduration/3600),((mpduration-3600*(mpduration/3600))/60),mpduration-3600*(mpduration/3600)-60*((mpduration-3600*(mpduration/3600))/60));
    }
    printf("\n ===========================[MPTool]===['98·TMG·]===============================\n\n");


}

/*============================================================================*/

void ListIt(char* startstring)

    {

    long   size;
    char   tempstring  [256];
    char   tempstring2 [256];
    char   startstringclean [256];
    char   * charptr;
    struct FileInfoBlock *fib_ptr;
    struct FileLock *FileLocked ;

    /* is startstring a directory/file/volume */

    strcpy(tempstring,startstring);
    charptr=PathPart(&tempstring);
    if ( (*charptr=='/') && ( *(charptr+1)==0) ) {*charptr=0;}
    strcpy(startstringclean,tempstring);                         // cuts the final "/"

    fib_ptr = AllocMem( sizeof( struct FileInfoBlock ),MEMF_PUBLIC );

    FileLocked = Lock( tempstring, ACCESS_READ );
    if ( FileLocked  == NULL ) {printf("\n Can't lock file \n");exit(0);}


    Examine(FileLocked,fib_ptr);

    if ((*fib_ptr).fib_DirEntryType<0)                    // it's a file
            {
            size=(*fib_ptr).fib_Size;
            UnLock(FileLocked);
            FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
            filetot++;
            IsMPEG(startstring,size);
            }
    else                                                  // it's not a file

    {
    charptr=&tempstring;

    while (ExNext(FileLocked,fib_ptr))

        {
        if ( ((*fib_ptr).fib_DirEntryType>0) && (fib_ptr!=NULL) )
             {
               dirtot++;
               if (recursiv==1)
               {
               strcpy(tempstring,startstringclean);
               if ( *(charptr+strlen(tempstring)-1) !=':')  // check if it's a volume
               {strcat(tempstring,"/");
                strcat(tempstring,(*fib_ptr).fib_FileName);}
               else {strcat(tempstring,(*fib_ptr).fib_FileName);}
               ListIt(tempstring);
               }
             }


        else {
               strcpy(tempstring,startstringclean);
               if ( *(charptr+strlen(tempstring)-1) !=':')  // check if it's a volume
               {strcat(tempstring,"/");
                strcat(tempstring,(*fib_ptr).fib_FileName);}
               else {strcat(tempstring,(*fib_ptr).fib_FileName);}
               filetot++;
               size=(*fib_ptr).fib_Size;
               IsMPEG(tempstring,size);
             }
        }
    UnLock(FileLocked);
    FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
    }
}

/*============================================================================*/

int  GetMinute(long size, int kbps)
{
if (kbps!=0) return(8*size/1000/kbps/60);
return(0);
}

/*============================================================================*/

int  GetSecond(long size, int kbps)
{
if (kbps!=0) return((8*size/1000/kbps)-(8*size/1000/kbps/60)*60);
return(0);
}

/*============================================================================*/

void IsMPEG(char* gimmefile,long size)

{
    int           kbps=0;
    int           wave=0;
    int           deepfound=0;
    int           buffersize=4096;
    int           i=0;
    struct        FileHandle * InFile;
    struct        FileHandle * OutFile;
    char          path [256];
    char          commy [80];
    char          temp [10];
    char *        tempo;
    long          tmpsize;
    long          bytes_read;
    unsigned char Buffer [15];           // buffer to store some infos from infile
    unsigned char * DeepSearchBuffer;

    tmpsize=size;
    InFile=(struct FileHandle *) Open(gimmefile,MODE_OLDFILE);

//  allocates 10 B for the buffer

    Read(InFile,Buffer,10);              // reads the header of the file

    Buffer[4]=NULL;

    if ( (strcmp("RIFF",Buffer))==0 )    // if there is a WAVE header
      {
       Seek(InFile,70,OFFSET_BEGINNING);
       Read(InFile,Buffer,10);           // reads the real header of the file
       if (Buffer[0]!=255)
           {
           Seek(InFile,72,OFFSET_BEGINNING);
           Read(InFile,Buffer,10);
           if (Buffer[0]!=255) {Close(InFile); return;}
           wave=2;
           }
       else {wave=1;}

       wavetot++;
      }

    if ( (deepscan) && (wave==0) && (Buffer[0]!=255) )
    {
    DeepSearchBuffer=calloc(8200,sizeof(unsigned char));
    if (DeepSearchBuffer==NULL) {Close(InFile); return;}      //    not enough memory
    Seek(InFile,0,OFFSET_BEGINNING);
    bytes_read=Read(InFile,DeepSearchBuffer,8192);            //    read the header of the file
    if (bytes_read!=8192) {free(DeepSearchBuffer);Close(InFile); return;}
    while ( DeepSearchBuffer[i]!=255 && (i<8192) ) {i++;}
    if (i==8192) {free(DeepSearchBuffer);Close(InFile); return;}
    deepfound=1;
    Seek(InFile,i,OFFSET_BEGINNING);
    Read(InFile,Buffer,10);                                   //    you can change the buffer
    free(DeepSearchBuffer);
    }


    if ( Buffer[0]!=255 )

        {
        Close(InFile); return;
        }


    if (!( (Buffer[1]==251) || (Buffer[1]==242) ||
           (Buffer[1]==250) || (Buffer[1]==252) ||
           (Buffer[1]==243)
           ))

        {
        Close(InFile); return;
        }


    if ((Buffer[1]==250) || (Buffer[1]==251))

      {
        switch (Buffer[2])

        {

        case 16:    kbps=32;break;
        case 32:    kbps=40;break;
        case 48:    kbps=48;break;
        case 64:    kbps=56;break;
        case 80:    kbps=64;break;
        case 96:    kbps=80;break;
        case 112:   kbps=96;break;
        case 128:   kbps=112;break;
        case 144:   kbps=128;break;
        case 160:   kbps=160;break;
        case 176:   kbps=192;break;
        case 192:   kbps=224;break;
        case 208:   kbps=256;break;
        case 224:   kbps=320;break;

        default: kbps=128;break;
        }
      }

     else

      {

        if (Buffer[1]==252)

            {

            switch (Buffer[2])

            {

            case 16:    kbps=32;break;
            case 32:    kbps=48;break;
            case 48:    kbps=56;break;
            case 64:    kbps=64;break;
            case 80:    kbps=80;break;
            case 96:    kbps=96;break;
            case 112:   kbps=112;break;
            case 128:   kbps=128;break;
            case 144:   kbps=168;break;
            case 160:   kbps=192;break;
            case 176:   kbps=224;break;
            case 192:   kbps=256;break;
            case 208:   kbps=320;break;
            case 224:   kbps=384;break;

            default: Close(InFile); return;
            }
            }
         else {
                if ( (Buffer[1]==242) || (Buffer[1]==243) )

                    {

                    switch (Buffer[2])

                    {

                    case 16:    kbps=8;break;
                    case 32:    kbps=16;break;
                    case 48:    kbps=24;break;
                    case 64:    kbps=32;break;
                    case 80:    kbps=40;break;
                    case 96:    kbps=48;break;
                    case 112:   kbps=56;break;
                    case 128:   kbps=64;break;
                    case 144:   kbps=80;break;
                    case 160:   kbps=96;break;
                    case 176:   kbps=112;break;
                    case 192:   kbps=128;break;
                    case 208:   kbps=144;break;

                    default:Close(InFile); return;
                    }
                    }
                 else {Close(InFile); return;}
               }

      }


       if (cleanit==1)

      {

        printf(" cleaning the file %s\n",gimmefile);
        strcpy(path,gimmefile);
        path[(strlen(gimmefile)-1)]=-57;
        OutFile=(struct FileHandle *) Open(path,MODE_NEWFILE);
        Seek(InFile,0,OFFSET_BEGINNING);

        tempo=calloc(buffersize,sizeof(char));

        bytes_read=Read(InFile, tempo, buffersize);
        for (i=0;i<4000;i++) {
                             if ( (tempo[i]==' ') && (tempo[i+1]==' ') )
                                {
                                tempo[i]=255;
                                tempo[i+1]=255;
                                }
                             }

        Write(OutFile, tempo, bytes_read);

        while ((bytes_read=Read(InFile, tempo, buffersize))==buffersize)
                 {
                 Write(OutFile, tempo, buffersize);
                 }

        Write(OutFile, tempo, bytes_read);
        free(tempo);
        Close(InFile);
        Close(OutFile);
        DeleteFile(gimmefile);
        Rename(path,gimmefile);

      }

      else
      {

      if ( (wave>0) && (removewaveheader==1) )

      {

        if (wave==1) {i=70;}
        if (wave==2) {i=72;}

        printf(" cutting the wave header of file %s\n",gimmefile);
        strcpy(path,gimmefile);
        path[(strlen(gimmefile)-1)]=-57;
        OutFile=(struct FileHandle *) Open(path,MODE_NEWFILE);
        Seek(InFile,i,OFFSET_BEGINNING);

        tempo=calloc(buffersize,sizeof(char));

        while ((bytes_read=Read(InFile, tempo, buffersize))==buffersize)

                 {
                 Write(OutFile, tempo, buffersize);
                 }

        Write(OutFile, tempo, bytes_read);
        free(tempo);
        Close(InFile);
        Close(OutFile);
        DeleteFile(gimmefile);
        Rename(path,gimmefile);

     }
     else
     {

        if (normallist==1)
                 {
                 mpduration=mpduration+(8*size/1000/kbps);
                 if (wave*symbol) {printf("#");} else
                                  {
                                  if (deepfound*symbol) {printf("@");} else {printf(" ");}
                                  }

                 printf("%-65.65s %0.2i:%0.2i %3ikbps\n",
                 gimmefile,GetMinute(size,kbps),GetSecond(size,kbps),kbps);
                 }

        if (com==1)
           {
           if ( GetMinute(size,kbps) <10) {strcpy(commy," [0");} else {strcpy(commy," [");}

           stci_d(temp,GetMinute(size,kbps));
           strcat(commy,temp);
           strcat(commy,":");

           size=GetSecond(size,kbps);

           if ( size <10 ) {strcat(commy,"0");}

           stci_d(temp,size);
           strcat(commy,temp);
           strcat(commy,"] - [");
           stci_d(temp,kbps);
           strcat(commy,temp);
           strcat(commy,"kbps]");

           SetComment(gimmefile , commy);
           }

        if (readTAG==1)   {ReadTAGFromFile(InFile);}

        if (TAGit==1)     {WriteTAGToFile(InFile);}

        if (removeTAG==1) {
                          Seek(InFile,-128,OFFSET_END);
                          bytes_read=Read(InFile, commy, 128);
                          if (commy[0]=='T'&&commy[1]=='A'&&commy[2]=='G'
                              && bytes_read==128)
                             {
                             SetFileSize(InFile,-128,OFFSET_END);
                             }
                          }

        Close(InFile);
        }
       }

    mptot++;
    mptotsize=mptotsize+tmpsize;
}

/*============================================================================*/

/*
fonction to be used to write some infos in a MP3 file
returns 0 if it's OK
returns 1 if the user has typed nothing
*/

int LimitedRead(int maxchar, char * temp)

{
int i,count;
int vide=0;

gets(temp);
count=0;
if (temp[0]==0) vide=1;
while ((temp[count]!=0)&&(count<maxchar)) {count++;}
if (count!=maxchar) {for (i=count;i<maxchar;i++) {temp[i]=' ';}}
temp[maxchar]=0;
if (vide) return(1);
return(0);
}

/*============================================================================*/

/*
extracts some text (limited length and space cut) from TAG
*/

void GetTag(int start, int length, char * TAG, char * PARTTAG)

{
int i;

i=start;
while ( (i<=(start+length-1)) && !( (TAG[i]==' ') && (TAG[i+1]==' ') ) )
{PARTTAG[i-start]=TAG[i];i++;}
PARTTAG[i-start]=0;
}

/*============================================================================*/

/*
extracts some text (limited length and NO SPACE CUT) from TAG
*/

void GetTagNS(int start, int length, char * TAG, char * PARTTAG)

{
int i;

i=start;
while  ( i<=(start+length-1) )
{PARTTAG[i-start]=TAG[i];i++;}
PARTTAG[i-start]=0;
}

/*============================================================================*/

/*
returns the string of the MP3 genre ... dunno if it's useful ;)
uses c:MPTool.Genres
*/

void Genre(int number, char * genrestring)

{
FILE *infp;
int i=0;

infp=fopen("c:MPTool.Genres","r");
if (infp==NULL)
{
strcpy(genrestring,"<Genre file is missing!>\n");
}
else
{
while  ( ( fgets(genrestring,25,infp) !=NULL ) && i<(number)) {i++;}
fgets(genrestring,25,infp);
fclose(infp);
}
}

/*============================================================================*/

/*
provides a genre list since it's hard to learn ;)
*/

void GenreList(void)

{
FILE *infp;
int i=3;
char genretemp [30];

infp=fopen("c:MPTool.Genres","r");
if (infp==NULL) {printf("\n The file c:MPTool.Genres is missing !!\n");}
else
{
printf("\nHere we go for a list :\n\n");

i=3;
while  ( fgets(genretemp,25,infp) !=NULL )
{
genretemp[strlen(genretemp)-1]=0;i--;
printf("%-25s",genretemp);
if (i==0) {printf("\n");i=3;}
}
printf("\n\n");
fclose(infp);
}
}

/*============================================================================*/

/*
the tag reader
returns 0 if it's OK
returns 1 if an error occurs
returns 2 if the file has no TAG
*/

int ReadTAGFromFile(struct FileHandle *FileTag)

{

long bytes_read;
char temp [256];
char TAG [128];
char INTAG [31];


Seek(FileTag,-128,OFFSET_END);
bytes_read=Read(FileTag, TAG, 128);
if (bytes_read!=128) return(1);

if (TAG[0]!='T'||TAG[1]!='A'||TAG[2]!='G') return(2);

GetTag(3,30,TAG,INTAG);
printf("\n Song Name : %s",INTAG);
GetTag(33,30,TAG,INTAG);
printf("\n Artist    : %s",INTAG);
GetTag(63,30,TAG,INTAG);
printf("\n Album     : %s",INTAG);
GetTag(93,4,TAG,INTAG);
printf("\n Year      : %s",INTAG);
GetTag(97,30,TAG,INTAG);
printf("\n Comment   : %s",INTAG);
Genre(TAG[127],temp);
printf("\n Genre     : %s\n",temp);
return(0);

}

/*============================================================================*/

/* the tag writer
returns 0 if it's OK
returns 1 if an error occurs
if a TAG already exists, it shows it
=> not answering a question will keep the old tag part
*/

int WriteTAGToFile(struct FileHandle *FileToTag)

{

char temp [128];
char TAG [128];

char OLD_Songname [31];
char OLD_Artist [31];
char OLD_Album [31];
char OLD_Year [5];
char OLD_Comment [31];
int  OLD_Genre;

int  OLD_TAG=0;
int  errorcode;
short  genre=-1;

Seek(FileToTag,-128,OFFSET_END);
bytes_read=Read(FileToTag, TAG, 128);
if (bytes_read!=128) return(1);

if (TAG[0]=='T'&&TAG[1]=='A'&&TAG[2]=='G')
   {
   printf("\n This file has already a TAG :\n");
   errorcode=ReadTAGFromFile(FileToTag);
   OLD_TAG=1;
   GetTagNS(3,30,TAG,OLD_Songname);
   GetTagNS(33,30,TAG,OLD_Artist);
   GetTagNS(63,30,TAG,OLD_Album);
   GetTagNS(93,4,TAG,OLD_Year);
   GetTagNS(97,30,TAG,OLD_Comment);
   OLD_Genre=TAG[127];
   SetFileSize(FileToTag,-128,OFFSET_END);  // delete TAG
   }


Seek(FileToTag,0,OFFSET_END);
FPuts(FileToTag,"TAG");

printf("\n Please enter the songname (30 caracteres max)\n ");
errorcode=LimitedRead(30,temp);
if (errorcode*OLD_TAG)
{printf(" %s\n",OLD_Songname);FPuts(FileToTag,OLD_Songname);}
else {FPuts(FileToTag,temp);}

printf(" Please enter the artist name (30 caracteres max)\n ");
errorcode=LimitedRead(30,temp);
if (errorcode*OLD_TAG)
{printf(" %s\n",OLD_Artist);FPuts(FileToTag,OLD_Artist);}
else {FPuts(FileToTag,temp);}


printf(" Please enter the album title (30 caracteres max)\n ");
errorcode=LimitedRead(30,temp);
if (errorcode*OLD_TAG)
{printf(" %s\n",OLD_Album);FPuts(FileToTag,OLD_Album);}
else {FPuts(FileToTag,temp);}

printf(" Please enter the year of creation (4 caracteres max)\n ");
errorcode=LimitedRead(4,temp);
if (errorcode*OLD_TAG)
{printf(" %s\n",OLD_Year);FPuts(FileToTag,OLD_Year);}
else {FPuts(FileToTag,temp);}

printf(" Please enter a comment :) (30 caracteres max)\n ");
errorcode=LimitedRead(30,temp);
if (errorcode*OLD_TAG)
{printf(" %s\n",OLD_Comment);FPuts(FileToTag,OLD_Comment);}
else {FPuts(FileToTag,temp);}

while (genre<0)
{
printf(" Please enter a genre number (type 'g' for a genre list) \n ");
gets(temp);
if (temp[0]=='g') {GenreList();}
else
{
if ( (temp[0]==0) && (OLD_TAG==1) )
{genre=OLD_Genre;printf(" %i\n",genre);FPutC(FileToTag,OLD_Genre);}
else {genre=atoi(temp);FPutC(FileToTag,genre);}
}
}

}

/*============================================================================*/

void PrintHelp(char * WhereIsMPTool)

{
printf("\n Usage : %s [-options] [file(s)/drawer(s)/device(s)]\n\n",WhereIsMPTool);
printf(" where options is one or more of the following one :\n\n");
printf("   B : reads a TAG if there's one\n");
printf("   C : adds duration and kbps in comment (deletes old comments)\n");
printf("   D : deep scan mode active\n");
printf("   E : cleans old MP3 files to avoid 'clicks' at start\n");
printf("   F : force the removal of a header ; be careful :\n");
printf("       usage for F : MPTool -F <sourcefile> <destination>\n");
printf("       or MPTool -F <sourcefile> <destination> <headerfile>\n");
printf("       F should also remove wave headers but H is faster.\n");
printf("   H : removes wave headers\n");
printf("   L : simple file listing\n");
printf("   N : removes TAG from MP3 files\n");
printf("   R : recursive mode active (scans all subdrawers)\n");
printf("   S : adds symbols while listing (@:deep scan file,#:wave header)\n");
printf("   T : adds an MP3 tag to a file or modifies an existing one\n");
printf("   Z : no final sum up\n\n");
printf(" If you want the genre list to be used, move MPTool.Genres in c:.\n");
printf(" While editing a TAG, if an OLD TAG exists, pressing enter will keep\n");
printf(" the OLD information. Type 'g' to have a nice genre list!\n\n");
exit(0);
}

/*============================================================================*/

void AnalyseOption(char * start,char * options)

{
int i=0;

if (options[0]!='-') {printf(" %s -h for help and options.\n\n",start);}
else
     {
     if ( (options[1]=='h') && (strlen(options)==2) ) {PrintHelp(start);}
     if ( (options[1]=='g') && (strlen(options)==2) ) {GenreList();exit(0);}

     for (i=1;i<(strlen(options));i++)
        {
        switch (options[i])
          {
          case 'B': readTAG=1;          break;
          case 'C': com=1;              break;
          case 'D': deepscan=1;         break;
          case 'E': cleanit=1;          break;
          case 'F': forcemode=1;        break;
          case 'H': removewaveheader=1; break;
          case 'L': normallist=1;       break;
          case 'N': removeTAG=1;        break;
          case 'R': recursiv=1;         break;
          case 'S': symbol=1;           break;
          case 'T': TAGit=1;            break;
          case 'Z': finalsumup=1;       break;
          default :                     break;
          }
        }
     }
}

/*============================================================================*/

