/* ***** BEGIN LICENSE BLOCK *****
* Version: CDDL 1.0
*
* The contents of this file are subject to the COMMON DEVELOPMENT AND
* DISTRIBUTION LICENSE (CDDL) Version 1.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.sun.com/cddl/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is
* "netlabs.org Open Source Archive Administrator/Client"
*
* The Original Distribution Package is named
* "netlabs.org Open Source Archive Administrator/Client"
* and maintained and distributed by the Initial Developer
* and/or netlabs.org only.
*
* In addition to the CDDL the following applies:
* If you modify the Original Code, you may distribute it only
* as a part of a distribution package where
*  - the name of the package, created directories or
*    OS2.INI entries do not contain any of the terms
*    - "netlabs.org Open Source Archive"
*    - "NOSA"
*    - "NOSAC"
*    - "NOSAADM"
*  - neither netlabs.org nor the Initial Developer is stated as
*    the vendor or originator of the resulting Distribution Package,
*    which contains the Modified Code.
*
* The Initial Developer of the Original Code is
* netlabs.org: Christian Langanke <cla@clanganke.de>.
* Portions created by the Initial Developer are Copyright (C) 1999-2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>

#define INCL_DOS
#define INCL_ERRORS
#include <os2.h>

#include "cvsstr.h"

// --------------------------------------------------------

PSZ dosslash( PSZ pszPathname)
{
         PSZ            p;

if (pszPathname)
   {
   p = pszPathname;
   while (*p)
      {
      if (*p == '/')
         *p = '\\';
      p++;
      }
   }

return pszPathname;
}

// --------------------------------------------------------

PSZ stripblanks (PSZ pszStr)
{
         PSZ            p;

if (pszStr)
   {

   // skip of leading whitepace
   p = pszStr;
   while (*p <= 0x20)
      {
      p++;
      }
   if (p != pszStr)
      strcpy( pszStr, p);

   // skip of trailing whitespace
   p = pszStr + strlen( pszStr) - 1;
   while (*p <= 0x20)
      {
      *p = 0;
      p--;
      }

   }

return pszStr;
}

// --------------------------------------------------------

// pszUserDefs requires two zero bytes at end !

PSZ makestrlist( PSZ pszStr, CHAR chDelimiter)
{
         PSZ            pszResult = pszStr;
         PSZ            p, c;
         PSZ            pszThis;
         PSZ            pszNext;

do
   {
   // check parms
   if (!pszStr)
      break;

   if (*(pszStr + strlen( pszStr) + 1) != 0)
      break;

   // scan off whitespace
   stripblanks( pszStr);

   pszThis = pszStr;
   c = strchr( pszThis, chDelimiter);
   while (pszThis)
      {
      // tokenize
      if (c)
         {
         pszNext = c + 1;
         *c = 0;
         }

      // strip blanks off the user
      stripblanks( pszThis);

      // move next def right behind current one
      // only required, if blanks have been stripped off
      if ((c) && (pszNext != pszThis + strlen( pszThis) + 1))
         {
         strcpy( pszThis + strlen( pszThis) + 1, pszNext);
         pszNext = pszThis + strlen( pszThis) + 1;
         }

      // next please
      if (c)
         {
         pszThis = pszNext;
         c = strchr( pszThis, chDelimiter);
         }
      else
         break;
      }

   // write second zero byte at end of last string
   *(pszThis + strlen( pszThis) + 1) = 0;

   } while (FALSE);

return pszResult;

}

