📄 main.cc
字号:
/* * Copyright (c) 1996 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement * is hereby granted, provided that the above copyright notice and the * following two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE * UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * * $Id: main.cc,v 1.8 1997/01/11 00:45:39 aswan Exp $ */#include <stdio.h>#ifdef sgi#include <getopt.h>#endif#include <X11/Xlib.h>#ifdef _AIX#include <stdlib.h>#include <unistd.h>#endif/* Get FD_SETSIZE */#if defined(linux)# include <sys/time.h>#elif defined(__hpux)# include <sys/types.h>#elif defined(HAVE_SYS_SELECT_H)# include <sys/select.h>#endifextern "C" {#include <tk.h>}#include "Tcl.h"static voidusage(){ fprintf(stderr, "\Usage: rtpmon [-C name] [-d display] [-K key] [-t threshold] [-u script]\n\[-X resource=value] addr/port\n"); exit(1);}static class UsageCommand : public TclObject { public: UsageCommand() : TclObject("usage") {} int command(int argc, const char*const* argv) { usage(); /*NOTREACHED*/ return (0); }} cmd_usage;extern "C" char version[];static class HaveFontCommand : public TclObject { public: HaveFontCommand() : TclObject("havefont") {} int command(int argc, const char*const* argv) { Tcl& t = Tcl::instance(); if (argc != 2) t.result("0"); else { Tk_Window tk = t.tkmain(); Tk_Uid uid = Tk_GetUid((char*)argv[1]); XFontStruct* p = Tk_GetFontStruct(t.interp(), tk, uid); t.result(p != 0 ? "1" : "0"); } return (TCL_OK); }} cmd_havefont;static class VersionCommand : public TclObject { public: VersionCommand() : TclObject("version") {} int command(int argc, const char*const* argv) { Tcl::instance().result(version); return (TCL_OK); }} cmd_version;extern "C" char *optarg;extern "C" int optind;extern "C" int opterr;const char*disparg(int argc, const char** argv, const char* optstr){ const char* display = 0; int op; while ((op = getopt(argc, (char**)argv, (char*)optstr)) != -1) { if (op == 'd') { display = optarg; break; } else if (op == '?') usage(); }#ifdef linux optind = 0;#else optind = 1;#endif return (display);}char*parse_assignment(char* cp){ cp = strchr(cp, '='); if (cp != 0) { *cp = 0; return (cp + 1); } else return ("true");}extern "C" int Tk_StripchartCmd(ClientData, Tcl_Interp*, int ac, char** av);extern "C" {intTkPlatformInit(Tcl_Interp* interp){ extern void TkCreateXEventSource(void); Tcl_SetVar(interp, "tk_library", ".", TCL_GLOBAL_ONLY); TkCreateXEventSource(); return(TCL_OK);}}intmain(int argc, const char** argv){ /* * Close open files. This is needed because if we get invoked via * a tcl "exec" from a program like vat or vic, we might accidentally * inherit the audio device or video capture device or network streams. */ for (int i = 3; i < FD_SETSIZE; i++) close(i); Tcl::init("rtpmon"); opterr = 0; const char* optstr = "C:K:t:u:X:"; const char* display = disparg(argc, argv, optstr); Tcl& tcl = Tcl::instance(); tcl.evalf(display ? "set argv \"-name rtpmon -display %s\"" : "set argv \"-name rtpmon\"", display); /* Tk_Window tk = Tk_CreateMainWindow(tcl.interp(), (char*)display, "rtpmon", "Rtpmon"); */ Tk_Window tk = 0; if (Tk_Init(tcl.interp()) == TCL_OK) tk = Tk_MainWindow(tcl.interp()); if (tk == 0) { fprintf(stderr, "rtpmon: %s\n", tcl.result()); exit(1); } tcl.tkmain(tk); /*Blt_TableInit(tcl.interp());*/ tcl.CreateCommand("stripchart", Tk_StripchartCmd, (ClientData)tk); EmbeddedTcl::init(); tcl.evalc("init_resources"); int op; while ((op = getopt(argc, (char**)argv, (char*)optstr)) != -1) { switch (op) { default: usage(); case 'C': tcl.add_option("conferenceName", optarg); break; case 'K': /*XXX probably do not want this in X server*/ tcl.add_option("sessionKey", optarg); break; case 't': tcl.add_option("threshold", optarg); break; case 'u': tcl.add_option("startupScript", optarg); break; case 'X': { const char* value = parse_assignment(optarg); tcl.add_option(optarg, value); } break; } } const char* dst; if (optind < argc && argc > 1) { dst = argv[optind]; if (argc - optind > 1) { fprintf(stderr, "rtpmon: extra arguments (starting with `%s')\n", argv[optind + 1]); exit(1); } } else if ((dst = tcl.attr("defaultHostSpec")) == 0) { fprintf(stderr, "rtpmon: destination address required\n"); exit(1); } tcl.add_option("defaultHostSpec", dst); tcl.evalc("rtpmon_main"); Tk_MainLoop(); return (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -