Ejemplo n.º 1
0
Archivo: erl.c Proyecto: Airon2014/otp
static void get_parameters(void)
{
    wchar_t buffer[MAX_PATH];
    wchar_t *ini_filename;
    HANDLE module = GetModuleHandle(NULL);
    InitFile *inif;
    InitSection *inis;
    char *utf8dir;
    int len;


    if (module = NULL) {
        error("Cannot GetModuleHandle()");
    }

    if (GetModuleFileNameW(module,buffer,MAX_PATH) == 0) {
        error("Could not GetModuleFileName");
    }

    ini_filename = replace_filename(buffer,INI_FILENAME);

    if ((inif = load_init_file(ini_filename)) == NULL) {
	erlexec_dir = find_erlexec_dir(ini_filename);
	SetEnvironmentVariableW(L"ERLEXEC_DIR", erlexec_dir);
    } else {

      if ((inis = lookup_init_section(inif,INI_SECTION)) == NULL) {
	error("Could not find section %s in init file %S",
	      INI_SECTION, ini_filename);
      }
      
      utf8dir = do_lookup_in_section(inis, "Bindir", INI_SECTION, ini_filename);
      len = MultiByteToWideChar(CP_UTF8, 0, utf8dir, -1, NULL, 0);
      erlexec_dir = malloc(len*sizeof(wchar_t));
      MultiByteToWideChar(CP_UTF8, 0, utf8dir, -1, erlexec_dir, len);
      if(len == 0) {
	  error("Bindir is not a valid utf8 '%s' in init file %S",
		utf8dir, ini_filename);
      }
      free_init_file(inif);
    }
    
    erlexec_name = malloc((wcslen(erlexec_dir) + wcslen(ERLEXEC_BASENAME) + 2)*sizeof(wchar_t));
    wcscpy(erlexec_name,erlexec_dir);
    wcscat(erlexec_name, L"\\" ERLEXEC_BASENAME);
    
    free(ini_filename);
}
Ejemplo n.º 2
0
int wmain(int argc, wchar_t **argv) 
{
    int silent = 0;
    int start_sasl = 0;
    wchar_t *root = NULL;
    int i;
    wchar_t buffer[MAX_PATH];
    wchar_t erts_dir[MAX_PATH];
    wchar_t release_dir[MAX_PATH];
    wchar_t bin_dir[MAX_PATH];
    char *tmp;
    char tmp_utf8[MAX_PATH*4];
    wchar_t my_ini_filename[MAX_PATH];
    InitFile *my_ini_file;
    InitSection *my_ini_section;
    char erts_version[MAX_PATH];
    InitFile *ini_file;
    InitSection *ini_section;
    HANDLE module = GetModuleHandle(NULL);
    wchar_t *binaries[] = { L"erl.exe", L"werl.exe", L"erlc.exe",
			    L"dialyzer.exe", L"typer.exe",
			    L"escript.exe", L"ct_run.exe", NULL };
    wchar_t *scripts[] = { L"start_clean.boot", L"start_sasl.boot", NULL };
    wchar_t fromname[MAX_PATH];
    wchar_t toname[MAX_PATH];
    size_t  converted;

    for (i = 1; i < argc; ++i) {
	switch(argv[i][0]) {
	case L'-' :
	    switch(argv[i][1]) {
	    case L's' :
		silent = 1;
		break;
	    default:
		fprintf(stderr, "Unknown command switch %S\n",
			argv[i]);
		exit(1);
	    }
	    break;
	default: {
	    if (root != NULL) {
		fprintf(stderr, "Only one root directory can be specified, "
			"parameter %S is illegal\n",
			argv[i]);
		exit(1);
	    }	    
	    root = argv[i];
	    }
	    break;
	}
    }
    if (root == NULL) {
	if (module = NULL) {
	    fprintf(stderr, "Cannot GetModuleHandle()\n");
	    exit(1);
	}

	if (GetModuleFileNameW(module,buffer,MAX_PATH) == 0) {
	    fprintf(stderr,"Could not GetModuleFileName()\n");
	    exit(1);
	}
	i = wcslen(buffer) - 1;
	while ( i >= 0 && buffer[i] != L'\\') {
	    --i;
	}
	if (i < 0) {
	    fprintf(stderr,"GetModuleFileName returned broken path\n");
	    exit(1);
	}
	buffer[i] = L'\0';
	root = buffer;
    }

    if (!silent) {
	char answer[100];
	char *eol;
	start_sasl = 1;
	printf("Do you want a minimal startup instead of sasl [No]: ");
	fflush(stdout);
	if (fgets(answer,100,stdin) == NULL) {
	    fprintf(stderr, "Could not read answer from user.\n");
	    exit(1);
	}
	eol = strchr(answer,'\n');
	if (eol == NULL) {
	    while (getchar() != '\n')
		;
	} else {
	    *eol = '\0';
	}
	if ((eol = strchr(answer, '\r')) != NULL) {
	    *eol = '\0';
	}
	if (_stricmp(answer,"yes") == 0 || _stricmp(answer,"y") == 0) {
	    start_sasl = 0;
	}
    }
    swprintf(my_ini_filename, MAX_PATH, L"%s\\Install.ini", root);
    my_ini_file = load_init_file(my_ini_filename);
    if (my_ini_file == NULL) {
	fprintf(stderr,"Cannot open init file %S\n",my_ini_filename);
	exit(1);
    }
    
    if ((my_ini_section = lookup_init_section(my_ini_file,"Install")) 
	== NULL) {
	fprintf(stderr,"No [Install] section in init file %S\n",
		my_ini_filename);
	exit(1);
    }
    
    if ((tmp = lookup_init_entry(my_ini_section, "VSN")) == NULL) {
	fprintf(stderr,"No key VSN in init file %S\n",
		my_ini_filename);
	exit(1);
    }
    strcpy(erts_version,tmp);
    
    swprintf(erts_dir,MAX_PATH,L"%s\\erts-%S\\bin",root,erts_version);
    if ((tmp = lookup_init_entry(my_ini_section, "SYSTEM_VSN")) == NULL) {
	fprintf(stderr,"No key SYSTEM_VSN in init file %S\n",
		 my_ini_filename);
	exit(1);
    }
    swprintf(release_dir,MAX_PATH,L"%s\\releases\\%S",root,tmp); 

    swprintf(bin_dir,MAX_PATH,L"%s\\bin",root);
    CreateDirectoryW(bin_dir,NULL);

    free_init_file(my_ini_file);
    
    for (i = 0; binaries[i] != NULL; ++i) {
	swprintf(fromname,MAX_PATH,L"%s\\%s",erts_dir,binaries[i]);
	swprintf(toname,MAX_PATH,L"%s\\%s",bin_dir,binaries[i]);
	if (GetFileAttributesW(fromname) == 0xFFFFFFFF) {
	    fprintf(stderr,"Could not find file %S\n",
		    fromname);
	    exit(1);
	}
	if (!CopyFileW(fromname,toname,FALSE)) {
	    fprintf(stderr,"Could not copy file %S to %S\n",
		    fromname,toname);
	    fprintf(stderr,"Continuing installation anyway...\n");
	}
    }
    
    for (i = 0; scripts[i] != NULL; ++i) {
	swprintf(fromname,MAX_PATH,L"%s\\%s",release_dir,scripts[i]);
	swprintf(toname,MAX_PATH,L"%s\\%s",bin_dir,scripts[i]);
	if (GetFileAttributesW(fromname) == 0xFFFFFFFF) {
	    fprintf(stderr,"Could not find file %S\n",
		    fromname);
	    exit(1);
	}
	if (!CopyFileW(fromname,toname,FALSE)) {
	    fprintf(stderr,"Could not copy file %S to %S\n",
		    fromname,toname);
	    fprintf(stderr,"Cannot continue installation, bailing out.\n");
	    exit(1);
	}
    }
    if (start_sasl) {
	swprintf(fromname,MAX_PATH,L"%s\\start_sasl.boot",bin_dir);
    } else {
	swprintf(fromname,MAX_PATH,L"%s\\start_clean.boot",bin_dir);
    }
    swprintf(toname,MAX_PATH,L"%s\\start.boot",bin_dir);
    if (!CopyFileW(fromname,toname,FALSE)) {
	fprintf(stderr,"Could not copy file %S to %S\n",
		fromname,toname);
	fprintf(stderr,"Cannot continue installation, bailing out.\n");
	exit(1);
    }

    /* OBS!!! If the format of the init file is changed, do not forget
       to update release_handler:write_ini_file(...) */
    ini_file = create_init_file();
    ini_section = create_init_section("erlang");
    add_init_section(ini_file,ini_section);
    WideCharToMultiByte(CP_UTF8,0,erts_dir,-1,tmp_utf8,MAX_PATH*4,NULL,NULL);
    add_init_entry(ini_section,"Bindir",tmp_utf8);
    add_init_entry(ini_section,"Progname","erl");
    WideCharToMultiByte(CP_UTF8,0,root,-1,tmp_utf8,MAX_PATH*4,NULL,NULL);
    add_init_entry(ini_section,"Rootdir",tmp_utf8);
    swprintf(fromname,MAX_PATH,L"%s\\erl.ini",erts_dir);
    swprintf(toname,MAX_PATH,L"%s\\erl.ini",bin_dir);
    if (store_init_file(ini_file,fromname) != 0) {
	fprintf(stderr,"Could not create file %S\n",
		fromname);
	fprintf(stderr,"Cannot continue installation, bailing out.\n");
	exit(1);
    }
    if (!CopyFileW(fromname,toname,FALSE)) {
	fprintf(stderr,"Could not copy file %S to %S\n",
		 fromname,toname);
	fprintf(stderr,"Cannot continue installation, bailing out.\n");
	exit(1);
    }
    if (!silent) {
	printf("Erlang %s installed successfully\n", erts_version);
    }
    return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv) 
{
    int silent = 0;
    int start_sasl = 0;
    char *root = NULL;
    int i;
    char buffer[MAX_PATH];
    char erts_dir[MAX_PATH];
    char release_dir[MAX_PATH];
    char bin_dir[MAX_PATH];
    char *tmp;
    char my_ini_filename[MAX_PATH];
    InitFile *my_ini_file;
    InitSection *my_ini_section;
    char version_string[MAX_PATH];
    InitFile *ini_file;
    InitSection *ini_section;
    HANDLE module = GetModuleHandle(NULL);
    char *binaries[] = { "erl.exe", "werl.exe", "erlc.exe",
			     "dialyzer.exe", "typer.exe",
			     "escript.exe", NULL };
    char *scripts[] = { "start_clean.boot", "start_sasl.boot", NULL };
    char fromname[MAX_PATH];
    char toname[MAX_PATH];
    

    for (i = 1; i < argc; ++i) {
	switch(argv[i][0]) {
	case '-' :
	    switch(argv[i][1]) {
	    case 's' :
		silent = 1;
		break;
	    default:
		fprintf(stderr, "Unknown command switch %s\n",
			argv[i]);
		exit(1);
	    }
	    break;
	default:
	    if (root != NULL) {
		fprintf(stderr, "Only one root directory can be specified, "
			"parameter %s is illegal\n",
			argv[i]);
		exit(1);
	    }
	    root = argv[i];
	    break;
	}
    }
    if (root == NULL) {
	if (module = NULL) {
	    fprintf(stderr, "Cannot GetModuleHandle()\n");
	    exit(1);
	}

	if (GetModuleFileName(module,buffer,MAX_PATH) == 0) {
	    fprintf(stderr,"Could not GetModuleFileName()\n");
	    exit(1);
	}
	i = strlen(buffer) - 1;
	while ( i >= 0 && buffer[i] != '\\') {
	    --i;
	}
	if (i < 0) {
	    fprintf(stderr,"GetModuleFileName returned broken path\n");
	    exit(1);
	}
	buffer[i] = '\0';
	root = buffer;
    }

    if (!silent) {
	char answer[100];
	char *eol;
	start_sasl = 1;
	printf("Do you want a minimal startup instead of sasl [No]: ");
	fflush(stdout);
	if (fgets(answer,100,stdin) == NULL) {
	    fprintf(stderr, "Could not read answer from user.\n");
	    exit(1);
	}
	eol = strchr(answer,'\n');
	if (eol == NULL) {
	    while (getchar() != '\n')
		;
	} else {
	    *eol = '\0';
	}
	if ((eol = strchr(answer, '\r')) != NULL) {
	    *eol = '\0';
	}
	if (_stricmp(answer,"yes") == 0 || _stricmp(answer,"y") == 0) {
	    start_sasl = 0;
	}
    }
    sprintf(my_ini_filename,"%s\\Install.ini",root);
    my_ini_file = load_init_file(my_ini_filename);
    if (my_ini_file == NULL) {
	fprintf(stderr,"Cannot open init file %s\n",my_ini_filename);
	exit(1);
    }
    
    if ((my_ini_section = lookup_init_section(my_ini_file,"Install")) 
	== NULL) {
	fprintf(stderr,"No [Install] section in init file %s\n",
		my_ini_filename);
	exit(1);
    }
    
    if ((tmp = lookup_init_entry(my_ini_section, "VSN")) == NULL) {
	fprintf(stderr,"No key VSN in init file %s\n",
		my_ini_filename);
	exit(1);
    }

    strcpy(version_string,tmp);
    
    sprintf(erts_dir,"%s\\erts-%s\\bin",root,tmp);
    if ((tmp = lookup_init_entry(my_ini_section, "SYSTEM_VSN")) == NULL) {
	fprintf(stderr,"No key SYSTEM_VSN in init file %s\n",
		my_ini_filename);
	exit(1);
    }
    sprintf(release_dir,"%s\\releases\\%s",root,tmp); 

    sprintf(bin_dir,"%s\\bin",root);
    CreateDirectory(bin_dir,NULL);

    free_init_file(my_ini_file);
    
    for (i = 0; binaries[i] != NULL; ++i) {
	sprintf(fromname,"%s\\%s",erts_dir,binaries[i]);
	sprintf(toname,"%s\\%s",bin_dir,binaries[i]);
	if (GetFileAttributes(fromname) == 0xFFFFFFFF) {
	    fprintf(stderr,"Could not find file %s\n",
		    fromname);
	    exit(1);
	}
	if (!CopyFile(fromname,toname,FALSE)) {
	    fprintf(stderr,"Could not copy file %s to %s\n",
		    fromname,toname);
	    fprintf(stderr,"Continuing installation anyway...\n");
	}
    }

    for (i = 0; scripts[i] != NULL; ++i) {
	sprintf(fromname,"%s\\%s",release_dir,scripts[i]);
	sprintf(toname,"%s\\%s",bin_dir,scripts[i]);
	if (GetFileAttributes(fromname) == 0xFFFFFFFF) {
	    fprintf(stderr,"Could not find file %s\n",
		    fromname);
	    exit(1);
	}
	if (!CopyFile(fromname,toname,FALSE)) {
	    fprintf(stderr,"Could not copy file %s to %s\n",
		    fromname,toname);
	    fprintf(stderr,"Cannot continue installation, bailing out.\n");
	    exit(1);
	}
    }
    if (start_sasl) {
	sprintf(fromname,"%s\\start_sasl.boot",bin_dir);
    } else {
	sprintf(fromname,"%s\\start_clean.boot",bin_dir);
    }
    sprintf(toname,"%s\\start.boot",bin_dir);
    if (!CopyFile(fromname,toname,FALSE)) {
	fprintf(stderr,"Could not copy file %s to %s\n",
		fromname,toname);
	fprintf(stderr,"Cannot continue installation, bailing out.\n");
	exit(1);
    }
    ini_file = create_init_file();
    ini_section = create_init_section("erlang");
    add_init_section(ini_file,ini_section);
    add_init_entry(ini_section,"Bindir",erts_dir);
    add_init_entry(ini_section,"Progname","erl");
    add_init_entry(ini_section,"Rootdir",root);
    sprintf(fromname,"%s\\erl.ini",erts_dir);
    sprintf(toname,"%s\\erl.ini",bin_dir);
    if (store_init_file(ini_file,fromname) != 0) {
	fprintf(stderr,"Could not create file %s\n",
		fromname);
	fprintf(stderr,"Cannot continue installation, bailing out.\n");
	exit(1);
    }
    if (!CopyFile(fromname,toname,FALSE)) {
	fprintf(stderr,"Could not copy file %s to %s\n",
		fromname,toname);
	fprintf(stderr,"Cannot continue installation, bailing out.\n");
	exit(1);
    }
    if (!silent) {
	printf("Erlang %s installed successfully\n", version_string);
    }
    return 0;
}
Ejemplo n.º 4
0
static void get_parameters(int argc, char** argv)
{
    char *p;
    char buffer[MAX_PATH];
    char *ini_filename;
    HANDLE module = GetModuleHandle(NULL); /* This might look strange, but we want the erl.ini 
					      that resides in the same dir as erl.exe, not 
					      an erl.ini in our directory */
    InitFile *inif;
    InitSection *inis;

    if (module == NULL) {
        error("Cannot GetModuleHandle()");
    }

    if (GetModuleFileName(module,buffer,MAX_PATH) == 0) {
        error("Could not GetModuleFileName");
    }

    ini_filename = replace_filename(buffer,INI_FILENAME);

    if ((inif = load_init_file(ini_filename)) == NULL) {
	/* Assume that the path is absolute and that
	   it does not contain any symbolic link */
	
	char buffer[MAX_PATH];
	
	/* Determine bindir */
	if (GetEnvironmentVariable("ERLEXEC_DIR", buffer, MAX_PATH) == 0) {
	    strcpy(buffer, ini_filename);
	    for (p = buffer+strlen(buffer)-1; p >= buffer && *p != '\\'; --p)
		;
	    *p ='\0';
	}
	bindir = path_massage(buffer);

	/* Determine rootdir */
	for (p = buffer+strlen(buffer)-1; p >= buffer && *p != '\\'; --p)
	    ;
	p--;
	for (;p >= buffer && *p != '\\'; --p)
	    ;
	*p ='\0';
	rootdir = path_massage(buffer);

	/* Hardcoded progname */
	progname = strsave(DEFAULT_PROGNAME);
    } else {
	if ((inis = lookup_init_section(inif,INI_SECTION)) == NULL) {
	    error("Could not find section %s in init file %s",
		  INI_SECTION, ini_filename);
	}

	bindir = do_lookup_in_section(inis, "Bindir", INI_SECTION, ini_filename,1);
	rootdir = do_lookup_in_section(inis, "Rootdir", INI_SECTION, 
				       ini_filename,1);
	progname = do_lookup_in_section(inis, "Progname", INI_SECTION, 
					ini_filename,0);
	free_init_file(inif);
    }

    emu = EMULATOR_EXECUTABLE;
    start_emulator_program = strsave(argv[0]);

    free(ini_filename);
}