Пример #1
0
static void
unparsech(struct Strbuf *buf, Char ch)
{
    if (ch == 0) {
	Strbuf_append1(buf, '^');
	Strbuf_append1(buf, '@');
    }
    else if (Iscntrl(ch)) {
	Strbuf_append1(buf, '^');
	if (ch == CTL_ESC('\177'))
	    Strbuf_append1(buf, '?');
	else
#ifdef IS_ASCII
	    Strbuf_append1(buf, ch | 0100);
#else
	    Strbuf_append1(buf, _toebcdic[_toascii[ch]|0100]);
#endif
    }
    else if (ch == '^') {
	Strbuf_append1(buf, '\\');
	Strbuf_append1(buf, '^');
    } else if (ch == '\\') {
	Strbuf_append1(buf, '\\');
	Strbuf_append1(buf, '\\');
    } else if (ch == ' ' || (Isprint(ch) && !Isspace(ch))) {
	Strbuf_append1(buf, ch);
    }
    else {
	Strbuf_append1(buf, '\\');
	Strbuf_append1(buf, ((ch >> 6) & 7) + '0');
	Strbuf_append1(buf, ((ch >> 3) & 7) + '0');
	Strbuf_append1(buf, (ch & 7) + '0');
    }
}
Пример #2
0
int
main(int argc, char* argv[])
{
    char line[MAXLINE];

    /* Input lines should look like
       		key = "value",
       where key is one of: month, number, pages, volume, or
       year. Lines with any other key values are ignored. */

    line_number = 0L;
    while (fgets(line,MAXLINE,stdin) != (char*)NULL)
    {
        char *p;

        line_number++;

        p = strchr(line,'\0');
        if (p != (char *)NULL)
        {
            for (--p; Isspace((int)*p) || (*p == ','); --p)
                *p = '\0';	/* remove trailing whitespace and commas */
            for (p = line; Isspace((int)*p); ++p)
                continue;
            if (strncmp(p,"month",4) == 0)
                process(line,month_patterns);
            else if (strncmp(p,"number",6) == 0)
                process(line,number_patterns);
            else if (strncmp(p,"pages",4) == 0)
                process(line,pages_patterns);
            else if (strncmp(p,"volume",6) == 0)
                process(line,volume_patterns);
            else if (strncmp(p,"year",4) == 0)
                process(line,year_patterns);
            else
                printf("%%%% %ld [%-24s]: %s\n", line_number, line, "ignored");
        }
    }

    exit (EXIT_SUCCESS);
    return (EXIT_SUCCESS);
}
Пример #3
0
unsigned char *
unparsestring(const CStr *str, const Char *sep)
{
    unsigned char *buf, *b;
    Char   p;
    int l;

    /* Worst-case is "\uuu" or result of wctomb() for each char from str */
    buf = xmalloc((str->len + 1) * max(4, MB_LEN_MAX));
    b = buf;
    if (sep[0])
#ifndef WINNT_NATIVE
	*b++ = sep[0];
#else /* WINNT_NATIVE */
	*b++ = CHAR & sep[0];
#endif /* !WINNT_NATIVE */

    for (l = 0; l < str->len; l++) {
	p = str->buf[l];
	if (Iscntrl(p)) {
	    *b++ = '^';
	    if (p == CTL_ESC('\177'))
		*b++ = '?';
	    else
#ifdef IS_ASCII
		*b++ = (unsigned char) (p | 0100);
#else
		*b++ = _toebcdic[_toascii[p]|0100];
#endif
	}
	else if (p == '^' || p == '\\') {
	    *b++ = '\\';
	    *b++ = (unsigned char) p;
	}
	else if (p == ' ' || (Isprint(p) && !Isspace(p)))
	    b += one_wctomb((char *)b, p & CHAR);
	else {
	    *b++ = '\\';
	    *b++ = ((p >> 6) & 7) + '0';
	    *b++ = ((p >> 3) & 7) + '0';
	    *b++ = (p & 7) + '0';
	}
    }
    if (sep[0] && sep[1])
#ifndef WINNT_NATIVE
	*b++ = sep[1];
#else /* WINNT_NATIVE */
	*b++ = CHAR & sep[1];
#endif /* !WINNT_NATIVE */
    *b++ = 0;
    return buf;			/* should check for overflow */
}
Пример #4
0
/* tw_tok():
 *	Return the next word from string, unquoteing it.
 */
