Skip to content

Commit

Permalink
Add -b (from beginning) option
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Dec 21, 2024
1 parent 4f849c2 commit 4b147cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
6 changes: 5 additions & 1 deletion man/cscut.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH CSCUT 1 "10 December 2024"
.TH CSCUT 1 "21 December 2024"
.\"
.\" (C) Copyright 2024 Diomidis Spinellis
.\"
Expand All @@ -21,6 +21,7 @@
cscut \- Extract portions of a CScout processing script
.SH SYNOPSIS
\fBcscut\fP
[\fB-b\fP]
[\fB-e\fP]
[\fB-F\fP \fIfile-list\fP | \fB-f\fP \fIfile\fP | \fB-p\fP \fIproject\fP]
\fIcscout-file\fP
Expand All @@ -32,6 +33,9 @@ script based on files or projects.
.PP
The following options are available:
.TP
\fB-b\fP
Output from the file's beginning until the specified point.
.TP
\fB-e\fP
Output from the specified point to the end of the file.
.TP
Expand Down
25 changes: 18 additions & 7 deletions src/cscut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ set -eu
usage()
{
cat <<EOF 1>&2
Usage: $(basename $0) [-e] (-F file-list|-f file|-p project) cscout-file
Usage: $(basename $0) [-be] (-F file-list|-f file|-p project) cscout-file
-b Output from the beginning to the specified point
-e Output from specified point to the end
-F file-list Process only the specified files contained in file-list file
-f file Process only the specified file
Expand All @@ -47,23 +48,29 @@ file_list=''
# Non-empty if a project is being cut
project=''

# Non-empty if files from the beginning are to be cut
from_beginning=''

# Non-empty if files until the end are to be cut
to_end=''


# Process command-line arguments
while getopts "eF:f:p:" opt; do
while getopts "beF:f:p:" opt; do
case $opt in
b)
from_beginning=1
;;
e)
to_end=1
;;
f)
search="$OPTARG"
file=1
;;
F)
file_list="$OPTARG"
;;
e)
to_end=1
;;
p)
search="project $OPTARG"
project=1
Expand Down Expand Up @@ -95,7 +102,11 @@ extract()

local pattern=$(echo "$search" | sed 's/\([].\\*$^\/[]\)/\\\1/g')

local begin="/#pragma echo \"Processing $pattern\\\\n\"/"
if [ -n "$from_beginning" ]; then
local begin=1
else
local begin="/#pragma echo \"Processing $pattern\\\\n\"/"
fi

if [ -n "$to_end" ]; then
local end=\$
Expand All @@ -106,7 +117,7 @@ extract()
sed -n "${begin},${end}p" "$csfile"
}

if [ -z "$project" ] ; then
if [ -z "$project" -a -z "$from_beginning" ]] ; then
cat <<\EOF
#pragma project "cscut"
#pragma block_enter
Expand Down

0 comments on commit 4b147cf

Please sign in to comment.