예제 #1
0
파일: proquint.c 프로젝트: TKorr/c-ipfs
/**
* Decodes an identifier into its corresponding byte slice.
*
* @param {string} str Identifier to convert.
*
* @return {[]byte} The identifier as a byte slice.
*/
char *ipfs_proquint_decode(char *str)
{
    char *ret;
    int i, c, l = strlen(str);
    uint16_t x;

    // make sure its a valid Proquint string.
    if (!ipfs_proquint_is_proquint(str) && ((l+1) % 3)==0) {
        return NULL;
    }

    ret = malloc((l+1)/3);
    if (!ret) {
        return NULL;
    }

    for (i = 0, c = 0 ; i < l ; i += 6) {
        x =(consd(str[i + 0]) << 12) | \
           (vowsd(str[i + 1]) << 10) | \
           (consd(str[i + 2]) <<  6) | \
           (vowsd(str[i + 3]) <<  4) | \
           (consd(str[i + 4]) <<  0);

        ret[c++] = x >> 8;
        ret[c++] = x & 0xff;
    }

    return ret;
}
예제 #2
0
파일: xlsym.c 프로젝트: 8l/csolve
/* xlenter - enter a symbol into the obarray */
NODE *xlenter(char *name,int type)
{
    NODE ***oldstk,*sym __HEAPIFY,*array;
    int i;

    /* check for nil */
    if (strcmp(name,"NIL") == 0)
	return (NIL);

    /* check for symbol already in table */
    array = getvalue(obarray);
    i = hash(name,HSIZE);
    for (sym = getelement(array,i); sym; sym = cdr(sym))
	if (strcmp(name,getstring(getpname(car(sym)))) == 0)
	    return (car(sym));

    /* make a new symbol node and link it into the list */
    oldstk = xlsave1(&sym);
    sym = consd(getelement(array,i));
    rplaca(sym,xlmakesym(name,type));
    setelement(array,i,sym);
    xlstack = oldstk;

    /* return the new symbol */
    return (car(sym));
}
예제 #3
0
파일: xlsym.c 프로젝트: AaronFae/VimProject
/* xlenter - enter a symbol into the obarray */
LVAL xlenter(char *name)
{
    LVAL sym,array;
    int i;

    /* check for nil */
    if (strcmp(name,"NIL") == 0)
        return (NIL);

    /* check for symbol already in table */
    array = getvalue(obarray);
    i = hash(name,HSIZE);
    for (sym = getelement(array,i); sym; sym = cdr(sym))
        if (strcmp(name,(char *) getstring(getpname(car(sym)))) == 0)
            return (car(sym));

    /* make a new symbol node and link it into the list */
    xlsave1(sym);
    sym = consd(getelement(array,i));
    rplaca(sym,xlmakesym(name));
    setelement(array,i,sym);
    xlpop();

    /* return the new symbol */
    return (car(sym));
}
예제 #4
0
xlbind(NODE *sym, NODE *val, NODE *env)
{
NODE *ptr;
ptr = consd(((env)->n_info.n_xlist.xl_car));
((env)->n_info.n_xlist.xl_car = (ptr));
((ptr)->n_info.n_xlist.xl_car = (cons(sym,val)));
}
예제 #5
0
파일: xlsym.c 프로젝트: 8l/csolve
/* xlbind - bind a value to a symbol */
void xlbind(NODE *sym,NODE *val,NODE *env)
{
    NODE *ptr;

    /* create a new environment list entry */
    ptr = consd(car(env));
    rplaca(env,ptr);

    /* create a new variable binding */
    rplaca(ptr,cons(sym,val));
}
예제 #6
0
NODE *xlenter(char *name, int type)
{
NODE ***oldstk,*sym,*array;
int i;
if (strcmp(name,"NIL") == 0)
return ((NODE *)0);
array = ((obarray)->n_info.n_xsym.xsy_value);
i = hash(name,199);
for (sym = ((array)->n_info.n_xvect.xv_data[i]); sym; sym = ((sym)->n_info.n_xlist.xl_cdr))
if (strcmp(name,((((((sym)->n_info.n_xlist.xl_car))->n_info.n_xsym.xsy_plist->n_info.n_xlist.xl_car))->n_info.n_xstr.xst_str)) == 0)
return (((sym)->n_info.n_xlist.xl_car));
oldstk = xlsave(&sym,(NODE **)0);
sym = consd(((array)->n_info.n_xvect.xv_data[i]));
((sym)->n_info.n_xlist.xl_car = (xlmakesym(name,type)));
((array)->n_info.n_xvect.xv_data[i] = (sym));
xlstack = oldstk;
return (((sym)->n_info.n_xlist.xl_car));
}
예제 #7
0
파일: proquint.c 프로젝트: TKorr/c-ipfs
/**
* Tests if a given string is a Proquint identifier
*
* @param {string} str The candidate string.
*
* @return {bool} Whether or not it qualifies.
* @return {error} Error
*/
int ipfs_proquint_is_proquint(char *str)
{
    int i, c, l = strlen(str);

    // if str is null, or length is invalid
    if (!str || ((l+1) % 6)) {
        return 0; // it's not a proquint
    }

    // run every position
    for (i = 0 ; i < l ; i++) {
        if (((i+1) % 6) == 0) {      // After each 5 characters
            if (str[i] != '-') { // need a -
                return 0;        // or it's not a proquint
            }
        } else {
            switch ((i+1) % 2) { // i + 1 to avoid zero division
                case 0:
                    // compare with vowse array
                    c = vowsd(str[i]);
                    if (str[i] != vowse[c]) {

                        return 0; // it's not a proquint
                    }
                    break;
                default:
                    // compare with conse array
                    c = consd(str[i]);
                    if (str[i] != conse[c]) {
                        return 0; // it's not a proquint
                    }
            }
        }
    }

    return 1; // passed on every value.
}
예제 #8
0
파일: xlsym.c 프로젝트: 8l/csolve
/* xlframe - create a new environment frame */
NODE *xlframe(NODE *env)
{
    return (consd(env));
}