예제 #1
0
void nemo_main(void) /* this replaces main(argc,argv)        <--- required */
{
    stream instr, outstr;
    string times = getparam("times");
    real   tsnap;
    Body  *btab = NULL, *bp;
    int    i, nbody, bits;
    bool   first = TRUE;

    instr = stropen(getparam("in"), "r");
    outstr = stropen(getparam("out"), "w");

    for (;;) {    /* infinite loop, broken only when ran out of snapshots */
    	get_history(instr);                    /* read history */
        if (!get_tag_ok(instr, SnapShotTag)) break; /* check if done */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);  /* get next */
        
        /* Operate on the snapshot here : */
        for (bp=btab, i=0; i<nbody; bp++, i++) {
            /* all the work goes here */
        }
        if (first) {
            put_history(outstr);
            first = FALSE;
        }
        put_snap(outstr, &btab, &nbody, &tsnap, &bits);     /* output */
    }
    strclose(instr);
    if (first) {
    	warning("No snapshots processed");
  	strdelete(outstr,TRUE);
    } else
        strclose(outstr);
}
예제 #2
0
파일: stropen.c 프로젝트: jobovy/nemo
void testing(string name, string mode, string text, bool del)
{
    char buf[128];
    stream str;

    str = stropen(name, mode);
    dprintf(0,"%s has strname -> %s\n", name, strname(str));
    dprintf(0,"%s has strseek -> %d\n", name, strseek(str)?1:0);

    if (streq(mode, "a") || streq(mode, "r")) {
        printf("READING\n");
	while (fgets(buf, 127, str) != NULL)
	    printf("%s", buf);
    }

    if (streq(mode,"w") || streq(mode,"w!") ||
	streq(mode,"s") || streq(mode,"a")) {
        printf("WRITING\n");
        sprintf(buf, "%s\n", text);
	fputs(buf, str);
    }

    if (streq(mode, "s")) {
      printf("REWIND AND READING\n");
        rewind(str);
	while (fgets(buf, 127, str) != NULL)
	    printf("%s", buf);
    }

    if (del)
        strdelete(str,TRUE);
    else
        strclose(str);
}
예제 #3
0
char *
shorten_e_num (char *s)
{
  char *pos;
  char e = 'e';
  pos = strchr (s, e);
  strdelete (s, (int) (pos - s) + 2, 3);
  return s;
}
예제 #4
0
void
mn_delete(cml_node *mn)
{
    strdelete(mn->name);
    strdelete(mn->banner);
    listclear(mn->rules_using);
    if (mn->visibility_expr != 0)
    	expr_destroy(mn->visibility_expr);
    if (mn->saveability_expr != 0)
    	expr_destroy(mn->saveability_expr);
    /* only remove the list structure, all nodes are deleted seperately */
    listclear(mn->children);
    if (mn->expr != 0)
    	expr_destroy(mn->expr);
    atom_dtor(&mn->value);
    listclear(mn->transactions_guarded);
    listclear(mn->bindings);
    range_delete(mn->range);
    listdelete(mn->enumdefs, cml_enumdef, cml_enumdef_delete);
    listclear(mn->dependants);
    listclear(mn->dependees);
    strdelete(mn->help_text);
    g_free(mn);
}