<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#! /usr/bin/python

import os
import sys
import linuxcnc

ini = linuxcnc.ini(os.environ['INI_FILE_NAME'])
cmd = linuxcnc.command()
stat = linuxcnc.stat()
materialFile = ini.find('EMC', 'MACHINE').lower() + '_material.cfg'
with open(materialFile, 'r') as f_in:
    toolList = [0]
    for line in f_in:
        if not line.startswith('#'):
            if line.startswith('[MATERIAL_NUMBER_') and line.strip().endswith(']'):
                a,b,c = line.split('_')
                t_number = int(c.replace(']',''))
                toolList.append(t_number)
tools = True
infile = sys.argv[1]
f = open(infile, 'r')
for line in f:
    if 'm190' in line.lower():
        a,b = line.lower().strip().split('p')
        tool = ''
        for c in b.strip():
            if c in '0123456789':
                tool += c
            else:
             break
        if int(tool) not in toolList:
            if tools:
                print '(Following tools missing from:)'
                print '(%s)' % (materialFile)
            tools = False
            print '(Tool #%s)' % (tool)
f.close()
if tools:
    infile = sys.argv[1]
    f = open(infile, 'r')
    for line in f:
        if line.strip().startswith(';'):
            print line.rstrip()
        elif line.strip().startswith('('):
            print line.rstrip()
        elif not 'z' in line.lower():
            print line.rstrip()
        elif 1 not in [c in line.lower() for c in 'xyabcuvw']:
            print '(%s)' % (line.rstrip())
        else:
            newline = ''
            newz = ''
            removing = 0
            comment = 0
            for bit in line:
                if comment:
                    if bit == ')':
                        comment = 0
                    newline += bit
                elif removing:
                    if bit in '0123456789.- ':
                        newz += bit
                    else:
                        removing = 0
                        if newz:
                            newz = newz.rstrip() + ')'
                        newline += bit
                elif bit == '(':
                    comment = 1
                    newline += bit
                elif bit.lower() == 'z':
                    removing = 1
                    newz += '(' + bit
                else:
                    newline += bit
            print '%s %s'% (newline.rstrip(), newz)
    f.close()
else:
    print 'M2'
</pre></body></html>