Exemple #1
0
void test2() {
    const char* hex = "0102";
    uint8_t bytebuf[1024];
    sgs_id* id;
    int result;
    size_t i;
    
    result = hextobytes(hex, bytebuf);
    
    if (result == -1) {
        printf("Error: invalid ID string (%s).\n", hex);
        return;
    }
    
    printf("hextobytes() returned %d\n", result);
    
    if ((id = sgs_id_create(bytebuf, strlen(hex)/2, NULL)) == NULL) {
        printf("Error: invalid ID string (%s).\n", hex);
        return;
    }
    
    printf("byte: { ");
    
    for (i=0; i < sgs_id_get_byte_len(id); i++) {
        if (i > 0) printf(", ");
        printf("%d", *(sgs_id_get_bytes(id) + i));
    }
    
    printf(" }\n");
    sgs_id_destroy(id);
}
Exemple #2
0
boolean tablegetwpedittext (hdlheadrecord hnode, boolean flunload) {
	
	/*
	2/7/97 dmb: adapted from tableeditleavecell
	
	called when some action implies that the user is finished editing the cell.
	
	we attempt to save off the new value, or new name, potentially causing an 
	error if there was a duplicate name, or something bad about the value.
	*/
	
	hdltableformats hc = tableformatsdata;
	short col = (**hc).editcol;
	tybrowserspec fs;
	tyvaluerecord val;
	bigstring bstext;
	boolean fl = false;
	Handle htext;
	tyvaluerecord newval;
	Handle x;
	hdlhashtable ht;
	boolean flmustexit;
	hdlhashnode hhashnode;
	
	//assert (hnode == (**hc).editnode);
	
	flmustexit = false; // ***flmustexiteditmode;
	
	if (!wpgettexthandle (&htext))
		return (false);
	
	texthandletostring (htext, bstext);
	
	if (!claygetfilespec (hnode, &fs)) { // a new node
		
		assert (col == namecolumn);
		}
	else {

		ht = fs.parID;
		
		if (!hashtablesymbolexists (ht, fs.name)) { /*node is gone!*/
			
			fl = true;
			
			goto exit;
			}
		}
	
	if (col == namecolumn) {
		
		if (isemptystring (bstext)) /*name wasn't changed; undo will be bogus*/
			killundo ();
		else
			fl = opsetheadstring (hnode, bstext); // must do first so we can 
		
		goto exit;
		}
	
	/*we were editing a value - run a script to do the assignment*/
	
	assert (col == valuecolumn);
	
	flmustexit = true; /*don't want to stick in edit mode w/out error dialogs*/
	
	if (equalhandles (htext, (**hc).editval)) { /*no change*/
	
		fl = true;
		
		goto exit;
		}
	
	if (!claylookupvalue (&fs, &val, &hhashnode))
		goto exit;
	
	if (isemptystring (bstext) && (val.valuetype != novaluetype) && (val.valuetype != stringvaluetype)) {
		
		fl = true;
		
		goto exit;
		}
	
	if (val.valuetype == binaryvaluetype) {
	
		OSType binarytype = getbinarytypeid (val.data.binaryvalue);
		Handle hbytes;
		
		if (!hextobytes (htext, &hbytes))
			goto exit;
		
		if (!setbinaryvalue (hbytes, binarytype, &newval))
			goto exit;
		
		if (hashtableassign (ht, fs.name, newval)) {
			
			exemptfromtmpstack (&newval);
			
			fl = true;
			}
		
		goto exit;
		}
	
	if (!copyhandle (htext, &x))
		goto exit;
	
	tablepushcontext (ht, val.valuetype);
	
	disablelangerror ();
	
	shellblockevents (); /*don't want backgrounding during assignment*/
	
	#ifdef version5orgreater
	
		if (langrun (x, &newval) && (newval.valuetype != externalvaluetype) && !isemptystring (bstext))
			disposehandle (htext);
		
		else {
			if (val.valuetype != stringvaluetype && !isemptystring (bstext)) {
			
				byte ch = chdoublequote;
				
				if (copyhandle (htext, &x)) { /*2.1b2: try again, with quotes*/
					
					insertinhandle (x, 0, &ch, 1);
					
					enlargehandle (x, 1, &ch);
					
					if (langrun (x, &newval) && (newval.valuetype != externalvaluetype)) {
						
						disposehandle (htext);
						
						htext = nil;
						}
					}
				}
			
			if (htext != nil)
				setheapvalue (htext, stringvaluetype, &newval);
			}
	#else
	
		if (langrun (x, &newval) && (newval.valuetype != externalvaluetype) && !isemptystring (bstext))
			disposehandle (htext);
		
		else {
			byte ch = chdoublequote;
			
			if (copyhandle (htext, &x)) { /*2.1b2: try again, with quotes*/
				
				insertinhandle (x, 0, &ch, 1);
				
				enlargehandle (x, 1, &ch);
				
				if (langrun (x, &newval) && (newval.valuetype != externalvaluetype) && !isemptystring (bstext)) {
					
					disposehandle (htext);
					
					htext = nil;
					}
				}
			
			if (htext != nil)
				setheapvalue (htext, stringvaluetype, &newval);
			}
	#endif
	
	htext = nil; /*it's been consumed, one way or another*/
	
	shellpopevents ();
	
	if ((val.valuetype == novaluetype) || coercevalue (&newval, val.valuetype)) {
		
		if (hashtableassign (ht, fs.name, newval)) {
			
			exemptfromtmpstack (&newval);
			
			fl = true;
			}
		}
	
	enablelangerror ();
	
	if (!fl) {
		
		sysbeep ();
		
		/*disposevaluerecord (newval, false);*/
		
		cleartmpstack ();
		}
	
	tablepopcontext (ht, val.valuetype);
	
	exit:
	
	disposehandle (htext);
	
	if (flunload) { /*exiting edit mode*/
		
		disposehandle ((**hc).editval);
		
		(**hc).editval = nil;
		
		(**hc).editnode = nil;
		}
	
	return (fl);
	} /*tablegetwpedittext*/