예제 #1
0
int Hashhandler(char* cmd){
	char* tok = strtok(NULL,DELIM);	
	if(!strcmp(tok,"--verify")){
		tok = strtok(NULL,DELIM);
		strcpy(files[0].name,tok);
		gethash(parse2(files[0].name));
		for(int j=0;j<MD5_DIGEST_LENGTH;++j){
			files[0].hash[j]=h[j];
		}
		files[0].timestamp = findtime(files[0].name);
		return 1;
	}
	else if(!strcmp(tok,"--checkall")){
		int nu = IndexGet();
		for(int i=0;i<nu;++i){
			gethash(parse2(files[i].name));
			for(int j=0;j<MD5_DIGEST_LENGTH;++j){
				files[i].hash[j]=h[j];
			}
			files[i].timestamp = findtime(parse2(files[i].name));
		}
		return nu;
	}
	else{
		//printf("wrong input\n");
		return -1;
	}
}
예제 #2
0
        void PptvLive2::async_open(
            response_type const & resp)
        {
            assert(StepType::closed == open_step_);

            set_response(resp);
            boost::system::error_code ec;

            if (url_.path().find('-') != std::string::npos) {
                // "[StreamID]-[Interval]-[datareate]
                std::vector<std::string> strs;
                slice<std::string>(url_.path(), std::inserter(strs, strs.end()), "-");
                if (strs.size() >= 3) {
                    jump_info_.video.name = strs[0].substr(1);
                    jump_info_.video.rid = jump_info_.video.name;
                    parse2(strs[2], jump_info_.video.bitrate);
                    parse2(strs[1], seg_.interval);
                } else {
                    ec = error::bad_url_format;
                }
            } else {
                ec = error::bad_url_format;
            }

            handle_async_open(ec);
        }
