Пример #1
0
static int left_callback(int count, int key) {
    reset_indent();
    if (rl_point > 0) {
        int i = line_start(rl_point);
        do {
            rl_point = (i == 0 || rl_point-i > prompt_length) ? rl_point-1 : i-1;
        } while (locale_is_utf8 && !isutf(rl_line_buffer[rl_point]) && rl_point > i-1);
    }
    return 0;
}
Пример #2
0
static off_t
begin_paragraph (WEdit * edit, gboolean force)
{
    long i;

    for (i = edit->buffer.curs_line - 1; i >= 0; i--)
        if (edit_line_is_blank (edit, i) ||
            (force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i))))
        {
            i++;
            break;
        }

    return edit_buffer_move_backward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer),
                                      edit->buffer.curs_line - i);
}
Пример #3
0
static int down_callback(int count, int key) {
    reset_indent();
    int j = line_end(rl_point);
    if (j < rl_end) {
        int i = line_start(rl_point);
        if (i == 0) rl_point += prompt_length;
        rl_point += j - i + 1;
        int k = line_end(j+1);
        if (rl_point > k) rl_point = k;
        return 0;
    } else {
        if (last_hist_offset >= 0) {
            history_set_pos(last_hist_offset);
            last_hist_offset = -1;
        }
        return rl_get_next_history(count, key);
    }
}
Пример #4
0
static off_t
end_paragraph (WEdit * edit, gboolean force)
{
    long i;

    for (i = edit->buffer.curs_line + 1; i <= edit->buffer.lines; i++)
        if (edit_line_is_blank (edit, i) ||
            (force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i))))
        {
            i--;
            break;
        }

    return edit_buffer_get_eol (&edit->buffer,
                                edit_buffer_move_forward (&edit->buffer,
                                                          edit_buffer_get_current_bol
                                                          (&edit->buffer),
                                                          i - edit->buffer.curs_line, 0));
}
Пример #5
0
/*
 * Find the start of the current paragraph for the purpose of formatting.
 * Return position in the file.
 */
static long
begin_paragraph (WEdit *edit, int force)
{
    int i;
    for (i = edit->curs_line - 1; i >= 0; i--) {
	if (line_is_blank (edit, i)) {
	    i++;
	    break;
	}
	if (force) {
	    if (bad_line_start (edit, line_start (edit, i))) {
		i++;
		break;
	    }
	}
    }
    return edit_move_backward (edit, edit_bol (edit, edit->curs1),
			       edit->curs_line - i);
}
Пример #6
0
/*
 * Find the end of the current paragraph for the purpose of formatting.
 * Return position in the file.
 */
