Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
fix for tracker item 3580176: environment variable LAMEOPT doesn't wo…
Browse files Browse the repository at this point in the history
…rk anymore
  • Loading branch information
Robert Hegemann committed Oct 25, 2012
1 parent c2018f1 commit e90cf55
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 48 deletions.
2 changes: 2 additions & 0 deletions doc/html/history.html
Expand Up @@ -70,6 +70,8 @@ <h3>LAME 3.100&nbsp; &nbsp;not yet released</h3>
</li>
<li>Fix for tracker item <i>[ 3544957 ] scale (empty) silent encode without warning</i>
</li>
<li>Fix for tracker item <i>[ 3580176 ] environment variable LAMEOPT doesn't work anymore</i>
</li>
</ul>
</li>
</ul>
Expand Down
42 changes: 1 addition & 41 deletions frontend/lame_main.c
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (c) 1999 Mark Taylor
* 2000 Takehiro TOMINAGA
* 2010-2011 Robert Hegemann
* 2010-2012 Robert Hegemann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -94,41 +94,6 @@ char *strchr(), *strrchr();
************************************************************************/


static int
parse_args_from_string(lame_global_flags * const gfp, const char *p, char *inPath, char *outPath)
{ /* Quick & very Dirty */
char *q;
char *f;
char *r[128];
int c = 0;
int ret;

if (p == NULL || *p == '\0')
return 0;

f = q = malloc(strlen(p) + 1);
strcpy(q, p);

r[c++] = "lhama";
for (;;) {
r[c++] = q;
while (*q != ' ' && *q != '\0')
q++;
if (*q == '\0')
break;
*q++ = '\0';
}
r[c] = NULL;

ret = parse_args(gfp, c, r, inPath, outPath, NULL, NULL);
free(f);
return ret;
}





static FILE *
init_files(lame_global_flags * gf, char const *inPath, char const *outPath)
{
Expand Down Expand Up @@ -647,11 +612,6 @@ lame_main(lame_t gf, int argc, char **argv)
* 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)
*/
{
char *str = lame_getenv("LAMEOPT");
parse_args_from_string(gf, str, inPath, outPath);
free(str);
}
ret = parse_args(gf, argc, argv, inPath, outPath, nogap_inPath, &max_nogap);
if (ret < 0) {
return ret == -2 ? 0 : 1;
Expand Down
10 changes: 5 additions & 5 deletions frontend/main.c
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (c) 1999 Mark Taylor
* 2000 Takehiro TOMINAGA
* 2010-2011 Robert Hegemann
* 2010-2012 Robert Hegemann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -407,13 +407,13 @@ char* lame_getenv(char const* var)
{
char* str = 0;
wchar_t* wvar = utf8ToUnicode(var);
wchar_t* wstr = 0;
if (wvar != 0) {
wstr = _wgetenv(wvar);
str = unicodeToUtf8(wstr);
wchar_t* wstr = _wgetenv(wvar);
if (wstr != 0) {
str = unicodeToUtf8(wstr);
}
}
free(wvar);
free(wstr);
return str;
}

Expand Down
88 changes: 86 additions & 2 deletions frontend/parse.c
Expand Up @@ -1499,8 +1499,8 @@ static int dev_only_without_arg(char const* str, char const* token, int* argIgno
} else if (dev_only_with_arg(str,token,nextArg,&argIgnored,&argUsed)) {


int
parse_args(lame_global_flags * gfp, int argc, char **argv,
static int
parse_args_(lame_global_flags * gfp, int argc, char **argv,
char *const inPath, char *const outPath, char **nogap_inPath, int *num_nogap)
{
char outDir[1024] = "";
Expand Down Expand Up @@ -2511,5 +2511,89 @@ parse_args(lame_global_flags * gfp, int argc, char **argv,
return 0;
}

static int
string_to_argv(char* str, char** argv, int N)
{
int argc = 0;
if (str == 0) return argc;
argv[argc++] = "lhama";
for (;;) {
int quoted = 0;
while (isspace(*str)) { /* skip blanks */
++str;
}
if (*str == '\"') { /* is quoted argument ? */
quoted = 1;
++str;
}
if (*str == '\0') { /* end of string reached */
break;
}
/* found beginning of some argument */
if (argc < N) {
argv[argc++] = str;
}
/* look out for end of argument, either end of string, blank or quote */
for(; *str != '\0'; ++str) {
if (quoted) {
if (*str == '\"') { /* end of quotation reached */
*str++ = '\0';
break;
}
}
else {
if (isspace(*str)) { /* parameter separator reached */
*str++ = '\0';
break;
}
}
}
}
return argc;
}

static int
merge_argv(int argc, char** argv, int str_argc, char** str_argv, int N)
{
int i;
if (argc > 0) {
str_argv[0] = argv[0];
if (str_argc < 1) str_argc = 1;
}
for (i = 1; i < argc; ++i) {
int j = str_argc + i - 1;
if (j < N) {
str_argv[j] = argv[i];
}
}
return argc + str_argc - 1;
}

#ifdef DEBUG
static void
dump_argv(int argc, char** argv)
{
int i;
for (i = 0; i < argc; ++i) {
printf("%d: \"%s\"\n",i,argv[i]);
}
}
#endif


int parse_args(lame_t gfp, int argc, char **argv, char *const inPath, char *const outPath, char **nogap_inPath, int *num_nogap)
{
char *str_argv[512], *str;
int str_argc, ret;
str = lame_getenv("LAMEOPT");
str_argc = string_to_argv(str, str_argv, dimension_of(str_argv));
str_argc = merge_argv(argc, argv, str_argc, str_argv, dimension_of(str_argv));
#ifdef DEBUG
dump_argv(str_argc, str_argv);
#endif
ret = parse_args_(gfp, str_argc, str_argv, inPath, outPath, nogap_inPath, num_nogap);
free(str);
return ret;
}

/* end of parse.c */

0 comments on commit e90cf55

Please sign in to comment.