From 2575b38f044b66dc9034c92f01ebd9da558ad3b3 Mon Sep 17 00:00:00 2001 From: Marcin Deranek Date: Thu, 25 Feb 2016 21:32:09 +0100 Subject: Initial release --- Makefile | 9 + micro.cc | 1312 +++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.txt | 166 +++++++ samples/out.txt.1 | 614 +++++++++++++++++++++++++ samples/out.txt.2 | 7 + samples/test.txt | 465 +++++++++++++++++++ samples/x-men.txt | 621 +++++++++++++++++++++++++ 7 files changed, 3194 insertions(+) create mode 100755 Makefile create mode 100755 micro.cc create mode 100755 readme.txt create mode 100755 samples/out.txt.1 create mode 100755 samples/out.txt.2 create mode 100755 samples/test.txt create mode 100755 samples/x-men.txt diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..27d82cf --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +CC=g++ +CPPFLAGS=-O2 +#CPPFLAGS=-O -DDEBUG + +all: micro + +micro: micro.o +clean: + rm -f micro *.o diff --git a/micro.cc b/micro.cc new file mode 100755 index 0000000..b39c28a --- /dev/null +++ b/micro.cc @@ -0,0 +1,1312 @@ +/* TODO: buffer <- replace strcpy with strncpy etc. + * + * + */ + +#include +#include +#include +#include +#include +#ifdef _WIN32 + #include + #define COMPARESTRING strnicmp +#else + #include + #define COMPARESTRING strncasecmp +#endif + +#define VERSION "2.76" // program version +#define BUFFER_SIZE 4096 // input line buffer size + +class line; // prototype of line class + +char const *params[]={ // parameters table + "if", // 0 + "t", // 1 + "e", // 2 + "o", // 3 + "n", // 4 + "of", // 5 + "v", // 6 + "i", // 7 + "s", // 8 + "j", // 9 + "c", // 10 + "tol", // 11 + "m", // 12 + "m0", // 13 + "tt", // 14 + "m1", // 15 + "l", // 16 + "f", // 17 +#ifdef _WIN32 + "g", // 18 +#endif + "o1", // 19 + "o2", // 20 + "i1", // 21 + "i2" // 22 +}; + +// Subtitle stat types +enum what {chars, lines, subs, length, subchars}; +// Work mode of program +enum state {normal, info, generate}; +// Subtitle formats +enum format {unknown, micro, sam}; + +char buffer[BUFFER_SIZE]; +line* root; // beginning of the text (pointer on the first line) +double iframerate=25.0; // default framerate for input subtitle +double oframerate=iframerate; // default framerate for output subtitle +double a=0.0, b=3.0, c=0.05; // default time conversion ratios +long int tolerance1; // time tolerance for moving subtitles +long int tolerance2; // time tolerance for squeezing subtitles +double offset=0; // default offset - don't move +unsigned int nlines=0; // number of read lines +long int splittime; // split time in fames +long int jointime; // join time in frames for 2nd subtitle file +long int cut1time, cut2time; // cut times in frames +int compactlines=2, compactchars=60; // number of lines and characters during compacting +int compactoffset=2; // 'window size' during compacting subtitles +int llength, clength; // length and number of lines which are displayed in report +state pmode=normal; // mode +format iformat; // input format (autodetect) +format oformat=unknown; // output format +#ifdef _WIN32 +char* language; // language name during generation of .mvd file +#endif + +class flags { // work modes +public: +unsigned int endtime : 1; +unsigned int calculate : 1; +unsigned int oframerate : 1; +unsigned int verbose : 1; +unsigned int split : 1; +unsigned int join : 1; +unsigned int cut : 1; +unsigned int tolerance : 1; +unsigned int compact0 : 1; +unsigned int compact1 : 1; +unsigned int compact2 : 1; +unsigned int length : 1; +unsigned int forcecompact : 1; +unsigned int autodetect : 1; +flags() {endtime=0; calculate=0; oframerate=0; verbose=1; split=1; join=1; cut=1; tolerance=1; compact0=1; compact1=1; compact2=1; length=1; forcecompact=1; autodetect=0; }; +}; +flags* disable=new flags(); + +char* input; // input filename +char* output; // output filename +char* join; // joining subtitle filename + +// error message function +void error(const int num, const void* message1,const void* message2) +{ +std::cerr << "Error: "; +switch(num){ + case 1: + std::cerr <<"Cannot open file '"<<(char*)message1<<"'.\n"; + break; + case 2: + std::cerr <<"Cannot write to file '"<<(char*)message1<<"'\n."; + break; + case 4: + std::cerr <<"Wrong switch '"<<(char*)message1<<"'.\n"; + break; + case 9: + std::cerr <<"Wrong number of arguments.\n"; + break; + case 16: + std::cerr <<"Switches -j and -i/-g are exclusive.\n"; + break; + case 17: + std::cerr <<" should be greater than .\n"; + break; + case 21: + std::cerr <<"Minimal available offset is "<<*(double *)message1<<" .\n"; + break; + case 50: + std::cerr <<"Missing "<<(char *)message1<<" argument.\n"; + break; + case 51: + std::cerr <<"Bad "<<(char *)message1<<" argument.\n"; + break; + case 52: + std::cerr <<"Bad "<<(char*)message1<<"argument of "<<(char *)message2<<" switch.\n"; + break; + case 53: + std::cerr <<(char *)message1<<" parameter should be "<<(char *)message2<<".\n"; + break; + default: + std::cerr <<"General error.\n"; + break; +} +exit (num); +} + +// warning message function +void warning(const int num, const void* message1, const void* message2, const void* message3) +{ +std::cerr << "Warning: "; +switch(num){ + case 1: + std::cerr <<"Skipping line "<<*(unsigned int *)message1<<" of '"<<(char *)message2<<"' ("<<(char *)message3<<").\n"; + break; + case 2: + std::cerr <<"Line "<<*(unsigned int *)message1<<" of '"<<(char *)message2<<"' contains more than 5 lines.\n"; + break; + case 3: + std::cerr <<"Enabling "<<(char *)message1<<" ("<<(char *)message2<<" set).\n"; + break; + default: + std::cerr <<"Something strange.\n"; + break; +} +} + +// short help function +void help(char* _filename) +{ +std::cout << "microAdjust "<] \n"; +std::cout << _filename << " -j