Crossfire Server, Trunk  R22047
describe.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
20 #include "global.h"
21 
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #include "ob_methods.h"
26 #include "ob_types.h"
27 
37 void common_ob_describe(const ob_methods *context, const object *op, const object *observer, int use_media_tags, char *buf, size_t size) {
38  char *desc;
39 
40  buf[0] = '\0';
41 
42  if (op == NULL)
43  return;
44 
45  desc = stringbuffer_finish(describe_item(op, observer, use_media_tags, NULL));
46  if (desc[0] != '\0') {
47  size_t len;
48 
49  query_name(op, buf, size-1);
50  buf[size-1] = 0;
51  len = strlen(buf);
52  if ((len+5) < size) {
53  /* Since we know the length, we save a few cpu cycles by using
54  * it instead of calling strcat */
55  strcpy(buf+len, " ");
56  len++;
57  strncpy(buf+len, desc, size-len-1);
58  buf[size-1] = 0;
59  }
60  }
61  free(desc);
62  if (buf[0] == '\0') {
63  query_name(op, buf, size-1);
64  buf[size-1] = 0;
65  }
66 }
StringBuffer * buf
Definition: readable.c:1591
void common_ob_describe(const ob_methods *context, const object *op, const object *observer, int use_media_tags, char *buf, size_t size)
Definition: describe.c:37
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Definition: item.c:935
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:583
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.c:76