Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
d5ab1fc5
Commit
d5ab1fc5
authored
11 years ago
by
Martin Nilsson
Browse files
Options
Downloads
Patches
Plain Diff
Throw a recognizable object from ADT.struct in case of parse errors.
parent
d2e2853b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/ADT.pmod/module.pmod
+10
-4
10 additions, 4 deletions
lib/modules/ADT.pmod/module.pmod
with
10 additions
and
4 deletions
lib/modules/ADT.pmod/module.pmod
+
10
−
4
View file @
d5ab1fc5
...
@@ -13,6 +13,12 @@ constant List = __builtin.List;
...
@@ -13,6 +13,12 @@ constant List = __builtin.List;
protected int item_counter;
protected int item_counter;
int get_item_id() { return item_counter++; }
int get_item_id() { return item_counter++; }
protected class structError
{
inherit Error.Generic;
constant ADT_struct = 1;
}
//! String buffer with the possibility to read and write data
//! String buffer with the possibility to read and write data
//! as they would be formatted in structs.
//! as they would be formatted in structs.
class struct {
class struct {
...
@@ -61,7 +67,7 @@ class struct {
...
@@ -61,7 +67,7 @@ class struct {
this_program put_uint(int i, int(0..) len)
this_program put_uint(int i, int(0..) len)
{
{
if (i<0)
if (i<0)
e
rror("Negative argument.\n");
throw(structE
rror("Negative argument.\n")
)
;
add_data([string(0..255)]sprintf("%*c", len, i));
add_data([string(0..255)]sprintf("%*c", len, i));
return this;
return this;
}
}
...
@@ -81,7 +87,7 @@ class struct {
...
@@ -81,7 +87,7 @@ class struct {
this_program put_bignum(Gmp.mpz i, int(0..)|void len_width)
this_program put_bignum(Gmp.mpz i, int(0..)|void len_width)
{
{
if (i<0)
if (i<0)
e
rror("Negative argument.\n");
throw(structE
rror("Negative argument.\n")
)
;
put_var_string(i->digits(256), len_width || 2);
put_var_string(i->digits(256), len_width || 2);
return this;
return this;
}
}
...
@@ -117,7 +123,7 @@ class struct {
...
@@ -117,7 +123,7 @@ class struct {
{
{
int(0..) i;
int(0..) i;
if ( (sizeof(buffer) - index) < len)
if ( (sizeof(buffer) - index) < len)
e
rror("No data.\n");
throw(structE
rror("No data.\n")
)
;
sscanf(buffer, "%*" + (string) index +"s%" + (string) len + "c", i);
sscanf(buffer, "%*" + (string) index +"s%" + (string) len + "c", i);
index += len;
index += len;
return i;
return i;
...
@@ -127,7 +133,7 @@ class struct {
...
@@ -127,7 +133,7 @@ class struct {
string(0..255) get_fix_string(int len)
string(0..255) get_fix_string(int len)
{
{
if ((sizeof(buffer) - index) < len)
if ((sizeof(buffer) - index) < len)
e
rror("No data\n");
throw(structE
rror("No data\n")
)
;
string(0..255) res = buffer[index .. index + len - 1];
string(0..255) res = buffer[index .. index + len - 1];
index += len;
index += len;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment