Skip to content

Instantly share code, notes, and snippets.

@mrryanjohnston
Created May 2, 2021 17:33
Show Gist options
  • Save mrryanjohnston/69e7a82f975b48e912fe635d184cb9dd to your computer and use it in GitHub Desktop.
Save mrryanjohnston/69e7a82f975b48e912fe635d184cb9dd to your computer and use it in GitHub Desktop.
CLIPS - GET and print to STDIO with curl

CLIPS - curl to STDIO

Usage

(curl "https://ryjo.codes")

outputs to STDIO (as of 05/02/2021):

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>ryjo.codes - Ryan Johnston's Personal Website</title>
    <link rel="stylesheet" type="text/css" href="index.css" />
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#000000" />
    <meta name="msapplication-TileColor" content="#ffffff" />
    <meta name="theme-color" content="#ffffff" />
  </head>

  <body>
    <h1>ryjo.codes</h1>
    <div class="intro">
      <p>Oh hai.</p>
      <p>
        I'm Ryan. Some of my friends call me "ryjo." I write code and draw stuff!
      </p>
      <p>
        The goal of this website is to share my own personal programming philosophies
        (alliteration!) through example. I'll talk about software that I write and
        why I write it.
      </p>
    </div>
    <div class="stwawbewwy">
      <img alt="cartoon strawberry playing with a cup-and-ball toy" src="stwawbewwy.png">
    </div>
    <h2 id="articles">Articles</h2>
    <p><a href="feed.rss">Subscribe to the RSS feed</a></p>
    <ul id="articles-list">
      <li><time datetime="2019-06-07">June 7th, 2019</time> - <a href="articles/creating-ci-cd-pipelines.html">Creating CI/CD Pipelines</a></li>
      <li><time datetime="2019-01-27">January 27th, 2019</time> - <a href="articles/hosting-your-own-git-server-part-1.html">Hosting Your Own Git Server: Part 1</a></li>
      <li><time datetime="2018-12-13">December 13th, 2018</time> - <a href="articles/turning-your-application-into-an-installable-package.html">Turning Your Application into an Installable Package</a></li>
      <li><time datetime="2018-11-26">November 26th, 2018</time> - <a href="articles/how-i-can-use-templates-to-streamline-writing.html">How I Can Use Templates to Streamline Writing</a></li>
      <li><time datetime="2018-11-08">November 8th, 2018</time> - <a href="articles/how-readers-can-stay-up-to-date.html">How Readers Can Stay Up to Date</a></li>
      <li><time datetime="2018-10-31">October 31st, 2018</time> - <a href="articles/how-this-site-gets-deployed.html">How This Site Gets Deployed</a></li>
    </ul>
    <h2 id="projects">Projects</h2>
    <ul>
      <li><a href="https://github.com/mrryanjohnston/ryjo-git" target="_blank">ryjo's git scripts</a></li>
      <li><a href="https://github.com/mrryanjohnston/ember-service-function-helper" target="_blank">ember-service-function-helper</a></li>
      <li><a href="https://github.com/mrryanjohnston/ryjo_static_site_deploy_scripts" target="_blank">ryjo's Static Site Deploy Scripts</a></li>
    </ul>
    <h2 id="links">Links</h2>
    <ul>
      <li><a href="https://github.com/mrryanjohnston" target="_blank">GitHub</a></li>
      <li><a href="https://www.linkedin.com/in/ryan-johnston-89615826/" target="_blank">LinkedIn</a></li>
      <li><a href="https://dribbble.com/mrryanjohnston" target="_blank">Dribbble</a></li>
    </ul>
  </body>
</html>

Description

Call curl from within CLIPS. This example simply prints the contents of webpage specified by the passed url.

Requirements

  • curl - You'll need libcurl
  • CLIPs - You'll need to download the source for version 6.31

Installation

  1. First you'll need to get the clips source code for CLIPs version 6.31.
  2. tar -xvf clips_core_source_631.tar.gz and cd clips_core_source_631/core/
  3. Apply the patches in this gist to the source: a url
patch makefile makefile.patch
patch userfunctions.c userfunctions.c.patch
  1. make
  2. ./clips
--- makefile 2021-05-02 13:16:45.384421241 -0400
+++ makefile.new 2021-05-02 13:06:33.274912456 -0400
@@ -67,7 +67,7 @@
release : CC = gcc
release : CFLAGS = -std=c99 -O3 -fno-strict-aliasing
-release : LDLIBS = -lm
+release : LDLIBS = -lm -lcurl
release : clips
debug_cpp : CC = g++
--- userfunctions.c 2021-05-02 13:19:02.368950800 -0400
+++ userfunctions.c.new 2021-05-02 13:19:27.459517012 -0400
@@ -65,6 +65,35 @@
// Use EnvUserFunctions instead.
}
+#include "curl/curl.h"
+#include "stdio.h"
+double curl(void *environment)
+{
+ if (EnvArgCountCheck(environment, "curl", EXACTLY, 1) == -1) {
+ return -1;
+ }
+ const char *url = EnvRtnLexeme(environment, 1);
+
+ // https://curl.se/libcurl/c/simple.html
+ CURL *curl;
+ CURLcode res;
+
+ curl = curl_easy_init();
+ if (curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+
+ res = curl_easy_perform(curl);
+
+ if (res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\n",
+ curl_easy_strerror(res));
+
+ curl_easy_cleanup(curl);
+
+ return 0;
+ }
+ return -1;
+}
/***********************************************************/
/* EnvUserFunctions: Informs the expert system environment */
/* of any user defined functions. In the default case, */
@@ -80,5 +109,6 @@
#if MAC_XCD
#pragma unused(environment)
#endif
+ EnvDefineFunction(environment,"curl",'v',PTIEF curl,"curl");
}
@mrryanjohnston
Copy link
Author

The curl bit is largely from the curl website: https://curl.se/libcurl/c/simple.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment