home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 March B
/
SCO_CASTOR4RRT.iso
/
scohelp
/
root.1
/
usr
/
man
/
bin
/
common.awk
/
common
Wrap
Text File
|
1998-08-19
|
3KB
|
123 lines
# @(#) SCCS ID: 15.1
#
# TechPubs SCCS ID:
# @(#) Filetype: AS
# @(#) SCCS ID: 100.5
# @(#) File: common.awk
# @(#) Last delta: 97/05/13 10:47:33
# @(#) Last get: 97/05/13 10:47:47
# @(#) SCCS file: /f/doctools/bin/s.common.awk
# @(#) Book: tools
#
# Copyright (C) 1986-1997 The Santa Cruz Operation, Inc.
# All Rights Reserved.
#
# This Module contains Proprietary Information of
# The Santa Cruz Operation, Inc. and should be
# treated as Confidential.
#
# This is part of the install_help utility.
#
# Awk functions that perform some common tasks used by several scripts.
# These provide case conversion, file existance testing, whitespace
# stripping and pattern generation capabilities.
#
function StripWhitespace(s)
{ # Removes any whitespace from the beginning and end of s.
sub(/^[[:blank:]]*/, "", s);
sub(/[[:blank:]]*$/, "", s);
return(s);
}
function Quote(s, o)
{ # Quotes characters that are special in REs.
o = "";
while (match(s, /[.*+?()\[\]{}^$|\\]/))
{ # Escape the special character.
o = o substr(s, 1, RSTART - 1) "\\" substr(s, RSTART, 1);
s = substr(s, RSTART + 1);
}
return(o s);
}
function basename(f)
{ # Returns the filename component of its argument.
sub(/\/*$/, "", f);
sub(/^.*\//, "", f);
return(f);
}
function dirname(f)
{ # Returns the directory component of its argument.
if (match(f, /^.*\//))
return(substr(f, RSTART, RLENGTH));
else return(".");
}
function FileExists(f)
{ # Returns 1 if the file f exists and is readable, 0 otherwise.
if (system("test -r " f " -a ! -d " f))
return(0);
return(1);
}
function DirExists(d)
{ # Returns 1 if the directory f exists and is searchable,
# 0 otherwise.
if (system("test -d " d " -a -x " d))
return(0);
return(1);
}
function FileIsText(f, c,l)
{ # Returns 1 if the file f is a text file, zero otherwise.
c = "file " f; # Construct the file(1) command.
c | getline l; # Execute the command and get the output.
close(c); # Terminate the command.
if (match(l, /text/) || match(l, /script/))
return(1);
return(0);
}
function ToUpper(s, LC,UC,c,i,o,p)
{ # Convert string s to all uppercase.
UC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
LC = "abcdefghijklmnopqrstuvwxyz"
for (i = 1; i <= length(s); i++)
{ # For each character in the string.
c = substr(s, i, 1);
if (p = index(LC, c))
o = o substr(UC, p, 1);
else o = o c;
}
return(o);
}
function ToLower(s, LC,UC,c,i,o,p)
{ # Convert string s to all lowercase.
UC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
LC = "abcdefghijklmnopqrstuvwxyz"
for (i = 1; i <= length(s); i++)
{ # For each character in the string.
c = substr(s, i, 1);
if (p = index(UC, c))
o = o substr(LC, p, 1);
else o = o c;
}
return(o);
}
function NoCasePattern(s, i,l,p,u)
{ # Return a pattern that matches s without regard to case.
p = "";
l = ToLower(s);
u = ToUpper(s);
for (i = 1; i <= length(s); i++)
{ # For each character in the string.
p = p "[" substr(u,i,1) substr(l,i,1) "]";
}
return(p);
}
#
### EOF