~ubuntu-branches/ubuntu/trusty/fldigi/trusty

« back to all changes in this revision

Viewing changes to src/fileselector/flnfc_common.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Joop Stakenborg
  • Date: 2008-11-17 19:40:43 UTC
  • mfrom: (1.1.6 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081117194043-sfe108e41ppsyhxr
New upstream release

Show diffs side-by-side

added added

removed removed

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