#!/usr/bin/perl

use strict;
use warnings;
use File::Slurp qw( write_file );
use File::Copy qw( copy );

my $cfg_default = "/opt/pos/common/addons/graphical_display/config_default.xml";
my $cfg = "/opt/pos/common/addons/graphical_display/config.xml";

my $x = shift;
die "$0 <x>" unless defined $x;

copy($cfg_default, $cfg);

my $form_start = 0;
my $first_x = 0;

my $cnt = "";

open(F, "< $cfg");
while(<F>) {
  if (/<FORM>/) {
    $form_start = 1;
  }
  elsif (/<\/FORM>/) {
    $first_x = 0;
    $form_start = 0;
  }
  else {
    if (/<X>/ && ! $first_x) {
      s/<X>\d+<\/X>/<X>$x<\/X>/;
      $first_x = 1;
    }
  }

  $cnt .= $_;
}
close(F);

write_file($cfg, $cnt);

