Exemple #1
0
static int
c_main(int argc, char *argv[])
{
    lame_t  gf;
    int     ret;

#if macintosh
    argc = ccommand(&argv);
#endif
#ifdef __EMX__
    /* This gives wildcard expansion on Non-POSIX shells with OS/2 */
    _wildcard(&argc, &argv);
#endif
#if defined( _WIN32 ) && !defined(__MINGW32__)
    set_process_affinity();
#endif

    frontend_open_console();    
    gf = lame_init(); /* initialize libmp3lame */
    if (NULL == gf) {
        error_printf("fatal error during initialization\n");
        ret = 1;
    }
    else {
        ret = lame_main(gf, argc, argv);
        lame_close(gf);
    }
    frontend_close_console();
    return ret;
}
Exemple #2
0
extern int main (int __unused__ argc, char **argv)
{
	cookedArgs *args;
#ifdef VMS
	extern int getredirection (int *ac, char ***av);

	/* do wildcard expansion and I/O redirection */
	getredirection (&argc, &argv);
#endif

#ifdef AMIGA
	/* This program doesn't work when started from the Workbench */
	if (argc == 0)
		exit (1);
#endif

#ifdef __EMX__
	_wildcard (&argc, &argv);  /* expand wildcards in argument list */
#endif

#if defined (macintosh) && BUILD_MPW_TOOL == 0
	argc = ccommand (&argv);
#endif

	setCurrentDirectory ();
	setExecutableName (*argv++);
	sanitizeEnviron ();
	checkRegex ();

	args = cArgNewFromArgv (argv);
	previewFirstOption (args);
	testEtagsInvocation ();
	initializeParsing ();
	initOptions ();
	readOptionConfiguration ();
	verbose ("Reading initial options from command line\n");
	parseOptions (args);
	checkOptions ();
	unifyLanguageMaps ();
	makeTags (args);

	/*  Clean up.
	 */
	cArgDelete (args);
	freeKeywordTable ();
	freeRoutineResources ();
	freeSourceFileResources ();
	freeTagFileResources ();
	freeOptionResources ();
	freeParserResources ();
	freeRegexResources ();
	freeXcmdResources ();

	if (Option.guessParser)
		return (Option.guessParser == TRUE)? 0: 1;

	exit (0);
	return 0;
}
Exemple #3
0
void
wildcard (int *pargc, char ***pargv)
{
#ifndef UNIX
  _wildcard(pargc, pargv);
  _internal_argc = *pargc;
  _internal_argv = *pargv;
#endif
}
Exemple #4
0
int
main(int argc, char **argv)
{
	int c;

	__progname = argv[0];
	_wildcard(&argc, &argv);

	while ((c = getopt(argc, argv, "knpswM:")) != -1) {
		switch (c) {
		case 'k':
			f_ignerr = 1;
			break;
		case 'n':
			f_nowhatis = 1;
			break;
		case 'p':
			f_noaction = 1;
			break;
		case 's':
			f_noprint = 1;
			break;
		case 'w':
			f_noformat = 1;
			break;
		case 'M':
			mp = optarg;
			break;

		case '?':
		default:
			usage();
		}
	}

	argc -= optind;
	argv += optind;

	if (f_noprint && f_noaction)
		f_noprint = 0;

	if (argc > 1)
		usage();
	if (argc == 1)
		sp = *argv;

	if (f_noformat == 0 || f_nowhatis == 0)
		catman(mp, sp);
	if (f_nowhatis == 0 && dowhatis)
		makewhatis(mp);

	exit(0);
}
Exemple #5
0
int main P2C(int, ac,  string *, av)
{
#ifdef __EMX__
  _wildcard (&ac, &av);
  _response (&ac, &av);
#endif
  extern void mainbody P1H(void);

  argc = ac;
  argv = av;
  mainbody ();
  return EXIT_SUCCESS;
}
Exemple #6
0
int main(int argc, char **argv)
{
	MCIPLAYARGS mcip;

	_wildcard(&argc, &argv);

	mcip.ARGC = argc;
	mcip.ARGV = argv;

	mciplay(&mcip);

	return(0);
} /* main */
Exemple #7
0
static int process_arglist(int argc, char **argv)
{
    int option;
    int count = 0;

    fpin = stdin;
    fpo  = stdout;
    dbgout = stderr;

#ifdef __EMX__
    _response (&argc, &argv);	/* expand response files (@filename) */
    _wildcard (&argc, &argv);	/* expand wildcards (*.*) */
#endif

    /* default: no token length checking */
    max_token_len = 0;

    while (1)
    {
	int option_index = 0;
	int this_option_optind = optind ? optind : 1;
	const char *name;

	option = getopt_long_chk(argc, argv, OPTIONS,
			     longopts_bogoutil, &option_index);

	if (option == -1)
 	    break;

	name = (option_index == 0) ? argv[this_option_optind] : longopts_bogoutil[option_index].name;
	count += process_arg(option, name, optarg, PR_NONE, PASS_1_CLI);
    }

    if (max_token_len != 0 && max_multi_token_len == 0) {
	/* token length checking ... */
	if (multi_token_count == 1)
	    max_multi_token_len = max_token_len + MAX_PREFIX_LEN;
	else
	    max_multi_token_len = max_token_len = (max_token_len+1) * multi_token_count + MAX_PREFIX_LEN;
    }

    if (count != 1)
    {
	usage(stderr);
	fprintf(stderr, "%s: Exactly one of the file or directory commands must be present.\n", progname);
	exit(EX_ERROR);
    }

    return count;
}
static int process_arglist(int argc, char **argv)
{
    int  count = 1;

    bulk_mode = B_CMDLINE;

#ifdef __EMX__
    _response (&argc, &argv);	/* expand response files (@filename) */
    _wildcard (&argc, &argv);	/* expand wildcards (*.*) */
#endif

#define	OPTIONS	":-:c:Cd:DeEM:n:qr:s:tT:vVx:"

    while (1)
    {
	int option;
	int option_index = 0;
	const char *val;

	option = getopt_long_chk(argc, argv, OPTIONS,
			     longopts_bogotune, &option_index);

	if (option == -1)
 	    break;

	val = optarg;
	process_arg(option, NULL, val, PR_NONE, PASS_1_CLI);
    }

    if (ds_flag == DS_NONE)	/* default is "wordlist on disk" */
	ds_flag = DS_DSK;

    if (ds_flag == DS_ERR) {
	fprintf(stderr, "Only one '-d dir' or '-D' option is allowed.\n");
	exit(EX_ERROR);
    }

    if (bogolex_file == NULL &&
	(spam_files->count == 0 || ham_files->count == 0)) {
	fprintf(stderr,
		"Bogotune needs both non-spam and spam message sets for its parameter testing.\n");
	exit(EX_ERROR);
    }

    if (!suppress_config_file)
	process_config_files(false, longopts_bogotune);

    return count;
}
Exemple #9
0
int
main( int argc, char *argv[])
{
	extern int optind;
	int ch;

	__progname = argv[0];
	_wildcard(&argc, &argv);

	setlocale(LC_ALL, "");

	while ((ch = getopt(argc, argv, "benstuv")) != -1)
		switch (ch) {
		case 'b':
			bflag = nflag = 1;	/* -b implies -n */
			break;
		case 'e':
			eflag = vflag = 1;	/* -e implies -v */
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		case 't':
			tflag = vflag = 1;	/* -t implies -v */
			break;
		case 'u':
			setbuf(stdout, NULL);
			break;
		case 'v':
			vflag = 1;
			break;
		default:
			(void)fprintf(stderr,
			    "usage: cat [-benstuv] [-] [file ...]\n");
			exit(1);
		}
	argv += optind;

	if (bflag || eflag || nflag || sflag || tflag || vflag)
		cook_args(argv);
	else
		raw_args(argv);
	if (fclose(stdout))
		err(1, "stdout");
	exit(rval);
}
Exemple #10
0
main (int ac, string *av)
#endif
{
#  ifdef __EMX__
    _wildcard(&ac, &av);
    _response(&ac, &av);
#  endif

#  ifdef WIN32
#    ifdef _MSC_VER
    _set_invalid_parameter_handler(myInvalidParameterHandler);
#    endif
    av[0] = kpse_program_basename (av[0]);
    _setmaxstdio(2048);
/*
    We choose to crash for fatal errors:

    SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
*/
    setmode(fileno(stdin), _O_BINARY);
#  endif

    lua_initialize(ac, av);

#  ifdef WIN32
    if (ac > 1) {
        char *pp;
        if ((strlen(av[ac-1]) > 2) && isalpha(av[ac-1][0]) && (av[ac-1][1] == ':') && (av[ac-1][2] == '\\')) {
            for (pp=av[ac-1]+2; *pp; pp++) {
            if (IS_KANJI(pp)) {
                pp++;
                continue;
            }
            if (*pp == '\\')
                *pp = '/';
            }
        }
    }
#  endif

    /*
        Call the real main program.
    */
    main_body();

    return EXIT_SUCCESS;
}
Exemple #11
0
/* The entry point for all the programs except TeX and Metafont, which
   have more to do.  We just have to set up the command line.  web2c
   transforms Pascal's main block into a procedure `main_body'.  */
