Skip to content

Commit

Permalink
Structure changes in awk
Browse files Browse the repository at this point in the history
  • Loading branch information
simosathan9 committed Oct 1, 2024
1 parent 39c2d0f commit f8ec981
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 119 deletions.
102 changes: 51 additions & 51 deletions bin/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
#!/bin/sh

# Run npm run check to perform checks before committing
npm run format-check

# If npm run check fails (returns non-zero exit code), exit with error
if [ $? -ne 0 ]; then
echo "npm run check failed, aborting commit."
echo "Run 'npm run prettier-fix' to fix formatting issues."
exit 1
fi

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --type=bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi

# If there are whitespace errors, print the offending file names and fail.
#!/bin/sh

# Run npm run check to perform checks before committing
npm run format-check

# If npm run check fails (returns non-zero exit code), exit with error
if [ $? -ne 0 ]; then
echo "npm run check failed, aborting commit."
echo "Run 'npm run prettier-fix' to fix formatting issues."
exit 1
fi

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --type=bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi

# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --
Binary file modified db/blockly_unix_database.db
Binary file not shown.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<script src="blocks/NRBlock.js"></script>
<script src="blocks/NFBlock.js"></script>
<script src="blocks/xargsBlock.js"></script>
<script src="blocks/conditionActionBlock.js"></script>
<!-- END OF BLOCK DEFINITION -->
<script>
document.addEventListener('DOMContentLoaded', () => {
Expand Down Expand Up @@ -452,6 +453,7 @@
colour: '#3B7C09',
contents: [
{ kind: 'block', type: 'beginEnd' },
{ kind: 'block', type: 'conditionAction' },
{ kind: 'block', type: 'awk' },
{ kind: 'block', type: 'condOutput' },
{ kind: 'block', type: 'column' },
Expand Down
56 changes: 4 additions & 52 deletions public/blocks/awkBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ var awkBlock = {
category: 'Data Processing',
unix_description: [
{
awkInput_delimiter: "-F'str' ", // Change to awk_delimiter
awkOutput_delimiter: 'OFS"str"', // Change to awk_delimiter
input_variable: '-v"',
regPattern: "'{patt",
awk_cols: "{print str}}'",
begin: 'BEGIN',
end: 'END'
awkInput_delimiter: "-F 'str' " // Change to awk_delimiter
}
],
message0: '%{BKY_AWK_TEXT_DATA_PROCESSING}',
Expand All @@ -21,53 +15,11 @@ var awkBlock = {
text: ''
}
],
message2: '%{BKY_AWK_OUTPUT_DELIMITER} %1',
message2: '%{BKY_AWK_CONDITION_ACTION} %1',
args2: [
{
type: 'field_input',
name: 'awkOutput_delimiter', // Change to output awk_delimiter
text: '',
align: 'RIGHT'
}
],
message3: '%{BKY_AWK_VARIABLE_INPUT} %1',
args3: [
{
type: 'field_checkbox',
name: 'input_variable',
checked: false // by default it's disabled
}
],
message3: '%{BKY_AWK_BEGIN} %1',
args3: [
{
type: 'input_value',
name: 'begin',
check: 'String'
}
],
message4: '%{BKY_AWK_ACTION} %1',
args4: [
{
type: 'input_value',
name: 'regPattern',
check: 'String'
}
],
message5: '%{BKY_AWK_BEGIN} %1',
args5: [
{
type: 'input_value',
name: 'end',
check: 'String'
}
],
message6: '%{BKY_AWK_PRINT} %1',
args6: [
{
type: 'input_value',
name: 'awk_cols',
text: ''
type: 'input_statement',
name: 'awkConditionAction'
}
],
style: 'Data Processing',
Expand Down
26 changes: 26 additions & 0 deletions public/blocks/conditionActionBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var conditionActionBlock = {
type: 'conditionAction',
category: 'Data Processing',
message0: '%{BKY_CONDITION_ACTION_COND} %1',
args0: [
{
type: 'input_statement',
name: 'COND'
}
],
message1: '%{BKY_CONDITION_ACTION_ACT} %1',
args1: [
{
type: 'input_statement',
name: 'DO'
}
],
previousStatement: true,
nextStatement: true,
nextStatement: null,
style: 'Data Processing',
tooltip: '%{BKY_CONDITION_ACTION_TOOLTIP}',
helpUrl: '%{BKY_CONDITION_ACTION_HELPURL}' // URL to further information or documentation.
};

Blockly.defineBlocksWithJsonArray([conditionActionBlock]);
12 changes: 9 additions & 3 deletions public/js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ document
pattern = pattern.replace(/\s+/g, '/');
replacementText = replacementText.replace(/\s+/g, '/');
// Extract if 'g' flag is present
const hasGlobalFlag = sedCommand.includes('g');
const hasGlobalFlag =
currentBlock.getFieldValue('globally') === 'TRUE';
// Construct the sed command with the escaped slashes and ensure no extra space between pattern/replacement
if (sedCommand.startsWith('sed ')) {
sedCommand = sedCommand.replace(
Expand All @@ -157,6 +158,12 @@ document
`sed -E 's/${pattern}/${replacementText}/` +
(hasGlobalFlag ? 'g' : '') +
`'`; // Ensure proper formatting

let previousBlock = currentBlock.getPreviousBlock();
if (previousBlock && previousBlock.type === 'filenamesCreate') {
const filenames = handleFilenamesBlocks(previousBlock); // Assuming handleFilenamesBlocks extracts filenames
sedCommand += ` ${filenames}`; // Append filenames to the sed command
}
}
// Add the constructed sed command to the generatedCommand
generatedCommand += (generatedCommand ? ' | ' : '') + sedCommand;
Expand Down Expand Up @@ -372,7 +379,7 @@ function handleBlock(block) {
if (blockType === 'awk') {
regexStringValue = '';
let contains = commandParts.some(
(element) => element && element.includes("-F'")
(element) => element && element.includes("-F '")
);
if (!contains) {
commandParts[0] = "'" + commandParts[0];
Expand Down Expand Up @@ -456,7 +463,6 @@ function handleBlock(block) {
' ' +
beginValue +
' ' +
filteredArray.join(' ') +
' ' +
regexStringValue +
' ' +
Expand Down
12 changes: 5 additions & 7 deletions public/msg/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ Blockly.Msg['ARRAY_CREATE_EMPTY_TITLE'] = 'Δημιουργία λίστας σ
Blockly.Msg['ARRAY_CREATE_WITH_HELPURL'] = '';
Blockly.Msg['AWK_TEXT_DATA_PROCESSING'] = 'Επεξεργασία δεδομένων κειμένου';
Blockly.Msg['AWK_INPUT_DELIMITER'] = 'Διαχωριστής εισόδου';
Blockly.Msg['AWK_OUTPUT_DELIMITER'] = 'Διαχωριστής εξόδου';
Blockly.Msg['AWK_VARIABLE_INPUT'] = 'Μεταβλητή εισόδου';
Blockly.Msg['AWK_BEGIN'] =
'Εκτέλεση μία φορά πριν από την επεξεργασία δεδομένων';
Blockly.Msg['AWK_ACTION'] = 'Ενέργεια';
Blockly.Msg['AWK_END'] = 'Εκτέλεση μία φορά μετά την επεξεργασία δεδομένων';
Blockly.Msg['AWK_PRINT'] = 'Στήλες προς εκτύπωση';
Blockly.Msg['AWK_CONDITION_ACTION'] = 'Τοποθετήστε συνθήκη και ενέργεια';
Blockly.Msg['AWK_TOOLTIP'] = 'Γλώσσα σάρωσης και επεξεργασίας με βάση μοτίβα';
Blockly.Msg['AWK_HELPURL'] = 'https://www.google.com/';
Blockly.Msg['BEGIN_END'] =
Expand All @@ -89,6 +83,10 @@ Blockly.Msg['CONDITION_OUTPUT'] = 'Τοποθετήστε συνθήκη ανα
Blockly.Msg['CONDITION_OUTPUT_TOOLTIP'] =
'Δημιουργία συνθήκης αναζήτησης με δηλώσεις if';
Blockly.Msg['CONDITION_OUTPUT_HELPURL'] = 'https://www.google.com/';
Blockly.Msg['CONDITION_ACTION_COND'] = 'Συνθήκη';
Blockly.Msg['CONDITION_ACTION_ACT'] = 'Ενέργεια';
Blockly.Msg['CONDITION_ACTION_TOOLTIP'] = 'Δημιουργία συνθήκης και ενέργειας';
Blockly.Msg['CONDITION_ACTION_HELPURL'] = 'https://www.google.com/';
Blockly.Msg['CUT'] = 'Αποκοπή σε αρχείο ή συμβολοσειρά';
Blockly.Msg['CUT_DELIMITER'] = 'Διαχωριστικό';
Blockly.Msg['CUT_DEFINE_COLUMNS'] = 'Ορισμός στηλών';
Expand Down
11 changes: 5 additions & 6 deletions public/msg/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ Blockly.Msg['ARRAY_CREATE_EMPTY_TITLE'] = 'Create list of elements';
Blockly.Msg['ARRAY_CREATE_WITH_HELPURL'] = '';
Blockly.Msg['AWK_TEXT_DATA_PROCESSING'] = 'Text data processing';
Blockly.Msg['AWK_INPUT_DELIMITER'] = 'Input delimiter';
Blockly.Msg['AWK_OUTPUT_DELIMITER'] = 'Output delimiter';
Blockly.Msg['AWK_VARIABLE_INPUT'] = 'Variable input';
Blockly.Msg['AWK_BEGIN'] = 'Execute once before data is processed';
Blockly.Msg['AWK_ACTION'] = 'Action';
Blockly.Msg['AWK_END'] = 'Execute once after data is processed';
Blockly.Msg['AWK_PRINT'] = 'Columns to print';
Blockly.Msg['AWK_CONDITION_ACTION'] = 'Condition and action';
Blockly.Msg['AWK_TOOLTIP'] =
'pattern-directed scanning and processing language';
Blockly.Msg['AWK_HELPURL'] = 'https://www.google.com/';
Expand All @@ -88,6 +83,10 @@ Blockly.Msg['CONDITION_OUTPUT'] = 'Put search condition';
Blockly.Msg['CONDITION_OUTPUT_TOOLTIP'] =
'Construct a search condition with if statements';
Blockly.Msg['CONDITION_OUTPUT_HELPURL'] = 'https://www.google.com/';
Blockly.Msg['CONDITION_ACTION_COND'] = 'Condition';
Blockly.Msg['CONDITION_ACTION_ACT'] = 'Action';
Blockly.Msg['CONDITION_ACTION_TOOLTIP'] = 'Condition and action';
Blockly.Msg['CONDITION_ACTION_HELPURL'] = 'https://www.google.com/';
Blockly.Msg['CUT'] = 'Cut out in file or string';
Blockly.Msg['CUT_DELIMITER'] = 'Delimiter';
Blockly.Msg['CUT_DEFINE_COLUMNS'] = 'Define columns';
Expand Down

0 comments on commit f8ec981

Please sign in to comment.