static Char *
tw_tok(Char *str)
{
    static Char *bf = NULL;

    if (str != NULL)
	bf = str;
    
    /* skip leading spaces */
    for (; *bf && Isspace(*bf); bf++)
	continue;

    for (str = bf; *bf && !Isspace(*bf); bf++) {
	if (ismetahash(*bf))
	    return INVPTR;
	*bf = *bf & ~QUOTE;
    }
    if (*bf != '\0')
	*bf++ = '\0';

    return *str ? str : NULL;
} /* end tw_tok */
Пример #5
0
static const char *
next_s(const char *s)
{
    /* find next position in s, ignoring braces and ignoring TeX control
       sequences and any space that follows them */
    for (++s; (*s != '\0'); )
    {
        switch (*s)
        {
        case '\\':			/* TeX control sequence */
            ++s;			/* look at next character */
            if (Isalpha((int)*s))		/* \<one-or-more-letters> */
            {
                while (Isalpha((int)*s))
                    ++s;
            }
            else			/* \<non-letter> */
                ++s;
            while (Isspace((int)*s))		/* advance over trailing whitespace */
                ++s;			/* since TeX does too */
            break;

        case '{':
        case '}':
            ++s;
            break;

        case BIBTEX_HIDDEN_DELIMITER:	/* ignore delimited inline comment */
            for (++s; (*s != '\0'); ++s)
            {
                if (*s == BIBTEX_HIDDEN_DELIMITER)
                {
                    ++s;
                    break;
                }
            }
            break;

        default:
            return (s);
        }				/* end switch */
    }					/* end for */
    return (s);
}
Пример #6
0
/* tw_pr():
 *	Pretty print a completion, adding single quotes around 
 *	a completion argument and collapsing multiple spaces to one.
 */
