Esempio n. 1
0
static void
render_tone (PangoFont *font, gunichar tone, PangoGlyphString *glyphs,
             int *n_glyphs, int cluster_offset)
{
  int index;

  index = find_char (font, tone);
  pango_glyph_string_set_size (glyphs, *n_glyphs + 1);
  if (index)
    {
      set_glyph_tone (font, glyphs, *n_glyphs, cluster_offset, index);
    }
  else 
    {
      /* fall back : HTONE1(0x302e) => middle-dot, HTONE2(0x302f) => colon */
      index = find_char (font, tone == HTONE1 ? 0x00b7 : 0x003a);
      if (index)
        {
          set_glyph_tone (font, glyphs, *n_glyphs, cluster_offset, index);
        }
      else 
        set_glyph (font, glyphs, *n_glyphs, cluster_offset,
		   get_unknown_glyph (font, tone));
    }
  (*n_glyphs)++;
}
Esempio n. 2
0
main(){
   char *source = "ABCDEFG";
   char *s1 = "XYZ";
   char *s2 = "JURY";
   char *s3 = "QQQQ";
   char *s4 = "XRCQEF";
   char *result;

   if((result = find_char(source, s1)) == NULL) {
       printf("Given %s %s Returned NULL\n", source, s1);
   } else {
       printf("Given %s %s Returned %c\n", source, s1, *result);
   }

   if((result = find_char(source, s2)) == NULL) {
       printf("Given %s %s Returned NULL\n", source, s2);
   } else {
       printf("Given %s %s Returned %c\n", source, s2, *result);
   }

   if((result = find_char(source, s3)) == NULL) {
       printf("Given %s %s Returned NULL\n", source, s3);
   } else {
       printf("Given %s %s Returned %c\n", source, s3, *result);
   }

   if((result = find_char(source, s4)) == NULL) {
       printf("Given %s %s Returned NULL\n", source, s4);
   } else {
       printf("Given %s %s Returned %c\n", source, s4, *result);
   }
}
Esempio n. 3
0
/**
* Cut spaces (or other char) from left/right of the string
*/
p2String& p2String::trim(int left, int right, char ch)
{
	if(string != NULL)
	{
		unsigned int  pos_left = find_char(ch, 0);
		unsigned int  pos_right = find_char(ch, 1);

		if(left)
		{
			if(pos_left > 0)
			{
				memcpy(string, &string[pos_left], size - pos_left);
				string[size - pos_left] = 0;
			}
		}

		if(right)
		{
			if(pos_right < size - 1)
			{
				string[pos_right - pos_left + 1] = '\0';
			}
		}

		update();
	}

	return(*this);
}
Esempio n. 4
0
/* This is a fallback for when we get a tone mark not preceded
 * by a syllable.
 */
