예제 #1
0
void rever_word(char *str) 
{
	int start = 0;
	int end = 0;
	while (str[++end] != '\0')
		;
	while(my_isspace(str[--end]))
		;
	rever_str(str, 0, end);
	str[end + 1] = '\0';

	int word = 0;
	end =0;
	while (str[end] != '\0') {
		if (my_isspace(str[end])) {
			if (word == 1) {
				word = 0;
				rever_str(str, start, end - 1);
			}
		} else if (word == 0){
				word = 1;
				start = end;
			}
		end++;
	}
	puts(str);
}
예제 #2
0
/* First word is always numbered zero. */
extern char	*BX_move_to_abs_word (const register char *start, char **mark, int word)
{
	register char *pointer = (char *)start;
	register int counter = word;

	/* This fixes a bug that counted leading spaces as
	 * a word, when theyre really not a word.... 
	 * (found by Genesis K.)
	 *
	 * The stock client strips leading spaces on both
	 * the cases $0 and $-0.  I personally think this
	 * is not the best choice, but im not going to stick
	 * my foot in this one... im just going to go with
	 * what the stock client does...
	 */
	 while (pointer && *pointer && my_isspace(*pointer))
		pointer++;

	for (;counter > 0 && *pointer;counter--)
	{
		while (*pointer && !my_isspace(*pointer))
			pointer++;
		while (*pointer && my_isspace(*pointer))
			pointer++;
	}

	if (mark)
		*mark = pointer;
	return pointer;
}
예제 #3
0
/********************************************************************** 
  ...
***********************************************************************/
static const char *get_token_entry_name(struct inputfile *inf)
{
  char *c, *start, *end;
  
  assert(have_line(inf));

  c = inf->cur_line.str + inf->cur_line_pos;
  while(*c != '\0' && my_isspace(*c)) {
    c++;
  }
  if (*c == '\0')
    return NULL;
  start = c;
  while (*c != '\0' && !my_isspace(*c) && *c != '=' && !is_comment(*c)) {
    c++;
  }
  if (!(*c != '\0' && (my_isspace(*c) || *c == '='))) 
    return NULL;
  end = c;
  while (*c != '\0' && *c != '=' && !is_comment(*c)) {
    c++;
  }
  if (*c != '=') {
    return NULL;
  }
  *end = '\0';
  inf->cur_line_pos = c + 1 - inf->cur_line.str;
  astr_minsize(&inf->token, strlen(start)+1);
  strcpy(inf->token.str, start);
  return inf->token.str;
}
예제 #4
0
void sort_str(const char *str)
{
	char ar[100][100];
	int index = 0;
	int word = 0;
	int start = 0;
	int end = 0;
	while (str[end] != '\0') {
		if (my_isspace(str[end])) {
			if (word == 1) {
				word = 0;
				str_ncpy(ar[index], str, start, end - 1);
				index++;
			}
		} else if (word == 0){
				word = 1;
				start = end;
			}
		end++;
	}
	if (!my_isspace(--end)) {
		str_ncpy(ar[index++], str, start, end);
	}
	sort_word(ar, index);
	print_word(ar, index);
}
예제 #5
0
static char *get_argument(const char *keyword, size_t kwlen,
                          char *ptr, char *name, uint line)
{
  char *end;

  /* Skip over "include / includedir keyword" and following whitespace */

  for (ptr+= kwlen - 1;
       my_isspace(&my_charset_latin1, ptr[0]);
       ptr++)
  {}

  /*
    Trim trailing whitespace from directory name
    The -1 below is for the newline added by fgets()
    Note that my_isspace() is true for \r and \n
  */
  for (end= ptr + strlen(ptr) - 1;
       my_isspace(&my_charset_latin1, *(end - 1));
       end--)
  {}
  end[0]= 0;                                    /* Cut off end space */

  /* Print error msg if there is nothing after !include* directive */
  if (end <= ptr)
  {
    fprintf(stderr,
	    "error: Wrong '!%s' directive in config file: %s at line %d\n",
	    keyword, name, line);
    return 0;
  }
  return ptr;
}
예제 #6
0
Statement *ParseAsmStatement() 
{
	static char buf[3501];
	int nn;

	Statement *snp; 
    snp = NewStatement(st_asm, FALSE); 
    while( my_isspace(lastch) )
		getch(); 
    NextToken();
    if (lastst == kw_leafs) {
    	currentFn->IsLeaf = FALSE;
	    while( my_isspace(lastch) )
			getch(); 
    	NextToken();
	}
	if (lastst != begin)
		error(ERR_PUNCT);
	nn = 0;
	do {
		getch();
		if (lastch=='}')
			break;
		buf[nn++] = lastch;
	}
	while(lastch!=-1 && nn < 3500);
	if (nn >= 3500)
		error(ERR_ASMTOOLONG);
	buf[nn] = '\0';
	snp->label = (int64_t *)my_strdup(buf);
    return snp;
} 
예제 #7
0
파일: input.c 프로젝트: Nicholas-S/xaric
/*
 * input_forward_word: move the input cursor forward one word in the input
 * line 
 */
