static void pukeit(const char *db, const char *defstring, char *retstring, int retsize, int *cqnum) { FILE *fp; char **help; int i, nhlp; gmx_rng_t rng; if (be_cool() && ((fp = low_libopen(db, FALSE)) != NULL)) { nhlp = fget_lines(fp, &help); /* for libraries we can use the low-level close routines */ gmx_ffclose(fp); rng = gmx_rng_init(gmx_rng_make_seed()); *cqnum = static_cast<int>(nhlp*gmx_rng_uniform_real(rng)); gmx_rng_destroy(rng); if (strlen(help[*cqnum]) >= STRLEN) { help[*cqnum][STRLEN-1] = '\0'; } strncpy(retstring, help[*cqnum], retsize); for (i = 0; (i < nhlp); i++) { sfree(help[i]); } sfree(help); } else { *cqnum = -1; strncpy(retstring, defstring, retsize); } }
static void pukeit(const char *db,const char *defstring, char *retstring, int retsize, int *cqnum) { FILE *fp; char **help; int i,nhlp; int seed; if (be_cool() && ((fp = low_libopen(db,FALSE)) != NULL)) { nhlp=fget_lines(fp,&help); /* for libraries we can use the low-level close routines */ ffclose(fp); seed=time(NULL); *cqnum=nhlp*rando(&seed); if (strlen(help[*cqnum]) >= STRLEN) help[*cqnum][STRLEN-1] = '\0'; strncpy(retstring,help[*cqnum],retsize); f(retstring); for(i=0; (i<nhlp); i++) sfree(help[i]); sfree(help); } else strncpy(retstring,defstring,retsize); }
int get_lines(const char *db,char ***strings) { FILE *in; int nstr; in = libopen(db); nstr = fget_lines(in,strings); ffclose(in); return nstr; }