bin/rmail
bin/rmdir
bin/sed/sed
+bin/sh/sh
bin/size
bin/strip
bin/stty
--- /dev/null
+#!/bin/sh
+#NOTE - this script does not work!
+column=$1
+awk '{print $$column}'
--- /dev/null
+#!/bin/sh
+column=$1
+awk '{print $'$column'}'
--- /dev/null
+#!/bin/sh
+column=${1:-1}
+awk '{print $'$column'}'
--- /dev/null
+#!/bin/sh
+awk '{print $'${1:-1}'}'
--- /dev/null
+#!/bin/sh
+awk '{print $c}' c=${1:-1}
--- /dev/null
+#!/bin/awk -f
+# this filter adds a carriage return to all lines
+# before the newline character
+BEGIN {
+ ORS="\r\n"
+}
+{ print }
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+# How many lines
+ lines=0;
+ total=0;
+}
+{
+# this code is executed once for each line
+# increase the number of files
+ lines++;
+# increase the total size, which is field #1
+ total+=$1;
+}
+END {
+# end, now output the total
+ print lines " lines read";
+ print "total is ", total;
+ if (lines > 0 ) {
+ print "average is ", total/lines;
+ } else {
+ print "average is 0";
+ }
+}
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+ print "type a number";
+}
+{
+ print "The square of ", $1, " is ", $1*$1;
+ print "type another number";
+}
+END {
+ print "Done"
+}
--- /dev/null
+#!/bin/awk -f
+# Linux users have to change $8 to $9
+BEGIN { print "File\tOwner" }
+ { print $8, "\t", $3}
+END { print " - DONE -" }
--- /dev/null
+#!/bin/csh -f
+# Linux users have to change $8 to $9
+awk '\
+BEGIN { print "File\tOwner" } \
+ { print $8, "\t", $3} \
+END { print " - DONE -" } \
+'
--- /dev/null
+#!/bin/sh
+# Linux users have to change $8 to $9
+awk '
+BEGIN { print "File\tOwner" }
+ { print $8, "\t", $3}
+END { print " - DONE -" }
+'
--- /dev/null
+#!/usr/bin/awk -f
+BEGIN {
+ printf("%10s %6s\n", "String", "Number");
+}
+{
+ printf("%10s %6d\n", $1, $2);
+}
--- /dev/null
+#!/usr/bin/awk -f
+BEGIN {
+ format1 ="%10s %6s\n";
+ format2 ="%10s %6d\n";
+ printf(format1, "String", "Number");
+}
+{
+ printf(format2, $1, $2);
+}
--- /dev/null
+#!/usr/bin/awk -f
+END {
+ for (i=0;i<30;i++) {
+ printf("i=%d\n", i) > "/tmp/a" i;
+ }
+}
--- /dev/null
+#!/bin/awk -f
+# demonstrate use of exp(), log() and sqrt in AWK
+# e.g. what is the difference between using logarithms and regular arithmetic
+# note - exp and log are natural log functions - not base 10
+#
+BEGIN {
+# what is the about of error that will be reported?
+ ERROR=0.000000000001;
+# loop a long while
+ for (i=1;i<=2147483647;i++) {
+# find log of i
+ logi=log(i);
+# what is square root of i?
+# divide the log by 2
+ logsquareroot=logi/2;
+# convert log of i back
+ squareroot=exp(logsquareroot);
+# find the difference between the logarithmic calculation
+# and the built in calculation
+ diff=sqrt(i)-squareroot;
+# make difference positive
+ if (diff < 0) {
+ diff*=-1;
+ }
+ if (diff > ERROR) {
+ printf("%10d, squareroot: %16.8f, error: %16.14f\n", \
+ i, squareroot, diff);
+ }
+ }
+ exit;
+}
--- /dev/null
+#!/usr/bin/awk -f
+BEGIN {
+# this script breaks up the sentence into words, using
+# a space as the character separating the words
+ string="This is a string, is it not?";
+ search=" ";
+ n=split(string,array,search);
+ for (i=1;i<=n;i++) {
+ printf("Word[%d]=%s\n",i,array[i]);
+ }
+ exit;
+}
--- /dev/null
+#!/usr/bin/nawk -f
+BEGIN {
+ string = "Another sample of an example sentence";
+ pattern="[Aa]n";
+ if (gsub(pattern,"AN",string)) {
+ printf("Substitution occurred: %s\n", string);
+ }
+
+ exit;
+}
--- /dev/null
+#!/usr/bin/nawk -f
+# demonstrate the match function
+
+BEGIN {
+ regex="[a-zA-Z0-9]+";
+}
+{
+ if (match($0,regex)) {
+# RSTART is where the pattern starts
+# RLENGTH is the length of the pattern
+ before = substr($0,1,RSTART-1);
+ pattern = substr($0,RSTART,RLENGTH);
+ after = substr($0,RSTART+RLENGTH);
+ printf("%s<%s>%s\n", before, pattern, after);
+ }
+}
--- /dev/null
+#!/usr/bin/awk -f
+# look for a \ as the last character.
+# if found, read the next line and append
+{
+ line = $0;
+ while (substr(line,length(line),1) == "\\") {
+# chop off the last character
+ line = substr(line,1,length(line)-1);
+ i=getline;
+ if (i > 0) {
+ line = line $0;
+ } else {
+ printf("missing continuation on line %d\n", NR);
+ }
+ }
+ print line;
+}
--- /dev/null
+#!/usr/local/bin/gawk -f
+# how long does it take to do a few loops?
+BEGIN {
+ LOOPS=100;
+# do the test twice
+ start=systime();
+ for (i=0;i<LOOPS;i++) {
+ }
+ end = systime();
+# calculate how long it takes to do a dummy test
+ do_nothing = end-start;
+# now do the test again with the *IMPORTANT* code inside
+ start=systime();
+ for (i=0;i<LOOPS;i++) {
+# How long does this take?
+ while ("date" | getline) {
+ date = $0;
+ }
+ close("date");
+ }
+ end = systime();
+ newtime = (end - start) - do_nothing;
+
+ if (newtime <= 0) {
+ printf("%d loops were not enough to test, increase it\n",
+ LOOPS);
+ exit;
+ } else {
+ printf("%d loops took %6.4f seconds to execute\n",
+ LOOPS, newtime);
+ printf("That's %10.8f seconds per loop\n",
+ (newtime)/LOOPS);
+# since the clock has an accuracy of +/- one second, what is the error
+ printf("accuracy of this measurement = %6.2f%%\n",
+ (1/(newtime))*100);
+ }
+ exit;
+}
--- /dev/null
+#!/usr/bin/nawk -f
+{
+ if (NF != 4) {
+ error("Expected 4 fields");
+ } else {
+ print;
+ }
+}
+function error ( message ) {
+ if (FILENAME != "-") {
+ printf("%s: ", FILENAME) > "/dev/tty";
+ }
+ printf("line # %d, %s, line: %s\n", NR, message, $0) >> "/dev/tty";
+}
--- /dev/null
+#!/bin/awk -f
+# Linux users have to change $8 to $9
+BEGIN { print "File\tOwner" }
+ { print $8, "\t", \
+ $3}
+END { print " - DONE -" }
--- /dev/null
+#!/bin/csh -f
+# Linux users have to change $8 to $9
+awk '\
+BEGIN { print "File\tOwner" }\
+ { print $8, "\t", \\
+ $3}\
+END { print "done"}\
+'
--- /dev/null
+#!/bin/sh
+# Linux users have to change $8 to $9
+awk '
+BEGIN { print "File\tOwner" }
+ { print $8, "\t", \
+ $3}
+END { print "done"}
+'
--- /dev/null
+#!/bin/awk -f
+{
+ if ($1 == "#START") {
+ FS=":";
+ } else if ($1 == "#STOP") {
+ FS=" ";
+ } else {
+ #print the Roman number in column 3
+ print $3
+ }
+}
--- /dev/null
+#!/bin/awk -f
+{
+ if ( $0 ~ /:/ ) {
+ FS=":";
+ } else {
+ FS=" ";
+ }
+ #print the third field, whatever format
+ print $3
+}
--- /dev/null
+#!/bin/awk -f
+{
+ if ( $0 ~ /:/ ) {
+ FS=":";
+ $0=$0
+ } else {
+ FS=" ";
+ $0=$0
+ }
+ #print the third field, whatever format
+ print $3
+}
--- /dev/null
+#!/bin/awk -f
+{ if (NR > 100) {
+ print NR, $0;
+}
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+# change the record separator from newline to nothing
+ RS=""
+# change the field separator from whitespace to newline
+ FS="\n"
+}
+{
+# print the second and third line of the file
+ print $2, $3;
+}
--- /dev/null
+#!/bin/awk -f
+# reports which file is being read
+BEGIN {
+ f="";
+}
+{ if (f != FILENAME) {
+ print "reading", FILENAME;
+ f=FILENAME;
+ }
+ print;
+}
--- /dev/null
+#!/bin/awk -f
+{
+ if (NF == 6) {
+ # do the right thing
+ } else {
+ if (FILENAME == "-" ) {
+ print "SYNTAX ERROR, Wrong number of fields,", \
+ "in STDIN, line #:", NR, "line: ", $0;
+ } else {
+ print "SYNTAX ERROR, Wrong number of fields,", \
+ "Filename: ", FILENAME, "line # ", NR,"line: ", $0;
+ }
+ }
+}
--- /dev/null
+#!/bin/awk -f
+# bad example of AWK programming
+# this counts how many files each user owns.
+BEGIN {
+ number_of_users=0;
+}
+{
+# must make sure you only examine lines with 8 or more fields
+ if (NF>7) {
+ user=0;
+# look for the user in our list of users
+ for (i=1; i<=number_of_users; i++) {
+# is the user known?
+ if (username[i] == $3) {
+# found it - remember where the user is
+ user=i;
+ }
+ }
+ if (user == 0) {
+# found a new user
+ username[++number_of_users]=$3;
+ user=number_of_users;
+ }
+# increase number of counts
+ count[user]++;
+ }
+}
+END {
+ for (i=1; i<=number_of_users; i++) {
+ print count[i], username[i]
+ }
+}
--- /dev/null
+#!/usr/bin/awk -f
+BEGIN {
+ printf("String Number\n");
+}
+{
+ printf("%10s %6d\n", $1, $2);
+}
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+ FS=":";
+}
+{
+ if ( $2 == "" ) {
+ print $1 ": no password!";
+ }
+}
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+
+# Print the squares from 1 to 10 the first way
+
+ i=1;
+ while (i <= 10) {
+ printf "The square of ", i, " is ", i*i;
+ i = i+1;
+ }
+
+# do it again, using more concise code
+
+ for (i=1; i <= 10; i++) {
+ printf "The square of ", i, " is ", i*i;
+ }
+
+# now end
+exit;
+}
--- /dev/null
+#!/bin/awk -f
+{
+ if (length($0) < 80) {
+ prefix = "";
+ for (i = 1;i<(80-length($0))/2;i++)
+ prefix = prefix " ";
+ print prefix $0;
+ } else {
+ print;
+ }
+}
--- /dev/null
+#!/bin/sh
+find . -type f -print | xargs /bin/ls -islg | \
+awk '
+BEGIN {
+# initialize all arrays used in for loop
+ count[""]=0;
+ fsize[""]=0;
+}
+{
+# validate your input
+ if (NF != 11) {
+# ignore
+ } else {
+# assign field names
+ inode=$1;
+ flsize=$2;
+ linkcount=$4;
+ user=$5;
+ group=$6;
+
+# should I count this file?
+
+ doit=0;
+ if (linkcount == 1) {
+# only one copy - count it
+ doit++;
+ } else {
+# a hard link - only count first one
+ seen[inode]++;
+ if (seen[inode] == 1) {
+ doit++;
+ }
+ }
+# if doit is true, then count the file
+ if (doit ) {
+
+# total up counts in one pass
+# use description array names
+# use array index that unifies the arrays
+
+# first the counts for the number of files
+
+ count[user " *"]++;
+ count["* " group]++;
+ count[user " " group]++;
+ count["* *"]++;
+
+# then the total disk space used
+
+ fsize[user " *"]+=flsize;
+ fsize["* " group]+=flsize;
+ fsize[user " " group]+=flsize;
+ fsize["* *"]+=flsize;
+ }
+ }
+}
+END {
+# output in a form that can be sorted
+ for (i in count) {
+ if (i != "") {
+ print fsize[i], count[i], i;
+ }
+ }
+} ' | \
+# numeric sort - biggest numbers first
+# sort fields 0 and 1 first (sort starts with 0)
+# followed by dictionary sort on fields 2 + 3
+sort +0nr -2 +2d | \
+# add header
+(echo "size count user group";cat -) |\
+# convert space to tab - makes it nice output
+# the second set of quotes contains a single tab character
+tr ' ' ' '
+# done - I hope you like it
--- /dev/null
+#!/bin/awk -f
+{
+ username[$3]++;
+}
+END {
+ for (i in username) {
+ print username[i], i;
+ }
+}
--- /dev/null
+#!/bin/awk -f
+{
+ if (NF>7) {
+ username[$3]++;
+ }
+}
+END {
+ for (i in username) {
+ print username[i], i;
+ }
+}
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+ username[""]=0;
+}
+{
+ username[$3]++;
+}
+END {
+ for (i in username) {
+ if (i != "") {
+ print username[i], i;
+ }
+ }
+}
--- /dev/null
+#!/bin/sh
+find . -type f -print | xargs /bin/ls -islg | \
+awk '
+BEGIN {
+# initialize all arrays used in for loop
+ u_count[""]=0;
+ g_count[""]=0;
+ ug_count[""]=0;
+ all_count[""]=0;
+}
+{
+# validate your input
+ if (NF != 11) {
+# ignore
+ } else {
+# assign field names
+ inode=$1;
+ size=$2;
+ linkcount=$4;
+ user=$5;
+ group=$6;
+
+# should I count this file?
+
+ doit=0;
+ if (linkcount == 1) {
+# only one copy - count it
+ doit++;
+ } else {
+# a hard link - only count first one
+ seen[inode]++;
+ if (seen[inode] == 1) {
+ doit++;
+ }
+ }
+# if doit is true, then count the file
+ if (doit ) {
+
+# total up counts in one pass
+# use description array names
+# use array index that unifies the arrays
+
+# first the counts for the number of files
+
+ u_count[user " *"]++;
+ g_count["* " group]++;
+ ug_count[user " " group]++;
+ all_count["* *"]++;
+
+# then the total disk space used
+
+ u_size[user " *"]+=size;
+ g_size["* " group]+=size;
+ ug_size[user " " group]+=size;
+ all_size["* *"]+=size;
+ }
+ }
+}
+END {
+# output in a form that can be sorted
+ for (i in u_count) {
+ if (i != "") {
+ print u_size[i], u_count[i], i;
+ }
+ }
+ for (i in g_count) {
+ if (i != "") {
+ print g_size[i], g_count[i], i;
+ }
+ }
+ for (i in ug_count) {
+ if (i != "") {
+ print ug_size[i], ug_count[i], i;
+ }
+ }
+ for (i in all_count) {
+ if (i != "") {
+ print all_size[i], all_count[i], i;
+ }
+ }
+} ' | \
+# numeric sort - biggest numbers first
+# sort fields 0 and 1 first (sort starts with 0)
+# followed by dictionary sort on fields 2 + 3
+sort +0nr -2 +2d | \
+# add header
+(echo "size count user group";cat -) |\
+# convert space to tab - makes it nice output
+# the second set of quotes contains a single tab character
+tr ' ' ' '
+# done - I hope you like it
--- /dev/null
+#!/bin/sh
+find . -type f -print | xargs ls -isl | \
+awk '
+BEGIN {
+# initialize all arrays used in for loop
+ count[""]=0;
+ fsize[""]=0;
+}
+{
+# validate your input
+ if (NF != 10) {
+ printf("I was expecting 10 columns, but found %d for the output of ls. Please tweak the script\n",NF);
+ exit;
+# ignore
+ } else {
+# assign field names
+ inode=$1;
+ flsize=$2;
+ linkcount=$4;
+ user=$5;
+ group=$6;
+
+# should I count this file?
+
+ doit=0;
+ if (linkcount == 1) {
+# only one copy - count it
+ doit++;
+ } else {
+# a hard link - only count first one
+ seen[inode]++;
+ if (seen[inode] == 1) {
+ doit++;
+ }
+ }
+# if doit is true, then count the file
+ if (doit ) {
+
+# total up counts in one pass
+# use description array names
+# use array index that unifies the arrays
+
+# first the counts for the number of files
+
+ count[user " *"]++;
+ count["* " group]++;
+ count[user " " group]++;
+ count["* *"]++;
+
+# then the total disk space used
+
+ fsize[user " *"]+=flsize;
+ fsize["* " group]+=flsize;
+ fsize[user " " group]+=flsize;
+ fsize["* *"]+=flsize;
+ }
+ }
+}
+END {
+# output in a form that can be sorted
+ for (i in count) {
+ if (i != "") {
+ print fsize[i], count[i], i;
+ }
+ }
+} ' | \
+# numeric sort - biggest numbers first
+# sort fields 0 and 1 first (sort starts with 0)
+# followed by dictionary sort on fields 2 + 3
+sort +0nr -2 +2d | \
+# add header
+(echo "size count user group";cat -) |\
+# convert space to tab - makes it nice output
+# the second set of quotes contains a single tab character
+tr ' ' ' '
+# done - I hope you like it
--- /dev/null
+#! /usr/local/bin/gawk -f
+#
+
+BEGIN {
+ format = "%a %b %e %H:%M:%S %Z %Y";
+ print strftime(format);
+}
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+ FS=":";
+ OFS=":";
+}
+{
+ $2="";
+ print
+}
--- /dev/null
+#!/bin/awk -f
+{
+# field 1 is the e-mail address - perhaps
+ if ((x=index($1,"@")) > 0) {
+ username = substr($1,1,x-1);
+ hostname = substr($1,x+1,length($1));
+# the above is the same as
+# hostname = substr($1,x+1);
+ printf("username = %s, hostname = %s\n", username, hostname);
+ }
+}
--- /dev/null
+#!/usr/bin/nawk -f
+{
+# a primitive include preprocessor
+ if (($1 == "#include") && (NF == 2)) {
+# found the name of the file
+ filename = $2;
+ while (i = getline < filename ) {
+ print;
+ }
+ } else {
+ print;
+ }
+}
--- /dev/null
+#!/usr/bin/nawk -f
+BEGIN {
+# Assume we want 6 random numbers between 1 and 36
+# We could get this information by reading standard input,
+# but this example will use a fixed set of parameters.
+#
+# First, initialize the seed
+ srand();
+# How many numbers are needed?
+ NUM=6;
+# what is the minimum number
+ MIN=1;
+# and the maximum?
+ MAX=36;
+# How many numbers will we find? start with 0
+ Number=0;
+ while (Number < NUM) {
+ r=int(((rand() *(1+MAX-MIN))+MIN));
+# have I seen this number before?
+ if (array[r] == 0) {
+# no, I have not
+ Number++;
+ array[r]++;
+ }
+ }
+
+# now output all numbers, in order
+ for (i=MIN;i<=MAX;i++) {
+# is it marked in the array?
+ if (array[i]) {
+# yes
+ printf("%d ",i);
+ }
+ }
+ printf("\n");
+ exit;
+}
--- /dev/null
+#!/usr/local/bin/gawk -f
+BEGIN {
+# get current time
+ ts = systime();
+# the time is in seconds, so
+ one_day = 24 * 60 * 60;
+ next_week = ts + (7 * one_day);
+ format = "%a %b %e %H:%M:%S %Z %Y";
+ print strftime(format, next_week);
+ exit;
+}
--- /dev/null
+#!/bin/awk -f
+BEGIN {
+ RS=" ";
+}
+{
+ print ;
+}
--- /dev/null
+#!/bin/awk -f
+# parse the output of "ls -l"
+# print owner and filename
+# remember - Berkeley ls -l has 8 fields, System V has 9
+{
+ if (NF == 8) {
+ print $3, $8;
+ } else if (NF == 9) {
+ print $3, $9;
+ }
+}
--- /dev/null
+#!/bin/awk -f
+{ print $NF; }
--- /dev/null
+#!/usr/bin/nawk -f
+# old AWK doesn't have rand() and srand()
+# only new AWK has them
+# how random is the random function?
+BEGIN {
+# srand();
+ i=0;
+ while (i++<1000000) {
+ x=int(rand()*100 + 0.5);
+ y[x]++;
+ }
+ for (i=0;i<=100;i++) {
+ printf("%d\t%d\n",y[i],i);
+ }
+ exit;
+}
--- /dev/null
+#!/usr/bin/nawk -f
+#
+# A smattering of trigonometry...
+#
+# This AWK script plots the values from 0 to 360
+# for the basic trigonometry functions
+# but first - a review:
+#
+# (Note to the editor - the following diagram assumes
+# a fixed width font, like Courier.
+# otherwise, the diagram looks very stupid, instead of slightly stupid)
+#
+# Assume the following right triangle
+#
+# Angle Y
+#
+# |\
+# | \
+# | \
+# a | \ c
+# | \
+# | \
+# +------- Angle X
+# b
+#
+# since the triangle is a right angle, then
+# X+Y=90
+#
+# Basic Trigonometric Functions. If you know the length
+# of 2 sides, and the angles, you can find the length of the third side.
+# Also - if you know the length of the sides, you can calculate
+# the angles.
+#
+# The formulas are
+#
+# sine(X) = a/c
+# cosine(X) = b/c
+# tangent(X) = a/b
+#
+# reciprocal functions
+# cotangent(X) = b/a
+# secant(X) = c/b
+# cosecant(X) = c/a
+#
+# Example 1)
+# if an angle is 30, and the hypotenuse (c) is 10, then
+# a = sine(30) * 10 = 5
+# b = cosine(30) * 10 = 8.66
+#
+# The second example will be more realistic:
+#
+# Suppose you are looking for a Christmas tree, and
+# while talking to your family, you smack into a tree
+# because your head was turned, and your kids were arguing over who
+# was going to put the first ornament on the tree.
+#
+# As you come to, you realize your feet are touching the trunk of the tree,
+# and your eyes are 6 feet from the bottom of your frostbitten toes.
+# While counting the stars that spin around your head, you also realize
+# the top of the tree is located at a 65 degree angle, relative to your eyes.
+
+# You suddenly realize the tree is 12.84 feet high! After all,
+# tangent(65 degrees) * 6 feet = 12.84 feet
+
+# All right, it isn't realistic. Not many people memorize the
+# tangent table, or can estimate angles that accurately.
+# I was telling the truth about the stars spinning around the head, however.
+
+#
+BEGIN {
+# assign a value for pi.
+ PI=3.14159;
+# select an "Ed Sullivan" number - really really big
+ BIG=999999;
+# pick two formats
+# Keep them close together, so when one column is made larger
+# the other column can be adjusted to be the same width
+ fmt1="%7s %8s %8s %8s %10s %10s %10s %10s\n";
+# print out the title of each column
+ fmt2="%7d %8.2f %8.2f %8.2f %10.2f %10.2f %10.2f %10.2f\n";
+# old AWK wants a backslash at the end of the next line
+# to continue the print statement
+# new AWK allows you to break the line into two, after a comma
+ printf(fmt1,"Degrees","Radians","Cosine","Sine", \
+ "Tangent","Cotangent","Secant", "Cosecant");
+
+ for (i=0;i<=360;i++) {
+# convert degrees to radians
+ r = i * (PI / 180 );
+# in new AWK, the backslashes are optional
+# in OLD AWK, they are required
+ printf(fmt2, i, r, \
+# cosine of r
+ cos(r), \
+# sine of r
+ sin(r), \
+#
+# I ran into a problem when dividing by zero.
+# So I had to test for this case.
+#
+# old AWK finds the next line too complicated
+# I don't mind adding a backslash, but rewriting the
+# next three lines seems pointless for a simple lesson.
+# This script will only work with new AWK, now - sigh...
+# On the plus side,
+# I don't need to add those back slashes anymore
+#
+# tangent of r
+ (cos(r) == 0) ? BIG : sin(r)/cos(r),
+# cotangent of r
+ (sin(r) == 0) ? BIG : cos(r)/sin(r),
+# secant of r
+ (cos(r) == 0) ? BIG : 1/cos(r),
+# cosecant of r
+ (sin(r) == 0) ? BIG : 1/sin(r));
+ }
+# put an exit here, so that standard input isn't needed.
+ exit;
+}
--- /dev/null
+#!/usr/bin/awk -f
+# convert upper case letters to lower case
+BEGIN {
+ LC="abcdefghijklmnopqrstuvwxyz";
+ UC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+}
+{
+ out="";
+# look at each character
+ for(i=1;i<=length($0);i++) {
+# get the character to be checked
+ char=substr($0,i,1);
+# is it an upper case letter?
+ j=index(UC,char);
+ if (j > 0 ) {
+# found it
+ out = out substr(LC,j,1);
+ } else {
+ out = out char;
+ }
+ }
+ printf("%s\n", out);
+}
--- /dev/null
+#!/usr/local/bin/gawk -f
+{
+ print tolower($0);
+}
# To profile, put -DPROF in DEFS and -pg in CFLAGS, and recompile.
DEFS= -DTELL -DVFORK -DFILEC
-CFLAGS= $(DEFS) -O
+CFLAGS= $(DEFS) -O -g
XSTR= /usr/ucb/xstr
AS= as
RM= -rm
--- /dev/null
+# sort by date:
+alias newest 'ls -lt | head -30'
+alias oldest 'ls -ltr | head -30'
+# sort by size:
+alias biggest 'ls -ls|sort -nr | head -30'
+alias smallest 'ls -ls|sort -n | head -30'
+# sort by time last used
+alias popular 'ls -lut | head -30'
+alias unpopular 'ls -lutr | head -30'
+# Sort by link time
+alias lsst 'ls -lct | head -30'
+alias lsstr 'ls -lctr | head -30'
--- /dev/null
+alias C 'eval "if (\!:1 !~ *.c) then \\
+ echo "Error: this is for C programs only" \\
+ echo "Extension should be .c on file \!:1, not .\!:1:e" \\
+ else \\
+ if ( -e \!:1:r ) mv \!:1:r \!:1:r.old\\
+ cc -o !:1:r !:1:r.c \!:2* \\
+ endif
+
--- /dev/null
+#!/bin/csh -f
+# this could be one script instead of three if
+# we were using the Bourne Shell
+# But the C shell isn't very good at piping
+# commands inside of loops.
+#
+# Therefore we generate the pipe in one script,
+# and feed AWK in another script
+GetPaths | analyze_paths.awk HOSTNAME=`hostname`
+
--- /dev/null
+#!/bin/csh
+
+foreach i ( 1 2 3 4 5 6 7 8 9 10 11 12 )
+
+ # if 9, exit
+ if ( $i == 9 ) break
+ # if odd, then don't echo
+ if ( $i % 2 == 1 ) continue
+ # Even numbers only
+ echo $i
+ sleep 1
+end
+echo 'Who do we appreciate?'
+sleep 1; echo $USER
+sleep 1; echo $USER
+sleep 1; echo $USER
+sleep 1; echo 'Yeah!!!!!!'
--- /dev/null
+#!/bin/sh
+# Argument #1 is the directory where we will cache
+# a filename. Actually, not a cache, but a link.
+# where is the cache directory?
+# Usage
+# CreateCacheDir Cachedir dir1 [dir2 ...]
+# Function:
+# - Create a symbolic link in cachedir, pointing to the files in dir1, etc.
+#
+CACHE=${1:?'Target directory not defined'}
+if [ ! -d "$CACHE" ]
+then
+ echo making cache directory "$CACHE"
+ mkdir $CACHE
+fi
+
+shift
+
+# The rest of the arguments are directories to cache
+
+verbose=false # true to see what happens
+debug=false # true if you want extra information
+doit=true # false if you don't want to change anything
+
+for D in $*
+do
+ $verbose && echo caching directory $D
+ # list files, but ignore any that end with ~, or # or % (backup copies)
+ for f in `cd $D;ls|grep -v '[~#%]$'`
+ do
+ if [ -f $CACHE/$f ]
+ then
+ $debug && echo $CACHE/$f already exists
+ else
+ if [ -f $D/$f -a -x $D/$f ]
+ then
+ echo $D/$f
+ $verbose && echo ln -s $D/$f $CACHE/$f
+ $doit && ln -s $D/$f $CACHE/$f
+ elif [ -d $D/$f ]
+ then
+ $verbose && echo linking directory: ln -s $D/$f $CACHE/$f
+ $doit && ln -s $D/$f $CACHE/$f
+ else
+ $verbose && echo linking other: ln -s $D/$f $CACHE/$f
+ $doit && ln -s $D/$f $CACHE/$f
+ fi
+ fi
+ done
+echo you can now take $D out of your searchpath
+
+done
+
--- /dev/null
+#!/bin/csh
+echo First argument is $1, second argument is $2
+echo All of the arguments are $*
--- /dev/null
+#!/bin/csh
+echo There are $#argv arguments
+echo First argument is $argv[1], second argument is $argv[2]
+echo All of the arguments are $argv[*]
+
--- /dev/null
+#!/bin/csh -f
+awk '{printf("%s\t%s\t%s\n",\\
+$3, $2, $1}'
+
--- /dev/null
+# Sample .cshrc file
+# Bruce Barnett
+# This part is executed on the following occasions:
+# 1. "rsh machine command"
+# 2. "csh scriptname"
+# 3. All scripts that start with #!/bin/csh (without -f)
+# Read the minimum .cshrc file, if there
+
+if ( -f ~/.cshrc.min ) source ~/.cshrc.min
+
+# if run as a script, then $?prompt == 0
+# if run as a remote shell, then $?prompt == 0 && $?term == 0
+# if $USER is not defined, then "~" doesn't have the proper value
+# so bail out in this case
+
+if ( ! ( $?USER && $?prompt && $?TERM )) exit
+
+# This is an interactive shell
+
+#---Local variables
+# examples:
+# set noclobber
+# set myvariable = "value"
+# set mylist = ( a b c d e f g)
+
+
+#----aliases
+if ( -f ~/.aliases ) source ~/.aliases
+
+#----Searchpath
+if ( -f ~/.path ) source ~/.path
--- /dev/null
+#!/bin/sh
+# Given a directory, return the system it is mounted on
+# If it is localhost, then echo `hostname`
+dir=${1:?'No directory specified'}
+cd $dir
+
+# On SunOS 4.x, use /usr/bin/df before /usr/5bin
+# On Solaris 5.x, use /usr/ucb/df before /usr/bin
+# Solve the problem by specifying the explicit path
+PATH=/usr/ucb:/usr/bin:/usr/5bin:$PATH
+export PATH
+
+x=`df . | grep -v Filesystem`
+# use expr to extract the system name
+server=`expr "$x" : '\(.*\)\:'`
+# with sed, I could do $server=`echo $x | sed 's/:.*//'`
+if [ "$server" ]
+then
+ echo $server
+else
+ hostname
+fi
+
--- /dev/null
+#!/bin/echo use source to execute this command
+# variable a = filename metacharacter
+# variable b = command to execute
+
+# source this to define the alias
+if ( ! $?FOREACH_def) then
+ alias FOREACH 'set a = \!:1; \\
+ set b = (\!:2*);\\
+ source ~/source_alias/FOREACH.csh;'
+ set FOREACH_def
+else
+ echo $b | grep '#' >/dev/null
+ # remember status
+ set r = $status
+ foreach i ( $a )
+ if ( $r == 0 ) then
+ # change '#' to $i
+ set B = `echo $b | sed 's/#/'$i'/g'`
+ else
+ # Add a '$i' to the end, if it is missing
+ set B = `echo $b | sed 's/$/ '$i'/'`
+ endif
+ eval $B
+ end
+endif
+
--- /dev/null
+#!/bin/echo use source to execute this command
+# variable a = filename metacharacter
+# variable b = command to execute
+
+# source this to define the alias
+if ( ! $?FOREACHr_def) then
+ alias FOREACHr 'set a = \!:1; \\
+ set b = (\!:2*); \\
+ source ~/source_alias/FOREACHr.csh;'
+ set FOREACHr_def
+else
+ echo $b | grep '#' >/dev/null
+ # remember status
+ set r = $status
+ foreach i ( $a )
+ # Here is the different part
+ set j = $i:r
+ if ( $r == 0 ) then
+ # change '#' to $j
+ set B = `echo $b | sed 's/#/'$j'/g'`
+ else
+ set B = `echo $b | sed 's/$/ '$j'/'`
+ endif
+ eval $B
+ end
+endif
+
--- /dev/null
+#!/bin/csh
+set d = (`date`)
+# like
+# set d = ( Sun Feb 9 16:08:29 EST 1997 )
+# therefore
+# d[1] = day of week
+set day2="[Mm]on"
+switch ( $d[1] )
+case "*Sun":
+ echo Sunday; breaksw
+case $day2:
+ echo Monday;breaksw;
+case Tue:
+ echo Tuesday;breaksw;
+case Wed:
+ echo Wednesday;breaksw;
+case Th?:
+ echo Thursday;breaksw;
+case F*:
+ echo Friday;breaksw;
+case [Ss]at:
+ echo Saturday;breaksw;
+default:
+ echo impossible condition
+ exit 2
+endsw
+
--- /dev/null
+#!/bin/csh -f
+foreach p ( $path )
+ if ( -d $p ) then
+ set newp = (`ResolveDir $p`)
+ set server = (`Dir_to_System $p`)
+ echo "${p}:${newp}:${server}"
+ else
+ echo "${p}:?:?"
+ endif
+end
+
--- /dev/null
+# C shell aliases to display hosts, directories, and directory stacks
+# in the window title bar, icon string, and directory prompt
+# created by Bruce Barnett
+# Based on the SunOS 3.5 Release notes
+# Usage:
+# if ( -f ~/.header && -f ~/bin/Zappath ) source ~/.header
+#
+# the SP alias sets the directory prompt
+# the setbar alias changes the window title bar and icon string
+# define them here as the default case
+
+ alias SP 'set prompt="$cwd:t% "'
+ alias setbar 'echo \!* >/dev/null'
+
+# If not a sun cmdtool or shelltool, or not an X terminal, exit.
+if ( ! ( $term =~ sun* ) && ! ( $term =~ xterm )) goto getout
+
+# if using a raw console, don't do anything
+if ( `tty` =~ /dev/console ) goto getout
+
+# set a few variables for later
+# but only if the environment variable is not set
+
+if ( ! $?HOSTNAME ) then
+ setenv HOSTNAME `hostname`
+endif
+
+# find the home machine
+# is there a file that has a machine name in it?
+if ( -f ~/.display ) then
+ set mymachine = `sed -e 's/:.*//' <~/.display`
+else
+ # obviously change this to match your
+ # default system. Mine is "grymoire" - of course
+ set mymachine = "grymoire"
+# alternately, some people use "who am i"
+endif
+
+set console = '<< CONSOLE >>'
+
+# figure how how to generate escape, bell,
+# and echo commands without a a line terminator
+# I may have done this before. If so, the variable E is set
+
+# have I executed this script before on this system?
+if ( $?E ) then
+# echo "already set the echo variables">/dev/tty
+else if ( -f ~/.echo.${HOSTNAME} ) then
+ source ~/.echo.${HOSTNAME}
+else if ( `echo -n |wc -l` == 0 ) then
+# echo "built in echo is bsd" >/dev/tty
+ # then berkeley style echo
+ echo 'set ech = "echo -n"' >~/.echo.${HOSTNAME}
+ echo "set E = `echo a | tr a '\033'`" >> ~/.echo.${HOSTNAME}
+ echo "set B = `echo a | tr a '\007'`" >> ~/.echo.${HOSTNAME}
+ echo 'set N = ""' >> ~/.echo.${HOSTNAME}
+ source ~/.echo.${HOSTNAME}
+else
+# echo "built in echo is sysV" >/dev/tty
+ echo 'set ech = "echo"' >~/.echo.${HOSTNAME}
+ echo 'set E = "\033"' >> ~/.echo.${HOSTNAME}
+ echo 'set B = "\007"' >> ~/.echo.${HOSTNAME}
+ echo 'set N = "\c"' >> ~/.echo.${HOSTNAME}
+ source ~/.echo.${HOSTNAME}
+endif
+
+
+# Are we using shelltool, cmdtool or xterm?
+# duplicate these aliases here to avoid problems
+if ( $term =~ sun* ) then
+ # Sun Aliases
+ alias Header '${ech} "${E}]l\!:1${E}\${N}"'
+ alias IHeader '${ech} "${E}]L\!:1${E}\${N}"'
+else if ( $term =~ xterm ) then
+ alias Header '${ech} "${E}]2;\!:1${B}${N}"'
+ alias IHeader '${ech} "${E}]1;\!:1${B}${N}"'
+endif
+
+# There are three different combinations:
+# 1) A window on a remote machine
+# 2) A window on my machine
+# 3) A console on my machine
+
+# test for each case:
+
+if (${HOSTNAME} != $mymachine ) then
+ # it is a remote machine, therefore:
+ # window title has machinename and dirs
+ # icon has machine name only
+ # prompt has machine name+directory
+
+ alias setbar 'Header "${HOSTNAME}: `dirs | ~/bin/Zappath`" ; IHeader ${HOSTNAME}'
+
+# use either of these two lines to suit your tastes
+# the first one shows the command number and full directory path
+# The second shows just the hostname and the tail of the directory name
+
+# alias SP 'set prompt="[\\!] ${HOSTNAME}:$cwd % "'
+ alias SP 'set prompt="${HOSTNAME}:$cwd:t% "'
+
+else if ( `tty` == "/dev/console" ) then
+ goto getout
+else if ( `tty` == "/dev/ttyp0" ) then
+
+# in this case an assumption is made that the first pty
+# window to appear is the console window.
+# It's not always true, but it usually works
+
+ # window title has <<CONSOLE>> and dirs
+ # icon has "console" only
+ # prompt has directory
+
+ alias setbar 'Header "${console} `dirs | ~/bin/Zappath`"'
+
+# both of these works - pick one that suits you
+# alias SP 'set prompt="[\\!] $cwd % "'
+ alias SP 'set prompt="$cwd:t% "'
+else
+ # a plain window on my localhost
+ # window title has dirs
+ # icon has cwd only
+ # prompt has directory
+ # The next line must be one line, and not split onto two
+ alias setbar 'Header "`dirs | ~/bin/Zappath `"; IHeader "`echo $cwd| ~/bin/Zappath`"'
+# alias SP 'set prompt="[\\!] $cwd % "'
+ alias SP 'set prompt="$cwd:t% "'
+endif
+
+# redo current window
+alias . 'dirs|~/bin/Zappath;setbar;jobs'
+
+# change cd to change prompt, window and icon title
+alias cd 'chdir \!*; SP;setbar'
+alias pushd 'pushd \!*; SP;setbar'
+alias popd 'popd \!*; SP;setbar'
+
+SP;setbar
+getout:
+# end
+
--- /dev/null
+#!/bin/csh -f
+# start OpenWindows
+setenv OPENWINHOME /usr/openwin
+source ~/.path
+$OPENWINHOME/bin/openwin
--- /dev/null
+# .path.default modified for SunOS
+
+if ( ! $?HOSTNAME ) then
+ setenv HOSTNAME `hostname`
+endif
+
+# get host specific path, if there
+if ( -f ~/.path.$HOSTNAME ) then
+ source ~/.path.$HOSTNAME
+endif
+
+if ( ! $?SYSTEM ) then
+ set SYSTEM = "`uname -s`"
+endif
+
+# get system-specific searchpath, if there
+if ( -f ~/.path.$SYSTEM ) then
+ source ~/.path.$SYSTEM
+endif
+
+# define these if .path.$SYSTEM doesn't
+
+# define the system defined paths
+if (! $?SYSPATH ) then
+ set SYSPATH = ( /usr/ucb /usr/bin /bin )
+endif
+
+# define the places a window system's files are located
+
+
+if (! $?WINPATH ) then
+ set WINPATH = ( /usr/X11/bin /usr/X11R6/bin /usr/openwin/bin )
+endif
+
+# Private executables
+if ( ! $?MYBIN ) then
+ set MYBIN = ( ~/bin ~/bin/$SYSTEM )
+endif
+
+# local to machine
+if ( ! $?LOCALBIN ) then
+ set LOCALBIN = ( /local/bin /local/bin/$SYSTEM )
+endif
+
+#set CACHEBIN = ( $HOME/cachebin )
+set CACHEBIN = ( )
+
+#If TOTALPATH is defined, use it, else build it up from the pieces
+if ( $?TOTALPATH ) then
+ set path = ( $TOTALPATH )
+else
+ set path = ( $CACHEBIN $MYBIN $LOCALBIN $WINPATH $SYSPATH )
+# set path = ( $CACHEBIN $MYBIN $LOCALBIN $WINPATH $SYSPATH . )
+
+endif
--- /dev/null
+# .path.SunOS
+# copied from .path.default, and modified
+
+if ( ! $?SYSTEM ) then
+ set SYSTEM = "`uname -s`"
+endif
+
+# Having this here would cause an infinite loop
+# Make sure it is commented out
+#if ( -f ~/.path.$SYSTEM ) then
+# source ~/.path.$SYSTEM
+#endif
+
+# define these if .path.$SYSTEM doesn't
+
+if ( ! $?MACHINE ) then
+ set MACHINE = "`uname -m`"
+endif
+
+if ( ! $?REV ) then
+ set REV = "`uname -r`"
+endif
+
+# define the system defined paths
+if (! $?SYSPATH ) then
+ if ( "$REV" =~ 4.[012].* ) then
+ set SYSPATH = ( /usr/ucb /usr/bin /usr/5bin /bin /usr/etc )
+ else if ( "$REV" =~ 5.[0-6].* ) then
+ set SYSPATH = ( /opt/SUNWspro/bin /usr/ccs/bin \
+ /usr/ucb /usr/bin /usr/sbin )
+ else
+# How did I get here?
+ set SYSPATH = ( /usr/ucb /usr/bin /bin )
+ endif
+endif
+
+# define the places a window system's files are located
+# I could look at DISPLAY, and change this depending on
+# the value
+
+if (! $?WINPATH ) then
+ if ( ! $?OPENWINHOME ) then
+ setenv OPENWINHOME /usr/openwin
+ endif
+ set WINPATH = ( $OPENWINHOME/bin )
+endif
+
+# define the places where architecture-specific binaries are
+#
+if ( ! $?MYBIN ) then
+ set MYBIN = ( ~/bin ~/$SYSTEM/$REV/$MACHINE/bin )
+endif
+
+if ( ! $?LOCALBIN ) then
+ set LOCALBIN = ( /local/bin )
+endif
+
+#set CACHEBIN = ( )
+set CACHEBIN = ( $HOME/cachebin )
+
+# If I set this,
+# then the variables in .path.default will be skipped
+#set TOTALPATH = ( $CACHEBIN $MYBIN $LOCALBIN $WINPATH $SYSPATH )
--- /dev/null
+# example .path file
+
+if ( -f ~/.path.default ) then
+ source ~/.path.default
+else
+ # this is a default searchpath
+ set path = ( ~/bin /usr/ucb /usr/bin /usr/local/bin /local/bin )
+endif
--- /dev/null
+#!/bin/sh
+# Find the unique and final location of a directory
+# Usage:
+# ResolveDir directoryname
+#
+# If the directory is called ".", return "."
+dir=${1:?'Missing argument'}
+
+[ "$dir" = "." ] && { echo "."; exit 0; }
+cd $dir >/dev/null 2>&1 && { pwd; exit 0; }
+exit 1;
+
--- /dev/null
+#!/usr/bin/nawk -f
+# Do this before you read any input
+BEGIN {
+ FS=":";
+}
+
+# do this for each line
+(NF==3) {
+ if ($3 ~ /\?/ ) {
+# then it is a directory that does not exist
+ missing[$1]=1;
+ number_of_missing++;
+ } else if ( $1 ~ /\./ ) {
+# ignore it - it is the "." directory
+ } else {
+# count how many times each directory is used
+ used_count[$2]++;
+# is it a duplicate,
+ if ($1 !~ $2) {
+ links[$2]++;
+# remember it, by catenating two strings
+ used[$2] = used[$2] " " $1;
+ }
+
+# Is it a remote system?
+ if ($3 !~ HOSTNAME) {
+ systems[$3]++;
+# if this is the first time we have seen this directory
+ system_to_dir[$3] =
+ system_to_dir[$3] " " $1;
+ remote_systems++;
+ }
+ }
+
+# printf("%s\t%s\t%s\n",$1, $2, $3);
+}
+# Do this at the end of the file
+END {
+# Any directories that do not have to be included?
+
+ if (number_of_missing>0) {
+ printf("Directories that don't exist on this system:\n");
+ for (i in missing) {
+ printf("\t%s\n", i);
+ }
+ }
+
+# how many computer systems are needed?
+
+ if (remote_systems) {
+ printf("You are dependent upon the following systems:\n");
+ for (i in systems ) {
+ printf("\tsystem %s, directories: %s\n", i, system_to_dir[i]);
+ }
+
+ } else {
+ printf("Good! You are not dependent upon any other servers,");
+for your current directory\n");
+ printf(" except for your current directory\n");
+ }
+
+
+# What about duplicate directories?
+
+ for (i in used ) {
+ if (used_count[i]>1) {
+ printf("\nDirectory %s used %d times (symbolic links: %d)\n",
+ i, used_count[i], links[i]);
+ if (links[i]>0) {
+ printf("\tsymbolic links for '%s' are: %s\n", i, used[i]);
+ }
+ }
+ }
+
+}
--- /dev/null
+#!/bin/csh -f
+# A simple version of which that prints all
+# locations that contain the command
+if ( $#argv != 1 ) then
+ echo "Wrong number of arguments - usage: 'which command'"
+ exit 1
+endif
+foreach dir ( $path )
+ if ( -x $dir/$1 ) echo $dir/$1
+end
--- /dev/null
+#!/bin/sh
+# A simple version of which that prints all
+# locations that contain the command
+file=${1:-"Wrong number of arguments - usage: 'which command'"}
+paths=`echo $PATH | sed '
+s/^:/.:/g
+s/:$/:./g
+s/::/:.:/g
+s/:/ /g
+'`
+for dir in $paths
+do
+ [ -x $dir/$file ] && echo $dir/$file
+done
+
--- /dev/null
+#!/bin/csh
+# arguments are $*
+foreach i ( $* )
+ echo file $i has `wc -l <$i` lines
+end
+
--- /dev/null
+#!/bin/sh
+# Zappath: created by Bruce Barnett
+# this script edits the output of the C shell "dirs"
+# command and shortens the strings to a compact form
+#
+# Some example editing:
+#
+# remove the automount /tmp_mnt prefix
+# change /usr/export/home to /home
+# change /homedisk to /home
+# change $HOME into ~
+# change /home/abc to abc
+# change /usr/etc to ./etc
+# change */*/ABC to ./ABC
+# one more thing:
+# must change ~ to be -
+sed '
+s:/tmp_mnt::g
+s:/usr/export/home:/home:g
+s:/homedisk:/home:g
+s:'${HOME}':~:g
+s:/home/::g
+s:/usr/:./:g
+s:[^/ ]*/[^/ ]*/:./:g
+s:~:-:g
+'
+
+
--- /dev/null
+#!/bin/csh
+exit $*
+
--- /dev/null
+#!/bin/csh
+tee /tmp/file | \
+( grep MATCH /tmp/file >/dev/null && \
+( echo BEFORE; cat - ) || ( cat - ; echo AFTER) )
+/bin/rm /tmp/file
--- /dev/null
+#!/bin/sed -f
+s/a/A/g
+s/e/E/g
+s/i/I/g
+s/o/O/g
+s/u/U/g
+
--- /dev/null
+#!/bin/sh
+# change the first hex number to upper case format
+# uses sed twice
+# used as a filter
+# convert2uc <in >out
+sed '
+s/ /\
+/' | \
+sed ' {
+ y/abcdef/ABCDEF/
+ N
+ s/\n/ /
+}'
--- /dev/null
+#!/bin/sh
+# convert2uc version b
+# change the first hex number to upper case format
+# uses sed once
+# used as a filter
+# convert2uc <in >out
+sed '
+{
+# remember the line
+h
+#change the current line to upper case
+y/abcdef/ABCDEF/
+# add the old line back
+G
+# Keep the first word of the first line,
+# and second word of the second line
+# with one humongous regular expression
+s/^\([^ ]*\) .*\n[^ ]* \(.*\)/\1 \2/
+}'
--- /dev/null
+#!/bin/sh
+# convert2uc version b
+# change the first hex number to upper case format
+# uses sed once
+# used as a filter
+# convert2uc <in >out
+sed '
+{
+# remember the line
+h
+#change the current line to upper case
+y/abcdef/ABCDEF/
+# add the old line back
+G
+# Keep the first word of the first line,
+# and second word of the second line
+# with one humongous regular expression
+# Carl Henrik Lunde suggested this shorter version:
+s/ .* / / # delete all but the first and last word
+}'
--- /dev/null
+#!/bin/sh
+sed '
+:again
+ s/([ ^I]*)//g
+ t again
+'
--- /dev/null
+#!/bin/sh
+# grep3 - prints out three lines around pattern
+# if there is only one argument, exit
+
+case $# in
+ 1);;
+ *) echo "Usage: $0 pattern";exit;;
+esac;
+# I hope the argument doesn't contain a /
+# if it does, sed will complain
+
+# use sed -n to disable printing
+# unless we ask for it
+sed -n '
+'/$1/' !{
+ #no match - put the current line in the hold buffer
+ x
+ # delete the old one, which is
+ # now in the pattern buffer
+ d
+}
+'/$1/' {
+ # a match - get last line
+ x
+ # print it
+ p
+ # get the original line back
+ x
+ # print it
+ p
+ # get the next line
+ n
+ # print it
+ p
+ # now add three dashes as a marker
+ a\
+---
+ # now put this line into the hold buffer
+ x
+}'
--- /dev/null
+#!/bin/sh
+# grep3 version b - another version using the hold commands
+# if there is only one argument, exit
+
+case $# in
+ 1);;
+ *) echo "Usage: $0 pattern";exit;;
+esac;
+
+# again - I hope the argument doesn't contain a /
+
+# use sed -n to disable printing
+
+sed -n '
+'/$1/' !{
+ # put the non-matching line in the hold buffer
+ h
+}
+'/$1/' {
+ # found a line that matches
+ # append it to the hold buffer
+ H
+ # the hold buffer contains 2 lines
+ # get the next line
+ n
+ # and add it to the hold buffer
+ H
+ # now print it back to the pattern space
+ x
+ # and print it.
+ p
+ # add the three hyphens as a marker
+ a\
+---
+}'
--- /dev/null
+#!/bin/sh
+# grep3 version c: use 'G' instead of H
+
+# if there is only one argument, exit
+
+case $# in
+ 1);;
+ *) echo "Usage: $0 pattern";exit;;
+esac;
+
+# again - I hope the argument doesn't contain a /
+
+sed -n '
+'/$1/' !{
+ # put the non-matching line in the hold buffer
+ h
+}
+'/$1/' {
+ # found a line that matches
+ # add the next line to the pattern space
+ N
+ # exchange the previous line with the
+ # 2 in pattern space
+ x
+ # now add the two lines back
+ G
+ # and print it.
+ p
+ # add the three hyphens as a marker
+ a\
+---
+ # remove first 2 lines
+ s/.*\n.*\n\(.*\)$/\1/
+ # and place in the hold buffer for next time
+ h
+}'
--- /dev/null
+#!/bin/sh
+
+# grep4: prints out 4 lines around pattern
+# if there is only one argument, exit
+
+case $# in
+ 1);;
+ *) echo "Usage: $0 pattern";exit;;
+esac;
+
+sed -n '
+'/$1/' !{
+ # does not match - add this line to the hold space
+ H
+ # bring it back into the pattern space
+ x
+ # Two lines would look like .*\n.*
+ # Three lines look like .*\n.*\n.*
+ # Delete extra lines - keep two
+ s/^.*\n\(.*\n.*\)$/\1/
+ # now put the two lines (at most) into
+ # the hold buffer again
+ x
+}
+'/$1/' {
+ # matches - append the current line
+ H
+ # get the next line
+ n
+ # append that one also
+ H
+ # bring it back, but keep the current line in
+ # the hold buffer. This is the line after the pattern,
+ # and we want to place it in hold in case the next line
+ # has the desired pattern
+ x
+ # print the 4 lines
+ p
+ # add the mark
+ a\
+---
+}'
--- /dev/null
+#!/bin/sh
+sed -n '
+'/$1/' !{;H;x;s/^.*\n\(.*\n.*\)$/\1/;x;}
+'/$1/' {;H;n;H;x;p;a\
+---
+}'
--- /dev/null
+#!/bin/sh
+sed -n '
+# if an empty line, check the paragraph
+/^$/ b para
+# else add it to the hold buffer
+H
+# at end of file, check paragraph
+$ b para
+# now branch to end of script
+b
+# this is where a paragraph is checked for the pattern
+:para
+# return the entire paragraph
+# into the pattern space
+x
+# look for the pattern, if there - print
+/'$1'/ p
+'
--- /dev/null
+#!/bin/sh
+# print previous entry
+sed -n '
+/^[ ^I]/!{
+ # line does not start with a space or tab,
+ # does it have the pattern we are interested in?
+ '/$1/' {
+ # yes it does. print three dashes
+ i\
+---
+ # get hold buffer, save current line
+ x
+ # now print what was in the hold buffer
+ p
+ # get the original line back
+ x
+ }
+ # store it in the hold buffer
+ h
+}
+# what about lines that start
+# with a space or tab?
+/^[ ^I]/ {
+ # append it to the hold buffer
+ H
+}'
--- /dev/null
+#!/bin/sh
+sed '
+/begin/ {
+0i\
+ This is a comment\
+ It can cover several lines\
+ It will work with any version of sed
+}'
--- /dev/null
+#!/bin/sh
+sed '
+/WORD/ a\
+Add this line after every line with WORD
+'
+
--- /dev/null
+#!/bin/sh
+sed '/WORD/ a\
+Add this line after every line with WORD'
+
--- /dev/null
+#!/bin/sh
+sed '
+/WORD/ i\
+Add this line before every line with WORD
+'
+
--- /dev/null
+#!/bin/csh -f
+sed '\
+s/ /\\\\
+/' file
+
--- /dev/null
+#!/bin/sh
+sed 's/ /\\\
+/' file
+
--- /dev/null
+#!/bin/sh
+# this example is WRONG
+sed -e '1 {
+ d
+ s/.*//
+}'
+
--- /dev/null
+#!/bin/sh
+# This is a Bourne shell script that removes #-type comments
+# between 'begin' and 'end' words.
+sed -n '
+ /begin/,/end/ {
+ s/#.*//
+ s/[ ^I]*$//
+ /^$/ d
+ p
+ }
+'
+
--- /dev/null
+#!/bin/sh
+# This is a Bourne shell script that removes #-type comments
+# between 'begin' and 'end' words.
+sed -n '
+ 1,100 {
+ /begin/,/end/ {
+ s/#.*//
+ s/[ ^I]*$//
+ /^$/ d
+ p
+ }
+ }
+'
+
--- /dev/null
+#!/bin/sh
+sed '
+ /begin/,/end/ !{
+ s/#.*//
+ s/[ ^I]*$//
+ /^$/ d
+ p
+ }
+'
+
--- /dev/null
+#!/bin/sh
+sed '
+/WORD/ c\
+Replace the current line with the line
+'
+
--- /dev/null
+#!/bin/sh
+sed '
+/ONE/ {
+# append the next line
+ N
+# look for "ONE" followed by "TWO"
+ /ONE.*TWO/ {
+# delete everything between
+ s/ONE.*TWO/ONE TWO/
+# print
+ P
+# then delete the first line
+ D
+ }
+}' file
+
--- /dev/null
+#!/bin/sh
+sed '
+/ONE/ {
+# append a line
+ N
+# if TWO found, delete the first line
+ /\n.*TWO/ D
+}' file
+
--- /dev/null
+#!/bin/sh
+echo -n 'what is the value? '
+read value
+sed 's/XXX/'"$value"'/' <<EOF
+The value is XXX
+EOF
+
--- /dev/null
+#!/bin/sh
+sed '/INCLUDE/ {
+ r file
+ d
+}'
+
--- /dev/null
+#!/bin/sh
+# watch out for a '/' in the parameter
+# use alternate search delimiter
+sed -e '\_#INCLUDE <'"$1"'>_{
+ r '"$1"'
+ d
+}'
+
--- /dev/null
+#!/bin/sh
+# watch out for a '/' in the parameter
+# use alternate search delimiter
+sed -e '\_#INCLUDE <'"$1"'>_{
+
+ # read the file
+ r '"$1"'
+
+ # delete any characters in the pattern space
+ # and read the next line in
+ d
+}'
+
--- /dev/null
+#!/bin/sh
+sed '
+/WORD/ {
+i\
+Add this line before
+a\
+Add this line after
+c\
+Change the line to this one
+}'
--- /dev/null
+#!/bin/sh
+sed '=' file | \
+sed '{
+ N
+ s/\n/ /
+}'
+
--- /dev/null
+#!/bin/sh
+sed -n '
+# by default - do not print anything
+/ONE/ {
+# append a line
+ N
+# if TWO found, print the first line
+ /\n.*TWO/ P
+}' file
+
--- /dev/null
+#!/bin/sh
+tr ' ' '\012' | \
+sed ' {
+ y/abcdef/ABCDEF/
+ N
+ s/\n/ /
+}'
+
--- /dev/null
+#!/bin/sh
+sed '
+s/ /\
+/' | \
+sed ' {
+ y/abcdef/ABCDEF/
+ N
+ s/\n/ /
+}'
+
--- /dev/null
+#!/bin/sh
+#print last 10 lines of file
+# First argument is the filename
+lines=`wc -l $1 | awk '{print $1}' `
+start=`expr $lines - 10`
+sed "1,$start d" $1
+
--- /dev/null
+#!/bin/sh
+arg=`echo "$1" | sed 's:[]\[\^\$\.\*\/]:\\\\&:g'`
+sed 's/'"$arg"'//g'
+
--- /dev/null
+#!/bin/sh
+sed -n 's/'"$1"'/&/p'
+
--- /dev/null
+#!/bin/sh
+echo Hey! You forgot to specify the command!
--- /dev/null
+#!/bin/sh
+filename=/tmp/$0.$$
+cat "$@" | wc -l >$filename
+echo `cat $filename` lines were found
+/bin/rm $filename
+
--- /dev/null
+#!/bin/sh
+# Scriptname: EchoArgs
+# It echoes arguments
+#First - make sure we are using the Berkeley style echoes
+PATH=/usr/ucb:$path;export PATH
+E="echo -n"
+# echo the name of the script
+${E} $0:
+# now echo each argument, but put a space
+# before the argument, and place single quotes
+# around each argument
+${E} " '${1-"?"}'"
+${E} " '${2-"?"}'"
+${E} " '${3-"?"}'"
+${E} " '${4-"?"}'"
+${E} " '${5-"?"}'"
+${E} " '${6-"?"}'"
+${E} " '${7-"?"}'"
+echo
+
--- /dev/null
+#!/bin/sh
+
+usage() {
+ echo `basename $0`: ERROR: $* 1>&2
+ echo usage: `basename $0` '[-[abc]] [-o file]' '[file ...]' 1>&2
+ exit 1
+}
+
+set -- `getopt "abco:" "$@"` || usage
+
+a= b= c= o=
+while :
+do
+ case "$1" in
+ -a) a=1;;
+ -b) b=1;;
+ -c) c=1;;
+ -o) shift; o="$1";;
+ --) break;;
+ esac
+ shift
+done
+shift # get rid of --
+# rest of script...
--- /dev/null
+#!/bin/sh
+
+usage() {
+ echo `basename $0`: ERROR: $* 1>&2
+ echo usage: `basename $0` '[-a] [-b] [-c] [-o file] \
+ [file ...]' 1>&2
+ exit 1
+}
+
+a= b= c= o=
+
+while :
+do
+ case "$1" in
+ -a) a=1;;
+ -b) b=1;;
+ -c) c=1;;
+ -o) shift; o="$1";;
+ --) shift; break;;
+ -*) usage "bad argument $1";;
+ *) break;;
+ esac
+ shift
+done
+# rest of script...
--- /dev/null
+#!/bin/sh
+
+usage() {
+ echo `basename $0`: ERROR: $* 1>&2
+ echo usage: `basename $0` '[-[abc]] [-o file]' '[file ...]' 1>&2
+ exit 1
+}
+
+
+inside() {
+# this function returns a TRUE if $2 is inside $1
+# I'll use a case statement, because this is a built-in of the shell,
+# and faster.
+# I could use grep:
+# echo $1 | grep -s "$2" >/dev/null
+# or expr:
+# expr "$1" : ".*$2" >/dev/null && return 0 # true
+# but case does not require another shell
+ case "$1" in
+ *$2*) return 0;;
+ esac
+ return 1;
+}
+
+
+done_options=
+more_options() {
+ # return true(0) if there are options left to parse
+ # otherwise, return false
+
+ # check the 'short-circuit' flag
+ test $done_options && return 1 # true
+
+ # how many arguments are left?
+ [ $# -eq 0 ] && return 0
+
+ # does the next argument start with a hyphen
+ inside "$1" '-' && return 0;
+
+ # otherwise, return false
+ return 1 # false
+}
+a= b= c= o=
+
+while more_options "$1"
+do
+ case "$1" in
+ --) done_options=1;;
+ -[abc]*)
+ inside "$1" a && a=1;
+ inside "$1" b && b=1;
+ inside "$1" c && c=1;
+ inside "$1" "[d-zA-Z]" &&
+ usage "unknown option in $1";
+ ;;
+ -o?*)
+ # have to extract string from argument
+ o=`expr "$1" : '-o\(.*\)'`
+ ;;
+ -o)
+ [ $# -gt 1 ] || usage "-o requires a value";
+ shift
+ o="$1";;
+ -*) usage "unknown option $1";;
+ esac
+ shift # each time around, pop off the option
+done
+# continue with script
+# ...
--- /dev/null
+#!/bin/sh
+arg1="a.out"
+arg2=`pwd`
+arg3=$HOME
+if [ $# -gt 3 ]
+then
+fi
+
+if [ $# -eq 0 ]
+then
+ echo must specify at least one argument
+ exit 1
+else if [ $# -eq 1 ]
+then
+ arg1="$1";
+else if [ $# -eq 2 ]
+then
+ arg1="$1";
+ arg2="$2";
+else if [ $# -eq 3 ]
+then
+ arg1="$1";
+ arg2="$2";
+ arg3="$3";
+else
+ echo too many arguments
+ exit 1
+fi
+
+mv $arg2/$arg1 $arg3
--- /dev/null
+#!/bin/sh
+arg1="a.out"
+arg2=`pwd`
+arg3=$HOME
+if [ $# -gt 3 ]
+then
+ echo too many arguments
+ exit 1
+fi
+
+if [ $# -eq 0 ]
+then
+ echo must specify at least one argument
+ exit 1
+fi
+[ $# -ge 1 ] && arg1=$1 # do this if 1, 2 or 3 arguments
+[ $# -ge 2 ] && arg2=$2 # do this if 2 or 3 arguments
+[ $# -ge 3 ] && arg3=$3 # do this if 3 arguments
+
+mv $arg2/$arg1 $arg3
--- /dev/null
+#!/bin/sh
+
+usage() {
+ echo `basename $0`: ERROR: $* 1>&2
+ echo usage: `basename $0` 'filename [fromdir] [todir]' 1>&2
+ exit 1
+}
+arg1="a.out"
+arg2=`pwd`
+arg3=$HOME
+
+[ $# -gt 3 -o $# -lt 1 ] && usage "Wrong number of arguments"
+
+arg1=$1;shift
+[ $# -gt 0 ] && { arg2=$1;shift;}
+[ $# -gt 0 ] && { arg3=$1;shift;}
+
+mv $arg2/$arg1 $arg3
--- /dev/null
+#!/bin/sh
+
+usage() {
+ echo `basename $0`: ERROR: $* 1>&2
+ echo usage: `basename $0` 'filename [fromdir] [todir]' 1>&2
+ exit 1
+}
+arg1="a.out"
+arg2=`pwd`
+arg3=$HOME
+
+case $# in
+ 0) usage "must provide at least one argument";;
+ 1) arg1=$1;;
+ 2) arg1=$1;arg2=$2;;
+ 3) arg1=$1;arg2=$2;arg3=$3;;
+ *) usage "too many arguments";;
+
+esac
+mv $arg2/$arg1 $arg3
--- /dev/null
+#!/bin/sh
+EchoArgs $*
+EchoArgs $@
+EchoArgs "$*"
+EchoArgs "$@"
+
--- /dev/null
+#!/bin/sh
+# Print a warning if any disk is more
+# than 95% full.
+/usr/ucb/df | tr -d '%' | awk '
+# only look at lines where the first field contains a "/"
+$1 ~ /\// { if ($5 > 95) {
+ printf("Warning, disk %s is %4.2f%% full\n",$6,$5);
+ }
+}'
--- /dev/null
+#!/bin/sh
+# scriptname: moveto
+# usage:
+# moveto directory files.....
+directory=${1:?"Missing"};shift
+mv $* $directory
--- /dev/null
+#!/bin/sh
+# rename: - rename a file
+# Usage: rename oldname newname
+oldname=$1
+newname=$2
+mv ${oldname:?"missing"} ${newname:?"missing"}
+
--- /dev/null
+#!/bin/sh
+# rename: - rename a file
+# Usage: rename oldname newname
+mv $1 $2
--- /dev/null
+#!/bin/sh
+grep -i $* /dev/null
getegid.c geteuid.c getgid.c getpagesize.c getpgrp.c getpid.c \
getppid.c getrusage.c gettimeofday.c getuid.c ioctl.c link.c linux.c \
lseek.c lstat.c read.c readlink.c readv.c sbrk.c setpgrp.c \
- setregid.c setreuid.c settimeofday.c sigvec.c stat.c symlink.c \
- sync.c truncate.c umask.c unlink.c utimes.c vopen.c wait.c write.c \
- writev.c
+ setregid.c setreuid.c settimeofday.c sigblock.c sigpause.c \
+ sigsetmask.c sigvec.c stat.c symlink.c sync.c truncate.c umask.c \
+ unlink.c utimes.c vopen.c wait.c wait3.c write.c writev.c
OBJS= chdir.o chmod.o chown.o chroot.o close.o dup2.o dup.o execve.o \
_exit.o fchmod.o fchown.o fork.o fstat.o ftruncate.o getdtablesize.o \
getegid.o geteuid.o getgid.o getpagesize.o getpgrp.o getpid.o \
getppid.o getrusage.o gettimeofday.o getuid.o ioctl.o link.o linux.o \
lseek.o lstat.o read.o readlink.o readv.o sbrk.o setpgrp.o \
- setregid.o setreuid.o settimeofday.o sigvec.o stat.o symlink.o \
- sync.o truncate.o umask.o unlink.o utimes.o vopen.o wait.o write.o \
- writev.o
+ setregid.o setreuid.o settimeofday.o sigblock.o sigpause.o \
+ sigsetmask.o sigvec.o stat.o symlink.o sync.o truncate.o umask.o \
+ unlink.o utimes.o vopen.o wait.o wait3.o write.o writev.o
TAGSFILE=tags
errno = htot_errno(nox_errno);
return -1;
}
- rip->ru_utime.tv_sec = (time_t)ru.nox_ru_utime.nox_tv_sec;
- rip->ru_utime.tv_usec = (time_t)ru.nox_ru_utime.nox_tv_usec;
- rip->ru_stime.tv_sec = (time_t)ru.nox_ru_stime.nox_tv_sec;
- rip->ru_stime.tv_usec = (time_t)ru.nox_ru_stime.nox_tv_usec;
- rip->ru_maxrss = (long)ru.nox_ru_maxrss;
- rip->ru_ixrss = (long)ru.nox_ru_ixrss;
- rip->ru_idrss = (long)ru.nox_ru_idrss;
- rip->ru_isrss = (long)ru.nox_ru_isrss;
- rip->ru_minflt = (long)ru.nox_ru_minflt;
- rip->ru_majflt = (long)ru.nox_ru_majflt;
- rip->ru_nswap = (long)ru.nox_ru_nswap;
- rip->ru_inblock = (long)ru.nox_ru_inblock;
- rip->ru_oublock = (long)ru.nox_ru_oublock;
- rip->ru_msgsnd = (long)ru.nox_ru_msgsnd;
- rip->ru_msgrcv = (long)ru.nox_ru_msgrcv;
- rip->ru_nsignals = (long)ru.nox_ru_nsignals;
- rip->ru_nvcsw = (long)ru.nox_ru_nvcsw;
- rip->ru_nivcsw = (long)ru.nox_ru_nivcsw;
+ htot_rusage(&ru, rip);
return 0;
}
#include <nox_errno.h>
#include <nox_stdlib.h>
#include <nox_string.h>
+#include <sys/nox_resource.h>
+#include <sys/nox_signal.h>
#include <sys/nox_types.h>
+#include <sys/nox_wait.h>
#include <nox_unistd.h>
#include <gen.h>
#include <string.h>
#include <sys/dir.h>
#include <sys/errno.h>
+#include <sys/resource.h>
#include <sys/signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include "linux.h"
nox_int ttoh_errno[] = {
res->st_blksize = (long)stat->nox_st_blksize;
res->st_blocks = (long)stat->nox_st_blocks;
}
+
+void htot_rusage(ru, res) struct nox_rusage *ru; struct rusage *res; {
+ res->ru_utime.tv_sec = (time_t)ru->nox_ru_utime.nox_tv_sec;
+ res->ru_utime.tv_usec = (time_t)ru->nox_ru_utime.nox_tv_usec;
+ res->ru_stime.tv_sec = (time_t)ru->nox_ru_stime.nox_tv_sec;
+ res->ru_stime.tv_usec = (time_t)ru->nox_ru_stime.nox_tv_usec;
+ res->ru_maxrss = (long)ru->nox_ru_maxrss;
+ res->ru_ixrss = (long)ru->nox_ru_ixrss;
+ res->ru_idrss = (long)ru->nox_ru_idrss;
+ res->ru_isrss = (long)ru->nox_ru_isrss;
+ res->ru_minflt = (long)ru->nox_ru_minflt;
+ res->ru_majflt = (long)ru->nox_ru_majflt;
+ res->ru_nswap = (long)ru->nox_ru_nswap;
+ res->ru_inblock = (long)ru->nox_ru_inblock;
+ res->ru_oublock = (long)ru->nox_ru_oublock;
+ res->ru_msgsnd = (long)ru->nox_ru_msgsnd;
+ res->ru_msgrcv = (long)ru->nox_ru_msgrcv;
+ res->ru_nsignals = (long)ru->nox_ru_nsignals;
+ res->ru_nvcsw = (long)ru->nox_ru_nvcsw;
+ res->ru_nivcsw = (long)ru->nox_ru_nivcsw;
+}
+
+int htot_wait(stat) int stat; {
+ union wait w;
+
+ if (nox_WIFEXITED(stat)) {
+ w.w_termsig = 0;
+ w.w_coredump = 0;
+ w.w_retcode = nox_WEXITSTATUS(stat);
+ }
+ else if (nox_WIFSIGNALED(stat)) {
+ w.w_termsig = htot_signo(nox_WTERMSIG(stat));
+ w.w_coredump = nox_WCOREDUMP(stat);
+ w.w_retcode = 0;
+ }
+ else if (nox_WIFSTOPPED(stat)) {
+ w.w_stopval = WSTOPPED;
+ w.w_stopsig = htot_signo(nox_WSTOPSIG(stat));
+ }
+ else {
+ nox_write((nox_int)2, "htot_wait()\n", 12);
+ nox_abort();
+ }
+ return w.w_status;
+}
static void htot_direct(dirent, res) struct nox_dirent *dirent; struct direct *res; {
res->d_ino = (ino_t)dirent->nox_d_ino;
nox_mode_t ttoh_mode(unsigned m);
unsigned htot_mode(nox_mode_t m);
void htot_stat(struct nox_stat *statbuf, struct stat *res);
+void htot_rusage(struct nox_rusage *ru, struct rusage *res);
+int htot_wait(int stat);
int htot_dir(nox_int fd);
#endif
--- /dev/null
+#include <nox_stdlib.h>
+#include <sys/nox_signal.h>
+#include <sys/nox_types.h>
+#include <nox_unistd.h>
+
+#include <sys/signal.h>
+#include <sys/types.h>
+#include "linux.h"
+
+int sigblock(m) int m; {
+ nox_sigset_t newset;
+ nox_sigset_t oldset;
+
+ ttoh_sigmask(m, &newset);
+ if (nox_sigprocmask(nox_SIG_BLOCK, &newset, &oldset)) {
+ nox_write((nox_int)2, "sigblock(): sigprocmask()\n", 26);
+ nox_abort();
+ }
+ return htot_sigmask(&oldset);
+}
--- /dev/null
+#include <nox_errno.h>
+#include <nox_stdlib.h>
+#include <sys/nox_signal.h>
+#include <sys/nox_types.h>
+#include <nox_unistd.h>
+
+#include <sys/errno.h>
+#include <sys/signal.h>
+#include <sys/types.h>
+#include "linux.h"
+
+int sigpause(m) int m; {
+ nox_sigset_t set;
+
+ ttoh_sigmask(m, &set);
+ if (nox_sigsuspend(&set)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ nox_write((nox_int)2, "sigpause(): sigsuspend()\n", 25);
+ nox_abort();
+}
--- /dev/null
+#include <nox_stdlib.h>
+#include <sys/nox_signal.h>
+#include <sys/nox_types.h>
+#include <nox_unistd.h>
+
+#include <sys/signal.h>
+#include <sys/types.h>
+#include "linux.h"
+
+int sigsetmask(m) int m; {
+ nox_sigset_t newset;
+ nox_sigset_t oldset;
+
+ ttoh_sigmask(m, &newset);
+ if (nox_sigprocmask(nox_SIG_SETMASK, &newset, &oldset)) {
+ nox_write((nox_int)2, "sigsetmask(): sigprocmask()\n", 28);
+ nox_abort();
+ }
+ return htot_sigmask(&oldset);
+}
#include "linux.h"
int sigvec(c, f, m) int c; struct sigvec *f; struct sigvec *m; {
- struct nox_sigaction act;
+ struct nox_sigaction act, *act_p;
struct nox_sigaction oldact;
- act.nox_sa_sigaction = (void (*)(nox_int, nox_siginfo_t *, void *))f->sv_handler; /* fix this later */
- ttoh_sigmask(f->sv_mask, &act.nox_sa_mask);
- act.nox_sa_flags = nox_SA_RESTART | nox_SA_SIGINFO;
- if (f->sv_flags & SV_ONSTACK)
- act.nox_sa_flags |= nox_SA_ONSTACK;
- if (f->sv_flags & SV_INTERRUPT) {
- nox_write((nox_int)2, "sigvec(): SV_INTERRUPT\n", 23);
- nox_abort();
+ act_p = 0;
+ if (f) {
+ act.nox_sa_sigaction = (void (*)(nox_int, nox_siginfo_t *, void *))f->sv_handler; /* fix this later */
+ ttoh_sigmask(f->sv_mask, &act.nox_sa_mask);
+ act.nox_sa_flags = nox_SA_RESTART | nox_SA_SIGINFO;
+ if (f->sv_flags & SV_ONSTACK)
+ act.nox_sa_flags |= nox_SA_ONSTACK;
+ if (f->sv_flags & SV_INTERRUPT) {
+ nox_write((nox_int)2, "sigvec(): SV_INTERRUPT\n", 23);
+ nox_abort();
+ }
+ act_p = &act;
}
if (c < 0 || c >= NSIG) {
nox_write((nox_int)2, "sigvec(): out of range\n", 23);
nox_abort();
}
- if (nox_sigaction(ttoh_signo[c], &act, &oldact)) {
+ if (nox_sigaction(ttoh_signo[c], act_p, &oldact)) {
errno = htot_errno(nox_errno);
return -1;
}
- m->sv_handler = (void (*)(int sig, int code, struct sigcontext *scp))oldact.nox_sa_sigaction; /* fix this later */
- m->sv_mask = htot_sigmask(&oldact.nox_sa_mask);
- m->sv_flags = 0;
- if (oldact.nox_sa_flags & nox_SA_ONSTACK)
- m->sv_flags |= SV_ONSTACK;
+ if (m) {
+ m->sv_handler = (void (*)(int sig, int code, struct sigcontext *scp))oldact.nox_sa_sigaction; /* fix this later */
+ m->sv_mask = htot_sigmask(&oldact.nox_sa_mask);
+ m->sv_flags = 0;
+ if (oldact.nox_sa_flags & nox_SA_ONSTACK)
+ m->sv_flags |= SV_ONSTACK;
+ }
return 0;
}
#include <nox_unistd.h>
#include <sys/errno.h>
+#include <sys/types.h>
#include <sys/wait.h>
#include "linux.h"
int wait(s) int *s; {
nox_pid_t res;
nox_int stat;
- union wait w;
res = nox_wait(&stat);
if (res == (nox_pid_t)-1) {
errno = htot_errno(nox_errno);
return -1;
}
- if (nox_WIFEXITED(stat)) {
- w.w_termsig = 0;
- w.w_coredump = 0;
- w.w_retcode = nox_WEXITSTATUS(stat);
- }
- else if (nox_WIFSIGNALED(stat)) {
- w.w_termsig = htot_signo(nox_WTERMSIG(stat));
- w.w_coredump = nox_WCOREDUMP(stat);
- w.w_retcode = 0;
- }
- else if (nox_WIFSTOPPED(stat)) {
- w.w_stopval = WSTOPPED;
- w.w_stopsig = htot_signo(nox_WSTOPSIG(stat));
- }
- else {
- nox_write((nox_int)2, "wait(): invalid status\n", 23);
- nox_abort();
- }
- *s = w.w_status;
+ if (s)
+ *s = htot_wait(stat);
return (int)res;
}
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_resource.h>
+#include <sys/nox_types.h>
+#include <sys/nox_wait.h>
+
+#include <sys/errno.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "linux.h"
+
+int wait3(s, o, r) int *s; int o; struct rusage *r; {
+ int opts;
+ nox_pid_t res;
+ nox_int stat;
+ struct nox_rusage ru;
+
+ opts = 0;
+ if (o & WNOHANG)
+ opts |= nox_WNOHANG;
+ if (o & WUNTRACED)
+ opts |= nox_WUNTRACED;
+ res = nox_wait3(&stat, opts, &ru);
+ if (res == (nox_pid_t)-1) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ if (s)
+ *s = htot_wait(stat);
+ if (r)
+ htot_rusage(&ru, r);
+ return (int)res;
+}
#include <sys/file.h>
/*#include <sys/signal.h> gen.h*/
-void sigpause(m) int m; {
+int sigpause(m) int m; {
write(2, "sigpause()\n", 11);
abort();
}
int sigblock __P((int m));
/* sys/sigpause.c */
-void sigpause __P((int m));
+int sigpause __P((int m));
/* sys/sigreturn.c */
int sigreturn __P((struct sigcontext *scp));