phrep

Artifact [8991a066b1]
Login

Artifact 8991a066b19dfd4d2fa9d36b3117a03889ebdca7:

Wiki page [manpage] by mario 2015-02-21 17:35:41.
D 2015-02-21T17:35:41.660
L manpage
N text/x-markdown
U mario
W 36074
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */

/* Default font. */
body {
  font-family: Georgia,serif;
}

/* Title font. */
h1, h2, h3, h4, h5, h6,
div.title, caption.title,
thead, p.table.header,
#toctitle,
#author, #revnumber, #revdate, #revremark,
#footer {
  font-family: Arial,Helvetica,sans-serif;
}

body {
  margin: 1em 5% 1em 5%;
}

a {
  color: blue;
  text-decoration: underline;
}
a:visited {
  color: fuchsia;
}

em {
  font-style: italic;
  color: navy;
}

strong {
  font-weight: bold;
  color: #083194;
}

h1, h2, h3, h4, h5, h6 {
  color: #527bbd;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

h1, h2, h3 {
  border-bottom: 2px solid silver;
}
h2 {
  padding-top: 0.5em;
}
h3 {
  float: left;
}
h3 + * {
  clear: left;
}
h5 {
  font-size: 1.0em;
}

div.sectionbody {
  margin-left: 0;
}

hr {
  border: 1px solid silver;
}

p {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

ul, ol, li > p {
  margin-top: 0;
}
ul > li     { color: #aaa; }
ul > li > * { color: black; }

.monospaced, code, pre {
  font-family: "Courier New", Courier, monospace;
  font-size: inherit;
  color: navy;
  padding: 0;
  margin: 0;
}
pre {
  white-space: pre-wrap;
}

#author {
  color: #527bbd;
  font-weight: bold;
  font-size: 1.1em;
}
#email {
}
#revnumber, #revdate, #revremark {
}

#footer {
  font-size: small;
  border-top: 2px solid silver;
  padding-top: 0.5em;
  margin-top: 4.0em;
}
#footer-text {
  float: left;
  padding-bottom: 0.5em;
}
#footer-badges {
  float: right;
  padding-bottom: 0.5em;
}

#preamble {
  margin-top: 1.5em;
  margin-bottom: 1.5em;
}
div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.admonitionblock {
  margin-top: 2.0em;
  margin-bottom: 2.0em;
  margin-right: 10%;
  color: #606060;
}

div.content { /* Block element content. */
  padding: 0;
}

/* Block element titles. */
div.title, caption.title {
  color: #527bbd;
  font-weight: bold;
  text-align: left;
  margin-top: 1.0em;
  margin-bottom: 0.5em;
}
div.title + * {
  margin-top: 0;
}

td div.title:first-child {
  margin-top: 0.0em;
}
div.content div.title:first-child {
  margin-top: 0.0em;
}
div.content + div.title {
  margin-top: 0.0em;
}

div.sidebarblock > div.content {
  background: #ffffee;
  border: 1px solid #dddddd;
  border-left: 4px solid #f0f0f0;
  padding: 0.5em;
}

div.listingblock > div.content {
  border: 1px solid #dddddd;
  border-left: 5px solid #f0f0f0;
  background: #f8f8f8;
  padding: 0.5em;
}

div.quoteblock, div.verseblock {
  padding-left: 1.0em;
  margin-left: 1.0em;
  margin-right: 10%;
  border-left: 5px solid #f0f0f0;
  color: #888;
}

div.quoteblock > div.attribution {
  padding-top: 0.5em;
  text-align: right;
}

div.verseblock > pre.content {
  font-family: inherit;
  font-size: inherit;
}
div.verseblock > div.attribution {
  padding-top: 0.75em;
  text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
  text-align: left;
}

div.admonitionblock .icon {
  vertical-align: top;
  font-size: 1.1em;
  font-weight: bold;
  text-decoration: underline;
  color: #527bbd;
  padding-right: 0.5em;
}
div.admonitionblock td.content {
  padding-left: 0.5em;
  border-left: 3px solid #dddddd;
}

div.exampleblock > div.content {
  border-left: 3px solid #dddddd;
  padding-left: 0.5em;
}

div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; vertical-align: text-bottom; }
a.image:visited { color: white; }

dl {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
dt {
  margin-top: 0.5em;
  margin-bottom: 0;
  font-style: normal;
  color: navy;
}
dd > *:first-child {
  margin-top: 0.1em;
}

ul, ol {
    list-style-position: outside;
}
ol.arabic {
  list-style-type: decimal;
}
ol.loweralpha {
  list-style-type: lower-alpha;
}
ol.upperalpha {
  list-style-type: upper-alpha;
}
ol.lowerroman {
  list-style-type: lower-roman;
}
ol.upperroman {
  list-style-type: upper-roman;
}

div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
  margin-top: 0.1em;
  margin-bottom: 0.1em;
}