static void
tw_pr(Char **cmp)
{
    int sp, osp;
    Char *ptr;

    for (; *cmp; cmp++) {
	xputchar('\'');
	for (osp = 0, ptr = *cmp; *ptr; ptr++) {
	    sp = Isspace(*ptr);
	    if (sp && osp)
		continue;
	    xputwchar(*ptr);
	    osp = sp;
	}
	xputchar('\'');
	if (cmp[1])
	    xputchar(' ');
    }
} /* end tw_pr */
Пример #7
0
YESorNO
match_pattern(const char *s, const char *pattern)
{
    const char *org_s;
    const char *org_pattern;

    org_s = s;
    org_pattern = pattern;

    s = next_s(s-1);
    for ( ; (*pattern != '\0'); ++pattern)
    {
        switch(*pattern)
        {
        case 'a':			/* single letter */
            if (!Isalpha((int)*s))
                RETURN_MATCH_FAILURE("single letter");
            s = next_s(s);
            break;

        case 'A':			/* one or more letters */
            if (!Isalpha((int)*s))
                RETURN_MATCH_FAILURE("one or more letters");
            while (Isalpha((int)*s))
                s = next_s(s);
            break;

        case 'd':
            if (!Isdigit((int)*s))	/* single digit */
                RETURN_MATCH_FAILURE("single digit");
            s = next_s(s);
            break;

        case 'D':			/* one or more digits */
            if (!Isdigit((int)*s))
                RETURN_MATCH_FAILURE("one or more digits");
            while (Isdigit((int)*s))
                s = next_s(s);
            break;

        case 'r':			/* single roman numeral */
            if (!is_roman((int)*s))
                RETURN_MATCH_FAILURE("single roman numeral");
            s = next_s(s);
            break;

        case 'R':			/* one or more roman numerals */
            if (!is_roman((int)*s))
                RETURN_MATCH_FAILURE("one or more roman numerals");
            while (is_roman((int)*s))
                s = next_s(s);
            break;

        case 'w':			/* one word (letters and digits) */
            if (!Isalnum((int)*s))
                RETURN_MATCH_FAILURE("one word (letters and digits)");
            while (Isalnum((int)*s))
                s = next_s(s);
            break;

        case 'W':			/* one or more space-separated words */
            if (!Isalnum((int)*s))
                RETURN_MATCH_FAILURE("one or more space-separated words");
            while (Isalnum((int)*s))		/* parse first word */
                s = next_s(s);
            for (;;)
            {
                if (!Isspace((int)*s))
                    break;
                while (Isspace((int)*s))	/* parse separators */
                    s = next_s(s);
                while (Isalnum((int)*s))	/* parse another word */
                    s = next_s(s);
            }
            break;

        case 'X':		/* one or more special-separated words */
            if (!Isalnum((int)*s))
                RETURN_MATCH_FAILURE("one or more special-separated words");
            while (Isalnum((int)*s))		/* parse first word */
                s = next_s(s);
            for (;;)
            {
                if (!is_special(*s))
                    break;
                while (is_special(*s))	/* parse separators */
                    s = next_s(s);
                while (Isalnum((int)*s))	/* parse another word */
                    s = next_s(s);
            }
            break;

        case ' ':			/* one or more whitespace characters */
            if (!Isspace((int)*s))
                RETURN_MATCH_FAILURE("one or more whitespace characters");
            while (Isspace((int)*s))
                s = next_s(s);
            break;

        case '.':			/* exactly one special character */
            if (!is_special(*s))
                RETURN_MATCH_FAILURE("exactly one special character");
            s = next_s(s);		/* [07-Mar-1999] bug fix: missing before bibclean 2.12 */
            break;

        case ':':			/* one or more special characters */
            if (!is_special(*s))
                RETURN_MATCH_FAILURE("one or more special characters");
            while (is_special(*s))
                s = next_s(s);
            break;

        case '\\':			/* literal next character */
            pattern++;
            /* fall through to exact match test */
            /*@fallthrough@*/ /*FALLTHROUGH*/

        default:			/* anything else: exact match */
            if (*pattern != *s)
                RETURN_MATCH_FAILURE("anything else: exact match");
            s = next_s(s);
        }				/* end switch */
    }					/* end for (; ;) */
    if (*s == '\0')
        return (YES);
    else
        RETURN_MATCH_FAILURE("end of string");
}
Пример #8
0
int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
{
    char **p;
    char *buf;
    char *c, *d;
    const char *s;
    int pre;
    unsigned spaces;
    int allow = 0;

    /*
        pre == 1 means that the previous character is a white space
        pre == 0 means that the previous character is not a white space
    */
    buf = xmalloc(strlen(cmd) + 1);
    strcpy(buf, cmd);
    c = buf;
    while (Isspace(*c))
        c++;
    d = c;
    while (!Isspace(*d) && *d)
        d++;
    *d = '\0';

    /*
        *cmdname is the first word of the command line. For example, *cmdname ==
        "kpsewhich" for:

        \write18{kpsewhich --progname=dvipdfm --format="other text files" config}
    */
    *cmdname = xstrdup(c);
    free(buf);

    /*
        Is *cmdname listed in a texmf.cnf vriable as shell_escape_commands =
        foo,bar,... ?
    */
    p = cmdlist;
    if (p) {
        while (*p) {
            if (strcmp(*p, *cmdname) == 0) {
                /*
                    *cmdname is found in the list, so restricted shell escape is
                    allowed
                */
                allow = 2;
                break;
            }
            p++;
        }
    }
    if (allow == 2) {
        spaces = 0;
        for (s = cmd; *s; s++) {
            if (Isspace(*s))
                spaces++;
        }

        /* allocate enough memory (too much?) */
#  ifdef WIN32
        *safecmd = xmalloc(2 * strlen(cmd) + 3 + 2 * spaces);
#  else
        *safecmd = xmalloc(strlen(cmd) + 3 + 2 * spaces);
#  endif

        /* make a safe command line *safecmd */
        s = cmd;
        while (Isspace(*s))
            s++;
        d = *safecmd;
        while (!Isspace(*s) && *s)
            *d++ = *s++;

        pre = 1;
        while (*s) {
            /*
                Quotation given by a user. " should always be used; we transform
                it below. On Unix, if ' is used, simply immediately return a
                quotation error.
            */
            if (*s == '\'') {
                return -1;
            }

            if (*s == '"') {
                /*
                    All arguments are quoted as 'foo' (Unix) or "foo" (Windows)
                    before calling system(). Therefore closing QUOTE is necessary
                    if the previous character is not a white space. For example:

                    --format="other text files" becomes
                    '--format=''other text files' (Unix)
                    "--format"="other text files" (Windows)
                */
                if (pre == 0) {
#  ifdef WIN32
                    if (*(s-1) == '=') {
                        *(d-1) = QUOTE;
                        *d++ = '=';
                    } else {
                      *d++ = QUOTE;
                    }
#  else
                    *d++ = QUOTE;
#  endif
                }
                pre = 0;
                /*
                    Output the quotation mark for the quoted argument.
                */
                *d++ = QUOTE;
                s++;

                while (*s != '"') {
                    /*
                        Illegal use of ', or closing quotation mark is missing
                    */
                    if (*s == '\'' || *s == '\0')
                        return -1;
#  if 0
#  ifdef WIN32
                    if (char_needs_quote(*s))
                        *d++ = '^';
#  endif
#  endif
                    *d++ = *s++;
                }
                /*
                    Closing quotation mark will be output afterwards, so we do
                    nothing here.
                */
                s++;
                /*
                    The character after the closing quotation mark should be a
                    white space or NULL.
                */
                if (!Isspace(*s) && *s)
                    return -1;
                /*
                    Beginning of a usual argument.
                */
            } else if (pre == 1 && !Isspace(*s)) {
                pre = 0;
                *d++ = QUOTE;
#  if 0
#  ifdef WIN32
                if (char_needs_quote(*s))
                    *d++ = '^';
#  endif
#  endif
                *d++ = *s++;
                /*
                    Ending of a usual argument.
                */
            } else if (pre == 0 && Isspace(*s)) {
                pre = 1;
                /* Closing quotation mark */
                *d++ = QUOTE;
                *d++ = *s++;
            } else {
                /*
                   Copy a character from cmd to *safecmd.
                */
#  if 0
#  ifdef WIN32
                if (char_needs_quote(*s))
                    *d++ = '^';
#  endif
#  endif
                *d++ = *s++;
            }
        }
        /*
            End of the command line.
        */
        if (pre == 0) {
            *d++ = QUOTE;
        }
        *d = '\0';
#ifdef WIN32
        {
          char *p, *q, *r;
          p = *safecmd;
          if (strlen (p) > 2 && p[1] == ':' && !IS_DIR_SEP (p[2])) {
              q = xmalloc (strlen (p) + 2);
              q[0] = p[0];
              q[1] = p[1];
              q[2] = '/';
              q[3] = '\0';
              strcat (q, (p + 2));
              free (*safecmd);
              *safecmd = q;
          } else if (!IS_DIR_SEP (p[0]) && !(p[1] == ':' && IS_DIR_SEP (p[2]))) {
            p = kpse_var_value ("SELFAUTOLOC");
            if (p) {
                r = *safecmd;
                while (*r && !Isspace(*r))
                    r++;
                if (*r == '\0')
                    q = concatn ("\"", p, "/", *safecmd, "\"", NULL);
                else {
                    *r = '\0';
                    r++;
                    while (*r && Isspace(*r))
                        r++;
                    if (*r)
                        q = concatn ("\"", p, "/", *safecmd, "\" ", r, NULL);
                    else
                        q = concatn ("\"", p, "/", *safecmd, "\"", NULL);
                }
                free (p);
                free (*safecmd);
                *safecmd = q;
            }
          }
        }
#endif
    }
    return allow;
}
Пример #9
0
void
do_ISBN_file(/*@null@*/ const char *pathlist, /*@null@*/ const char *name)
{
    FILE *fp;
    char *p;

    if (name == (const char*)NULL)
	return;

    if ((ISBN_file = findfile(pathlist,name)) == (char*)NULL)
	return;				/* silently ignore missing files */

    if ((fp = tfopen(ISBN_file,"r")) == (FILE*)NULL)
	return;				/* silently ignore missing files */

    /* The ISBN file is expected to look like the output of
       -print-ISBN-table: lines are (1) blank or empty, (2) comments
       from percent to end-of-line, (3) pairs of whitespace-separated
       (begin-prefix, end-prefix) values, or (4) triples of
       whitespace-separated (begin-prefix, end-prefix values, countries).
       In the latter case, the countries continue to end-of-line or a
       comment character, whichever comes first, and may include
       blanks. */
    while ((p = get_line(fp)) != (char*)NULL)
    {
	const char *the_begin;
	const char *the_end;
	const char *the_countries;
	char *comment;

	comment = strchr(p, BIBTEX_COMMENT_PREFIX);
	if (comment != (const char*)NULL)
	    *comment = '\0';		/* then discard comment text */

	the_begin = strtok(p, TOKEN_SEPARATORS);
	if (the_begin == (const char*)NULL)
	    continue;			/* ignore blank or empty lines */
	if (*the_begin == (char)BIBTEX_COMMENT_PREFIX)
	    continue;			/* ignore comment lines */
	the_end = strtok((char*)NULL, TOKEN_SEPARATORS);
	if (the_end == (const char*)NULL)
	{
	    fprintf(stdlog,"Expected end-prefix after begin-prefix [%s] in ISBN file [%s]\n",
			  the_begin, ISBN_file);
	    continue;
	}
	the_countries = strtok((char*)NULL, "");
	if (the_countries != (const char*)NULL)
	{				/* skip over leading space */
	    while (Isspace((int)*the_countries))
		++the_countries;
	}
	if ((the_countries != (const char*)NULL) && (*the_countries == '\0'))
	    the_countries = (const char*)NULL;
#if defined(DEBUG)
	fprintf(stdlog,
		      "DEBUG:\t[%s]\t[%s]\t[%s]\t[%s]\n",
		      ISBN_file,
		      the_begin,
		      the_end,
		      ((the_countries == (const char*)NULL) ? "" : the_countries));
#endif
	add_ISBN_range(the_begin, the_end, the_countries);
    }
    (void)fclose(fp);
}
Пример #10
0
Файл: chat.c Проект: wyat/kbs
static int ent_chat(int chatnum)
{                               /* 进入聊天室 */
    chatcontext *pthis;
    char inbuf[128];
    int ch, cmdpos;
    int currchar;
    int modified;               /* the line is modified? -- wwj */
    int newmail;
    int page_pending = false;
    int chatting = true;
#ifdef NEW_HELP
    int oldhelpmode=helpmode;
#endif

    if (!strcmp(getCurrentUser()->userid, "guest"))
        return -1;
    pthis = (chatcontext *) malloc(sizeof(chatcontext));
    bzero(pthis, sizeof(chatcontext));
    if (!pthis)
        return -1;
    modify_user_mode(CHAT1);
    ch = ent_chat_conn(pthis, chatnum);
    if (ch != 1) {
        free(pthis);
        return ch;
    }
#ifdef NEW_HELP
    helpmode=HELP_CHAT;
#endif
    add_io(pthis->cfd, 0);
    modified = newmail = cmdpos = currchar = 0;
    /* update uinfo */
    uinfo.in_chat = true;
    strcpy(uinfo.chatid, pthis->chatid);
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP_STR(chatid, uinfo);
    /* initiate screen */
    clear();
    pthis->chatline = 2;
    move(s_lines, 0);
    outs(msg_seperator);
    move(1, 0);
    outs(msg_seperator);
    print_chatid(pthis);
    memset(inbuf, 0, 80);
    /* chat begin */
    while (chatting) {
        if (chat_checkparse(pthis) == 0)
            break;
        move(b_lines, currchar + 10);
        pthis->outputcount = 0;
        ch = igetkey();
        if (ch==KEY_TALK) {
            int talkpage = servicepage(0, pthis->buf);

            if (talkpage != page_pending) {
                bell();
                oflush();
                printchatline(pthis, pthis->buf);
                page_pending = talkpage;
            }
        }
        if (chat_checkparse(pthis) == 0)
            break;
        if (ch == I_OTHERDATA)
            continue;
        switch (ch) {
            case KEY_UP:
            case KEY_DOWN:
                if (cmdpos == pthis->cmdpos) {
                    strcpy(pthis->lastcmd[cmdpos], inbuf);
                    modified = 0;
                }
                if (ch == KEY_UP) {
                    if (cmdpos != (pthis->cmdpos + 1) % MAXLASTCMD) {
                        int i = (cmdpos + MAXLASTCMD - 1) % MAXLASTCMD;

                        if (pthis->lastcmd[i][0])
                            cmdpos = i;
                    }
                }
                if (ch == KEY_DOWN) {
                    if (cmdpos != pthis->cmdpos)
                        cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                strcpy(inbuf, pthis->lastcmd[cmdpos]);
                if (cmdpos == pthis->cmdpos) {
                    modified = 1;
                }
                move(b_lines, 10);
                clrtoeol();
                ch = inbuf[69];
                inbuf[69] = 0;
                outs(inbuf);
                inbuf[69] = ch;
                currchar = strlen(inbuf);
                continue;
#ifdef CHINESE_CHARACTER
            case Ctrl('R'):
                SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR);
                continue;
#endif
            case KEY_LEFT:
                if (currchar)
                    --currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        currchar--;
                    }
                }
#endif
                continue;
            case KEY_RIGHT:
                if (inbuf[currchar])
                    ++currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        if (inbuf[currchar])
                            ++currchar;
                    }
                }
