Article View: news.software.readers
Article #159841Re: [Dialog] A script that substitutes problematical win chars
From: Enrico C
Date: Wed, 29 Dec 2004 11:15
Date: Wed, 29 Dec 2004 11:15
415 lines
15855 bytes
15855 bytes
On 28 Dec 2004 01:08:08 +0100, Enrico C wrote:
> I would like to have a Dialog script that automatically substitutes some
> "problematical" CP-win-1252 chars with their ISO-8859-1 equivalents before
> sending the message.
> That means, for instance, replacing β and β with " , β with ' , and so
> on.
Here it is (in a different way!)
Just run the script (in Dialog main window) before pasting any text with
Windows special chars (for instance when you copy from a web page or a Word
document with such chars) to a new message.
To make it, I combined two existing scripts. Thank you very much to their
authors! :)
|| Program PasteSpecial;
||
|| {**********************************************
|| PasteSpecial beta 0.2a
||
|| A script that replaces Win special chars in the clipboard.
|| It can be useful for copy&paste to a new message from the web or from a Word doc.
||
||
|| Ciao!
||
|| I didn't do much to write this script! :)
|| It's mainly based on the SelectiveQuotedDestructor script by Alain Guerin
|| and on the Umlaut replace script on 40tude Wiki.
|| I (Enrico C , Sir and Master of www.lillathedog.net :)
|| combined those two scripts and used the result for my purposes.
||
|| This script replaces the special Windows CP-1252 characters, sometimes problematical,
|| with their equivalent "normal" ISO characters
|| (see http://www.cs.tut.fi/~jkorpela/www/windows-chars.html#subst ).
||
|| You can use it when you copy any text to a new message,
|| especially when you copy from a web page or from a Word document
|| that may have such chars.
||
|| βDonβt write like thisβ
|| will become
|| "Don't write like this"
||
|| β’ They only accept florins (Ζ)β¦
|| will became
|| * They only accept florins (f)...
||
||
|| Instructions:
||
|| Just run the script before pasting.
||
|| STEP 1: Copy a text
||
|| STEP 2: Select Dialog main window and run the script
|| (I do that by pressing CTRL-E, the shortcut I assigned to the script),
||
|| STEP 3: Paste the text in the new message composition window.
||
|| Steps 1 and 3 are the usual steps when you copy and paste.
|| Use step 2 (the script) if you want to "purify" a text containing special chars.
||
|| (Note that you can use the script to "purify" and copy a text
|| to any document, not only Dialog new messages).
||
||
||
|| Installation:
||
|| To use this script, create a new blank script in Custom scripts,
|| then replace with this script
|| (delete the || chars at the beginning of lines, of course),
|| save and compile it.
||
|| It's easier if you define a shortcut or a button to run the script.
|| 1 Pick an Icon for this script,
|| 2 Write a Hint ("PasteSpecial") and close the scripting window,
|| 3 Rightclick on the toolbar in Dialog main window,
|| 4 select Configure buttons/shortcuts,
|| 5 browse to Script - PasteSpecial,
|| 6a define a Shortcut, for instance CTRL-E if you don't use it otherwise,
|| 6b drag the script Icon on the toolbar to create a button.
||
|| To run the script by a shortcut, select Dialog main window first
|| (Alt-Tab frome the Composition window).
||
||
|| Here are the replaced chars
||
|| // β baseline single quote Alt+130 ==> ' apostrophe
||
|| // Ζ florin Alt+131 ==> f
||
|| // β baseline double quote Alt+132 ==> " quotation mark
||
|| // β¦ ellipsis Alt+133 ==> ... 3 dots
||
|| // β dagger Alt+134 ==> superscript 1: ΒΉ (assuming use as footnote reference)
||
|| // β‘ double dagger Alt+135 ==> superscript 2: Β² (assuming use as footnote reference)
||
|| // Λ circumflex accent Alt+136 ==> ^ circumflex
||
|| // β° permile Alt+137 ==> o/oo
||
|| // Ε S Hacek Alt+138 ==> Sh
||
|| // βΉ left single guillemet Alt+139 ==> <
||
|| // Ε OE ligature Alt+140 ==> OE
||
|| // β left single quote Alt+145 ==> ' apostrophe used as single quote
||
|| // β right single quote Alt+146 ==> ' apostrophe used as single quote
||
|| // β left double quote Alt+147 ==> " quotation mark
||
|| // β right double quote Alt+148 ==> " quotation mark
||
|| // β’ bullet Alt+149 ==> * asterisk
||
|| // β endash Alt+150 ==> - hyphen
||
|| // β emdash Alt+151 ==> -- 2 hyphens
||
|| // Λ tilde accent Alt+152 ==> ~ tilde
||
|| // β’ trademark ligature Alt+153 ==> (TM)
||
|| // Ε‘ s Hacek Alt+154 ==> sh
||
|| // βΊ right single guillemet Alt+155 ==> >
||
|| // Ε oe ligature Alt+156 ==> oe
||
|| // ΕΈ Y Dieresis Alt+159 ==> Y
||
||
||
|| NB: some symbols can different meanings according to language/context.
|| You can therefore set the script to behave differently for some newsgroups, e.g. according to language
|| If you want the script to behave in a special way for some English groups, for ecample,
|| write a list of those groups in a text file. See the CONST section in the script.
|| If you want to use more languages modify the "SelectLanguage" Function section accordingly.
||
|| ***********************************************}
||
|| uses
|| Forms,
|| StdCtrls;
||
|| // CONST
||
|| // EnglishGroups = 'C:\Documenti\Short English groups.txt';
|| // ItalianGroups = 'C:\Documenti\Short English groups.txt';
|| // GermanGroups = 'C:\Documenti\Short German groups.txt';
|| // FrenchGroups = 'C:\Documenti\Short German groups.txt';
||
|| TYPE
|| TLanguage = (LGeneral, LEnglish, LItalian, LGerman, LFrench);
|| // TDayTime = (DTMorning, DTDay, DTAfternoon, DTEvening, DTNight);
||
||
|| VAR
|| DummyForm : TForm;
|| DummyMemo : TMemo;
|| DummyEdit : TEdit;
|| HeaderName : String;
|| WithDigit : boolean;
|| s:string;
||
||
|| function StringReplace(S, OldPattern, NewPattern: string): string;
|| var
|| SearchStr, Patt, NewStr: string;
|| Offset: Integer;
|| begin
|| SearchStr := S;
|| Patt := OldPattern;
|| NewStr := S;
|| Result := '';
|| while SearchStr <> '' do
|| begin
|| Offset := AnsiPos(Patt, SearchStr);
|| if Offset = 0 then
|| begin
|| Result := Result + NewStr;
|| Break;
|| end;
|| Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
|| NewStr := Copy(NewStr, Offset + Length(OldPattern), 2147483647);
|| SearchStr := Copy(SearchStr, Offset + Length(Patt), 2147483647);
|| end;
|| end;
||
||
|| FUNCTION FindLanguage(VAR List : TStringList; LanguageFileName: string; NewsHeader : string): boolean;
||
|| begin
|| result := false;
|| list.LoadFromFile(LanguageFileName);
|| try
|| writeln(inttostr(list.indexof(NewsHeader)));
|| Result := list.indexof(NewsHeader) > -1;
|| (* where each line is a newsgroup in the language tested, e.g. English:
|| news.software.readers
|| carlokok.public.pascalscript
|| *)
||
|| except
|| writeln('(error)')
|| end;
|| end;
||
||
|| function SelectLanguage(NewsHeader : String):TLanguage;
||
|| var
|| list: TStringList;
||
||
|| begin
|| writeln(NewsHeader);
|| Result := LGeneral;
|| list := TStringList.Create();
||
|| try
||
|| // IF FindLanguage(List, EnglishGroups, NewsHeader) THEN
|| // Result := LEnglish
|| (*
|| ELSE
|| IF FindLanguage(List, GermanGroups, NewsHeader) THEN
|| Result := LGerman*);
||
|| finally
|| list.free;
|| end;
|| (* or in code option:
|| IF (POS('news.software.readers', NewsHeader) > 0)
|| OR (POS('carlokok.public.pascalscript', NewsHeader) > 0) THEN
|| Result := LEnglish;
|| but it is case sen;sitive in this way ;-)
|| *)
||
|| end;
||
|| BEGIN
|| DummyForm := TForm.Create(Nil);
|| try
|| DummyMemo := TMemo.Create(DummyForm);
|| DummyMemo.Parent := DummyForm;
|| DummyMemo.WordWrap := false;
|| DummyMemo.PasteFromClipBoard;
|| IF DummyMemo.Lines.Count > 0 THEN
|| BEGIN
|| DummyEdit := TEdit.Create(DummyForm);
|| try
|| DummyEdit.Parent := DummyForm;
|| ADo('NewgroupPane');
|| Ado('Copy');
|| DummyEdit.PasteFromClipBoard;
|| IF Pos('(', DummyEdit.Text) > 0 THEN
|| HeaderName := copy(DummyEdit.Text, 1, Pos('(', DummyEdit.Text)-1 )
|| ELSE
|| HeaderName := DummyEdit.Text;
|| HeaderName := trim(headername);
|| WHILE Pos(#9, HeaderName)> 0 DO
|| delete(HeaderName,Pos(#9, HeaderName),1);
|| IF Length(HeaderName) >0 THEN
|| WithDigit := (HeaderName[1] >='0') AND (HeaderName[1] <='9')
|| ELSE
|| WithDigit := false;
|| WHILE WithDigit AND (Length(HeaderName) >0) DO
|| BEGIN
|| Delete(HeaderName, 1, 1);
|| IF Length(HeaderName) >0 THEN
|| WithDigit := (HeaderName[1] >='0') AND (HeaderName[1] <='9')
|| ELSE
|| WithDigit := false;
|| END;
|| WHILE Pos(#9, HeaderName)> 0 DO
|| delete(HeaderName,Pos(#9, HeaderName),1);
||
||
|| s:=DummyMemo.text;
||
|| CASE SelectLanguage(HeaderName) OF
||
|| LGeneral :
||
|| begin
||
|| s:=StringReplace(s,'β','"'); // virgolette inglesi sx con normali
|| s:=stringreplace(s,'β','"'); // virgolette inglesi dx con normali
||
|| // β baseline single quote Alt+130 ==> apostrophe
|| s:=stringreplace(s,'β',#39);
||
|| // Ζ florin Alt+131 ==> f
|| s:=stringreplace(s,'Ζ','f');
||
|| // β baseline double quote Alt+132 ==> " quotation mark
|| s:=stringreplace(s,'β','"');
||
|| // β¦ ellipsis Alt+133 ==> ... 3 dots
|| s:=stringreplace(s,'β¦','...');
||
|| // β dagger Alt+134 ==> superscript 1: ΒΉ (assuming use as footnote reference)
|| s:=stringreplace(s,'β ','ΒΉ');
||
|| // β‘ double dagger Alt+135 ==> superscript 2: Β² (assuming use as footnote reference)
|| s:=stringreplace(s,'β‘','Β²');
||
|| // Λ circumflex accent Alt+136 ==> ^ circumflex
|| s:=stringreplace(s,'Λ','^');
||
|| // β° permile Alt+137 ==> o/oo
|| s:=stringreplace(s,'β°','o/oo');
||
|| // Ε S Hacek Alt+138 ==> Sh
|| s:=stringreplace(s,'Ε ','Sh');
||
|| // βΉ left single guillemet Alt+139 ==> <
|| s:=stringreplace(s,'βΉ','<');
||
|| // Ε OE ligature Alt+140 ==> OE
|| s:=stringreplace(s,'Ε','OE');
||
|| // β left single quote Alt+145 ==> ' apostrophe used as single quote
|| s:=stringreplace(s,'β',#39);
||
|| // β right single quote Alt+146 ==> ' apostrophe used as single quote
|| s:=stringreplace(s,'β',#39);
||
|| // β left double quote Alt+147 ==> " quotation mark
|| s:=stringreplace(s,'β','"');
||
|| // β right double quote Alt+148 ==> " quotation mark
|| s:=stringreplace(s,'β','"');
||
|| // β’ bullet Alt+149 ==> * asterisk
|| s:=stringreplace(s,'β’','*');
||
|| // β endash Alt+150 ==> - hyphen
|| s:=stringreplace(s,'β','-');
||
|| // β emdash Alt+151 ==> -- 2 hyphens
|| s:=stringreplace(s,'β','--');
||
|| // Λ tilde accent Alt+152 ==> ~ tilde
|| s:=stringreplace(s,'Λ','~');
||
|| // β’ trademark ligature Alt+153 ==> (TM)
|| s:=stringreplace(s,'β’','(TM)');
||
|| // Ε‘ s Hacek Alt+154 ==> sh
|| s:=stringreplace(s,'Ε‘','sh');
||
|| // βΊ right single guillemet Alt+155 ==> >
|| s:=stringreplace(s,'βΊ','>');
||
|| // Ε oe ligature Alt+156 ==> oe
|| s:=stringreplace(s,'Ε','oe');
||
|| // ΕΈ Y Dieresis Alt+159 ==> Y
|| s:=stringreplace(s,'ΕΈ','Y');
||
||
|| end;
||
||
||
|| LEnglish :
||
|| begin
||
|| // insert chars replace commands here
||
|| end;
||
||
|| // LItalian :
|| // insert chars replace commands here
||
|| // LGerman :
|| // insert chars replace commands here
||
|| // LFrench :
|| // insert chars replace commands here
||
|| END;
||
|| DummyMemo.text:=s;
|| DummyMemo.SelectAll;
|| DummyMemo.CopyToClipBoard;
|| beep;
|| finally
|| writeln('1');
|| dummyedit.free;
|| end;
|| END;
|| finally
|| beep;
|| writeln('2');
|| DummyForm.Free
|| end
||
|| END.
Technical Details
Message-ID:
<3yf8op1yopkl.dlg@news.lillathedog.net>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!tiscali!newsfeed1.ip.tiscali.net!nntp.eutelia.it!area.cu.mi.it!x-privat.org!not-for-mailReferences:
<1xln9aej5brbh.dlg@news.lillathedog.net>Show Full Headers
Complete Article Headers
Message-ID: <3yf8op1yopkl.dlg@news.lillathedog.net> Subject: Re: [Dialog] A script that substitutes problematical win chars Date: Wed, 29 Dec 2004 11:15:12 +0000 From: Enrico C <use_replyto_address@despammed.com> References: <1xln9aej5brbh.dlg@news.lillathedog.net> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!tiscali!newsfeed1.ip.tiscali.net!nntp.eutelia.it!area.cu.mi.it!x-privat.org!not-for-mail Newsgroups: news.software.readers User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Reply-To: enrico.c@people.it Organization: X-Privat NNTP Server - http://www.x-privat.org Supersedes: <cdazpam42f9d.dlg@news.lillathedog.net> NNTP-Posting-Host: $$6drnk_$xlnwm-.x-privat.org Lines: 415 X-Authenticated-User: $$t9dw0m0cxnc-vpzkjjlef X-Complaints-To: abuse@x-privat.org