## Synopsis
- `nsub --help`
-- `nsub` (`--from FMT`) (`--to FMT`) (`--apply-offset`) (`IN` (`OUT`))
-- `nsub` (`-f FMT`) (`-t FMT`) (`-o`) (`IN` (`OUT`))
+- `nsub` (`--from FMT`) (`--to FMT`) (`--apply-offset`) (--output `OUT`) (`IN`)
+- `nsub` (`-f FMT`) (`-t FMT`) (`-a`) (`-o OUT`) (`IN`)
## Description
## Options
-- **--help** (or **-h**) : information sur la syntaxe du programme
-- **--from** (or **-f**) **FMT** : choisi le format d'entrée
-- **--to** (or **-t**) **FMT** : choisi le format de sortie
-- **--apply-offset** (or **-o**) : applique l'offset interne au fichier dans les calcul de temps des paroles
+- **--help** (ou **-h**) : information sur la syntaxe du programme
+- **--from** (ou **-f**) **FMT** : choisi le format d'entrée
+- **--to** (ou **-t**) **FMT** : choisi le format de sortie
+- **--apply-offset** (ou **-a**) : applique l'offset interne au fichier dans les calcul de temps des paroles
+- **--output** (ou **-o**) **OUT**: le fichier destination ou '-' pour stdout (défaut)
- **IN** : le fichier source ou '-' pour stdin (défaut)
-- **OUT** : le fichier destination ou '-' pour stdout (défaut)
Note : les formats in/out seront devinés en fonction de l'extension si nécessaire/possible
Note : pour spécifier un fichier appelé tiret (-), préfixez-le avec un chemin (ex : './-')
## Synopsis
- `nsub --help`
-- `nsub` (`--from FMT`) (`--to FMT`) (`--apply-offset`) (`IN` (`OUT`))
-- `nsub` (`-f FMT`) (`-t FMT`) (`-o`) (`IN` (`OUT`))
+- `nsub` (`--from FMT`) (`--to FMT`) (`--apply-offset`) (--output `OUT`) (`IN`)
+- `nsub` (`-f FMT`) (`-t FMT`) (`-a`) (`-o OUT`) (`IN`)
## Description
- **--help** (or **-h**): information about the syntax
- **--from** (or **-f**) **FMT**: select the input format FMT
- **--to** (or **-t**) **FMT**: select the output format FMT
-- **--apply-offset** (or **-o**): apply the offset tag value to the lyrics
+- **--apply-offset** (or **-a**): apply the offset tag value to the lyrics
+- **--output** (or **-o**) **OUT**: the output file or '-' for stdout (which is the default)
- **IN**: the input file or '-' for stdin (which is the default)
-- **OUT**: the output file or '-' for stdout (which is the default)
Note: the in/out formats will be guessed from the extension if needed/possible
Note: to specify a file named dash (-), prefix it with a path (e.g., './-')
char *out_file = NULL;
int apply_offset = 0;
+ if (argc <= 1) {
+ help(argv[0]);
+ return 5;
+ }
+
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (!strcmp("--help", arg) || !strcmp("-h", arg)) {
fprintf(stderr, "Unsupported output format: %s\n", argv[i]);
return 9;
}
- } else if (!strcmp("--apply-offset", arg) || !strcmp("-o", arg)) {
+ } else if (!strcmp("--apply-offset", arg) || !strcmp("-a", arg)) {
apply_offset = 1;
+ } else if (!strcmp("--output", arg) || !strcmp("-o", arg)) {
+ if (i + 1 >= argc) {
+ fprintf(stderr,
+ "The parameter --output/-o requires an argument\n");
+ return 5;
+ }
+ out_file = argv[++i];
+ if (to == NSUB_FMT_UNKNOWN) {
+ char *ext = strrchr(arg, '.');
+ if (ext) {
+ ext++;
+ to = nsub_parse_fmt(ext, 0);
+ }
+ }
} else if (!in_file) {
in_file = arg;
if (from == NSUB_FMT_UNKNOWN) {
void help(char *program) {
printf("NSub subtitles conversion program\n");
printf("Syntax:\n");
- printf(
- "\t%s (--from FMT) (--to FMT) (--apply-offset) (IN_FILE (OUT_FILE))\n",
- program);
+ printf("\t%s (--from FMT) (--to FMT) (--apply-offset)\n"
+ "\t\t (--output OUT_FILE) (IN_FILE)\n", program);
printf("\t> --help (or -h): this help message\n");
printf("\t> --from (or -f) FMT: select the input format FMT\n");
printf("\t> --to (or -t) FMT: select the output format FMT\n");
printf(
- "\t> --apply-offset (or -o): apply the offset tag value to the lyrics\n");
+ "\t> --apply-offset (or -a): apply the offset tag value to the lyrics\n");
printf(
"\t> IN_FILE: the input file or '-' for stdin (which is the default)\n");
printf(