Back to index

tetex-bin  3.0
concatn.c
Go to the documentation of this file.
00001 /* concatn.c: Concatenate an arbitrary number of strings.
00002 
00003 Copyright (C) 1993, 95 Karl Berry.
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #include <kpathsea/config.h>
00020 
00021 #include <kpathsea/concatn.h>
00022 
00023 
00024 /* OK, it would be epsilon more efficient to compute the total length
00025    and then do the copying ourselves, but I doubt it matters in reality.  */
00026 
00027 string
00028 concatn PVAR1C(const_string, str1,  ap)
00029 {
00030   string arg;
00031   string ret;
00032 
00033   if (!str1)
00034     return NULL;
00035   
00036   ret = xstrdup (str1);
00037   
00038   while ((arg = va_arg (ap, string)) != NULL)
00039     {
00040       string temp = concat (ret, arg);
00041       free (ret);
00042       ret = temp;
00043     }
00044   va_end (ap);
00045   
00046   return ret;
00047 }}
00048 
00049 #ifdef TEST
00050 int
00051 main ()
00052 {
00053   printf ("null = \"%s\"\n", concatn (NULL));
00054   printf ("\"a\" = \"%s\"\n", concatn ("a", NULL));
00055   printf ("\"ab\" = \"%s\"\n", concatn ("a", "b", NULL));
00056   printf ("\"abc\" = \"%s\"\n", concatn ("a", "b", "c", NULL));
00057   printf ("\"abcd\" = \"%s\"\n", concatn ("ab", "cd", NULL));
00058   printf ("\"abcde\" = \"%s\"\n", concatn ("ab", "c", "de", NULL));
00059   printf ("\"abcdef\" = \"%s\"\n", concatn ("", "a", "", "bcd", "ef", NULL));
00060   return 0;
00061 }
00062 
00063 #endif /* TEST */
00064 
00065 
00066 /*
00067 Local variables:
00068 standalone-compile-command: "gcc -posix -g -I. -I.. -DTEST concatn.c kpathsea.a"
00069 End:
00070 */