Crossfire Server, Trunk  R20513
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 
36 void common_ob_describe(const ob_methods *context, const object *op, const object *observer, char *buf, size_t size) {
37  char *desc;
38 
39  buf[0] = '\0';
40 
41  if (op == NULL)
42  return;
43 
44  desc = stringbuffer_finish(describe_item(op, observer, 0, NULL));
45  if (desc[0] != '\0') {
46  size_t len;
47 
48  query_name(op, buf, size-1);
49  buf[size-1] = 0;
50  len = strlen(buf);
51  if ((len+5) < size) {
52  /* Since we know the length, we save a few cpu cycles by using
53  * it instead of calling strcat */
54  strcpy(buf+len, " ");
55  len++;
56  strncpy(buf+len, desc, size-len-1);
57  buf[size-1] = 0;
58  }
59  }
60  free(desc);
61  if (buf[0] == '\0') {
62  query_name(op, buf, size-1);
63  buf[size-1] = 0;
64  }
65 }
Typedefs for ob_methods.
Definition: ob_methods.h:45
Global type definitions and header inclusions.
void common_ob_describe(const ob_methods *context, const object *op, const object *observer, char *buf, size_t size)
Describes an object, seen by a given observer.
Definition: describe.c:36
Object type variables.
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Describes an item, in all its details.
Definition: item.c:980
void query_name(const object *op, char *buf, size_t size)
Describes an item.
Definition: item.c:625
Object type functions and variables.
char * stringbuffer_finish(StringBuffer *sb)
Deallocate the string buffer instance and return the string.
Definition: stringbuffer.c:76