void input_forward_word(char unused, char *not_used)
{
    cursor_to_input();

    while ((my_isspace(THIS_CHAR) || ispunct(THIS_CHAR)) && (THIS_CHAR))
	THIS_POS++;
    while (!(ispunct(THIS_CHAR) || my_isspace(THIS_CHAR)) && (THIS_CHAR))
	THIS_POS++;
    update_input(UPDATE_JUST_CURSOR);
}
예제 #8
0
파일: input.c 프로젝트: Nicholas-S/xaric
/* input_backward_word: move the cursor left on word in the input line */
void input_backward_word(char unused, char *not_used)
{
    cursor_to_input();
    while ((THIS_POS > MIN_POS) && (my_isspace(PREV_CHAR) || ispunct(PREV_CHAR)))
	THIS_POS--;
    while ((THIS_POS > MIN_POS) && !(ispunct(PREV_CHAR) || my_isspace(PREV_CHAR)))
	THIS_POS--;

    update_input(UPDATE_JUST_CURSOR);
}
예제 #9
0
void execute(const char *cmdline, enum kernel_type type)
{
  com32sys_t ireg;
  const char *p, * const *pp;
  char *q = __com32.cs_bounce;
  const char *kernel, *args;

  memset(&ireg, 0, sizeof ireg);

  kernel = q;
  p = cmdline;
  while ( *p && !my_isspace(*p) ) {
    *q++ = *p++;
  }
  *q++ = '\0';

  args = q;
  while ( *p && my_isspace(*p) )
    p++;

  strcpy(q, p);

  if (kernel[0] == '.' && type == KT_NONE) {
    /* It might be a type specifier */
    enum kernel_type type = KT_NONE;
    for (pp = kernel_types; *pp; pp++, type++) {
      if (!strcmp(kernel+1, *pp)) {
	execute(p, type);	/* Strip the type specifier and retry */
      }
    }
  }

  if (type == KT_LOCALBOOT) {
    ireg.eax.w[0] = 0x0014;	/* Local boot */
    ireg.edx.w[0] = strtoul(kernel, NULL, 0);
  } else {
    if (type < KT_KERNEL)
      type = KT_KERNEL;

    ireg.eax.w[0] = 0x0016;	/* Run kernel image */
    ireg.esi.w[0] = OFFS(kernel);
    ireg.ds       = SEG(kernel);
    ireg.ebx.w[0] = OFFS(args);
    ireg.es       = SEG(args);
    ireg.edx.l    = type-KT_KERNEL;
    /* ireg.ecx.l    = 0; */		/* We do ipappend "manually" */
  }

  __intcall(0x22, &ireg, NULL);

  /* If this returns, something went bad; return to menu */
}
예제 #10
0
Statement *ParseAsmStatement() 
{
	static char buf[3501];
	int nn;
	bool first = true;

	Statement *snp; 
    snp = NewStatement(st_asm, FALSE); 
    while( my_isspace(lastch) )
		getch(); 
    NextToken();
    if (lastst == kw_leafs) {
    	currentFn->IsLeaf = FALSE;
	    while( my_isspace(lastch) )
			getch(); 
    	NextToken();
	}
	if (lastst != begin)
		error(ERR_PUNCT);
	nn = 0;
	do {
		// skip over leading spaces on the line
		getch();
		while (isspace(lastch)) getch();
		if (lastch=='}')
			break;
		if (lastch=='\r' || lastch=='\n')
			continue;
		if (nn < 3500) buf[nn++] = '\n';
		if (nn < 3500) buf[nn++] = '\t';
		if (nn < 3500) buf[nn++] = '\t';
		if (nn < 3500) buf[nn++] = '\t';
		if (nn < 3500) buf[nn++] = lastch;
		while(lastch != '\n') {
			getch();
			if (lastch=='}')
				goto j1;
			if (lastch=='\r' || lastch=='\n')
				break;
			if (nn < 3500) buf[nn++] = lastch;
		}
	}
	while(lastch!=-1 && nn < 3500);
j1:
	if (nn >= 3500)
		error(ERR_ASMTOOLONG);
	buf[nn] = '\0';
	snp->label = (int *)my_strdup(buf);
    return snp;
} 
예제 #11
0
char            *my_strtrim(char *s)
{
  size_t        i;
  size_t        j;
  int           space;

  if (!s)
    return (NULL);
  i = 0;
  j = 0;
  space = 1;
  while (s[i] != '\0')
    {
      if (my_isspace(s[i]) == 0)
        {
          if (j > 0 && space == 1)
            s[j++] = ' ';
          space = 0;
          s[j] = s[i];
          j++;
        }
      else
        space = 1;
      i++;
    }
  my_bzero((s + j), i - j);
  return (s);
}
예제 #12
0
/**
 * Converts (only) the initial portion of 'str' to an integer.
 *
 * Implement my_atoi(str) as follows:
 * (1) Increment str to skip all white-space characters as defined by 
 * my_isspace(...)
 * (2) If there is a '-' sign, note that 'str' is a negative number, and 
 * increment str past the minus sign.
 * (3) Initialize a return value "ret" to 0. (int ret = 0)
 * (4) While '0' <= *str <= '9':
 *     (4.a) Multiply ret by 10
 *     (4.b) Add (*str - '0') to ret
 *     (4.c) Increment str
 * (5) If there was a minus sign, return -ret. Otherwise return ret.
 *
 * Examples:
 * my_atoi("0"); // 0
 * my_atoi("-12"); // -12
 * my_atoi("15th of March would be the ides."); // 15
 * my_atoi("4 months to Summer."); // 4
 * my_atoi("\n\f\t\v\r 6 white space characters handled correctly."); // 6
 * my_atoi("garbage, instead of a number like 73 for example, should yield a zero"); // 0
 */
