<commit_before>var getAuthString = require('./auth');
var xutil = require('./xutil');

function readVisuals(bl, visuals, n_visuals, cb)
{
    if (n_visuals == 0)
    {
        cb();
        return;
    }

    var visual = {};
    bl.unpackTo( visual,
    [
        'L vid',
        'C class',
        'C bits_per_rgb',
        'S map_ent',
        'L red_mask',
        'L green_mask',
        'L blue_mask',
        'xxxx'
    ],
    function() {
         var vid = visual.vid;
         // delete visual.vid;
         visuals[visual.vid] = visual;
         if (Object.keys(visuals).length == n_visuals)
             cb()
         else
             readVisuals(bl, visuals, n_visuals, cb);
    });
}

function readDepths(bl, display, depths, n_depths, cb)
{
    if (n_depths == 0)
    {
        cb();
        return;
    }

    bl.unpack( 'CxSxxxx', function(res) {
        var dep = res[0];
        var n_visuals = res[1];
        var visuals = {};
        readVisuals(bl, visuals, n_visuals, function()
        {
            if (dep in depths) {
                for (var visual in visuals) {
                    depths[dep][visual] = visuals[visual];
                }
                n_depths--;
            } else {
                depths[dep] = visuals;
            }
            if (Object.keys(depths).length == n_depths)
                cb();
            else
                readDepths(bl, display, depths, n_depths, cb);
        });
    });
}

function readScreens(bl, display, cbDisplayReady)
{
     // for (i=0; i < display.screen_num; ++i)
     {
         var scr = {};
         bl.unpackTo( scr,
         [
             'L root',
             'L default_colormap',
             'L white_pixel',
             'L black_pixel',
             'L input_masks',
             'S pixel_width',
             'S pixel_height',
             'S mm_width',
             'S mm_height',
             'S min_installed_maps',
             'S max_installed_maps',
             'L root_visual',
             'C root_depth',
             'C backing_stores',
             'C root_depth',
             'C num_depths'
         ],
         function () {
             var depths = {};
             readDepths(bl, display, depths, scr.num_depths, function() {

                 scr.depths = depths;
                 delete scr.num_depths;
                 display.screen.push(scr);

                 if (display.screen.length == display.screen_num)<commit_msg>Refactor to keep number of parsed depths in a counter<commit_after>var getAuthString = require('./auth');
var xutil = require('./xutil');

function readVisuals(bl, visuals, n_visuals, cb)
{
    if (n_visuals == 0)
    {
        cb();
        return;
    }

    var visual = {};
    bl.unpackTo( visual,
    [
        'L vid',
        'C class',
        'C bits_per_rgb',
        'S map_ent',
        'L red_mask',
        'L green_mask',
        'L blue_mask',
        'xxxx'
    ],
    function() {
         var vid = visual.vid;
         // delete visual.vid;
         visuals[visual.vid] = visual;
         if (Object.keys(visuals).length == n_visuals)
             cb()
         else
             readVisuals(bl, visuals, n_visuals, cb);
    });
}

function readScreens(bl, display, cbDisplayReady)
{
     var numParsedDepths = 0;
     var readDepths = function(bl, display, depths, n_depths, cb)
     {
         if (n_depths == 0)
         {
             cb();
             return;
         }

         bl.unpack( 'CxSxxxx', function(res) {
             var dep = res[0];
             var n_visuals = res[1];
             var visuals = {};
             readVisuals(bl, visuals, n_visuals, function()
             {
                 if (dep in depths) {
                     for (var visual in visuals) {
                         depths[dep][visual] = visuals[visual];
                     }
                 } else {
                     depths[dep] = visuals;
                 }
                 numParsedDepths++;
                 if (numParsedDepths == n_depths)
                     cb();
                 else
                     readDepths(bl, display, depths, n_depths, cb);
             });  
         });
     }

     // for (i=0; i < display.screen_num; ++i)
     {
         var scr = {};
         bl.unpackTo( scr,
         [
             'L root',
             'L default_colormap',
             'L white_pixel',
             'L black_pixel',
             'L input_masks',
             'S pixel_width',
             'S pixel_height',
             'S mm_width',
             'S mm_height',
             'S min_installed_maps',
             'S max_installed_maps',
             'L root_visual',
             'C root_depth',
             'C backing_stores',
             'C root_depth',
             'C num_depths'
         ],
         function () {
             var depths = {};
             readDepths(bl, display, depths, scr.num_depths, function() {

                 scr.depths = depths;
                 delete scr.num_depths;
                 display.screen.push(scr);

                 if (display.screen.length == display.screen_num)
{'fraction_non_alphanumeric': 0.11892633228840126, 'fraction_numerical': 0.0021551724137931034, 'mean_word_length': 1.249889819303658, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3988463', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1502, 'n_words': 340}