[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146]
[0147]
[0148]
[0149]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164]
[0165]
[0166]
[0167]
[0168]
[0169]
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184]
[0185]
[0186]
[0187]
[0188]
[0189]
[0190]
[0191]
[0192]
[0193]
[0194]
[0195]
[0196]
[0197]
[0198]
[0199]
[0200]
[0201]
[0202]
[0203]
[0204]
[0205]
[0206]
[0207]
[0208]
[0209]
[0210]
[0211]
[0212]
[0213]
[0214]
[0215]
[0216]
[0217]
[0218]
[0219]
[0220]
[0221]
[0222]
[0223]
[0224]
[0225]
[0226]
[0227]
[0228]
[0229]
[0230]
[0231]
[0232]
[0233]
[0234]
[0235]
[0236]
[0237]
[0238]
[0239]
[0240]
[0241]
[0242]
[0243]
[0244]
[0245]
[0246]
[0247]
[0248]
[0249]
[0250]
[0251]
[0252]
[0253]
[0254]
[0255]
[0256]
[0257]
[0258]
[0259]
[0260]
[0261]
[0262]
[0263]
[0264]
[0265]
[0266]
[0267]
[0268]
[0269]
[0270]
[0271]
[0272]
[0273]
[0274]
[0275]
[0276]
[0277]
[0278]
[0279]
[0280]
[0281]
[0282]
[0283]
[0284]
[0285]
[0286]
[0287]
[0288]
[0289]
[0290]
[0291]
[0292]
[0293]
[0294]
[0295]
[0296]
[0297]
[0298]
[0299]
[0300]
[0301]
[0302]
[0303]
[0304]
[0305]
[0306]
[0307]
[0308]
[0309]
[0310]
[0311]
[0312]
[0313]
[0314]
[0315]
[0316]
[0317]
[0318]
[0319]
[0320]
[0321]
[0322]
[0323]
[0324]
[0325]
[0326]
[0327]
[0328]
[0329]
[0330]
[0331]
[0332]
[0333]
[0334]
[0335]
[0336]
[0337]
[0338]
[0339]
[0340]
[0341]
[0342]
[0343]
[0344]
[0345]
[0346]
[0347]
[0348]
[0349]
[0350]
[0351]
[0352]
[0353]
[0354]
[0355]
[0356]
[0357]
[0358]
[0359]
[0360]
[0361]
[0362]
[0363]
[0364]
[0365]
[0366]
[0367]
[0368]
[0369]
[0370]
[0371]
[0372]
[0373]
[0374]
[0375]
[0376]
[0377]
[0378]
[0379]
[0380]
[0381]
[0382]
[0383]
[0384]
[0385]
[0386]
[0387]
[0388]
[0389]
[0390]
[0391]
[0392]
[0393]
[0394]
[0395]
[0396]
[0397]
[0398]
[0399]
[0400]
[0401]
[0402]
[0403]
[0404]
[0405]
[0406]
[0407]
[0408]
[0409]
[0410]
[0411]
[0412]
[0413]
[0414]
[0415]
[0416]
[0417]
[0418]
[0419]
[0420]
[0421]
[0422]
[0423]
[0424]
[0425]
[0426]
[0427]
[0428]
[0429]
[0430]
[0431]
[0432]
[0433]
[0434]
[0435]
[0436]
[0437]
[0438]
[0439]
[0440]
[0441]
[0442]
[0443]
[0444]
[0445]
[0446]
[0447]
[0448]
[0449]
[0450]
[0451]
[0452]
[0453]
[0454]
[0455]
[0456]
[0457]
[0458]
[0459]
[0460]
[0461]
[0462]
[0463]
[0464]
[0465]
[0466]
[0467]
[0468]
[0469]
[0470]
[0471]
[0472]
[0473]
[0474]
[0475]
[0476]
[0477]
[0478]
[0479]
[0480]
[0481]
[0482]
[0483]
[0484]
[0485]
[0486]
[0487]
[0488]
[0489]
[0490]
[0491]
[0492]
[0493]
[0494]
[0495]
[0496]
[0497]
[0498]
[0499]
[0500]
[0501]
[0502]
[0503]
[0504]
[0505]
[0506]
[0507]
[0508]
[0509]
[0510]
[0511]
[0512]
[0513]
[0514]
[0515]
[0516]
[0517]
[0518]
[0519]
[0520]
[0521]
[0522]
[0523]
[0524]
[0525]
[0526]
[0527]
[0528]
[0529]
[0530]
[0531]
[0532]
[0533]
[0534]
[0535]
[0536]
[0537]
[0538]
[0539]
[0540]
[0541]
[0542]
[0543]
[0544]
[0545]
[0546]
[0547]
[0548]
[0549]
[0550]
[0551]
[0552]
[0553]
[0554]
[0555]
[0556]
[0557]
[0558]
[0559]
[0560]
[0561]
[0562]
[0563]
[0564]
[0565]
[0566]
[0567]
[0568]
[0569]
[0570]
[0571]
[0572]
[0573]
[0574]
[0575]
[0576]
[0577]
[0578]
[0579]
[0580]
[0581]
[0582]
[0583]
[0584]
[0585]
[0586]
[0587]
[0588]
[0589]
[0590]
[0591]
[0592]
[0593]
[0594]
[0595]
[0596]
[0597]
[0598]
[0599]
[0600]
[0601]
[0602]
[0603]
[0604]
[0605]
[0606]
[0607]
[0608]
[0609]
[0610]
[0611]
[0612]
[0613]
[0614]
[0615]
[0616]
[0617]
[0618]
[0619]
[0620]
[0621]
[0622]
[0623]
[0624]
[0625]
[0626]
[0627]
[0628]
[0629]
[0630]
[0631]
[0632]
[0633]
[0634]
/*****************************************************************************/
/*
                               ReportError.c

A CGI-compliant script.
The greater efficiencies mean it's much better used as a CGIplus script!

Provided to work in with the WASD HTTPd [ErrorReportScript] configuration
parameter, this script is designed to be both a basic work-horse for
implementing a local error reporting format as well as a template and/or basis
for a local reporting script.  Configuration directives (either/or):

   [ErrorReportScript] /cgi-bin/reporterror

   [ErrorReportScript] /cgiplus-bin/reporterror

The /DEFAULT qualifier generates an error report much like that supplied by
native WASD HTTPd error reporting.


LOCALLY IMPLEMENTED REPORTING CODE
----------------------------------

Using the /HEADER qualifier this program can be called from a DCL procedure to
supply an appropriate (and correct) HTTP response header, IMPORTANTLY providing
a correct challenge for 401 errors (authorization required).  The procedure
could then go on to provide the body of the error report.

The /LOCAL qualifier results in the LocalReport() function being called.  This
function stub is provided as a simple place-holder for a locally implemented
error report.  ANY LOCAL VERSION MUST BE CAREFUL TO SUPPLY CORRECT RESPONSE
HEADERS FOR 401 ERRORS (authorization required) ... using the HttpHeader()
function is strongly recommended.  The "WWW_FORM_ERROR..." CGI variables listed
below supply relevant information specially generated by the HTTPd for error
reporting.  When developing a local version be sure to move the source code out
of the WASD_ROOT:[SRC.MISC] so it's not lost in some future update!


CGI VARIABLES
-------------

WWW_FORM_ERROR_ABOUT        item message is about (if applicable)
WWW_FORM_ERROR_ABOUT2       additional information (if applicable)
WWW_FORM_ERROR_BASIC        basic authentication challenge
WWW_FORM_ERROR_DIGEST       digest authentication challenge
WWW_FORM_ERROR_LINE         name of source code line (e.g. "1732")
WWW_FORM_ERROR_MODULE       name of source code module (e.g. "REQUEST")
WWW_FORM_ERROR_STATUS       HTTP status code (e.g. "404")
WWW_FORM_ERROR_STATUS_TEXT  brief description of status code (e.g. "Not Found")
WWW_FORM_ERROR_STATUS_EXPLANATION  longer description of status code
WWW_FORM_ERROR_TEXT         server-generated error message
WWW_FORM_ERROR_TEXT2        server suggestion about what to do about it :^)
WWW_FORM_ERROR_TYPE         "basic" or "detailed"
WWW_FORM_ERROR_VMS          VMS status value, decimal (if applicable)

WWW_HTTP_PRAGMA             "no-cache" (optional)
WWW_HTTP_REFERER            "close" button becomes active
WWW_PATH_INFO               URL path to shelf
WWW_PATH_TRANSLATED         VMS file specification for shelf
WWW_REQUEST_METHOD          any method
WWW_REQUEST_CHARSET         request determined character set
WWW_SCRIPT_NAME             path to script
WWW_SERVER_CHARSET          server default character set
WWW_SERVER_NAME             host on which the script is executing
WWW_SERVER_PORT             port from which the script is executing
WWW_SERVER_SIGNATURE        server's "signature"
WWW_SERVER_SOFTWARE         HTTPd identifying string


QUALIFIERS
----------
/CHARSET=       "Content-Type: text/html; charset=...", empty suppress charset
/DBUG           turns on all "if (Debug)" statements (don't use with OSU)
/DEFAULT        output the default error report
/HEADER         output an appropriate HTTP response header only
/LOCAL          execute the error reporting function ProcessLocal()
/MORE=          string added to bottom of default report (can be any HTML)


LOGICAL NAMES
-------------
REPORTERROR$DBUG       turns on all "if (Debug)" statements
REPORTERROR$PARAM      equivalent to (overrides) the command line
                       parameters/qualifiers (define as a system-wide logical)


BUILD DETAILS
-------------
See BUILD_REPORTERROR.COM procedure.


COPYRIGHT
---------
Copyright (C) 1998-2021 Mark G.Daniel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


VERSION HISTORY (update SoftwareID as well!)
---------------
23-DEC-2003  MGD  v1.3.1, minor conditional mods to support IA64
28-OCT-2000  MGD  v1.3.0, use CGILIB object module
12-APR-2000  MGD  v1.2.0, reflect changes in WASD v7.0 report format
24-APR-1999  MGD  v1.1.0, use CGILIB.C
18-OCT-1998  MGD  v1.0.0, initial (with HTTPd v5.3 [ErrorReportPath])
*/
/*****************************************************************************/

