/*-------------------------------------------------------------------------*/ void save_error (const char *msg, const char *file, int line) /* A runtime error <msg> occured for object <file> in line number <line>. * Store this information in the wizlist so that the mudlib can handle * it later with the efun get_error_file(). * TODO: A proper runtime error handling could put this into the mudlib * TODO:: completely. */ { wiz_list_t *wl; char *copy, *p; string_t *name; size_t len; /* Get the wizard name and the wizlist entry. */ name = get_wiz_name(file); if (!name) return; wl = add_name(name); /* Set the file_name */ if (wl->file_name) free_mstring(wl->file_name); len = strlen(file); copy = alloca(len + 4); /* May add .c plus the null byte, and / */ *copy = '/'; strcpy(copy+1, file); /* If it is a cloned object, we have to find out what the file * name is, and add '.c'. */ if ( NULL != (p = strrchr(copy, '#')) || ((p = copy+len), *p++ != 'c') || p[-2] != '.' ) { p[0] = '.'; p[1] = 'c'; p[2] = '\0'; } wl->file_name = new_mstring(copy); /* Set the error_message */ if (wl->error_message) free_mstring(wl->error_message); wl->error_message = new_mstring(msg); /* Set the line_number */ wl->line_number = line; } /* save_error() */
/*-------------------------------------------------------------------------*/ svalue_t * f_tls_error(svalue_t *sp) /* EFUN tls_error() * * string tls_error(int errorno) * * tls_error() returns a string describing the error behind the * error number <errorno>. */ { string_t *s; const char *text; int err = sp->u.number; text = tls_error(err); if (text) { memsafe(s = new_mstring(text), strlen(text), "tls_error()"); free_svalue(sp); put_string(sp, s); } else { free_svalue(sp); put_number(sp, 0); } return sp; } /* f_tls_error() */
/*-------------------------------------------------------------------------*/ string_t * struct_t_unique_name (struct_type_t *pSType) /* Also aliased to: struct_unique_name(struct_t *) * * Compose and return the unique name of struct type <pSType>. * The returned string reference is not counted. * * The value save/restore routines rely on the format of this string. */ { char name[MAXPATHLEN+256]; if (pSType->unique_name) return pSType->unique_name; snprintf(name, sizeof(name), "%s %s #%"PRId32 , get_txt(struct_t_name(pSType)) , get_txt(struct_t_pname(pSType)) , struct_t_pid(pSType) ); pSType->unique_name = new_mstring(name); return pSType->unique_name; } /* struct_t_unique_name() */
/*-------------------------------------------------------------------------*/ void load_wiz_file (void) /* Load the old wizlist from the wizlist file and add it's data to * the wizlist already in memory. * * This function is called at driver start up. * TODO: Since the wizlist is saved from the mudlib, this function * TODO:: should be implemented on mudlib level, too. */ { char buff[1000]; FILE *f; if (wizlist_name[0] == '\0') return; f = fopen(wizlist_name, "r"); if (f == NULL) return; while (fgets(buff, sizeof buff, f) != NULL) { char *p; uint32 score; p = strchr(buff, ' '); if (p == 0) { fprintf(stderr, "%s Bad WIZLIST file '%s'.\n" , time_stamp(), wizlist_name); break; } *p = '\0'; p++; if (*p == '\0') { fprintf(stderr, "%s Bad WIZLIST file '%s'.\n" , time_stamp(), wizlist_name); break; } score = atoi(p); if (score > 0) { string_t * tmp; tmp = new_mstring(buff); add_name(tmp)->score += score; free_mstring(tmp); } } fclose(f); } /* load_wiz_file() */