Skip to content

Commit

Permalink
Fixes in block.js and sedBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
simosathan9 committed Oct 4, 2024
1 parent 18a5b3e commit 85d365d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions public/blocks/sedBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var sedBlock = {
}

generatedCommand = sedCommand;
return generatedCommand;
}
};

Expand Down
64 changes: 59 additions & 5 deletions public/js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const replacementMap = new Map([

var filenameBlocks = ['filename', 'filenamesCreate', 'fileEndStart'];

Blockly.JavaScript.forBlock['filename'] = function (block) {
var filename = block.getFieldValue('FILENAME');
return [JSON.stringify(filename), Blockly.JavaScript.ORDER_NONE];
};

function generateCommandFromWorkspace() {
let currentBlock = workspace.getTopBlocks()[0];
let generatedCommand = '';
Expand All @@ -19,13 +14,16 @@ function generateCommandFromWorkspace() {
while (currentBlock) {
blockCount++;
var blockDef = window[currentBlock.type + 'Block'];
const specificCommand = handleSpecificBlocks(currentBlock);
try {
if (
blockDef &&
(blockDef.category === 'I/O Redirection' ||
blockDef.category === 'Regular Expressions')
) {
generatedCommand += handleBlock(currentBlock);
} else if (specificCommand) {
generatedCommand += (generatedCommand ? ' | ' : '') + specificCommand;
} else {
generatedCommand +=
(generatedCommand ? ' | ' : '') + handleBlock(currentBlock);
Expand Down Expand Up @@ -368,6 +366,47 @@ function handleMainBlocks(
return commandParts;
}

function handleSpecificBlocks(currentBlock) {
let generatedCommand = '';
// Handle different block types
if (currentBlock.type === 'touch') {
generatedCommand = touchBlock.generateCommand(currentBlock);
} else if (currentBlock.type === 'sed') {
generatedCommand = sedBlock.generateCommand(currentBlock);
} else if (currentBlock.type === 'ln') {
generatedCommand = lnBlock.generateCommand(currentBlock);
} else if (currentBlock.type === 'mv') {
generatedCommand = mvBlock.generateCommand(currentBlock);
} else if (currentBlock.type === 'rm') {
generatedCommand = rmBlock.generateCommand(currentBlock);
}
return generatedCommand;
}

function handleArgumentsBlocks(block) {
console.log('handleArgumentsBlocks - init');
var arguments = '';
if (block && block.type === 'argumentsCreate') {
console.log('handleArgumentsBlocks - block:', block.type);
let args = [];
for (let i = 0; i < block.itemCount_; i++) {
let inputBlock = block.getInputTargetBlock('ADD' + i);
if (inputBlock) {
let arg = inputBlock.getFieldValue('ARGUMENT');
if (arg) {
args.push(arg);
}
}
}
return args.join(' ');
} else if (block && block.type === 'argument') {
console.log('handleArgumentsBlocks - block:', block.type);
return block.getFieldValue('ARGUMENT');
} else {
return '';
}
}

function handleRegexBlocks(block, blockDefinition, patternValue) {
console.log('handleRegexBlocks init');
let commandParts = [];
Expand Down Expand Up @@ -625,6 +664,21 @@ function handleFilenamesBlocks(block) {
return filename;
}

function getFileNames(block) {
console.log('getFileNames - init');
let fileNames = [];
for (let i = 0; i < block.itemCount_; i++) {
let inputBlock = block.getInputTargetBlock('ADD' + i);
if (inputBlock) {
let fileName = inputBlock.getFieldValue('FILENAME');
if (fileName) {
fileNames.push(fileName);
}
}
}
return fileNames.join(' ');
}

function getMultiplePrints(block) {
console.log('getMultiplePrints - init');
let prints = [];
Expand Down

0 comments on commit 85d365d

Please sign in to comment.