File: commandline.cxx

package info (click to toggle)
mpgtx 1.3.1-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 432 kB
  • ctags: 426
  • sloc: cpp: 5,624; sh: 1,542; makefile: 107
file content (829 lines) | stat: -rw-r--r-- 23,241 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
/*************************************************************
 *   mpgtx an mpeg toolbox                                   *
 *   by Laurent Alacoque <laureck@users.sourceforge.net>     *
 *   (c) 2001                                                *
 *   You may copy, modify and redistribute this              *
 *   source file under the terms of the GNU Public License   *
 ************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mpeg.hh"
#include "mpegOut.hh"
#include "chunkTab.hh"

// declared in id3command.hh
extern int ParseID3Command(int argc, char** argv, int argc_offset);

// philipp
bool desperate_mode = false;
bool preserve_header = false;
bool print_progress = true;
// [L] ifdef the endMessage
#ifdef NEED_END_MESSAGE
void endMessage(void);
#endif

bool aspect_correction  = false;
byte forced_sequence_header = 0;

char* progname;
#ifndef NOSIGNAL_H
// for bug report
#include <signal.h>
#include <stdlib.h>
// for bug report

char** myargv;
int myargc;
c_char mpgtx_stack[mpgtx_stack_count];
int mpgtx_stack_current=0;

/*!
 * Callback for SIGSEGV, SIGBUS and SIGFPE.
 * prints a formated bug report, warns user and opens the bug report file
 *
 * @param signum catched signal: SIGSEGV, SIGBUS or SIGFPE
 */
void CatchBug(int signum)
{
	//print a formated bug report and warn user
	//open the bug report file
	FILE* bugreport;
	bugreport=fopen("bug.report","w+");

	//warn user
	fprintf(stderr,"BUG: Sorry you shouldn't read this...\n");
	fprintf(stderr,"Please help me to correct this and send a bug report\n");
	fprintf(stderr,"To send a bug report go to http://mpgtx.sourceforge.net\n");
	fprintf(stderr,"and click the submit new bug link (top right)\n");
	fprintf(stderr,"you can send it to <laureck@users.sourceforge.net> either\n");

	if (!bugreport) {
		bugreport=stderr;
		fprintf(stderr,"Please Include the following lines and the program output in the bug report\n");
		fprintf(stderr,  "---------------------------------------------------------------------------\n");
	}else{
		fprintf(stderr,"Please include the file \"bug.report\" and the program output in the bug report\n");
	}

	//start of bug report
	//version
	fprintf(bugreport,"%s version %s\n",progname,MPGTX_VERSION);

	// arguments to the program
	fprintf(bugreport,"args : ");
	for (int i=0; i < myargc; i++){
		fprintf (bugreport,"%s ",myargv[i]);
	}
	fprintf(bugreport,"\n");

	//what killed me
	switch(signum){
		case SIGSEGV: fprintf(bugreport,"SIGSEGV");break;
		case SIGBUS: fprintf(bugreport,"SIGBUS");break;
		case SIGFPE: fprintf(bugreport,"SIGFPE");break;
	}
	fprintf(bugreport," received\n");

	//print the calling stack
	fprintf(bugreport,"stack : ");
	for (int j=0; j <mpgtx_stack_count; j++){
		if (mpgtx_stack[(mpgtx_stack_current+j)%mpgtx_stack_count]!=0)
			fprintf(bugreport,"[%s] ",mpgtx_stack[(mpgtx_stack_current+j)%mpgtx_stack_count]);
	}
	fprintf(bugreport,"\nstack current: %d\n",mpgtx_stack_current);



	fclose(bugreport);
	exit(1);
}

/*!
 * Callback for SIGINT.
 *
 * @param signum unused
 */
void CatchBreak(int signum) {
	fprintf(stderr,"\nHave a Nice Day\n");
	exit(1);
}
#endif

#ifdef ENABLE_OPTIMIZATION
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>

struct timeval tv;
struct timezone tz;
double MainClockStart;

double Clock_Now(){
	double time_now;
	gettimeofday(&tv,&tz);
	time_now=tv.tv_sec + 0.000001 * tv.tv_usec;

	gettimeofday(&tv,&tz);
	functions_cummulated_time[SELF]+=2*((tv.tv_sec + 0.000001 * tv.tv_usec)-time_now);
	return tv.tv_sec + 0.000001 * tv.tv_usec;
}

void   AddTime(double timestart, int function){
	functions_cummulated_time[function]+= Clock_Now()-timestart;
}

