home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / makepath.c < prev    next >
Text File  |  1994-09-25  |  3KB  |  118 lines

  1. /*  makepath.c   Routines to create directories to reach passed pathname.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. #include "uucp.h"
  26. #include <modes.h>
  27.  
  28. #define WORDSIZE  20
  29.  
  30. EXTERN QQ unsigned myuid;
  31.  
  32.  
  33. int makepath (path)
  34. char *path;
  35. {
  36.      char filepath[200], *words[WORDSIZE];
  37.      char *p, delim;
  38.      register int i;
  39.      int n;
  40.  
  41.      /* newsgroup path or uucp path? */
  42.      delim = (strchr (path, '/') == NULL)  ?  '.'  :  '/';
  43.  
  44.      /* parse out the components of path */
  45.      strcpy (filepath, path);
  46.  
  47.      for (p = filepath; *p != '\0'; p++)
  48.           if (*p == delim)
  49.                *p = ' ';
  50.  
  51.      n = getargs (words, filepath, WORDSIZE);
  52.  
  53.      /* if uucp path, last component is not directory */
  54.      if (delim == '/')
  55.           n--;
  56.  
  57.      /* Create intermediate directories.  Make directory names uppercase. */
  58.      asetuid (0);
  59.      for (i = 0; i < n; i++)
  60.           if (chdir (*(words + i)) != 0)
  61.             {
  62.                mknod (strupr (*(words + i)), S_IREAD|S_IWRITE|S_IOREAD);
  63.                chdir (*(words + i));
  64.             }
  65.      asetuid (myuid);
  66. }
  67.  
  68.  
  69.  
  70. /* Fix names with - or + in them since OS-9 does not normally support these as
  71.    directory names. */
  72.  
  73. char *fixgroupname (groupname)
  74. char *groupname;
  75. {
  76.      register char *ptr;
  77.      char *gp, *gptr;
  78.      int plus = 0;
  79.  
  80.      ptr = groupname;
  81.  
  82.      while (*ptr)
  83.           if (*ptr++ == '+')
  84.                ++plus;
  85.  
  86.      gp = (char *) malloc ((strlen (groupname)+plus+1) * sizeof (char *));
  87.  
  88.      if (gp == NULL)
  89.        {
  90.           fputs ("fixgroupname(): can't make copy of newsgroup name", stderr);
  91.           return ((char *) NULL);
  92.        }
  93.  
  94.      ptr = groupname;
  95.      gptr = gp;
  96.  
  97.      while (*ptr)
  98.        {
  99.           if (*ptr == '+')                 /* replace + with __ */
  100.             {
  101.                *gptr++ = '_';
  102.                *gptr++ = '_';
  103.             }
  104. #ifndef _OSK
  105. #  ifndef DASHOK
  106.           else if (*ptr == '-')            /* replace - with _ */
  107.                *gptr++ = '_';
  108. #  endif
  109. #endif
  110.           else
  111.                *gptr++ = *ptr;
  112.  
  113.           *gptr = '\0';
  114.           ++ptr;
  115.        }
  116.      return (gp);
  117. }
  118.