⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iportfromfile.cpp

📁 用于解析ts流中的各种业务信息表可以用于dvb中嘛流分析
💻 CPP
字号:
/* Copyright (C) 1995, Tektronix Inc. All Rights Reserved. * *   Usage Restrictions * * License is granted to copy, to use, and to make and to use derivative * works for research and evaluation purposes only. * *   Disclaimer of Warranty * * These software programs are available to the user without any license * fee or royalty on an "as is" basis.  Tektronix Inc. disclaims any and * all warranties, whether express, implied, or statuary, including any * implied warranties or merchantability or of fitness for a particular * purpose.  In no event shall the copyright-holder be liable for any  * incidental, punitive, or consequential damages of any kind whatsoever * arising from the use of these programs. * * This disclaimer of warranty extends to the user of these programs and * user's customers, employees, agents, transferees, successors, and * assigns. * * The Tektronix Inc. does not represent or warrant that the programs * furnished hereunder are free of infringement of any third-party * patents.*//* IPortFromFile implementation */#include "IPortFromFile.H"#include "Utilities.H"
#include "memory.h"/*extern "C"{#include <stdio.h>#include <fcntl.h>#include <errno.h>int read (int, char*, int);int write (int, char*, int);int close (int);}*/IPortFromFile::IPortFromFile (char* fileName, int flag) : InputPort(){

	memset(fbuf, 0, sizeof(fbuf));
	flen = 0;    // opens file and sets pos    cycle_flag = flag;    file_name = fileName;//  fd = open(file_name, O_RDONLY);//  fd = _open(file_name, _O_RDONLY);
//  fd = _open(file_name, _O_RDONLY);
	fd2 = fopen(file_name, "rb");
//test begin
/*  char bufTest[188*40];
  int itest = fread(bufTest, 1, 188*40, fd2);
  itest = fread(bufTest, 1, 188*40, fd2);
  itest = fread(bufTest, 1, 188*40, fd2);
  itest = fread(bufTest, 1, 188*40, fd2);
*/
  //test end
  if (fd2 != NULL)  {      pos = -1;  // forces read on first call to read_bit  }  else  {      sys_message("unable to open file in IPortFromFile::IPortFromFile");  }}char IPortFromFile::input_bit ()// returns next bit as a char or BADBIT for an error{  int result = inc_bit ();   if (result) return bit2char();  return BADBIT;}char IPortFromFile::input_byte (){//  int result;  if (flen == 0)  {      flen = fread(fbuf, 1, CacheSize, fd2);      if (flen == 0) 	  {	    if (cycle_flag == NOCYCLE) sys_halt("End of Input Stream");	    fclose(fd2);	    fd2 = fopen(file_name, "rb");	    if (fd2 != NULL) flen = fread(fbuf, 1, CacheSize, fd2);	    if (flen == 0) sys_halt("Unable to Cycle on input file");	    if (flen < 0) sys_error("error reading input file");	  }      else if (flen < 0) 	  {	    sys_error("error reading input file");	  }      bufpos = 0;  }  if (pos <= 0)    {      byte = fbuf[bufpos++];      if (bufpos == flen) flen = 0;    }  else    {      sys_error("can't read_byte; not on byte boundary");    }    return byte;}int IPortFromFile::inc_bit ()// increments pos or reads from file if necessary{//  int result;  if (pos <= 0)    {      (void) input_byte(); // it has already set `byte'      pos = 7;    }  else    {      pos--;    }  return 1;}char IPortFromFile::bit2char ()// returns ONE or ZERO depending on current bit;{  return (byte & (1 << pos)) ? ONE : ZERO;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -