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

📄 command.c

📁 mpeg 解复用
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * ISO 13818 stream multiplexer * Copyright (C) 2001 Convergence Integrated Media GmbH Berlin * Copyright (C) 2004 Oskar Schirmer (schirmer@scara.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *//* * Module:  Command * Purpose: User interface. */#include "global.h"#include "error.h"#include "input.h"#include "output.h"#include "command.h"#include "splice.h"#include "splitpes.h"#include "splitts.h"#include "dispatch.h"#include "ts.h"static int argc, argi;static char **argv;static boolean first;static int cmdf;static byte combuf[MAX_DATA_COMB];static int combln, comlln;static char *comarg;static char *lastfile;  /* Hold last filename used */static filerefer_list *filerefer;static command_list coms[] = { {C_HELP,14,-1, "help",   "display this help", ""}, {C_VERS,14,'V',"version","output version information", ""}, {C_QUIT,14,'Q',"quit",   "quit this program", ""}, {C_VERB,8, 'v',"verbose","[<level>]", ""}, {0,     18,-1, NULL,    "verbose mode 0..6, default=2, initial=1", ""}, {C_OPES,4, 'p',"pes",    "<file>%s", " <target program>"}, {0,     18,-1, NULL,    "open a PES input <file>%s", ", output as <target program>"}, {C_OPES,4, 'p',"pes",   "<file'>%s <target stream id>", " <target program>"}, {0,     18,-1, NULL,    "open a PES input <file'>, output as <target stream id>", ""}, {C_OPS, 3, 'P',"ps",    "<file>%s", " <target program>"}, {0,     18,-1, NULL,    "open a PS input <file>%s", ", output as <target program>"}, {C_OPS, 3, 'P',"ps",    "<file'>%s <source stream id> [<target stream id>]", " <target program>"}, {0,     18,-1, NULL,    "take a stream from PS, output as <target stream id>", ""}, {C_OTS, 3, 'T',"ts",    "<file>     open a TS input <file>", ""}, {C_OTS, 3, 'T',"ts",    "<file'> <source program>%s", " [<target program>]"}, {0,     18,-1, NULL,    "open <source program>%s", ", output as <target program>"}, {C_OTS, 3, 'T',"ts",    "<file'> <source prog> %s<stream id> [<target stream id>]",    "<target prog> "}, {0,     18,-1, NULL,    "open <source prog>, take <stream id>, output%s", " in"}, {0,     18,-1, NULL,    "%sas <target stream id>", "<target prog> "}, {C_OTS, 3, 'T',"ts",    "<file'> 0 %s<source stream id> [<target stream id>]",    "<target prog> "}, {0,     18,-1, NULL,    "from a single-program TS with broken PSI, take a stream", ""}, {C_CLOS,6, 'c',"close", "<file>  close <file> as if eof is reached", ""}, {C_APPE,7, 'a',"append","<file'> <file2> [<num>]", ""}, {0,     18,-1, NULL,    "append <file2> to open as soon as <file'> is done,", ""}, {0,     18,-1, NULL,    "set repeatition for <file2> to <num>, infinite=0", ""}, {C_FILE,5, 'f',"file",  "<refnum> <filename>", ""}, {0,     18,-1, NULL,    "declare a number to be used instead of a file name", ""}, {C_CROP,5, 'x',"crop",  "%s[<target stream id>]", "<target prog> "}, {0,     18,-1, NULL,    "crop %sprogram or a stream", "a "}, {C_REPT,7, 'r',"repeat","<file'> <num>", ""}, {0,     18,-1, NULL,    "set repeatition for <file'> to <num>, infinite=0", ""}, {C_FROP,7,'R',"reopen",    "...    open the next file with new handle even if yet open", ""}, {C_TSSI,3, -1, "si",    "<file'> [<low> <high>]", NULL}, {0,     18,-1, NULL,    "in TS <file'> handle pids in <low>..<high> as SI-streams", NULL}, {C_TSSP,6, -1, "sipid",    "<target program> [<pid> [<stream type>]]", NULL}, {0,    18, -1, NULL,    "manually add/delete entry in PMT for <target program>", NULL}, {C_DSCR,6, -1, "descr",    "%s[<tag> [<length> <data>...]]", "<target_prog> "}, {0,    18, -1, NULL,    "add/inhibit/delete a descriptor (not stream specific)", ""}, {C_DSCS,7, -1, "sdescr",    "[%s[<stream_id> [<tag> [<length> <data>...]]]]", "<target_prog> "}, {0,    18, -1, NULL,    "add/inhibit/delete a descriptor for <stream_id>", ""}, {C_DSCP,7, -1, "pdescr",    "[<target_prog> [<pid> [<tag> [<length> <data>...]]]]", NULL}, {0,    18, -1, NULL,    "add/inhibit/delete a descriptor for <pid>", NULL}, {C_TSID,6, 'I',"ident",    "<num>   set the output transport stream id", NULL}, {C_BUSY,5, 'B',"busy",  "[0|1]    if '1' do not stop if idle", ""}, {C_TIMD,14,-1, "timed",    "force delay timing even if solely diskfiles in use", ""}, {C_FPSI,5 ,'F',"fpsi",    "<msec>   set psi table frequency, single=0, initial=0", ""}, {C_TRGI,7, -1, "trigin",    "<msec> set input buffer trigger timing, initial=250", ""}, {C_TRGO,8, -1, "trigout",    "<msec>", ""}, {0,     18,-1, NULL,    "set output buffer trigger timing, initial=250", ""}, {C_CONF,7 ,'C',"config",    "0..2   show current stream configuration (off=0, on=1, more=2)", ""}, {C_STAT,11,'S',"statistics",    "<msec>", ""}, {0,     18,-1, NULL,    "show load statistics periodically (off=0)", ""}, {C_BSCR,14,-1, "badtiming",    "accept and maybe correct bad timing from DVB card", ""}, {C_CPID,17,-1, "conservativepids", "[0|1]", NULL}, {0,     18,-1, NULL,    "be conservative in pid assignment", NULL}, {0,     0,  0, NULL,    NULL, NULL}};/* Pop m characters from command input buffer by moving * the rest to the left. * Precondition: 0<=m<=cmbln */static void moveleft (int m){  combln -= m;  memmove (&combuf[0], &combuf[m], combln);}/* Determine whether there is a complete command line * available. If so, split into single words. * Precondition: combln>=0 * Postcondition: argc==WordCount and argi==1 and comarg^==Word[0] *                and comlln==LineLength * Return: TRUE, if line complete, FALSE otherwise. */ static boolean line_complete (void){  int i;  i = 0;  while (i < combln) {    if (combuf[i] == '\n') {      argc = 1;      comlln = i;      while (i >= 0) {        if (combuf[i] <= ' ') {          combuf[i] = 0;          argi = argc;        } else {          comarg = &combuf[i];          argc = argi+1;        }        i -= 1;      }      argi = 1;      return (TRUE);    }    i += 1;  }  return (FALSE);}/* Determine, if there is a tokenword available. * Precondition: argc==Number_of_Words * Return: Pointer to the word, if available, NULL otherwise. */static char *available_token (void){  char *r = NULL;  if (argi < argc) {    if (first) {      r = argv[argi];    } else {      r = comarg;    }  }  return (r);}/* Scan to the next tokenword. * Precondition: argc==WordCount and if !first: comarg^==Word[argi-1] * Postcondition: dito. */ static void next_token (void){  if (argi < argc) {    argi += 1;    if (!first) {      if (argi < argc) {        do {          comarg += 1;        } while (*comarg != 0);        do {          comarg += 1;        } while (*comarg == 0);      }    }  }}/* Determine the token code for a word. * If first: Decide for long command word, if double hyphen. * If !first: Decide for long command word, if word length > 1 * Precondition: argc==WordCount and if !first: comarg^==Word[argi-1] * Return: token>0, if found, -1 otherwise. */static int token_code (char *t){  command_list *l;  boolean islong;  if (t == NULL) {    return (0);  }  if (first) {    if (*t++ != '-') {      return (-1);    }    if ((islong = (*t == '-'))) {      t += 1;    }  } else {    islong = (t[1] != 0);  }  l = &coms[0];  while (l->width != 0) {    if (splice_multipleprograms || (l->explmulti != NULL)) {      if (l->comlong != NULL) {        if (islong ? (!strcmp(t,l->comlong))                   : (*t == l->comshort)) {          return (l->token);        }      }    }    l += 1;  }  return (-1);}/* Print usage information to stderr. */static void command_help (void){  command_list *l;  fprintf (stderr, "Usage: %s [COMMAND...]\n\n  ", argv[0]);  l = &coms[0];  while (l->width != 0) {    if (splice_multipleprograms || (l->explmulti != NULL)) {      if (l->comshort > 0) {        fprintf (stderr, "-%c,", l->comshort);      } else {        fprintf (stderr, "   ");      }      if (l->comlong != NULL) {        fprintf (stderr, "  --%-*s", l->width, l->comlong);      } else {        fprintf (stderr, "%-*s", l->width, "");      }      fprintf (stderr, l->explain, splice_multipleprograms ? l->explmulti : "");      fprintf (stderr, "\n  ");    }    l += 1;  }  fprintf (stderr, "\n"    "Any command may be fed to stdin omitting the leading (double) hyphen\n"    "during operation. '...' means following command wanted on same line.\n"    "Files may be specified by filename or reference number (set by --file).\n"    "<file'> may be replaced with '=' to use previously mentioned file.\n");}/* Check the filerefer list for the given filerefnum * Precondition: filerefnum>=0 * Return: Pointer to corresponding filename, if found, NULL otherwise. */static char *filerefer_name (int filerefnum){  filerefer_list *fref;  fref = filerefer;  while ((fref != NULL)      && (fref->filerefnum != filerefnum)) {    fref = fref->next;  }  if (fref != NULL) {    return (fref->filename);  } else {    return (input_filerefername (filerefnum));  }}/* Add a pair of filerefnum and filename to the filerefer list. * Replace a pair with same filerefnum, if found. * Precondition: filerefnum>=0 * Postcondition: Only one entry with filerefnum is in the list. */static void filerefer_remind (int filerefnum,    char *filename){  filerefer_list *fref;  fref = filerefer;  while ((fref != NULL)      && (fref->filerefnum != filerefnum)) {    fref = fref->next;  }  if (fref == NULL) {    if ((fref = malloc (sizeof (filerefer_list))) != NULL) {      fref->next = filerefer;      fref->filerefnum = filerefnum;      filerefer = fref;    }  } else {    if (fref->filename != NULL) {      free (fref->filename);    }  }  if (fref != NULL) {    if ((fref->filename = malloc (strlen (filename) + 1)) != NULL) {      strcpy (fref->filename,filename);    }  }}/* Remove a pair of filerefnum and filename from the filerefer list * Precondition: Only one entry with filerefnum in the list. * Postcondition: No entry with filerefnum in the list. */static void filerefer_forget (int filerefnum){  filerefer_list **rref;  rref = &filerefer;  while ((*rref != NULL)      && ((*rref)->filerefnum != filerefnum)) {    rref = &((*rref)->next);  }  if (*rref != NULL) {    filerefer_list *fref;    if ((*rref)->filename != NULL) {      free ((*rref)->filename);    }    fref = *rref;    *rref = (*rref)->next;    free (fref);  }}/* Check for special token "=" that denotes "same file again" * return: TRUE is name=="=", FALSE otherwise */static boolean fileagain (char *name){  if (name != NULL) {    return ((name[0] == '=') && (name[1] == 0));  } else {    return (FALSE);  }}/* Remind the filename that was just used. * Precondition: name!=NULL */static void set_lastfile (char *name){  char *lf;  if ((lf = malloc (strlen (name) + 1)) != NULL) {    strcpy (lf,name);  }  if (lastfile != NULL) {    free (lastfile);  }  lastfile = lf;}/* Open a file given by name. If name is "=", use last filename, else * set last filename. If opening succeeds, delete any corresponding * entry from the filerefer list. * Precondition: name!=NULL * Return: File if opened, NULL otherwise. */static file_descr* openfile (char *name,    int filerefnum,    content_type content,    boolean automatic,    int programnb,    boolean forcereopen){  file_descr *f;  if (fileagain (name)) {    name = lastfile;

⌨️ 快捷键说明

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