tfoot {
  font-weight: bold;
}
td > div.verse {
  white-space: pre;
}

div.hdlist {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
div.hdlist tr {
  padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
  font-weight: bold;
}
td.hdlist1 {
  vertical-align: top;
  font-style: normal;
  padding-right: 0.8em;
  color: navy;
}
td.hdlist2 {
  vertical-align: top;
}
div.hdlist.compact tr {
  margin: 0;
  padding-bottom: 0;
}

.comment {
  background: yellow;
}

.footnote, .footnoteref {
  font-size: 0.8em;
}

span.footnote, span.footnoteref {
  vertical-align: super;
}

#footnotes {
  margin: 20px 0 20px 0;
  padding: 7px 0 0 0;
}

#footnotes div.footnote {
  margin: 0 0 5px 0;
}

#footnotes hr {
  border: none;
  border-top: 1px solid silver;
  height: 1px;
  text-align: left;
  margin-left: 0;
  width: 20%;
  min-width: 100px;
}

div.colist td {
  padding-right: 0.5em;
  padding-bottom: 0.3em;
  vertical-align: top;
}
div.colist td img {
  margin-top: 0.3em;
}

@media print {
  #footer-badges { display: none; }
}

#toc {
  margin-bottom: 2.5em;
}

#toctitle {
  color: #527bbd;
  font-size: 1.1em;
  font-weight: bold;
  margin-top: 1.0em;
  margin-bottom: 0.1em;
}

div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
  margin-top: 0;
  margin-bottom: 0;
}
div.toclevel2 {
  margin-left: 2em;
  font-size: 0.9em;
}
div.toclevel3 {
  margin-left: 4em;
  font-size: 0.9em;
}
div.toclevel4 {
  margin-left: 6em;
  font-size: 0.9em;
}

span.aqua { color: aqua; }
span.black { color: black; }
span.blue { color: blue; }
span.fuchsia { color: fuchsia; }
span.gray { color: gray; }
span.green { color: green; }
span.lime { color: lime; }
span.maroon { color: maroon; }
span.navy { color: navy; }
span.olive { color: olive; }
span.purple { color: purple; }
span.red { color: red; }
span.silver { color: silver; }
span.teal { color: teal; }
span.white { color: white; }
span.yellow { color: yellow; }

span.aqua-background { background: aqua; }
span.black-background { background: black; }
span.blue-background { background: blue; }
span.fuchsia-background { background: fuchsia; }
span.gray-background { background: gray; }
span.green-background { background: green; }
span.lime-background { background: lime; }
span.maroon-background { background: maroon; }
span.navy-background { background: navy; }
span.olive-background { background: olive; }
span.purple-background { background: purple; }
span.red-background { background: red; }
span.silver-background { background: silver; }
span.teal-background { background: teal; }
span.white-background { background: white; }
span.yellow-background { background: yellow; }

span.big { font-size: 2em; }
span.small { font-size: 0.6em; }

span.underline { text-decoration: underline; }
span.overline { text-decoration: overline; }
span.line-through { text-decoration: line-through; }

div.unbreakable { page-break-inside: avoid; }


/*
 * xhtml11 specific
 *
 * */

div.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.tableblock > table {
  border: 3px solid #527bbd;
}
thead, p.table.header {
  font-weight: bold;
  color: #527bbd;
}
p.table {
  margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
  border-style: none;
}
div.tableblock > table[frame="hsides"] {
  border-left-style: none;
  border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
  border-top-style: none;
  border-bottom-style: none;
}


/*
 * html5 specific
 *
 * */

table.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
thead, p.tableblock.header {
  font-weight: bold;
  color: #527bbd;
}
p.tableblock {
  margin-top: 0;
}
table.tableblock {
  border-width: 3px;
  border-spacing: 0px;
  border-style: solid;
  border-color: #527bbd;
  border-collapse: collapse;
}
th.tableblock, td.tableblock {
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #527bbd;
}

table.tableblock.frame-topbot {
  border-left-style: hidden;
  border-right-style: hidden;
}
table.tableblock.frame-sides {
  border-top-style: hidden;
  border-bottom-style: hidden;
}
table.tableblock.frame-none {
  border-style: hidden;
}