int my_atoi(const char * str)
{
	int ret = 0;
	int sign = 1;
	int i = 0;
	

	while(my_isspace(str[i]))
	{
		
		i++;
	}
	if(str[i] == '-')
	{
		sign = -1;
		i++;
	}
	if ('0'<=str[i] && str[i]<='9')
	{
		for(;'0'<=str[i] && str[i]<='9';i++)
		{
          ret = ret* 10;
          ret = ret+(str[i] - 48);//the ascii code for '0' is 48

		}
		ret = sign * ret;
		return ret;
	}
	else
	{
		return 0;
	}
}
예제 #13
0
SEQFLOW ctxscan(const CHARSET_INFO *cs, char *src, char *src_end, my_wc_t *dst, int *readsize, int context){
    *readsize = cs->cset->mb_wc(cs, dst, (uchar*)src, (uchar*)src_end);
    if(*readsize <= 0){
      return SF_BROKEN; // break;
    }
    
    if(!(context & CTX_ESCAPE)){
        if(*dst=='\\') return SF_ESCAPE;
        if(context & CTX_QUOTE){
            if(*dst=='"') return SF_QUOTE_END;
            return SF_CHAR;
        }
        if(*dst=='"') return SF_QUOTE_START;
        if(*dst=='(') return SF_LEFT_PAREN;
        if(*dst==')') return SF_RIGHT_PAREN;
        if(my_isspace(cs, *src)) return SF_WHITE;
        
        if(context & CTX_CONTROL){
            if(*dst=='+') return SF_PLUS;
            if(*dst=='-') return SF_MINUS;
            if(*dst=='>') return SF_WEAK;
            if(*dst=='<') return SF_STRONG;
            if(*dst=='~') return SF_WASIGN;
        }else{
            if(*dst=='*') return SF_TRUNC;
        }
    }
    return SF_CHAR;
}
예제 #14
0
파일: reginit.c 프로젝트: 0x00xw/mysql-2
void my_regex_init(CHARSET_INFO *cs, my_regex_stack_check_t func)
{
  char buff[CCLASS_LAST][256];
  int  count[CCLASS_LAST];
  uint i;

  if (!regex_inited)
  {
    regex_inited=1;
    my_regex_enough_mem_in_stack= func;
    bzero((uchar*) &count,sizeof(count));

    for (i=1 ; i<= 255; i++)
    {
      if (my_isalnum(cs,i))
	buff[CCLASS_ALNUM][count[CCLASS_ALNUM]++]=(char) i;
      if (my_isalpha(cs,i))
	buff[CCLASS_ALPHA][count[CCLASS_ALPHA]++]=(char) i;
      if (my_iscntrl(cs,i))
	buff[CCLASS_CNTRL][count[CCLASS_CNTRL]++]=(char) i;
      if (my_isdigit(cs,i))
	buff[CCLASS_DIGIT][count[CCLASS_DIGIT]++]=(char) i;
      if (my_isgraph(cs,i))
	buff[CCLASS_GRAPH][count[CCLASS_GRAPH]++]=(char) i;
      if (my_islower(cs,i))
	buff[CCLASS_LOWER][count[CCLASS_LOWER]++]=(char) i;
      if (my_isprint(cs,i))
	buff[CCLASS_PRINT][count[CCLASS_PRINT]++]=(char) i;
      if (my_ispunct(cs,i))
	buff[CCLASS_PUNCT][count[CCLASS_PUNCT]++]=(char) i;
      if (my_isspace(cs,i))
	buff[CCLASS_SPACE][count[CCLASS_SPACE]++]=(char) i;
      if (my_isupper(cs,i))
	buff[CCLASS_UPPER][count[CCLASS_UPPER]++]=(char) i;
      if (my_isxdigit(cs,i))
	buff[CCLASS_XDIGIT][count[CCLASS_XDIGIT]++]=(char) i;
    }
    buff[CCLASS_BLANK][0]=' ';
    buff[CCLASS_BLANK][1]='\t';
    count[CCLASS_BLANK]=2;
    for (i=0; i < CCLASS_LAST ; i++)
    {
      char *tmp=(char*) malloc(count[i]+1);
      if (!tmp)
      {
	/*
	  This is very unlikely to happen as this function is called once
	  at program startup
	*/
	fprintf(stderr,
		"Fatal error: Can't allocate memory in regex_init\n");
	exit(1);
      }
      memcpy(tmp,buff[i],count[i]*sizeof(char));
      tmp[count[i]]=0;
      cclasses[i].chars=tmp;
    }
  }
  return;
}
예제 #15
0
파일: 27.c 프로젝트: ajaysusarla/learning
long my_strtol(const char *str)
{
        char *p = (char *) str;
        long res = 0;
        int sign = 0, temp = 0;

        while (my_isspace(*p)) {
                p++;
        }

        if (*p == '-') {
                sign = 1;
                p++;
        } else if (*p == '+') {
                sign = 0;
                p++;
        }

        while (*p) {
                if (my_isnum(*p)) {
                        temp = *p - '0';
                        res = res*10 + temp;
                        p++;
                } else {
                        res = -999999;
                        break;
                }
        }

        if (sign)
                res = -res;

        return res;
}
예제 #16
0
파일: answer02.c 프로젝트: bsarkar16/ECE264
/**
 * Convert the initial portion of 'str' to an integer.
 *
 * Implement my_atoi(str) as follows:
 * (1) Increment str to skip all white-space characters as defined by 
 * my_isspace(...)
 * (2) If there is a '-' sign, note that 'str' is a negative number, and 
 * increment str past the minus sign.
 * (3) Initialize a return value "ret" to 0. (int ret = 0)
 * (4) While '0' <= *str <= '9':
 *     (4.a) Multiply ret by 10
 *     (4.b) Add (*str - '0') to ret
 *     (4.c) Increment str
 * (5) If there was a minus sign, return -ret. Otherwise return ret.
 *
 * Examples:
 * my_atoi("0"); // 0
 * my_atoi("-12"); // -12
 * my_atoi("15th of March would be the ides."); // 15
 * my_atoi("4 months to Summer."); // 4
 * my_atoi("\n\f\t\v\r 6 white space characters handled correctly."); // 6
 * my_atoi("garbage should yield 0"); // 0
 */
