summaryrefslogtreecommitdiff
path: root/autoopts/test/nls.test
blob: 1455515dcecc509134c16f117518f6af1aeccf37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#! /bin/sh
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# nls.test      ---  test NLS, sort-of
#
# Time-stamp:        "2011-08-07 17:36:29 bkorb"
# Author:            Bruce Korb <bkorb@gnu.org>
##
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under any one of two licenses.  The license
##  in use must be one of these two and the choice is under the control
##  of the user of the license.
##
##   The GNU Lesser General Public License, version 3 or later
##      See the files "COPYING.lgplv3" and "COPYING.gplv3"
##
##   The Modified Berkeley Software Distribution License
##      See the file "COPYING.mbsd"
##
##  These files have the following md5sums:
##
##  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
##  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
##  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
#
# ----------------------------------------------------------------------

. ./defs
AUTOGEN_TEMPL_DIRS=`cd ${srcdir}/..;pwd`
export AUTOGEN_TEMPL_DIRS

# # # # # # # # # # DEFINITIONS FILE # # # # # # # # #

echo "creating ${testname}.def in `pwd`"
testname="${testname}" test_main="YES" \
argument="${argument}" long_opts="YES" \
${SHELLX} ${stdopts} option:'opt init' second=020 || \
    failure "Could not run stdopts.def"

echo 'export = "extern char* gettext( char const* );";' >> ${testname}.def
CC="${CC} ${CFLAGS} -DENABLE_NLS=1 ${INC}"
CFLAGS=''
INC=''

compile_with_nls() {

  echo ${AG_L} ${testname}.def
  ${AG_L} ${testname}.def || \
    failure AutoGen could not process

  chmod u+w ${testname}.[ch]
  cat >> ${testname}.c <<'_EOF_'
#include <ctype.h>
char*
gettext( char const* pzS )
{
    static char z[ 4096 ];
    char* pzD = z + sizeof(z) - 1;
    int ct = 0;
    int found_nl = 0;
    if (pzS == NULL)
        return NULL;
    if (strchr(pzS, '%') != NULL)
        return (void *)pzS;
    *--pzD = '\0';
    while (*pzS == ' ')  pzS++;
    for (;;) {
        char ch = *(pzS++);
        if (ch == '\0')
            break;
        *(--pzD) = ch;
        ct++;
        if (ch != '\n')
            continue;
        found_nl = 1;
        while (*pzS == ' ')  pzS++;
    }
    if (found_nl)
        strcpy(z + sizeof(z) - 2, "\n");
    while (*pzD == '\n')
        pzD++;
    return pzD;
}
_EOF_

  sedcmd='/ot sgub .* tropeR$/d;/ yb degakcaP/d'
  compile "--pleh"
  mv ${testname}.help ${testname}-${1}.help
  cmp -s ${testname}-${1}.help ${testname}-${1}.hlp || { set +x ; \
    failure "`diff -c ${testname}-${1}.hlp ${testname}-${1}.help`" ; }
}

# # # # # # # # # # HELP OUTPUT FILE # # # # # # # # #

echo creating ${testname}.hlp
clean_help > ${testname}-1.hlp <<'_EOF_'
test_nls - Test AutoOpts for nls
USAGE:  nls [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
noitpircseD    emaN-noitpO grA glF
   -o rtS noitpo         pircsed noitpo noitpo ehT
   -s muN dnoces         pircsed noitpo dnoces ehT
   -?  on pleh           tixe dna noitamrofni egasu dednetxe yalpsiD
   -!  on pleh-erom      regap urht dessap noitamrofni egasu dednetxE

.retcarahc galf eht dna nehpyh
elgnis a yb ro eman rieht dna snehpyh delbuod yb deificeps era snoitpO
_EOF_

compile_with_nls 1

mv ${testname}.def  ${testname}-1.def

exec 3> ${testname}.def
cat ${testname}-1.def >&3
echo 'full-usage = <''<''- _EOF_' >&3
clean_help >&3 <<'_EOF_'
test_nls - Test AutoOpts for nls
USAGE:  nls [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
  Flg Arg Option-Name    Description
   -o Str option         The option descrip
   -s Num second         The second descrip
   -? no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager

Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.
_EOF_
echo '_EOF_;' >&3
exec 3>&-

clean_help > ${testname}-2.hlp <<'_EOF_'
.retcarahc galf eht dna nehpyh
elgnis a yb ro eman rieht dna snehpyh delbuod yb deificeps era snoitpO

regap urht dessap noitamrofni egasu dednetxE      pleh-erom  on !-
tixe dna noitamrofni egasu dednetxe yalpsiD           pleh  on ?-
pircsed dnoces ehT         dnoces muN s-
pircsed noitpo ehT         noitpo rtS o-
noitpircseD    emaN-noitpO grA glF
...] ]>lav<} |={[>eman<-- | ]>lav<[ >galf<- [ sln  :EGASU
sln rof stpOotuA tseT - sln_tset
_EOF_

compile_with_nls 2
cleanup

## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## End:

# end of nls.test