示例#1
0
文件: export.c 项目: swhobbit/UUPC
void exportpath(char *canon, const char *host, const char *remote)
{
   const char *xhost;
   char *copy;
   char tempname[FILENAME_MAX];
   unsigned subscript;
   unsigned char number[MAX_DIGITS];
   char *token, *out;

   static size_t range =  UNIX_END_C - UNIX_START_C + 1;
                              /* Determine unique number characters in
                                 the UNIX file names we are mapping   */
   size_t charsetsize;
            /* Number of allowed characters in
                              MS-DOS file names                   */

#ifdef UDEBUG
   printmsg(5,"Exporting %s for %s", host, remote );
#endif

/*--------------------------------------------------------------------*/
/*                      Define our character set                      */
/*--------------------------------------------------------------------*/

   if ( E_charset == NULL )
      E_charset = DOSCHARS;

   charsetsize = strlen( E_charset );

/*--------------------------------------------------------------------*/
/*                Drop leading spool directory, if any                */
/*--------------------------------------------------------------------*/

   if (equalni(host, E_spooldir, strlen( E_spooldir )))
      xhost = host + strlen( E_spooldir ) + 1;
   else
      xhost = host;

   copy = strdup( xhost );
   checkref( copy );

/*--------------------------------------------------------------------*/
/*                        Drop the remote name                        */
/*--------------------------------------------------------------------*/

   token = strtok( copy, "/");

   if ((token == NULL) || !equaln( token, remote, strlen( token )))
   {
      printmsg(0,"exportpath: Badly formed host name \"%s\"",xhost);
      panic();
   }

/*--------------------------------------------------------------------*/
/*                 Get the character leading the name                 */
/*--------------------------------------------------------------------*/

   token = strtok( NULL, "/");
   if ( (token == NULL) || (strlen(token) != 1))
   {
      printmsg(0,"exportpath: Badly formed host name \"%s\"",xhost);
      panic();
   }

   strcpy(canon, token);
   strcat(canon, ".");

/*--------------------------------------------------------------------*/
/*       Create a binary number which represents our file name        */
/*--------------------------------------------------------------------*/

   for (subscript = 0; subscript < MAX_DIGITS; subscript++ )
      number[subscript] = 0;  /* Initialize number to zero        */

   token = strtok( NULL, "/");   /* Get variable part of name         */
   while( (*token != '\0') && (*number == '\0'))
   {
      unsigned char digit;
      mult(number, charsetsize, MAX_DIGITS); /* Shift the number over */
      digit = (unsigned char) (strchr( E_charset , *token++) - E_charset);
      add(number, digit , MAX_DIGITS); /* Add in new low order        */
      if (*token == '.')               /* Next character a period?    */
         token ++;                     /* Yes --> Ignore it           */
   } /* while */

   out = &tempname[FILENAME_MAX];
   *--out = '\0';          /* Terminate the string we will build  */

/*--------------------------------------------------------------------*/
/*         Here's the loop to actually do the base conversion         */
/*--------------------------------------------------------------------*/

      while(adiv( number, range, &subscript, MAX_DIGITS))
       *--out = (char) (subscript + UNIX_START_C);

/*--------------------------------------------------------------------*/
/*    We sort of lied above; the first character out of the           */
/*    conversion is not a character at all, but bits which say how    */
/*    many characters the remote and local file names get prefixed    */
/*    to the converted name.  Retrieve that information now           */
/*--------------------------------------------------------------------*/

      subscript = (unsigned) (*out - UNIX_START_C);
                              /* Convert back to pure number          */
      token = canon + strlen( canon ); /* Remember end of string      */
      if (subscript > HOSTLEN)
      {
         subscript /= HOSTLEN;
         strcat( canon, remote );
      }
      else
         strcat( canon, E_nodename );
      token[ subscript ] = '\0';    /* Only use the length we were told */

/*--------------------------------------------------------------------*/
/*               Add in the variable name and we're done              */
/*--------------------------------------------------------------------*/

      strcat( canon, ++out );
      free( copy );

/*--------------------------------------------------------------------*/
/*                          Check the result                          */
/*--------------------------------------------------------------------*/

      importpath( tempname, canon, remote );
      if ( !equal( tempname, xhost ))
      {
         printmsg(0,
            "exportpath: **mapping error** input \"%s\","
            " result \"%s\", import \"%s\"",
            xhost, canon, tempname );
         panic();
      } /* if */

} /* exportpath */
示例#2
0
文件: ulibos2.c 项目: swhobbit/UUPC
int nopenline(char *name, BPS portSpeed, const KWBoolean direct )
{

   APIRET rc;
   USHORT com_error;

#ifdef __OS2__
   ULONG ParmLengthInOut;
   ULONG DataLengthInOut;

   ULONG action;

#else

   USHORT action;

#endif

   if (portActive)               /* Was the port already active?    */
      closeline();               /* Yes --> Shutdown it before open */

#ifdef UDEBUG
   printmsg(15, "nopenline: %s, %lu", name, portSpeed);
#endif

/*--------------------------------------------------------------------*/
/*                      Validate the port format                      */
/*--------------------------------------------------------------------*/

   if (!equaln(name, "COM", 3 ))
   {
      printmsg(0,"nopenline: Communications port begin with COM, was %s",
         name);
      panic();
   }

   if ( commHandle == -1 )
   {

/*--------------------------------------------------------------------*/
/*                          Perform the open                          */
/*--------------------------------------------------------------------*/

      rc = DosOpen( name,
                    &commHandle,
                    &action,
                    0L,
                    0 ,
                    FILE_OPEN ,
                    OPEN_FLAGS_FAIL_ON_ERROR |
                    OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,
                    0L );

/*--------------------------------------------------------------------*/
/*                       Check the open worked.                       */
/*--------------------------------------------------------------------*/

      if ( rc )
      {
         printOS2error( name, rc );
         commHandle = -1;
         return KWTrue;
      }

   } /* if ( commHandle == -1 ) */

/*--------------------------------------------------------------------*/
/*            Reset any errors on the communications port             */
/*--------------------------------------------------------------------*/

#ifdef __OS2__

   ParmLengthInOut = 0;
   DataLengthInOut = sizeof(com_error);
   rc = DosDevIOCtl( commHandle, IOCTL_ASYNC, ASYNC_GETCOMMERROR,
      NULL,0L,&ParmLengthInOut,(PVOID) &com_error,sizeof(com_error),
      &DataLengthInOut);

#else

   rc = DosDevIOCtl( &com_error, FAR_NULL, ASYNC_GETCOMMERROR ,
                     IOCTL_ASYNC, commHandle);

#endif

   if (rc)
   {
      ShowError( com_error );
      printOS2error( "ASYNC_GETCOMMERROR", rc );
   } /*if */
   else if ( com_error )
      ShowError( com_error );

/*--------------------------------------------------------------------*/
/*                           Set port speed                           */
/*--------------------------------------------------------------------*/

   saveSpeed = GetSpeed();    /* Save original speed                 */

   if ( portSpeed )           /* Don't set it we're a hot open       */
      SIOSpeed(portSpeed);

/*--------------------------------------------------------------------*/
/*                        Set line attributes                         */
/*--------------------------------------------------------------------*/

#ifdef UDEBUG
   printmsg(15,"nopenline: Getting attributes");
#endif

#ifdef __OS2__

   ParmLengthInOut = 0;
   DataLengthInOut = sizeof(com_attrib);
   rc = DosDevIOCtl( commHandle,
                     IOCTL_ASYNC,
                     ASYNC_GETLINECTRL,
                     NULL,
                     0L,
                     &ParmLengthInOut,
                     (PVOID) &com_attrib,
                     sizeof(com_attrib),
                     &DataLengthInOut); /* Get old attributes from device  */

#else

   rc = DosDevIOCtl( &com_attrib,
                     FAR_NULL,
                     ASYNC_GETLINECTRL,
                     IOCTL_ASYNC,
                     commHandle);   /* Get old attributes from device  */
#endif

   if (rc)
   {
      printOS2error( "ASYNC_GETLINECTRL", rc );
      panic();
   } /*if */

   memcpy( &save_com_attrib, &com_attrib, sizeof com_attrib );
                              /* Save the attributes                */

   com_attrib.bDataBits = 0x08; /* Use eight bit path for data      */
   com_attrib.bParity   = 0x00; /* No parity                        */
   com_attrib.bStopBits = 0x00; /* 1 Stop Bit                       */

#ifdef UDEBUG
   printmsg(15,"nopenline: Setting attributes");
#endif

#ifdef __OS2__

   ParmLengthInOut = sizeof(com_attrib);
   DataLengthInOut = 0;
   rc = DosDevIOCtl( commHandle,
                     IOCTL_ASYNC,
                     ASYNC_SETLINECTRL,
                     (PVOID) &com_attrib,
                     sizeof(com_attrib),
                     &ParmLengthInOut,
                     NULL,
                     0L,
                     &DataLengthInOut);

#else

   rc = DosDevIOCtl( FAR_NULL,
                     &com_attrib,
                     ASYNC_SETLINECTRL,
                     IOCTL_ASYNC,
                     commHandle);
#endif

   if (rc)
   {
      printOS2error( "ASYNC_SETLINECTRL", rc );
      panic();
   } /*if */

/*--------------------------------------------------------------------*/
/*       Disable software (XON/XOFF) flow control and enable          */
/*       hardware (CTS) for flow control                              */
/*--------------------------------------------------------------------*/

#ifdef UDEBUG
   printmsg(15,"nopenline: Getting flow control information");
#endif

#ifdef __OS2__

   ParmLengthInOut = 0;
   DataLengthInOut = sizeof(com_dcbinfo);
   rc = DosDevIOCtl( commHandle,
                     IOCTL_ASYNC,
                     ASYNC_GETDCBINFO,
                     NULL,
                     0L,
                     &ParmLengthInOut,
                     (PVOID) &com_dcbinfo,
                     sizeof(com_dcbinfo),
                     &DataLengthInOut);   /* Get old attributes from device  */

#else

   rc = DosDevIOCtl( &com_dcbinfo,
                     FAR_NULL,
                     ASYNC_GETDCBINFO,
                     IOCTL_ASYNC,
                     commHandle);    /* Get old attributes from device  */

#endif

   if (rc)
   {
      printOS2error( "ASYNC_GETDCBINFO", rc );
      panic();
   } /*if */

   memcpy( &save_com_dcbinfo, &com_dcbinfo, sizeof com_dcbinfo );
                              /* Save the DCB information            */

   com_dcbinfo.usWriteTimeout = 2999;  /* Write timeout 30 seconds   */
   com_dcbinfo.usReadTimeout = 24;     /* Read timeout .25 seconds   */
   com_dcbinfo.fbCtlHndShake = (BYTE) (MODE_DTR_CONTROL |
                                      (direct ? 0 : MODE_CTS_HANDSHAKE));
                                       /* Always drop DTR at port close,
                                          only use CTS handshaking on
                                          requested ports.            */

   com_dcbinfo.fbFlowReplace = MODE_RTS_HANDSHAKE;
                                       /* Handshake on output         */

   com_dcbinfo.fbTimeout = MODE_READ_TIMEOUT | MODE_NO_WRITE_TIMEOUT;

#ifdef UDEBUG
   printmsg(15,"nopenline: Setting dcb information");
#endif

#ifdef __OS2__

   ParmLengthInOut = sizeof(com_dcbinfo);
   DataLengthInOut = 0;
   rc = DosDevIOCtl( commHandle,
                     IOCTL_ASYNC,
                     ASYNC_SETDCBINFO,
                     (PVOID) &com_dcbinfo,
                     sizeof(com_dcbinfo),
                     &ParmLengthInOut,
                     NULL,
                     0L,
                     &DataLengthInOut);

#else

   rc = DosDevIOCtl( FAR_NULL,
                     &com_dcbinfo,
                     ASYNC_SETDCBINFO,
                     IOCTL_ASYNC,
                     commHandle);

#endif

   if ( rc )
   {
      printOS2error( "ASYNC_SETDCBINFO", rc );
      panic();
   } /*if */

/*--------------------------------------------------------------------*/
/*                     Raise Data Terminal Ready                      */
/*--------------------------------------------------------------------*/

   com_signals.fbModemOn = DTR_ON;
   com_signals.fbModemOff = 0xff;

#ifdef UDEBUG
   printmsg(15,"nopenline: Raising RTS/DTR");
#endif

#ifdef __OS2__

   ParmLengthInOut = sizeof(com_signals);
   DataLengthInOut = sizeof(com_error);

   rc = DosDevIOCtl( commHandle,
                     IOCTL_ASYNC,
                     ASYNC_SETMODEMCTRL,
                     (PVOID)&com_signals,
                     sizeof(com_signals),
                     &ParmLengthInOut,
                     (PVOID) &com_error,
                     sizeof(com_error),
                     &DataLengthInOut);

#else

   rc = DosDevIOCtl( &com_error,
                     &com_signals,
                     ASYNC_SETMODEMCTRL,
                     IOCTL_ASYNC,
                     commHandle);

#endif

   if (rc)
   {
      printOS2error( "ASYNC_SETMODEMCTRL", rc );
      ShowError( com_error );
      panic();
   } /*if */

   traceStart( name );     /* Enable logging                         */

   portActive = KWTrue;     /* record status for error handler        */
   carrierDetect = KWFalse;  /* Modem is not connected                */

/*--------------------------------------------------------------------*/
/*                     Wait for port to stablize                      */
/*--------------------------------------------------------------------*/

   ddelay(500);            /* Allow port to stablize          */
   return 0;

} /* nopenline */
示例#3
0
文件: import.c 项目: swhobbit/UUPC
void importpath(char *local, const char *canon, const char *remote)
{
   char *s, *out;
   size_t charsetsize;     /* Number of allowed characters in
                              MS-DOS file names                   */

   out = local;

/*--------------------------------------------------------------------*/
/*                       Verify our parameters                        */
/*--------------------------------------------------------------------*/

   if (local == NULL)
      panic();

   if (canon == NULL)
      panic();

/*--------------------------------------------------------------------*/
/*                      Define our character set                      */
/*--------------------------------------------------------------------*/

    if (E_charset == NULL)
       E_charset = DOSCHARS;

    charsetsize = strlen(E_charset);

/*--------------------------------------------------------------------*/
/*                 Determine if spool file directory                  */
/*--------------------------------------------------------------------*/

   if ((s = strrchr(canon, '/')) == NULL)
   {                          /* File for spooling directory, use
                                 internal character set to avoid
                                 collisions                           */
      static size_t range =  UNIX_END_C - UNIX_START_C + 1;
                              /* Determine unique number characters in
                                 the UNIX file names we are mapping   */

      size_t remlen = min(HOSTLEN, strlen(remote));
                              /* Length of the remote name passed
                                 in, shortened below to number of
                                 characters matched in name           */
      size_t nodelen = min(HOSTLEN, strlen(E_nodename));
                              /* Length of the local host name,
                                 shortened below to number of
                                 characters matched in name           */
      size_t subscript = 0;   /* Value of UNIX character to be
                                 converted to MS-DOS character set    */
      char *next        = local + remlen;
      char tempname[FILENAME_MAX];
      unsigned char number[MAX_DIGITS];
                              /* Arbitary length number, for base
                                 conversions                        */

      KWBoolean longname;

      if (bflag[F_LONGNAME] && advancedFS(E_spooldir))
         longname = KWTrue;
      else
         longname = KWFalse;

/*--------------------------------------------------------------------*/
/*                    Verify we have a remote name                    */
/*--------------------------------------------------------------------*/

      if (remote == NULL)
         panic();

/*--------------------------------------------------------------------*/
/*    Put the host name (up to six characters) at the beginning of    */
/*    the MS-DOS file name as a sub-directory name.                   */
/*--------------------------------------------------------------------*/

      strncpy(local, remote, remlen);
      *next++ = '/';          /* Add in the sub-directory seperator   */
      s = (char *) canon;     /* Get the beginnging of the UNIX name  */

/*--------------------------------------------------------------------*/
/*    Files in the spooling directory generally start with "D.",      */
/*    "C.", or "X."; strip off any upper case letter followed by a    */
/*    period into its own directory.                                  */
/*--------------------------------------------------------------------*/

      if ((s[0] >= 'A') && (s[0] <= 'Z') && (s[1] == '.'))
      {
         *next++ = *s;        /* Copy the input character             */
         *next++ = '/';       /* Add the sub-directory indicator too  */
         s += 2;              /* Step input string past the copied
                                 data                                 */
      }

      while (remlen > 0)
      {
         if (equaln(remote,s,remlen))
            break;
         remlen--;
      }

      while (nodelen > 0)
      {
         if (equaln(E_nodename,s,nodelen))
            break;
         nodelen--;
      }

      if (nodelen > remlen)
      {
         remlen = 0;
         s += nodelen;
      }
      else {
         nodelen = 0;
         s += remlen;
      }

      *next  = '\0';          /* Terminate first part of host string  */

/*--------------------------------------------------------------------*/
/*       Create a binary number which represents our file name        */
/*--------------------------------------------------------------------*/

      for (subscript = 0; subscript < MAX_DIGITS; subscript++)
         number[subscript] = 0;  /* Initialize number to zero         */

      add(number, nodelen + remlen * HOSTLEN, MAX_DIGITS);
                                 /* Append host name info to the
                                    front of the converted string     */

      while ((*s != '\0') && (*number == '\0'))
      {
         if (isspace(*s))
         {
            printmsg(0,"importPath: Invalid file \"%s\" for %s, "
                       "name contains whitespace",
                       canon,
                       remote);
            panic();
         }

         mult(number, range, MAX_DIGITS); /* Shift the number over    */
         add(number, (unsigned) (*s++  - UNIX_START_C), MAX_DIGITS);
                                          /* Add in new low order     */
      } /* while */

/*--------------------------------------------------------------------*/
/*   We now have stripped off the leading x. and host name, if any;   */
/*   now, convert the remaining characters in the name by doing a     */
/*   range to charset base conversion.                                */
/*--------------------------------------------------------------------*/

      out = tempname + FILENAME_MAX;
      *--out = '\0';          /* Terminate the string we will build   */

/*--------------------------------------------------------------------*/
/*         Here's the loop to actually do the base conversion         */
/*--------------------------------------------------------------------*/

      while (adiv(number, charsetsize, &subscript, MAX_DIGITS))
            *--out = E_charset[ subscript ];

/*--------------------------------------------------------------------*/
/*    The conversion is done; now squeeze it into an 11 character     */
/*    MS-DOS name with period.                                        */
/*--------------------------------------------------------------------*/

      ImportName(next, out, charsetsize, longname);

   }
   else {         /* Not file for spooling directory, convert it  */

      char *in = (char *) canon;
      KWBoolean longname ;

      longname = advancedFS(canon);

      if (ValidDOSName(canon, longname))
      {
         strcpy(local, canon);
         return;
      }

/*--------------------------------------------------------------------*/
/*      Handle leading drive letter (ignore it, assuming valid)       */
/*--------------------------------------------------------------------*/

      if (isalpha(*in) && (in[1] == ':'))
      {
         *out++ = *in++;      /* The drive letter                     */
         *out++ = *in++;      /* The colon making it a driver letter  */
      } /* if */

      if (*in == '/')         /* Absolute path name?                  */
         *out++ = *in++;      /* Yes, step past it                    */

      while (*in == '/')       /* Additional slashes?                  */
         in++;                /* Skip them,  they mean nothing        */

      s = strchr(in, '/');    /* Get end of next path segment         */

/*--------------------------------------------------------------------*/
/*              Now convert each simple name in the path              */
/*--------------------------------------------------------------------*/

      while (*in)
      {
         if (s != NULL)
            *s = '\0';        /* Truncate input string to simple name */

         ImportName(out, in, charsetsize, longname);

         if (s == NULL)
            break;
         out = out + strlen(out);
         *out++ = *s++ = '/'; /* Restore path to input and output     */
         in = s;              /* Remember start of this simple name   */
         while (*in == '/')    /* Additional slashes?                  */
            in++;             /* Skip them,  they mean nothing        */
         s = strchr(in, '/');
      }

   } /* else */

   printmsg(equali(canon,local) ? 8 : 4,
            "ImportPath: Mapped %s to %s", canon, local);

} /*importpath*/
示例#4
0
static int
yysimfac(int h)
{
	int i, j;

	for (i = h; i < tos; i++) {
		p1 = stack[i];
		for (j = h; j < tos; j++) {
			if (i == j)
				continue;
			p2 = stack[j];

			//	n! / n		->	(n - 1)!

			if (car(p1) == symbol(FACTORIAL)
			&& car(p2) == symbol(POWER)
			&& isminusone(caddr(p2))
			&& equal(cadr(p1), cadr(p2))) {
				push(cadr(p1));
				push(one);
				subtract();
				factorial();
				stack[i] = pop();
				stack[j] = one;
				return 1;
			}

			//	n / n!		->	1 / (n - 1)!
			{
				int a,b,c,d;
				a = car(p2) == symbol(POWER);
				b = isminusone(caddr(p2));
				c = caadr(p2) == symbol(FACTORIAL);
				d = equal(p1, cadadr(p2));
				if ( a
				&& b
				&& c
				&& d){
					push(p1);
					push_integer(-1);
					add();
					factorial();
					reciprocate();
					stack[i] = pop();
					stack[j] = one;
					return 1;
				}
			}
			//	(n + 1) n!	->	(n + 1)!

			if (car(p2) == symbol(FACTORIAL)) {
				push(p1);
				push(cadr(p2));
				subtract();
				p3 = pop();
				if (isplusone(p3)) {
					push(p1);
					factorial();
					stack[i] = pop();
					stack[j] = one;
					return 1;
				}
			}

			//	1 / ((n + 1) n!)	->	1 / (n + 1)!

			if (car(p1) == symbol(POWER)
			&& isminusone(caddr(p1))
			&& car(p2) == symbol(POWER)
			&& isminusone(caddr(p2))
			&& caadr(p2) == symbol(FACTORIAL)) {
				push(cadr(p1)); // modified

				push(car(cdr(cadr(p2))));
				subtract();
				p3 = pop();
				if (isplusone(p3)) {
					push(cadr(p1));
					factorial();
					reciprocate();
					stack[i] = pop();
					stack[j] = one;
					return 1;
				}
			}

			//	(n + 1)! / n!	->	n + 1

			//	n! / (n + 1)!	->	1 / (n + 1)

			if (car(p1) == symbol(FACTORIAL)
			&& car(p2) == symbol(POWER)
			&& isminusone(caddr(p2))
			&& caadr(p2) == symbol(FACTORIAL)) {
				push(cadr(p1));
				push(car(cdr(cadr(p2))));
				subtract();
				p3 = pop();
				if (isplusone(p3)) {
					stack[i] = cadr(p1);
					stack[j] = one;
					return 1;
				}
				if (isminusone(p3)) {
					push(car(cdr(cadr(p2))));
					reciprocate();
					stack[i] = pop();
					stack[j] = one;
					return 1;
				}
				if (equaln(p3, 2)) {
					stack[i] = cadr(p1);
					push(cadr(p1));
					push_integer(-1);
					add();
					stack[j] = pop();
					return 1;
				}
				if (equaln(p3, -2)) {
					push(car(cdr(cadr(p2))));
					reciprocate();
					stack[i] = pop();
					push(car(cdr(cadr(p2))));
					push_integer(-1);
					add();
					reciprocate();
					stack[j] = pop();
					return 1;
				}
			}
		}
	}

	return 0;
}
示例#5
0
void
run(char *s)
{
	int i, n;

	/*if (strncmp(s, "selftest", 8) == 0) {
		selftest();
		return;
	}*/

	if (setjmp(stop_return))
		return;

	init();

	while (1) {

		n = scan(s);

		p1 = pop();
		check_stack();

		if (n == 0)
			break;

		// if debug mode then print the source text

		if (equaln(get_binding(symbol(TRACE)), 1)) {
			for (i = 0; i < n; i++)
				if (s[i] != '\r')
					printchar(s[i]);
			if (s[n - 1] != '\n') // n is not zero, see above
				printchar('\n');
		}

		s += n;

		push(p1);
		top_level_eval();

		p2 = pop();
		check_stack();

		if (p2 == symbol(NIL))
			continue;

		// print string w/o quotes

		if (isstr(p2)) {
			printstr(p2->u.str);
			printstr("\n");
			continue;
		}

		if (equaln(get_binding(symbol(TTY)), 1) || test_flag) // tty mode?
			printline(p2);
		else {
//#ifdef LINUX
			display(p2);
/*#else
			push(p2);
			cmdisplay();
#endif*/
		}
	}
}
示例#6
0
int main(int ac, char *av[])
{
    int ret = 0;

    //strcpy(applnamebuf,av[0]);
    if(strrchr(av[0],SLASHC))
        strcpy(applnamebuf, strrchr(av[0],SLASHC)+1);
    else
        strcpy(applnamebuf, av[0]);
#ifdef _WIN32
    {
        char *q;
        
        if((q=strrchr(applnamebuf, '.')))
            if(!equal(q+1,"exe"))
                strcat(applnamebuf,".exe");
    }
#endif
    applname = applnamebuf;

    if(ac == 1) {
        USAGE();
        return 0;
    }
    while(ac > 1) {
        if(equal(av[1],"-debug") || equal(av[1],"-d")) {
            ac--;
            av++;
            showme++;
        }
        else if(equal(av[1],"-csv")) {
            ac--;
            av++;
            csv = 1;
        }
        else if(equaln(av[1], "-t",2)) {
            if(av[1][2] == 0) {
                ac--;
                av++;
                nthreads = atoik(av[1]);
            }
            else {
                nthreads = atoik(&av[1][2]);
            }
            //if(nthreads > 1000) nthreads = 1000;
            if(nthreads < 2) nthreads = 2;
            ac--;
            av++;
        }
        else if(equaln(av[1], "-c",2)) {
            if(av[1][2] == 0) {
                ac--;
                av++;
                ncrits = atoik(av[1]);
            }
            else {
                ncrits = atoik(&av[1][2]);
            }
            ac--;
            av++;
        }
        else if(isdigit(av[1][0])) {
            maxcount = atoik(av[1]);
            ac--;
            av++;
            if(maxcount == 0)
                maxcount = 1;
        }
    }
    //
    // There has to be at least 1 more critical section than threads.
    //
    if(ncrits <= nthreads)
        ncrits = nthreads + 1;

    ret = do_threads();
    return ret;
}