Example #1
0
int rc_getbuttons(FILE *file, char ***pbutton){
  char *s;
  int count;

  // count buttons
  count = 0;
  fseek(file, 0, SEEK_SET);
  while((s = rc_gettoken(file)) != NULL){
    if(strcmp(s, "button") == 0)
      count++;
  }

  // read buttons
  *pbutton = (char **)calloc(count, sizeof(char *));
  count = 0;
  fseek(file, 0, SEEK_SET);
  while((s = rc_gettoken(file)) != NULL){
    if(strcmp(s, "button") == 0){
      s = rc_gettoken(file);
      (*pbutton)[count++] = strdup(s);
    }
  }

  return count;
}
Example #2
0
/* pointer to the beginning of the results. */
int rd_parse (char func_name [], int break_no, char * last_break, char ** results) {
	struct element *e;
	int number;
	int err;
	struct rasl_instruction *translation, *q;
	char *blk_temp;

	/* don't need to allocate memory for tables etc. */

	/* set the output stream. */
	fdlis = rdout;

	/* initialize the parser. */
	err = 0;
	rc_initrp ();
	last_label = 1;

	/* get the first token and extract the function name. */
	token = rc_gettoken ();
	if (token != LCBRAK) {
		fprintf (rdout, "Illegal pattern.\n");
		return 1;
	}
	strcpy (func_name, str);
	nonret = (char *) malloc (MEM_BLK_SIZE);
	if (nonret == NULL) {
		fprintf (stderr,"Can\'t allocate memory.\n");
		return 1;
	}
	nrptr = 0;

	/* parse the pattern expression. */
	token = rc_gettoken ();
	e = refal_expression (0);
	if (token != '>') {
		fprintf (rdout, "Missing \'>\'\n");
		free ((void *) e);
		err = 1;
	}
	if (e == NULL) err = 2;
	else if (nerrors > 0) {
		free ((void *) e);
		err = 2;
	}

	/* set up some variables for the compiler. */
	if (!err) {
		number = 1;
		ftransl = (struct rasl_instruction *) malloc (sizeof (struct rasl_instruction));
		/* No checking of malloc result. Shura. 27.01.98 */
		if (NULL == ftransl) {
			exit (1);
		}
		/* Was ftransl -> code = NULL. Shura. 27.01.98 */
		ftransl -> code = 0;
		ftransl -> next = NULL;

		/* translation -> next is the first element of translation. */
		translation = (struct rasl_instruction *) malloc (sizeof (struct rasl_instruction));
		/* No checking of malloc result. Shura. 27.01.98 */
		if (NULL == translation) {
			exit (1);
		}
		/* Was translation -> code = NULL. Shura. 27.01.98 */
		translation -> code = 0;
		translation -> next = ftransl;

		table_len = 0;

		/* perform the actual translation. */
		transl_left (e, &number);

		/* copy variables to the break table with their offsets. */
		rd_cr_lvtab (break_no);

		/* free the memory for the expression. */
		free ((void *) e);

		/* perform the post optimizing ritual. */
		rc_post (translation);

		/* output the result. */
		rd_vyvod (translation, last_break, break_no, results);

		/* free the memory. */
		while (translation != NULL) {
			q = translation -> next;
			free ((void *) translation);
			translation = q;
		}
	}

	/* free the discardable memory: for strings etc. */
	while (block != NULL) {
		blk_temp = * ((char **) block);
		free ((void *) block);
		block = blk_temp;
	}

	/* free the compiler non-returnable memory: the Tracer doesn't need it. */
	if (nonret != NULL) free ((void *) nonret);

	return err;
}