#define SOFTWAREVN "1.3.1"
#define SOFTWARENM "REPORTERROR"
#ifdef __ALPHA
#  define SOFTWAREID SOFTWARENM " AXP-" SOFTWAREVN
#endif
#ifdef __ia64
#  define SOFTWAREID SOFTWARENM " IA64-" SOFTWAREVN
#endif
#ifdef __VAX
#  define SOFTWAREID SOFTWARENM " VAX-" SOFTWAREVN
#endif
#ifdef __x86_64
#  define SOFTWAREID SOFTWARENM " X86-" SOFTWAREVN
#endif

/* standard C header files */
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unixio.h>

/* VMS-related header files */
#include <descrip.h>
#include <ssdef.h>
#include <stsdef.h>

/* application header file */
#include <cgilib.h>

#define boolean int
#define true 1
#define false 0

#ifndef __VAX
#   pragma nomember_alignment
#endif

#define VMSok(x) ((x) & STS$M_SUCCESS)
#define VMSnok(x) (!((x) & STS$M_SUCCESS))
 
#define DEFAULT_CHARSET "ISO-8859-1"

#define HTML_BODY_TAG "<BODY>"

char  Utility [] = "REPORTERROR";

boolean  Debug,
         DoDefaultReport,
         DoLocalReport,
         HeaderOnly,
         HttpHasBeenOutput,
         IsCgiPlus,
         MethodHead,
         PragmaNoCache,
         ReportDetailed;