double functions_cummulated_time[N_FUNCTIONS];
void init_cummulated_time(){
	MainClockStart=Clock_Now();
	atexit(PrintTime);
	for (int i=0; i <N_FUNCTIONS; i++){
		functions_cummulated_time[i]=0.0;
	}
}

void PrintTime(){
	AddTime(MainClockStart,MAIN);
	printf("-------------------------\n");
	printf("Time passed in main %.4f s\n",functions_cummulated_time[MAIN]);
	printf("\t(f)printf : %.4f s [%.2f%%]\n",
		functions_cummulated_time[PRINTF],
		functions_cummulated_time[PRINTF]*100.0/functions_cummulated_time[MAIN]);
	printf("\t  GetByte : %.4f s [%.2f%%]\n",
		functions_cummulated_time[GETBYTE],
		functions_cummulated_time[GETBYTE]*100.0/functions_cummulated_time[MAIN]);
	printf("\t     Copy : %.4f s [%.2f%%]\n",
		functions_cummulated_time[COPY],
		functions_cummulated_time[COPY]*100.0/functions_cummulated_time[MAIN]);
	printf("\tProfiling Time approx : %.4f [%.2f%%]\n",
		functions_cummulated_time[SELF],
		functions_cummulated_time[SELF]*100.0/functions_cummulated_time[MAIN]);
	
	
}

#endif



typedef enum argtype {file,option,range,none};
typedef enum programname {mpgsplit,mpgcat,mpgjoin,mpginfo,mpgdemux,other,mp3tag};



void print_help(programname invocation){
	BTRACK;
	switch(invocation)
	{
		case mpgsplit:
			printf("mpgsplit : split mpeg files into playable chunks\n");
			break;
		case mpgcat:
			printf("mpgcat   : cat mpeg files to standard output\n");
			break;
		case mpgjoin:
			printf("mpgjoin  : join compatible mpeg files into one\n");
			break;
		case mpgdemux:
			printf("mpgdemux : demultiplex elementary streams from a composite mpeg file\n");
			printf("Usage    : mpgdemux [options] composite_file \n");
			break;
		case mpginfo:
			printf("mpginfo  : print informations about mpeg files\n");
			printf("Usage    : mpginfo file [file...]\n");
			printf("Options  :\n");
			printf("  -N              Do not check timeline (save some time).\n");
			return;
			break;
		default :
			printf("%s : manipulate mpeg files\n",progname);
			break;
	}

	if (invocation != mpgdemux)
		printf("Usage    : %s [command] [options] [mpegfile [mpegfile | range]...\n",progname);
	printf("Commands :\n");

	if(invocation==other)
	{
		printf("  -i              print infos about following files.\n");
		printf("  -s              split following files according to the specified ranges.\n");
		printf("  -j              join  following files (ranges may be specified).\n");
		printf("  -d              demultiplex elementary streams from following file\n");
		printf("  -T              modify id3 tag.\n");
	}
	printf("  -h              print this help screen.\n");
	printf("  -v              print version informations.\n");
	if (invocation==other || invocation == mpgsplit)
		printf("  -#              where # is a number, split the following file in #.\n");
	if (invocation != mpgcat){
		printf("Options  :\n");
		printf("  -N              Do not print out excessive information while processing\n");
		printf("                  If you use MacOS Classic, this is RECOMMENDED\n");
		printf("                  Otherwise mpgtx will be dead slow!\n");
		printf("  -f              force overwriting of files, don't ask for confirmation\n");
		printf("  -P              keep headers of mpegs which sometimes is usefull\n");
		printf("  -X              Try to search for a valid PACK header in the whole file.\n");
		printf("                  Additionally option -N suppress output during search.\n");
		printf("                  This may result in an endless loop if not successfull!\n");
		printf("  -An             While joining or splitting, aspect ratio will be forced to:\n");
		printf("                  n=1 -> 1:1, n=2 -> 4:3, n=3 -> 16:9, n=4 -> 2.21:1 \n");
		printf("                  All Numbers from 0 - 16 will be accepted but the above are valid!\n"); 
		if (invocation != mpgjoin)
			printf("  -b NAME         set the basename for the output files\n");
		if (invocation != mpgsplit && invocation != mpgdemux){
			printf("  -o FILE         set the output file name (join implied)\n");
			printf("                  if FILE is - , standard output will be used\n");
			printf("  --force         force joining of incompatible files\n");
		}
		printf("  --no-parachute  don't try to catch SIGSEGV (usefull for debugging)\n");
	}
	if (invocation==mpgdemux) return;
	printf("Ranges   :\n");
	printf("  Ranges must follow an mpeg file\n");
	printf("  [a-b]           from 'a' inclusive to 'b' inclusive. If you want half opened\n");
	printf("                  ranges, you may want to use ]a-b], [a-b[ or ]a-b[ instead\n");
	printf("  [num/total]     the 'num' part if the mpeg file was split in 'total'.\n");
	printf("                  [1/4] would result in the first quarter of the mpeg file.\n");
	if (invocation !=mpgjoin){
		printf("  {a-b-...}       where 'a', 'b', ... are in ascending order. Split the file\n");
		printf("                  at given values. {700M} is therefore equivalent to ranges\n");
		printf("                  [-700M] ]700M-]\n");
	}
	printf("Values   :\n");
	printf("  Values can be time or offsets in the mpeg file\n");
	printf("  Time Format     HH:MM:SS where the HH: part can be omited\n");
	printf("  Offset Format   a number optionally followed by:\n");
	printf("                    M : offset is in Megabytes\n");
	printf("                    k : offset is in Kilobytes\n");
	printf("  An empty value means the corresponding file boundary:\n");
	printf("                  [-10M]  the first 10 Megabytes of file\n");
	printf("                  [500M-] from 500 Megabytes to the end of file\n");
	return;
}

