1 /*  mode.h - mode module definitions
2  *  Copyright (C) 2000-2009  Jason Jordan <shnutils@freeshell.org>
3  *
4  *  This program is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU General Public License
6  *  as published by the Free Software Foundation; either version 2
7  *  of the License, or (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 /*
20  * $Id: mode.h,v 1.39 2009/03/30 06:44:42 jason Exp $
21  */
22 
23 #ifndef __MODE_H__
24 #define __MODE_H__
25 
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include "format-types.h"
29 #include "mode-types.h"
30 #include "module.h"
31 #include "binary.h"
32 
33 /* default output directories */
34 #define CURRENT_DIR    "."
35 #define INPUT_FILE_DIR ""
36 
37 /* various buffer sizes */
38 #define BUF_SIZE  2048
39 #define XFER_SIZE 262144
40 
41 /* error codes */
42 #define ST_EXIT_SUCCESS 0
43 #define ST_EXIT_ERROR   1
44 #define ST_EXIT_QUIT    255
45 
46 /* global mode-accessible options */
47 extern global_opts st_ops;
48 
49 /* function to open an input stream and skip past the ID3v2 tag, if one exists */
50 bool open_input_stream(wave_info *);
51 
52 /* function to handle command-line option parsing with global (i.e. non-mode-specific) options */
53 int st_getopt(int,char **,char *);
54 
55 /* global usage screen */
56 void st_global_usage();
57 
58 /* returns program name ("prog mode" or "alias") */
59 char *st_progname(void);
60 
61 /* function to convert a file's length to m:ss or m:ss.ff format */
62 void length_to_str(wave_info *);
63 
64 /* close a file descriptor, and wait for a child process if necessary */
65 int close_and_wait(FILE *,proc_info *,int,format_module *);
66 #define close_input(a,b)       close_and_wait(a,&b,CHILD_INPUT,NULL)
67 #define close_output(a,b)      close_and_wait(a,&b,CHILD_OUTPUT,NULL)
68 #define close_input_stream(a)  close_and_wait(a->input,&a->input_proc,CHILD_INPUT,a->input_format)
69 #define close_output_stream(a) close_and_wait(a->output,&a->output_proc,CHILD_OUTPUT,NULL)
70 
71 /* function to discard the WAVE header, leaving the file pointer at the beginning of the audio data */
72 void discard_header(wave_info *);
73 
74 /* wrapper function to name output filename based on input filename and extension */
75 void create_output_filename(char *,char *,char *);
76 
77 /* wrapper function to open an output stream */
78 FILE *open_output_stream(char *,proc_info *);
79 
80 /* function to determine if two filenames point to the same file */
81 int files_are_identical(char *,char *);
82 
83 /* function to remove a file if it exists */
84 void remove_file(char *);
85 
86 /* a simple menu system to alter the order in which given input files will be processed */
87 void alter_file_order(wave_info **,int);
88 
89 /* function to reorder files based on user preference */
90 void reorder_files(wave_info **,int);
91 
92 /* functions to aid in parsing input length formats */
93 wlong smrt_parse(unsigned char *,wave_info *);
94 
95 /* function to determine whether odd-sized data chunks are NULL-padded to an even length */
96 bool odd_sized_data_chunk_is_null_padded(wave_info *);
97 
98 /* functions for building argument lists in format modules */
99 void arg_reset(child_args *);
100 void arg_add(child_args *,char *);
101 void arg_replace(child_args *,int,char *);
102 
103 /* functions for progress output */
104 void prog_update(progress_info *);
105 void prog_success(progress_info *);
106 void prog_error(progress_info *);
107 
108 /* functions for managing the input file source */
109 void input_init(int,int,char **);
110 char *input_get_filename();
111 void input_read_all_files();
112 int input_get_file_count();
113 
114 #endif
115