Permalink
Browse files

initial commit for futil

Summary: rebooting the repo to just have public things.
unfortunately we lose repo history but i think that's ok.

Reviewed By: srush

Test Plan: builds

Revert Plan: ok
  • Loading branch information...
0 parents commit 13c3ec21aaf83560a1206f6cc81c30cd84ff9a54 Daniel Corson committed May 5, 2009
Showing with 839 additions and 0 deletions.
  1. +23 −0 FUtil.cabal
  2. +10 −0 LICENSE
  3. +6 −0 README
  4. +3 −0 Setup.lhs
  5. +124 −0 bin/hsb
  6. +3 −0 bin/hsg
  7. +8 −0 bin/hst
  8. +13 −0 bin/killQual
  9. +10 −0 g
  10. +4 −0 install
  11. +28 −0 src/FUtil.Check.hs
  12. +534 −0 src/FUtil.hs
  13. +40 −0 src/align.hs
  14. +3 −0 src/sorth.hs
  15. +30 −0 src/wordSwap.hs
@@ -0,0 +1,23 @@
+name: FUtil
+version: 0.1
+synopsis: generic utility library and scripts useful for many projects
+license: GPL
+license-file: LICENSE
+author: dan corson <danl@alum.mit.edu>
+build-depends: HSH, MonadRandom, array, base, bytestring, containers,
+ haskell98, mtl, parsec >= 3.0.0, process, random, time
+exposed-modules: FUtil
+hs-source-dirs: src
+build-type: Simple
+
+executable: align
+main-is: align.hs
+hs-source-dirs: src
+
+executable: sorth
+main-is: sorth.hs
+hs-source-dirs: src
+
+executable: wordSwap
+main-is: wordSwap.hs
+hs-source-dirs: src
10 LICENSE
@@ -0,0 +1,10 @@
+Copyright (c) 2009, Dan Corson, Sasha Rush, Facebook, inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of Facebook, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 README
@@ -0,0 +1,6 @@
+to install
+- ./install
+dependencies should all be on hackage (so grabbed for you)
+
+to get help
+- haskell@lists.facebook.com
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMain
124 bin/hsb
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+#
+# haskell build/etc wrapper for cabal or non-cabal (ghc with obj/ dir)
+# - note this has very little (but non-zero still) use now that cabal-install
+# exists
+#
+#
+# cabal is more standard for packaging
+# non-cabal is faster for development work on an executable (non-library)
+#
+# non-cabal mode can read a 'name' file for the name of your executable which
+# is produced from src/<name>.hs. it will assume name = 'Main' otherwise
+
+from optparse import OptionParser
+import cmd_util as cu
+import os
+import sys
+
+usage = """usage: %prog [options] [-- <args for run, or configure, or build>]
+
+configure/build/install your program with cabal (by default)
+or build/run program or test suite with ghc
+(assuming src/ structure and other things)"""
+p = OptionParser(usage)
+# todo: support clean for gen?, support test for cabal
+# fixme: too many non-obviousities,
+# like that optimize with cabal only applies to configure?
+# or should you know that (we could at least warn)
+p.add_option('-b', '--build', action='store_true')
+p.add_option('-c', '--configure', action='store_true')
+p.add_option('-C', '--cabal', action='store_true')
+#p.add_option('-H', '--haddock', action='store_true')
+p.add_option('-k', '--clean', action='store_true')
+p.add_option('-i', '--install', action='store_true')
+p.add_option('-O', '--optimize', action='store_true')
+p.add_option('-2', '--optimize2', action='store_true')
+p.add_option('-r', '--run', action='store_true')
+p.add_option('-t', '--test', action='store_true')
+(opts, args) = p.parse_args()
+
+#steps_poss = ['clean', 'configure', 'build', 'install', 'run', 'haddock']
+steps_poss = ['clean', 'configure', 'build', 'install', 'run']
+steps = []
+for step in steps_poss:
+ if getattr(opts, step):
+ steps.append(step)
+if not steps:
+ if opts.test:
+ # common case for test is to build the test then run the test
+ steps = ['build', 'run']
+ else:
+ # in most common case we just want to install some normal cabal package
+ steps = ['configure', 'build', 'install']
+ opts.cabal = True
+ if not opts.optimize:
+ # this if is so that 'hsb -O' works as expected (and not as
+ # 'hsb -2' which is the default); no reason not to support that
+ opts.optimize2 = True
+
+if opts.cabal:
+ if opts.test:
+ cu.error_out('testing thru cabal not supported')
+
+ setup = 'Setup.lhs'
+ if not os.path.exists(setup):
+ setup = 'Setup.hs'
+
+ for step in steps:
+ if step == 'run':
+ continue
+ cmd = ['runhaskell', setup, step]
+ if step == 'configure':
+ if opts.optimize:
+ cmd += ['-O']
+ if opts.optimize2:
+ cmd += ['--ghc-options=-O2']
+ if 'run' not in steps:
+ # configure is most useful step to take extra args in cabal case
+ # if we aren't running
+ cmd += args
+ elif step == 'install':
+ cmd = ['sudo'] + cmd
+ cu.cmd_wait(cmd)
+else:
+ if 'configure' in steps:
+ cu.error_out('configuring thru non-cabal not supported')
+ if opts.clean:
+ cu.error_out('cleaning thru non-cabal not supported')
+
+ if os.path.exists('name'):
+ name = file('name').readlines()[0][:-1]
+ else:
+ name = 'Main'
+ if opts.test:
+ if 'install' in steps:
+ cu.error_out('installing test not supported')
+
+ name += '.Check'
+ if 'build' in steps:
+ if not os.path.exists('obj'):
+ os.mkdir('obj')
+ cmd = ['ghc', '--make', '-odir', 'obj', '-hidir', 'obj',
+ 'src/' + name + '.hs', '-o', name]
+ if opts.optimize:
+ cmd += ['-O']
+ if opts.optimize2:
+ cmd += ['-O2']
+ if 'run' not in steps:
+ # build is most useful step to take extra args in non-cabal case
+ # if we aren't running
+ cmd += args
+ cu.cmd_wait(cmd)
+
+if 'run' in steps:
+ if opts.cabal:
+ name_cmd = 'grep executable *.cabal | head -n1 | awk \'{print $2}\''
+ name = cu.cmd_output(name_cmd)[0]
+ else:
+ name = './' + name
+ print >> sys.stdout, 'running'
+ cu.cmd_wait([name] + args)
+
+#if 'haddock' in steps:
+#
@@ -0,0 +1,3 @@
+#!/bin/sh
+# grep thru haskell code
+find . -path ./_darcs -prune -o -name '*.*hs' -print | xargs grep -nH "$@"
@@ -0,0 +1,8 @@
+#!/bin/sh
+# generate haskell ctags
+find . -path ./_darcs -prune -o -name '*.*hs' -print | xargs hasktags -c &&
+# hasktags does not sort the tags
+# also, sort (for all its options) cannot seem to be made to sort them
+# correctly! (i.e. simple ascii sort..)
+# but sorth does (simple ascii sort written in haskell)
+inPl tags sorth >/dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# ~ killQual MyLol someFile.hs
+# will convert from:
+# import qualified Lol as MyLol
+# MyLol.yay
+# to:
+# import Lol
+# yay
+
+Q="$1"
+F="$2"
+inPl "$F" sed 's/qualified \([^ ]*\) \bas '"$Q"'\b/\1/;s/'"$Q"'\.//g'
10 g
@@ -0,0 +1,10 @@
+#!/bin/sh
+# wrapper for iteration while developing
+
+set -e
+
+./install 2>&1 | less -E
+
+# for profiling
+#mkdir -p obj
+#ghc -O2 --make src/FUtil.hs -isrc -odir obj -hidir obj -auto-all -caf-all -fforce-recomp
@@ -0,0 +1,4 @@
+#!/bin/sh
+set -e
+cabal install --enable-optimization=2 --global --root-cmd=sudo
+sudo cp bin/* /usr/local/bin
@@ -0,0 +1,28 @@
+module Main where
+
+import Data.Char
+import Data.List
+import Test.QuickCheck
+import FUtil
+
+instance Arbitrary Char where
+ arbitrary = choose ('a', 'b')
+ coarbitrary c = variant (ord c `rem` 4)
+
+chkInterBreaks :: Char -> [Char] -> Bool
+chkInterBreaks c s = intercalate [c] (breaks (== c) s) == s
+
+chkCalate :: [Char] -> [Char] -> Bool
+chkCalate glue s = s == intercalate glue (uncalate glue s)
+
+{-
+chks = [chkInterBreaks, chkDblTransp]
+-}
+
+--chkF = quickCheck
+--chkF = verboseCheck
+
+main = do
+ -- todo: TH to at least get chkF..
+ quickCheck chkInterBreaks
+ verboseCheck chkCalate
Oops, something went wrong.

0 comments on commit 13c3ec2

Please sign in to comment.