예제 #1
0
		// time := hour colon minute [ colon second ] .
		void time()
		{
			hour();
			colon();
			minute();
			if (is_colon(scan.get())) {
				colon();
				second();
			}
		}
예제 #2
0
파일: clock.cpp 프로젝트: poyu1990/Clock
void Clock::display(tm *currentTime){

     int hour = currentTime->tm_hour;
     bool isPm = 0;

     if( hour>=12 )
         isPm = 1;
     else 
         isPm = 0;

     // military time to 12 hour time
     if(!militaryTime){
         if(hour>12)
             hour -= 12;
         else if(hour == 0)
             hour = 12;
     }
     
     int hourTens = hour/10;
     int hourOnes = hour%10;
     int minuteTens = ((currentTime->tm_min))/10;
     int minuteOnes = ((currentTime->tm_min))%10;
     int secondTens = ((currentTime->tm_sec))/10;
     int secondOnes = ((currentTime->tm_sec))%10;
     
     hour1.display( hourTens );
     hour2.display( hourOnes );
     minute1.display( minuteTens );
     minute2.display( minuteOnes );
     
     if(showSeconds && (mode != ALARM && mode != ALARM_SET)){
          second1.display( secondTens );
          second2.display( secondOnes );
          colon2( currentTime->tm_sec%2 );
          
     }
     else{
          second1.clear();
          second2.clear();
          colon2(0);
     }
          
     if( mode == ALARM || mode == ALARM_SET )
         colon(1);
     else
          colon( currentTime->tm_sec%2 );
          
     pm( isPm && !militaryTime );
     
     refresh();    
}
예제 #3
0
파일: symbols.c 프로젝트: hogliux/cctools
void
local_colon(
int n)	/* just saw "n:" */
{
  fb_label_instance_inc (n);
  colon (fb_label_name (n, 0));
}
예제 #4
0
void
local_colon(
int n)	/* just saw "n:" */
{
  local_label_counter [n] ++;
  colon (local_label_name (n, 0));
}
예제 #5
0
파일: Parameter.cpp 프로젝트: zklvyy/hikyuu
HKU_API std::ostream& operator <<(std::ostream &os, const Parameter& param) {
    //os << std::fixed;
    //os.precision(4);
    os << "params[";
    string strip(", ");
    string colon(": ");
    Parameter::param_map_t::const_iterator iter = param.m_params.begin();
    for (; iter != param.m_params.end(); ++iter) {
        os << iter->first;
        if (iter->second.type() == typeid(int)) {
            os << "(i): "
               << boost::any_cast<int>(iter->second) << strip;
        } else if (iter->second.type() == typeid(bool)) {
            os << "(b): "
               << boost::any_cast<bool>(iter->second) << strip;
        } else if (iter->second.type() == typeid(double)) {
            os << "(d): "
               << boost::any_cast<double>(iter->second) << strip;
        } else if (iter->second.type() == typeid(string)) {
            os << "(s): "
               << boost::any_cast<string>(iter->second) << strip;
        } else {
            os << "Unsupported" << strip;
        }
    }
    os << "]";
    return os;
}
예제 #6
0
format unification_app_mismatch_exception::pp(formatter const & fmt, options const & opts) const {
    unsigned indent     = get_pp_indent(opts);
    auto const & ctx    = get_context();
    expr const & app    = get_expr();
    auto args_it        = get_args().begin();
    auto args_end       = get_args().end();
    auto types_it       = get_types().begin();
    format app_fmt      = fmt(ctx, app, false, opts);
    format r            = format{format(what()), nest(indent, compose(line(), app_fmt))};
    format fun_type_fmt = fmt(ctx, *types_it, false, opts);
    r += compose(line(), format("Function type:"));
    r += nest(indent, compose(line(), fun_type_fmt));
    ++args_it;
    ++types_it;
    if (get_args().size() > 2)
        r += compose(line(), format("Arguments types:"));
    else
        r += compose(line(), format("Argument type:"));
    for (; args_it != args_end; ++args_it, ++types_it) {
        format arg_fmt    = fmt(ctx, *args_it, false, opts);
        format type_fmt   = fmt(ctx, *types_it, false, opts);
        r += nest(indent, compose(line(), group(format{arg_fmt, space(), colon(), nest(indent, format{line(), type_fmt})})));
    }
    r += pp_elaborator_state(fmt, get_elaborator(), opts);
    return r;
}
예제 #7
0
void
tolocal(int argc, char *argv[])
{
	int i, len, tos;
	char *bp, *host, *src, *suser;

	for (i = 0; i < argc - 1; i++) {
		if (!(src = colon(argv[i]))) {		/* Local to local. */
			len = strlen(_PATH_CP) + strlen(argv[i]) +
			    strlen(argv[argc - 1]) + 20;
			if (!(bp = malloc(len)))
				err(1, "malloc");
			(void)snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP,
			    iamrecursive ? " -PR" : "", pflag ? " -p" : "",
			    argv[i], argv[argc - 1]);
			if (susystem(bp, userid))
				++errs;
			(void)free(bp);
			continue;
		}
		*src++ = 0;
		if (*src == 0)
			src = period;
		if ((host = strchr(argv[i], '@')) == NULL) {
			host = argv[i];
			suser = pwd->pw_name;
		} else {
			*host++ = 0;
			suser = argv[i];
			if (*suser == '\0')
				suser = pwd->pw_name;
			else if (!okname(suser)) {
				++errs;
				continue;
			}
		}
		len = strlen(src) + CMDNEEDS + 20;
		if ((bp = malloc(len)) == NULL)
			err(1, "malloc");
		(void)snprintf(bp, len, "%s -f %s", cmd, src);
		rem = rcmd_af(&host, port, pwd->pw_name, suser, bp, 0,
			    family);
		(void)free(bp);
		if (rem < 0) {
			++errs;
			continue;
		}
		(void)seteuid(userid);
		if (family == PF_INET) {
			tos = IPTOS_THROUGHPUT;
			if (setsockopt(rem, IPPROTO_IP, IP_TOS, &tos,
			    sizeof(int)) < 0)
				warn("TOS (ignored)");
		}
		sink(1, argv + argc - 1);
		(void)seteuid(0);
		(void)close(rem);
		rem = -1;
	}
}
void CSenPropertiesElement::Set( const TDesC8& aNamespaceURI,
                                 const TDesC8& aLocalName,
                                 const TDesC8& aQName )
    {
    if ( !ipStringPool )
        {
        CSenXmlElement::Set(aNamespaceURI, aLocalName, aQName);
        }
    else
        {
        RString localName;
        TInt leaveCode(KErrNone);
        TRAP( leaveCode, localName = ipStringPool->OpenStringL(aLocalName); )
        if( !leaveCode )
            {
            iLocalName.Close();
            iLocalName = localName;
        
            TPtrC8 prefix(KNullDesC8);
    
            if(aQName != KNullDesC8)
                {
                TInt colon(KErrNotFound);
                colon = aQName.Locate(':');
                if(colon!=KErrNotFound)
                    {
                    prefix.Set(aQName.Left(colon));
                    }
                }
            TRAP( leaveCode, SetNamespaceL(prefix, aNamespaceURI); )
예제 #9
0
format nested_elaborator_exception::pp() const {
    format r = m_exception->pp();
    if (dynamic_cast<nested_elaborator_exception*>(m_exception.get()) == nullptr) {
        r += line() + format("Additional information:");
    }
    pos_info_provider * pip = get_pos_info_provider();
    r += line();
    if (pip) {
        r += format(pip->get_file_name()) + colon();
        if (m_pos) {
            r += format(m_pos->first) + colon() + format(m_pos->second) + colon();
        }
        r += space();
    }
    r += format("context: ") + m_fmt;
    return r;
}
예제 #10
0
TEST(CSSTokenizerTest, CommentToken)
{
    TEST_TOKENS("/*comment*/a", ident("a"));
    TEST_TOKENS("/**\\2f**//", delim('/'));
    TEST_TOKENS("/**y*a*y**/ ", whitespace());
    TEST_TOKENS(",/* \n :) \n */)", comma(), rightParenthesis());
    TEST_TOKENS(":/*/*/", colon());
    TEST_TOKENS("/**/*", delim('*'));
    TEST_TOKENS(";/******", semicolon());
}
예제 #11
0
파일: rcp.c 프로젝트: lacombar/netbsd-alc
void
tolocal(int argc, char *argv[])
{
	int i;
	size_t len;
	char *bp, *host, *src, *suser;

	for (i = 0; i < argc - 1; i++) {
		if (!(src = colon(argv[i]))) {		/* Local to local. */
			len = strlen(_PATH_CP) + strlen(argv[i]) +
			    strlen(argv[argc - 1]) + 20;
			if (!(bp = malloc(len)))
				err(1, NULL);
			(void)snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP,
			    iamrecursive ? " -r" : "", pflag ? " -p" : "",
			    argv[i], argv[argc - 1]);
			if (susystem(bp))
				++errs;
			(void)free(bp);
			continue;
		}
		*src++ = 0;
		if (*src == 0)
			src = dot;
		if ((host = strchr(argv[i], '@')) == NULL) {
			host = argv[i];
			suser = pwname;
		} else {
			*host++ = 0;
			suser = argv[i];
			if (*suser == '\0')
				suser = pwname;
			else if (!okname(suser))
				continue;
		}
		host = unbracket(host);
		len = strlen(src) + CMDNEEDS + 20;
		if ((bp = malloc(len)) == NULL)
			err(1, NULL);
		(void)snprintf(bp, len, "%s -f %s", cmd, src);
		rem = 
			rcmd_af(&host, port, pwname, suser, bp, NULL, family);
		(void)free(bp);
		if (rem < 0) {
			++errs;
			continue;
		}
		sink(1, argv + argc - 1);
		(void)close(rem);
		rem = -1;
	}
}
예제 #12
0
TEST(CSSTokenizerTest, UrlToken)
{
    TEST_TOKENS("url(foo.gif)", url("foo.gif"));
    TEST_TOKENS("urL(https://example.com/cats.png)", url("https://example.com/cats.png"));
    TEST_TOKENS("uRl(what-a.crazy^URL~this\\ is!)", url("what-a.crazy^URL~this is!"));
    TEST_TOKENS("uRL(123#test)", url("123#test"));
    TEST_TOKENS("Url(escapes\\ \\\"\\'\\)\\()", url("escapes \"')("));
    TEST_TOKENS("UrL(   whitespace   )", url("whitespace"));
    TEST_TOKENS("URl( whitespace-eof ", url("whitespace-eof"));
    TEST_TOKENS("URL(eof", url("eof"));
    TEST_TOKENS("url(not/*a*/comment)", url("not/*a*/comment"));
    TEST_TOKENS("urL()", url(""));
    TEST_TOKENS("uRl(white space),", badUrl(), comma());
    TEST_TOKENS("Url(b(ad),", badUrl(), comma());
    TEST_TOKENS("uRl(ba'd):", badUrl(), colon());
    TEST_TOKENS("urL(b\"ad):", badUrl(), colon());
    TEST_TOKENS("uRl(b\"ad):", badUrl(), colon());
    TEST_TOKENS("Url(b\\\rad):", badUrl(), colon());
    TEST_TOKENS("url(b\\\nad):", badUrl(), colon());
    TEST_TOKENS("url(/*'bad')*/", badUrl(), delim('*'), delim('/'));
    TEST_TOKENS("url(ba'd\\\\))", badUrl(), rightParenthesis());
}
예제 #13
0
/*
   - ttoaddr - convert text name or dotted-decimal address to binary address
 */
err_t                           /* NULL for success, else string literal */
ttoaddr_base(const char *src,
	     size_t srclen,     /* 0 means "apply strlen" */
	     int af,            /* address family */
	     int   *allnumericfailed,
	     ip_address *dst)
{
	err_t oops;

#       define  HEXLEN  10      /* strlen("0x11223344") */

	switch (af) {
	case AF_INET:
	case AF_INET6:
	case 0:                  /* guess */
		break;

	default:
		return "invalid address family";
	}

	if (af == AF_INET && srclen == HEXLEN && *src == '0') {
		if (*(src + 1) == 'x' || *(src + 1) == 'X')
			return tryhex(src + 2, srclen - 2, 'x', dst);

		if (*(src + 1) == 'h' || *(src + 1) == 'H')
			return tryhex(src + 2, srclen - 2, 'h', dst);
	}

	if (memchr(src, ':', srclen) != NULL) {
		if (af == 0)
			af = AF_INET6;

		if (af != AF_INET6)
			return "non-ipv6 address may not contain `:'";

		return colon(src, srclen, dst);
	}

	if (af == 0 || af == AF_INET) {
		oops = trydotted(src, srclen, dst);
		if (oops == NULL)
			return NULL;            /* it worked */

		if (*oops != '?')
			return oops;            /* probably meant as d-d */
	}

	*allnumericfailed = 1;
	return "not numeric";
}
예제 #14
0
파일: scp.c 프로젝트: 0x0mar/backdoored-ssh
void
tolocal(int argc, char **argv)
{
	char *bp, *host, *src, *suser;
	arglist alist;
	int i;

	memset(&alist, '\0', sizeof(alist));
	alist.list = NULL;

	for (i = 0; i < argc - 1; i++) {
		if (!(src = colon(argv[i]))) {	/* Local to local. */
			freeargs(&alist);
			addargs(&alist, "%s", _PATH_CP);
			if (iamrecursive)
				addargs(&alist, "-r");
			if (pflag)
				addargs(&alist, "-p");
			addargs(&alist, "--");
			addargs(&alist, "%s", argv[i]);
			addargs(&alist, "%s", argv[argc-1]);
			if (do_local_cmd(&alist))
				++errs;
			continue;
		}
		*src++ = 0;
		if (*src == 0)
			src = ".";
		if ((host = strrchr(argv[i], '@')) == NULL) {
			host = argv[i];
			suser = NULL;
		} else {
			*host++ = 0;
			suser = argv[i];
			if (*suser == '\0')
				suser = pwd->pw_name;
		}
		host = cleanhostname(host);
		xasprintf(&bp, "%s -f %s%s",
		    cmd, *src == '-' ? "-- " : "", src);
		if (do_cmd(host, suser, bp, &remin, &remout) < 0) {
			free(bp);
			++errs;
			continue;
		}
		free(bp);
		sink(1, argv + argc - 1);
		(void) close(remin);
		remin = remout = -1;
	}
}
예제 #15
0
파일: clock.cpp 프로젝트: poyu1990/Clock
void Clock::clear(){
    
    hour1.clear();
    hour2.clear();
    minute1.clear();
    minute2.clear();
    second1.clear();
    second2.clear();
    
    pm(0);
    colon(0);
    colon2(0);
     
}
예제 #16
0
TEST(CSSTokenizerTest, SingleCharacterTokens)
{
    TEST_TOKENS("(", leftParenthesis());
    TEST_TOKENS(")", rightParenthesis());
    TEST_TOKENS("[", leftBracket());
    TEST_TOKENS("]", rightBracket());
    TEST_TOKENS(",", comma());
    TEST_TOKENS(":", colon());
    TEST_TOKENS(";", semicolon());
    TEST_TOKENS(")[", rightParenthesis(), leftBracket());
    TEST_TOKENS("[)", leftBracket(), rightParenthesis());
    TEST_TOKENS("{}", leftBrace(), rightBrace());
    TEST_TOKENS(",,", comma(), comma());
}
예제 #17
0
파일: scp.c 프로젝트: rdebath/sgt
/*
 *  We will issue a list command to get a remote directory.
 */
static void get_dir_list(int argc, char *argv[])
{
    char *src, *host, *user;
    char *cmd, *p, *q;
    char c;

    src = argv[0];

    /* Separate host from filename */
    host = src;
    src = colon(src);
    if (src == NULL)
	bump("Local to local copy not supported");
    *src++ = '\0';
    if (*src == '\0')
	src = ".";
    /* Substitute "." for empty filename */

    /* Separate username and hostname */
    user = host;
    host = strrchr(host, '@');
    if (host == NULL) {
	host = user;
	user = NULL;
    } else {
	*host++ = '\0';
	if (*user == '\0')
	    user = NULL;
    }

    cmd = smalloc(4*strlen(src) + 100);
    strcpy(cmd, "ls -la '");
    p = cmd + strlen(cmd);
    for (q = src; *q; q++) {
	if (*q == '\'') {
	    *p++ = '\''; *p++ = '\\'; *p++ = '\''; *p++ = '\'';
	} else {
	    *p++ = *q;
	}
    }
    *p++ = '\'';
    *p = '\0';
    
    do_cmd(host, user, cmd);
    sfree(cmd);

    while (ssh_recv(&c, 1) > 0)
	fputc(c, stdout);	       /* thank heavens for buffered I/O */
}
예제 #18
0
    HostAndPort parseName(std::string const& str)
    {
        std::string host (str);
        std::string port;

        std::string::size_type colon (host.find(':'));

        if (colon != std::string::npos)
        {
            port = host.substr (colon + 1);
            host.erase(colon);
        }

        return std::make_pair(host, port);
    }
예제 #19
0
파일: rcp.c 프로젝트: Kendra123/heimdal
void
tolocal(int argc, char **argv)
{
	int i;
	char *bp, *host, *src, *suser;

	for (i = 0; i < argc - 1; i++) {
		int ret;

		if (!(src = colon(argv[i]))) {		/* Local to local. */
			ret = asprintf(&bp, "exec %s%s%s %s %s", _PATH_CP,
			    iamrecursive ? " -PR" : "", pflag ? " -p" : "",
			    argv[i], argv[argc - 1]);
			if (ret == -1)
				err (1, "malloc");
			if (susystem(bp))
				++errs;
			free(bp);
			continue;
		}
		*src++ = 0;
		if (*src == 0)
			src = ".";
		if ((host = strchr(argv[i], '@')) == NULL) {
			host = argv[i];
			suser = pwd->pw_name;
		} else {
			*host++ = 0;
			suser = argv[i];
			if (*suser == '\0')
				suser = pwd->pw_name;
			else if (!okname(suser))
				continue;
		}
		ret = asprintf(&bp, "%s -f %s", cmd, src);
		if (ret == -1)
			err (1, "malloc");
		if (do_cmd(host, suser, bp, &remin, &remout) < 0) {
			free(bp);
			++errs;
			continue;
		}
		free(bp);
		sink(1, argv + argc - 1);
		close(remin);
		remin = remout = -1;
	}
}
예제 #20
0
파일: builtin_cmds.cpp 프로젝트: silky/lean
environment check_cmd(parser & p) {
    expr e   = p.parse_expr();
    list<expr> ctx = locals_to_context(e, p);
    level_param_names ls = to_level_param_names(collect_univ_params(e));
    level_param_names new_ls;
    std::tie(e, new_ls) = p.elaborate_relaxed(e, ctx);
    auto tc = mk_type_checker_with_hints(p.env(), p.mk_ngen(), true);
    expr type = tc->check(e, append(ls, new_ls));
    auto reg              = p.regular_stream();
    formatter const & fmt = reg.get_formatter();
    options opts          = p.ios().get_options();
    unsigned indent       = get_pp_indent(opts);
    format r = group(format{fmt(e), space(), colon(), nest(indent, compose(line(), fmt(type)))});
    reg << mk_pair(r, opts) << endl;
    return p.env();
}
예제 #21
0
파일: scp.c 프로젝트: rdebath/sgt
/*
 *  We will copy files from a remote server to the local machine.
 */
static void tolocal(int argc, char *argv[])
{
    char *src, *targ, *host, *user;
    char *cmd;

    if (argc != 2)
	bump("More than one remote source not supported");

    src = argv[0];
    targ = argv[1];

    /* Separate host from filename */
    host = src;
    src = colon(src);
    if (src == NULL)
	bump("Local to local copy not supported");
    *src++ = '\0';
    if (*src == '\0')
	src = ".";
    /* Substitute "." for empty filename */

    /* Separate username and hostname */
    user = host;
    host = strrchr(host, '@');
    if (host == NULL) {
	host = user;
	user = NULL;
    } else {
	*host++ = '\0';
	if (*user == '\0')
	    user = NULL;
    }

    cmd = smalloc(strlen(src) + 100);
    sprintf(cmd, "scp%s%s%s%s -f %s",
	    verbose ? " -v" : "",
	    recursive ? " -r" : "",
	    preserve ? " -p" : "",
	    targetshouldbedirectory ? " -d" : "",
	    src);
    do_cmd(host, user, cmd);
    sfree(cmd);

    sink(targ);
}
예제 #22
0
// ---------------------------------------------------------
// TCodParser::Colon()
// ---------------------------------------------------------
//
TBool TCodParser::Colon()
    {
    TBool colon( EFalse );
    SkipWhiteSpace();
    if ( iCurP < iEndP && *iCurP == KCodColon )
        {
        // OK it's a colon.
        colon = ETrue;
        iCurP++;
        }
    else
        {
        // Expected a colon.
        Error( KErrCodInvalidDescriptor );
        }
    SkipWhiteSpace();
    return colon;
    }
예제 #23
0
PRBool
nsNodeInfo::QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const
{
  NS_PRECONDITION(mInner.mPrefix, "Must have prefix");
  
  nsACString::const_iterator start;
  aQualifiedName.BeginReading(start);

  nsACString::const_iterator colon(start);

  const char* prefix;
  mInner.mPrefix->GetUTF8String(&prefix);

  PRUint32 len = strlen(prefix);

  if (len >= aQualifiedName.Length()) {
    return PR_FALSE;
  }

  colon.advance(len);

  // If the character at the prefix length index is not a colon,
  // aQualifiedName is not equal to this string.
  if (*colon != ':') {
    return PR_FALSE;
  }

  // Compare the prefix to the string from the start to the colon
  if (!mInner.mPrefix->EqualsUTF8(Substring(start, colon)))
    return PR_FALSE;

  ++colon; // Skip the ':'

  nsACString::const_iterator end;
  aQualifiedName.EndReading(end);

  // Compare the local name to the string between the colon and the
  // end of aQualifiedName
  return mInner.mName->EqualsUTF8(Substring(colon, end));
}
예제 #24
0
/*!
  Attempts to read a line and returns an LByteArray containing the line.
  This wraps around readOneLine and provides a hack to do additional unwrapping for a malformed
  vCard where a space is not added to the start of the line continuation.

  Some malformed vCards we get look like this: (Case 1)
  ORG:A
   B
  C
  (CRLF-SPACE wrapping is employed for the first time, then the space is subsequently omitted).
  But a valid vCard can be weirdly wrapped without the CRLF-SPACE, if it's quoted-printable and
  ends in an equals, eg. (Case 2)
  ORG;ENCODING=QUOTED-PRINTABLE:A=
  B=
  C
  Unwrap in Case 1 but not in Case 2 - leave that for the QP-decoder in QVR::unencode
  */
LByteArray LineReader::readLine()
{
    QByteArray colon(VersitUtils::encode(':', mCodec));
    QByteArray equals(VersitUtils::encode('=', mCodec));
    if (!mPushedLines.isEmpty()) {
        LByteArray retval(mPushedLines.pop());
        return retval;
    }
    readOneLine(&mBuffer);
    // Hack: read the next line and see if it's a continuation of this line
    while (true) {
        int prevStart = mBuffer.mStart;
        int prevEnd = mBuffer.mEnd;
        // readOneLine only appends to mBuffer so these saved offsets should remain valid
        readOneLine(&mBuffer);

        // Get an LByteArray of the previous line.  This should be fast because copying the
        // LByteArray copies the QByteArray, which is implicitly shared
        LByteArray prevLine(mBuffer.mData, prevStart, prevEnd);
        if (mBuffer.isEmpty()
                || mBuffer.contains(colon)
                || prevLine.endsWith(equals)) {
            // Normal, the next line is empty, or a new property, or it's been wrapped using
            // QUOTED-PRINTABLE.  Rewind it back one line so it gets read next time round.
            mBuffer.setBounds(prevStart, prevEnd);
            break;
        } else {
            // Some silly vCard generator has probably wrapped a line without prepending a space
            // Join the previous line with this line by deleting the characters between prevEnd and
            // mStart (eg. any newline characters)
            int crlfLen = mBuffer.mStart-prevEnd;
            mBuffer.mData.remove(prevEnd, crlfLen);
            mBuffer.setBounds(prevStart, mBuffer.mEnd - crlfLen);
        }
    }
    mBuffer.dropOldData();
    mOdometer += mBuffer.size();
    return mBuffer;
}
// The scalar cases in llsd_matches() use this helper. In most cases, we can
// accept not only the exact type specified in the prototype, but also other
// types convertible to the expected type. That implies looping over an array
// of such types. If the actual type doesn't match any of them, we want to
// provide a list of acceptable conversions as well as the exact type, e.g.:
// "Integer (or Boolean, Real, String) required instead of UUID". Both the
// implementation and the calling logic are simplified by separating out the
// expected type from the convertible types.
static std::string match_types(LLSD::Type expect, // prototype.type()
                               const TypeVector& accept, // types convertible to that type
                               LLSD::Type actual,        // type we're checking
                               const std::string& pfx)   // as for llsd_matches
{
    // Trivial case: if the actual type is exactly what we expect, we're good.
    if (actual == expect)
        return "";

    // For the rest of the logic, build up a suitable error string as we go so
    // we only have to make a single pass over the list of acceptable types.
    // If we detect success along the way, we'll simply discard the partial
    // error string.
    std::ostringstream out;
    out << colon(pfx) << sTypes.lookup(expect);

    // If there are any convertible types, append that list.
    if (! accept.empty())
    {
        out << " (";
        const char* sep = "or ";
        for (TypeVector::const_iterator ai(accept.begin()), aend(accept.end());
             ai != aend; ++ai, sep = ", ")
        {
            // Don't forget to return success if we match any of those types...
            if (actual == *ai)
                return "";
            out << sep << sTypes.lookup(*ai);
        }
        out << ')';
    }
    // If we got this far, it's because 'actual' was not one of the acceptable
    // types, so we must return an error. 'out' already contains colon(pfx)
    // and the formatted list of acceptable types, so just append the mismatch
    // phrase and the actual type.
    out << op << sTypes.lookup(actual);
    return out.str();
}
예제 #26
0
static void switch_block(void) {
	int	lb, ls, ldflt = 0;
	int	cval[MAXCASE];
	int	clab[MAXCASE];
	int	nc = 0;

	Token = scan();
	pushbrk(lb = label());
	ls = label();
	genjump(ls);
	while (RBRACE != Token) {
		if (eofcheck()) return;
		if ((CASE == Token || DEFAULT == Token) && nc >= MAXCASE) {
			error("too many 'case's in 'switch'", NULL);
			nc = 0;
		}
		if (CASE == Token) {
			Token = scan();
			cval[nc] = constexpr();
			genlab(clab[nc++] = label());
			colon();
		}
		else if (DEFAULT == Token) {
예제 #27
0
void ShowTime(int ShowAlways)
{
	static SYSTEMTIME lasttm={};

	if (ShowAlways==2)
	{
		ClearStruct(lasttm);
		return;
	}

	if (Global->ScreenSaverActive)
		return;

	SYSTEMTIME tm;
	matrix<FAR_CHAR_INFO> colon(1, 1);
	GetLocalTime(&tm);
	GetText(ScrX - 4 + 2, 0, ScrX - 4 + 2, 0, colon);
	if (!ShowAlways && lasttm.wMinute == tm.wMinute && lasttm.wHour == tm.wHour && colon[0][0].Char == L':')
		return;

	Global->ProcessShowClock++;

	lasttm=tm;
	string strClockText = str_printf(L"%02d:%02d",tm.wHour,tm.wMinute);
	GotoXY(ScrX-4,0);

	auto CurrentWindow = Global->WindowManager->GetCurrentWindow();
	if (CurrentWindow)
	{
		int ModType=CurrentWindow->GetType();
		SetColor(ModType==windowtype_viewer?COL_VIEWERCLOCK:(ModType==windowtype_editor?COL_EDITORCLOCK:COL_CLOCK));
		Text(strClockText);
	}

	Global->ProcessShowClock--;
}
예제 #28
0
파일: more.c 프로젝트: aalm/obsd-src
/*
 * Read a command and do it. A command consists of an optional integer
 * argument followed by the command character.  Return the number of lines
 * to display in the next screenful.  If there is nothing more to display
 * in the current file, zero is returned.
 */
int
command(char *filename, FILE *f)
{
	int nlines;
	int retval;
	int ch;
	char colonch;
	int done;
	char comchar, cmdbuf[80];

#define ret(val) retval=val;done++;break

	retval = done = 0;
	if (!errors)
		prompt(filename);
	else
		errors = 0;
	for (;;) {
		nlines = number(&comchar);
		lastp = colonch = 0;
		if (comchar == '.') {	/* Repeat last command */
			lastp++;
			comchar = lastcmd;
			nlines = lastarg;
			if (lastcmd == ':')
				colonch = lastcolon;
		}
		lastcmd = comchar;
		lastarg = nlines;
		if (comchar == otty.c_cc[VERASE]) {
			kill_line();
			prompt(filename);
			continue;
		}
		switch (comchar) {
		case ':':
			retval = colon(filename, colonch, nlines);
			if (retval >= 0)
				done++;
			break;
		case 'b':
		case ctrl('B'):
		    {
			int initline;

			if (no_intty) {
				write(STDERR_FILENO, &bell, 1);
				return (-1);
			}

			if (nlines == 0)
				nlines++;

			putchar('\r');
			erasep(0);
			putchar('\n');
			if (clreol)
				cleareol();
			printf("...back %d page", nlines);
			if (nlines > 1)
				fputs("s\n", stdout);
			else
				putchar('\n');

			if (clreol)
				cleareol();
			putchar('\n');

			initline = Currline - (off_t)dlines * (nlines + 1);
			if (!noscroll)
				--initline;
			if (initline < 0)
				initline = 0;
			Fseek(f, (off_t)0);
			Currline = 0; /* skiplns() will make Currline correct */
			skiplns(initline, f);
			ret(dlines);
		    }
		case ' ':
		case 'z':
			if (nlines == 0)
				nlines = dlines;
			else if (comchar == 'z')
				dlines = nlines;
			ret(nlines);
		case 'd':
		case ctrl('D'):
			if (nlines != 0)
				nscroll = nlines;
			ret(nscroll);
		case 'q':
		case 'Q':
			end_it();
		case 's':
		case 'f':
			if (nlines == 0)
				nlines++;
			if (comchar == 'f')
				nlines *= dlines;
			putchar('\r');
			erasep(0);
			putchar('\n');
			if (clreol)
				cleareol();
			printf("...skipping %d line", nlines);
			if (nlines > 1)
				fputs("s\n", stdout);
			else
				putchar('\n');

			if (clreol)
				cleareol();
			putchar('\n');

			while (nlines > 0) {
				while ((ch = Getc(f)) != '\n') {
					if (ch == EOF) {
						retval = 0;
						done++;
						goto endsw;
					}
				}
				Currline++;
				nlines--;
			}
			ret(dlines);
		case '\n':
			if (nlines != 0)
				dlines = nlines;
			else
				nlines = 1;
			ret(nlines);
		case '\f':
			if (!no_intty) {
				doclear();
				Fseek(f, screen_start.chrctr);
				Currline = screen_start.line;
				ret(dlines);
			} else {
				write(STDERR_FILENO, &bell, 1);
				break;
			}
		case '\'':
			if (!no_intty) {
				kill_line();
				fputs("\n***Back***\n\n", stdout);
				Fseek(f, context.chrctr);
				Currline = context.line;
				ret(dlines);
			} else {
				write(STDERR_FILENO, &bell, 1);
				break;
			}
		case '=':
			kill_line();
			promptlen = printf("%lld", (long long)Currline);
			fflush(stdout);
			break;
		case 'n':
			lastp++;
		case '/':
			if (nlines == 0)
				nlines++;
			kill_line();
			putchar('/');
			promptlen = 1;
			fflush(stdout);
			if (lastp) {
				/* Use previous r.e. */
				write(STDERR_FILENO, "\r", 1);
				if (search(NULL, f, nlines) < 0)
					break;
			} else {
				if (ttyin(cmdbuf, sizeof(cmdbuf) - 2, '/') < 0) {
					kill_line();
					prompt(filename);
					continue;
				}
				write(STDERR_FILENO, "\r", 1);
				if (search(cmdbuf, f, nlines) < 0)
					break;
			}
			ret(dlines-1);
		case '?':
		case 'h':
			if (noscroll)
				doclear();
			fputs(more_help, stdout);
			prompt(filename);
			break;
		default:
			if (dum_opt) {
				kill_line();
				if (Senter && Sexit) {
					tputs(Senter, 1, putch);
					fputs(DUM_ERROR, stdout);
					promptlen = sizeof(DUM_ERROR) - 1 +
					    (2 * soglitch);
					tputs(Sexit, 1, putch);
				} else {
					fputs(DUM_ERROR, stdout);
					promptlen = sizeof(DUM_ERROR) - 1;
				}
				fflush(stdout);
			} else
				write(STDERR_FILENO, &bell, 1);
			break;
		}
		if (done)
			break;
	}
	putchar('\r');
endsw:
	inwait = 0;
	notell++;
	return (retval);
}
예제 #29
0
void
toremote(char *targ, int argc, char *argv[])
{
	int i, tos;
	char *bp, *host, *src, *suser, *thost, *tuser;

	*targ++ = 0;
	if (*targ == 0)
		targ = period;

	if ((thost = strchr(argv[argc - 1], '@'))) {
		/* user@host */
		*thost++ = 0;
		tuser = argv[argc - 1];
		if (*tuser == '\0')
			tuser = NULL;
		else if (!okname(tuser))
			exit(1);
	} else {
		thost = argv[argc - 1];
		tuser = NULL;
	}

	for (i = 0; i < argc - 1; i++) {
		src = colon(argv[i]);
		if (src) {			/* remote to remote */
			*src++ = 0;
			if (*src == 0)
				src = period;
			host = strchr(argv[i], '@');
			if (host) {
				*host++ = 0;
				suser = argv[i];
				if (*suser == '\0')
					suser = pwd->pw_name;
				else if (!okname(suser)) {
					++errs;
					continue;
				}
				if (asprintf(&bp, 
				    "%s %s -l %s -n %s %s '%s%s%s:%s'",
				    _PATH_RSH, host, suser, cmd, src,
				    tuser ? tuser : "", tuser ? "@" : "",
				    thost, targ) == -1)
					err(1, "asprintf");
			} else
				if (asprintf(&bp,
				    "exec %s %s -n %s %s '%s%s%s:%s'",
				    _PATH_RSH, argv[i], cmd, src,
				    tuser ? tuser : "", tuser ? "@" : "",
				    thost, targ) == -1)
					err(1, "asprintf");
			(void)susystem(bp, userid);
			(void)free(bp);
		} else {			/* local to remote */
			if (rem == -1) {
				if (asprintf(&bp, "%s -t %s", cmd, targ)
					== -1)
					err(1, "asprintf");
				host = thost;
				rem = rcmd_af(&host, port,
				    pwd->pw_name,
				    tuser ? tuser : pwd->pw_name,
				    bp, 0, family);
				if (rem < 0)
					exit(1);
				if (family == PF_INET) {
					tos = IPTOS_THROUGHPUT;
					if (setsockopt(rem, IPPROTO_IP, IP_TOS,
					    &tos, sizeof(int)) < 0)
						warn("TOS (ignored)");
				}
				if (response() < 0)
					exit(1);
				(void)free(bp);
				(void)setuid(userid);
			}
			source(1, argv+i);
		}
	}
}
예제 #30
0
int
main(int argc, char *argv[])
{
	struct servent *sp;
	int ch, fflag, i, tflag;
	char *targ;

	/*
	 * Prepare for execing ourselves.
	 */
	argc_copy = argc + 1;
	argv_copy = malloc((argc_copy + 1) * sizeof(*argv_copy));
	if (argv_copy == NULL)
		err(1, "malloc");
	argv_copy[0] = argv[0];
	argv_copy[1] = "-K";
	for (i = 1; i < argc; ++i) {
		argv_copy[i + 1] = strdup(argv[i]);
		if (argv_copy[i + 1] == NULL)
			errx(1, "strdup: out of memory");
	}
	argv_copy[argc + 1] = NULL;

	fflag = tflag = 0;
	while ((ch = getopt(argc, argv, OPTIONS)) != -1)
		switch(ch) {			/* User-visible flags. */
		case '4':
			family = PF_INET;
			break;

		case '6':
			family = PF_INET6;
			break;

		case 'p':
			pflag = 1;
			break;
		case 'r':
			iamrecursive = 1;
			break;
						/* Server options. */
		case 'd':
			targetshouldbedirectory = 1;
			break;
		case 'f':			/* "from" */
			iamremote = 1;
			fflag = 1;
			break;
		case 't':			/* "to" */
			iamremote = 1;
			tflag = 1;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	sp = getservbyname("shell", "tcp");
	if (sp == NULL)
		errx(1, "shell/tcp: unknown service");
	port = sp->s_port;

	if ((pwd = getpwuid(userid = getuid())) == NULL)
		errx(1, "unknown user %d", (int)userid);

	rem = STDIN_FILENO;		/* XXX */

	if (fflag) {			/* Follow "protocol", send data. */
		(void)response();
		(void)setuid(userid);
		source(argc, argv);
		exit(errs);
	}

	if (tflag) {			/* Receive data. */
		(void)setuid(userid);
		sink(argc, argv);
		exit(errs);
	}

	if (argc < 2)
		usage();
	if (argc > 2)
		targetshouldbedirectory = 1;

	rem = -1;
	/* Command to be executed on remote system using "rsh". */
	(void)snprintf(cmd, sizeof(cmd), "rcp%s%s%s",
	    iamrecursive ? " -r" : "", pflag ? " -p" : "",
	    targetshouldbedirectory ? " -d" : "");

	(void)signal(SIGPIPE, lostconn);

	if ((targ = colon(argv[argc - 1])))	/* Dest is remote host. */
		toremote(targ, argc, argv);
	else {
		tolocal(argc, argv);		/* Dest is local host. */
		if (targetshouldbedirectory)
			verifydir(argv[argc - 1]);
	}
	exit(errs);
}