int  StatusClass,
     StatusCode;

char  *CgiEnvironmentPtr,
      *CgiFormErrorBasicPtr,
      *CgiFormErrorDigestPtr,
      *CgiFormErrorAboutPtr,
      *CgiFormErrorAbout2Ptr,
      *CgiFormErrorLinePtr,
      *CgiFormErrorModulePtr,
      *CgiFormErrorTextPtr,
      *CgiFormErrorText2Ptr,
      *CgiFormErrorStatusPtr,
      *CgiFormErrorStatusTextPtr,
      *CgiFormErrorStatusExplPtr,
      *CgiFormErrorTypePtr,
      *CgiFormErrorVmsPtr,
      *CgiHttpPragmaPtr,
      *CgiPathInfoPtr,
      *CgiPathTranslatedPtr,
      *CgiRequestMethodPtr,
      *CgiRequestTimeGmtPtr,
      *CgiScriptNamePtr,
      *CgiServerNamePtr,
      *CgiServerPortPtr,
      *CgiServerProtocolPtr,
      *CgiServerSignaturePtr,
      *CgiServerSoftwarePtr,
      *CgiTypePtr,
      *CharsetPtr,
      *CliCharsetPtr,
      *MoreInfoPtr = "",
      *PageFileNamePtr;

char  BasicChallenge [256],
      ContentTypeCharset [64],
      DigestChallenge [256],
      SoftwareID [48];

