Skip to content

Commit

Permalink
Merge pull request #68 from sebastiancarlos/master
Browse files Browse the repository at this point in the history
Add --clear-cache flag
  • Loading branch information
ryanmjacobs authored Nov 24, 2023
2 parents 29b78bf + e48e382 commit fb52d58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ The default cache path is set to `$TMPDIR/c.cache`. You can change this with:
$ export C_CACHE_PATH="/tmp/the_cache"
```

### Clear cache
You can clear the cache with the `--clear-cache` flag:
```bash
$ c --clear-cache
```

# Contributing
Feel free to submit any ideas, questions, or problems by reporting an issue.
Or, if you're feeling a bit brave, submit a pull request. :grimacing:
Expand Down
20 changes: 13 additions & 7 deletions c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fi

help_msg() {
>&$1 echo "Usage: $(basename "$0") <file.c ... | compiler_options ...> [program_arguments]"
>&$1 echo " $(basename "$0") --clear-cache"
>&$1 echo 'Execute C programs from the command line.'
>&$1 echo
>&$1 echo ' Ex: c main.c'
Expand All @@ -36,6 +37,17 @@ cleanup() {
[[ "$1" == "--help" || "$1" == "-h" ]] && { help_msg 1; exit 0; }
[[ "$#" -lt 1 ]] && { help_msg 2; exit 2; }

# get cache location
if [[ -n "$C_CACHE_PATH" ]]; then
tmproot="$C_CACHE_PATH"
else
[[ -z "$TMPDIR" ]] && TMPDIR="/tmp"
tmproot="$TMPDIR/c.cache.$USER"
fi

# Hadle --clear-cache
[[ "$1" == "--clear-cache" ]] && { rm -rf "$tmproot"; exit 0; }

# ensure our $CC and $CXX variables are set
[[ -z "$CC" ]] && CC=cc
[[ -z "$FC" ]] && FC=gfortran
Expand Down Expand Up @@ -76,13 +88,7 @@ else
fi
fi

# get cache location
if [[ -n "$C_CACHE_PATH" ]]; then
tmproot="$C_CACHE_PATH"
else
[[ -z "$TMPDIR" ]] && TMPDIR="/tmp"
tmproot="$TMPDIR/c.cache.$USER"
fi
# create cache location
mkdir -p "$tmproot"
chmod 700 "$tmproot"

Expand Down

0 comments on commit fb52d58

Please sign in to comment.