/* Called from the main thread to start watching FILE in PARENT_DIR, subject to FLAGS. If SUBDIRS is TRUE, watch the subdirectories of PARENT_DIR as well. Value is a pointer to 'struct notification' used by the thread that watches the changes. */ static struct notification * add_watch (const char *parent_dir, const char *file, BOOL subdirs, DWORD flags) { HANDLE hdir; struct notification *dirwatch = NULL; if (!file) return NULL; if (w32_unicode_filenames) { wchar_t dir_w[MAX_PATH], file_w[MAX_PATH]; filename_to_utf16 (parent_dir, dir_w); if (*file) filename_to_utf16 (file, file_w); else file_w[0] = 0; hdir = CreateFileW (dir_w, FILE_LIST_DIRECTORY, /* FILE_SHARE_DELETE doesn't preclude other processes from deleting files inside parent_dir. */ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); } else { char dir_a[MAX_PATH], file_a[MAX_PATH]; filename_to_ansi (parent_dir, dir_a); if (*file) filename_to_ansi (file, file_a); else file_a[0] = '\0'; hdir = CreateFileA (dir_a, FILE_LIST_DIRECTORY, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); } if (hdir == INVALID_HANDLE_VALUE) return NULL; if ((dirwatch = start_watching (file, hdir, subdirs, flags)) == NULL) { CloseHandle (hdir); dirwatch->dir = NULL; } return dirwatch; }
static int do_play_sound (const char *psz_file, unsigned long ui_volume) { int i_result = 0; MCIERROR mci_error = 0; char sz_cmd_buf_a[520]; char sz_ret_buf_a[520]; MMRESULT mm_result = MMSYSERR_NOERROR; unsigned long ui_volume_org = 0; BOOL b_reset_volume = FALSE; char warn_text[560]; /* Since UNICOWS.DLL includes only a stub for mciSendStringW, we need to encode the file in the ANSI codepage on Windows 9X even if w32_unicode_filenames is non-zero. */ if (w32_major_version <= 4 || !w32_unicode_filenames) { char fname_a[MAX_PATH], shortname[MAX_PATH], *fname_to_use; filename_to_ansi (psz_file, fname_a); fname_to_use = fname_a; /* If the file name is not encodable in ANSI, try its short 8+3 alias. This will only work if w32_unicode_filenames is non-zero. */ if (_mbspbrk ((const unsigned char *)fname_a, (const unsigned char *)"?")) { if (w32_get_short_filename (psz_file, shortname, MAX_PATH)) fname_to_use = shortname; else mci_error = MCIERR_FILE_NOT_FOUND; } if (!mci_error) { memset (sz_cmd_buf_a, 0, sizeof (sz_cmd_buf_a)); memset (sz_ret_buf_a, 0, sizeof (sz_ret_buf_a)); sprintf (sz_cmd_buf_a, "open \"%s\" alias GNUEmacs_PlaySound_Device wait", fname_to_use); mci_error = mciSendStringA (sz_cmd_buf_a, sz_ret_buf_a, sizeof (sz_ret_buf_a), NULL); } } else { wchar_t sz_cmd_buf_w[520]; wchar_t sz_ret_buf_w[520]; wchar_t fname_w[MAX_PATH]; filename_to_utf16 (psz_file, fname_w); memset (sz_cmd_buf_w, 0, sizeof (sz_cmd_buf_w)); memset (sz_ret_buf_w, 0, sizeof (sz_ret_buf_w)); /* _swprintf is not available on Windows 9X, so we construct the UTF-16 command string by hand. */ wcscpy (sz_cmd_buf_w, L"open \""); wcscat (sz_cmd_buf_w, fname_w); wcscat (sz_cmd_buf_w, L"\" alias GNUEmacs_PlaySound_Device wait"); mci_error = mciSendStringW (sz_cmd_buf_w, sz_ret_buf_w, ARRAYELTS (sz_ret_buf_w) , NULL); } if (mci_error != 0) { strcpy (warn_text, "mciSendString: 'open' command failed to open sound file "); strcat (warn_text, psz_file); SOUND_WARNING (mciGetErrorString, mci_error, warn_text); i_result = (int) mci_error; return i_result; } if ((ui_volume > 0) && (ui_volume != UINT_MAX)) { mm_result = waveOutGetVolume ((HWAVEOUT) WAVE_MAPPER, &ui_volume_org); if (mm_result == MMSYSERR_NOERROR) { b_reset_volume = TRUE; mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume); if (mm_result != MMSYSERR_NOERROR) { SOUND_WARNING (waveOutGetErrorText, mm_result, "waveOutSetVolume: failed to set the volume level" " of the WAVE_MAPPER device.\n" "As a result, the user selected volume level will" " not be used."); } } else { SOUND_WARNING (waveOutGetErrorText, mm_result, "waveOutGetVolume: failed to obtain the original" " volume level of the WAVE_MAPPER device.\n" "As a result, the user selected volume level will" " not be used."); } } memset (sz_cmd_buf_a, 0, sizeof (sz_cmd_buf_a)); memset (sz_ret_buf_a, 0, sizeof (sz_ret_buf_a)); strcpy (sz_cmd_buf_a, "play GNUEmacs_PlaySound_Device wait"); mci_error = mciSendStringA (sz_cmd_buf_a, sz_ret_buf_a, sizeof (sz_ret_buf_a), NULL); if (mci_error != 0) { strcpy (warn_text, "mciSendString: 'play' command failed to play sound file "); strcat (warn_text, psz_file); SOUND_WARNING (mciGetErrorString, mci_error, warn_text); i_result = (int) mci_error; } memset (sz_cmd_buf_a, 0, sizeof (sz_cmd_buf_a)); memset (sz_ret_buf_a, 0, sizeof (sz_ret_buf_a)); strcpy (sz_cmd_buf_a, "close GNUEmacs_PlaySound_Device wait"); mci_error = mciSendStringA (sz_cmd_buf_a, sz_ret_buf_a, sizeof (sz_ret_buf_a), NULL); if (b_reset_volume == TRUE) { mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume_org); if (mm_result != MMSYSERR_NOERROR) { SOUND_WARNING (waveOutGetErrorText, mm_result, "waveOutSetVolume: failed to reset the original" " volume level of the WAVE_MAPPER device."); } } return i_result; }
/* Dump out .data and .bss sections into a new executable. */ void unexec (const char *new_name, const char *old_name) { file_data in_file, out_file; char out_filename[MAX_PATH], in_filename[MAX_PATH], new_name_a[MAX_PATH]; unsigned long size; char *p; char *q; /* Ignore old_name, and get our actual location from the OS. */ if (!GetModuleFileNameA (NULL, in_filename, MAX_PATH)) abort (); /* Can't use dostounix_filename here, since that needs its file name argument encoded in UTF-8. */ for (p = in_filename; *p; p = CharNextA (p)) if (*p == '\\') *p = '/'; strcpy (out_filename, in_filename); filename_to_ansi (new_name, new_name_a); /* Change the base of the output filename to match the requested name. */ if ((p = strrchr (out_filename, '/')) == NULL) abort (); /* The filenames have already been expanded, and will be in Unix format, so it is safe to expect an absolute name. */ if ((q = strrchr (new_name_a, '/')) == NULL) abort (); strcpy (p, q); #ifdef ENABLE_CHECKING report_temacs_memory_usage (); #endif /* Make sure that the output filename has the ".exe" extension...patch it up if not. */ p = out_filename + strlen (out_filename) - 4; if (strcmp (p, ".exe")) strcat (out_filename, ".exe"); printf ("Dumping from %s\n", in_filename); printf (" to %s\n", out_filename); /* Open the undumped executable file. */ if (!open_input_file (&in_file, in_filename)) { printf ("Failed to open %s (%d)...bailing.\n", in_filename, GetLastError ()); exit (1); } /* Get the interesting section info, like start and size of .bss... */ get_section_info (&in_file); /* The size of the dumped executable is the size of the original executable plus the size of the heap and the size of the .bss section. */ size = in_file.size + extra_bss_size + extra_bss_size_static; if (!open_output_file (&out_file, out_filename, size)) { printf ("Failed to open %s (%d)...bailing.\n", out_filename, GetLastError ()); exit (1); } /* Set the flag (before dumping). */ using_dynamic_heap = TRUE; copy_executable_and_dump_data (&in_file, &out_file); /* Unset it because it is plain wrong to keep it after dumping. Malloc can still occur! */ using_dynamic_heap = FALSE; /* Patch up header fields; profiler is picky about this. */ { PIMAGE_DOS_HEADER dos_header; PIMAGE_NT_HEADERS nt_header; HANDLE hImagehelp = LoadLibrary ("imagehlp.dll"); DWORD headersum; DWORD checksum; dos_header = (PIMAGE_DOS_HEADER) out_file.file_base; nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header + dos_header->e_lfanew); nt_header->OptionalHeader.CheckSum = 0; // nt_header->FileHeader.TimeDateStamp = time (NULL); // dos_header->e_cp = size / 512; // nt_header->OptionalHeader.SizeOfImage = size; pfnCheckSumMappedFile = (void *) GetProcAddress (hImagehelp, "CheckSumMappedFile"); if (pfnCheckSumMappedFile) { // nt_header->FileHeader.TimeDateStamp = time (NULL); pfnCheckSumMappedFile (out_file.file_base, out_file.size, &headersum, &checksum); nt_header->OptionalHeader.CheckSum = checksum; } FreeLibrary (hImagehelp); } close_file_data (&in_file); close_file_data (&out_file); }