/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1996, by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* tabs.c
*
* Copyright 1990, 1992 by Mortice Kern Systems Inc. All rights reserved.
*
* PORTABILITY:
* POSIX.2a UPE full support
* SVID 3 full support except +m option is stubbed
* XPG full support except +m option is stubbed
*
* SYNOPSIS:
* tabs [-T term] [+m[n]] [-n]
* tabs [-T term] [+m[n]] -t tablist
* tabs [-T term] [+m[n]] n1[,n2,...]
* tabs [-T term] [+m[n]] tabspec
*
* DESCRIPTION:
* The tabs utility shall display a series of characters that first clears
* the hardware terminal tab settings and then initializes the tab stops
* at the specified positions.
*
* The phrase "tab-stop position N" shall be taken to mean that, from the
* start of a line of output, tabbing to position N shall cause the next
* character output to be in the (N+1)th column position on that line.
* The maximum number of tab stops allowed is terminal dependent.
*
* 'tabspec' is one of the following:
*
* Assembler:
* -a 1,10,16,36,72
* -a2 1,10,16,40,72
* -u 1,12,20,44
*
* COBOL:
* -c 1,8,12,16,20,55
* -c2 1,6,10,14,49
* -c3 1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67
*
* FORTRAN:
* -f 1,7,11,15,19,23
*
* PL/I:
* -p 1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61
*
* SNOBOL:
* -s 1,10,55
*
*
* EXIT STATUS:
* 0 successful completion.
*
* >0 An error occured.
*/
#ifdef M_RCSID
#ifndef lint
#endif
#endif
#include <mks.h>
#include <curses.h>
#include <term.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern char *_cmdname;
/* Exit Status */
#define SUCCESS 0
#define NO_FORM 0
* tabs [-T term] [+m[n]] tabspec
*/
static int margin = 0;
typedef struct {
char *option;
char *list;
} predefined;
{ "a", "1,10,16,36,72" },
{ "a2", "1,10,16,40,72" },
{ "u", "1,12,20,44" },
{ "c", "1,8,12,16,20,55" },
{ "c2", "1,6,10,14,49" },
{ "c3", "1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67" },
{ "f", "1,7,11,15,19,23" },
{ "p", "1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61" },
{ "s", "1,10,55" },
};
static char *term_name;
Usage: tabs [-T term] [+m[n]] [-n]\n\
tabs [-T term] [+m[n]] -t <tablist>\n\
tabs [-T term] [+m[n]] n1[,n2,...]\n\
tabs [-T term] [+m[n]] -a|a2|u|c|c2|c3|f|p|s\n", "U");
/*f
* mainline for tabs
*/
int
int argc;
char **argv;
{
char *ap;
int i;
int err_code;
predefined *p;
/* Check for standard io '-' */
if (*ap == '\0')
break;
/* End option list '--'? */
++argv;
--argc;
break;
}
if (**argv == '-') {
/* '-xyz...' or '-xyzF<parm>' or '-xyzF <parm>' */
switch (*ap) {
case 't':
return (usage());
if (*++ap != '\0') {
break;
} else if (1 < argc) {
--argc;
break;
}
return (usage());
break;
case 'T':
/* '-T<term>' or '-T <term>' */
if (*++ap != '\0') {
break;
} else if (1 < argc) {
--argc;
break;
}
return (usage());
default:
return (usage());
continue;
}
for (p = tabspec;
++p)
;
break;
}
return (usage());
}
break;
}
} else {
/* All '+' options. */
if (*ap == 'm') {
if (margin == 0)
margin = 10;
} else {
return (usage());
}
}
}
switch (argc) {
case 0:
break;
case 1:
break;
default:
return (usage());
}
} else if (0 < argc) {
return (usage());
}
switch (err_code) {
case 1:
break;
case 0:
return (BAD_TERMINAL);
case -1:
return (BAD_TERMINAL);
}
if (save_cursor != NULL)
if (restore_cursor != NULL)
else
mvcol(0, 0);
return (err_code);
}
/*f
* actually do tabs
*/
STATIC int
do_tabs()
{
int oc = 0;
int nc = 0;
return (NOT_DEFINED);
}
mvcol(0, 0);
#if 0 /* margins are not yet supported in terminfo */
return (NOT_DEFINED);
} else {
}
#endif
switch (form) {
case N_FORM:
if (0 < n_width)
break;
case T_FORM:
return (NOT_VALID);
}
if (*p == '\0') {
break;
}
do {
return (NOT_VALID);
}
return (NOT_VALID);
}
++p;
set_tab_at(nc);
} while (nc != 0);
break;
case P_FORM:
if (*p == '+' || *p == '-') {
return (NOT_VALID);
}
for (;;) {
if (nc == 0)
break;
return (NOT_VALID);
}
return (NOT_VALID);
}
++p;
set_tab_at(nc);
if (*p == '+')
++p;
else
nc = 0;
}
break;
}
return (SUCCESS);
}
/*f
* Set a tab every n columns starting with column 0.
*/
STATIC void
set_every(n)
int n;
{
int x;
for (x = 0; x < columns; x += n)
set_tab_at(x);
}
/*f
* Set tab at column x. Assume that cursor has been positioned at the
* start of the line before settiing the first tab.
*/
STATIC void
set_tab_at(x)
int x;
{
static int col = 0;
col = x;
}
/*f
* Move the cursor on the current row from column 'col' to column 'x'.
* We can't use mvcur() because we have no idea what row we're on.
*/
STATIC void
{
if (nc == 0) {
putchar('\r');
} else if (column_address != NULL) {
} else if (parm_right_cursor != NULL) {
} else if (cursor_right != NULL) {
while (diff--)
} else {
while (diff--)
putchar(' ');
}
}
/*f
* usage message for tabs
*/
STATIC int
usage()
{
return (USAGE);
}
/*f
* display error message
*/
STATIC void
{
}