You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.4KB

  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. #include <string.h>
  28. #include <FL/Enumerations.H>
  29. // COPY A STRING WITH 'new'
  30. // Value can be NULL
  31. //
  32. static char *strnew(const char *val) {
  33. if ( val == NULL ) return(NULL);
  34. char *s = new char[strlen(val)+1];
  35. strcpy(s, val);
  36. return(s);
  37. }
  38. // FREE STRING CREATED WITH strnew(), NULLS OUT STRING
  39. // Value can be NULL
  40. //
  41. static char *strfree(char *val) {
  42. if ( val ) delete [] val;
  43. return(NULL);
  44. }
  45. // 'DYNAMICALLY' APPEND ONE STRING TO ANOTHER
  46. // Returns newly allocated string, or NULL
  47. // if s && val == NULL.
  48. // 's' can be NULL; returns a strnew(val).
  49. // 'val' can be NULL; s is returned unmodified.
  50. //
  51. // Usage:
  52. // char *s = strnew("foo"); // s = "foo"
  53. // s = strapp(s, "bar"); // s = "foobar"
  54. //
  55. #if !defined(WIN32)
  56. static char *strapp(char *s, const char *val) {
  57. if ( ! val ) {
  58. return(s); // Nothing to append? return s
  59. }
  60. if ( ! s ) {
  61. return(strnew(val)); // New string? return copy of val
  62. }
  63. char *news = new char[strlen(s)+strlen(val)+1];
  64. strcpy(news, s);
  65. strcat(news, val);
  66. delete [] s; // delete old string
  67. return(news); // return new copy
  68. }
  69. #endif
  70. // APPEND A CHARACTER TO A STRING
  71. // This does NOT allocate space for the new character.
  72. //
  73. static void chrcat(char *s, char c) {
  74. char tmp[2] = { c, '\0' };
  75. strcat(s, tmp);
  76. }
  77. //
  78. // End of "$Id: Fl_Native_File_Chooser_common.cxx 7977 2010-12-08 13:16:27Z AlbrechtS $".
  79. //