}
-INLINE ident *id_from_str (const char *str, int len) {
+INLINE ident *id_from_str (const char *str, int len)
+{
assert (len > 0);
- return (const set_entry *) set_hinsert (id_set,
- (str),
- (len),
- ID_HASH ((str), (len)));
+ return (ident *)set_hinsert(id_set, str, len, ID_HASH(str, len));
}
INLINE const char *id_to_str (ident *id) {
- return ((const char *)&(id)->dptr[0]);
+ return (const char *)id->dptr;
}
INLINE int id_to_strlen(ident *id) {
- return ((id)->size);
+ return id->size;
}
int id_is_prefix (ident *prefix, ident *id) {
if (id_to_strlen(prefix) > id_to_strlen(id)) return 0;
- if (0 == memcmp(&(prefix->dptr[0]), &(id->dptr[0]), id_to_strlen(prefix)))
- return 1;
- return 0;
+ return 0 == memcmp(prefix->dptr, id->dptr, id_to_strlen(prefix));
}
int id_is_suffix (ident *suffix, ident *id) {
int suflen = id_to_strlen(suffix);
- int idlen = id_to_strlen(id);
+ int idlen = id_to_strlen(id);
char *part;
+
if (suflen > idlen) return 0;
- part = (char *) &id->dptr[0];
+ part = (char *)id->dptr;
part = part + (idlen - suflen);
- if (0 == memcmp(&(suffix->dptr[0]), part, suflen))
- return 1;
- return 0;
+
+ return 0 == memcmp(suffix->dptr, part, suflen);
}
int print_id (ident *id) {
- xprintf("%I", id);
- return(0);
+ return xprintf("%I", id);
}
int fprint_id (FILE *F, ident *id) {
- xfprintf(F, "%I", id);
- return(0);
+ return xfprintf(F, "%I", id);
}
/* Identifiers */
/**
- * the abstract data type ident
+ * The abstract data type ident.
+ *
+ * An ident repraesents an unique string. The == operator
+ * is sufficient to compare two idents.
*/
typedef const struct set_entry ident;
/**
* Store a string and create an ident.
+ *
* Stores a string in the ident module and returns a handle for the string.
* Copies the string.
*
*
* @return id - a handle for the generated ident
*
- * @see id_to_str, id_to_strlen
+ * @see id_to_str(), id_to_strlen()
*/
INLINE ident *id_from_str (const char *str, int len);
/**
* Returns a string represented by an ident.
- * Returns the string cp represented by id. This string cp is not
+ *
+ * Returns the string represented by id. This string is not
* NULL terminated! The string may not be changed.
*
* @param id - the ident
*
* @return cp - a string
*
- * @see id_from_str, id_to_strlen
+ * @see id_from_str(), id_to_strlen()
*/
INLINE const char *id_to_str (ident *id);
/**
- * Returns the length of a string represented by an ident.
+ * Returns the length of the string represented by an ident.
*
* @param id - the ident
*
* @return len - the length of the string
*
- * @see id_from_str, id_to_str
+ * @see id_from_str(), id_to_str()
*/
INLINE int id_to_strlen(ident *id);
/**
- * Returns true if prefix is prefix of an ident.
+ * Returns true if prefix is a prefix of an ident.
*
* @param prefix - the prefix
* @param id - the ident
*
- * @see id_from_str, id_to_str, id_is_prefix
+ * @see id_from_str(), id_to_str(), id_is_prefix()
*/
int id_is_prefix (ident *prefix, ident *id);
/**
- * Returns true if suffix is suffix of id.
+ * Returns true if suffix is a suffix of an ident.
*
* @param suffix - the suffix
* @param id - the ident
*
- * @see id_from_str, id_to_str, id_is_prefix
+ * @see id_from_str(), id_to_str(), id_is_prefix()
*/
int id_is_suffix (ident *suffix, ident *id);
/**
* Prints the ident to stdout.
*
- * @param id - The ident to print.
+ * @param id - The ident to be printed.
*
- * @see id_from_str, id_to_str, id_is_prefix, fprint_id
+ * @return
+ * number of btes written
+ *
+ * @see id_from_str(), id_to_str(), id_is_prefix(), fprint_id()
*/
int print_id (ident *id);
* @param F - file pointer to print the ident to.
* @param id - The ident to print and the file.
*
- * @see id_from_str, id_to_str, id_is_prefix, print_id
+ * @return
+ * number of btes written
+ *
+ * @see id_from_str(), id_to_str(), id_is_prefix(), print_id()
*/
int fprint_id (FILE *F, ident *id);