Exemplo n.º 1
0
int hm_add(TIME duration,  DADDRESS address){
    time_t now, timeout;
    now = time(NULL);
    timeout = now + duration;
    hm_put(hashmap, address, timeout, duration);
    return 1;
}
Exemplo n.º 2
0
Arquivo: linker.c Projeto: fwum/fwum
static void continue_build(build *current, char *filename, file_contents newest) {
    slice name_slice = new_slice(filename);
    slice *boxed_slice = new(boxed_slice);
    *boxed_slice = name_slice;
    hm_put(current->declarations, slice_hash(name_slice), boxed_slice, filename);
    linked_iter iterator = ll_iter_head(newest.imports);
    while(ll_iter_has_next(&iterator)) {
        import_declaration *dec = ll_iter_next(&iterator);
        char *filename = resolve_name(dec->name);
        slice filename_slice = new_slice(filename);
        slice *boxed_filename = new(boxed_filename);
        *boxed_filename = filename_slice;
        if(!hm_has(current->declarations, slice_hash(filename_slice), &(filename_slice))) {
            file_contents contents = get_contents(filename);
            ll_concat(current->composite.structs, contents.structs);
            ll_concat(current->composite.functions, contents.functions);
            hm_put(current->declarations, slice_hash(filename_slice), boxed_filename, filename);
            continue_build(current, filename, contents);
        }
    }
}
Exemplo n.º 3
0
int install_automata(char* automata, AutomataHandler_t ahandle) {
    int err,rc;
    int alen;
    char buf[1024];

    // Prep the automata reg string
    char* rq;
    rc = asprintf(&rq, "SQL:register \"%s\" %s %hu %s",automata,lhost,lport,MY_SERVICE_NAME);
    if(rc<1) {
        fprintf(stderr, "Can't install the automata. Can't generate the query string.\n");
        return 1;
    }
    Q_Decl(query, rc+1);
    memcpy(query,rq,rc+1);
    free(rq);

    // Install the automata
    rc = rpc_call(rpc, Q_Arg(query), strlen(query)+1, buf, sizeof(buf), &alen);
    if(rc==0) {
        fprintf(stderr,"Registration call failed\n");
        return(1);
    }

    // Update the accounting for automata events
    CacheResponse res;
    res = newCacheResponse(buf, sizeof(buf));
    printf("%s\n",buf);
    if(res==NULL || cache_response_retcode(res) != 0) {
        fprintf(stderr,"can't process the registration return for:\n%s--\n",query);
        return 1;
    }
    rc = hm_put(service_functions, cache_response_msg(res), ahandle, NULL);
    freeCacheResponse(res);

    return 0;
}
Exemplo n.º 4
0
void append_var_info(compiler_wrapper *cw, char *ch, char load, int lineno)
{
    char needs_close = cw->repl;
    char already_defined = 0;
    arraylist list = cw->used_names;
    int i;
    for(i = 0; i < list.count; i++)
    {
        name_wrapper *w = arr_get(&cw->used_names, i);
        
        if(strcmp(w->name, ch))
            continue;   

        if(w->owner != cw)
        {
            switch_to_close(w->owner, ch, w->idx);
            needs_close = 1;
        }
        else
        {
            needs_close = is_close(cw, w->idx);
            already_defined = 1;
        }
    }

    if(!needs_close && !already_defined && load)
        needs_close = 1;

    if(needs_close)
    {
        lky_instruction istr = load ? LI_LOAD_CLOSE : LI_SAVE_CLOSE;
        char *nsid = malloc(strlen(ch) + 1);
        strcpy(nsid, ch);

        int i = find_prev_name(cw, nsid);
        if(i < 0)
        {
            i = (int)cw->rnames.count;
            arr_append(&cw->rnames, nsid);
        }

        append_op(cw, istr, lineno);
        unsigned char buf[4];
        int_to_byte_array(buf, i);
        append_op(cw, buf[0], lineno);
        append_op(cw, buf[1], lineno);
        append_op(cw, buf[2], lineno);
        append_op(cw, buf[3], lineno);

        return;
    }

    lky_instruction istr = load ? LI_LOAD_LOCAL : LI_SAVE_LOCAL;
    hm_error_t err;
    
    int idx = 0;
    lky_object_builtin *o = hm_get(&cw->saved_locals, ch, &err);
    if(err == HM_KEY_NOT_FOUND)
    {
        idx = get_next_local(cw);
        lky_object *obj = lobjb_build_int(idx);
        pool_add(&ast_memory_pool, obj);
        hm_put(&cw->saved_locals, ch, obj);
    }
    else
        idx = OBJ_NUM_UNWRAP(o);

    append_op(cw, istr, lineno);
    unsigned char buf[4];
    int_to_byte_array(buf, idx);
    append_op(cw, buf[0], lineno);
    append_op(cw, buf[1], lineno);
    append_op(cw, buf[2], lineno);
    append_op(cw, buf[3], lineno);

    name_wrapper *wrap = malloc(sizeof(name_wrapper));
    pool_add(&ast_memory_pool, wrap);
    wrap->idx = cw->rops.count - 5;
    wrap->name = ch;
    wrap->owner = cw;
    arr_append(&cw->used_names, wrap);
}
Exemplo n.º 5
0
HashMap *InsertSubsToHashTable(char *fullFileNamePath, int allSubsLinesLength)
{
    int i, endOfLinePos = 0, line_number = 0, firstTextLineIndex = 0;
    char line_buffer[BUFSIZ]; /* BUFSIZ is defined if you include stdio.h */
    FILE *infile;
    char endOfLine[] = "\n";
    HashMap *hm;
    char *shours, *sminutes, *sseconds, *smiliSeconds, scurTotlaTime[100];
    char *ehours, *eminutes, *eseconds, *emiliSeconds, ecurTotlaTime[100];
    scurTotlaTime[0] = 0;
    ecurTotlaTime[0] = 0;
    char subLines[(BUFSIZ * 2) + 50], **strArr;
    
    infile = fopen(fullFileNamePath, "r");
    
    if(!infile)
    {
        g_error("Couldn't' open file %s for reading", fullFileNamePath);
    }

    //Count number of subtitles in .srt files
    while(fgets(line_buffer, sizeof(line_buffer), infile))
    {
        ++line_number;
    }
    
    fclose(infile);
    hm = hm_new(line_number);
    
    if (hm == NULL)
    {
        g_error("Could'nt allocate hash table");
    }

    int lineIndex = 0;
    infile = fopen(fullFileNamePath, "r");
    
    if(!infile)
    {
        g_error("Couldn't' open file %s for reading", fullFileNamePath);
    }

    strArr = (char**)malloc((line_number + 1) * sizeof(char*));
    
    for(i = 0; i < line_number + 1; i++)
    {
        strArr[i] = (char*)malloc((BUFSIZ + 1) * sizeof(char));
	}
	
    while(fgets(line_buffer, sizeof(line_buffer), infile))
    {
        strcpy(strArr[lineIndex], line_buffer);

        lineIndex++;
    }
    
    fclose(infile);

    for(i = 0; i < lineIndex; i++)
    {
        endOfLinePos = strcspn(strArr[i], endOfLine) + 1;
        
        if(endOfLinePos > 8)
        {
            if(strcmp(substring(strArr[i], 2, 1), ":") == 0)
            {
                shours = substring(strArr[i], 0, 2);
                sminutes = substring(strArr[i], 3, 2);
                sseconds = substring(strArr[i], 6, 2);
                smiliSeconds = substring(strArr[i], 9, 2);
                firstTextLineIndex = i;
                strcat(scurTotlaTime, shours);
                strcat(scurTotlaTime, ":");
                strcat(scurTotlaTime, sminutes);
                strcat(scurTotlaTime, ":");
                strcat(scurTotlaTime, sseconds);
                strcat(scurTotlaTime, ":");
                strcat(scurTotlaTime, smiliSeconds);

                if(strcmp(substring(strArr[i], 13, 3), "-->") == 0)
                {
                    ehours = substring(strArr[i], 13, 6);
                    eminutes = substring(strArr[i], 20, 2);
                    eseconds = substring(strArr[i], 23, 2);
                    emiliSeconds = substring(strArr[i], 26, 2);

                    strcat(ecurTotlaTime, ehours);
                    strcat(ecurTotlaTime, ":");
                    strcat(ecurTotlaTime, eminutes);
                    strcat(ecurTotlaTime, ":");
                    strcat(ecurTotlaTime, eseconds);
                    strcat(ecurTotlaTime, ":");
                    strcat(ecurTotlaTime, emiliSeconds);
                    hm_put(hm, ecurTotlaTime, ""); //insert end time
                }

                strcat(subLines, strArr[firstTextLineIndex + 1]);
                strcat(subLines, strArr[firstTextLineIndex + 2]);
                hm_put(hm, scurTotlaTime, subLines); //insert start time                
                strcpy(scurTotlaTime, ""); //clean string
                strcpy(ecurTotlaTime, ""); //clean string
                strcpy(subLines, ""); //clean string
            }
        }
    }
    
    free(shours);
    free(sminutes);
    free(sseconds);
    free(smiliSeconds);
    free(ehours);
    free(eminutes);
    free(eseconds);
    free(emiliSeconds);
    free_matrix(strArr, line_number - 1);
    return hm;
}