static variable_t *__declare_variable(token_t *name_tok, token_t *type_tok, int type_len, int gen_code) { if (COMP_DESCR.current_parent != NULL) { sprintf(COMP_DESCR.err_msg, "cannot declare variables inside condition fields ..."); return NULL; } char name[32]; tok_strcpy(name, name_tok); if (var_get_variable(COMP_DESCR.current_field->vars, name) != NULL) { sprintf(COMP_DESCR.err_msg, "variable '%s' already declared ...", name); return NULL; } var_type_t *v_type = var_get_var_type(type_tok, type_len); if (v_type == NULL) { sprintf(COMP_DESCR.err_msg, "variable '%s': unknown datatype ...", name); return NULL; } if (v_type->type == VAR_TYPE_VOID) { sprintf(COMP_DESCR.err_msg, "variable '%s': datatype not allowed ...", name); return NULL; } variable_t *var = var_add_variable(&COMP_DESCR.current_field->vars, name, v_type, NULL, NULL, NULL); if (!gen_code) return var; if (COMP_DESCR.current_field->type == FIELD_GLOBAL) { sprintf( COMP_DESCR.buffer, "_glb_var_%s: .size %d\n", var->name, var_get_byte_size(v_type) ); asm_add_code(&COMP_DESCR.glb_data_code, comp_malloc_buffer()); sprintf( COMP_DESCR.buffer, "mov "VM_REG_VAR_LOAD", __glb_var_%s\n", var->name ); var->addr = comp_malloc_buffer(); } else if (COMP_DESCR.current_field->type == FIELD_FUNCTION) { COMP_DESCR.loc_var_size += var_get_byte_size(v_type); sprintf( COMP_DESCR.buffer, "mov "VM_REG_VAR_LOAD", "VM_REG_FP"\n" "sub "VM_REG_VAR_LOAD", %d\n", COMP_DESCR.loc_var_size ); var->addr = comp_malloc_buffer(); } /* generate load asm-code */ switch (var->type->type) { case (VAR_TYPE_BYTE): sprintf( COMP_DESCR.buffer, "%s" "ldb "VM_REG_VAR_LOAD", "VM_REG_VAR_LOAD"\n", var->addr ); break; case (VAR_TYPE_WORD): sprintf( COMP_DESCR.buffer, "%s" "ldw "VM_REG_VAR_LOAD", "VM_REG_VAR_LOAD"\n", var->addr ); break; case (VAR_TYPE_INT): case (VAR_TYPE_POINTER): case (VAR_TYPE_FLOAT): sprintf( COMP_DESCR.buffer, "%s" "ldr "VM_REG_VAR_LOAD", "VM_REG_VAR_LOAD"\n", var->addr ); break; case (VAR_TYPE_STRUCT): case (VAR_TYPE_ARRAY): sprintf( COMP_DESCR.buffer, "%s", var->addr ); break; } var->load = comp_malloc_buffer(); /* generate store asm-code */ switch (var->type->type) { case (VAR_TYPE_BYTE): sprintf( COMP_DESCR.buffer, "%s" "stb "VM_REG_VAR_STORE", "VM_REG_VAR_LOAD"\n", var->addr ); break; case (VAR_TYPE_WORD): sprintf( COMP_DESCR.buffer, "%s" "stw "VM_REG_VAR_STORE", "VM_REG_VAR_LOAD"\n", var->addr ); break; case (VAR_TYPE_INT): case (VAR_TYPE_POINTER): case (VAR_TYPE_FLOAT): sprintf( COMP_DESCR.buffer, "%s" "str "VM_REG_VAR_STORE", "VM_REG_VAR_LOAD"\n", var->addr ); break; } if (var->type->type != VAR_TYPE_STRUCT && var->type->type != VAR_TYPE_ARRAY) var->store = comp_malloc_buffer(); return var; }
char * decode_notice(ZNotice_t *notice, char *hostname) { char *temp; string when, notyear, year, date_string, time_string; /* * Convert useful notice fields to ascii and store away in * description language variables for later use by the * the user's program: */ var_set_variable("zephyr_version", notice->z_version); var_set_variable("class", notice->z_class); var_set_variable("instance", notice->z_class_inst); var_set_variable("opcode", notice->z_opcode); var_set_variable("default", notice->z_default_format); var_set_variable("notice_charset", (char *)ZCharsetToString(notice->z_charset)); /*XXX const*/ var_set_variable("recipient", (notice->z_recipient[0] ? notice->z_recipient : "*")); var_set_variable("fullsender", notice->z_sender); var_set_variable_to_number("port", (int)ntohs(notice->z_port)); var_set_variable_then_free_value("kind", z_kind_to_ascii(notice->z_kind)); var_set_variable_then_free_value("auth", z_auth_to_ascii(notice->z_auth)); #ifdef CMU_ZWGCPLUS if ((temp=getSelectedText()) != 0) var_set_variable("selection", temp); var_set_variable("delete_window", "none"); var_set_variable("event_time", "none"); var_set_variable("event_name", "event"); #endif /* * Set $sender to the name of the notice sender except first strip off the * realm name if it is the local realm: */ if ( (temp=strchr(notice->z_sender,'@')) && string_Eq(temp+1, ZGetRealm()) ) var_set_variable_then_free_value("sender", string_CreateFromData(notice->z_sender, temp-notice->z_sender)); else var_set_variable("sender", notice->z_sender); #ifdef CMU_ZWGCPLUS if (get_full_names) { struct passwd *pwnam = getpwnam(var_get_variable("sender")); if (pwnam) { temp = string_Copy(pwnam->pw_gecos); var_set_variable_then_free_value("sendername", temp); } else { var_set_variable("sendername", "unknown"); } } #endif /* * Convert time & date notice was sent to ascii. The $time * has the format "01:03:52" while $date has the format * "Sun Sep 16 1973". */ { /* the fields of struct timeval might not be the right type to pass to ctime, so use a temporary */ time_t sec = notice->z_time.tv_sec; when = ctime(&sec); } time_string = string_CreateFromData(when+11,8); var_set_variable_then_free_value("time", time_string); date_string = string_Concat(notyear=string_CreateFromData(when,11), year=string_CreateFromData(when+20,4)); var_set_variable_then_free_value("date", date_string); free(notyear); free(year); /* * Convert host notice sent from to ascii: */ var_set_variable("fromhost", hostname ? hostname : inet_ntoa(notice->z_sender_addr)); /* * Set $message to the message field of the notice with nulls changed * to newlines: */ var_set_variable_then_free_value("message", convert_nulls_to_newlines(notice->z_message, notice->z_message_len)); /* * Decide if its a control notice. If so, return the notice's * opcode. Otherwise, return NULL: */ if ((strcasecmp(notice->z_class, WG_CTL_CLASS)==0) && /* <<<>>> */ (strcasecmp(notice->z_class_inst, WG_CTL_USER)==0)) return(notice->z_opcode); return(0); }