void test_string_concat() {
  const char *test_type = "string", *test_content = "concat";
  bool ok = 1;
  String s1 = sinit();
  String s2 = sinit();

  for (int i = 0; i < 50; i++) {
    sinsertc(&s1, s1.size, i);
  }

  for (int i = 0; i < 50; i++) {
    sinsertc(&s2, s2.size, i+50);
  }

  String s3 = sconcat(s1, s2);

  for (int i = 0; i < 100; i++) {
    if (snth(s3, i) != i) {
      ok = 0;
      break;
    }
  }

  if (!ok) {
    printf("%s test fails on %s.\n", test_type, test_content);
  }

  sdestro(&s1);
  sdestro(&s2);
  sdestro(&s3);
}
Beispiel #2
0
const char * srepresent(const char * string)
{
    char * result;
    result = "";
    for (size_t i = 0; i < strlen(string); i++) {
        sconcat(result, sformat("%d|", (int)string[i]));
    }
    return result;
}
Beispiel #3
0
void cons(char *str, char *lstr) {
  int len = slength(str);

  if (len <= 0) {
    iwrites("Error: No string entered\n");
  }
  else {
    sconcat(lstr, str);

    iwrites("The string added to the buffer looks like this:\n");
    iwrites(str);
    iwrites("\n");
  }
}
Beispiel #4
0
	void send_regular_msg(const FirstType& first_val, 
		const RemArgTypes&... rem_args)
	{
		std::string orig_to_send, to_send;

		if (comm_type() == CommType::Discord)
		{
			orig_to_send += "``` ";
		}

		orig_to_send += sconcat(first_val, rem_args...);


		if (comm_type() == CommType::Discord)
		{
			orig_to_send += " ```";

		}


		for (auto iter : orig_to_send)
		{
			//if ((comm_type() == CommType::Discord)
			//	&& ((iter == '\"') || (iter == '\\')
			//	|| (iter == '`')))
			if ((comm_type() == CommType::Discord)
				&& ((iter == '\"') || (iter == '\\')))
			{
				to_send += '\\';
				//if (iter == '`')
				//{
				//	to_send += '\\';
				//}
			}
			to_send += iter;
		}

		//if (comm_type() == CommType::Discord)
		//{
		//	to_send += "\n\\`\\`\\`";
		//}


		printout("Communicator::send_regular_msg():  ", to_send, "\n");
		inner_send_regular_msg(std::move(to_send));

	}