int my_atoi(const char * str)
{
	int ret = 0;
	int len = 0;
	int iter = 0;
	len = my_strlen(str);
	int pos = 0;
	for(iter = 0;iter <= len;iter++)
	{
		if(my_isspace(str[iter]))
		{
			continue;
		}
		if(str[iter] == '-')
		{
			pos = -1;
			continue;
		}
		while(str[iter] >= '0' && str[iter] <= '9')
		{
			ret *= 10;
			ret += (str[iter] - '0');
			iter++;
		}
		break;
	}
	if(pos == -1)
		ret = -ret;
	return ret;
}
예제 #17
0
static my_bool init_state_maps(CHARSET_INFO *cs)
{
  uint i;
  uchar *state_map;
  uchar *ident_map;

  if (!(cs->state_map= state_map= (uchar*) my_once_alloc(256, MYF(MY_WME))))
    return 1;

  if (!(cs->ident_map= ident_map= (uchar*) my_once_alloc(256, MYF(MY_WME))))
    return 1;

  /* Fill state_map with states to get a faster parser */
  for (i=0; i < 256 ; i++)
  {
    if (my_isalpha(cs,i))
      state_map[i]=(uchar) MY_LEX_IDENT;
    else if (my_isdigit(cs,i))
      state_map[i]=(uchar) MY_LEX_NUMBER_IDENT;
    else if (my_ismb1st(cs, i))
      /* To get whether it's a possible leading byte for a charset. */
      state_map[i]=(uchar) MY_LEX_IDENT;
    else if (my_isspace(cs,i))
      state_map[i]=(uchar) MY_LEX_SKIP;
    else
      state_map[i]=(uchar) MY_LEX_CHAR;
  }
  state_map[(uchar)'_']=state_map[(uchar)'$']=(uchar) MY_LEX_IDENT;
  state_map[(uchar)'\'']=(uchar) MY_LEX_STRING;
  state_map[(uchar)'.']=(uchar) MY_LEX_REAL_OR_POINT;
  state_map[(uchar)'>']=state_map[(uchar)'=']=state_map[(uchar)'!']= (uchar) MY_LEX_CMP_OP;
  state_map[(uchar)'<']= (uchar) MY_LEX_LONG_CMP_OP;
  state_map[(uchar)'&']=state_map[(uchar)'|']=(uchar) MY_LEX_BOOL;
  state_map[(uchar)'#']=(uchar) MY_LEX_COMMENT;
  state_map[(uchar)';']=(uchar) MY_LEX_SEMICOLON;
  state_map[(uchar)':']=(uchar) MY_LEX_SET_VAR;
  state_map[0]=(uchar) MY_LEX_EOL;
  state_map[(uchar)'\\']= (uchar) MY_LEX_ESCAPE;
  state_map[(uchar)'/']= (uchar) MY_LEX_LONG_COMMENT;
  state_map[(uchar)'*']= (uchar) MY_LEX_END_LONG_COMMENT;
  state_map[(uchar)'@']= (uchar) MY_LEX_USER_END;
  state_map[(uchar) '`']= (uchar) MY_LEX_USER_VARIABLE_DELIMITER;
  state_map[(uchar)'"']= (uchar) MY_LEX_STRING_OR_DELIMITER;

  /*
    Create a second map to make it faster to find identifiers
  */
  for (i=0; i < 256 ; i++)
  {
    ident_map[i]= (uchar) (state_map[i] == MY_LEX_IDENT ||
			   state_map[i] == MY_LEX_NUMBER_IDENT);
  }

  /* Special handling of hex and binary strings */
  state_map[(uchar)'x']= state_map[(uchar)'X']= (uchar) MY_LEX_IDENT_OR_HEX;
  state_map[(uchar)'b']= state_map[(uchar)'B']= (uchar) MY_LEX_IDENT_OR_BIN;
  state_map[(uchar)'n']= state_map[(uchar)'N']= (uchar) MY_LEX_IDENT_OR_NCHAR;

  return 0;
}
예제 #18
0
파일: util.c 프로젝트: Oxyoptia/x3270
/*
 * List resource splitter, for lists of elements speparated by newlines.
 *
 * Can be called iteratively.
 * Returns 1 for success, 0 for EOF, -1 for error.
 */