th.tableblock.halign-left, td.tableblock.halign-left {
  text-align: left;
}
th.tableblock.halign-center, td.tableblock.halign-center {
  text-align: center;
}
th.tableblock.halign-right, td.tableblock.halign-right {
  text-align: right;
}

th.tableblock.valign-top, td.tableblock.valign-top {
  vertical-align: top;
}
th.tableblock.valign-middle, td.tableblock.valign-middle {
  vertical-align: middle;
}
th.tableblock.valign-bottom, td.tableblock.valign-bottom {
  vertical-align: bottom;
}


/*
 * manpage specific
 *
 * */

body.manpage h1 {
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  border-top: 2px solid silver;
  border-bottom: 2px solid silver;
}
body.manpage h2 {
  border-style: none;
}
body.manpage div.sectionbody {
  margin-left: 3em;
}

@media print {
  body.manpage div#toc { display: none; }
}


</style>
<script type="text/javascript">
/*<![CDATA[*/
var asciidoc = {  // Namespace.

/////////////////////////////////////////////////////////////////////
// Table Of Contents generator
/////////////////////////////////////////////////////////////////////

/* Author: Mihai Bazon, September 2002
 * http://students.infoiasi.ro/~mishoo
 *
 * Table Of Content generator
 * Version: 0.4
 *
 * Feel free to use this script under the terms of the GNU General Public
 * License, as long as you do not remove or alter this notice.
 */

 /* modified by Troy D. Hanson, September 2006. License: GPL */
 /* modified by Stuart Rackham, 2006, 2009. License: GPL */

// toclevels = 1..4.
toc: function (toclevels) {

  function getText(el) {
    var text = "";
    for (var i = el.firstChild; i != null; i = i.nextSibling) {
      if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
        text += i.data;
      else if (i.firstChild != null)
        text += getText(i);
    }
    return text;
  }

  function TocEntry(el, text, toclevel) {
    this.element = el;
    this.text = text;
    this.toclevel = toclevel;
  }

  function tocEntries(el, toclevels) {
    var result = new Array;
    var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
    // Function that scans the DOM tree for header elements (the DOM2
    // nodeIterator API would be a better technique but not supported by all
    // browsers).
    var iterate = function (el) {
      for (var i = el.firstChild; i != null; i = i.nextSibling) {
        if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
          var mo = re.exec(i.tagName);
          if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
            result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
          }
          iterate(i);
        }
      }
    }
    iterate(el);
    return result;
  }

  var toc = document.getElementById("toc");
  if (!toc) {
    return;
  }

  // Delete existing TOC entries in case we're reloading the TOC.
  var tocEntriesToRemove = [];
  var i;
  for (i = 0; i < toc.childNodes.length; i++) {
    var entry = toc.childNodes[i];
    if (entry.nodeName.toLowerCase() == 'div'
     && entry.getAttribute("class")
     && entry.getAttribute("class").match(/^toclevel/))
      tocEntriesToRemove.push(entry);
  }
  for (i = 0; i < tocEntriesToRemove.length; i++) {
    toc.removeChild(tocEntriesToRemove[i]);
  }

  // Rebuild TOC entries.
  var entries = tocEntries(document.getElementById("content"), toclevels);
  for (var i = 0; i < entries.length; ++i) {
    var entry = entries[i];
    if (entry.element.id == "")
      entry.element.id = "_toc_" + i;
    var a = document.createElement("a");
    a.href = "#" + entry.element.id;
    a.appendChild(document.createTextNode(entry.text));
    var div = document.createElement("div");
    div.appendChild(a);
    div.className = "toclevel" + entry.toclevel;
    toc.appendChild(div);
  }
  if (entries.length == 0)
    toc.parentNode.removeChild(toc);
},


/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////

/* Based on footnote generation code from:
 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
 */

