Exemplo n.º 1
0
lexer * lex_new_file(const char * filename) {
  script * s;
  if(0 == (s = scr_new(SCR_FILE, filename))) { return 0; }
  return lex_new(s);
}
Exemplo n.º 2
0
/* LATER deal with corrupt binary files? */
int binport_read(t_binbuf *bb, char *filename, char *dirname)
{
    int result;
    FILE *fp;
    char namebuf[MAXPDSTRING];
    namebuf[0] = 0;
    if (*dirname)
    	strcat(namebuf, dirname), strcat(namebuf, "/");
    strcat(namebuf, filename);
    sys_bashfilename(namebuf, namebuf);
    if (fp = fopen(namebuf, "rb"))
    {
	int ftype;
	t_binport *bp = binport_new(fp, &ftype);
	if (bp)
	{
	    if (ftype == BINPORT_MAXBINARY)
		result = (binport_tobinbuf(bp, bb)
			  ? BINPORT_MAXBINARY : BINPORT_CORRUPT);
	    else if (ftype == BINPORT_MAXTEXT)
	    {
		t_atom at;
		if (bp->b_lex = lex_new(fp, A_INT))
		{
		    while (binport_nextatom(bp, &at))
			if (at.a_type == A_SEMI)
			    break;
		    binbuf_addv(bb, "ss;", gensym("max"), gensym("v2"));
		    result = (binport_tobinbuf(bp, bb)
			      ? BINPORT_MAXTEXT : BINPORT_CORRUPT);
		}
		else result = BINPORT_FAILED;
	    }
	    else if (ftype == BINPORT_MAXOLD)
	    {
		t_binpold *old = binpold_new(fp);
		result = BINPORT_FAILED;
		if (old)
		{
		    bp->b_old = old;
		    if (binpold_load(old) && binport_tobinbuf(bp, bb))
			result = BINPORT_MAXOLD;
		}
		else binpold_failure(filename);
	    }
	    else result = BINPORT_FAILED;
	    binport_free(bp);
	}
	else if (ftype == BINPORT_PDFILE)
	    result = (binbuf_read(bb, filename, dirname, 0)
		      ? BINPORT_FAILED : BINPORT_PDFILE);
	else
	{
	    binport_failure(filename);
	    result = BINPORT_INVALID;
	}
    }
    else
    {
	binport_bug("cannot open file");
	result = BINPORT_FAILED;
    }
    return (result);
}