diff -Nru catcodec-1.0.0/catcodec.1 catcodec-1.0.4/catcodec.1 --- catcodec-1.0.0/catcodec.1 2009-12-17 23:09:12.000000000 +0000 +++ catcodec-1.0.4/catcodec.1 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -.\" $Id: catcodec.1 18526 2009-12-17 23:09:12Z rubidium $ - -.\" catcodec is a tool to decode/encode the sample catalogue for OpenTTD. -.\" Copyright (C) 2009 Remko Bijker -.\" -.\" This manual page is free software. It is distributed under the -.\" terms of the GNU General Public License as published by the Free -.\" Software Foundation; either version 2 of the License. -.\" -.\" This manual page 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 manual page; if not, write to the Free Software -.\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 -.\" USA -.\" -.Dd November 05, 2009 -.Dt CATCODEC 1 -.Sh NAME -.Nm catcodec -.Nd An open source tool to decode/encode the sample catalogue for OpenTTD -.Sh SYNOPSIS -.Nm -.Op Fl d Ar sample_file -.Op Fl e Ar sample_file -.Sh DESCRIPTION -catcodec decodes and encodes sample catalogues for OpenTTD. These sample -catalogues are not much more than some meta-data (description and file name) -and raw PCM data. -.sp -Decoding a sample catalogue, e.g. sample.cat, results in a sample.sfo that -contains the file names and descriptions of the samples and all samples with -the file name as specified in the catalogue. -.sp -Encoding a sample catalogue, e.g. sample.cat, reads sample.sfo for the file -names and descriptions. It will then load the samples described in sample.sfo -and encodes these into sample.cat. -.sp -Generally speaking encoding a file and then decoding it results in the same -file. Decoding of the original, Transport Tycoon Deluxe, sample format will -force the output to be 11025 Hz, 8 bits mono because the meta-data of some -of the samples is incorrect or even missing. -.sp -Only PCM WAVE files with only the format and data chunks are supported. Any -other formats need to be converted into this. Furthermore only 11025 Hz, -22050 Hz and 44100 Hz with 8 or 16 bits per sample single channel PCM WAVE -files are supported. -.sp -.Sh OPTIONS -.Bl -tag -width ".Fl d Ar sample_file" -.It Fl d Ar sample_file -Decode the given sample catalogue into its components. The -.Ar sample_file -must have the extension '.cat'. For the output meta-data file the '.cat' is -replaced with '.sfo'. The actual samples, in PCM WAVE format, are extracted -into files using the file names, including extension, as described in the -catalogue or meta-data file. -.sp -If any of the files already exists a backup is made, by adding '.bak', -overwriting the existing backup. -.sp -.It Fl e Ar sample_file -Encode the components for the given sample file into a sample catalogue. The -.Ar sample_file -must have the extension '.cat'. For the input meta-data file the '.cat' is -replaced with '.sfo'. The actual samples, in PCM WAVE format, are read from -files using the file names, including extension, as described in the -meta-data file. -.sp -If the -.Ar sample_file -already exists a backup is made, by adding '.bak', overwriting the existing -backup. -.sp -.El -.Sh SEE ALSO -.Nm openttd Ns (1) -the game that uses these sample catalogues. -.sp -.Sh AUTHORS -.An Remko Bijker -.Aq rubidium@openttd.org diff -Nru catcodec-1.0.0/catcodec.cpp catcodec-1.0.4/catcodec.cpp --- catcodec-1.0.0/catcodec.cpp 2009-12-17 22:22:51.000000000 +0000 +++ catcodec-1.0.4/catcodec.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,252 +0,0 @@ -/* $Id: catcodec.cpp 18524 2009-12-17 22:22:51Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file catcodec.cpp Encoding and decoding of "cat" files */ - -#include -#include - -#include "stdafx.h" -#include "io.hpp" -#include "sample.hpp" -#include "rev.hpp" - -/** Are we run interactively, i.e. from the console, or from a script? */ -static bool _interactive; - -/** Show progress, but only on interactive consoles */ -static void ShowProgress() -{ - if (!_interactive) return; - - printf("."); - fflush(stdin); -} - - -/** - * Read a cat file from a reader and extract it's samples. - * @param samples collection to put our samples in - * @param reader reader for the file - */ -static void ReadCat(Samples &samples, FileReader &reader) -{ - uint32_t count = reader.ReadDword(); - bool new_format = (count >> 31) != 0; - count &= 0x7FFFFFFFU; - count /= 8; - - reader.Seek(0); - for (uint32_t i = 0; i < count; i++) { - samples.push_back(new Sample(reader)); - } - - for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { - (*iter)->ReadCatEntry(reader, new_format); - ShowProgress(); - } -} - -/** - * Write a cat file (including the samples) to a cat file - * @param samples collection samples to write to the cat file - * @param writer writer for the file - */ -static void WriteCat(Samples &samples, FileWriter &writer) -{ - uint32_t offset = (uint32_t)samples.size() * 8; - for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { - Sample *sample = *iter; - - sample->SetOffset(offset); - offset = sample->GetNextOffset(); - - writer.WriteDword(sample->GetOffset() | (1U << 31)); - writer.WriteDword(sample->GetSize()); - } - - for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { - (*iter)->WriteCatEntry(writer); - ShowProgress(); - } -} - - -/** - * Read a sfo file from a reader and and the samples mentioned in there - * @param samples collection to put our samples in - * @param reader reader for the sfo file - */ -static void ReadSFO(Samples &samples, FileReader &reader) -{ - /* Temporary read buffer; 512 is long enough for all valid - * lines because the filename and name may be at most 255. - * Add a single space separator and the terminator and you - * got exactly 512. */ - char buffer[512] = ""; - char *filename; - - while (reader.ReadLine(buffer, sizeof(buffer)) != NULL) { - /* Line with comment */ - if (strncmp(buffer, "//", 2) == 0) continue; - - char *name; - if (*buffer == '"') { - filename = buffer + 1; - name = strchr(filename, '"'); - } else { - filename = buffer; - name = strchr(filename, ' '); - } - if (name == NULL) { - throw "Invalid format for " + reader.GetFilename() + " at [" + buffer + "]"; - } - - *name = '\0'; - name++; - while (isspace(*name)) name++; - - char *newline = name + strlen(name) - 1; - while (isspace(*newline)) { - *newline = '\0'; - newline--; - } - - if (strlen(filename) + 1 > 255) throw "Filename is too long in " + reader.GetFilename() + " at [" + buffer + "]"; - if (strlen(name) + 1 > 255) throw "Name is too long in " + reader.GetFilename() + " at [" + name + "]"; - - samples.push_back(new Sample(filename, name)); - - ShowProgress(); - } -} - -/** - * Write a sfo file and the samples to disk - * @param samples collection samples to write to the sfo file and disk - * @param writer writer for the sfo file - */ -static void WriteSFO(Samples &samples, FileWriter &writer) -{ - writer.WriteString("// \"file name\" internal name\n"); - - for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { - Sample *sample = *iter; - - writer.WriteString("\"%s\" %s\n", sample->GetFilename().c_str(), sample->GetName().c_str()); - - FileWriter sample_writer(sample->GetFilename()); - sample->WriteSample(sample_writer); - sample_writer.Close(); - - ShowProgress(); - } -} - - -/** - * Show the help to the user. - * @param cmd the command line the user used - */ -void ShowHelp(const char *cmd) -{ - printf( - "catcodec version %s - Copyright 2009 by Remko Bijker\n" - "Usage:\n" - " %s -d \n" - " Decode all samples in the sample file and put them in this directory\n" - " %s -e \n" - " Encode all samples in this directory and put them in the sample file\n" - "\n" - " denotes the .cat file you want to work on, e.g. sample.cat\n" - "\n" - "catcodec is Copyright 2009 by Remko Bijker\n" - "You may copy and redistribute it under the terms of the GNU General Public\n" - "License version 2, as stated in the file 'COPYING'\n", - _catcodec_version, cmd, cmd - ); -} - -/** - * Oh hello, the user has found the way in :) - * @param argc the number of arguments + 1 - * @param argv list with given arguments - */ -int main(int argc, char *argv[]) -{ - int ret = 0; - Samples samples; - _interactive = isatty(fileno(stdout)) == 1; - - try { - if (argc != 3 || (strcmp(argv[1], "-d") != 0 && strcmp(argv[1], "-e") != 0)) { - ShowHelp(argv[0]); - return 0; - } - - char sfo_file[1024]; - strncpy(sfo_file, argv[2], sizeof(sfo_file)); - char *ext = strrchr(sfo_file, '.'); - if (ext == NULL || strlen(ext) != 4 || strcmp(ext, ".cat") != 0) { - throw string("Unexpected extension; expected \".cat\""); - } - strcpy(ext, ".sfo"); - - if (strcmp(argv[1], "-d") == 0) { - /* Decode the file, so read the cat and then write the sfo */ - - if (_interactive) printf("Reading %s\n", argv[2]); - FileReader reader(argv[2]); - ReadCat(samples, reader); - - if (_interactive) printf("\nWriting %s\n", sfo_file); - FileWriter sfo_writer(sfo_file, false); - WriteSFO(samples, sfo_writer); - sfo_writer.Close(); - } else if (strcmp(argv[1], "-e") == 0) { - /* Encode the file, so read the sfo and then write the cat */ - - if (_interactive) printf("Reading %s\n", sfo_file); - FileReader sfo_reader(sfo_file, false); - ReadSFO(samples, sfo_reader); - - if (_interactive) printf("\nWriting %s\n", argv[2]); - FileWriter cat_writer(argv[2]); - WriteCat(samples, cat_writer); - cat_writer.Close(); - } else { - /* Some invalid second param -> show the help */ - ShowHelp(argv[0]); - return -1; - } - if (_interactive) printf("\nDone\n"); - - } catch (string s) { - fprintf(stderr, "An error occured: %s\n", s.c_str()); - ret = -1; - } - - /* Clear up the samples */ - while (samples.size() != 0) { - delete samples.back(); - samples.pop_back(); - } - return ret; -} diff -Nru catcodec-1.0.0/changelog.txt catcodec-1.0.4/changelog.txt --- catcodec-1.0.0/changelog.txt 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/changelog.txt 2011-08-04 19:23:21.000000000 +0000 @@ -0,0 +1,23 @@ +1.0.4 (2011-08-04) +------------------------------------------------------------------------ +- Change: add option for using Makefile.local + + +1.0.3 (2010-10-31) +------------------------------------------------------------------------ +- Fix: Documentation got installed into the wrong directory + + +1.0.2 (2010-10-20) +------------------------------------------------------------------------ +- Change: Sync installing options with GRFCodec and NFORenum to make packaging more unified for downstream + + +1.0.1 (2010-08-25) +------------------------------------------------------------------------ +- Add: Support for "make install" with DESTDIR support like GRFCodec and NFORenum + + +1.0.0 (2009-12-18) +------------------------------------------------------------------------ +- Add: Initial release diff -Nru catcodec-1.0.0/debian/changelog catcodec-1.0.4/debian/changelog --- catcodec-1.0.0/debian/changelog 2010-02-16 15:36:30.000000000 +0000 +++ catcodec-1.0.4/debian/changelog 2011-08-04 19:40:56.000000000 +0000 @@ -1,3 +1,10 @@ +catcodec (1.0.4-1) unstable; urgency=low + + * [482c4b7] New upstream release 1.0.4. + * [0ceaa00] Bump Standards-Version to 3.9.2, no changed required. + + -- Matthijs Kooijman Thu, 04 Aug 2011 21:39:48 +0200 + catcodec (1.0.0-1) unstable; urgency=low * Initial release (Closes: #568411) diff -Nru catcodec-1.0.0/debian/control catcodec-1.0.4/debian/control --- catcodec-1.0.0/debian/control 2010-02-17 11:35:44.000000000 +0000 +++ catcodec-1.0.4/debian/control 2011-08-04 19:40:56.000000000 +0000 @@ -5,7 +5,7 @@ Uploaders: Jordi Mallach DM-Upload-Allowed: yes Build-Depends: debhelper (>= 7.0.50) -Standards-Version: 3.8.4 +Standards-Version: 3.9.2 Vcs-Browser: http://git.debian.org/?p=collab-maint/catcodec.git Vcs-Git: git://git.debian.org/collab-maint/catcodec.git Homepage: http://www.openttd.org/download-catcodec diff -Nru catcodec-1.0.0/debian/copyright catcodec-1.0.4/debian/copyright --- catcodec-1.0.0/debian/copyright 2010-02-16 15:36:30.000000000 +0000 +++ catcodec-1.0.4/debian/copyright 2011-08-04 19:40:56.000000000 +0000 @@ -36,7 +36,6 @@ Copyright (C) 2009 Matthijs Kooijman -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. +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. diff -Nru catcodec-1.0.0/debian/docs catcodec-1.0.4/debian/docs --- catcodec-1.0.0/debian/docs 2010-02-16 15:36:30.000000000 +0000 +++ catcodec-1.0.4/debian/docs 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -README diff -Nru catcodec-1.0.0/debian/manpages catcodec-1.0.4/debian/manpages --- catcodec-1.0.0/debian/manpages 2010-02-16 15:36:30.000000000 +0000 +++ catcodec-1.0.4/debian/manpages 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -catcodec.1 diff -Nru catcodec-1.0.0/debian/rules catcodec-1.0.4/debian/rules --- catcodec-1.0.0/debian/rules 2010-02-16 15:36:30.000000000 +0000 +++ catcodec-1.0.4/debian/rules 2011-08-04 19:40:56.000000000 +0000 @@ -8,11 +8,12 @@ # Upstream uses make mrproper, which dh_auto_clean doesn't recognize. override_dh_auto_clean: $(MAKE) mrproper + # Remove our config file generated in the configure step + rm -f Makefile.local -# Upstream has no configure override_dh_auto_configure: - -# Upstream has no install -override_dh_auto_install: - $(Q)install -d debian/catcodec/usr/bin/ - $(Q)install -m 755 catcodec debian/catcodec/usr/bin/catcodec + # Default is to install to /usr/local + echo "prefix=/usr" >> Makefile.local + # These will be installed by debhelper + echo "DO_NOT_INSTALL_CHANGELOG=1" >> Makefile.local + echo "DO_NOT_INSTALL_LICENSE=1" >> Makefile.local diff -Nru catcodec-1.0.0/docs/catcodec.1 catcodec-1.0.4/docs/catcodec.1 --- catcodec-1.0.0/docs/catcodec.1 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/docs/catcodec.1 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,85 @@ +.\" $Id: catcodec.1 20614 2010-08-25 16:39:16Z rubidium $ + +.\" catcodec is a tool to decode/encode the sample catalogue for OpenTTD. +.\" Copyright (C) 2009 Remko Bijker +.\" +.\" This manual page is free software. It is distributed under the +.\" terms of the GNU General Public License as published by the Free +.\" Software Foundation; either version 2 of the License. +.\" +.\" This manual page 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 manual page; if not, write to the Free Software +.\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +.\" USA +.\" +.Dd November 05, 2009 +.Dt CATCODEC 1 +.Sh NAME +.Nm catcodec +.Nd An open source tool to decode/encode the sample catalogue for OpenTTD +.Sh SYNOPSIS +.Nm +.Op Fl d Ar sample_file +.Op Fl e Ar sample_file +.Sh DESCRIPTION +catcodec decodes and encodes sample catalogues for OpenTTD. These sample +catalogues are not much more than some meta-data (description and file name) +and raw PCM data. +.sp +Decoding a sample catalogue, e.g. sample.cat, results in a sample.sfo that +contains the file names and descriptions of the samples and all samples with +the file name as specified in the catalogue. +.sp +Encoding a sample catalogue, e.g. sample.cat, reads sample.sfo for the file +names and descriptions. It will then load the samples described in sample.sfo +and encodes these into sample.cat. +.sp +Generally speaking encoding a file and then decoding it results in the same +file. Decoding of the original, Transport Tycoon Deluxe, sample format will +force the output to be 11025 Hz, 8 bits mono because the meta-data of some +of the samples is incorrect or even missing. +.sp +Only PCM WAVE files with only the format and data chunks are supported. Any +other formats need to be converted into this. Furthermore only 11025 Hz, +22050 Hz and 44100 Hz with 8 or 16 bits per sample single channel PCM WAVE +files are supported. +.sp +.Sh OPTIONS +.Bl -tag -width ".Fl d Ar sample_file" +.It Fl d Ar sample_file +Decode the given sample catalogue into its components. The +.Ar sample_file +must have the extension '.cat'. For the output meta-data file the '.cat' is +replaced with '.sfo'. The actual samples, in PCM WAVE format, are extracted +into files using the file names, including extension, as described in the +catalogue or meta-data file. +.sp +If any of the files already exists a backup is made, by adding '.bak', +overwriting the existing backup. +.sp +.It Fl e Ar sample_file +Encode the components for the given sample file into a sample catalogue. The +.Ar sample_file +must have the extension '.cat'. For the input meta-data file the '.cat' is +replaced with '.sfo'. The actual samples, in PCM WAVE format, are read from +files using the file names, including extension, as described in the +meta-data file. +.sp +If the +.Ar sample_file +already exists a backup is made, by adding '.bak', overwriting the existing +backup. +.sp +.El +.Sh SEE ALSO +.Nm openttd Ns (1) +the game that uses these sample catalogues. +.sp +.Sh AUTHORS +.An Remko Bijker +.Aq rubidium@openttd.org diff -Nru catcodec-1.0.0/docs/readme.txt catcodec-1.0.4/docs/readme.txt --- catcodec-1.0.0/docs/readme.txt 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/docs/readme.txt 2010-10-31 17:53:44.000000000 +0000 @@ -0,0 +1,91 @@ +catcodec README +Last updated: 2010-10-31 +Release version: 1.0.3 +------------------------------------------------------------------------ + + +Table of Contents: +------------------ +1) About +2) Contacting +3) Installing +4) Running +5) Compiling + + +1) About: +-- ------ +catcodec decodes and encodes sample catalogues for OpenTTD. These sample +catalogues are not much more than some meta-data (description and file name) +and raw PCM data. + +catcodec is licensed under the GNU General Public License version 2.0. For +more information, see the file 'COPYING'. + + +2) Contact: +-- -------- +Contacting the author can be done in two ways: + - sending an email to rubidium@openttd.org + - chat with him on IRC; Rubidium can be found in #openttd on irc.oftc.net + + +3) Installation: +-- ------------- +Installing catcodec is fairly straightforward. Just copy the executable into +any directory. It is advised to put the executable in one of the directories +in your path so it can be easily found. For example when compiling OpenSFX. +To uninstall simply remove the executable. + + +4) Usage: +-- ------ +Decoding a sample catalogue, e.g. sample.cat, results in a sample.sfo that +contains the file names and descriptions of the samples and all samples with +the file name as specified in the catalogue. + +Encoding a sample catalogue, e.g. sample.cat, reads sample.sfo for the file +names and descriptions. It will then load the samples described in sample.sfo +and encodes these into sample.cat. + +Generally speaking encoding a file and then decoding it results in the same +file. Decoding of the original, Transport Tycoon Deluxe, sample format will +force the output to be 11025 Hz, 8 bits mono because the meta-data of some of +the samples is incorrect or even missing. + +Only PCM WAVE files with only the format and data chunks are supported. Any +other formats need to be converted into this. Furthermore only 11025 Hz, +22050 Hz and 44100 Hz with 8 or 16 bits per sample single channel PCM WAVE +files are supported. + +Options for catcodec are (mutually exclusive): + -d sample_file Decode the given sample catalogue into its components. The + sample_file must have the extension '.cat'. For the output + meta-data file the '.cat' is replaced with '.sfo'. The actual + samples, in PCM WAVE format, are extracted into files using + the file names, including extension, as described in the + catalogue or meta-data file. + + If any of the files already exists a backup is made, by + adding '.bak', overwriting the existing backup. + + -e sample_file Encode the components for the given sample file into a sample + catalogue. The sample_file must have the extension '.cat'. + For the input meta-data file the '.cat' is replaced with + '.sfo'. The actual samples, in PCM WAVE format, are read from + files using the file names, including extension, as described + in the meta-data file. + + If the sample_file already exists a backup is made, by adding + '.bak', overwriting the existing backup. + + +5) Compiling: +-- ---------- +GCC/ICC: + Just use "make", or on non-GNU systems "gmake". + +Microsoft Visual C++: + There is no project file, but you can compile catcodec using this compiler + by either running "make.bat" or "make -f Makefile.msvc". In both cases the + compiler's executable "cl.exe" must be in the path. diff -Nru catcodec-1.0.0/findversion.sh catcodec-1.0.4/findversion.sh --- catcodec-1.0.0/findversion.sh 2009-12-17 22:38:12.000000000 +0000 +++ catcodec-1.0.4/findversion.sh 2011-08-04 19:23:21.000000000 +0000 @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: findversion.sh 18525 2009-12-17 22:38:12Z rubidium $ +# $Id: findversion.sh 22718 2011-08-04 19:23:21Z rubidium $ # This file is part of catcodec. # catcodec 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, version 2. @@ -56,5 +56,5 @@ exit 1; fi -VERSION="1.0.0" +VERSION="1.0.4" echo "$VERSION $VERSION 0 $VERSION" diff -Nru catcodec-1.0.0/io.cpp catcodec-1.0.4/io.cpp --- catcodec-1.0.0/io.cpp 2009-11-05 22:11:04.000000000 +0000 +++ catcodec-1.0.4/io.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,186 +0,0 @@ -/* $Id: io.cpp 17979 2009-11-05 22:11:04Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file io.cpp Implementation of reading/writing to files */ - -#include "stdafx.h" -#include "io.hpp" - -FileReader::FileReader(string filename, bool binary) -{ - this->file = fopen(filename.c_str(), binary ? "rb" : "r"); - this->filename = filename; - - if (this->file == NULL) { - throw "Could not open " + filename + " for reading"; - } -} - -FileReader::~FileReader() -{ - fclose(this->file); -} - -uint8_t FileReader::ReadByte() -{ - uint8_t b; - this->ReadRaw(&b, 1); - return b; -} - -uint16_t FileReader::ReadWord() -{ - uint16_t b = this->ReadByte(); - return (this->ReadByte() << 8) | b; -} - -uint32_t FileReader::ReadDword() -{ - uint32_t b = this->ReadWord(); - return (this->ReadWord() << 16) | b; -} - -void FileReader::ReadRaw(uint8_t *in, size_t amount) -{ - if (fread(in, 1, amount, this->file) != amount) { - throw "Unexpected end of " + this->filename; - } -} - -char *FileReader::ReadLine(char *in, int length) -{ - char *ret = fgets(in, length, this->file); - - /* fgets doesn't guarantee string termination if no newline/EOF is found */ - in[length - 1] = '\0'; - - return ret; -} - -void FileReader::Seek(uint32_t pos) -{ - if (fseek(this->file, pos, SEEK_SET) != 0) throw "Seeking in " + this->filename + " failed."; -} - -uint32_t FileReader::GetPos() -{ - return ftell(this->file); -} - -string FileReader::GetFilename() const -{ - return this->filename; -} - - -FileWriter::FileWriter(string filename, bool binary) -{ - this->filename_new = filename + ".new"; - this->filename = filename; - - this->file = fopen(filename_new.c_str(), binary ? "w+b" : "w+"); - - if (this->file == NULL) { - throw "Could not open " + this->filename_new + " for writing"; - } -} - -FileWriter::~FileWriter() -{ - if (this->file != NULL) { - fclose(this->file); - unlink(this->filename_new.c_str()); - } -} - -void FileWriter::WriteByte(uint8_t data) -{ - this->WriteRaw(&data, 1); -} - -void FileWriter::WriteWord(uint16_t data) -{ - this->WriteByte(data & 0xFF); - this->WriteByte(data >> 8); -} - -void FileWriter::WriteDword(uint32_t data) -{ - this->WriteWord(data & 0xFFFF); - this->WriteWord(data >> 16); -} - -void FileWriter::WriteRaw(const uint8_t *out, size_t amount) -{ - assert(this->file != NULL); - - if (fwrite(out, 1, amount, this->file) != amount) { - throw "Unexpected failure while writing to " + this->filename; - } -} - -void FileWriter::WriteString(const char *format, ...) -{ - assert(this->file != NULL); - - va_list ap; - - va_start(ap, format); - if (vfprintf(this->file, format, ap) < 0) { - throw "Unexpected failure while writing to " + this->filename; - } - va_end(ap); -} - -uint32_t FileWriter::GetPos() -{ - assert(this->file != NULL); - - return ftell(this->file); -} - -string FileWriter::GetFilename() const -{ - return this->filename; -} - -void FileWriter::Close() -{ - /* First close the .new file */ - fclose(this->file); - this->file = NULL; - - /* Then remove the existing .bak file */ - string filename_bak = this->filename + ".bak"; - if (unlink(filename_bak.c_str()) != 0 && errno != ENOENT) { - fprintf(stderr, "Warning: could not remove %s (%s)\n", filename_bak.c_str(), strerror(errno)); - } - - /* Then move the existing file to .bak */ - if (rename(this->filename.c_str(), filename_bak.c_str()) != 0 && errno != ENOENT) { - fprintf(stderr, "Warning: could not rename %s to %s (%s)\n", this->filename.c_str(), filename_bak.c_str(), strerror(errno)); - } - - /* And finally move the .new file to the actual wanted filename */ - if (rename(this->filename_new.c_str(), this->filename.c_str()) != 0) { - fprintf(stderr, "Warning: could not rename %s to %s (%s)\n", this->filename_new.c_str(), this->filename.c_str(), strerror(errno)); - throw "Could not close " + this->filename; - } -} diff -Nru catcodec-1.0.0/io.hpp catcodec-1.0.4/io.hpp --- catcodec-1.0.0/io.hpp 2009-11-05 22:11:04.000000000 +0000 +++ catcodec-1.0.4/io.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,174 +0,0 @@ -/* $Id: io.hpp 17979 2009-11-05 22:11:04Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file io.hpp Interface for reading/writing to files */ - -#ifndef IO_H -#define IO_H - -/** A string is a string; simple as that */ -typedef std::string string; - -/** - * Simple class to perform binary and string reading from a file. - */ -class FileReader { - FILE *file; ///< The file to be read by this instance - string filename; ///< The filename of the file - -public: - /** - * Create a new reader for the given file. - * @param filename the file to read from - * @param binary read the file as binary or text? - */ - FileReader(string filename, bool binary = true); - - /** - * Cleans up our mess - */ - ~FileReader(); - - - /** - * Read a single byte from the stream. - * @return the read byte - */ - uint8_t ReadByte(); - - /** - * Read a word (2 bytes) from the stream in little endian. - * @return the read word - */ - uint16_t ReadWord(); - - /** - * Read a dword (4 bytes) from the stream in little endian. - * @return the read dword - */ - uint32_t ReadDword(); - - /** - * Read a number of raw bytes from the stream. - * @param in the buffer where to put the data - * @param amount the amount of bytes to read - */ - void ReadRaw(uint8_t *in, size_t amount); - - /** - * Read a line of text from the stream. - * @param in the buffer where to put the data - * @param length the maximum amount of bytes to read - */ - char *ReadLine(char *in, int length); - - - /** - * Go to a specific location in the stream. - * @param pos the position to go to. - */ - void Seek(uint32_t pos); - - /** - * Get the current position in the stream. - * @return the position in the stream - */ - uint32_t GetPos(); - - /** - * Get the filename of this file. - * @return the filename - */ - string GetFilename() const; -}; - -/** - * Simple class to perform binary and string writing to a file. - */ -class FileWriter { - FILE *file; ///< The file to be read by this instance - string filename; ///< The filename of the file - string filename_new; ///< The filename for the temporary file - -public: - /** - * Create a new writer for the given file. - * @param filename the file to write to - * @param binary write the file as binary or text? - */ - FileWriter(string filename, bool binary = true); - - /** - * Cleans up our mess - */ - ~FileWriter(); - - /** - * Write a single byte to the stream. - * @param data the byte to write - */ - void WriteByte(uint8_t data); - - /** - * Write a word (2 bytes) to the stream in little endian. - * @param data the word to write - */ - void WriteWord(uint16_t data); - - /** - * Write a dword (4 bytes) to the stream in little endian. - * @param data the dword to write - */ - void WriteDword(uint32_t data); - - /** - * Write a number of raw bytes to the stream. - * @param out the buffer of data to write - * @param amount the amount of bytes to write - */ - void WriteRaw(const uint8_t *out, size_t amount); - - /** - * Write a line of text to the stream. - * @param format the format of the written string - * @param ... the data to actually write - */ - void WriteString(const char *format, ...); - - /** - * Get the current position in the stream. - * @return the position in the stream - */ - uint32_t GetPos(); - - /** - * Get the filename of this file. - * @return the filename - */ - string GetFilename() const; - - /** - * Close the output, i.e. commit the file to disk. - * If this is not done, the file with not be written to disk. - */ - void Close(); -}; - -#endif /* IO_H */ diff -Nru catcodec-1.0.0/make.bat catcodec-1.0.4/make.bat --- catcodec-1.0.0/make.bat 2009-11-05 22:11:04.000000000 +0000 +++ catcodec-1.0.4/make.bat 2010-08-25 16:39:16.000000000 +0000 @@ -1,8 +1,8 @@ -rem $Id: make.bat 17979 2009-11-05 22:11:04Z rubidium $ +rem $Id: make.bat 20614 2010-08-25 16:39:16Z rubidium $ rem This file is part of catcodec. rem catcodec 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, version 2. rem catcodec 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. rem See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with catcodec. If not, see . -cl /MT /Ot /W2 /RTC1 /EHsc /DWIN32 catcodec.cpp io.cpp sample.cpp +cl /MT /Ot /W2 /RTC1 /EHsc /DWIN32 src/catcodec.cpp src/io.cpp src/sample.cpp diff -Nru catcodec-1.0.0/Makefile catcodec-1.0.4/Makefile --- catcodec-1.0.0/Makefile 2009-11-05 22:33:48.000000000 +0000 +++ catcodec-1.0.4/Makefile 2011-08-04 19:23:21.000000000 +0000 @@ -1,6 +1,13 @@ -# $Id: Makefile 17982 2009-11-05 22:33:48Z rubidium $ +# $Id: Makefile 22718 2011-08-04 19:23:21Z rubidium $ -# This file is part of catcodec. +# ========================================================= +# Makefile for the catcodec program +# +# Don't put any local configuration in here +# Change Makefile.local instead, it'll be +# preserved when updating the sources +# ========================================================= +# # catcodec 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, version 2. # catcodec 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 catcodec. If not, see . @@ -11,37 +18,51 @@ Q = @ endif -AWK = "awk" + ROOT_DIR := $(shell pwd) -BUNDLE_DIR = "$(ROOT_DIR)/bundle" -BUNDLES_DIR = "$(ROOT_DIR)/bundles" -CATCODEC = catcodec$(EXTENSION) +PACKAGE_NAME = catcodec + +-include Makefile.local + +AWK ?= "awk" +BUNDLE_DIR ?= "$(ROOT_DIR)/bundle" +BUNDLES_DIR ?= "$(ROOT_DIR)/bundles" +CATCODEC ?= catcodec$(EXTENSION) +CXXFLAGS ?= -Wall -Wcast-qual -Wwrite-strings +OS ?= unknown + + OBJS = catcodec.o io.o sample.o rev.o -OS = unknown -CFLAGS += -Wall -Wcast-qual -Wwrite-strings -Wno-multichar +# Regardless of the warning settings, we really do not want these errors. +CXXFLAGS += -Wno-multichar ifdef DEBUG - CFLAGS += -g -ggdb + CXXFLAGS += -g -ggdb endif all: $(CATCODEC) -%.o: %.cpp - $(CXX) $(CFLAGS) -c -o $@ $^ - -$(CATCODEC): $(OBJS) - $(CXX) $(CFLAGS) -o $@ $^ +objs/%.o: src/%.cpp + $(Q)mkdir -p objs + @echo '[CPP] $@' + $(Q)$(CXX) $(CXXFLAGS) -c -o $@ $< + +$(CATCODEC): $(OBJS:%=objs/%) + @echo '[LINK] $@' + $(Q)$(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $^ VERSION := $(shell ./findversion.sh | cut -f 1 -d' ') RES := $(shell if [ "`cat version.cache 2>/dev/null`" != "$(VERSION)" ]; then echo "$(VERSION)" > version.cache; fi ) -rev.cpp: version.cache rev.cpp.in - $(Q)cat rev.cpp.in | sed "s@\!\!VERSION\!\!@$(VERSION)@g" > rev.cpp +src/rev.cpp: version.cache src/rev.cpp.in + $(Q)cat src/rev.cpp.in | sed "s@\!\!VERSION\!\!@$(VERSION)@g" > src/rev.cpp clean: - rm -f $(OBJS) $(CATCODEC) rev.cpp version.cache + @echo '[CLEAN]' + $(Q)rm -f $(CATCODEC) rev.cpp version.cache + $(Q)rm -rf objs mrproper: clean - rm -rf $(BUNDLE_DIR) $(BUNDLES_DIR) + $(Q)rm -rf $(BUNDLE_DIR) $(BUNDLES_DIR) include Makefile.bundle diff -Nru catcodec-1.0.0/Makefile.bundle catcodec-1.0.4/Makefile.bundle --- catcodec-1.0.0/Makefile.bundle 2009-12-17 16:03:49.000000000 +0000 +++ catcodec-1.0.4/Makefile.bundle 2010-10-20 07:20:51.000000000 +0000 @@ -1,4 +1,4 @@ -# $Id: Makefile.bundle 18521 2009-12-17 16:03:49Z rubidium $ +# $Id: Makefile.bundle 20998 2010-10-20 07:20:51Z rubidium $ # This file is part of catcodec. # catcodec 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, version 2. @@ -9,6 +9,21 @@ # Creation of bundles # +# Standard make convention variables/locations +prefix ?= /usr/local +exec_prefix ?= $(prefix) +datarootdir ?= $(prefix)/share +datadir ?= $(datarootdir) + +bindir ?= $(exec_prefix)/bin +mandir ?= $(datarootdir)/man +man1dir ?= $(mandir)/man1 +docdir ?= $(datarootdir)/doc/$(PACKAGE_NAME) + +openttddir ?= $(datarootdir}/openttd +openttdgmdir ?= $(openttddir)/gm/$(PACKAGE_NAME) +openttddatadir ?= $(openttddir)/data/$(PACKAGE_NAME) + # The revision is needed for the bundle name and creating an OSX application bundle. ifdef REVISION REV := $(REVISION) @@ -29,14 +44,40 @@ bundle: all @echo '[BUNDLE] Constructing bundle' - $(Q)rm -rf "${BUNDLE_DIR}" - $(Q)mkdir -p "${BUNDLE_DIR}" + $(Q)rm -rf "$(BUNDLE_DIR)" + $(Q)mkdir -p "$(BUNDLE_DIR)" + $(Q)mkdir -p "$(BUNDLE_DIR)/docs" + $(Q)mkdir -p "$(BUNDLE_DIR)/man" $(Q)cp "$(CATCODEC)" "$(BUNDLE_DIR)/" $(Q)cp "$(ROOT_DIR)/COPYING" "$(BUNDLE_DIR)/" - $(Q)cp "$(ROOT_DIR)/README" "$(BUNDLE_DIR)/" - $(Q)cp catcodec.1 "$(BUNDLE_DIR)/" + $(Q)cp "$(ROOT_DIR)/changelog.txt" "$(BUNDLE_DIR)/" + $(Q)cp "$(ROOT_DIR)/docs/readme.txt" "$(BUNDLE_DIR)/docs/" + $(Q)cp "$(ROOT_DIR)/docs/catcodec.1" "$(BUNDLE_DIR)/man/" + $(Q)gzip -9 "$(BUNDLE_DIR)/man/catcodec.1" ifeq ($(CATCODEC), catcodec.exe) $(Q)unix2dos "$(BUNDLE_DIR)/COPYING" + $(Q)unix2dos "$(BUNDLE_DIR)/"*.txt +endif + +install: bundle + @echo '[INSTALL] Installing catcodec' + $(Q)install -d "$(DESTDIR)$(bindir)" + $(Q)install -m 755 "$(BUNDLE_DIR)/$(CATCODEC)" "$(DESTDIR)$(bindir)/" +ifndef DO_NOT_INSTALL_DOCS + $(_C)install -d "$(DESTDIR)$(docdir)" + $(_C)install -m 644 "$(BUNDLE_DIR)/docs/"* "$(DESTDIR)$(docdir)" +endif +ifndef DO_NOT_INSTALL_CHANGELOG + $(_C)install -d "$(DESTDIR)$(docdir)" + $(_C)install -m 644 "$(BUNDLE_DIR)/changelog.txt" "$(DESTDIR)$(docdir)" +endif +ifndef DO_NOT_INSTALL_LICENSE + $(_C)install -d "$(DESTDIR)$(docdir)" + $(_C)install -m 644 "$(BUNDLE_DIR)/COPYING" "$(DESTDIR)$(docdir)" +endif +ifndef DO_NOT_INSTALL_MAN + $(_C)install -d "$(DESTDIR)$(man1dir)" + $(_C)install -m 644 "$(BUNDLE_DIR)/man/"*.1.gz "$(DESTDIR)$(man1dir)/" endif ### Packing the current bundle into several compressed file formats ### diff -Nru catcodec-1.0.0/Makefile.msvc catcodec-1.0.4/Makefile.msvc --- catcodec-1.0.0/Makefile.msvc 2009-11-05 22:33:48.000000000 +0000 +++ catcodec-1.0.4/Makefile.msvc 2010-08-25 16:39:16.000000000 +0000 @@ -1,4 +1,4 @@ -# $Id: Makefile.msvc 17982 2009-11-05 22:33:48Z rubidium $ +# $Id: Makefile.msvc 20614 2010-08-25 16:39:16Z rubidium $ # This file is part of catcodec. # catcodec 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, version 2. # catcodec 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. @@ -27,12 +27,12 @@ OS = "windows" all: rev.cpp - cl /MT /Ot /W2 /RTC1 /EHsc /DWIN32 catcodec.cpp io.cpp sample.cpp rev.cpp + cl /MT /Ot /W2 /RTC1 /EHsc /DWIN32 src/catcodec.cpp src/io.cpp src/sample.cpp src/rev.cpp VERSION := $(shell ./findversion.sh | cut -f 1 -d' ') RES := $(shell if [ "`cat version.cache 2>/dev/null`" != "$(VERSION)" ]; then echo "$(VERSION)" > version.cache; fi ) -rev.cpp: version.cache rev.cpp.in - $(Q)cat rev.cpp.in | sed "s@\!\!VERSION\!\!@$(VERSION)@g" > rev.cpp +src/rev.cpp: version.cache src/rev.cpp.in + $(Q)cat src/rev.cpp.in | sed "s@\!\!VERSION\!\!@$(VERSION)@g" > src/rev.cpp include Makefile.bundle diff -Nru catcodec-1.0.0/README catcodec-1.0.4/README --- catcodec-1.0.0/README 2009-12-17 22:22:51.000000000 +0000 +++ catcodec-1.0.4/README 1970-01-01 00:00:00.000000000 +0000 @@ -1,91 +0,0 @@ -catcodec README -Last updated: 2009-12-17 -Release version: 0.1.0 ------------------------------------------------------------------------- - - -Table of Contents: ------------------- -1) About -2) Contacting -3) Installing -4) Running -5) Compiling - - -1) About: --- ------ -catcodec decodes and encodes sample catalogues for OpenTTD. These sample -catalogues are not much more than some meta-data (description and file name) -and raw PCM data. - -catcodec is licensed under the GNU General Public License version 2.0. For -more information, see the file 'COPYING'. - - -2) Contact: --- -------- -Contacting the author can be done in two ways: - - sending an email to rubidium@openttd.org - - chat with him on IRC; Rubidium can be found in #openttd on irc.oftc.net - - -3) Installation: --- ------------- -Installing catcodec is fairly straightforward. Just copy the executable into -any directory. It is advised to put the executable in one of the directories -in your path so it can be easily found. For example when compiling OpenSFX. -To uninstall simply remove the executable. - - -4) Usage: --- ------ -Decoding a sample catalogue, e.g. sample.cat, results in a sample.sfo that -contains the file names and descriptions of the samples and all samples with -the file name as specified in the catalogue. - -Encoding a sample catalogue, e.g. sample.cat, reads sample.sfo for the file -names and descriptions. It will then load the samples described in sample.sfo -and encodes these into sample.cat. - -Generally speaking encoding a file and then decoding it results in the same -file. Decoding of the original, Transport Tycoon Deluxe, sample format will -force the output to be 11025 Hz, 8 bits mono because the meta-data of some of -the samples is incorrect or even missing. - -Only PCM WAVE files with only the format and data chunks are supported. Any -other formats need to be converted into this. Furthermore only 11025 Hz, -22050 Hz and 44100 Hz with 8 or 16 bits per sample single channel PCM WAVE -files are supported. - -Options for catcodec are (mutually exclusive): - -d sample_file Decode the given sample catalogue into its components. The - sample_file must have the extension '.cat'. For the output - meta-data file the '.cat' is replaced with '.sfo'. The actual - samples, in PCM WAVE format, are extracted into files using - the file names, including extension, as described in the - catalogue or meta-data file. - - If any of the files already exists a backup is made, by - adding '.bak', overwriting the existing backup. - - -e sample_file Encode the components for the given sample file into a sample - catalogue. The sample_file must have the extension '.cat'. - For the input meta-data file the '.cat' is replaced with - '.sfo'. The actual samples, in PCM WAVE format, are read from - files using the file names, including extension, as described - in the meta-data file. - - If the sample_file already exists a backup is made, by adding - '.bak', overwriting the existing backup. - - -5) Compiling: --- ---------- -GCC/ICC: - Just use "make", or on non-GNU systems "gmake". - -Microsoft Visual C++: - There is no project file, but you can compile catcodec using this compiler - by either running "make.bat" or "make -f Makefile.msvc". In both cases the - compiler's executable "cl.exe" must be in the path. diff -Nru catcodec-1.0.0/rev.cpp.in catcodec-1.0.4/rev.cpp.in --- catcodec-1.0.0/rev.cpp.in 2009-11-05 22:33:48.000000000 +0000 +++ catcodec-1.0.4/rev.cpp.in 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -/* $Id: rev.cpp.in 17982 2009-11-05 22:33:48Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file rev.cpp Autogenerated file with the revision and such of OpenTTD. */ - -#include "stdafx.h" -#include "rev.hpp" - -/** - * The text version of catcodec's revision. - */ -const char _catcodec_version[] = "!!VERSION!!"; diff -Nru catcodec-1.0.0/rev.hpp catcodec-1.0.4/rev.hpp --- catcodec-1.0.0/rev.hpp 2009-11-05 22:33:48.000000000 +0000 +++ catcodec-1.0.4/rev.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ -/* $Id: rev.hpp 17982 2009-11-05 22:33:48Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file rev.h declaration of catcodec revision dependant variables */ - -#ifndef REV_HPP -#define REV_HPP - -extern const char _catcodec_version[]; - -#endif /* REV_HPP */ diff -Nru catcodec-1.0.0/sample.cpp catcodec-1.0.4/sample.cpp --- catcodec-1.0.0/sample.cpp 2009-11-05 22:11:04.000000000 +0000 +++ catcodec-1.0.4/sample.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,255 +0,0 @@ -/* $Id: sample.cpp 17979 2009-11-05 22:11:04Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - * @file sample.cpp Implementation of Samples - * - * The format of .wav PCM encoded files is fairly simple. The "verbatim" - * 'RIFF' etc. is written as is in the file. The numbers are always - * written in the little endian way. - *
    - *
  • 'RIFF'
  • - *
  • dword with number of bytes following
  • - *
  • 'WAVE'
  • - *
  • 'fmt '
  • - *
  • dword with size of 'fmt ' chunk, always 16
  • - *
  • word with audio format, always 1 (PCM)
  • - *
  • word with number of channels, always 1
  • - *
  • dword with sample rate, always 11025, 22050 or 44100
  • - *
  • dword with byte rate, always sample rate * number of channels * bits per sample / 8
  • - *
  • word with block alignment, always number of channels * bits per sample / 8
  • - *
  • word with bits per sample, always 8 or 16
  • - *
  • 'data'
  • - *
  • dword with number of bytes following
  • - *
  • actual raw PCM data
  • - *
