static void run_weather() { enum Joystick_dir curJoy = getJoyDirection(); switch (curJoy) { case RIGHT: get_weather(B_WEATHER_CURR); print_weather("Current Weather\n", "^ Forecast"); break; case LEFT: get_weather(B_WEATHER_FOR); print_weather("Forecast\n", "v Current Weather"); break; case IN: next_state = MAIN_WATCH; break; default: break; } }
void look_object(struct char_data *ch, struct gameobject *obj, const char *argument) { struct gameobject *portal; struct room_index_data *location; if (!validate_look(ch)) { return; } switch (obj->item_type) { default: send_to_char("That is not a container.\n\r", ch); break; case ITEM_DRINK_CON: if (obj->value[1] == 0) { send_to_char("It is empty.\n\r", ch); } else { printf_to_char(ch, "It's %sfilled with a %s liquid.\n\r", obj->value[1] < obj->value[0] / 4 ? "less than half-" : obj->value[1] < 3 * obj->value[0] / 4 ? "about half-" : "more than half-", liq_table[obj->value[2]].liq_color); } break; case ITEM_CONTAINER: case ITEM_CORPSE_NPC: case ITEM_CORPSE_PC: if (IS_SET(obj->value[1], CONT_CLOSED)) { send_to_char("It is closed.\n\r", ch); } else { act("$p holds```8:``", ch, obj, NULL, TO_CHAR); show_list_to_char(obj->contains, ch, true, true); } break; case ITEM_PORTAL: portal = get_obj_list(ch, argument, ch->in_room->contents); if (portal != NULL) { location = get_room_index(portal->value[3]); if (location == NULL) { send_to_char("It looks very empty..\n\r", ch); } else { send_to_char(location->name, ch); send_to_char("\n\r", ch); if (!IS_SET(location->room_flags, ROOM_INDOORS)) print_weather(ch); else send_to_char("You can not discern weather conditions beyond this portal.\n\r", ch); if (!IS_NPC(ch) && !IS_SET(ch->comm, COMM_BRIEF)) { send_to_char(location->description, ch); } send_to_char("\n\r", ch); if (!IS_NPC(ch) && IS_SET(ch->act, PLR_AUTOEXIT)) { char showexit[100]; sprintf(showexit, "%ld exits auto", location->vnum); do_at(ch, showexit); } show_list_to_char(location->contents, ch, false, false); show_char_to_char(location->people, ch); } } break; } }
int parse_weather_google(weather_t *w, char *buffer_orig){ const char *section, *p,*p2; iconv_t cd; size_t insize,outsize; char buffer[MAX_BUF*4]="",*b1,*b2; cd = iconv_open ("UTF-8",charset); if( cd == (iconv_t)-1){ /* failed to convert! */ return RSS_RETRY; /*!!!!!!!!!!!!!!!!!!!!!!!!*/ } /* covert! */ insize=strlen(buffer_orig); outsize=MAX_BUF*4; b1=buffer_orig; b2=buffer; iconv(cd, NULL,NULL, &b2,&outsize); iconv(cd, &b1, &insize, &b2,&outsize); iconv_close(cd); mylog("GOOGLE: %s\n\n",buffer); if(NULL!=(section=strstr(buffer,"<current_conditions>"))){ /* found conditions section */ if(NULL!=(p=strstr(section,"<condition "))){ p=strstr(p,"\"")+1; p2=strstr(p,"\""); if((p!=NULL) &&(p2!=NULL)){ if(w->now_weather_text==NULL) {w->now_weather_text=malloc(1);w->now_weather_text[0]='\0';} if(strncmp(w->now_weather_text,p,p2-p)){ if(w->now_weather_text) free(w->now_weather_text); w->now_weather_text=malloc(p2-p+1); strncpy(w->now_weather_text,p,p2-p); w->now_weather_text[p2-p]='\0'; } } else{ return RSS_RETRY;} } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<icon "))){ p=strstr(p,"\"")+1; p2=strstr(p,"\""); if((p!=NULL) &&(p2!=NULL)){ if(w->now_weather_icon==NULL) {w->now_weather_icon=malloc(1);w->now_weather_icon[0]='\0';} if(strncmp(w->now_weather_icon,p,p2-p)){ if(w->now_weather_icon) free(w->now_weather_icon); w->now_weather_icon=malloc(p2-p+1); strncpy(w->now_weather_icon,p,p2-p); w->now_weather_icon[p2-p]='\0'; w->now_image_index=get_icon_index(w->now_weather_icon); } } else{ return RSS_RETRY;} } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<temp_c"))){ p=strstr(p,"\"")+1; p2=strstr(p,"\""); sscanf(p,"%d",&(w->now_celsium)); } else{ return RSS_RETRY;} } /* current cond */ if(NULL!=(section=strstr(buffer,"<forecast_conditions>"))){ /* found first forecast section */ if(NULL!=(p=strstr(section,"<condition data"))){ p=strstr(p,"\"")+1; p2=strstr(p,"\""); if((p!=NULL) &&(p2!=NULL)){ if(w->today_forecast_text==NULL) {w->today_forecast_text=malloc(1);w->today_forecast_text[0]='\0';} if(strncmp(w->today_forecast_text,p,p2-p)){ if(w->today_forecast_text) free(w->today_forecast_text); w->today_forecast_text=malloc(p2-p+1); strncpy(w->today_forecast_text,p,p2-p); w->today_forecast_text[p2-p]='\0'; } } else{ return RSS_RETRY;} } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<icon "))){ p=strstr(p,"\"")+1; p2=strstr(p,"\""); if((p!=NULL) &&(p2!=NULL)){ if(w->today_forecast_icon==NULL) {w->today_forecast_icon=malloc(1);w->today_forecast_icon[0]='\0';} if(strncmp(w->today_forecast_icon,p,p2-p)){ if(w->today_forecast_icon) free(w->today_forecast_icon); w->today_forecast_icon=malloc(p2-p+1); strncpy(w->today_forecast_icon,p,p2-p); w->today_forecast_icon[p2-p]='\0'; w->today_image_index=get_icon_index(w->today_forecast_icon); } } else{ return RSS_RETRY;} } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<high "))){ p=strstr(p,"\"")+1; sscanf(p,"%d",&(w->today_celsium_high)); } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<low "))){ p=strstr(p,"\"")+1; sscanf(p,"%d",&(w->today_celsium_low)); } else{ return RSS_RETRY;} } /* today forecast */ if(NULL!=(section=strstr(p+1,"<day_of_week"))){ /* found second forecast section */ if(NULL!=(p=strstr(section,"<condition data"))){ p=strstr(p,"\"")+1; p2=strstr(p,"\""); if((p!=NULL) &&(p2!=NULL)){ if(w->tomorrow_forecast_text==NULL){ w->tomorrow_forecast_text=malloc(1); w->tomorrow_forecast_text[0]='\0'; } if(strncmp(w->tomorrow_forecast_text,p,p2-p)){ if(w->tomorrow_forecast_text) free(w->tomorrow_forecast_text); w->tomorrow_forecast_text=malloc(p2-p+1); strncpy(w->tomorrow_forecast_text,p,p2-p); w->tomorrow_forecast_text[p2-p]='\0'; } } else{ return RSS_RETRY;} } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<icon "))){ p=strstr(p,"\"")+1; p2=strstr(p,"\""); if((p!=NULL) &&(p2!=NULL)){ if(w->tomorrow_forecast_icon==NULL){ w->tomorrow_forecast_icon=malloc(1); w->tomorrow_forecast_icon[0]='\0'; } if(strncmp(w->tomorrow_forecast_icon,p,p2-p)){ if(w->tomorrow_forecast_icon) free(w->tomorrow_forecast_icon); w->tomorrow_forecast_icon=malloc(p2-p+1); strncpy(w->tomorrow_forecast_icon,p,p2-p); w->tomorrow_forecast_icon[p2-p]='\0'; w->tomorrow_image_index=get_icon_index(w->tomorrow_forecast_icon); } } else{ return RSS_RETRY;} } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<high "))){ p=strstr(p,"\""); sscanf(p+1,"%d",&(w->tomorrow_celsium_high)); } else{ return RSS_RETRY;} if(NULL!=(p=strstr(section,"<low "))){ p=strstr(p,"\""); sscanf(p+1,"%d",&(w->tomorrow_celsium_low)); } else{ return RSS_RETRY;} } /* tomorrow forecast */ if(w->now_image_index==-1 || w->today_image_index == -1 || w->tomorrow_image_index ==-1){ return IMAGE_RETRY; } #ifdef DEBUG print_weather(w); #endif return 0; }
//!!!!!!!!!!!!! yahoo int parse_weather_yahoo(weather_t *w, char *buffer_orig){ int code,retcode=0; char img_buf[MAX_BUF]; mxml_node_t *top, *tree, *node; const char *text; top = mxmlLoadString(NULL, buffer_orig, MXML_TEXT_CALLBACK); tree = mxmlFindElement(top, top, "item",NULL,NULL,MXML_DESCEND); node = mxmlFindElement(tree, top, "yweather:condition",NULL,NULL,MXML_DESCEND); text=mxmlElementGetAttr(node,"code"); code=get_code(text); mylog("Now code=%02d\n",code); if(code==NO_CODE) return RSS_RETRY; w->now_weather_text=codes[lang][code+1]; sprintf(img_buf,BASE_URL "%02d.gif",code); w->now_image_index=get_icon_index(img_buf); if(w->now_image_index==0) retcode=IMAGE_RETRY; else if(w->today_image_index<0) retcode=0; text=mxmlElementGetAttr(node,"temp"); sscanf(text,"%d",&(w->now_celsium)); node = mxmlFindElement(tree, top, "yweather:forecast",NULL,NULL,MXML_DESCEND); text=mxmlElementGetAttr(node,"code"); code=get_code(text); mylog("Today code=%02d\n",code); if(code==NO_CODE) return RSS_RETRY; w->today_forecast_text=codes[lang][code+1]; sprintf(img_buf,BASE_URL "%02d.gif",code); w->today_image_index=get_icon_index(img_buf); if(w->today_image_index==0) retcode=IMAGE_RETRY; else if(w->today_image_index<0) retcode=0; text=mxmlElementGetAttr(node,"low"); sscanf(text,"%d",&(w->today_celsium_low)); text=mxmlElementGetAttr(node,"high"); sscanf(text,"%d",&(w->today_celsium_high)); node = mxmlFindElement(node, top, "yweather:forecast",NULL,NULL,MXML_DESCEND); // node = mxmlFindElement(node, top, "yweather:forecast",NULL,NULL,MXML_NO_DESCEND); // node = mxmlWalkNext(node, top,MXML_NO_DESCEND); text=mxmlElementGetAttr(node,"code"); code=get_code(text); if(code==NO_CODE) return RSS_RETRY; w->tomorrow_forecast_text=codes[lang][code+1]; sprintf(img_buf,BASE_URL "%02d.gif",code); w->tomorrow_image_index=get_icon_index(img_buf); // w->tomorrow_image_index=code; if(w->tomorrow_image_index==0) retcode=IMAGE_RETRY; else if(w->today_image_index<0) retcode=0; text=mxmlElementGetAttr(node,"low"); sscanf(text,"%d",&(w->tomorrow_celsium_low)); text=mxmlElementGetAttr(node,"high"); sscanf(text,"%d",&(w->tomorrow_celsium_high)); #ifdef YAHOO_DYNAMIC_ICON_LOAD node = mxmlFindElement(tree, tree, "description",NULL,NULL,MXML_DESCEND); node=mxmlGetFirstChild(node); text=mxmlGetElement(node); img=strstr(text,"<img src=\""); if(img==NULL) return RSS_RETRY; img+=10; strncpy(img_buf,img,MAX_BUF); end=strstr(img_buf,"\""); if(end==NULL) return RSS_RETRY; *end='\0'; if(w->now_weather_icon==NULL) {w->now_weather_icon=malloc(1);w->now_weather_icon[0]='\0';} len=strlen(img_buf)+1; if(strncmp(w->now_weather_icon,img_buf,len)){ if(w->now_weather_icon) free(w->now_weather_icon); w->now_weather_icon=malloc(len); strncpy(w->now_weather_icon,img_buf,len); w->now_weather_icon[len]='\0'; w->now_image_index=get_icon_index(w->now_weather_icon); } #endif #ifdef DEBUG print_weather(w); #endif return retcode; }
static void start_weather() { get_weather(B_WEATHER_CURR); print_weather("Current Weather\n", "^ Forecast"); }