int
split_lresource(char **st, char **value)
{
    char *s = *st;
    char *t;
    bool quote;

    /* Skip leading white space. */
    while (my_isspace(*s)) {
	s++;
    }

    /* If nothing left, EOF. */
    if (!*s) {
	return 0;
    }

    /* Save starting point. */
    *value = s;

    /* Scan until an unquoted newline is found. */
    quote = false;
    for (; *s; s++) {
	if (*s == '\\' && *(s+1) == '"') {
	    s++;
	} else if (*s == '"') {
	    quote = !quote;
	} else if (!quote && *s == '\n') {
	    break;
	}
    }

    /* Strip white space before the newline. */
    if (*s) {
	t = s;
	*st = s+1;
    } else {
	t = s-1;
	*st = s;
    }
    while (my_isspace(*t)) {
	*t-- = '\0';
    }

    /* Done. */
    return 1;
}
예제 #19
0
파일: util.c 프로젝트: Oxyoptia/x3270
/*
 * Whitespace stripper.
 */
char *
strip_whitespace(const char *s)
{
    char *t = NewString(s);

    while (*t && my_isspace(*t)) {
	t++;
    }
    if (*t) {
	char *u = t + strlen(t) - 1;

	while (my_isspace(*u)) {
	    *u-- = '\0';
	}
    }
    return t;
}
예제 #20
0
파일: input.c 프로젝트: Nicholas-S/xaric
/*
 * input_delete_previous_word: deletes from the cursor backwards to the next
 * space character. 
 */
