bool TaskGoodsInfo::isMonsterDrop(char* deadMonsterId)
{
	char* temp = monsterId;
	cout<<"[Bison Test drop task goods] MonsterIdSet is "<<temp<<endl;
	int pos = 0;
	char oneMonsterId[51];
	int len = strlen(temp);
	while (len > 0)
	{
		pos = findChar(temp, ',', len);
		if (pos == -1)
		{
			//防止最后一个没加冒号
			strncpy(oneMonsterId, temp, len + 1);
			temp = temp + len;
		} else {
			sub_str(oneMonsterId, temp, 0, pos);
			temp = temp + pos + 1;
		}
		len = strlen(temp);
		
		if (!strcmp(oneMonsterId, deadMonsterId))
		{
			cout<<"[Bison Test drop task goods] oneMonsterId "<<oneMonsterId<<endl;
			return true;
		}
	}
	cout<<"[Bison test drop task goods monid is "<<deadMonsterId<<endl;
	return false;
}
Exemple #2
0
/* lookup in all symbol tables */
TreeNode *Lookup(char *name, char *path){
	SymbolTable *p = SymTab;
	int ansLevel = -1;
	TreeNode *ret = NULL;
	TreeNode *tmp = NULL;
	// printf("lookup:%s, path:%s\n", name, path);
	while (p){
		if (sub_str(p->path, path)){
			// cout<<"lookup symbol"<<endl;
			tmp = LookupSymbol(name, p);
			// cout<<"end"<<endl;
			if (tmp){
				// cout<<"find"<<endl;
				if (ansLevel<p->nestLevel){
					ret = tmp;
					ansLevel = p->nestLevel;
				}
			}
		}
		if (!strcmp(p->path, path)) break;
		p = p->sibling;
	}
	
/*	if (ret){
		switch (ret->type){
			case integer_type: printf("find %s: integer\n", name); break;
			case real_type: printf("find %s: real\n", name); break;
			case char_type: printf("find %s: char\n", name); break;
			case boolean_type: printf("find %s: boolean\n", name); break;
			case string_type: printf("find %s: string\n", name); break;
		}
	}*/
	
	return ret;
}
int load_jvm_from_env_variable(const char* env_variable, const char* class_path, JavaVM** java_vm, JNIEnv** jni_env)
{
  char* java_home = getenv(env_variable);
  char java_home_path[MAX_LEN];
  char* jvm_so_path = NULL;
  int len;
  if(java_home && (len = strlen(java_home)) > 0)
  {
    printf("%s=%s\n",env_variable, java_home);
		int i, pos = 0;
		for (i = 0; i <= len; i++)
		{
			if (java_home[i] == PATH_SEPARATOR || i == len)
			{
				if (sub_str(java_home, pos, i - pos, java_home_path))
				{
					if (java_home_path[strlen(java_home_path) - 1] == FILE_SEPARATOR)
						java_home_path[strlen(java_home_path) - 1] = '\0';
					jvm_so_path = find_jvm_so(java_home_path);
					if (jvm_so_path != NULL)
					{
						if(load_jvm_dll(jvm_so_path, class_path, java_vm, jni_env) == JVM_LOAD_SUCCESS)
						{
              free(jvm_so_path);
              return JNI_TRUE;
						}
            free(jvm_so_path);
            jvm_so_path = NULL;
					}
				}
			}
		}
  }
  return JNI_FALSE;
}
Exemple #4
0
/* Waits for the process name g_paymod->proc_name and replaces the PIDSTR
 * string by the process ID in the g_paymod->file. 
 */