/*****************************************************************************/
/*
*/

main ()

{
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   sprintf (SoftwareID, "%s (%s)", SOFTWAREID, CgiLibEnvironmentVersion());

   if (getenv ("REPORTERROR$DBUG") != NULL) Debug = true;
   CgiLibEnvironmentSetDebug (Debug);

   CgiLibEnvironmentInit (0, NULL, false);

   GetParameters ();

   CgiLibResponseSetSoftwareID (SoftwareID);
   CgiLibResponseSetErrorMessage ("Reported by reportERROR");

   IsCgiPlus = CgiLibEnvironmentIsCgiPlus ();

   /***********/
   /* process */
   /***********/

   if (IsCgiPlus)
   {
      for (;;)
      {
         /* block waiting for next request */
         CgiLibVar ("");
         ProcessRequest ();
         CgiLibCgiPlusEOF ();
      }
   }
   else
      ProcessRequest ();

   exit (SS$_NORMAL);
}

/*****************************************************************************/
/*
*/ 
 
ProcessRequest ()

{
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "ProcessRequest()\n");

   CgiEnvironmentPtr = CgiLibEnvironmentName ();

   HttpHasBeenOutput = false;

   CgiHttpPragmaPtr = CgiLibVar ("WWW_HTTP_PRAGMA");
   CgiPathInfoPtr = CgiLibVar ("WWW_PATH_INFO");
   CgiPathTranslatedPtr = CgiLibVar ("WWW_PATH_TRANSLATED");
   CgiRequestMethodPtr = CgiLibVar ("WWW_REQUEST_METHOD");
   CgiRequestTimeGmtPtr = CgiLibVar ("WWW_REQUEST_TIME_GMT");
   CgiScriptNamePtr = CgiLibVar ("WWW_SCRIPT_NAME");
   CgiServerNamePtr = CgiLibVar ("WWW_SERVER_NAME");
   CgiServerPortPtr = CgiLibVar ("WWW_SERVER_PORT");
   CgiServerSignaturePtr = CgiLibVar ("WWW_SERVER_SIGNATURE");
   CgiServerSoftwarePtr = CgiLibVar ("WWW_SERVER_SOFTWARE");
   CgiServerProtocolPtr = CgiLibVar ("WWW_SERVER_PROTOCOL");

   if ((CharsetPtr = CliCharsetPtr) == NULL)
   {
      CharsetPtr = CgiLibVar ("WWW_REQUEST_CHARSET");
      if (!CharsetPtr[0]) CharsetPtr = CgiLibVar ("WWW_SERVER_CHARSET");
      if (!CharsetPtr[0]) CharsetPtr = DEFAULT_CHARSET;
   }
   if (CharsetPtr[0])
      sprintf (ContentTypeCharset, "; charset=%s", CharsetPtr);
   else
      ContentTypeCharset[0] = '\0';

   if (!strcmp (CgiRequestMethodPtr, "HEAD"))
      MethodHead = true;
   else
      MethodHead = false;

   if (strsame (CgiHttpPragmaPtr, "no-cache", -1))
      PragmaNoCache = true;
   else
      PragmaNoCache = true;

   CgiFormErrorBasicPtr = CgiLibVar ("WWW_FORM_ERROR_BASIC");
   CgiFormErrorDigestPtr = CgiLibVar ("WWW_FORM_ERROR_DIGEST");
   CgiFormErrorAboutPtr = CgiLibVar ("WWW_FORM_ERROR_ABOUT");
   CgiFormErrorAbout2Ptr = CgiLibVar ("WWW_FORM_ERROR_ABOUT2");
   CgiFormErrorLinePtr = CgiLibVar ("WWW_FORM_ERROR_LINE");
   CgiFormErrorModulePtr = CgiLibVar ("WWW_FORM_ERROR_MODULE");
   CgiFormErrorStatusPtr = CgiLibVar ("WWW_FORM_ERROR_STATUS");
   CgiFormErrorStatusTextPtr = CgiLibVar ("WWW_FORM_ERROR_STATUS_TEXT");
   CgiFormErrorStatusExplPtr = CgiLibVar ("WWW_FORM_ERROR_STATUS_EXPLANATION");
   CgiFormErrorTextPtr = CgiLibVar ("WWW_FORM_ERROR_TEXT");
   CgiFormErrorText2Ptr = CgiLibVar ("WWW_FORM_ERROR_TEXT2");
   CgiFormErrorTypePtr = CgiLibVar ("WWW_FORM_ERROR_TYPE");
   CgiFormErrorVmsPtr = CgiLibVar ("WWW_FORM_ERROR_VMS");

   if (strsame (CgiFormErrorTypePtr, "detailed", -1))
      ReportDetailed = true;
   else
      ReportDetailed = false;

   StatusCode = atoi(CgiFormErrorStatusPtr);
   StatusClass = StatusCode / 100;

   /* if it's an authorization challenge */
   if (StatusCode == 401 ||
       StatusCode == 407)
   {
      if (CgiFormErrorBasicPtr[0])
         sprintf (BasicChallenge, "%s\r\n", CgiFormErrorBasicPtr);
      else
         BasicChallenge[0] = '\0';
      if (CgiFormErrorDigestPtr[0])
         sprintf (DigestChallenge, "%s\r\n", CgiFormErrorDigestPtr);
      else
         DigestChallenge[0] = '\0';
   }
   else
      BasicChallenge[0] = DigestChallenge[0] = '\0';

   if (HeaderOnly)
      HttpHeader ();
   else
   if (DoDefaultReport || strsame (CgiPathInfoPtr, "/default", -1))
      DefaultReport ();
   else
   if (DoLocalReport || strsame (CgiPathInfoPtr, "/local", -1))
      LocalReport ();
   else
      DefaultReport ();
}

