示例#1
0
void print_escaped_for_html_keywords(FILE * f, const char * str)
{
    /* generate HTML links */

    /* HTML link only for second keyword */
    if (st->n_keys > 1 &&
        strcmp(st->module_info.keywords[1], str) == 0) {
    
        const char *s;
        
        /* TODO: fprintf(f, _("topic: ")); */
        fprintf(f, "<a href=\"topic_");
        for (s = str; *s; s++) {
            switch (*s) {
                do_escape(' ', "_");
            default:
                fputc(*s, f);
            }
        }
        fprintf(f, ".html\">%s</a>", str);
    }
    else { /* first and other than second keyword */
         if (st->n_keys > 0 &&
             strcmp(st->module_info.keywords[0], str) == 0) {
             /* command family */
             const char *s;

             fprintf(f, "<a href=\"");
             for (s = str; *s; s++) {
                 switch (*s) {
                     do_escape(' ', "_");
                 default:
                     fputc(*s, f);
                 }
             }
             fprintf(f, ".html\">%s</a>", str);
         } else {
             /* keyword index */
             if (st->n_keys > 0 &&
                strcmp(st->module_info.keywords[2], str) == 0) {

                /* TODO: fprintf(f, _("keywords: ")); */
                fprintf(f, "<a href=\"keywords.html#%s\">%s</a>", str, str);
             } else {
                fprintf(f, "<a href=\"keywords.html#%s\">%s</a>", str, str);
             }
         }
    }
}
示例#2
0
static void print_escaped_for_html(FILE * f, const char *str)
{
    const char *s;

    for (s = str; *s; s++) {
	switch (*s) {
	    do_escape('&', "&amp;");
	    do_escape('<', "&lt;");
	    do_escape('>', "&gt;");
	    do_escape('\n', "<br>");
	default:
	    fputc(*s, f);
	}
    }
}
示例#3
0
文件: console.c 项目: Jimx-/lyos
/*****************************************************************************
 *                     parse_escape
 *****************************************************************************/
PRIVATE void	parse_escape(CONSOLE * con, char c)
{

	switch (con->c_esc_state){
		case 1:
		con->c_esc_intro = '\0';
		con->c_esc_paramp = bufend(con->c_esc_params);
		do {
			*--con->c_esc_paramp = 0;
		} while (con->c_esc_paramp > con->c_esc_params);
		switch (c) {
			case '[':	/* Control Sequence Introducer */
				con->c_esc_intro = c;
				con->c_esc_state = 2;
				break;
			case 'M':	/* Reverse Index */
				do_escape(con, c);
				break;
			default:
				con->c_esc_state = 0;
		}
		break;

		case 2:
		if (c >= '0' && c <= '9') {
			if (con->c_esc_paramp < bufend(con->c_esc_params))
				*con->c_esc_paramp = *con->c_esc_paramp * 10 + (c-'0');
		} else
		if (c == ';') {
			if (con->c_esc_paramp < bufend(con->c_esc_params))
				con->c_esc_paramp++;
		} else {
			do_escape(con, c);
		}
		break;
	}
}
示例#4
0
static PyObject *
plissken__generic_escape(houdini_cb do_escape,PyObject *args)
{
    const char *str;
    gh_buf buf = GH_BUF_INIT;

    if (!PyArg_ParseTuple(args, "s", &str))
        return NULL;

    if (do_escape(&buf, (const uint8_t *)str, sizeof(str))) {
        PyObject *result = Py_BuildValue("s",buf.ptr);
        return result;
    }

    return Py_BuildValue("s",str);
}
示例#5
0
文件: args.hpp 项目: xaizek/dit
    bool operator()(InputIterator &next, InputIterator end, Token &tok)
    {
        bool bInQuote = false;
        tok = Token();

        if (next == end) {
            return false;
        }
        while (next != end) {
            if (is_escape(*next)) {
                do_escape(next, end, tok);
            } else if (is_c(*next)) {
                if (!bInQuote) {
                    do {
                        ++next;
                    } while (next != end && is_c(*next));

                    if (tok.empty()) {
                        if (next == end) {
                            return false;
                        }
                        continue;
                    }

                    return true;
                } else {
                    tok += *next;
                }
            } else if (is_quote(*next)) {
                bInQuote = !bInQuote;
            } else {
                tok += *next;
            }

            ++next;
        }
        if (bInQuote) {
            throw boost::escaped_list_error(
                std::string("incomplete quoted argument")
            );
        }
        return true;
    }
