-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mkm: add script to split files, make client.h and others work with it
- Loading branch information
Showing
4 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "policy.h" | ||
|
||
enum client_state { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Run the C preprocessor on the second half of a file only: | ||
# 1. Split the file at the first occurrence of //SYSTEM_HEADERS | ||
# 2. Run the C preprocessor on the second chunk | ||
# 3. Concatenate the first chunk and preprocessed second chunk | ||
# | ||
# Usage: | ||
# ./process.sh <input-file> [<output-file>] | ||
|
||
set -euo pipefail | ||
|
||
# Check arguments | ||
if [[ $# -lt 1 ]]; then | ||
echo "Usage: $0 <input-file> [<output-file>]" | ||
exit 1 | ||
fi | ||
|
||
INPUT_FILE="$1" | ||
OUTBASE="${INPUT_FILE%.c}" | ||
DEFAULT_OUTPUT="${OUTBASE}-out.c" | ||
|
||
# If user provided the second argument, use it; otherwise use our default | ||
OUTPUT_FILE="${2:-$DEFAULT_OUTPUT}" | ||
|
||
# Create a temporary directory and ensure it's cleaned up on exit | ||
TMP_DIR="$(mktemp -d)" | ||
trap 'rm -rf "$TMP_DIR"' EXIT | ||
|
||
# 1. Split at the first occurrence of /\/\/SYSTEM_HEADERS/ | ||
csplit -s -f "${TMP_DIR}/split_" -n 1 "$INPUT_FILE" "/\/\/SYSTEM_HEADERS/" | ||
|
||
# 2. Run the C preprocessor on the second chunk | ||
ROOT_DIR="$(pwd)" | ||
|
||
# Need to figure out where the cerberus posix headers are | ||
eval "$(opam env)" | ||
|
||
# gcc flags, stored in an array for robustness | ||
GCC_FLAGS=( | ||
"-E" "-P" "-CC" "-x" "c" | ||
"--include=${ROOT_DIR}/../include/wars.h" | ||
"-I${ROOT_DIR}/../include" | ||
"-I." | ||
"-I${OPAM_SWITCH_PREFIX}/lib/cerberus/runtime/libc/include/posix" | ||
"-DCN_ENV" | ||
) | ||
|
||
# # Print the exact command for debug purposes | ||
# echo "Running gcc command:" | ||
# echo gcc "${GCC_FLAGS[@]}" "${TMP_DIR}/split_1" -o "${TMP_DIR}/split_1_out.c" | ||
|
||
gcc "${GCC_FLAGS[@]}" "${TMP_DIR}/split_1" -o "${TMP_DIR}/split_1_out.c" | ||
|
||
# 3. Concatenate the first chunk and preprocessed second chunk | ||
cat "${TMP_DIR}/split_0" "${TMP_DIR}/split_1_out.c" > "$OUTPUT_FILE" | ||
|
||
echo "Done. Merged output is in: $OUTPUT_FILE" |