/
hammer.sh
executable file
·5228 lines (4252 loc) · 92.8 KB
/
hammer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
##
# Hammer build system
# version 1.0dev0
##
TMP=".hammer.c"
BIN="hammer.cache"
CC="gcc"
test $VERBOSE && echo "cc=$CC"
sed '0,/\#\#csrc\#\#/d' "$0" > "$TMP" || exit $?
"$CC" -Wall -g -O2 "$TMP" -o "$BIN" || exit $?
exit 0
##csrc##
/*
* required headers
*/
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* shorter type names
*/
typedef int64_t i64;
typedef uint64_t u64;
/*
* structure prototypes
*/
struct ast_cmd_t;
struct ast_pipe_t;
struct cmd_t;
struct ctx_t;
struct env_t;
struct list_t;
struct queue_t;
struct ns_t;
struct rd_t;
struct rule_t;
struct rt_pipe_t;
struct seq_t;
struct set_t;
struct target_t;
struct target_list_t;
struct val_t;
struct loc_t;
struct tok_t;
struct val_t;
typedef int(*cmp_f)(const void *, const void *);
typedef void(*del_f)(void *);
typedef struct val_t *(func_t)(struct val_t **args, uint32_t cnt, struct loc_t loc);
/*
* common declarations
*/
uint64_t hash64(uint64_t hash, const char *str);
/*
* base declarations
*/
struct block_t *ham_load(const char *path);
/*
* backend declarations
*/
extern i64 os_memcnt;
void print(const char *fmt, ...);
void printv(const char *fmt, va_list args);
void fatal(const char *fmt, ...) __attribute__((noreturn));
void os_init(void);
int os_exec(struct cmd_t *cmd);
int os_wait(void);
int64_t os_mtime(const char *path);
void os_mkdir(const char *path);
/*
* argument declarations
*/
void args_init(struct val_t ***args, uint32_t *cnt);
void args_add(struct val_t ***args, uint32_t *cnt, struct val_t *val);
void args_delete(struct val_t **args, uint32_t cnt);
/*
* set declarations
*/
struct set_t *set_new(void);
void set_delete(struct set_t *set, void(*del)(void *));
void set_add(struct set_t *set, void *ref);
/**
* List structure.
* @head, tail: The head and tail links.
* @del: Value deletion function.
*/
struct list_t {
struct link_t *head, **tail;
void (*del)(void *);
};
/**
* Link structure.
* @val: The value.
* @next: The next link.
*/
struct link_t {
void *val;
struct link_t *next;
};
/*
* list declarations
*/
struct list_t *list_new(void(*del)(void *));
void list_delete(struct list_t *list);
void list_add(struct list_t *list, void *val);
/**
* Options structure.
* @force: Force rebuild.
* @jobs: The number of jobs.
* @dir: The selected directory.
*/
struct opt_t {
bool force;
int jobs;
const char *dir;
};
/**
* Context structure.
* @opt: The options.
* @map: The target map.
* @rules: The set of rules.
* @gen, dep: The generator and depedency values.
* @dir: The selected directory.
* @gen, deps: The generated and dependency targets.
*/
struct ctx_t {
const struct opt_t *opt;
struct map_t *map;
struct rule_list_t *rules;
struct val_t *gen, *dep;
struct bind_t *dir;
struct target_list_t *gens, *deps;
};
/*
* context declarations
*/
struct ctx_t *ctx_new(const struct opt_t *opt);
void ctx_delete(struct ctx_t *ctx);
void ctx_run(struct ctx_t *ctx, const char **builds);
struct target_t *ctx_target(struct ctx_t *ctx, bool spec, const char *path);
struct rule_t *ctx_rule(struct ctx_t *ctx, const char *id, struct target_list_t *gens, struct target_list_t *deps, struct seq_t *seq);
/**
* Rule structure.
* @id: The identifier.
* @gens, deps: The generated an depdency targets.
* @seq: The command sequence.
* @add: Flag indicated it has been added.
* @edges: The unresolved edge count.
*/
struct rule_t {
char *id;
struct target_list_t *gens, *deps;
struct seq_t *seq;
bool add;
uint32_t edges;
};
/**
* Rule list structure.
* @inst: The instance list.
*/
struct rule_list_t {
struct rule_inst_t *inst;
};
/**
* Rule instance structure.
* @rule: The rule.
* @next: The next instance.
*/
struct rule_inst_t {
struct rule_t *rule;
struct rule_inst_t *next;
};
/**
* Rule iterator stucture.
* @inst: The current instance.
*/
struct rule_iter_t {
struct rule_inst_t *inst;
};
/*
* rule declarations
*/
struct rule_t *rule_new(char *id, struct target_list_t *gens, struct target_list_t *deps, struct seq_t *seq);
void rule_delete(struct rule_t *rule);
/*
* rule iterator declarations
*/
struct rule_iter_t rule_iter(struct rule_list_t *list);
struct rule_t *rule_next(struct rule_iter_t *iter);
/*
* rule list declarations
*/
struct rule_list_t *rule_list_new(void);
void rule_list_delete(struct rule_list_t *list);
void rule_list_add(struct rule_list_t *list, struct rule_t *rule);
/*
* queue declarations
*/
struct queue_t *queue_new(void);
void queue_delete(struct queue_t *queue);
void queue_recur(struct queue_t *queue, struct rule_t *rule);
void queue_add(struct queue_t *queue, struct rule_t *rule);
struct rule_t *queue_rem(struct queue_t *queue);
/**
* Target structure.
* @path: The path.
* @flags: The flags.
* @mtime: The modification time.
* @rule: The associated rule.
* @edge: The forward edges.
*/
struct target_t {
char *path;
uint32_t flags;
int64_t mtime;
struct rule_t *rule;
struct edge_t *edge;
};
/**
* Target list structure.
* @inst: The head instance.
*/
struct target_list_t {
struct target_inst_t *inst;
};
/**
* Target instance structure.
* @target: The target.
* @next: The next instance.
*/
struct target_inst_t {
struct target_t *target;
struct target_inst_t *next;
};
/**
* Target iterator stucture.
* @inst: The current instance.
*/
struct target_iter_t {
struct target_inst_t *inst;
};
/**
* Edge instance stucture.
* @rule: The target rule.
* @next: The next instance.
*/
struct edge_t {
struct rule_t *rule;
struct edge_t *next;
};
/**
* Flag definitions
* @FLAG_BUILD: Built target (not source).
* @FLAG_SPEC: Special rule.
*/
#define FLAG_BUILD (1 << 0)
#define FLAG_SPEC (1 << 1)
/*
* target declarations
*/
struct target_t *target_new(bool spec, char *path);
void target_delete(struct target_t *target);
int64_t target_mtime(struct target_t *target);
void target_conn(struct target_t *target, struct rule_t *rule);
bool target_equal(const struct target_t *lhs, const struct target_t *rhs);
/*
* target iterator declarations
*/
struct target_iter_t target_iter(struct target_list_t *list);
struct target_t *target_next(struct target_iter_t *iter);
/*
* target list declarations
*/
struct target_list_t *target_list_new(void);
void target_list_delete(struct target_list_t *list);
uint32_t target_list_len(struct target_list_t *list);
bool target_list_contains(struct target_list_t *list, struct target_t *target);
void target_list_add(struct target_list_t *list, struct target_t *target);
struct target_t *target_list_find(struct target_list_t *list, bool spec, const char *path);
/**
* Target map structure.
* @ent: The head entry.
*/
struct map_t {
struct ent_t *ent;
};
/**
* Entry structure.
* @target: The target.
* @next: The next entry.
*/
struct ent_t {
struct target_t *target;
struct ent_t *next;
};
/*
* map declarations
*/
struct map_t *map_new(void);
void map_delete(struct map_t *map);
struct target_t *map_get(struct map_t *map, bool spec, const char *path);
void map_add(struct map_t *map, struct target_t *target);
/**
* Sequence structure.
* @head, tail: The head and tail commands.
*/
struct seq_t {
struct cmd_t *head, **tail;
};
/**
* Command structure.
* @pipe: The command pipe.
* @in, out: The input and output files.
* @append: Append mode.
* @next: The next value.
*/
struct cmd_t {
struct rt_pipe_t *pipe;
char *in, *out;
bool append;
struct cmd_t *next;
};
/*
* sequence declarations
*/
struct seq_t *seq_new(void);
void seq_delete(struct seq_t *seq);
void seq_add(struct seq_t *seq, struct rt_pipe_t *pipe, char *in, char *out, bool append);
/**
* Pipe structure.
* @cmd: The command.
* @next: The next pipe.
*/
struct rt_pipe_t {
struct val_t *cmd;
struct rt_pipe_t *next;
};
/*
* pipe declarations
*/
struct rt_pipe_t *rt_pipe_new(struct val_t *cmd);
void rt_pipe_clear(struct rt_pipe_t *pipe);
/************************/
/**
* Graph node structure.
* @path: The file path.
* @hash: The hash for quick comparisons.
* @flags: The flags.
* @deps: The number of dependencies.
* @edge: The set of forward edges.
*/
struct node_t {
char *path;
uint64_t hash;
uint32_t flags;
uint32_t deps;
struct set_t *edge;
};
/*
* node flags
*/
#define NODE_SPEC (1 << 0)
/*
* node declarations
*/
struct node_t *node_new(bool spec, char *path);
void node_delete(struct node_t *node);
/**
* Location structure.
* @path: The path.
* @lin, col: The line and column information.
*/
struct loc_t {
const char *path;
uint32_t lin, col;
};
/*
* command-line declarations
*/
extern char *cli_app;
void cli_proc(char **args);
void cli_err(const char *fmt, ...) __attribute__((noreturn));
/*
* location declarations
*/
struct loc_t loc_off(struct loc_t loc, uint32_t off);
void loc_err(struct loc_t loc, const char *fmt, ...) __attribute__((noreturn));
/**
* Value structure.
* @spec: Special flag.
* @str: The string.
* @next: The next value.
*/
struct val_t {
bool spec;
char *str;
struct val_t *next;
};
/*
* value declarations
*/
struct val_t *val_new(bool spec, char *str);
struct val_t *val_dup(const struct val_t *val);
void val_delete(struct val_t *val);
void val_clear(struct val_t *val);
char *val_id(struct val_t *val, struct loc_t loc);
char *val_str(struct val_t *val, struct loc_t loc);
uint32_t val_len(struct val_t *val);
/**
* Binding structure.
* @id: The identifier.
* @tag: The tag.
* @data: The data.
* @loc: The location.
* @next: The next binding.
*/
enum bind_e { val_v, func_v, ns_v };
union bind_u { struct val_t *val; func_t *func; };
struct bind_t {
char *id;
enum bind_e tag;
union bind_u data;
struct loc_t loc;
struct bind_t *next;
};
/*
* binding declarations
*/
struct bind_t *bind_new(char *id, enum bind_e tag, union bind_u data, struct loc_t loc);
void bind_delete(struct bind_t *bind);
void bind_erase(struct bind_t *bind);
void bind_set(struct bind_t **dst, struct bind_t *src);
struct bind_t *bind_val(char *id, struct val_t *val);
struct bind_t *bind_func(char *id, func_t *func);
/*
* string converstion declarations
*/
char *get_str(const char **str, struct loc_t loc);
void get_var(const char **str, char *var, struct loc_t loc);
/*
* string declarations
*/
void str_trim(const char **str);
char *str_fmt(const char *pat, ...);
void str_set(char **dst, char *src);
void str_final(char **str, const char *dir);
/**
* String structure.
* @buf: The character buffer.
* @len, max; The current and maximum lengths.
*/
struct buf_t {
char *str;
uint32_t len, max;
};
/*
* string declarations
*/
struct buf_t buf_new(uint32_t init);
void buf_delete(struct buf_t *buf);
char *buf_done(struct buf_t *buf);
void buf_ch(struct buf_t *buf, char ch);
void buf_mem(struct buf_t *buf, const char *mem, uint32_t len);
void buf_str(struct buf_t *buf, const char *str);
/*
* character declarations
*/
bool ch_space(int ch);
bool ch_alpha(int ch);
bool ch_num(int ch);
bool ch_alnum(int ch);
bool ch_var(int ch);
bool ch_str(int ch);
bool ch_id(int ch);
/**
* Namespace structure.
* @id: The name or null.
* @up, next: The parent and sibling namespaces
* @bindings: The list of bindings.
*/
struct ns_t {
char *id;
struct ns_t *up, *next;
struct bind_t *bind;
};
/*
* namespace declarations
*/
struct ns_t *ns_new(char *id, struct ns_t *up);
void ns_delete(struct ns_t *ns);
struct bind_t *ns_get(struct ns_t *ns, const char *id);
void ns_add(struct ns_t *ns, struct bind_t *bind);
struct bind_t *ns_find(struct ns_t *ns, const char *id);
struct bind_t **ns_lookup(struct ns_t *ns, const char *id);
/**
* Block structure.
* @stmt: The list of statements.
*/
struct block_t {
struct stmt_t *stmt;
};
/*
* block declarations
*/
struct block_t *block_new(void);
void block_delete(struct block_t *block);
/**
* Syntatic rule structure.
* @gen, dep: The generator and dependency values.
* @cmd: The list of commands.
* @in, out: The input and output redirect.
* @loc: The location.
*/
struct syn_t {
struct imm_t *gen, *dep;
struct list_t *cmd;
struct loc_t loc;
};
/*
* syntax rule declarations
*/
struct syn_t *syn_new(struct imm_t *gen, struct imm_t *dep, struct loc_t loc);
void syn_delete(struct syn_t *syn);
void syn_add(struct syn_t *syn, struct imm_t *cmd);
/**
* Processing statement structure.
* @pipe: The list of piped commands.
* @in, out: The redirect input and output.
* @append: The append flag.
*/
struct ast_cmd_t {
struct ast_pipe_t *pipe;
struct raw_t *in, *out;
bool append;
};
/*
* processing statement declarations
*/
struct ast_cmd_t *ast_cmd_new(struct ast_pipe_t *pipe);
void ast_cmd_delete(struct ast_cmd_t *cmd);
/**
* Pipe statement.
* @imm: The immediate value.
* @next: The next pipe.
*/
struct ast_pipe_t {
struct imm_t *imm;
struct ast_pipe_t *next;
};
/*
* pipe declarations
*/
struct ast_pipe_t *ast_pipe_new(struct imm_t *imm);
void ast_pipe_clear(struct ast_pipe_t *bar);
/**
* Directory structure.
* @def: Default flag.
* @raw: The raw string.
* @block: The optional blcok.
*/
struct dir_t {
bool def;
struct raw_t *raw;
struct block_t *block;
};
/*
* directory declarations
*/
struct dir_t *dir_new(bool def, struct raw_t *raw, struct block_t *block);
void dir_delete(struct dir_t *dir);
/**
* Conditional structure.
*/
struct cond_t {
};
/**
* Loop structure.
* @id: Variable binding identifier.
* @imm: The immediate value.
* @body: The body statement.
* @loc: The location.
*/
struct loop_t {
char *id;
struct imm_t *imm;
struct stmt_t *body;
struct loc_t loc;
};
struct loop_t *loop_new(char *id, struct imm_t *imm, struct stmt_t *body, struct loc_t loc);
void loop_delete(struct loop_t *loop);
/**
* Statement structure.
* @tag: The tag.
* @data: The data.
* @loc: The location.
* @next: The next statement.
*/
enum stmt_e { assign_v, syn_v, dir_v, loop_v, print_v, block_v };
union stmt_u { struct assign_t *assign; struct syn_t *syn; struct dir_t *dir; struct cond_t *conf; struct loop_t *loop; struct print_t *print; struct block_t *block; };
struct stmt_t {
enum stmt_e tag;
union stmt_u data;
struct loc_t loc;
struct stmt_t *next;
};
/*
* statement declarations
*/
struct stmt_t *stmt_new(enum stmt_e tag, union stmt_u data, struct loc_t loc);
void stmt_delete(struct stmt_t *stmt);
void stmt_clear(struct stmt_t *stmt);
/**
* Printing statement.
* @imm: The immediate value.
*/
struct print_t {
struct imm_t *imm;
};
/*
* print declarations
*/
struct print_t *print_new(struct imm_t *imm);
void print_delete(struct print_t *print);
/**
* Assignment structure.
* @id: The identifier.
* @val: The value.
*/
struct assign_t {
struct raw_t *id;
struct imm_t *val;
};
/*
* assignment declarations
*/
struct assign_t *assign_new(struct raw_t *id, struct imm_t *val);
void assign_delete(struct assign_t *assign);
/**
* String list.
* @raw: The raw strings list.
*/
struct imm_t {
struct raw_t *raw;
};
/*
* immediate value declaration
*/
struct imm_t *imm_new(void);
void imm_delete(struct imm_t *imm);
uint32_t imm_len(struct imm_t *imm);
/**
* Raw string structure.
* @spec, var: Special and variable flags.
* @str: The string.
* @loc: The location.
* @next: The next raw string.
*/
struct raw_t {
bool spec, var;
char *str;
struct loc_t loc;
struct raw_t *next;
};
/*
* raw value declarations
*/
struct raw_t *raw_new(bool spec, bool var, char *str, struct loc_t loc);
struct raw_t *raw_dup(const struct raw_t *raw);
void raw_delete(struct raw_t *raw);
void raw_clear(struct raw_t *raw);
/**
* Environment structure.
* @map: The variable mapping.
* @up: The parent environment.
*/
struct env_t {
struct map0_t *map;
struct env_t *up;
};
/*
* evaluation declarations
*/
void eval_top(struct block_t *block, struct ctx_t *ctx);
void eval_block(struct block_t *block, struct ctx_t *ctx, struct env_t *env);
void eval_stmt(struct stmt_t *stmt, struct ctx_t *ctx, struct env_t *env);
struct val_t *eval_imm(struct imm_t *imm, struct ctx_t *ctx, struct env_t *env);
struct val_t *eval_raw(struct raw_t *raw, struct ctx_t *ctx, struct env_t *env);
struct val_t *eval_var(const char **str, struct loc_t loc, struct ctx_t *ctx, struct env_t *env);
/*
* environment declarations
*/
struct env_t env_new(struct env_t *up);
void env_delete(struct env_t env);
struct bind_t *env_get(struct env_t *env, const char *id);
void env_put(struct env_t *env, struct bind_t *bind);
/**
* Job structure.
* @pid: The pid.
* @rule: The rule.
* @cmd: The current command.
*/
struct job_t {
int pid;
struct rule_t *rule;
struct cmd_t *cmd;
};
/**
* Job control structure.
* @queue: The rule queue.
* @job: The job array.
* @cnt: The number of jobs.
*/
struct ctrl_t {
struct queue_t *queue;
struct job_t *job;
uint32_t cnt;
};
/*
* job control declarations
*/
struct ctrl_t *ctrl_new(struct queue_t *queue, uint32_t n);
void ctrl_delete(struct ctrl_t *ctrl);
void ctrl_add(struct ctrl_t *ctrl, struct rule_t *rule);
bool ctrl_avail(struct ctrl_t *ctrl);
bool ctrl_busy(struct ctrl_t *ctrl);
void ctrl_wait(struct ctrl_t *ctrl);
void ctrl_done(struct ctrl_t *ctrl, struct rule_t *rule);
/*
* builtin function declarations
*/
struct val_t *fn_sub(struct val_t **args, uint32_t cnt, struct loc_t loc);
struct val_t *fn_pat(struct val_t **args, uint32_t cnt, struct loc_t loc);
/**
* Map structure.
* @ent: The entity list.
* @cmp: Comparison function.
* @del: Delete function.
*/
struct map1_t {
struct ent1_t *ent;
void (*cmp)(const void *, const void *);
void (*del)(void *);
};
/**
* Entity structure.
* @id: The identifier.
* @ref: The reference.
* @next: The next entity.
*/
struct ent1_t {
const char *id;
void *ref;
struct ent1_t *next;
};
/**
* Entry structure.
* @key: The key.
* @val: The value.
* @next: The next entry.
*/
struct entry0_t {
const void *key;
void *val;
struct entry0_t *next;
};
/**
* Map structure.
* @cmp: The comparison function.
* @del: The deletion function.
*/
struct map0_t {
cmp_f cmp;
del_f del;
struct entry0_t *entry;
};
/*
* map declarations
*/
struct map0_t *map0_new(cmp_f cmp, del_f del);
void map0_delete(struct map0_t *map);
void map0_add(struct map0_t *map, const void *key, void *val);
void *map0_get(struct map0_t *map, const void *key);
void *map_rem(struct map0_t *map, const void *key);
/**
* Main entry point.
* @argc: The number of arguments.
* @argv: The argument array.
* &returns: Exit status.
*/
int main(int argc, char **argv)
{
cli_app = "hammer";
os_init();
cli_proc(argv + 1);
return 0;
}
/**
* Create a 64-bit hash of a string.
* @hash: The starting hash.
* @str: The string.
* &returns: The hash.
*/
uint64_t hash64(uint64_t hash, const char *str)
{
while(*str != '\0') {
hash += (uint64_t)*str++ ^ 0x687ebde0fd11d4ae;