Example #1
0
/*
 * Allocate a new completion structure.
 */
Completion *
completion_new (int fileflag)
{
  Completion *cp = (Completion *) XZALLOC (Completion);

  cp->completions = gl_list_create_empty (GL_LINKED_LIST,
                                          completion_streq, NULL,
                                          (gl_listelement_dispose_fn) free, false);
  cp->matches = gl_list_create_empty (GL_LINKED_LIST,
                                      completion_streq, NULL,
                                      NULL, false);

  if (fileflag)
    {
      cp->path = astr_new ();
      cp->flags |= CFLAG_FILENAME;
    }

  return cp;
}
Example #2
0
/*
 * level_disasm()
 */
static void level_disasm(uint8_t dunno, uint8_t levno)
{
    uint32_t	i;
    b3level_t	*level;
    FILE		*fp;
    uint16_t	offset;

    rangeSkipList = gl_list_create_empty(GL_ARRAY_LIST,
                                         NULL, NULL, range_free, 1);

    level = readMap(duns[dunno].levels[levno]);

    currentLevel.dataStartOffset	= level->dataBaseOffset;
    currentLevel.monsterIndex	= level->monIndex;

    if ((dunno == 11) && (levno == 0))
        currentLevel.codeStartOffset = 4;
    else
        currentLevel.codeStartOffset = 0;

    fp = xfopen(mkCodePath("%s-%d.code", duns[dunno].name, levno), "wb");

#undef DUMP_CODE
#ifdef DUMP_CODE
    dump_btstring(bts_sprintf("%s-%d.dump", duns[dunno].name, levno),
                  level->codeBuf, 0);
#endif

    for (i = 0; i < level->dataCount; i++) {
        offset = level->dataList[i].offset;
        fprintf(fp, "(%3d, %3d) offset: %04x\n",
                level->dataList[i].sqE,
                level->dataList[i].sqN,
                offset
               );
    }
    fprintf(fp, "=====================================\n");

    disasmCode(fp, level->codeBuf, level->dataBaseOffset);

    gl_list_free(rangeSkipList);
    rangeSkipList = NULL;

    fclose(fp);

    freeLevel(level);
}
Example #3
0
/*
 * city_disasm()
 */
static void city_disasm(uint8_t cityno)
{
    uint32_t	i;
    b3city_t	*city;
    FILE		*fp;
    uint16_t	offset;

    rangeSkipList = gl_list_create_empty(GL_ARRAY_LIST,
                                         NULL, NULL, range_free, 1);

    city	= readCity(cityno);

    currentLevel.dataStartOffset	= city->dataBaseOffset;
    currentLevel.monsterIndex	= city->monsterIndex;
    currentLevel.codeStartOffset	= 0;

    fp = xfopen(mkCodePath("%s.code", cityList[cityno].name, 0), "wb");

    for (i = 0; i < city->dataCount; i++) {
        offset	= city->dataList[i].offset;
        fprintf(fp, "(%3d, %3d) offset: %04x\n",
                city->dataList[i].sqE,
                city->dataList[i].sqN,
                offset
               );
    }

    fprintf(fp, "=====================================\n");

#undef DUMP_CODE
#ifdef DUMP_CODE
    dump_btstring(bts_sprintf("%s.dump", cityList[cityno].name),
                  city->codeBuf, 1);
#endif

    disasmCode(fp, city->codeBuf, city->dataBaseOffset);

    gl_list_free(rangeSkipList);
    rangeSkipList = NULL;

    fclose(fp);

    freeCity(city);
}
Example #4
0
/** 
 * @see free_tmpfiles
 * @see tmpfiles
 *
 */