void substitute_process_id(void) {

  char *pid;

  pid = loop_pgrep(g_paymod->proc_name);

  sub_str(PIDSTR, pid, g_paymod->file);
}
Exemple #5
0
int main()
{
    char szBuf1[32] = "Hello";
    char szBuf2[32] = "world!";
    sub_str(szBuf2, szBuf1, 1, 5);
    printf("%s\r\n", szBuf1);
    return 0;
}
Exemple #6
0
int main()
{
    printf ("Hello! This is a simple program without a high destination "
            "that can read 2 strings and demonstrates functions "
            "for operations with strings.\n");
    printf ("Please enter maximum length of string"
            "(it should be less than %d)\n-> ", Max_Len);

    char *str_1 = NULL, *str_2 = NULL;
    int MaxLen = 0;
    int res_input = 0;

    res_input = scanf ("%d", &MaxLen);
    ASSERT (res_input); ASSERT ((MaxLen > 0)); ASSERT ((MaxLen < Max_Len));
    getchar();

    str_1 = (char*) calloc (MaxLen, sizeof(char));
    str_2 = (char*) calloc (MaxLen, sizeof(char));

    ASSERT (str_1); ASSERT (str_2);

    printf ("Please enter 2 strings: \n");

    get_str (str_1, MaxLen);
    get_str (str_2, MaxLen);

    int mode = -1;

    printf ("-------------------------------------------------------------\n");    \
    printf ("Now you can command what to do: \n");                                 \
    printf ("1 - print lengths of strings\n");                                     \
    printf ("2 - print result of comparision of 2 strings\n");                     \
    printf ("3 - print first index where second string is a part of the first\n"); \
    printf ("0 - exit program\n");

    while (mode != 0)
    {
        printf ("What's your choice?\n");

        scanf ("%d", &mode);

        ASSERT ((mode >= 0)); ASSERT ((mode <= 3));

        if (mode == 1) printf ("Lengts of strings: %d %d\n", str_len (str_1), str_len (str_2));

        if (mode == 2) printf ("Result of comparision: %d\n", str_cmp (str_1, str_2, MaxLen));

        if (mode == 3) printf ("Substring search result: %d\n", sub_str (str_1, str_2, MaxLen));
    }

    printf ("Good bye!\n");

    return 0;
}
  int main()
  {
	 int c;
	 int i = 0;
	 int buffer_dest_size = 0;
	 int should_print = 0;
	 int print_buffer = 0;
	 int past_line_start = 0;
	 int temp_arr_size = 0;
	 
	 char current_line[MAXSIZE];
	 char past_line[MAXSIZE];
	 char buffer_dest[MAX]; /* Will hold all strings that match */
	 char temp_arr[MAXSIZE] = {'a'};
	 
	 while(fgets(current_line, sizeof current_line, stdin) != NULL)
	 {
		 /*
		  * Compare past line with the current line.
		  * If the match, a print command is issued.
		  * Copy current line.
		  * Get a substring of saved string and compare with current line.
		  * if the line is not repeated, then it will be printed.
		  */
		 
		 if((strcmp(past_line, current_line) == 0))
		 {
			 should_print = 1;
		 }//end if
		 
		 strcpy(past_line, current_line);
		 sub_str(temp_arr, buffer_dest, past_line_start,buffer_dest_size); 
		 
		 if((should_print) && (strcmp(temp_arr, current_line)) != 0)
		 {
			 past_line_start = buffer_dest_size;
			 buffer_dest_size = copy_string(past_line, buffer_dest);
			 should_print = 0;
		 }//end if
		
	 }//end while
	 
	 
	 for(print_buffer; print_buffer < buffer_dest_size; print_buffer++)
	 {
		 printf("%c",buffer_dest[print_buffer]);
	 }//end for
	 
  }//end main 
