NTK 1.3.0
Fl_Native_File_Chooser_common.cxx
1// "$Id: Fl_Native_File_Chooser_common.cxx 7977 2010-12-08 13:16:27Z AlbrechtS $"
2//
3// FLTK native OS file chooser widget
4//
5// Copyright 1998-2010 by Bill Spitzak and others.
6// Copyright 2004 Greg Ercolano.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems to:
24//
25// http://www.fltk.org/str.php
26//
27
28#include <string.h>
29#include <FL/Enumerations.H>
30
31// COPY A STRING WITH 'new'
32// Value can be NULL
33//
34static char *strnew(const char *val) {
35 if ( val == NULL ) return(NULL);
36 char *s = new char[strlen(val)+1];
37 strcpy(s, val);
38 return(s);
39}
40
41// FREE STRING CREATED WITH strnew(), NULLS OUT STRING
42// Value can be NULL
43//
44static char *strfree(char *val) {
45 if ( val ) delete [] val;
46 return(NULL);
47}
48
49// 'DYNAMICALLY' APPEND ONE STRING TO ANOTHER
50// Returns newly allocated string, or NULL
51// if s && val == NULL.
52// 's' can be NULL; returns a strnew(val).
53// 'val' can be NULL; s is returned unmodified.
54//
55// Usage:
56// char *s = strnew("foo"); // s = "foo"
57// s = strapp(s, "bar"); // s = "foobar"
58//
59#if !defined(WIN32)
60static char *strapp(char *s, const char *val) {
61 if ( ! val ) {
62 return(s); // Nothing to append? return s
63 }
64 if ( ! s ) {
65 return(strnew(val)); // New string? return copy of val
66 }
67 char *news = new char[strlen(s)+strlen(val)+1];
68 strcpy(news, s);
69 strcat(news, val);
70 delete [] s; // delete old string
71 return(news); // return new copy
72}
73#endif
74
75// APPEND A CHARACTER TO A STRING
76// This does NOT allocate space for the new character.
77//
78static void chrcat(char *s, char c) {
79 char tmp[2] = { c, '\0' };
80 strcat(s, tmp);
81}
82
83//
84// End of "$Id: Fl_Native_File_Chooser_common.cxx 7977 2010-12-08 13:16:27Z AlbrechtS $".
85//
This file contains type definitions and general enumerations.