From 2542c6b1c38b6d08c9434aef2886914cfdac1b6c Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Thu, 23 Apr 2015 22:43:10 -0700 Subject: [PATCH 01/10] Added CPU socket count to hello perl example. Also tweaked command line argmument handling section to match output of python example script. --- perl/hello.pl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/perl/hello.pl b/perl/hello.pl index a45cf03..d05e47c 100755 --- a/perl/hello.pl +++ b/perl/hello.pl @@ -14,10 +14,15 @@ my $verinfo = `git describe --abbrev=7 --dirty --always --tags`; print "Hello Perl World! Version: $verinfo\n"; # Show list of command line arguments -print "Command line args: @ARGV\n"; -print "ARGV[0] = $ARGV[0]"; -print "ARGV[1] = $ARGV[1]"; -print "ARGV[2] = $ARGV[2]"; +print "Command line args: "; +foreach (@ARGV) { + print " $_"; +} +print "\n"; + +# Determine number of physical CPU sockets +my $socketcount=`cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l`; +print "CPU socket count: $socketcount\n"; # print out our animals array in reverse-sorted order print "\nValue of animals array:\n"; From e213617d4eac4eac7fa9b4d02d5bfbe1a06363fe Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Fri, 24 Apr 2015 13:31:55 -0700 Subject: [PATCH 02/10] Updated Makefile for openmp-c to add build date and commit author to embedded version info in the binary. --- openmp-c/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openmp-c/Makefile b/openmp-c/Makefile index 3c1031b..dbb532d 100644 --- a/openmp-c/Makefile +++ b/openmp-c/Makefile @@ -4,14 +4,18 @@ COMPILER_VER:=$(shell gcc --version) COMPILER_OPTS=-fopenmp GIT_DESCRIBE:=$(shell git describe --abbrev=7 --dirty --always --tags --long) +GIT_AUTHOR:=$(shell git --no-pager log -1 --pretty=format:"%an <%ae>") +BUILD_DATE:=$(shell date +"%F %H:%M:%S") .PHONY: all all: hello-omp versioninfo.txt: - @echo "@(#) Compiler version: ${COMPILER_VER}." >versioninfo.txt + @echo "@(#) Build date: ${BUILD_DATE}." >versioninfo.txt + @echo "@(#) Compiler version: ${COMPILER_VER}." >>versioninfo.txt @echo "@(#) Compiler options: ${COMPILER_OPTS}." >>versioninfo.txt @echo "@(#) Git info: ${GIT_DESCRIBE}" >>versioninfo.txt + @echo "@(#) Commit author: ${GIT_AUTHOR}" >>versioninfo.txt versioninfo.o: versioninfo.txt objcopy --input binary \ From 6538e6034d239d223f0fd9fb988c9d732e96d38b Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Fri, 24 Apr 2015 13:44:53 -0700 Subject: [PATCH 03/10] Added LDFLAGS to embedded version info for hello-omp. Tweaked Makefile to be more maintainable and to use common CFLAGS/LDFLAGS variable names. --- openmp-c/Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/openmp-c/Makefile b/openmp-c/Makefile index dbb532d..c20d9d6 100644 --- a/openmp-c/Makefile +++ b/openmp-c/Makefile @@ -1,8 +1,10 @@ # Sample makefile to add version/compiler info via an extra # object module linked to final binary. # -COMPILER_VER:=$(shell gcc --version) -COMPILER_OPTS=-fopenmp +CC=gcc +COMPILER_VER:=$(shell $(CC) --version) +CFLAGS=-fopenmp +LDFLAGS= GIT_DESCRIBE:=$(shell git describe --abbrev=7 --dirty --always --tags --long) GIT_AUTHOR:=$(shell git --no-pager log -1 --pretty=format:"%an <%ae>") BUILD_DATE:=$(shell date +"%F %H:%M:%S") @@ -13,7 +15,8 @@ all: hello-omp versioninfo.txt: @echo "@(#) Build date: ${BUILD_DATE}." >versioninfo.txt @echo "@(#) Compiler version: ${COMPILER_VER}." >>versioninfo.txt - @echo "@(#) Compiler options: ${COMPILER_OPTS}." >>versioninfo.txt + @echo "@(#) Compiler options: '${CFLAGS}'." >>versioninfo.txt + @echo "@(#) Linker options: '${LDFLAGS}'." >>versioninfo.txt @echo "@(#) Git info: ${GIT_DESCRIBE}" >>versioninfo.txt @echo "@(#) Commit author: ${GIT_AUTHOR}" >>versioninfo.txt @@ -26,8 +29,8 @@ versioninfo.o: versioninfo.txt versioninfo.txt versioninfo.o hello-omp: hello-omp.c Makefile versioninfo.o - gcc $(COMPILER_OPTS) -DVERSIONINFO="\"$(GIT_DESCRIBE)\"" hello-omp.c \ - versioninfo.o -o hello-omp + gcc $(CFLAGS) $(LDFLAGS) -DVERSIONINFO="\"$(GIT_DESCRIBE)\"" \ + hello-omp.c versioninfo.o -o hello-omp .PHONY: test test: From 010ed93aafd3fb959e0fa8b3e216036f431abf04 Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Mon, 27 Apr 2015 22:33:02 -0700 Subject: [PATCH 04/10] Added environment variable manipulation to hello.pl script. --- perl/hello.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/perl/hello.pl b/perl/hello.pl index d05e47c..9c17e64 100755 --- a/perl/hello.pl +++ b/perl/hello.pl @@ -41,6 +41,27 @@ foreach (keys %fruit_color) { print "$_ = $fruit_color{$_}\n"; } +# Read a non-existent environment variable and supply default value... +my $some_env_var; +if (defined $ENV{'PROBABLY_NOT_THERE'}) { + $some_env_var = $ENV{'PROBABLY_NOT_THERE'}; +} else { + $some_env_var = "Default value"; +} +print "\nPROBABLY_NOT_THERE is set to \'$some_env_var\'\n\n"; + +# Let's read in the PATH variable from the OS and print it out... +my $path_env_var = $ENV{'PATH'}; +print "OS PATH var is set to: \'$path_env_var\'\n\n"; + +# Let's manipulate PATH variable and then restore it +print "Adding :/test to PATH variable\n"; +$ENV{'PATH'} = "$ENV{'PATH'}:/test"; +print "OS PATH var is set to: \'$ENV{'PATH'}\'\n\n"; +print "Restoring original PATH value.\n"; +$ENV{'PATH'} = $path_env_var; +print "OS PATH var is set to: \'$path_env_var\'\n\n"; + # Let's create the file test.out and write animals array to it... print "\nWriting test.out file...\n"; open(my $out, ">", "test.out") or die "Can't create/open test.out! $!\n"; From f09f5083240cbfaafdc01e109bf4a8402e442318 Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Mon, 4 May 2015 19:51:54 -0700 Subject: [PATCH 05/10] Initial commit of sample Hello Forth World script. --- forth/hello.fs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 forth/hello.fs diff --git a/forth/hello.fs b/forth/hello.fs new file mode 100755 index 0000000..f5118ef --- /dev/null +++ b/forth/hello.fs @@ -0,0 +1,7 @@ +#! /usr/bin/gforth +\ +\ Sample Hello World! Forth script... +\ + +.( Hello Forth World! ) cr +bye From fdbb99aeeb7e1de41f52c47bfc8da66677c6c91b Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Fri, 8 May 2015 23:18:50 -0700 Subject: [PATCH 06/10] Added version info output to Hello Forth World script and made initial pass at outputing command line arguments. --- forth/hello.fs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/forth/hello.fs b/forth/hello.fs index f5118ef..3ce247e 100755 --- a/forth/hello.fs +++ b/forth/hello.fs @@ -3,5 +3,15 @@ \ Sample Hello World! Forth script... \ -.( Hello Forth World! ) cr +: verinfo s" git describe --abbrev=7 --dirty --always --tags" system ; + +\ Obligatory Hello World with some version info +.( Hello Forth World! Version: ) verinfo cr + +\ Show list of command line arguments +: printargs + argc @ 0 do i arg type cr loop ; +.( Command line args: ) cr +printargs + bye From b0196162a903819a807b89f2e9bc9e6d44b371ed Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Sat, 9 May 2015 10:39:02 -0700 Subject: [PATCH 07/10] Completed FORTH command line arg printing and added comments to document example better. --- forth/hello.fs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/forth/hello.fs b/forth/hello.fs index 3ce247e..e8408dc 100755 --- a/forth/hello.fs +++ b/forth/hello.fs @@ -3,15 +3,31 @@ \ Sample Hello World! Forth script... \ +\ Define "verinfo" : verinfo s" git describe --abbrev=7 --dirty --always --tags" system ; +\ Define "printargs" +: printargs + \ The argc variable contains the count of cmd line args + \ in gforth, so we put it's value (@) on the stack plus + \ the number one and test if the value is greater than one. + argc @ 1 > if + \ condition is true, so put the value of argc (@) + \ on the stack and the value one as the range of + \ our do loop - we don't pring arg 0 which is the + \ name of the program. + argc @ 1 do i arg type space loop cr + else + \ condition is false, so don't print anything + cr + then ; + + \ Obligatory Hello World with some version info .( Hello Forth World! Version: ) verinfo cr + \ Show list of command line arguments -: printargs - argc @ 0 do i arg type cr loop ; -.( Command line args: ) cr -printargs +.( Command line args: ) printargs bye From 787c1866e2bd7b2aec70b8f1bc9271f636850953 Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Sun, 17 May 2015 08:55:00 -0700 Subject: [PATCH 08/10] Added "what" script. Moved miscellaneous tools (sizeofchk, what) into their own "misc-tools" sub-directory and updated README.md to reflect the change. --- README.md | 5 +++-- {sizeofchk => misc-tools/sizeofchk}/Makefile | 0 {sizeofchk => misc-tools/sizeofchk}/README.md | 0 {sizeofchk => misc-tools/sizeofchk}/sizeofchk.c | 0 misc-tools/what | 12 ++++++++++++ 5 files changed, 15 insertions(+), 2 deletions(-) rename {sizeofchk => misc-tools/sizeofchk}/Makefile (100%) rename {sizeofchk => misc-tools/sizeofchk}/README.md (100%) rename {sizeofchk => misc-tools/sizeofchk}/sizeofchk.c (100%) create mode 100755 misc-tools/what diff --git a/README.md b/README.md index 4f92b6a..d257295 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # src-ed -Source code samples for various languages - hello name-your-language world! - +Source code samples for various languages - hello "name-your-language" world! +The subdirectory "misc-tools" contains miscellaneous utilities that may +be of interest or help to a programmer. diff --git a/sizeofchk/Makefile b/misc-tools/sizeofchk/Makefile similarity index 100% rename from sizeofchk/Makefile rename to misc-tools/sizeofchk/Makefile diff --git a/sizeofchk/README.md b/misc-tools/sizeofchk/README.md similarity index 100% rename from sizeofchk/README.md rename to misc-tools/sizeofchk/README.md diff --git a/sizeofchk/sizeofchk.c b/misc-tools/sizeofchk/sizeofchk.c similarity index 100% rename from sizeofchk/sizeofchk.c rename to misc-tools/sizeofchk/sizeofchk.c diff --git a/misc-tools/what b/misc-tools/what new file mode 100755 index 0000000..61d4528 --- /dev/null +++ b/misc-tools/what @@ -0,0 +1,12 @@ +#!/bin/bash +# +# what - get SCCS identification information +# +# SCCS was the source code control system distributed +# with AT&T Unix System III and V. +# +for i in "$@"; +do + echo "$i:" + strings "$i" | grep -e '@(#)' | sed 's/^.*[@][(][#][)]\(.*\)/ \1/' +done From eb12c8f9cf9db5946e5ed67a1b7f9855a227abc0 Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Fri, 9 Oct 2020 11:26:29 -0700 Subject: [PATCH 09/10] Modernized python script print statements. --- python/hello.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/python/hello.py b/python/hello.py index 154d35f..ed21fed 100755 --- a/python/hello.py +++ b/python/hello.py @@ -15,13 +15,13 @@ verinfo = subprocess.check_output(["git", "describe", "--abbrev=7", "--dirty", "--always", "--tags"]) # Obligatory Hello World with some version info -print "Hello Python World! Version: " +verinfo +print("Hello Python World! Version: {}".format(verinfo)) # Show list of command line arguments -print "Command line args: ", +print("Command line args: "), for i in sys.argv[1:]: - print " " + i, -print "" + print(" {}".format(i)) +print("") # Determine number of physical CPU sockets if os.name == 'nt': @@ -29,52 +29,52 @@ if os.name == 'nt': else: socketcount = subprocess.check_output(["bash","-c", "(cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l)"]) - print "CPU socket count: ", socketcount + print("CPU socket count: {}".format(socketcount)) # print out our animals array in reverse-sorted order -print "\nValue of animals array:" +print("\nValue of animals array:") for i in sorted(animals, reverse=True): - print "item = " + i + print("item = " + i) if (i == animals[0]): - print " Condition is TRUE, \"" +i+ "\" == " + animals[0] + print(" Condition is TRUE, \"" +i+ "\" == " + animals[0]) else: - print " Condition is FALSE, \"" +i+ "\" != " + animals[0] + print(" Condition is FALSE, \"" +i+ "\" != " + animals[0]) # print our fruit_color dictionary (key/value pairs) -print "\nValue of fruit_color hash:" +print("\nValue of fruit_color hash:") for fruit,color in sorted(fruit_color.items(), reverse=True): - print fruit, " = ", color + print(fruit, " = ", color) # Read a non-existent environment variable and supply default value... some_env_var = os.getenv("PROBABLY_NOT_THERE", "Default Value") -print "\nPROBABLY_NOT_THERE is set to '"+some_env_var+"'\n" +print("\nPROBABLY_NOT_THERE is set to '"+some_env_var+"'\n") # Let's read in the PATH variable from the OS and print it out... path_env_var = os.environ['PATH'] -print "OS PATH var is set to: '"+path_env_var+"'\n" +print("OS PATH var is set to: '"+path_env_var+"'\n") # Let's manipulate PATH variable and then restore it -print "Adding :/test to PATH variable" +print("Adding :/test to PATH variable") os.environ['PATH'] = os.environ['PATH'] + ":/test" -print "OS PATH var is set to: '"+os.environ['PATH']+"'\n" -print "Restoring original PATH value." +print("OS PATH var is set to: '"+os.environ['PATH']+"'\n") +print("Restoring original PATH value.") os.environ['PATH'] = path_env_var -print "OS PATH var is set to: '"+path_env_var+"'\n" +print("OS PATH var is set to: '"+path_env_var+"'\n") # Let's create the file test.out and write animals array to it... -print "\nWriting test.out file..." +print("\nWriting test.out file...") file = open("test.out", "w") for i in animals: file.write(i+"\n") file.close() # Now open the file we wrote and read it back... -print "\nContents of test.out file:" +print("\nContents of test.out file:") file = open("test.out", "r") linenum = 1 for line in file: - print "line "+str(linenum)+": "+line, + print("line "+str(linenum)+": "+line) linenum += 1 file.close() From 18e6cfbb117fa00cb77d2ca01b276148c1486e48 Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Sat, 10 Oct 2020 17:24:29 -0700 Subject: [PATCH 10/10] Initial commit of rust/ directory. First "Hello, rust world!" program. --- rust/Cargo.lock | 5 +++++ rust/Cargo.toml | 9 +++++++++ rust/src/main.rs | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 rust/Cargo.lock create mode 100644 rust/Cargo.toml create mode 100644 rust/src/main.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..f7d53cc --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "rust" +version = "0.1.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..a8b9818 --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rust" +version = "0.1.0" +authors = ["Ed Braaten "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/rust/src/main.rs b/rust/src/main.rs new file mode 100644 index 0000000..f69047c --- /dev/null +++ b/rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, rust world!"); +}