static long
end_paragraph (WEdit *edit, int force)
{
    int i;
    for (i = edit->curs_line + 1; i <= edit->total_lines; i++) {
	if (line_is_blank (edit, i)) {
	    i--;
	    break;
	}
	if (force)
	    if (bad_line_start (edit, line_start (edit, i))) {
		i--;
		break;
	    }
    }
    return edit_eol (edit,
		     edit_move_forward (edit, edit_bol (edit, edit->curs1),
					i - edit->curs_line, 0));
}
Пример #7
0
static int backspace_callback(int count, int key) {
    reset_indent();
    if (!rl_point) return 0;

    int i = line_start(rl_point), j = rl_point, k;
    if (!i || rl_point <= i + prompt_length) goto backspace;
    for (k = i; k < rl_point; k++)
        if (rl_line_buffer[k] != ' ') goto backspace;

//unindent:
    k = i + prompt_length;
    do { rl_point--; } while ((rl_point - k) % tab_width);
    goto finish;

backspace:
    rl_point = (i == 0 || rl_point-i > prompt_length) ? rl_point-1 : i-1;

finish:
    rl_delete_text(rl_point, j);
    return 0;
}
Пример #8
0
void http_digest(PCHAR pDstBuf, PCHAR pAuthData, PCHAR pUri, PCHAR pAccount, PCHAR pPassword, PCHAR pMethod)
{
    PCHAR pCur;
    PCHAR pTemp;
    PCHAR pValue;
    PCHAR pRealm;
    PCHAR pNonce;
    PCHAR pOpaque;
    BOOLEAN bRealm, bNonce, bOpaque;
    UCHAR iAlg, iQop;
    UCHAR pHA1[33];
    UCHAR pHA2[33];
    UCHAR pMD5Value[MD5_SIGNATURE_SIZE];

    strcpy(pDstBuf, pAuthData);
    pCur = pDstBuf;
    if (memcmp_lowercase(pCur, "digest "))
    {
        pDstBuf[0] = 0;
        return;
    }
    pCur += 7;

    iQop = QOP_NONE;
    iAlg = ALG_NONE;
    pRealm = NULL;
    pNonce = NULL;
    pOpaque = NULL;
    bRealm = FALSE;
    bNonce = FALSE;
    bOpaque = FALSE;
    do
    {
        pTemp = SkipField(pCur, ',');
        pValue = SkipField(pCur, '=');
        pValue = _unquote_str(pValue);
        if (!strcmp_lowercase(pCur, "realm"))
        {
            if (!bRealm)
            {
                pRealm = heap_save_str(pValue);
                bRealm = TRUE;
            }
        }
        else if (!strcmp_lowercase(pCur, "nonce"))
        {
            if (!bNonce)
            {
                pNonce = heap_save_str(pValue);
                bNonce = TRUE;
            }
        }
        else if (!strcmp_lowercase(pCur, "opaque"))
        {
            if (!bOpaque)
            {
                pOpaque = heap_save_str(pValue);
                bOpaque = TRUE;
            }
        }
        else if (!strcmp_lowercase(pCur, "qop"))
        {
            iQop = QOP_AUTH;
        }
        else if (!strcmp_lowercase(pCur, "algorithm"))
        {
            if (!strcmp_lowercase(pValue, "md5"))
            {
                iAlg = ALG_MD5;
            }
            if (!strcmp_lowercase(pValue, "md5-sess"))
            {
                iAlg = ALG_MD5SESS;
            }
        }
        if (pTemp)
        {
            pCur = pTemp;
//			pCur ++;
            pCur += count_space(pCur);
        }
    } while (pTemp);

    line_backup();
    // generate HA1
    line_start(pDstBuf);
    line_add_str_with_char(pAccount, ':');
    line_add_str_with_char(pRealm, ':');
    line_add_str(pPassword);
    MD5GenValue(pHA2, pDstBuf, line_get_len());
    TaskMiniRun();
    if (iAlg == ALG_MD5SESS)
    {
        line_start(pDstBuf);
        line_add_data(pHA2, MD5_SIGNATURE_SIZE);
        line_add_char(':');
        line_add_str_with_char(pNonce, ':');
        line_add_str(_cCnonce);
        MD5GenValue(pHA2, pDstBuf, line_get_len());
        TaskMiniRun();
    }
    char2asc_str(pHA1, pHA2, MD5_SIGNATURE_SIZE, FALSE);

    // Generate HA2
    line_start(pDstBuf);
    line_add_str_with_char(pMethod, ':');
    line_add_str(pUri);
    if (iQop == QOP_AUTHINT)
    {
        line_add_char(':');
        line_add_str(_cHEntity);
    }
    MD5GenValue(pMD5Value, pDstBuf, line_get_len());
    TaskMiniRun();
    char2asc_str(pHA2, pMD5Value, MD5_SIGNATURE_SIZE, FALSE);

    // generate final response
    line_start(pDstBuf);
    line_add_str_with_char(pHA1, ':');
    line_add_str_with_char(pNonce, ':');
    if (iQop != QOP_NONE)
    {
        line_add_str_with_char(_cNc, ':');
        line_add_str_with_char(_cCnonce, ':');
        line_add_str_with_char(_cQopType[iQop], ':');
    }
    line_add_str(pHA2);
    MD5GenValue(pMD5Value, pDstBuf, line_get_len());
    TaskMiniRun();
    char2asc_str(pHA2, pMD5Value, MD5_SIGNATURE_SIZE, FALSE);

    // Write response
    line_start(pDstBuf);
    line_add_str("Digest username=\"");
    line_add_str_with_char(pAccount, '"');
    if (bRealm)
    {
        line_add_str(",realm=\"");
        line_add_str_with_char(pRealm, '"');
    }
    if (bNonce)
    {
        line_add_str(",nonce=\"");
        line_add_str_with_char(pNonce, '"');
    }
    line_add_str(",uri=\"");
    line_add_str_with_char(pUri, '"');
    // qop=auth, some system don't allow quote sign qop="auth" here
    if (iQop != QOP_NONE)
    {
        line_add_str(",qop=");
        line_add_str(_cQopType[iQop]);
        line_add_str(",nc=");
        line_add_str(_cNc);
        line_add_str(",cnonce=\"");
        line_add_str_with_char(_cCnonce, '"');
    }
    if (bOpaque)
    {
        line_add_str(",opaque=\"");
        line_add_str_with_char(pOpaque, '"');
    }
    if (iAlg != ALG_NONE)
    {
        line_add_str(",algorithm=");
        line_add_str(_cAlgType[iAlg]);
    }
    line_add_str(",response=\"");
    line_add_str_with_char(pHA2, '"');

    if (pRealm)		free(pRealm);
    if (pNonce)		free(pNonce);
    if (pOpaque)	free(pOpaque);

    line_restore();
}
Пример #9
0
void indent(editor_t *ed, char *indentation)
  {
  int start, end, i, lines, toplines, newline, ch;
  char *buffer, *p;
  int buflen;
  int width = strlen(indentation);
  int pos = ed->linepos + ed->col;

  if (!get_selection(ed, &start, &end))
    {
    insert_char(ed, '\t');
    return;
    }

  lines = 0;
  toplines = 0;
  newline = 1;
  for (i = start; i < end; i++)
    {
    if (i == ed->toppos) toplines = lines;
    if (newline)
      {
      lines++;
      newline = 0;
      }
    if (get(ed, i) == '\n') newline = 1;
    }
  buflen = end - start + lines * width;
  buffer = neutron_malloc(buflen);
  if (!buffer) return;

  newline = 1;
  p = buffer;
  for (i = start; i < end; i++)
    {
    if (newline)
      {
      memcpy(p, indentation, width);
      p += width;
      newline = 0;
      }
    ch = get(ed, i);
    *p++ = ch;
    if (ch == '\n') newline = 1;
    }

  replace(ed, start, end - start, buffer, buflen, 1);
  neutron_free(buffer);

  if (ed->anchor < pos)
    {
    pos += width * lines;
    }
  else
    {
    ed->anchor += width * lines;
    }

  ed->toppos += width * toplines;
  ed->linepos = line_start(ed, pos);
  ed->col = ed->lastcol = pos - ed->linepos;

  adjust(ed);
  ed->refresh = 1;
  }