/* [MS-XLSB] 2.4.305 BrtCellError
434980
function parse_BrtCellError(data, length) {
	var cell = parse_XLSBCell(data);
	var bError = data.read_shift(1);
	return [cell, bError, 'e'];
}
596389
function write_BrtBookView(idx, o) {
	if(!o) o = new_buf(29);
	o.write_shift(-4, 0);
	o.write_shift(-4, 460);
	o.write_shift(4,  28800);
	o.write_shift(4,  17600);
	o.write_shift(4,  500);
	o.write_shift(4,  idx);
	o.write_shift(4,  idx);
	var flags = 0x78;
	o.write_shift(1,  flags);
	return o.length > o.l ? o.slice(0, o.l) : o;
}
1201222
function write_BrtFileVersion(data, o) {
	if(!o) o = new_buf(127);
	for(var i = 0; i != 4; ++i) o.write_shift(4, 0);
	write_XLWideString("SheetJS", o);
	write_XLWideString(XLSX.version, o);
	write_XLWideString(XLSX.version, o);
	write_XLWideString("7262", o);
	o.length = o.l;
	return o.length > o.l ? o.slice(0, o.l) : o;
}
577071
@Override
    public String displayError(String pathPrefix) {

        if (pathPrefix == null) {
            pathPrefix = "";
        }
        StringBuffer html = new StringBuffer(512);
        html.append("<table border='0' cellpadding='5' cellspacing='0' style='width: 100%; height: 100%;'>");
        html.append("\t<tr>");
        html.append("\t\t<td style='vertical-align: middle; height: 100%;'>");
        html.append(getHtmlPart("C_BLOCK_START", "Error"));
        html.append("\t\t\t<table border='0' cellpadding='0' cellspacing='0' style='width: 100%;'>");
        html.append("\t\t\t\t<tr>");
        html.append("\t\t\t\t\t<td><img src='").append(pathPrefix).append("resources/error.png' border='0'></td>");
        html.append("\t\t\t\t\t<td>&nbsp;&nbsp;</td>");
        html.append("\t\t\t\t\t<td style='width: 100%;'>");
        html.append("\t\t\t\t\t\tThe Alkacon OpenCms update wizard has not been started correctly!<br>");
        html.append("\t\t\t\t\t\tPlease click <a href='").append(pathPrefix);
        html.append("index.jsp'>here</a> to restart the wizard.");
        html.append("\t\t\t\t\t</td>");
        html.append("\t\t\t\t</tr>");
        html.append("\t\t\t</table>");
        html.append(getHtmlPart("C_BLOCK_END"));
        html.append("\t\t</td>");
        html.append("\t</tr>");
        html.append("</table>");
        return html.toString();
    }
1001387
function parse_BrtXF(data, length) {
	var ixfeParent = data.read_shift(2);
	var ifmt = data.read_shift(2);
	parsenoop(data, length-4);
	return {ixfe:ixfeParent, ifmt:ifmt };
}
1217435
def _netbsd_brshow(br=None):
    '''
    
    '''
    brconfig = _tool_path('brconfig')

    if br:
        cmd = '{0} {1}'.format(brconfig, br)
    else:
        cmd = '{0} -a'.format(brconfig)

    brs = {}
    start_int = False

    for line in __salt__['cmd.run'](cmd, python_shell=False).splitlines():
        if line.startswith('bridge'):
            start_int = False
            brname = line.split(':')[0]  # on NetBSD, always ^bridge([0-9]+):
            brs[brname] = {
                'interfaces': [],
                'stp': 'no'
            }
        if 'Interfaces:' in line:
            start_int = True
            continue
        if start_int and brname:
            m = re.match(r'\s*([a-z0-9]+)\s.*<.*>', line)
            if m:
                brs[brname]['interfaces'].append(m.group(1))
                if 'STP' in line:
                    brs[brname]['stp'] = 'yes'

    if br:
        try:
            return brs[br]
        except KeyError:
            return None
    return brs
147867
function parse_BrtFmt(data, length/*:number*/) {
	var numFmtId = data.read_shift(2);
	var stFmtCode = parse_XLWideString(data,length-2);
	return [numFmtId, stFmtCode];
}
1372673
function CartoValidationError (type, message, opts) {
  return new CartoError({
    origin: 'validation',
    type: type,
    message: message
  }, opts);
}
629742
function ping_fefd_udp(options, cb) {
  const host = options.host;
  const port = options.port;
  const udp = dgram.createSocket('udp4');

  //console.log('udp ping');

  const STARTED = 0;
  const SENT_CHALLENGE_REQUEST = 1;
  const SENT_STATUS_REQUEST = 2;
  const DONE = 3;
  let state = 0;

  udp.on('error', (err) => {
    //console.log(`udp error:\n${err.stack}`);
    cb(err, null, 'fefd_udp');
    udp.close();
  });

  udp.on('message', (msg, rinfo) => {
    //console.log(msg);
    //console.log(`udp got: ${msg} from ${rinfo.address}:${rinfo.port}`);
    if (state === STARTED) {
      cb(new Error('received unexpected packet before sent anything'), null, 'fefd_udp');
      return;
    } else if (state === SENT_CHALLENGE_REQUEST) {
      // challenge token
      // 09          challenge type
      // 00 00 00 00 id token (sent all zeros)
      // xx xx xx xx new challenge token
      if (msg[0] != 0x09) {
        cb(new Error('unexpected packet received after sent challenge request'), null, 'fefd_udp');
        return;
      }
      // challenge token is received as ASCII decimal string, but replied as encoded uint32be
      const challengeTokenString = msg.slice(5).toString();
      const challengeTokenInt = parseInt(challengeTokenString);
      //console.log('challenge token: '+challengeTokenInt);
      const challengeTokenBuffer = new Buffer(4);
      challengeTokenBuffer.writeUInt32BE(challengeTokenInt);

      const statusRequest = new Buffer(
        'fefd'+ // magic
        '00'+   // status type
        '00000000'+ // id token
        challengeTokenBuffer.toString('hex')+ // challenge token
        '00000000', // id token, again (extended status request) (see https://github.com/Dinnerbone/mcstatus/commit/6b6a5659156785bcaaa75980782215f777bd5b97 it gets more)
        'hex');

      //console.log('requesting status');
      //console.log(statusRequest.toString('hex'));
      udp.send(statusRequest, 0, statusRequest.length, port, host, function() {
        state = SENT_STATUS_REQUEST;
      });
    } else if (state === SENT_STATUS_REQUEST) {
      //console.log('response', msg);
      //console.log('response', msg.toString('hex'));
      //console.log('response', msg.toString());
      const array = msg.toString('binary').split('\0');
      //console.log(array);
      let result = {};
      // example response array, some fields are not fixed strings
      // ['', '', '', '', '', 'splitnum', '\x80', 'hostname', 'A Minecraft Server', 'gametype', 'SMP', 'game_id', 'MINECRAFT', 'version', '1.5.2', 'plugins', 'CraftBukkit on Bukkit 1.5.2-R1.1-SNAPSHOT: MultiWorld 4.5.4; SilkSpawners 3.2.2; OpenInv 2.0.2; EnchantMore 2.0; WorldEdit 5.5.6', 'map', 'world', 'numplayers', '0', 'maxplayers', '20', 'hostport', '25565', 'hostip', '0.0.0.0', '', '\x01player_', '', '', '']
      result.worldHeight = array[6].charCodeAt(0);
      result.motd = array[8];
      result.gameType = array[10];
      result.gameName = array[12];
      result.gameVersion = array[14];
      result.plugins = array[16]; // TODO: decode structure, which is:  server-software: plugin1; plugin2; plugin3...
      result.defaultWorld = array[18];
      result.numPlayers = parseInt(array[20]);
      result.maxPlayers = parseInt(array[22]);
      result.port = parseInt(array[24]);
      result.host = array[26];
      // TODO: online players comes last, parse it
      //console.log('result',result);
      state = DONE;
      cb(null, result, 'fefd_udp');
    }
  });

  udp.on('listening', () => {
    const address = udp.address();
    //console.log(`udp listening ${address.address}:${address.port}`);

    // query request
    const request = new Buffer('fefd090000000000000000', 'hex');
    udp.send(request, 0, request.length, port, host, function() {
      state = SENT_CHALLENGE_REQUEST;
    });
  });

  udp.bind();
}
863824
function _bst(chunk, type) {
  // we should have already read the chunk
  var len = this._int(chunk, type), buf;
  if(!isNaN(len)) {
    // read an integer less than zero, treat as null
    if(len < 0) return null;
    // read in the entire bulk string and swallow the crlf
    if((chunk.length - this._offset) >= len + 2) {
      buf = chunk.slice(this._offset, this._offset + len);
      this._offset += (len + 2);
      //this._buffer = this._buffer.slice(this._offset, this._buffer.length);
      //console.dir(buf);
      return this.buffers ? buf : '' + buf;
    }else{
      this._wait();
    }
  }
}
1075701
function parse_BrtShrFmla(data, length, opts) {
	var end = data.l + length;
	var rfx = parse_UncheckedRfX(data, 16);
	var o = [rfx];
	if(opts.cellFormula) {
		var formula = parse_XLSBSharedParsedFormula(data, end - data.l, opts);
		o[1] = formula;
		data.l = end;
	} else data.l = end;
	return o;
}
1015508
function setHashOrThrowError(parseMap, routeObject) {
    var route = routeObject.route;
    var get = routeObject.get;
    var set = routeObject.set;
    var call = routeObject.call;

    getHashesFromRoute(route).
        map(function mapHashToString(hash) { return hash.join(','); }).
        forEach(function forEachRouteHash(hash) {
            if (get && parseMap[hash + 'get'] ||
                set && parseMap[hash + 'set'] ||
                    call && parseMap[hash + 'call']) {
                throw new Error(errors.routeWithSamePrecedence + ' ' +
                               prettifyRoute(route));
            }
            if (get) {
                parseMap[hash + 'get'] = true;
            }
            if (set) {
                parseMap[hash + 'set'] = true;
            }
            if (call) {
                parseMap[hash + 'call'] = true;
            }
        });
}
589640
function TcpSvrListenFx (err) {
    this.controller.Debug (0,"Hoop fail to listen port: %d ==> %s", this.controller.svcopts.port, err);
    console.log ("### gateway process abort ###");
    process.exit (-1);
}
1207942
function parse_BrtRowHdr(data, length) {
	var z = ({});
	var tgt = data.l + length;
	z.r = data.read_shift(4);
	data.l += 4; // TODO: ixfe
	var miyRw = data.read_shift(2);
	data.l += 1; // TODO: top/bot padding
	var flags = data.read_shift(1);
	data.l = tgt;
	if(flags & 0x07) z.level = flags & 0x07;
	if(flags & 0x10) z.hidden = true;
	if(flags & 0x20) z.hpt = miyRw / 20;
	return z;
}
1103746
function formatSassError(err, data) {
  // Generate three-line preview around the error:
  var preview = data.split('\n');
  preview = preview.slice(Math.max(0, err.line-2), Math.min(err.line+1, preview.length-1));
  preview = preview.map(function(src) { return '>>> '+ src });
  preview.unshift(err.message);

  var error = new Error('Error rendering theme Sass:\n'+ preview.join('\n'));
  error.line = err.line || null;
  error.column = err.column || null;
  return error;
}
45508
def error(msg, line = nil)
      error = ::Opal::SyntaxError.new(msg)
      error.location = Opal::OpalBacktraceLocation.new(file, line)
      raise error
    end
828912
function parse_BrtColor(data, length) {
	var out = {};
	var d = data.read_shift(1);

	var fValidRGB = d & 1;
	var xColorType = d >>> 1;

	var index = data.read_shift(1);
	var nTS = data.read_shift(2, 'i');
	var bR = data.read_shift(1);
	var bG = data.read_shift(1);
	var bB = data.read_shift(1);
	var bAlpha = data.read_shift(1);

	switch(xColorType) {
		case 0: out.auto = 1; break;
		case 1:
			out.index = index;
			var icv = XLSIcv[index];
			/* automatic pseudo index 81 */
			if(icv) out.rgb = icv[0].toString(16) + icv[1].toString(16) + icv[2].toString(16);
			break;
		case 2:
			/* if(!fValidRGB) throw new Error("invalid"); */
			out.rgb = bR.toString(16) + bG.toString(16) + bB.toString(16);
			break;
		case 3: out.theme = index; break;
	}
	if(nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768;

	return out;
}