Exemple #8
0
val debug(val ctx, val bindings, val data, val line, val pos, val base)
{
  uses_or2;
  val form = ctx_form(ctx);
  val rl = source_loc(form);
  cons_bind (lineno, file, rl);

  if (consp(data))
    data = car(data);
  else if (data == t)
    data = nil;

  if (!step_mode && !memqual(rl, breakpoints)
      && (debug_depth > next_depth))
  {
    return nil;
  } else {
    val print_form = t;
    val print_data = t;

    for (;;) {
      val input, command;

      if (print_form) {
        format(std_debug, lit("stopped at line ~d of ~a\n"),
               lineno, file, nao);
        format(std_debug, lit("form: ~s\n"), form, nao);
        format(std_debug, lit("depth: ~s\n"), num(debug_depth), nao);
        print_form = nil;
      }

      if (print_data) {
        int lim = cols * 8;

        if (data && pos) {
          val half = num((lim - 8) / 2);
          val full = num((lim - 8));
          val prefix, suffix;

          if (lt(pos, half)) {
            prefix = sub_str(data, zero, pos);
            suffix = sub_str(data, pos, full);
          } else {
            prefix = sub_str(data, minus(pos, half), pos);
            suffix = sub_str(data, pos, plus(pos, half));
          }

          format(std_debug, lit("data (~d:~d):\n~s . ~s\n"),
                 line, plus(pos, base), prefix, suffix, nao);
        } else if (data && length_str_ge(data, num(lim - 2))) {
          format(std_debug, lit("data (~d):\n~s...~s\n"), line,
                 sub_str(data, zero, num(lim/2 - 4)),
                 sub_str(data, num(-(lim/2 - 3)), t), nao);
        } else {
          format(std_debug, lit("data (~d):\n~s\n"), line, data, nao);
        }
        print_data = nil;
      }

      format(std_debug, lit("txr> "), nao);
      flush_stream(std_debug);

      input = split_str_set(or2(get_line(std_input), lit("q")), lit("\t "));
      command = if3(equal(first(input), null_string),
                    or2(last_command, lit("")), first(input));
      last_command = command;

      if (equal(command, lit("?")) || equal(command, lit("h"))) {
        help(std_debug);
        continue;
      } else if (equal(command, null_string)) {
        continue;
      } else if (equal(command, lit("c"))) {
        step_mode = 0;
        next_depth = -1;
        return nil;
      } else if (equal(command, lit("s"))) {
        step_mode = 1;
        return nil;
      } else if (equal(command, lit("n"))) {
        step_mode = 0;
        next_depth = debug_depth;
        return nil;
      } else if (equal(command, lit("f"))) {
        step_mode = 0;
        next_depth = debug_depth - 1;
        return nil;
      } else if (equal(command, lit("v"))) {
        show_bindings(bindings, std_debug);
      } else if (equal(command, lit("o"))) {
        print_form = t;
      } else if (equal(command, lit("i"))) {
        print_data = t;
      } else if (equal(command, lit("b")) || equal(command, lit("d")) ||
                 equal(command, lit("g")))
      {
        if (!rest(input)) {
          format(std_debug, lit("~s needs arguments\n"), command, nao);
          continue;
        } else {
          val n = int_str(second(input), num(10));
          val l = cons(n, or2(third(input), file));

          if (!n) {
            format(std_debug, lit("~s needs <line> [ <file> ]\n"),
                   command, nao);
            continue;
          }

          if (equal(command, lit("b"))) {
            breakpoints = remqual(l, breakpoints, nil);
            push(l, &breakpoints);
          } else if (equal(command, lit("d"))) {
            val breakpoints_old = breakpoints;
            breakpoints = remqual(l, breakpoints, nil);
            if (breakpoints == breakpoints_old)
              format(std_debug, lit("no such breakpoint\n"), nao);
          } else {
            opt_loglevel = c_num(n);
          }
        }
      } else if (equal(command, lit("l"))) {
        format(std_debug, lit("breakpoints: ~s\n"), breakpoints, nao);
      } else if (equal(command, lit("w"))) {
        format(std_debug, lit("backtrace:\n"), nao);
        {
          uw_frame_t *iter;

          for (iter = uw_current_frame(); iter != 0; iter = iter->uw.up) {
            if (iter->uw.type == UW_DBG) {
              if (iter->db.ub_p_a_pairs)
                format(std_debug, lit("(~s ~s ~s)\n"), iter->db.func,
                       args_copy_to_list(iter->db.args),
                       iter->db.ub_p_a_pairs, nao);
              else
                format(std_debug, lit("(~s ~s)\n"), iter->db.func,
                       args_copy_to_list(iter->db.args), nao);
            }
          }
        }
      } else if (equal(command, lit("q"))) {
        uw_throwf(debug_quit_s, lit("terminated via debugger"), nao);
      } else {
        format(std_debug, lit("unrecognized command: ~a\n"), command, nao);
      }
    }

    return nil;
  }
}