7 // cheat - pre-examined input to learn max name length (3+NUL)
10 typedef struct reg reg
;
21 for (reg
*iter
= list
; iter
; iter
= iter
->next
)
22 if (!strcmp (iter
->name
, name
))
24 reg
*r
= calloc (1, sizeof *r
);
25 strcpy (r
->name
, name
); // safe because of max name
32 set(const char *name
, int adjust
)
35 printf(" adjusting %s by %d\n", name
, adjust
);
36 for (reg
*iter
= list
; iter
; iter
= iter
->next
)
37 if (!strcmp (iter
->name
, name
)) {
38 iter
->value
+= adjust
;
41 reg
*r
= calloc (1, sizeof *r
);
42 strcpy (r
->name
, name
); // safe because of max name
51 char d
[MAXNAME
], s
[MAXNAME
], dir
, op
[3];
55 // ugly, but works because our data is sane
56 while (scanf("%3[a-z] %c%*[ne]c %d if %3[a-z] %2[><!=] %d\n",
57 d
, &dir
, &adjust
, s
, op
, &v
) == 6) {
69 printf("%s %d if %s (%d) %s %d\n", d
, adjust
, s
, r
, op
, v
);
72 switch (op
[0] + op
[1]) {
106 printf("parsed %d lines\n", count
);
108 for (reg
*iter
= list
; iter
; iter
= iter
->next
)
109 if (iter
->value
> max
)
111 printf("largest register contains %d\n", max
);
112 printf("largest value seen %d\n", high
);