diff options
| author | Tyge Løvset <[email protected]> | 2022-01-05 15:14:32 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-01-05 15:14:32 +0100 |
| commit | ead3df255f79f60257ae9626e7d52838de3caa67 (patch) | |
| tree | 96e67304ff45b541ddc8b5119b6b0c4d7eb6a84b /include/stc | |
| parent | 7083c748e2c00d0236146d21f9b20cfe69f953e6 (diff) | |
| download | STC-modified-ead3df255f79f60257ae9626e7d52838de3caa67.tar.gz STC-modified-ead3df255f79f60257ae9626e7d52838de3caa67.zip | |
Added docs on checkauto util program. Renamed (mainly internal) c_rawstr type to crawstr.
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/cbox.h | 29 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 11 | ||||
| -rw-r--r-- | include/stc/template.h | 4 |
3 files changed, 20 insertions, 24 deletions
diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 0aa6a752..42f5ede8 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -24,36 +24,35 @@ /* cbox: heap allocated boxed type
#include <stc/cstr.h>
-typedef struct { cstr name, last; } Person;
+typedef struct { cstr name, email; } Person;
-Person Person_new(const char* name, const char* last) {
- return (Person){.name = cstr_from(name), .last = cstr_from(last)};
+Person Person_from(const char* name, const char* email) {
+ return (Person){.name = cstr_from(name), .email = cstr_from(email)};
}
Person Person_clone(Person p) {
p.name = cstr_clone(p.name);
- p.last = cstr_clone(p.last);
+ p.email = cstr_clone(p.email);
return p;
}
void Person_drop(Person* p) {
- printf("drop: %s %s\n", p->name.str, p->last.str);
- c_drop(cstr, &p->name, &p->last);
+ printf("drop: %s %s\n", p->name.str, p->email.str);
+ c_drop(cstr, &p->name, &p->email);
}
-#define i_val Person
-#define i_valdrop Person_drop
-#define i_valfrom Person_clone
+#define i_val_bind Person // bind Person clone+drop fn's
#define i_opt c_no_cmp // compare by .get addresses only
-#define i_tag prs
+#define i_type PBox
#include <stc/cbox.h>
int main() {
- c_autovar (cbox_prs p = cbox_prs_new(Person_new("John", "Smiths")), cbox_prs_drop(&p))
- c_autovar (cbox_prs q = cbox_prs_clone(p), cbox_prs_drop(&q))
+ c_auto (PBox, p, q)
{
- cstr_assign(&q.get->name, "Joe");
+ p = PBox_from(Person_from("John Smiths", "[email protected]"));
+ q = PBox_clone(p);
+ cstr_assign(&q.get->name, "Joe Smiths");
- printf("%s %s.\n", p.get->name.str, p.get->last.str);
- printf("%s %s.\n", q.get->name.str, q.get->last.str);
+ printf("%s %s.\n", p.get->name.str, p.get->email.str);
+ printf("%s %s.\n", q.get->name.str, q.get->email.str);
}
}
*/
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 60e12433..2b1f38a2 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -106,13 +106,10 @@ typedef const char c_strlit[]; /* Generic algorithms */
-typedef char* c_mutstr;
-typedef const char* c_rawstr;
-#define c_rawstr_cmp(xp, yp) strcmp(*(xp), *(yp))
-#define c_rawstr_eq(xp, yp) (!strcmp(*(xp), *(yp)))
-#define c_rawstr_hash(p, dummy) c_strhash(*(p))
-#define c_rawstr_clone(s) strcpy((char*)c_malloc(strlen(s) + 1), s)
-#define c_rawstr_drop(p) c_free((char *) &**(p))
+typedef const char* crawstr;
+#define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp))
+#define crawstr_eq(xp, yp) (!strcmp(*(xp), *(yp)))
+#define crawstr_hash(p, dummy) c_strhash(*(p))
#define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
diff --git a/include/stc/template.h b/include/stc/template.h index 16218ecb..7670ec92 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -57,7 +57,7 @@ #ifdef i_key_str
#define i_key_bind cstr
- #define i_keyraw c_rawstr
+ #define i_keyraw crawstr
#ifndef i_tag
#define i_tag str
#endif
@@ -116,7 +116,7 @@ #ifdef i_val_str
#define i_val_bind cstr
- #define i_valraw c_rawstr
+ #define i_valraw crawstr
#if !defined i_tag && !defined i_key
#define i_tag str
#endif
|
