packages feed

binembed-example (empty) → 0.1

raw patch · 8 files changed

+189/−0 lines, 8 filesdep +basedep +binembeddep +bytestringbuild-type:Customsetup-changed

Dependencies added: base, binembed, bytestring, containers, filepath

Files

+ Example.binembed view
@@ -0,0 +1,8 @@+Example.binembed+LICENSE+Main_haskell.hs+Makefile+README+Setup.hs+binembed-example.cabal+main_c.c
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2010, Claude Heiland-Allen++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 Claude Heiland-Allen nor the names of other+      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.
+ Main_haskell.hs view
@@ -0,0 +1,24 @@+import Prelude hiding  (putStr)+import Data.ByteString (putStr, ByteString)+import Data.Map (toAscList)+import System.FilePath ((</>))+import Example++main :: IO ()+main = do+  putStrLn "binembed-example\n\+           \================"+  printEmbedded "binembed-example" =<< unBinEmbed example++printEmbedded :: String -> Node ByteString -> IO ()+printEmbedded path (File f) = do+  putStrLn "\n"+  putStrLn path+  putStrLn (replicate (length path) '-')+  putStrLn ""+  putStrLn "{{{"+  putStr f+  putStrLn "}}}"++printEmbedded path (Dir d) = do+  mapM_ (\(p, n) -> printEmbedded (path </> p) n) (toAscList d)
+ Makefile view
@@ -0,0 +1,11 @@+all: binembed-example++clean:+	rm -f binembed-example \+	Example.s Example.h Example.c++binembed-example: main_c.c Example.c Example.s+	gcc -std=c99 -Wall -pedantic -O2 -o $@ $^++%.s %.h %.c: %.binembed+	binembed --output-s=$*.s --output-h=$*.h --output-c=$*.c $*.binembed
+ README view
@@ -0,0 +1,16 @@+binembed is designed to be as simple as possible to use.  This example+package contains two programs, each of which print out the sources of+the package.++Usage from Haskell:+  Example.binembed+  Main_haskell.hs+  Setup.hs+  binembed-example.cabal+  -- 'cabal sdist' is currently broken; use 'runhaskell Setup.hs sdist'++Usage from C:+  Example.binembed+  main_c.c+  Makefile+  -- 'make install' is currently unimplemented
+ Setup.hs view
@@ -0,0 +1,5 @@+import Distribution.Simple+import Distribution.Simple.BinEmbed++main :: IO ()+main = defaultMainWithHooks (withBinEmbed simpleUserHooks)
+ binembed-example.cabal view
@@ -0,0 +1,38 @@+Name:                binembed-example+Version:             0.1+Synopsis:            Example project using binembed to embed data in object files.+Description:         binembed-example prints out its source code, embedded into it+                     at compile time using the "binembed" package.++Homepage:            http://gitorious.org/binembed+License:             BSD3+License-file:        LICENSE+Author:              Claude Heiland-Allen+Maintainer:          claudiusmaximus@goto10.org+Category:            Distribution+Build-type:          Custom+Cabal-version:       >=1.6++Extra-source-files:  main_c.c+                     Makefile+                     README++Executable binembed-example+  Main-is:             Main_haskell.hs+  Other-modules:       Example+  -- The next line is needed for the @withBinEmbed@ hooks to work:+  x-binembed:          Example+  Build-depends:       base >= 4 && < 5, bytestring >= 0.9 && < 0.10, filepath >= 1.1 && < 1.2, containers >= 0.3 && < 0.4, binembed >= 0.1 && < 0.2+  GHC-options:         -Wall+  GHC-prof-options:    -prof -auto-all++Source-repository head+  type:     git+  location: git://gitorious.org/binembed/binembed.git+  subdir:   example++Source-repository this+  type:     git+  location: git://gitorious.org/binembed/binembed.git+  subdir:   example+  tag:      v0.1
+ main_c.c view
@@ -0,0 +1,57 @@+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include "Example.h"++#define SEP "/"++void printEmbedded(char const *path, struct binembed_node const *node) {+  int pathLength = 0;+  char *pathBuffer = 0;+  for (; node->type != binembed_none; ++node) {+    switch (node->type) {+      case binembed_file:+        pathLength = strlen(path) + strlen(SEP) + strlen(node->name);+        pathBuffer = malloc(pathLength + 1);+        if (! pathBuffer) {+          exit(1);+        }+        sprintf(pathBuffer, "%s%s%s", path, SEP, node->name);+        printf("\n\n%s\n", pathBuffer);+        for (int i = 0; i < pathLength; ++i) {+          printf("-");+        }+        printf("\n\n{{{\n");+        struct binembed_file const *f = node->content.file;+        fflush(stdout);+        if (1 != fwrite(f->data, f->size, 1, stdout)) {+          exit(1);+        }+        fflush(stdout);+        printf("}}}\n");+        free(pathBuffer);+        pathBuffer = 0;+        break;+      case binembed_dir:+        pathLength = strlen(path) + strlen(SEP) + strlen(node->name);+        pathBuffer = malloc(pathLength + 1);+        if (! pathBuffer) {+          exit(1);+        }+        sprintf(pathBuffer, "%s%s%s", path, SEP, node->name);+        printEmbedded(pathBuffer, node->content.dir);+        free(pathBuffer);+        pathBuffer = 0;+        break;+      default:+        break;+    }+  }+}++int main(int argc, char **argv) {+  printf("binembed-example\n");+  printf("================\n");+  printEmbedded("binembed-example", Example);+  return 0;+}