static void
render_isolated_tone (PangoFont *font, gunichar tone, PangoGlyphString *glyphs,
		      int *n_glyphs, int cluster_offset)
{
#if 0 /* FIXME: what kind of hack is it?  it draws dummy glyphs.  */
  /* Find a base character to render the mark on
   */
  int index = find_char (font, 0x25cc);	/* DOTTED CIRCLE */
  if (!index)
    index = find_char (font, 0x25cb);   /* WHITE CIRCLE, in KSC-5601 */
  if (!index)
    index = find_char (font, ' ');      /* Space */
  if (!index)				/* Unknown glyph box with 0000 in it */
    index = find_char (font, PANGO_GET_UNKNOWN_GLYPH (0));

  /* Add the base character
   */
  pango_glyph_string_set_size (glyphs, *n_glyphs + 1);
  set_glyph (font, glyphs, *n_glyphs, cluster_offset, index);
  (*n_glyphs)++;
#endif

  /* And the tone mark
   */
  render_tone(font, tone, glyphs, n_glyphs, cluster_offset);
}
Esempio n. 5
0
/* Return a pointer to a string containing the array size */
char *parse_array_size (char string[]) {
  char output_buffer[BUFFER_LEN];
  int length;
  char *size_string, *ptr = string;

  memset (output_buffer, '\0', BUFFER_LEN);
  ptr = find_char (ptr, '(');
  while (ptr < find_char(string,')')) {
    if (strlen(output_buffer) != 0) strcat (output_buffer, "*");
    length = min (find_char(ptr,',')-ptr, find_char(ptr,')')-ptr) - 1;
    strcat (output_buffer, "(");
    if (find_char(ptr,':')-ptr < length) {
      strcat (output_buffer, "1-");
      strncat (output_buffer, ptr, find_char(ptr,':')-ptr-1);
      strcat (output_buffer, "+");
      ptr = find_char (ptr, ':');
      length = min (find_char(ptr,',')-ptr, find_char(ptr,')')-ptr) - 1;
    }
    strncat (output_buffer, ptr, length);
    strcat (output_buffer, ")");
    ptr = skip_blanks (find_char (ptr, ','));
  }
  size_string = malloc (strlen(output_buffer)+1);
  if (size_string == NULL) memory_error ();
  strcpy (size_string, output_buffer);
  return (size_string);
}
Esempio n. 6
0
static void parse_KernData_line(struct temp_font *tf, char *line) {
    int ch, ch2, kern;
    char name[200], name2[200];
    struct kern_info *ki;

    while ( isspace(*line)) ++line;
    if ( *line=='\0' )
return;
    if ( sscanf(line,"KPX %s %s %d", name, name2, &kern )!= 3 ) {
	if ( sscanf(line,"KP %s %s %d", name, name2, &kern )!= 3 ) {
	    fprintf( stderr, "Bad afm kern line <%s>\n", line );
return;
	}
    }
    if ( (ch = find_char(tf,name))== -1 ) {
	if ( tf->is_8859_1 )
	    fprintf( stderr, "Unknown character name <%s>\n", name );
return;
    }
    if ( (ch2 = find_char(tf,name2))== -1 ) {
	if ( tf->is_8859_1 )
	    fprintf( stderr, "Unknown character name <%s>\n", name2 );
return;
    }
    tf->per_char[ch].attributes |= AFM_KERN;
    ki = malloc(sizeof(struct kern_info));
    ki->next = tf->kerns[ch];
    tf->kerns[ch] = ki;
    ki->following = ch2;
    ki->kern = kern;
}
Esempio n. 7
0
/*
 *  This function forms a search string, to look for the best
 *  letter to underline in a menu item. It first tries the
 *  accelerator key, then the uppercase letters from the menu name,
 *  then the digits, and finally the lowercase letters.
 *  It ignores spaces.
 */