int
main (int  ac,  string* av)
{
#ifdef __EMX__
  _wildcard (&ac, &av);
  _response (&ac, &av);
#endif

#ifdef WIN32
  _setmaxstdio(2048);
#endif

  argc = ac;
  argv = av;
  mainbody ();
  return EXIT_SUCCESS;
}
Exemple #12
0
int main(int argc, char *argv[])
{
    char path[256];

    _wildcard(&argc, &argv);

    /* Search in current dir and then in directories on PATH */
    _searchenv(EXE_NAME, "PATH", path);
    if(path[0] == 0) {
        /* Search directories in HFSUTILS variable */
        _searchenv(EXE_NAME, "HFSUTILS", path);
    }

    if(path[0] == 0) {
        fprintf(stderr,
                "Cannot find the hfsutil executable.\n"
                "Please set the HFSUTIL variable.\n");
        return -1;
    }

    return spawnv(P_WAIT, path, argv);
}
Exemple #13
0
static void process_arglist(int argc, char **argv)
{
    int option;

    fpin = stdin;
    dbgout = stderr;

#ifdef __EMX__
    _response (&argc, &argv);	/* expand response files (@filename) */
    _wildcard (&argc, &argv);	/* expand wildcards (*.*) */
#endif

    while (1)
    {
	int option_index = 0;
	int this_option_optind = optind ? optind : 1;
	const char *name;

#ifdef __EMX__
	if (optind == 1) optind = 0;
#endif

	option = getopt_long_chk(argc, argv, OPTIONS,
			     longopts_bogolexer, &option_index);

	if (option == -1)
	    break;

	name = (option_index == 0) ? argv[this_option_optind] : longopts_bogolexer[option_index].name;
	process_arg(option, name, optarg, PR_COMMAND, PASS_1_CLI);
    }

    if (optind < argc) {
	fprintf(stderr, "Extra arguments given, first: %s. Aborting.\n",
		argv[optind]);
	exit(EX_ERROR);
    }
}
Exemple #14
0
int main(int argc, char *argv[])
{
	int r = EXIT_OK;
	int i, ii;
	int m;
	time_t t_total;

#if defined(__EMX__)
	_response(&argc,&argv);
	_wildcard(&argc,&argv);
#endif

	if (argv[0])
		argv0 = argv[0];
	align_mem();
	(void) my_clock();

	printf("\nLZO real-time data compression library (v%s, %s).\n",
	        LZO_VERSION_STRING, LZO_VERSION_DATE);
	printf("Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer\n\n");

	if (lzo_init() != LZO_E_OK)
	{
		printf("lzo_init() failed !!!\n");
		exit(EXIT_LZO_INIT);
	}

	if (argc < 2)
		usage(argv0,-1,0);
	i = get_options(argc,argv);

	if (methods_n == 0)
		add_method(default_method);
	if (methods_n > 1 && opt_read_from_stdin)
	{
		printf("%s: cannot use multiple methods and '-@'\n", argv0);
		exit(EXIT_USAGE);
	}

	if (opt_block_size < 16)
		opt_block_size = 16;
	if (opt_block_size > MAX_BLOCK_SIZE)
		opt_block_size = MAX_BLOCK_SIZE;

	dict_len = 0;
#ifndef USE_DICT
	opt_dict = 0;
#else
	if (opt_dict)
	{
		opt_optimize_compressed_data = 0;
		if (opt_dictionary_file)
		{
			read_dict(opt_dictionary_file);
			if (opt_max_dict_len > 0 && dict_len > (lzo_uint) opt_max_dict_len)
				dict_len = opt_max_dict_len;
			if (dict_len > 0)
				printf("Using dictionary '%s', %ld bytes, ID 0x%08lx.\n",
				        opt_dictionary_file,
			            (long) dict_len, (long) dict_adler32);
		}
		if (dict_len <= 0)
		{
			init_default_dict();
			if (opt_max_dict_len > 0 && dict_len > (lzo_uint) opt_max_dict_len)
				dict_len = opt_max_dict_len;
			printf("Using default dictionary, %ld bytes, ID 0x%08lx.\n",
			        (long) dict_len, (long) dict_adler32);
		}
		if (opt_max_dict_len == -1)
			printf("Dictionary size will be adjusted to file size.\n");
		else if (opt_max_dict_len <= 0)
			printf("Dictionary size will be adjusted to file size.\n");
	}
#endif

	t_total = time(NULL);
	(void) my_clock();
	ii = i;
	for (m = 0; m < methods_n && r == EXIT_OK; m++)
	{
		int method = methods[m];

		i = ii;
		if (i >= argc && opt_calgary_corpus_path == NULL && !opt_read_from_stdin)
			usage(argv0,-1,0);
		if (m == 0 && opt_verbose >= 1)
			printf("%lu block-size\n\n", (long) opt_block_size);

		if (!info(method,NULL))
			info(method,stdout);

#ifdef USE_CORPUS
		if (opt_calgary_corpus_path != NULL)
			r = do_corpus(calgary_corpus,method,opt_calgary_corpus_path,
			              opt_c_loops,opt_d_loops);
		else
#endif
		{
			for ( ; i < argc && r == EXIT_OK; i++)
			{
				r = do_file(method,argv[i],opt_c_loops,opt_d_loops,NULL,NULL);
				if (r == EXIT_FILE)		/* ignore file errors */
					r = EXIT_OK;
			}
			if (opt_read_from_stdin)
			{
				char buf[512], *p;

				while (r == EXIT_OK && fgets(buf,sizeof(buf)-1,stdin) != NULL)
				{
					buf[sizeof(buf)-1] = 0;
					p = buf + strlen(buf);
					while (p > buf && is_space(p[-1]))
							*--p = 0;
					p = buf;
					while (*p && is_space(*p))
						p++;
					if (*p)
						r = do_file(method,p,opt_c_loops,opt_d_loops,NULL,NULL);
					if (r == EXIT_FILE)		/* ignore file errors */
						r = EXIT_OK;
				}
				opt_read_from_stdin = 0;
			}
		}
	}
	t_total = time(NULL) - t_total;

	if (opt_totals)
		print_totals();
	if (opt_execution_time || (methods_n > 1 && opt_verbose >= 1))
		printf("\n%s: execution time: %lu seconds\n", argv0, (long) t_total);
	if (r != EXIT_OK)
		printf("\n%s: exit code: %d\n", argv0, r);

	return r;
}
Exemple #15
0
int
main(int argc, char **argv)
{
    int     ret;
    lame_global_flags *gf;
    char    outPath[PATH_MAX + 1];
    char    nogapdir[PATH_MAX + 1];
    char    inPath[PATH_MAX + 1];

    /* support for "nogap" encoding of up to 200 .wav files */
#define MAX_NOGAP 200
    int    nogapout = 0;
    int     max_nogap = MAX_NOGAP;
    char   *nogap_inPath[MAX_NOGAP];

    int     i;
    FILE   *outf;

#if macintosh
    argc = ccommand(&argv);
#endif

#if defined(_WIN32)
   /* set affinity back to all CPUs.  Fix for EAC/lame on SMP systems from
     "Todd Richmond" <*****@*****.**> */
    typedef BOOL (WINAPI *SPAMFunc)(HANDLE, DWORD);
    SPAMFunc func;
    SYSTEM_INFO si;

    if ((func = (SPAMFunc)GetProcAddress(GetModuleHandle("KERNEL32.DLL"),
        "SetProcessAffinityMask")) != NULL) {
        GetSystemInfo(&si);
        func(GetCurrentProcess(), si.dwActiveProcessorMask);
    }
#endif


#ifdef __EMX__
    /* This gives wildcard expansion on Non-POSIX shells with OS/2 */
    _wildcard(&argc, &argv);
#endif

    for (i = 0; i < max_nogap; ++i) {
        nogap_inPath[i] = malloc(PATH_MAX + 1);
    }

    memset(inPath, 0, sizeof(inPath));
    
    /* initialize libmp3lame */
    input_format = sf_unknown;
    if (NULL == (gf = lame_init())) {
        fprintf(stderr, "fatal error during initialization\n");
        return 1;
    }
    if (argc <= 1) {
        usage(stderr, argv[0]); /* no command-line args, print usage, exit  */
        return 1;
    }

    /* parse the command line arguments, setting various flags in the
     * struct 'gf'.  If you want to parse your own arguments,
     * or call libmp3lame from a program which uses a GUI to set arguments,
     * skip this call and set the values of interest in the gf struct.
     * (see the file API and lame.h for documentation about these parameters)
     */
    parse_args_from_string(gf, getenv("LAMEOPT"), inPath, outPath);
    ret = parse_args(gf, argc, argv, inPath, outPath, nogap_inPath, &max_nogap);
    if (ret < 0)
        return ret == -2 ? 0 : 1;

    if (update_interval < 0.)
        update_interval = 2.;

    if (outPath[0] != '\0' && max_nogap>0) {
        strncpy(nogapdir, outPath, PATH_MAX + 1);  
        nogapout = 1;
    }
    
    /* initialize input file.  This also sets samplerate and as much
       other data on the input file as available in the headers */
    if (max_nogap > 0) {
        /* for nogap encoding of multiple input files, it is not possible to
         * specify the output file name, only an optional output directory. */
        parse_nogap_filenames(nogapout,nogap_inPath[0],outPath,nogapdir);
        outf = init_files(gf, nogap_inPath[0], outPath);
    }
    else {
        outf = init_files(gf, inPath, outPath);
    }
    if (outf == NULL) {
        return -1;
    }

    /* Now that all the options are set, lame needs to analyze them and
     * set some more internal options and check for problems
     */
    i = lame_init_params(gf);
    if (i < 0) {
        if (i == -1) {
            display_bitrates(stderr);
        }
        fprintf(stderr, "fatal error during initialization\n");
        return i;
    }

    if (silent > 0 
#ifndef RH_HIST   
    || lame_get_VBR(gf) == vbr_off
#endif
    ) {
        brhist = 0;     /* turn off VBR histogram */
    }


    if (lame_get_decode_only(gf)) {
        /* decode an mp3 file to a .wav */
        if (mp3_delay_set)
            lame_decoder(gf, outf, mp3_delay, inPath, outPath);
        else
            lame_decoder(gf, outf, 0, inPath, outPath);

    }
    else {
        if (max_nogap > 0) {
            /*
             * encode multiple input files using nogap option
             */
            for (i = 0; i < max_nogap; ++i) {
                int     use_flush_nogap = (i != (max_nogap - 1));
                if (i > 0) {
                    parse_nogap_filenames(nogapout,nogap_inPath[i],outPath,nogapdir);
                    /* note: if init_files changes anything, like
                       samplerate, num_channels, etc, we are screwed */
                    outf = init_files(gf, nogap_inPath[i], outPath);
                }
                brhist_init_package(gf);
                lame_set_nogap_total(gf, max_nogap);
                lame_set_nogap_currentindex(gf, i);
                ret =
                    lame_encoder(gf, outf, use_flush_nogap, nogap_inPath[i],
                                 outPath);	
                
                if (silent<=0) print_lame_tag_leading_info(gf);
                lame_mp3_tags_fid(gf, outf); /* add VBR tags to mp3 file */
		
                if (silent<=0) print_trailing_info(gf);
                
                fclose(outf); /* close the output file */
                close_infile(); /* close the input file */

                /* reinitialize bitstream for next encoding.  this is normally done
                 * by lame_init_params(), but we cannot call that routine twice */
                if (use_flush_nogap) 
                    lame_init_bitstream(gf);
            }
            lame_close(gf);

        }
        else {
            /*
             * encode a single input file
             */
            brhist_init_package(gf);
            ret = lame_encoder(gf, outf, 0, inPath, outPath);
            
            if (silent<=0) print_lame_tag_leading_info(gf);
            lame_mp3_tags_fid(gf, outf); /* add VBR tags to mp3 file */
	    
            if (silent<=0) print_trailing_info(gf);
            
            fclose(outf); /* close the output file */
            close_infile(); /* close the input file */
            lame_close(gf);
        }
    }
    return ret;
}
Exemple #16
0
int main(int argc, char *argv[])
{
	int r;
	int lazy;
	const int max_try_lazy = 5;
	const lzo_uint big = 65536L;	/* can result in very slow compression */
	const lzo_uint32 flags = 0x1;

	lzo_byte *in;
	lzo_uint in_len;

	lzo_byte *out;
	lzo_uint out_len = 0;

	lzo_byte *wrkmem;
	lzo_uint wrk_len;

	lzo_uint best_len;
	int best_compress = -1;
	int best_lazy = -1;

	lzo_uint orig_len;
	lzo_uint32 uncompressed_checksum;
	lzo_uint32 compressed_checksum;

	FILE *f;
	const char *progname = NULL;
	const char *in_name = NULL;
	const char *out_name = NULL;
	long l;


#if defined(__EMX__)
	_response(&argc,&argv);
	_wildcard(&argc,&argv);
#endif

	printf("\nLZO real-time data compression library (v%s, %s).\n",
	        lzo_version_string(), lzo_version_date());
	printf("Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer\n\n");

	progname = argv[0];
	if (argc < 2 || argc > 3)
	{
		printf("usage: %s file [output-file]\n", progname);
		exit(1);
	}
 	in_name = argv[1];
 	out_name = (argc > 2) ? argv[2] : NULL;

/*
 * Step 1: initialize the LZO library
 */
	if (lzo_init() != LZO_E_OK)
	{
		printf("lzo_init() failed !!!\n");
		exit(1);
	}

/*
 * Step 2: allocate the work-memory
 */
 	wrk_len = 1;
#ifdef USE_LZO1X
 	if (wrk_len < LZO1X_999_MEM_COMPRESS)
	 	wrk_len = LZO1X_999_MEM_COMPRESS;
#endif
#ifdef USE_LZO1Y
 	if (wrk_len < LZO1Y_999_MEM_COMPRESS)
	 	wrk_len = LZO1Y_999_MEM_COMPRESS;
#endif
	wrkmem = (lzo_bytep) lzo_malloc(wrk_len);
	if (wrkmem == NULL)
	{
		printf("%s: out of memory\n", progname);
		exit(1);
	}

/*
 * Step 3: open the input file
 */
 	f = fopen(in_name,"rb");
	if (f == NULL)
	{
		printf("%s: cannot open file %s\n", progname, in_name);
		exit(1);
	}
	fseek(f,0,SEEK_END);
	l = ftell(f);
	fseek(f,0,SEEK_SET);
	if (l <= 0)
	{
		printf("%s: %s: empty file\n", progname, in_name);
		fclose(f);
		exit(1);
	}
	in_len = (lzo_uint) l;
	best_len = in_len;

/*
 * Step 4: allocate compression buffers and read the file
 */
	in = (lzo_bytep) lzo_malloc(in_len);
	out = (lzo_bytep) lzo_malloc(in_len + in_len / 64 + 16 + 3);
	if (in == NULL || out == NULL)
	{
		printf("%s: out of memory\n", progname);
		exit(1);
	}
	in_len = lzo_fread(f,in,in_len);
	printf("%s: loaded file %s: %ld bytes\n", progname, in_name, (long) in_len);
	fclose(f);

/*
 * Step 5: compute a checksum of the uncompressed data
 */
 	uncompressed_checksum = lzo_adler32(0,NULL,0);
 	uncompressed_checksum = lzo_adler32(uncompressed_checksum,in,in_len);

/*
 * Step 6a: compress from `in' to `out' with LZO1X-999
 */
#ifdef USE_LZO1X
 	for (lazy = 0; lazy <= max_try_lazy; lazy++)
	{
		r = lzo1x_999_compress_internal(in,in_len,out,&out_len,wrkmem,
		                                NULL, 0, 0,
		                                lazy, big, big, big, big, flags);
		if (r != LZO_E_OK)
		{
			/* this should NEVER happen */
			printf("internal error - compression failed: %d\n", r);
			exit(1);
		}
		printf("LZO1X-999: lazy =%2d: %8lu -> %8lu\n",
				lazy, (long) in_len, (long) out_len);
		if (out_len < best_len)
		{
			best_len = out_len;
			best_lazy = lazy;
			best_compress = 1;		/* LZO1X-999 */
		}
	}
#endif /* USE_LZO1X */

/*
 * Step 6b: compress from `in' to `out' with LZO1Y-999
 */
#ifdef USE_LZO1Y
 	for (lazy = 0; lazy <= max_try_lazy; lazy++)
	{
		r = lzo1y_999_compress_internal(in,in_len,out,&out_len,wrkmem,
		                                NULL, 0, 0,
		                                lazy, big, big, big, big, flags);
		if (r != LZO_E_OK)
		{
			/* this should NEVER happen */
			printf("internal error - compression failed: %d\n", r);
			exit(1);
		}
		printf("LZO1Y-999: lazy =%2d: %8lu -> %8lu\n",
				lazy, (long) in_len, (long) out_len);
		if (out_len < best_len)
		{
			best_len = out_len;
			best_lazy = lazy;
			best_compress = 2;		/* LZO1Y-999 */
		}
	}
#endif /* USE_LZO1Y */

/*
 * Step 7: check if compressible
 */
 	if (best_len >= in_len)
	{
		printf("This file contains incompressible data.\n");
		return 0;
	}

/*
 * Step 8: compress data again using the best compressor found
 */
	if (best_compress == 1)
		r = lzo1x_999_compress_internal(in,in_len,out,&out_len,wrkmem,
		                                NULL, 0, 0,
		                                best_lazy, big, big, big, big, flags);
	else if (best_compress == 2)
		r = lzo1y_999_compress_internal(in,in_len,out,&out_len,wrkmem,
		                                NULL, 0, 0,
		                                best_lazy, big, big, big, big, flags);
	else
		r = -100;
	assert(r == LZO_E_OK);
	assert(out_len == best_len);

/*
 * Step 9: optimize compressed data (compressed data is in `out' buffer)
 */
#if 1
	/* Optimization does not require any data in the buffer that will
	 * hold the uncompressed data. To prove this, we clear the buffer.
	 */
	lzo_memset(in,0,in_len);
#endif

 	orig_len = in_len;
	if (best_compress == 1)
		r = lzo1x_optimize(out,out_len,in,&orig_len,NULL);
	else if (best_compress == 2)
		r = lzo1y_optimize(out,out_len,in,&orig_len,NULL);
	else
		r = -100;
	if (r != LZO_E_OK || orig_len != in_len)
	{
		/* this should NEVER happen */
		printf("internal error - optimization failed: %d\n", r);
		exit(1);
	}

/*
 * Step 10: compute a checksum of the compressed data
 */
 	compressed_checksum = lzo_adler32(0,NULL,0);
 	compressed_checksum = lzo_adler32(compressed_checksum,out,out_len);

/*
 * Step 11: write compressed data to a file
 */
	printf("%s: %s: %ld -> %ld, checksum 0x%08lx 0x%08lx\n",
	        progname, in_name, (long) in_len, (long) out_len,
	        (long) uncompressed_checksum, (long) compressed_checksum);

	if (out_name && out_name[0])
	{
		printf("%s: writing to file %s\n", progname, out_name);
		f = fopen(out_name,"wb");
		if (f == NULL)
		{
			printf("%s: cannot open output file %s\n", progname, out_name);
			exit(1);
		}
		if (lzo_fwrite(f,out,out_len) != out_len || fclose(f) != 0)
		{
			printf("%s: write error !!\n", progname);
			exit(1);
		}
	}

/*
 * Step 12: verify decompression
 */
#ifdef PARANOID
 	orig_len = in_len;
	if (best_compress == 1)
		r = lzo1x_decompress(out,out_len,in,&orig_len,NULL);
	else if (best_compress == 2)
		r = lzo1y_decompress(out,out_len,in,&orig_len,NULL);
	else
		r = -100;
	if (r != LZO_E_OK || orig_len != in_len)
	{
		/* this should NEVER happen */
		printf("internal error - decompression failed: %d\n", r);
		exit(1);
	}
	if (uncompressed_checksum != lzo_adler32(lzo_adler32(0,NULL,0),in,in_len))
	{
		/* this should NEVER happen */
		printf("internal error - decompression data error\n");
		exit(1);
	}
	/* Now you could also verify decompression under similar conditions as in
	 * your application, e.g. overlapping assembler decompression etc.
	 */
#endif

	lzo_free(in);
	lzo_free(out);
	lzo_free(wrkmem);

	return 0;
}
Exemple #17
0
int main(int argc,char *argv[])

