robert/echo - wapm
Wapm logo
search

The search results will appear here

robert/echoWASI

0.1.5 Public • Published 2 months ago12.12 KB

A very basic echo

Copy and paste to install this package
wapm install robert/echo

echo

A very basic echo (doesn't support coreutils echo parameters except -n):

#include <stdio.h>
#include <string.h>

#define true 1
#define false 0

int main(int argc, char *argv[])
{
  int display_return = true;

  for(int i = 1; i < argc; i++)
  {
    // Parse arguments:
    //   -n = don't output trailing newline
    if(strcmp("-n", argv[i]) == 0) {
      display_return = false;
      continue;
    }

    // Output arg if not a parameter
    printf("%s", argv[i]);
    if(i < (argc - 1))
      printf(" ");
  }

  // Show trailing newline
  if(display_return == true)
    printf("\n");
}

To run:

$ wasmer run -- echo.wasm -n this is a test  # notice the "--"