static void set_search_string(char *search, const char *name, int key)
{
    int source;
    int dest = 0;
    int mb_len;
    mbstate_t mb_st;

    /* handle a couple of special cases first */
    if (! string_diff(name, "Cut"))  search[dest++] = 't';
    if (! string_diff(name, "Exit")) search[dest++] = 'x';
    if (! string_diff(name, "?")) search[dest++] = '?';

    {
	/* If there is an '&' in the string, use the next letter first */
	char *p = strchr(name, '&');
	if (p && *(p+1)) search[dest++] = *(p+1);
    }

    /* add the accelerator key if it is in the name string */
    if (key) {
	key = toupper(key);
	if (find_char(key, name) >= 0)
	    search[dest++] = (char) key;
	else {
	    key = tolower(key);
	    if (find_char(key, name) >= 0)
		search[dest++] = (char) key;
	}
    }
    /* add the uppercase letters */
    for (source=0; name[source]; source++) {
	mbs_init(mb_st);
	mb_len = Rf_mbrtowc(NULL, name + source, MB_CUR_MAX,&mb_st);
	if (mb_len > 1) source += mb_len-1;
	else
	    if (isupper(name[source])) search[dest++] = name[source];
    }
    /* add the digits */
    for (source=0; name[source]; source++) {
	mbs_init(mb_st);
	mb_len = Rf_mbrtowc(NULL, name + source, MB_CUR_MAX,&mb_st);
	if (mb_len > 1) source += mb_len-1;
	else
	    if (isdigit(name[source])) search[dest++] = name[source];
    }
    /* add the lowercase letters */
    for (source=0; name[source]; source++) {
	mbs_init(mb_st);
	mb_len = Rf_mbrtowc(NULL, name + source, MB_CUR_MAX,&mb_st);
	if (mb_len > 1) source += mb_len-1;
	else
	    if (islower(name[source])) search[dest++] = name[source];
    }
    /* end the search string */
    search[dest] = '\0';
}
Esempio n. 8
0
////////////////////////////////////////////////////////// 
// PRE:  
// POST: RetVal == vector of Strings split from this by ch 
//
//
std::vector<String> String::split(char ch) const
{
  std::vector<String> result;
  
  int start = 0;
  int end = find_char(ch, 0);         // find the first occurance of ch
  while(end < length() && end != -1)
  {
    result.push_back(substr(start, end));   // add the substring between start and end to result
    start = end + 1;                        // move start to one after end
    end = find_char(ch, start);             // find the next occurance of ch
  }

  return result;
}
Esempio n. 9
0
mod_pointer get_module_name (void)
{ 
  { eight_bits c; char* k=mod_text; /* points to last recorded character */
    do
    { if (!find_char())
      { err_print("! Input ended in module name"); break; }
  		   
      c=*loc++;
      
      if (c=='@')
      { if ((c=*loc++)=='>') break;
        if (isspace(c) || c=='*' || c=='~')
        { err_print("! Module name didn't end"); loc-=2; break; }
      		   
        if (k<mod_text_end-1) *++k='@';
          /* record the `\.{@}', now |c==loc[-1]| again */
      }
      if (isspace(c)) c=' '; /* convert tabs, newlines etc. */
      if (k<mod_text_end-1 && !(c==' ' && *k==' ') ) *++k=c;
    } while(true);
    id_first=&mod_text[1];
    if (k>=mod_text_end-1)
  { print("\n! Module name too long: "); 
      term_write(id_first,25); err_print("..");
    }
    id_loc= *k==' ' && k>mod_text ? k : k+1;
      /* point after last non-space character */
  }
  { int l=(int)(id_loc-id_first);
    return l>=3 && strncmp(id_loc-3,"...",3)==0
    	? prefix_lookup(id_first,l-3) : mod_name_lookup(id_first,l);
  }
}
Esempio n. 10
0
gboolean
ide_xml_find_previous_element (const GtkTextIter *iter,
                               GtkTextIter       *start,
                               GtkTextIter       *end)
{
  g_return_val_if_fail (iter != NULL,  FALSE);
  g_return_val_if_fail (start != NULL, FALSE);
  g_return_val_if_fail (end != NULL,   FALSE);

  if(find_char (gtk_text_iter_backward_char, iter, end, '>') &&
     find_char (gtk_text_iter_backward_char, end, start, '<') &&
     gtk_text_iter_compare (start, end) < 0)
    return TRUE;

  return FALSE;
}
Esempio n. 11
0
/* current should point to the opening quote
 * here we return the location of the ending quote
 *
 * We allow empty strings and escaped quote characters
 *
 * on error we return zero and status is set
 */
static size_t find_end_of_quoted_string(const struct cfg_string *str, 
                                        size_t current, 
                                        enum cfg_status *status)
{
    size_t loc=0;

    *status = CFG_EOF;
    if (current == (str->size-1)) {
        return 0;
    }

    // skip past the quote
    current++;
    while (1) {
        loc = find_char(str, current, CFG_QUOTE, status);
        // the end of the word could come with no white space, that is OK too
        if (*status) {
            break;
        }

        if (str->data[loc-1] == CFG_ESCAPE) {
            current=loc+1;
            continue;
        } else {
            break;
        }
    }
    return loc;
}
Esempio n. 12
0
/*
 * end will be left on the assignment character
 */
