Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #sublime text 2 plugin
- #xorc1zt
- #2012
- import sublime
- import sublime_plugin
- import subprocess
- import os
- COMPILER_READY = False
- compilerprocess = None
- def has_file_ext(view, ext):
- """Returns ``True`` if view has file extension ``ext``.
- ``ext`` may be specified with or without leading ``.``.
- """
- if not view.file_name(): return False
- if not ext.strip().replace('.', ''): return False
- if not ext.startswith('.'):
- ext = '.' + ext
- return view.file_name().endswith(ext)
- def SendCommandLine( process, bytestring ):
- process.stdin.write( bytestring )
- process.stdin.flush()
- def GetOutputSucces( process ):
- while True:
- line = process.stdout.readline()
- print( line )
- if line == b'SUCCESS\r\n':
- break
- def GetOutputComplete( process ):
- while True:
- line = process.stdout.readline()
- print( line )
- if line == b'OUTPUT\tCOMPLETE\r\n':
- break
- def GetStatus( process ):
- while True:
- line = process.stdout.readline()
- print( line )
- if line == b'READY\r\n':
- retval = 1
- break
- if line.find( b'ERROR' ) != -1:
- retval = 2
- break
- return retval
- def StartCompiler():
- global COMPILER_READY
- process = subprocess.Popen(['pbcompiler','/STANDBY'],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- shell=False
- )
- status = GetStatus( process )
- if status == 1:
- COMPILER_READY = True
- elif status == 2:
- COMPILER_READY = False
- return False
- return process
- def StopCompiler( process ):
- SendCommandLine( process, b'END\n' )
- def DoCompilation( process ):
- view = sublime.active_window().active_view()
- settings = view.settings()
- sourcename = view.file_name()
- targetname = sourcename.strip().replace('.pb', '.exe')
- SendCommandLine( process, b'SOURCE\t'+sourcename+b'\n')
- SendCommandLine( process, b'TARGET\t'+targetname+b'\n')
- SendCommandLine( process, b'COMPILE\n')
- line = process.stdout.readline()
- print(line)
- if line == b'SUCCESS\r\n':
- print("COMPILATIONSUCCES")
- print(b'SOURCE\t'+sourcename+b'\n')
- print(b'SOURCE\t'+targetname+b'\n')
- #GetOutputComplete( process )
- class MakepbCommand(sublime_plugin.ApplicationCommand):
- """Compile a purebasic file with flags
- """
- def is_enabled(self):
- return has_file_ext( sublime.active_window().active_view(), '.pb' )
- def run(self, command=''):
- global COMPILER_READY
- global compilerprocess
- if( compilerprocess == None ) or ( compilerprocess.poll()!=None ) :
- compilerprocess = StartCompiler()
- if COMPILER_READY:
- DoCompilation( compilerprocess )
- if command !='':
- SendCommandLine( compilerprocess, command )
- GetOutputComplete( compilerprocess )
- #StopCompiler( compilerprocess)
- class buildpbCommand(sublime_plugin.WindowCommand):
- """Compile a purebasic file with flags
- """
- def is_enabled(self):
- return has_file_ext( self.window.active_view(), '.pb' )
- def run(self, cmd = [], file_regex = "", line_regex = "", working_dir = "",
- encoding = "utf-8", env = {}, quiet = False, kill = False,
- # Catches "path" and "shell"
- **kwargs):
- view = self.window.active_view()
- targetname = view.file_name()
- print("sdfssdfsdf")
- if not view.settings().get('pbcompiler_autoexec') and not view.settings().get('pbcompiler_dll'):
- cmd.append("/EXE")
- cmd.append(targetname.strip().replace('.pb', '.exe'))
- if view.settings().get('pbcompiler_debugger') and not view.settings().get('pbcompiler_dll'):
- cmd.append("/DEBUGGER")
- if view.settings().get('pbcompiler_dll'):
- cmd.append("/DLL")
- cmd.append("/EXE")
- cmd.append(targetname.strip().replace('.pb', '.dll'))
- if view.settings().get('pbcompiler_console'):
- cmd.append("/CONSOLE")
- if view.settings().get('pbcompiler_quiet'):
- cmd.append("/QUIET")
- if view.settings().get('pbcompiler_commented'):
- cmd.append("/COMMENTED")
- if view.settings().get('pbcompiler_inlineasm'):
- cmd.append("/INLINEASM")
- if view.settings().get('pbcompiler_linenumbering'):
- cmd.append("/LINENUMBERING")
- if view.settings().get('pbcompiler_dynamiccpu'):
- cmd.append("/DYNAMICCPU")
- if view.settings().get('pbcompiler_xp'):
- cmd.append("/XP")
- if view.settings().get('pbcompiler_administrator'):
- cmd.append("/ADMINISTRATOR")
- if view.settings().get('pbcompiler_user'):
- cmd.append("/USER")
- if view.settings().get('pbcompiler_thread'):
- cmd.append("/THREAD")
- if view.settings().get('pbcompiler_unicode'):
- cmd.append("/UNICODE")
- if view.settings().get('pbcompiler_subsystem')==1:
- cmd.append("/SUBSYSTEM")
- cmd.append("opengl")
- elif view.settings().get('pbcompiler_subsystem')==2:
- cmd.append("/SUBSYSTEM")
- cmd.append("winnt")
- args = {
- "cmd": cmd,
- "file_regex": file_regex,
- "line_regex": line_regex,
- "working_dir": working_dir,
- "encoding": encoding,
- "env": env,
- "quiet": quiet,
- "kill": kill,
- }
- self.window.run_command("exec", args )
Advertisement
Add Comment
Please, Sign In to add comment