Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@

#include "os.h"
#include "vm.h"
#include "path.h"
#include "wren.h"

int main(int argc, const char* argv[])
{
if (argc == 2 && strcmp(argv[1], "--help") == 0)
int main(int argc, const char* argv[]) {
Path* p = pathNew(argv[0]);
pathBaseName(p);
char* cli = p->chars;

if (argc == 2 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0))
{
printf("Usage: wren [file] [arguments...]\n");
printf("Usage: %s [options] [ file.wren ] [arguments...] \n", cli);
printf("\n");
printf("Optional arguments:\n");
printf(" --help Show command line usage\n");
printf(" --version Show version\n");
printf("Options:\n");
printf(" -h, --help Show command line usage\n");
printf(" -v, --version Show version\n");
return 0;
}

if (argc == 2 && strcmp(argv[1], "--version") == 0)
if (argc == 2 && (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0))
{
printf("wren %s\n", WREN_VERSION_STRING);
printf("%s %s\n", cli, WREN_VERSION_STRING);
return 0;
}

Expand Down
14 changes: 14 additions & 0 deletions src/cli/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ void pathFree(Path* path)
free(path);
}

void pathBaseName(Path* path) {
int pos = 0;
for (size_t i = path->length - 1; i >=0 ; i--)
{
if (isSeparator(path->chars[i]))
{
pos = i;
break;
}
}
if (pos == 0) return;
strcpy(path->chars, (char*)path->chars + pos + 1);
}

void pathDirName(Path* path)
{
// Find the last path separator.
Expand Down
3 changes: 3 additions & 0 deletions src/cli/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void pathFree(Path* path);
// Strips off the last component of the path name.
void pathDirName(Path* path);

// returns the basename of the path
void pathBaseName(Path* path);

// Strips off the file extension from the last component of the path.
void pathRemoveExtension(Path* path);

Expand Down