#include <stdio.h>
#include <string.h>
#define MAX_BUF 1025

char obj[1025],par[1025],file[1025];
char *getenv();
char *parptr[250];
char *env[20];
char option[250];

int dctsearch();

main(argc,argv)
int argc;
char *argv[];
{
char *sp;
int j,np;

sp=getenv("PATH_INFO");
if(sp==NULL){
  printf("Content-type: text/html\n\n");
  printf("&x <b>No object specified</b>\n");
  exit(1);
};
strcpy(obj,sp);
sp=strchr(obj,'.');
if(sp) *sp = 0;
sp=getenv("QUERY_STRING");
if(sp) strcpy(par,sp) ; else *par = 0;

strcpy(option,"OPTIONSERVER=");
strcat(option,OPTIONHOST);
putenv(option);

j=dctsearch(obj,file,par,0);

if(!j){
  printf("Content-type: text/html\n\n");
  printf("&x <b>Error:</b> %s %s.\n",file,obj);
  exit(1);
};

j=0;
parptr[j]=file;
parptr[++j]=par;
np=0;
sp=par;
while(*sp){
  switch(*sp){
  case '(':np++;break;
  case ')':np--;break;
  case ',':if(np)break;
    *sp=0;
    parptr[++j]=sp+1;
    break;
  };
  sp++;
};
parptr[++j]=NULL;

execv(file,parptr);
printf("Content-type: text/html\n\n");
printf("&x <b>Method not found:</b> %s\n",file);
exit(1);
}
