//release maker
//stupid prog made on September 18th of 2005 by Cafe-Alpha
//(some corrections on Dec 2005)
//(some changes on May 2010)


#include <stdio.h>
#include <time.h>

int main()
{

    FILE* f;
    unsigned char c;
    int i, n;
    time_t t;
    struct tm* date;
    //struct tm* test;

    f = fopen("release.h", "rb");
    if(f)
    {
    
        //search #define
        //then search name
        for(i=0; i<2; i++)
        {
            do
            {
                c=fgetc(f);
                //printf("%c", c);
            } while(c != ' ');
            //printf("\n");
        }
    
        n=0; 
        c=fgetc(f);
        while(c != '\n')
        {
            n = 10*n + (int)(c-'0');
            c=fgetc(f);
        }
    }
    else
    {
        n=0;
    }

    fclose(f);

    time(&t);
    date = localtime(&t);

    f = fopen("release.h", "wb");

    //print the new release id
    fprintf(f, "#define RELEASE_ID %d\n", ++n);

    //print the current date, time and release ID
    fprintf(f, "#define RELEASE_DATE \"%04d/%02d/%02d %02d:%02d:%02d (#%04d)\"\n", 
        date->tm_year+1900, date->tm_mon+1, date->tm_mday, 
        date->tm_hour, date->tm_min, date->tm_sec, 
        n);
    
    fclose(f);

    //final printing
    printf("Release maker v0.2 by cafe-alpha.\n");
    /*f = fopen("release.h", "rb");
    while(!feof(f))
        printf("%c", fgetc(f));
    fclose(f);*/
    //printf("\n");
/*    printf("\nhit any key to continue\n");
    getchar();*/

    return 42;
}
