fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Native_File_Chooser_common.cxx

Go to the documentation of this file.
00001 // "$Id: Fl_Native_File_Chooser_common.cxx 7977 2010-12-08 13:16:27Z AlbrechtS $"
00002 //
00003 // FLTK native OS file chooser widget
00004 //
00005 // Copyright 1998-2010 by Bill Spitzak and others.
00006 // Copyright 2004 Greg Ercolano.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems to:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 #include <string.h>
00029 #include <FL/Enumerations.H>
00030 
00031 // COPY A STRING WITH 'new'
00032 //    Value can be NULL
00033 //
00034 static char *strnew(const char *val) {
00035   if ( val == NULL ) return(NULL);
00036   char *s = new char[strlen(val)+1];
00037   strcpy(s, val);
00038   return(s);
00039 }
00040 
00041 // FREE STRING CREATED WITH strnew(), NULLS OUT STRING
00042 //    Value can be NULL
00043 //
00044 static char *strfree(char *val) {
00045   if ( val ) delete [] val;
00046   return(NULL);
00047 }
00048 
00049 // 'DYNAMICALLY' APPEND ONE STRING TO ANOTHER
00050 //    Returns newly allocated string, or NULL 
00051 //    if s && val == NULL.
00052 //    's' can be NULL; returns a strnew(val).
00053 //    'val' can be NULL; s is returned unmodified.
00054 //
00055 //    Usage:
00056 //      char *s = strnew("foo");        // s = "foo"
00057 //      s = strapp(s, "bar");           // s = "foobar"
00058 //
00059 #if !defined(WIN32)
00060 static char *strapp(char *s, const char *val) {
00061   if ( ! val ) {
00062     return(s);                  // Nothing to append? return s
00063   }
00064   if ( ! s ) {
00065     return(strnew(val));        // New string? return copy of val
00066   }
00067   char *news = new char[strlen(s)+strlen(val)+1];
00068   strcpy(news, s);
00069   strcat(news, val);
00070   delete [] s;                  // delete old string
00071   return(news);                 // return new copy
00072 }
00073 #endif
00074 
00075 // APPEND A CHARACTER TO A STRING
00076 //     This does NOT allocate space for the new character.
00077 //
00078 static void chrcat(char *s, char c) {
00079   char tmp[2] = { c, '\0' };
00080   strcat(s, tmp);
00081 }
00082 
00083 //
00084 // End of "$Id: Fl_Native_File_Chooser_common.cxx 7977 2010-12-08 13:16:27Z AlbrechtS $".
00085 //