* reg.kex Regular expression explorer. * Version 1.2 * Last update: 10-03-98 (dd-mm-yy) * (C) 1997 AIAP * Golub M.A. * Russia * Moscow * e-mail: golub@aha.ru * To call: macro reg command argument * "macro" may be omited if IMPMACRO is ON; * "command" any search command, allowing regular expressions, * e.g., LOCATE or ALL (maybe abbreviated); * "argument" the search pattern or a predefined string; * If "argument" starts with '/' or -'/' then the "command" may * be omited if you imply LOCATE. * There is a special command "TEST" that creates a file * and makes some settings to test the REG.KEX macro. * The predefined strings: * -------------------------------------------------------------- * Shortest Longest Description * form form * -------------------------------------------------------------- * DIG DIGITS digits * INT INTEGERS integer (digits, +, -) * NUM NUMBERS integer or fixed point * FL FLOATS floating point number in E or D notation * (finds any number: int, fixed, float) * ALPHA ALPHANUM alphanimeric characters * LAT LATIN Latin alphabet * UPP UPPERCASE Latin uppercase * LOW LOWERCASE Latin lowercase * ENG ENGLISH Latin plus @ $ # & * RUS RUSSIAN Russian alphabet only (ANSI) * RUP RUPPERCASE Russian uppercase (ANSI) * RLO RLOWERCASE Russian lowercase (ANSI) * CYR CYRILLIC Cyrillic alphabet (ANSI) * EURO EUROPEAN European alphabet (ANSI) * COM COMMENTS KEXX comments * NOC NOCOMMENTS negation to COMMENT * FIR FIRST first executional KEXX line (command ignored) * DEL DELIMITER punctuation only * You can add your own definitions by modifying the and sending it * via e-mail to . * You can also send you wish lists to the same address. /* End of built-in help */ * The following lines added by Macro Help: ***************** * DO NOT REMOVE THE COMMENTS! THEY ARE USED FOR UPGRADING! * Swap or comment one of the following two lines to switch * to another procedure: Call Version /* The variable VER gets the version value */ If Arg(1)="?"|\Arg() Then Do; Call MacroPage; Exit RC; End If Arg(1)="?"|\Arg() Then Do; Call MacroHelp; Exit RC; End * The end of the insertion. ******************************** Parse Arg arg_string; If arg_string='' Then Exit 1000 If arg_string='?' Then Call MacroHelp arg_string=Strip(arg_string, 'L') * Assume LOCATE if / is the first nonblank character If Left(arg_string, 1)='/' | Left(arg_string, 2)='-/' Then arg_string='Locate' arg_string Parse Value arg_string With cmd argument cmdu=Upper(cmd) If cmdu='TEST' Then Call Test If Abbrev('FIRST', cmdu, 3) Then Do; cmd='All'; argument='FIRST'; End /* special case */ If Lower(Word(argument, 1))='r' Then argument=DelWord(argument, 1, 1) argu=Upper(argument) addroutine='*' /* just a comment, may be a command or a subroutine supplied */ pm='[\+\-]@' /* plus, minus or nothing */ lower='a-z' upper='A-Z' rlow='\xE0-\xFF\xB8' /* Russian lower (ANSI) */ rupp='\xC0-\xDF\xA8' /* Russian upper (ANSI) */ delimiters='\,\.\<\>\{\}\[\]\:\;\"\''\?\`\~\!\%\^\/\\' If Abbrev('DELIMITERS', argu, 3) Then argument=Delimit('['delimiters']') If Abbrev('DIGITS', argu, 3) Then argument='/:d/' If Abbrev('INTEGRS', argu, 3) Then argument='/'pm':z/' If Abbrev('NUMBERS', argu, 3) Then argument='/'pm':n/' If Abbrev('FLOATS', argu, 2) Then argument='/('pm':n.[eEdD]'pm':z)|('pm':n)/' If Abbrev('ALPHANUM', argu, 3) Then argument='/:a/' If Abbrev('LATIN', argu, 3) Then argument='/['upper||lower']/' If Abbrev('ENGLISH', argu, 3) Then argument='/['upper||lower'\&\@\&\#]/' If Abbrev('UPPERCASE', argu, 3) Then argument='/['upper']/' If Abbrev('LOWERCASE', argu, 3) Then argument='/['lower']/' If Abbrev('RUSSIAN', argu, 3) Then argument='/['rupp||rlow']/' /* ANSI */ If Abbrev('RUPPERCASE', argu, 3) Then argument='/['rupp']/' /* ANSI */ If Abbrev('RLOWERCASE', argu, 3) Then argument='/['rlow']/' /* ANSI */ If Abbrev('EUROPEAN', argu, 3) Then argument='/['upper||lower'\x83\x8A\x8C-\x8F\x9A\x9C-\x9F\xA3-\xA5\xAA\xAF\xB3\xB5\xB9\xBA\xBC\xBE-\xDF\xE0-\xF6\xF8-\xFE]/' /* ANSI */ If Abbrev('CYRILLIC', argu, 3) Then argument='/['rupp||rlow'\x80\x81\x83\x8A\x8C\x90\x9A\x9C-\x9F\xA1-\xA3\xA5\xAA\xAF\xB2-\xB4\xBA\xBC-\xBF]/' /* ANSI */ If Abbrev('FIRST', argu, 3) Then Do; argument='/^~([\x20]@\*)/'; addroutine='NoMsg Imm Less Blank; All'; End If Abbrev('COMMENTS', argu, 3) Then Do; argument='/^[\x20]@\*/'; If cmdu='ALL' Then addroutine='NoMsg More Blank'; End If Abbrev('NOCOMMENTS', argu, 3) Then Do; argument='/^~([\x20]@\*)/'; If cmdu='ALL' Then addroutine='NoMsg Less Blank'; End 'Extract /Case' 'Set Case Mixed Respect' cmd 'r' argument; R=RC 'Set Case' Case.1 Case.2 Case.3 Interpret addroutine RC=Max(R, RC) Exit RC Test: /* build the brief test file */ rzone=35; rz1=rzone-1 eu.1=Left(XRange('A', 'Z'), rzone) eu.2=Left(XRange('a', 'z'), rzone) eu.3=Left('838A8C8D8E8F9A9C9D9E9FA3A5AAAFB3B5B9BABCBDBEBF'x, rzone) eu.4=XRange('C0'x, 'DF'x) eu.5=XRange('E0'x, 'F6'x)||XRange('F8'x, 'FE'x) ru.1=eu.4 'A8'x; ru.2=XRange('E0'x, 'FF'x) 'B8'x eu.4=Left(eu.4, rzone) eu.5=Left(eu.5, rzone) ul.1='upper'; ul.2='lower' cyr.1=ru.1; cyr.2=ru.2 cyr.3=Left('8081838A8C8D8E8F909A9C9D9E9FA1A2A3A5AAAFB2B3B4BABCBDBEBF'x, rz1) inp='NoMsg Input' add='NoMsg Add' 'X REG!TEMP.TXT (New NoProf'; If RC<>0 Then Exit RC 'Range -* *'; 'Tr *'; 'Z 1 *'; 'All'; 'Del All' inp Left('', rz1) FName.1()'.'FExt.1()': REG.KEX brief test'; add Do i=1 to 2; inp eu.i'---' ul.i; End; add Do i=1 to 2; inp ru.i '--- Russian' ul.i; End; add Do i=1 to 3; inp cyr.i '--- Cyrillic' i'/3'; End; add Do i=1 to 5; inp eu.i'--- Euro' i'/5'; End; add dig=XRange(0, 9) inp Left(' 'dig, rzone)'--- digits'; add inp Left('+'dig, rzone)'--- integer 1/2' inp Left('-'dig, rzone)'--- integer 2/2'; add dig=XRange(0, 4)'.'XRange(5, 9) inp Left(' 'dig, rzone)'--- number 1/3' inp Left('+'dig, rzone)'--- number 2/3' inp Left('-'dig, rzone)'--- number 3/3'; add inp Left('-'dig'e123', rzone)'--- float 1/6' inp Left('-'dig'E+123', rzone)'--- float 2/6' inp Left('-'dig'E-123', rzone)'--- float 3/6' inp Left('-'dig'D123', rzone)'--- float 4/6' inp Left('-'dig'D+123', rzone)'--- float 5/6' inp Left('-'dig'D-123', rzone)'--- float 6/6'; add inp '!"#$%&''()*+,-.:;<=>?@[]^_`{|}~\/ --- delimiters' ':0 Set Alt 0 0'; 'Set Zone 1' rzone; 'Refresh' 'MsgLine On' MsgLine.2() 5 'Overlay' Say 'This file size must be 35 lines and zone must be 1' rzone'.' 'Q Zone'; 'Q Size' 'CMsg Macro Reg All UpperCase'; 'SOS TabCmd EndChar' Exit MacroHelp: Procedure Expose RC Arg cmd; If cmd='' Then cmd='Msg' nl=SourceLine() flag=1 Do i=1 to nl ln=SourceLine(i) blank?=(ln='') If Left(Strip(ln, 'L'), 1)<>'*' & \blank? Then Leave If flag & blank? Then Iterate cmd SubStr(ln, 2); If RC<>0 Then Return flag=0 End If flag Then Do 'EMsg No built-in help available.'; RC=1000; Return End Return MacroPage: Procedure Expose RC ver MacroName 'Extract /LScreen/MsgLine/InputMode' Parse Upper Source . . MacroName MacroName=Strip(MacroName) MacroName=Left(MacroName, Min(10, Length(MacroName))) Left(ver, 3) ps=LScreen.1-3 If ps<1 Then Do 'EMsg No room to display built-in help.'; RC=1001; Return End * Define the range of the header comments nl=SourceLine(); start_no=0; end_no=0 Do i=1 to nl ln=SourceLine(i) blank?=(ln='') If Left(Strip(ln, 'L'), 1)<>'*' & \blank? Then Leave If start_no=0 Then Do If blank? Then Iterate /* ignore leading blank lines */ start_no=i End end_no=i End If start_no=0 Then Do 'EMsg No built-in help available.'; RC=1000; Return End 'Set MsgLine On 1' LScreen.1 'Overlay' np=(end_no-start_no+ps)%ps /* number of pages */ pg=1 /* current page number */ Do Forever p1=(pg-1)*ps+1 pend=pg*ps p2=Min(end_no, pend) sep=pend-p2+1 Do i=p1 to p2; Say SubStr(SourceLine(i), 2); End Do sep; Say; End Say MacroName 'Page:' pg 'PgUp/PgDn=Paging; Home=Top; End=Bottom; ESC=Quit; F10=Insert' 'ReadV Key' If ReadV.1='ESC' Then Leave If ReadV.1='F10' Then Do 'Set InputMode Off'; 'Point .MacroHelp' Call MacroHelp 'Command Input' 'Set InputMode' InputMode.1; 'Locate .MacroHelp' Leave End If ReadV.1='HOME' Then pg=1 If ReadV.1='END' Then pg=np If ReadV.1='PGUP' Then pg=Max(1, pg-1) If ReadV.1='PGDN' Then pg=Min(np, pg+1) End 'Set MsgLine' MsgLine.1 MsgLine.2 MsgLine.3 MsgLine.4 'Refresh' Return Version: Procedure Expose ver nl=SourceLine() ver='' Do i=1 to nl ln=SourceLine(i) blank?=(ln='') If Left(Strip(ln, 'L'), 1)<>'*' & \blank? then Leave If blank? then Iterate Parse Value ln With "*" vers ver . If Upper(Strip(vers))='VERSION' then Leave End ver=Strip(ver) Return