home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / nn.tar / nn-6.5.1 / awksplit.c < prev    next >
C/C++ Source or Header  |  1995-04-29  |  3KB  |  83 lines

  1. /*******************WARNING*********************
  2.  
  3. This is a *MODIFIED* version of Geoff Coller's proof-of-concept NOV
  4. implementation.
  5.  
  6. It has been modified to support threading directly from a file handle
  7. to a NNTP server without a temporary file.
  8.  
  9. This is not a complete distribution.  We have only distributed enough
  10. to support NN's needs.
  11.  
  12. The original version came from world.std.com:/src/news/nov.dist.tar.Z
  13. and was dated 11 Aug 1993.
  14.  
  15. In any case, bugs you find here are probably my fault, as I've trimmed
  16. a fair bit of unused code.
  17.  
  18. -Peter Wemm  <peter@DIALix.oz.au>
  19. */
  20.  
  21. /*
  22.  * Copyright (c) Geoffrey Collyer 1992, 1993.
  23.  * All rights reserved.
  24.  * Written by Geoffrey Collyer.
  25.  * Thanks to UUNET Communications Services Inc for financial support.
  26.  *
  27.  * This software is not subject to any license of the American Telephone
  28.  * and Telegraph Company, the Regents of the University of California, or
  29.  * the Free Software Foundation.
  30.  *
  31.  * Permission is granted to anyone to use this software for any purpose on
  32.  * any computer system, and to alter it and redistribute it freely, subject
  33.  * to the following restrictions:
  34.  *
  35.  * 1. The authors are not responsible for the consequences of use of this
  36.  *    software, no matter how awful, even if they arise from flaws in it.
  37.  *
  38.  * 2. The origin of this software must not be misrepresented, either by
  39.  *    explicit claim or by omission.  Since few users ever read sources,
  40.  *    credits must appear in the documentation.
  41.  *
  42.  * 3. Altered versions must be plainly marked as such, and must not be
  43.  *    misrepresented as being the original software.  Since few users
  44.  *    ever read sources, credits must appear in the documentation.
  45.  *
  46.  * 4. This notice may not be removed or altered.
  47.  */
  48.  
  49.  
  50. /*
  51.  * awksplit - awk-like split(3) that handles memory allocation automatically
  52.  */
  53.  
  54. #include "config.h"
  55.  
  56. int                /* number of fields, including overflow */
  57. awksplit(string, fieldsp, nfields, sep)
  58. char *string;
  59. register char ***fieldsp;    /* list is not NULL-terminated */
  60. register int nfields;        /* number of entries available in fields[] */
  61. char *sep;            /* "" white, "c" single char, "ab" [ab]+ */
  62. {
  63.     register int nf;
  64.  
  65.     nf = split(string, *fieldsp, nfields, sep);
  66.     if (nf > nfields) {    /* too many fields to fieldsp? */
  67.         register char **array =
  68.             (char **)malloc((unsigned)(nf * sizeof(char *)));
  69.         register int i;
  70.  
  71.         if (array == NULL)
  72.             *fieldsp = NULL;    /* you lose */
  73.         else {
  74.             for (i = 0; i < nfields; i++)
  75.                 array[i] = (*fieldsp)[i];
  76.             *fieldsp = array;
  77.             (void) split(array[nfields-1], &array[nfields],
  78.                 nf - nfields, sep);
  79.         }
  80.     }
  81.     return nf;
  82. }
  83.