2018-12-08 22:43:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes\Frame;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
use App\Classes\Frame as AbstractFrame;
|
|
|
|
use App\Classes\FrameFields;
|
|
|
|
|
|
|
|
class Videotex extends AbstractFrame
|
|
|
|
{
|
|
|
|
public static $frame_length = 22;
|
|
|
|
public static $frame_width = 40;
|
|
|
|
|
|
|
|
public static $header_length = 20;
|
|
|
|
public static $pagenum_length = 9;
|
|
|
|
public static $cost_length = 7;
|
|
|
|
public static $cost_unit = 'u';
|
|
|
|
|
2018-12-11 12:31:44 +00:00
|
|
|
public static $if_filler = '.';
|
|
|
|
|
2018-12-13 13:02:42 +00:00
|
|
|
public function __construct(\App\Models\Frame $o,string $msg='')
|
|
|
|
{
|
|
|
|
parent::__construct($o);
|
|
|
|
|
|
|
|
// If we have a message to display on the bottom line.
|
|
|
|
if ($msg)
|
|
|
|
$this->output .= HOME.UP.$msg.HOME;
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:21:25 +00:00
|
|
|
// @todo Change to use a Parser, like we do for ANSI
|
2018-12-13 13:02:42 +00:00
|
|
|
public function fields($startline=1)
|
2018-12-08 22:43:18 +00:00
|
|
|
{
|
|
|
|
$infield = FALSE; // In a field
|
|
|
|
$fieldtype = NULL; // Type of field
|
|
|
|
$fieldlength = 0; // Length of field
|
|
|
|
|
|
|
|
// $fieldadrline = 1;
|
|
|
|
|
|
|
|
// Scan the frame for a field start
|
2018-12-13 13:02:42 +00:00
|
|
|
for ($y=$startline-1;$y<=static::$frame_length;$y++)
|
2018-12-08 22:43:18 +00:00
|
|
|
{
|
|
|
|
// Fields can only be on a single line
|
|
|
|
$fieldx = $fieldy = FALSE;
|
|
|
|
|
|
|
|
for ($x=0;$x<static::$frame_width;$x++)
|
|
|
|
{
|
2018-12-13 13:02:42 +00:00
|
|
|
$posn = $y*static::$frame_width+$x;
|
2018-12-08 22:43:18 +00:00
|
|
|
|
|
|
|
// If the frame is not big enough, fill it with spaces.
|
|
|
|
$byte = ord(isset($this->frame->content{$posn}) ? $this->frame->content{$posn} : ' ')%128;
|
|
|
|
|
|
|
|
// Check for start-of-field
|
|
|
|
if ($byte == ord(ESC)) { // Esc designates start of field (Esc-K is end of edit)
|
|
|
|
$infield = TRUE;
|
|
|
|
$fieldlength = 1;
|
|
|
|
$fieldtype = ord(substr($this->frame->content,$posn+1,1))%128;
|
2018-12-11 12:31:44 +00:00
|
|
|
$this->output .= static::$if_filler;
|
2018-12-08 22:43:18 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if ($infield) {
|
|
|
|
if ($byte == $fieldtype) {
|
|
|
|
$fieldlength++;
|
2018-12-11 12:31:44 +00:00
|
|
|
$byte = ord(static::$if_filler); // Replace field with static::$if_filler.
|
2018-12-08 22:43:18 +00:00
|
|
|
|
|
|
|
if ($fieldx === FALSE) {
|
|
|
|
$fieldx = $x;
|
|
|
|
$fieldy = $y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this a magic field?
|
|
|
|
if (array_get($this->fieldmap,chr($fieldtype)) ) {
|
|
|
|
$field = $this->fieldmap[chr($fieldtype)];
|
|
|
|
//dump(['infield','byte'=>$byte,'fieldtype'=>$fieldtype,'field'=>$field,'strpos'=>strpos($field,'#')]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
// address field has many lines. increment when hit on first character.
|
|
|
|
if ($fieldlength == 1 && strpos($field,'#') !== false) {
|
|
|
|
$field = str_replace('#',$fieldadrline,$field);
|
|
|
|
dump(['field'=>$field,'fieldadrline'=>$fieldadrline,'fieldadrline'=>$fieldadrline]);
|
|
|
|
$fieldadrline++;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Replace field with Date
|
|
|
|
if ($field == '%date') {
|
|
|
|
// Drop the last dot and replace it.
|
|
|
|
if ($fieldlength == 2) {
|
|
|
|
$datetime = date('D d M H:ia');
|
2018-12-11 12:31:44 +00:00
|
|
|
$this->output = rtrim($this->output,static::$if_filler);
|
2018-12-08 22:43:18 +00:00
|
|
|
$this->output .= $datetime{0};
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($fieldlength > 1 AND $fieldlength <= strlen($datetime))
|
|
|
|
$byte = ord($datetime{$fieldlength-1});
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo user data
|
|
|
|
/* else if (isset($user[$field])) {
|
|
|
|
if ($fieldlength <= strlen($user[$field])) {
|
|
|
|
$byte = ord($user[$field]{$fieldlength-1});
|
|
|
|
}
|
|
|
|
} /*else // pre-load field contents. PAM or *00 ?
|
|
|
|
if (isset($fields[what]['value'])) {
|
|
|
|
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->fields->push(new FrameFields([
|
|
|
|
'type'=>chr($fieldtype),
|
|
|
|
'length'=>$fieldlength,
|
|
|
|
'x'=>$fieldx-1, // Adjust for the ESC char
|
|
|
|
'y'=>$fieldy,
|
|
|
|
]));
|
|
|
|
|
|
|
|
Log::debug(sprintf('Frame: %s, Field found at [%s,%s], Type: %s, Length: %s',$this->page(),$fieldx-1,$fieldy,$fieldtype,$fieldlength));
|
|
|
|
|
|
|
|
$infield = FALSE;
|
|
|
|
$fieldx = $fieldy = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// truncate end of lines @todo havent validated this code or used it?
|
|
|
|
if (isset($pageflags['tru']) && substr($this->frame->content,$posn,40-$x) === str_repeat(' ',40-$x)) {
|
|
|
|
$this->output .= CR . LF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $infield OR $fieldlength > 1)
|
|
|
|
$this->output .= ($byte < 32) ? ESC.chr($byte+64) : chr($byte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function strlenv($text):int {
|
|
|
|
return strlen($text)-substr_count($text,ESC);
|
|
|
|
}
|
|
|
|
}
|