bool RemoteRepositoryAssistant::check_git_version ()
// Checks the git version.
{
  bool okay = false;
  GwSpawn spawn("git");
  spawn.arg("--version");
  spawn.read();
  spawn.run();
  ustring versiontext;
  if (!spawn.standardout.empty())
    versiontext = spawn.standardout[0];
  gw_message (versiontext);
  Parse parse1(versiontext, false);
  if (parse1.words.size() >= 3) {
    Parse parse2(parse1.words[2], false, ".");
    if (parse2.words.size() >= 3) {
      unsigned int version = 100 * convert_to_int(parse2.words[0]) + 10 * convert_to_int(parse2.words[1]) + convert_to_int(parse2.words[2]);
      if (version >= 150)
        okay = true;
    }
  }
  if (!okay) {
    versiontext.append(_(", but should be 1.5.0 or higher"));
    gtk_label_set_text(GTK_LABEL(label_try_git), versiontext.c_str());
  }
  if (!spawn.result) {
    gtk_label_set_text(GTK_LABEL(label_try_git), _("Program git failed to run. Has git been installed?"));
  }
  return okay;
}
예제 #4
0
void FunctionListPanel::reload()
{
	// clean up
	removeAllEntries();

	generic_string funcBegin = TEXT("^[\\s]*");
	generic_string qualifier_maybe = TEXT("((static|const)[\\s]+)?");
	generic_string returnType = TEXT("[\\w]+");
	generic_string space_starMaybe = TEXT("([\\s]+|\\*[\\s]+|[\\s]+\\*|[\\s]+\\*[\\s]+)");
	//generic_string space_starMaybe = TEXT("([\\s]+|\\*[\\s]+|[\\s]+\\*)");
	generic_string classQualifier_maybe = TEXT("([\\w_]+[\\s]*::)?");
	generic_string funcName = TEXT("(?!(if|whil|for))[\\w_]+");
	generic_string const_maybe = TEXT("([\\s]*const[\\s]*)?");
	generic_string space_maybe = TEXT("[\\s]*");
	generic_string params = TEXT("\\([\\n\\w_,*&\\s]*\\)");
	generic_string funcBody = TEXT("\\{");
	generic_string space_eol_maybe = TEXT("[\\n\\s]*");

	generic_string function = funcBegin + qualifier_maybe + returnType + space_starMaybe + classQualifier_maybe + funcName + space_maybe + params + const_maybe + space_eol_maybe + funcBody;
	generic_string secondSearch = funcName + space_maybe;
	secondSearch += TEXT("\\(");


	int docLen = (*_ppEditView)->getCurrentDocLen();
	vector<foundInfo> fi;
	vector<generic_string> regExpr1;
	vector<generic_string> regExpr2;

	regExpr1.push_back(secondSearch);
	regExpr1.push_back(funcName);

	generic_string secondSearch_className = TEXT("[\\w_]+(?=[\\s]*::)");
	regExpr2.push_back(secondSearch_className);

	generic_string classRegExpr = TEXT("^[\\t ]*(class|struct)[\\t ]+[\\w]+[\\s]*(:[\\s]*(public|protected|private)[\\s]+[\\w]+[\\s]*)?\\{");
	vector<generic_string> classRegExprArray;
	generic_string str1 = TEXT("(class|struct)[\\t ]+[\\w]+");
	generic_string str2 = TEXT("[\\t ]+[\\w]+");
	generic_string str3 = TEXT("[\\w]+");
	classRegExprArray.push_back(str1.c_str());
	classRegExprArray.push_back(str2.c_str());
	classRegExprArray.push_back(str3.c_str());
	//parse(fi, 0, docLen, function.c_str(), regExpr1, regExpr2);
	const TCHAR bodyOpenSymbol[] = TEXT("\\{");
	const TCHAR bodyCloseSymbol[] = TEXT("\\}");
	parse2(fi, 0, docLen, classRegExpr.c_str(), classRegExprArray, bodyOpenSymbol, bodyCloseSymbol, function.c_str(), regExpr1);

	for (size_t i = 0; i < fi.size(); i++)
	{
		generic_string entryName = TEXT("");
		if (fi[i]._pos2 != -1)
		{
			entryName = fi[i]._data2;
			entryName += TEXT("=>");
		}
		entryName += fi[i]._data;
		addEntry(entryName.c_str(), fi[i]._pos);
	}
}
예제 #5
0
ff::Signature ff::SignatureParser::parse(const std::string &str)
{
    string::size_type pos = 0;

    if ((pos = str.rfind("->")) == string::npos) {
        return parse1(str);
    }

    return parse2(str, pos);
}
예제 #6
0
http_method_t HttpMethod::parse( const char * pMethod )
{
    http_method_t method = parse2( pMethod );
    if ( method )
    {
        char ch= *(pMethod + getLen( method ) );
        if (( ch != ' ' )&&( ch != '\t' ))
            return 0;
    }
    return method;
}
예제 #7
0
void iterate(int size, char arr[20][20], char arr2[20][20], char lines[108][200]) {
        printf("size is %d \n", size);   

        if (size % 2 == 0) {
            printf("2->3 transform \n");    
            
            int x;
            int y;

            for (x=0;x<size/2;x++){
                for(y=0;y<size/2;y++){
                    printf("x, y = %d, %d\n", x,y);    
                    //grab a 2x2 square into "two"
                    copyfrom(20, 2, arr, x*2, y*2, a2);
                    
                    //looking for match
                    int l;
                    for (l=0; l<108; l++)
                    {
                        if (lines[l][6]=='=') {
                            parse2(lines[l],b2, b3);                            
                            if (match(2, a2, b2)==1) {                                
                                printf("match found \n");    

                                copyto(3,20, b3, arr2,x*3,y*3);
                                break;
                            }
                        }
                    }                                                        
                }
            }
            size = (size/2)*3;
        }
        else if (size % 3 == 0) {
            printf("3->4 transform \n");    
            int x;
            int y;

            for (x=0;x<size/3;x++){
                for(y=0;y<size/3;y++){
                    printf("x, y = %d, %d\n", x,y);    
                    //grab a 3x3 square into "three"
                    copyfrom(20, 3, arr, x*3, y*3, a3);

                    printf("three:\n");
                    printarr(3, a3);
                    
                    //looking for match
                    int l;
                    for (l=0; l<108; l++)
                    {
                        if (lines[l][6]!='=') {
                            parse3(lines[l],b3, b4);     

                            if (match(3, a3, b3)==1) {    
                                /*
                                printf("line > ");
                                printf(lines[l]);
                                printf("three2:\n");
                                printarr(3, b3);
                                printf("four2:\n");
                                printarr(4, b4);
                                printf("----\n\n");
                                */

                                printf("match!\n");                         
                                copyto(4,20, b4, arr2,x*4,y*4);
                                break;
                            }
                        }
                    }                                                        
                }
            }            
            size = (size/3)*4;
        }    
    return;
}
예제 #8
0
command_t
parse(arvore_vec* v)
{
  if (v->size == 0)
  {
    fprintf(stderr, "Input is empty.\n");
    exit(0);
  }

  if (DEBUG)
  {
    printf("-----------------------\n  INITIAL\n-----------------------\n");
    print_arvore_vec(v);
  }

  size_t i, j, k;
  int started = 0;

  // parse subshell
  int has_sub = 0;
  do
  {
    // find the longest subshell, skipping over any nested subshells
    size_t paren_start = 0;
    size_t paren_end = 0;
    size_t open_count = 0;
    started = 0;
    for (i = 0; i < v->size; i++)
    {
      if (v->array[i].type == TOKEN_AT)
      {
        if (v->array[i].u.tok->type == OPEN_PAREN_TOKEN)
        {
          if (!started)
          {
            started = 1;
            paren_start = i;
          }
          open_count++;
        }
        else if (v->array[i].u.tok->type == CLOSE_PAREN_TOKEN)
        {
          open_count--;
          if (started && open_count == 0)
          {
            started = 0;
            paren_end = i;
            break;
          }
        }
      }
    }

    if (open_count != 0)
      error(1, 0, "Parenthesis do not match.");

    // if there is a subshell, recursively parse the contents inside
    if (paren_end > 0)
    {
      // copy the subsequence
      arvore_vec* w;
      size_t w_len = paren_end - paren_start + 1 - 2;
      init_arvore_vec(&w, w_len);
      for (i = 0; i < w_len; i++)
        append_arvore_vec(w, v->array[paren_start + 1 + i]);

      // parse the subsequence
      command_t ss = parse(w);

      // create the subshell command and replace the original tokens
      arvore a;
      a.type = COMMAND_AT;
      a.u.cmd = (command_t) checked_malloc(sizeof(struct command));
      a.u.cmd->input = NULL;
      a.u.cmd->output = NULL;
      a.u.cmd->type = SUBSHELL_COMMAND;
      a.u.cmd->u.subshell_command = ss;
      splice_arvore_vec(v, paren_start, w_len + 2, a);

      has_sub = 1;
    }
    else
      has_sub = 0;
  }
  while (has_sub);

  if (DEBUG)
  {
    printf("-----------------------\n  SUBSHELL\n-----------------------\n");
    print_arvore_vec(v);
  }

  // parse simple commands
  size_t cmd_start = 0;
  size_t cmd_len = 0;
  started = 0;
  for (i = 0;
      i <= v->size /* iterate one past to deal with file ending on a word */;
      i++)
  {
    if (i < v->size && v->array[i].type == TOKEN_AT
        && v->array[i].u.tok->type == WORD_TOKEN)
    {
      // check it's not a IO redirect
      if (i == 0
          || (v->array[i - 1].type == TOKEN_AT
              && v->array[i - 1].u.tok->type != L_REDIR_TOKEN
              && v->array[i - 1].u.tok->type != R_REDIR_TOKEN))
      {
        if (!started)
        {
          cmd_start = i;
          started = 1;
        }
        if (started)
          cmd_len++;
      }
    }
    else if (started)
    {
      char** words = (char**) checked_malloc(sizeof(char*) * (cmd_len + 1));
      for (j = 0; j < cmd_len; j++)
        words[j] = v->array[cmd_start + j].u.tok->text;
      words[cmd_len] = NULL;

      command_t com = (command_t) checked_malloc(sizeof(struct command));
      com->input = NULL;
      com->output = NULL;
      com->type = SIMPLE_COMMAND;
      com->u.word = words;

      arvore a;
      a.type = COMMAND_AT;
      a.u.cmd = com;

      splice_arvore_vec(v, cmd_start, cmd_len, a);
      cmd_len = 0;
      i = cmd_start;
      started = 0;
    }
  }

  if (DEBUG)
  {
    printf(
        "-----------------------\n  SIMPLE COMMANDS\n-----------------------\n");
    print_arvore_vec(v);
  }

  // parse IO redirects
  for (i = 0; i < v->size; i++)
  {
    if (v->array[i].type == TOKEN_AT)
    {
      if (v->array[i].u.tok->type == L_REDIR_TOKEN
          || v->array[i].u.tok->type == R_REDIR_TOKEN)
      {
        // left side must be a command
        if (i == 0 || v->array[i - 1].type == TOKEN_AT)
        {
          //printf("----------\n fail at %u\n----------\n", (unsigned int) i);
          //print_arvore_vec(v);
          error(1, 0, "Invalid input: IO redirection in wrong place.");
          //exit(1);
        }
        // next token must be a word
        if (i + 1 >= v->size || v->array[i + 1].type != TOKEN_AT
            || v->array[i + 1].u.tok->type != WORD_TOKEN)
        {
          //printf("----------\n fail at %u\n----------\n", (unsigned int) i);
          //print_arvore_vec(v);
          error(1, 0, "Invalid input: redirect source/destination invalid.");
          //exit(1);
        }

        // store the redirect
        if (v->array[i].u.tok->type == L_REDIR_TOKEN)
          v->array[i - 1].u.cmd->input = v->array[i + 1].u.tok->text;
        else
          v->array[i - 1].u.cmd->output = v->array[i + 1].u.tok->text;

        // delete the 2 tokens consumed
        delete_arvore_vec(v, i);
        delete_arvore_vec(v, i);

        i--;
      }
    }
  }

  if (DEBUG)
  {
    printf(
        "-----------------------\n  IO REDIRECTS\n-----------------------\n");
    print_arvore_vec(v);
  }

  // parse the rest
  token_type pp = PIPE_TOKEN;
  v = parse2(v, &pp, 1);
  if (DEBUG)
  {
    printf("-----------------------\n  PIPES\n-----------------------\n");
    print_arvore_vec(v);
  }

  token_type and_n_ors[2] =
  { AND_TOKEN, OR_TOKEN };
  v = parse2(v, and_n_ors, 2);
  if (DEBUG)
  {
    printf("-----------------------\n  ANDS & ORS\n-----------------------\n");
    print_arvore_vec(v);
  }

  token_type nls_n_scs[2] =
  { NEWLINE_TOKEN, SEMICOLON_TOKEN };
  v = parse2(v, nls_n_scs, 2);
  if (DEBUG)
  {
    printf(
        "-----------------------\n  NEWLINE & SEMICOLONSs\n-----------------------\n");
    print_arvore_vec(v);
  }

  return get_arvore_vec(v, 0).u.cmd;
}
예제 #9
0
arvore_vec*
parse2(arvore_vec *cmds_tokens, token_type* target_types, size_t num_targets)
{
  size_t array_size = cmds_tokens->size;
  arvore_vec *temp;
  init_arvore_vec(&temp, array_size);
  token_type curr_token_type;

  size_t i, z, loc = array_size + 1;
  for (i = 0; i < array_size; i++)
  {
    //look for delimiter, it can be either pipes, and or or
    //once delimiter is found it splits the arvore vect into 2.
    if (cmds_tokens->array[i].type == TOKEN_AT)
    {
      token_type tp = cmds_tokens->array[i].u.tok->type;
      for (z = 0; z < num_targets; z++)
      {
        if (tp == target_types[z])
        {
          //location of first delim found
          //location of delim = i;
          loc = i;
          curr_token_type = cmds_tokens->array[i].u.tok->type;
          i = array_size;
          break;
        }
      } //end if
    }
  } //end for

  if (loc == 0)
  {
    error(1, 0, "Cannot start with a special token.");
    //exit(1);
  }

  if (loc == array_size - 1)
  {
    error(1, 0, "Cannot end with a special token.");
    //exit(1);
  }

  if (loc < array_size)
  {
    if (get_arvore_vec(cmds_tokens, loc - 1).type != COMMAND_AT)
      error(1, 0, "Left hand side not a command.");
    if (get_arvore_vec(cmds_tokens, loc + 1).type != COMMAND_AT)
      error(1, 0, "Right hand side not a command.");

    // create parent node
    command_t left = get_arvore_vec(cmds_tokens, loc - 1).u.cmd;
    command_t right = get_arvore_vec(cmds_tokens, loc + 1).u.cmd;
    command_t new_cmd = (command_t) checked_malloc(sizeof(struct command));
    new_cmd->input = NULL;
    new_cmd->output = NULL;
    if (curr_token_type == PIPE_TOKEN)
    {
      new_cmd->type = PIPE_COMMAND;
    }
    else if (curr_token_type == OR_TOKEN)
    {
      new_cmd->type = OR_COMMAND;
    }
    else if (curr_token_type == AND_TOKEN)
    {
      new_cmd->type = AND_COMMAND;
    }
    else if (curr_token_type == NEWLINE_TOKEN || curr_token_type == SEMICOLON_TOKEN)
    {
      new_cmd->type = SEQUENCE_COMMAND;
    }
    new_cmd->u.command[0] = left;
    new_cmd->u.command[1] = right;

    // copy unused arvores on the left
    size_t j;
    for (j = 0; j < loc - 1; j++)
      append_arvore_vec(temp, get_arvore_vec(cmds_tokens, j));

    // append command on left hand side
    arvore a;
    a.type = COMMAND_AT;
    a.u.cmd = new_cmd;
    append_arvore_vec(temp, a);

    // copy unused arvores on the right
    for (j = loc + 2; j < array_size; j++)
    {
      append_arvore_vec(temp, get_arvore_vec(cmds_tokens, j));
    }

    // recurse
    return parse2(temp, target_types, num_targets);
  }

  // base case: return the only command left
  return cmds_tokens;

}
예제 #10
0
파일: object.c 프로젝트: joshbressers/ularn
/*
	function to drink a potion
 */
