示例#1
0
文件: qhashtbl.c 项目: Cybsloth/qlibc
/**
 * qhashtbl->debug(): Print hash table for debugging purpose
 *
 * @param tbl   qhashtbl_t container pointer.
 * @param out   output stream
 *
 * @return true if successful, otherwise returns false.
 * @retval errno will be set in error condition.
 *  - EIO : Invalid output stream.
 */
bool qhashtbl_debug(qhashtbl_t *tbl, FILE *out) {
    if (out == NULL) {
        errno = EIO;
        return false;
    }

    qhashtbl_obj_t obj;
    memset((void *) &obj, 0, sizeof(obj));  // must be cleared before call
    qhashtbl_lock(tbl);
    while (tbl->getnext(tbl, &obj, false) == true) {
        fprintf(out, "%s=", obj.name);
        _q_textout(out, obj.data, obj.size, MAX_HUMANOUT);
        fprintf(out, " (%zu, hash=%u)\n", obj.size, obj.hash);
    }
    qhashtbl_unlock(tbl);

    return true;
}
示例#2
0
文件: qlist.c 项目: Cybsloth/qlibc
/**
 * qlist->debug(): Prints out stored elements for debugging purpose.
 *
 * @param list  qlist_t container pointer.
 * @param out   output stream FILE descriptor such like stdout, stderr.
 *
 * @return true if successful, otherwise returns false.
 * @retval errno will be set in error condition.
 *  -EIO  : Invalid output stream.
 */
bool qlist_debug(qlist_t *list, FILE *out) {
    if (out == NULL) {
        errno = EIO;
        return false;
    }

    qlist_lock(list);
    qlist_obj_t *obj;
    int i;
    for (i = 0, obj = list->first; obj; obj = obj->next, i++) {
        fprintf(out, "%d=", i);
        _q_textout(out, obj->data, obj->size, MAX_HUMANOUT);
        fprintf(out, " (%zu)\n", obj->size);
    }
    qlist_unlock(list);

    return true;
}
示例#3
0
文件: qhasharr.c 项目: Masshat/qlibc
/**
 * qhasharr->debug(): Print hash table for debugging purpose
 *
 * @param tbl       qhasharr_t container pointer.
 * @param out       output stream
 *
 * @return true if successful, otherwise returns false
 * @retval errno will be set in error condition.
 *  - EIO       : Invalid output stream.
 */
bool qhasharr_debug(qhasharr_t *tbl, FILE *out) {
    if (tbl == NULL) {
        errno = EINVAL;
        return false;
    }

    if (out == NULL) {
        errno = EIO;
        return false;
    }

    qhasharr_slot_t *tblslots = get_slots(tbl);

    int idx = 0;
    qhasharr_obj_t obj;
    while (tbl->getnext(tbl, &obj, &idx) == true) {
        uint16_t namesize = tblslots[idx - 1].data.pair.namesize;
        _q_textout(out, obj.name, obj.namesize, MAX_HUMANOUT);
        fprintf(out, "%s(%d)=", (namesize > Q_HASHARR_NAMESIZE) ? "..." : "",
                namesize);
        _q_textout(out, obj.data, obj.datasize, MAX_HUMANOUT);
        fprintf(out, " (%zu)\n", obj.datasize);

        free(obj.name);
        free(obj.data);
    }

#ifdef BUILD_DEBUG
    qhasharr_data_t *tbldata = tbl->data;
    fprintf(out, "%d elements (slot %d used/%d total)\n",
            tbldata->num, tbldata->usedslots, tbldata->maxslots);
    for (idx = 0; idx < tbldata->maxslots; idx++) {
        if (tblslots[idx].count == 0) continue;

        fprintf(out, "slot=%d,type=", idx);
        if (tblslots[idx].count == EXTBLOCK_MARK) {
            fprintf(out, "EXTEND");
            fprintf(out, ",prev=%d", tblslots[idx].hash);
            fprintf(out, ",next=%d", tblslots[idx].link);
            fprintf(out, ",datasize=%d", tblslots[idx].datasize);
            fprintf(out, ",data=");
            _q_textout(out,
                    tblslots[idx].data.ext.data,
                    tblslots[idx].datasize,
                    MAX_HUMANOUT);
        } else {
            fprintf(out, "%s", (tblslots[idx].count == COLLISION_MARK)?"COLISN":"NORMAL");
            fprintf(out, ",next=%d", tblslots[idx].link);
            fprintf(out, ",count=%d", tblslots[idx].count);
            fprintf(out, ",hash=%u", tblslots[idx].hash);
            fprintf(out, ",namesize=%d", tblslots[idx].data.pair.namesize);
            fprintf(out, ",datasize=%d", tblslots[idx].datasize);
            fprintf(out, ",name=");
            _q_textout(out,
                    tblslots[idx].data.pair.name,
                    (tblslots[idx].data.pair.namesize>Q_HASHARR_NAMESIZE)
                    ? Q_HASHARR_NAMESIZE
                    : tblslots[idx].data.pair.namesize,
                    MAX_HUMANOUT);
            fprintf(out, ",data=");
            _q_textout(out,
                    tblslots[idx].data.pair.data,
                    tblslots[idx].datasize,
                    MAX_HUMANOUT);
        }
        fprintf(out, "\n");
    }
#endif

    return true;
}