EVERYTHING FROM THE OTHER REPO

This commit is contained in:
2026-07-29 03:36:26 +03:00
parent 6777ea96db
commit 92a6ae42f5
4426 changed files with 1696506 additions and 2 deletions
@@ -0,0 +1,47 @@
Version 1.2
===========
Thanks for help with beta test to Bill Davidsen, Tom Dickey, Ed
Ferguson, Jack Fitts, Onno van der Linden, Carl Mascott, Jean-Pierre
Radley, John Roll, Ian Searle, Bob Stockler.
The calendar program examples/hical was written by Bob Stockler.
Darrel Hankerson ported versions 1.2.x to DOS/OS2.
Version 1.0 and 1.1
===================
Carl Mascott ported mawk to V7 and in the process rooted out
some subtle (and not so subtle) bugs.
Ian Searle ported mawk to System V and put up with my insane
attempts to get fpe exception trapping off.
An anonymous reviewer for comp.sources.reviewed did the
MSC and Mac ports and wrote .bat files for the tests.
Another or maybe the same reviewer did the Dynix port.
Ports to new systems:
Ed Ferguson MIPS M2000 C2.20 OS4.52
Jwahar R. Bammi Atari ST
Berry Kercheval SGI IRIX 4.0.1
Andy Newman Next 2.1
Mike Carlton Next 2.1
Elliot Jaffe AIX 3.1
Jeremy Martin Convex 9.1
Scott Hunziker Coherent 4.0
Ken Poulton Hpux
Onno van der Linden 386bsd 0.1
Bob Hutchinson Linux 0.98p14
The DOS version is a lot better thanks to suggestions and testing
from Ed Ferguson, Jack Fitts, Nadav Horesh, Michael Golan and
Conny Ohstrom. The DOS additions for 1.1.2d are all ideas of
Ben Myers; much of the code is his too.
Arnold Robbins kept me current on POSIX standards for AWK, and
explained some of the "dark corners".
Thank you to everyone who reported bugs or offered encouragement,
suggestions or criticism. (At least the bugs got fixed).
@@ -0,0 +1,95 @@
-- $MawkId: README,v 1.7 2023/02/16 00:19:21 tom Exp $
-- vile:txtmode fc=78
mawk -- an implementation of new/posix awk
version 1.3.4
Generic installation instructions are in file INSTALL.
This file gives more specific information.
Send bug reports, comments, questions, etc. to
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net/mawk/
-------------------------------------------------------------------------------
Portability:
-----------
This program builds/runs on several POSIX-style platforms.
It has been recently tested for these:
AIX (5.1 and 5.3, using cc and gcc)
Cygwin (1.5.21 on Windows/XP)
FreeBSD (6.0)
HPUX (10.20, 11.00, 11.11 and 11.23, using cc and gcc)
IRIX64 (using cc and gcc)
Linux (several flavors, using gcc and icc)
MinGW/MSYS (on Windows/XP)
OpenBSD (4.1)
Solaris (2.6 to 10, using cc and gcc)
Tru64 (4.0D and 5.1, using cc and gcc)
Options:
-------
The configure script has these application-specific options:
--disable-echo display "compiling" commands
Show "compiling foo.c" rather than the full compiler and
options. Those are clutter useful only to a developer.
Developers focus on compiler warnings anyway.
--enable-warnings test: turn on gcc compiler warnings
This turns on the usual gcc compiler warnings needed to
do useful development. If you happen to be using the
Intel compiler icc, it does the right thing for that.
--with-builtin-regex use mawk's own regular-expressions engine
Normally mawk's configure script uses the built-in regular
expressions. The choice of default is based on where the
greatest lossage occurs. More scripts use gawk's
null-character extension than use POSIX brace expressions. If
your needs are different, build mawk using an external library.
Limitations:
-----------
mawk 1.3.3 was developed to correspond with a POSIX draft. POSIX
continued, and incorporated some of mawk's extensions as features.
The 1.3.4 release fills in the major areas in which POSIX grew past
the mawk 1.3.3 implementation.
mawk's built-in regular expression engine does not yet support brace
expressions, e.g.,
/a{,4}/
Use an external regular expression library if you require brace
expressions. Aside from that, mawk's built-in regular expressions
provide POSIX functionality.
Using an external regular expression library means that mawk cannot
match expressions containing the null character. That is a
nonstandard feature provided by gawk. Using mawk's built-in regular
expressions, there is some support for this feature.
Aside from supporting nulls, using an external regular expression
library is usually advantageous.
The Cygwin math library has some problems (which are also visible in
the gawk port). For instance, its log() function returns Inf
(infinity) for log(-8) rather than NaN (not a number) as all of the
Unix and similar platforms would do.
The MSYS package for regular expressions is unusable as an external
library for mawk because it generates a runtime error when asked to
compile a newline, e.g., "\n". mawk does this during initialization.
The MinGW/MSYS port does not currently support pipes. There is
source-code from the obsolete MS-DOS port which can be reused for this
purpose; however that is not the focus of the 1.3.4 release.
Binary file not shown.
@@ -0,0 +1,393 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Comment: This is the Debian GNU prepackaged version of mawk,
an implementation of the AWK Programming Language.
This package was put together by Chris Fearnley <cjf@netaxs.com>.
Upstream-Contact: Mike Brennan <brennan@whidbey.com>
Source: https://invisible-island.net/mawk/
Files: *
Copyright: 1996, Michael D. Brennan.
2008-2023, Thomas E. Dickey.
License: GPL-2.0-only
Files: debian/*
Copyright: (C) 1995-96 Chris Fearnley.
(C) 1998-2003 James Troup.
License: GPL-2.0-only
Files: install-sh
Copyright: (C) 1994 X Consortium
License: X11
Comment: FSF changes to this file are in the public domain.
Files: icons/mawk48.svg
Copyright: 2012, Thomas E. Dickey.
License: CC-BY-3.0
Files:
test/interval0.awk
test/interval0.out
test/repetitions.awk
test/repetitions.dat
test/repetitions.out
Copyright: 2016, jlp765
License: GPL-2.0-only
License: CC-BY-3.0
Creative Commons Legal Code
.
Attribution 3.0 Unported
.
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR
DAMAGES RESULTING FROM ITS USE.
.
License
.
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY
BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
CONDITIONS.
.
1. Definitions
.
a. "Adaptation" means a work based upon the Work, or upon the Work and
other pre-existing works, such as a translation, adaptation,
derivative work, arrangement of music or other alterations of a
literary or artistic work, or phonogram or performance and includes
cinematographic adaptations or any other form in which the Work may be
recast, transformed, or adapted including in any form recognizably
derived from the original, except that a work that constitutes a
Collection will not be considered an Adaptation for the purpose of
this License. For the avoidance of doubt, where the Work is a musical
work, performance or phonogram, the synchronization of the Work in
timed-relation with a moving image ("synching") will be considered an
Adaptation for the purpose of this License.
b. "Collection" means a collection of literary or artistic works, such as
encyclopedias and anthologies, or performances, phonograms or
broadcasts, or other works or subject matter other than works listed
in Section 1(f) below, which, by reason of the selection and
arrangement of their contents, constitute intellectual creations, in
which the Work is included in its entirety in unmodified form along
with one or more other contributions, each constituting separate and
independent works in themselves, which together are assembled into a
collective whole. A work that constitutes a Collection will not be
considered an Adaptation (as defined above) for the purposes of this
License.
c. "Distribute" means to make available to the public the original and
copies of the Work or Adaptation, as appropriate, through sale or
other transfer of ownership.
d. "Licensor" means the individual, individuals, entity or entities that
offer(s) the Work under the terms of this License.
e. "Original Author" means, in the case of a literary or artistic work,
the individual, individuals, entity or entities who created the Work
or if no individual or entity can be identified, the publisher; and in
addition (i) in the case of a performance the actors, singers,
musicians, dancers, and other persons who act, sing, deliver, declaim,
play in, interpret or otherwise perform literary or artistic works or
expressions of folklore; (ii) in the case of a phonogram the producer
being the person or legal entity who first fixes the sounds of a
performance or other sounds; and, (iii) in the case of broadcasts, the
organization that transmits the broadcast.
f. "Work" means the literary and/or artistic work offered under the terms
of this License including without limitation any production in the
literary, scientific and artistic domain, whatever may be the mode or
form of its expression including digital form, such as a book,
pamphlet and other writing; a lecture, address, sermon or other work
of the same nature; a dramatic or dramatico-musical work; a
choreographic work or entertainment in dumb show; a musical
composition with or without words; a cinematographic work to which are
assimilated works expressed by a process analogous to cinematography;
a work of drawing, painting, architecture, sculpture, engraving or
lithography; a photographic work to which are assimilated works
expressed by a process analogous to photography; a work of applied
art; an illustration, map, plan, sketch or three-dimensional work
relative to geography, topography, architecture or science; a
performance; a broadcast; a phonogram; a compilation of data to the
extent it is protected as a copyrightable work; or a work performed by
a variety or circus performer to the extent it is not otherwise
considered a literary or artistic work.
g. "You" means an individual or entity exercising rights under this
License who has not previously violated the terms of this License with
respect to the Work, or who has received express permission from the
Licensor to exercise rights under this License despite a previous
violation.
h. "Publicly Perform" means to perform public recitations of the Work and
to communicate to the public those public recitations, by any means or
process, including by wire or wireless means or public digital
performances; to make available to the public Works in such a way that
members of the public may access these Works from a place and at a
place individually chosen by them; to perform the Work to the public
by any means or process and the communication to the public of the
performances of the Work, including by public digital performance; to
broadcast and rebroadcast the Work by any means including signs,
sounds or images.
i. "Reproduce" means to make copies of the Work by any means including
without limitation by sound or visual recordings and the right of
fixation and reproducing fixations of the Work, including storage of a
protected performance or phonogram in digital form or other electronic
medium.
.
2. Fair Dealing Rights. Nothing in this License is intended to reduce,
limit, or restrict any uses free from copyright or rights arising from
limitations or exceptions that are provided for in connection with the
copyright protection under copyright law or other applicable laws.
.
3. License Grant. Subject to the terms and conditions of this License,
Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
perpetual (for the duration of the applicable copyright) license to
exercise the rights in the Work as stated below:
.
a. to Reproduce the Work, to incorporate the Work into one or more
Collections, and to Reproduce the Work as incorporated in the
Collections;
b. to create and Reproduce Adaptations provided that any such Adaptation,
including any translation in any medium, takes reasonable steps to
clearly label, demarcate or otherwise identify that changes were made
to the original Work. For example, a translation could be marked "The
original work was translated from English to Spanish," or a
modification could indicate "The original work has been modified.";
c. to Distribute and Publicly Perform the Work including as incorporated
in Collections; and,
d. to Distribute and Publicly Perform Adaptations.
e. For the avoidance of doubt:
.
i. Non-waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme cannot be waived, the Licensor
reserves the exclusive right to collect such royalties for any
exercise by You of the rights granted under this License;
ii. Waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme can be waived, the Licensor waives the
exclusive right to collect such royalties for any exercise by You
of the rights granted under this License; and,
iii. Voluntary License Schemes. The Licensor waives the right to
collect royalties, whether individually or, in the event that the
Licensor is a member of a collecting society that administers
voluntary licensing schemes, via that society, from any exercise
by You of the rights granted under this License.
.
The above rights may be exercised in all media and formats whether now
known or hereafter devised. The above rights include the right to make
such modifications as are technically necessary to exercise the rights in
other media and formats. Subject to Section 8(f), all rights not expressly
granted by Licensor are hereby reserved.
.
4. Restrictions. The license granted in Section 3 above is expressly made
subject to and limited by the following restrictions:
.
a. You may Distribute or Publicly Perform the Work only under the terms
of this License. You must include a copy of, or the Uniform Resource
Identifier (URI) for, this License with every copy of the Work You
Distribute or Publicly Perform. You may not offer or impose any terms
on the Work that restrict the terms of this License or the ability of
the recipient of the Work to exercise the rights granted to that
recipient under the terms of the License. You may not sublicense the
Work. You must keep intact all notices that refer to this License and
to the disclaimer of warranties with every copy of the Work You
Distribute or Publicly Perform. When You Distribute or Publicly
Perform the Work, You may not impose any effective technological
measures on the Work that restrict the ability of a recipient of the
Work from You to exercise the rights granted to that recipient under
the terms of the License. This Section 4(a) applies to the Work as
incorporated in a Collection, but this does not require the Collection
apart from the Work itself to be made subject to the terms of this
License. If You create a Collection, upon notice from any Licensor You
must, to the extent practicable, remove from the Collection any credit
as required by Section 4(b), as requested. If You create an
Adaptation, upon notice from any Licensor You must, to the extent
practicable, remove from the Adaptation any credit as required by
Section 4(b), as requested.
b. If You Distribute, or Publicly Perform the Work or any Adaptations or
Collections, You must, unless a request has been made pursuant to
Section 4(a), keep intact all copyright notices for the Work and
provide, reasonable to the medium or means You are utilizing: (i) the
name of the Original Author (or pseudonym, if applicable) if supplied,
and/or if the Original Author and/or Licensor designate another party
or parties (e.g., a sponsor institute, publishing entity, journal) for
attribution ("Attribution Parties") in Licensor's copyright notice,
terms of service or by other reasonable means, the name of such party
or parties; (ii) the title of the Work if supplied; (iii) to the
extent reasonably practicable, the URI, if any, that Licensor
specifies to be associated with the Work, unless such URI does not
refer to the copyright notice or licensing information for the Work;
and (iv) , consistent with Section 3(b), in the case of an Adaptation,
a credit identifying the use of the Work in the Adaptation (e.g.,
"French translation of the Work by Original Author," or "Screenplay
based on original Work by Original Author"). The credit required by
this Section 4 (b) may be implemented in any reasonable manner;
provided, however, that in the case of a Adaptation or Collection, at
a minimum such credit will appear, if a credit for all contributing
authors of the Adaptation or Collection appears, then as part of these
credits and in a manner at least as prominent as the credits for the
other contributing authors. For the avoidance of doubt, You may only
use the credit required by this Section for the purpose of attribution
in the manner set out above and, by exercising Your rights under this
License, You may not implicitly or explicitly assert or imply any
connection with, sponsorship or endorsement by the Original Author,
Licensor and/or Attribution Parties, as appropriate, of You or Your
use of the Work, without the separate, express prior written
permission of the Original Author, Licensor and/or Attribution
Parties.
c. Except as otherwise agreed in writing by the Licensor or as may be
otherwise permitted by applicable law, if You Reproduce, Distribute or
Publicly Perform the Work either by itself or as part of any
Adaptations or Collections, You must not distort, mutilate, modify or
take other derogatory action in relation to the Work which would be
prejudicial to the Original Author's honor or reputation. Licensor
agrees that in those jurisdictions (e.g. Japan), in which any exercise
of the right granted in Section 3(b) of this License (the right to
make Adaptations) would be deemed to be a distortion, mutilation,
modification or other derogatory action prejudicial to the Original
Author's honor and reputation, the Licensor will waive or not assert,
as appropriate, this Section, to the fullest extent permitted by the
applicable national law, to enable You to reasonably exercise Your
right under Section 3(b) of this License (right to make Adaptations)
but not otherwise.
.
5. Representations, Warranties and Disclaimer
.
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR
OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY
KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE,
INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY,
FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF
LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS,
WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION
OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
.
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE
LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR
ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES
ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
.
7. Termination
.
a. This License and the rights granted hereunder will terminate
automatically upon any breach by You of the terms of this License.
Individuals or entities who have received Adaptations or Collections
from You under this License, however, will not have their licenses
terminated provided such individuals or entities remain in full
compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will
survive any termination of this License.
b. Subject to the above terms and conditions, the license granted here is
perpetual (for the duration of the applicable copyright in the Work).
Notwithstanding the above, Licensor reserves the right to release the
Work under different license terms or to stop distributing the Work at
any time; provided, however that any such election will not serve to
withdraw this License (or any other license that has been, or is
required to be, granted under the terms of this License), and this
License will continue in full force and effect unless terminated as
stated above.
.
8. Miscellaneous
.
a. Each time You Distribute or Publicly Perform the Work or a Collection,
the Licensor offers to the recipient a license to the Work on the same
terms and conditions as the license granted to You under this License.
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor
offers to the recipient a license to the original Work on the same
terms and conditions as the license granted to You under this License.
c. If any provision of this License is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this License, and without further action
by the parties to this agreement, such provision shall be reformed to
the minimum extent necessary to make such provision valid and
enforceable.
d. No term or provision of this License shall be deemed waived and no
breach consented to unless such waiver or consent shall be in writing
and signed by the party to be charged with such waiver or consent.
e. This License constitutes the entire agreement between the parties with
respect to the Work licensed here. There are no understandings,
agreements or representations with respect to the Work not specified
here. Licensor shall not be bound by any additional provisions that
may appear in any communication from You. This License may not be
modified without the mutual written agreement of the Licensor and You.
f. The rights granted under, and the subject matter referenced, in this
License were drafted utilizing the terminology of the Berne Convention
for the Protection of Literary and Artistic Works (as amended on
September 28, 1979), the Rome Convention of 1961, the WIPO Copyright
Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996
and the Universal Copyright Convention (as revised on July 24, 1971).
These rights and subject matter take effect in the relevant
jurisdiction in which the License terms are sought to be enforced
according to the corresponding provisions of the implementation of
those treaty provisions in the applicable national law. If the
standard suite of rights granted under applicable copyright law
includes additional rights not granted under this License, such
additional rights are deemed to be included in the License; this
License is not intended to restrict the license of any rights under
applicable law.
.
Creative Commons Notice
.
Creative Commons is not a party to this License, and makes no warranty
whatsoever in connection with the Work. Creative Commons will not be
liable to You or any party on any legal theory for any damages
whatsoever, including without limitation any general, special,
incidental or consequential damages arising in connection to this
license. Notwithstanding the foregoing two (2) sentences, if Creative
Commons has expressly identified itself as the Licensor hereunder, it
shall have all rights and obligations of Licensor.
.
Except for the limited purpose of indicating to the public that the
Work is licensed under the CCPL, Creative Commons does not authorize
the use by either party of the trademark "Creative Commons" or any
related trademark or logo of Creative Commons without the prior
written consent of Creative Commons. Any permitted use will be in
compliance with Creative Commons' then-current trademark usage
guidelines, as may be published on its website or otherwise made
available upon request from time to time. For the avoidance of doubt,
this trademark restriction does not form part of this License.
.
Creative Commons may be contacted at https://creativecommons.org/.
License: GPL-2.0-only
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as published
by the Free Software Foundation.
.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
.
You should have received a copy of the GNU General Public License with
your Debian GNU system, in /usr/share/common-licenses/GPL-2, or with the
Debian GNU mawk source package as the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
License: X11
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
.
Except as contained in this notice, the name of the X Consortium shall not
be used in advertising or otherwise to promote the sale, use or other deal-
ings in this Software without prior written authorization from the X Consor-
tium.
@@ -0,0 +1,27 @@
#!/usr/bin/mawk -f
# $MawkId: ct_length.awk,v 1.3 2020/09/19 14:49:10 tom Exp $
# ct_length.awk
#
# replaces all length
# by length($0)
{
while ( ( i = index($0, "length") ) > 0 )
{
printf "%s" , substr($0,1, i+5) # ...length
$0 = substr($0,i+6)
if ( match($0, /^[ \t]*\(/) )
{
# its OK
printf "%s", substr($0, 1, RLENGTH)
$0 = substr($0, RLENGTH+1)
}
else # length alone
printf "($0)"
}
print
}
+136
View File
@@ -0,0 +1,136 @@
#!/usr/bin/awk -f
# $MawkId: decl.awk,v 1.12 2020/09/19 13:46:31 tom Exp $
# parse a C declaration by recursive descent
# based on a C program in K&R ANSI edition
#
# run on a C file it finds the declarations
#
# restrictions: one declaration per line
# doesn't understand struct {...}
# makes assumptions about type names
#
#
# some awks need double escapes on strings used as
# regular expressions. If not run on mawk, use gdecl.awk
################################################
# lexical scanner -- gobble()
# input : string s -- treated as a regular expression
# gobble eats SPACE, then eats longest match of s off front
# of global variable line.
# Cuts the matched part off of line
function gobble(s, xg)
{
if ( length(line) > 0 ) {
sub( /^ /, "", line) # eat SPACE if any
# surround s with parenthesis to make sure ^ acts on the
# whole thing
if ( match(line, "^" "(" s ")") > 0 ) {
xg = substr(line, 1, RLENGTH)
line = (RLENGTH < length(line)) ? substr(line, RLENGTH+1) : ""
return xg
} else {
return "";
}
} else {
return "";
}
}
function ptr_to(n, xp) # print "pointer to" , n times
{ n = int(n)
if ( n <= 0 ) return ""
xp = "pointer to" ; n--
while ( n-- ) xp = xp " pointer to"
return xp
}
#recursively get a decl
# returns an english description of the declaration or
# "" if not a C declaration.
function decl( xd, t, ptr_part)
{
xd = gobble("[* ]+") # get list of *** ...
gsub(/ /, "", xd) # remove all SPACES
ptr_part = ptr_to( length(xd) )
# We expect to see either an identifier or '('
#
if ( gobble("[(]") )
{
# this is the recursive descent part
# we expect to match a declaration and closing ')'
# If not return "" to indicate failure
if ( (xd = decl()) == "" || gobble( "[)]" ) == "" ) return ""
}
else # expecting an identifier
{
if ( (xd = gobble(id)) == "" ) return ""
xd = xd ":"
}
# finally look for ()
# or [ opt_size ]
while ( 1 )
if ( gobble( funct_mark ) ) xd = xd " function returning"
else
if ( ( t = gobble( array_mark ) ) != "" )
{ gsub(/ /, "", t)
xd = xd " array" t " of"
}
else break
xd = xd " " ptr_part
return xd
}
BEGIN {
id = "[_A-Za-z][_A-Za-z0-9]*"
funct_mark = "[(][ \t]*[)]"
array_mark = "[[ \t]*[_A-Za-z0-9]*[ \t]*]"
# I've assumed types are keywords or all CAPS or end in _t
# Other conventions could be added.
type0 = "int|char|short|long|double|float|void"
type1 = "[_A-Z][_A-Z0-9]*" # types are CAPS
type2 = "[_A-Za-z][_A-Za-z0-9]*_t" # end in _t
types = "(" type0 "|" type1 "|" type2 ")"
}
{
gsub( "/[*]([^*]|[*][^/])*([*]/|$)" , " ") # remove comments
gsub( /[ \t]+/, " ") # squeeze white space to a single space
line = $0
scope = gobble( "extern|static" )
if ( ( type = gobble("(struct|union|enum) ") ) != "" )
type = type gobble(id) # get the tag
else
{
type = gobble("(un)?signed ") gobble( types )
}
if ( ! type ) next
if ( (x = decl()) != "" && gobble( ";") )
{
x = x " " type
if ( scope ) x = x " (" scope ")"
gsub( / +/, " ", x) #
print x
}
}
+66
View File
@@ -0,0 +1,66 @@
#!/usr/bin/mawk -f
# $MawkId: deps.awk,v 1.4 2023/10/31 22:58:49 tom Exp $
# vile: notab ts=4 sw=4
# find include dependencies in C source
#
# mawk -f deps.awk C_source_files
# -- prints a dependency list suitable for make
BEGIN {
stack_index = 0 # stack[] holds the input files
for(i = 1 ; i < ARGC ; i++)
{
file = ARGV[i]
if ( file !~ /\.[cC]$/ ) continue # skip it
outfile = substr(file, 1, length(file)-2) ".o"
# INCLUDED[] stores the set of included files
# -- start with the empty set
for( j in INCLUDED ) delete INCLUDED[j]
while ( 1 )
{
if ( getline line < file <= 0 ) # no open or EOF
{
if ( stack_index == 0 ) break # empty stack
else
{
file = stack[ stack_index-- ]
continue
}
}
if ( line ~ /^#include[ \t]+".*"/ )
split(line, X, "\"") # filename is in X[2]
else if ( line ~ /^#include[ \t]+<.*>/ )
split(line, X, "[<>]") # filename is in X[2]
else
continue;
if ( X[2] in INCLUDED ) # we've already included it
continue
if ( getline line < X[2] <= 0 ) # no open or EOF
continue;
#push current file
stack[ ++stack_index ] = file
INCLUDED[ file = X[2] ] = ""
} # end of while
# test if INCLUDED is empty
flag = 0 # on once the front is printed
for( j in INCLUDED )
{
if ( ! flag )
{ printf "%s : %s" , outfile, j ; flag = 1 }
else printf " %s" , j
close(j);
}
if ( flag ) print ""
}# end of loop over files in ARGV[i]
}
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/mawk -f
# $MawkId: eatc.awk,v 1.3 2020/09/19 11:51:23 tom Exp $
# eatc.awk
# another program to remove comments
{ while( ( t = index($0 , "/*") ) > 0 )
{
if ( t > 1 )
printf "%s" , substr($0,1,t-1)
$0 = eat_comment( ( t + 2 <= length($0) ) ? substr($0, t+2) : "" )
}
print
}
function eat_comment(s, t2)
{
#replace comment by one space
printf " "
while ( (t2 = index(s, "*/")) == 0 )
if ( getline s == 0 )
{ # input error -- unterminated comment
system("/bin/sh -c 'echo unterminated comment' 1>&2")
exit 1
}
return ( t2 + 2 <= length(s) ) ? substr(s,t2+2) : ""
}
+127
View File
@@ -0,0 +1,127 @@
#!/usr/bin/mawk -f
# $MawkId: gdecl.awk,v 1.6 2020/09/19 14:04:25 tom Exp $
# parse a C declaration by recursive descent
#
# decl.awk with extra escapes \
################################################
############################################
# lexical scanner -- gobble()
# input : string s -- treated as a regular expression
# gobble eats SPACE, then eats longest match of s off front
# of global variable line.
# Cuts the matched part off of line
function gobble(s, xg)
{
sub( /^ /, "", line) # eat SPACE if any
# surround s with parenthesis to make sure ^ acts on the
# whole thing
if ( match(line, "^" "(" s ")") > 0 ) {
xg = substr(line, 1, RLENGTH)
line = (RLENGTH < length(line)) ? substr(line, RLENGTH+1) : ""
return xg
} else {
return ""
}
}
function ptr_to(n, xp) # print "pointer to" , n times
{ n = int(n)
if ( n <= 0 ) return ""
xp = "pointer to" ; n--
while ( n-- ) xp = xp " pointer to"
return xp
}
#recursively get a decl
# returns an english description of the declaration or
# "" if not a C declaration.
function decl( xd, t, ptr_part)
{
xd = gobble("[* ]+") # get list of *** ...
gsub(/ /, "", xd) # remove all SPACES
ptr_part = ptr_to( length(xd) )
# We expect to see either an identifier or '('
if ( gobble("\\(") )
{
# this is the recursive descent part
# we expect to match a declaration and closing ')'
# If not return "" to indicate failure
if ( (xd = decl()) == "" || gobble( "\\)" ) == "" ) return ""
}
else # expecting an identifier
{
if ( (xd = gobble(id)) == "" ) return ""
xd = xd ":"
}
# finally look for ()
# or [ opt_size ]
while ( 1 )
if ( gobble( funct_mark ) ) xd = xd " function returning"
else
if ( ( t = gobble( array_mark ) ) != "" )
{ gsub(/ /, "", t)
xd = xd " array" t " of"
}
else break
xd = xd " " ptr_part
return xd
}
BEGIN { id = "[_A-Za-z][_A-Za-z0-9]*"
funct_mark = "\\([ \t]*\\)"
array_mark = "\\[[ \t]*[_A-Za-z0-9]*[ \t]*\\]"
# I've assumed types are keywords or all CAPS or end in _t
# Other conventions could be added.
type0 = "int|char|short|long|double|float|void"
type1 = "[_A-Z][_A-Z0-9]*" # types are CAPS
type2 = "[_A-Za-z][_A-Za-z0-9]*_t" # end in _t
types = "(" type0 "|" type1 "|" type2 ")"
}
{
gsub( /\/\*([^*]|\*[^\/])*(\*\/|$)/ , " ") # remove comments
gsub( /[ \t]+/, " ") # squeeze white space to a single space
line = $0
scope = gobble( "extern|static" )
if ( ( type = gobble("(struct|union|enum) ") ) != "" )
{
type = type gobble(id) # get the tag
}
else
{
type = gobble("(un)?signed ") gobble( types )
}
if ( ! type ) next
if ( ( (x = decl()) != "" ) && gobble( ";") )
{
x = x " " type
if ( scope ) x = x " (" scope ")"
gsub( / +/, " ", x) #
print x
}
}
+423
View File
@@ -0,0 +1,423 @@
#!/usr/bin/mawk -We
# $MawkId: hcal,v 1.6 2020/09/24 22:05:19 tom Exp $
# vile:ts=4 sw=4
# edit the above to be the full pathname of 'mawk'
# @(#) hcal - v01.00.02 - Tue Feb 27 21:21:21 EST 1996
# @(#) prints a 3-month (highlighted) calendar centered on the target month
# @(#) may be edited for week to start with Sun or Mon & for local language
# @(#) to display a usage screen, execute: hcal -h
# NOTE: to edit, set ts=4 in 'vi' (or equivalent)
# to print, pipe through 'pr -t -e4'
# Using ideas from a KornShell script by Mikhail Kuperblum (mikhail@klm.com)
# Bob Stockler - bob@trebor.iglou.com - Sysop CompuServe SCOForum [75162,1612]
BEGIN {
# Local Edits:
PROG = "hcal" # Program name given to this script
# FMT = 0 # date format dd/mm/yyyy
# FMT1 = 0 # for weekdays ordered "Mo Tu We Th Fr Sa Su"
FMT = 1 # date format mm/dd/yyyy
FMT1 = 1 # for weekdays ordered "Su Mo Tu We Th Fr Sa"
# edit day & month names and abbreviations for local language names
Days[0] = "Mo Tu We Th Fr Sa Su"
Days[1] = "Su Mo Tu We Th Fr Sa"
MONTHS = "January February March April May June July August"
MONTHS = MONTHS " September October November December"
Months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
# STDOUT = 0 # emulate SCO Unix 'cal' (NO highlighting)
STDOUT = 1 # default to highlight mode
MINUS = "-" # possible input date field delimiter
SLASH = "/" # possible input date field delimiter
DOT = "." # possible input date field delimiter
IDFD = "[" MINUS # make MINUS the first character in this series
IDFD = IDFD SLASH # so that it stands for itself in the RE
IDFD = IDFD DOT "]" # Input Date Field Delimiters RE
ODFD = SLASH # Output Date Field Delimiter (default)
DATE_FMT = "%.2d%s%.2d%s%.4d" # date format
## this script presumes 'date' recognizes these arguments in these ways:
## w - Day of the week - Sunday = 0
## m - Month of year - 01 to 12
## d - Day of month - 01 to 31
## y Last 2 digits of year - 00 to 99
## Y - Year (including century), as decimal numbers
## j - Day of the year - 001 to 366 (Julian date)
## T - Time as HH:MM:SS
## X Current time, as defined by the locale
## a - Abbreviated weekday - Sun to Sat
## b - Abbreviated month name
## Z - Timezone name, or no characters if no timezone exists
## Command to get today's date information:
## DATE = "/bin/date '+%w %m %d 19%y %j~%a %b %d %T %Z 19%y'"
## For sunos4
## DATE = DATE = "/bin/date '+%w %m %d 19%y %j~%a %h %d %T 19%y'"
DATE = "/bin/date '+%w %m %d %Y %j~%a %b %d %X %Z %Y'"
# End of Local Edits
INT_RE = "^[0-9]+$" # unsigned integer RE
S_INT_RE = "^[-+][0-9]+$" # signed integer RE
MNAM_RE = "^[A-Za-z]+$" # month name RE
YEAR_RE = "^[0-9]?[0-9]?[0-9]?[0-9]$"
DATE_RE = "^[0-9]?[0-9]" IDFD "[0-9]?[0-9]" IDFD "[0-9]?[0-9]?[0-9]?[0-9]$"
DAT1_RE = "^[0-9]?[0-9]" IDFD "[0-9]?[0-9]$"
split(Months,M_Name)
split("31 28 31 30 31 30 31 31 30 31 30 31",Mdays) ; Mdays[0] = 0
ERR = 0
HELP = 0
RMSO = 0
NUM_ARGS = ARGC - 1
if ( ARGV[1] == "-x" ) {
# standout mode switch
if ( STDOUT == 1 ) STDOUT = 0 ; else STDOUT = 1
ARG1 = ARGV[2] ; ARG2 = ARGV[3] ; NUM_ARGS -= 1
}
else if ( ARGV[1] ~ /^-[h?]$/ ) { HELP = 1 ; exit }
else { ARG1 = ARGV[1] ; ARG2 = ARGV[2] }
if ( STDOUT == 1 ) {
# get the terminal standout-start & standout-end control codes
so = ENVIRON["so"] ; if ( ! so ) "tput smso" | getline so
se = ENVIRON["se"] ; if ( ! se ) "tput rmso" | getline se
}
if ( NUM_ARGS == 0 ) {
# no arguments - print a calendar display centered on today
DEFAULT = 1
}
else if ( NUM_ARGS == 1 ) {
# one argument - may be a month name, date, year, or interval of days
if ( ARG1 ~ DATE_RE ) DATE1 = Fmt_Date(ARG1)
else if ( ARG1 ~ DAT1_RE ) DATE1 = ARG1
else if ( ARG1 ~ MNAM_RE ) { Get_Mnum() ; DATE1 = RMSO = ARG1 "/1" }
else if ( ARG1 ~ S_INT_RE ) INTERVAL = ARG1 + 0
else if ( ARG1 ~ INT_RE ) {
if ( ARG1 > 0 && ARG1 <= 9999 ) YEAR = ARG1 + 0
else if ( ARG1 > 9999 ) { ERR = 9 ; exit }
else { ERR = 7 ; exit }
}
else { ERR = 1 ; exit }
}
else if ( NUM_ARGS == 2 ) {
# two arguments, the second of which must be an integer
if ( ARG2 ~ INT_RE ) {
ARG2 = ARG2 + 0
if ( ARG2 < 1 ) { ERR = 7 ; exit }
else if ( ARG2 > 9999 ) { ERR = 9 ; exit }
}
else { ERR = 1 ; exit }
RMSO = 1
# the first may be a string or an integer
if ( ARG1 ~ INT_RE ) {
# a month number and a year
if ( ARG1 < 1 || ARG1 > 12 ) { ERR = 4 ; mm = ARG1 ; exit }
}
else if ( ARG1 ~ MNAM_RE ) {
Get_Mnum()
}
else { ERR = 6 ; exit }
DATE1 = ARG1 "/1/" ARG2
}
else { ERR = 2 ; exit }
if ( DEFAULT ) { Get_Now() }
else if ( INTERVAL ) {
Get_Now()
daynum = daynum + ( INTERVAL % 7 )
this_date = ""
DATE1 = Get_Date(INTERVAL,m,d,y,j)
split(DATE1,mdy,IDFD)
Mon[2] = mdy[1] + 0
today = mdy[2] + 0
Year[1] = Year[2] = Year[3] = mdy[3] + 0
}
else if ( DATE1 ) {
Get_Now()
if ( split(DATE1,mdy,IDFD) == 2 ) DATE1 = DATE1 "/" This_Year
Chk_Date(DATE1)
Mon[2] = mdy[1] + 0
today = mdy[2] + 0
Year[1] = Year[2] = Year[3] = mdy[3] + 0
DATE1 = sprintf( "%.2d/%.2d/%.4d", Mon[2], today, Year[2] )
INTERVAL = Get_Num(DATE1,m,d,y,j)
daynum = daynum + ( INTERVAL % 7 )
this_date = ""
}
else if ( YEAR ) {
so = se = ""
Get_Now()
Mon[2] = 2
today = 1
Year[1] = Year[2] = Year[3] = YEAR
DATE1 = sprintf( "%.2d/%.2d/%.4d", Mon[2], today, Year[2] )
INTERVAL = Get_Num(DATE1,m,d,y,j)
daynum = daynum + ( INTERVAL % 7 )
this_date = ""
}
else { ERR = 5 ; exit }
if ( Mon[2] != 1 ) Mon[1] = Mon[2] - 1
else { Mon[1] = 12 ; Year[1] -= 1 }
if ( Mon[2] != 12 ) Mon[3] = Mon[2] + 1
else { Mon[3] = 1 ; Year[3] += 1 }
if ( Mon[1] == 2 ) Leap(Year[1])
else if ( Mon[2] == 2 ) Leap(Year[2])
else if ( Mon[3] == 2 ) Leap(Year[3])
Start[2] = 7 - ( ( today - daynum ) % 7 )
Start[1] = 7 - ( ( Mdays[Mon[1]] - Start[2] ) % 7 )
Start[3] = ( Mdays[Mon[2]] + Start[2] ) % 7
if ( ! YEAR ) quarters = 1
else {
quarters = 4 ; s[3] = Start[3]
for (i=4;i<=12;i++) { s[i] = ( Mdays[i-1] + s[i-1] ) % 7 }
}
ll = 0
for ( quarter = 1 ; quarter <= quarters ; quarter++ ) {
if ( quarter > 1 ) {
delete cal
ll = 0 ; Mon[1] += 3 ; Mon[2] += 3 ; Mon[3] += 3
Start[1] = s[Mon[1]] ; Start[2] = s[Mon[2]] ; Start[3] = s[Mon[3]]
}
if ( Year[2] == 1752 && Mon[2] ~ /8|9|10/ ) Kludge_1752()
if ( ARG1 ) print "" ; else printf( "\n%s\n\n", this_date )
for (i=1;i<=3;i++) { while ( Start[i] >= 7 ) Start[i] -= 7 }
for (mm=1;mm<=3;mm++) { l = 1
if ( mm != 2 ) { So = Se = "" } else { So = so ; Se = se }
cal[mm SUBSEP l++] = sprintf( "%s %-4s%.4d %s ", \
So, M_Name[Mon[mm]], Year[mm], Se )
cal[mm SUBSEP l++] = sprintf( "%s%3s", Days[FMT1], "" )
j = k = 1
while ( j <= Mdays[Mon[mm]] ) {
line = ""
for (i=1;i<=7;i++) {
if ( Start[mm] > 0 || j > Mdays[Mon[mm]] ) {
date = "" ; Start[mm]-- }
else date = j++
if ( Year[mm] == 1752 && Mon[mm] == 9 && date == 3 ) {
date = 14 ; j = 15 }
if ( date == today && mm == 2 && ! RMSO ) {
So = so ; Se = se }
else { So = Se = "" }
line = sprintf( "%s%s%2s%s ", line, So, date, Se )
}
cal[mm SUBSEP l++] = sprintf( "%s ", line )
}
if ( l > ll ) ll = l
}
for (l=1;l<ll;l++) {
for (mm=1;mm<=3;mm++) {
if ( cal[mm SUBSEP l] != "" ) printf( cal[mm SUBSEP l] )
else printf( "%23s", "" )
if ( mm % 3 == 0 ) print ""
}
}
}
print ""
exit 0
}
END {
if ( ! HELP && ! ERR ) exit 0
if ( ERR ) {
for (i=1;i<ARGC;i++) { ARGS = ARGS sp ARGV[i] ; sp = " " }
if ( ERR == 1 ) msg = "Bad argument format or content:"
else if ( ERR == 2 ) msg = "Wrong argument count (" ARGC - 1 "):"
else if ( ERR == 3 ) msg = "Date before 01/01/0001 (" Get_Y1() "):"
else if ( ERR == 4 ) msg = "Bad month (" mm "):"
else if ( ERR == 5 ) msg = "Bad date (" dd "):"
else if ( ERR == 6 ) msg = "Impossible date:"
else if ( ERR == 7 ) msg = "The was no year 0000:"
else if ( ERR == 8 ) msg = "Non-unique month name (" ARG1 "):"
else if ( ERR == 9 ) msg = "Year greater than 9999:"
else msg = "Unknown error:"
HELP = 1 ; q = "\""
}
if ( HELP ) {
if ( FMT == 1 ) { fmt = "[m]m/[d]d[/yyyy]" ; range = "12/31/9999" }
else { fmt = "[d]d/[m]m[/yyyy]" ; range = "31/12/9999" }
if ( STDOUT == 0 ) n = " not " ; else n = " " ; sp = " "
u= "\n Usage: " PROG " [-x] [args]\n\n" sp
u=u "Prints a 3-month calendar centered on the target month.\n\n" sp
u=u "The default is" n "to highlight the target month (and date if\n" sp
u=u "appropriate); -x switches the default highlight behavior.\n" sp
u=u "With no arguments the target date defaults to today.\n\n" sp
u=u "Arguments may be a date in " fmt " format (where\n" sp
u=u "leading 0's are implied in all unfilled fields, defaulting\n" sp
u=u "to the current year if that field is omitted); a month and\n" sp
u=u "year (where month may be an integer or a month name, perhaps\n" sp
u=u "abbreviated, but sufficient to be unique); or the month name\n" sp
u=u "alone (which defaults to the current year); or a year alone\n" sp
u=u "(which prints a 12-month calendar for that year).\n\n" sp
u=u "A signed integer alone as an argument specifies the target\n" sp
u=u "date to be -n days before or +n days after the current date.\n\n" sp
u=u "Dates from 01/01/0001 to " range " are supported.\n"
usage = u
}
printf( "\n%s: %s %s%s%s\n", PROG, msg, q, ARGS, q ) >"/dev/tty"
print usage >"/dev/tty"
exit ERR
}
function Get_Now() {
# get the week, month, date & year numbers and the time-of-day
DATE | getline date
split(date,Date,"~")
split(Date[1],field)
daynum = field[1] + FMT1
m = field[2] ; This_Mon = Mon[2] = m + 0
d = field[3] ; This_Date = today = d + 0
y = This_Year = Year[1] = Year[2] = Year[3] = field[4]
j = julian = field[5] + 0
this_date = Date[2]
}
function Fmt_Date(fmt_date) {
# format dates as mm/dd/yyyy or dd/mm/yyyy
split(fmt_date,MorD_DorM_Y,IDFD)
if ( FMT == 1 ) { Dt_Fld1 = MorD_DorM_Y[1] ; Dt_Fld2 = MorD_DorM_Y[2] }
else { Dt_Fld1 = MorD_DorM_Y[2] ; Dt_Fld2 = MorD_DorM_Y[1] }
Dt_Fld3 = MorD_DorM_Y[3]
return sprintf( DATE_FMT, Dt_Fld1, ODFD, Dt_Fld2, ODFD, Dt_Fld3 )
}
function Kludge_1752() {
# kludge for September 1752 & the change to the Gregorian Calendar
Mdays[9] = 30
if ( Mon[2] == 9 ) {
Start[1] = Start[2] = 1 + FMT1 ; Start[3] = -1 + FMT1
}
else if ( Mon[2] == 8 ) {
Start[1] = 2 + FMT1 ; Start[2] = 5 + FMT1 ; Start[3] = 1 + FMT1
}
else if ( Mon[2] == 10 ) {
Start[1] = 1 + FMT1 ; Start[2] = -1 + FMT1 ; Start[3] = 3
}
}
function Get_Mnum() {
ARG1 = tolower(ARG1)
months = tolower(MONTHS)
split(months,month)
for (i=1;i<=12;i++) {
if ( index(month[i],ARG1) == 1 ) { ARG = i ; n++ }
}
if ( n == 1 ) ARG1 = ARG
else if ( n == 0 ) { ERR = 1 ; exit }
else { ERR = 8 ; exit }
}
function Get_Num(get_date,get_m,get_d,get_y,get_j) {
# get the number of days from one date to another date
NOW = get_y get_m get_d ; N = 0 ; M = get_m + 0 ; D = get_d + 0 ; Y = get_y + 0 ; J = get_j + 0
split(get_date,mdy,IDFD)
M2 = mdy[1] ; D2 = mdy[2] ; Y2 = mdy[3]
THEN = Y2 M2 D2 ; M2 = M2 + 0 ; D2 = D2 + 0 ; Y2 = Y2 + 0
Leap(Y2)
if ( M2 > 12 ) { ERR = 4 ; exit }
if ( D2 > Mdays[M2] && Y2 != 1752 && M2 != 9 ) { ERR = 5 ; exit }
if ( THEN ~ /^1752090[3-9]$|^1752091[0-3]$/ ) { ERR = 6 ; exit }
Leap(Y)
if ( THEN > NOW ) {
Ydays = Ydays - J + 1 ; mdays = Mdays[M] - D + 1
while ( Y < Y2 ) Next_Y()
while ( M < M2 ) Next_M()
while ( D < D2 ) Next_D()
N *= -1
}
else {
Ydays = J ; mdays = D
while ( Y > Y2 ) Prev_Y()
while ( M > M2 ) Prev_M()
if ( Y == 1752 && M == 9 && D == 19 ) D = 30
while ( D > D2 ) Prev_D()
}
return N
}
function Get_Date(get_n,get_m,get_d,get_y,get_j) {
# get the date a number of days before or after a date
N = get_n + 0 ; M = get_m + 0 ; D = get_d + 0 ; Y = get_y + 0 ; J = get_j + 0
if ( N != 0 ) {
Leap(Y)
if ( N > 0 ) {
Ydays = Ydays - J + 1 ; mdays = Mdays[M] - D + 1
while ( N >= Ydays ) { Next_Y() ; Leap(Y) }
while ( N >= ( ( mdays > 0 ) ? mdays : Mdays[M] ) ) { Next_M() }
while ( N > 0 ) Next_D()
}
else {
Ydays = J ; mdays = D ; N *= -1
while ( N >= Ydays ) { Prev_Y() ; Leap(Y) }
while ( N >= ( ( mdays > 0 ) ? mdays : Mdays[M] ) ) { Prev_M() }
if ( Y == 1752 && M == 9 && D == 19 ) D = 30
while ( N > 0 ) Prev_D()
}
if ( Y < 1 ) { ERR = 3 ; exit }
}
return M ODFD D ODFD Y
}
function Leap(YR) {
# adjust for Leap Years
if ( YR % 4 == 0 && ( YR % 100 != 0 || YR % 400 == 0 || YR < 1800 ) ) {
Ydays = 366 ; Mdays[2] = 29 }
else { Ydays = 365 ; Mdays[2] = 28 }
if ( YR != 1752 ) Mdays[9] = 30
else { Ydays = 355 ; Mdays[9] = 19 }
}
function Chk_Date(chk_date) {
# check validity of input dates
split(chk_date,mdy,IDFD)
mm = mdy[1] + 0 ; dd = mdy[2] + 0 ; yy = mdy[3] + 0
if ( mm == 2 ) Leap(yy)
if ( yy < 1 ) { ERR = 3 ; exit }
if ( mm < 1 || mm > 12 ) { ERR = 4 ; exit }
if ( dd < 1 || dd > Mdays[mm] ) { ERR = 5 ; exit }
}
# day counting functions for next or previous year, month and day
function Next_Y() {
N -= Ydays ; Y += 1 ; M = 1 ; D = 1 ; mdays = 0 ; Leap(Y)
}
function Next_M() {
if ( mdays != 0 ) N -= mdays ; else N -= Mdays[M]
M += 1 ; D = 1 ; mdays = 0
}
function Next_D() {
N -= 1 ; D += 1
if ( D > Mdays[M] ) { M += 1 ; D = 1 }
else if ( Y == 1752 && M == 9 && D == 2 ) D = 13
}
function Prev_Y() {
N -= Ydays ; Y -= 1 ; M = 12 ; D = 31 ; mdays = 0 ; Leap(Y)
}
function Prev_M() {
if ( mdays != 0 ) N -= mdays ; else N -= Mdays[M]
M -= 1 ; D = Mdays[M] ; mdays = 0
}
function Prev_D() {
N -= 1 ; D -= 1 ; if ( Y == 1752 && M == 9 && D == 13 ) D = 2
}
function Get_J(get_m,get_d,get_y) {
# get the Julian date for an input date
get_m = get_m + 0 ; get_d = get_d + 0 ; get_y = get_y + 0
Leap(get_y)
j = get_d
for (i=1;i<get_m;i++) j = j + Mdays[i]
return j
}
function Get_Y1() {
# get the number of days to day 1 for the help screen
if ( ! m ) {
if ( mm ) { m = mm ; d = dd ; y = yy }
else if ( M ) { m = M ; d = D ; y = Y }
}
if ( ! j ) Get_J()
return Get_Num("01/01/0001",m,d,y,j)
}
+77
View File
@@ -0,0 +1,77 @@
#!/bin/sh
# $MawkId: hical,v 1.4 2009/08/21 00:36:34 tom Exp $
# @(#) hical - displays previous, current & next months - today highlighted
# @(#) an "internationalizationable" version of a 3-month 'cal' display, it
# @(#) may be edited for week to start with Sun or Mon & for local language
prog=${TMPDIR-/tmp}/hical.$$ ; trap 'rm -f $prog ; trap 0 ; exit' 0 1 2 3 15
: ${so:=`tput smso`} ${se:=`tput rmso`}
# USER EDITS MAY BE REQUIRED for the arguments to the 'date' command
# the script presumes 'date' recognizes these arguments in these ways:
# w - Day of the week - Sunday = 0
# m - Month of year - 01 to 12
# d - Day of month - 01 to 31
# T - Time as HH:MM:SS
# Y - Year (including century), as decimal numbers
DATE_ARGS='%w %m %d %T %Y'
# the 'awk' program file is written to a temporary file to avoid any
# "arg list too long" error messages, yet have all the code in one file.
cat >$prog <<'EOF'
{
# USER EDITS MAY BE REQUIRED (for FMT, day & month names, and the time stuff)
# FMT = 0 # for weekdays ordered "Mo Tu We Th Fr Sa Su"
FMT = 1 # for weekdays ordered "Su Mo Tu We Th Fr Sa"
Header[0] = "Mo Tu We Th Fr Sa Su"
Header[1] = "Su Mo Tu We Th Fr Sa"
months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
time_is = "The time is:" ; time_fmt = "%s %s %s %s\n"
# NO MORE USER EDITS REQUIRED (I think!)
split(months,M_Name) ; split("31 28 31 30 31 30 31 31 30 31 30 31",M_Len)
daynum = $1 + FMT
Mon[2] = $2 + 0
today = $3 + 0
time = $4
Year[1] = Year[2] = Year[3] = $NF
if ( Mon[2] == 1 ) { Year[1] = Year[1] - 1 ; Mon[1] = 12 }
else { Mon[1] = Mon[2] - 1 }
if ( Mon[2] == 12 ) { Year[3] = Year[3] + 1 ; Mon[3] = 1 }
else { Mon[3] = Mon[2] + 1 }
if ( Year[2] % 4 == 0 &&
Year[2] % 100 != 0 ||
Year[2] % 400 == 0 ) M_Len[2] = 29
Start[2] = 7 - ( ( today - daynum ) % 7 )
Start[1] = 7 - ( ( M_Len[Mon[1]] - Start[2] ) % 7 )
Start[3] = ( M_Len[Mon[2]] + Start[2] ) % 7
for (i=1;i<=3;i++) { while ( Start[i] >= 7 ) Start[i] -= 7 }
for (mm=1;mm<=3;mm++) {
if ( Year[mm] != Year[mm-1] )
printf( "%s %s %s\n", so, Year[mm], se )
if ( mm == 1 ) printf( "%s %s %s\n", so, Header[FMT], se )
j = k = 1
while ( j <= M_Len[Mon[mm]] ) {
line = ""
for (i=1;i<=7;i++) {
if ( Start[mm] > 0 || j > M_Len[Mon[mm]] ) { date = "" ; Start[mm]-- }
else date = j++
if ( mm == 2 && date == today ) { So = so ; Se = se }
else { So = Se = "" }
line = sprintf( "%s%s%2s%s ", line, So, date, Se )
}
m1 = substr(M_Name[Mon[mm]],k++,1)
printf( "%s %1s %s %s%s %s\n", so, m1, se, line, so, se )
}
}
printf( time_fmt, so, time_is, time, se )
}
EOF
date +"$DATE_ARGS" | ${AWK:=mawk} -f $prog so=$so se=$se
exit 0
# EOF 'hical' - Tue Dec 19 19:19:19 EST 1994
# Bob Stockler - bob@trebor.iglou.com - CIS: 72726,452
@@ -0,0 +1,32 @@
#!/usr/bin/mawk -f
# $MawkId: nocomment.awk,v 1.3 2020/09/19 13:02:14 tom Exp $
# remove C comments from a list of files
# using a comment as the record separator
#
# this is trickier than I first thought
# The first version in .97-.9993 was wrong
BEGIN {
# RS is set to a comment (this is mildly tricky, I blew it here
RS = "/[*]([^*]|[*]+[^*/])*[*]+/"
ORS = " "
getline hold
filename = FILENAME
}
# if changing files
filename != FILENAME {
filename = FILENAME
printf "%s" , hold
hold = $0
next
}
{ # hold one record because we don't want ORS on the last
# record in each file
print hold
hold = $0
}
END { printf "%s", hold }
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/mawk -f
# primes.awk
#
# mawk -f primes.awk [START] STOP
# find all primes between 2 and STOP
# or START and STOP
#
function usage()
{ ustr = sprintf("usage: %s [start] stop", ARGV[0])
system( "echo " ustr)
exit 1
}
BEGIN { if (ARGC == 1 || ARGC > 3 ) usage()
if ( ARGC == 2 ) { start = 2 ; stop = ARGV[1]+0 }
else
if ( ARGC == 3 ) { start = ARGV[1]+0 ; stop = ARGV[2]+0 }
if ( start < 2 ) start = 2
if ( stop < start ) stop = start
prime[ p_cnt = 1 ] = 3 # keep primes in prime[]
# keep track of integer part of square root by adding
# odd integers
odd = test = 5
root = 2
squares = 9
while ( test <= stop )
{
if ( test >= squares )
{ root++
odd += 2
squares += odd
}
flag = 1
for ( i = 1 ; prime[i] <= root ; i++ )
if ( test % prime[i] == 0 ) # not prime
{ flag = 0 ; break }
if ( flag ) prime[ ++p_cnt ] = test
test += 2
}
prime[0] = 2
for( i = 0 ; prime[i] < start ; i++) ;
for ( ; i <= p_cnt ; i++ ) print prime[i]
}
+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/mawk -f
# $MawkId: qsort.awk,v 1.4 2020/09/19 14:20:45 tom Exp $
# qsort text files
function middle(x,y,z) #return middle of 3
{
if ( x <= y )
{ if ( z >= y ) return y
if ( z < x ) return x
return z
}
if ( z >= x ) return x
if ( z < y ) return y
return z
}
function isort(A , n, i, j, hold)
{
# if needed a sentinel at A[0] will be created
for( i = 2 ; i <= n ; i++)
{
hold = A[ j = i ]
while ( A[j-1] > hold )
{ j-- ; A[j+1] = A[j] }
A[j] = hold
}
}
# recursive quicksort
function qsort(A, left, right ,i , j, pivot, hold)
{
pivot = middle(A[left], A[int((left+right)/2)], A[right])
i = left
j = right
while ( i <= j )
{
while ( A[i] < pivot ) i++
while ( A[j] > pivot ) j--
if ( i <= j )
{ hold = A[i]
A[i++] = A[j]
A[j--] = hold
}
}
if ( j - left > BLOCK ) qsort(A,left,j)
if ( right - i > BLOCK ) qsort(A,i,right)
}
BEGIN { BLOCK = 5 }
{ line[NR] = $0 "" # sort as string
}
END {
if ( NR > BLOCK ) qsort(line, 1, NR)
isort(line, NR)
for(ie = 1 ; ie <= NR ; ie++) print line[ie]
}