diff --git a/COBOL/Makefile b/COBOL/Makefile new file mode 100644 index 0000000..b990062 --- /dev/null +++ b/COBOL/Makefile @@ -0,0 +1,5 @@ +COBCFLAGS=-free -x + + +hello: hello.cob + cobc ${COBCFLAGS} -o hello hello.cob diff --git a/COBOL/hello.cob b/COBOL/hello.cob new file mode 100644 index 0000000..81c0919 --- /dev/null +++ b/COBOL/hello.cob @@ -0,0 +1,6 @@ +IDENTIFICATION DIVISION. +PROGRAM-ID. HELLO-WORLD. +* simple hello world program +PROCEDURE DIVISION. + DISPLAY 'Hello COBOL world!'. + STOP RUN. diff --git a/README.md b/README.md index 749e5f9..4f92b6a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # src-ed -Soruce code samples for various languages - hello name-your-language world! +Source code samples for various languages - hello name-your-language world! + + + diff --git a/bash/hello.sh b/bash/hello.sh new file mode 100755 index 0000000..0869db8 --- /dev/null +++ b/bash/hello.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Sample Hello World! bash script... +# + +declare -A FRUIT_COLOR + +FRUIT_COLOR=( ["apple"]="red" ["banana"]="yellow") +VERINFO=`git describe --abbrev=7 --dirty --always --tags` + + +# Obligatory Hello World with some version info +echo "Hello Bash World! Version: $VERINFO" + +# Show list of command line arguments +echo "Command line args: $*" + +# Determine number of physical CPU sockets +SOCKETCOUNT=`cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l` +echo "CPU socket count: $SOCKETCOUNT" + +# print out our FRUIT_COLOR associative array (key/value pairs) +declare -A sorted_fruit +for fruit in "${!FRUIT_COLOR[@]}"; do + echo "$fruit = ${FRUIT_COLOR["$fruit"]}"; +done | sort --reverse + diff --git a/openmp-c/Makefile b/openmp-c/Makefile new file mode 100644 index 0000000..3c1031b --- /dev/null +++ b/openmp-c/Makefile @@ -0,0 +1,38 @@ +# Sample makefile to add version/compiler info via an extra +# object module linked to final binary. +# +COMPILER_VER:=$(shell gcc --version) +COMPILER_OPTS=-fopenmp +GIT_DESCRIBE:=$(shell git describe --abbrev=7 --dirty --always --tags --long) + +.PHONY: all +all: hello-omp + +versioninfo.txt: + @echo "@(#) Compiler version: ${COMPILER_VER}." >versioninfo.txt + @echo "@(#) Compiler options: ${COMPILER_OPTS}." >>versioninfo.txt + @echo "@(#) Git info: ${GIT_DESCRIBE}" >>versioninfo.txt + +versioninfo.o: versioninfo.txt + objcopy --input binary \ + --output elf64-x86-64 \ + --binary-architecture i386 \ + --add-section versioninfo=versioninfo.txt \ + --set-section-flags versioninfo=contents,noload \ + 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 + +.PHONY: test +test: + (export OMP_NUM_THREADS=2; ./hello-omp) + sleep 5 + (export OMP_NUM_THREADS=24; ./hello-omp) + sleep 5 + (export OMP_NUM_THREADS=500; ./hello-omp) + +.PHONY: clean +clean: + rm -f hello-omp versioninfo.* diff --git a/openmp-c/hello-omp b/openmp-c/hello-omp new file mode 100755 index 0000000..01c0621 Binary files /dev/null and b/openmp-c/hello-omp differ diff --git a/openmp-c/hello-omp.c b/openmp-c/hello-omp.c new file mode 100644 index 0000000..321b412 --- /dev/null +++ b/openmp-c/hello-omp.c @@ -0,0 +1,43 @@ +#include +#include + +#ifdef _OPENMP + +static char versionbuf[16]; +static char gitversion[] = VERSIONINFO; + +int main() +{ + int tcount = 0; + char *versionp; + + /* Tell about the version of OpenMP API we're using. + * Specification source: www.openmp.org. + */ + switch (_OPENMP) { + case 200805: + versionp = "3.0 (May 2008)"; break; + case 201107: + versionp = "3.1 (Jul 2011)"; break; + case 201307: + versionp = "4.0 (Jul 2013)"; break; + default: + sprintf(versionbuf, "(%6.6d)", _OPENMP); + versionp = versionbuf; + break; + } + printf("Using OpenMP version: %s\n", versionp); + printf("Program git commit info: %s\n", gitversion); + printf("Max threads = %d\n", omp_get_max_threads()); + +#pragma omp parallel +#pragma omp atomic + tcount++; + +#pragma omp parallel + /* Hello parallel world... */ + printf("Hello OpenMP World from thread %3.3d of %3.3d! (tcount=%d)\n", + omp_get_thread_num() + 1, omp_get_num_threads(), tcount); +} + +#endif diff --git a/openmp-c/versioninfo.txt b/openmp-c/versioninfo.txt new file mode 100644 index 0000000..432ca87 --- /dev/null +++ b/openmp-c/versioninfo.txt @@ -0,0 +1,3 @@ +@(#) Compiler version: gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16) Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.. +@(#) Compiler options: -fopenmp. +@(#) Git info: e1e14b8-dirty diff --git a/perl/hello.pl b/perl/hello.pl new file mode 100755 index 0000000..a45cf03 --- /dev/null +++ b/perl/hello.pl @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +# +# Perl language Hello World! (and then some...) +use strict; +use warnings; + +my @animals = ("camel", "llama", "owl"); +my %fruit_color = (apple => "red", banana => "yellow"); +my @fruits = keys %fruit_color; +my @colors = values %fruit_color; +my $verinfo = `git describe --abbrev=7 --dirty --always --tags`; + +# Obligatory Hello World with some version info +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 out our animals array in reverse-sorted order +print "\nValue of animals array:\n"; +foreach (reverse @animals) { + print 'item = ' . $_ . "\n"; + if ($_ eq $animals[0]) { + print " Condition is TRUE, \"$_\" eq " . "$animals[0]\n"; + } else { + print " Condition is FALSE, \"$_\" ne " . "$animals[0]\n"; + } +} + +# print our fruit_color hash (key/value pairs) +print "\nValue of fruit_color hash:\n"; +foreach (keys %fruit_color) { + print "$_ = $fruit_color{$_}\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"; +foreach (@animals) { + print $out "$_\n"; +} +close $out or die "$out: $!\n"; + +# Now open the file we wrote and read it back... +print "\nContents of test.out file:\n"; +open (my $in, "<", "test.out") or die "Can't open test.out! $!\n"; +my $linenum = 1; +while (<$in>) { + print "line $linenum: $_"; + $linenum += 1; +} +close $in or die "$in $!\n"; diff --git a/python/hello.py b/python/hello.py new file mode 100755 index 0000000..0564ab7 --- /dev/null +++ b/python/hello.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# +# Sample Hello World! python script... +# + +import subprocess +import sys +import os + +animals = ["camel", "llama", "owl"] +fruit_color = { "apple":"red", "banana":"yellow"} +fruits = fruit_color.keys() +colors = fruit_color.items() +verinfo = subprocess.check_output(["git", "describe", "--abbrev=7", + "--dirty", "--always", "--tags"]) + +# Obligatory Hello World with some version info +print "Hello Python World! Version: " +verinfo + +# Show list of command line arguments +print "Command line args: ", +for i in sys.argv[1:]: + print " " + i, +print "" + +# Determine number of physical CPU sockets +if os.name == 'nt': + pass +else: + socketcount = subprocess.check_output(["bash","-c", + "(cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l)"]) + print "CPU socket count: ", socketcount + +# print out our animals array in reverse-sorted order +print "\nValue of animals array:" +for i in sorted(animals, reverse=True): + print "item = " + i + if (i == animals[0]): + print " Condition is TRUE, \"" +i+ "\" == " + animals[0] + else: + print " Condition is FALSE, \"" +i+ "\" != " + animals[0] + +# print our fruit_color dictionary (key/value pairs) +print "\nValue of fruit_color hash:" +for fruit,color in sorted(fruit_color.items(), reverse=True): + 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" + +# 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" + +# Let's manipulate PATH variable and then restore it +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." +os.environ['PATH'] = path_env_var +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..." +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:" +file = open("test.out", "r") +linenum = 1 +for line in file: + print "line "+str(linenum)+": "+line, + linenum += 1 +file.close() + +sys.exit(0) diff --git a/ruby/hello.rb b/ruby/hello.rb new file mode 100755 index 0000000..3a5d63c --- /dev/null +++ b/ruby/hello.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env ruby +# +# Hello Ruby World! +# + +animals = ["camel", "llama", "owl"] +fruit_color = { "apple" => "red", "banana" => "yellow" } + +verinfo = `git describe --abbrev=7 --dirty --always --tags` + +puts "Hello Ruby World! Version: #{verinfo}" +print "Command line args: " +ARGV.each do |arg| + print "#{arg} " +end +print "\n" + +# print out our animals array reverse sorted... +(animals.reverse).each do |i| + print "item = ", i, "\n" + if i == animals.first + print 'Condition is True, "camel" == ', i, "\n" + else + print 'Condition is False, "camel" != ', i, "\n" + end +end + +# print out our Ruby hash +fruit_color.each do |key, value| + print key, " = ", value, "\n" +end + +# Let's create the file test.out and write animals array to it... +file = File.new("test.out", "w") +animals.each do |i| + file.syswrite("#{i}\n") +end +file.close + +# Now open the file we wrote and read it back... +filelines = IO.readlines("test.out") +filelines.each do |i| + print i +end + diff --git a/sizeofchk/Makefile b/sizeofchk/Makefile new file mode 100644 index 0000000..f7acd45 --- /dev/null +++ b/sizeofchk/Makefile @@ -0,0 +1,40 @@ +# Makefile for Simple Sizeof Utility +# +# Created 2014-06-26 by Ed Braaten +# + +# Variables that may need tweaking... +COMPILER=gcc +#COMPILER=icc +#COMPILER=clang +CCOPTIONS=-O -Wall +INSTALLPATH=/usr/local/bin + +# These variables shouldn't need any tweaking +CCVERSION=`${COMPILER} --version | head -1` +BINARYNAME=sizeofchk-${COMPILER} +SHORT_SHA:=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") +PGM_VERSION=1.0 (git-$(SHORT_SHA)) + + +# Target to build the main program... +${BINARYNAME}: Makefile sizeofchk.c + @echo "#define COMPILEINFO \"${CCVERSION}\"" >sizeofchk.h + @echo "#define ARCHINFO \""`uname -m`"\"" >>sizeofchk.h + @echo "#define SYSINFO \""`uname -s`"\"" >>sizeofchk.h + @echo "#define RELEASEINFO \""`uname -r`"\"" >>sizeofchk.h + @echo "#define VERSION_STRING \"${PGM_VERSION}\"" >>sizeofchk.h + @echo "Header file created..." + ${COMPILER} ${CCOPTIONS} -o ${BINARYNAME} sizeofchk.c + chmod 755 ${BINARYNAME} + +install: + mkdir -p /usr/local/bin + cp ${BINARYNAME} ${INSTALLPATH} + chmod 755 ${INSTALLPATH}/${BINARYNAME} + +clean: + rm -f ${BINARYNAME} sizeofchk.h *.o + +tidy: + rm -f *.o diff --git a/sizeofchk/README.md b/sizeofchk/README.md new file mode 100644 index 0000000..365dc80 --- /dev/null +++ b/sizeofchk/README.md @@ -0,0 +1,4 @@ +sizeofchk +========= + +Utility to print out size in bits of basic types supported by your compiler. diff --git a/sizeofchk/sizeofchk.c b/sizeofchk/sizeofchk.c new file mode 100644 index 0000000..5fcc28b --- /dev/null +++ b/sizeofchk/sizeofchk.c @@ -0,0 +1,46 @@ +/* simple utility to print out sizeof values... +*/ + +#include +#include +#include "sizeofchk.h" /* generated by makefile */ + +static char version[] = VERSION_STRING; + + +int main() +{ + int (*funcptr)(); + + printf("Sizeof Utility by Ed Braaten - Version %s\n", version); + printf("Running on %s (%s %s)\n", ARCHINFO, SYSINFO, RELEASEINFO); + printf("Compiler version: '%s'\n\n", COMPILEINFO); + + printf(" sizeof(char) = %lu bits\n", sizeof(char) * 8); + printf(" sizeof(short) = %lu bits\n", sizeof(short) * 8); + printf(" sizeof(int) = %lu bits\n", sizeof(int) * 8); + printf(" sizeof(long int) = %lu bits\n", sizeof(long int) * 8); + printf(" sizeof(long) = %lu bits\n", sizeof(long) * 8); + printf(" sizeof(long long) = %lu bits\n", sizeof(long long) * 8); + printf(" sizeof(float) = %lu bits\n", sizeof(float) * 8); + printf(" sizeof(double) = %lu bits\n", sizeof(double) * 8); + printf(" sizeof(long double) = %lu bits\n", sizeof(long double) * 8); + printf(" sizeof(char *) = %lu bits\n", sizeof(char *) * 8); + printf(" sizeof((*)()) = %lu bits\n", sizeof(funcptr) * 8); + +#ifdef __SSE__ + printf("\nSSE types\n\n"); + printf(" sizeof(__m64) = %lu bits\n", sizeof(__m64) * 8); + printf(" sizeof(__m128) = %lu bits\n", sizeof(__m128) * 8); +#endif +#ifdef __clang__ + /* clang doesn't support __float128 */ +#else +#ifdef __SSE2__ + printf(" sizeof(__float128) = %lu bits\n", sizeof(__float128) * 8); +#endif + +#endif + printf("\n"); + return(0); +}