<commit_before>#include "lib/ilib.h"
#include "lib/slib.h"
#include "lib/flib.h"

void ls();
void cd(char *dir);
void cat(char *fname);

int main() {
  char buffer[80];
  char verb[80];
  char wd[512];
  int len;
  int prog;
  while (1) {
    fgetwd(wd);
    iwrites(wd);
    iwrites("> ");
    ireads(buffer);
    len = sfindc(buffer, ' ');
    if (len < 0)
      len = slength(buffer);
    scopy(verb, buffer, len);
    if (!scompare(verb, "help")) {
      iwrites("\ncat: print file contents\ncd: change directories\nhelp: display this message\nls: list files\n\n");
    }
    else if (!scompare(verb, "ls")) {
      ls();
    }
    else if (!scompare(verb, "cd")) {
      cd(buffer + len + 1);
    }
    else if (!scompare(verb, "cat")) {
      /* Mrew? */
      cat(buffer + len + 1);
    }
    else if (!scompare(verb, "reboot")) {
      ireboot();
    }
    else if (sfindc(verb, '/') == -1) {
      prog = fget("/bin/");
      if (!prog) {
        iwrites("Error: unable to locate bin directory\n");
        continue;
      }
      prog = ffind(prog, verb);
      if (!prog) {
        iwrites("Error: unrecognized command \"");
        iwrites(verb);
        iwrites("\"\n");
        continue;
      }
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else if (prog = fget(verb)) {
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else {
      iwrites("Error: executable not found\n");
      continue;
    }
  }
}

void ls() {
  char path[512];
  char name[9];
  file dir;
  file f;
  int i;
  int type;
  filecache c;
  
  finitcache(&c);
  
  fgetwd(path);
  iwrites("\n-- Directory ");
  iwrites(path);
  iwrites(" --\n\n");
  dir = fget(path);
  
  for (i = 0; 1; i++) {
    f = fdirget(dir, i, &c);
    if (!f)
      break;
    fgetname(name, f);
    type = fgettype(f);
    if (type == 1)
      isetcolor(14);
    else if (type == 2)
      isetcolor(9);
    else if (type == 3)
      isetcolor(12);
    iwrites(name);
    iwrites("\n");
    isetcolor(7);
  }
  
  iwrites("\n");
}

void cd(char *dir) {
  char dir2[512];
  int f;
  fexpand(dir2, dir);
  f = fget(dir2);
  if (!f) {
    iwrites("Error: directory does not exist\n");
    return;
  }
  if (fgettype(f) != 3) {
    iwrites("Error: file is not a directory\n");
    return;
  }
  fsetwd(dir2);
}

void cat(char *fname) {
  file f;
  int type;
  char buf[512];
  char buffer[1536];
  int i;
  int errcode;
  f = fget(fname);
  if (!f) {
    iwrites("Error: file does not exist\n");
    return;
  }
  type = fgettype(f);
  if (type == 3) {
    iwrites("Error: file is a directory\n");
    return;
  }
  else if (type == 0) {
    for (i = 0; 1; i++) {
      errcode = freads(buffer, f, i);
      if (errcode == 2) {
        iwrites("Error: unable to read file\n");
        return;
      }
      else if (errcode == 1)
        break;
      buffer[512] = '\0';
      iwrites(buffer);
    }
  }
  else {
    for (i = 0; 1; i++) {
      errcode = freads(buf, f, i);
      if (errcode == 2) {
        iwrites("Error: unable to read file\n");
        return;
      }
      else if (errcode == 1)
        break;
      sformath(buffer, buf, 512);
      if (i > 0)
        iwritec(' ');
      iwrites(buffer);
    }
  }
  iwrites("\n");
}<commit_msg>pwd and echo implemented and tested<commit_after>#include "lib/ilib.h"
#include "lib/slib.h"
#include "lib/flib.h"

void ls();
void cd(char *dir);
void cat(char *fname);
void echo(char *str);
void pwd();

int main() {
  char buffer[80];
  char verb[80];
  char wd[512];
  int len;
  int prog;
  while (1) {
    fgetwd(wd);
    iwrites(wd);
    iwrites("> ");
    ireads(buffer);
    len = sfindc(buffer, ' ');
    if (len < 0)
      len = slength(buffer);
    scopy(verb, buffer, len);
    if (!scompare(verb, "help")) {
      iwrites("\ncat: print file contents\ncd: change directories\nhelp: display this message\nls: list files\necho: print a string\n\n");
    }
    else if (!scompare(verb, "ls")) {
      ls();
    }
    else if (!scompare(verb, "cd")) {
      cd(buffer + len + 1);
    }
    else if (!scompare(verb, "cat")) {
      /* Mrew? */
      cat(buffer + len + 1);
    }
    else if  (!scompare(verb, "echo")){
      echo(buffer + len + 1);
    }
    else if  (!scompare(verb, "pwd")){
      pwd(buffer + len + 1);
    }
    else if (!scompare(verb, "reboot")) {
      ireboot();
    }
    else if (sfindc(verb, '/') == -1) {
      prog = fget("/bin/");
      if (!prog) {
        iwrites("Error: unable to locate bin directory\n");
        continue;
      }
      prog = ffind(prog, verb);
      if (!prog) {
        iwrites("Error: unrecognized command \"");
        iwrites(verb);
        iwrites("\"\n");
        continue;
      }
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else if (prog = fget(verb)) {
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else {
      iwrites("Error: executable not found\n");
      continue;
    }
  }
}

void ls() {
  char path[512];
  char name[9];
  file dir;
  file f;
  int i;
  int type;
  filecache c;

  finitcache(&c);

  fgetwd(path);
  iwrites("\n-- Directory ");
  iwrites(path);
  iwrites(" --\n\n");
  dir = fget(path);

  for (i = 0; 1; i++) {
    f = fdirget(dir, i, &c);
    if (!f)
      break;
    fgetname(name, f);
    type = fgettype(f);
    if (type == 1)
      isetcolor(14);
    else if (type == 2)
      isetcolor(9);
    else if (type == 3)
      isetcolor(12);
    iwrites(name);
    iwrites("\n");
    isetcolor(7);
  }

  iwrites("\n");
}

void cd(char *dir) {
  char dir2[512];
  int f;
  fexpand(dir2, dir);
  f = fget(dir2);
  if (!f) {
    iwrites("Error: directory does not exist\n");
    return;
  }
  if (fgettype(f) != 3) {
    iwrites("Error: file is not a directory\n");
    return;
  }
  fsetwd(dir2);
}

void cat(char *fname) {
  file f;
  int type;
  char buf[512];
  char buffer[1536];
  int i;
  int errcode;
  f = fget(fname);
  if (!f) {
    iwrites("Error: file does not exist\n");
    return;
  }
  type = fgettype(f);
  if (type == 3) {
    iwrites("Error: file is a directory\n");
    return;
  }
  else if (type == 0) {
    for (i = 0; 1; i++) {
      errcode = freads(buffer, f, i);
      if (errcode == 2) {
        iwrites("Error: unable to read file\n");
        return;
      }
      else if (errcode == 1)
        break;
      buffer[512] = '\0';
      iwrites(buffer);
    }
  }
  else {
    for (i = 0; 1; i++) {
      errcode = freads(buf, f, i);
      if (errcode == 2) {
        iwrites("Error: unable to read file\n");
        return;
      }
      else if (errcode == 1)
        break;
      sformath(buffer, buf, 512);
      if (i > 0)
        iwritec(' ');
      iwrites(buffer);
    }
  }
  iwrites("\n");
}

void echo(char *str) {
  int len = slength(str);

  if (len <= 0) {
    iwrites("Error: No string was provided");
  }
  else {
    iwrites(str);
  }

  iwrites("\n");
}

void pwd() {
  char *wd = "";
  fgetwd(wd);

  iwrites(wd);
  iwrites("\n");
}
{'fraction_non_alphanumeric': 0.1786593707250342, 'fraction_numerical': 0.0173734610123119, 'mean_word_length': 2.0260761589403975, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2022728', 'n_tokens_mistral': 2983, 'n_tokens_neox': 2837, 'n_words': 705}