void quaffpotion(int pot)
{
	int i,j;
	int k;

	if (pot<0 || pot>=MAXPOTION) 
		return; /* check for within bounds */

/* first character of potion name starts off as \0. */
/* drinking a certain type of potion changes that to a space */
/* ...and from then on it is printable.  */
/*	if (potionname[pot][0] == '\0')   */
/*		potionname[pot][0] = ' '; */
	if (potionknown[pot] == 0) 
	  potionknown[pot] = 1;
	lprintf("\nYou drink a potion of %s.", &potionname[pot][1]);

	switch(pot) {
	case PSLEEP:
		lprcat("  You fall asleep...");
		lflush();
		i=rnd(11)-(c[CONSTITUTION]>>2)+2;
		while(--i>0) {
			parse2();
			nap(1000);
		}
		cursors();
		lprcat("\n.. you wake up.");
		return;

	case PHEALING:
		lprcat("  You feel better.");
		if (c[HP] == c[HPMAX])
			raisemhp(1);
		else if ((c[HP] += rnd(20)+20+c[LEVEL]) > c[HPMAX])
			c[HP]=c[HPMAX];
		break;

	case PRAISELEVEL:
		lprcat("  You feel much more skillful!");
		raiselevel();
		raisemhp(1);
		return;

	case PINCABILITY:
		lprcat("  You feel strange for a moment.");
		c[rund(6)]++;
		break;

	case PWISDOM:
		lprcat("  You feel more self-confident!");
		c[WISDOM] += rnd(2);
		break;

	case PSTRENGTH:
		lprcat("  Wow!  You feel great!");
		if (c[STRENGTH]<12) c[STRENGTH]=12;
		else c[STRENGTH]++;
		break;

	case PCHARISMA:
		lprcat("  You feel charismatic!");
		c[CHARISMA]++;
		break;

	case PDIZZINESS:
		lprcat("  You become dizzy!");
		if (--c[STRENGTH] < 3) c[STRENGTH]=3;
		break;

	case PLEARNING:
		lprcat("  You feel clever!");
		c[INTELLIGENCE]++;
		break;

	case PGOLDDET:
		lprcat("  You feel greedy...");
		lflush();
		nap(2000);
		for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
			if ((item[j][i]==OGOLDPILE) || (item[j][i]==OMAXGOLD)) {
				know[j][i]=1; 
				show1cell(j,i);
			}
		showplayer();
		return;

	case PMONSTDET:
		for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
			if (mitem[j][i].mon) {
				know[j][i]=1; 
				show1cell(j,i);
			}
		return;

	case PFORGETFUL:
		lprcat("  You stagger for a moment...");
		lflush();
		for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
			know[j][i]=0;
		nap(2000);	
		draws(0,MAXX,0,MAXY);
		return;

	case PWATER:
		return;

	case PBLINDNESS:
		lprcat("  You can't see anything!"); 
		c[BLINDCOUNT]+=500;  /* dang, that's a long time. */
		/* erase the character, too! */
		cursor(playerx+1,playery+1);
		lprc(' ');
		cursor(playerx+1,playery+1);
		return;

	case PCONFUSION:
		lprcat("  You feel confused.");
		c[CONFUSE]+= 20+rnd(9); 
		return;

	case PHEROISM:
		lprcat("  WOW!  You feel fantastic!");
		if (c[HERO]==0) for (i=0; i<6; i++) c[i] += 11;
		c[HERO] += 250;  
		break;

	case PSTURDINESS:
		lprcat("  You feel healthier!");
		c[CONSTITUTION]++;  
		break;

	case PGIANTSTR:
		lprcat("  You now have incredible bulging muscles!");
		if (c[GIANTSTR]==0) c[STREXTRA] += 21;
		c[GIANTSTR] += 700;  
		break;

	case PFIRERESIST:
		lprcat("  You feel a chill run up your spine!");
		c[FIRERESISTANCE] += 1000;  
		break;

	case PTREASURE:
		lprcat("  You feel greedy...");
		lflush();
		nap(2000);
		for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) {
			k=item[j][i];
			if ((k==ODIAMOND) || (k==ORUBY) || (k==OEMERALD) 
		 	    || (k==OMAXGOLD) || (k==OSAPPHIRE) 
			    || (k==OLARNEYE) || (k==OGOLDPILE)) {
				know[j][i]=1; 
				show1cell(j,i);
			}
		}
		showplayer();  
		return;

	case PINSTHEAL:
		c[HP] = c[HPMAX]; 
		removecurse();
		break;

	case PCUREDIANTH:
		lprcat("  You don't seem to be affected.");
		return;

	case PPOISON:
		lprcat("  You feel a sickness engulf you!");
		c[HALFDAM] += 200 + rnd(200);  
		return;

	case PSEEINVIS:
		lprcat("  You feel your vision sharpen.");
		c[SEEINVISIBLE] += rnd(1000)+400;
		monstnamelist[INVISIBLESTALKER] = 'I';  
		return;
	};
	/*	show new stats		*/
	bottomline();		
	return;
}