static void find_next_identifier(const struct cfg_string *str, 
                                 size_t current, 
                                 size_t *beg, 
                                 size_t *end, 
                                 enum cfg_status *status)
{
    while (1) {
        // skip any whitespace and comments
        current = find_nonwhite(str, current, status);
        if (*status) { // EOF
            return;
        }

        *beg=current;

        // now find the assignment character
        current = find_char(str, current, CFG_ASSIGN, status);
        if (*status) {
            // this can't be good; must have left off the assignment char
            return;
        }
        *status = CFG_SUCCESS;
        *end=current;
        break;
    }
}
Esempio n. 13
0
int main(void)
{
	char st[SIZE];
	char *found;
	char ch;

	puts("Enter a string:");
	while (s_gets(st, SIZE) && st[0] != '\n')
	{
		puts("Enter a character you want to find:");
		ch = getchar();
		while (getchar() != '\n')
		{
			continue;
		}
		found = find_char(st, ch);
		if (found != NULL)
		{
			puts(found);
		}
		else
		{
			printf("%c not found in string.\n", ch);
		}
		puts("Enter next string:");
	}

	puts("Done!");

	return 0;
}
Esempio n. 14
0
static int
display_char(FILE *fp, int chr)
{
  char *s;
  int bit, n, high;
  char bits[6][MAX_WIDTH];

  s = find_char(chr);
  if (s != 0) {
    fprintf(fp, "Glyph '%c'\n", chr);
    bit = 0;
    high = 0;
    do {
      if (*s >= '?' && *s <= '~') {
        for (n = 0; n < 6; n++)
          bits[n][bit] = (char) (((*s - '?') & 1 << n) ? 'O' : '.');
        bit++;
      } else if ((*s == ';' || *s == '/') && bit) {
        for (n = 0; (n < 6) && (high++ < MatrixHigh); n++) {
          bits[n][bit] = '\0';
          fprintf(fp, "%s\n", bits[n]);
        }
        bit = 0;
      }
    } while (*s++ != ';');
    return TRUE;
  }
  return FALSE;
}
Esempio n. 15
0
int main ()
{
	char *StringOne = (char *)malloc(StringSize*sizeof(char));
	char *StringTwo = (char *)malloc(StringSize*sizeof(char));
	
	if(StringOne==NULL || StringTwo == NULL)
	{
		printf("The application for RAM failed!Process end.\n\n");
		return 0;
	}
	
	printf("Please enter the first string and make sure the\
length of the string shorter than 100 characeter(include\
the empty charater)\n\n");

	gets(StringOne);

	printf("Please enter the second  string and make sure the \
length of the string shorter than 100 characeter(include \
the empty charater)\n\n");

	gets(StringTwo);

	printf("%c\n",*(find_char(StringOne,StringTwo)));

	free(StringOne);
	free(StringTwo);
	StringOne = NULL;
	StringTwo = NULL;
    return 0;
}
Esempio n. 16
0
/* Add a variable to a linked list */
void create (struct node *start, int vartype, char string[], char comment[]) {
  struct node *end = start, *temp;

  if (find_node (start, string) == NULL) {
    /* Create a new node and add it to the end of the linked list */
    while (end->next != NULL) end = end->next;
    end->next = malloc (sizeof(struct node));
    if (end->next == NULL) memory_error ();
    end = end->next;
    end->vartype = vartype;
    end->action = NOP;
    end->calltype = current_calltype;
    end->line_number = current_line;
    end->name = calloc (extract_text(string)+1, sizeof(char));
    if (end->name == NULL) memory_error ();
    copy (end->name, string, extract_text(string));
    if ((find_char (string, '(') < find_char (string, ',')) &&
	(find_char (string, '(') < find_char (string, '!'))) {
      /* Variable is an array */
      if (start == common_start) {
	/* Array is defined in a common block, so print a warning */
	eprint_newline ();
	eprint ("Warning - Array size defined in common block:");
	eprint_newline ();
	eprint_line (current_line);
	eprintn (string, find_char(string, ')') - string);
	eprint_newline ();
	temp = find_node (register_start, string);
	if (temp != NULL) {
	  if (temp->vartype > 0) array_flags[temp->calltype][temp->vartype]=1;
	  free (temp->size);
	  temp->size = parse_array_size (string);
	  end->size = NULL;
	}
      }
      else end->size = parse_array_size (string);
    }
    else (end->size = NULL);
    if (comment != NULL) {
      end->title = calloc (strlen(comment), sizeof(char));
      if (end->title == NULL) memory_error ();
      copy (end->title, comment, strlen(comment)-1);
    }
    else end->title = NULL;
    end->next = NULL;
  }
}
Esempio n. 17
0
char	*wordcpy(char *str, char *sep, int i)
{
  char	*word;
  int	j;

  j = i;
  while (find_char(str[j], sep) == 1 && str[j] != '\0')
    j++;
  if ((word = malloc(sizeof(char) * j - i + 1)) == NULL)
    return (NULL);
  j = 0;
  while (find_char(str[i], sep) == 1 && str[i] != '\0')
    word[j++] = str[i++];
  word[j] = '\0';
  word = epur_str(word);
  return (word);
}
Esempio n. 18
0
void read_white(char* data, esize_t size, esize_t* pos, esize_t* line, herror_t* perror)
{
    bool_t condition;

    condition = find_char(data[*pos], white_space);
    if (!condition) {
        *perror = 1;
        return;
    }
    while (condition) {
        condition = find_char(data[*pos], white_space);
        if (data[*pos] == '\n') {
            (*line)++;
        }
        (*pos)++;
    }
}
Esempio n. 19
0
int main(int argc, char *argv[])
{
    int n_states, n_symbols, n_accepting_states;
    int i, j;
    char string[MAX_LEN];

    scanf("%d %d\n", &n_states, &n_symbols);
    char alphab[n_symbols];
    int table[n_states][n_symbols];

    for (i = 0; i < n_symbols; ++i)
        scanf("%c", &alphab[i]);

    for (i = 0; i < n_states; ++i)
        for (j = 0; j < n_symbols; ++j)
            scanf("%d", &table[i][j]);

    scanf("%d", &n_accepting_states);
    int accepting_states[n_accepting_states];

    for (i = 0; i < n_accepting_states; ++i)
        scanf("%d ", &accepting_states[i]);

    fgets(string, MAX_LEN, stdin);
    
        int current_state = 0;
        int word_length = strlen(string) - 1;
		int done = 0;
		
       // if (word_length == 0)
           
        if (string[word_length] == '\n')
            string[word_length] = '\0';
		
		while(done != 1)
		{
		
			for (i = 0; i < word_length; ++i)
			{
				if (string[i] == '.')
				{
					done = 1;
					break;
				}

				int char_index = find_char(alphab, n_symbols, string[i]);
				current_state = table[current_state][char_index];
			}
	    }
        printf("DFA has %saccepted input %s Ended in state %d.\n",
                find_state(accepting_states, n_accepting_states, current_state) == -1
                    ? "NOT " : "",
                strtok(string, "."),
                current_state);
    

    return 0;
}
Esempio n. 20
0
File: 6.1.c Progetto: AllenAdom/c
int main()
{
    char *source = "ABCDEF";
    char *chars  = "ESmSG";
    char *result;
    result = find_char(source, chars);
    printf("%c\r\n", *result);

    return 0;
}
Esempio n. 21
0
int main(void) {
    char *source = "ABCDEF";
    char *chars = "XRCEF";
    char *res = find_char(source, chars);
    if (res == NULL) {
        printf("res is null\n");
    } else {
        printf("%c\n", *res);
    }
}
Esempio n. 22
0
int	nb_word(char *str, char *sep)
{
  int	i;
  int	nb;

  i = 0;
  nb = 0;
  while (str[i])
    {
      if (find_char(str[i], sep) == 1)
	{
	  ++nb;
	  while (str[i] != '\0' && find_char(str[i], sep) == 1)
	    ++i;
	}
      else
	++i;
    }
  return (nb);
}
Esempio n. 23
0
int main(int argc, char const *argv[]) {
  char *source = "ABCDEF";
  char *chars = "erwtwEt";
  char const *ch =  NULL;

  if( (ch = find_char( source, chars ) ) != NULL )
    printf("%c\n", *ch );
  else
    printf("NULL \n" );
  return 0;
}
Esempio n. 24
0
/*
 * On entry, current should point to the opening array character
 * On exit end will point to the closing character.
 */
