The sample C programs and C shell scripts in the samples directory are meant to help you install or experiment with Hamilton C shell. Deliberately, they're relatively trivial. All were created assuming TABS=3.
a2e.csh |
Convert ASCII to EBCDIC using the tr utility. |
args.c |
A simple C program that prints out the *argv[] (argument) and *envp[] (environmental variable) arrays. Notice that wildcarding, variable substitutions, quoting and command substitutions are done before the C program is started. If you do a lot of wildcarding, you can create and pass very long parameter lists (up to 32K characters.) Try some of these commands: % args "ho"w 'no'w % args "$cwd" '$cwd' % args * "*" '*' % args `whereis more` % args '`whereis more`' % args * *\* *\*\* | more |
average.csh |
Find the average numeric values in a list. If none of the elements are numeric, return 0. |
basename.csh |
Emulate the POSIX basename command to extract just the last component of a pathname, deleting any suffix, if specified. |
bits.csh |
A simple self-loading procedure that calculates the minimum bits required to represent the argument it's passed as a binary integer. |
blksize.c |
A simple C program that reads from Stdin, copying to Stdout, using the specified blocksize. This program can be useful to read or write tape devices that only support certain blocksizes. |
bumpdate.csh |
Print the date n number of days forward or backward from a given date. If only the bump value is given, today's date is bumped. |
c2f.csh |
A simple C shell script for converting between Celsius and Fahrenheit. |
caldate.csh |
Print the date corresponding to a given Julian day. |
calendar.csh |
A C shell script for printing out the calendar for any given month, highlighting the current date. If no date is given, this month's calendar is printed. |
colors.csh |
Instructions and examples on customizing the screen colors. |
decimal.csh |
Force numeric strings with leading zeros to be treated as decimal numbers rather than as octal. |
deltaday.csh |
Print the number of days separating two dates. If only one date is given, the difference between it and today's date is returned. |
deltahrs.csh |
Calculate the difference in hours and fractions of an hour between two times, given in hours and minutes. |
dirname.csh |
Emulate the POSIX basename command to extract all but the last level of a pathname. |
dumpenv.c |
This C program writes out the environment it's passed in the form of setenv commands. If you're installing Hamilton C shell for the first time, dumpenv is a convenient way to snapshot the environmental variables you've been using with cmd.exe in a form you can append to your login.csh file. |
duplicat.csh |
Look for duplicate files anywhere in a directory tree. |
e2a.csh |
Convert EBCDIC to ASCII using the tr utility. |
easter.csh |
A C shell script that calculates when Easter will occur in any given year. If no year is given, the current year is assumed. |
f2c.csh |
A simple C shell script for converting between Fahrenheit to Celsius. |
factor.csh |
The simple factor C shell script shown in the User Guide. It's intended to show to show the use of recursion, expressions, and a self-loading procedure. |
finance.csh |
Another C shell script showing expression evaluation. This defines a number of routines for calculating financial conversion factors, e.g., from present to future value. |
findinclude.csh |
Search the INCLUDE directories for the specified header file. |
fixup.csh |
Fixup source files to discard any extraneous tabs or spaces at the end of the lines, to ensure that all lines end properly with \r\n and to ensure that the timestamps can be exactly represented on a FAT or HPFS partition. |
julian.csh |
Calculate the Julian day number (number of days since January 1, 4713 B.C.) for any given date. If you don't give a date, it uses today's date. |
laptop.csh |
Customize the screen colors for a laptop computer. |
makecpgm.csh |
A simple C shell script showing how a "make" function might be written in the C shell language. This one rebuilds any .exe files in the current directory that are older than the corresponding .c file or any of the .h files. |
max.csh |
Find the maximum numeric value out of a list. If none of the elements are numeric, return 0. |
mcvisa.csh |
A simple C shell script that constructs a special checksum of a credit card number to tell if the card number is plausible or not. The checksum used is designed to catch transposed or incorrect digits. Try it on the cards in your wallet. |
member.csh |
Test whether the first argument word appears somewhere in the list given by the second argument. |
memberi.csh |
Test by case-insensitive comparison whether the first argument word appears somewhere in the list given by the second argument. |
min.csh |
Find the minimum numeric value out of a list. If none of the elements are numeric, return 0. |
myecho.c |
A variation on the builtin echo command that prints its *argv[] (argument) list with quotes around each word it's passed and tells the total character count. Try these examples: % myecho now is the % myecho "now is" the % myecho `ls` % myecho `echo` % myecho `echo hello` % myecho * *\* *\*\* | more |
newfiles.csh |
List all the files or directories in the current directory that do not occur in the specified directory. |
percentchg.csh |
Calculate the percentage change between an old value and a new value. |
postage.csh |
Calculate the U.S. first class postage required for a given weight in ounces. |
posxpath.csh |
Convert ordinary filenames to POSIX format. |
rcode.c |
A trivial C program that just prints, then exits with the return code value you pass it. You can use this routine to see how the status variable is set and also, how the ;, || and && statement connectors work. Try these examples: % rcode % calc status % rcode 1 % calc status % echo $status % echo status % rcode 2 % calc status % rcode 0 || rcode 1 % rcode 1 || rcode 2 % rcode 0 && rcode 1 % rcode 1 && rcode 2 % rcode 0; rcode 1 % rcode 1; rcode 2 rcode also illustrates another aspect of return codes to consider: if you use C library stdio (as rcode.c does) and you exit with a non-zero return code, stdio thinks it was an error and discards anything in the stdio buffers. In the following example, stdio writes to the screen are unbuffered so it works; but pipes are buffered, so nothing gets written to it: % rcode 1 1 % rcode 1 | more --- End of file --- % If you're writing an application that uses return codes, you should remember to explicitly flush the buffers with stdio fflush() or use the kernel calls directly. |
read.csh |
Emulate the Bourne Shell's read command, which reads a line of input, breaking it into words, which are then assigned, one-by-one, to the variables whose names are passed as arguments. |
renet.csh |
A script for attempting to reconnect any unavailable network resources. |
sh2csh.csh |
A script for converting Bourne or Korn shell scripts into Hamilton C shell scripts using a set of sed scripts contained in the sh2csh directory. |
sizeof.csh |
A short C shell script that calculates and prints the cumulative size of any number of files or directories. |
splitstring.csh |
Split up a string into multiple lines, replacing each occurrence of the separator text with a line break, writing them to stdout. |
timestmp.csh |
Extract a timestamp from a file or directory in the format needed by touch.exe. |
trapz.csh |
A C shell script that does numeric integration using the trapezoidal rule. |
ts.csh |
A C shell script that searches for occurrences of a simple string in all the files with a given extension anywhere in a directory tree. |
update.csh |
Compare the frompath and topath directories, looking for differences, updating the topath directory as needed to make it an up-to-date copy. |
uptime.csh |
Print the elapsed time the system has been up. |
vectormath.csh |
A simple set of functions for doing vector math in both rectangualar and polar coordinates. |
weekday.csh |
Print the day of the week corresponding to any given date. |
which.csh |
Figure out what will be run if a command is typed. |
white.csh |
Customize the screen colors for a bright white window. |
winerror.c |
Print the Win32 message corresponding to a given error code. |