aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-03-17 18:28:00 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-03-17 18:28:00 +0100
commit7b3204679bf53733ade52436723fc41858260d36 (patch)
tree0ad5d04eee28245dd86612d65b6a65ae7069881c
parentb376b24e6d475d90e3c8267e8340b13ec7a43121 (diff)
downloadsciteco-7b3204679bf53733ade52436723fc41858260d36.tar.gz
^E\ string building character to format number
* new Expressions::format() * may be used format numbers as part of arrays (Q-Register names)
-rw-r--r--doc/sciteco.7.template7
-rw-r--r--src/expressions.cpp21
-rw-r--r--src/expressions.h2
-rw-r--r--src/parser.cpp29
4 files changed, 45 insertions, 14 deletions
diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template
index 84e10cc..d59aec0 100644
--- a/doc/sciteco.7.template
+++ b/doc/sciteco.7.template
@@ -804,6 +804,13 @@ part of Q-Register \fIq\fP.
For instance if register \(lqA\(rq contains the code 66,
\(lq^EUa\(rq expands to the character \(lqB\(rq.
.TP
+.BI ^E\(rs q
+Expands to the formatted number stored in the
+numeric part of Q-Register \fIq\fP.
+The number is formatted according to the current
+radix and exactly the same as the backslash (\fB\(rs\fP)
+command would format it.
+.TP
.BI ^E c
All remaining \fB^E\fP combinations are passed down
unmodified.
diff --git a/src/expressions.cpp b/src/expressions.cpp
index 7975d10..8d15d73 100644
--- a/src/expressions.cpp
+++ b/src/expressions.cpp
@@ -220,3 +220,24 @@ Expressions::discard_args(void)
for (int i = args(); i; i--)
pop_num_calc();
}
+
+const gchar *
+Expressions::format(tecoInt number)
+{
+ /* maximum length if radix = 2 */
+ static gchar buf[1+sizeof(number)*8+1];
+ gchar *p = buf + sizeof(buf);
+
+ tecoInt v = ABS(number);
+
+ *--p = '\0';
+ do {
+ *--p = '0' + (v % radix);
+ if (*p > '9')
+ *p += 'A' - '9';
+ } while ((v /= radix));
+ if (number < 0)
+ *--p = '-';
+
+ return p;
+}
diff --git a/src/expressions.h b/src/expressions.h
index 48ce6ee..83d3b12 100644
--- a/src/expressions.h
+++ b/src/expressions.h
@@ -202,6 +202,8 @@ public:
operators.clear();
}
+ const gchar *format(tecoInt number);
+
private:
void calc(void);
diff --git a/src/parser.cpp b/src/parser.cpp
index 80bd3b5..c1cb42e 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -308,6 +308,10 @@ StateUpper:
StateCtlE:
switch (g_ascii_toupper(chr)) {
+ case '\\':
+ undo.push_obj(qregspec_machine) = new QRegSpecMachine;
+ set(&&StateCtlENum);
+ break;
case 'Q':
undo.push_obj(qregspec_machine) = new QRegSpecMachine;
set(&&StateCtlEQ);
@@ -323,6 +327,15 @@ StateCtlE:
return NULL;
+StateCtlENum:
+ reg = qregspec_machine->input(chr);
+ if (!reg)
+ return NULL;
+
+ undo.push_obj(qregspec_machine) = NULL;
+ set(StateStart);
+ return g_strdup(expressions.format(reg->get_integer()));
+
StateCtlEU:
reg = qregspec_machine->input(chr);
if (!reg)
@@ -460,22 +473,10 @@ StateStart::StateStart() : State()
void
StateStart::insert_integer(tecoInt v)
{
- gchar buf[sizeof(tecoInt)*8+1]; /* maximum length if radix = 2 */
- gchar *p = buf + sizeof(buf);
+ const gchar *str = expressions.format(v);
- *--p = '\0';
interface.ssm(SCI_BEGINUNDOACTION);
- if (v < 0) {
- interface.ssm(SCI_ADDTEXT, 1, (sptr_t)"-");
- v *= -1;
- }
- do {
- *--p = '0' + (v % expressions.radix);
- if (*p > '9')
- *p += 'A' - '9';
- } while ((v /= expressions.radix));
- interface.ssm(SCI_ADDTEXT, buf + sizeof(buf) - p - 1,
- (sptr_t)p);
+ interface.ssm(SCI_ADDTEXT, strlen(str), (sptr_t)str);
interface.ssm(SCI_SCROLLCARET);
interface.ssm(SCI_ENDUNDOACTION);
ring.dirtify();