home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / kpathsea / concatn.c < prev    next >
C/C++ Source or Header  |  1993-07-18  |  2KB  |  69 lines

  1. /* concatn.c: Concatenate an arbitrary number of strings.
  2.  
  3. Copyright (C) 1993 Karl Berry.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program 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
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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.       ret = concat (ret, arg);
  41.     }
  42.   va_end (ap);
  43.   
  44.   return ret;
  45. }}
  46.  
  47. #ifdef TEST
  48. int
  49. main ()
  50. {
  51.   printf ("null = \"%s\"\n", concatn (NULL));
  52.   printf ("\"a\" = \"%s\"\n", concatn ("a", NULL));
  53.   printf ("\"ab\" = \"%s\"\n", concatn ("a", "b", NULL));
  54.   printf ("\"abc\" = \"%s\"\n", concatn ("a", "b", "c", NULL));
  55.   printf ("\"abcd\" = \"%s\"\n", concatn ("ab", "cd", NULL));
  56.   printf ("\"abcde\" = \"%s\"\n", concatn ("ab", "c", "de", NULL));
  57.   printf ("\"abcdef\" = \"%s\"\n", concatn ("", "a", "", "bcd", "ef", NULL));
  58.   return 0;
  59. }
  60.  
  61. #endif /* TEST */
  62.  
  63.  
  64. /*
  65. Local variables:
  66. standalone-compile-command: "gcc -posix -g -I. -I.. -DTEST concatn.c kpathsea.a"
  67. End:
  68. */
  69.