Beispiel #1
0
char *genRawFieldChecker(char *src, const rawAST_coding_taglist *taglist,
  boolean is_equal)
{
  int i;
  for (i = 0; i < taglist->nElements; i++) {
    rawAST_coding_field_list *fields = taglist->fields + i;
    char *field_name = NULL;
    boolean first_expr = TRUE;
    int j;
    if (i > 0) src = mputstr(src, is_equal ? " || " : " && ");
    for (j = 0; j < fields->nElements; j++) {
      rawAST_coding_fields *field = fields->fields + j;
      if (j == 0) {
        /* this is the first field reference */
        if (field->fieldtype == UNION_FIELD)
          field_name = mputprintf(field_name,"(*field_%s)",field->nthfieldname);
        else
          field_name = mputprintf(field_name,"field_%s", field->nthfieldname);
      }
      else {
        /* this is not the first field reference */
        if (field->fieldtype == UNION_FIELD) {
          /* checking for the right selection within the union */
          if (first_expr) {
            if (taglist->nElements > 1) src = mputc(src, '(');
            first_expr = FALSE;
          }
          else src = mputstr(src, is_equal ? " && " : " || ");
          src = mputprintf(src, "%s.get_selection() %s %s%s%s", field_name,
            is_equal ? "==" : "!=", fields->fields[j - 1].type,
            "::ALT_", field->nthfieldname);
        }
        /* appending the current field name to the field reference */
        field_name = mputprintf(field_name, ".%s()", field->nthfieldname);
      }
      if (j < fields->nElements - 1 && field->fieldtype == OPTIONAL_FIELD) {
        /* this is not the last field in the chain and it is optional */
        if (first_expr) {
          if (taglist->nElements > 1) src = mputc(src, '(');
          first_expr = FALSE;
        }
        else src = mputstr(src, is_equal ? " && " : " || ");
        /* check for the presence */
        if (!is_equal) src = mputc(src, '!');
        src = mputprintf(src, "%s.ispresent()", field_name);
        /* add an extra () to the field reference */
        field_name = mputstr(field_name, "()");
      }
    }
    if (!first_expr) src = mputstr(src, is_equal ? " && " : " || ");
    /* compare the referred field with the given value */
    src = mputprintf(src, "%s %s %s", field_name, is_equal ? "==" : "!=",
      fields->value);
    if (!first_expr && taglist->nElements > 1) src = mputc(src, ')');
    Free(field_name);
  }
  return src;
}
Beispiel #2
0
void bcd(int n)
{
	int mm;
	int num=0;
	int array[100];
	while(n>0)
	{
		array[num]=mod_u10(n);
		n=div_u10(n);
		num++;
	}
	while(num>0)
	{
		switch(array[num-1])
		{
			case 0: mputs("0000"); break;
			case 1: mputs("0001"); break;
			case 2: mputs("0010"); break;
			case 3: mputs("0011"); break;
			case 4: mputs("0100"); break;
			case 5: mputs("0101"); break;
			case 6: mputs("0110"); break;
			case 7: mputs("0111"); break;
			case 8: mputs("1000"); break;
			case 9: mputs("1001"); break;
		}
		mputc(' ');
		num--;
	}
}
Beispiel #3
0
void parse_printf(const char *fmt, va_list args) {
  /* Character to be printed */
  unsigned char prntch;
  /* String to be printed */
  char *prntstr;
  /* Number to be printed */
  long number;

  while(*fmt != '\0') {
    switch(*fmt) {
      case '%':
        if(*(fmt+1) == 'c') {
          prntch = (unsigned char) va_arg(args,unsigned char);
          mputc(prntch);
          ++fmt;
          break;
        }
        if(*(fmt+1) == 'd') {
          number = (long) va_arg(args,int);
          mputnum(number,10);
          ++fmt;
          break;
        }
        if(*(fmt+1) == 'u') {
          number = (long) va_arg(args,unsigned);
          mputnum(number,10);
          ++fmt;
          break;
        }
Beispiel #4
0
int print(int n){
	char* p;

	p = i2str(n);
	while(*p)
		mputc(*p++);
	return 0;
}
Beispiel #5
0
void mputc_at(short n, short row, short col, char c)
{
	if (!WinMonoInitialized) return;
	
	msetcursor(row,col);

	mputc(n, c);
}
Beispiel #6
0
char *msdone(struct mstring *s) {
    char *r = 0;
    if (s) {
        mputc(s, 0);
        r = s->base;
        free(s);
    }
    return r;
}
Beispiel #7
0
void mputc_at( short n, short row, short col, char c )
{
	CROW = row;
	CCOL = col;

	if (!OPEN) return;

	mputc( n, c );

}
Beispiel #8
0
int main(){
	int fahr, celsius;
	int lower, upper, step;

	lower = 0;
	upper = 300;
	step = 20;

	fahr = lower;
	while(fahr <= upper) {
		celsius = 5 * (fahr - 32) / 9;
		print(fahr);
		mputc('\t');
		print(celsius);
		mputc(13);
		mputc('\n');
		fahr += step;
	}
	return 0;
}
Beispiel #9
0
void mprintf( short n, char * format, ... )
{
	char *ptr=temp_m_buffer;
	va_list args;

	if (!OPEN) return;

	va_start(args, format );
	vsprintf(temp_m_buffer,format,args);
	while( *ptr )
		mputc( n, *ptr++ );

}
Beispiel #10
0
static void mputnum(long number,int base) {
  unsigned char numbuf[15];
  int numlen = 0;
  int index = 0;
  int remainder = 0;
  numlen = 0;
  do {
    remainder = (number % base);
    if(remainder > 9 && base == 16) {
      remainder = 'A' + (remainder-10);
    } else {
      remainder = remainder + '0';
    }
    numbuf[numlen++] = remainder;
    number = number / base;
  } while(number != 0);
  for(index = numlen-1; index >= 0; --index)
    mputc(numbuf[index]);
}
Beispiel #11
0
static int GetEvent(FILE *fp, LogEvent *event)
{
    time_t prev_sec;
    unsigned long prev_usec;
    for ( ; ; ) {
	/* find and read timestamp */
	if (fgets(event->timestamp, TimeStampLength + 1, fp) == NULL) {
	    event->ignore = True;
	    return False;
	}
	event->start_line=event->line_ctr;
	if (FormatMatch(event->timestamp, TimeStampUsed)) break;
    }
    prev_sec = event->sec;
    prev_usec = event->usec;
    TS2long(&event->sec, &event->usec, event->timestamp);
    if (event->sec < prev_sec ||
	(event->sec == prev_sec && event->usec < prev_usec)) {
	event->wrap = 1;
    }
    event->ignore = False;
    for ( ; ; ) {
	size_t a;
	char buf[BUFFERSIZE];
	/* read the log-event */
	if (fgets(buf, sizeof(buf), fp) == NULL) {
	    /* EOF was detected */
	    if (event->data == NULL) event->data = mcopystr("\n");
	    else if (event->data[mstrlen(event->data) - 1] != '\n')
		event->data = mputc(event->data, '\n');
	    return False;
	}
	a = strlen(buf);
	if(FormatMatch(buf,TimeStampUsed)) {/*Did we read the next event's timestamp?*/
	    fseek(fp, -1L * a, SEEK_CUR);/*"unread" next event*/
	    break;
	} else if (buf[a - 1] == '\n') event->line_ctr++;
	event->data=mputstr(event->data, buf);/*append buffer to event-data*/
    }
    return True;
}
Beispiel #12
0
void mprintf_at( short n, short row, short col, char * format, ... )
{
	int r,c;
	char buffer[1000], *ptr=buffer;
	va_list args;

	if (!OPEN) return;

	r = CROW; c = CCOL;

	CROW = row;
	CCOL = col;

	va_start(args, format );
	vsprintf(buffer,format,args);
	while( *ptr )
		mputc( n, *ptr++ );


	CROW = r; CCOL = c;

	msetcursor( ROW+CROW, COL+CCOL );

}
Beispiel #13
0
/**********************************************************************
 *  Function  suf_tree_menu()
 *                                                                    
 *  Parameter:                                                       
 *   
 *                                                              
 *  This function prompts user to choose an algorithm to create 
 *  a suffix tree and use it.  
 *  The utilities menu is also available from this menu.
 *                                                                   
 **********************************************************************/
void suf_tree_menu()
{
  int i, status, num_lines, num_strings;
  char ch;
  STRING *pattern, **strings, *text;

  while (1) {
    num_lines = 18;

    printf("\n**   Suffix Tree Menu    **\n\n");
    printf("1)  Build a suffix tree using Ukkonen's algorithm\n");
    printf("2)  Build a suffix tree using Weiner's algorithm\n");
    printf("3)  Exact matching using a suffix tree for the text\n");
    printf("4)  Walk around a suffix tree\n");
    printf("5)  Compute the LCA values for a suffix tree\n");
    printf("     a) using the naive LCA algorithm\n");
    printf("     b) using the constant time LCA algorithm\n");
    printf("6)  Compute Lempel-Ziv decomposition\n");
    printf("     a) original version (f-factorization)\n");
    printf("     b) nonoverlapping blocks (as in the book)\n");
    printf("8)  Set suffix tree build policy (current: ");
    switch(stree_build_policy)  {
    case LINKED_LIST:      printf("linked list)\n");  break;
    case SORTED_LIST:      printf("sorted list)\n");  break;
    case LIST_THEN_ARRAY:  printf("list then array, threshold %d)\n",
                                  stree_build_threshold);  break;
    case COMPLETE_ARRAY:   printf("complete array)\n");  break;
    }
    printf("9)  Suffix tree print toggle (current: %s)\n",
           (stree_print_flag == ON ? "on" : "off"));
    printf("*)  String Utilites\n");
    printf("0)  Exit\n");
    printf("\nEnter Selection: ");
 
    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;

    switch (choice[0]) {
    case '0':
      return;

    case '1':
      strings = get_string_ary("list of sequences", &num_strings);
      if (strings == NULL)
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe sequences:\n");
      for (i=0; i < num_strings; i++) {
        mprintf("%2d)", i + 1);
        terse_print_string(strings[i]);
      }
      mputc('\n');

      status = map_sequences(NULL, NULL, strings, num_strings);
      if (status != -1) {
        mprintf("Executing Ukkonen's Algorithm...\n\n");
        strmat_ukkonen_build(strings, num_strings, stree_build_policy,
                             stree_build_threshold, stats_flag,
                             stree_print_flag);
        unmap_sequences(NULL, NULL, strings, num_strings);
      }
      mend(num_lines);
      putchar('\n');

      free(strings);
      break;

    case '2':
      strings = get_string_ary("list of sequences", &num_strings);
      if (strings == NULL)
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe sequences:\n");
      for (i=0; i < num_strings; i++) {
        mprintf("%2d)", i + 1);
        terse_print_string(strings[i]);
      }
      mputc('\n');

      status = map_sequences(NULL, NULL, strings, num_strings);
      if (status != -1) {
        mprintf("Executing Weiner's Algorithm...\n\n");
        strmat_weiner_build(strings, num_strings, stree_build_policy,
                            stree_build_threshold, stats_flag,
                            stree_print_flag);
        unmap_sequences(NULL, NULL, strings, num_strings);
      }
      mend(num_lines);
      putchar('\n');

      free(strings);
      break;

    case '3':
      if (!(pattern = get_string("pattern")) ||
          !(strings = get_string_ary("list of sequences", &num_strings)))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe texts:\n");
      for (i=0; i < num_strings; i++) {
        mprintf("%2d)", i + 1);
        terse_print_string(strings[i]);
      }
      mputc('\n');

      status = map_sequences(NULL, pattern, strings, num_strings);
      if (status != -1) {
        mprintf("Executing exact matching with a suffix tree...\n\n");
        strmat_stree_match(pattern, strings, num_strings, stree_build_policy,
                           stree_build_threshold, stats_flag);
        unmap_sequences(NULL, pattern, strings, num_strings);
      }
      mend(num_lines);
      putchar('\n');

      free(strings);
      break;
        
    case '4':
      strings = get_string_ary("list of sequences", &num_strings);
      if (strings == NULL)
        continue;

      status = map_sequences(NULL, NULL, strings, num_strings);
      if (status != -1) {
        strmat_stree_walkaround(strings, num_strings, stree_build_policy,
                                stree_build_threshold);
        unmap_sequences(NULL, NULL, strings, num_strings);
      }
      putchar('\n');

      free(strings);
      break;

    case '5':
      ch = toupper(choice[1]);
      if (ch != 'A' && ch != 'B') {
        printf("\nYou must specify which type of LCA algorithm to use "
               "(as in '3a' or '3b').\n");
        continue;
      }

      strings = get_string_ary("list of sequences", &num_strings);
      if (strings == NULL)
        continue;

      status = map_sequences(NULL, NULL, strings, num_strings);
      if (status != -1) {
        if (ch == 'A')
          strmat_stree_naive_lca(strings, num_strings, stree_build_policy,
                                 stree_build_threshold, stats_flag);
        else
          strmat_stree_lca(strings, num_strings, stree_build_policy,
                           stree_build_threshold, stats_flag);
        unmap_sequences(NULL, NULL, strings, num_strings);
      }
      putchar('\n');

      free(strings);
      break;

    case '6':
      ch = toupper(choice[1]);
      if (ch!='A' && ch!='B') {
        printf("\nYou must specify which type of decomposition to compute "
               "(as in '6a' or '6b').\n");
        continue;
      }

      if (!(text = get_string("string")))
        continue;

      mstart(stdin, fpout, OK, OK, 0, NULL);
      mprintf("\nThe string:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if(status != -1) {
        strmat_stree_lempel_ziv(text, stree_build_policy,
                                stree_build_threshold, stats_flag,ch);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '8':
      choice = "0";
      while (choice[0] != '1' && choice[0] != '2' &&
             choice[0] != '3' && choice[0] != '4') {
        printf("\n**  Suffix Tree Build Policies **\n");
        printf("\n(1 - linked list, 2 - sorted list, 3 - linked list/array,"
               " 4 - complete array)\n");
        printf("Enter Build Policy [%d]: ",
               (stree_build_policy == LINKED_LIST ? 1
                  : (stree_build_policy == SORTED_LIST ? 2
                       : (stree_build_policy == LIST_THEN_ARRAY ? 3 : 4))));

        if ((choice = my_getline(stdin, &ch_len)) == NULL || choice[0] == '\0')
          break;
      
        switch (choice[0]) {
        case '1':
          stree_build_policy = LINKED_LIST;
          break;

        case '2':
          stree_build_policy = SORTED_LIST;
          break;
        case '3':
          stree_build_policy = LIST_THEN_ARRAY;
          break;

        case '4':
          stree_build_policy = COMPLETE_ARRAY;
          break;

        default:
          printf("\nThat is not a choice.\n");
        }
      }
      if (stree_build_policy == LIST_THEN_ARRAY) {
        printf("\nEnter Build Threshold [%d]: ", stree_build_threshold);
        if ((choice = my_getline(stdin, &ch_len)) != NULL)
          sscanf(choice, "%d", &stree_build_threshold);
      }
      putchar('\n');
      break;

    case '9':
      if (stree_print_flag == ON)
        stree_print_flag = OFF;
      else
        stree_print_flag = ON;
      break;

    case '*':
      util_menu();
      break;
   
    default:
      printf("\nThat is not a choice.\n");
    }
  }
}
Beispiel #14
0
void fill(int no, char c) {
    for (int i = 0; i < no; i++)
        mputc(c);
}
Beispiel #15
0
void defSignatureClasses(const signature_def *sdef, output_struct *output)
{
  char *decl = NULL, *def = NULL, *src = NULL;
  const char *name = sdef->name, *dispname = sdef->dispname;
  size_t i, num_in = 0, num_out = 0;

  for (i = 0; i < sdef->parameters.nElements; i++) {
    if (sdef->parameters.elements[i].direction != PAR_OUT) num_in++;
    if (sdef->parameters.elements[i].direction != PAR_IN) num_out++;
  }

  /*
   *
   * xxx_call class
   *
   */

  decl = mputprintf(decl, "class %s_call;\n", name);

  /* class definition */
  def = mputprintf(def, "class %s_call {\n", name);

  /* signature's in and inout parameters */
  for (i = 0; i < sdef->parameters.nElements; i++) {
    if (sdef->parameters.elements[i].direction != PAR_OUT)
      def = mputprintf(def, "%s param_%s;\n",
        sdef->parameters.elements[i].type,
        sdef->parameters.elements[i].name);
  }

  def = mputstr(def, "public:\n");

  /* parameters' access functions */
  for (i = 0; i < sdef->parameters.nElements; i++) {
    if (sdef->parameters.elements[i].direction != PAR_OUT) {
      def = mputprintf(def, "inline %s& %s() { return param_%s; }\n"
        "inline const %s& %s() const { return param_%s; }\n",
        sdef->parameters.elements[i].type,
        sdef->parameters.elements[i].name,
        sdef->parameters.elements[i].name,
        sdef->parameters.elements[i].type,
        sdef->parameters.elements[i].name,
        sdef->parameters.elements[i].name);
    }
  }

  if (num_in > 0) {
    /* encode_text function */
    def = mputstr(def, "void encode_text(Text_Buf& text_buf) const;\n");
    src = mputprintf(src, "void %s_call::encode_text(Text_Buf& text_buf) "
      "const\n"
      "{\n", name);
    for(i = 0; i < sdef->parameters.nElements; i++) {
      if(sdef->parameters.elements[i].direction != PAR_OUT)
        src = mputprintf(src, "param_%s.encode_text(text_buf);\n",
          sdef->parameters.elements[i].name);
    }
    src = mputstr(src, "}\n\n");
    /* decode_text function */
    def = mputstr(def, "void decode_text(Text_Buf& text_buf);\n");
    src = mputprintf(src, "void %s_call::decode_text(Text_Buf& text_buf)\n"
      "{\n", name);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction!= PAR_OUT)
        src = mputprintf(src, "param_%s.decode_text(text_buf);\n",
          sdef->parameters.elements[i].name);
    }
    src = mputstr(src, "}\n\n");
  } else {
    def = mputstr(def, "inline void encode_text(Text_Buf&) const "
      "{ }\n"
      "inline void decode_text(Text_Buf&) { }\n");
  }

  /* log function */
  def = mputstr(def, "void log() const;\n");
  src = mputprintf(src, "void %s_call::log() const\n"
    "{\n", name);
  if (num_in > 0) {
    boolean first_param = TRUE;
    src = mputprintf(src, "TTCN_Logger::log_event_str(\"%s : { \");\n",
      dispname);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_OUT) {
        src = mputstr(src, "TTCN_Logger::log_event_str(\"");
        if (first_param) first_param = FALSE;
        else src = mputstr(src, ", ");
        src = mputprintf(src, "%s := \");\n"
          "param_%s.log();\n",
          sdef->parameters.elements[i].dispname,
          sdef->parameters.elements[i].name);
      }
    }
    src = mputstr(src, "TTCN_Logger::log_event_str(\" }\");\n");
  } else {
    src = mputprintf(src, "TTCN_Logger::log_event_str(\"%s : { }\");\n",
      dispname);
  }
  src = mputstr(src, "}\n\n");

  def = mputstr(def, "};\n\n");
  /* end of xxx_call class*/

  /*
   *
   * xxx_call_redirect class (for getcall port-operation)
   *
   */
  decl = mputprintf(decl, "class %s_call_redirect;\n", name);

  /* class definition */
  def = mputprintf(def, "class %s_call_redirect {\n", name);

  /* parameter pointers */
  for (i = 0; i < sdef->parameters.nElements; i++) {
    if (sdef->parameters.elements[i].direction != PAR_OUT) {
      def = mputprintf(def, "%s *ptr_%s;\n",
        sdef->parameters.elements[i].type,
        sdef->parameters.elements[i].name);
    }
  }

  def = mputstr(def, "public:\n");

  if (num_in > 0) {
    /* constructor */
    boolean first_param = TRUE;
    def = mputprintf(def, "%s_call_redirect(", name);
    for (i = 0;i<sdef->parameters.nElements;i++) {
      if (sdef->parameters.elements[i].direction != PAR_OUT) {
        if (first_param) first_param = FALSE;
        else def = mputstr(def, ", ");
        def = mputprintf(def, "%s *par_%s = NULL",
          sdef->parameters.elements[i].type,
          sdef->parameters.elements[i].name);
      }
    }
    def = mputstr(def, ")\n"
      " : ");
    first_param = TRUE;
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_OUT) {
        if (first_param) first_param = FALSE;
        else def = mputstr(def, ", ");
        def = mputprintf(def, "ptr_%s(par_%s)",
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name);
      }
    }
    def = mputstr(def, " { }\n");
  }
  /* otherwise constructor is not needed */

  /* set_parameters function (used for param redirect in getcall) */
  if (num_in > 0) {
    def = mputprintf(def, "void set_parameters(const %s_call& call_par) "
      "const;\n", name);
    src = mputprintf(src, "void %s_call_redirect::set_parameters(const "
      "%s_call& call_par) const\n"
      "{\n", name, name);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_OUT) {
        src = mputprintf(src, "if (ptr_%s != NULL) "
          "*ptr_%s = call_par.%s();\n",
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name);
      }
    }
    src = mputstr(src, "}\n\n");
  } else {
    def = mputprintf(def, "inline void set_parameters(const %s_call&"
      ") const { }\n", name);
  }

  def = mputstr(def, "};\n\n");
  /* end of class xxx_call_redirect */


  if (!sdef->is_noblock) {
    /*
     *
     * xxx_reply class
     *
     */
    decl = mputprintf(decl, "class %s_reply;\n", name);

    /* class definition */
    def = mputprintf(def, "class %s_reply {\n", name);

    /* signature's out and inout parameters */
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_IN) {
        def = mputprintf(def, "%s param_%s;\n",
          sdef->parameters.elements[i].type,
          sdef->parameters.elements[i].name);
      }
    }
    if (sdef->return_type != NULL) {
      def = mputprintf(def, "%s reply_value;\n", sdef->return_type);
    }

    def = mputstr(def, "public:\n");

    /* parameters' access functions */
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_IN) {
        def = mputprintf(def, "inline %s& %s() { return param_%s; }\n"
          "inline const %s& %s() const { return param_%s; }\n",
          sdef->parameters.elements[i].type,
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].type,
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name);
      }
    }
    if (sdef->return_type != NULL) {
      def = mputprintf(def, "inline %s& return_value() "
        "{ return reply_value; }\n"
        "inline const %s& return_value() const "
        "{ return reply_value; }\n",
        sdef->return_type, sdef->return_type);
    }

    if (num_out > 0 || sdef->return_type != NULL) {
      /* encode_text function */
      def = mputstr(def, "void encode_text(Text_Buf& text_buf) const;\n");
      src = mputprintf(src, "void %s_reply::encode_text(Text_Buf& "
        "text_buf) const\n"
        "{\n", name);
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if (sdef->parameters.elements[i].direction != PAR_IN)
          src = mputprintf(src, "param_%s.encode_text(text_buf);\n",
            sdef->parameters.elements[i].name);
      }
      if (sdef->return_type != NULL)
        src = mputstr(src, "reply_value.encode_text(text_buf);\n");
      src = mputstr(src, "}\n\n");
      /* decode_text function */
      def = mputstr(def, "void decode_text(Text_Buf& text_buf);\n");
      src = mputprintf(src, "void %s_reply::decode_text(Text_Buf& "
        "text_buf)\n"
        "{\n", name);
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if (sdef->parameters.elements[i].direction != PAR_IN)
          src = mputprintf(src, "param_%s.decode_text(text_buf);\n",
            sdef->parameters.elements[i].name);
      }
      if (sdef->return_type != NULL)
        src = mputstr(src, "reply_value.decode_text(text_buf);\n");
      src = mputstr(src, "}\n\n");
    } else {
      def = mputstr(def, "inline void encode_text(Text_Buf&) "
        "const { }\n"
        "inline void decode_text(Text_Buf&) { }\n");
    }

    /* log function */
    def = mputstr(def, "void log() const;\n");
    src = mputprintf(src, "void %s_reply::log() const\n"
      "{\n", name);
    if (num_out > 0) {
      boolean first_param = TRUE;
      src = mputprintf(src, "TTCN_Logger::log_event_str(\"%s : { \");\n",
        dispname);
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if (sdef->parameters.elements[i].direction != PAR_IN) {
          src = mputstr(src, "TTCN_Logger::log_event_str(\"");
          if (first_param) first_param = FALSE;
          else src = mputstr(src, ", ");
          src = mputprintf(src, "%s := \");\n"
            "param_%s.log();\n",
            sdef->parameters.elements[i].dispname,
            sdef->parameters.elements[i].name);
        }
      }
      if (sdef->return_type != NULL) {
        src = mputstr(src, "TTCN_Logger::log_event_str(\" } "
          "value \");\n"
          "reply_value.log();\n");
      } else {
        src = mputstr(src, "TTCN_Logger::log_event_str(\" }\");\n");
      }
    } else if (sdef->return_type != NULL) {
      src = mputprintf(src, "TTCN_Logger::log_event_str(\"%s : { } "
        "value \");\n"
        "reply_value.log();\n", dispname);
    } else {
      src = mputprintf(src, "TTCN_Logger::log_event_str(\"%s : "
        "{ }\");\n", dispname);
    }
    src = mputstr(src, "}\n\n");

    def = mputstr(def, "};\n\n");
    /* end of xxx_reply class*/

    /*
     *
     * xxx_reply_redirect class (for getreply port-operation)
     *
     */
    decl = mputprintf(decl, "class %s_reply_redirect;\n", name);

    /* class definition */
    def = mputprintf(def, "class %s_reply_redirect {\n", name);

    /* parameter pointers */
    if (sdef->return_type != NULL) {
      def = mputprintf(def, "%s *ret_val_ptr;\n", sdef->return_type);
    }
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_IN) {
        def = mputprintf(def, "%s *ptr_%s;\n",
          sdef->parameters.elements[i].type,
          sdef->parameters.elements[i].name);
      }
    }

    def = mputstr(def, "public:\n");

    if (num_out > 0 || sdef->return_type != NULL) {
      boolean first_param = TRUE;
      /* constructor */
      def = mputprintf(def, "%s_reply_redirect(", name);
      if (sdef->return_type != NULL) {
        def = mputprintf(def, "%s *return_ptr", sdef->return_type);
        first_param = FALSE;
      }
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if(sdef->parameters.elements[i].direction != PAR_IN) {
          if (first_param) first_param = FALSE;
          else def = mputstr(def, ", ");
          def = mputprintf(def, "%s *par_%s = NULL",
            sdef->parameters.elements[i].type,
            sdef->parameters.elements[i].name);
        }
      }
      def = mputstr(def, ")\n"
        " : ");
      first_param = TRUE;
      if (sdef->return_type != NULL) {
        def = mputstr(def, "ret_val_ptr(return_ptr)");
        first_param = FALSE;
      }
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if(sdef->parameters.elements[i].direction != PAR_IN) {
          if (first_param) first_param = FALSE;
          else def = mputstr(def, ", ");
          def = mputprintf(def, "ptr_%s(par_%s)",
            sdef->parameters.elements[i].name,
            sdef->parameters.elements[i].name);
        }
      }
      def = mputstr(def, " { }\n");
    }
    /* otherwise constructor is not needed */

    /* set_parameters function (used for param redirect in getreply) */
    if ((sdef->parameters.nElements - num_in) > 0
      || sdef->return_type != NULL) {
      /* if there are "out" or "inout" parameters or a "return" ... */
      def = mputprintf(def, "void set_parameters(const %s_reply& reply_par) "
        "const;\n", name);
      src = mputprintf(src, "void %s_reply_redirect::set_parameters(const "
        "%s_reply& reply_par) const\n"
        "{\n", name, name);
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if (sdef->parameters.elements[i].direction != PAR_IN) {
          src = mputprintf(src, "if (ptr_%s != NULL) "
            "*ptr_%s = reply_par.%s();\n",
            sdef->parameters.elements[i].name,
            sdef->parameters.elements[i].name,
            sdef->parameters.elements[i].name);
        }
      }
      if (sdef->return_type!=NULL) {
        src = mputstr(src, "if (ret_val_ptr != NULL) "
          "*ret_val_ptr = reply_par.return_value();\n");
      }
      src = mputstr(src, "}\n\n");
    }
    else {
      def = mputprintf(def, "inline void set_parameters(const %s_reply&) "
        "const {}\n", name);
    }

    def = mputstr(def, "};\n\n");
    /* end of class xxx_reply_redirect */
  } /* if (!sdeff->is_noblock) */


  if (sdef->exceptions.nElements > 0) {
    char *selection_type, *unbound_value, *selection_prefix;

    selection_type = mcopystr("exception_selection_type");
    unbound_value = mcopystr("UNBOUND_VALUE");
    selection_prefix = mcopystr("ALT");

    /*
     *
     * xxx_exception class
     *
     */
    decl = mputprintf(decl, "class %s_exception;\n", name);
    /* class definition */
    def = mputprintf(def, "class %s_exception {\n", name);

    /* enum type */
    def = mputstr(def, "public:\n"
      "enum exception_selection_type { ");
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      def = mputprintf(def, "ALT_%s = %lu, ",
        sdef->exceptions.elements[i].altname, (unsigned long) i);
    }
    def = mputprintf(def, " UNBOUND_VALUE = %lu };\n"
          "private:\n", (unsigned long) sdef->exceptions.nElements);

    /* data members */
    def = mputprintf(def, "%s exception_selection;\n"
      "union {\n", selection_type);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      def = mputprintf(def, "%s *field_%s;\n",
        sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname);
    }
    def = mputstr(def, "};\n");

    /* clean_up function */
    def = mputstr(def, "void clean_up();\n");
    src = mputprintf(src, "void %s_exception::clean_up()\n"
      "{\n"
      "switch (exception_selection) {\n", name);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "delete field_%s;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
      if (i < sdef->exceptions.nElements - 1)
        src = mputstr(src, "break;\n");
    }
    src = mputprintf(src, "default:\n"
      "break;\n"
      "}\n"
      "exception_selection = %s;\n"
      "}\n\n", unbound_value);

    /* copy_value function */
    def = mputprintf(def, "void copy_value(const %s_exception& "
      "other_value);\n", name);
    src = mputprintf(src, "void %s_exception::copy_value(const "
      "%s_exception& other_value)\n"
      "{\n"
      "switch (other_value.exception_selection) {\n", name, name);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "field_%s = new %s(*other_value.field_%s);\n"
        "break;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname);
    }
    src = mputprintf(src, "default:\n"
      "TTCN_error(\"Copying an uninitialized exception of signature "
      "%s.\");\n"
      "}\n"
      "exception_selection = other_value.exception_selection;\n"
      "}\n\n", name);

    /* default constructor */
    def = mputprintf(def, "public:\n"
      "%s_exception() : exception_selection(%s) { }\n", name,
      unbound_value);

    /* copy constructor */
    def = mputprintf(def, "%s_exception(const %s_exception& "
      "other_value) { copy_value(other_value); }\n", name, name);

    /* constructors (from exception types) */
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      def = mputprintf(def, "%s_exception(const %s& other_value);\n",
        name, sdef->exceptions.elements[i].name);
      src = mputprintf(src, "%s_exception::%s_exception(const "
        "%s& other_value)\n"
        "{\n"
        "field_%s = new %s(other_value);\n"
        "exception_selection = %s_%s;\n"
        "}\n\n", name, name, sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].name, selection_prefix,
        sdef->exceptions.elements[i].altname);
      def = mputprintf(def, "%s_exception(const %s_template& "
        "other_value);\n", name, sdef->exceptions.elements[i].name);
      src = mputprintf(src, "%s_exception::%s_exception(const "
        "%s_template& other_value)\n"
        "{\n"
        "field_%s = new %s(other_value.valueof());\n"
        "exception_selection = %s_%s;\n"
        "}\n\n", name, name, sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].name, selection_prefix,
        sdef->exceptions.elements[i].altname);
    }

    /* destructor */
    def = mputprintf(def, "~%s_exception() { clean_up(); }\n", name);

    /* assignment operator */
    def = mputprintf(def, "%s_exception& operator=(const %s_exception& "
      "other_value);\n", name, name);
    src = mputprintf(src, "%s_exception& %s_exception::operator=(const "
      "%s_exception& other_value)\n"
      "{\n"
      "if (this != &other_value) {\n"
      "clean_up();\n"
      "copy_value(other_value);\n"
      "}\n"
      "return *this;\n"
      "}\n\n", name, name, name);

    /* field (type) access functions */
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      def = mputprintf(def, "%s& %s_field();\n",
        sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname);
      src = mputprintf(src, "%s& %s_exception::%s_field()\n"
        "{\n"
        "if (exception_selection != %s_%s) {\n"
        "clean_up();\n"
        "field_%s = new %s;\n"
        "exception_selection = %s_%s;\n"
        "}\n"
        "return *field_%s;\n"
        "}\n\n", sdef->exceptions.elements[i].name, name,
        sdef->exceptions.elements[i].altname, selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].name,
        selection_prefix, sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
      def = mputprintf(def, "const %s& %s_field() const;\n",
        sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname);
      src = mputprintf(src, "const %s& %s_exception::%s_field() const\n"
        "{\n"
        "if (exception_selection != %s_%s) "
        "TTCN_error(\"Referencing to non-selected type %s in an "
        "exception of signature %s.\");\n"
        "return *field_%s;\n"
        "}\n\n", sdef->exceptions.elements[i].name, name,
        sdef->exceptions.elements[i].altname, selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].dispname, dispname,
        sdef->exceptions.elements[i].altname);
    }

    /* get_selection function */
    def = mputprintf(def, "inline %s get_selection() const "
      "{ return exception_selection; }\n", selection_type);

    /* encode_text function */
    def = mputstr(def, "void encode_text(Text_Buf& text_buf) const;\n");
    src = mputprintf(src, "void %s_exception::encode_text(Text_Buf& "
      "text_buf) const\n"
      "{\n"
      "text_buf.push_int(exception_selection);\n"
      "switch (exception_selection) {\n", name);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "field_%s->encode_text(text_buf);\n"
        "break;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
    }
    src = mputprintf(src, "default:\n"
      "TTCN_error(\"Text encoder: Encoding an uninitialized exception "
      "of signature %s.\");\n"
      "}\n"
      "}\n\n", dispname);

    /* decode_text function */
    def = mputstr(def, "void decode_text(Text_Buf& text_buf);\n");
    src = mputprintf(src, "void %s_exception::decode_text(Text_Buf& "
      "text_buf)\n"
      "{\n"
      "switch ((%s)text_buf.pull_int().get_val()) {\n", name, selection_type);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "%s_field().decode_text(text_buf);\n"
        "break;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
    }
    src = mputprintf(src, "default:\n"
      "TTCN_error(\"Text decoder: Unrecognized selector was received "
      "for an exception of signature %s.\");\n"
      "}\n"
      "}\n\n", dispname);

    /* log function */
    def = mputstr(def, "void log() const;\n");
    src = mputprintf(src, "void %s_exception::log() const\n"
      "{\n"
      "TTCN_Logger::log_event_str(\"%s, \");\n"
      "switch (exception_selection) {\n",
      name, dispname);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "TTCN_Logger::log_event_str(\"%s : \");\n"
        "field_%s->log();\n"
        "break;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].dispname,
        sdef->exceptions.elements[i].altname);
    }
    src = mputstr(src, "default:\n"
      "TTCN_Logger::log_event_str(\"<uninitialized exception>\");\n"
      "}\n"
      "}\n\n");

    def = mputstr(def, "};\n\n");
    /* end of xxx_exception class*/

    Free(selection_type);
    selection_type = mprintf("%s_exception::exception_selection_type", name);
    Free(unbound_value);
    unbound_value = mprintf("%s_exception::UNBOUND_VALUE", name);
    Free(selection_prefix);
    selection_prefix = mprintf("%s_exception::ALT", name);

    /*
     *
     * simple xxx_exception_template for the catch port-operator
     * only with constructors, a log/match function and value redirect
     *
     */
    decl = mputprintf(decl, "class %s_exception_template;\n", name);

    def = mputprintf(def, "class %s_exception_template {\n", name);

    /* data members */
    /* exception-selection enum */
    def = mputprintf(def, "%s exception_selection;\n", selection_type);
    /* union of all possible exceptions (templates) */
    def = mputstr(def, "union {\n");
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      def = mputprintf(def, "const %s_template *field_%s;\n",
        sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname);
    }
    def = mputstr(def, "};\n");
    /* union of all possible value redirect pointers */
    def = mputstr(def, "union {\n");
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      def = mputprintf(def, "%s *ptr_%s;\n",
        sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].altname);
    }
    def = mputstr(def, "};\n"
      "public:\n");
    /* constructors (for all possible template + redirect pointer pairs) */
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      def = mputprintf(def, "%s_exception_template(const %s_template& "
        "init_template, %s *value_ptr = NULL);\n", name,
        sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].name);
      src = mputprintf(src, "%s_exception_template::%s_exception_template"
        "(const %s_template& init_template, %s *value_ptr)\n"
        "{\n"
        "exception_selection = %s_%s;\n"
        "field_%s = &init_template;\n"
        "ptr_%s = value_ptr;\n"
        "}\n\n", name, name, sdef->exceptions.elements[i].name,
        sdef->exceptions.elements[i].name, selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
    }

    /* match function */
    def = mputprintf(def, "boolean match(const %s_exception& other_value) "
      "const;\n", name);
    src = mputprintf(src, "boolean %s_exception_template::match(const "
      "%s_exception& other_value) const\n"
      "{\n"
      "if (exception_selection != other_value.get_selection()) "
      "return FALSE;\n"
      "switch (exception_selection) {\n", name, name);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "return field_%s->match(other_value.%s_field());\n",
        selection_prefix, sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
    }
    src = mputprintf(src, "default:\n"
      "TTCN_error(\"Internal error: Invalid selector when matching an "
      "exception of signature %s.\");\n"
      "return FALSE;\n"
      "}\n"
      "}\n\n", dispname);

    /* log_match function */
    def = mputprintf(def, "void log_match(const %s_exception& other_value) "
      "const;\n", name);
    src = mputprintf(src, "void %s_exception_template::log_match(const "
      "%s_exception& other_value) const\n"
      "{\n"
      "TTCN_Logger::log_event_str(\"%s, \");\n"
      "if (exception_selection == other_value.get_selection()) {\n"
      "switch (exception_selection) {\n", name, name, dispname);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "TTCN_Logger::log_event_str(\"%s : \");\n"
        "field_%s->log_match(other_value.%s_field());\n"
        "break;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].dispname,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
    }
    src = mputstr(src, "default:\n"
      "TTCN_Logger::log_event_str(\"<invalid selector>\");\n"
      "}\n"
      "} else {\n"
      "other_value.log();\n"
      "TTCN_Logger::log_event_str(\" with \");\n"
      "switch (exception_selection) {\n");
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "TTCN_Logger::log_event_str(\"%s : \");\n"
        "field_%s->log();\n"
        "break;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].dispname,
        sdef->exceptions.elements[i].altname);
    }
    src = mputstr(src, "default:\n"
      "TTCN_Logger::log_event_str(\"<invalid selector>\");\n"
      "}\n"
      "if (match(other_value)) "
      "TTCN_Logger::log_event_str(\" matched\");\n"
      "else TTCN_Logger::log_event_str(\" unmatched\");\n"
      "}\n"
      "}\n\n");

    /* set_value function */
    def = mputprintf(def, "void set_value(const %s_exception& "
      "source_value) const;\n", name);
    src = mputprintf(src, "void %s_exception_template::set_value(const "
      "%s_exception& source_value) const\n"
      "{\n"
      "if (exception_selection == source_value.get_selection()) {\n"
      "switch (exception_selection) {\n", name, name);
    for (i = 0; i < sdef->exceptions.nElements; i++) {
      src = mputprintf(src, "case %s_%s:\n"
        "if (ptr_%s != NULL) *ptr_%s = source_value.%s_field();\n"
        "return;\n", selection_prefix,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname,
        sdef->exceptions.elements[i].altname);
    }
    src = mputprintf(src, "default:\n"
      "break;\n"
      "}\n"
      "}\n"
      "TTCN_error(\"Internal error: Invalid selector when performing "
      "value redirect on an exception of signature %s.\");\n"
      "}\n\n", dispname);

    def = mputstr(def, "};\n\n");
    /* end of class xxx_exception_template */

    Free(selection_type);
    Free(unbound_value);
    Free(selection_prefix);
  } /* if (sdef->exceptions.nElements > 0) */

  /*
   * template class
   */

  decl = mputprintf(decl, "class %s_template;\n", name);

  def = mputprintf(def, "class %s_template {\n", name);

  /* parameters */
  for (i = 0; i < sdef->parameters.nElements; i++) {
    def = mputprintf(def, "%s_template param_%s;\n",
      sdef->parameters.elements[i].type,
      sdef->parameters.elements[i].name);
  }
  if (sdef->return_type != NULL) {
    def = mputprintf(def, "mutable %s_template reply_value;\n",
      sdef->return_type);
  }

  def = mputstr(def, "public:\n");
  /* constructor */
  if (sdef->parameters.nElements > 0 || sdef->return_type != NULL) {
    boolean first_param = TRUE;
    def = mputprintf(def, "%s_template();\n", name);
    src = mputprintf(src, "%s_template::%s_template()\n"
      " : ", name, name);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (first_param) first_param = FALSE;
      else src = mputstr(src, ", ");
      src = mputprintf(src, "param_%s(ANY_VALUE)",
        sdef->parameters.elements[i].name);
    }
    if (sdef->return_type != NULL) {
      if (first_param) /*first_param = FALSE*/;
      else src = mputstr(src, ", ");
      src = mputstr(src, "reply_value(ANY_VALUE)");
    }
    src = mputstr(src, "\n"
      "{\n"
      "}\n\n");
  } else {
    def = mputprintf(def, "%s_template() { }\n", name);
  }

  if (sdef->parameters.nElements == 0) {
    /* constructor and assignment operator for parameter-less signatures */
    if (sdef->return_type != NULL) {
      def = mputprintf(def, "%s_template(null_type null_value);\n",
        name);
      src = mputprintf(src,
        "%s_template::%s_template(null_type)\n"
        " : reply_value(ANY_VALUE)\n"
        "{\n"
        "}\n\n", name, name);
    } else {
      def = mputprintf(def, "%s_template(null_type) { }\n",
        name);
    }
    def = mputprintf(def, "inline %s_template& operator=(null_type)"
      " { return *this; }\n", name);
  }

  /* parameter access functions */
  for (i = 0; i < sdef->parameters.nElements; i++) {
    def = mputprintf(def, "inline %s_template& %s() { return param_%s; }\n"
      "inline const %s_template& %s() const { return param_%s; }\n",
      sdef->parameters.elements[i].type,
      sdef->parameters.elements[i].name,
      sdef->parameters.elements[i].name,
      sdef->parameters.elements[i].type,
      sdef->parameters.elements[i].name,
      sdef->parameters.elements[i].name);
  }
  if (sdef->return_type != NULL) {
    def = mputprintf(def, "inline %s_template& return_value() const "
      "{ return reply_value; }\n", sdef->return_type);
  }

  /* create_call function for creating xxx_call signature-value */
  if (num_in > 0) {
    def = mputprintf(def, "%s_call create_call() const;\n", name);
    src = mputprintf(src, "%s_call %s_template::create_call() const\n"
      "{\n"
      "%s_call ret_val;\n", name, name, name);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_OUT) {
        src = mputprintf(src, "ret_val.%s() = param_%s.valueof();\n",
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name);
      }
    }
    src = mputstr(src, "return ret_val;\n"
      "}\n\n");
  } else {
    def = mputprintf(def, "inline %s_call create_call() const "
      "{ return %s_call(); }\n", name, name);
  }

  if (!sdef->is_noblock) {
    /* create_reply function for creating xxx_reply signature-value */
    if (num_out > 0 || sdef->return_type != NULL) {
      def = mputprintf(def, "%s_reply create_reply() const;\n", name);
      src = mputprintf(src, "%s_reply %s_template::create_reply() const\n"
        "{\n"
        "%s_reply ret_val;\n", name, name, name);
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if (sdef->parameters.elements[i].direction != PAR_IN) {
          src = mputprintf(src, "ret_val.%s() = "
            "param_%s.valueof();\n",
            sdef->parameters.elements[i].name,
            sdef->parameters.elements[i].name);
        }
      }
      if (sdef->return_type != NULL) {
        src = mputstr(src, "ret_val.return_value() = "
          "reply_value.valueof();\n");
      }
      src = mputstr(src, "return ret_val;\n"
        "}\n\n");
    } else {
      def = mputprintf(def, "inline %s_reply create_reply() const "
        "{ return %s_reply(); }\n", name, name);
    }
  }

  /* match_call function for matching with xxx_call signature-value */
  if (num_in > 0) {
    boolean first_param = TRUE;
    def = mputprintf(def, "boolean match_call(const %s_call& match_value) "
      "const;\n", name);
    src = mputprintf(src, "boolean %s_template::match_call(const %s_call& "
      "match_value) const\n"
      "{\n"
      "return ", name, name);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_OUT) {
        if (first_param) first_param = FALSE;
        else src = mputstr(src, " &&\n");
        src = mputprintf(src, "param_%s.match(match_value.%s())",
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name);
      }
    }
    src = mputstr(src, ";\n"
      "}\n\n");
  } else {
    def = mputprintf(def, "inline boolean match_call(const %s_call&"
      ") const { return TRUE; }\n", name);
  }

  if (!sdef->is_noblock) {
    if (num_out > 0 || sdef->return_type != NULL) {
      boolean first_param = TRUE;
      /* match_reply function for matching with xxx_reply value */
      def = mputprintf(def, "boolean match_reply(const %s_reply& "
        "match_value) const;\n", name);
      src = mputprintf(src, "boolean %s_template::match_reply(const "
        "%s_reply& match_value) const\n"
        "{\n"
        "return ", name, name);
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if(sdef->parameters.elements[i].direction != PAR_IN) {
          if (first_param) first_param = FALSE;
          else src = mputstr(src, " &&\n");
          src = mputprintf(src, "param_%s.match(match_value.%s())",
            sdef->parameters.elements[i].name,
            sdef->parameters.elements[i].name);
        }
      }
      if (sdef->return_type != NULL) {
        if (first_param) /*first_param = FALSE*/;
        else src = mputstr(src, " &&\n");
        src = mputstr(src,
          "reply_value.match(match_value.return_value())");
      }
      src = mputstr(src, ";\n"
        "}\n\n");
    } else {
      def = mputprintf(def, "inline boolean match_reply(const %s_reply&"
        ") const { return TRUE; }\n", name);
    }
  }

  /* set_value_template function */
  if (sdef->return_type != NULL) {
    def = mputprintf(def, "const %s_template& set_value_template(const "
      "%s_template& new_template) const;\n", name, sdef->return_type);
    src = mputprintf(src,
      "const %s_template& %s_template::set_value_template"
      "(const %s_template& new_template) const\n"
      "{\n"
      "reply_value = new_template;\n"
      "return *this;\n"
      "}\n\n", name, name, sdef->return_type);
  }

  /* log function */
  def = mputstr(def, "void log() const;\n");
  src = mputprintf(src, "void %s_template::log() const\n"
    "{\n", name);
  if (sdef->parameters.nElements >= 1) {
    for (i = 0; i < sdef->parameters.nElements; i++) {
      src = mputstr(src, "TTCN_Logger::log_event_str(\"");
      if (i == 0) src = mputc(src, '{');
      else src = mputc(src, ',');
      src = mputprintf(src, " %s := \");\n"
        "param_%s.log();\n", sdef->parameters.elements[i].dispname,
        sdef->parameters.elements[i].name);
    }
    src = mputstr(src, "TTCN_Logger::log_event_str(\" }\");\n");
  } else {
    src = mputstr(src, "TTCN_Logger::log_event_str(\"{ }\");\n");
  }
  src = mputstr(src, "}\n\n");

  /* log_match_call function */
  def = mputprintf(def, "void log_match_call(const %s_call& match_value) "
    "const;\n", name);
  src = mputprintf(src, "void %s_template::log_match_call(const %s_call& "
    , name, name);
  if (num_in > 0) {
    boolean first_param = TRUE;
    src = mputstr(src, "match_value) const\n{\n");
    for (i = 0; i < sdef->parameters.nElements; i++) {
      if (sdef->parameters.elements[i].direction != PAR_OUT) {
        src = mputstr(src, "TTCN_Logger::log_event_str(\"");
        if (first_param) {
          src = mputc(src, '{');
          first_param = FALSE;
        } else src = mputc(src, ',');
        src = mputprintf(src, " %s := \");\n"
          "param_%s.log_match(match_value.%s());\n",
          sdef->parameters.elements[i].dispname,
          sdef->parameters.elements[i].name,
          sdef->parameters.elements[i].name);
      }
    }
    src = mputstr(src, "TTCN_Logger::log_event_str(\" }\");\n");
  } else {
    src = mputstr(src, ") const\n{\n"
      "TTCN_Logger::log_event_str(\"{ } with { } matched\");\n");
  }
  src = mputstr(src, "}\n\n");

  if (!sdef->is_noblock) {
    /* log_match_reply function */
    def = mputprintf(def, "void log_match_reply(const %s_reply& match_value) "
      "const;\n", name);
    src = mputprintf(src, "void %s_template::log_match_reply(const %s_reply& "
      , name, name);
    if (num_out > 0) {
      boolean first_param = TRUE;
      src = mputstr(src, "match_value) const\n{\n");
      for (i = 0; i < sdef->parameters.nElements; i++) {
        if (sdef->parameters.elements[i].direction != PAR_IN) {
          src = mputstr(src, "TTCN_Logger::log_event_str(\"");
          if (first_param) {
            src = mputc(src, '{');
            first_param = FALSE;
          } else src = mputc(src, ',');
          src = mputprintf(src, " %s := \");\n"
            "param_%s.log_match(match_value.%s());\n",
            sdef->parameters.elements[i].dispname,
            sdef->parameters.elements[i].name,
            sdef->parameters.elements[i].name);
        }
      }
      if (sdef->return_type != NULL) {
        src = mputstr(src, "TTCN_Logger::log_event_str(\" } value "
          "\");\n"
          "reply_value.log_match(match_value.return_value());\n");
      } else {
        src = mputstr(src, "TTCN_Logger::log_event_str(\" }\");\n");
      }
    } else {
      if (sdef->return_type != NULL) {
        src = mputstr(src, "match_value) const\n{\n"
          "TTCN_Logger::log_event_str(\"{ } with { } "
          "matched value \");\n"
          "reply_value.log_match(match_value.return_value());\n");
      } else {
        src = mputstr(src, ") const\n{\n"
          "TTCN_Logger::log_event_str(\"{ } with { } "
          "matched\");\n");
      }
    }
    src = mputstr(src, "}\n\n");
  }

  if (sdef->parameters.nElements > 0) {
    /* encode_text function */
    def = mputstr(def, "void encode_text(Text_Buf& text_buf) const;\n");
    src = mputprintf(src, "void %s_template::encode_text(Text_Buf& "
      "text_buf) const\n"
      "{\n", name);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      src = mputprintf(src, "param_%s.encode_text(text_buf);\n",
        sdef->parameters.elements[i].name);
    }
    src = mputstr(src, "}\n\n");
    /* decode_text function */
    def = mputstr(def, "void decode_text(Text_Buf& text_buf);\n");
    src = mputprintf(src, "void %s_template::decode_text(Text_Buf& "
      "text_buf)\n"
      "{\n", name);
    for (i = 0; i < sdef->parameters.nElements; i++) {
      src = mputprintf(src, "param_%s.decode_text(text_buf);\n",
        sdef->parameters.elements[i].name);
    }
    src = mputstr(src, "}\n\n");
  } else {
    def = mputstr(def, "inline void encode_text(Text_Buf&) const "
      "{ }\n"
      "inline void decode_text(Text_Buf&) { }\n");
  }

  /* end of template definition */
  def = mputstr(def, "};\n\n");

  output->header.class_decls = mputstr(output->header.class_decls, decl);
  Free(decl);

  output->header.class_defs = mputstr(output->header.class_defs, def);
  Free(def);

  output->source.methods = mputstr(output->source.methods, src);
  Free(src);
}
Beispiel #16
0
/**********************************************************************
 *  Function  suf_ary_menu()
 *                                                                    
 *  Parameter:                                                       
 *   
 *                                                              
 *  This function prompts user to choose an algorithm to create 
 *  a suffix array and use it.  
 *  The utilities menu is also available from this menu.
 *                                                                   
 **********************************************************************/