footnotes: function () {
  // Delete existing footnote entries in case we're reloading the footnodes.
  var i;
  var noteholder = document.getElementById("footnotes");
  if (!noteholder) {
    return;
  }
  var entriesToRemove = [];
  for (i = 0; i < noteholder.childNodes.length; i++) {
    var entry = noteholder.childNodes[i];
    if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
      entriesToRemove.push(entry);
  }
  for (i = 0; i < entriesToRemove.length; i++) {
    noteholder.removeChild(entriesToRemove[i]);
  }

  // Rebuild footnote entries.
  var cont = document.getElementById("content");
  var spans = cont.getElementsByTagName("span");
  var refs = {};
  var n = 0;
  for (i=0; i<spans.length; i++) {
    if (spans[i].className == "footnote") {
      n++;
      var note = spans[i].getAttribute("data-note");
      if (!note) {
        // Use [\s\S] in place of . so multi-line matches work.
        // Because JavaScript has no s (dotall) regex flag.
        note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
        spans[i].innerHTML =
          "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
        spans[i].setAttribute("data-note", note);
      }
      noteholder.innerHTML +=
        "<div class='footnote' id='_footnote_" + n + "'>" +
        "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
        n + "</a>. " + note + "</div>";
      var id =spans[i].getAttribute("id");
      if (id != null) refs["#"+id] = n;
    }
  }
  if (n == 0)
    noteholder.parentNode.removeChild(noteholder);
  else {
    // Process footnoterefs.
    for (i=0; i<spans.length; i++) {
      if (spans[i].className == "footnoteref") {
        var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
        href = href.match(/#.*/)[0];  // Because IE return full URL.
        n = refs[href];
        spans[i].innerHTML =
          "[<a href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
      }
    }
  }
},

install: function(toclevels) {
  var timerId;

  function reinstall() {
    asciidoc.footnotes();
    if (toclevels) {
      asciidoc.toc(toclevels);
    }
  }

  function reinstallAndRemoveTimer() {
    clearInterval(timerId);
    reinstall();
  }

  timerId = setInterval(reinstall, 500);
  if (document.addEventListener)
    document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
  else
    window.onload = reinstallAndRemoveTimer;
}

}
asciidoc.install();
/*]]>*/
</script>

<div id="header">
<h1>
phrep(1) Manual Page
</h1>
<h2>NAME</h2>
<div class="sectionbody">
<p>phrep -
   Macro preprocessor for PHP scripts
</p>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="_synopsis">SYNOPSIS</h2>
<div class="sectionbody">
<div class="paragraph"><p><strong>phrep</strong> [<em>-OPTIONS</em>] <strong>-i</strong> <em>input.php</em> [<strong>-o</strong> <em>output.php</em>]</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_description">DESCRIPTION</h2>
<div class="sectionbody">
<div class="paragraph"><p>The <strong>phrep</strong> command applies <strong>#define</strong>, <strong>#include</strong>, <strong>#if</strong>, <strong>#else</strong>, <strong>#endif</strong>
and other C-style preprocessing directives for PHP scripts.  It also
replaces collected constants and macros within <strong>&lt;?php</strong> code sections, then
outputs the resulting source code.  Other comments and the code structure
are preserved.</p></div>
<div class="paragraph"><p>It provides some command-line similarity to <strong>cpp</strong><em>(1)</em> and further syntax
compatibility with <strong>preprocess</strong><em>(1)</em>.py and <strong>phpp</strong><em>(1)</em>.  It can read most
C/C++ header <strong>.h</strong> files or doubly-escaped <strong>// #directives</strong>.  Whereas the
<strong>#if</strong> <em>expr</em> syntax is closer to PHP.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_options">OPTIONS</h2>
<div class="sectionbody">
<div class="paragraph"><p>Option arguments can be space-separated <strong>-o</strong> <em>arg</em>, adjoined <strong>-o</strong><em>arg</em>,
or use an equal sign <strong>-o</strong>=<em>arg</em>.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>-i</strong> <em>file.php</em>
</dt>
<dd>
<p>
    Reads the input PHP script to be processed. There&#8217;s no requirement
    as to the specific file extension being used. For Makefiles or other
    build systems a <em>*.phpp</em> extension or <em>*.p.php</em> might make sense.
    <strong>phrep</strong> only processes one file at a time.
    If <strong>-i</strong><em>-</em> is used instead of a filename, then standard input is read instead.
</p>
</dd>
<dt class="hdlist1">
<strong>-o</strong> <em>output.php</em>
</dt>
<dd>
<p>
    When specified, writes the converted source file to a specific name.
    One can also use <strong>-o-</strong> to write it to standard output (that&#8217;s the
    default anyway). With <strong>-oi</strong> or <strong>-o</strong><em>input</em> the original input file is
    overwritten. Whereas <strong>-o</strong><em>target</em> is a magic name that can be set from
    within proccessed files via <strong>#pragma(</strong><em>target</em>=<code>bld/targetfn.php</code><strong>)</strong>.
</p>
</dd>
<dt class="hdlist1">
<strong>-f</strong>
</dt>
<dd>
<p>
    Force overwriting of output file. Which phrep doesn&#8217;t do per default,
    unless <strong>-oi</strong> or <strong>-oinput</strong> was specified.