void input_delete_previous_word(char unused, char *not_used)
{
    int old_pos;
    char c;

    cursor_to_input();
    old_pos = THIS_POS;
    while ((THIS_POS > MIN_POS) && (my_isspace(PREV_CHAR) || ispunct(PREV_CHAR)))
	THIS_POS--;
    while ((THIS_POS > MIN_POS) && !(ispunct(PREV_CHAR) || my_isspace(PREV_CHAR)))
	THIS_POS--;
    c = INPUT_BUFFER[old_pos];
    INPUT_BUFFER[old_pos] = (char) 0;
    malloc_strcpy(&cut_buffer, &THIS_CHAR);
    INPUT_BUFFER[old_pos] = c;
    strcpy(&(THIS_CHAR), &(INPUT_BUFFER[old_pos]));
    update_input(UPDATE_FROM_CURSOR);
}
예제 #21
0
static int get_date_time_separator(uint *number_of_fields, ulonglong flags,
                                   const char **str, const char *end)
{
  const char *s= *str;
  if (s >= end)
    return 0;

  if (*s == 'T')
  {
    (*str)++;
    return 0;
  }

  /*
    now, this is tricky, for backward compatibility reasons.
    cast("11:11:11.12.12.12" as datetime) should give 2011-11-11 12:12:12
    but
    cast("11:11:11.12.12.12" as time) should give 11:11:11.12
    that is, a punctuation character can be accepted as a date/time separator
    only if TIME_DATETIME_ONLY (see str_to_time) is not set.
  */
  if (my_ispunct(&my_charset_latin1, *s))
  {
    if (flags & TIME_DATETIME_ONLY)
    {
      /* see above, returning 1 is not enough, we need hard abort here */
      *number_of_fields= 0;
      return 1;
    }

    (*str)++;
    return 0;
  }

  if (!my_isspace(&my_charset_latin1, *s))
    return 1;

  do
  {
    s++;
  } while (my_isspace(&my_charset_latin1, *s));
  *str= s;
  return 0;
}
예제 #22
0
파일: my_init.c 프로젝트: A-eolus/mysql
static ulong atoi_octal(const char *str)
{
  long int tmp;
  while (*str && my_isspace(&my_charset_latin1, *str))
    str++;
  str2int(str,
	  (*str == '0' ? 8 : 10),       /* Octalt or decimalt */
	  0, INT_MAX, &tmp);
  return (ulong) tmp;
}
예제 #23
0
/* Move a relative number of words from the present mark */
extern char	*BX_move_word_rel (const register char *start, char **mark, int word)
{
	register char *pointer = *mark;
	register int counter = word;
	char *end = (char *)start + strlen((char *)start);

	if (end == start) 	/* null string, return it */
		return (char *)start;

	/* 
	 * XXXX - this is utterly pointless at best, and
	 * totaly wrong at worst.
 	 */

	if (counter > 0)
	{
		for (;counter > 0 && pointer;counter--)
		{
			while (*pointer && !my_isspace(*pointer))
				pointer++;
			while (*pointer && my_isspace(*pointer)) 
				pointer++;
		}
	}
	else if (counter == 0)
		pointer = *mark;
	else /* counter < 0 */
	{
		for (;counter < 0 && pointer > start;counter++)
		{
			while (pointer >= start && my_isspace(*pointer))
				pointer--;
			while (pointer >= start && !my_isspace(*pointer))
				pointer--;
		}
		pointer++; /* bump up to the word we just passed */
	}

	if (mark)
		*mark = pointer;
	return pointer;
}
예제 #24
0
파일: input.c 프로젝트: Nicholas-S/xaric
/*
 * input_delete_next_word: deletes from the cursor to the end of the next
 * word 
 */
