├── _config.yml ├── .gitignore ├── lib ├── template.cpp ├── cp-automation-view.js ├── codeforces.js ├── atcoder.js ├── codechef.js ├── component.js ├── diffComponent.js └── cp-automation.js ├── keymaps └── cp-automation.json ├── spec ├── cp-automation-view-spec.js └── cp-automation-spec.js ├── styles ├── cp-automation.less └── cp-automation.css ├── menus └── cp-automation.json ├── package.json ├── LICENSE └── readme.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /lib/template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /keymaps/cp-automation.json: -------------------------------------------------------------------------------- 1 | { 2 | "atom-workspace": { 3 | "ctrl-alt-k": "cp-automation:toggle", 4 | "ctrl-alt-c": "cp-automation:compile", 5 | "ctrl-alt-p": "cp-automation:diff", 6 | "ctrl-alt-o": "cp-automation:removeDiff" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /spec/cp-automation-view-spec.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | 3 | import CpAutomationView from '../lib/cp-automation-view'; 4 | 5 | describe('CpAutomationView', () => { 6 | it('has one valid test', () => { 7 | expect('life').toBe('easy'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /styles/cp-automation.less: -------------------------------------------------------------------------------- 1 | // The ui-variables file is provided by base themes provided by Atom. 2 | // 3 | // See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less 4 | // for a full listing of what's available. 5 | @import "ui-variables"; 6 | 7 | .cp-automation { 8 | } 9 | 10 | .diffText{ 11 | font-family: var(--editor-font-family); 12 | font-size: var(--editor-font-size); 13 | line-height: var(--editor-line-height); 14 | } -------------------------------------------------------------------------------- /lib/cp-automation-view.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | 3 | export default class CpAutomationView { 4 | 5 | constructor(serializedState) { 6 | // Create root element 7 | this.element = document.createElement('div'); 8 | this.element.classList.add('cp-automation'); 9 | 10 | // Create message element 11 | const message = document.createElement('div'); 12 | message.textContent = 'The CpAutomation package is Alive! It\'s ALIVE!'; 13 | message.classList.add('message'); 14 | this.element.appendChild(message); 15 | } 16 | 17 | // Returns an object that can be retrieved when package is activated 18 | serialize() {} 19 | 20 | // Tear down any state and detach 21 | destroy() { 22 | this.element.remove(); 23 | } 24 | 25 | getElement() { 26 | return this.element; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /menus/cp-automation.json: -------------------------------------------------------------------------------- 1 | { 2 | "context-menu": { 3 | "atom-text-editor": [ 4 | { 5 | "label": "Toggle cp-automation", 6 | "command": "cp-automation:toggle" 7 | }, 8 | { 9 | "label": "Compile cp-automation", 10 | "command": "cp-automation:compile" 11 | }, 12 | { 13 | "label": "Diff cp-automation", 14 | "command": "cp-automation:diff" 15 | } 16 | ] 17 | }, 18 | "menu": [ 19 | { 20 | "label": "Packages", 21 | "submenu": [ 22 | { 23 | "label": "cp-automation", 24 | "submenu": [ 25 | { 26 | "label": "Toggle", 27 | "command": "cp-automation:toggle" 28 | }, 29 | { 30 | "label": "Compile", 31 | "command": "cp-automation:compile" 32 | } 33 | ] 34 | } 35 | ] 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "AFCP", 3 | "main": "./lib/cp-automation", 4 | "version": "0.8.20", 5 | "description": "Automation for programming contests.", 6 | "repository": "https://github.com/horcrux2301/AFCP", 7 | "author": "Harsh Khajuria", 8 | "keywords": [], 9 | "activationCommands": { 10 | "atom-workspace": [ 11 | "cp-automation:toggle", 12 | "cp-automation:compile", 13 | "cp-automation:diff", 14 | "cp-automation:removeDiff" 15 | ] 16 | }, 17 | "license": "MIT", 18 | "engines": { 19 | "atom": ">=1.0.0 <2.0.0" 20 | }, 21 | "dependencies": { 22 | "async": "^2.6.1", 23 | "cheerio": "^1.0.0-rc.2", 24 | "diff": "^3.5.0", 25 | "etch": "^0.14.0", 26 | "filehound": "^1.16.2", 27 | "fs": "0.0.1-security", 28 | "jsdiff": "^1.1.1", 29 | "nightmare": "^3.0.1", 30 | "node-exec-promise": "^1.0.2", 31 | "performance-now": "^2.1.0", 32 | "pidtree": "^0.3.0", 33 | "ps-tree": "^1.1.0", 34 | "request": "^2.85.0", 35 | "request-promise": "^4.2.2", 36 | "shelljs": "^0.8.1", 37 | "tree-kill": "^1.2.2" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2017 HARSH KHAJURIA 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /styles/cp-automation.css: -------------------------------------------------------------------------------- 1 | .top-div{ 2 | text-align: center; 3 | padding: 10px; 4 | } 5 | 6 | .check-span{ 7 | padding: 10px; 8 | } 9 | 10 | .fetch-btn{ 11 | color: black; 12 | border: none; 13 | margin-left: 10px; 14 | background-color: white; 15 | border-radius: 5px; 16 | } 17 | 18 | .bottom-div{ 19 | text-align: center; 20 | padding: 10px; 21 | } 22 | 23 | .contestcode-input{ 24 | border: none; 25 | border-radius: 4px; 26 | width: 150px; 27 | font-weight: 600; 28 | color: black; 29 | } 30 | 31 | .heading{ 32 | font-size: 15px; 33 | text-align: center; 34 | } 35 | 36 | .show-heading{ 37 | display: block; 38 | } 39 | 40 | .hide-heading{ 41 | display: none; 42 | } 43 | 44 | .show-fetching{ 45 | display: block; 46 | font-size: 17px; 47 | color: white; 48 | text-align: center; 49 | } 50 | 51 | .hide-fetching{ 52 | display: none; 53 | } 54 | 55 | 56 | .addedText{ 57 | background-color: #bbff99; 58 | } 59 | 60 | .removedText{ 61 | background-color: #ffcccc; 62 | } 63 | 64 | .noneText{ 65 | background-color: rgb(40,44,52); 66 | } 67 | 68 | 69 | .files-list{ 70 | display: inline; 71 | padding: 5px; 72 | font-size: 14px; 73 | } 74 | 75 | .files-list:hover{ 76 | background-color: white; 77 | cursor: pointer; 78 | color: black; 79 | } 80 | 81 | .files-list-active{ 82 | background-color: white; 83 | color: black; 84 | } 85 | 86 | .files-list-div{ 87 | padding-bottom: 5px; 88 | } 89 | 90 | .main-div{ 91 | min-width: 300px; 92 | } 93 | 94 | .diff-view-header{ 95 | text-align: center; 96 | font-size: 13px; 97 | padding-top: 5px; 98 | padding-bottom: 5px; 99 | } 100 | -------------------------------------------------------------------------------- /lib/codeforces.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | import request from 'request'; 3 | import cheerio from 'cheerio'; 4 | import fs from 'fs'; 5 | import rp from 'request-promise'; 6 | 7 | export function FetchDataCodeforces(dir, contestCode){ 8 | atom.notifications.addInfo('Fetching data for the contest code ' + contestCode); 9 | let problems = []; 10 | rp('http://codeforces.com/contest/' + contestCode, (error,response,body) => { 11 | const $ = cheerio.load(body); 12 | $("option").each((i,el) => { 13 | let temp = {}; 14 | let b = $(el).attr("value") 15 | let a = $(el).attr("data-problem-name"); 16 | if(a!==undefined && a!=''){ 17 | temp.code = b; 18 | temp.name = a; 19 | problems.push(temp); 20 | } 21 | }) 22 | }) 23 | .then(() => { 24 | baseurl1 = 'http://codeforces.com/contest/' + contestCode +'/problem/'; 25 | fs.mkdirSync(dir + contestCode); 26 | Object.keys(problems).map((problem) => { 27 | testcases(baseurl1+problems[problem].code, problems[problem].name,contestCode, dir); 28 | }); 29 | 30 | }); 31 | } 32 | 33 | function testcases(url,name,contestCode,dir){ 34 | atom.notifications.addInfo(`Fetching data for problem ${name}`); 35 | rp(url, (a,b,c) => { 36 | const $ = cheerio.load(c); 37 | fs.mkdirSync(dir + contestCode + '/' + name); 38 | fs.closeSync(fs.openSync(dir + contestCode + '/' + name + '/' + name + '.cpp', 'w')); 39 | fs.createReadStream(__dirname + '/template.cpp').pipe(fs.createWriteStream(dir + contestCode + '/' + name + '/' + name + '.cpp')); 40 | $("div[class=\"input\"]").each((i,el) => { 41 | let xx = $(el).children("pre"); 42 | let ss = xx.html(); 43 | ss = ss.replace(/
/g, "\n"); 44 | fs.appendFileSync(dir + contestCode + '/' + name + '/input' + i +'.txt', ss); 45 | }); 46 | $("div[class=\"output\"]").each((i,el) => { 47 | let xx = $(el).children("pre"); 48 | let ss = xx.html(); 49 | ss = ss.replace(/
/g, "\n"); 50 | fs.appendFileSync(dir + contestCode + '/' + name + '/output' + i +'.txt', ss); 51 | }); 52 | }) 53 | .then(() => { 54 | console.log(''); 55 | }); 56 | } 57 | -------------------------------------------------------------------------------- /lib/atcoder.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | import cheerio from 'cheerio'; 3 | import fs from 'fs'; 4 | import rp from 'request-promise'; 5 | 6 | export function FetchDataAtcoder(dir, contestCode){ 7 | atom.notifications.addInfo('Fetching data for the contest code ' + contestCode); 8 | let problems = []; 9 | let contestUrl = 'https://' + contestCode +'.contest.atcoder.jp/assignments'; 10 | rp(contestUrl , (error,response,body) => { 11 | const $ = cheerio.load(body); 12 | $("td").each((i,el) => { 13 | if(i%5===0){ 14 | let temp = {}; 15 | temp.link = $("a",el).attr("href"); 16 | temp.code = $(el).text(); 17 | problems.push(temp); 18 | } 19 | else if(i%5==1){ 20 | problems[Math.floor(i/5)].name = $(el).text(); 21 | } 22 | }) 23 | }) 24 | .then(() => { 25 | baseurl1 = 'https://' + contestCode + '.contest.atcoder.jp'; 26 | fs.mkdirSync(dir + contestCode); 27 | Object.keys(problems).map((problem) => { 28 | testcases(baseurl1+problems[problem].link, problems[problem].name,problems[problem].code, contestCode, dir); 29 | }); 30 | 31 | }) 32 | .catch((err) => { 33 | console.log(err); 34 | }); 35 | } 36 | 37 | function testcases(url,name,code,contestCode,dir){ 38 | atom.notifications.addInfo(`Fetching data for problem ${name}`); 39 | rp(url, (a,b,c) => { 40 | const $ = cheerio.load(c); 41 | fs.mkdirSync(dir + contestCode + '/' + name); 42 | fs.closeSync(fs.openSync(dir + contestCode + '/' + name + '/' + name + '.cpp', 'w')); 43 | fs.createReadStream(__dirname + '/template.cpp').pipe(fs.createWriteStream(dir + contestCode + '/' + name + '/' + name + '.cpp')); 44 | let xyz = $("section>pre"); 45 | let size = Object.keys(xyz).length; 46 | let start = 1; 47 | let end = size-5; 48 | end = Math.floor(end/2); 49 | $("section>pre").each((i,el) => { 50 | if(i>=1 && i<=end){ 51 | let text = $(el).text(); 52 | if(i%2===0){ 53 | let k = Math.floor(i/2)-1; 54 | fs.appendFileSync(dir + contestCode + '/' + name + '/output' + k +'.txt', text); 55 | } 56 | else{ 57 | let k = Math.floor((i-1)/2); 58 | fs.appendFileSync(dir + contestCode + '/' + name + '/input' + k +'.txt', text); 59 | } 60 | } 61 | }); 62 | }) 63 | .then(() => { 64 | console.log(''); 65 | }); 66 | } 67 | -------------------------------------------------------------------------------- /spec/cp-automation-spec.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | 3 | import CpAutomation from '../lib/cp-automation'; 4 | 5 | // Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. 6 | // 7 | // To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` 8 | // or `fdescribe`). Remove the `f` to unfocus the block. 9 | 10 | describe('CpAutomation', () => { 11 | let workspaceElement, activationPromise; 12 | 13 | beforeEach(() => { 14 | workspaceElement = atom.views.getView(atom.workspace); 15 | activationPromise = atom.packages.activatePackage('cp-automation'); 16 | }); 17 | 18 | describe('when the cp-automation:toggle event is triggered', () => { 19 | it('hides and shows the modal panel', () => { 20 | // Before the activation event the view is not on the DOM, and no panel 21 | // has been created 22 | expect(workspaceElement.querySelector('.cp-automation')).not.toExist(); 23 | 24 | // This is an activation event, triggering it will cause the package to be 25 | // activated. 26 | atom.commands.dispatch(workspaceElement, 'cp-automation:toggle'); 27 | 28 | waitsForPromise(() => { 29 | return activationPromise; 30 | }); 31 | 32 | runs(() => { 33 | expect(workspaceElement.querySelector('.cp-automation')).toExist(); 34 | 35 | let cpAutomationElement = workspaceElement.querySelector('.cp-automation'); 36 | expect(cpAutomationElement).toExist(); 37 | 38 | let cpAutomationPanel = atom.workspace.panelForItem(cpAutomationElement); 39 | expect(cpAutomationPanel.isVisible()).toBe(true); 40 | atom.commands.dispatch(workspaceElement, 'cp-automation:toggle'); 41 | expect(cpAutomationPanel.isVisible()).toBe(false); 42 | }); 43 | }); 44 | 45 | it('hides and shows the view', () => { 46 | // This test shows you an integration test testing at the view level. 47 | 48 | // Attaching the workspaceElement to the DOM is required to allow the 49 | // `toBeVisible()` matchers to work. Anything testing visibility or focus 50 | // requires that the workspaceElement is on the DOM. Tests that attach the 51 | // workspaceElement to the DOM are generally slower than those off DOM. 52 | jasmine.attachToDOM(workspaceElement); 53 | 54 | expect(workspaceElement.querySelector('.cp-automation')).not.toExist(); 55 | 56 | // This is an activation event, triggering it causes the package to be 57 | // activated. 58 | atom.commands.dispatch(workspaceElement, 'cp-automation:toggle'); 59 | 60 | waitsForPromise(() => { 61 | return activationPromise; 62 | }); 63 | 64 | runs(() => { 65 | // Now we can test for view visibility 66 | let cpAutomationElement = workspaceElement.querySelector('.cp-automation'); 67 | expect(cpAutomationElement).toBeVisible(); 68 | atom.commands.dispatch(workspaceElement, 'cp-automation:toggle'); 69 | expect(cpAutomationElement).not.toBeVisible(); 70 | }); 71 | }); 72 | }); 73 | }); 74 | -------------------------------------------------------------------------------- /lib/codechef.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | 3 | import Nightmare from 'nightmare' ; 4 | import fs from 'fs'; 5 | 6 | export function FetchDataCodechef(dir,contestCode){ 7 | atom.notifications.addInfo('Fetching data for the contest code ' + contestCode); 8 | const nightmare = Nightmare({ 9 | electronPath: require('../node_modules/electron'), 10 | waitTimeout: 150000, 11 | show: false 12 | }); 13 | nightmare 14 | .goto('https://www.codechef.com/' + contestCode) 15 | .wait('td.cc-problem-name') 16 | .evaluate(() => 17 | { 18 | return Array.from(document.querySelectorAll('a.ember-view')).map( 19 | element => ({"link" : element.href, "name" : element.title}) 20 | ); 21 | } 22 | ) 23 | .end() 24 | .then((data) => { 25 | var x = iterateProblems(data); 26 | x.then((data) => { 27 | console.log('done', data); 28 | createFiles(data,dir,contestCode); 29 | }); 30 | }) 31 | .catch(error => { 32 | console.error('Search failed:', error) 33 | }) 34 | } 35 | 36 | async function iterateProblems(data) { 37 | for (let i = 4; i < data.length; i++) { 38 | const problem = data[i]; 39 | const x = await testcases(problem); 40 | data[i].testCases = x; 41 | } 42 | return data; 43 | } 44 | 45 | function testcases(problem){ 46 | atom.notifications.addInfo(`Fetching data for problem ${problem.name}`); 47 | const nightmarex = Nightmare({ 48 | electronPath: require('../node_modules/electron'), 49 | waitTimeout: 150000, 50 | show: false, 51 | }); 52 | return new Promise(resolve => { 53 | nightmarex 54 | .goto(problem.link) 55 | .wait('pre.mathjax-support') 56 | .evaluate(() => 57 | { 58 | return Array.from(document.querySelectorAll('pre.mathjax-support')).map( 59 | element => element.innerText 60 | ); 61 | } 62 | ) 63 | .end() 64 | .then((data) => { 65 | // console.log("result for problem is" , problem); 66 | resolve(data); 67 | }) 68 | .catch(error => { 69 | console.error('Search failed:', error) 70 | }) 71 | }); 72 | } 73 | 74 | function createFiles(data,dir, contestCode){ 75 | fs.mkdirSync(dir + contestCode); 76 | for (let i = 4; i < data.length; i++){ 77 | let problem = data[i]; 78 | let name = problem.name; 79 | let cases = problem.testCases; 80 | fs.mkdirSync(dir + contestCode + '/' + name); 81 | fs.closeSync(fs.openSync(dir + contestCode + '/' + name + '/' + name + '.cpp', 'w')); 82 | fs.createReadStream(__dirname + '/template.cpp').pipe(fs.createWriteStream(dir + contestCode + '/' + name + '/' + name + '.cpp')); 83 | cases.forEach((el,i) => { 84 | let caseHere = el.replace(/
/g, "\n"); 85 | let casex = cleanmyData(caseHere); 86 | fs.appendFileSync(dir + contestCode + '/' + name + '/input' + i +'.txt', casex.input); 87 | fs.appendFileSync(dir + contestCode + '/' + name + '/output' + i +'.txt', casex.output); 88 | }); 89 | }; 90 | } 91 | 92 | function cleanmyData(casex){ 93 | let ind1 = casex.indexOf("Input"); 94 | let ind2 = casex.indexOf("Output"); 95 | ind1+=5; 96 | while(casex[ind1]===' ') 97 | ind1+=1; 98 | let input = casex.substring(ind1+2,ind2); 99 | ind2+=7; 100 | while(casex[ind2]===' ') 101 | ind2+=1; 102 | let output = casex.substring(ind2+1,casex.length); 103 | let a = {}; 104 | a.input = input; 105 | a.output = output; 106 | // console.log(a); 107 | return a; 108 | } 109 | -------------------------------------------------------------------------------- /lib/component.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | /** @jsx etch.dom */ 3 | 4 | const etch = require('etch'); 5 | import { FetchDataCodeforces } from './codeforces'; 6 | import { FetchDataAtcoder } from './atcoder'; 7 | import { FetchDataCodechef } from './codechef'; 8 | 9 | export default class ChildView { 10 | constructor (Atcoderdir, Codeforcesdir, Codechefdir) { 11 | this.isCodechef = false; 12 | this.isCodeforces = false; 13 | this.isAtcoder = false; 14 | this.contestCode = ''; 15 | this.Atcoderdir = Atcoderdir; 16 | this.Codeforcesdir = Codeforcesdir; 17 | this.Codechefdir = Codechefdir; 18 | this.isFetching = false; 19 | etch.initialize(this); 20 | } 21 | 22 | render () { 23 | return
24 |
25 |
26 | Select the site and enter the code. 27 |
28 |
29 | 30 | Codechef 31 | 32 | 33 | Codeforces 34 | 35 | 36 | Atcoder 37 | 38 |
39 |
40 | 41 | 42 |
43 |
44 |
45 | Fetching data. Press ctrl+alt+k to close. 46 |
47 |
48 | } 49 | 50 | clickedCodeChef() { 51 | this.isCodechef = true; 52 | this.isCodeforces = false; 53 | this.isAtcoder = false; 54 | etch.update(this); 55 | } 56 | 57 | clickedCodeforces() { 58 | console.log(this); 59 | this.isCodechef = false; 60 | this.isCodeforces = true; 61 | this.isAtcoder = false; 62 | etch.update(this); 63 | } 64 | 65 | clickedAtCoder() { 66 | this.isCodechef = false; 67 | this.isCodeforces = false; 68 | this.isAtcoder = true; 69 | etch.update(this); 70 | } 71 | 72 | getContestCode() { 73 | return this.contestCode; 74 | } 75 | 76 | closePane() { 77 | this.showPane.hide(); 78 | } 79 | 80 | getData(e) { 81 | e.preventDefault(); 82 | this.isFetching = true; 83 | console.log(this); 84 | etch.update(this); 85 | if (this.contestCode === '') { 86 | atom.notifications.addError('Add a contest code.'); 87 | } else { 88 | if (this.isCodechef === true) { 89 | console.log('isCodechef'); 90 | FetchDataCodechef(this.Codechefdir, this.contestCode); 91 | } else if (this.isAtcoder === true) { 92 | FetchDataAtcoder(this.Atcoderdir, this.contestCode); 93 | } else if (this.isCodeforces === true) { 94 | FetchDataCodeforces(this.Codeforcesdir, this.contestCode); 95 | } else { 96 | atom.notifications.addError('Select a site'); 97 | } 98 | } 99 | } 100 | 101 | changedContestCode(e){ 102 | this.contestCode = e.target.value; 103 | } 104 | 105 | update () { 106 | return etch.update(this) 107 | } 108 | 109 | async destroy () { 110 | await etch.destroy(this) 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /lib/diffComponent.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | /** @jsx etch.dom */ 3 | const etch = require('etch'); 4 | const jsdiff = require('diff'); 5 | import fs from 'fs'; 6 | 7 | class ChildComponent { 8 | constructor (properties) { 9 | this.file = properties.file; 10 | this.number = properties.number; 11 | this.diff = []; 12 | this.element =
element from
13 | etch.initialize(this); 14 | } 15 | 16 | update (properties) { 17 | this.file = properties.file; 18 | this.number = properties.number; 19 | let file1 = properties.file.in; 20 | let file2 = properties.file.out; 21 | // if(!fs.existsSync(file1) || ! fs.exsistsSync(file2)){ 22 | // console.log("a"); 23 | // return ; 24 | // } 25 | try{ 26 | var text1 = fs.readFileSync(file1).toString(); 27 | } 28 | catch (err){ 29 | console.log(err); 30 | atom.notifications.addError(`No myOutput${this.number}.txt found in this directory`); 31 | this.diff = []; 32 | etch.update(this); 33 | return ; 34 | } 35 | try{ 36 | var text2 = fs.readFileSync(file2).toString(); 37 | } 38 | catch (err){ 39 | console.log(err); 40 | atom.notifications.addError(`No output${this.number}.txt found in this directory`); 41 | this.diff = []; 42 | etch.update(this); 43 | return ; 44 | } 45 | //var diff = jsdiff.diffLines(text2, text1, {ignoreWhitespace: true, newlineIsToken: true}); 46 | var diff = jsdiff.diffWords(text2, text1); 47 | this.diff = diff; 48 | 49 | let newDiff = []; 50 | 51 | 52 | Object.keys(this.diff).map((i) => { 53 | if (this.diff[i].added !== undefined && this.diff[i].added === true) { 54 | for (let index = 0; index < this.diff[i].value.length; index++) { 55 | if (this.diff[i].value[index] === '\n') { 56 | newDiff.push({"added": true, "removed": undefined, "value": '\n'}); 57 | } else { 58 | newDiff.push({"added": true, "removed": undefined, "value": this.diff[i].value[index]}); 59 | } 60 | } 61 | } else if (this.diff[i].removed !== undefined && this.diff[i].removed === true) { 62 | for (let index = 0; index < this.diff[i].value.length; index++) { 63 | if (this.diff[i].value[index] === '\n') { 64 | newDiff.push({"added": undefined, "removed": true, "value": '\n'}); 65 | } else { 66 | newDiff.push({"added": undefined, "removed": true, "value": this.diff[i].value[index]}); 67 | } 68 | } 69 | } else { 70 | for (let index = 0; index < this.diff[i].value.length; index++) { 71 | if (this.diff[i].value[index] === '\n') { 72 | newDiff.push({"added": undefined, "removed": undefined, "value": '\n'}); 73 | } else { 74 | newDiff.push({"added": undefined, "removed": undefined, "value": this.diff[i].value[index]}); 75 | } 76 | } 77 | } 78 | 79 | 80 | }); 81 | 82 | this.diff = newDiff; 83 | return etch.update(this); 84 | } 85 | 86 | render () { 87 | return ( 88 |
89 | { 90 | Object.keys(this.diff).map((i) => { 91 | if (this.diff[i].added !== undefined && this.diff[i].added === true) { 92 | if (this.diff[i].value === '\n') { 93 | return
; 94 | } else { 95 | return {this.diff[i].value}; 96 | } 97 | } else if (this.diff[i].removed !== undefined && this.diff[i].removed === true) { 98 | if (this.diff[i].value === '\n') { 99 | return
; 100 | } else { 101 | return {this.diff[i].value}; 102 | } 103 | } else { 104 | if (this.diff[i].value === '\n') { 105 | return
; 106 | } else { 107 | return {this.diff[i].value}; 108 | } 109 | } 110 | }) 111 | } 112 |
113 | ); 114 | } 115 | } 116 | 117 | export default class DiffView { 118 | constructor (filesArray) { 119 | this.files = filesArray; 120 | this.number = 0; 121 | this.active = -1; 122 | etch.initialize(this); 123 | } 124 | 125 | update (props, children) { 126 | return etch.update(this); 127 | } 128 | 129 | didClick(e, number) { 130 | e.preventDefault(); 131 | this.number = number; 132 | this.active = number; 133 | return etch.update(this); 134 | } 135 | 136 | render () { 137 | // console.log(this.files); 138 | return ( 139 |
140 |
AFCP Diff View
141 |
142 | { 143 | Object.keys(this.files).map((i) => { 144 | return
  • this.didClick(e, i) }}>File {this.files[i].number}
  • 145 | }) 146 | } 147 |
    148 | 149 |
    150 | ); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | ## AFCP 3 | 4 | #### AFCP is a Competitive Programming Contests Automation Package for text editor Atom. 5 | 6 | [![Installs!](https://img.shields.io/apm/dm/afcp.svg?style=flat-square)](https://atom.io/packages/afcp) 7 | [![Package version!](https://img.shields.io/apm/v/afcp.svg?style=flat-square)](https://atom.io/packages/afcp) 8 | [![GitHub stars](https://img.shields.io/github/stars/horcrux2301/AFCP.svg)](https://github.com/horcrux2301/AFCP/stargazers) 9 | [![GitHub forks](https://img.shields.io/github/forks/horcrux2301/AFCP.svg)](https://github.com/horcrux2301/AFCP/network/members) 10 | [![GitHub issues](https://img.shields.io/github/issues/horcrux2301/AFCP.svg)](https://github.com/horcrux2301/AFCP/issues) 11 | [![GitHub license](https://img.shields.io/github/license/horcrux2301/AFCP.svg)](https://github.com/horcrux2301/AFCP) 12 | [![Made with Love in India](https://madewithlove.org.in/badge.svg)](https://madewithlove.org.in/) 13 | 14 | ### YouTube video explaining how to use the package 15 | 16 | [![YouTube Icon](https://i.imgur.com/neHd1HE.jpg)](https://www.youtube.com/watch?v=vlOA-zxK_bE) 17 | 18 | Sites Supported | Yes 19 | ------------ | ------------- 20 | Codechef | :white_check_mark: 21 | Codeforces | :white_check_mark: 22 | Atcoder | :white_check_mark: 23 | 24 | `Note:- The package has been fairly tested for MacOS and Linux. However Windows users might face some issues. Please open one in the repo if you do.`. 25 | 26 | **The notification feature is not currently supported for windows. I don't have access to a machine right now to test the code for windows, but you can expect an update for windows in a couple of days.** 27 | 28 | [Never used atom for competing? Read this](#packages) 29 | 30 | ## Installation 31 | 32 | Install package either by running `apm install afcp` from the terminal or by searching in the Install menu from Atom. 33 | 34 | You will also need to install the following to use the package properly. 35 | 36 | Linux - 37 | 38 | 1. [Install gcc](https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91) 39 | 40 | MacOS- 41 | 42 | 1. Install gcc. This can be done by installing Xcode or Command Line Developer Tools. 43 | 44 | Windows - 45 | 46 | 1. Install MinGW. 47 | 48 | 49 | 50 | ## Usage 51 | 52 | **Add the directory locations** 53 | --- 54 | 55 | Add directory locations for each site i.e where you want the folder for the problems to be created. 56 | 57 | ![Image](https://i.imgur.com/x66KloC.png) 58 | 59 | An example location can look like this:- `/Users/harshkhajuria/Desktop/TEST/` . 60 | 61 | **Important. Don't forget to add a `/`(for MacOS and Linux) or `\` (for Windows) at the end of the location.** 62 | 63 | You can drag and drop the folder into terminal to get the paths 64 | 65 | 66 | ![Drag and drop](https://i.imgur.com/PYwz7Qh.gif) 67 | 68 | ~~`coreutils` is used to make sure that your code doesn't goes into an infinite loop. The time limit right now is `5 seconds` which can be edited from the setting menu.~~ (There is no need to install `coreutils` since version `0.8.18`). 69 | 70 | **To fetch the problems and testcases** 71 | --- 72 | 73 | ![Image](https://i.imgur.com/HRwTUOT.png) 74 | 75 | Press `alt+control+k` to open the pane. Check the site radio button and put the contest code into the input field. Press `Fetch Data` . 76 | 77 | A folder will be created for each of the problems with their test cases in the directory that you specify in the settings menu. 78 | 79 | 80 | #### Examples for Code of Contests. 81 | 82 | Site | Link | Code 83 | ------------ | ------------- | ------------- 84 | Codechef | https://www.codechef.com/COOK94A | COOK94A 85 | Codechef | https://www.codechef.com/MAY18B | MAY18B 86 | Codeforces | http://codeforces.com/contest/354 | 354 87 | Codeforces | http://codeforces.com/contest/490 | 490 88 | Atcoder | https://arc097.contest.atcoder.jp/ | arc097 89 | Atcoder | https://agc024.contest.atcoder.jp/ | agc024 90 | 91 | 92 | *In order to close the pane press again `ctrl+alt+k`* 93 | 94 | **To compile and create output files** 95 | --- 96 | 97 | Press `alt+control+c` to compile. One output file will be generated for each and every file that starts with `input` in the folder where `.cpp` file is. 98 | 99 | In order to create your own test cases create a input*.txt file in the same directory of the problem replacing * with a integer. 100 | Corresponding output file can be generated by pressing `alt+control+c` again. 101 | 102 | Since version `0.8.18`, I have also added notifications based on the diffs generated between `output*.txt` and `myOutput*.txt`. 103 | 104 | ![Drag and drop](https://i.imgur.com/eUtCzQ7.gif) 105 | 106 | *If no corresponding file is found either for `output` or `myOutput` a notification will be added and only time taken for the execution will be shown.* 107 | 108 | **To see diffs** 109 | --- 110 | 111 | Press `alt+control+p` to bring out a right pane to see the diffs generated between corresponding files. To close the pane press `alt+control+o`. 112 | 113 | **To change gcc version and add additional flags while compiling** 114 | --- 115 | Update the `Default GCC` in the settings menu with the gcc version of your choice. For example if you use homebrew to install g++-4.9 then simply update the settings to use `g++-4.9`. 116 | 117 | Update the `GCC Options` in the settings menu to add additional flags while compiling. For eg:- `-std=c++14` 118 | 119 | **To change the Time Limit** 120 | --- 121 | Update the `Time Limit ` in the settings menu (in seconds). 122 | 123 | # Packages 124 | 125 | Install the following packages for using atom to code in C/C++. To install them go to `Install` in `Preferences` and search them by typing their name. 126 | 127 | 1. [autocomplete-clang](https://atom.io/packages/autocomplete-clang) - Autocompletion of C/C++ code. 128 | 2. [gpp-compiler](https://atom.io/packages/gpp-compiler) - Compile C/C++ code from within Atom. 129 | 3. [linter](https://atom.io/packages/linter) - Base Linter. 130 | 4. [linter-ui-default](https://atom.io/packages/linter-ui-default) - Default UI for the linter package. 131 | 5. [linter-clang](https://atom.io/packages/linter-clang) - Linter for C/C++ files. 132 | -------------------------------------------------------------------------------- /lib/cp-automation.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | 3 | import CpAutomationView from './cp-automation-view'; 4 | import { 5 | CompositeDisposable 6 | } from 'atom'; 7 | import shell from 'shelljs'; 8 | import os from 'os'; 9 | import FileHound from 'filehound'; 10 | import ChildView from './component'; 11 | import DiffView from './diffComponent'; 12 | import fs from 'fs'; 13 | const path = require('path'); 14 | const jsdiff = require('diff'); 15 | const exec = require('child_process').exec; 16 | const promiseexec = require('node-exec-promise').exec; 17 | const now = require("performance-now"); 18 | const pidtree = require('pidtree'); 19 | const kill = require('tree-kill'); 20 | 21 | 22 | export default { 23 | 24 | cpAutomationView: null, 25 | modalPanel: null, 26 | subscriptions: null, 27 | 28 | "config": { 29 | "Codechef": { 30 | "type": "string", 31 | "default": "/Users" 32 | }, 33 | "Codeforces": { 34 | "type": "string", 35 | "default": "/Users" 36 | }, 37 | "Atcoder": { 38 | "type": "string", 39 | "default": "/Users" 40 | }, 41 | "TimeLimit": { 42 | "type": "integer", 43 | "default": 5 44 | }, 45 | "DefaultGCC": { 46 | "type": "string", 47 | "default": "g++" 48 | }, 49 | "GCCOptions": { 50 | "type": "string", 51 | "default": "" 52 | } 53 | }, 54 | 55 | activate(state) { 56 | 57 | /*directories*/ 58 | this.Codechefdir = atom.config.get('AFCP.Codechef'); 59 | this.Codeforcesdir = atom.config.get('AFCP.Codeforces'); 60 | this.Atcoderdir = atom.config.get('AFCP.Atcoder'); 61 | this.TimeLimit = atom.config.get('AFCP.TimeLimit'); 62 | this.defaultGCC = atom.config.get('AFCP.DefaultGCC'); 63 | this.GCCOptions = atom.config.get('AFCP.GCCOptions'); 64 | this.markers = new Array(); 65 | this.panes = new Array(); 66 | this.platform = os.platform(); 67 | // console.log(this); 68 | atom.config.observe('AFCP.Codechef', (newValue) => { 69 | this.Codechefdir = newValue; 70 | }); 71 | atom.config.observe('AFCP.Codeforces', (newValue) => { 72 | this.Codeforcesdir = newValue; 73 | }); 74 | atom.config.observe('AFCP.Atcoder', (newValue) => { 75 | this.Atcoderdir = newValue; 76 | }); 77 | atom.config.observe('AFCP.TimeLimit', (newValue) => { 78 | this.TimeLimit = newValue; 79 | }); 80 | atom.config.observe('AFCP.DefaultGCC', (newValue) => { 81 | this.DefaultGCC = newValue; 82 | }); 83 | atom.config.observe('AFCP.GCCOptions', (newValue) => { 84 | this.GCCOptions = newValue; 85 | }); 86 | /*directories*/ 87 | 88 | /*view*/ 89 | let view = document.createElement("div"); 90 | this.childView = new ChildView(this.Atcoderdir, this.Codeforcesdir, this.Codechefdir); 91 | view.appendChild(this.childView.element); 92 | /*view*/ 93 | 94 | 95 | this.showpane = atom.workspace.addModalPanel({ 96 | item: view, 97 | }); 98 | 99 | 100 | this.hidePane = () => { 101 | this.showpane.hide(); 102 | } 103 | 104 | this.revealPane = () => { 105 | /*view*/ 106 | let view = document.createElement("div"); 107 | this.childView = new ChildView(this.Atcoderdir, this.Codeforcesdir, this.Codechefdir, this.showpane); 108 | view.appendChild(this.childView.element); 109 | /*view*/ 110 | 111 | 112 | this.showpane = atom.workspace.addModalPanel({ 113 | item: view, 114 | }); 115 | this.showpane.show(); 116 | } 117 | 118 | this.subscriptions = new CompositeDisposable(); 119 | 120 | this.subscriptions.add(atom.commands.add('atom-workspace', { 121 | 'cp-automation:compile': () => this.compile(), 122 | 'cp-automation:toggle': () => this.toggle(), 123 | 'cp-automation:diff': () => this.addPane(), 124 | 'cp-automation:removeDiff': () => this.closePane() 125 | })); 126 | 127 | }, 128 | 129 | deactivate() { 130 | this.modalPanel.destroy(); 131 | this.subscriptions.dispose(); 132 | this.cpAutomationView.destroy(); 133 | }, 134 | 135 | // serialize() { 136 | // return { 137 | // cpAutomationViewState: this.cpAutomationView.serialize() 138 | // }; 139 | // }, 140 | 141 | getTitle() { 142 | // Used by Atom for tab text 143 | return 'AFCP Diff Tab'; 144 | }, 145 | 146 | 147 | addPane() { 148 | this.closePane(); 149 | 150 | 151 | let filePath = atom.workspace.getActiveTextEditor().getPath(); 152 | let xx = filePath; 153 | xx = filePath.substring(0, filePath.lastIndexOf('/')); 154 | filePath = filePath.replace(/ /g, "\\ ") 155 | let dirPath = filePath.substring(0, filePath.lastIndexOf('/')); 156 | 157 | var doneFiles = new Promise( 158 | function(resolve, reject) { 159 | var filesArray = []; 160 | const files1 = FileHound.create() 161 | .depth(0) 162 | .paths(xx) 163 | .match('myOutput*') 164 | .find(); 165 | 166 | const files2 = FileHound.create() 167 | .depth(0) 168 | .paths(xx) 169 | .match('output*') 170 | .find(); 171 | 172 | const files = FileHound.any(files1, files2) 173 | .then((file) => { 174 | Object.keys(file).map((i) => { 175 | let file_here = file[i]; 176 | var number = file_here.substring( 177 | file_here.lastIndexOf("/") + 1, 178 | file_here.lastIndexOf(".") 179 | ); 180 | var name = number.substring(0, 8); 181 | if (name === "myOutput") { 182 | number = number.substring(8); 183 | // console.log(number); 184 | filesArray.push({ in: file_here, 185 | out: "", 186 | number: number 187 | }); 188 | } 189 | }); 190 | 191 | Object.keys(file).map((i) => { 192 | let file_here = file[i]; 193 | var number = file_here.substring( 194 | file_here.lastIndexOf("/") + 1, 195 | file_here.lastIndexOf(".") 196 | ); 197 | var name = number.substring(0, 6); 198 | if (name === "output") { 199 | number = number.substring(6); 200 | Object.keys(filesArray).map((i) => { 201 | if (filesArray[i].number === number) { 202 | filesArray[i].out = file_here; 203 | } 204 | }) 205 | } 206 | }); 207 | resolve(filesArray); 208 | }) 209 | }); 210 | 211 | var doneFilesPromise = () => { 212 | doneFiles 213 | .then((fulfilled) => { 214 | this.hogaya(fulfilled); 215 | }) 216 | .catch(function(error) { 217 | console.log(error.message); 218 | }); 219 | }; 220 | doneFilesPromise(); 221 | }, 222 | 223 | 224 | hogaya(filesArray) { 225 | let newView1 = new DiffView(filesArray); 226 | let tempPanel = atom.workspace.addRightPanel({ 227 | "item": newView1, 228 | "visible": true 229 | }); 230 | this.panes.push(tempPanel); 231 | }, 232 | 233 | closePane() { 234 | Object.keys(this.panes).map((index) => { 235 | this.panes[index].destroy(); 236 | }) 237 | }, 238 | 239 | toggle() { 240 | this.showpane.isVisible() ? this.hidePane() : this.revealPane(); 241 | }, 242 | 243 | compile() { 244 | // console.log('compiling'); 245 | shell.cd('~/Desktop/'); 246 | atom.notifications.addInfo('Compiling and generating output'); 247 | let filePath = atom.workspace.getActiveTextEditor().getPath(); 248 | let extensionIndex = filePath.lastIndexOf('.'); 249 | let extension = filePath.substring(extensionIndex + 1, filePath.length); 250 | if (extension === "cpp") { 251 | if (this.platform === "win32") { 252 | // console.log(filePath); 253 | let xx = filePath; 254 | xx = filePath.substring(0, filePath.lastIndexOf('\\')); 255 | // console.log("xx for windows is" , xx); 256 | let dirPath = filePath.substring(0, filePath.lastIndexOf('\\')); 257 | // console.log(dirPath); 258 | const tempdir = dirPath; 259 | let path2 = dirPath.substring(0, dirPath.lastIndexOf('\\')); 260 | // console.log("path2 is ", path2); 261 | dirPath += '\\abc.o'; 262 | filePath = '"' + filePath + '"'; 263 | dirPath = '"' + dirPath + '"'; 264 | exec(`${this.DefaultGCC} ${this.GCCOptions} ${filePath} -o ${dirPath}`, 265 | (error, stdout, stderr) => { 266 | // console.log(`${stdout}`); 267 | // console.log(`${stderr}`); 268 | if (error !== null) { 269 | error = error.toString().substring(command.length + 23); 270 | console.log(`exec error: ${error}`); 271 | atom.notifications.addError(`Error in compiling: ${error}`); 272 | } 273 | this.executeCasesWindows(tempdir, dirPath, xx); 274 | }); 275 | } else { 276 | let xx = filePath; 277 | xx = filePath.substring(0, filePath.lastIndexOf('/')); 278 | filePath = filePath.replace(/ /g, "\\ ") 279 | let dirPath = filePath.substring(0, filePath.lastIndexOf('/')); 280 | const tempdir = dirPath; 281 | dirPath += '/abc.o'; 282 | let command = `${this.DefaultGCC} ${this.GCCOptions} ${filePath} -o ${dirPath}`; 283 | exec(`${this.DefaultGCC} ${this.GCCOptions} ${filePath} -o ${dirPath}`, 284 | (error, stdout, stderr) => { 285 | // console.log(`${stdout}`); 286 | // console.log(`${stderr}`); 287 | if (error !== null) { 288 | error = error.toString().substring(command.length + 23); 289 | console.log(`exec error: ${error}`); 290 | atom.notifications.addError(`Error in compiling: ${error}`); 291 | } 292 | this.executeCases(tempdir, dirPath, xx); 293 | }); 294 | } 295 | } else { 296 | atom.notifications.addError("Run this command through a cpp file"); 297 | } 298 | }, 299 | 300 | executeCasesWindows(tempdir, dirPath, xx) { 301 | // console.log('inside executing', tempdir, dirPath, xx); 302 | let a = 0; 303 | files = FileHound.create() 304 | .depth(0) 305 | .paths(xx) 306 | .match('input*') 307 | .find() 308 | .then((file) => { 309 | file.map((file) => { 310 | // console.log(file); 311 | // file = file.replace(/ /g,"\\ "); 312 | file = '"' + file + '"'; 313 | let output = tempdir + '\\myOutput' + a + '.txt'; 314 | output = '"' + output + '"'; 315 | // console.log(`${dirPath} <${file} >${output}`); 316 | exec(`${dirPath} <${file} >${output}`); 317 | a++; 318 | }); 319 | }); 320 | }, 321 | 322 | executeCases(tempdir, dirPath, xx) { 323 | let a = 0; 324 | files = FileHound.create() 325 | .depth(0) 326 | .paths(xx) 327 | .match('input*') 328 | .find() 329 | .then( 330 | (file) => { 331 | this.testCompilationFunction(file, tempdir, dirPath, xx) 332 | } 333 | ); 334 | }, 335 | 336 | async anotherFunction(dirPath, file, output) { 337 | let command = `gtimeout ${this.TimeLimit}s ${dirPath} <${file} >${output}`; 338 | const p = await promiseexec(`${dirPath} <${file} >${output}`, { 339 | timeout: 10000 340 | }, (error, stdout, stderr) => { 341 | if (error != null) { 342 | console.log(error); 343 | let message = error.message; 344 | message = error.message.substring(command.length + 16, error.message.length - command.length - 3); 345 | atom.notifications.addError(`Error while executing cases: ${message}`); 346 | } 347 | }); 348 | return p; 349 | }, 350 | 351 | 352 | async testCompilationFunction(files, tempdir, dirPath, xx) { 353 | // console.log(files); 354 | let a = 0; 355 | for (let i = 0; i < files.length; i++) { 356 | let file = files[i]; 357 | // console.log(file); 358 | file = file.replace(/ /g, "\\ "); 359 | let output = tempdir + '/myOutput' + a + '.txt'; 360 | let compare = tempdir + '/output' + a + '.txt'; 361 | if (this.platform === 'darwin' || this.platform === "linux") { 362 | let command = `${dirPath} <${file} >${output}`; 363 | // console.log(`gtimeout ${this.TimeLimit}s ${dirPath} <${file} >${output}`); 364 | let start = now() 365 | // console.log("file is ", file); 366 | 367 | const executeFilePromise = new Promise((resolve, reject) => { 368 | const limit = this.TimeLimit * 1000; 369 | // console.log(limit); 370 | const childProcess = exec(command, { 371 | timeout: limit, 372 | killSignal: "SIGKILL" 373 | }, (err, b, c) => { 374 | if (err) { 375 | console.log("err occured", err); 376 | resolve(childProcess); 377 | } else { 378 | // console.log("NO error and resolving"); 379 | resolve({}); 380 | } 381 | }) 382 | }); 383 | 384 | const killPromise = (child) => { 385 | return new Promise((resolve, reject) => { 386 | kill(child.pid + 1, 'SIGKILL', function(err) { 387 | // console.log("child pid is ", child.pid + 1); 388 | if (err) { 389 | reject(err); 390 | } else { 391 | resolve({ 392 | msg: "We resolved this" 393 | }); 394 | } 395 | }); 396 | // pidtree(child.pid, function (err, pids) { 397 | // console.log(pids) 398 | // if (err) { 399 | // reject(err); 400 | // } else { 401 | // resolve({ 402 | // msg: "We resolved this" 403 | // }); 404 | // } 405 | // // => [] 406 | // }) 407 | }); 408 | } 409 | 410 | var child = await executeFilePromise; 411 | let end = now() 412 | let time = ((end - start) / 1000).toFixed(3) 413 | // console.log(child.pid) 414 | // console.log(time) 415 | if (child.pid) { 416 | await killPromise(child); 417 | atom.notifications.addError(`Time Limit Exceeded for file ${a}\n. Time taken: ${time} seconds`, { 418 | dismissable: true 419 | }) 420 | } else { 421 | let file1 = output; 422 | let file2 = compare; 423 | file1 = file1.replace(/\\/g, '') 424 | file2 = file2.replace(/\\/g, '') 425 | let f1 = 0, 426 | f2 = 0; 427 | try { 428 | var text1 = fs.readFileSync(file1).toString(); 429 | } catch (err) { 430 | f1 = 1; 431 | console.log(err); 432 | atom.notifications.addInfo(`No myOutput${a}.txt found in this directory. Time taken: ${time} seconds`, { 433 | dismissable: true 434 | }); 435 | } 436 | try { 437 | var text2 = fs.readFileSync(file2).toString(); 438 | } catch (err) { 439 | f2 = 1; 440 | // console.log(err); 441 | let notif = atom.notifications.addInfo(`No output${a}.txt found in this directory. Time taken: ${time} seconds`, { 442 | dismissable: true 443 | }); 444 | } 445 | let f3 = 0; 446 | if (!f1 && !f2) { 447 | //var diff = jsdiff.diffLines(text2, text1, {ignoreWhitespace: true, newlineIsToken: true}); 448 | var diff = jsdiff.diffWords(text2, text1); 449 | // console.log(diff); 450 | Object.keys(diff).map((i) => { 451 | if (diff[i].added === true || diff[i].removed === true) { 452 | f3 = 1; 453 | } 454 | }) 455 | if (!f3) { 456 | atom.notifications.addSuccess(`Accepted answer for file ${a}\n. Time taken: ${time} seconds`, { 457 | dismissable: true 458 | }) 459 | } else { 460 | atom.notifications.addError(`Wrong answer for file ${a}\n. Time taken: ${time} seconds`, { 461 | dismissable: true 462 | }) 463 | } 464 | } 465 | } 466 | } 467 | // else if (this.platform === 'linux') { 468 | // // console.log(`timeout ${this.TimeLimit}s ${dirPath} <${file} >${output}`); 469 | // exec(`gtimeout ${this.TimeLimit}s ${dirPath} <${file} >${output}`, (error, stdout, stderr) => { 470 | // if (error != null) { 471 | // console.log(error); 472 | // let message = error.message; 473 | // message = error.message.substring(command.length + 16, error.message.length - command.length - 3); 474 | // atom.notifications.addError(`Error while executing cases: ${message}`); 475 | // } 476 | // }); 477 | // } 478 | else { 479 | // console.log(`${dirPath} <${file} >${output}`); 480 | exec(`${dirPath} <${file} >${output}`); 481 | } 482 | a++; 483 | } 484 | } 485 | } --------------------------------------------------------------------------------