static size_t copy_array(struct cfg_field *self,
                         const struct cfg_string *str,
                         size_t current,
                         enum cfg_status *status)
{
    // skip past the opening brace
    current++;

    CFG_FIELD_ELTYPE(self) = CFG_ELTYPE_UNKNOWN;
    while (1) {
        current = find_nonwhite(str, current, status);
        if (*status) { // EOF
            goto _copy_array_bail;
        }
        if (str->data[current] == CFG_ARRAY_SEP) {
            // this is the separator between elements of array, skip
            current++;
            continue;
        }
        if (str->data[current] == CFG_ARRAY_END) {
            break;
        }

        if (str->data[current] == '#') {
            // found a comment, skip to next EOL
            current = find_char(str, current, '\n', status);
            if (*status) { // EOF
                goto _copy_array_bail;
            }
            continue;
        }
        if (str->data[current] == CFG_QUOTE) {
            current = copy_quoted_string(self, str, current, status);
            if (*status) {
                goto _copy_array_bail;
            }

            CFG_FIELD_ELTYPE(self) = CFG_ELTYPE_QUOTED_STRING;
            // skip ending quote
            current ++;
        } else {
            current = copy_bare_array_token(self, str, current, status);
        }
    }

_copy_array_bail:
    if (CFG_ELTYPE_QUOTED_STRING != CFG_FIELD_ELTYPE(self)) {
        // no quoted strings were found, use bare
        CFG_FIELD_ELTYPE(self)=CFG_ELTYPE_BARE;
    }
    return current;
}
int main(int argc, char *argv[])
{
	if (1 == argc) {
		printf("Enter text as an argument.\n");
		return 1;
	}

	if (!bcm2835_init()) {
		printf("Unable to init bcm2835.\n");
		return 2;
	}

	bcm2835_spi_begin();
	bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // The default
	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256); // The default
	bcm2835_gpio_fsel(Max7219_pinCS, BCM2835_GPIO_FSEL_OUTP); 
	bcm2835_gpio_write(disp1[0][0],HIGH);
	Delay_xms(50);
	Init_MAX7219();

	size_t index = 0;
	while (index < strlen(argv[1])) {
		// Retrive first letter
		char letter1 = toupper(argv[1][index]);
		index++;
		// Retrieve second letter
		// If it does not exist use space
		char letter2 = (index < strlen(argv[1])) ? toupper(argv[1][index]) : (char) 0;
		led_print(find_char(letter1), find_char(letter2));
		Delay_xms(1000);
		index++;
	}
	// Clear screen
	led_print(36, 36);
	bcm2835_spi_end();
	bcm2835_close();
	return 0;
}
Esempio n. 26
0
//
// handles "find" and "purge" in one function
bool try_reset_old_mobile(RESET_DATA *reset, void *initiator,int initiator_type,
			  int reset_cmd, const char *locale) {
  const char *fullkey = get_fullkey_relative(resetGetArg(reset), locale);
  CHAR_DATA      *mob = NULL;

  // is it the room?
  if(initiator_type == INITIATOR_ROOM)
    mob = find_char(NULL, roomGetCharacters(initiator),1, NULL, fullkey, FALSE);
  // is it furniture?
  else if(initiator_type == INITIATOR_ON_OBJ)
    mob = find_char(NULL, objGetUsers(initiator), 1, NULL, fullkey, FALSE);
  // after an object
  else if(initiator_type == INITIATOR_THEN_OBJ) {
    if(objGetRoom(initiator) == NULL)
      return FALSE;
    mob = find_char(NULL, roomGetCharacters(objGetRoom(initiator)), 1, NULL,
		    fullkey, FALSE);
  }
  // after another mob
  else if(initiator_type == INITIATOR_THEN_MOB)
    mob = find_char(NULL, roomGetCharacters(charGetRoom(initiator)), 1, NULL,
		    fullkey, FALSE);

  // if we didn't find it, return FALSE
  if(mob == NULL)
    return FALSE;

  // if we found it, do the reset of the commands
  resetRunOn(reset->on,   mob, INITIATOR_ON_MOB,   locale);
  resetRunOn(reset->in,   mob, INITIATOR_IN_MOB,   locale);
  resetRunOn(reset->then, mob, INITIATOR_THEN_MOB, locale);

  // if this is a purge and it wasn't our initiator, kill it
  // if we purge our initiator, we might run into some problems
  if(mob != initiator && reset_cmd == RESET_PURGE_MOBILE)
    extract_mobile(mob);

  return TRUE;
}
Esempio n. 27
0
static int name_char(struct temp_font *tf,int ch, char *name) {

    if ( tf->is_adobe )
return( find_char(tf,name));
    if ( ch>=tf->max_alloc ) {
	if ( tf->max_alloc==256 ) tf->max_alloc = 128*256; else tf->max_alloc = 65536;
	tf->per_char = realloc(tf->per_char,tf->max_alloc*sizeof(XCharStruct));
	tf->kerns = realloc(tf->kerns,tf->max_alloc*sizeof(struct kern_info *));
    }
    if ( ch!=-1 && ch<256 && name[0]!='\0')
	tf->names[ch] = copy(name);
return( ch );
}
char *get_env(char *name, char **env)
{
  int n, i;

  for (i = 0; env[i] != NULL ; i++)
    {
      if (str_ncmp(env[i], name, str_len(name)) == 0 )
	{
	  n = find_char(env[i], '=');
	  return env[i] + n + 1;
	}
    }
  return "";
}
Esempio n. 29
0
File: post.c Progetto: fbbs/fbbs
static void quote_author_pack(const char *begin, const char *end, FILE *fp,
		filter_t filter)
{
	const char *user_begin = begin + sizeof("发信人: ") - 1;
	const char *lend = get_newline(begin, end);
	const char *user_end = reverse_find_char(begin, lend, ',');

	begin = get_newline(lend, end);
	lend = get_newline(begin, end);

	const char *date_begin = find_char(begin, lend, '(');
	if (date_begin)
		++date_begin;
	const char *date_end = find_char(begin, lend, ')');

	PRINT_CONST_STRING("    \033[0;1;32m");
	if (user_end && user_end > user_begin)
		filter(user_begin, user_end - user_begin, fp);
	PRINT_CONST_STRING(" 于 \033[1;36m");
	if (date_begin && date_end > date_begin)
		filter(date_begin, date_end - date_begin, fp);
	PRINT_CONST_STRING("\033[0;1m 提到:\033[0m\n\n");
}
Esempio n. 30
0
int main(void)
{
    char str[CLIMIT], strc[CLIMIT], src[CLIMIT], c, pch;
    
    printf("Enter a string, a substring, and a character:\n");
    
    if(scanf("%s", str) !=1){
        printf("Invalid input.\n");
        return EXIT_FAILURE;
    }
    
    pch = getc(stdin);
    if(pch != ' '){
        printf("Invalid input.\n");
        return EXIT_FAILURE;
    }
    
    if(scanf("%s", src) !=1){
        printf("Invalid input.\n");
        return EXIT_FAILURE;
    }
    
    pch = getc(stdin);
    if(pch != ' '){
        printf("Invalid input.\n");
        return EXIT_FAILURE;
    }
    
    c = getc(stdin);
    if((c == '\n') ||(c == '\0')){
        printf("Invalid input.\n");
        return EXIT_FAILURE;
    }
    
    pch = getc(stdin);
    if(pch != '\n'){
        printf("Invalid input.\n");
        return EXIT_FAILURE;
    }
    
    strncpy(strc, str, CLIMIT);
    
    if(find_string(str, src) != EXIT_SUCCESS)
        return EXIT_FAILURE;
    if(find_char(strc, c) != EXIT_SUCCESS)
        return EXIT_FAILURE;
    
	return EXIT_SUCCESS;
}