Exemple #1
0
static PyObject *
graph_query(graphobject *self, PyObject *args) {
	PyObject *tpl;
	struct triple tr;
	struct substitution *fake = NULL;
	int i;
	if (!PyArg_ParseTuple(args, "O", &tpl))
		return NULL;
	if (!get_triple(tpl, &tr.subj, &tr.pred, &tr.obj)) {
		PyErr_SetString(PyExc_TypeError,
				"argument must be a 3-tuple");
		return NULL;
	}
	PyObject *lst = PyList_New(0);
	for (i = 0; i < self->pointer; i++) {
		struct triple *t = &self->triples[i];
		if (triple_matches(&tr, t, &fake)) {
			PyList_Append(lst,
				      tripleToPyTuple(t));
		}
	}
	return lst;
}
Exemple #2
0
int main(int argc, char **argv)
{
  int oc;
  GLint mdepth;
  extern char *optarg;
  extern int optind;
  char *outfile_name = NULL;
  FILE *outfile;
  int yyreturn;
  double triple[3];
  int num_initial_derivations = 0;
  unsigned int rndseed = 1;

  glutInit(&argc, argv);
  /* printf("%s\n", gluGetString(GLU_VERSION)); */
  while ((oc = getopt(argc, argv, "d:i:p:r:vh")) != -1)
  {
    switch(oc)
    {
    case 'v':
      verbose = 1;
      fprintf(stderr, "verbose mode activated\n");
      break;
    case 'd':
      num_initial_derivations = strtol(optarg, NULL, 10);
      break;
    case 'i':
      render_parameters.ppm_filename = optarg;
      break;
    case 's':
      rndseed = strtoul(optarg, NULL, 10);
      break;
    case 'r':
      if (get_triple(triple, optarg) == 0)
      {
	rotate_model(&render_parameters, 1, triple[0]);
	rotate_model(&render_parameters, 2, triple[1]);
	rotate_model(&render_parameters, 3, triple[2]);
      }
      else
	fprintf(stderr, "bad angle triple \"%s\"\n", optarg);
      break;
    case 'p':
      if (get_triple(triple, optarg) == 0)
      {
	render_parameters.view_position.x = triple[0];
	render_parameters.view_position.y = triple[1];
	render_parameters.view_position.z = triple[2];
      }
      else
	fprintf(stderr, "bad coordinate triple \"%s\"\n", optarg);
      break;
    case 'h':
      printf("ltransps -- make PostScript ltranssys derivation series\n");
      printf("usage: %s [options] <infile> <outfile>\n", argv[0]);
      printf("options:\n");
      printf("-d <num>: specify initial number of derivations\n");
      printf("-i <filename>: specify image file name (PPM format)\n");
      printf("-p <num>,<num>,<num>: specify initial viewer coordinates\n");
      printf("-r <num>,<num>,<num>: specify initial model rotation angles\n");
      printf("-h: print this help and exit\n");
      exit(EXIT_SUCCESS);
    }
  }
  if (optind < argc)
    yyin_name = argv[optind++];
  if (optind < argc)
    outfile_name = argv[optind++];
  if (yyin_name)
  {
    if ((yyin = fopen(yyin_name, "r")) == NULL)
    {
      fprintf(stderr, "Failed to open \"%s\" for input -- exit\n", yyin_name);
      exit(EXIT_FAILURE);
    }
  }
  else
  {
    yyin = stdin;
    yyin_name = "stdin";
  }
  if (outfile_name)
  {
    if ((outfile = fopen(outfile_name, "w")) == NULL)
    {
      fprintf(stderr, "Failed to open \"%s\" for output -- exit\n", outfile_name);
      if (yyin != stdin)
        fclose(yyin);
      exit(EXIT_FAILURE);
    }
  }
  else
  {
    outfile = stdout;
    outfile_name = "stdout";
  }
  yyreturn = yyparse();
  if (yyreturn)
  {
    fprintf(stderr, "Failed to parse from \"%s\" -- exit\n", yyin_name);
    if (yyin != stdin)
      fclose(yyin);
    if (outfile != stdout)
      fclose(outfile);
    exit(EXIT_FAILURE);
  }
  if (parsed_lsys == NULL)
  {
    fprintf(stderr, "No lsys found in \"%s\" -- exit\n", yyin_name);
    if (yyin != stdin)
      fclose(yyin);
    if (outfile != stdout)
      fclose(outfile);
    free_transsys_list(parsed_transsys);
    exit(EXIT_FAILURE);
  }    
  ulong_srandom(rndseed);
  init_lstr_block(&lstr_block, parsed_lsys);
  lstr_block.string_index = num_initial_derivations;
  ltgl_init();
  glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &mdepth);
  printf("max matrix depth is %d\n", (int) mdepth);
  glutMainLoop();
  fprintf(stderr, "glutMainLoop() finished\n");
  if (yyin != stdin)
    fclose(yyin);
  if (outfile != stdout)
    fclose(outfile);
  return (EXIT_SUCCESS);
}
Exemple #3
0
static int
get_triple_from_many(PyObject *tpl, int index,
		     int *s, int *p, int *o) {
	return get_triple(PyTuple_GetItem(tpl, index), s, p, o);
}