void input_delete_next_word(char unused, char *not_used)
{
    int pos;
    char *ptr = NULL, c;

    cursor_to_input();
    pos = THIS_POS;
    while ((my_isspace(INPUT_BUFFER[pos]) || ispunct(INPUT_BUFFER[pos])) && INPUT_BUFFER[pos])
	pos++;
    while (!(ispunct(INPUT_BUFFER[pos]) || my_isspace(INPUT_BUFFER[pos])) && INPUT_BUFFER[pos])
	pos++;
    c = INPUT_BUFFER[pos];
    INPUT_BUFFER[pos] = (char) 0;
    malloc_strcpy(&cut_buffer, &(THIS_CHAR));
    INPUT_BUFFER[pos] = c;
    malloc_strcpy(&ptr, &(INPUT_BUFFER[pos]));
    strcpy(&(THIS_CHAR), ptr);
    new_free(&ptr);
    update_input(UPDATE_FROM_CURSOR);
}
예제 #25
0
파일: srtm4.c 프로젝트: cpalmann/s2p
// this function is like regular strtok, but faster
// the delimiter list is, implicitly, spaces
static char *my_strtok(char *str)
{
	static char *next; // points to the remaining part of the string
	char *begin = str ? str : next, *s = begin;
	if (!*s)
		return NULL;
	while (*s && !my_isspace(*s))
		s++;
	if (!*s)
		return begin;
	assert(my_isspace(*s));
	while(*s && my_isspace(*s))
		s++;
	if (!*s)
		return begin;
	assert(!my_isspace(*s));
	s--;
	*s = '\0';
	next = s + 1;
	return begin;
}
예제 #26
0
파일: words.c 프로젝트: jnbek/TekNap
/* 
 * Move to an absolute word number from start
 * First word is always numbered zero.
 */