</p>
</dd>
<dt class="hdlist1">
<strong>-D</strong> <em>CONST=VAL</em>
</dt>
<dd>
<p>
    Predefines a constant or a macro. Constants simply take the form
    <em>NAME=1.2.3</em> for substition values, or just <strong>-D</strong> <em>FLAG</em> for options
    that are just probed in <strong>#ifdef</strong> or <strong>#ifndef</strong> directives.
    Whereas macros require arguments in parens <em>DIV(x,y)=x/y</em>. And often
    you&#8217;d want to enclose this option in quotes to avoid shell substitution.
</p>
</dd>
<dt class="hdlist1">
<strong>-I</strong> <em>lib/inc/</em>
</dt>
<dd>
<p>
    Adds a directory to the search path for <strong>#include &lt;fn&gt;</strong> directives.
</p>
</dd>
<dt class="hdlist1">
<strong>-I</strong> <em>preload.inc</em>
</dt>
<dd>
<p>
    If an existing file is given as <strong>-I</strong> argument, then that&#8217;s read before
    the main input. It&#8217;ll however just be used to collect constants and
    macros, but will not be prepended or generate output.
</p>
</dd>
<dt class="hdlist1">
<strong>-w</strong>
</dt>
<dd>
<p>
    Suppress all warning messages.
</p>
</dd>
<dt class="hdlist1">
<strong>-W</strong>
</dt>
<dd>
<p>
    Turn all warnings into errors instead, and stop execution.
</p>
</dd>
<dt class="hdlist1">
<strong>-m</strong> <em>token</em>
</dt>
<dd>
<p>
    The constant/macro substitution phase is context-sensitive per default.
    It will only replace constants within <strong>&lt;?php</strong> code sections.
</p>
<div class="ulist"><ul>
<li>
<p>
The alternative <strong>-m</strong> <em>regex</em> mode however will replace constants
       irrespective of that (in raw HTML areas before PHP code, in strings,
       in comments; really everywhere).