#endif
                continue;
            case KEY_ESC:
            case Ctrl('X'):
                inbuf[0] = 0;
                currchar = 0;
                move(b_lines, currchar + 10);
                clrtoeol();
                modified = 1;
                continue;
            case Ctrl('A'):
                currchar = 0;
                continue;
            case Ctrl('E'):
                currchar = strlen(inbuf);
                continue;
        }
        if (!newmail && chkmail(0)) {   /* check mail */
            newmail = 1;
            printchatline(pthis, "\033[32m*** \033[31m当!你有新信来啦...\033[m");
        }
        if (isprint2(ch)) {
            if (currchar < 126) {       /* 未满一行,print it */
                modified = 1;
                if (inbuf[currchar]) {  /* insert */
                    int i;

                    for (i = currchar; inbuf[i] && i < 127; i++);
                    inbuf[i + 1] = '\0';
                    for (; i > currchar; i--)
                        inbuf[i] = inbuf[i - 1];
                } else {        /* append */
                    inbuf[currchar + 1] = '\0';
                }
                inbuf[currchar] = ch;
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                move(b_lines, currchar + 10);
                outs(&inbuf[currchar++]);
                inbuf[69] = ch;
            }
            continue;
        }
        if (ch == '\n' || ch == '\r') {
            if (currchar) {
                if (modified) {
                    /* add to command history */
                    ch = sizeof(pthis->lastcmd[pthis->cmdpos]) - 1;
                    strncpy(pthis->lastcmd[pthis->cmdpos], inbuf, ch);
                    pthis->lastcmd[pthis->cmdpos][ch] = 0;
                    pthis->cmdpos = (pthis->cmdpos + 1) % MAXLASTCMD;
                    cmdpos = pthis->cmdpos;
                } else {        /* use history, so can +1 */
                    cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                if (inbuf[0] == '/' && Isspace(inbuf[1])) {     /* discard / b */
                    printchatline(pthis,
                                  "\x1b[37m*** \x1b[32m请输入正确的指令,使用/h寻求帮助\x1b[37m ***\x1b[m");
                } else {
                    chatting = chat_cmd(pthis, inbuf);  /*local命令处理 */
                    if (chatting == 0)
                        chatting = chat_send(pthis, inbuf);
                    if (inbuf[0] == '/') {
                        ch = 1;
                        while (inbuf[ch] != '\0' && inbuf[ch] != ' ')
                            ch++;
                        if (ch > 1) {
                            if (!strncasecmp(inbuf, "/bye", ch))
                                break;
                            if (!strncasecmp(inbuf, "/exit", ch))
                                break;  /*added by alex, 96.9.5 */
                        }
                    }
                }
                modified = 0;
                inbuf[0] = '\0';
                currchar = 0;
                move(b_lines, 10);
                clrtoeol();
            }
            continue;
        }
        if (ch == Ctrl('H') || ch == '\177') {  /*Backspace */
            if (currchar) {
                currchar--;
                inbuf[127] = '\0';
                memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                       127 - currchar);
                move(b_lines, currchar + 10);
                clrtoeol();
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                outs(&inbuf[currchar]);
                inbuf[69] = ch;
            }
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0;i<currchar;i++)
                    if (j) j=0;
                    else if (inbuf[i]<0) j=1;
                if (j) {
                    currchar--;
                    inbuf[127] = '\0';
                    memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                           127 - currchar);
                    move(b_lines, currchar + 10);
                    clrtoeol();
                    ch = inbuf[69]; /* save the end of line */
                    inbuf[69] = 0;
                    outs(&inbuf[currchar]);
                    inbuf[69] = ch;
                }
            }
