2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 #ifdef VERBOSE_REV_INFO
25 static char rcs_id[] = "$XConsortium: DtTermSyntax.c /main/4 1996/05/16 11:22:57 ageorge $";
26 #endif /* VERBOSE_REV_INFO */
30 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
31 * (c) Copyright 1993, 1994 International Business Machines Corp. *
32 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
33 * (c) Copyright 1993, 1994 Novell, Inc. *
36 #include "TermHeader.h"
37 #include "TermPrimMessageCatI.h"
41 struct _options *next;
44 static struct _options *optHead;
45 static struct _options *messageHead;
47 static char *options_default[] = {
48 "-/+132 enable/disable 80<->132 column escape seq",
49 "-/+aw enable/disable autowrap",
50 "-/+bs turn off/on Term background is select color",
51 "-display displayname X server to contact",
52 "-e command args command to execute",
53 "-fb fontset bold text font",
54 "-fn fontset normal text font",
55 "-geometry geom size (in characters) and position of window",
56 "-help print out this message",
57 "-/+iconic start/do not start iconic",
58 "-/+j enable/disable jump scroll",
59 "-/+kshMode enable/disable ksh mode",
60 "-/+l enable/disable logging",
61 "-lf filename logging filename",
62 "-/+ls enable/disable login shell",
63 "-/+map enable/disable map window on pty output",
64 "-/+mb enable/disable margin bell",
65 "-ms color pointer color",
66 "-n string specify icon name",
67 "-name string client instance, icon, and title strings",
68 "-nb distance specify distance for right margin bell",
69 "-/+rw enable/disable reverse wrap",
70 "-/+sb enable/disable scroll bar",
71 "-/+sf enable/disable SUN function keys",
72 "-sl number[s] number of scrolled lines [screens] to save",
73 "-ti name string used for programmatic identification",
74 "-title string title string for window",
75 "-tm string terminal mode keywords and characters",
76 "-tn name TERM environment variable name",
77 "-usage print out this message",
78 "-/+vb enable/disable visual bell",
79 "-xrm resourcestring additional resource specifications",
81 "-Sxxd slave mode on \"ttyxx\" file descriptor \"d\"",
82 "-Sxxx.d slave mode on \"ttyxxx\" file descriptor \"d\"",
86 static char *message_defaults[] = {
87 "The -e option, if given must appear at the end of the command line,",
88 "otherwise the user's default shell will be started. Options that start",
89 "with a plus sign (+) restore the default.",
93 static void GetUsage(void)
95 register struct _options *optPtr;
100 optHead = (struct _options *) 0;
101 optPtr = (struct _options *) 0;
105 ** get the next option...
108 c2 = GETMESSAGE(NL_SETN_Syntax, i, options_default[i-1]);
109 c = XtMalloc(strlen(c2) + 1);
110 (void) strcpy(c, c2);
112 ** check and see if we are at the end of the list...
114 if (!strcmp(c, "End-Of-List"))
118 ** allocate the next entry...
121 optHead = (struct _options *) malloc(sizeof(struct _options));
124 optPtr->next = (struct _options *) malloc(sizeof(struct _options));
125 optPtr = optPtr->next;
130 ** did we run out of malloc space...
135 SysError(HPT_MALLOC4);
136 #else /* _VUE_NO_PROTO */
137 SysError(HPT_MALLOC4, NULL);
138 #endif /* _VUE_NO_PROTO */
143 ** there is no next element yet...
145 optPtr->next = (struct _options *) 0;
148 ** the first part of the string is the option...
154 while (*c && ('\t' != *c))
157 ** this marks the end of the option...
162 ** skip over any more tabs...
164 while (*c && ('\t' == *c))
167 ** and this is the beginning of the option desc..
172 messageHead = (struct _options *) 0;
173 optPtr = (struct _options *) 0;
175 for (i = num_messages + 1; ; i++) {
177 ** get the next message string...
179 c2 = GETMESSAGE(NL_SETN_Syntax, i,message_defaults[i - num_messages - 1]);
180 c = XtMalloc(strlen(c2) + 1);
181 (void) strcpy(c, c2);
183 ** check and see if we are at the end of the list...
185 if (!strcmp(c, "End-Of-List"))
189 ** allocate the next entry...
192 messageHead = (struct _options *) malloc(sizeof(struct _options));
193 optPtr = messageHead;
195 optPtr->next = (struct _options *) malloc(sizeof(struct _options));
196 optPtr = optPtr->next;
201 ** did we run out of malloc space...
206 SysError(HPT_MALLOC5);
207 #else /* _VUE_NO_PROTO */
208 SysError(HPT_MALLOC5, NULL);
209 #endif /* _VUE_NO_PROTO */
214 ** there is no next element yet...
216 optPtr->next = (struct _options *) 0;
219 ** the entire string is the "desc"...
225 void Syntax(char *programName, char *badOption)
227 register struct _options *optPtr;
236 ** get the usage message string...
240 /* suppress codecenter "Assignment in conditional 'if' expression."
244 if (c = getenv("COLUMNS")) cols = atoi(c);
247 (void) fprintf(stderr, (GETMESSAGE(NL_SETN_Syntax,47,
248 "%s: bad command line option \"%s\"\r\n\n")),
249 programName, badOption);
251 (void) fprintf(stderr, (GETMESSAGE(NL_SETN_Syntax,48, "usage: %s")),
253 col = 8 + strlen(programName);
255 ** now that we are NLSized, we need to figure out the width that the
256 ** format string adds to each option...
259 c = GETMESSAGE(NL_SETN_Syntax,50, " [%s]");
260 fmt = XtMalloc(strlen(c) + 1);
261 (void) strcpy(fmt, c);
262 (void) sprintf(buffer, fmt, "");
263 fmtlen = strlen(buffer);
265 for (optPtr = optHead; optPtr; optPtr = optPtr->next) {
267 ** the following 3 assumes that the msg_catalog doesn't add more than
268 ** 2 characters to the string...
270 int len = fmtlen + strlen(optPtr->opt);
271 if (col + len >= cols) {
272 (void) fprintf(stderr, "%s", (GETMESSAGE(NL_SETN_Syntax,49, "\r\n ")));
275 (void) fprintf(stderr, fmt, optPtr->opt);
278 (void) fprintf(stderr, (GETMESSAGE(NL_SETN_Syntax,51,
279 "\r\n\nType \"%s -help\" for a full description.\r\n\n")),
285 void Help(char *programName)
287 register struct _options *optPtr;
291 ** get the usage message string...
295 (void) fprintf(stderr, "%s", (GETMESSAGE(NL_SETN_Syntax,52, "usage:\n")));
296 (void) fprintf(stderr, (GETMESSAGE(NL_SETN_Syntax,53,
297 "\t%s [-options ...] [-e command args]\n\n")),
299 (void) fprintf(stderr, "%s", (GETMESSAGE(NL_SETN_Syntax,54,
300 "where options include:\n")));
301 for (optPtr = optHead; optPtr; optPtr = optPtr->next)
302 if (strlen(optPtr->opt) > (size_t) width) width = strlen(optPtr->opt);
304 for (optPtr = optHead; optPtr; optPtr = optPtr->next)
305 (void) fprintf(stderr, " %-*s %s\n", width, optPtr->opt,
308 (void) fprintf(stderr, "\n");
309 for (optPtr = messageHead; optPtr; optPtr = optPtr->next)
310 (void) fprintf(stderr, "%s\n", optPtr->desc);
312 (void) fprintf(stderr, "\n");