tool to upload data to a SuperCharger cartridge
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.0KB

  1. /* queue.c */
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "queue.h"
  7. /* allocates enough memory to store 1 q node */
  8. struct qnode *qalloc(void) {
  9. return (struct qnode *) malloc(sizeof(struct qnode));
  10. }
  11. /* returns pointer to duplicate of s */
  12. struct qnode *qdup(struct qnode *s, int *fileCount)
  13. {
  14. struct qnode *temp, *p;
  15. p = NULL;
  16. temp = s;
  17. while (temp != NULL) {
  18. p = addq(p,temp->fileName, fileCount);
  19. temp = temp->next;
  20. }
  21. return p;
  22. }
  23. /* adds q node to tail of p - use form 'p = addq(p,w,t)' */
  24. struct qnode *addq(struct qnode *p, char *fileName, int *fileCount)
  25. {
  26. if (p == NULL) {
  27. p = qalloc();
  28. strcpy(p->fileName, fileName);
  29. p->next = NULL;
  30. (*fileCount)++;
  31. }
  32. else if (strcmp(p->fileName, fileName))
  33. p->next = addq(p->next, fileName, fileCount);
  34. return p;
  35. }
  36. /* remove node from head of p - use form 'p = delq(p)' */
  37. /* frees memory previously used by node deleted */
  38. struct qnode *delq(struct qnode *p)
  39. {
  40. struct qnode *t;
  41. t = p;
  42. if (p != NULL) {
  43. t = p->next;
  44. free(p);
  45. }
  46. return t;
  47. }
  48. /* deletes all nodes from queue pointed to by p */
  49. void clearq(struct qnode *p)
  50. {
  51. while (p != NULL)
  52. p = delq(p);
  53. }
  54. /* prints all bursts in a q - used for debugging */
  55. void qprint(struct qnode *p)
  56. {
  57. if (p != NULL) {
  58. printf("FileName: %s\n",p->fileName);
  59. qprint(p->next);
  60. }
  61. }
  62. /*
  63. main()
  64. {
  65. struct qnode *addresses;
  66. addresses = NULL;
  67. addresses = addq(addresses,0xfeac);
  68. addresses = addq(addresses,0xfbba);
  69. qprint(addresses);
  70. printf("--\n");
  71. printf("%0.4X\n",addresses->address);
  72. addresses = delq(addresses);
  73. printf("%0.4x\n",addresses->address);
  74. }
  75. */