Esempio n. 1
0
int main(int argc, char *argv[])
{
    char *listName = "finished.new";
    char *fofName = "unfinished_acc.fof";
    char *outName = "frags.txt";
    FILE *out = mustOpen(outName, "w");
    struct fof *fof = fofOpen(fofName, NULL);
    struct kvt *kvt = newKvt(64);
    char line[512];
    int lineCount = 0;
    FILE *lf;
    char *keyText;
    char *s, *t;
    int size;

    lf = mustOpen(listName, "r");
    while (fgets(line, sizeof(line), lf))
    {
        ++lineCount;
        kvtClear(kvt);
        s = trimSpaces(line);
        t = strchr(s, '.');
        if (t != NULL)
            *t = 0;
        keyText = fofFetchString(fof, s, &size);
        kvtParseAdd(kvt, keyText);
        fprintf(out, "%s phase %s frags %s\n", s, kvtLookup(kvt, "pha"), kvtLookup(kvt, "frg"));
        freez(&keyText);
    }
    freeKvt(&kvt);
    return 0;
}
Esempio n. 2
0
void scanFile(struct keyExp *exp, char *fileName)
/* Scan file for things that match expression. */
{
FILE *f = mustOpen(fileName, "r");
int keyBufSize = 32*1024;
char *keysBuf = needMem(keyBufSize+1);
int lastc, c;
int kbIx;
int modMax = 10000;
int mod = modMax;

printf("scanning %s", fileName);
fflush(stdout);
for (;;)
    {
    if (--mod <= 0)
        {
        printf(".");
        fflush(stdout);
        mod = modMax;
        }
    kvtClear(kvt);
    kbIx = 0;
    lastc = 0;
    for (;;)
        {
        if (((c = fgetc(f)) == EOF) || (c == '\n' && lastc == '\n'))
            break;         
        keysBuf[kbIx] = c;
        if (++kbIx >= keyBufSize)
            errAbort("Record too long\n");
        lastc = c;
        }
    if (kbIx > 0)
        {
        kvtParseAdd(kvt, keysBuf);
        if (exp == NULL || keyExpEval(exp, kvt))
            {
            ++matchCount;
            if (command == ctPrint)
                {
                char *kv = kvtLookup(kvt, selectKey);
                if (kv == NULL)
                    kv = "NULL";
                fprintf(out, "%s\n", kv);
                }
            if (command == ctStats || command == ctHist)
                {
                char *kv = kvtLookup(kvt, selectKey);
                struct useCount *u;
                struct hashEl *hel;
                if (kv == NULL)
                    kv = "NULL";
                if ((hel = hashLookup(statHash, kv)) == NULL)
                    {
                    AllocVar(u);
                    hel = hashAdd(statHash, kv, u);
                    u->what = hel->name;
                    u->count = 1;
                    slAddHead(&useCounts, u);
                    }
                else
                    {
                    u = hel->val;
                    ++u->count;
                    }
                }
            }
        }
    if (c == EOF)
        break;
    }
freeMem(keysBuf);
fclose(f);
printf("\n");
}