branch: externals/beardbolt
commit e215ece289a533a38da5d326c895ac109a108639
Author: João Távora <joaotav...@gmail.com>
Commit: João Távora <joaotav...@gmail.com>

    New bearbolt-link-flags option to add libs & control linking
    
    * beardbolt.el (bb-link-flags): New option.
    (bb--c/c++-setup): Use it.
    
    * starters/beardbolt.c: Update starter template.
    
    * starters/beardbolt.cpp: Update starter template.
---
 beardbolt.el           |  5 ++++-
 starters/beardbolt.c   | 32 ++++++++++++++++++++------------
 starters/beardbolt.cpp | 19 +++++++++++--------
 3 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/beardbolt.el b/beardbolt.el
index 1d831eae9a..fe70d9305e 100644
--- a/beardbolt.el
+++ b/beardbolt.el
@@ -49,6 +49,9 @@
 (bb--defoption bb-command nil
   "The base command to run beardbolt from."
   :type 'string :safe (lambda (v) (or (listp v) (stringp v))))
+(bb--defoption bb-link-flags nil
+  "Linker flags to pass to linking command."
+  :type 'string :safe (lambda (v) (or (listp v) (stringp v))))
 (bb--defoption bb-disassemble nil
   "Non-nil to assemble then disassemble an output binary."
   :type 'boolean :safe 'booleanp)
@@ -225,7 +228,7 @@ Useful if you have multiple objdumpers and want to select 
between them")
                                           `("-x" ,language "-" "<" ,in)
                                         `(,(shell-quote-argument 
(buffer-file-name))))))
                 (assemble (in out) `("&&" ,cc "-c" ,in "-o" ,out))
-                (link     (in out) `("&&" ,cc ,in      "-fsanitize=address" 
"-o" ,out))
+                (link     (in out) `("&&" ,cc ,@(ensure-list bb-link-flags) 
,in "-o" ,out))
                 (execute  (in)     `("&& (" ,in
                                      ,(if (stringp bb-execute) bb-execute "")
                                      "|| true )"))
diff --git a/starters/beardbolt.c b/starters/beardbolt.c
index b7d6ba2743..26a3405d1d 100644
--- a/starters/beardbolt.c
+++ b/starters/beardbolt.c
@@ -1,24 +1,32 @@
 #include <string.h>
 #include <stdio.h>
+#include <math.h>
 
 int main(int argc, char *argv[]) {
-        if(argc==2) {
-               printf("Checking License: %s\n", argv[1]);
-               if(strcmp(argv[1], "AAAA-Z10N-42-OK")==0) {
-                       printf("Access Granted!\n");
-               } else {
-                       printf("WRONG!\n");
-               }
-       } else {
-               printf("Usage: <key>\n");
-       }
-       return 0;
+    if(argc == 2) {
+        printf("Checking License: %s\n", argv[1]);
+
+        double hash_value = 0;
+        for(int i = 0; i < strlen(argv[1]); i++) {
+            hash_value += sin(argv[1][i]) * pow(2.3765, i % 5);
+        }
+
+        if(fabs(hash_value - 42.0) < 0.01) {
+            printf("Access Granted!\n");
+        } else {
+            printf("WRONG! (Hash: %.2f)\n", hash_value);
+        }
+    } else {
+        printf("Usage: %s <key>\n", argv[0]);
+    }
+    return 0;
 }
 
 /* Local Variables: */
 /* beardbolt-command: "gcc -O3" */
 /* beardbolt-demangle: t */
-/* beardbolt-execute: t */
+/* beardbolt-execute: "DEAD-BEEF-42-OK" */
+/* beardbolt-link-flags: "-lm" */
 /* beardbolt-disassemble: nil */
 /* beardbolt-preserve-library-functions: nil */
 /* beardbolt-preserve-unused-labels: nil */
diff --git a/starters/beardbolt.cpp b/starters/beardbolt.cpp
index 32482eafaa..b0d7527797 100644
--- a/starters/beardbolt.cpp
+++ b/starters/beardbolt.cpp
@@ -1,5 +1,5 @@
 #include <iostream>
-#include <array>
+#include <algorithm>
 #include <vector>
 
 template <typename It>
@@ -10,19 +10,22 @@ void bubble(It from, It to) {
         std::swap(*j, *(j - 1));
 }
 
-int main() {
-  std::vector v{5, 2, 1, 4, 2};
-  bubble(v.begin(), v.end());
+int main(int argc, char* argv[]) {
+  std::vector<int> vi;
+  std::transform(argv, argv+argc, std::back_inserter(vi),
+      std::atoi);
+  bubble(vi.begin(), vi.end());
 
-  std::cout << "Sorted array : ";
-  for (const auto& e : v) std::cout << e << "\n";
+  std::cout << "Sorted array : \n";
+  for (auto&& e : vi) std::cout << e << "\n";
   return 0;
 }
 
 // Local Variables:
-// beardbolt-command: "g++ -std=c++20 -O0"
+// beardbolt-command: "g++ -std=c++20 -O3"
 // beardbolt-demangle: t
-// beardbolt-execute: t
+// beardbolt-execute: "5 4 blargh 2 1"
+// beardbolt-link-flags: "-fsanitize=address"
 // beardbolt-disassemble: nil
 // beardbolt-preserve-library-functions: nil
 // beardbolt-preserve-unused-labels: nil

Reply via email to