- * - * This makes the whole thing 44 bytes + the actual payload long. - */ - -#include "stdafx.h" -#include "sample.hpp" - -/** The size of the RIFF headers of a WAV file */ -static const uint32_t RIFF_HEADER_SIZE = 44; - -/** - * Read a string (byte length including termination, actual data) from a reader. - * @param reader the reader to read from - * @return the read string - */ -static string ReadString(FileReader &reader) -{ - uint8_t name_len = reader.ReadByte(); - char buffer[256]; - - reader.ReadRaw((uint8_t *)buffer, name_len); - buffer[name_len - 1] = '\0'; - - return buffer; -} - -/** - * Write a string (byte length including termination, actual data) to a writer. - * @param str the string to write - * @param writer the writer to write to - */ -static void WriteString(const string str, FileWriter &writer) -{ - uint8_t str_len = (uint8_t)(str.length() + 1); - writer.WriteByte(str_len); - writer.WriteRaw((const uint8_t *)str.c_str(), str_len); -} - - -Sample::Sample(FileReader &reader) : - sample_data(NULL) -{ - this->offset = reader.ReadDword() & 0x7FFFFFFF; - this->size = reader.ReadDword(); -} - -Sample::Sample(string filename, string name) : - offset(0), - name(name), - filename(filename), - sample_data(NULL) -{ - FileReader sample_reader(filename); - this->ReadSample(sample_reader, false); -} - -Sample::~Sample() -{ - free(this->sample_data); -} - -void Sample::ReadSample(FileReader &reader, bool check_size) -{ - assert(this->sample_data == NULL); - - if (reader.ReadDword() != 'FFIR') throw "Unexpected chunk; expected \"RIFF\" in " + reader.GetFilename(); - - if (check_size) { - if (reader.ReadDword() + 8 != size ) throw "Unexpected RIFF chunk size in " + reader.GetFilename(); - } else { - this->size = reader.ReadDword() + 8; - } - if (reader.ReadDword() != 'EVAW') throw "Unexpected format; expected \"WAVE\" in " + reader.GetFilename(); - if (reader.ReadDword() != ' tmf') throw "Unexpected format; expected \"fmt \" in " + reader.GetFilename(); - if (reader.ReadDword() != 16 ) throw "Unexpected fmt chunk size in " + reader.GetFilename(); - if (reader.ReadWord() != 1 ) throw "Unexpected audio format; expected \"PCM\" in " + reader.GetFilename(); - - this->num_channels = reader.ReadWord(); - if (this->num_channels != 1) throw "Unexpected number of audio channels; expected 1 in " + reader.GetFilename(); - - this->sample_rate = reader.ReadDword(); - if (this->sample_rate != 11025 && this->sample_rate != 22050 && this->sample_rate != 44100) throw "Unexpected same rate; expected 11025, 22050 or 44100 in " + reader.GetFilename(); - - /* Read these and validate them later on. - * Saving them is unnecesary as they can be easily calucated. */ - uint32_t byte_rate = reader.ReadDword(); - uint16_t block_align = reader.ReadWord(); - - this->bits_per_sample = reader.ReadWord(); - if (this->bits_per_sample != 8 && this->bits_per_sample != 16) throw "Unexpected number of bits per channel; expected 8 or 16 in " + reader.GetFilename(); - - if (byte_rate != this->sample_rate * this->num_channels * this->bits_per_sample / 8) throw "Unexpected byte rate in " + reader.GetFilename(); - if (block_align != this->num_channels * this->bits_per_sample / 8) throw "Unexpected block align in " + reader.GetFilename(); - - if (reader.ReadDword() != 'atad') throw "Unexpected chunk; expected \"data\" in " + reader.GetFilename(); - - /* Sometimes the files are padded, which causes them to start at the - * wrong offset further on, so just read whatever amount of data was - * specified in the top RIFF as long as sample size is within those - * boundaries, i.e. within the RIFF. */ - this->sample_size = reader.ReadDword(); - if (this->sample_size + RIFF_HEADER_SIZE > size) throw "Unexpected data chunk size in " + reader.GetFilename(); - - this->sample_data = (uint8_t *)malloc(this->size - RIFF_HEADER_SIZE); - reader.ReadRaw(this->sample_data, this->size - RIFF_HEADER_SIZE); -} - -void Sample::ReadCatEntry(FileReader &reader, bool new_format) -{ - assert(this->sample_data == NULL); - - if (reader.GetPos() != this->GetOffset()) throw "Invalid offset in file " + reader.GetFilename(); - - this->name = ReadString(reader); - - if (!new_format && this->GetName().compare("Corrupt sound") == 0) { - /* In the old format there was one sample that was raw PCM. */ - this->sample_size = this->size; - this->sample_data = (uint8_t *)malloc(this->sample_size); - reader.ReadRaw(this->sample_data, this->sample_size); - - this->size += RIFF_HEADER_SIZE; - } else { - this->ReadSample(reader); - } - - if (!new_format) { - /* The old format had sometimes the wrong values for e.g. - * sample rate which made the playback too fast. */ - this->num_channels = 1; - this->sample_rate = 11025; - this->bits_per_sample = 8; - } - - /* Some kind of data byte, unused */ - reader.ReadByte(); - - this->filename = ReadString(reader); -} - -void Sample::WriteSample(FileWriter &writer) const -{ - assert(this->sample_data != NULL); - - writer.WriteDword('FFIR'); - writer.WriteDword(this->size - 8); - writer.WriteDword('EVAW'); - - writer.WriteDword(' tmf'); - writer.WriteDword(16); - writer.WriteWord(1); - writer.WriteWord(this->num_channels); - writer.WriteDword(this->sample_rate); - writer.WriteDword(this->sample_rate * this->num_channels * this->bits_per_sample / 8); - writer.WriteWord(this->num_channels * this->bits_per_sample / 8); - writer.WriteWord(this->bits_per_sample); - - writer.WriteDword('atad'); - writer.WriteDword(this->sample_size); - writer.WriteRaw(this->sample_data, this->size - RIFF_HEADER_SIZE); -} - -void Sample::WriteCatEntry(FileWriter &writer) const -{ - assert(this->sample_data != NULL); - - if (writer.GetPos() != this->GetOffset()) throw "Invalid offset when writing file " + writer.GetFilename(); - - WriteString(this->GetName(), writer); - this->WriteSample(writer); - - /* Some kind of separator byte */ - writer.WriteByte(0); - - WriteString(this->GetFilename(), writer); -} - -string Sample::GetName() const -{ - return this->name; -} - -string Sample::GetFilename() const -{ - return this->filename; -} - -void Sample::SetOffset(uint32_t offset) -{ - assert(this->offset == 0); - this->offset = offset; -} - -uint32_t Sample::GetNextOffset() const -{ - return this->offset + - 1 + // length of the name - (this->name.length() + 1) + // the name + '\0' - this->size + // size of the data - 1 + // the delimiter - 1 + // length of the filename - (this->filename.length() + 1); // the filename + '\0' -} - -uint32_t Sample::GetOffset() const -{ - return this->offset; -} - -uint32_t Sample::GetSize() const -{ - return this->size; -} diff -Nru catcodec-1.0.0/sample.hpp catcodec-1.0.4/sample.hpp --- catcodec-1.0.0/sample.hpp 2009-11-05 22:11:04.000000000 +0000 +++ catcodec-1.0.4/sample.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,142 +0,0 @@ -/* $Id: sample.hpp 17979 2009-11-05 22:11:04Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file sample.hpp Interface for Sample reading/writing */ - -#ifndef SAMPLE_HPP -#define SAMPLE_HPP - -#include -#include "io.hpp" - -/** - * Simple in-memory representation of a sample. - */ -class Sample { -private: - uint32_t offset; ///< Offset from the begin of the cat - uint32_t size; ///< The size of the WAV RIFF, i.e. excluding name and filename - - string name; ///< The name of the sample - string filename; ///< The filename of the sample - - uint16_t num_channels; ///< Number of channels; either 1 or 2 - uint32_t sample_rate; ///< Sample rate; either 11025, 22050 or 44100 - uint16_t bits_per_sample; ///< Number of bits per sample; either 8 or 16 - - uint32_t sample_size; ///< The size of the raw data below - uint8_t *sample_data; ///< The actual raw sample data - -public: - /** - * Create a new sample by reading data from a file. - * In this case the data comes from a cat file, so for now we only - * read the offset and size from the file. - * @param reader the file to read from - */ - Sample(FileReader &reader); - - /** - * Creates a new sample by reading the sample from a given (wav) file. - * @param filename the file to read the sample from - * @param name the name of the sample - */ - Sample(string filename, string name); - - /** - * Cleans up our mess. - */ - ~Sample(); - - - /** - * Reads a sample from a reader. - * It reads WAV files (if that is the only thing in the file). - * This function has some very strict tests on validity of the input file. - * @param reader place to read the sample from - * @param check_size whether to check that our size makes sense with the size from the sample - */ - void ReadSample(FileReader &reader, bool check_size = true); - - /** - * Reads a cat entry from a reader. - * This function has some very strict tests on validity of the input file. - * @param reader place to read the cat entry from - * @param new_format whether this is the old or new format; there are different strictness tests for both cases - */ - void ReadCatEntry(FileReader &reader, bool new_format); - - /** - * Write a sample to a writer. If only a sample is written to the - * file it would be a valid WAV file. - * @param writer place to write the sample to - */ - void WriteSample(FileWriter &writer) const; - - /** - * Write a cat entry to a writer. - * @param writer place to write the cat entry to - */ - void WriteCatEntry(FileWriter &writer) const; - - - /** - * Get the name of the sample. - * @return the name of the sample - */ - string GetName() const; - - /** - * Get the filename of the sample - * @return the filename of the sample - */ - string GetFilename() const; - - - /** - * Set the offset from the begin of the cat to this cat entry. - * @param offset the offset. - */ - void SetOffset(uint32_t offset); - - /** - * Get the offset for the cat entry that follows us. - * @return the offset for the next cat entry - */ - uint32_t GetNextOffset() const; - - /** - * Get the offset from the begin of the cat to this cat entry. - * @return the offset - */ - uint32_t GetOffset() const; - - - /** - * Get the size of the WAV part of the file. - * @return the size - */ - uint32_t GetSize() const; -}; - -/** Lets have us a vector of samples */ -typedef std::vector Samples; - -#endif /* SAMPLE_HPP */ diff -Nru catcodec-1.0.0/src/catcodec.cpp catcodec-1.0.4/src/catcodec.cpp --- catcodec-1.0.0/src/catcodec.cpp 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/catcodec.cpp 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,252 @@ +/* $Id: catcodec.cpp 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** @file catcodec.cpp Encoding and decoding of "cat" files */ + +#include +#include + +#include "stdafx.h" +#include "io.hpp" +#include "sample.hpp" +#include "rev.hpp" + +/** Are we run interactively, i.e. from the console, or from a script? */ +static bool _interactive; + +/** Show progress, but only on interactive consoles */ +static void ShowProgress() +{ + if (!_interactive) return; + + printf("."); + fflush(stdin); +} + + +/** + * Read a cat file from a reader and extract it's samples. + * @param samples collection to put our samples in + * @param reader reader for the file + */ +static void ReadCat(Samples &samples, FileReader &reader) +{ + uint32_t count = reader.ReadDword(); + bool new_format = (count >> 31) != 0; + count &= 0x7FFFFFFFU; + count /= 8; + + reader.Seek(0); + for (uint32_t i = 0; i < count; i++) { + samples.push_back(new Sample(reader)); + } + + for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { + (*iter)->ReadCatEntry(reader, new_format); + ShowProgress(); + } +} + +/** + * Write a cat file (including the samples) to a cat file + * @param samples collection samples to write to the cat file + * @param writer writer for the file + */ +static void WriteCat(Samples &samples, FileWriter &writer) +{ + uint32_t offset = (uint32_t)samples.size() * 8; + for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { + Sample *sample = *iter; + + sample->SetOffset(offset); + offset = sample->GetNextOffset(); + + writer.WriteDword(sample->GetOffset() | (1U << 31)); + writer.WriteDword(sample->GetSize()); + } + + for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { + (*iter)->WriteCatEntry(writer); + ShowProgress(); + } +} + + +/** + * Read a sfo file from a reader and and the samples mentioned in there + * @param samples collection to put our samples in + * @param reader reader for the sfo file + */ +static void ReadSFO(Samples &samples, FileReader &reader) +{ + /* Temporary read buffer; 512 is long enough for all valid + * lines because the filename and name may be at most 255. + * Add a single space separator and the terminator and you + * got exactly 512. */ + char buffer[512] = ""; + char *filename; + + while (reader.ReadLine(buffer, sizeof(buffer)) != NULL) { + /* Line with comment */ + if (strncmp(buffer, "//", 2) == 0) continue; + + char *name; + if (*buffer == '"') { + filename = buffer + 1; + name = strchr(filename, '"'); + } else { + filename = buffer; + name = strchr(filename, ' '); + } + if (name == NULL) { + throw "Invalid format for " + reader.GetFilename() + " at [" + buffer + "]"; + } + + *name = '\0'; + name++; + while (isspace(*name)) name++; + + char *newline = name + strlen(name) - 1; + while (isspace(*newline)) { + *newline = '\0'; + newline--; + } + + if (strlen(filename) + 1 > 255) throw "Filename is too long in " + reader.GetFilename() + " at [" + buffer + "]"; + if (strlen(name) + 1 > 255) throw "Name is too long in " + reader.GetFilename() + " at [" + name + "]"; + + samples.push_back(new Sample(filename, name)); + + ShowProgress(); + } +} + +/** + * Write a sfo file and the samples to disk + * @param samples collection samples to write to the sfo file and disk + * @param writer writer for the sfo file + */ +static void WriteSFO(Samples &samples, FileWriter &writer) +{ + writer.WriteString("// \"file name\" internal name\n"); + + for (Samples::iterator iter = samples.begin(); iter != samples.end(); iter++) { + Sample *sample = *iter; + + writer.WriteString("\"%s\" %s\n", sample->GetFilename().c_str(), sample->GetName().c_str()); + + FileWriter sample_writer(sample->GetFilename()); + sample->WriteSample(sample_writer); + sample_writer.Close(); + + ShowProgress(); + } +} + + +/** + * Show the help to the user. + * @param cmd the command line the user used + */ +void ShowHelp(const char *cmd) +{ + printf( + "catcodec version %s - Copyright 2009 by Remko Bijker\n" + "Usage:\n" + " %s -d \n" + " Decode all samples in the sample file and put them in this directory\n" + " %s -e \n" + " Encode all samples in this directory and put them in the sample file\n" + "\n" + " denotes the .cat file you want to work on, e.g. sample.cat\n" + "\n" + "catcodec is Copyright 2009 by Remko Bijker\n" + "You may copy and redistribute it under the terms of the GNU General Public\n" + "License version 2, as stated in the file 'COPYING'\n", + _catcodec_version, cmd, cmd + ); +} + +/** + * Oh hello, the user has found the way in :) + * @param argc the number of arguments + 1 + * @param argv list with given arguments + */ +int main(int argc, char *argv[]) +{ + int ret = 0; + Samples samples; + _interactive = isatty(fileno(stdout)) == 1; + + try { + if (argc != 3 || (strcmp(argv[1], "-d") != 0 && strcmp(argv[1], "-e") != 0)) { + ShowHelp(argv[0]); + return 0; + } + + char sfo_file[1024]; + strncpy(sfo_file, argv[2], sizeof(sfo_file)); + char *ext = strrchr(sfo_file, '.'); + if (ext == NULL || strlen(ext) != 4 || strcmp(ext, ".cat") != 0) { + throw string("Unexpected extension; expected \".cat\""); + } + strcpy(ext, ".sfo"); + + if (strcmp(argv[1], "-d") == 0) { + /* Decode the file, so read the cat and then write the sfo */ + + if (_interactive) printf("Reading %s\n", argv[2]); + FileReader reader(argv[2]); + ReadCat(samples, reader); + + if (_interactive) printf("\nWriting %s\n", sfo_file); + FileWriter sfo_writer(sfo_file, false); + WriteSFO(samples, sfo_writer); + sfo_writer.Close(); + } else if (strcmp(argv[1], "-e") == 0) { + /* Encode the file, so read the sfo and then write the cat */ + + if (_interactive) printf("Reading %s\n", sfo_file); + FileReader sfo_reader(sfo_file, false); + ReadSFO(samples, sfo_reader); + + if (_interactive) printf("\nWriting %s\n", argv[2]); + FileWriter cat_writer(argv[2]); + WriteCat(samples, cat_writer); + cat_writer.Close(); + } else { + /* Some invalid second param -> show the help */ + ShowHelp(argv[0]); + return -1; + } + if (_interactive) printf("\nDone\n"); + + } catch (string s) { + fprintf(stderr, "An error occured: %s\n", s.c_str()); + ret = -1; + } + + /* Clear up the samples */ + while (samples.size() != 0) { + delete samples.back(); + samples.pop_back(); + } + return ret; +} diff -Nru catcodec-1.0.0/src/io.cpp catcodec-1.0.4/src/io.cpp --- catcodec-1.0.0/src/io.cpp 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/io.cpp 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,186 @@ +/* $Id: io.cpp 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** @file io.cpp Implementation of reading/writing to files */ + +#include "stdafx.h" +#include "io.hpp" + +FileReader::FileReader(string filename, bool binary) +{ + this->file = fopen(filename.c_str(), binary ? "rb" : "r"); + this->filename = filename; + + if (this->file == NULL) { + throw "Could not open " + filename + " for reading"; + } +} + +FileReader::~FileReader() +{ + fclose(this->file); +} + +uint8_t FileReader::ReadByte() +{ + uint8_t b; + this->ReadRaw(&b, 1); + return b; +} + +uint16_t FileReader::ReadWord() +{ + uint16_t b = this->ReadByte(); + return (this->ReadByte() << 8) | b; +} + +uint32_t FileReader::ReadDword() +{ + uint32_t b = this->ReadWord(); + return (this->ReadWord() << 16) | b; +} + +void FileReader::ReadRaw(uint8_t *in, size_t amount) +{ + if (fread(in, 1, amount, this->file) != amount) { + throw "Unexpected end of " + this->filename; + } +} + +char *FileReader::ReadLine(char *in, int length) +{ + char *ret = fgets(in, length, this->file); + + /* fgets doesn't guarantee string termination if no newline/EOF is found */ + in[length - 1] = '\0'; + + return ret; +} + +void FileReader::Seek(uint32_t pos) +{ + if (fseek(this->file, pos, SEEK_SET) != 0) throw "Seeking in " + this->filename + " failed."; +} + +uint32_t FileReader::GetPos() +{ + return ftell(this->file); +} + +string FileReader::GetFilename() const +{ + return this->filename; +} + + +FileWriter::FileWriter(string filename, bool binary) +{ + this->filename_new = filename + ".new"; + this->filename = filename; + + this->file = fopen(filename_new.c_str(), binary ? "w+b" : "w+"); + + if (this->file == NULL) { + throw "Could not open " + this->filename_new + " for writing"; + } +} + +FileWriter::~FileWriter() +{ + if (this->file != NULL) { + fclose(this->file); + unlink(this->filename_new.c_str()); + } +} + +void FileWriter::WriteByte(uint8_t data) +{ + this->WriteRaw(&data, 1); +} + +void FileWriter::WriteWord(uint16_t data) +{ + this->WriteByte(data & 0xFF); + this->WriteByte(data >> 8); +} + +void FileWriter::WriteDword(uint32_t data) +{ + this->WriteWord(data & 0xFFFF); + this->WriteWord(data >> 16); +} + +void FileWriter::WriteRaw(const uint8_t *out, size_t amount) +{ + assert(this->file != NULL); + + if (fwrite(out, 1, amount, this->file) != amount) { + throw "Unexpected failure while writing to " + this->filename; + } +} + +void FileWriter::WriteString(const char *format, ...) +{ + assert(this->file != NULL); + + va_list ap; + + va_start(ap, format); + if (vfprintf(this->file, format, ap) < 0) { + throw "Unexpected failure while writing to " + this->filename; + } + va_end(ap); +} + +uint32_t FileWriter::GetPos() +{ + assert(this->file != NULL); + + return ftell(this->file); +} + +string FileWriter::GetFilename() const +{ + return this->filename; +} + +void FileWriter::Close() +{ + /* First close the .new file */ + fclose(this->file); + this->file = NULL; + + /* Then remove the existing .bak file */ + string filename_bak = this->filename + ".bak"; + if (unlink(filename_bak.c_str()) != 0 && errno != ENOENT) { + fprintf(stderr, "Warning: could not remove %s (%s)\n", filename_bak.c_str(), strerror(errno)); + } + + /* Then move the existing file to .bak */ + if (rename(this->filename.c_str(), filename_bak.c_str()) != 0 && errno != ENOENT) { + fprintf(stderr, "Warning: could not rename %s to %s (%s)\n", this->filename.c_str(), filename_bak.c_str(), strerror(errno)); + } + + /* And finally move the .new file to the actual wanted filename */ + if (rename(this->filename_new.c_str(), this->filename.c_str()) != 0) { + fprintf(stderr, "Warning: could not rename %s to %s (%s)\n", this->filename_new.c_str(), this->filename.c_str(), strerror(errno)); + throw "Could not close " + this->filename; + } +} diff -Nru catcodec-1.0.0/src/io.hpp catcodec-1.0.4/src/io.hpp --- catcodec-1.0.0/src/io.hpp 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/io.hpp 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,174 @@ +/* $Id: io.hpp 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** @file io.hpp Interface for reading/writing to files */ + +#ifndef IO_H +#define IO_H + +/** A string is a string; simple as that */ +typedef std::string string; + +/** + * Simple class to perform binary and string reading from a file. + */ +class FileReader { + FILE *file; ///< The file to be read by this instance + string filename; ///< The filename of the file + +public: + /** + * Create a new reader for the given file. + * @param filename the file to read from + * @param binary read the file as binary or text? + */ + FileReader(string filename, bool binary = true); + + /** + * Cleans up our mess + */ + ~FileReader(); + + + /** + * Read a single byte from the stream. + * @return the read byte + */ + uint8_t ReadByte(); + + /** + * Read a word (2 bytes) from the stream in little endian. + * @return the read word + */ + uint16_t ReadWord(); + + /** + * Read a dword (4 bytes) from the stream in little endian. + * @return the read dword + */ + uint32_t ReadDword(); + + /** + * Read a number of raw bytes from the stream. + * @param in the buffer where to put the data + * @param amount the amount of bytes to read + */ + void ReadRaw(uint8_t *in, size_t amount); + + /** + * Read a line of text from the stream. + * @param in the buffer where to put the data + * @param length the maximum amount of bytes to read + */ + char *ReadLine(char *in, int length); + + + /** + * Go to a specific location in the stream. + * @param pos the position to go to. + */ + void Seek(uint32_t pos); + + /** + * Get the current position in the stream. + * @return the position in the stream + */ + uint32_t GetPos(); + + /** + * Get the filename of this file. + * @return the filename + */ + string GetFilename() const; +}; + +/** + * Simple class to perform binary and string writing to a file. + */ +class FileWriter { + FILE *file; ///< The file to be read by this instance + string filename; ///< The filename of the file + string filename_new; ///< The filename for the temporary file + +public: + /** + * Create a new writer for the given file. + * @param filename the file to write to + * @param binary write the file as binary or text? + */ + FileWriter(string filename, bool binary = true); + + /** + * Cleans up our mess + */ + ~FileWriter(); + + /** + * Write a single byte to the stream. + * @param data the byte to write + */ + void WriteByte(uint8_t data); + + /** + * Write a word (2 bytes) to the stream in little endian. + * @param data the word to write + */ + void WriteWord(uint16_t data); + + /** + * Write a dword (4 bytes) to the stream in little endian. + * @param data the dword to write + */ + void WriteDword(uint32_t data); + + /** + * Write a number of raw bytes to the stream. + * @param out the buffer of data to write + * @param amount the amount of bytes to write + */ + void WriteRaw(const uint8_t *out, size_t amount); + + /** + * Write a line of text to the stream. + * @param format the format of the written string + * @param ... the data to actually write + */ + void WriteString(const char *format, ...); + + /** + * Get the current position in the stream. + * @return the position in the stream + */ + uint32_t GetPos(); + + /** + * Get the filename of this file. + * @return the filename + */ + string GetFilename() const; + + /** + * Close the output, i.e. commit the file to disk. + * If this is not done, the file with not be written to disk. + */ + void Close(); +}; + +#endif /* IO_H */ diff -Nru catcodec-1.0.0/src/rev.cpp.in catcodec-1.0.4/src/rev.cpp.in --- catcodec-1.0.0/src/rev.cpp.in 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/rev.cpp.in 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,29 @@ +/* $Id: rev.cpp.in 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** @file rev.cpp Autogenerated file with the revision and such of OpenTTD. */ + +#include "stdafx.h" +#include "rev.hpp" + +/** + * The text version of catcodec's revision. + */ +const char _catcodec_version[] = "!!VERSION!!"; diff -Nru catcodec-1.0.0/src/rev.hpp catcodec-1.0.4/src/rev.hpp --- catcodec-1.0.0/src/rev.hpp 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/rev.hpp 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,28 @@ +/* $Id: rev.hpp 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** @file rev.h declaration of catcodec revision dependant variables */ + +#ifndef REV_HPP +#define REV_HPP + +extern const char _catcodec_version[]; + +#endif /* REV_HPP */ diff -Nru catcodec-1.0.0/src/sample.cpp catcodec-1.0.4/src/sample.cpp --- catcodec-1.0.0/src/sample.cpp 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/sample.cpp 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,255 @@ +/* $Id: sample.cpp 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * @file sample.cpp Implementation of Samples + * + * The format of .wav PCM encoded files is fairly simple. The "verbatim" + * 'RIFF' etc. is written as is in the file. The numbers are always + * written in the little endian way. + *
    + *
  • 'RIFF'
  • + *
  • dword with number of bytes following
  • + *
  • 'WAVE'
  • + *
  • 'fmt '
  • + *
  • dword with size of 'fmt ' chunk, always 16
  • + *
  • word with audio format, always 1 (PCM)
  • + *
  • word with number of channels, always 1
  • + *
  • dword with sample rate, always 11025, 22050 or 44100
  • + *
  • dword with byte rate, always sample rate * number of channels * bits per sample / 8
  • + *
  • word with block alignment, always number of channels * bits per sample / 8
  • + *
  • word with bits per sample, always 8 or 16
  • + *
  • 'data'
  • + *
  • dword with number of bytes following
  • + *
  • actual raw PCM data
  • + *
