예제 #1
0
static int
printCharacter(TranslationTableCharacter *thisChar, int mode) {
	TranslationTableRule *thisRule;
	TranslationTableOffset nextRule;
	if (mode == 0) {
		printf("Char: ");
		printf("real=%s, ", print_chars(&thisChar->realchar, 1));
		printf("upper=%s, ", print_chars(&thisChar->uppercase, 1));
		printf("lower=%s, ", print_chars(&thisChar->lowercase, 1));
	} else
		printf("Dots: real=%s, ", _lou_showDots(&thisChar->realchar, 1));
	printf("attr=%s, ", _lou_showAttributes(thisChar->attributes));
	nextRule = thisChar->otherRules;
	while (nextRule) {
		thisRule = (TranslationTableRule *)&table->ruleArea[nextRule];
		if (nextRule == thisChar->definitionRule) printf("definition ");
		printRule(thisRule, mode);
		printf("\n");
		if (mode == 0)
			nextRule = thisRule->charsnext;
		else
			nextRule = thisRule->dotsnext;
	}
	return 1;
}
예제 #2
0
static int
printRule(TranslationTableRule *thisRule, int mode) {
	printf("Rule: ");
	printf("opcode=%s, ", _lou_findOpcodeName(thisRule->opcode));
	if (thisRule->before) printf("before=%x, ", thisRule->before);
	if (thisRule->after) printf("after=%x, ", thisRule->after);
	switch (thisRule->opcode) {
	case CTO_Context:
	case CTO_Correct:
	case CTO_SwapCd:
	case CTO_SwapDd:
	case CTO_Pass2:
	case CTO_Pass3:
	case CTO_Pass4:
		printf("code=%s ",
				print_chars(thisRule->charsdots, thisRule->charslen + thisRule->dotslen));
		break;
	default:
		if (mode == 0) {
			printf("chars=%s, ", print_chars(thisRule->charsdots, thisRule->charslen));
			printf("dots=%s, ", _lou_showDots(&thisRule->charsdots[thisRule->charslen],
										thisRule->dotslen));
		} else {
			printf("dots=%s, ", _lou_showDots(&thisRule->charsdots[thisRule->charslen],
										thisRule->dotslen));
			printf("chars=%s, ", print_chars(thisRule->charsdots, thisRule->charslen));
		}
		break;
	}
	return 1;
}
예제 #3
0
int main(int argc, char *argv[])
{
    char from[MAX_SIZE] = { 'a' };
    char to[MAX_SIZE] = { 'c' };
    int rc = 0;

    debug("Starting");
    // set up the from to have some stuff
    debug("Set up from");
    memset(from, 'x', MAX_SIZE);
    print_chars(from, MAX_SIZE);
    // set it to a failure mode
    debug("Set up to");
    memset(to, 'y', MAX_SIZE);
    print_chars(to, MAX_SIZE);
    check(valid_copy(to, MAX_SIZE, 'y'), "Not initialized correctly");

    // use normal copy to
    rc = normal_copy(from, to, MAX_SIZE);
    check(rc == MAX_SIZE, "Normal copy failed: %d", rc);
    check(valid_copy(to, MAX_SIZE, 'x'), "Normal copy failed");

    // reset
    memset(to, 'y', MAX_SIZE);
    debug("From: ");
    print_chars(from, MAX_SIZE);
    debug("To: ");
    print_chars(to, MAX_SIZE);
    rc = duffs_device(from, to, MAX_SIZE);
    debug("Duffs - From: ");
    print_chars(from, MAX_SIZE);
    debug("Duffs - To: ");
    print_chars(to, MAX_SIZE);

    debug("Duff's value: %d", rc);
    check(rc == MAX_SIZE, "Duff's device failed: %d", rc);
    check(valid_copy(to, MAX_SIZE, 'x'), "Duff's device copy failed");

    // reset
    memset(to, 'y', MAX_SIZE);

    // zed shaw's version
    debug("From: ");
    print_chars(from, MAX_SIZE);
    debug("To: ");
    print_chars(to, MAX_SIZE);
    rc = zeds_device(from, to, MAX_SIZE);
    debug("Zed - From: ");
    print_chars(from, MAX_SIZE);
    debug("Zed - To: ");
    print_chars(to, MAX_SIZE);    debug("Zed's value: %d", rc);
    check(rc == MAX_SIZE, "Zed's device failed: %d", rc);
    check(valid_copy(to, MAX_SIZE, 'x'), "Zed's device failed copy");

    debug("Finishing");
    return 0;
error:
    return 1;
}
예제 #4
0
// Pop the data from the next lower layer
int internet::pop (unsigned char *buf, int len, message *mb)
{
 int i;
 if(popit)
   { 
     unsigned long *beef;
     cout << "This is the internet pop routine" << endl;
     print_chars(prot_name, buf, len);
     if(whichtest>=4)
       {
	 cout<< "If the sentence went through with no errors you passed!!!"<<endl;
	 cin.getline(buf, 900);
 
	 exit(0);
       }
     beef = (unsigned long *)buf;
     if(*beef == 0xefbeadde) {
       cout << "test #" << whichtest << " worked" << endl;
       whichtest++;
     } else {
       printf("expected 0xdeadbeef, got %X\n", *beef);
       exit(0);
     }
     if(whichtest >= 4) { 
       cout << "IT WORKED !!!!!!!!!!!!! You passed off the receive portion of the lab!!" << endl;
       cout<<"GOTO the Server and type in a string to send."<<endl;
     }
     
   }
 else
   {
      
     cout << "This is the internet pop routine" << endl;
     print_chars(prot_name, buf, len);
     if(len != curlen) { // We keep track of what we expect next
       cout << "ERROR!!!!!!!!!! expected packet of length " << curlen << "Got packet of length " << len; 
       exit(0);
       }
     for(i = 0; i < curlen; i++) {
       if((unsigned char)buf[i] != (unsigned char)(i ^ 0xff)) {
	 printf("Error, expected %x at buf[%d] but got %x\n",(i ^ 0xff),i,buf[i]);
	 exit(0);
       }
     }
     curlen+=2;
     if(curlen == MAXLEN) {
      
       cout << "IT WORKED !!!!!!!!!!!!! You passed off the send portion of lab 4!!" << endl;
       cout << "Now type the ENTER key to run the receive tests." << endl;
       cout << "If you havent done so already, you will need to compile your code with" << endl;
       cout << "the new version of internet.cc that you can find on the lab 4 web page. " << endl;
       cout << "It will tell you if you passed off everything. " << endl;
       
     }
   }
 
	return 0;
}
예제 #5
0
int main()
{
  int i;

  printf("x0 = %d\n", x0);
  printf("x1 = '%c'\n", x1);
  printf("x2 = %d\n", x2);
  printf("x3 = %.5f\n", x3);
  printf("x4 = { '%c', '%c', '%c', '%c' }\n",
         x4[0], x4[1], x4[2], x4[3]);
  printf("x5 = { ");
  for (i = 0; i < 10; i++) printf("%d, ", x5[i]);
  printf("}\n");
  printf("x6 = { %d, %d }\n", x6.y, x6.z);
  printf("x7 = { %d, '%c' }\n", x7.y, x7.z);
  printf("x8 = { '%c', %d }\n", x8.y, x8.z);
  printf("x9 = { { ");
  print_chars(x9.y, 9);
  printf("}, %.3f }\n", x9.z);
  printf("x10 = { { '%c', %d }, %.3f }\n",
         x10.u.y, x10.u.z, x10.v);
  printf("x11 = %.10f\n", x11);
  printf("x12 = %.10f\n", x12);
  printf("x13 = { %d, %d }\n", x13[0], x13[1]);
  if (x14 == &x2) printf("x14 ok\n"); else printf("x14 error\n");
  if (x15.y == x4 && x15.z == x5 && x15.u == &x11 && x15.v == &x12)
    printf("x15 ok\n");
  else
    printf("x15 error\n");
  if (x16[0] == (unsigned char *) x4 + 1
      && x16[1] == (unsigned char *) x4 + 2
      && x16[2] == (unsigned char *) x4 + 3)
    printf("x16 ok\n");
  else
    printf("x16 error\n");
  printf("x17[%d] = { ", (int) sizeof(x17));
  print_chars(x17, sizeof(x17));
  printf("}\n");
  printf("x18 = \"%s\"\n", x18);
  printf("x19 = { \"%s\", \"%s\" }\n", x19[0], x19[1]);
  printf("x20 = { ");
  print_chars(x20, sizeof(x20));
  printf("}\n");
  printf("x21 = { ");
  print_chars(x21, sizeof(x21));
  printf("}\n");
  if (x22 == &(x10.u.y))
    printf("x22 ok\n");
  else
    printf("x22 error\n");
  return 0;
}
예제 #6
0
파일: print.hpp 프로젝트: Jenny-fa/lingo
inline void
print(char const* msg, Args const&... args)
{
  Printer p(default_print_stream());
  p.needs_newline = true;
  print_chars(p, format(msg, to_string(args)...));
}
예제 #7
0
static int
show_dotsMap(int startHash) {
	int k;
	CharOrDots *thisDots;
	TranslationTableOffset nextDots;
	printf("Press enter for next or (e)xit, next-(h)ash, then enter\n");
	if (startHash < 0)
		k = 0;
	else
		k = startHash;
	for (; k < HASHNUM; k++)
		if (table->dotsToChar[k]) {
			printf("Hash=%d\n", k);
			nextDots = table->dotsToChar[k];
			while (nextDots) {
				thisDots = (CharOrDots *)&table->ruleArea[nextDots];
				printf("Dots: %s ", _lou_showDots(&thisDots->lookFor, 1));
				printf("char=%s\n", print_chars(&thisDots->found, 1));
				printf("=> ");
				getInput();
				if (*inputBuffer == 'h') break;
				if (*inputBuffer == 'e') return 1;
				nextDots = thisDots->next;
			}
		}
	return 1;
}
예제 #8
0
static int
show_misc(void) {
	printf("Table size: %u\n", table->tableSize);
	printf("Bytes used: %u\n", table->bytesUsed);
	printf("Number of passes: %d\n", table->numPasses);
	printf("'correct' opcodes: %s\n", pickYN(table->corrections));
	printf("'syllable' opcodes: %s\n", pickYN(table->syllables));
	printf("'capsnocont' opcode: %s\n", pickYN(table->capsNoCont));
	printf("Hyphenation table: %s\n", pickYN(table->hyphenStatesArray));
	printf("noletsignbefore %s\n",
			print_chars(&table->noLetsignBefore[0], table->noLetsignBeforeCount));
	printf("noletsign %s\n", print_chars(&table->noLetsign[0], table->noLetsignCount));
	printf("noletsignafter %s\n",
			print_chars(&table->noLetsignAfter[0], table->noLetsignAfterCount));
	return 1;
}
static PyObject *py_print_chars(PyObject *self, PyObject *args) {
    char *s;
    if (!PyArg_ParseTuple(args, "s", &s)) {
        return NULL;
    }
    print_chars(s);
    Py_RETURN_NONE;
}
예제 #10
0
파일: race1.c 프로젝트: kavinsivak/sandbox
int main (void)
{
    switch (fork ()) {
    case -1:
        err_msg ("Can't fork");
        break;

    case 0:
        print_chars ("Hello from child\n");
        _exit (0);

    default:
        print_chars ("Hello from parent\n");
        break;
    }

    return (0);
}
예제 #11
0
파일: tcp.cpp 프로젝트: HintonBR/scratch
// Push the data to the next lower layer
int tcp::push (unsigned char *buf, int len, char *addr, message *mb)
{
  cout << "This is the tcp push routine" << endl;
  print_chars(prot_name, buf, len);


  if(prot_lower)
    prot_lower->push (buf, len, addr, mb);
}
예제 #12
0
int main()
{
  /* Initialization of arrays */
  const int x5[10] = { 1, 2, 3 };
  char x17[] = "Hello!";
  char * x18 = "Hello!";
  char * x19[2] = { "Hello", "world!" };
  char x20[3] = "Hello!";
  char x21[10] = "Hello!";
  printf("x5 = { ");
  for (int i = 0; i < 10; i++) printf("%d, ", x5[i]);
  printf("}\n");
  printf("x17[%d] = { ", (int) sizeof(x17));
  print_chars(x17, sizeof(x17));
  printf("}\n");
  printf("x18 = \"%s\"\n", x18);
  printf("x19 = { \"%s\", \"%s\" }\n", x19[0], x19[1]);
  printf("x20 = { ");
  print_chars(x20, sizeof(x20));
  printf("}\n");
  printf("x21 = { ");
  print_chars(x21, sizeof(x21));
  printf("}\n");
  /* Local const arrays */
  printf("f(0,42) = %d, f(1,42) = %d, f(2,42) = %d, f(3,42) = %d, f(4,42) = %d\n",
         f(0,42), f(1, 42), f(2, 42), f(3, 42), f(4, 42));
  /* Structs/unions */
  struct P p1 = { 66, 77 };
  struct S s1 = { 0, p1 };
  print_S("s1", &s1);
  struct S s2 = { .a.y = 1, .u.c[4] = 'x', .u.b = p1 };
  print_S("s2", &s2);
  /* ISO C99 and recent Clang say s3.a.y = 77
     GCC and earlier CompCert versions say s3.a.y = 0
     Now CompCert fails on an error "unsupported reinitialization". */
#if 0
  struct S s3 = { .tag = 1, .a = p1, .a.x = 1, .u.c = "Hello!", .u.c[7] = 'X' };
  print_S("s3", &s3);
#endif
  /* This other reinitialization is correctly supported, though. */
  struct S s4 = { .tag = 0, .a.x = 1, .a = p1, .u.b = 88, 99 };
  print_S("s4", &s4);
  return 0;
}
static PyObject *py_print_chars(PyObject *self, PyObject *args) {
    char *s;
    Py_ssize_t len;
    /* accepts bytes, bytearray, or other byte-like object */
    if (!PyArg_ParseTuple(args, "y#", &s, &len)) {
        return NULL;
    }
    print_chars(s, len);
    Py_RETURN_NONE;
}
예제 #14
0
파일: char-arg.c 프로젝트: kw-udon/ucc
int main()
{
  int i;
  char c[4][2] = { "ab", "cd", "ef", "gh"};

  for (i = 0; i < 4; ++i) {
    print_chars(c[i][0], c[i][1]);
  }

}
static PyObject *py_print_chars(PyObject *self, PyObject *args) {
    PyObject *o, *bytes;
    char *s;
    if (!PyArg_ParseTuple(args, "U", &o)) {
        return NULL;
    }
    bytes = PyUnicode_AsUTF8String(o);
    s = PyBytes_AsString(bytes);
    print_chars(s);
    Py_DECREF(bytes);
    Py_RETURN_NONE;
}
예제 #16
0
파일: regexp.c 프로젝트: bkearney/augeas
void print_regexp(FILE *out, struct regexp *r) {
    if (r == NULL) {
        fprintf(out, "<NULL>");
        return;
    }

    fputc('/', out);
    if (r->pattern == NULL)
        fprintf(out, "%p", r);
    else
        print_chars(out, r->pattern->str, -1);
    fputc('/', out);
}
static PyObject *py_print_chars(PyObject *self, PyObject *args) {
    PyObject *obj, *bytes;
    char *s;
    Py_ssize_t len;
    
    if (!PyArg_ParseTuple(args, "U", &obj)) {
        return NULL;
    }
    bytes = PyUnicode_AsUTF8String(obj);
    PyBytes_AsStringAndSize(bytes, &s, &len);
    print_chars(s, len);
    Py_DECREF(bytes);
    Py_RETURN_NONE;
}
예제 #18
0
static void print_S(char * name, struct S * s)
{
  printf("%s = { tag = %d, a = {%d,%d}, u = ", name, s->tag, s->a.x, s->a.y);
  switch(s->tag) {
  case 0:
    printf("{%d,%d} }\n", s->u.b.x, s->u.b.y);
    break;
  case 1:
    printf("{"); print_chars(s->u.c, 8); printf("} }\n");
    break;
  default:
    printf("BAD }\n");
    break;
  }
}
예제 #19
0
// Push the data to the next lower layer
int internet::push (unsigned char *buf, int len, char *addr, message *mb)
{
  cout << "This is the internet push routine" << endl;
  print_chars(prot_name, buf, len);

  // The default behavior will be to echo the same data back through 
  // pop routine if there is no lower layer protocol

  // You should put code to send the data over the network here

  if(prot_lower)
    prot_lower->push (buf, len, addr, mb);

  return 0;
}
예제 #20
0
파일: print.hpp 프로젝트: Jenny-fa/lingo
inline void
print_list(Printer& p, T const& range)
{
  auto first = range.begin();
  auto last = range.end();

  // Don't print anything for empty ranges.
  if (first == last)
    return;

  while (first != last) {
    print(p, *first);
    if (std::next(first) != last)
      print_chars(p, ", ");
    ++first;
  }
}
예제 #21
0
int
main (void){
    srand ( time(NULL) );
    int i;

    /* Tree constructor */
    Tree * t = Tree_init(9);

    /* Creates a random topology for the tree */ 
    rnd_tree(t);

    /* Randomly associates integer indexes to the leaves */
    name_leaves(t);

    /* Reorder the tree */
    reorder_tree(t->root);

    /* Print the tree in Newick format */
    print_newick(t->root);
    
    /* Create species with random characteristics */
    rnd_characteristics(t,3,5);
    printf("-----\n");

    /* Print the characteristics of every leaf */
    print_chars(t);
    printf("-----\n");

   /* Calculate Fitch cost */
   int cost;
   get_Fitch_cost(t,&cost);

   printf("COST: %d\n",cost);
    
   // for(i = 0; i<=LEAVES; i ++){
   //     t[i].key = &list[i];
   //     printf("%d \n",t->key[i]);
   // }
    
    
    return EXIT_SUCCESS;
}
예제 #22
0
static void main_loop(char *table) {
  widechar inbuf[BUFSIZE];
  widechar outbuf[BUFSIZE];
  int inlen;
  int outlen;
  TranslationTableRule **rules = malloc(512 * sizeof(TranslationTableRule));
  int ruleslen;
  int i;
  while (1) {
    inlen = get_wide_input(inbuf);
    outlen = BUFSIZE;
    ruleslen = RULESSIZE;
    if (!trace_translate(table, inbuf, &inlen, outbuf, &outlen,
                         NULL, NULL, NULL, NULL, NULL, rules, &ruleslen, 0))
      break;
    printf("%s\n", print_chars(outbuf, outlen));
    for (i=0; i<ruleslen; i++) {
      printf("%d.\t", i+1);
      print_rule(rules[i]); }}
}
예제 #23
0
static int
show_compDots(int startChar) {
	widechar k;
	printf("Press enter for next or (e)xit, next-(h)ash, then enter\n");
	if (startChar < 0)
		k = 0;
	else
		k = startChar;
	for (; k < 256; k++)
		if (table->compdotsPattern[k]) {
			TranslationTableRule *thisRule =
					(TranslationTableRule *)&table->ruleArea[table->compdotsPattern[k]];
			printf("Char: %s ", print_chars(&k, 1));
			printf("dots=%s\n",
					_lou_showDots(&thisRule->charsdots[1], thisRule->dotslen));
			printf("=> ");
			getInput();
			if (*inputBuffer == 'e') return 1;
		}
	return 1;
}
예제 #24
0
파일: regexp.c 프로젝트: mchf/augeas
void print_regexp(FILE *out, struct regexp *r) {
    if (r == NULL) {
        fprintf(out, "<NULL>");
        return;
    }

    fputc('/', out);
    if (r->pattern == NULL)
        fprintf(out, "%p", r);
    else {
        char *rx;
        size_t rx_len;
        fa_restrict_alphabet(r->pattern->str, strlen(r->pattern->str),
                             &rx, &rx_len, 2, 1);
        print_chars(out, rx, rx_len);
        FREE(rx);
    }
    fputc('/', out);
    if (r->nocase)
        fputc('i', out);
}
예제 #25
0
void encode() {
  char buffer[32];
  size_t count;
  mpz_t bignum;
  mpz_init(bignum);
  bool first = true;
  while (true) {
    count = fread(buffer, 1, 32, stdin);
    if (count == 0) {
      break;
    }
    // print the separating space
    if (!first) {
      putchar(' ');
    }
    first = false;
    // print the bignum in base 62
    print_chars(&bignum, buffer, count);
  }
  putchar('\n');
  mpz_clear(bignum);
}
예제 #26
0
static void print_rule(TranslationTableRule *rule) {
  char *opcode = findOpcodeName(rule->opcode);
  char *chars;
  char *dots;
  char *script;
  switch (rule->opcode) {
    case CTO_Context:
    case CTO_Correct:
    case CTO_SwapCd:
    case CTO_SwapDd:
    case CTO_Pass2:
    case CTO_Pass3:
    case CTO_Pass4:
      script = print_script(&rule->charsdots[rule->charslen], rule->dotslen);
      printf("%s\t%s\n", opcode, script);
      break;
    default:
      chars = print_chars(rule->charsdots, rule->charslen);
      dots = print_dots(&rule->charsdots[rule->charslen], rule->dotslen);
      printf("%s\t%s\t%s\n", opcode, chars, dots);
      break; }
}
예제 #27
0
파일: print.hpp 프로젝트: Jenny-fa/lingo
inline void
print(Printer& p, char const* msg, Args const&... args)
{
  print_chars(p, format(msg, to_string(args)...));
}
예제 #28
0
파일: errors.c 프로젝트: dbousque/pr
void	malloc_error(void)
{
	print_chars("Could not allocate memory.\n");
	exit(1);
}
예제 #29
0
파일: print.hpp 프로젝트: Jenny-fa/lingo
// Print the string pointed to by `s`.
inline void
print(Printer& p, String const* s)
{
  print_chars(p, *s);
}
예제 #30
0
파일: print.hpp 프로젝트: Jenny-fa/lingo
// Print the string view `s`.
inline void
print(Printer& p, String_view s)
{
  print_chars(p, s.begin(), s.end());
}