home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / kpathsea / concatn.c < prev    next >
C/C++ Source or Header  |  2000-01-15  |  2KB  |  71 lines

  1. /* concatn.c: Concatenate an arbitrary number of strings.
  2.  
  3. Copyright (C) 1993, 95 Karl Berry.
  4.  
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  18.  
  19. #include <kpathsea/config.h>
  20.  
  21. #include <kpathsea/concatn.h>
  22.  
  23.  
  24. /* OK, it would be epsilon more efficient to compute the total length
  25.    and then do the copying ourselves, but I doubt it matters in reality.  */
  26.  
  27. string
  28. concatn PVAR1C(const_string, str1,  ap)
  29. {
  30.   string arg;
  31.   string ret;
  32.  
  33.   if (!str1)
  34.     return NULL;
  35.   
  36.   ret = xstrdup (str1);
  37.   
  38.   while ((arg = va_arg (ap, string)) != NULL)
  39.     {
  40.       string temp = concat (ret, arg);
  41.       free (ret);
  42.       ret = temp;
  43.     }
  44.   va_end (ap);
  45.   
  46.   return ret;
  47. }}
  48.  
  49. #ifdef TEST
  50. int
  51. main ()
  52. {
  53.   printf ("null = \"%s\"\n", concatn (NULL));
  54.   printf ("\"a\" = \"%s\"\n", concatn ("a", NULL));
  55.   printf ("\"ab\" = \"%s\"\n", concatn ("a", "b", NULL));
  56.   printf ("\"abc\" = \"%s\"\n", concatn ("a", "b", "c", NULL));
  57.   printf ("\"abcd\" = \"%s\"\n", concatn ("ab", "cd", NULL));
  58.   printf ("\"abcde\" = \"%s\"\n", concatn ("ab", "c", "de", NULL));
  59.   printf ("\"abcdef\" = \"%s\"\n", concatn ("", "a", "", "bcd", "ef", NULL));
  60.   return 0;
  61. }
  62.  
  63. #endif /* TEST */
  64.  
  65.  
  66. /*
  67. Local variables:
  68. standalone-compile-command: "gcc -posix -g -I. -I.. -DTEST concatn.c kpathsea.a"
  69. End:
  70. */
  71.