const char *
tmpfile_name (void)
{
  /* If this is the first time that this routine is run, set up the
     list and add the destructors to the cleanup functions. */
  if (tmpfiles == NULL)
    {
      /** @note @parblock Incorperate GL_LINKED_LIST's feature to
	  make all actions on it signal safe.  This is turned on in
	  configure.ac by invoking:

	  @code
	  AC_DEFINE([SIGNAL_SAFE_LIST], [1],
	            [Define if lists must be signal-safe.])
	  @endcode

	  Thus this can be safely cleaned up while catching a fatal
	  signal.  @endparblock 
      */
      tmpfiles = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, 1);
      /* Register the free_tmpfiles cleanup function so that it is
	 called when the program exits and whenever the program
	 recieves a fatal signal. */
      atexit (free_tmpfiles);
      at_fatal_signal (free_tmpfiles);
    }

  /* Determine the name of the temporary file. */
  char *out = xstrdup ("compilerXXXXXX");
  int fd = gen_tempname (out, 0, 0, GT_FILE);
  if (fd < 0)
    error (1, errno, _("FATAL: failed to create temporary file"));
  else if (close (fd))
    error (1, errno, _("FATAL: failed to close the temporary file"));

  /* Add the entry to the list of temporary files. */
  gl_list_add_last (tmpfiles, out);

  return out;
}
Example #5
0
static void
html_ostream::end_span (html_ostream_t stream, const char *classname)
{
  if (!(stream->curr_class_stack_size > 0
        && strcmp ((char *) gl_list_get_at (stream->class_stack,
                                            stream->curr_class_stack_size - 1),
                   classname) == 0))
    /* Improperly nested begin_span/end_span calls.  */
    abort ();
  stream->curr_class_stack_size--;
}

/* Constructor.  */

