strid_t startup_findfile(void) { static DIR *dir = NULL; static char *pathstart = NULL; static char *path = NULL; strid_t stream; struct dirent *d; char *name = NULL; if(!pathstart) { char *p = search_path; if(!p) return 0; pathstart = n_strdup(p); if(!(path = n_strtok(pathstart, ":"))) { n_free(pathstart); pathstart = 0; return 0; } } do { if(!dir) { dir = opendir(path); if(!dir) { n_free(pathstart); pathstart = 0; return 0; } } d = readdir(dir); if(!d) { closedir(dir); dir = NULL; if(!(path = n_strtok(NULL, ":"))) { n_free(pathstart); pathstart = 0; return 0; } } } while(!dir); name = (char *) n_malloc(n_strlen(path) + n_strlen(d->d_name) + 2); n_strcpy(name, path); n_strcat(name, "/"); n_strcat(name, d->d_name); stream = glkunix_stream_open_pathname(name, fileusage_Data | fileusage_BinaryMode, 0); if(stream) set_game_filename(name); n_free(name); return stream; }
static void POSCALL n_buildKeyName(char *dest, const char *basename, VAR_t baselen, INT_t nbr) { char buf[5]; VAR_t l, i; #if NOSCFG_FEATURE_SPRINTF != 0 nosSPrintf1(buf, "%i", nbr); #else sprintf(buf, "%i", nbr); #endif l = n_strlen(buf); if ((baselen + l) >= NOS_MAX_REGKEYLEN) { baselen = NOS_MAX_REGKEYLEN - l; } else { dest[baselen + l] = 0; } for (i=0; i<baselen; ++i) dest[i] = basename[i]; for (i=0; i<l; ++i) dest[baselen + i] = buf[i]; }
void serv_seg(t_on_screen *screen, char *msg) { char *team; SDL_Color color; SDL_Rect pos; SDL_Surface *victory; pos.x = 0; pos.y = 0; team = get_argument(msg, 2); team[n_strlen(team, 1)] = '\0'; victory = img_load("images/victory.png"); xsdl_blitsurface(victory, NULL, screen->window, &pos); if (TTF_Init() != -1) { color.r = 250; color.g = 250; color.b = 0; send_team(screen, team, &pos, &color); TTF_Quit(); } SDL_FreeSurface(victory); xsdl_flip(screen->window); SDL_Delay(10000); }
bool bool_query_param_def(const struct mg_request_info *request_info, const char * param, const bool def) { char queryParam[10]; size_t queryLength = n_strlen(request_info->query_string); int res = mg_get_var(request_info->query_string, queryLength, param, queryParam, 10); if(res > 0) { return (queryParam[0] == '1'); } return def; }
bool contains_path_chars(const char * s) { int len = n_strlen(s); for(int i = 0; i < len; i++) { if(s[i] == '/') { return true; } if(s[i] == '.' && s[i+1] == '.') { return true; } } return false; }
NOSGENERICHANDLE_t POSCALL nosGetHandleByName(NOSREGTYPE_t objtype, const char *objname) { REGELEM_t re; if ((objtype > MAX_REGTYPE) || (objname ==NULL)) return NULL; if (n_strlen(objname) > NOS_MAX_REGKEYLEN) return NULL; posSemaGet(reglist_sema_g); re = n_findKeyByName(objtype, objname); posSemaSignal(reglist_sema_g); if (re == NULL) return NULL; return IS_VISIBLE(re) ? re->handle.generic : NULL; }
int str_query_param(const struct mg_request_info *request_info, const char * param, char * buffer, const int length) { size_t queryLength = n_strlen(request_info->query_string); return mg_get_var(request_info->query_string, queryLength, param, buffer, length); }
static VAR_t POSCALL n_newKey(NOSREGTYPE_t type, const char* name, REGELEM_t *reret) { REGELEM_t re; #if NOSCFG_FEATURE_REGQUERY != 0 REGELEM_t ri; #endif VAR_t i, bl, status; INT_t n; bl = n_strlen(name); if (bl == 0) return -E_FAIL; re = n_regAlloc(); if (re == NULL) return -E_NOMEM; status = -E_FAIL; if ((bl > NOS_MAX_REGKEYLEN) || (name[bl - 1] == '*')) { if (bl > NOS_MAX_REGKEYLEN) bl = NOS_MAX_REGKEYLEN; --bl; for (n=0; n <= KEY_MAXNAMENBR; ++n) { n_buildKeyName(re->name, name, bl, n); if (n_findKeyByName(type, re->name) == NULL) { status = E_OK; break; } } } else { if (n_findKeyByName(type, name) == NULL) { status = E_OK; for (i=0; i<bl; ++i) re->name[i] = name[i]; if (i < NOS_MAX_REGKEYLEN) re->name[i] = 0; } } if (status != E_OK) { n_regFree(re); } else { #if NOSCFG_FEATURE_REGQUERY != 0 re->next = NULL; ri = reglist_syselem_g[type]; if (ri == NULL) { reglist_syselem_g[type] = re; } else { for (; ri->next != NULL; ri = ri->next); ri->next = re; } #else re->next = reglist_syselem_g[type]; reglist_syselem_g[type] = re; #endif *reret = re; } return status; }
static BOOL parse_commands(int argc, char **argv) { int i; unsigned n; for(i = 1; i < argc; i++) { BOOL flag = TRUE; const char *p = argv[i]; if(p[0] == '-') { BOOL found = FALSE; while(*p == '-') p++; if(n_strncmp(p, "no-", 3) == 0) { flag = FALSE; p+=3; } if(n_strcasecmp(p, "help") == 0) { show_help(); exit(0); } if(n_strcasecmp(p, "version") == 0) { printf("nitfol version %d.%d\n", NITFOL_MAJOR, NITFOL_MINOR); exit(0); } for(n = 0; n < sizeof(options) / sizeof(*options); n++) { if((n_strlen(p) == 1 && *p == options[n].shortname) || n_strcmp(options[n].longname, p) == 0) { found = TRUE; switch(options[n].type) { case option_flag: options[n].int_func(flag); break; case option_file: i++; options[n].str_func(startup_open(argv[i])); break; case option_wfile: i++; options[n].str_func(startup_wopen(argv[i])); break; case option_number: i++; options[n].int_func(n_strtol(argv[i], NULL, 0)); break; case option_string: i++; options[n].string_func(argv[i]); break; } } } if(!found) return FALSE; } else { strid_t s = startup_open(argv[i]); if(!s) return FALSE; if(!game_use_file(s)) return FALSE; } } return TRUE; }
static void read_textpref(strid_t pref, const char *progname) { unsigned n; char buffer[1024]; int prognamelen = n_strlen(progname); if(!pref) return; while(glk_get_line_stream(pref, buffer, sizeof(buffer))) { char *optname; char *optval; long int optnum; if(buffer[0] == '#') continue; while(buffer[0] == '[') { if(n_strncasecmp(buffer+1, progname, prognamelen) != 0 || buffer[1+prognamelen] != ']') { while(glk_get_line_stream(pref, buffer, sizeof(buffer))) if(buffer[0] == '[') break; } else { glk_get_line_stream(pref, buffer, sizeof(buffer)); } } optname = buffer; while(isspace(*optname)) optname++; if((optval = n_strchr(optname, '=')) != NULL) { char *p; *optval = 0; optval++; if((p = n_strchr(optname, ' ')) != NULL) *p = 0; while(isspace(*optval)) optval++; while(isspace(optval[strlen(optval)-1])) optval[strlen(optval)-1] = 0; optnum = n_strtol(optval, NULL, 0); if(n_strcasecmp(optval, "false") == 0 || n_strcasecmp(optval, "f") == 0) optnum = FALSE; if(n_strcasecmp(optval, "true") == 0 || n_strcasecmp(optval, "t") == 0) optnum = TRUE; for(n = 0; n < sizeof(options) / sizeof(*options); n++) { if(n_strcmp(options[n].longname, optname) == 0) { switch(options[n].type) { case option_flag: case option_number: options[n].int_func(optnum); break; case option_file: options[n].str_func(startup_open(optval)); break; case option_wfile: options[n].str_func(startup_wopen(optval)); break; case option_string: options[n].string_func(optval); break; } break; } } } } glk_stream_close(pref, NULL); }
static void code_terpver(const char *string) #line 79 "nitfol.opt" { if(string) { if(n_strlen(string) == 1) interp_ver = *string; else interp_ver = n_strtol(string, NULL, 10); } }
glui32 intd_get_size(void) { if(!game_filename) return 0; return n_strlen(game_filename) + 12; }