~ubuntu-branches/ubuntu/natty/ibm-3270/natty

« back to all changes in this revision

Viewing changes to wc3270/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2009-12-14 11:48:53 UTC
  • mfrom: (1.1.4 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091214114853-mywixml32hct9jr1
Tags: 3.3.10ga4-2
* Fix section to match override.
* Use debhelper compat level 7.
* Use 3.0 (quilt) source format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3
 
 *   2007 by Paul Mattes.
4
 
 * Parts Copyright 1990 by Jeff Sparkes.
5
 
 *  Permission to use, copy, modify, and distribute this software and its
6
 
 *  documentation for any purpose and without fee is hereby granted,
7
 
 *  provided that the above copyright notice appear in all copies and that
8
 
 *  both that copyright notice and this permission notice appear in
9
 
 *  supporting documentation.
10
 
 *
11
 
 * x3270, c3270, s3270 and tcl3270 are distributed in the hope that they will
12
 
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file LICENSE
14
 
 * for more details.
 
2
 * Copyright (c) 1993-2009, Paul Mattes.
 
3
 * Copyright (c) 1990, Jeff Sparkes.
 
4
 * All rights reserved.
 
5
 *
 
6
 * Redistribution and use in source and binary forms, with or without
 
7
 * modification, are permitted provided that the following conditions are met:
 
8
 *     * Redistributions of source code must retain the above copyright
 
9
 *       notice, this list of conditions and the following disclaimer.
 
10
 *     * Redistributions in binary form must reproduce the above copyright
 
11
 *       notice, this list of conditions and the following disclaimer in the
 
12
 *       documentation and/or other materials provided with the distribution.
 
13
 *     * Neither the names of Paul Mattes, Jeff Sparkes nor the names of their
 
14
 *       contributors may be used to endorse or promote products derived from
 
15
 *       this software without specific prior written permission.
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED BY PAUL MATTES AND JEFF SPARKES "AS IS" AND
 
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
20
 * ARE DISCLAIMED. IN NO EVENT SHALL PAUL MATTES OR JEFF SPARKES BE LIABLE FOR
 
21
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
23
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
24
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 
27
 * DAMAGE.
15
28
 */
16
29
 
17
30
/*
25
38
#endif /*]*/
26
39
#include <stdarg.h>
27
40
#include "resources.h"
 
41
#include "charsetc.h"
28
42
 
29
43
#include "utilc.h"
30
44
 
36
50
static char *
37
51
xs_vsprintf(const char *fmt, va_list args)
38
52
{
39
 
        char *r;
 
53
        char *r = CN;
40
54
#if defined(HAVE_VASPRINTF) /*[*/
41
 
        (void) vasprintf(&r, fmt, args);
42
 
        if (r == CN)
 
55
        int nw;
 
56
 
 
57
        nw = vasprintf(&r, fmt, args);
 
58
        if (nw < 0 || r == CN)
43
59
                Error("Out of memory");
44
60
        return r;
45
61
#else /*][*/
791
807
static iorec_t *iorecs = NULL;
792
808
 
793
809
static void
794
 
io_fn(XtPointer closure, int *source unused, XtInputId *id)
 
810
io_fn(XtPointer closure, int *source _is_unused, XtInputId *id)
795
811
{
796
812
        iorec_t *iorec;
797
813
 
959
975
        return XStringToKeysym(s);
960
976
}
961
977
#endif /*]*/
 
978
 
 
979
/* Return configuration options. */
 
980
const char *
 
981
build_options(void)
 
982
{
 
983
        return "Build options:"
 
984
#if defined(X3270_ANSI) /*[*/
 
985
                " --enable-ansi"
 
986
#else /*][*/
 
987
                " --disable-ansi"
 
988
#endif /*]*/
 
989
#if defined(X3270_APL) /*[*/
 
990
                " --enable-apl"
 
991
#else /*][*/
 
992
                " --disable-apl"
 
993
#endif /*]*/
 
994
#if defined(X3270_DBCS) /*[*/
 
995
                " --enable-dbcs"
 
996
#else /*][*/
 
997
                " --disable-dbcs"
 
998
#endif /*]*/
 
999
#if defined(X3270_FT) /*[*/
 
1000
                " --enable-ft"
 
1001
#else /*][*/
 
1002
                " --disable-ft"
 
1003
#endif /*]*/
 
1004
#if defined(X3270_DISPLAY) /*[*/
 
1005
# if defined(X3270_KEYPAD) /*[*/
 
1006
                " --enable-keypad"
 
1007
# else /*][*/
 
1008
                " --disable-keypad"
 
1009
# endif /*]*/
 
1010
#endif /*]*/
 
1011
#if defined(X3270_LOCAL_PROCESS) /*[*/
 
1012
                " --enable-local-process"
 
1013
#else /*][*/
 
1014
                " --disable-local-process"
 
1015
#endif /*]*/
 
1016
#if defined(X3270_DISPLAY) /*[*/
 
1017
# if defined(X3270_MENUS) /*[*/
 
1018
                " --enable-menus"
 
1019
# else /*][*/
 
1020
                " --disable-menus"
 
1021
# endif /*]*/
 
1022
#endif /*]*/
 
1023
#if defined(X3270_DISPLAY) || defined(C3270) /*[*/
 
1024
# if defined(X3270_PRINTER) /*[*/
 
1025
                " --enable-printer"
 
1026
# else /*][*/
 
1027
                " --disable-printer"
 
1028
# endif /*]*/
 
1029
#endif /*]*/
 
1030
#if defined(X3270_DISPLAY) || defined(C3270) /*[*/
 
1031
# if defined(X3270_SCRIPT) /*[*/
 
1032
                " --enable-script"
 
1033
# else /*][*/
 
1034
                " --disable-script"
 
1035
# endif /*]*/
 
1036
#endif /*]*/
 
1037
#if defined(X3270_TN3270E) /*[*/
 
1038
                " --enable-tn3270e"
 
1039
#else /*][*/
 
1040
                " --disable-tn3270e"
 
1041
#endif /*]*/
 
1042
#if defined(X3270_TRACE) /*[*/
 
1043
                " --enable-trace"
 
1044
#else /*][*/
 
1045
                " --disable-trace"
 
1046
#endif /*]*/
 
1047
#if defined(HAVE_LIBSSL) /*[*/
 
1048
                " --with-ssl"
 
1049
#else /*][*/
 
1050
                " --without-ssl"
 
1051
#endif /*]*/
 
1052
#if defined(C3270) /*[*/
 
1053
# if defined(HAVE_LIBREADLINE) /*[*/
 
1054
                " --with-readline"
 
1055
# else /*][*/
 
1056
                " --without-readline"
 
1057
# endif /*]*/
 
1058
# if !defined(_WIN32) /*[*/
 
1059
#  if defined(CURSES_WIDE) /*[*/
 
1060
                " --with-curses-wide"
 
1061
#  else /*][*/
 
1062
                " --without-curses-wide"
 
1063
#  endif /*]*/
 
1064
# endif /*]*/
 
1065
#endif /*]*/
 
1066
#if defined(USE_ICONV) /*[*/
 
1067
                " --with-iconv"
 
1068
#endif /*]*/
 
1069
                ;
 
1070
}
 
1071
 
 
1072
void
 
1073
dump_version(void)
 
1074
{
 
1075
        printf("%s\n%s\n", build, build_options());
 
1076
        charset_list();
 
1077
        printf("\n"
 
1078
"Copyright 1989-2009, Paul Mattes, GTRC and others.\n"
 
1079
"See the source code or documentation for licensing details.\n"
 
1080
"Distributed WITHOUT ANY WARRANTY; without even the implied warranty of\n"
 
1081
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
 
1082
        exit(0);
 
1083
}
 
1084
 
 
1085
/* Scale a number for display. */
 
1086
const char *
 
1087
display_scale(double d, char *buf, size_t buflen)
 
1088
{
 
1089
    if (d >= 1000000.0)
 
1090
        snprintf(buf, buflen, "%.3g M", d / 1000000.0);
 
1091
    else if (d >= 1000.0)
 
1092
        snprintf(buf, buflen, "%.3g K", d / 1000.0);
 
1093
    else
 
1094
        snprintf(buf, buflen, "%.3g ", d);
 
1095
 
 
1096
    /* Don't trust snprintf. */
 
1097
    buf[buflen - 1] = '\0';
 
1098
 
 
1099
    return buf;
 
1100
}