html_ostream_t
html_ostream_create (ostream_t destination)
{
  html_ostream_t stream = XMALLOC (struct html_ostream_representation);

  stream->base.vtable = &html_ostream_vtable;
  stream->destination = destination;
  stream->class_stack =
    gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, true);
  stream->curr_class_stack_size = 0;
  stream->last_class_stack_size = 0;
  stream->buflen = 0;

  return stream;
}
Example #6
0
int
main (int argc, char *argv[])
{
  gl_list_t list1, list2;

  set_program_name (argv[0]);

  /* Allow the user to provide a non-default random seed on the command line.  */
  if (argc > 1)
    srand (atoi (argv[1]));

  {
    size_t initial_size = RANDOM (50);
    const void **contents =
      (const void **) malloc (initial_size * sizeof (const void *));
    size_t i;
    unsigned int repeat;

    for (i = 0; i < initial_size; i++)
      contents[i] = RANDOM_OBJECT ();

    /* Create list1.  */
    list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, NULL, true,
                            initial_size, contents);
    /* Create list2.  */
    list2 = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, true);
    for (i = 0; i < initial_size; i++)
      gl_list_add_last (list2, contents[i]);

    check_equals (list1, list2);

    for (repeat = 0; repeat < 10000; repeat++)
      {
        unsigned int operation = RANDOM (16);
        switch (operation)
          {
          case 0:
            if (gl_list_size (list1) > 0)
              {
                size_t index = RANDOM (gl_list_size (list1));
                const char *obj = RANDOM_OBJECT ();
                gl_list_node_t node1, node2;

                node1 = gl_list_set_at (list1, index, obj);
                ASSERT (gl_list_get_at (list1, index) == obj);
                ASSERT (gl_list_node_value (list1, node1) == obj);

                node2 = gl_list_set_at (list2, index, obj);
                ASSERT (gl_list_get_at (list2, index) == obj);
                ASSERT (gl_list_node_value (list2, node2) == obj);

                if (index > 0)
                  {
                    ASSERT (gl_list_node_value (list1, gl_list_previous_node (list1, node1))
                            == gl_list_get_at (list1, index - 1));
                  }
                if (index + 1 < gl_list_size (list1))
                  {
                    ASSERT (gl_list_node_value (list1, gl_list_next_node (list1, node1))
                            == gl_list_get_at (list1, index + 1));
                  }
              }
            break;
          case 1:
            {
              const char *obj = RANDOM_OBJECT ();
              gl_list_node_t node1, node2;
              node1 = gl_list_search (list1, obj);
              node2 = gl_list_search (list2, obj);
              if (node1 == NULL)
                {
                  ASSERT (node2 == NULL);
                }
              else
                {
                  ASSERT (node2 != NULL);
                  ASSERT (gl_list_node_value (list1, node1) == obj);
                  ASSERT (gl_list_node_value (list2, node2) == obj);
                }
            }
            break;
          case 2:
            {
              const char *obj = RANDOM_OBJECT ();
              size_t index1, index2;
              index1 = gl_list_indexof (list1, obj);
              index2 = gl_list_indexof (list2, obj);
              if (index1 == (size_t)(-1))
                {
                  ASSERT (index2 == (size_t)(-1));
                }
              else
                {
                  ASSERT (index2 != (size_t)(-1));
                  ASSERT (gl_list_get_at (list1, index1) == obj);
                  ASSERT (gl_list_get_at (list2, index2) == obj);
                  ASSERT (index2 == index1);
                }
            }
            break;
          case 3: /* add 1 element */
            {
              const char *obj = RANDOM_OBJECT ();
              gl_list_node_t node1, node2;
              node1 = gl_list_add_first (list1, obj);
              node2 = gl_list_add_first (list2, obj);
              ASSERT (gl_list_node_value (list1, node1) == obj);
              ASSERT (gl_list_node_value (list2, node2) == obj);
              ASSERT (gl_list_get_at (list1, 0) == obj);
              ASSERT (gl_list_get_at (list2, 0) == obj);
            }
            break;
          case 4: /* add 1 element */
            {
              const char *obj = RANDOM_OBJECT ();
              gl_list_node_t node1, node2;
              node1 = gl_list_add_last (list1, obj);
              node2 = gl_list_add_last (list2, obj);
              ASSERT (gl_list_node_value (list1, node1) == obj);
              ASSERT (gl_list_node_value (list2, node2) == obj);
              ASSERT (gl_list_get_at (list1, gl_list_size (list1) - 1) == obj);
              ASSERT (gl_list_get_at (list2, gl_list_size (list2) - 1) == obj);
            }
            break;
          case 5: /* add 3 elements */
            {
              const char *obj0 = RANDOM_OBJECT ();
              const char *obj1 = RANDOM_OBJECT ();
              const char *obj2 = RANDOM_OBJECT ();
              gl_list_node_t node1, node2;
              node1 = gl_list_add_first (list1, obj2);
              node1 = gl_list_add_before (list1, node1, obj0);
              node1 = gl_list_add_after (list1, node1, obj1);
              node2 = gl_list_add_first (list2, obj2);
              node2 = gl_list_add_before (list2, node2, obj0);
              node2 = gl_list_add_after (list2, node2, obj1);
              ASSERT (gl_list_node_value (list1, node1) == obj1);
              ASSERT (gl_list_node_value (list2, node2) == obj1);
              ASSERT (gl_list_get_at (list1, 0) == obj0);
              ASSERT (gl_list_get_at (list1, 1) == obj1);
              ASSERT (gl_list_get_at (list1, 2) == obj2);
              ASSERT (gl_list_get_at (list2, 0) == obj0);
              ASSERT (gl_list_get_at (list2, 1) == obj1);
              ASSERT (gl_list_get_at (list2, 2) == obj2);
            }
            break;
          case 6: /* add 1 element */
            {
              size_t index = RANDOM (gl_list_size (list1) + 1);
              const char *obj = RANDOM_OBJECT ();
              gl_list_node_t node1, node2;
              node1 = gl_list_add_at (list1, index, obj);
              node2 = gl_list_add_at (list2, index, obj);
              ASSERT (gl_list_get_at (list1, index) == obj);
              ASSERT (gl_list_node_value (list1, node1) == obj);
              ASSERT (gl_list_get_at (list2, index) == obj);
              ASSERT (gl_list_node_value (list2, node2) == obj);
              if (index > 0)
                {
                  ASSERT (gl_list_node_value (list1, gl_list_previous_node (list1, node1))
                          == gl_list_get_at (list1, index - 1));
                }
              if (index + 1 < gl_list_size (list1))
                {
                  ASSERT (gl_list_node_value (list1, gl_list_next_node (list1, node1))
                          == gl_list_get_at (list1, index + 1));
                }
            }
            break;
          case 7: case 8: /* remove 1 element */
            if (gl_list_size (list1) > 0)
              {
                size_t n = gl_list_size (list1);
                const char *obj = gl_list_get_at (list1, RANDOM (n));
                gl_list_node_t node1, node2;
                node1 = gl_list_search (list1, obj);
                node2 = gl_list_search (list2, obj);
                ASSERT (node1 != NULL);
                ASSERT (node2 != NULL);
                ASSERT (gl_list_remove_node (list1, node1));
                ASSERT (gl_list_remove_node (list2, node2));
                ASSERT (gl_list_size (list1) == n - 1);
              }
            break;
          case 9: case 10: /* remove 1 element */
            if (gl_list_size (list1) > 0)
              {
                size_t n = gl_list_size (list1);
                size_t index = RANDOM (n);
                ASSERT (gl_list_remove_at (list1, index));
                ASSERT (gl_list_remove_at (list2, index));
                ASSERT (gl_list_size (list1) == n - 1);
              }
            break;
          case 11: case 12: /* remove 1 element */
            if (gl_list_size (list1) > 0)
              {
                size_t n = gl_list_size (list1);
                const char *obj = gl_list_get_at (list1, RANDOM (n));
                ASSERT (gl_list_remove (list1, obj));
                ASSERT (gl_list_remove (list2, obj));
                ASSERT (gl_list_size (list1) == n - 1);
              }
            break;
          case 13:
            if (gl_list_size (list1) > 0)
              {
                size_t n = gl_list_size (list1);
                const char *obj = "xyzzy";
                ASSERT (!gl_list_remove (list1, obj));
                ASSERT (!gl_list_remove (list2, obj));
                ASSERT (gl_list_size (list1) == n);
              }
            break;
          case 14:
            {
              size_t n = gl_list_size (list1);
              gl_list_iterator_t iter1, iter2;
              const void *elt;
              iter1 = gl_list_iterator (list1);
              iter2 = gl_list_iterator (list2);
              for (i = 0; i < n; i++)
                {
                  ASSERT (gl_list_iterator_next (&iter1, &elt, NULL));
                  ASSERT (gl_list_get_at (list1, i) == elt);
                  ASSERT (gl_list_iterator_next (&iter2, &elt, NULL));
                  ASSERT (gl_list_get_at (list2, i) == elt);
                }
              ASSERT (!gl_list_iterator_next (&iter1, &elt, NULL));
              ASSERT (!gl_list_iterator_next (&iter2, &elt, NULL));
              gl_list_iterator_free (&iter1);
              gl_list_iterator_free (&iter2);
            }
            break;
          case 15:
            {
              size_t end = RANDOM (gl_list_size (list1) + 1);
              size_t start = RANDOM (end + 1);
              gl_list_iterator_t iter1, iter2;
              const void *elt;
              iter1 = gl_list_iterator_from_to (list1, start, end);
              iter2 = gl_list_iterator_from_to (list2, start, end);
              for (i = start; i < end; i++)
                {
                  ASSERT (gl_list_iterator_next (&iter1, &elt, NULL));
                  ASSERT (gl_list_get_at (list1, i) == elt);
                  ASSERT (gl_list_iterator_next (&iter2, &elt, NULL));
                  ASSERT (gl_list_get_at (list2, i) == elt);
                }
              ASSERT (!gl_list_iterator_next (&iter1, &elt, NULL));
              ASSERT (!gl_list_iterator_next (&iter2, &elt, NULL));
              gl_list_iterator_free (&iter1);
              gl_list_iterator_free (&iter2);
            }
            break;
          }
        check_equals (list1, list2);
      }

    gl_list_free (list1);
    gl_list_free (list2);
    free (contents);
  }

  return 0;
}
int
main (int argc, char *argv[])
{
  gl_oset_t set1;
  gl_list_t set2;

  set_program_name (argv[0]);

  /* Allow the user to provide a non-default random seed on the command line.  */
  if (argc > 1)
    srand (atoi (argv[1]));

  {
    size_t initial_size = RANDOM (20);
    size_t i;
    unsigned int repeat;

    /* Create set1.  */
    set1 = gl_oset_nx_create_empty (GL_ARRAY_OSET, (gl_setelement_compar_fn) strcmp, NULL);
    ASSERT (set1 != NULL);

    /* Create set2.  */
    set2 = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, false);

    check_all (set1, set2);

    /* Initialize them.  */
    for (i = 0; i < initial_size; i++)
      {
        const char *obj = RANDOM_OBJECT ();
        ASSERT (gl_oset_nx_add (set1, obj)
                == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL
                    ? false
                    : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true)));
        check_all (set1, set2);
      }

    for (repeat = 0; repeat < 100000; repeat++)
      {
        unsigned int operation = RANDOM (3);
        switch (operation)
          {
          case 0:
            {
              const char *obj = RANDOM_OBJECT ();
              ASSERT (gl_oset_search (set1, obj)
                      == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL));
            }
            break;
          case 1:
            {
              const char *obj = RANDOM_OBJECT ();
              ASSERT (gl_oset_nx_add (set1, obj)
                      == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL
                          ? false
                          : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true)));
            }
            break;
          case 2:
            {
              const char *obj = RANDOM_OBJECT ();
              ASSERT (gl_oset_remove (set1, obj)
                      == gl_sortedlist_remove (set2, (gl_listelement_compar_fn)strcmp, obj));
            }
            break;
          }
        check_all (set1, set2);
      }

    gl_oset_free (set1);
    gl_list_free (set2);
  }

  return 0;
}