{
  FILE *in,*out;
  char *infile=NULL,*outfile=NULL,*tmpfile=NULL,*copt,*ptr,*gsexec,buf[21];
  char command[MAX_IN],ch[MAX_IN],*BBname,*device,ropt[20],*gsopt;
  double bbllx,bblly,bburx,bbury,xoffset,yoffset,enlarge;
  int    width,height,res,xpix,ypix;
  int i,count,status,BBCorrected,did_CR,debug,compress,usegs,wait,
    BBhires,BBexact,found,depth,filter,ngsopt;
  int doseps;
  unsigned long dosepsbegin, dosepsend, pos;
  unsigned int c;
  fpos_t  fpos;


#if defined (__EMX__)
  _wildcard (&argc, &argv);
#endif

  /* default parameter */
  status=0;
  BBCorrected=0;
  BBhires=0;
  BBexact=0;
  debug=0;
  compress=1;
  usegs=1;
  gsexec=GSEXEC;
  wait=0;
  filter=0;
  enlarge=0.;
  res=600;
  device="pdfwrite";
  xpix=0;
  ypix=0;
  ngsopt=100;
  gsopt=malloc(ngsopt);
  gsopt[0]='\0';


  /******************************************************************

								     Process command line options

  ******************************************************************/

  for(i=1;i<argc;i++){

    /* printf("i=%d  arg=>>%s<<\n",i,argv[i]); */

    if(!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h")){
      usage();
      status=0;
      goto EXIT;
    }

    if(!strcmp(argv[i],"--debug") || !strcmp(argv[i],"-d")){
      debug=1;
      continue;
    }

    if(!strcmp(argv[i],"--nodebug")){
      debug=0;
      continue;
    }

    if(!strcmp(argv[i],"--compress") || !strcmp(argv[i],"-c")){
      compress=1;
      continue;
    }

    if(!strcmp(argv[i],"--nocompress")){
      compress=0;
      continue;
    }

    if(!strcmp(argv[i],"--nogs")){
      usegs=0;
      continue;
    }

    if(!strcmp(argv[i],"--gs")){
      usegs=1;
      continue;
    }

    if(!strcmp(argv[i],"--wait")  || !strcmp(argv[i],"-w")){
      wait=1;
      continue;
    }

    if(!strcmp(argv[i],"--nowait")){
      wait=0;
      continue;
    }

    if(!strcmp(argv[i],"--filter")){
      filter=1;
      continue;
    }

    if(!strcmp(argv[i],"--nofilter")){
      filter=0;
      continue;
    }

    if(!strcmp(argv[i],"--hires")){
      BBhires=1;
      continue;
    }

    if(!strcmp(argv[i],"--nohires")){
      BBhires=0;
      continue;
    }

    if(!strcmp(argv[i],"--exact")){
      BBexact=1;
      continue;
    }

    if(!strcmp(argv[i],"--noexact")){
      BBexact=0;
      continue;
    }

    if(!strncmp(argv[i],"--outfile=",strlen("--outfile="))){
      outfile=malloc(strlen(argv[i])-strlen("--outfile=")+1);
      strcpy(outfile, argv[i]+strlen("--outfile="));
      continue;
    }

    if(!strncmp(argv[i],"--tmpfile=",strlen("--tmpfile="))){
      tmpfile=malloc(strlen(argv[i])-strlen("--tmpfile=")+1);
      strcpy(tmpfile, argv[i]+strlen("--tmpfile="));
      continue;
    }

    if(!strncmp(argv[i],"-r",strlen("-r"))){
      sscanf(argv[i]+strlen("-r"),"%d",&res);
      continue;
    }

    if(!strncmp(argv[i],"--width=",strlen("--width="))){
      sscanf(argv[i]+strlen("--width="),"%d",&xpix);
      continue;
    }

    if(!strncmp(argv[i],"--height=",strlen("--height="))){
      sscanf(argv[i]+strlen("--height="),"%d",&ypix);
      continue;
    }

    if(!strncmp(argv[i],"--gsopt=",strlen("--gsopt="))){
      char *opt=argv[i]+strlen("--gsopt=");
      if(strlen(gsopt)+strlen(opt)+2 < ngsopt){
	ngsopt+=100;
	gsopt=realloc(gsopt,ngsopt);
      }
      strcat(gsopt," ");
      strcat(gsopt,opt);
      continue;
    }

    if(!strncmp(argv[i],"-sDEVICE=",strlen("-sDEVICE="))){
      device=argv[i]+strlen("-sDEVICE=");
      continue;
    }

    if(!strcmp(argv[i],"-o") && i+1<argc){
      outfile=malloc(strlen(argv[i+1])+1);
      strcpy(outfile, argv[i+1]);
      i++;
      continue;
    }

    if(!strncmp(argv[i],"--gsexec=",strlen("--gsexec="))){
      gsexec=argv[i]+strlen("--gsexec=");
      continue;
    }


    if(argv[i][0]!='-'){
      if(infile) printf("\nCan process only one input file\n");
      else       infile=argv[i];
      continue;
    }

    if(!strncmp(argv[i],"--enlarge=",strlen("--enlarge="))){
      sscanf(argv[i]+strlen("--enlarge="),"%lf",&enlarge);
      continue;
    }

    usage();
    fprintf(stderr,"\nunknown option >>%s<<\n",argv[i]);
    status=1;
    goto EXIT;
  }



  /******************************************************************

								     check arguments and files

  ******************************************************************/


  if(filter) debug=0;
  if(filter) wait =0;

  if(BBexact && BBhires){
    fprintf(stderr,"\nOptions --hires and --exact cannot be used together\n");
    status=1;
    goto EXIT;
  }

  if     (BBexact) BBname="%%ExactBoundingBox:";
  else if(BBhires) BBname="%%HiresBoundingBox:";
  else             BBname="%%BoundingBox:";  

  if(!filter) {

    if(!infile) {
      usage();
      fprintf(stderr,"no input file specified!\n");
      status=1;
      goto EXIT;
    }

    if((in=fopen(infile,"rb")) == NULL) {
      usage();
      fprintf(stderr,"%s: File not found!\n",infile);
      status=1;
      goto EXIT;
    }
    fclose(in);

  }else{

    if(infile) {
      fprintf(stderr,"Input file cannot be used with filter option!\n");
      status=1;
      goto EXIT;
    }

    infile="epstopdf";   /* dummy input filename to generate tmp-filename */
  }



  /* find a temporary filename that does not exist yet */
  if(usegs && !tmpfile){
    tmpfile=malloc(strlen(infile)+9);
    count=0;
    do{
      if(count>99) {
	fprintf(stderr,"No temporary file available! Try deleting *.tmp.\n\n");
	status=1;
	goto EXIT;
      }
      sprintf(tmpfile,"%s.%d.tmp",infile,count);
      if(debug) printf("checking temporary filename >>%s<<\n",tmpfile);
      out=fopen(tmpfile,"rb");
      if(out) fclose(out);
      count++;
    }while(out);
  }

  if(!filter){
    if(!outfile){
      outfile=malloc(strlen(infile)+6);
      strcpy(outfile,infile);
      ptr=outfile;
      while(strpbrk(ptr,"\\/")) ptr=strpbrk(ptr,"\\/")+1;
      ptr=strrchr(ptr,'.');
      if(ptr) *ptr='\0';
      if(usegs) strcat(outfile,".pdf");
      else      strcat(outfile,"2.eps");
    }
  }else{
    if(outfile) {
      fprintf(stderr,"Output file cannot be used with filter option!\n");
      status=1;
      goto EXIT;
    }
    outfile=malloc(2);
    strcpy(outfile,"-");
  }



  if(!filter) printf("Converting %s to %s ..... ",infile,outfile);


  /******************************************************************

  put the pagesize from the bounding box into the eps file

  ******************************************************************/

	
  if(debug) printf("\nAdding correct pagesize to EPS ... searching for %s ...\n",BBname);

  if     (!filter) in  = fopen(infile, "rb");
  else {
    in  = stdin; 
    setmode(fileno(stdin), O_BINARY);
  }
  if     (usegs)   out = fopen(tmpfile,"wb");
  else if(!filter) out = fopen(outfile,"wb");
  else {
    out = stdout;
    setmode(fileno(stdout), O_BINARY);
  }
  if(!in || !out){
    fprintf(stderr,"cannot open files\n");
    status=1;
    goto EXIT;
  }
  depth=0;

  doseps = dosepsbegin = dosepsend = 0;
  c = getc(in);
  if (c == 'E'+0x80) {
    if ((getc(in)=='P'+0x80) && (getc(in)=='S'+0x80)
	&& (getc(in)=='F'+0x80)) {
      doseps = 1;
      dosepsbegin = getc(in) ;
      dosepsbegin += getc(in) * 256L ;
      dosepsbegin += getc(in) * 65536L ;
      dosepsbegin += getc(in) * 256L * 65536 ;
      dosepsend = getc(in) ;
      dosepsend += getc(in) * 256L ;
      dosepsend += getc(in) * 65536L ;
      dosepsend += getc(in) * 256L * 65536 ;
      fseek(in, dosepsbegin, 0);
      c = getc(in);
      dosepsend-- ;
    }
  }
  rewind(in);
  if (doseps)
    fseek(in, dosepsbegin, SEEK_SET);
  pos = dosepsbegin;
  while (fgets(ch,MAX_IN,in)) {
    if (doseps && ftell(in) > dosepsend + dosepsbegin) {
      ch[dosepsend + dosepsbegin - pos ] = '\0';
      fputs(ch, out); fputc('\n', out);
      break;
    }
    pos = ftell(in);    
    
    if(!strncmp(ch,BEGINDOC,strlen(BEGINDOC))) depth++;   /* count included documents */
    if(!strncmp(ch,ENDDOC,  strlen(ENDDOC)  )) depth--;
    if(!strncmp(ch,BBname,  strlen(BBname)) && depth==0) { /* look for BB comment in main doc only */
      sscanf(ch,"%*s %20s",buf);
      if(!strcmp(buf,"(atend)")){                       /* BB is atended */  
	if(filter){
	  fprintf(stderr,"Cannot look for BoundingBox in the trailer "
		  "with option --filter\n");
	  if(usegs) remove(tmpfile);
	  status=1;
	  goto EXIT;
	}
	if(debug) printf("\n (atend)! ...\n");
	fgetpos(in, &fpos); /* store file position */
	found=0;  
	while (fgets(ch,MAX_IN,in)){
	  if(!strncmp(ch,BEGINDOC,strlen(BEGINDOC))) depth++;   /* count included documents */
	  if(!strncmp(ch,ENDDOC,  strlen(ENDDOC)  )) depth--;
	  if(!strncmp(ch,BBname,strlen(BBname)) && depth==0) { /* look for bounding box in main doc only */
	    found=1;
	    fsetpos(in, &fpos);  /* rewind to (atend) comment */
	    break;
	  }	
	} 
	if(!found){
	  fprintf(stderr,"atended %s not found\n",BBname);
	  if(usegs  && !debug) remove(tmpfile);
	  if(!usegs && !debug) remove(outfile);
	  status=1;
	  goto EXIT;
	} 
      }


      /* No Idea what ExactBoundingBox means. Hope it also works with this code */

      /* I thought Postscript says that the bounding box should be integer.
	 However, some applications (like Corel Draw) use floats and gs has no
	 problem with it. So I use floats for translate that will result in a
	 more exact box. Since gs seems not to be able to use floats in 
	 setpagedevice, these values are converted to integer */   

      if(!BBCorrected){ /* write Bounding box one time only! */
	if(sscanf(ch,"%*s %lf %lf %lf %lf",&bbllx,&bblly,&bburx,&bbury)!=4){
	  fprintf(stderr,"incorrect %s \n",BBname);
	  if(usegs && !debug) remove(tmpfile);
	  status=1;
	  goto EXIT;
	}
	if(debug) printf("BoundingBox: %f %f %f %f\n",bbllx,bblly,bburx,bbury);
	bblly  -= enlarge;
	bbllx  -= enlarge;
	bbury  += enlarge;
	bburx  += enlarge;
	width   = ceil(bburx-bbllx);  /* make papersize integer and enlarge it a little bit */
	height  = ceil(bbury-bblly);
	xoffset =-bbllx;
	yoffset =-bblly;
	fprintf(out,"%s %d %d %d %d\n",BBname,0,0,width,height);
	fprintf(out,"<< /PageSize [%d %d] >> setpagedevice \n",width,height);
	if(isint(xoffset) && isint(yoffset)) fprintf(out,"gsave %d %d translate\n",round(xoffset),round(yoffset));
	else                                 fprintf(out,"gsave %f %f translate\n",xoffset,yoffset);
	if(!filter) printf(" (%dx%d mm) ... ",(int)(25.4/72.*width),(int)(25.4/72.*height));
	did_CR=1;
	BBCorrected=1;
      }
    }else{
      fputs(ch,out);
      if(strpbrk(ch, "\n")) did_CR=1;
      else                  did_CR=0;
    }
  }
  if(BBCorrected){
    if(!did_CR) fprintf(out,"\ngrestore\n");
    else        fprintf(out,  "grestore\n");
  }
  if(in !=stdin ) fclose(in);
  if(out!=stdout) fclose(out);

  if(width && height){
    if      (xpix) res=(72*xpix)/width;
    else if (ypix) res=(72*ypix)/height;
  }


  /******************************************************************

								     do the conversion eps->pdf using gs

  ******************************************************************/


  if(usegs){

#ifdef FPTEX
    char stemp[512];
    char *gs_argv[] = {
      NULL,		/* 0 gsexec */
      "-q",
      "-dNOPAUSE",
      "-dBATCH",
      NULL,		/* 4 copt */
      NULL,		/* 5 device */
      NULL,		/* 6 ropt */
      NULL,		/* 7 gsopt */
      NULL,		/* 8 outfile */
      /*	    "-", "-c", "quit", "-f", */
      NULL		/* 9 tmpfile */,
      NULL
    };
    int gs_argc = sizeof(gs_argv)/sizeof(gs_argv[0]);

    gs_argv[0] = gsexec;
    if(compress) gs_argv[4]="-dUseFlateCompression=true";
    else         gs_argv[4]="-dUseFlateCompression=false";

    if(res)      sprintf(ropt,"-r%d",res);
    else         ropt[0]='\0';

    if(res && debug) printf(" (%d dpi) ... ",res);

    sprintf(stemp, "-sDEVICE=%s", device);
    gs_argv[5] = xstrdup(stemp);
    gs_argv[6] = ropt;
    if (gsopt && *gsopt) {
      gs_argv[7] = gsopt;
      sprintf(stemp, "-sOutputFile=%s", outfile);
      gs_argv[8] = xstrdup(stemp);
      sprintf(stemp, "%s", tmpfile);
      gs_argv[9] = xstrdup(stemp);
    }
    else {
      sprintf(stemp, "-sOutputFile=%s", outfile);
      gs_argv[7] = xstrdup(stemp);
      sprintf(stemp, "%s", tmpfile);
      gs_argv[8] = xstrdup(stemp);
      gs_argc--;
    }
    if(debug) {
      int i;
      printf("running ghostscript ...\n");
      for (i = 0; i < gs_argc - 1; i++)
	fprintf(stderr, "gs_argv[%d] = %s\n", i, gs_argv[i]);
    }

    if (gs_locate() == NULL) {
      fprintf(stderr, "\nCan't locate Ghostscript ! Exiting ...\n");
      return EXIT_FAILURE;
    }

    if (!gs_dll_initialize()) {
      fprintf(stderr, "Can't initialize ghostscript, exiting ...\n");
      return EXIT_FAILURE;
    }
	 
    if ((status = (*pgsdll_init)(gsdll_callback,
				 NULL,
				 gs_argc - 1,
				 gs_argv)) == 0) {
      /* Should not happen : gs should quit right after being initialized. */
      /* fprintf(stderr, "gs exited quickly.\n"); */
      (*pgsdll_exit)();
    }
	 
    if (status != 0 && status != GSDLL_INIT_QUIT)
      fprintf(stderr, "gsdll_init returned %d\n", status);
	 
    gs_dll_release();
	 
    free(gs_argv[5]);

#if 1
    if(!debug) remove(tmpfile);
    else       printf("keeping temporary file >>%s<<\n",tmpfile);
#else
    remove(tmpfile);
#endif

#else
    if(compress) copt="-dUseFlateCompression=true";
    else         copt="-dUseFlateCompression=false";

    if(res)      sprintf(ropt,"-r%d",res);
    else         ropt[0]='\0';

    if(res && debug) printf(" (%d dpi) ... ",res);

    sprintf(command,"%s -q -dNOPAUSE -dBATCH %s -sDEVICE=%s %s %s"
	    " \"-sOutputFile=%s\" -c save pop -f \"%s\"",
	    gsexec,copt,device,ropt,gsopt,outfile,tmpfile);
    if(debug) printf("running ghostscript ...\n");
    if(debug) puts(command);
    status=system(command);
    if(!debug) remove(tmpfile);
    else       printf("keeping temporary file >>%s<<\n",tmpfile);
#endif /* ! FPTEX */
  }
	
  if(!filter) printf("Done\n");



 EXIT:

  free(outfile);
  free(tmpfile);
  free(gsopt);

  if(wait){
    printf("\n<Press a key> ");
    getchar();
    printf("\n");
  }

  return status;
}
Exemple #18
0
int
main(int argc, char *argv[])
{
	ENTRY *ep;
	TAG *tp;
	int ch, rv;
	char *conffile, **p, *p_augment, *p_path;

	__progname = argv[0];
	_wildcard(&argc, &argv);
	conffile = NULL;
	p_augment = p_path = NULL;
	while ((ch = getopt(argc, argv, "C:M:m:P:")) != -1)
		switch (ch) {
		case 'C':
			conffile = optarg;
			break;
		case 'M':
		case 'P':		/* backward compatible */
			p_path = optarg;
			break;
		case 'm':
			p_augment = optarg;
			break;
		case '?':
		default:
			usage();
		}
	argv += optind;
	argc -= optind;

	if (argc < 1)
		usage();

	if ((found = malloc((u_int)argc * sizeof(int))) == NULL)
		err(1, NULL);
	memset(found, 0, argc * sizeof(int));

	for (p = argv; *p; ++p)			/* convert to lower-case */
		lowstr(*p, *p);

	if (p_augment)
		apropos(argv, p_augment, 1);
	if (p_path || (p_path = getenv("MANPATH")))
		apropos(argv, p_path, 1);
	else {
		config(conffile);
		ep = (tp = getlist("_whatdb")) == NULL ?
		    NULL : tp->list.tqh_first;
		for (; ep != NULL; ep = ep->q.tqe_next)
			apropos(argv, ep->s, 0);
	}

	if (!foundman)
		errx(1, "no %s file found", _PATH_WHATIS);

	rv = 1;
	for (p = argv; *p; ++p)
		if (found[p - argv])
			rv = 0;
		else
			(void)printf("%s: nothing appropriate\n", *p);
	exit(rv);
}
Exemple #19
0
int main(int argc,char **argv)
{
	const char *name;
	int i;

	init_privs();
#ifdef __EMX__
	_wildcard(&argc,&argv);
#endif

/*#define PRIV_TEST*/

#ifdef PRIV_TEST
	{ 
		int euid;
		char command[100];
	
		printf("INIT: %d %d\n", getuid(), geteuid());
		drop_privs();
		printf("DROP: %d %d\n", getuid(), geteuid());
		reclaim_privs();
		printf("RECLAIM: %d %d\n", getuid(), geteuid());
		euid = geteuid();
		if(argc & 1) {
			drop_privs();
			printf("DROP: %d %d\n", getuid(), geteuid());
		}
		if(!((argc-1) & 2)) {
			destroy_privs();
			printf("DESTROY: %d %d\n", getuid(), geteuid());
		}
		sprintf(command, "a.out %d", euid);
		system(command);
		return 1;
	}
#endif


#ifdef __EMX__
       _wildcard(&argc,&argv);
#endif 


	/* check whether the compiler lays out structures in a sane way */
	if(sizeof(struct partition) != 16 ||
	   sizeof(struct directory) != 32 ||
	   sizeof(struct vfat_subentry) !=32) {
		fprintf(stderr,"Mtools has not been correctly compiled\n");
		fprintf(stderr,"Recompile it using a more recent compiler\n");
		return 137;
	}

#ifdef __EMX__
       argv[0] = _getname(argv[0]); _remext(argv[0]); name = argv[0];
#else  
	name = _basename(argv[0]);
#endif

#if 0
	/* this allows the different tools to be called as "mtools -c <command>"
	** where <command> is mdir, mdel, mcopy etcetera
	** Mainly done for the BeOS, which doesn't support links yet.
	*/

	if(argc >= 3 && 
	   !strcmp(argv[1], "-c") &&
	   !strcmp(name, "mtools")) {
		argc-=2;
		argv+=2;
		name = argv[0];
	}
#endif

	/* print the version */
	if(argc >= 2 && 
	   (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "--version") ==0)) {
		printf("%c%s version %s, dated %s\n", 
		       toupper(name[0]), name+1,
		       mversion, mdate);
		printf("configured with the following options: ");
#ifdef USE_XDF
		printf("enable-xdf ");
#else
		printf("disable-xdf ");
#endif
#ifdef USING_VOLD
		printf("enable-vold ");
#else
		printf("disable-vold ");
#endif
#ifdef USING_NEW_VOLD
		printf("enable-new-vold ");
#else
		printf("disable-new-vold ");
#endif
#ifdef DEBUG
		printf("enable-debug ");
#else
		printf("disable-debug ");
#endif
#ifdef USE_RAWTERM
		printf("enable-raw-term ");
#else
		printf("disable-raw-term ");
#endif
		printf("\n");
		return 0;
	}

	if (argc >= 2 && strcmp(name, "mtools") == 0) {
		/* mtools command ... */
		argc--;
		argv++;
		name = argv[0];
	}
	progname = argv[0];

	read_config();
	setup_signal();
	for (i = 0; i < NDISPATCH; i++) {
		if (!strcmp(name,dispatch[i].cmd)
		    || (name[0] == 'm' && !strcmp(name+1,dispatch[i].cmd)))
			dispatch[i].fn(argc, argv, dispatch[i].type);
	}
	if (strcmp(name,"mtools"))
		fprintf(stderr,"Unknown mtools command '%s'\n",name);
	fprintf(stderr,"Usage: mtools [-V] command [-options] arguments ...\n");
	fprintf(stderr,"Supported commands:");
	for (i = 0; i < NDISPATCH; i++) {
		fprintf(stderr, i%8 == 0 ? "\n\t" : ", ");
		fprintf(stderr, "%s", dispatch[i].cmd);
	}
	putc('\n', stderr);
	fprintf(stderr, "Use 'mtools command -?' for help per command\n");

	return 1;
}
Exemple #20
0
int main(int sys_argc, char ** sys_argv)
{
	int result;
	char end_of_files = FALSE;
	long parr;
	char *fname;
	int libpar = 0;
	mpg123_pars *mp;
#if !defined(WIN32) && !defined(GENERIC)
	struct timeval start_time;
#endif
	aux_out = stdout; /* Need to initialize here because stdout is not a constant?! */
#if defined (WANT_WIN32_UNICODE)
	if(win32_cmdline_utf8(&argc, &argv) != 0)
	{
		error("Cannot convert command line to UTF8!");
		safe_exit(76);
	}
#else
	argv = sys_argv;
	argc = sys_argc;
#endif
#if defined (WANT_WIN32_SOCKETS)
	win32_net_init();
#endif

	/* Extract binary and path, take stuff before/after last / or \ . */
	if((prgName = strrchr(argv[0], '/')) || (prgName = strrchr(argv[0], '\\')))
	{
		/* There is some explicit path. */
		prgName[0] = 0; /* End byte for path. */
		prgName++;
		binpath = argv[0];
	}
	else
	{
		prgName = argv[0]; /* No path separators there. */
		binpath = NULL; /* No path at all. */
	}

	/* Need to initialize mpg123 lib here for default parameter values. */

	result = mpg123_init();
	if(result != MPG123_OK)
	{
		error1("Cannot initialize mpg123 library: %s", mpg123_plain_strerror(result));
		safe_exit(77);
	}
	cleanup_mpg123 = TRUE;

	mp = mpg123_new_pars(&result); /* This may get leaked on premature exit(), which is mainly a cosmetic issue... */
	if(mp == NULL)
	{
		error1("Crap! Cannot get mpg123 parameters: %s", mpg123_plain_strerror(result));
		safe_exit(78);
	}

	/* get default values */
	mpg123_getpar(mp, MPG123_DOWN_SAMPLE, &parr, NULL);
	param.down_sample = (int) parr;
	mpg123_getpar(mp, MPG123_RVA, &param.rva, NULL);
	mpg123_getpar(mp, MPG123_DOWNSPEED, &param.halfspeed, NULL);
	mpg123_getpar(mp, MPG123_UPSPEED, &param.doublespeed, NULL);
	mpg123_getpar(mp, MPG123_OUTSCALE, &param.outscale, NULL);
	mpg123_getpar(mp, MPG123_FLAGS, &parr, NULL);
	mpg123_getpar(mp, MPG123_INDEX_SIZE, &param.index_size, NULL);
	param.flags = (int) parr;
	param.flags |= MPG123_SEEKBUFFER; /* Default on, for HTTP streams. */
	mpg123_getpar(mp, MPG123_RESYNC_LIMIT, &param.resync_limit, NULL);
	mpg123_getpar(mp, MPG123_PREFRAMES, &param.preframes, NULL);

#ifdef OS2
        _wildcard(&argc,&argv);
#endif

	while ((result = getlopt(argc, argv, opts)))
	switch (result) {
		case GLO_UNKNOWN:
			fprintf (stderr, "%s: Unknown option \"%s\".\n", 
				prgName, loptarg);
			usage(1);
		case GLO_NOARG:
			fprintf (stderr, "%s: Missing argument for option \"%s\".\n",
				prgName, loptarg);
			usage(1);
	}
	/* Do this _after_ parameter parsing. */
	check_locale(); /* Check/set locale; store if it uses UTF-8. */

	if(param.list_cpu)
	{
		const char **all_dec = mpg123_decoders();
		printf("Builtin decoders:");
		while(*all_dec != NULL){ printf(" %s", *all_dec); ++all_dec; }
		printf("\n");
		mpg123_delete_pars(mp);
		return 0;
	}
	if(param.test_cpu)
	{
		const char **all_dec = mpg123_supported_decoders();
		printf("Supported decoders:");
		while(*all_dec != NULL){ printf(" %s", *all_dec); ++all_dec; }
		printf("\n");
		mpg123_delete_pars(mp);
		return 0;
	}
	if(param.gain != -1)
	{
	    warning("The parameter -g is deprecated and may be removed in the future.");
	}

	if (loptind >= argc && !param.listname && !param.remote) usage(1);
	/* Init audio as early as possible.
	   If there is the buffer process to be spawned, it shouldn't carry the mpg123_handle with it. */
	bufferblock = mpg123_safe_buffer(); /* Can call that before mpg123_init(), it's stateless. */
	if(init_output(&ao) < 0)
	{
		error("Failed to initialize output, goodbye.");
		mpg123_delete_pars(mp);
		return 99; /* It's safe here... nothing nasty happened yet. */
	}
	have_output = TRUE;

	/* ========================================================================================================= */
	/* Enterning the leaking zone... we start messing with stuff here that should be taken care of when leaving. */
	/* Don't just exit() or return out...                                                                        */
	/* ========================================================================================================= */

	httpdata_init(&htd);

#if !defined(WIN32) && !defined(GENERIC)
	if (param.remote)
	{
		param.verbose = 0;
		param.quiet = 1;
		param.flags |= MPG123_QUIET;
	}
#endif

	/* Set the frame parameters from command line options */
	if(param.quiet) param.flags |= MPG123_QUIET;

#ifdef OPT_3DNOW
	if(dnow != 0) param.cpu = (dnow == SET_3DNOW) ? "3dnow" : "i586";
#endif
	if(param.cpu != NULL && (!strcmp(param.cpu, "auto") || !strcmp(param.cpu, ""))) param.cpu = NULL;
	if(!(  MPG123_OK == (result = mpg123_par(mp, MPG123_VERBOSE, param.verbose, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_FLAGS, param.flags, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_DOWN_SAMPLE, param.down_sample, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_RVA, param.rva, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_FORCE_RATE, param.force_rate, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_DOWNSPEED, param.halfspeed, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_UPSPEED, param.doublespeed, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_ICY_INTERVAL, 0, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_RESYNC_LIMIT, param.resync_limit, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_TIMEOUT, param.timeout, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_OUTSCALE, param.outscale, 0))
	    && ++libpar
	    && MPG123_OK == (result = mpg123_par(mp, MPG123_PREFRAMES, param.preframes, 0))
			))
	{
		error2("Cannot set library parameter %i: %s", libpar, mpg123_plain_strerror(result));
		safe_exit(45);
	}
	if (!(param.listentry < 0) && !param.quiet) print_title(stderr); /* do not pollute stdout! */

	{
		long default_index;
		mpg123_getpar(mp, MPG123_INDEX_SIZE, &default_index, NULL);
		if( param.index_size != default_index && (result = mpg123_par(mp, MPG123_INDEX_SIZE, param.index_size, 0.)) != MPG123_OK )
		error1("Setting of frame index size failed: %s", mpg123_plain_strerror(result));
	}

	if(param.force_rate && param.down_sample)
	{
		error("Down sampling and fixed rate options not allowed together!");
		safe_exit(1);
	}

	/* Now actually get an mpg123_handle. */
	mh = mpg123_parnew(mp, param.cpu, &result);
	if(mh == NULL)
	{
		error1("Crap! Cannot get a mpg123 handle: %s", mpg123_plain_strerror(result));
		safe_exit(77);
	}
	mpg123_delete_pars(mp); /* Don't need the parameters anymore ,they're in the handle now. */

	/* Prepare stream dumping, possibly replacing mpg123 reader. */
	if(dump_open(mh) != 0) safe_exit(78);

	/* Now either check caps myself or query buffer for that. */
	audio_capabilities(ao, mh);

	load_equalizer(mh);

#ifdef HAVE_SETPRIORITY
	if(param.aggressive) { /* tst */
		int mypid = getpid();
		setpriority(PRIO_PROCESS,mypid,-20);
	}
#endif

#if defined (HAVE_SCHED_SETSCHEDULER) && !defined (__CYGWIN__) && !defined (HAVE_WINDOWS_H)
/* Cygwin --realtime seems to fail when accessing network, using win32 set priority instead */
/* MinGW may have pthread installed, we prefer win32API */
	if (param.realtime) {  /* Get real-time priority */
	  struct sched_param sp;
	  fprintf(stderr,"Getting real-time priority\n");
	  memset(&sp, 0, sizeof(struct sched_param));
	  sp.sched_priority = sched_get_priority_min(SCHED_FIFO);
	  if (sched_setscheduler(0, SCHED_RR, &sp) == -1)
	    fprintf(stderr,"Can't get real-time priority\n");
	}
#endif

#ifdef HAVE_WINDOWS_H
	/* argument "3" is equivalent to realtime priority class */
	win32_set_priority( param.realtime ? 3 : param.w32_priority);
#endif

	if(!param.remote) prepare_playlist(argc, argv);

#if !defined(WIN32) && !defined(GENERIC)
	/* Remote mode is special... but normal console and terminal-controlled operation needs to catch the SIGINT.
	   For one it serves for track skip when not in terminal control mode.
	   The more important use being a graceful exit, including telling the buffer process what's going on. */
	if(!param.remote) catchsignal (SIGINT, catch_interrupt);
#endif

	if(param.remote) {
		int ret;
		ret = control_generic(mh);
		safe_exit(ret);
	}
#ifdef HAVE_TERMIOS
		debug1("param.term_ctrl: %i", param.term_ctrl);
		if(param.term_ctrl)
			term_init();
#endif
	if(APPFLAG(MPG123APP_CONTINUE)) frames_left = param.frame_number;

	while ((fname = get_next_file()))
	{
		char *dirname, *filename;
		int newdir;
		/* skip_tracks includes the previous one. */
		if(skip_tracks) --skip_tracks;
		if(skip_tracks)
		{
			debug("Skipping this track.");
			continue;
		}
		if(param.delay > 0)
		{
			/* One should enable terminal control during that sleeping phase! */
			if(param.verbose > 2) fprintf(stderr, "Note: pausing %i seconds before next track.\n", param.delay);
			output_pause(ao);
#ifdef WIN32
			Sleep(param.delay*1000);
#else
			sleep(param.delay);
#endif
			output_unpause(ao);
		}
		if(!APPFLAG(MPG123APP_CONTINUE)) frames_left = param.frame_number;

		debug1("Going to play %s", strcmp(fname, "-") ? fname : "standard input");

		if(intflag || !open_track(fname))
		{
#ifdef HAVE_TERMIOS
			/* We need the opportunity to cancel in case of --loop -1 . */
			if(param.term_ctrl) term_control(mh, ao);
#endif
			/* No wait for a second interrupt before we started playing. */
			if(intflag) break;

			continue;
		}

		if(!param.quiet) fprintf(stderr, "\n");
		if(param.index)
		{
			if(param.verbose) fprintf(stderr, "indexing...\r");
			mpg123_scan(mh);
		}
		/*
			Only trigger a seek if we do not want to start with the first frame.
			Rationale: Because of libmpg123 sample accuracy, this could cause an unnecessary backwards seek, that even may fail on non-seekable streams.
			For start frame of 0, we are already at the correct position!
		*/
		framenum = 0;
		if(param.start_frame > 0)
		framenum = mpg123_seek_frame(mh, param.start_frame, SEEK_SET);

		if(APPFLAG(MPG123APP_CONTINUE)) param.start_frame = 0;

		if(framenum < 0)
		{
			error1("Initial seek failed: %s", mpg123_strerror(mh));
			if(mpg123_errcode(mh) == MPG123_BAD_OUTFORMAT)
			{
				fprintf(stderr, "%s", "So, you have trouble getting an output format... this is the matrix of currently possible formats:\n");
				print_capabilities(ao, mh);
				fprintf(stderr, "%s", "Somehow the input data and your choices don't allow one of these.\n");
			}
			mpg123_close(mh);
			continue;
		}

		/* Prinout and xterm title need this, possibly independently. */
		newdir = split_dir_file(fname ? fname : "standard input", &dirname, &filename);

		if (!param.quiet)
		{
			if(newdir) fprintf(stderr, "Directory: %s\n", dirname);

#ifdef HAVE_TERMIOS
		/* Reminder about terminal usage. */
		if(param.term_ctrl) term_hint();
#endif


			fprintf(stderr, "Playing MPEG stream %lu of %lu: %s ...\n", (unsigned long)pl.pos, (unsigned long)pl.fill, filename);
			if(htd.icy_name.fill) fprintf(stderr, "ICY-NAME: %s\n", htd.icy_name.p);
			if(htd.icy_url.fill)  fprintf(stderr, "ICY-URL: %s\n",  htd.icy_url.p);
		}
#if !defined(GENERIC)
{
	const char *term_type;
	term_type = getenv("TERM");
	if(term_type && param.xterm_title)
	{
		if(!strncmp(term_type,"xterm",5) || !strncmp(term_type,"rxvt",4))
		fprintf(stderr, "\033]0;%s\007", filename);
		else if(!strncmp(term_type,"screen",6))
		fprintf(stderr, "\033k%s\033\\", filename);
		else if(!strncmp(term_type,"iris-ansi",9))
		fprintf(stderr, "\033P1.y %s\033\\\033P3.y%s\033\\", filename, filename);

		fflush(stderr); /* Paranoia: will the buffer buffer the escapes? */
	}
}
#endif

/* Rethink that SIGINT logic... */
#if !defined(WIN32) && !defined(GENERIC)
#ifdef HAVE_TERMIOS
		if(!param.term_ctrl)
#endif
			gettimeofday (&start_time, NULL);
#endif

		while(!intflag)
		{
			int meta;
			if(param.frame_number > -1)
			{
				debug1("frames left: %li", (long) frames_left);
				if(!frames_left)
				{
					if(APPFLAG(MPG123APP_CONTINUE)) end_of_files = TRUE;

					break;
				}
			}
			if(!play_frame()) break;
			if(!param.quiet)
			{
				meta = mpg123_meta_check(mh);
				if(meta & (MPG123_NEW_ID3|MPG123_NEW_ICY))
				{
					if(meta & MPG123_NEW_ID3) print_id3_tag(mh, param.long_id3, stderr);
					if(meta & MPG123_NEW_ICY) print_icy(mh, stderr);

					mpg123_meta_free(mh); /* Do not waste memory after delivering. */
				}
			}
			if(!fresh && param.verbose)
			{
#ifndef NOXFERMEM
				if (param.verbose > 1 || !(framenum & 0x7))
					print_stat(mh,0,xfermem_get_usedspace(buffermem)); 
#else
				if(param.verbose > 1 || !(framenum & 0x7))	print_stat(mh,0,0);
#endif
			}
#ifdef HAVE_TERMIOS
			if(!param.term_ctrl) continue;
			else term_control(mh, ao);
#endif
		}

	if(!param.smooth && param.usebuffer) buffer_drain();
	if(param.verbose) print_stat(mh,0,xfermem_get_usedspace(buffermem)); 

	if(!param.quiet)
	{
		double secs;
		long frank;
		fprintf(stderr, "\n");
		if(mpg123_getstate(mh, MPG123_FRANKENSTEIN, &frank, NULL) == MPG123_OK && frank)
		fprintf(stderr, "This was a Frankenstein track.\n");

		mpg123_position(mh, 0, 0, NULL, NULL, &secs, NULL);
		fprintf(stderr,"[%d:%02d] Decoding of %s finished.\n", (int)(secs / 60), ((int)secs) % 60, filename);
	}
	else if(param.verbose) fprintf(stderr, "\n");

	mpg123_close(mh);

	if (intflag)
	{
		if(!skip_or_die(&start_time)) break;

        intflag = FALSE;

#ifndef NOXFERMEM
        if(!param.smooth && param.usebuffer) buffer_resync();
#endif
	}

		if(end_of_files) break;
	} /* end of loop over input files */

	/* Ensure we played everything. */
	if(param.smooth && param.usebuffer)
	{
		buffer_drain();
		buffer_resync();
	}

	if(APPFLAG(MPG123APP_CONTINUE))
	{
		continue_msg("CONTINUE");
	}

	/* Free up memory used by playlist */    
	if(!param.remote) free_playlist();

	safe_exit(0); /* That closes output and restores terminal, too. */
	return 0;
}
Exemple #21
0
int main(int argc, char *argv[])
{
    int i = 1;

#ifdef __EMX__
    _wildcard(&argc, &argv);   /* Unix-like globbing for OS/2 and DOS */
#endif

    while(argc > 1 && argv[1][0] == '-')
    {
	switch(argv[1][i]) {
	case '\0':
	    argc--;
	    argv++;
	    i = 1;
	    break;
	case 'v':
	    ++verbose;
	    i++;
	    break;
	case 'i':
	    ++idat;
	    i++;
	    break;
	case 'V':
	    fprintf(stdout, "sng version " VERSION " by Eric S. Raymond.\n");
	    exit(0);
	case 'h':
	default:
	    fprintf(stderr, "sng: unknown option %c\n", argv[1][i]);
	    exit(1);
	}
    }

    if (argc == 1)
    {
	if (isatty(0))
	    fprintf(stderr, "sng: usage sng [-v] [file...]\n");
	else
	{
	    int	c = getchar();

	    ungetc(c, stdin);

	    if (isprint(c))
		exit(sngc(stdin, "stdin", stdout));
	    else
		exit(sngd(stdin, "stdin", stdout));
	}
    } 
    else
    {
	for (i = 1; i < argc; i++)
	{
	    int sng2png, dot = strlen(argv[i]) - 4;
	    char outfile[BUFSIZ];
	    FILE	*fpin, *fpout;

	    if (argv[i][dot] != '.')
	    {
		fprintf(stderr, "sng: %s is neither SNG nor PNG\n", argv[i]);
		continue;
	    }
	    else if (strcmp(argv[i] + dot, ".sng") == 0)
	    {
		sng2png = TRUE;
		strncpy(outfile, argv[i], dot);
		outfile[dot] = '\0';
		strcat(outfile, ".png");
	    }
	    else if (strcmp(argv[i] + dot, ".png") == 0)
	    {
		sng2png = FALSE;
		strncpy(outfile, argv[i], dot);
		outfile[dot] = '\0';
		strcat(outfile, ".sng");
	    }
	    else
	    {
		fprintf(stderr, "sng: %s is neither SNG nor PNG\n", argv[i]);
		continue;
	    }

	    if (verbose)
		printf("sng: converting %s to %s\n", argv[i], outfile);

	    if ((fpin = fopen(argv[i], "r")) == NULL)
	    {
		fprintf(stderr,
			"sng: couldn't open %s for input (%d)\n",
			argv[i], errno);
		continue;
	    }
	    if ((fpout = fopen(outfile, "w")) == NULL)
	    {
		fprintf(stderr,
			"sng: couldn't open for output %s (%d)\n",
			outfile, errno);
		continue;
	    }

	    if (sng2png)
		sngc(fpin, argv[i], fpout);
	    else
		sngd(fpin, argv[i], fpout);
	}
    }

    /* This only returns the error on the last file.  Works OK if you are only
     * checking the status of a single file. */
    return sng_error;
}
Exemple #22
0
int main(int argc, const char *argv[])
{
	const char *fs = NULL, *marg;
	int temp;

	__progname = argv[0];
	_wildcard(&argc, &argv);

	setlocale(LC_ALL, "");
	cmdname = __progname;
	if (argc == 1) {
		fprintf(stderr, "Usage: %s [-f programfile | 'program'] [-Ffieldsep] [-v var=value] [-safe] [-mrn] [-mfn] [files]\n", cmdname);
		exit(1);
	}
	signal(SIGFPE, fpecatch);
	yyin = NULL;
	symtab = makesymtab(NSYMTAB);
	while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {
		if (strcmp(argv[1], "--") == 0) {	/* explicit end of args */
			argc--;
			argv++;
			break;
		}
		switch (argv[1][1]) {
		case 's':
			if (strcmp(argv[1], "-safe") == 0)
				safe = 1;
			break;
		case 'f':	/* next argument is program filename */
			argc--;
			argv++;
			if (argc <= 1)
				ERROR "no program filename" FATAL;
			pfile[npfile++] = argv[1];
			break;
		case 'F':	/* set field separator */
			if (argv[1][2] != 0) {	/* arg is -Fsomething */
				if (argv[1][2] == 't' && argv[1][3] == 0)	/* wart: t=>\t */
					fs = "\t";
				else if (argv[1][2] != 0)
					fs = &argv[1][2];
			} else {		/* arg is -F something */
				argc--; argv++;
				if (argc > 1 && argv[1][0] == 't' && argv[1][1] == 0)	/* wart: t=>\t */
					fs = "\t";
				else if (argc > 1 && argv[1][0] != 0)
					fs = &argv[1][0];
			}
			if (fs == NULL || *fs == '\0')
				ERROR "field separator FS is empty" WARNING;
			break;
		case 'v':	/* -v a=1 to be done NOW.  one -v for each */
			if (argv[1][2] == '\0' && --argc > 1 && isclvar((++argv)[1]))
				setclvar((char*)argv[1]);
			break;
		case 'm':	/* more memory: -mr=record, -mf=fields */
				/* no longer needed */
			marg = argv[1];
			if (argv[1][3])
				temp = atoi(&argv[1][3]);
			else {
				argv++; argc--;
				temp = atoi(&argv[1][0]);
			}
			switch (marg[2]) {
			case 'r':	recsize = temp; break;
			case 'f':	nfields = temp; break;
			default: ERROR "unknown option %s\n", marg FATAL;
			}
			break;
		case 'd':
			dbg = atoi(&argv[1][2]);
			if (dbg == 0)
				dbg = 1;
			printf("awk %s\n", version);
			break;
		case 'V':	/* added for exptools "standard" */
			printf("awk %s\n", version);
			exit(0);
			break;
		default:
			ERROR "unknown option %s ignored", argv[1] WARNING;
			break;
		}
		argc--;
		argv++;
	}
	/* argv[1] is now the first argument */
	if (npfile == 0) {	/* no -f; first argument is program */
		if (argc <= 1) {
			if (dbg)
				exit(0);
			ERROR "no program given" FATAL;
		}
		   dprintf( ("program = |%s|\n", argv[1]) );
		lexprog = argv[1];
		argc--;
		argv++;
	}
	recinit(recsize);
	syminit();
	compile_time = 1;
	argv[0] = cmdname;	/* put prog name at front of arglist */
	   dprintf( ("argc=%d, argv[0]=%s\n", argc, argv[0]) );
	arginit(argc, argv);
	if (!safe)
		envinit(environ);
	yyparse();
	if (fs)
		*FS = qstring(fs, '\0');
	   dprintf( ("errorflag=%d\n", errorflag) );
	if (errorflag == 0) {
		compile_time = 0;
		run(winner);
	} else
		bracecheck();
	return(errorflag);
}
Exemple #23
0
int
main (int argc, char **argv)
{

  int frequency, oversample, stereo;
  struct song *song;
  int index;
  int c;
  int opt, error_flag;


  /* supposed to make wildcard expansion */
  _wildcard(&argc,&argv);

  signal (2, nextsong);
  signal (3, goodbye);

  printf("Tracker1 V0.91 for the SBOS2 package\n");

  /* Read environment variables */
  frequency = read_env ("FREQUENCY", 0);
  oversample = read_env ("OVERSAMPLE", 1);
  transpose = read_env ("TRANSPOSE", 0);

  if (getenv ("MONO"))
    pref.stereo = 0;
  else if (getenv ("STEREO"))
    pref.stereo = 1;
  else
    pref.stereo = DEFAULT_CHANNELS - 1;
  pref.type = BOTH;
  pref.repeats = 1;
  pref.speed = 50;
  pref.tolerate = 2;
  pref.verbose = 0;
  set_mix (DEFAULT_MIX);        /* 0 = full stereo, 100 = mono */

  error_flag = 0;
  while ((opt = getopt_long_only (argc, argv, "", long_options, NULL)) != EOF)
    {
      switch (opt)
        {
        case 'H':               /* help */
          error_flag++;
          break;
        case 'Q':               /* quiet */
          quiet++;
          break;
        case 'P':               /* abort on faults (be picky) */
          pref.tolerate = 0;
          break;
        case 'N':               /* new tracker type */
          pref.type = NEW;
          break;
        case 'O':               /* old tracker type */
          pref.type = OLD;
          break;
        case 'B':               /* both tracker types */
          pref.type = BOTH;
          break;
        case 'M':               /* mono */
          pref.stereo = 0;
          break;
        case 'S':               /* stereo */
          pref.stereo = 1;
          break;
        case 'V':
          pref.verbose = 1;
          break;
        case 'f':               /* frequency */
          frequency = atoi (optarg);
          break;
        case 'o':               /* oversampling */
          oversample = atoi (optarg);
          break;
        case 't':               /* transpose half-steps*/
          transpose = atoi (optarg);
          break;
        case 'r':               /* number of repeats */
          pref.repeats = atoi (optarg);
          break;
        case 's':               /* speed */
          pref.speed = atoi (optarg);
          break;
        case 'm':               /* % of channel mix.  100=mono */
          set_mix (atoi (optarg));
          break;
        default:                /* ??? */
          error_flag++;
          break;
        }
    }
  if (error_flag || !argv[optind])
    {
      fprintf (stderr, "Usage: %s " USAGE, argv[0]);
      exit(1);
    }

  frequency = open_audio (frequency);
  init_player (oversample, frequency);

  while (argv[optind])
    {
      switch (pref.type)
        {
        case BOTH:
          song = do_read_song (argv[optind], NEW);
          if (!song)
            song = do_read_song (argv[optind], OLD);
          break;
        case OLD:
          song = do_read_song (argv[optind], pref.type);
          break;
        case NEW:
          /* this is explicitly flagged as a new module,
           * so we don't need to look for a signature.
           */
          song = do_read_song (argv[optind], NEW_NO_CHECK);
          break;
        }
      optind++;
      if (song == NULL)
        continue;

      dump_song (song);
      play_song (song, &pref);
      release_song (song);

      /* flush out anything remaining in DMA buffers */
      flush_DMA_buffers();

    }

  close_audio ();
  return 0;
}