diff options
-rwxr-xr-x | xdelta3/xdelta3-main.h | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index 848f709..5d8b51e 100755 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h | |||
@@ -2810,6 +2810,55 @@ main_cleanup (void) | |||
2810 | XD3_ASSERT (main_mallocs == 0); | 2810 | XD3_ASSERT (main_mallocs == 0); |
2811 | } | 2811 | } |
2812 | 2812 | ||
2813 | static void | ||
2814 | setup_environment (int argc, | ||
2815 | char **argv, | ||
2816 | int *argc_out, | ||
2817 | char ***argv_out, | ||
2818 | char ***argv_free, | ||
2819 | char **env_free) | ||
2820 | { | ||
2821 | int n, i, i0; | ||
2822 | char *p, *v = getenv("XDELTA"); | ||
2823 | if (v == NULL) { | ||
2824 | (*argc_out) = argc; | ||
2825 | (*argv_out) = argv; | ||
2826 | return; | ||
2827 | } | ||
2828 | *env_free = main_malloc(strlen(v) + 1); | ||
2829 | strcpy(*env_free, v); | ||
2830 | |||
2831 | /* Space needed for new argv: count spaces */ | ||
2832 | n = argc + 1; | ||
2833 | for (p = *env_free; *p != 0; ) { | ||
2834 | if (*p++ == ' ') { | ||
2835 | n++; | ||
2836 | } | ||
2837 | } | ||
2838 | |||
2839 | (*argc_out) = n; | ||
2840 | (*argv_out) = main_malloc(sizeof(char*) * (n + 1)); | ||
2841 | (*argv_out)[0] = argv[0]; | ||
2842 | (*argv_out)[n] = NULL; | ||
2843 | |||
2844 | i = 1; | ||
2845 | for (p = *env_free; *p != 0; ) { | ||
2846 | (*argv_out)[i++] = p; | ||
2847 | while (*p != ' ' && *p != 0) { | ||
2848 | p++; | ||
2849 | } | ||
2850 | if (*p == ' ') { | ||
2851 | *p++ = 0; | ||
2852 | } | ||
2853 | } | ||
2854 | |||
2855 | for (i0 = 1; i0 < argc; i0++) { | ||
2856 | (*argv_out)[i++] = argv[i0]; | ||
2857 | } | ||
2858 | |||
2859 | XD3_ASSERT (i == n); | ||
2860 | } | ||
2861 | |||
2813 | int | 2862 | int |
2814 | #if PYTHON_MODULE || SWIG_MODULE | 2863 | #if PYTHON_MODULE || SWIG_MODULE |
2815 | xd3_main_cmdline (int argc, char **argv) | 2864 | xd3_main_cmdline (int argc, char **argv) |
@@ -2826,8 +2875,10 @@ main (int argc, char **argv) | |||
2826 | char *my_optarg; | 2875 | char *my_optarg; |
2827 | char *my_optstr; | 2876 | char *my_optstr; |
2828 | char *sfilename; | 2877 | char *sfilename; |
2829 | int orig_argc = argc; | 2878 | int env_argc; |
2830 | char **orig_argv = argv; | 2879 | char **env_argv; |
2880 | char **free_argv = NULL; /* malloced */ | ||
2881 | char *free_value = NULL; /* malloced */ | ||
2831 | int ret; | 2882 | int ret; |
2832 | 2883 | ||
2833 | #ifdef _WIN32 | 2884 | #ifdef _WIN32 |
@@ -2842,11 +2893,12 @@ main (int argc, char **argv) | |||
2842 | 2893 | ||
2843 | go: /* Go. */ | 2894 | go: /* Go. */ |
2844 | cmd = CMD_NONE; | 2895 | cmd = CMD_NONE; |
2896 | setup_environment(argc, argv, &env_argc, &env_argv, &free_argv, &free_value); | ||
2845 | sfilename = NULL; | 2897 | sfilename = NULL; |
2846 | my_optind = 1; | 2898 | my_optind = 1; |
2847 | argv = orig_argv; | 2899 | argv = env_argv; |
2848 | argc = orig_argc; | 2900 | argc = env_argc; |
2849 | program_name = argv[0]; | 2901 | program_name = env_argv[0]; |
2850 | extcomp_types[0].recomp_cmdname = program_name; | 2902 | extcomp_types[0].recomp_cmdname = program_name; |
2851 | extcomp_types[0].decomp_cmdname = program_name; | 2903 | extcomp_types[0].decomp_cmdname = program_name; |
2852 | takearg: | 2904 | takearg: |
@@ -3177,6 +3229,9 @@ main (int argc, char **argv) | |||
3177 | 3229 | ||
3178 | main_cleanup (); | 3230 | main_cleanup (); |
3179 | 3231 | ||
3232 | main_free (free_argv); | ||
3233 | main_free (free_value); | ||
3234 | |||
3180 | if (--option_profile_cnt > 0 && ret == EXIT_SUCCESS) { goto go; } | 3235 | if (--option_profile_cnt > 0 && ret == EXIT_SUCCESS) { goto go; } |
3181 | 3236 | ||
3182 | fflush (stdout); | 3237 | fflush (stdout); |