Beispiel #5
0
static void tioServer(void) {
    Create(TIO_NOTIFIER_PRIORITY, tioNotifier);

    int rx_tid = -1;
    struct String rx_buffer;
    sinit(&rx_buffer);

    while (true) {
        int tid;
        struct String req;
        sinit(&req);

        if (g_tio_quit) {
            break;
        }

        Receive(&tid, (char *) &req, sizeof(struct String));

        switch (stag(&req)) {
            default:
                assert(0);

            case CMD_NOTIFIER_RX:
                sconcat(&rx_buffer, &req);
                Reply(tid, (char *) 0, 0);

                break;

            case CMD_USER_TX: {
                char *buf = sbuffer(&req);

                for (unsigned int i = 0; i < slen(&req); ++i) {
                    g_tio_tx_buffer.buffer[g_tio_tx_buffer.tail] = buf[i];
                    g_tio_tx_buffer.tail =
                        (g_tio_tx_buffer.tail + 1) % TIO_TX_BUFFER_LEN;
                }

                Reply(tid, (char *) 0, 0);

                /* raise a software interrupt to inform the notifier */
                *((volatile unsigned int *)
                    (SOFTINT_BASE + VIC_SOFTWARE_INT)) = SOFTINT_POS;

                break;
            }

            case CMD_USER_RX:
                assert(rx_tid == -1);
                rx_tid = tid;
                break;

            case CMD_QUIT:
                g_tio_quit = true;
                Reply(tid, (char *) 0, 0);

                /* raise a software interrupt to quit the notifier */
                *((volatile unsigned int *)
                    (SOFTINT_BASE + VIC_SOFTWARE_INT)) = SOFTINT_POS;

                break;
        }

        if (slen(&rx_buffer) > 0 && rx_tid >= 0) {
            Reply(rx_tid, (char *) &rx_buffer, sizeof(struct String));

            sinit(&rx_buffer);
            rx_tid = -1;
        }
    }

    Exit();
}
static void load(const char *fname)
{
  char buf[4096];
  FILE *f;
  instr *i = 0;
  int line = 0;

  sprintf(buf, "Error opening %s for reading\n", fname);
  f = fopen(fname, "r");
  if(!f) {
    perror(buf);
    exit(1);
  }

  while(fgets(buf, sizeof(buf), f)) {
    char *p = buf;

    while(*p && *p != '\r' && *p != '\n')
      p++;
    *p = 0;

    line++;

    if(!buf[0]) {
      i = 0;
      continue;
    }
    if(buf[0] == ' ' || buf[0] == '\t') {
      if(!i) {
	fprintf(stderr, "%s:%d: Text line without an instruction.\n", fname, line);
	exit(1);
      }
      if(i->dasm)
	i->run = sconcat(i->run, buf);
      else {
	p = buf;
	while(*p == ' ' || *p == '\t')
	  p++;
	i->dasm = xstrdup(p);
      }
    } else {
      char *name=0, *cat=0, *id=0, *cyc=0, *rep=0, *type=0;
      p = buf;
      int pid, limit;
      instr *bi;
      unsigned int flags;

      name = p;
      next(&p);
      cat = p;
      next(&p);
      id = p;
      next(&p);
      cyc = p;
      next(&p);
      rep = p;
      next(&p);
      type = p;
      next(&p);
      if(*p) {
	fprintf(stderr, "%s:%d: Extra text at end of instruction description.\n", fname, line);
	exit(1);
      }
      if(!rep[0]) {
	fprintf(stderr, "%s:%d: Missing columns in instruction description.\n", fname, line);
	exit(1);
      }

      flags = 0;
      pid = strtol(id, 0, 16);
      if(!strcmp(cat, "1")) {
	bi = cat1;
	limit = 0x40;
      } else if(!strcmp(cat, "2a")) {
	bi = cat2;
	limit = 0x80;
      } else if(!strcmp(cat, "2b")) {
	bi = cat2;
	limit = 0x80;
	flags = I_POST;
      } else if(!strcmp(cat, "3")) {
	bi = cat3;
	limit = 0x80;
      } else {
	fprintf(stderr, "%s:%d: Unknown category '%s'.\n", fname, line, cat);
	exit(1);
      }

      if(pid<0 || pid >= limit) {
	fprintf(stderr, "%s:%d: Index %s out of range for category %s.\n", fname, line, id, cat);
	exit(1);
      }

      i = bi + pid;
      if(i->name) {
	fprintf(stderr, "%s:%d: Conflict with %s instruction line %d.\n", fname, line, i->name, i->line);
	exit(1);
      }

      if(!strcmp(rep, "y"))
	flags |= I_REP;
      else if(strcmp(rep, "n")) {
	fprintf(stderr, "%s:%d: Unknown repetition mode '%s'.\n", fname, line, rep);
	exit(1);
      }

      i->name = xstrdup(name);
      i->line = line;
      i->cycles = strtol(cyc, 0, 10);
      i->flags = flags;

      if(type[0] == 0)
	i->type = T_STD;
      else if(!strcmp(type, "b"))
	i->type = T_BRANCH;
      else if(!strcmp(type, "cb"))
	i->type = T_CBRANCH;
      else if(!strcmp(type, "i"))
	i->type = T_IDLE;
      else if(!strcmp(type, "f"))
	i->type = T_FLAGS;
      else {
	fprintf(stderr, "%s:%d: Unknown type '%s'.\n", fname, line, type);
	exit(1);
      }
    }
  }
  fclose(f);
}