Permalink
Browse files

Importing Tetristats 1.00

  • Loading branch information...
0 parents commit 51c06bb3be48b7025d3508f6ac6dfd7730a8b226 @fcambus committed Nov 21, 2011
Showing with 764 additions and 0 deletions.
  1. +1 −0 AUTHORS
  2. +340 −0 COPYING
  3. +3 −0 ChangeLog
  4. +18 −0 Makefile
  5. +89 −0 README
  6. +271 −0 tetristats.c
  7. +42 −0 tetristats.css
@@ -0,0 +1 @@
+Frederic Cambus <fcambus AT users DOT sourceforge DOT net>
Oops, something went wrong.
@@ -0,0 +1,3 @@
+1.00 (2005-01-18)
+
+- Initial release
@@ -0,0 +1,18 @@
+###############################################################################
+# #
+# Tetristats 1.00 (c) by Frederic Cambus 2001-2005 #
+# http://tetristats.sourceforge.net #
+# #
+# Last Updated: 2005/01/18 #
+# #
+###############################################################################
+
+CC = gcc
+TARGET = all
+CFLAGS = -Wall -ansi -pedantic
+
+all :
+ $(CC) $(CFLAGS) -o tetristats tetristats.c
+
+clean:
+ rm -f tetristats *.o *.core core
@@ -0,0 +1,89 @@
+-------------------------------------------------------------------------------
+ Tetristats 1.00 (c) by Frederic Cambus 2001-2005
+-------------------------------------------------------------------------------
+
+
+
+LICENSE:
+--------
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+
+DESCRIPTION:
+------------
+
+Tetristats is a tool to convert TetriNET servers winlist files to HTML.
+It supports Tetrinetx (http://tetrinetx.sourceforge.net) and JetriX
+(http://jetrix.sourceforge.net) score files.
+
+
+
+COMPILING:
+----------
+
+Simply type "make" to compile the program.
+
+It has been successfully compiled on:
+
+- 32-bit x86 Architecture (Debian GNU/Linux 3.1, Fedora Linux FC2, FreeBSD 4.8,
+ NetBSD 1.6.1, OpenBSD 3.4, Sun Solaris 9)
+- AMD 64-bit (Opteron) Architecture (Fedora Core release 3)
+- DEC Alpha (ev67) Architecture (Debian GNU/Linux 3.0)
+- PowerPC Architecture (Apple Mac OS X 10.2 Server with Fink)
+- Sparc (UltraSPARC-II) Architecture (Sun Solaris 9)
+
+
+
+USAGE:
+------
+
+tetristats servertype inputfile outputfile
+servertype must be either -tx (for Tetrinetx) or -jx (for JetriX)
+
+Examples: tetristats -tx game.winlist tetristats.html
+ tetristats -jx default.winlist tetristats.html
+
+You must have the file tetristats.css in the same directory than your
+generated .html file if you want customized colors.
+
+
+
+CUSTOMIZATION:
+--------------
+
+Edit tetristats.css if you want to customize colors and text attributes.
+
+
+
+DISTRIBUTION:
+-------------
+
+If you want to add a tetristats download link on your page, please use the
+following sourceforge download link:
+
+For version 1.00:
+http://prdownloads.sourceforge.net/tetristats/tetristats-1.00-src.tar.gz?download
+
+
+
+CONTACT:
+--------
+
+Project Homepage: http://tetristats.sourceforge.net
+
+For bug report, feedback, or any other reasons:
+Frederic Cambus <fcambus AT users DOT sourceforge DOT net>
@@ -0,0 +1,271 @@
+/*****************************************************************************/
+/* */
+/* Tetristats 1.00 (c) by Frederic Cambus 2001-2005 */
+/* http://tetristats.sourceforge.net */
+/* */
+/* Last Updated: 2005/01/18 */
+/* */
+/* This program is free software; you can redistribute it and/or modify */
+/* it under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/*****************************************************************************/
+
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+FILE *input_file;
+char *input_file_buffer;
+int input_file_size;
+struct stat input_file_stat;
+
+FILE *output_file;
+time_t output_file_time;
+
+struct tx_scoreline
+{
+ char type;
+ char name[31];
+ unsigned long int score;
+ char inuse;
+} tx_scoreline;
+
+struct jx_scoreline
+{
+ char *type;
+ char *score;
+ char *name;
+
+} *jx_scoreline;
+
+int jx_lines;
+int jx_tabspaces;
+
+int loop;
+
+
+
+/*****************************************************************************/
+/* CREATE OUTPUT FILE */
+/*****************************************************************************/
+
+void create_output_file(char *output_file_name)
+{
+ output_file=fopen(output_file_name,"w");
+ if (output_file==NULL)
+ {
+ printf("ERROR: Cannot create file %s\n\n",output_file_name);
+ exit(-1);
+ }
+
+ fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n",output_file);
+ fputs("<HTML>\n<HEAD>\n",output_file);
+ fputs("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; CHARSET=iso-8859-1\">\n",output_file);
+ fputs("<TITLE>Tetrinet Statistics</TITLE>",output_file);
+ fputs("<LINK REL=\"stylesheet\" HREF=\"tetristats.css\" TYPE=\"text/css\">",output_file);
+ fputs("</HEAD>\n",output_file);
+ fputs("<CENTER>\n<TABLE BORDER=\"3\">",output_file);
+ fputs("<TR CLASS=\"TITLE\"><TD WIDTH=\"5%\">&nbsp;Rank&nbsp;<TD WIDTH=\"65%\">&nbsp;Name<TD WIDTH=\"15%\"ALIGN=\"center\">&nbsp;Category<TD WIDTH=\"15%\"ALIGN=\"right\">Score&nbsp;</TD></TR>\n",output_file);
+}
+
+
+
+/*****************************************************************************/
+/* MAIN */
+/*****************************************************************************/
+
+int main (int argc, char *argv[])
+{
+ printf("-------------------------------------------------------------------------------\n");
+ printf(" Tetristats 1.00 (c) by Frederic Cambus 2001-2005\n");
+ printf("-------------------------------------------------------------------------------\n\n");
+
+ if (argc!=4)
+ {
+ printf("USAGE: tetristats servertype inputfile outputfile\n\n");
+ printf("SERVERTYPE: -tx (for Tetrinetx)\n -jx (for JetriX)\n\n");
+ printf("EXAMPLES: tetristats -tx game.winlist tetristats.html\n tetristats -jx default.winlist tetristats.html\n\n");
+ exit(-1);
+ }
+
+ if ((strcmp(argv[1],"-jx")!=0) & (strcmp(argv[1],"-tx")!=0))
+ {
+ printf("ERROR: servertype must be either -tx (for Tetrinetx) or -jx (for JetriX)\n\n");
+ exit(-1);
+ }
+
+
+
+/*****************************************************************************/
+/* LOAD INPUT FILE */
+/*****************************************************************************/
+
+ stat (argv[2], &input_file_stat);
+ input_file_size=input_file_stat.st_size;
+
+ input_file_buffer= (char *) malloc(input_file_size);
+
+ if (input_file_buffer==NULL)
+ {
+ printf("ERROR: Cannot allocate memory\n\n");
+ exit(-1);
+ }
+
+ input_file=fopen(argv[2],"rb");
+ if (input_file==NULL)
+ {
+ printf("ERROR: Cannot open file %s\n\n",argv[2]);
+ exit(-1);
+ }
+
+ fread(input_file_buffer,input_file_size,1,input_file);
+ fclose(input_file);
+
+
+
+/*****************************************************************************/
+/* TETRINETX */
+/*****************************************************************************/
+
+ if (strcmp(argv[1],"-tx")==0)
+ {
+ if ((input_file_size==0) || (input_file_size%40!=0))
+ {
+ printf("ERROR: %s is not a Tetrinetx score file\n\n",argv[2]);
+ exit(-1);
+ }
+
+ create_output_file(argv[3]);
+
+ for (loop=0;loop<(input_file_size/40);loop++)
+ {
+ memcpy(&tx_scoreline,input_file_buffer+(loop*40),40);
+
+ if ( tx_scoreline.type=='\0')
+ {
+ break;
+ }
+
+ fprintf(output_file,"<TR CLASS=\"COLOR\"><TD>&nbsp;%i</TD><TD>&nbsp;%s</TD><TD ALIGN=\"center\">",loop+1,tx_scoreline.name);
+
+ switch (tx_scoreline.type)
+ {
+ case 'p': fputs("Player",output_file);
+ break;
+
+ case 't': fputs("Team",output_file);
+ break;
+
+ default:
+ break;
+ }
+
+ fprintf(output_file,"</TD><TD ALIGN=\"right\">%lu&nbsp;</TD></TR>\n",tx_scoreline.score);
+ }
+ }
+
+
+
+/*****************************************************************************/
+/* JETRIX */
+/*****************************************************************************/
+
+ if (strcmp(argv[1],"-jx")==0)
+ {
+ for (loop=0;loop<input_file_size;loop++)
+ {
+ switch (input_file_buffer[loop])
+ {
+ case '\t': jx_tabspaces++;
+ break;
+
+ case '\n': jx_lines++;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if ((jx_lines==0) || (jx_tabspaces/jx_lines!=2))
+ {
+ printf("ERROR: %s is not a JetriX score file\n\n",argv[2]);
+ exit(-1);
+ }
+
+ create_output_file(argv[3]);
+
+ jx_scoreline=malloc(jx_lines);
+
+ if (jx_scoreline==NULL)
+ {
+ printf("ERROR: Cannot allocate memory\n\n");
+ exit (-1);
+ }
+
+ jx_scoreline[0].type=strtok(input_file_buffer,"\t");
+ jx_scoreline[0].score=strtok(NULL,"\t");
+ jx_scoreline[0].name=strtok(NULL,"\t\n");
+
+ for (loop=1;loop<jx_lines;loop++)
+ {
+ jx_scoreline[loop].type=strtok(NULL,"\t");
+ jx_scoreline[loop].score=strtok(NULL,"\t");
+ jx_scoreline[loop].name=strtok(NULL,"\t\n");
+ }
+
+ for (loop=0;loop<jx_lines;loop++)
+ {
+ if (strcmp(jx_scoreline[loop].type,"p")==0)
+ {
+ jx_scoreline[loop].type="Player";
+ }
+
+ if (strcmp(jx_scoreline[loop].type,"t")==0)
+ {
+ jx_scoreline[loop].type="Team";
+ }
+
+ fprintf(output_file,"<TR CLASS=\"COLOR\"><TD>&nbsp;%i</TD><TD>&nbsp;%s</TD><TD ALIGN=\"center\">%s</TD><TD ALIGN=\"right\">%s&nbsp;</TD></TR>\n",loop+1,jx_scoreline[loop].name,jx_scoreline[loop].type,jx_scoreline[loop].score);
+ }
+
+ free(jx_scoreline);
+ }
+
+
+
+/*****************************************************************************/
+/* OUTPUT FILE FOOTER */
+/*****************************************************************************/
+
+ output_file_time = time((time_t *)NULL);
+ fputs("\n</TABLE>\n<BR>",output_file);
+ fprintf(output_file,"Created on %s with <A HREF=\"http://tetristats.sourceforge.net\">Tetristats</A> 1.00 (c) by Frederic Cambus 2001-2005\n",ctime(&output_file_time));
+ fputs("</CENTER>\n</BODY>\n</HTML>\n",output_file);
+
+
+
+/*****************************************************************************/
+/* TERMINATE PROGRAM */
+/*****************************************************************************/
+
+ fclose(output_file);
+ free(input_file_buffer);
+
+ printf("Successfully created file %s\n\n",argv[3]);
+
+ return (0);
+}
Oops, something went wrong.

0 comments on commit 51c06bb

Please sign in to comment.