πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #159838

Re: [Dialog] A script that substitutes problematical win chars

#159838
From: Enrico C
Date: Wed, 29 Dec 2004 10:46
411 lines
15769 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"
||      
||             
||  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: <cdazpam42f9d.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!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!131.211.141.196.MISMATCH!humbolt.nl.linux.org!news.nl.linux.org!news.newsland.it!x-privat.org!not-for-mail
References: <1xln9aej5brbh.dlg@news.lillathedog.net>

Show Full Headers
Complete Article Headers
Message-ID: <cdazpam42f9d.dlg@news.lillathedog.net>
Subject: Re: [Dialog] A script that substitutes problematical win chars
Date: Wed, 29 Dec 2004 10:46:34 +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!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!131.211.141.196.MISMATCH!humbolt.nl.linux.org!news.nl.linux.org!news.newsland.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
NNTP-Posting-Host: $$6drnk_$xlnwm-.x-privat.org
Organization: X-Privat NNTP Server - http://www.x-privat.org
Lines: 411
X-Authenticated-User: $$t9dw0m0cxnc-vpzkjjlef
X-Complaints-To: abuse@x-privat.org