示例#6
0
    bool operator()(InputIterator& next,InputIterator end,Token& tok) {
      bool bInQuote = false;
      tok = Token();

      if (next == end) {
        if (last_) {
          last_ = false;
          return true;
        }
        else
          return false;
      }
      last_ = false;
      for (;next != end;++next) {
        if (is_escape(*next)) {
          do_escape(next,end,tok);
        }
        else if (is_c(*next)) {
          if (!bInQuote) {
            // If we are not in quote, then we are done
            ++next;
            // The last character was a c, that means there is
            // 1 more blank field
            last_ = true; 
            return true;
          }
          else tok+=*next;
        }
        else if (is_quote(*next)) {
          bInQuote=!bInQuote;
        }
        else {
          tok += *next;
        }
      }
      return true;
    }
示例#7
0
文件: parser.c 项目: Pyjoneer/Aquila
size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
{
  size_t pos = 0;
  const char *string_start;

  switch(vt->parser.state) {
  case NORMAL:
  case CSI_LEADER:
  case CSI_ARGS:
  case CSI_INTERMED:
  case ESC:
    string_start = NULL;
    break;
  case STRING:
  case ESC_IN_STRING:
    string_start = bytes;
    break;
  }

#define ENTER_STRING_STATE(st) do { vt->parser.state = STRING; string_start = bytes + pos + 1; } while(0)
#define ENTER_STATE(st)        do { vt->parser.state = st; string_start = NULL; } while(0)
#define ENTER_NORMAL_STATE()   ENTER_STATE(NORMAL)

  for( ; pos < len; pos++) {
    unsigned char c = bytes[pos];

    if(c == 0x00 || c == 0x7f) { // NUL, DEL
      if(vt->parser.state >= STRING) {
        more_string(vt, string_start, bytes + pos - string_start);
        string_start = bytes + pos + 1;
      }
      continue;
    }
    if(c == 0x18 || c == 0x1a) { // CAN, SUB
      ENTER_NORMAL_STATE();
      continue;
    }
    else if(c == 0x1b) { // ESC
      vt->parser.intermedlen = 0;
      if(vt->parser.state == STRING)
        vt->parser.state = ESC_IN_STRING;
      else
        ENTER_STATE(ESC);
      continue;
    }
    else if(c == 0x07 &&  // BEL, can stand for ST in OSC or DCS state
            vt->parser.state == STRING) {
      // fallthrough
    }
    else if(c < 0x20) { // other C0
      if(vt->parser.state >= STRING)
        more_string(vt, string_start, bytes + pos - string_start);
      do_control(vt, c);
      if(vt->parser.state >= STRING)
        string_start = bytes + pos + 1;
      continue;
    }
    // else fallthrough

    switch(vt->parser.state) {
    case ESC_IN_STRING:
      if(c == 0x5c) { // ST
        vt->parser.state = STRING;
        done_string(vt, string_start, bytes + pos - string_start - 1);
        ENTER_NORMAL_STATE();
        break;
      }
      vt->parser.state = ESC;
      // else fallthrough

    case ESC:
      switch(c) {
      case 0x50: // DCS
        start_string(vt, VTERM_PARSER_DCS);
        ENTER_STRING_STATE();
        break;
      case 0x5b: // CSI
        vt->parser.csi_leaderlen = 0;
        ENTER_STATE(CSI_LEADER);
        break;
      case 0x5d: // OSC
        start_string(vt, VTERM_PARSER_OSC);
        ENTER_STRING_STATE();
        break;
      default:
        if(is_intermed(c)) {
          if(vt->parser.intermedlen < INTERMED_MAX-1)
            vt->parser.intermed[vt->parser.intermedlen++] = c;
        }
        else if(!vt->parser.intermedlen && c >= 0x40 && c < 0x60) {
          do_control(vt, c + 0x40);
          ENTER_NORMAL_STATE();
        }
        else if(c >= 0x30 && c < 0x7f) {
          do_escape(vt, c);
          ENTER_NORMAL_STATE();
        }
        else {
          DEBUG_LOG("TODO: Unhandled byte %02x in Escape\n", c);
        }
      }
      break;

    case CSI_LEADER:
      /* Extract leader bytes 0x3c to 0x3f */
      if(c >= 0x3c && c <= 0x3f) {
        if(vt->parser.csi_leaderlen < CSI_LEADER_MAX-1)
          vt->parser.csi_leader[vt->parser.csi_leaderlen++] = c;
        break;
      }

      /* else fallthrough */
      vt->parser.csi_leader[vt->parser.csi_leaderlen] = 0;

      vt->parser.csi_argi = 0;
      vt->parser.csi_args[0] = CSI_ARG_MISSING;
      vt->parser.state = CSI_ARGS;

      /* fallthrough */
    case CSI_ARGS:
      /* Numerical value of argument */
      if(c >= '0' && c <= '9') {
        if(vt->parser.csi_args[vt->parser.csi_argi] == CSI_ARG_MISSING)
          vt->parser.csi_args[vt->parser.csi_argi] = 0;
        vt->parser.csi_args[vt->parser.csi_argi] *= 10;
        vt->parser.csi_args[vt->parser.csi_argi] += c - '0';
        break;
      }
      if(c == ':') {
        vt->parser.csi_args[vt->parser.csi_argi] |= CSI_ARG_FLAG_MORE;
        c = ';';
      }
      if(c == ';') {
        vt->parser.csi_argi++;
        vt->parser.csi_args[vt->parser.csi_argi] = CSI_ARG_MISSING;
        break;
      }

      /* else fallthrough */
      vt->parser.csi_argi++;
      vt->parser.intermedlen = 0;
      vt->parser.state = CSI_INTERMED;
    case CSI_INTERMED:
      if(is_intermed(c)) {
        if(vt->parser.intermedlen < INTERMED_MAX-1)
          vt->parser.intermed[vt->parser.intermedlen++] = c;
        break;
      }
      else if(c == 0x1b) {
        /* ESC in CSI cancels */
      }
      else if(c >= 0x40 && c <= 0x7e) {
        vt->parser.intermed[vt->parser.intermedlen] = 0;
        do_csi(vt, c);
      }
      /* else was invalid CSI */

      ENTER_NORMAL_STATE();
      break;

    case STRING:
      if(c == 0x07 || (c == 0x9c && !vt->mode.utf8)) {
        done_string(vt, string_start, bytes + pos - string_start);
        ENTER_NORMAL_STATE();
      }
      break;

    case NORMAL:
      if(c >= 0x80 && c < 0xa0 && !vt->mode.utf8) {
        switch(c) {
        case 0x90: // DCS
          start_string(vt, VTERM_PARSER_DCS);
          ENTER_STRING_STATE();
          break;
        case 0x9b: // CSI
          ENTER_STATE(CSI_LEADER);
          break;
        case 0x9d: // OSC
          start_string(vt, VTERM_PARSER_OSC);
          ENTER_STRING_STATE();
          break;
        default:
          do_control(vt, c);
          break;
        }
      }
      else {
        size_t eaten = 0;
        if(vt->parser.callbacks && vt->parser.callbacks->text)
          eaten = (*vt->parser.callbacks->text)(bytes + pos, len - pos, vt->parser.cbdata);

        if(!eaten) {
          DEBUG_LOG("libvterm: Text callback did not consume any input\n");
          /* force it to make progress */
          eaten = 1;
        }

        pos += (eaten - 1); // we'll ++ it again in a moment
      }
      break;
    }
  }

  return len;
}