Example #1
0
char*
scsierror(int asc, int ascq)
{
	char *p, *q;
	static char search[32];
	static char buf[128];

	getcodes();

	if(codes) {
		sprint(search, "\n%.2ux%.2ux ", asc, ascq);
		if(p = strstr(codes, search)) {
			p += 6;
			if((q = strchr(p, '\n')) == nil)
				q = p+strlen(p);
			snprint(buf, sizeof buf, "%.*s", (int)(q-p), p);
			return buf;
		}

		sprint(search, "\n%.2ux00", asc);
		if(p = strstr(codes, search)) {
			p += 6;
			if((q = strchr(p, '\n')) == nil)
				q = p+strlen(p);
			snprint(buf, sizeof buf, "(ascq #%.2ux) %.*s", ascq, (int)(q-p), p);
			return buf;
		}
	}

	sprint(buf, "scsi #%.2ux %.2ux", asc, ascq);
	return buf;
}
Example #2
0
{
    map<char, int> freq = calcfreq(s);

    map<char, node*> position;
    
    node *p;
    foreach(v, freq) {    
        node *p = maketree(v->second);
        position[v->first] = p;
        rootnodes.push(p);
    }
        
    buildtree();

    map<char, string> codes;
    codes = getcodes(position);

    string hfcode = "";
    rep(i, 0, s.length()) {
        hfcode += codes[s[i]];
    }

    return hfcode;
}

/**
 * Return the pointer to the newly allocated node
 */
node* Huffman::maketree(int data) 
{
    node *p = new node;