// added 22 March 2001 to get rid of unistd (portability)
int mpgtx_access(char* filename){
	BTRACK;
	// returns 0 if file exist (readable)
	// returns 1 if not.
	FILE* test_file = fopen(filename,"r+");
	if (test_file == NULL) {
		return 1;
	}
	else {
		fclose(test_file);
		return 0;
	}
}



int main (int argc,char** argv){
#ifndef NOSIGNAL_H
	signal(SIGBUS,CatchBug);
	signal(SIGSEGV,CatchBug);
	signal(SIGFPE,CatchBug);
	signal(SIGINT,CatchBreak);
	for (int k=0; k < mpgtx_stack_count; k++) mpgtx_stack[k]=0;
	BTRACK;
	myargv=argv;
	myargc=argc;
#endif

#ifdef ENABLE_OPTIMIZATION
	init_cummulated_time();
#endif

	mpegOutFactory TheFac;
	chunkTab Tab(20);
	//char* current_filename=0;
	mpegOut* current_out;
	char* number;
	char* mybasename=0;
	char* myoutfile=0;
	chunk** ChunkTab;
	int ChunkCount;
	int nparts;
	char answer;
	bool want_info=false;
	bool basename_specified=false;
	bool joined=false;
	bool inparts=false;
	bool opresent=false;
	bool confirm_files=true;
	bool Id3Tag=false;
	bool force_option=false;
	bool catch_sigsegv=true;
	argtype lastarg=none;
	programname invocation;
	bool demux=false;
	int tmp_seq;



	////////////////////////////////////////
	//    Parse the program name          //
	////////////////////////////////////////
	ATRACK("parse progname");
	int i;
	int length=strlen(argv[0]);
	int start=0;

	for ( i = length-1; i >= 0; i--)
	{
		if((argv[0][i] == '/') || (argv[0][i] == '\\'))
		{
			start = i + 1;
			break;
		}
	}

	progname=new char[length-start+1];
	strcpy(progname,&argv[0][start]);
	if (!strcmp(progname,"mpgsplit")){
		invocation=mpgsplit;
		inparts=true;
	} else {
		if (!strcmp(progname,"mpgcat"))
		{
			invocation=mpgcat;
			joined=true;
			opresent=true;
			myoutfile=new char[2];
			myoutfile[0]='-';
			myoutfile[1]=0;
		}
		else {
			if (!strcmp(progname,"mpgjoin")){
				invocation=mpgjoin;
				joined=true;
			}
			else{
				if (!strcmp(progname,"mpginfo")){
					invocation=mpginfo;
					want_info=true;
				}
				else {
					if (!strcmp(progname,"mpgdemux")){
						invocation=mpgdemux;
						demux=true;
					}
					else{
						if (!strcmp(progname,"tagmp3")){
							return ParseID3Command(argc,argv,1);
						}
						else{

							invocation=other;
						}

					}
				}
			}
		}
	}


	// Warn user.
	/*fprintf(stderr,"%s version %s\n"
	  "THIS IS *BETA* SOFTWARE I really need your help to correct all remaining bugs.\n"
	  "If you find any bug in this program you are encouraged to post a bug report on\n"
	  "mpgtx homepage <http://mpgtx.sourceforge.net>.Thanks in advance for your help.\n\n"
	  ,progname,MPGTX_VERSION);

	 */
	///////////////////////////////////////
	//   Parse remaining args           //
	/////////////////////////////////////
	ATRACK("Parse Args");
	for ( i=1; i<argc; i++){
		switch(argv[i][0])
		{
			case '-':
				// this is an option
				if (lastarg==file && (!want_info)){
					// an option following a filename
					// appy range [0-100%]
					Tab.ParseRange("]0-]");
				}
				lastarg=option;
				if((argv[i][1] > '0')&&(argv[i][1]<='9')) {
					number=&argv[i][1];
					sscanf(number,"%d",&nparts);
					if(i+1>=argc){
						fprintf(stderr,"%s option used without a filename\n",argv[i]);
						return 1;
					}
					if(!Tab.AddFile(argv[++i])){
						fprintf(stderr,"%s is not a valid mpeg file\n",argv[i-1]);
						if(!want_info) return 1;
					}
					Tab.Nchunks(nparts);
					inparts=true;
				}
				else {
					switch (argv[i][1]){
						case 'd' :
							demux=true;
							break;
						case 'X' :
							desperate_mode =true;
							break;
						case 'P' :
							preserve_header = true;
							break;
						case 'N':
							print_progress = false;
							break;
						case 'A':
							aspect_correction = true;
							tmp_seq = -1;
							sscanf(&(argv[i][2]),"%d",&tmp_seq);
							if ((tmp_seq < 0 ) || (tmp_seq > 15))
							{
								fprintf(stderr,"invalid Value for aspect correction %d, exit!\n",tmp_seq);
								exit(1);
							}
							forced_sequence_header = tmp_seq << 4;
							break;

						case 'h' : print_help(invocation);
									return 0;
									break;
						case 'i' :
									want_info=true;
									break;
						case 'f' :
									confirm_files=false;
									break;
						case 's' :
									inparts=true;
									break;

						case 'j' :
									joined=true;
									if(!myoutfile) myoutfile="output.mpg";
									break;
						case 'T' :
									Id3Tag=true;
									return ParseID3Command(argc,argv,i+1);
									break;
						case 'b' :
									inparts=true;
									if (joined) {
										fprintf(stderr,"-o and -b options are mutually exclusive\n");
										return 1;
									} else { if (basename_specified) {
										fprintf(stderr,"only one basename is allowed\n");
										return 1;
									}
									basename_specified=true;
									if(i+1>=argc){
										fprintf(stderr,"-b option used without basename\n");
										return 1;
									}
									else {
										//TODO copy basename
										i++;
										// fprintf(stderr,"option -b read, basename : %s\n",argv[i]);
										mybasename=new char [strlen(argv[i])+1];
										strcpy(mybasename,argv[i]);
									}
									}
									break;
						case 'o' :
									if (basename_specified) {
										fprintf(stderr,"-b and -o options are mutually exclusive\n");
										return 1;
									}
									else
									{
										if (opresent){
											fprintf(stderr,"only one -o option allowed\n");
											return 1;
										}
										opresent=true;
										if(i+1>=argc){
											fprintf(stderr,"-o option used without outfile name\n");
											return 1;
										}
										else {
											i++;
											// fprintf(stderr,"option -o read, will join all in file : %s\n",argv[i]);
											myoutfile=new char [strlen(argv[i])+1];
											strcpy(myoutfile,argv[i]);
										}
									}
									break;
						case 'v':
									printf("%s Version %s\n",progname,MPGTX_VERSION);
									printf("Copyleft 2001 Laurent Alacoque <laureck@users.sourceforge.net>\n");
									printf("Partial work 2002 by Philipp Biermann <mpegcut@biermann.org>\n");
									printf("updates, bugs, patch, money :    http://mpgtx.sourceforge.net\n");
									return 0;
									break;
						case '-':
									// this is a long option (--xxxx)
									if (strcmp(argv[i],"--force")==0) force_option=true;
									if (strcmp(argv[i],"--no-parachute")==0) catch_sigsegv=false;
									break;
						default:
									fprintf(stderr,"unrecognized option %s\n",argv[i]);
									return 1;
									break;
					}
				}
				break;

			case ']':
			case '[':
				// this is a range
				lastarg=range;
				if(!Tab.ParseRange(argv[i])){
					return 1;
				}
				break;
			case '{':
				// comma separated list of boundaries
				lastarg=range;
				if(!Tab.ParseBoundaries(argv[i])){
					return 1;
				}
				break;
			default:
				// might be an input file, check!
				if (lastarg==file && !(want_info)){
					// two file arguments encountered, apply 100% range to the first
					//one
					Tab.ParseRange("]0-]");
				}
				lastarg=file;
				if(!Tab.AddFile(argv[i])) {
					fprintf(stderr,"%s is not a valid mpeg file\n",argv[i]);
					if(!want_info) return 1;
				}

		}


	}//for
	if (lastarg==file && (!want_info)){
		//range's missing
		Tab.ParseRange("]0-]");
	}

	///////////////////////////////////////////////////////////////////
	//                      Args are parsed
	///////////////////////////////////////////////////////////////////

#ifndef NOSIGNAL_H
	if (!catch_sigsegv){
		// if the --no-parachute was used, restore the default behaviour
		signal(SIGBUS,SIG_DFL);
		signal(SIGSEGV,SIG_DFL);
		signal(SIGFPE,SIG_DFL);
		signal(SIGINT,SIG_DFL);
	}
#endif





	ChunkTab = Tab.GetChunks(&ChunkCount);


#ifdef _DEBUG_
	Tab.PrintTab();
#endif
	ATRACK("handling info mode");
	/////////////////////////////////////////////////////////////////
	// Handle Info mode
	/////////////////////////////////////////////////////////////////

	if (want_info){
		Tab.PrintInfos();
#ifdef NEED_END_MESSAGE
		endMessage();
#endif
		return 0;
	}

	ChunkTab=Tab.GetChunks(&ChunkCount);
	// from here we need at least one chunk
	if (ChunkCount==0){
		fprintf(stderr,"nothing to do \n");
		return 0;
	}
	RTRACK;
	ATRACK("demux mode");
	/////////////////////////////////////////////////////////////////
	// Handle demux mode
	/////////////////////////////////////////////////////////////////
	if (demux){
		if (ChunkCount!=1){
			fprintf(stderr,"demux currently requires exactly one mpeg file\n");
			return 1;
		}
		if (!basename_specified){
			fprintf(stderr,"No base name specified, defaulting to basename : chunk\n");
			mybasename="chunk";
		}
		demuxer Dmux(ChunkTab[0]->mpegfile, mybasename,confirm_files);
		Dmux.Process();
		//check the errors!
#ifdef NEED_END_MESSAGE
		endMessage();
#endif
		return 0;
	}
	// from here we need at least one chunk
	if (ChunkCount==0){
		fprintf(stderr,"nothing to do \n");
		return 0;
	}

	// Tab.PrintTab();
	RTRACK;
	ATRACK("join mode");
	/////////////////////////////////////////////////////////////////
	// All files are joined
	/////////////////////////////////////////////////////////////////
	if (joined) {
		if (!opresent) {
			myoutfile = new char[500];
			if (ChunkTab[0]->mpegfile->has_video() == false)
				sprintf(myoutfile, "chunk.mp3");
			else
				sprintf(myoutfile, "chunk.mpg");
		}
		if (ChunkCount >1) {
			for ( i = 1; i < ChunkCount ; i++)
			{
				if(!ChunkTab[0]->mpegfile->Match(ChunkTab[i]->mpegfile))
				{
					if (force_option)
						fprintf(stderr, "Specified files don't seem to be compatible\n");
					else {
						fprintf(stderr, "Specified files are not compatible, if you still want to join them use --force switch\n");
						return 1;
					}
				}
				//okay they match
			}
		}
		if (!strcmp(myoutfile,"-")){
			//output to stdout
			current_out=TheFac.NewMpegFrom(ChunkTab[0]->mpegfile,stdout);
			if (!current_out){
				fprintf(stderr,"\nFatal : could not process file\n");
			}
		}
		else {
			//output to myoutfile
			// if (!force_action)
			if (confirm_files && !mpgtx_access(myoutfile))
			{
				fprintf(stderr,"file %s already exist. erase ? [n/y/a]:", myoutfile);
				fflush(stderr);
				answer=getchar();
				while (getchar() != '\n'); //flush the leading \n
				if (answer!='y' && answer !='Y' && answer != 'a' && answer != 'A') {
					fprintf(stderr,"Aborted\n");
					return 0;
				}
				if (answer == 'a' || answer == 'A') confirm_files = false;
			}
			current_out = TheFac.NewMpegFrom(ChunkTab[0]->mpegfile, myoutfile);
			if (!current_out)
				fprintf(stderr,"\nFatal : could not process file %s\n",myoutfile);
		}
		if (!current_out){
			//something went wrong
			return 0;
		}

		for ( i=0;i<ChunkCount;i++)
		{
			fprintf(stderr,"Now processing %s %d/%d ...  ",
				ChunkTab[i]->mpegfile->FileName, i+1, ChunkCount);
			fflush(stderr);
			if (!current_out->WriteChunk(ChunkTab[i]->mpegfile, ChunkTab[i]->from,
						ChunkTab[i]->from_included, ChunkTab[i]->to, ChunkTab[i]->to_included))
				fprintf (stderr," failed, range results in an empty chunk\n");
			else
				fprintf(stderr,"\n");
		}
		current_out->Finish();
#ifdef NEED_END_MESSAGE
		endMessage();
#endif
		return 0;
	}

	if (inparts) {
		RTRACK;
		ATRACK("split mode");
		/////////////////////////////////////////////////////////////////
		// each chunk in one file
		/////////////////////////////////////////////////////////////////
		int myprec;
		char sChunkCount[50];
		//write ChunkCount as a string
		sprintf(sChunkCount,"%d", ChunkCount + 1);
		//now we now how many digits we need -> in myprec
		myprec = strlen(sChunkCount);

		if (!basename_specified) {
			if (!opresent)
				//neither -o nor -b, use default basename
				mybasename="chunk";
			else
			{
				if (ChunkCount >1){
					fprintf(stderr,"-o option invalid for %d output files\n",ChunkCount);
					return 1;
				}
				mybasename = new char[strlen(myoutfile)+1];
				strcpy(mybasename, myoutfile);
			}
		}

		myoutfile = new char[500];
		for (i = 0;i < ChunkCount; i++)
		{
			//compute the name
			if (ChunkTab[i]->mpegfile->has_video()==false)
			{
				if (opresent)
					sprintf(myoutfile,"%s",mybasename);
				else
				{
					if (ChunkCount==1)
						sprintf(myoutfile,"%s.mp3",mybasename);
					else 
						sprintf(myoutfile,"%s-%0*d.mp3",mybasename,myprec,i+1);
				}
			}
			else
			{
				if (opresent)
					sprintf(myoutfile,"%s",mybasename);
				else
				{
					if (ChunkCount==1)
						sprintf(myoutfile,"%s.mpg",mybasename);
					else 
						sprintf(myoutfile,"%s-%0*d.mpg",mybasename,myprec,i+1);
				}
			}	
			if (confirm_files && !mpgtx_access(myoutfile))
			{
				fprintf(stderr,"file %s already exist. erase ?"
						" [n/y/a]:",myoutfile);
				fflush(stderr);
				answer=getchar();
				while (getchar() != '\n'); //flush the leading \n
				if (answer != 'y' && answer != 'Y' && answer != 'a' && answer != 'A') {
					fprintf(stderr,"Aborted\n");
					return 0;
				}
				if (answer == 'a' || answer == 'A') confirm_files = false;

			}

			current_out = TheFac.NewMpegFrom(ChunkTab[0]->mpegfile, myoutfile);
			if (!current_out) {
				fprintf(stderr,"\nFatal : could not process %s\n", myoutfile);
				return 1;
			}
			fprintf(stderr,"Now processing %s [%d/%d] ...  ",
				ChunkTab[i]->mpegfile->FileName, i+1, ChunkCount);
			fflush(stderr);
			if (!current_out->WriteChunk(ChunkTab[i]->mpegfile, ChunkTab[i]->from,
						ChunkTab[i]->from_included, ChunkTab[i]->to, ChunkTab[i]->to_included))
				fprintf (stderr,"  failed, range results in an empty chunk\n");
			else
				fprintf(stderr,"\n");
			current_out->Finish();
		} // for
		delete [] myoutfile;
#ifdef NEED_END_MESSAGE
		endMessage();
#endif
		return 0;
	}

	//no action were taken
	fprintf(stdout, "You must choose one options between -i -s -j\n");
	fprintf(stdout, "Type %s -h for help\n", progname);
	return 0;
}

#ifdef NEED_END_MESSAGE
void endMessage(void) {
		fprintf(stderr,"-------Done--------\n");
}
#endif