- * Copyright (C) 1998-1999,2003 Ian Jackson
+ * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
+ * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
+ * Copyright 1999,2003
+ * Chancellor Masters and Scholars of the University of Cambridge
+ * Copyright 2010 Tony Finch <fanf@dotat.at>
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with userv-utils; if not, write to the Free Software
- * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
+ * along with userv-utils; if not, see http://www.gnu.org/licenses/.
for (;;) {
i= getopt(argc, argv, "+e:"); if (i < 0) break;
switch (i) {
case 'e': filters= optarg; break;
for (;;) {
i= getopt(argc, argv, "+e:"); if (i < 0) break;
switch (i) {
case 'e': filters= optarg; break;
- if (!*argv) error("no script directory argument");
- ev= getenv("HOME"); if (!ev) error("no HOME env. var");
+ if (!*argv) error("no script directory argument", 500);
+ ev= getenv("HOME"); if (!ev) error("no HOME env. var", 500);
l= strlen(*argv)+strlen(ev);
newvar= xmalloc(l+2);
sprintf(newvar,"%s/%s",ev,*argv);
l= strlen(*argv)+strlen(ev);
newvar= xmalloc(l+2);
sprintf(newvar,"%s/%s",ev,*argv);
- if (*lastslash != '/') error("PATH_INFO expected slash not found");
- if (lastslash[1]=='.' || lastslash[1]=='#' || !lastslash[1]) error("bad char begin");
+ if (*lastslash != '/') error("PATH_INFO expected slash not found", 400);
+ if (lastslash[1]=='.' || lastslash[1]=='#' || !lastslash[1])
+ error("bad char begin", 400);
nextslash= strchr(lastslash+1,'/');
if (!nextslash) nextslash= lastslash+1+strlen(lastslash+1);
nextslash= strchr(lastslash+1,'/');
if (!nextslash) nextslash= lastslash+1+strlen(lastslash+1);
- if (!nextslash) error("insufficient elements in PATH_INFO");
- if (nextslash==lastslash+1) error("empty component in PATH_INFO");
- if (nextslash-pathi > MAX_SCRIPTPATH_LEN) error("PATH_INFO script path too long");
+ if (!nextslash) error("insufficient elements in PATH_INFO", 400);
+ if (nextslash==lastslash+1) error("empty component in PATH_INFO", 400);
+ if (nextslash-pathi > MAX_SCRIPTPATH_LEN)
+ error("PATH_INFO script path too long", 400);
scriptpathlen= scriptdirlen+(nextslash-pathi);
scriptpath= xrealloc(scriptpath,scriptpathlen+1);
strcpy(scriptpath,scriptdir);
memcpy(scriptpath+scriptdirlen,pathi,nextslash-pathi);
scriptpath[scriptpathlen]= 0;
scriptpathlen= scriptdirlen+(nextslash-pathi);
scriptpath= xrealloc(scriptpath,scriptpathlen+1);
strcpy(scriptpath,scriptdir);
memcpy(scriptpath+scriptdirlen,pathi,nextslash-pathi);
scriptpath[scriptpathlen]= 0;
D( if (debugmode) printf(";; try `%s'\n", scriptpath); )
r= stat(scriptpath,&stab); if (r) syserror("stat script");
if (S_ISREG(stab.st_mode)) break;
D( if (debugmode) printf(";; try `%s'\n", scriptpath); )
r= stat(scriptpath,&stab); if (r) syserror("stat script");
if (S_ISREG(stab.st_mode)) break;
newvar= xmalloc(strlen(ev)+2+strlen(ev2)+scriptpathlen-scriptdirlen+2);
sprintf(newvar,"%s/~%s%s",ev,ev2,scriptpath+scriptdirlen);
xsetenv("SCRIPT_NAME",newvar,1);
newvar= xmalloc(strlen(ev)+2+strlen(ev2)+scriptpathlen-scriptdirlen+2);
sprintf(newvar,"%s/~%s%s",ev,ev2,scriptpath+scriptdirlen);
xsetenv("SCRIPT_NAME",newvar,1);