🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #141043

Re: [slrn] fixing tofu for display

#141043
From: John E. Davis
Date: Mon, 12 Jan 2004 05:49
185 lines
7938 bytes
On 24 Dec 2003 23:09:08 GMT, Paul Boekholt <p.boekholt@hetnet.nl>
wrote:
>Doing it with S-Lang is not easy either, it has a nice C-like syntax but
>the regexp functions are not as powerful as in, say, Emacs lisp (or sed).
>That's actually the weakest point of S-Lang. Maybe it should be solved in

Agreed.  However, you should be able to use the pcre module
(slang/modules in the slang source dist) with slrn, e.g., 
#v+
   import ("pcre");
       .
       .
   compiled_pattern = pcre_compile (pattern);
   if (pcre_exec (compiled_pattern, text_to_match)) {...}
       .
       .
#v-

The module contains documentation that may be stripped with sl2tm and
tm2txt (in the slang/doc/tm/tools directory):
#v+
  sl2tm pcre-module.c | tm2txt
#v-
to yield:

#v+
pcre_compile

 SYNOPSIS
   Compile a regular expression

 USAGE
   PCRE_Type pcre_compile (String_Type pattern [, Int_Type options])

 DESCRIPTION
   The `pcre_compile' function compiles a PCRE style regular expression
   and returns the result.  The optional `options' argument may be used
   to provide addition information affecting the compilation of the pattern.
   Specifically, it is a bit-mapped value formed from the logical-or of zero 
   or more of the following symbolic constants:

       PCRE_ANCHORED     Force the match to be at the start of a string
       PCRE_CASELESS     Matches are to be case-insensitive
       PCRE_DOLLAR_ENDONLY (See PCRE docs for more information)
       PCRE_DOTALL       The dot pattern matches all characters
       PCRE_EXTENDED     Ignore whitespace in the pattern
       PCRE_EXTRA        (See PCRE docs for features this activates)
       PCRE_MULTILINE    Treat the subject string as multi-lines
       PCRE_UNGREEDY     Make the matches greedy
       PCRE_UTF8         Regard the pattern and subject strings as UTF-8

   Many of these flags may be set within the pattern itself.   See the PCRE
   library documentation for more information about the precise details 
   of these flags and the supported regular expressions.
   
   Upon success, this function returns a `PCRE_Type' object representing
   the compiled patterned.  If compilation fails, an error will be thrown.

 SEE ALSO
   pcre_exec, pcre_nth_match, pcre_nth_substr
--------------------------------------------------------------

pcre_exec

 SYNOPSIS
   Match a string against a compiled PCRE pattern

 USAGE
   Int_Type pcre_exec(p, str [,pos [,options]]);

      PCRE_Type p;
      String_Type str;
      Int_Type pos, options;


 DESCRIPTION
   The `pcre_exec' function applies a pre-compiled pattern `p' to a 
   string `str' and returns the result of the match.  The optional third 
   argument `pos' may be used to specify the point, as an offset from the
   start of the string, where matching is to start.  The fourth argument, if
   present, may be used to provide additional information about how matching
   is to take place.  Its value may be specified as a logical-or of zero or
   more of the following flags:

      PCRE_NOTBOL      
           The first character in the string is not at the beginning of a line.
      PCRE_NOTEOL
           The last character in the string is not at the end of a line.
      PCRE_NOTEMPTY
           An empty string is not a valid match.

   See the PCRE library documentation for more information about the meaning 
   of these flags.
   
   Upon success, this function returns a positive integer equal to 1 plus the
   number of so-called captured substrings.  It returns 0 if the pattern
   fails to match the string.

 SEE ALSO
   pcre_compile, pcre_nth_match, pcre_nth_substr
--------------------------------------------------------------

