1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
46 fprintf(stderr
, "MANGLE: <file>\n");
49 BOOL
MangleFile( const char *real_name
, const char *mangle_name
)
55 if( mangle_name
&& *mangle_name
&& strcmpi(real_name
, mangle_name
) ) {
56 printf("Mangle: renaming %s to %s\n", real_name
, mangle_name
);
58 if( ! MoveFile(real_name
, "X_MANGLE.TMP") ) {
59 fprintf(stderr
, "MANGLE: cannot rename %s to X_MANGLE.TMP\n",
64 if( ! MoveFile("X_MANGLE.TMP", mangle_name
) ) {
65 MoveFile("X_MANGLE.TMP", real_name
);
66 fprintf(stderr
, "MANGLE: cannot rename X_MANGLE.TMP to %s\n",
71 len
= sprintf(buffer
, "mv %s %s\r\n", mangle_name
, real_name
);
73 if( (WriteFile( hMangleFile
, buffer
, len
, &dwWritten
, NULL
) == FALSE
) ||
74 (dwWritten
!= len
) ) {
75 fprintf(stderr
, "MANGLE: error writing to UNMANGLE.BAT\n");
83 int main( int argc
, char *argv
[] )
85 WIN32_FIND_DATA find_data
;
94 hMangleFile
= CreateFile("unmangle.bat", /* name */
95 GENERIC_READ
|GENERIC_WRITE
, /* access mode */
97 NULL
, /* security descriptor */
98 CREATE_NEW
, /* how to create */
99 FILE_ATTRIBUTE_NORMAL
, /* file attributes */
100 NULL
); /* template file */
102 if( hMangleFile
== INVALID_HANDLE_VALUE
) {
103 if( GetLastError() == ERROR_FILE_EXISTS
) {
104 fprintf(stderr
, "MANGLE: UNMANGLE.BAT already exists\n");
106 fprintf(stderr
, "MANGLE: cannot open UNMANGLE.BAT\n");
111 if( (hFoundFile
= FindFirstFile("*.*", &find_data
)) == INVALID_HANDLE_VALUE
) {
112 fprintf(stderr
, "MANGLE: cannot read directory\n");
117 if( !MangleFile(find_data
.cFileName
, find_data
.cAlternateFileName
) ) {
118 fprintf(stderr
, "MANGLE: cannot rename %s to %s\n",
119 find_data
.cFileName
, find_data
.cAlternateFileName
);
121 FindClose( hFoundFile
);
122 CloseHandle( hMangleFile
);
125 } while( FindNextFile(hFoundFile
, &find_data
) );
126 FindClose( hFoundFile
);
133 len
= sprintf(buffer
, "del unmangle.bat\r\n");
134 WriteFile ( hMangleFile
, buffer
, len
, &dwWritten
, NULL
);
136 CloseHandle( hMangleFile
);