#endif
            continue;
        }
        if (ch == Ctrl('Z')) {
            r_lastmsg();        /* Leeward 98.07.30 support msgX */
            inbuf[0] = '\0';
            currchar = 0;
            move(b_lines, 10);
            clrtoeol();
            continue;
        }
        if (ch == Ctrl('C') /*|| ch == Ctrl('D') */) {  /* ^C 退出 */
            chat_send(pthis, "/b");
            if (pthis->rec)
                set_rec(pthis,NULL);
            break;
        }
    }
    /* chat end */
    if (pthis->rec)set_rec(pthis,NULL);
    close(pthis->cfd);
    add_io(0, 0);
    uinfo.in_chat = false;
    uinfo.chatid[0] = '\0';
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP(chatid[0], uinfo);
    clear();
    free(pthis);
#ifdef NEW_HELP
    helpmode=oldhelpmode;
#endif
    return 0;
}
Пример #11
0
static int
do_search(FILE *fpout, int code, int line_number, int pause_after, const char *lines[])
{
    int c;
    int k;
    int last_line_number = line_number;

    /*@-modobserver@*/
    static char search_string[80] = ""; /* preserved across calls */

    (void)fputs((code == KEYBOARD_SEARCH_BACKWARD) ?
		"Search backward: " :
		"Search forward: ",fpout);
    (void)fflush(fpout);
    for (k = 0; ;)
    {
	c = kbget();
	if ((c == CH_NUL) || (c == CH_ESCAPE) ||
	    (c == (int)'\r') || (c == (int)'\n'))
	    break;		/* here's the loop exit */
	else if ((c == CH_BACKSPACE) || (c == CH_DELETE))
	{
	    erase_characters(fpout,1);
	    if (k > 0)
		k--;
	    search_string[k] = '\0';
	}
	else if (c == CH_LINE_KILL)	/* erase entire search string */
	{
	    erase_characters(fpout,k);
	    k = 0;
	    search_string[k] = '\0';
	}
	else if (c == CH_REPRINT)	/* reprint entire search string */
	{
	    int m;

	    erase_characters(fpout,k);
	    for (m = 0; m < k; ++m)
		(void)fputc((int)search_string[m],fpout);
	    (void)fflush(fpout);
	}
	else if (c == CH_WORD_ERASE)	/* erase last non-blank word */
	{
	    YESorNO saw_word;

	    saw_word = NO;
	    for (--k ; k >= 0; --k)
	    {
		if (Isspace(search_string[k]) && (saw_word == YES))
		{
		    k++;	/* so that we keep this space */
		    break;
		}
		if (!Isspace(search_string[k]))
		    saw_word = YES;
		erase_characters(fpout,1);
	    }
	    if (k < 0)
		k = 0;
	    search_string[k] = '\0';
	    (void)fflush(fpout);
	}
	else if (k < ((int)sizeof(search_string) - 1))
	{
	    search_string[k++] = (char)c;
	    (void)fputc(c,fpout);	/* echo input character */
	    (void)fflush(fpout);
	}
	else			/* search string too long: beep at user */
	    beep(fpout);
    }
    if (k > 0)			/* got new search string */
	search_string[k] = '\0';
    else			/* re-use last search string */
    {
	(void)fputs(search_string,fpout);
	(void)fputc('\r',fpout);
	(void)fputc('\n',fpout);
	(void)fflush(fpout);
    }
    (void)fputc('\r',fpout);

    for (k = (int)(strlen("Search backward: ") + strlen(search_string));
	 (k > 0); --k)
	(void)fputc(' ',fpout);	/* erase the search line */
    (void)fputc('\r',fpout);

    (void)fflush(fpout);

#if defined(DEBUG)
    (void)sleep(1);		/* DEBUG delay */
#endif

    if (code == KEYBOARD_SEARCH_BACKWARD)
	line_number = MAX(0,line_number - pause_after);
    else
	line_number++;
    while ((line_number >= 0) &&
	   (lines[line_number] != (const char*)NULL))
    {
	if (stristr(lines[line_number],search_string) != (char*)NULL)
	    break;
	else if (code == KEYBOARD_SEARCH_BACKWARD)
	    line_number--;
	else
	    line_number++;
    }
    if ((line_number < 0) || (lines[line_number] == (const char*)NULL))
    {				/* then search failed */
	beep(fpout);
	line_number = MAX(0,last_line_number + 1 - pause_after);
    }
    return (line_number);
}
Пример #12
0
double strtod 
    (
    const char * s,	/* string to convert */
    char **      endptr	/* ptr to final string */
    )
    {
    /* Note that the point positioning is locale dependant */
    const char *start     = s;
    double      accum     = 0.0;
    int         flags     = 0;
    int         texp      = 0;
    int         e         = 0;
    BOOL        conv_done = FALSE;

    while (Isspace (*s)) s++;
    if (*s == EOS)
	{   /* just leading spaces */
	if (endptr != NULL) 
	    *endptr = CHAR_FROM_CONST (start);

	return (0.0);
	}

    if (Issign (*s))
	{
	if (*s == '-') flags = SIGN;

	if (*++s == EOS)
	    {   /* "+|-" : should be an error ? */
	    if (endptr != NULL) 
		*endptr = CHAR_FROM_CONST (start);

	    return (0.0);
	    }
	}

    /* added code to fix problem with leading e, E, d, or D */

    if ( !Isdigit (*s) && (*s != '.'))
	{
	if (endptr != NULL)
	    *endptr = CHAR_FROM_CONST (start);

	return (0.0);
	}


    for ( ; (Isdigit (*s) || (*s == '.')); s++)
	{
	conv_done = TRUE;

	if (*s == '.')
	    flags |= DECP;
	else
	    {
	    if ( __ten_mul (&accum, Val(*s)) ) 
		texp++;
	    if (flags & DECP) 
		texp--;
	    }
	}

    if (Ise (*s))
	{
	conv_done = TRUE;

	if (*++s != EOS)             /* skip e|E|d|D */
	    {                         /* ! ([s]xxx[.[yyy]]e)  */

	    while (Isspace (*s)) s++; /* Ansi allows spaces after e */
	    if (*s != EOS)
		{                     /*  ! ([s]xxx[.[yyy]]e[space])  */
		if (Issign (*s))
		    if (*s++ == '-') flags |= ESIGN;

		if (*s != EOS)
                                      /*  ! ([s]xxx[.[yyy]]e[s])  -- error?? */
		    {                
		    for(; Isdigit (*s); s++)
                                      /* prevent from grossly overflowing */
			if (e < MAXE) 
			    e = e*10 + Val (*s);

		                      /* dont care what comes after this */
		    if (flags & ESIGN)
			texp -= e;
		    else
			texp += e;
		    }
		}
	    }
	}

    if (endptr != NULL)
	*endptr = CHAR_FROM_CONST ((conv_done) ? s : start);

    return (__adjust (&accum, (int) texp, (int) (flags & SIGN)));
    }