xref: /illumos-gate/usr/src/cmd/sgs/tools/common/sgsmsg_piglatin_nl.pl (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
1#!/usr/bin/perl
2
3#
4# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
5# Use is subject to license terms.
6#
7# CDDL HEADER START
8#
9# The contents of this file are subject to the terms of the
10# Common Development and Distribution License (the "License").
11# You may not use this file except in compliance with the License.
12#
13# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14# or http://www.opensolaris.org/os/licensing.
15# See the License for the specific language governing permissions
16# and limitations under the License.
17#
18# When distributing Covered Code, include this CDDL HEADER in each
19# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
20# If applicable, add the following below this CDDL HEADER, with the
21# fields enclosed by brackets "[]" replaced with your own identifying
22# information: Portions Copyright [yyyy] [name of copyright owner]
23#
24# CDDL HEADER END
25#
26#ident	"%Z%%M%	%I%	%E% SMI"
27
28
29#
30# Replacement for /usr/bin/nl in the sgs/messages piglatin tests.
31#
32#	usage: sgsmsg_piglatin_nl start_index
33#
34#	where start_index is the staring number
35#
36#
37# The sgs/messages test target used to use /usr/bin/nl as part
38# of the process of adding a piglatin translation to the file.
39# The invocations looked like:
40#
41#	nl -v1 -i2
42# or
43#	nl -v2 -i2
44#
45# This adds line numbers to the beginning of each non-empty line
46# from stdin, counting by 2, and starting at either 1 or 2, depending
47# on whether the master file, or the piglatin file is being processed.
48#
49# The output format is "%6d\t%s". Empty lines are replaced with
50# 7 space characters in the output, and the line number is not
51# incremented.
52#
53# The problem with nl is that it has a 2K buffer for input lines,
54# and our catalog files can have some very long lines, thanks to
55# the elfedit module help strings. This perl script emulates nl
56# to the extent required to replace it in the sgs piglatin tests,
57# while not breaking lines longer than 2K characters.
58
59use warnings;
60use strict;
61
62use vars qw($script $lineno);
63
64$script = 'sgsmsg_piglatin_nl';
65
66die "usage: $script start_index\n" if ($ARGV[0] eq '');
67$lineno = int($ARGV[0]);
68
69
70while (<STDIN>) {
71	if (($_ ne "") && ($_ ne "\n")) {
72		printf ("%6d\t%s", $lineno, $_);
73		$lineno += 2;
74	} else {
75		print "       \n";
76	}
77}
78