void suf_ary_menu()
{
  int status, num_lines;
  STRING *spt, *pattern, *text;

  while (1)  {
    num_lines = 13;
    printf("\n**   Suffix Array Menu    **\n\n");
    printf("1)  Build suffix array using quick sort\n");
    printf("2)  Build suffix array (Zerkle's version)\n");
    printf("3)  Build suffix array from a suffix tree\n");
    printf("4)  Exact matching using suffix array and naive algorithm\n");
    printf("5)  Exact matching using suffix array and mlr accelerant\n");
    printf("6)  Exact matching using suffix array and lcp super-accelerant\n");
    printf("*)  String Utilites\n");
    printf("0)  Exit\n");
    printf("\nEnter Selection: ");
  
    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;
    switch (choice[0]) {
    case '0':
      return;

    case '1':
      if (!(spt = get_string("sequence")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe sequence:\n");
      terse_print_string(spt);
      mputc('\n');

      status = map_sequences(spt, NULL, NULL, 0);
      if (status != -1) {
        mprintf("Building suffix array using qsort...\n\n");
        strmat_sary_qsort(spt, stats_flag);
        unmap_sequences(spt, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;
        
    case '2':
      if (!(spt = get_string("sequence")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe sequence:\n");
      terse_print_string(spt);
      mputc('\n');

      status = map_sequences(spt, NULL, NULL, 0);
      if (status != -1) {
        mprintf("Executing Zerkle's algorithm...\n\n");
        strmat_sary_zerkle(spt, stats_flag);
        unmap_sequences(spt, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;
      
    case '3':
      if (!(spt = get_string("sequence")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe sequence:\n");
      terse_print_string(spt);
      mputc('\n');

      status = map_sequences(spt, NULL, NULL, 0);
      if (status != -1) {
        mprintf("Building suffix array from suffix tree...\n\n");
        strmat_sary_stree(spt, stats_flag);
        unmap_sequences(spt, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '4':
      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);    
      mputc('\n');

      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        mprintf("Executing exact matching using suffix array...\n\n");
        strmat_sary_match_naive(pattern, text, stats_flag);
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;  

    case '5':
      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);    
      mputc('\n');

      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        mprintf("Executing exact matching using suffix array...\n\n");
        strmat_sary_match_mlr(pattern, text, stats_flag);
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;  

    case '6':
      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);    
      mputc('\n');

      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        mprintf("Executing exact matching using suffix array...\n\n");
        strmat_sary_match_lcp(pattern, text, stats_flag);
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;  

    case '*':
      util_menu();
      break;

    default:
      printf("\nThat is not a choice.\n");
    }
  }
}
Beispiel #17
0
static void mputstr(const char *prntstr) {
  while(*prntstr) mputc(*prntstr++);
}
Beispiel #18
0
/**********************************************************************
 *  Function  z_alg_menu();
 *                                                                    
 *  Parameter:                                                       
 *   
 *                                                              
 *  This function prompts user to create and utilize the Z values 
 *  for a string.  The utilities menu is also available from this menu.
 *                                                                   
 **********************************************************************/
void z_alg_menu()
{
  int status, num_lines;
  char ch;
  STRING *text, *pattern;

  while (1) {
    num_lines = 12;
    printf("\n**   Z-value Algorithm Menu    **\n\n");
    printf("1)  Build Z values for a sequence\n");
    printf("2)  Exact matching using Z values\n");
    printf("3)  Knuth-Morris-Pratt  (Z-values preprocessing)\n");
    printf("     a) using sp values\n");
    printf("     b) using sp' values\n");
    printf("*)  String Utilites\n");
    printf("0)  Exit\n");
    printf("\nEnter Selection: ");
  
    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;
    switch (choice[0]) {
    case '0':
      return;

    case '1':
      if (!(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mputs("The string:\n");
      terse_print_string(text);

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        mputs("Building Z values...\n\n");
        strmat_z_build(text, stats_flag);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '2':
      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mputs("\nThe pattern:\n");
      terse_print_string(pattern);
      mputs("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        mputs("Executing exact matching with Z values algorithm...\n\n");
        strmat_z_match(pattern, text, stats_flag);
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '3':
      ch = choice[1];
      if (toupper(ch) != 'A' && toupper(ch) != 'B') {
        printf("\nYou must specify the KMP variation (as in '3a' or '3b').\n");
        continue;
      }

      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');
        
      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        if (toupper(ch) == 'A') {
          mprintf ("Executing KMP with sp values...\n\n");
          strmat_kmp_sp_z_match(pattern, text, stats_flag);
        }
        else {
          mprintf ("Executing KMP with sp' values...\n\n");
          strmat_kmp_spprime_z_match(pattern, text, stats_flag);
        }
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '*':
      util_menu();
      break;

    default:
      printf("\nThat is not a choice.\n");
    }
  }
}
Beispiel #19
0
/**********************************************************************
 *  Function  repeats_menu()
 *                                                                    
 *  Parameter:                                                       
 *   
 *                                                              
 *  This function prompts user to choose an algorithm to compute
 *  repeats and similar things.
 *  The utilities menu is also available from this menu.
 *                                                                   
 **********************************************************************/
void repeats_menu()
{
  static int smax_percent = 0;
  static int smax_minlen = 0;
  int status, num_lines;
  char ch;
  STRING *text;

  while (1) {
    num_lines = 20;

    printf("\n**   Repeats Menu    **\n\n");
    printf("1)  Find primitive tandem repeats (Crochemore's algorithm)\n");
    printf("2)  Find supermaximals and near supermaximals of a string\n");
    printf("3)  Find nonoverlapping maximals of a string"
           " (Crochemore variant)\n");
    printf("4)  Find nonoverlapping maximals of a string"
           " (big path algorithm)\n");
    printf("5)  Find tandem repeats/tandem arrays using the suffix tree\n");
    printf("6)  Find vocabulary of tandem repeats (and more) using\n");
    printf("     a) Ziv-Lempel decomposition\n");
    printf("     b) nonoverlapping blocks decomposition (as in the book)\n");
    printf("7)  Find occurrences in linear time (without suffix tree) using\n");
    printf("     a) Ziv-Lempel decomposition\n");
    printf("     b) nonoverlapping blocks decomposition (as in the book)\n");
    printf("*)  String Utilites\n");
    printf("0)  Exit\n");
    printf("\nEnter Selection: ");
 
    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;

    switch (choice[0]) {
    case '0':
      return;

    case '1':
      if (!(text = get_string("string")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe string:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        strmat_repeats_primitives(text, stats_flag);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '2':
      if (!(text = get_string("text")))
        continue;

      smax_percent = get_bounded("Percent Supermaximal", 0, 100, smax_percent);
      printf("\n");
      if (smax_percent == -1)
        continue;

      smax_minlen = get_bounded("Supermax. Minimum Length", 0, text->length,
                                smax_minlen);
      printf("\n");
      if (smax_minlen == -1)
        continue;
                                         
      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        mprintf("Finding the supermaximals...\n\n");
        strmat_repeats_supermax(text, smax_percent, smax_minlen);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '3':
      if (!(text = get_string("string")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe string:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        strmat_repeats_nonoverlapping(text, stats_flag);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '4':
      if (!(text = get_string("string")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe string:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        strmat_repeats_bigpath(text, stree_build_policy, stree_build_threshold,
                               stats_flag);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '5':
      if (!(text = get_string("string")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe string:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        strmat_repeats_tandem(text, stree_build_policy, stree_build_threshold,
                              stats_flag);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '6':
      ch = toupper(choice[1]);
      if (ch!='A' && ch!='B') {
        printf("\nYou must specify which type of decomposition to use"
               "(as in '6a' or '6b').\n");
        continue;
      }

      if (!(text = get_string("string")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe string:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        strmat_repeats_vocabulary(text, stree_build_policy,
                                  stree_build_threshold, stats_flag,ch);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '7':
      ch = toupper(choice[1]);
      if (ch!='A' && ch!='B') {
        printf("\nYou must specify which type of decomposition to use"
               "(as in '7a' or '7b').\n");
        continue;
      }

      if (!(text = get_string("string")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe string:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        strmat_repeats_linear_occs(text, stree_build_policy,
                                   stree_build_threshold, stats_flag,ch);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '*':
      util_menu();
      break;
   
    default:
      printf("\nThat is not a choice.\n");
    }
  }
}
Beispiel #20
0
int print_matches(const STRING *string, const STRING **strings, int num_strings, MATCHES list, int num_matches)
{
    int i, j, N, count, matchdigs, minwidth, maxwidth;
    int width, maxposdigs, maxiddigs, multistring_mode;
    CHAR_TYPE *T;
    char format[32];
    MATCHES ptr;

    if (num_matches == 0) {
        mputs("Found 0 matches:\n");
        return 1;
    }

    multistring_mode = (list->type == TEXT_SET_EXACT);
    if ((!multistring_mode && string == NULL) 
        || (multistring_mode && strings == NULL))
    return 0;

  /*
   * Compute the number of digits in the number of matches and the
   * widest position (and possibly widest identifier) of any match.  Also,
   * find the smallest and largest match length.
   */
  matchdigs = my_itoalen(num_matches);

  maxposdigs = maxiddigs = 0;
  minwidth = maxwidth = -1;
  for (count=0,ptr=list; count < num_matches; count++,ptr=ptr->next) {
    if (minwidth == -1 || ptr->rend - ptr->lend + 1 < minwidth)
      minwidth = ptr->rend - ptr->lend + 1;
    if (maxwidth == -1 || ptr->rend - ptr->lend + 1 > maxwidth)
      maxwidth = ptr->rend - ptr->lend + 1;

    width = my_itoalen(ptr->rend);
    if (width > maxposdigs)
      maxposdigs = width;

    if (multistring_mode && num_strings > 1) {
      width = my_itoalen(ptr->textid);
      if (width > maxiddigs)
        maxiddigs = width;
    }
  }

  /* 
   * Print the header line with signal characters showing where
   * the matches are.
   */
  printf("Found %d matches:", num_matches);
  width = (17 + 2 * maxposdigs + maxiddigs) - (15 + matchdigs);
  for (i=0; i < width; i++)
    mputc(' ');
  for (i=0; i < minwidth && i < 43; i++)
    mputc('_');
  for ( ; i < maxwidth && i < 43; i++)
    mputc('.');
  if (i == 43)
    mputc('>');
  mputc('\n');

  /*
   * Build the format for printing the positions of the match, and 
   * then loop through the matches, printing the information.
   */
  if (multistring_mode && num_strings > 1)
    sprintf(format, " %%%dd:  %%%dd-%%%dd:    ", maxiddigs, maxposdigs,
            maxposdigs);
  else
    sprintf(format, "    %%%dd-%%%dd:    ", maxposdigs, maxposdigs);

  T = NULL;
  N = 0;
  if (!multistring_mode) {
      T = string->sequence;
      N = string->length;
  }
  else if (num_strings == 1) {
     T = strings[0]->sequence;
    N = strings[0]->length;
  }
    
  for (count=0,ptr=list; count < num_matches; count++,ptr=ptr->next) {
    if (multistring_mode && num_strings > 1) {
      printf(format, ptr->textid, ptr->lend, ptr->rend);
      T = strings[ptr->textid-1]->sequence;
      N = strings[ptr->textid-1]->length;
    }
    else
      printf(format, ptr->lend, ptr->rend);

    if (ptr->lend - 4 >= 1) {
      mputs("...");
      i = ptr->lend - 4;
    }
    else {
      mputs("   ");
      for (i=ptr->lend-4; i < 1; i++)
        mputc(' ');
    }

    for (j=0; j < 44 && i <= N && i <= ptr->rend + 4; i++,j++)
      mputc((isprint((int)T[i-1]) ? T[i-1] : '#'));

    if (i <= N)
      mputs("...");

    if (mputc('\n') == 0)
      break;
  }

  mputc('\n');

  return 1;
}
Beispiel #21
0
static void mputhex(long number) {
	/* first put 0x */
	mputc('0'); mputc('x');
	/* now put the number in hex */
	mputnum(number,16);
}
Beispiel #22
0
/**********************************************************************
 *  Function  basic_alg_menu();
 *                                                                    
 *  Parameter:                                                       
 *   
 *                                                              
 *  This function prompts user to choose a basic algorithm to execute
 *  such as Boyer-Moore.  The utilities menu is also available from
 *  this menu.
 *                                                                   
 **********************************************************************/
void basic_alg_menu()
{
  int i, status, num_lines, alpha_size, num_patterns;
  char ch;
  STRING *text, *pattern, **patterns;

  alpha_size = 0;
  while (1)  {
    num_lines = 22;
    printf("\n**   Basic Search Algorithm Menu    **\n\n");
    printf("1)  Naive Algorithm\n");
    printf("2)  Boyer-Moore Variations\n");
    printf("     a) Bad character rule\n");
    printf("     b) Extended bad character rule\n");
    printf("     c) Good suffix & bad character rules\n");
    printf("     d) Good suffix & extended bad character rules\n");
    printf("3)  Knuth-Morris-Pratt (original preprocessing)\n");
    printf("     a) using sp values\n");
    printf("     b) using sp' values\n");
    printf("4)  Aho-Corasick Set Matching\n");
    printf("5)  Boyer-Moore Set Matching\n");
    printf("     a) Bad character rule only\n");
    printf("     b) Good suffix rule using keyword and suffix trees\n");
    printf("     c) Good suffix rule using suffix tree only\n");
    printf("     d) using original Boyer-Moore (1c) on each pattern\n");
    printf("*)  String Utilites\n");
    printf("0)  Exit\n");
    printf("\nEnter Selection: ");
  
    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;
    switch (choice[0]) {
    case '0':
      return;

    case '1':
      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');
        
      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        mprintf ("Executing naive search algorithm...\n\n");
        strmat_naive_match(pattern, text, stats_flag);
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '2':
      ch = choice[1];
      if (toupper(ch) != 'A' && toupper(ch) != 'B' &&
          toupper(ch) != 'C' && toupper(ch) != 'D') {
        printf("\nYou must specify the Boyer-Moore variation"
               " (as in '2a' or '2c').\n");
        continue;
      }

      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        mprintf("Executing Boyer-Moore algorithm...\n\n");
        switch (toupper(ch)) {
        case 'A':  strmat_bmbad_match(pattern, text, stats_flag);  break;
        case 'B':  strmat_bmext_match(pattern, text, stats_flag);  break;
        case 'C':  strmat_bmgood_match(pattern, text, stats_flag);  break;
        case 'D':  strmat_bmextgood_match(pattern, text, stats_flag);  break;
        }
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '3':
      ch = choice[1];
      if (toupper(ch) != 'A' && toupper(ch) != 'B') {
        printf("\nYou must specify the KMP variation (as in '3a' or '3b').\n");
        continue;
      }

      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');
        
      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        if (toupper(ch) == 'A') {
          mprintf ("Executing KMP with sp values...\n\n");
          strmat_kmp_sp_orig_match(pattern, text, stats_flag);
        }
        else {
          mprintf ("Executing KMP with sp' values...\n\n");
          strmat_kmp_spprime_orig_match(pattern, text, stats_flag);
        }
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '4':
      if (!(patterns = get_string_ary("list of patterns", &num_patterns)))
        continue;
      if (!(text = get_string("text"))) {
        free(patterns);
        continue;
      }

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe patterns:\n");
      for (i=0; i < num_patterns; i++) {
        mprintf("%2d)", i + 1);
        terse_print_string(patterns[i]);
      }
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, patterns, num_patterns);
      if (status != -1) {
        mprintf("Executing Aho-Corasick algorithm...\n\n");
        strmat_ac_match(patterns, num_patterns, text, stats_flag);
        unmap_sequences(text, NULL, patterns, num_patterns);
      }
      mend(num_lines);
      putchar('\n');

      free(patterns);
      break;

    case '5':
      ch = toupper(choice[1]);
      if (ch != 'A' && ch != 'B' && ch != 'C' && ch != 'D') {
        printf("\nYou must specify the set Boyer-Moore variation"
               " (as in '5a' or '5c').\n");
        continue;
      }

      if (!(patterns = get_string_ary("list of patterns", &num_patterns)))
        continue;
      if (!(text = get_string("text"))) {
        free(patterns);
        continue;
      }

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe patterns:\n");
      for (i=0; i < num_patterns; i++) {
        mprintf("%2d)", i + 1);
        terse_print_string(patterns[i]);
      }
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, NULL, patterns, num_patterns);
      if (status != -1) {
        mprintf("Executing Boyer-Moore set matching algorithm...\n\n");
        switch (toupper(ch)) {
        case 'A':  strmat_bmset_badonly_match(patterns, num_patterns,
                                              text, stats_flag);       break;
        case 'B':  strmat_bmset_2trees_match(patterns, num_patterns,
                                             text, stats_flag);        break;
        case 'C':  strmat_bmset_1tree_match(patterns, num_patterns,
                                            text, stats_flag);         break;
        case 'D':  strmat_bmset_naive_match(patterns, num_patterns,
                                            text, stats_flag);         break;
        }
        unmap_sequences(text, NULL, patterns, num_patterns);
      }
      mend(num_lines);
      putchar('\n');

      free(patterns);
      break;

    case '*':
      util_menu();
      break;

    default:
      printf("\nThat is not a choice.\n");
    }
  }
}