From: Chris Koeritz Date: Sat, 4 Feb 2012 20:10:16 +0000 (-0500) Subject: assorted examples being moved to the top. X-Git-Tag: 2.140.90~1640 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=a13cd5a85a0981acfd3702c4eaec9aeff3ed80da;p=feisty_meow.git assorted examples being moved to the top. --- diff --git a/examples/bashisms/fred_techniques.txt b/examples/bashisms/fred_techniques.txt new file mode 100644 index 00000000..c841a89c --- /dev/null +++ b/examples/bashisms/fred_techniques.txt @@ -0,0 +1,62 @@ +#!/bin/bash + +############## +# Name : fred_techniques +# Author : Chris Koeritz +# Rights : Copyright (C) 2010-$now by Author +############## +# Copyright (c) 2010-$now By Author. This script is free software; you can +# redistribute it and/or modify it under the terms of the simplified BSD +# license. See: http://www.opensource.org/licenses/bsd-license.php +# Please send updates for this code to: fred@gruntose.com -- Thanks, fred. +############## + +# this script is a collection of helpful bash practices that unfortunately +# sometimes slip my mind when i need them. it's intended to collect all the +# good bits so they don't slip away. feel free to re-use them in your own +# code as needed. + +############## + +# clean for loops in bash: + +for ((i=0; i < 5; i++)) do + echo $i +done + +############## + +# removing an array element +# --> only works on arrays that have no elements containing a space character. + +# define a 5 element array. +arr=(a b c d e) + +# remove element 2 (the 'c'). +removepoint=2 + +# set the array to slices of itself. +arr=(${arr[*]:0:$removepoint} ${arr[*]:(($removepoint+1))} ) + +# show the new contents. +echo ${arr[*]} +# shows: a b d e + +############## + +# store to a variable name by derefercing it. + +# shows how you can store into a variable when you are given only its name. +function store_to_named_var() +{ + local name="$1"; shift + eval ${name}=\(gorbachev "perestroikanator 12000" chernenko\) +} + +declare -a ted=(petunia "butter cup" smorgasbord) +echo ted is ${ted[@]} +store_to_named_var ted +echo ted is now ${ted[@]} + +############## + diff --git a/examples/bashisms/qs_handy_unix_examples.sh b/examples/bashisms/qs_handy_unix_examples.sh new file mode 100644 index 00000000..5293f3bb --- /dev/null +++ b/examples/bashisms/qs_handy_unix_examples.sh @@ -0,0 +1,220 @@ +#!/bin/bash + +# +# these great examples of handy unix tidbits were donated by "q. black". +# + +# list a directory tree +ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' + +# list directory sizes (biggest first) +du -h $(du -s * |sort -nr|awk '{print $2}') + +# this will sort a date field of the form: DD-MON-YYYY HH:MM:SS +sort +0.7 -1 +0.3M -0.6 +0 -0.2 +1 + +# this will sort a date field of the form: MON DD HH:MM:SS YYYY +sort +3 -4 +0M +1n + +# this will sort a date field of the form: MON DD HH:MM:SS +sort +0M +1n + +# this will sort a date field of the form: Date: Tue Feb 3 09:17:58 EST 2004 +sort +6 -7 +2M +3n +4 + +# display all lines from a certain line onward +start_line=132 +|awk "{if (NR >= ${start_line}){print \$0}}" + +# display all lines after a token +sed '1,/CUT HERE/d' + +# print the first and last lines +sed -n '1,1p;$,$p' + +# signal bash about a window size change +kill -winch $$ + +# show the date 1 year, 2 months and 3 days ago +date -v -1y -v -2m -v -3d + +# set the date back 1 year +sudo date $(date -v -1y +%Y%m%d%H%M) + +# output the standard date format for setting the time +# get the date +date -u +%Y%m%d%H%M.%S +# set the date +date -u (cut and paste from above) + +# convert one date format to another (output is in the current time zone) +old_date="Aug 27 15:24:33 2005 GMT" +new_date=$(date -j -f "%b %e %T %Y %Z" "${old_date}" +%D) +echo ${new_date} +# returns "08/27/05" + +# output the modification time of a file in different format +file= +date -j -f "%b %e %T %Y" "$(ls -lT ${file} |awk '{print $6,$7,$8,$9}')" + +# output the number of days until a certain date +target_date="Sep 2 15:20:20 2005 GMT" +target_seconds=$(date -j -f "%b %e %T %Y" +%s "${target_date}" 2>/dev/null) +diff_seconds=$(expr ${target_seconds} - $(date +%s)) +diff_days=$(expr ${diff_seconds} / 86400) +echo "${diff_days} day(s)" + +# these commands can be used to fill in missing times in a "uniq -c" count +# of times. +# output 24 hours in one minute increments +for h in $(jot -w %02d - 0 23 1); do + for m in $(jot -w %02d - 0 59 1); do + echo " 0 ${h}:${m}" + done +done +# sort them together, and remove any 0 counts if an count already exists +sort +1 +0rn out1 out2 |uniq -f 1 + +# output with w3m to get basic html word wrap +w3m -T "text/html" -dump -cols 72 < + This test verifies basic networking and that the ${product_short_name} + can reach it's default gateway. +EOF + +# another way to format text for output +fmt 72 <used = %ld\n", msg->used); +BIO_write(sc->log, jkwbuf, strlen(jkwbuf)+1); +free(jkwbuf); +} + +# rolling diff of a list of files (diff a & b, then b & c,...) +last= +for i in $(ls -1rt); do + if [ ! -z "${last}" ]; then + diff -u ${last} ${i} + fi + last=${i} +done + +# clearing and restoring chflags +file= +old_chflags=$(ls -lo ${file}|awk '{print $5}') +chflags 0 ${file} +# do whatever +if [ ."${old_chflags}" != ."-" ]; then + chflags ${old_chflags} ${file} +fi + +# way to do standard edits to files +file= +{ + # append line(s) after a line, "i" to insert before + echo '/www_recovery/a' + echo 'mithril ALL = (root) NOPASSWD: /usr/local/libexec/destroyer' + echo '.' + # modify a line + echo 'g/^xntpd_program=/s,^xntpd_program=.*$,xntpd_program="ntpd",' + # delete a line + echo 'g/^controls key secret =/d' + echo 'x!' +} | ex - ${file} + +# how to search for errors in the last 24 hours +# note that this command does not work quite right. The sort is off early +# in the year because the dates do not have the year. +# Also sed never sees the /CUT HERE/ when it is the first line. +(echo "$(date -v-24H "+%b %e %H:%M:%S") --CUT HERE--"; \ + zgrep -h "cookie" /var/log/messages*)|sort +0M| \ + sed '1,/CUT HERE/d' +# This version fixes those problems. It adds the file year to the date +# and puts a marker at the start of the list. +(echo "$(date -j -f "%s" 0 "+%Y %b %e %H:%M:%S") --ALWAYS FIRST--"; \ + echo "$(date -v-24H "+%Y %b %e %H:%M:%S") --CUT HERE--"; \ + for i in /var/log/messages*; do + year=$(ls -lT ${i}|awk '{print $9}') + zgrep -h "cookie" ${i}|while read line; do + echo "${year} ${line}" + done + done)|sort +0n +1M| sed '1,/CUT HERE/d' + +# process a list of quoted values +{ + # It tends to be easiest to use a 'here-document' to feed in the list. + # I prefer to have the list at the start instead of the end + cat </dev/null) + if [ ${#any_there[*]} -gt 0 ]; then + (( last = ${#any_there[@]} - 1 )) + JAVA_HOME="${any_there[$last]}" + fi + if [ ! -d "$JAVA_HOME" ]; then + # if no jdk, try a jre. + declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jre" 2>/dev/null) + if [ ${#any_there[*]} -gt 0 ]; then + (( last = ${#any_there[@]} - 1 )) + JAVA_HOME="${any_there[$last]}" + fi + fi +fi +# this should go last, since it changes the bin dir. +if [ ! -d "$JAVA_HOME" ]; then + # if that didn't work, try the location for mac os x. + JAVA_HOME=/Library/Java/Home + JAVA_BIN_PIECE=Commands +fi +# last thing is to tell them we couldn't find it. +if [ ! -d "$JAVA_HOME" ]; then + intuition_failure JAVA_HOME + unset JAVA_BIN_PIECE +fi + +############################ + +# intuit where we have our local eclipse. +if [ ! -d "$ECLIPSE_DIR" ]; then + export ECLIPSE_DIR=/usr/local/eclipse_jee +fi +if [ ! -d "$ECLIPSE_DIR" ]; then + ECLIPSE_DIR=$HOME/eclipse +fi +if [ ! -d "$ECLIPSE_DIR" ]; then + ECLIPSE_DIR=$HOME/apps/eclipse +fi +if [ ! -d "$ECLIPSE_DIR" ]; then +#uhhh, default on winders? + ECLIPSE_DIR="/c/Program Files/eclipse" +fi +if [ ! -d "$ECLIPSE_DIR" ]; then + ECLIPSE_DIR="/c/tools/eclipse" +fi +if [ ! -d "$ECLIPSE_DIR" ]; then + ECLIPSE_DIR="/d/tools/eclipse" +fi +if [ ! -d "$ECLIPSE_DIR" ]; then + ECLIPSE_DIR="/e/tools/eclipse" +fi +# final option is to whine. +if [ ! -d "$ECLIPSE_DIR" ]; then intuition_failure ECLIPSE_DIR; fi + +############################ + +# use the variables we just set in our path, and try to make them override +# any other paths to different versions. + +if [ ! -z "$JAVA_HOME" ]; then + export PATH=$JAVA_HOME/$JAVA_BIN_PIECE:$PATH +fi +if [ ! -z "$ECLIPSE_DIR" ]; then + export PATH=$ECLIPSE_DIR:$PATH +fi + +############################ + + diff --git a/examples/custom_overrides/readme.txt b/examples/custom_overrides/readme.txt new file mode 100644 index 00000000..554f9278 --- /dev/null +++ b/examples/custom_overrides/readme.txt @@ -0,0 +1,11 @@ + +this folder has some examples of how various people (or one person right now) +do their custom scripts. + +the folder can have alias files (ending in .alias) that are written in bash, +and it can also have shell scripts that are sourced into the main-line of +script initialization (any files ending in .sh). + +when you have some custom scripts you want to use, copy them from your own +folder to the $FEISTY_MEOW_GENERATED/custom directory. + diff --git a/examples/feisty_meow_startup/bashrc_grover b/examples/feisty_meow_startup/bashrc_grover new file mode 100644 index 00000000..6eda65dd --- /dev/null +++ b/examples/feisty_meow_startup/bashrc_grover @@ -0,0 +1,8 @@ +export LC_ALL=C +alias mc='mc -a' + +export PATH=$PATH:/home/QtPalmtop/j2me:/home/QtPalmtop/j2me/bin + +alias fredme='export HOME=/home/zaurus/fred ; export TMP=$HOME/.tmp ; source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh ; cd ' + + diff --git a/examples/feisty_meow_startup/bashrc_root b/examples/feisty_meow_startup/bashrc_root new file mode 100644 index 00000000..a29ec0b2 --- /dev/null +++ b/examples/feisty_meow_startup/bashrc_root @@ -0,0 +1,4 @@ +# added to root's ~/.bashrc, the fredme macro enables all the feisty_meow tools. + +alias fredme='source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh' + diff --git a/examples/feisty_meow_startup/bashrc_user b/examples/feisty_meow_startup/bashrc_user new file mode 100644 index 00000000..6c2b67f9 --- /dev/null +++ b/examples/feisty_meow_startup/bashrc_user @@ -0,0 +1,20 @@ + +# in addition to the .bashrc code that the operating system gives you, +# you can add this file to your ~/.bashrc if you want the feisty_meow scripts +# to be loaded up automatically. +# +# this is for normal users, not the root user! + +# note: it is useful to set your own NAME variable to identify who you are. +# the feisty_meow scripts will set up a bogus one for you otherwise. in your home +# directory's .bashrc, you could add something like this, for example: +# export NAME='Doodmodeus Q. Nornberton' + +# don't bother running our stuff for a dumb terminal since any echo +# can mess with an sftp or scp connection, apparently. similarly, we +# don't want any automatic startup stuff if we are running under PBS. +if [ "${TERM}" != "dumb" -a -z "$PBS_ENVIRONMENT" ]; then + # sets up the feisty_meow scripts, using the default locations for all scripts. + source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh +fi + diff --git a/examples/feisty_meow_startup/bashrc_user_windoz b/examples/feisty_meow_startup/bashrc_user_windoz new file mode 100644 index 00000000..46dce184 --- /dev/null +++ b/examples/feisty_meow_startup/bashrc_user_windoz @@ -0,0 +1,22 @@ + +# in addition to the .bashrc code that the operating system gives you, +# you should added this file to your ~/.bashrc if you want the feisty_meow scripts +# to be loaded up. +# +# you also must run bootstrap_shells.sh if you've never used feisty_meow before. + +# note: it is useful to set your own NAME variable to identify who you are. +# the feisty_meow scripts will set up a bogus one for you otherwise. in your home +# directory's .bashrc, you could add something like this, for example: +#export NAME='Curmudgeon J. Wankslausteen' + +#export TMP=/h/tmp + +# add in some useful paths for the local machine. +export PATH=/bin:$PATH:/c/utilities/emacs-23.2/bin:/c/tools/cvsnt:/c/utilities/Vim/vim71:/c/system/Perl/site/bin:/c/system/Perl/bin:/c/tools/doxygen/bin:/c/tools/graphviz/Graphviz/bin + +if [ "${TERM}" != "dumb" -a -z "$PBS_ENVIRONMENT" ]; then + source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh +fi + + diff --git a/examples/legacy/template.pl b/examples/legacy/template.pl new file mode 100644 index 00000000..ebae784d --- /dev/null +++ b/examples/legacy/template.pl @@ -0,0 +1,596 @@ +#!/usr/bin/perl + +############################################################################### +# # +# Name : template # +# Author : Chris Koeritz # +# Rights : Copyright (C) 1996-$now by Author # +# # +# Purpose: # +# # +# Attempts to pre-instantiate C++ templates to work-around C++ compilers # +# that don't support templates (a rare breed, these days). # +# # +############################################################################### +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; either version 2 of the License or (at your option) # +# any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a # +# version of the License. Please send any updates to "fred@gruntose.com". # +############################################################################### + +# this was a majestic abortive attempt to create a template instantiator for +# compilers that do not possess templates, but which do support some subset +# of C++. This was necessary at the time, due to our firmware compiler's +# limitations. This processor never totally worked, although it did produce +# some interesting compilable code. Might be useful as a demo or maybe just +# as a warning to avoid brain-damaged C++ compilers. + +# to do: +# maintain statistics about placement in file for error resolution. + +# limitations so far: +# +# the word "template" must be the first word on the line. +# +# the type to instantiate must be one word (like charstar, not char *). +# +# templates must follow the form templateName without +# any spaces between the angle brackets. + +# flag to enable debugging print outs. +$DEBUG_TEMPLATIZER = 1; +#$DEBUG_TEMPLATIZER = 0; + +# array to store instance types to convert to +@instance_type_buffer = (); +# flag for checking read from file option +$f_option = 0; +$d_option = 0; + +if ($#ARGV < 1) { + die(" + The template instantiater supports an optional directory path as the first + parameter (preceded by a -d with no spaces in between the d and the + directory name) in which to store the generated templates, and then + requires the instantiation type as the next argument (or a file + specification preceded by -f), and a list of files as the last + arguments. + The files will be scanned for templates and those templates will be + instantiated in the type(s) specified. + Examples: + perl template.pl char istring.h torpedo.h + perl template.pl -f instance.txt matrix.h + perl template.pl -d. -f instance.txt function.h data_src.h + perl template.pl -dfirm_src\library\basis -f instance.txt amorph.h\n"); +} + +# Check directory option +if (grep(/^\s*-d/, @ARGV)) { + $d_option = 1; + $d_dir = @ARGV[0]; +# print $d_dir, "\n"; + shift; +} + + +# Check to see if user used a file to specify instantiation types +if (grep(/^\s*-f/, @ARGV)) { + $f_option = 1; + shift; + $types_file = @ARGV[0]; + +# Open instantiation type file to read from + open(TYPES_FILE, "<$types_file") + || die("couldn't open file $types_file for reading"); + +# Read in all the different types to instantiate +# Create instance_type list + @tp = ; + while (@tp) { + local($line) = @tp; + chop $line; + push(@instance_type_buffer, $line); + shift @tp; + } + shift @ARGV; + &instantiate_templates(@ARGV); + exit; +} + +&instantiate_templates(@ARGV); +exit; + +# +# driver of the instantiation process. +# +sub instantiate_templates { + if (!$f_option) { + # grab the user's desired instance type. + $instance_type = @_[0]; + push(@instance_type_buffer, $instance_type); + print "Instantiation type is \"$instance_type\".\n"; + # jump over the instance type to look at the filenames. + shift; + } + + local($i) = 0; + foreach $filename (@_) { + open(INPUT_FILE, "<$filename") + || die("couldn't open file $filename for reading"); + # create an output name for the instance. + $out_filename = &make_output_name($filename); + if ($DEBUG_TEMPLATIZER) { +# print "out file is ", $out_filename, "\n"; + } + local($index) = $i + 1; + print "Instantiating file[$index] as $out_filename.\n"; + # now try opening our output file. + open(OUTPUT_FILE, ">$out_filename") + || die("couldn't open file $filename for writing"); + # grab the current file into an array. + + @file_array = ; + @start_template = @file_array; + @stop_template = @file_array; + # process the file's contents as a manipulable array. + while (@file_array) { + local($line) = shift @file_array; + if (grep(/^\s*template/, $line)) { + @start_template = @file_array; + + # iterate through all the instance types for each template + foreach $instance_type (@instance_type_buffer) { + @file_array = @start_template; + &snag_place_holder($line); + &snag_object_name; + &absorb_until_matched_block; + &replace_place_holder; + &dump_the_buffer; + print OUTPUT_FILE "\n"; + } + } elsif (grep(/\w+<\w+>/, $line)) { + local(@pieces) = split(/\s/, $line); + foreach $piece (@pieces) { + local($prefix) = ""; + # special case for separating function name from templated first + # parameter to it. + if (grep(/\(\w+/, $piece)) { $piece = &special_mangle($piece); } + print OUTPUT_FILE "$prefix$piece "; + } + print OUTPUT_FILE "\n"; + } else { + print OUTPUT_FILE $line; + } + } + $i++; + } +} + +# +# generates an output name from the filename to be translated. +# +sub make_output_name { + local($out_filename) = @_[0]; + local($d_dir_temp) = $d_dir; +# print "OUTFILE NAME: ",$out_filename,"\n"; + # break down the filename at the slashes. + local(@split_filename) = split(/[\\\/]/, $out_filename); + # take the basename of the list of names. + $out_filename = $split_filename[$#split_filename]; + local($hold_filename) = $out_filename; + if (grep(!/\.cpp$/i, $out_filename) && grep(!/\.h$/i, $out_filename) + && grep(!/\.c$/i, $out_filename) && grep(!/\.h$/i, $out_filename) ) { + die("filename @_[0] not recognized as a C++ code file."); + } + # makes an instance of the file in a directory named after the instance type + # that is located under the current directory. + + $d_dir_temp = join('/',$d_dir, $hold_filename); + if ($d_option) { + $d_dir_temp =~ s/-d//i; + @split_filename = split(/[\\\/]/, $d_dir_temp); +# exit; + } + +# try to create dir using the deepest dir given in filename input + + local($y) = 0; + foreach (@split_filename) { $y++; } + + local($x) = 0; + local($ret) = 0; + local($dirs) = 0; + + if ($y >= 2) { + foreach (@split_filename) { + if ((($x > 0) && ($x < $y-1)) || (($d_option) && ($x < $y-1))) { + if (!$dirs) { $dirs = @split_filename[$x]; } + else { $dirs = $dirs."/".@split_filename[$x]; } +# print "Creating... ",$dirs,"\n"; + $ret = mkdir($dirs, 0777); + if (!ret) { die("a directory named $instance_dir could not be made."); } + } + $x++; + } + $out_filename = $dirs."/".$hold_filename; + } + else { $out_filename = "template/".$hold_filename; + local($instance_dir) = "template"; + $ret = mkdir($instance_dir, 0777); + if (!ret) { die("a directory named $instance_dir could not be made."); } + } +# print $out_filename, "\n"; + +# local($instance_dir) = @split_filename[$x-2]; +# creates the directory. +# local($ret) = mkdir($instance_dir, 0777); +# if (!ret) { die("a directory named $instance_dir could not be made."); } + + $out_filename; # return the new name. +} + +# +# grabs the name of the placeholder type that will be replaced by +# the template instantiation type. +# +sub snag_place_holder { + $place_holder = @_[0]; + chop $place_holder; + + local(@pieces) = split(/>\s*/, $place_holder, 2); + + # send back the parts not involved in the template statement. + if (length($pieces[1])) { + unshift(@file_array, $pieces[1]."\n"); + } + $place_holder = $pieces[0]; + $place_holder =~ s/\s*template\s+"])/\1 \2 \3/; + local(@broken_up) = split(/ /, $temp); + # strip off the punctuation from the name. + local($incl_prefix) = @broken_up[1]; + $incl_prefix =~ s/["<](.*)[">]/\1/; + $incl_prefix =~ s/\s//g; + # return if it's not a code file being included. + if (!grep(/.cpp/i, $incl_prefix)) { print OUTPUT_FILE $line, "\n"; return; } + # strip to just the name without the ending. + $incl_prefix =~ s/\.cpp$//i; + # now get the name of the file we're processing. + local($file_prefix) = $filename; + # return if it's not a header file being examined. + if (!grep(/.h/i, $file_prefix)) { print OUTPUT_FILE $line, "\n"; return; } + # strip off the extension. + $file_prefix =~ s/\.h$//i; + # return if the names aren't equivalent--this means the include doesn't + # refer to our new templated form of the code file. + if ($incl_prefix ne $file_prefix) { print OUTPUT_FILE $line, "\n"; return FALSE; } + # dump out a message about the removal. + $line =~ s/^\s*//; + print OUTPUT_FILE "/* removed unneeded template inclusion: $line */\n"; +} + +# +# extracts lines from the file until the curly brackets are matched up +# at level 0. +# +sub absorb_until_matched_block { + $bracket_level = 0; + $end_absorb = 0; + @template_buffer = (); + $hit_one=0; + while (@file_array) { + local($line) = shift @file_array; + &look_for_curlies($line); + if (($hit_one && ($bracket_level == 0)) || $end_absorb) { return; } + } +} + +# +# examines the parameters passed in for curly brackets and changes the +# counter if they are found. +# +sub look_for_curlies { +# $hit_one = 0; # records whether a bracket was found or not. + local($line) = @_[0]; + @word = (); + foreach $char (split(//, $line)) { + if ($char eq '{') { + $hit_one = 1; + $bracket_level++; + } elsif ($char eq '}') { + $hit_one = 1; + $bracket_level--; + } elsif (($char eq ';') && ($hit_one==0)) { + $end_absorb = 1; + } + + + if ($DEBUG_TEMPLATIZER) { +# print "~$char~ "; + } + push(@word, $char); + if (grep(!/\w/, $char)) { + # don't split yet if it's a possible template char. + if (grep(!/[<>]/, $char)) { + local($real_word) = join("", @word); + if ($DEBUG_TEMPLATIZER) { +# print "adding a word $real_word\n"; + } + push(@template_buffer, "$real_word"); + @word = (); + } + } + } +} + +# +# this goes through the buffer and replaces all occurrences of the name to +# replace with the instance name. +# +sub replace_place_holder { + @new_template_buffer = @template_buffer; + @template_buffer = (); + + foreach $i (0 .. $#new_template_buffer) { + $word = $new_template_buffer[$i]; +# if ($DEBUG_TEMPLATIZER) { +# print "<$i $word> "; +# $old = $word; +# } + + # replace a templated combination with the mangled version. + $word =~ s/^${object_name}<${instance_type}>/${mangled_name}/; + +# if ($DEBUG_TEMPLATIZER) { +# if ($old ne $word) {print "1 ... changed to $word.\n"; $old = $word; } +# } + + if (grep(/^\w+<\w+>/, $word)) { + # replace some other template with our stuff if we can. + $word = &special_mangle($word); + } + +# if ($DEBUG_TEMPLATIZER) { +# if ($old ne $word) {print "2 ... changed to $word.\n"; $old = $word; } +# } + + # replace the object's name with its mangled form. + $word =~ s/^${object_name}/${mangled_name}/; + +# if ($DEBUG_TEMPLATIZER) { +# if ($old ne $word) {print "3... changed to $word.\n"; $old = $word; } +# } + + # replace the place holder with the instantiation type. + $word =~ s/^${place_holder}/${instance_type}/; + +# if ($DEBUG_TEMPLATIZER) { +# if ($old ne $word) {print "4... changed to $word.\n"; $old = $word; } +# } + + push(@template_buffer, $word); + } +} + +# +# processes a general template usage, in the form X, where either +# X or Y are not ones that we think we need to replace. it is assumed +# that it's safe to use the mangled form of the template. +# +sub special_mangle { + local($word) = @_[0]; + # split the template form into pieces. + local(@pieces) = split(/[<>]/, $word, 2); + + $pieces[1] =~ s/${place_holder}/${instance_type}/; + $pieces[1] =~ s/>//; + # hold onto the real instance type. + local($hold_instance) = $instance_type; + $instance_type = $pieces[1]; + # mangle the name in the template usage line. + local($hold_mangled) = &mangle_name($pieces[0]); + # restore the original instance type. + $instance_type = $hold_instance; + # returns the new mangled form. + $hold_mangled; +} + +# +# prints out the buffer we've accumulated to the output file. +# +sub dump_the_buffer { + print OUTPUT_FILE @template_buffer; +} + +# +# processes a class declaration and sets the object name for future use. +# +sub match_class_declaration { + local($next_line) = @_[0]; +# too strict! +# if (grep(!/class\s.*\w+$/, $next_line) +# && grep(!/class\s.*\w+\s*\{/, $next_line) +# && grep(!/struct\s.*\w+$/, $next_line) +# && grep(!/struct\s.*\w+\s*\{/, $next_line)) { +# return 0; +# } + + if (grep(!/class\s+\w+/, $next_line) && grep(!/struct\s+\w+/, $next_line) ) { + return 0; + } + + if ($DEBUG_TEMPLATIZER) { +# print "matched class decl in $next_line\n"; + } + + if (grep(/class\s+\w+.*:/, $next_line) + || grep(/struct\s+\w+.*:/, $next_line)) { + # parses an inheriting class decl. + if ($DEBUG_TEMPLATIZER) { +# print "in inheritance case on $next_line\n"; + } + local(@pieces) = split(/:/, $next_line, 2); + # push the rest of the line back into the input array. + if ($DEBUG_TEMPLATIZER) { +# print "going to unshift $pieces[1]...\n"; + } + unshift(@file_array, ": ".$pieces[1]." "); + $next_line = $pieces[0]; + } elsif (grep(/class\s.*\w+\s*\{/, $next_line) + || grep(/struct\s.*\w+\s*\{/, $next_line)) { + # parses a non-inheriting declaration with bracket on same line. + if ($DEBUG_TEMPLATIZER) { +# print "in special case on $next_line\n"; + } + # special case for continued stuff on same line. + local(@pieces) = split(/{/, $next_line, 2); + # push the rest of the line back into the input array. + unshift(@file_array, " { ".$pieces[1]." "); + $next_line = $pieces[0]; + } + if ($DEBUG_TEMPLATIZER) { +# print "matched class declaration... $next_line\n"; + } + local(@pieces) = split(/\s/, $next_line); + $object_name = $pieces[$#pieces]; + $mangled_name = &mangle_name($object_name); + foreach $posn (0 .. $#pieces - 1) { print OUTPUT_FILE "$pieces[$posn] "; } + print OUTPUT_FILE "$mangled_name\n"; + 1; +} + +# +# processes the implementation of a class member and sets the object +# name for future use. +# +sub match_class_member_definition { + local($next_line) = @_[0]; + local($junk); + if (grep(!/\w+<\w+>::/, $next_line)) { + return 0; + } + if ($DEBUG_TEMPLATIZER) { +# print "matched class member definition... $next_line\n"; + } + local(@pieces) = split(/>::/, $next_line, 2); + # checks for spaces in the first part of the split. if there is one, + # it means we don't have a simple object thing. + if (grep(/\s/, $pieces[0])) { + if ($DEBUG_TEMPLATIZER) { +# print "matched a space in the first part of supposed object name... $pieces[0]\n"; + } + if (grep(/^\w+<\w+>/, $pieces[0])) { + if ($DEBUG_TEMPLATIZER) { +# print "matched a template usage in first part of name..."; + } + # replace some other template with our stuff if we can. + $pieces[0] = &special_mangle($pieces[0]); + } + if ($DEBUG_TEMPLATIZER) { +# print "now our first bit is: $pieces[0]\n"; + } + local(@new_pieces) = split(/ /, $pieces[0]); + $pieces[0] = $new_pieces[$#new_pieces]; + foreach $posn (0 .. $#new_pieces - 1) { + $new_pieces[$posn] =~ s/${place_holder}/${instance_type}/g; + print OUTPUT_FILE "$new_pieces[$posn] "; + } + } + unshift(@file_array, "::\n".$pieces[1]."\n"); + $object_name = $pieces[0]; + $object_name =~ s/(\W*)(\w+)<(\w+)/\2/; + if (length($1)) { print OUTPUT_FILE "$1"; } + if ($3 ne $place_holder) { + die("The placeholder does not match on this line: $next_line"); + } + $mangled_name = &mangle_name($object_name); + print OUTPUT_FILE "$mangled_name\n"; + 1; # return success. +} + +# +# processes a function template by making sure it fits the format and +# then setting up the variables for the replacement. since function templates +# are so simple, the object name is not changed; only the place_holder is +# changed to the instance type. +# +sub match_function_definition { + local($next_line) = @_[0]; + + if (grep(!/^\s*\w+\s+.*/, $next_line) ) { + if ($DEBUG_TEMPLATIZER) { + print "failed on funcdef for ", $next_line, "!\n"; + } + return 0; + } + +# old broken code:... +# if (grep(!/^\s*\w+\s+.*\(.*\)\s*/, $next_line) ) { +#print "failed on funcdef for ", $next_line, "!\n"; +# return 0; +# } + +# if ($DEBUG_TEMPLATIZER) { +# print "matched function definition on $next_line\n"; +# } + +# if ($DEBUG_TEMPLATIZER) { +# print "stuffing back into the file array $next_line.\n"; +# } + # put the line back because it's nearly right for being instantiated. + unshift(@file_array, "inline ".$next_line."\n"); + # come up with a very rare name that will not be matched in the text. + $object_name = "hogga_wogga_nunky_budget_weeny_teeny_kahini_beany"; + $mangled_name = &mangle_name($object_name); + 1; # return a success. +} diff --git a/examples/multimedia/wma2mp3.sh b/examples/multimedia/wma2mp3.sh new file mode 100644 index 00000000..a0224ef3 --- /dev/null +++ b/examples/multimedia/wma2mp3.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# wma to mp3 script by mtron +# from http://ubuntuforums.org/showthread.php?t=37793 + +# have found that soundconverter package on ubuntu works on more types +# and is a bit more polished, but mtron's script kicks ass anyhow, if all +# you need is wma -> mp3 conversions. +# --fred hamster + +zenity --info \ + --text="this script converts all wma files in the current folder +to mp3s and puts them in the folder output + +all lame command line options can be set in the next step. + +usage: + lame -m s: for stereo mp3 output + lame -m s V 3-4-5: for stereo mp3 output with VBR" + +# Dialog box to choose output quality +FORMAT=$(zenity --list --title="Choose mp3 output quality" --radiolist --column="Check" --column="Quality (editable)" --editable "" "lame -m s" "" "lame -m s -V 3" "" "lame -m s -V 4" "" "lame -m s -V 5") + +if [ $FORMAT -eq ""]; then +zenity --error --text="mp3 output quality not defined or no wma file found + +usage: + lame -m s: for stereo mp3 output + lame -m s V 3-4-5: for stereo mp3 output with VBR + +type: lame --longhelp +for all command line options " +exit 1 +fi + +mkdir -p output +cp *.wma output +cd output + +# How many files to make the progress bar +PROGRESS=0 +NUMBER_OF_FILES=$(find -iname "*.wma") +let "INCREMENT=100/$NUMBER_OF_FILES" + +#remove spaces +(for i in *.wma; do mv "$i" $(echo $i | tr ' ' '_'); done + +#remove uppercase +for i in *.[Ww][Mm][Aa]; do mv "$i" $(echo $i | tr '[A-Z]' '[a-z]'); done + +#Rip with Mplayer / encode with LAME +for i in *.wma ; do +echo "$PROGRESS"; +echo "# Re-Coding $i"; +mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader $i && $FORMAT audiodump.wav -o $i; +let "PROGRESS+=$INCREMENT" +done + +#convert file names +for i in *.wma; do mv "$i" "$(basename "$i" .wma).mp3"; +done + +rm audiodump.wav +let "PROGRESS+=$INCREMENT" +) | zenity --progress --title "$Recoding...encoding..." --percentage=0 + + diff --git a/examples/os_related/OS_crusher.bat b/examples/os_related/OS_crusher.bat new file mode 100644 index 00000000..8adabbea --- /dev/null +++ b/examples/os_related/OS_crusher.bat @@ -0,0 +1,7 @@ + + +:top +start "eep" "%0" +start "op" "%0" + +goto :top diff --git a/examples/os_related/OS_crusher.sh b/examples/os_related/OS_crusher.sh new file mode 100644 index 00000000..7c1683fa --- /dev/null +++ b/examples/os_related/OS_crusher.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +while true; do + $0 & + $0 & +done + diff --git a/examples/os_related/example_registry_ops.sh b/examples/os_related/example_registry_ops.sh new file mode 100644 index 00000000..3480d948 --- /dev/null +++ b/examples/os_related/example_registry_ops.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# an example of using the reg.exe tool on windows to find some things in +# the registry. +# this happens to look in the registry for PuTTY keys for a set of named +# displays. + +declare ip_array=(zorba-1 zorba-2 zorba-3 zorba-4 zorba-5) + +for i in ${ip_array[*]}; do + target=${i} + echo "display is $target" + reg query 'HKCU\Software\SimonTatham\PuTTY\SshHostKeys' /v "rsa2@22:$target" +done + + diff --git a/scripts/examples/bashisms/fred_techniques.txt b/scripts/examples/bashisms/fred_techniques.txt deleted file mode 100644 index c841a89c..00000000 --- a/scripts/examples/bashisms/fred_techniques.txt +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -############## -# Name : fred_techniques -# Author : Chris Koeritz -# Rights : Copyright (C) 2010-$now by Author -############## -# Copyright (c) 2010-$now By Author. This script is free software; you can -# redistribute it and/or modify it under the terms of the simplified BSD -# license. See: http://www.opensource.org/licenses/bsd-license.php -# Please send updates for this code to: fred@gruntose.com -- Thanks, fred. -############## - -# this script is a collection of helpful bash practices that unfortunately -# sometimes slip my mind when i need them. it's intended to collect all the -# good bits so they don't slip away. feel free to re-use them in your own -# code as needed. - -############## - -# clean for loops in bash: - -for ((i=0; i < 5; i++)) do - echo $i -done - -############## - -# removing an array element -# --> only works on arrays that have no elements containing a space character. - -# define a 5 element array. -arr=(a b c d e) - -# remove element 2 (the 'c'). -removepoint=2 - -# set the array to slices of itself. -arr=(${arr[*]:0:$removepoint} ${arr[*]:(($removepoint+1))} ) - -# show the new contents. -echo ${arr[*]} -# shows: a b d e - -############## - -# store to a variable name by derefercing it. - -# shows how you can store into a variable when you are given only its name. -function store_to_named_var() -{ - local name="$1"; shift - eval ${name}=\(gorbachev "perestroikanator 12000" chernenko\) -} - -declare -a ted=(petunia "butter cup" smorgasbord) -echo ted is ${ted[@]} -store_to_named_var ted -echo ted is now ${ted[@]} - -############## - diff --git a/scripts/examples/bashisms/qs_handy_unix_examples.sh b/scripts/examples/bashisms/qs_handy_unix_examples.sh deleted file mode 100644 index 5293f3bb..00000000 --- a/scripts/examples/bashisms/qs_handy_unix_examples.sh +++ /dev/null @@ -1,220 +0,0 @@ -#!/bin/bash - -# -# these great examples of handy unix tidbits were donated by "q. black". -# - -# list a directory tree -ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' - -# list directory sizes (biggest first) -du -h $(du -s * |sort -nr|awk '{print $2}') - -# this will sort a date field of the form: DD-MON-YYYY HH:MM:SS -sort +0.7 -1 +0.3M -0.6 +0 -0.2 +1 - -# this will sort a date field of the form: MON DD HH:MM:SS YYYY -sort +3 -4 +0M +1n - -# this will sort a date field of the form: MON DD HH:MM:SS -sort +0M +1n - -# this will sort a date field of the form: Date: Tue Feb 3 09:17:58 EST 2004 -sort +6 -7 +2M +3n +4 - -# display all lines from a certain line onward -start_line=132 -|awk "{if (NR >= ${start_line}){print \$0}}" - -# display all lines after a token -sed '1,/CUT HERE/d' - -# print the first and last lines -sed -n '1,1p;$,$p' - -# signal bash about a window size change -kill -winch $$ - -# show the date 1 year, 2 months and 3 days ago -date -v -1y -v -2m -v -3d - -# set the date back 1 year -sudo date $(date -v -1y +%Y%m%d%H%M) - -# output the standard date format for setting the time -# get the date -date -u +%Y%m%d%H%M.%S -# set the date -date -u (cut and paste from above) - -# convert one date format to another (output is in the current time zone) -old_date="Aug 27 15:24:33 2005 GMT" -new_date=$(date -j -f "%b %e %T %Y %Z" "${old_date}" +%D) -echo ${new_date} -# returns "08/27/05" - -# output the modification time of a file in different format -file= -date -j -f "%b %e %T %Y" "$(ls -lT ${file} |awk '{print $6,$7,$8,$9}')" - -# output the number of days until a certain date -target_date="Sep 2 15:20:20 2005 GMT" -target_seconds=$(date -j -f "%b %e %T %Y" +%s "${target_date}" 2>/dev/null) -diff_seconds=$(expr ${target_seconds} - $(date +%s)) -diff_days=$(expr ${diff_seconds} / 86400) -echo "${diff_days} day(s)" - -# these commands can be used to fill in missing times in a "uniq -c" count -# of times. -# output 24 hours in one minute increments -for h in $(jot -w %02d - 0 23 1); do - for m in $(jot -w %02d - 0 59 1); do - echo " 0 ${h}:${m}" - done -done -# sort them together, and remove any 0 counts if an count already exists -sort +1 +0rn out1 out2 |uniq -f 1 - -# output with w3m to get basic html word wrap -w3m -T "text/html" -dump -cols 72 < - This test verifies basic networking and that the ${product_short_name} - can reach it's default gateway. -EOF - -# another way to format text for output -fmt 72 <used = %ld\n", msg->used); -BIO_write(sc->log, jkwbuf, strlen(jkwbuf)+1); -free(jkwbuf); -} - -# rolling diff of a list of files (diff a & b, then b & c,...) -last= -for i in $(ls -1rt); do - if [ ! -z "${last}" ]; then - diff -u ${last} ${i} - fi - last=${i} -done - -# clearing and restoring chflags -file= -old_chflags=$(ls -lo ${file}|awk '{print $5}') -chflags 0 ${file} -# do whatever -if [ ."${old_chflags}" != ."-" ]; then - chflags ${old_chflags} ${file} -fi - -# way to do standard edits to files -file= -{ - # append line(s) after a line, "i" to insert before - echo '/www_recovery/a' - echo 'mithril ALL = (root) NOPASSWD: /usr/local/libexec/destroyer' - echo '.' - # modify a line - echo 'g/^xntpd_program=/s,^xntpd_program=.*$,xntpd_program="ntpd",' - # delete a line - echo 'g/^controls key secret =/d' - echo 'x!' -} | ex - ${file} - -# how to search for errors in the last 24 hours -# note that this command does not work quite right. The sort is off early -# in the year because the dates do not have the year. -# Also sed never sees the /CUT HERE/ when it is the first line. -(echo "$(date -v-24H "+%b %e %H:%M:%S") --CUT HERE--"; \ - zgrep -h "cookie" /var/log/messages*)|sort +0M| \ - sed '1,/CUT HERE/d' -# This version fixes those problems. It adds the file year to the date -# and puts a marker at the start of the list. -(echo "$(date -j -f "%s" 0 "+%Y %b %e %H:%M:%S") --ALWAYS FIRST--"; \ - echo "$(date -v-24H "+%Y %b %e %H:%M:%S") --CUT HERE--"; \ - for i in /var/log/messages*; do - year=$(ls -lT ${i}|awk '{print $9}') - zgrep -h "cookie" ${i}|while read line; do - echo "${year} ${line}" - done - done)|sort +0n +1M| sed '1,/CUT HERE/d' - -# process a list of quoted values -{ - # It tends to be easiest to use a 'here-document' to feed in the list. - # I prefer to have the list at the start instead of the end - cat </dev/null) - if [ ${#any_there[*]} -gt 0 ]; then - (( last = ${#any_there[@]} - 1 )) - JAVA_HOME="${any_there[$last]}" - fi - if [ ! -d "$JAVA_HOME" ]; then - # if no jdk, try a jre. - declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jre" 2>/dev/null) - if [ ${#any_there[*]} -gt 0 ]; then - (( last = ${#any_there[@]} - 1 )) - JAVA_HOME="${any_there[$last]}" - fi - fi -fi -# this should go last, since it changes the bin dir. -if [ ! -d "$JAVA_HOME" ]; then - # if that didn't work, try the location for mac os x. - JAVA_HOME=/Library/Java/Home - JAVA_BIN_PIECE=Commands -fi -# last thing is to tell them we couldn't find it. -if [ ! -d "$JAVA_HOME" ]; then - intuition_failure JAVA_HOME - unset JAVA_BIN_PIECE -fi - -############################ - -# intuit where we have our local eclipse. -if [ ! -d "$ECLIPSE_DIR" ]; then - export ECLIPSE_DIR=/usr/local/eclipse_jee -fi -if [ ! -d "$ECLIPSE_DIR" ]; then - ECLIPSE_DIR=$HOME/eclipse -fi -if [ ! -d "$ECLIPSE_DIR" ]; then - ECLIPSE_DIR=$HOME/apps/eclipse -fi -if [ ! -d "$ECLIPSE_DIR" ]; then -#uhhh, default on winders? - ECLIPSE_DIR="/c/Program Files/eclipse" -fi -if [ ! -d "$ECLIPSE_DIR" ]; then - ECLIPSE_DIR="/c/tools/eclipse" -fi -if [ ! -d "$ECLIPSE_DIR" ]; then - ECLIPSE_DIR="/d/tools/eclipse" -fi -if [ ! -d "$ECLIPSE_DIR" ]; then - ECLIPSE_DIR="/e/tools/eclipse" -fi -# final option is to whine. -if [ ! -d "$ECLIPSE_DIR" ]; then intuition_failure ECLIPSE_DIR; fi - -############################ - -# use the variables we just set in our path, and try to make them override -# any other paths to different versions. - -if [ ! -z "$JAVA_HOME" ]; then - export PATH=$JAVA_HOME/$JAVA_BIN_PIECE:$PATH -fi -if [ ! -z "$ECLIPSE_DIR" ]; then - export PATH=$ECLIPSE_DIR:$PATH -fi - -############################ - - diff --git a/scripts/examples/custom_overrides/readme.txt b/scripts/examples/custom_overrides/readme.txt deleted file mode 100644 index 554f9278..00000000 --- a/scripts/examples/custom_overrides/readme.txt +++ /dev/null @@ -1,11 +0,0 @@ - -this folder has some examples of how various people (or one person right now) -do their custom scripts. - -the folder can have alias files (ending in .alias) that are written in bash, -and it can also have shell scripts that are sourced into the main-line of -script initialization (any files ending in .sh). - -when you have some custom scripts you want to use, copy them from your own -folder to the $FEISTY_MEOW_GENERATED/custom directory. - diff --git a/scripts/examples/feisty_meow_startup/bashrc_grover b/scripts/examples/feisty_meow_startup/bashrc_grover deleted file mode 100644 index 6eda65dd..00000000 --- a/scripts/examples/feisty_meow_startup/bashrc_grover +++ /dev/null @@ -1,8 +0,0 @@ -export LC_ALL=C -alias mc='mc -a' - -export PATH=$PATH:/home/QtPalmtop/j2me:/home/QtPalmtop/j2me/bin - -alias fredme='export HOME=/home/zaurus/fred ; export TMP=$HOME/.tmp ; source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh ; cd ' - - diff --git a/scripts/examples/feisty_meow_startup/bashrc_root b/scripts/examples/feisty_meow_startup/bashrc_root deleted file mode 100644 index a29ec0b2..00000000 --- a/scripts/examples/feisty_meow_startup/bashrc_root +++ /dev/null @@ -1,4 +0,0 @@ -# added to root's ~/.bashrc, the fredme macro enables all the feisty_meow tools. - -alias fredme='source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh' - diff --git a/scripts/examples/feisty_meow_startup/bashrc_user b/scripts/examples/feisty_meow_startup/bashrc_user deleted file mode 100644 index 6c2b67f9..00000000 --- a/scripts/examples/feisty_meow_startup/bashrc_user +++ /dev/null @@ -1,20 +0,0 @@ - -# in addition to the .bashrc code that the operating system gives you, -# you can add this file to your ~/.bashrc if you want the feisty_meow scripts -# to be loaded up automatically. -# -# this is for normal users, not the root user! - -# note: it is useful to set your own NAME variable to identify who you are. -# the feisty_meow scripts will set up a bogus one for you otherwise. in your home -# directory's .bashrc, you could add something like this, for example: -# export NAME='Doodmodeus Q. Nornberton' - -# don't bother running our stuff for a dumb terminal since any echo -# can mess with an sftp or scp connection, apparently. similarly, we -# don't want any automatic startup stuff if we are running under PBS. -if [ "${TERM}" != "dumb" -a -z "$PBS_ENVIRONMENT" ]; then - # sets up the feisty_meow scripts, using the default locations for all scripts. - source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh -fi - diff --git a/scripts/examples/feisty_meow_startup/bashrc_user_windoz b/scripts/examples/feisty_meow_startup/bashrc_user_windoz deleted file mode 100644 index 46dce184..00000000 --- a/scripts/examples/feisty_meow_startup/bashrc_user_windoz +++ /dev/null @@ -1,22 +0,0 @@ - -# in addition to the .bashrc code that the operating system gives you, -# you should added this file to your ~/.bashrc if you want the feisty_meow scripts -# to be loaded up. -# -# you also must run bootstrap_shells.sh if you've never used feisty_meow before. - -# note: it is useful to set your own NAME variable to identify who you are. -# the feisty_meow scripts will set up a bogus one for you otherwise. in your home -# directory's .bashrc, you could add something like this, for example: -#export NAME='Curmudgeon J. Wankslausteen' - -#export TMP=/h/tmp - -# add in some useful paths for the local machine. -export PATH=/bin:$PATH:/c/utilities/emacs-23.2/bin:/c/tools/cvsnt:/c/utilities/Vim/vim71:/c/system/Perl/site/bin:/c/system/Perl/bin:/c/tools/doxygen/bin:/c/tools/graphviz/Graphviz/bin - -if [ "${TERM}" != "dumb" -a -z "$PBS_ENVIRONMENT" ]; then - source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh -fi - - diff --git a/scripts/examples/legacy/template.pl b/scripts/examples/legacy/template.pl deleted file mode 100644 index ebae784d..00000000 --- a/scripts/examples/legacy/template.pl +++ /dev/null @@ -1,596 +0,0 @@ -#!/usr/bin/perl - -############################################################################### -# # -# Name : template # -# Author : Chris Koeritz # -# Rights : Copyright (C) 1996-$now by Author # -# # -# Purpose: # -# # -# Attempts to pre-instantiate C++ templates to work-around C++ compilers # -# that don't support templates (a rare breed, these days). # -# # -############################################################################### -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; either version 2 of the License or (at your option) # -# any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a # -# version of the License. Please send any updates to "fred@gruntose.com". # -############################################################################### - -# this was a majestic abortive attempt to create a template instantiator for -# compilers that do not possess templates, but which do support some subset -# of C++. This was necessary at the time, due to our firmware compiler's -# limitations. This processor never totally worked, although it did produce -# some interesting compilable code. Might be useful as a demo or maybe just -# as a warning to avoid brain-damaged C++ compilers. - -# to do: -# maintain statistics about placement in file for error resolution. - -# limitations so far: -# -# the word "template" must be the first word on the line. -# -# the type to instantiate must be one word (like charstar, not char *). -# -# templates must follow the form templateName without -# any spaces between the angle brackets. - -# flag to enable debugging print outs. -$DEBUG_TEMPLATIZER = 1; -#$DEBUG_TEMPLATIZER = 0; - -# array to store instance types to convert to -@instance_type_buffer = (); -# flag for checking read from file option -$f_option = 0; -$d_option = 0; - -if ($#ARGV < 1) { - die(" - The template instantiater supports an optional directory path as the first - parameter (preceded by a -d with no spaces in between the d and the - directory name) in which to store the generated templates, and then - requires the instantiation type as the next argument (or a file - specification preceded by -f), and a list of files as the last - arguments. - The files will be scanned for templates and those templates will be - instantiated in the type(s) specified. - Examples: - perl template.pl char istring.h torpedo.h - perl template.pl -f instance.txt matrix.h - perl template.pl -d. -f instance.txt function.h data_src.h - perl template.pl -dfirm_src\library\basis -f instance.txt amorph.h\n"); -} - -# Check directory option -if (grep(/^\s*-d/, @ARGV)) { - $d_option = 1; - $d_dir = @ARGV[0]; -# print $d_dir, "\n"; - shift; -} - - -# Check to see if user used a file to specify instantiation types -if (grep(/^\s*-f/, @ARGV)) { - $f_option = 1; - shift; - $types_file = @ARGV[0]; - -# Open instantiation type file to read from - open(TYPES_FILE, "<$types_file") - || die("couldn't open file $types_file for reading"); - -# Read in all the different types to instantiate -# Create instance_type list - @tp = ; - while (@tp) { - local($line) = @tp; - chop $line; - push(@instance_type_buffer, $line); - shift @tp; - } - shift @ARGV; - &instantiate_templates(@ARGV); - exit; -} - -&instantiate_templates(@ARGV); -exit; - -# -# driver of the instantiation process. -# -sub instantiate_templates { - if (!$f_option) { - # grab the user's desired instance type. - $instance_type = @_[0]; - push(@instance_type_buffer, $instance_type); - print "Instantiation type is \"$instance_type\".\n"; - # jump over the instance type to look at the filenames. - shift; - } - - local($i) = 0; - foreach $filename (@_) { - open(INPUT_FILE, "<$filename") - || die("couldn't open file $filename for reading"); - # create an output name for the instance. - $out_filename = &make_output_name($filename); - if ($DEBUG_TEMPLATIZER) { -# print "out file is ", $out_filename, "\n"; - } - local($index) = $i + 1; - print "Instantiating file[$index] as $out_filename.\n"; - # now try opening our output file. - open(OUTPUT_FILE, ">$out_filename") - || die("couldn't open file $filename for writing"); - # grab the current file into an array. - - @file_array = ; - @start_template = @file_array; - @stop_template = @file_array; - # process the file's contents as a manipulable array. - while (@file_array) { - local($line) = shift @file_array; - if (grep(/^\s*template/, $line)) { - @start_template = @file_array; - - # iterate through all the instance types for each template - foreach $instance_type (@instance_type_buffer) { - @file_array = @start_template; - &snag_place_holder($line); - &snag_object_name; - &absorb_until_matched_block; - &replace_place_holder; - &dump_the_buffer; - print OUTPUT_FILE "\n"; - } - } elsif (grep(/\w+<\w+>/, $line)) { - local(@pieces) = split(/\s/, $line); - foreach $piece (@pieces) { - local($prefix) = ""; - # special case for separating function name from templated first - # parameter to it. - if (grep(/\(\w+/, $piece)) { $piece = &special_mangle($piece); } - print OUTPUT_FILE "$prefix$piece "; - } - print OUTPUT_FILE "\n"; - } else { - print OUTPUT_FILE $line; - } - } - $i++; - } -} - -# -# generates an output name from the filename to be translated. -# -sub make_output_name { - local($out_filename) = @_[0]; - local($d_dir_temp) = $d_dir; -# print "OUTFILE NAME: ",$out_filename,"\n"; - # break down the filename at the slashes. - local(@split_filename) = split(/[\\\/]/, $out_filename); - # take the basename of the list of names. - $out_filename = $split_filename[$#split_filename]; - local($hold_filename) = $out_filename; - if (grep(!/\.cpp$/i, $out_filename) && grep(!/\.h$/i, $out_filename) - && grep(!/\.c$/i, $out_filename) && grep(!/\.h$/i, $out_filename) ) { - die("filename @_[0] not recognized as a C++ code file."); - } - # makes an instance of the file in a directory named after the instance type - # that is located under the current directory. - - $d_dir_temp = join('/',$d_dir, $hold_filename); - if ($d_option) { - $d_dir_temp =~ s/-d//i; - @split_filename = split(/[\\\/]/, $d_dir_temp); -# exit; - } - -# try to create dir using the deepest dir given in filename input - - local($y) = 0; - foreach (@split_filename) { $y++; } - - local($x) = 0; - local($ret) = 0; - local($dirs) = 0; - - if ($y >= 2) { - foreach (@split_filename) { - if ((($x > 0) && ($x < $y-1)) || (($d_option) && ($x < $y-1))) { - if (!$dirs) { $dirs = @split_filename[$x]; } - else { $dirs = $dirs."/".@split_filename[$x]; } -# print "Creating... ",$dirs,"\n"; - $ret = mkdir($dirs, 0777); - if (!ret) { die("a directory named $instance_dir could not be made."); } - } - $x++; - } - $out_filename = $dirs."/".$hold_filename; - } - else { $out_filename = "template/".$hold_filename; - local($instance_dir) = "template"; - $ret = mkdir($instance_dir, 0777); - if (!ret) { die("a directory named $instance_dir could not be made."); } - } -# print $out_filename, "\n"; - -# local($instance_dir) = @split_filename[$x-2]; -# creates the directory. -# local($ret) = mkdir($instance_dir, 0777); -# if (!ret) { die("a directory named $instance_dir could not be made."); } - - $out_filename; # return the new name. -} - -# -# grabs the name of the placeholder type that will be replaced by -# the template instantiation type. -# -sub snag_place_holder { - $place_holder = @_[0]; - chop $place_holder; - - local(@pieces) = split(/>\s*/, $place_holder, 2); - - # send back the parts not involved in the template statement. - if (length($pieces[1])) { - unshift(@file_array, $pieces[1]."\n"); - } - $place_holder = $pieces[0]; - $place_holder =~ s/\s*template\s+"])/\1 \2 \3/; - local(@broken_up) = split(/ /, $temp); - # strip off the punctuation from the name. - local($incl_prefix) = @broken_up[1]; - $incl_prefix =~ s/["<](.*)[">]/\1/; - $incl_prefix =~ s/\s//g; - # return if it's not a code file being included. - if (!grep(/.cpp/i, $incl_prefix)) { print OUTPUT_FILE $line, "\n"; return; } - # strip to just the name without the ending. - $incl_prefix =~ s/\.cpp$//i; - # now get the name of the file we're processing. - local($file_prefix) = $filename; - # return if it's not a header file being examined. - if (!grep(/.h/i, $file_prefix)) { print OUTPUT_FILE $line, "\n"; return; } - # strip off the extension. - $file_prefix =~ s/\.h$//i; - # return if the names aren't equivalent--this means the include doesn't - # refer to our new templated form of the code file. - if ($incl_prefix ne $file_prefix) { print OUTPUT_FILE $line, "\n"; return FALSE; } - # dump out a message about the removal. - $line =~ s/^\s*//; - print OUTPUT_FILE "/* removed unneeded template inclusion: $line */\n"; -} - -# -# extracts lines from the file until the curly brackets are matched up -# at level 0. -# -sub absorb_until_matched_block { - $bracket_level = 0; - $end_absorb = 0; - @template_buffer = (); - $hit_one=0; - while (@file_array) { - local($line) = shift @file_array; - &look_for_curlies($line); - if (($hit_one && ($bracket_level == 0)) || $end_absorb) { return; } - } -} - -# -# examines the parameters passed in for curly brackets and changes the -# counter if they are found. -# -sub look_for_curlies { -# $hit_one = 0; # records whether a bracket was found or not. - local($line) = @_[0]; - @word = (); - foreach $char (split(//, $line)) { - if ($char eq '{') { - $hit_one = 1; - $bracket_level++; - } elsif ($char eq '}') { - $hit_one = 1; - $bracket_level--; - } elsif (($char eq ';') && ($hit_one==0)) { - $end_absorb = 1; - } - - - if ($DEBUG_TEMPLATIZER) { -# print "~$char~ "; - } - push(@word, $char); - if (grep(!/\w/, $char)) { - # don't split yet if it's a possible template char. - if (grep(!/[<>]/, $char)) { - local($real_word) = join("", @word); - if ($DEBUG_TEMPLATIZER) { -# print "adding a word $real_word\n"; - } - push(@template_buffer, "$real_word"); - @word = (); - } - } - } -} - -# -# this goes through the buffer and replaces all occurrences of the name to -# replace with the instance name. -# -sub replace_place_holder { - @new_template_buffer = @template_buffer; - @template_buffer = (); - - foreach $i (0 .. $#new_template_buffer) { - $word = $new_template_buffer[$i]; -# if ($DEBUG_TEMPLATIZER) { -# print "<$i $word> "; -# $old = $word; -# } - - # replace a templated combination with the mangled version. - $word =~ s/^${object_name}<${instance_type}>/${mangled_name}/; - -# if ($DEBUG_TEMPLATIZER) { -# if ($old ne $word) {print "1 ... changed to $word.\n"; $old = $word; } -# } - - if (grep(/^\w+<\w+>/, $word)) { - # replace some other template with our stuff if we can. - $word = &special_mangle($word); - } - -# if ($DEBUG_TEMPLATIZER) { -# if ($old ne $word) {print "2 ... changed to $word.\n"; $old = $word; } -# } - - # replace the object's name with its mangled form. - $word =~ s/^${object_name}/${mangled_name}/; - -# if ($DEBUG_TEMPLATIZER) { -# if ($old ne $word) {print "3... changed to $word.\n"; $old = $word; } -# } - - # replace the place holder with the instantiation type. - $word =~ s/^${place_holder}/${instance_type}/; - -# if ($DEBUG_TEMPLATIZER) { -# if ($old ne $word) {print "4... changed to $word.\n"; $old = $word; } -# } - - push(@template_buffer, $word); - } -} - -# -# processes a general template usage, in the form X, where either -# X or Y are not ones that we think we need to replace. it is assumed -# that it's safe to use the mangled form of the template. -# -sub special_mangle { - local($word) = @_[0]; - # split the template form into pieces. - local(@pieces) = split(/[<>]/, $word, 2); - - $pieces[1] =~ s/${place_holder}/${instance_type}/; - $pieces[1] =~ s/>//; - # hold onto the real instance type. - local($hold_instance) = $instance_type; - $instance_type = $pieces[1]; - # mangle the name in the template usage line. - local($hold_mangled) = &mangle_name($pieces[0]); - # restore the original instance type. - $instance_type = $hold_instance; - # returns the new mangled form. - $hold_mangled; -} - -# -# prints out the buffer we've accumulated to the output file. -# -sub dump_the_buffer { - print OUTPUT_FILE @template_buffer; -} - -# -# processes a class declaration and sets the object name for future use. -# -sub match_class_declaration { - local($next_line) = @_[0]; -# too strict! -# if (grep(!/class\s.*\w+$/, $next_line) -# && grep(!/class\s.*\w+\s*\{/, $next_line) -# && grep(!/struct\s.*\w+$/, $next_line) -# && grep(!/struct\s.*\w+\s*\{/, $next_line)) { -# return 0; -# } - - if (grep(!/class\s+\w+/, $next_line) && grep(!/struct\s+\w+/, $next_line) ) { - return 0; - } - - if ($DEBUG_TEMPLATIZER) { -# print "matched class decl in $next_line\n"; - } - - if (grep(/class\s+\w+.*:/, $next_line) - || grep(/struct\s+\w+.*:/, $next_line)) { - # parses an inheriting class decl. - if ($DEBUG_TEMPLATIZER) { -# print "in inheritance case on $next_line\n"; - } - local(@pieces) = split(/:/, $next_line, 2); - # push the rest of the line back into the input array. - if ($DEBUG_TEMPLATIZER) { -# print "going to unshift $pieces[1]...\n"; - } - unshift(@file_array, ": ".$pieces[1]." "); - $next_line = $pieces[0]; - } elsif (grep(/class\s.*\w+\s*\{/, $next_line) - || grep(/struct\s.*\w+\s*\{/, $next_line)) { - # parses a non-inheriting declaration with bracket on same line. - if ($DEBUG_TEMPLATIZER) { -# print "in special case on $next_line\n"; - } - # special case for continued stuff on same line. - local(@pieces) = split(/{/, $next_line, 2); - # push the rest of the line back into the input array. - unshift(@file_array, " { ".$pieces[1]." "); - $next_line = $pieces[0]; - } - if ($DEBUG_TEMPLATIZER) { -# print "matched class declaration... $next_line\n"; - } - local(@pieces) = split(/\s/, $next_line); - $object_name = $pieces[$#pieces]; - $mangled_name = &mangle_name($object_name); - foreach $posn (0 .. $#pieces - 1) { print OUTPUT_FILE "$pieces[$posn] "; } - print OUTPUT_FILE "$mangled_name\n"; - 1; -} - -# -# processes the implementation of a class member and sets the object -# name for future use. -# -sub match_class_member_definition { - local($next_line) = @_[0]; - local($junk); - if (grep(!/\w+<\w+>::/, $next_line)) { - return 0; - } - if ($DEBUG_TEMPLATIZER) { -# print "matched class member definition... $next_line\n"; - } - local(@pieces) = split(/>::/, $next_line, 2); - # checks for spaces in the first part of the split. if there is one, - # it means we don't have a simple object thing. - if (grep(/\s/, $pieces[0])) { - if ($DEBUG_TEMPLATIZER) { -# print "matched a space in the first part of supposed object name... $pieces[0]\n"; - } - if (grep(/^\w+<\w+>/, $pieces[0])) { - if ($DEBUG_TEMPLATIZER) { -# print "matched a template usage in first part of name..."; - } - # replace some other template with our stuff if we can. - $pieces[0] = &special_mangle($pieces[0]); - } - if ($DEBUG_TEMPLATIZER) { -# print "now our first bit is: $pieces[0]\n"; - } - local(@new_pieces) = split(/ /, $pieces[0]); - $pieces[0] = $new_pieces[$#new_pieces]; - foreach $posn (0 .. $#new_pieces - 1) { - $new_pieces[$posn] =~ s/${place_holder}/${instance_type}/g; - print OUTPUT_FILE "$new_pieces[$posn] "; - } - } - unshift(@file_array, "::\n".$pieces[1]."\n"); - $object_name = $pieces[0]; - $object_name =~ s/(\W*)(\w+)<(\w+)/\2/; - if (length($1)) { print OUTPUT_FILE "$1"; } - if ($3 ne $place_holder) { - die("The placeholder does not match on this line: $next_line"); - } - $mangled_name = &mangle_name($object_name); - print OUTPUT_FILE "$mangled_name\n"; - 1; # return success. -} - -# -# processes a function template by making sure it fits the format and -# then setting up the variables for the replacement. since function templates -# are so simple, the object name is not changed; only the place_holder is -# changed to the instance type. -# -sub match_function_definition { - local($next_line) = @_[0]; - - if (grep(!/^\s*\w+\s+.*/, $next_line) ) { - if ($DEBUG_TEMPLATIZER) { - print "failed on funcdef for ", $next_line, "!\n"; - } - return 0; - } - -# old broken code:... -# if (grep(!/^\s*\w+\s+.*\(.*\)\s*/, $next_line) ) { -#print "failed on funcdef for ", $next_line, "!\n"; -# return 0; -# } - -# if ($DEBUG_TEMPLATIZER) { -# print "matched function definition on $next_line\n"; -# } - -# if ($DEBUG_TEMPLATIZER) { -# print "stuffing back into the file array $next_line.\n"; -# } - # put the line back because it's nearly right for being instantiated. - unshift(@file_array, "inline ".$next_line."\n"); - # come up with a very rare name that will not be matched in the text. - $object_name = "hogga_wogga_nunky_budget_weeny_teeny_kahini_beany"; - $mangled_name = &mangle_name($object_name); - 1; # return a success. -} diff --git a/scripts/examples/multimedia/wma2mp3.sh b/scripts/examples/multimedia/wma2mp3.sh deleted file mode 100644 index a0224ef3..00000000 --- a/scripts/examples/multimedia/wma2mp3.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -# wma to mp3 script by mtron -# from http://ubuntuforums.org/showthread.php?t=37793 - -# have found that soundconverter package on ubuntu works on more types -# and is a bit more polished, but mtron's script kicks ass anyhow, if all -# you need is wma -> mp3 conversions. -# --fred hamster - -zenity --info \ - --text="this script converts all wma files in the current folder -to mp3s and puts them in the folder output - -all lame command line options can be set in the next step. - -usage: - lame -m s: for stereo mp3 output - lame -m s V 3-4-5: for stereo mp3 output with VBR" - -# Dialog box to choose output quality -FORMAT=$(zenity --list --title="Choose mp3 output quality" --radiolist --column="Check" --column="Quality (editable)" --editable "" "lame -m s" "" "lame -m s -V 3" "" "lame -m s -V 4" "" "lame -m s -V 5") - -if [ $FORMAT -eq ""]; then -zenity --error --text="mp3 output quality not defined or no wma file found - -usage: - lame -m s: for stereo mp3 output - lame -m s V 3-4-5: for stereo mp3 output with VBR - -type: lame --longhelp -for all command line options " -exit 1 -fi - -mkdir -p output -cp *.wma output -cd output - -# How many files to make the progress bar -PROGRESS=0 -NUMBER_OF_FILES=$(find -iname "*.wma") -let "INCREMENT=100/$NUMBER_OF_FILES" - -#remove spaces -(for i in *.wma; do mv "$i" $(echo $i | tr ' ' '_'); done - -#remove uppercase -for i in *.[Ww][Mm][Aa]; do mv "$i" $(echo $i | tr '[A-Z]' '[a-z]'); done - -#Rip with Mplayer / encode with LAME -for i in *.wma ; do -echo "$PROGRESS"; -echo "# Re-Coding $i"; -mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader $i && $FORMAT audiodump.wav -o $i; -let "PROGRESS+=$INCREMENT" -done - -#convert file names -for i in *.wma; do mv "$i" "$(basename "$i" .wma).mp3"; -done - -rm audiodump.wav -let "PROGRESS+=$INCREMENT" -) | zenity --progress --title "$Recoding...encoding..." --percentage=0 - - diff --git a/scripts/examples/os_related/OS_crusher.bat b/scripts/examples/os_related/OS_crusher.bat deleted file mode 100644 index 8adabbea..00000000 --- a/scripts/examples/os_related/OS_crusher.bat +++ /dev/null @@ -1,7 +0,0 @@ - - -:top -start "eep" "%0" -start "op" "%0" - -goto :top diff --git a/scripts/examples/os_related/OS_crusher.sh b/scripts/examples/os_related/OS_crusher.sh deleted file mode 100644 index 7c1683fa..00000000 --- a/scripts/examples/os_related/OS_crusher.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -while true; do - $0 & - $0 & -done - diff --git a/scripts/examples/os_related/example_registry_ops.sh b/scripts/examples/os_related/example_registry_ops.sh deleted file mode 100644 index 3480d948..00000000 --- a/scripts/examples/os_related/example_registry_ops.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# an example of using the reg.exe tool on windows to find some things in -# the registry. -# this happens to look in the registry for PuTTY keys for a set of named -# displays. - -declare ip_array=(zorba-1 zorba-2 zorba-3 zorba-4 zorba-5) - -for i in ${ip_array[*]}; do - target=${i} - echo "display is $target" - reg query 'HKCU\Software\SimonTatham\PuTTY\SshHostKeys' /v "rsa2@22:$target" -done - -