static char *_mars_translate_hostname(const char *name) { struct mars_global *global = mars_global; char *res = brick_strdup(name); struct mars_dent *test; char *tmp; if (unlikely(!global)) { goto done; } for (tmp = res; *tmp; tmp++) { if (*tmp == ':') { *tmp = '\0'; break; } } tmp = path_make("/mars/ips/ip-%s", res); if (unlikely(!tmp)) { goto done; } test = mars_find_dent(global, tmp); if (test && test->new_link) { MARS_DBG("'%s' => '%s'\n", tmp, test->new_link); brick_string_free(res); res = brick_strdup(test->new_link); } else { MARS_DBG("no translation for '%s'\n", tmp); } brick_string_free(tmp); done: return res; }
bool init_graphics_modes(const char *filename) { int i = 0; int line = 0; int previd; char *zz[16]; char buf[1024]; ang_file *fp; graphics_mode *mode = NULL,*next; /* Build the filename */ path_make(buf, ANGBAND_DIR_USER, filename); fp = file_open(buf, MODE_READ, FTYPE_TEXT); if (!fp) { /* Build the filename */ path_make(buf, ANGBAND_DIR_XTRA_GRAF, filename); fp = file_open(buf, MODE_READ, FTYPE_TEXT); } if (!fp) { return FALSE; } while (0 <= file_getl(fp, buf, 1024)) { /* Count lines */ line++; /* Skip "empty" lines */ if (!buf[0]) continue; /* Skip "blank" lines */ if (isspace(buf[0])) continue; /* Skip comments */ if (buf[0] == '#') continue; /* Require "?:*" format */ if (buf[1] != ':') return FALSE;/*(1);*/ /* process the line */ /* Process "N:<id>:<menuname>" -- start a new record */ if (buf[0] == 'N') { if (tokenize(buf + 2, 2, zz, TOKENIZE_CHECKQUOTE) == 2) { mode = ZNEW(graphics_mode); if (mode) { mode->grafID = strtol(zz[0], NULL, 0); strncpy(mode->menuname, zz[1], 32); mode->menuname[31] = 0; if (graphics_mode_high_id < mode->grafID) { graphics_mode_high_id = mode->grafID; } mode->pNext = graphics_modes; graphics_modes = mode; } else { return FALSE;/*(PARSE_ERROR_OUT_OF_MEMORY);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } /* Process "P:<prefname>:<preffile>" -- set the name used with pref files */ else if (buf[0] == 'P') { byte count = tokenize(buf + 2, 2, zz, TOKENIZE_CHECKQUOTE); if (count >= 1) { if (mode) { strncpy(mode->pref, zz[0], 32); if (count == 2) { /* overwrite the pref name with the pref filename */ strncpy(mode->pref, zz[1], 32); } mode->pref[31] = 0; } else { return FALSE;/*(PARSE_ERROR_MISSING_RECORD_HEADER);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } /* Process "I:<cell width>:<cell height>:<filename>" -- read the tileset info */ else if (buf[0] == 'I') { if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3) { if (mode) { mode->cell_width = strtol(zz[0], NULL, 0); mode->cell_height = strtol(zz[1], NULL, 0); strncpy(mode->file, zz[2], 32); mode->file[31] = 0; } else { return FALSE;/*(PARSE_ERROR_MISSING_RECORD_HEADER);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } /* Process "X:<alpha>:<overdraw_min>:<overdraw_max>" -- read some extra info */ else if (buf[0] == 'X') { if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3) { if (mode) { mode->alphablend = strtol(zz[0], NULL, 0); mode->overdrawRow = strtol(zz[1], NULL, 0); mode->overdrawMax = strtol(zz[2], NULL, 0); } else { return FALSE;/*(PARSE_ERROR_MISSING_RECORD_HEADER);*/ } } else { return FALSE;/*(PARSE_ERROR_GENERIC);*/ } } else { /* Oops */ return FALSE;/*(PARSE_ERROR_UNDEFINED_DIRECTIVE);*/ } } /* close the file */ file_close(fp); mode = graphics_modes; graphics_modes = C_RNEW(graphics_mode_high_id+1,graphics_mode); /* set the default mode */ graphics_modes[0].grafID = 0; graphics_modes[0].alphablend = 0; graphics_modes[0].cell_height = 1; graphics_modes[0].cell_width = 1; graphics_modes[0].overdrawRow = 0; graphics_modes[0].overdrawMax = 0; strncpy(graphics_modes[0].menuname, "None", 32); strncpy(graphics_modes[0].pref, "font.prf", 32); strncpy(graphics_modes[0].file, "", 32); if (mode) { next = mode; while (next->pNext) next = next->pNext; graphics_modes[0].pNext = &(graphics_modes[next->grafID]); } else { graphics_modes[0].pNext = NULL; } previd = 0; while (mode) { next = mode->pNext; i = mode->grafID; graphics_modes[i].grafID = mode->grafID; graphics_modes[i].cell_height = mode->cell_height; graphics_modes[i].cell_width = mode->cell_width; graphics_modes[i].alphablend = mode->alphablend; graphics_modes[i].overdrawRow = mode->overdrawRow; graphics_modes[i].overdrawMax = mode->alphablend; strncpy(graphics_modes[i].menuname, mode->menuname, 32); strncpy(graphics_modes[i].pref, mode->pref, 32); strncpy(graphics_modes[i].file, mode->file, 32); if (previd) { graphics_modes[i].pNext = &(graphics_modes[previd]); } else { graphics_modes[i].pNext = NULL; } previd = i; FREE(mode); mode = next; } return TRUE; }
/* * Init the tk port */ int init_tnb(int argc, cptr *argv) { /* Hack -ignore parameter */ (void) argc; /* Save the "tk" directory */ path_make(ANGBAND_DIR_TK, ANGBAND_DIR_SCRIPT, "tk"); /* Use graphics */ pick_graphics(GRAPHICS_ADAM_BOLT, &tnb_tile_x, &tnb_tile_y, tnb_tile_file); /* Try the "16x16.bmp" file */ path_make(tnb_font_file, ANGBAND_DIR_XTRA, "font/16x16.txt"); /* Use the "16x16.bmp" file if it exists */ if (fd_close(fd_open(tnb_font_file, O_RDONLY))) { quit("Could not initialise font metrics!"); } /* Always 16x16 for now */ tnb_font_size = 16; /* Prepare the windows */ init_windows(); /* Activate hooks */ quit_aux = hook_quit; core_aux = hook_quit; /* Hack - TclTk_Init doesn't fail gracefully, so check manually for X11 */ if (!XOpenDisplay("")) return (1); /* Initialize Tcl and Tk. */ g_interp = TclTk_Init(argv); /* Paranoia */ if (!g_interp) return(1); /* Set the memory-allocation hooks */ rnfree_aux = my_tcl_free; ralloc_aux = my_tcl_alloc; /* Initialize */ angtk_init(); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Program is intialized */ angtk_angband_initialized(); /* Init colours */ Term_xtra_tnb_react(); #if 0 while (TRUE) { while (Tcl_DoOneEvent(TRUE) != 0) ; } #endif /* 0 */ /* Press a key for the player */ Term_keypress(' '); /* Paranoia */ return (0); }