Check-in [03e7a7b726]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:When no charset is specified, and using the standard input and/or output stream, default to their defined code page instead of hard-coding OEM. When no output charset is defined, and we're not writing to standard output, default to UTF-8.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:03e7a7b726e8146165de7bc814b863214795ac0e
User & Date: Martijn 2014-03-12 20:37:07
Context
2015-12-10
07:04
Edited readme. Removed .res files, they don't belong in the repo. Moved ignore-glob to versionable file. Leaf check-in: d1a015905b user: tinus tags: trunk
2014-03-12
20:37
When no charset is specified, and using the standard input and/or output stream, default to their defined code page instead of hard-coding OEM. When no output charset is defined, and we're not writing to standard output, default to UTF-8. check-in: 03e7a7b726 user: Martijn tags: trunk
2014-02-28
08:22
Added /b option to ConvertCharset, to keep a backup of any overwritten file. Updated all projects to XE5. check-in: 728d68c864 user: Martijn tags: trunk
Changes

Changes to src/ConvertCharset.dpr.

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121





122
123
124
125
126
127
128
129
...
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184

      if Args.Count < 2 then
        Args.Add(Args[0]);

      CharsetIn := Opts.Values['r'];
      if CharsetIn = '' then begin
        if Args[0] = '-' then
          EncIn := TEncoding.GetEncoding(CP_OEMCP)
        else
          EncIn := TEncoding.Default;
      end else if TryStrToInt(CharsetIn, CPIn) then begin
        EncIn := TEncoding.GetEncoding(CPIn);
      end else begin
        EncIn := TEncoding.GetEncoding(CharsetIn);
      end;

      CharsetOut := Opts.Values['w'];





      if TryStrToInt(CharsetOut, CPOut) then begin
        EncOut := TEncoding.GetEncoding(CPOut);
      end else begin
        EncOut := TEncoding.GetEncoding(CharsetOut);
      end;

      FileIn := Args[0];
      if FileIn = '-' then begin
................................................................................
      end;

      if FileOrg <> '' then begin
        if Opts.IndexOf('b') > -1 then begin
          FileBak := ChangeFileExt(FileOut, '.bak');
        end;


        Win32Check(ReplaceFile(PChar(FileOrg), PChar(FileOut), PChar(FileBak), REPLACEFILE_IGNORE_MERGE_ERRORS, nil, nil));
      end;
    finally
      Opts.Free;
      Args.Free;
    end;
  except
    on E: Exception do begin
      Writeln(ErrOutput, E.ClassName, ': ', E.Message);
      ExitCode := -1;
    end;
  end;
end.







|









>
>
>
>
>
|







 







>













105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

      if Args.Count < 2 then
        Args.Add(Args[0]);

      CharsetIn := Opts.Values['r'];
      if CharsetIn = '' then begin
        if Args[0] = '-' then
          EncIn := TEncoding.GetEncoding(GetConsoleCP)
        else
          EncIn := TEncoding.Default;
      end else if TryStrToInt(CharsetIn, CPIn) then begin
        EncIn := TEncoding.GetEncoding(CPIn);
      end else begin
        EncIn := TEncoding.GetEncoding(CharsetIn);
      end;

      CharsetOut := Opts.Values['w'];
      if CharsetOut = '' then begin
        if Args[1] = '-' then
          EncOut := TEncoding.GetEncoding(GetConsoleOutputCP)
        else
          EncOut := TEncoding.UTF8;
      end else if TryStrToInt(CharsetOut, CPOut) then begin
        EncOut := TEncoding.GetEncoding(CPOut);
      end else begin
        EncOut := TEncoding.GetEncoding(CharsetOut);
      end;

      FileIn := Args[0];
      if FileIn = '-' then begin
................................................................................
      end;

      if FileOrg <> '' then begin
        if Opts.IndexOf('b') > -1 then begin
          FileBak := ChangeFileExt(FileOut, '.bak');
        end;

        // Now we replace the original FileOut by our new output file
        Win32Check(ReplaceFile(PChar(FileOrg), PChar(FileOut), PChar(FileBak), REPLACEFILE_IGNORE_MERGE_ERRORS, nil, nil));
      end;
    finally
      Opts.Free;
      Args.Free;
    end;
  except
    on E: Exception do begin
      Writeln(ErrOutput, E.ClassName, ': ', E.Message);
      ExitCode := -1;
    end;
  end;
end.