<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
  <title>USIN Analysis</title>
  <style type="text/css">
  BODY { background: white; }
  h1 {text-align : center;}
  </style>
<script type="text/javascript">
<!-- // bibres.js  version 1.1
     // (c) Robert D. Cameron and Serban Tatu, November 2000.
     // GNU General Public License, Version 2 applies.
var BibP_BaseURL;
var BibP_nocitehost = typeof(BibP_citehost) == "undefined";
function BibP_SetBaseURL (server) {
  BibP_BaseURL = server + "bibp1.0/resolve?" +
  (BibP_nocitehost ? "usin=" : "citehost="+ BibP_citehost+ "&usin=")}
BibP_SetBaseURL(BibP_nocitehost ? "http://usin.org/" :BibP_citehost);
function BibP_onMouseOver () {
  window.status = "bibp:" + this.href.substring(BibP_BaseURL.length);
  return true}
function BibP_onMouseOut () {window.status = "";  return true}
function BibP_ProcessLink(L, srchKey) {
  var spot = L.href.indexOf(srchKey);
  if (spot != -1) {
    L.href = BibP_BaseURL + L.href.substring(spot + srchKey.length);
    L.onmouseover = BibP_onMouseOver;
    L.onmouseout = BibP_onMouseOut}}
var BibP_Icon = new Image ();      // To test for local bibhost icon.
function BibP_onIcon () {
  if (BibP_Icon.height!=0) {
    var oldBase = BibP_BaseURL;
    BibP_SetBaseURL("http://bibhost/");
    for (var i = 0; i < document.links.length; i++)
      BibP_ProcessLink(document.links[i], oldBase)}}
function BibP_onLoad () {
  for (var i = 0; i < document.links.length; i++)
    BibP_ProcessLink(document.links[i], "bibp:")
  BibP_Icon.onload = BibP_onIcon;  // Now test for bibhost.
  BibP_Icon.src = "http://bibhost/bibp1.0/bibpicon.jpg"}
if (typeof(navigator.bibpSupport) == "undefined") {
  window.onload = BibP_onLoad}
// -->
</script>
</head>
<body>
<?php
//  USIN-analyzer.php  - USIN Analysis Service
//  Version 1.0
//  Robert D. Cameron, February 14, 2001.
//  Copyright (c) 2001,  GNU Public License, Version 2, applies.

$server_root getcwd();  
while (
basename($server_root) != 'usin.org') {
  
$server_root dirname($server_root);
}
require(
"$server_root/scripts/utilities/USIN.php");


function 
report_USIN_structure($USIN_proto) {
  
$map parse_USIN($USIN_proto);
  
$junksize strlen($map['junk']);
  if (
$junksize 0) {
    echo(
"<h1>Erroneous USIN</h1>");
  }
  else {
     echo(
"<h1>USIN Analyzer at USIN.org</h1>");
  }
  echo(
"<h3>USIN Structural Analysis</h3>\n");
  echo(
"<p>USIN protostring under analysis:" .
       
"<code>$USIN_proto</code></p>\n");
  if (
$junksize == strlen($USIN_proto)) {
    echo(
"<h3>Junk</h3><p>This is junk. " .
         
"No prefix of this string represents a valid USIN.</p>\n");
  }
  else {
    if (
$junksize 0) {
      echo(
"<h3>Well-Formed Prefix</h3>");
      if (
$junksize strlen($USIN_proto))
        echo(
"<p>This is mostly junk.\n");
      else echo(
"<p>This USIN contains junk at the end.\n");
      echo(
"The longest prefix that is a well-formed USIN:\n");
      echo(
"<code>" substr($USIN_proto0strlen($USIN_proto)-$junksize) . 
           
"</code></p>");
    }
    echo(
"<h3>USIN Type</h3>\n");
    echo(
"<p>This USIN parses as");
    if (
$map['attributes']) 
      foreach (
$map['attributes'] as $att) echo(" an attribute of");
    if (
$map['item_extensions']) 
      echo(
" an item within a collection or publication.</p>\n");
    else if (
$map['collection_label']) 
      echo(
" a particular collection or publication.</p>\n");
    else echo(
" a publication domain.</p>\n");
    echo(
"<h3>Domain</h3>\n");
    echo(
"<p>The principal domain is <code>" 
         
$map['principal_domain'] . "</code>.\n");
    
$ext_text '';
    if (!
$map['domain_extensions']) 
      echo(
"There are no domain extensions.</p>\n");
    else {
      foreach (
$map['domain_extensions'] as $ext) {
        
$ext_text .= "<li><code>$ext</code></li>\n";   
      }
      echo(
"This domain is qualified by the following extensions.</p>\n" .
           
"<ul>\n$ext_text</ul>\n");
    }
    if (
$map['collection_label']) {
      echo(
"<h3>Collection Label</h3>\n");
      echo(
"<p>The collection label is <code>" 
         
$map['collection_label'] . "</code>.</p>\n");
      if (
$map['item_extensions']) {
        echo(
"<h3>Item Extensions</h3>\n");
        echo(
"<p>Within the collection, the particular item of interest is\n" .
             
"specified through the following item extensions.<p>\n<ul>\n"); 
        foreach (
$map['item_extensions'] as $ext) {
          echo(
"<li><code>$ext</code></li>\n");
        }
        echo(
"</ul>\n");
      }    
    }
    if (
$map['attributes']) {
      echo(
"<h3>Attributes</h3>\n");
      echo(
"<p>The USIN is qualified by the following\n" .
           
" attribute specifiers.<p>\n<ul>\n"); 
      foreach (
$map['attributes'] as $ext) {
        echo(
"<li><code>$ext</code></li>\n");
      }
      echo(
"</ul>\n");
    }    
  }
}



# If this script was invoked with a QUERY_STRING, analyze that.
if (strlen($usin) != 0) {
  
report_USIN_structure($usin);
}
# If the script was invoked by a POST method setting $USIN_proto,
# analyze that.
elseif ($USIN_by_POST) {
  
report_USIN_structure($USIN_by_POST);
}
?>
<hr>
<form enctype="multipart/form-data" 
      action="http://usin.org/scripts/USIN-analyzer.php" 
      method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
<H3>USIN Syntax Analyzer</h3>
<p>
Enter a USIN protostring for analysis.  
</p>
<table>
<tr>
<td><textarea name="USIN_by_POST" type="text" cols="50" rows="5"></textarea></td>
<td><p>A USIN may be broken
over multiple lines using the USIN hyphenation convention:
hyphens followed by whitespace (blanks and newlines) may be inserted
before any operator within a USIN.
</p>
</tr>
</table>
<br>
<input TYPE="submit" VALUE="Analyze!">
</form>

</body>
</html>