const char *	real_move_to_abs_word (const char *start, const char **mark, int word, int extended)
{
	const char *	pointer = start;
	int 		counter = word;

	CHECK_EXTENDED_SUPPORT

	/* 
	 * This fixes a bug that counted leading spaces as
	 * a word, when theyre really not a word.... 
	 * (found by Genesis K.)
	 */
	while (*pointer && my_isspace(*pointer))
		pointer++;

	for (;counter > 0 && *pointer;counter--)
	{
		if (extended && *pointer == '"')
		{
			const char *	after;

			if (!(after = find_forward_quote(pointer, start)))
				nappanic("find_forward returned NULL [1]");
			if (*after)
				after++;
			pointer = after;
		}
		else
			while (*pointer && !my_isspace(*pointer))
				pointer++;

		while (*pointer && my_isspace(*pointer))
			pointer++;
	}

	if (mark)
		*mark = pointer;
	return pointer;
}
예제 #27
0
void str_replace(char *str, const char *rpl)
{
	int index = 0;
	int space_cnt = 0;
	while (str[index] != '\0') {
		if (my_isspace(str[index])) {
			space_cnt++;
		}
		index++;
	}
	int end = index + 3 * space_cnt;
	str[end + 1] = '\0';
	while (index >= 0 && end >= 0) {
		if (my_isspace(str[index])) {
			for (int i = 3; i >= 0; i--) {
				str[end--] = rpl[i];
			}
		} else {
			str[end--] = str[index];
		}
		index--;
	}
}
예제 #28
0
int word_cnt(char *str) 
{
	int word = 0;
	int cnt = 0;
	while (*str != '\0') {
		if (my_isspace(*str)) {
			word = 0;
		} else if (word == 0) {
			cnt++;
			word = 1;
		}
		str++;
	}
	return cnt;
}
예제 #29
0
/****************************************************************************
  Replace the spaces by line breaks when the line lenght is over the desired
  one.
****************************************************************************/
void astr_cut_lines(struct astring *astr, size_t desired_len)
{
  char *c;
  size_t n = 0;

  for (c = astr->str; '\0' != *c; c++) {
    if ('\n' == *c) {
      n = 0;
    } else if (my_isspace(*c) && n >= desired_len) {
      *c = '\n';
      n = 0;
    } else {
      n++;
    }
  }
}
예제 #30
0
/********************************************************************** 
  Get a flag token of a single character, with optional
  preceeding whitespace.
***********************************************************************/
static const char *get_token_white_char(struct inputfile *inf,
					char target)
{
  char *c;
  
  assert(have_line(inf));

  c = inf->cur_line.str + inf->cur_line_pos;
  while(*c != '\0' && my_isspace(*c)) {
    c++;
  }
  if (*c != target)
    return NULL;
  inf->cur_line_pos = c + 1 - inf->cur_line.str;
  assign_flag_token(&inf->token, target);
  return inf->token.str;
}