+extern int narches;
+extern char **archnames;
+extern int *islandid2arch;
+
+extern int granusz_fin[GRANUS], granusz_mid[GRANUS];
+
+
+extern FILE *output;
+
+
+#define NEW(ptr) ((ptr)= mmalloc(sizeof(*ptr)))
+
+#define MCALLOC(array, count) ((array)= mcalloc(sizeof(*(array)) * (count)))
+
+#define MCALLOC_INITEACH(array, count, init_this) ({ \
+ MCALLOC((array), (count)); \
+ int initi; \
+ typeof(&(array)[0]) this; \
+ for (initi=0, this=(array); initi<(count); initi++, this++) { \
+ init_this; \
+ } \
+ })
+
+
+typedef struct {
+ double value;
+ Bucket *bucket;
+} HighScoreEntry;
+
+extern int granus;
+extern int nhighscores[GRANUS][AP];
+extern HighScoreEntry *highscores[GRANUS][AP];
+
+
+#define ONDEMAND(pointer_lvalue, calloc_size_count) \
+ ((pointer_lvalue) ? : \
+ ((pointer_lvalue) = mcalloc(sizeof(*(pointer_lvalue)) * calloc_size_count)))
+
+
+static inline int isle2arch(int isle) {
+ int arch= islandid2arch[isle];
+ assert(arch>=0);
+ return arch;
+}
+
+static inline int route2midarch(const int *ports, int nports) {
+ int archs[nports], last_arch=-1, narchs=0, i;
+ for (i=0; i<nports; i++) {
+ int arch= isle2arch(ports[i]);
+ if (arch==last_arch) continue;
+ archs[narchs++]= last_arch= arch;
+ }
+ return archs[narchs/2];
+}
+