+ * + * This makes the whole thing 44 bytes + the actual payload long. + */ + +#include "stdafx.h" +#include "sample.hpp" + +/** The size of the RIFF headers of a WAV file */ +static const uint32_t RIFF_HEADER_SIZE = 44; + +/** + * Read a string (byte length including termination, actual data) from a reader. + * @param reader the reader to read from + * @return the read string + */ +static string ReadString(FileReader &reader) +{ + uint8_t name_len = reader.ReadByte(); + char buffer[256]; + + reader.ReadRaw((uint8_t *)buffer, name_len); + buffer[name_len - 1] = '\0'; + + return buffer; +} + +/** + * Write a string (byte length including termination, actual data) to a writer. + * @param str the string to write + * @param writer the writer to write to + */ +static void WriteString(const string str, FileWriter &writer) +{ + uint8_t str_len = (uint8_t)(str.length() + 1); + writer.WriteByte(str_len); + writer.WriteRaw((const uint8_t *)str.c_str(), str_len); +} + + +Sample::Sample(FileReader &reader) : + sample_data(NULL) +{ + this->offset = reader.ReadDword() & 0x7FFFFFFF; + this->size = reader.ReadDword(); +} + +Sample::Sample(string filename, string name) : + offset(0), + name(name), + filename(filename), + sample_data(NULL) +{ + FileReader sample_reader(filename); + this->ReadSample(sample_reader, false); +} + +Sample::~Sample() +{ + free(this->sample_data); +} + +void Sample::ReadSample(FileReader &reader, bool check_size) +{ + assert(this->sample_data == NULL); + + if (reader.ReadDword() != 'FFIR') throw "Unexpected chunk; expected \"RIFF\" in " + reader.GetFilename(); + + if (check_size) { + if (reader.ReadDword() + 8 != size ) throw "Unexpected RIFF chunk size in " + reader.GetFilename(); + } else { + this->size = reader.ReadDword() + 8; + } + if (reader.ReadDword() != 'EVAW') throw "Unexpected format; expected \"WAVE\" in " + reader.GetFilename(); + if (reader.ReadDword() != ' tmf') throw "Unexpected format; expected \"fmt \" in " + reader.GetFilename(); + if (reader.ReadDword() != 16 ) throw "Unexpected fmt chunk size in " + reader.GetFilename(); + if (reader.ReadWord() != 1 ) throw "Unexpected audio format; expected \"PCM\" in " + reader.GetFilename(); + + this->num_channels = reader.ReadWord(); + if (this->num_channels != 1) throw "Unexpected number of audio channels; expected 1 in " + reader.GetFilename(); + + this->sample_rate = reader.ReadDword(); + if (this->sample_rate != 11025 && this->sample_rate != 22050 && this->sample_rate != 44100) throw "Unexpected same rate; expected 11025, 22050 or 44100 in " + reader.GetFilename(); + + /* Read these and validate them later on. + * Saving them is unnecesary as they can be easily calucated. */ + uint32_t byte_rate = reader.ReadDword(); + uint16_t block_align = reader.ReadWord(); + + this->bits_per_sample = reader.ReadWord(); + if (this->bits_per_sample != 8 && this->bits_per_sample != 16) throw "Unexpected number of bits per channel; expected 8 or 16 in " + reader.GetFilename(); + + if (byte_rate != this->sample_rate * this->num_channels * this->bits_per_sample / 8) throw "Unexpected byte rate in " + reader.GetFilename(); + if (block_align != this->num_channels * this->bits_per_sample / 8) throw "Unexpected block align in " + reader.GetFilename(); + + if (reader.ReadDword() != 'atad') throw "Unexpected chunk; expected \"data\" in " + reader.GetFilename(); + + /* Sometimes the files are padded, which causes them to start at the + * wrong offset further on, so just read whatever amount of data was + * specified in the top RIFF as long as sample size is within those + * boundaries, i.e. within the RIFF. */ + this->sample_size = reader.ReadDword(); + if (this->sample_size + RIFF_HEADER_SIZE > size) throw "Unexpected data chunk size in " + reader.GetFilename(); + + this->sample_data = (uint8_t *)malloc(this->size - RIFF_HEADER_SIZE); + reader.ReadRaw(this->sample_data, this->size - RIFF_HEADER_SIZE); +} + +void Sample::ReadCatEntry(FileReader &reader, bool new_format) +{ + assert(this->sample_data == NULL); + + if (reader.GetPos() != this->GetOffset()) throw "Invalid offset in file " + reader.GetFilename(); + + this->name = ReadString(reader); + + if (!new_format && this->GetName().compare("Corrupt sound") == 0) { + /* In the old format there was one sample that was raw PCM. */ + this->sample_size = this->size; + this->sample_data = (uint8_t *)malloc(this->sample_size); + reader.ReadRaw(this->sample_data, this->sample_size); + + this->size += RIFF_HEADER_SIZE; + } else { + this->ReadSample(reader); + } + + if (!new_format) { + /* The old format had sometimes the wrong values for e.g. + * sample rate which made the playback too fast. */ + this->num_channels = 1; + this->sample_rate = 11025; + this->bits_per_sample = 8; + } + + /* Some kind of data byte, unused */ + reader.ReadByte(); + + this->filename = ReadString(reader); +} + +void Sample::WriteSample(FileWriter &writer) const +{ + assert(this->sample_data != NULL); + + writer.WriteDword('FFIR'); + writer.WriteDword(this->size - 8); + writer.WriteDword('EVAW'); + + writer.WriteDword(' tmf'); + writer.WriteDword(16); + writer.WriteWord(1); + writer.WriteWord(this->num_channels); + writer.WriteDword(this->sample_rate); + writer.WriteDword(this->sample_rate * this->num_channels * this->bits_per_sample / 8); + writer.WriteWord(this->num_channels * this->bits_per_sample / 8); + writer.WriteWord(this->bits_per_sample); + + writer.WriteDword('atad'); + writer.WriteDword(this->sample_size); + writer.WriteRaw(this->sample_data, this->size - RIFF_HEADER_SIZE); +} + +void Sample::WriteCatEntry(FileWriter &writer) const +{ + assert(this->sample_data != NULL); + + if (writer.GetPos() != this->GetOffset()) throw "Invalid offset when writing file " + writer.GetFilename(); + + WriteString(this->GetName(), writer); + this->WriteSample(writer); + + /* Some kind of separator byte */ + writer.WriteByte(0); + + WriteString(this->GetFilename(), writer); +} + +string Sample::GetName() const +{ + return this->name; +} + +string Sample::GetFilename() const +{ + return this->filename; +} + +void Sample::SetOffset(uint32_t offset) +{ + assert(this->offset == 0); + this->offset = offset; +} + +uint32_t Sample::GetNextOffset() const +{ + return this->offset + + 1 + // length of the name + (this->name.length() + 1) + // the name + '\0' + this->size + // size of the data + 1 + // the delimiter + 1 + // length of the filename + (this->filename.length() + 1); // the filename + '\0' +} + +uint32_t Sample::GetOffset() const +{ + return this->offset; +} + +uint32_t Sample::GetSize() const +{ + return this->size; +} diff -Nru catcodec-1.0.0/src/sample.hpp catcodec-1.0.4/src/sample.hpp --- catcodec-1.0.0/src/sample.hpp 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/sample.hpp 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,142 @@ +/* $Id: sample.hpp 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** @file sample.hpp Interface for Sample reading/writing */ + +#ifndef SAMPLE_HPP +#define SAMPLE_HPP + +#include +#include "io.hpp" + +/** + * Simple in-memory representation of a sample. + */ +class Sample { +private: + uint32_t offset; ///< Offset from the begin of the cat + uint32_t size; ///< The size of the WAV RIFF, i.e. excluding name and filename + + string name; ///< The name of the sample + string filename; ///< The filename of the sample + + uint16_t num_channels; ///< Number of channels; either 1 or 2 + uint32_t sample_rate; ///< Sample rate; either 11025, 22050 or 44100 + uint16_t bits_per_sample; ///< Number of bits per sample; either 8 or 16 + + uint32_t sample_size; ///< The size of the raw data below + uint8_t *sample_data; ///< The actual raw sample data + +public: + /** + * Create a new sample by reading data from a file. + * In this case the data comes from a cat file, so for now we only + * read the offset and size from the file. + * @param reader the file to read from + */ + Sample(FileReader &reader); + + /** + * Creates a new sample by reading the sample from a given (wav) file. + * @param filename the file to read the sample from + * @param name the name of the sample + */ + Sample(string filename, string name); + + /** + * Cleans up our mess. + */ + ~Sample(); + + + /** + * Reads a sample from a reader. + * It reads WAV files (if that is the only thing in the file). + * This function has some very strict tests on validity of the input file. + * @param reader place to read the sample from + * @param check_size whether to check that our size makes sense with the size from the sample + */ + void ReadSample(FileReader &reader, bool check_size = true); + + /** + * Reads a cat entry from a reader. + * This function has some very strict tests on validity of the input file. + * @param reader place to read the cat entry from + * @param new_format whether this is the old or new format; there are different strictness tests for both cases + */ + void ReadCatEntry(FileReader &reader, bool new_format); + + /** + * Write a sample to a writer. If only a sample is written to the + * file it would be a valid WAV file. + * @param writer place to write the sample to + */ + void WriteSample(FileWriter &writer) const; + + /** + * Write a cat entry to a writer. + * @param writer place to write the cat entry to + */ + void WriteCatEntry(FileWriter &writer) const; + + + /** + * Get the name of the sample. + * @return the name of the sample + */ + string GetName() const; + + /** + * Get the filename of the sample + * @return the filename of the sample + */ + string GetFilename() const; + + + /** + * Set the offset from the begin of the cat to this cat entry. + * @param offset the offset. + */ + void SetOffset(uint32_t offset); + + /** + * Get the offset for the cat entry that follows us. + * @return the offset for the next cat entry + */ + uint32_t GetNextOffset() const; + + /** + * Get the offset from the begin of the cat to this cat entry. + * @return the offset + */ + uint32_t GetOffset() const; + + + /** + * Get the size of the WAV part of the file. + * @return the size + */ + uint32_t GetSize() const; +}; + +/** Lets have us a vector of samples */ +typedef std::vector Samples; + +#endif /* SAMPLE_HPP */ diff -Nru catcodec-1.0.0/src/stdafx.h catcodec-1.0.4/src/stdafx.h --- catcodec-1.0.0/src/stdafx.h 1970-01-01 00:00:00.000000000 +0000 +++ catcodec-1.0.4/src/stdafx.h 2010-08-25 16:39:16.000000000 +0000 @@ -0,0 +1,65 @@ +/* $Id: stdafx.h 20614 2010-08-25 16:39:16Z rubidium $ */ + +/* + * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. + * Copyright (C) 2009 Remko Bijker + * + * 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, version 2. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** @file stdafx.h Definition of base types and functions in a cross-platform compatible way. */ + +#ifndef STDAFX_H +#define STDAFX_H + +#include +#include +#include +#include + +#include +#include +#include + +#if defined(_MSC_VER) + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #define UNUSED + + #define fileno _fileno + #pragma warning(disable: 4996) // 'strdup' was declared deprecated +#elif defined(__GNUC__) + #include + #define UNUSED __attribute__((unused)) +#else + #warning "Unknown compiler type, might not compile!" + #include + #define UNUSED +#endif + +#if defined(WIN32) + #include + #define isatty _isatty + #define unlink _unlink +#endif + +#define assert_compile(expr) extern const int __ct_assert__[1 - 2 * !(expr)] UNUSED + +/* Check if the types have the bitsizes like we are using them */ +assert_compile(sizeof(uint32_t) == 4); +assert_compile(sizeof(uint16_t) == 2); +assert_compile(sizeof(uint8_t) == 1); + +#endif /* STDAFX_H */ diff -Nru catcodec-1.0.0/stdafx.h catcodec-1.0.4/stdafx.h --- catcodec-1.0.0/stdafx.h 2009-11-05 22:11:04.000000000 +0000 +++ catcodec-1.0.4/stdafx.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ -/* $Id: stdafx.h 17979 2009-11-05 22:11:04Z rubidium $ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file stdafx.h Definition of base types and functions in a cross-platform compatible way. */ - -#ifndef STDAFX_H -#define STDAFX_H - -#include -#include -#include -#include - -#include -#include -#include - -#if defined(_MSC_VER) - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; - #define UNUSED - - #define fileno _fileno - #pragma warning(disable: 4996) // 'strdup' was declared deprecated -#elif defined(__GNUC__) - #include - #define UNUSED __attribute__((unused)) -#else - #warning "Unknown compiler type, might not compile!" - #include - #define UNUSED -#endif - -#if defined(WIN32) - #include - #define isatty _isatty - #define unlink _unlink -#endif - -#define assert_compile(expr) extern const int __ct_assert__[1 - 2 * !(expr)] UNUSED - -/* Check if the types have the bitsizes like we are using them */ -assert_compile(sizeof(uint32_t) == 4); -assert_compile(sizeof(uint16_t) == 2); -assert_compile(sizeof(uint8_t) == 1); - -#endif /* STDAFX_H */