pcre_nth_match

 SYNOPSIS
   Return the location of the nth match of a PCRE

 USAGE
   Int_Type[2] pcre_nth_match (PCRE_Type p, Int_Type nth)

 DESCRIPTION
   The `pcre_nth_match' function returns an integer array whose values
   specify the locations of the beginning and end of the `nth' captured 
   substrings of the most recent call to `pcre_exec' with the compiled
   pattern.  A value of `nth' equal to 0 represents the substring 
   representing the entire match of the pattern.
   
   If the `nth' match did not take place, the function returns `NULL'.

 EXAMPLE
   After the execution of:

       str = "Error in file foo.c, line 127, column 10";
       pattern = "file ([^,]+), line (\\d+)";
       p = pcre_compile (pattern);
       if (pcre_exec (p, str))
         { 
            match_pos = pcre_nth_match (p, 0);
            file_pos = pcre_nth_match (p, 1);
            line_pos = pcre_nth_match (p, 2);
         }

   `match_pos' will be set to `[9,29]', `file_pos' to `[14,19,]'
   and `line_pos' to `[26,29]'.  These integer arrays may be used to 
   extract the substrings matched by the pattern, e.g.,

        file = substr (str, file_pos[0]+1, file_pos[1]-file_pos[0]);

   Alternatively, the function `pcre_nth_substr' may be used to get the 
   matched substrings:

        file = pcre_nth_substr (p, str, 0);


 SEE ALSO
   pcre_compile, pcre_exec, pcre_nth_substr
--------------------------------------------------------------

pcre_nth_substr

 SYNOPSIS
   Extract the nth substring from a PCRE match

 USAGE
   String_Type pcre_nth_substr (PCRE_Type p, String_Type str, Int_Type nth)

 DESCRIPTION
   This function may be used to extract the `nth' captured substring
   resulting from the most recent use of the compiled pattern `p' by the
   `pcre_exec' function.  Unlike `pcre_nth_match', this function returns
   the specified captured substring itself and not the position of the substring.
   For this reason, the subject string of the pattern is a required argument.

 SEE ALSO
   pcre_compile, pcre_exec, pcre_nth_match
--------------------------------------------------------------

slang_to_pcre

 SYNOPSIS
   Convert a S-Lang regular expression to a PCRE one

 USAGE
   String_Type slang_to_pcre (String_Type pattern)

 DESCRIPTION
   This function may be used to convert a slang regular expression to a PCRE
   compatible one.  The converted is returned.

 SEE ALSO
   pcre_compile, string_match
--------------------------------------------------------------
#v-

--John
Technical Details
Message-ID: <slrnc04dao.5iu.davis@aluche.mit.edu>
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!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!nntp2.aus1.giganews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!canoe.uoregon.edu!aanews.merit.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail
References: <slrnbtv8su.e4o.usenet@pima.hostsharing.net> <slrnbu1mou.2j1.tststs@moonlight.tststs.ddns.org> <2003-12-18T19-33-21@guckes.net> <slrnbu6kmt.1cg.tststs@moonlight.tststs.ddns.org> <bs1is8$5ga$1@reader10.wxs.nl> <slrnbu9n9s.2hu.jbn@forestfield.org> <bs410m$qqt$1@reader11.wxs.nl> <slrnbucuqm.a6d.jbn@forestfield.org> <bs6ck7$l3e$1@reader10.wxs.nl> <slrnbuet82.bg4.jbn@forestfield.org> <bs9cni$oi3$1@reader10.wxs.nl> <2003-12-24T07-30-39@guckes.net> <bsbogt$hag$1@reader10.wxs.nl> <2003-12-24T10-54-38@guckes.net> <bsd6ak$42s$1@reader08.wxs.nl>

Show Full Headers
Complete Article Headers
Message-ID: <slrnc04dao.5iu.davis@aluche.mit.edu>
Subject: Re: [slrn] fixing tofu for display
Date: Mon, 12 Jan 2004 05:49:13 +0000
From: davis@space.mit.edu (John E. Davis)
References: <slrnbtv8su.e4o.usenet@pima.hostsharing.net> <slrnbu1mou.2j1.tststs@moonlight.tststs.ddns.org> <2003-12-18T19-33-21@guckes.net> <slrnbu6kmt.1cg.tststs@moonlight.tststs.ddns.org> <bs1is8$5ga$1@reader10.wxs.nl> <slrnbu9n9s.2hu.jbn@forestfield.org> <bs410m$qqt$1@reader11.wxs.nl> <slrnbucuqm.a6d.jbn@forestfield.org> <bs6ck7$l3e$1@reader10.wxs.nl> <slrnbuet82.bg4.jbn@forestfield.org> <bs9cni$oi3$1@reader10.wxs.nl> <2003-12-24T07-30-39@guckes.net> <bsbogt$hag$1@reader10.wxs.nl> <2003-12-24T10-54-38@guckes.net> <bsd6ak$42s$1@reader08.wxs.nl>
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!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!nntp2.aus1.giganews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!canoe.uoregon.edu!aanews.merit.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail
Newsgroups: news.software.readers
Organization: Center for Space Research
Reply-To: davis@space.mit.edu
User-Agent: slrn/0.9.6.4 (Linux)
Lines: 185
NNTP-Posting-Host: ALUCHE.MIT.EDU
X-Trace: 1073886553 senator-bedfellow.mit.edu 562 18.75.2.45