</p>
</li>
<li>
<p>
You can define custom delimiters with <strong>-m</strong> "<em>regex [[ ]]</em>" to constrain
       that. Thus constants would only be replaced where written as <code>[[DEFNAME]]</code>
       or macros enclosed as <code>[[HTML_INPUT(text,title,href]]</code> for example.
</p>
</li>
<li>
<p>
Or use predefined constant delimiters <em>%{</em> and <em>}</em> with <strong>-m erb</strong>,
       or in the <strong>-m phpp</strong> mode <em>{{{</em> and <em>}}}</em> for example.
</p>
</li>
</ul></div>
</dd>
<dt class="hdlist1">
<strong>-k</strong>
</dt>
<dd>
<p>
    Keep empty lines in place for <strong>#include</strong> or <strong>#define</strong> and <strong>#if</strong> etc
    directives.
</p>
</dd>
<dt class="hdlist1">
<strong>-p</strong> <em>opt=val</em>
</dt>
<dd>
<p>
    Set further processing (<strong>#pragma</strong>) options.
</p>
</dd>
<dt class="hdlist1">
<strong>-E</strong>
</dt>
<dd>
<p>
    NOP.
</p>
</dd>
<dt class="hdlist1">
<strong>-v</strong>
</dt>
<dd>
<p>
    NOP.
</p>
</dd>
<dt class="hdlist1">
<strong>-V</strong>
</dt>
<dd>
<p>
    Print program version number.
</p>
</dd>
<dt class="hdlist1">
<strong>-h</strong>
</dt>
<dd>
<p>
    Outputs a short help page and option summary.
</p>
</dd>
</dl></div>
</div>
</div>
<div class="sect1">
<h2 id="X1">DIRECTIVES (No! They&#8217;re not <em>hashtags</em>)</h2>
<div class="sectionbody">
<div class="paragraph"><p>Preprocessing <strong>#directives</strong> are mostly in-line
with their CPP equivalents.  They must be noted leftmost in source code.
Albeit up to two ␣␣ spaces may be prepended.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>#define</strong> <em>CONSTANT</em>
</dt>
<dd>
<p>
    Declares a constant without value. This is mostly used to provide
    known identifiers for <strong>#ifdef</strong> and <strong>#ifndef</strong> directives.
</p>
</dd>
<dt class="hdlist1">
<strong>#define</strong> <em>CONSTANT</em> <em>VALUE</em>
</dt>
<dd>
<p>
    Value literals can be interpolated in <strong>&lt;?php</strong> sections later. The value
    can be string or number, or often a version number. To use them in PHP
    code sections it&#8217;s sensible to enquote <em>"strings"</em> already.
</p>
</dd>
<dt class="hdlist1">
<strong>#define</strong> <em>MACRO(x,y)</em> <em>(2*x+3*y)</em>
</dt>
<dd>
<p>
    Defines a standard macro. Complex macros (see next section) are defined
    by naming them with a trailing <em>@</em>. Note that <strong>#macro</strong> is an alias for
    <strong>#define</strong>.
</p>
</dd>
<dt class="hdlist1">
<strong>#undef</strong> <em>CONSTANT</em>
</dt>
<dd>
<p>
    Undefines a previously defined constant or macro.
</p>
</dd>
<dt class="hdlist1">
<strong>#ifdef</strong> <em>CONSTANT</em>
</dt>
<dd>
<p>
    Checks for a declared identifier. If it&#8217;s undefined, then following
    source code is omitted from output until an <strong>#else</strong>, <strong>#elif</strong> or <strong>#endif</strong> etc.
</p>
</dd>
<dt class="hdlist1">
<strong>#ifndef</strong> <em>CONSTANT</em>
</dt>
<dd>
<p>
    Probes if a constant does <strong>not</strong> exist.
</p>
</dd>
<dt class="hdlist1">
<strong>#else</strong>
</dt>
<dd>
<p>
    If all previous conditional sections failed, then code between <strong>#else</strong>
    and <strong>#endif</strong> will be written out.
</p>
</dd>
<dt class="hdlist1">
<strong>#if</strong> <em>expr</em>
</dt>
<dd>
<p>
    You can check for more complex conditions using an if expression.
</p>
<div class="ulist"><ul>
<li>
<p>
<em>7 * 12 &gt; 3 / 0.5 || (12 / 4 ^ 2)</em> &#8658; Common arithmetic
       and comparison operations.
</p>
</li>
<li>
<p>
<em>CONST &gt; 2.0.0-beta</em> &#8658;  Is often used for comparing version tuples
       or floats.
</p>
</li>
<li>
<p>
<em>VER =~ beta</em> &#8658;  Does a case-insensitive regex comparison.
</p>
</li>
<li>
<p>
<em>defined(WHATEVER) || defined("PKG_VERSION")</em> &#8658;
        The <strong>defined()</strong> function tests for existing constants within
        arbitrary expressions. A few PHP more functions like <strong>strpos</strong>,
        <strong>is_int</strong>, etc. may also be used. Most constants can be written
        as literals and/or put in quotes.
</p>
</li>
</ul></div>
</dd>
<dt class="hdlist1">
<strong>#elif</strong> <em>expr</em>
</dt>
<dd>
<p>
    Works like <strong>#if</strong>, but is used as alternative condition leave between
    if and else/endif.
</p>
</dd>
<dt class="hdlist1">
<strong>#endif</strong>
</dt>
<dd>
<p>
    Ends a conditional section. Note that #if/#endif constructs can be
    nested.  Which is where minimally space-indentend ␣#if* directives
    become useful.
</p>
</dd>
<dt class="hdlist1">
<strong>#include</strong> <em>&lt;config.php&gt;</em>
</dt>
<dd>
<p>
    Loads a referenced file, consumes its constant and macro definitions
    and literal source output, but has <strong>&lt;?php</strong> and <strong>?&gt;</strong> tags stripped.
    Files are searched among the <strong>-I</strong> include dirs, when relative paths
    have been given.
    Filename enclosures <strong>&lt;&gt;</strong> and <strong>""</strong> or <strong><code>''</code></strong> are all equivalent to <strong>phrep</strong>
    (unlike for <strong>cpp</strong>), and they can even be omitted.
</p>
<div class="ulist"><ul>
<li>
<p>
<em>"lib/deps.ph"</em> - Common extensions for PHP includes are
      just <strong>.php</strong> or <strong>.ph</strong> for header-style files, or even the olden <strong>.inc</strong>,
      and are usually interpolated.
</p>
</li>
<li>
<p>
<em>&lt;header.h&gt;</em> - While C header <strong>.h</strong> or macro <strong>.def</strong> files have
      their output suppressed by default.
</p>
</li>
</ul></div>
</dd>
<dt class="hdlist1">
<strong>#pragma(</strong><em>option=value</em><strong>)</strong>
</dt>
<dd>
<p>
    Sets preprocessing and substition options from within source files.<br />
    For instance there are:
</p>
<div class="ulist"><ul>
<li>
<p>
<em>output</em>=<em>0</em> to omit further code from the current or included files.
</p>
</li>
<li>
<p>
<em>target</em>=<em>filename.php</em> to override the target filename for <strong>phrep -o target</strong>.
</p>
</li>
<li>
<p>
<em>omit</em>=<em>*.{h,def}</em> is a glob pattern to declare which includes to generally suppress output from.
</p>
</li>
<li>
<p>
<em>comments</em>=<em>0</em> strips inline comments from constants.
</p>
</li>
<li>
<p>
<em>macros</em>=<em>0</em> disables reading macro definitions.
</p>
</li>
<li>
<p>
<em>complex</em>=<em>0</em> disables complex macros (PHP callback code).
</p>
</li>
<li>
<p>
<em>multipass</em>=<em>1</em> enables macro-in-macro substitution.
</p>
</li>
<li>
<p>
<em>keep_empty</em>=<em>1</em> retains empty lines for inactive conditional sections
       (see <strong>-k</strong> flag).
</p>
</li>
<li>
<p>
<em>fail</em>=<em>1</em> makes preprocessing fail with fatal errors instead of
       warnings (equals <strong>-W</strong> option).
</p>
</li>
<li>
<p>
<em>quiet</em>=<em>1</em> disables warnings (equals <strong>-w</strong> option).
</p>
</li>
<li>
<p>
<em>interpolate</em>=<em>delim &lt;&lt; &gt;&gt;</em> is the <strong>-m</strong> option.
</p>
</li>
<li>
<p>
<em>dirs</em>=<em>./lib</em><strong>:</strong><em>../includes</em> can add further search paths, like the <strong>-I</strong> option.
</p>
</li>
</ul></div>
</dd>
<dt class="hdlist1">
 
</dt>
<dd>
<p>
The more traditional <strong><code>#pragma option value</code></strong> syntax is also allowed.
</p>
</dd>
<dt class="hdlist1">
<strong>#stderr</strong> Message string
</dt>
<dd>
<p>
    Outputs a warning or error message. (To be used within conditional sections).
</p>
</dd>
<dt class="hdlist1">
<strong>#srcout</strong> Literal code
</dt>
<dd>
<p>
    Adds code to the output. This is a <strong>phrep</strong>-specific extension. It&#8217;s
    intended to keep unpreprocessed .php scripts running, by escaping some
    literal code that would trip up PHP interpretion else.
</p>
</dd>
<dt class="hdlist1">
<strong>#macro</strong> NAME(x) (x+1)
</dt>
<dd>
<p>
    Is just an alias for <strong>#define</strong>.
</p>
</dd>
</dl></div>
</div>
</div>
<div class="sect1">
<h2 id="_constant_usage">CONSTANT USAGE</h2>
<div class="sectionbody">
<div class="paragraph"><p>Now some care must be taken to not inadvertently overwrite PHP-code
constants everywhere.  Define your preprocessing constants with unambiguous
names. Use common prefixes such as <strong>PKG_</strong>, <strong>BLD_</strong> or <strong>USE_</strong>.</p></div>
<div class="paragraph"><p>Internal/C-style predefined constants for example are <strong><code>__STDC_VERSION__</code></strong>,
<strong><code>__TIMESTAMP__</code></strong>, and <strong><code>__PHP_VERSION__</code></strong> (which is the PHP version used at
build/preprocessing time, not the PHP runtimes´ <em>PHP_VERSION</em> in later script
executions).</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_standard_macros">STANDARD MACROS</h2>
<div class="sectionbody">
<div class="paragraph"><p>Standard/basic macros allow code substitutions. They&#8217;re in line with CPP,
and simply <strong>#define</strong> <em>MACRO</em><strong>(</strong><em>a</em><strong>,</strong><em>b</em><strong>)</strong> names with a list of params
along.  Params don&#8217;t use <strong>$</strong> variable prefixes in their definition or the
replacement code.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Declaration
</dt>
<dd>
<p>
    <strong>#define</strong> ␣ <em>MUL</em><strong>(</strong><em>a</em><strong>,</strong><em>b</em><strong>)</strong> ␣ <em>(a*b)</em>
</p>
</dd>
<dt class="hdlist1">
Usage in PHP code
</dt>
<dd>
<p>
    <em>$var</em> = <strong>MUL(7,5)</strong>;
</p>
</dd>
<dt class="hdlist1">
Becomes
</dt>
<dd>
<p>
    <em>$var</em> = <strong>(7*5)</strong>;
</p>
</dd>
</dl></div>
<div class="paragraph"><p>This is obviously not the most useful example. Their purpose is to shorten
lengthier code templates.  Important to note however is that interpolated
args <em>a</em> or <em>b</em> often need to be parenthesized <em>(a)*(b)</em> themselves. Because
macro arguments <em>MUL(1+2,3+4)</em> can be expressions instead of just literals.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_complex_macros">COMPLEX MACROS</h2>
<div class="sectionbody">
<div class="paragraph"><p>Complex macros can be defined using an <em>@</em>-decorated macro name and an
anonymous function body. The param definition again doesn&#8217;t use <strong>$</strong> signs,
but the substitution code must:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Declaration
</dt>
<dd>
<p>
    <strong>#define</strong> ␣ <em>MSTR@</em><strong>(</strong><em>i</em><strong>,</strong><em>str</em><strong>)</strong> ␣ <strong><code>{return '"'.str_repeat(</code></strong><em>$str</em><strong>,</strong><em>$i</em><strong><code>).'"';}</code></strong>
</p>
</dd>
<dt class="hdlist1">
Usage in PHP code
</dt>
<dd>
<p>
    <em>$var</em> = <strong>MSTR@(3,abc)</strong>;
</p>
</dd>
<dt class="hdlist1">
Becomes
</dt>
<dd>
<p>
    <em>$var</em> = <strong>"abcabcabc"</strong>;
</p>
</dd>
</dl></div>
<div class="paragraph"><p>Notably now the macro must take care to produce valid PHP code from its
literal/stringified arguments, which become <em>$i</em> and <em>$str</em>.</p></div>
<div class="paragraph"><p>A <em>varg&#8230;</em> parameter can also be used as macro declaration argument.
It becomes <em>$varg</em> for the callback, and collects extraneous arguments
(as a list of expr/value strings).</p></div>
<div class="paragraph"><p>There&#8217;s also an implied <em>$token</em> parameter for each complex macro callback.
It&#8217;s an array of all macro arguments, but not in string form.  Each entry is
a list of PHP parser tokens (T_VARIABLE, T_IS_EQUAL, T_LNUMBER, etc).
Obviously they&#8217;re more involving to craft, but would allow more complex
expression transformations.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_exit_status">EXIT STATUS</h2>
<div class="sectionbody">
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>0</strong>
</dt>
<dd>
<p>
    Successfully successed.
</p>
</dd>
<dt class="hdlist1">
<strong>1</strong>
</dt>
<dd>
<p>
    Failure (syntax or usage error; document processing failure; etc).
</p>
</dd>
<dt class="hdlist1">
<strong>66</strong>
</dt>
<dd>
<p>
    No input <strong>-i</strong> file given.
</p>
</dd>
<dt class="hdlist1">
<strong>70</strong>
</dt>
<dd>
<p>
    Internal software error, mostly invalid preprocessing directives
    or #if expressions.
</p>
</dd>
<dt class="hdlist1">
<strong>73</strong>
</dt>
<dd>
<p>
    Refusing to overwriting existing <strong>-o</strong> output file.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>Anyway, just check for an exit code <em>&gt; 0</em> and output on <strong>stderr</strong>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_environment">ENVIRONMENT</h2>
<div class="sectionbody">
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>PHP_INCLUDE_PATH</strong>
</dt>
<dd>
<p>
    May predefine a list of <strong>-I</strong> include search dirs.
</p>
</dd>
<dt class="hdlist1">
<strong>XDG_CONFIG_HOME</strong>
</dt>
<dd>
<p>
    No configuration file is present per default. One can however
    craft a <em>~/.config/php/phrep.php</em> script. - It&#8217;ll run after <em>$opts</em>
    and <em>$proc</em> have been initialized. Which allows to override some
    settings, or predefine utility functions / bindings for complex
    macro callbacks.
</p>
</dd>
</dl></div>
</div>
</div>
<div class="sect1">
<h2 id="_bugs">BUGS</h2>
<div class="sectionbody">
<div class="paragraph"><p>Yes, certainly.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_author">AUTHOR</h2>
<div class="sectionbody">
<div class="paragraph"><p>:x</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_license">LICENSE</h2>
<div class="sectionbody">
<div class="paragraph"><p>MIT License</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_see_also">SEE ALSO</h2>
<div class="sectionbody">
<div class="paragraph"><p><strong>cpp</strong><em>(1)</em>, <strong>phpp</strong><em>(1)</em>, <strong>preprocess</strong><em>(1)</em>, <strong>php</strong><em>(1)</em>, <strong>ccpp</strong><em>(1)</em></p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Repository/Docs</strong>
</dt>
<dd>
<p>
    <a href="http://fossil.include-once.org/phrep/">http://fossil.include-once.org/phrep/</a>
</p>
</dd>
<dt class="hdlist1">
<strong>Announcements</strong>
</dt>
<dd>
<p>
    <a href="http://freshcode.club/projects/macro.php">http://freshcode.club/projects/macro.php</a>
</p>
</dd>
</dl></div>
</div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2015-02-21 01:27:10 CET
</div>
</div>
</body>
</html>

Z cef25627cb8ec76366924fbb95214bec