/*****************************************************************************/
/*
Output a text/html HTTP response header complete with 401 basic and/or digest
authorization challenge if necessary.
*/

HttpHeader ()

{
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "HttpHeader()\n");

   fprintf (stdout,
"%s %s %s\r\n\
Server: %s\r\n\
Date: %s\r\n\
%s\
%s\
Content-Type: text/html%s\r\n\
\r\n",
      CgiServerProtocolPtr, CgiFormErrorStatusPtr, CgiFormErrorStatusPtr,
      CgiServerSoftwarePtr, CgiRequestTimeGmtPtr,
      BasicChallenge, DigestChallenge,
      ContentTypeCharset);

   HttpHasBeenOutput = true;
}

/*****************************************************************************/
/*
This function will be called when the script is executed with /LOCAL qualifier.
Place any locally implemented error reporter here.  The DefaultReport() could
be used as a template.
*/

LocalReport ()

{
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "LocalReport()\n");

   /* of course remove this when a local reporter is implemented! */
   DefaultReport ();
}

/*****************************************************************************/
/*
Produce an error report that looks a lot like the WASD HTTPd native one!
(This code is based laregly on that in CGILIB.C CgiLibresponseError())
*/

DefaultReport ()

{
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "DefaultReport()\n");

   HttpHeader ();

   if (MethodHead) return;

   fputs (
"<HTML>\n\
<HEAD>\n", stdout);

   if (ReportDetailed)
      fprintf (stdout,
"<META NAME=\"generator\" CONTENT=\"%s (%s)\">\n\
<META NAME=\"module\" CONTENT=\"%s\">\n\
<META NAME=\"line\" CONTENT=\"%s\">\n",
         CgiServerSoftwarePtr, SoftwareID,
         CgiFormErrorModulePtr,
         CgiFormErrorLinePtr);

   fprintf (stdout,
"<TITLE>%s %s %s</TITLE>\n\
</HEAD>\n\
%s\n\
<FONT SIZE=+1><B>%s %s</B> &nbsp;-&nbsp; %s</FONT>\n",
      (StatusCode >= 200 && StatusCode < 299) ? "SUCCESS" : "ERROR",
      CgiFormErrorStatusPtr,
      CgiFormErrorStatusTextPtr,
      HTML_BODY_TAG,
      (StatusCode >= 200 && StatusCode < 299) ? "SUCCESS" : "ERROR",
      CgiFormErrorStatusPtr,
      CgiFormErrorStatusExplPtr);

   if (ReportDetailed)
   {
      fprintf (stdout, "<P>%s", CgiFormErrorTextPtr);

      if (CgiFormErrorAboutPtr[0])
         fprintf (stdout, " ... %s\n", CgiFormErrorAboutPtr);
      else
         fputc ('\n', stdout);

      if (CgiFormErrorVmsPtr[0])
         fprintf (stdout, "<!-- sts: %s \"%s\" -->\n",
                  CgiFormErrorVmsPtr, CgiFormErrorAbout2Ptr);

      if (CgiFormErrorText2Ptr[0])
         fprintf (stdout, "%s\n", CgiFormErrorText2Ptr);
   }

   fprintf (stdout, "<P><HR WIDTH=85%% ALIGN=left SIZE=2 NOSHADE>\n");

   if (CgiServerSignaturePtr[0])
      fprintf (stdout, "%s\n", CgiServerSignaturePtr);

   fputs (
"</BODY>\n\
</HTML>\n",
      stdout);
}

