# Path: k_os/OIL/Error.py
# class OILError(object):
#     inst=None
# 
#     def __new__(cls):
#         if cls.inst is None:
#             # Make it a Singleton.
#             cls.inst=super(OILError,cls).__new__(cls)
#             cls.fatalErrorCounter=0
#             cls.errorCounter=0
#             cls.warningCounter=0
#             cls.informationCounter=0
# 
#             cls.loggerMessageonly=createLogger(logging.NOTSET,"kos.oil.logger.messageonly",
#                 "[%(levelname)s] - %(message)s"
#             )
#             cls.loggerFilename=createLogger(logging.NOTSET,"kos.oil.logger.filename",
#                 "[%(levelname)s]:%(fname)s - %(message)s"
#             )
#             cls.loggerFull=createLogger(logging.NOTSET,"kos.oil.logger.full",
#                  "[%(levelname)s]:%(fname)s:%(lno)s - %(message)s"
#             )
#         return cls.inst
# 
#     def logMessage(self,level,message,lineno=None,filename=None,code=None):
#         if lineno and filename:
#             self.loggerFull.log(level,message,extra={'lno': lineno,'fname': filename})
#         elif filename:
#             self.loggerFilename.log(level,message,extra={'fname': filename})
#         else:
#             self.loggerMessageonly.log(level,message)
# 
# 
#     def fatalError(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.CRITICAL,message,lineno,filename,"F-"+code)
#         self.fatalErrorCounter+=1
#         sys.exit(1)
# 
#     def error(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.ERROR,message,lineno,filename,"E-"+code)
#         self.errorCounter+=1
# 
#     def warning(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.WARNING,message,lineno,filename,"W-"+code)
#         self.warningCounter+=1
# 
#     def information(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.INFO,message,lineno,filename,"I-"+code)
#         self.informationCounter+=1


import logging
import os
import re
import sys
from k_os.OIL.Error import OILError
    match=STRING.match(line)
    while match is not None:
        line=match.group('before')+match.group('after')
        match=STRING.match(line)
    return line


def locateIncludeFile(quoted,fname):
    path=None
    found=False
    if quoted:
        ## Try current directory first.
        path=os.path.join(os.path.curdir,fname)
        found=TryOpen(path)
    if not found:
        for p in PathList:
            path=os.path.join(p,fname)
            found=TryOpen(path)
            if found:
                break
    return (found,path)

class Preproc(object):
    def __init__(self,inFile,outFile):
        self.inFile=inFile
        self.outFile=outFile
        inc_paths=os.getenv('KOS_INCLUDE')
        if inc_paths is not None:
            for p in inc_paths.split(';'):
                AddToPathList(p)

# Path: k_os/OIL/Error.py
# class OILError(object):
#     inst=None
# 
#     def __new__(cls):
#         if cls.inst is None:
#             # Make it a Singleton.
#             cls.inst=super(OILError,cls).__new__(cls)
#             cls.fatalErrorCounter=0
#             cls.errorCounter=0
#             cls.warningCounter=0
#             cls.informationCounter=0
# 
#             cls.loggerMessageonly=createLogger(logging.NOTSET,"kos.oil.logger.messageonly",
#                 "[%(levelname)s] - %(message)s"
#             )
#             cls.loggerFilename=createLogger(logging.NOTSET,"kos.oil.logger.filename",
#                 "[%(levelname)s]:%(fname)s - %(message)s"
#             )
#             cls.loggerFull=createLogger(logging.NOTSET,"kos.oil.logger.full",
#                  "[%(levelname)s]:%(fname)s:%(lno)s - %(message)s"
#             )
#         return cls.inst
# 
#     def logMessage(self,level,message,lineno=None,filename=None,code=None):
#         if lineno and filename:
#             self.loggerFull.log(level,message,extra={'lno': lineno,'fname': filename})
#         elif filename:
#             self.loggerFilename.log(level,message,extra={'fname': filename})
#         else:
#             self.loggerMessageonly.log(level,message)
# 
# 
#     def fatalError(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.CRITICAL,message,lineno,filename,"F-"+code)
#         self.fatalErrorCounter+=1
#         sys.exit(1)
# 
#     def error(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.ERROR,message,lineno,filename,"E-"+code)
#         self.errorCounter+=1
# 
#     def warning(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.WARNING,message,lineno,filename,"W-"+code)
#         self.warningCounter+=1
# 
#     def information(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.INFO,message,lineno,filename,"I-"+code)
#         self.informationCounter+=1


# Path: pySART/kosek/Preproc.py
import logging
import os
import re
import sys
from k_os.OIL.Error import OILError

    match=STRING.match(line)
    while match is not None:
        line=match.group('before')+match.group('after')
        match=STRING.match(line)
    return line


def locateIncludeFile(quoted,fname):
    path=None
    found=False
    if quoted:
        ## Try current directory first.
        path=os.path.join(os.path.curdir,fname)
        found=TryOpen(path)
    if not found:
        for p in PathList:
            path=os.path.join(p,fname)
            found=TryOpen(path)
            if found:
                break
    return (found,path)

class Preproc(object):
    def __init__(self,inFile,outFile):
        self.inFile=inFile
        self.outFile=outFile
        inc_paths=os.getenv('KOS_INCLUDE')
        if inc_paths is not None:
            for p in inc_paths.split(';'):
                AddToPathList(p)

        self.Parse(self.inFile,OILError())