示例#1
0
char *test_binstr_performance()
{
    int i = 0;
    int found_at = 0;
    unsigned long find_count = 0;
    time_t elapsed = 0;

    found_at = binstr(&IN_STR, 0, &ALPHA);

    time_t start = time(NULL);

    do {
        for(i = 0; i < 1000; i++) {
            found_at = binstr(&IN_STR, 0, list->entry[i % list->mlen]);
            mu_assert(found_at != BSTR_ERR, "Failed to find!");
            find_count++;
        }

        elapsed = time(NULL) - start;
    } while(elapsed <= TEST_TIME);

    debug("BINSTR COUNT: %lu, END TIME: %d, OPS: %f",
            find_count, (int)elapsed, (double)find_count / elapsed);
    return NULL;
}
示例#2
0
void rparse_do(char* yytext, int* out_line, bstring* out_filename)
{
    bstring str = bfromcstr(yytext);
    bstring space = bfromcstr(" ");

    // Determine the space positions.
    int firstSpace = binstr(str, 0, space);
    int secondSpace = binstr(str, firstSpace + 1, space);

    // Create substrings.
    bstring bline = bmidstr(str, firstSpace + 1, secondSpace - firstSpace);
    bstring file = bmidstr(str, secondSpace + 1, blength(str) - secondSpace);

    // Convert the line number and trim file name.
    int line = strtoul((const char*)bline->data, NULL, 10);
    btrimws(file);

    // Set variables.
    if (*out_filename == NULL)
        *out_filename = bfromcstr("");
    bassign(*out_filename, file);
    *out_line = line;

    // Free resources.
    bdestroy(file);
    bdestroy(bline);
    bdestroy(space);
    bdestroy(str);
}
示例#3
0
文件: util.c 项目: dasfaha/sky
// Retrieves a flag stating if the type name is a function type.
//
// name - The name of the type.
//
// Returns true if the the type is a function type, otherwise returns false.
bool qip_is_function_type_name(bstring name)
{
    struct tagbstring function_str1 = bsStatic("Function");
    struct tagbstring function_str2 = bsStatic("Function<");
    
    return binstr(name, 0, &function_str1) != BSTR_ERR
        || binstr(name, 0, &function_str2) != BSTR_ERR;
}
示例#4
0
文件: bstr_tests.c 项目: wenzong/lab
char *test_binstr() {
    bstring bstr_a = bfromcstr("abc");
    bstring bstr_b = bfromcstr("zzabcz");
    int pos = binstr(bstr_b, 1, bstr_a);
    mu_assert(pos == 2, "search abc in zzabcz from position 1, should return 2");

    pos = binstr(bstr_b, 3, bstr_a);
    mu_assert(pos == BSTR_ERR, "search abc in zzabcz from position 3, should return BSTR_ERR");

    bdestroy(bstr_a);
    bdestroy(bstr_b);
    return NULL;
}
char *test_binstr_performance()
{
  int i = 0;
  int found_at = 0;
  unsigned long find_count = 0;
  time_t elapsed = 0;
  time_t start = time(NULL);
  int j  = 0;

  Stats *st = Stats_create();

  while (j <= 10) {
    do {
      for(i = 0; i < 1000; i++) {
        found_at = binstr(&IN_STR, 0, &ALPHA);
        mu_assert(found_at != BSTR_ERR, "Failed to find!");
        find_count++;
      }
      elapsed = time(NULL) - start;
      Stats_sample(st, (double)find_count);
    } while(elapsed <= TEST_TIME);
    i = 0;
    found_at = 0;
    find_count = 0;
    elapsed = 0;
    start = time(NULL);
    j++;
  }

  Stats_dump(st);

  return NULL;
}
示例#6
0
int32_t ddbg_file_to_address(bstring file, int index)
{
    unsigned int i;
    struct dbg_sym* sym;
    struct dbg_sym_payload_line* payload_line;

    if (symbols != NULL)
    {
        // Search through our debugging symbols.
        for (i = 0; i < list_size(symbols); i++)
        {
            sym = list_get_at(symbols, i);
            switch (sym->type)
            {
                case DBGFMT_SYMBOL_LINE:
                    payload_line = (struct dbg_sym_payload_line*)sym->payload;
                    if (binstr(payload_line->path, 0, file) != BSTR_ERR && payload_line->lineno == index)
                    {
                        // The filename and line number matches, we have found
                        // our symbol entry.
                        printd(LEVEL_DEFAULT, "Line information: %s:%u is at 0x%04X\n", payload_line->path->data, payload_line->lineno, payload_line->address);
                        return payload_line->address;
                    }
                    break;
                default:
                    break;
            }
        }
    }

    // If we don't find a memory address, we return -1.
    return -1;
}
示例#7
0
int DB_find(const char *url)
{
    bstring data = NULL;
    bstring line = bfromcstr(url);
    int res = -1;

    data = DB_load();
    check(data, "Failed to load: %s", DB_FILE);

    if (binstr(data, 0, line) == BSTR_ERR) {
        res = 0;
    } else {
        res = 1;
    }

error: // fallthrough
    if (data) {
        bdestroy(data);
    }
    if (line) {
        bdestroy(line);
    }

    return res;
}
示例#8
0
文件: vars.c 项目: smaclennan/zedit
void Zshow_config(void)
{
	int i;
	char line[STRMAX * 2];
	zbuff_t *tbuff = cmakebuff(CONFBUFF, NULL);
	if (!tbuff)
		return;

	bempty(Bbuff);
	for (i = 0; i < NUMVARS; ++i) {
		if (Vars[i].vtype == V_STRING) {
			if (VARSTR(i))
				strfmt(line, sizeof(line), "%-15s %s\n",
					 Vars[i].vname, VARSTR(i));
			else
				strfmt(line, sizeof(line), "#%-15s\n",
					 Vars[i].vname);
		} else if (Vars[i].vtype == V_DECIMAL)
			strfmt(line, sizeof(line), "%-15s %d\n",
				 Vars[i].vname, VAR(i));
		else if (Vars[i].vtype == V_FLAG)
			strfmt(line, sizeof(line), "%-15s %s\n",
				 Vars[i].vname,
				 VAR(i) ? "true" : "false");

		binstr(Bbuff, line);
	}

	tbuff->buff->bmodf = false;
	btostart(Bbuff);
	cswitchto(tbuff);
}
示例#9
0
static void
nodeMeminfo(int node, uint64_t* totalMemory, uint64_t* freeMemory)
{
    FILE *fp;
    bstring filename;
    bstring totalString = bformat("MemTotal:");
    bstring freeString  = bformat("MemFree:");
    int i;

    filename = bformat("/sys/devices/system/node/node%d/meminfo", node);

    if (NULL != (fp = fopen (bdata(filename), "r"))) 
    {
        bstring src = bread ((bNread) fread, fp);
        struct bstrList* tokens = bsplit(src,(char) '\n');

        for (i=0;i<tokens->qty;i++)
        {
            if (binstr(tokens->entry[i],0,totalString) != BSTR_ERR)
            {
                 bstring tmp = bmidstr (tokens->entry[i], 18, blength(tokens->entry[i])-18 );
                 bltrimws(tmp);
                 struct bstrList* subtokens = bsplit(tmp,(char) ' ');
                 *totalMemory = str2int(bdata(subtokens->entry[0]));
            }
            else if (binstr(tokens->entry[i],0,freeString) != BSTR_ERR)
            {
                 bstring tmp = bmidstr (tokens->entry[i], 18, blength(tokens->entry[i])-18  );
                 bltrimws(tmp);
                 struct bstrList* subtokens = bsplit(tmp,(char) ' ');
                 *freeMemory = str2int(bdata(subtokens->entry[0]));
            }
        }
    }
    else
    {
        ERROR;
    }

    fclose(fp);
}
示例#10
0
文件: heap.c 项目: ptcte/allinone
void adjustHeap(Heap* hp)
{
  int x = hp->root->count;
  Node* t = hp->root;
  char* w = (char*)malloc(20*sizeof(char));
  w = binstr(w,x);
  int ln = strlen(w);
  if(ln == 1)
  {
    t = hp->root;
  }
  for(int j = 1; j < ln-1; j++)
  {
    if(w[j] == 'L')
    {
      t = t->l;
    }else
      if(w[j] == 'R')
      {
    t = t->r;
      }
  }
  if(ln > 1)
  {
    if(w[ln-1] == 'L')
    {
      t = t->l;
//       printf("latest : %p %s\n",t,t->str);
    }
    else
    {
      if(w[ln-1] == 'R')
      {
    t = t->r;
    printf("latest : %p %s\n",t,t->str);
      }
    }
  }

  while(t != hp->root){
    char* temp;
    if(strcmp(t->str,(t->p)->str) > 0)
    {
      temp = t->str;
      t->str = (t->p)->str;
      (t->p)->str = temp;
    }
    t = t->p;
  }
}
示例#11
0
文件: heap.c 项目: ptcte/allinone
Node* insertNode(Node* n,char* data)
{
  Node* t = makeNode(data);
  Node* c = n;
  char* w = (char*)malloc(20*sizeof(char));
  int a = t->i;
  w = binstr(w,a);
  int ln = strlen(w);
  //   printf("%d%s%d%s\n",a,w,ln,t->str);
  if(ln == 1)
  {
    n = t;
    //     printf("inserted %s\n",t->str);
  }
  for(int j = 1; j < ln-1; j++)
  {
    if(w[j] == 'L')
    {
      c = c->l;
      (c->count)++;
    }else
    if(w[j] == 'R')
    {
      c = c->r;
      (c->count)++;
    }
  }
  if(ln > 1)
  {
    if(w[ln-1] == 'L')
    {
      c->l = t;
      t->p = c;
      (n->count)++;
      //       printf("inserted %s\n",t->str);
    }
    else
    {
      if(w[ln-1] == 'R')
      {
    c->r = t;
    t->p = c;
    (n->count)++;
      }
      //       printf("inserted %s\n",t->str);
    }
  }
  return n;
}
示例#12
0
wxString Helper::toBinary(wxUint8 input)
{
	//if(input == 0) return _T("00000000"); 
	std::string result;
	int n = sizeof(wxUint8);
	
	for(int i = n*7; i > 0; i--) 
		{
			if(input & (1 << i)) 
				result += "1";	
			else 
				result += "0";		
		}
	wxString binstr(result.c_str(),wxConvUTF8); 
	return binstr;
}
示例#13
0
char *test_bfindreplace()
{
	bstr = bfromcstr(test2);
	bstring pattern = bfromcstr(data);
	bstring replace = bfromcstr(vata);
	int rc = bfindreplace(bstr, pattern, replace, 0);
	mu_assert(rc == 0, "Replace did not go well.");

	int pos = binstr(bstr, 0, replace);
	mu_assert(pos == 6, "Find returned incorrect result.");

	bdestroy(pattern);
	bdestroy(replace);
	bdestroy(bstr);
	return NULL;
}
示例#14
0
文件: heap.c 项目: ptcte/allinone
char* binstr(char* s,int n)
{
  if(n > 1)
  {
    s = binstr(s,n/2);
  }
  if(n%2 == 0)
  {
    strcat(s,"L");
  }
  else
  {
    strcat(s,"R");
  }
  return s;
}
示例#15
0
bool do_uninstall_all(CURL* curl)
{
    // define used variables
    DIR* dir;
    bool something_was_removed;
    struct dirent* entry;
    bstring fname, sstr;
    bstring ext = bfromcstr(".lua");
    bstring modpath = osutil_getmodulepath();

    // Attempt to open the modules directory.
    dir = opendir(modpath->data);
    if (dir == NULL)
    {
        printd(LEVEL_ERROR, "unable to query local repository.\n");
        return 1;
    }
    bdestroy(modpath);

    // iterate through the installed modules
    something_was_removed = false;
    while ((entry = readdir(dir)) != NULL)
    {
        fname = bfromcstr(&entry->d_name[0]);
        if (binstr(fname, blength(fname) - 4, ext) == BSTR_ERR)
        {
            bdestroy(fname);
            continue;
        }
        if (entry->d_type != DT_REG)
        {
            bdestroy(fname);
            continue;
        }
        sstr = bmidstr(fname, 0, blength(fname) - 4);
        do_uninstall(curl, bfromcstr(sstr->data));
        something_was_removed = true;
        bdestroy(sstr);
        bdestroy(fname);
    }
    if (!something_was_removed)
        printd(LEVEL_DEFAULT, "No changes were made.\n");

    return 0;
}
示例#16
0
文件: cwatch.c 项目: 0xNaN/cwatch
void log_message(char *message, ...)
{
    /* Init variable argument list */
    va_list la;
    va_start(la, message);

    /* Convert message to bstring for better manage */
    bstring b_message = bfromcstr(message);
    int index = 0;

    bstring b_percent = bfromcstr("%");

    if (syslog_flag || (verbose_flag && (NULL == format))){
        /* Find each special char and replace with the correct arg */
        while ( (index = binstr(b_message, index, b_percent)) != BSTR_ERR){

            /* Find the type of value */
            char type = b_message->data[++index];

            if (type == 's'){

                /* Get the next char* arg and replace it */
                char *arg_char = va_arg (la, char *);
                bstring b_arg_char = bfromcstr(arg_char);

                breplace(b_message, index - 1, 2, b_arg_char, ' ');
                bdestroy(b_arg_char);
            }else if (type == 'd'){

                /* Get the next int arg, cast in cstr, and replace it*/
                int arg_int = va_arg (la, int);

                /* TODO: find the correct length of maxint */
                char *str_int = (char *) malloc (15);

                sprintf(str_int, "%d", arg_int);
                bstring b_str_int = bfromcstr(str_int);

                breplace(b_message, index - 1, 2, b_str_int, ' ');
                bdestroy(b_str_int);
            }
示例#17
0
int DB_find(char *url)
{
	bstring data = NULL;
	bstring line = bfromcstr(url);
	int res = -1;

	data = DB_load(DB_FILE);
	check(data, "Could not load %s.", DB_FILE);

	if(binstr(data, 0, line) == BSTR_ERR){
		res = 0;
	} else {
		res = 1;
	}

error: // fallthrough
	if(data) bdestroy(data);
	if(line) bdestroy(line);

	return res;
}
示例#18
0
void rparse_dol(char* yytext, int* out_line)
{
    bstring str = bfromcstr(yytext);
    bstring space = bfromcstr(" ");

    // Determine the space positions.
    int firstSpace = binstr(str, 0, space);

    // Create substrings.
    bstring bline = bmidstr(str, firstSpace + 1, blength(str));

    // Convert the line number and trim file name.
    int line = strtoul((const char*)bline->data, NULL, 10);

    // Set variables.
    *out_line = line;

    // Free resources.
    bdestroy(bline);
    bdestroy(space);
    bdestroy(str);
}
示例#19
0
char *test_binstr(void)
{
	bstring b = bfromcstr(test);
	bstring search = bfromcstr(test_1);
	mu_assert(binstr(b, 0, search) == BSTR_ERR, "Failed to not found on binstr().");
	
	mu_assert(bdestroy(search) == BSTR_OK, "Failed to bdestroy() afetr binstr().");
	search = bfromcstr(test_search);
	mu_assert(binstr(b, 0, search) == 18, "Failed to found on binstr().");
	mu_assert(binstr(b, 1, search) == 18, "Failed to found on binstr().");
	mu_assert(binstr(b, 10, search) == 18, "Failed to found on binstr().");
	mu_assert(binstr(b, 18, search) == 18, "Failed to found on binstr().");
	mu_assert(binstr(b, 19, search) == BSTR_ERR, "Failed to not found on binstr().");
		
	mu_assert(bdestroy(b) == BSTR_OK, "Failed to bdestroy() afetr binstr).");
	mu_assert(bdestroy(search) == BSTR_OK, "Failed to bdestroy() afetr binstr().");
	return NULL;
}
示例#20
0
int DB_find(const char *url)
{
	bstring data = NULL;
	bstring line = bfromcstr(url);
	int res = -1;

	data = DB_load(DB_FILE);
	check(data, "Failed to load: %s", DB_FILE);
	// 从0开始,在data中找line
	if(binstr(data, 0, line) == BSTR_ERR)
	{
		res = 0;
	}
	else
	{
		res = 1;
	}

  error:
	if(data) bdestroy(data);
	if(line) bdestroy(line);

	return res;
}
示例#21
0
int DB_find(const char *url, bool *found)
{
    assert(url != NULL);
    assert(found != NULL);
    
    bstring data = NULL;
    bstring line = bfromcstr(url);
    
    int rc = 0;
    
    data = DB_load();
    assert(data != NULL);
    
    if (binstr(data, 0, line) == BSTR_ERR) {
        *found = false;
    } else {
        *found = true;
    }

    bdestroy(data);
    bdestroy(line);    

    return rc;
}
示例#22
0
文件: glsw.c 项目: Cloudef/glhck
const char* glswGetShader(const char* pEffectKey, const char* pContentsFromMemory)
{
    glswContext* gc = __glsw__Context;
    bstring effectKey;
    glswList* closestMatch = 0;
    struct bstrList* tokens;
    bstring effectName;
    glswList* pLoadedEffect;
    glswList* pShaderEntry;
    bstring shaderKey = 0;

    if (!gc)
    {
        return 0;
    }

    // Extract the effect name from the effect key
    effectKey = bfromcstr(pEffectKey);
    tokens = bsplit(effectKey, '.');
    if (!tokens || !tokens->qty)
    {
        bdestroy(gc->ErrorMessage);
        gc->ErrorMessage = bformat("Malformed effect key key '%s'.", pEffectKey);
        bstrListDestroy(tokens);
        bdestroy(effectKey);
        return 0;
    }
    effectName = tokens->entry[0];

    // Check if we already loaded this effect file
    pLoadedEffect = gc->LoadedEffects;
    while (pLoadedEffect)
    {
        if (1 == biseq(pLoadedEffect->Key, effectName))
        {
            break;
        }
        pLoadedEffect = pLoadedEffect->Next;
    }

    // If we haven't loaded this file yet, load it in
    if (!pLoadedEffect)
    {
        bstring effectContents;
        struct bstrList* lines;
        int lineNo;

        if (!pContentsFromMemory) {
            FILE* fp;
            bstring effectFile;

            // Decorate the effect name to form the fullpath
            effectFile = bstrcpy(effectName);
            binsert(effectFile, 0, gc->PathPrefix, '?');
            bconcat(effectFile, gc->PathSuffix);

            // Attempt to open the file
            fp = fopen((const char*) effectFile->data, "rb");
            if (!fp)
            {
                bdestroy(gc->ErrorMessage);
                gc->ErrorMessage = bformat("Unable to open effect file '%s'.", effectFile->data);
                bdestroy(effectFile);
                bdestroy(effectKey);
                bstrListDestroy(tokens);
                return 0;
            }

            // Add a new entry to the front of gc->LoadedEffects
            {
                glswList* temp = gc->LoadedEffects;
                gc->LoadedEffects = (glswList*) calloc(sizeof(glswList), 1);
                gc->LoadedEffects->Key = bstrcpy(effectName);
                gc->LoadedEffects->Next = temp;
            }

            // Read in the effect file
            effectContents = bread((bNread) fread, fp);
            fclose(fp);
            bdestroy(effectFile);
        } else {
            effectContents = bfromcstr(pContentsFromMemory);
        }

        lines = bsplit(effectContents, '\n');
        bdestroy(effectContents);
        effectContents = 0;

        for (lineNo = 0; lineNo < lines->qty; lineNo++)
        {
            bstring line = lines->entry[lineNo];

            // If the line starts with "--", then it marks a new section
            if (blength(line) >= 2 && line->data[0] == '-' && line->data[1] == '-')
            {
                // Find the first character in [A-Za-z0-9_].
                int colNo;
                for (colNo = 2; colNo < blength(line); colNo++)
                {
                    char c = line->data[colNo];
                    if (__glsw__Alphanumeric(c))
                    {
                        break;
                    }
                }

                // If there's no alphanumeric character,
                // then this marks the start of a new comment block.
                if (colNo >= blength(line))
                {
                    bdestroy(shaderKey);
                    shaderKey = 0;
                }
                else
                {
                    // Keep reading until a non-alphanumeric character is found.
                    int endCol;
                    for (endCol = colNo; endCol < blength(line); endCol++)
                    {
                        char c = line->data[endCol];
                        if (!__glsw__Alphanumeric(c))
                        {
                            break;
                        }
                    }

                    bdestroy(shaderKey);
                    shaderKey = bmidstr(line, colNo, endCol - colNo);

                    // Add a new entry to the shader map.
                    {
                        glswList* temp = gc->ShaderMap;
                        gc->ShaderMap = (glswList*) calloc(sizeof(glswList), 1);
                        gc->ShaderMap->Key = bstrcpy(shaderKey);
                        gc->ShaderMap->Next = temp;
                        gc->ShaderMap->Value = bformat("#line %d\n", lineNo);

                        binsertch(gc->ShaderMap->Key, 0, 1, '.');
                        binsert(gc->ShaderMap->Key, 0, effectName, '?');
                    }

                    // Check for a version mapping.
                    if (gc->TokenMap)
                    {
                        struct bstrList* tokens = bsplit(shaderKey, '.');
                        glswList* pTokenMapping = gc->TokenMap;

                        while (pTokenMapping)
                        {
                            bstring directive = 0;
                            int tokenIndex;

                            // An empty key in the token mapping means "always prepend this directive".
                            // The effect name itself is also checked against the token mapping.
                            if (0 == blength(pTokenMapping->Key) ||
                                1 == biseq(pTokenMapping->Key, effectName))
                            {
                                directive = pTokenMapping->Value;
                                binsert(gc->ShaderMap->Value, 0, directive, '?');
                            }

                            // Check all tokens in the current section divider for a mapped token.
                            for (tokenIndex = 0; tokenIndex < tokens->qty && !directive; tokenIndex++)
                            {
                                bstring token = tokens->entry[tokenIndex];
                                if (1 == biseq(pTokenMapping->Key, token))
                                {
                                    directive = pTokenMapping->Value;
                                    binsert(gc->ShaderMap->Value, 0, directive, '?');
                                }
                            }

                            pTokenMapping = pTokenMapping->Next;
                        }

                        bstrListDestroy(tokens);
                    }
                }

                continue;
            }
            if (shaderKey)
            {
                bconcat(gc->ShaderMap->Value, line);
                bconchar(gc->ShaderMap->Value, '\n');
            }
        }

        // Cleanup
        bstrListDestroy(lines);
        bdestroy(shaderKey);
    }

    // Find the longest matching shader key
    pShaderEntry = gc->ShaderMap;

    while (pShaderEntry)
    {
        if (binstr(effectKey, 0, pShaderEntry->Key) == 0 &&
            (!closestMatch || blength(pShaderEntry->Key) > blength(closestMatch->Key)))
        {
            closestMatch = pShaderEntry;
        }

        pShaderEntry = pShaderEntry->Next;
    }

    bstrListDestroy(tokens);
    bdestroy(effectKey);

    if (!closestMatch)
    {
        bdestroy(gc->ErrorMessage);
        gc->ErrorMessage = bformat("Could not find shader with key '%s'.", pEffectKey);
        return 0;
    }

    return (const char*) closestMatch->Value->data;
}
示例#23
0
bool do_search(CURL* curl, bstring name, bool all)
{
    DIR* dir;
    bool printed;
    CURLcode res;
    FILE* fp;
    list_t installed;
    struct bStream* stream;
    long httpcode = 0;
    bstring buffer, fname, sstr;
    bstring ext = bfromcstr(".lua");
    bstring url = bfromcstr("http://dms.dcputoolcha.in/modules/search?q=");
    bstring modpath = osutil_getmodulepath();
    struct dirent* entry;
    list_init(&installed);
    list_attributes_copy(&installed, list_meter_string, 1);
    list_attributes_comparator(&installed, list_comparator_string);

    // Attempt to open the modules directory.
    dir = opendir(modpath->data);
    if (dir == NULL)
    {
        printd(LEVEL_ERROR, "unable to query local repository.\n");
        return 1;
    }

    // Append the temporary search file name.
    bcatcstr(modpath, "/.search");
    bconcat(url, name);

    // Open the file and do the cURL transfer.
    printd(LEVEL_DEFAULT, "querying module repository...\n");
    fp = fopen(modpath->data, "wb");
    curl_easy_setopt(curl, CURLOPT_URL, url->data);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    res = curl_easy_perform(curl);
    curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &httpcode);
    if (res != 0 || httpcode != 200)
    {
        bdestroy(url);
        bdestroy(name);
        bdestroy(modpath);
        printd(LEVEL_ERROR, "curl failed with error code %i, HTTP error code %i.\n", res, httpcode);
        return 1;
    }
    fclose(fp);

    // Print the local results.
    if (all)
        printd(LEVEL_DEFAULT, "all modules:\n");
    else
        printd(LEVEL_DEFAULT, "search results for %s:\n", name->data);
    while ((entry = readdir(dir)) != NULL)
    {
        fname = bfromcstr(&entry->d_name[0]);
        if (binstr(fname, blength(fname) - 4, ext) == BSTR_ERR)
        {
            bdestroy(fname);
            continue;
        }
        if (binstr(fname, 0, name) == BSTR_ERR)
        {
            bdestroy(fname);
            continue;
        }
        if (entry->d_type != DT_REG)
        {
            bdestroy(fname);
            continue;
        }
        sstr = bmidstr(fname, 0, blength(fname) - 4);
        printd(LEVEL_DEFAULT, "   %s (installed)\n", sstr->data);
        list_append(&installed, sstr->data);
        bdestroy(sstr);
        bdestroy(fname);
    }

    // Print the online results.
    fp = fopen(modpath->data, "r");
    stream = bsopen(&read_data, fp);
    buffer = bfromcstr("");
    printed = false;
    while (bsreadln(buffer, stream, '\n') != BSTR_ERR)
    {
        btrimws(buffer);
        sstr = bmidstr(buffer, 0, blength(buffer) - 4);
        if (!list_contains(&installed, sstr->data))
            printd(LEVEL_DEFAULT, "  %s\n", sstr->data);
        printed = true;
        bdestroy(sstr);
    }
    if (!printed)
        printd(LEVEL_DEFAULT, "   <no online results>\n");
    bsclose(stream);
    fclose(fp);

    // Clean up.
    curl_easy_cleanup(curl);
    return 0;
}
示例#24
0
bool do_install_all(CURL* curl)
{
    // define used variables
    DIR* dir;
    FILE* fp;
    CURLcode res;
    bool printed;
    bool install_status;
    bool something_errored;
    bool if_something_was_installed;
    list_t installed;
    long httpcode = 0;
    struct dirent* entry;
    struct bStream* stream;
    bstring buffer, fname, sstr;
    bstring modpath = osutil_getmodulepath();
    bstring ext = bfromcstr(".lua");
    bstring url = bfromcstr("http://dms.dcputoolcha.in/modules/list");
    list_init(&installed);
    list_attributes_copy(&installed, list_meter_string, 1);
    list_attributes_comparator(&installed, list_comparator_string);

    // Attempt to open the modules directory.
    dir = opendir(modpath->data);
    if (dir == NULL)
    {
        printd(LEVEL_ERROR, "unable to query local repository.\n");
        return 1;
    }

    // add the filename we wish to query to the modules folder path
    bcatcstr(modpath, "/.all_avail");

    // Open the file and do the cURL transfer.
    printd(LEVEL_DEFAULT, "loading a list of all the modules...\n");
    fp = fopen(modpath->data, "wb");
    curl_easy_setopt(curl, CURLOPT_URL, url->data);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    res = curl_easy_perform(curl);
    curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &httpcode);
    if (res != 0 || httpcode != 200)
    {
        bdestroy(url);
        bdestroy(modpath);
        printd(LEVEL_ERROR, "curl failed with error code %i, HTTP error code %i.\n", res, httpcode);
        return 1;
    }
    fclose(fp);


    // create a list of already installed modules
    while ((entry = readdir(dir)) != NULL)
    {
        fname = bfromcstr(&entry->d_name[0]);
        if (binstr(fname, blength(fname) - 4, ext) == BSTR_ERR)
        {
            bdestroy(fname);
            continue;
        }
        if (entry->d_type != DT_REG)
        {
            bdestroy(fname);
            continue;
        }
        sstr = bmidstr(fname, 0, blength(fname) - 4);
        list_append(&installed, sstr->data);
        bdestroy(sstr);
        bdestroy(fname);
    }

    printd(LEVEL_DEFAULT, "\n");

    // Print the names of the modules, and install them through the do_install function
    fp = fopen(modpath->data, "r");
    stream = bsopen(&read_data, fp);
    buffer = bfromcstr("");
    printed = false;
    if_something_was_installed = false;
    something_errored = false;
    while (bsreadln(buffer, stream, '\n') != BSTR_ERR)
    {
        btrimws(buffer);
        sstr = bmidstr(buffer, 0, blength(buffer) - 4);

        // if the module is not already installed
        if (!list_contains(&installed, sstr->data))
        {
            install_status = do_install(curl, bfromcstr(sstr->data));
            if_something_was_installed = true;
            // check whether the installation was successful
            if (install_status != 0)
            {
                printd(LEVEL_DEFAULT, "  %s failed to install.\n", sstr->data);
                something_errored = true;
            }
            printd(LEVEL_DEFAULT, "\n");
        }

        printed = true;
        bdestroy(sstr);
    }
    if (!printed)
        printd(LEVEL_DEFAULT, "  <no modules available>\n");
    if (something_errored)
        printd(LEVEL_DEFAULT, "errors occured\n");
    if (!if_something_was_installed)
        printd(LEVEL_DEFAULT, "no changes were made\n");
    bsclose(stream);
    fclose(fp);

    // Clean up.
    curl_easy_cleanup(curl);

    return 0;
}
示例#25
0
void vm_hw_lua_init(vm_t* vm)
{
	DIR* dir;
	struct dirent* entry;
	bstring name = NULL;
	bstring hwpath = NULL;
	bstring ext = bfromcstr(".lua");

	// Work out the name of the hw directory.
	hwpath = osutil_getarg0path();
#ifdef _WIN32
	bcatcstr(hwpath, "\\modules");
#else
	bcatcstr(hwpath, "/modules");
#endif

	// Attempt to open the hw directory.
	dir = opendir(hwpath->data);
	if (dir == NULL)
	{
		// The directory does not exist, so we don't load
		// any custom hardware.
		vm_lua_online = false;
		bdestroy(hwpath);
		bdestroy(ext);
		return;
	}

	// Load each file from the hw directory.
	while ((entry = readdir(dir)) != NULL)
	{
		name = bfromcstr(&entry->d_name[0]);

		// Check to see whether it is a lua file.
		if (binstr(name, blength(name) - 4, ext) == BSTR_ERR)
		{
			// Not a Lua file, skip over and
			// then continue.
			bdestroy(name);
			continue;
		}

		// Check to see if it is a normal file.
#if defined(DT_REG)
		if (entry->d_type != DT_REG)
#elif defined(DT_DIR)
		if (entry->d_type == DT_DIR)
#elif defined(DT_UNKNOWN)
		if (entry->d_type == DT_UNKNOWN)
#else
#error Build system must support DT_REG, DT_DIR or DT_UNKNOWN in dirent.h.
#endif
		{
			// Not a file, skip over and then
			// continue.
			bdestroy(name);
			continue;
		}

		// Attempt to load the Lua file.
		printf("loading Lua hardware from: %s\n", name->data);
		vm_hw_lua_load(vm, name);

		// Free data.
		bdestroy(name);
	}

	// Free resources.
	closedir(dir);

	/*


	hw_t keyboard;

	keyboard.id = 0x30CF7406;
	keyboard.version = 0x1802;
	keyboard.manufacturer = 0x1C6C8B36;
	keyboard.handler = &vm_hw_lua_interrupt;

	// Register hooks.
	vm_cycle_update = vm_hook_register(vm, &vm_hw_lua_cycle, HOOK_ON_CYCLE);
	vm_write_update = vm_hook_register(vm, &vm_hw_lua_write, HOOK_ON_WRITE);
	vm_hw_register(vm, keyboard);*/
}
示例#26
0
void SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg)
{
	int i;
	time_t	tt;

	fprintf(fp,"%-20.20s %"PRId32"\n"		,"number"			,msg->hdr.number);

	/* convenience strings */
	if(msg->subj)
		fprintf(fp,"%-20.20s \"%s\"\n"	,"subject"			,msg->subj);
	if(msg->to) {
		fprintf(fp,"%-20.20s %s"	,"to"				,msg->to);
		if(msg->to_ext)
			fprintf(fp," #%s",msg->to_ext);
		if(msg->to_net.type)
			fprintf(fp," <%s>",smb_netaddr(&msg->to_net));
		fprintf(fp,"\n");
	}
	if(msg->from) {
		fprintf(fp,"%-20.20s \"%s\""	,"from"				,msg->from);
		if(msg->from_ext)
			fprintf(fp," #%s",msg->from_ext);
		if(msg->from_net.type)
			fprintf(fp," <%s>",smb_netaddr(&msg->from_net));
		fprintf(fp,"\n");
	}
	if(msg->replyto) {
		fprintf(fp,"%-20.20s \"%s\""	,"reply-to"			,msg->replyto);
		if(msg->replyto_ext)
			fprintf(fp," #%s",msg->replyto_ext);
		if(msg->replyto_net.type)
			fprintf(fp," <%s>",smb_netaddr(&msg->replyto_net));
		fprintf(fp,"\n");
	}
	if(msg->summary)
		fprintf(fp,"%-20.20s \"%s\"\n"	,"summary"			,msg->summary);

	/* convenience integers */
	if(msg->expiration) {
		tt=msg->expiration;
		fprintf(fp,"%-20.20s %.24s\n","expiration"	
			,ctime(&tt));
	}

	/* fixed header fields */
	tt=msg->hdr.when_written.time;
	fprintf(fp,"%-20.20s %.24s  UTC%+d:%02d\n"	,"when_written"	
		,ctime(&tt)	
		,smb_tzutc(msg->hdr.when_written.zone)/60
		,abs(smb_tzutc(msg->hdr.when_written.zone)%60));
	tt=msg->hdr.when_imported.time;
	fprintf(fp,"%-20.20s %.24s  UTC%+d:%02d\n"	,"when_imported"	
		,ctime(&tt)	
		,smb_tzutc(msg->hdr.when_imported.zone)/60
		,abs(smb_tzutc(msg->hdr.when_imported.zone)%60));
	fprintf(fp,"%-20.20s %04Xh\n"	,"type"				,msg->hdr.type);
	fprintf(fp,"%-20.20s %04Xh\n"	,"version"			,msg->hdr.version);
	fprintf(fp,"%-20.20s %04Xh\n"	,"attr"				,msg->hdr.attr);
	fprintf(fp,"%-20.20s %08"PRIX32"h\n"	,"auxattr"			,msg->hdr.auxattr);
	fprintf(fp,"%-20.20s %08"PRIX32"h\n"	,"netattr"			,msg->hdr.netattr);

	/* optional fixed fields */
	if(msg->hdr.thread_id)
		fprintf(fp,"%-20.20s %"PRId32"\n"	,"thread_id"		,msg->hdr.thread_id);
	if(msg->hdr.thread_back)
		fprintf(fp,"%-20.20s %"PRId32"\n"	,"thread_back"		,msg->hdr.thread_back);
	if(msg->hdr.thread_next)
		fprintf(fp,"%-20.20s %"PRId32"\n"	,"thread_next"		,msg->hdr.thread_next);
	if(msg->hdr.thread_first)
		fprintf(fp,"%-20.20s %"PRId32"\n"	,"thread_first"		,msg->hdr.thread_first);
	if(msg->hdr.delivery_attempts)
		fprintf(fp,"%-20.20s %hu\n"	,"delivery_attempts",msg->hdr.delivery_attempts);
	if(msg->hdr.times_downloaded)
		fprintf(fp,"%-20.20s %"PRIu32"\n"	,"times_downloaded"	,msg->hdr.times_downloaded);
	if(msg->hdr.last_downloaded) {
		tt=msg->hdr.last_downloaded;
		fprintf(fp,"%-20.20s %.24s\n"	,"last_downloaded"	,ctime(&tt));
	}

	fprintf(fp,"%-20.20s %06"PRIX32"h\n"	,"header offset"	,msg->idx.offset);
	fprintf(fp,"%-20.20s %u\n"		,"header length"	,msg->hdr.length);
	fprintf(fp,"%-20.20s %lu\n"		,"calculated length",smb_getmsghdrlen(msg));

	/* variable fields */
	for(i=0;i<msg->total_hfields;i++)
		fprintf(fp,"%-20.20s \"%s\"\n"
			,smb_hfieldtype(msg->hfield[i].type)
			,binstr((uchar *)msg->hfield_dat[i],msg->hfield[i].length));

	/* data fields */
	fprintf(fp,"%-20.20s %06"PRIX32"h\n"	,"data offset"		,msg->hdr.offset);
	for(i=0;i<msg->hdr.total_dfields;i++)
		fprintf(fp,"data field[%u]        %s, offset %"PRIu32", length %"PRIu32"\n"
			,i
			,smb_dfieldtype(msg->dfield[i].type)
			,msg->dfield[i].offset
			,msg->dfield[i].length);
}
示例#27
0
文件: sky_lua.c 项目: emiddleton/sky
// Generates the LuaJIT header given a Lua script and a property file. The
// header file is generated based on the property usage of the 'event'
// variable in the script.
//
// source          - The source code of the Lua script.
// property_file   - The property file used to lookup properties.
// event_decl      - A pointer to where the struct def should be returned.
// init_descriptor_func - A pointer to where the descriptor init function should be returned.
//
// Returns 0 if successful, otherwise returns -1.
int sky_lua_generate_event_info(bstring source,
                                sky_property_file *property_file,
                                bstring *event_decl,
                                bstring *init_descriptor_func)
{
    int rc;
    bstring identifier = NULL;
    assert(source != NULL);
    assert(property_file != NULL);
    assert(event_decl != NULL);
    assert(init_descriptor_func != NULL);

    // Initialize returned value.
    *event_decl = bfromcstr(
        "  int64_t timestamp;\n"
        "  uint16_t action_id;\n"
    );
    check_mem(*event_decl);
    *init_descriptor_func = bfromcstr(
        "  ffi.C.sky_data_descriptor_set_timestamp_offset(descriptor, ffi.offsetof(\"sky_lua_event_t\", \"timestamp\"));\n"
        "  ffi.C.sky_data_descriptor_set_action_id_offset(descriptor, ffi.offsetof(\"sky_lua_event_t\", \"action_id\"));\n"
    );
    check_mem(*init_descriptor_func);

    // Setup a lookup of properties.
    bool lookup[SKY_PROPERTY_ID_COUNT+1];
    memset(lookup, 0, sizeof(lookup));

    // Loop over every mention of an "event." property.
    int pos = 0;
    struct tagbstring EVENT_DOT_STR = bsStatic("event.");
    while((pos = binstr(source, pos, &EVENT_DOT_STR)) != BSTR_ERR) {
        // Make sure that this is not part of another identifier.
        bool skip = false;
        if(pos > 0 && (isalnum(bchar(source, pos-1)) || bchar(source, pos-1) == '_')) {
            skip = true;
        }
        
        // Move past the "event." string.
        pos += blength(&EVENT_DOT_STR);

        if(!skip) {
            // Read in identifier.
            int i;
            for(i=pos+1; i<blength(source); i++) {
                char ch = bchar(source, i);
                if(!(isalnum(ch) || ch == '_')) {
                    break;
                }
            }
            identifier = bmidstr(source, pos, i-pos); check_mem(identifier);
            if(blength(identifier)) {
                sky_property *property = NULL;
                rc = sky_property_file_find_by_name(property_file, identifier, &property);
                check(rc == 0, "Unable to find property by name: %s", bdata(identifier));
                check(property != NULL, "Property not found: %s", bdata(identifier));
            
                if(!lookup[property->id-SKY_PROPERTY_ID_MIN]) {
                    // Append property definition to event decl and function.
                    switch(property->data_type) {
                        case SKY_DATA_TYPE_STRING: {
                            bformata(*event_decl, "  char %s[];\n", bdata(property->name));
                            break;
                        }
                        case SKY_DATA_TYPE_INT: {
                            bformata(*event_decl, "  int64_t %s;\n", bdata(property->name));
                            break;
                        }
                        case SKY_DATA_TYPE_DOUBLE: {
                            bformata(*event_decl, "  double %s;\n", bdata(property->name));
                            break;
                        }
                        case SKY_DATA_TYPE_BOOLEAN: {
                            bformata(*event_decl, "  bool %s;\n", bdata(property->name));
                            break;
                        }
                        default:{
                            sentinel("Invalid sky lua type: %d", property->data_type);
                        }
                    }
                    check_mem(*event_decl);

                    bformata(*init_descriptor_func, "  ffi.C.sky_data_descriptor_set_property(descriptor, %d, ffi.offsetof(\"sky_lua_event_t\", \"%s\"), %d);\n", property->id, bdata(property->name), property->data_type);
                    check_mem(*init_descriptor_func);

                    // Flag the property as already processed.
                    lookup[property->id - SKY_PROPERTY_ID_MIN] = true;
                }
            }

            bdestroy(identifier);
            identifier = NULL;
        }
    }

    // Wrap properties in a struct.
    bassignformat(*event_decl, "typedef struct {\n%s} sky_lua_event_t;", bdata(*event_decl));
    check_mem(*event_decl);

    // Wrap info function.
    bassignformat(*init_descriptor_func,
        "function sky_init_descriptor(_descriptor)\n"
        "  descriptor = ffi.cast(\"sky_data_descriptor_t*\", _descriptor)\n"
        "%s"
        "end\n",
        bdata(*init_descriptor_func)
    );
    check_mem(*init_descriptor_func);

    return 0;

error:
    bdestroy(identifier);
    bdestroy(*event_decl);
    *event_decl = NULL;
    bdestroy(*init_descriptor_func);
    *init_descriptor_func = NULL;
    return -1;
}
示例#28
0
uint64_t
getTotalNodeMem(int nodeId)
{
    int i;
    FILE *fp;
    uint64_t total = 0;
    bstring totalString  = bformat("MemTotal:");
    bstring sysfilename = bformat("/sys/devices/system/node/node%d/meminfo", nodeId);
    bstring procfilename = bformat("/proc/meminfo");
    char *sptr = bdata(procfilename);

    if (NULL != (fp = fopen (bdata(sysfilename), "r")))
    {
        bstring src = bread ((bNread) fread, fp);
        struct bstrList* tokens = bsplit(src,(char) '\n');

        for (i=0;i<tokens->qty;i++)
        {
            if (binstr(tokens->entry[i],0,totalString) != BSTR_ERR)
            {
                 bstring tmp = bmidstr (tokens->entry[i], 18, blength(tokens->entry[i])-18  );
                 bltrimws(tmp);
                 struct bstrList* subtokens = bsplit(tmp,(char) ' ');
                 total = str2int(bdata(subtokens->entry[0]));
                 bdestroy(tmp);
                 bstrListDestroy(subtokens);
            }
        }
        bstrListDestroy(tokens);
        bdestroy(src);
        fclose(fp);
    }
    else if (!access(sptr, R_OK))
    {
        if (NULL != (fp = fopen (bdata(procfilename), "r")))
        {
            bstring src = bread ((bNread) fread, fp);
            struct bstrList* tokens = bsplit(src,(char) '\n');
            for (i=0;i<tokens->qty;i++)
            {
                if (binstr(tokens->entry[i],0,totalString) != BSTR_ERR)
                {
                     bstring tmp = bmidstr (tokens->entry[i], 10, blength(tokens->entry[i])-10  );
                     bltrimws(tmp);
                     struct bstrList* subtokens = bsplit(tmp,(char) ' ');
                     total = str2int(bdata(subtokens->entry[0]));
                     bdestroy(tmp);
                     bstrListDestroy(subtokens);
                }
            }
            bstrListDestroy(tokens);
            bdestroy(src);
            fclose(fp);
        }
    }
    else
    {
        bdestroy(totalString);
        bdestroy(sysfilename);
        bdestroy(procfilename);
        ERROR;
    }

    bdestroy(totalString);
    bdestroy(sysfilename);
    bdestroy(procfilename);
    return total;
}
示例#29
0
int cpustr_to_cpulist(char* cpustring, int* cpulist, int length)
{
    int insert = 0;
    int len = 0;
    int ret = 0;
    bstring bcpustr = bfromcstr(cpustring);
    struct bstrList* strlist = bstrListCreate();
    bstring scattercheck = bformat("scatter");
    topology_init();
    CpuTopology_t cpuid_topology = get_cpuTopology();
    strlist = bsplit(bcpustr, '@');

    int* tmpList = (int*)malloc(length * sizeof(int));
    if (tmpList == NULL)
    {
        bstrListDestroy(strlist);
        bdestroy(scattercheck);
        bdestroy(bcpustr);
        return -ENOMEM;
    }
    for (int i=0; i< strlist->qty; i++)
    {
        if (binstr(strlist->entry[i], 0, scattercheck) != BSTR_ERR)
        {
            ret = cpustr_to_cpulist_scatter(strlist->entry[i], tmpList, length);
            insert += cpulist_concat(cpulist, insert, tmpList, ret);
        }
        else if (bstrchrp(strlist->entry[i], 'E', 0) == 0)
        {
            ret = cpustr_to_cpulist_expression(strlist->entry[i], tmpList, length);
            insert += cpulist_concat(cpulist, insert, tmpList, ret);
        }
        else if (bstrchrp(strlist->entry[i], 'L', 0) == 0)
        {
            ret = cpustr_to_cpulist_logical(strlist->entry[i], tmpList, length);
            insert += cpulist_concat(cpulist, insert, tmpList, ret);
        }
        else if (cpuid_topology->activeHWThreads < cpuid_topology->numHWThreads)
        {
            fprintf(stdout, "INFO: You are running LIKWID in a cpuset with %d CPUs, only logical numbering allowed\n", cpuid_topology->activeHWThreads);
            if (((bstrchrp(strlist->entry[i], 'N', 0) == 0) ||
                (bstrchrp(strlist->entry[i], 'S', 0) == 0) ||
                (bstrchrp(strlist->entry[i], 'C', 0) == 0) ||
                (bstrchrp(strlist->entry[i], 'M', 0) == 0)) &&
                (bstrchrp(strlist->entry[i], ':', 0) != BSTR_ERR))
            {
                bstring newstr = bformat("L:");
                bconcat(newstr, strlist->entry[i]);
                ret = cpustr_to_cpulist_logical(newstr, tmpList, length);
                insert += cpulist_concat(cpulist, insert, tmpList, ret);
                bdestroy(newstr);
            }
            else
            {
                bstring newstr = bformat("L:N:");
                bconcat(newstr, strlist->entry[i]);
                ret = cpustr_to_cpulist_logical(newstr, tmpList, length);
                insert += cpulist_concat(cpulist, insert, tmpList, ret);
                bdestroy(newstr);
            }
        }
        else if (((bstrchrp(strlist->entry[i], 'N', 0) == 0) ||
            (bstrchrp(strlist->entry[i], 'S', 0) == 0) ||
            (bstrchrp(strlist->entry[i], 'C', 0) == 0) ||
            (bstrchrp(strlist->entry[i], 'M', 0) == 0)) &&
            (bstrchrp(strlist->entry[i], ':', 0) != BSTR_ERR))
        {
            bstring newstr = bformat("L:");
            bconcat(newstr, strlist->entry[i]);
            ret = cpustr_to_cpulist_logical(newstr, tmpList, length);
            insert += cpulist_concat(cpulist, insert, tmpList, ret);
            bdestroy(newstr);
        }

        else
        {
            ret = cpustr_to_cpulist_physical(strlist->entry[i], tmpList, length);
            insert += cpulist_concat(cpulist, insert, tmpList, ret);
        }
    }
    free(tmpList);
    bstrListDestroy(strlist);
    return insert;
}
示例#30
0
uint64_t
getFreeNodeMem(int nodeId)
{
    FILE *fp;
    bstring filename;
    uint64_t free = 0;
    bstring freeString  = bformat("MemFree:");
    int i;

    filename = bformat("/sys/devices/system/node/node%d/meminfo", nodeId);

    if (NULL != (fp = fopen (bdata(filename), "r")))
    {
        bstring src = bread ((bNread) fread, fp);
        struct bstrList* tokens = bsplit(src,(char) '\n');

        for (i=0;i<tokens->qty;i++)
        {
            if (binstr(tokens->entry[i],0,freeString) != BSTR_ERR)
            {
                 bstring tmp = bmidstr (tokens->entry[i], 18, blength(tokens->entry[i])-18  );
                 bltrimws(tmp);
                 struct bstrList* subtokens = bsplit(tmp,(char) ' ');
                 free = str2int(bdata(subtokens->entry[0]));
                 bdestroy(tmp);
                 bstrListDestroy(subtokens);
            }
        }
        bstrListDestroy(tokens);
        bdestroy(src);
        fclose(fp);
    }
    else if (!access("/proc/meminfo", R_OK))
    {
        bdestroy(filename);
        filename = bfromcstr("/proc/meminfo");
        if (NULL != (fp = fopen (bdata(filename), "r")))
        {
            bstring src = bread ((bNread) fread, fp);
            struct bstrList* tokens = bsplit(src,(char) '\n');
            for (i=0;i<tokens->qty;i++)
            {
                if (binstr(tokens->entry[i],0,freeString) != BSTR_ERR)
                {
                     bstring tmp = bmidstr (tokens->entry[i], 10, blength(tokens->entry[i])-10  );
                     bltrimws(tmp);
                     struct bstrList* subtokens = bsplit(tmp,(char) ' ');
                     free = str2int(bdata(subtokens->entry[0]));
                     bdestroy(tmp);
                     bstrListDestroy(subtokens);
                }
            }
            bstrListDestroy(tokens);
            bdestroy(src);
            fclose(fp);
        }
    }
    else
    {
        bdestroy(freeString);
        bdestroy(filename);
        ERROR;
    }
    bdestroy(freeString);
    bdestroy(filename);
    return free;
}