File: rewriteutil.crm

package info (click to toggle)
crm114 20100106-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,120 kB
  • sloc: ansic: 34,361; sh: 617; makefile: 584; lisp: 208
file content (63 lines) | stat: -rwxr-xr-x 1,733 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/crm
#
#	rewriteutil.crm - rewrite utility using rewrites.mfp

# Copyright 2009 William S. Yerazunis.
# This file is under GPLv3, as described in COPYING.
#

#   do rewriting, based on rewrite rules in rewrites.mfp
{
	isolate (:rewrites:)
	input (:rewrites:) [:*:_arg2:]
	#    reset matching on rewrites to start of string
}

#    Be sure we're at the start of the rewrites, and the start of the :_dw:
match [:rewrites:] //
{
    #    Grab the next regexturn the one-per-line patterns into a regex
    #    First, do the line-spanning regexes.
    match //
    match <fromend nomultiline> (:ch: :fr: :to:) [:rewrites:]  /(.+)>-->(.*)/
    output [/dev/tty] /:*:_nl: checking :*:ch: -- /
    #    see if the "fr" regex matches anywhere
    {
	match <fromcurrent> (:place:) /:*:fr:/
	#  Yep, it matched... alter it and do it again
	#

	alter (:place:) /:*:to:/
	output [/dev/tty] /./
	output [/dev/tty] /:*:_dw:\n/
	liaf
    }
    #   Nope, didn't match... grab the next regex and try again,
    liaf
}

#     reset back to the start of the rewrites, and the start of the :_dw:.
#
match [:rewrites:] //
#      and do it again for non-line-spanners
{
    #    Go through and do it again, except this time do it for
    #    the non-line-spanning regexes.
    match //
    match <fromend nomultiline> (:ch: :fr: :to:) [:rewrites:]  /(.+)>->(.*)/
    output [/dev/tty] /:*:_nl:checking :*:ch: --/

    #    see if the "fr" regex matches anywhere
    {
	match <fromcurrent nomultiline> (:place:) /:*:fr:/
	#  Yep, it matched... alter it and do it again
	#
	alter (:place:) /:*:to:/
	output [/dev/tty] /./
	liaf
    }
    #   Nope, didn't match... grab the next regex and try again,
    liaf
}
output [/dev/tty] /:*:_nl:/
accept