| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- type
- bar = array [0..255] of byte;
- par = ^bar;
- const
- ParamChars :set of char = ['D','d','K','k','W','w'];
- {Constants have stolen from FAR Manager (C) Eugene Roshal tables}
- WIN1251 : bar = (
- $00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0a,$0b,$0c,$0d,$0e,$0f,$10,$11,$12,$13,$14,
- $15,$16,$17,$18,$19,$1a,$1b,$1c,$1d,$1e,$1f,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2a,$2b,$2c,$2d,
- $2e,$2f,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3a,$3b,$3c,$3d,$3e,$3f,$40,$41,$42,$43,$44,$45,$46,
- $47,$48,$49,$4a,$4b,$4c,$4d,$4e,$4f,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$5a,$5b,$5c,$5d,$5e,$5f,
- $60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$6a,$6b,$6c,$6d,$6e,$6f,$70,$71,$72,$73,$74,$75,$76,$77,$78,
- $79,$7a,$7b,$7c,$7d,$7e,$7f,$3f,$3f,$27,$3f,$22,$3a,$c5,$d8,$3f,$25,$3f,$3c,$3f,$3f,$3f,$3f,$3f,$27,
- $27,$22,$22,$07,$2d,$2d,$3f,$54,$3f,$3e,$3f,$3f,$3f,$3f,$ff,$f6,$f7,$3f,$fd,$3f,$b3,$15,$f0,$63,$f2,
- $3c,$bf,$2d,$52,$f4,$f8,$2b,$49,$69,$3f,$e7,$14,$fa,$f1,$fc,$f3,$3e,$3f,$3f,$3f,$f5,$80,$81,$82,$83,
- $84,$85,$86,$87,$88,$89,$8a,$8b,$8c,$8d,$8e,$8f,$90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9a,$9b,$9c,
- $9d,$9e,$9f,$a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$aa,$ab,$ac,$ad,$ae,$af,$e0,$e1,$e2,$e3,$e4,$e5,
- $e6,$e7,$e8,$e9,$ea,$eb,$ec,$ed,$ee,$ef);
- KOI8R : bar = (
- $00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0a,$0b,$0c,$0d,$0e,$0f,$10,$11,$12,$13,$14,
- $15,$16,$17,$18,$19,$1a,$1b,$1c,$1d,$1e,$1f,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2a,$2b,$2c,$2d,
- $2e,$2f,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3a,$3b,$3c,$3d,$3e,$3f,$40,$41,$42,$43,$44,$45,$46,
- $47,$48,$49,$4a,$4b,$4c,$4d,$4e,$4f,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$5a,$5b,$5c,$5d,$5e,$5f,
- $60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$6a,$6b,$6c,$6d,$6e,$6f,$70,$71,$72,$73,$74,$75,$76,$77,$78,
- $79,$7a,$7b,$7c,$7d,$7e,$7f,$c4,$b3,$da,$bf,$c0,$d9,$c3,$b4,$c2,$c1,$c5,$df,$dc,$db,$dd,$de,$b0,$b1,
- $b2,$f4,$fe,$f9,$fb,$f7,$f3,$f2,$ff,$f5,$f8,$fd,$fa,$f6,$cd,$ba,$d5,$f1,$d6,$c9,$b8,$b7,$bb,$d4,$d3,
- $c8,$be,$bd,$bc,$c6,$c7,$cc,$b5,$f0,$b6,$b9,$d1,$d2,$cb,$cf,$d0,$ca,$d8,$d7,$ce,$fc,$ee,$a0,$a1,$e6,
- $a4,$a5,$e4,$a3,$e5,$a8,$a9,$aa,$ab,$ac,$ad,$ae,$af,$ef,$e0,$e1,$e2,$e3,$a6,$a2,$ec,$eb,$a7,$e8,$ed,
- $e9,$e7,$ea,$9e,$80,$81,$96,$84,$85,$94,$83,$95,$88,$89,$8a,$8b,$8c,$8d,$8e,$8f,$9f,$90,$91,$92,$93,
- $86,$82,$9c,$9b,$87,$98,$9d,$99,$97,$9a);
- DOS866 : bar = (
- $00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0a,$0b,$0c,$0d,$0e,$0f,
- $10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1a,$1b,$1c,$1d,$1e,$1f,
- $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2a,$2b,$2c,$2d,$2e,$2f,
- $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3a,$3b,$3c,$3d,$3e,$3f,
- $40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$4a,$4b,$4c,$4d,$4e,$4f,
- $50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$5a,$5b,$5c,$5d,$5e,$5f,
- $60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$6a,$6b,$6c,$6d,$6e,$6f,
- $70,$71,$72,$73,$74,$75,$76,$77,$78,$79,$7a,$7b,$7c,$7d,$7e,$7f,
- $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8a,$8b,$8c,$8d,$8e,$8f,
- $90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9a,$9b,$9c,$9d,$9e,$9f,
- $A0,$A1,$A2,$A3,$A4,$A5,$A6,$A7,$A8,$A9,$Aa,$Ab,$Ac,$Ad,$Ae,$Af,
- $B0,$B1,$B2,$B3,$B4,$B5,$B6,$B7,$B8,$B9,$Ba,$Bb,$Bc,$Bd,$Be,$Bf,
- $C0,$C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$C9,$Ca,$Cb,$Cc,$Cd,$Ce,$Cf,
- $d0,$d1,$d2,$d3,$d4,$d5,$d6,$d7,$d8,$d9,$da,$db,$dc,$dd,$de,$df,
- $e0,$e1,$e2,$e3,$e4,$e5,$e6,$e7,$e8,$e9,$ea,$eb,$ec,$ed,$ee,$ef,
- $f0,$f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$fa,$fb,$fc,$fd,$fe,$ff);
- Procedure Usage;
- begin
- WriteLn('Usage: charconv.exe <mode_from> <mode_to> <input_name> [out_name]');
- WriteLn('where mode: ');
- WriteLn(' D : DOS-866');
- WriteLn(' W : WIN-1251');
- WriteLn(' K : KOI-8-R');
- WriteLn('');
- WriteLn('Copyright RodSoft 2001 by Innocenty Enikeew 9:159/1');
- Halt(255);
- end;{Usage}
- var
- TOKOI8R : bar;
- TOWIN1251: bar;
- fIn,fOut,tmp : file of byte;
- mIn,mOut : char;
- tIn,tOut : par;
- ch : byte;
- nIn,nOut : string;
- begin
- if ParamCount < 3 then Usage;
- for ch := 0 to 255 do TOKOI8R[KOI8R[ch]]:=ch;
- for ch := 0 to 255 do TOWIN1251[WIN1251[ch]]:=ch;
- nIn:=ParamStr(1);mIn := nIn[1];
- nIn:=ParamStr(2);mOut := nIn[1];
- if not ((mIn In ParamChars) and (mOut In ParamChars)) then Usage;
- case mIn of
- 'D','d' : tIn:=@DOS866;
- 'W','w' : tin:=@WIN1251;
- 'K','k' : tin:=@KOI8R;
- end;
- case mOut of
- 'D','d' : tOut:=@DOS866;
- 'W','w' : tOut:=@TOWIN1251;
- 'K','k' : tOut:=@TOKOI8R;
- end;
- nIn := ParamStr(3);
- if ParamCount = 4 then nOut:=ParamStr(4) else nOut:=nIn;
- {$I-}
- Assign(fIn,nIn);
- Reset(fIn);
- If IOResult <> 0 then
- begin
- WriteLn('Error opening ',nIn);
- Usage;
- end;
- Assign(fOut,'chconv.!!!');
- Rewrite(fOut);
- If IOResult <> 0 then
- begin
- WriteLn('Error opening tempfile');
- Halt(254);
- end;
- {$I+}
- while not EOF(fIn) do
- begin
- Read(fIn,ch);
- Write(fOut,tOut^[tIn^[ch]]);
- end;
- close(fIn);
- Close(fOut);
- {$I-}
- Rename(fOut,nOut);
- if IOResult <> 0 then
- begin
- Assign(tmp,nOut);
- Erase(tmp);
- Rename(fOut,nOut);
- end;
- {$I+}
- WriteLn('Converted ',mIn,'->',mOut);
- WriteLn('Files: ',nIn,'->',nOut);
- WriteLn('Copyright RodSoft 2001 by Innocenty Enikeew 9:159/1');
- end.
|