/*****************************************************************************/
/*
Get "command-line" parameters, whether from the command-line or from a
configuration symbol or logical containing the equivalent.
*/

GetParameters ()

{
   static char  CommandLine [256];
   static unsigned long  Flags = 0;

   int  status;
   unsigned short  Length;
   char  ch;
   char  *aptr, *cptr, *clptr, *sptr;
   $DESCRIPTOR (CommandLineDsc, CommandLine);

   /*********/
   /* begin */
   /*********/

   if ((clptr = getenv ("REPORTERROR$PARAM")) == NULL)
   {
      /* get the entire command line following the verb */
      if (VMSnok (status =
          lib$get_foreign (&CommandLineDsc, 0, &Length, &Flags)))
         exit (status);
      (clptr = CommandLine)[Length] = '\0';
   }

   aptr = NULL;
   ch = *clptr;
   for (;;)
   {
      if (aptr != NULL) *aptr = '\0';
      if (!ch) break;

      *clptr = ch;
      if (Debug) fprintf (stdout, "clptr |%s|\n", clptr);
      while (*clptr && isspace(*clptr)) *clptr++ = '\0';
      aptr = clptr;
      if (*clptr == '/') clptr++;
      while (*clptr && !isspace (*clptr) && *clptr != '/')
      {
         if (*clptr != '\"')
         {
            clptr++;
            continue;
         }
         cptr = clptr;
         clptr++;
         while (*clptr)
         {
            if (*clptr == '\"')
               if (*(clptr+1) == '\"')
                  clptr++;
               else
                  break;
            *cptr++ = *clptr++;
         }
         *cptr = '\0';
         if (*clptr) clptr++;
      }
      ch = *clptr;
      if (*clptr) *clptr = '\0';
      if (Debug) fprintf (stdout, "aptr |%s|\n", aptr);
      if (!*aptr) continue;

      if (strsame (aptr, "/CHARSET=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         CliCharsetPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/DBUG", -1))
      {
         Debug = true;
         continue;
      }
      if (strsame (aptr, "/DEFAULT", 4))
      {
         DoDefaultReport = true;
         continue;
      }
      if (strsame (aptr, "/HEADER", 4))
      {
         HeaderOnly = true;
         continue;
      }
      if (strsame (aptr, "/LOCAL", 4))
      {
         DoLocalReport = true;
         continue;
      }
      if (strsame (aptr, "/MORE=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         MoreInfoPtr = cptr;
         continue;
      }

      if (*aptr != '/')
      {
         fprintf (stdout, "%%%s-E-MAXPARM, too many parameters\n \\%s\\\n",
                  Utility, aptr);
         exit (STS$K_ERROR | STS$M_INHIB_MSG);
      }
      else
      {
         fprintf (stdout, "%%%s-E-IVQUAL, unrecognized qualifier\n \\%s\\\n",
                  Utility, aptr+1);
         exit (STS$K_ERROR | STS$M_INHIB_MSG);
      }
   }
}
/****************************************************************************/
/*
Does a case-insensitive, character-by-character string compare and returns 
true if two strings are the same, or false if not.  If a maximum number of 
characters are specified only those will be compared, if the entire strings 
should be compared then specify the number of characters as 0.
*/ 

boolean strsame
(
char *sptr1,
char *sptr2,
int  count
)
{
   while (*sptr1 && *sptr2)
   {
      if (toupper (*sptr1++) != toupper (*sptr2++)) return (false);
      if (count)
         if (!--count) return (true);
   }
   if (*sptr1 || *sptr2)
      return (false);
   else
      return (true);
}

/*****************************************************************************/