コード例 #1
0
ファイル: kdk_string.c プロジェクト: rookieINc/KDK
kdk_uint32
kdk_string_merge(kdk_char32 *ret, kdk_char32 *str1, kdk_char32 *str_split, kdk_char32 *str2, kdk_char32 low_or_up)
{
    void        (*func)();
    kdk_char32  str1_cpy[1024] = {'\0'};
    kdk_char32  str2_cpy[1024] = {'\0'};

    if(ret == NULL) return KDK_NULLPTR;

    strncpy(str1_cpy, str1, sizeof(str1_cpy) - 1);
    strncpy(str2_cpy, str2, sizeof(str2_cpy) - 1);

    str_trim(str1_cpy);
    str_trim(str_split);
    str_trim(str2_cpy);

    if(low_or_up == 'L' || low_or_up == 'l')
        func = kdk_string_low;
    else if(low_or_up == 'U' || low_or_up == 'u')
        func = kdk_string_up;
    else
       return KDK_INVAL;

    (*func)(str1_cpy);
    (*func)(str2_cpy);

    sprintf(ret, "%s%s%s", str1_cpy, str_split, str2_cpy);
    
    return KDK_SUCCESS;
}
コード例 #2
0
ファイル: css_ini_file.c プロジェクト: zhifeichen/libcapture
/**
 * already ignore space character.
 */
static int get_key_value(char* buf, char** key, char** value)
{
	get_split_strs(buf, "=", key, value);
	str_trim(*key);
	str_trim(*value);
	return 0;
}
コード例 #3
0
ファイル: Config.cpp プロジェクト: edeproject/svn
/*
 * scans key = value part
 * returned values are terminated with '\0'
 */
static bool scan_keyvalues(char* line, char* key, char* val, int linesz, int keysz, int valsz) {
	char* linep = line;

	char* pos = strchr(line, KV_DELIM);
	if (!pos)
		return false;

	int i;
	for (i = 0; (*linep != *pos) && (i < keysz); linep++, i++)
		key[i] = *linep;
	key[i] = '\0';

	// skip KV_DELIM
	if (*linep == KV_DELIM)
		linep++;

	for (i = 0; *linep && (*linep != '\n') && (i < valsz) && (i < linesz); linep++, i++)
		val[i] = *linep;
	val[i] = '\0';

	// trim spaces
	str_trim(key);
	str_trim(val);

	return true;
}
コード例 #4
0
ファイル: file.c プロジェクト: andy-uq/Andy-Rogue-Like
void parse_key_value(char* buffer, char** key, char** value)
{
	*key = buffer;
	*value = parse_value(buffer);

	str_trim(key);
	str_trim(value);
}
コード例 #5
0
ファイル: tw2.c プロジェクト: kernel-bz/linux-kernel-struct
///단어 수정(삭제후 입력)
//현재, 교정 단어로 수정되면 번역하지 못함
int tw2_word_update (BTREE* ws, BTREE* wi, char* prompt)
{
	char akey1[ASIZE], akey2[ASIZE];
	char *pkey1, *pkey2;
	int	 c, cnt=0;
	register int i;
	unsigned int kno;
	NODE5 *leaf;
	bool deleted;

	while (1) {
		printf ("%s Word: ", prompt);
		i = 0;
		while ((c = getchar()) != (int)'\n' && i < ASIZE-2)
			akey1[i++] = c;
		akey1[i] = '\0';

		if (i < 2 || i == ASIZE-2) break;
		pkey1 = str_lower (akey1);	//소문자로 변환
		pkey1 = str_trim (pkey1);	//앞뒤 whitespace 잘라냄
		if (! *pkey1) break;

		printf ("%s To: ", prompt);
		i = 0;
		while ((c = getchar()) != (int)'\n' && i < ASIZE-2)
			akey2[i++] = c;
		akey2[i] = '\0';

		if (i < 2 || i == ASIZE-2) break;
		pkey2 = str_lower (akey2);	//소문자로 변환
		pkey2 = str_trim (pkey2);	//앞뒤 whitespace 잘라냄
		if (! *pkey2) break;

		if (bpt_find_leaf_key (ws, pkey2, &leaf) >= 0) {
			printf ("*# Exist same word.\n");	//이 조건이 발생하면 번역키도 수정해야 함(현재는 그냥 종료)
			break;
		}

		//수정(삭제후 입력)
		kno = tw1_drop_word_run (ws, wi, pkey1, &deleted);
		if (deleted) {
			//수정(입력)
			if (_tw2_word_update_run (ws, wi, pkey2, kno) != UIFAIL) {
				printf ("** Updated.\n");
				cnt++;
			}
		} else printf ("** Not exist.\n");

		printf ("\n");
	} //while

	return cnt;
}
コード例 #6
0
ファイル: test.cpp プロジェクト: minnowc/nes
int dbg_get_input(char str[][CMD_SIZE],int len){
    char input[80];
    int i = 0;
    fgets(input, 80, stdin);
    input[strlen(input)-1]='\0';					//remove the last '\n'
    char * temp = str_trim(input);
    while(sscanf(temp, "%[^ ]", &str[i][0]) > 0){
        temp += strlen(str[i]);
        ++i;
        temp = str_trim(temp);
        if(*temp == '\0') break;
    }
    return i;
}
コード例 #7
0
ファイル: strstr_test.c プロジェクト: nsf/lib99
END_TEST

START_TEST(test_str_trim)
{
	str_t *str = str_from_cstr(" 	\n\r123  \n");
	str_trim(str);
	CHECK_STR(str, >= 3, == 3, "123");
	str_free(str);

	str = str_new(0);
	str_trim(str);
	CHECK_STR(str, == STR_DEFAULT_CAPACITY, == 0, "");
	str_free(str);
}
コード例 #8
0
ファイル: Matrix.cpp プロジェクト: jfellus/fvec_dump
Matrix& Matrix::operator=(const std::string& s) {
	std::string s1 = str_trim(str_replace(str_replace(s, "]", " "), "[", " "));
	size_t rows = std::count(s1.begin(), s1.end(), ';');
	std::string first = str_trim(str_before(s1, ";"));
	size_t cols = std::count(first.begin(), first.end(), ' ');
	init(rows+1, cols+1);
	std::string ss = str_trim(str_replace(s1, ";", " "));
	std::istringstream iss(ss);
	for(size_t i=0; i<height; i++) {
		for(size_t j=0; j<width; j++) {
			iss >> data[i*width + j];
		}
	}
	return *this;
}
コード例 #9
0
ファイル: ini.c プロジェクト: gvsurenderreddy/openulteo
static bool ini_parseKey(Ini* ini, char* line) {
	int i = 0;
	char key[256];
	char value[1024];
	int strLen = str_len(line);
	bool keyFound = false;
	Section* section;

	key[0] = '\0';
	value[0] = '\0';

	for (i = 0; i < strLen; i++) {
		if (keyFound) {
			str_ncpy(value, (line + i), strLen - i);
			value[strLen - i] = '\0';
			break;
		}

		if ((line[i] == '=') && keyFound == false) {
			keyFound = true;
			str_ncpy(key, line, i);
			key[i] = '\0';
			continue;
		}
	}

	str_trim(key);
	str_trim(value);

	if (str_len(key) == 0) {
		logWarn("No key in line '%s'", line);
		return false;
	}

	if (str_len(value) == 0) {
		logWarn("No value in line '%s'", line);
		return false;
	}

	if (ini->sections->size == 0) {
		logWarn("There is no section to add the key");
		return false;
	}

	// Get the last section added
	section = (Section*)list_get(ini->sections, (ini->sections->size - 1));
	return ini_addKey(ini, section, key, value);
}
コード例 #10
0
ファイル: String.cpp プロジェクト: GustavoMOG/edelib
void String::trim(void) {
	if(length()) {
		str_trim(sdata->chars);
		/* update length */
		sdata->length = strlen(sdata->chars);
	}
}
コード例 #11
0
//사용자 작업경로에 파일명 입력(파일명 길이 반환)
int fio_getchar_fname (char* msg, char* fname)
{
	register int i;
	int c;
	char *pstr = fname;

	pstr = (char*)getcwd (NULL, 0);	//Current Directory
	str_replace (pstr, '\\', '/');
	*pstr = a_upper (*pstr);
	printf ("(Path)%s", pstr);

	str_copy (fname, DIR_WORKS);
	printf ("%s\n", fname+1);

	printf (msg);

	i = str_len (fname);
	while ((c = getchar()) != (int)'\n' && i < ASIZE-2)
		fname[i++] = c;
	fname[i] = '\0';

	if (i == ASIZE-2) return 0;

	str_trim (fname);
	return (str_cmp (DIR_WORKS, fname)) ? i : 0;
}
コード例 #12
0
static void messaging_server_exec_room_close(ServerData* server, User* user, char* name){
	//Process param (Check if valid name)
	name = (name == NULL) ? NULL : str_trim(name);
	if(user == NULL || name == NULL || room_is_valid_name(name) != 1){
		fprintf(stderr, "[ERR] Invalid enter message\n");
		messaging_send_error(user->socket, MSG_ERR_GENERAL, "Invalid room name.");
		return;
	}
	
	//Try to remove room and send err message if error (See doc fct for err value)
	int errstatus = server_data_remove_room(server, user, name);
	switch(errstatus){
		case 1:
			messaging_send_confirm(user->socket, MSG_CONF_GENERAL, "Room successfully closed.");
			fprintf(stdout, "[ROOM] '%s' closed. (Owner: '%s')\n", name, user->login);
			return;
		case -1:
			messaging_send_error(user->socket, MSG_ERR_GENERAL, "Room doesn't exists.");
			return;
		case -2:
			messaging_send_error(user->socket, MSG_ERR_GENERAL, "Room must be empty in order to be closed.");
			return;
		case -3:
			messaging_send_error(user->socket, MSG_ERR_GENERAL, "You must own this room.");
			return;
		case -4:
			messaging_send_error(user->socket, MSG_ERR_GENERAL, "Error occured while closing.");
			return;
	}
}
コード例 #13
0
static void messaging_server_exec_room_open(ServerData *server, User *user, char *name){
	//Params must be not null
	if(user == NULL || name == NULL){
		fprintf(stderr, "[ERR] Invalid open message (NULL data)\n");
		messaging_send_error(user->socket, MSG_ERR_GENERAL, "Invalid room name.");
		return;
	}

	//Try to add room and check error
	name = str_trim(name);
	int errstatus = server_data_add_room(server, user, name);
	switch(errstatus){
		case 1: //OK
			fprintf(stdout, "[ROOM] New room created: '%s' (Owner: '%s')\n", name, user->login);
			messaging_send_confirm(user->socket, MSG_CONF_GENERAL, "Room successfully created");
			return;
		case -1: //Invalid name
			fprintf(stderr, "[ERR] Invalid open message: room name '%s'\n", name);
			messaging_send_error(user->socket, MSG_ERR_GENERAL, "Invalid room name.");
			return;
		case -2: //Room already used by server
			fprintf(stderr, "[ERR] Invalid open message: room name '%s' already used.\n", name);
			messaging_send_error(user->socket, MSG_ERR_GENERAL, "Invalid room name: already used.");
			return;
		case -3: //Internal error (Malloc error)
			fprintf(stderr, "[ERR] Unable to create room '%s': internal error (malloc).\n", name);
			messaging_send_error(user->socket, MSG_ERR_GENERAL, "Sorry, we are unable to create the room.");
			return;
	}
}
コード例 #14
0
ファイル: tw2.c プロジェクト: kernel-bz/linux-kernel-struct
///교정(revision) 단어 사전에서 삭제
int tw2_rev_word_delete (BTREE* rs)
{
	char akey1[ASIZE], *pkey1;
	int	 c, cnt=0;
	register int i;
	bool deleted;

	while (1) {
		printf ("Word1: ");
		i = 0;
		while ((c = getchar()) != (int)'\n' && i < ASIZE-2)
			akey1[i++] = c;
		akey1[i] = '\0';

		if (i < 2 || i == ASIZE-2) break;
		pkey1 = str_lower (akey1);	//소문자로 변환
		pkey1 = str_trim (pkey1);	//앞뒤 whitespace 잘라냄
		if (! *pkey1) break;

		//리프노드로 이동하여 삭제
		//deleted = false;
		rs->root = bpt_delete (rs, pkey1, &deleted);
		if (deleted) {
			printf ("** Deleted.\n");
			cnt++;
		}
	} //while
	return cnt;
}
コード例 #15
0
ファイル: parse.c プロジェクト: gimunu/octopus-irECS
static int parse_get_line(FILE *f, char **s, int *length)
{
  int i, c;

  i = 0;
  do{
    c = getc(f);
    if(c == '#') /* skip comments */
      while(c!=EOF && c!='\n') c = getc(f);
    else if(c != EOF){
      if (i == *length - 1){
	*length *= 2;
	*s = (char *)realloc(*s, *length + 1);
      }
      /* check for continuation lines */
      if(i > 0 && c == '\n' && (*s)[i-1] == '\\'){
        c = 'd'; /* dummy */
        i--;
      }else
        (*s)[i++] = (char)c;
    }
  }while(c != EOF && c != '\n');
  (*s)[i] = '\0';
	
  str_trim(*s);
  return c;
}
コード例 #16
0
static void messaging_server_exec_room_enter(ServerData* server, User* user, char* name){
	//Params must be not null
	name = (name == NULL) ? NULL : str_trim(name);
	if(user == NULL || name == NULL || room_is_valid_name(name) != 1){
		fprintf(stderr, "[ERR] Invalid enter message\n");
		messaging_send_error(user->socket, MSG_ERR_GENERAL, "Invalid room name.");
		return;
	}

	//To enter a room, user must be first in the default room (The one from connection)
	if(strcmp(user->room, ROOM_WELCOME_NAME) != 0){
		messaging_send_error(user->socket, MSG_ERR_GENERAL, "You must leave your current room first.");
		return;
	}

	//Check whether the requested room exists
	//TODO Add mutex on the room list
	Room* new_room = list_get_where(&(server->list_rooms), (void*)name, room_match_name);
	Room* old_room = list_get_where(&(server->list_rooms), (void*)user->room, room_match_name);
	if(new_room == NULL || old_room == NULL){
		messaging_send_error(user->socket, MSG_ERR_GENERAL, "Room doesn't exists...");
		return;
	}

	//Change user room
	room_remove_user(old_room, user);
	room_add_user(new_room, user);
	messaging_send_confirm(user->socket, MSG_CONF_ROOM_ENTER, "You successfully enterred the room.");
	fprintf(stdout, "[ROOM] User '%s' moved from '%s' to '%s'\n", user->login, old_room->name, new_room->name);
}
コード例 #17
0
ファイル: system_win32.c プロジェクト: bandilab/bandicoot
extern void sys_die(const char *msg, ...)
{

    DWORD dw = GetLastError();
    LPSTR lpMsgBuf = NULL;
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
                  FORMAT_MESSAGE_FROM_SYSTEM |
                  FORMAT_MESSAGE_IGNORE_INSERTS,
                  NULL,
                  dw,
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                  (LPSTR) &lpMsgBuf,
                  0,
                  NULL);

    va_list ap;

    va_start(ap, msg);
    vprintf(msg, ap);
    va_end(ap);

    if (dw)
        printf("[system error: '%s']\n", str_trim(lpMsgBuf));

    exit(PROC_FAIL);
}
コード例 #18
0
ファイル: attrs_map.c プロジェクト: cf981378640/cosmonaut
void attrs_map_parse(attrs_map *map, char *str) {
  char *pair, *name, *value, *header_str, *original_ptr;
  header_str = strdup(str);
  original_ptr = header_str;

  while(isspace(*header_str)) header_str++;

  while((pair = strsep(&header_str, ";")) && pair != NULL) {
    name = strsep(&pair, "=");
    value = strsep(&pair, "=");

    attrs_map_add(map, str_trim(name), str_trim(str_strip_quotes(value)));
  }

  free(original_ptr);
}
コード例 #19
0
void QTVList_Parse_EndElement(void *userData, const XML_Char *name)
{
	sb_qtvlist_parse_state_t *sb_qtvparse = (sb_qtvlist_parse_state_t *) userData;
	char *buf = str_trim(sb_qtvparse->chardata_buffer);

	if (sb_qtvparse->position == QTVLIST_INITIAL) {
	}
	else if (sb_qtvparse->position == QTVLIST_ITEM) {
		if (strcmp(name, "hostname") == 0) {
			strlcpy(sb_qtvparse->list->hostname, buf, MAX_QTV_ENTRY_TEXTLEN);
		}
		else if (strcmp(name, "port") == 0) {
			sb_qtvparse->list->port = Q_atoi(buf);
		}
		else if (strcmp(name, "observercount") == 0) {
			sb_qtvparse->list->observercount = Q_atoi(buf);
		}
		else if (strcmp(name, "title") == 0) {
			strlcpy(sb_qtvparse->list->title, buf, MAX_QTV_ENTRY_TEXTLEN);
		}
		else if (strcmp(name, "link") == 0) {
			strlcpy(sb_qtvparse->list->link, buf, MAX_QTV_ENTRY_TEXTLEN);
		}
		else if (strcmp(name, "item") == 0) {
			sb_qtvparse->position = QTVLIST_INITIAL; // go up
		}
		else if (strcmp(name, "player") == 0) {
			sb_qtvparse->position = QTVLIST_PLAYER; // go down
		}
	}
	else if (sb_qtvparse->position == QTVLIST_PLAYER) {
		if (strcmp(name, "name") == 0) {
			strlcpy(sb_qtvparse->list->players->name, buf, MAX_SCOREBOARDNAME);
		}
		else if (strcmp(name, "team") == 0) {
			strlcpy(sb_qtvparse->list->players->team, buf, MAX_SCOREBOARDNAME);
		}
		else if (strcmp(name, "frags") == 0) {
			sb_qtvparse->list->players->frags = Q_atoi(buf);
		}
		else if (strcmp(name, "ping") == 0) {
			sb_qtvparse->list->players->ping = Q_atoi(buf);
		}
		else if (strcmp(name, "pl") == 0) {
			sb_qtvparse->list->players->pl = Q_atoi(buf);
		}
		else if (strcmp(name, "topcolor") == 0) {
			sb_qtvparse->list->players->topcolor = Q_atoi(buf);
		}
		else if (strcmp(name, "bottomcolor") == 0) {
			sb_qtvparse->list->players->bottomcolor = Q_atoi(buf);
		}
		else if (strcmp(name, "player") == 0) {
			sb_qtvparse->position = QTVLIST_ITEM;
		}
	}

	buf[0] = '\0';
}
コード例 #20
0
ファイル: vamas.cpp プロジェクト: wojdyr/xylib
bool VamasDataSet::check(istream &f, string*)
{
    static const string magic =
     "VAMAS Surface Chemical Analysis Standard Data Transfer Format 1988 May 4";
    string line;
    skip_whitespace(f);
    return getline(f, line) && str_trim(line) == magic;
}
コード例 #21
0
ファイル: author_getsimilar.c プロジェクト: SimoneCnt/cygne
char *
peer_author_getsimilar(xmlDocPtr doc, char *full) 
{

    int i;
    char *ans=NULL;
    double namedist;
    char *fullname = str_trim(full);

    xmlNodeSetPtr nodeset;
    xmlXPathObjectPtr result;
    xmlNodePtr node;

    xmlChar *name;
    xmlChar *peerid;

    printf("Checking author name <%s>...\n", fullname);

    result = peer_getnodeset(doc, (const xmlChar*)"/db/authors/author");
    if (result) {
        nodeset = result->nodesetval;
        for (i=0; i < nodeset->nodeNr; i++) {

            node = nodeset->nodeTab[i];

            name   = peer_getchildinfo(doc, node, "fullname");
            peerid = peer_getchildinfo(doc, node, "peerid");

            namedist = 100.0*str_similarity(fullname, (char*)name, false);
            //printf("Get similarity of %.1f with <%s>\n", namedist, name);

            if (namedist>50) {
                peer_author_printinfo(doc, (char*)peerid);
                printf("Is <%s> this author (similarity %.1lf)? (y/n) ", fullname, namedist);
                str_getline(&ans, stdin);
                if (ans[0]=='y' || ans[0]=='Y') {
                    printf("Match found!\n");
                    xmlFree(name);
                    free(ans);
                    free(fullname);
                    xmlXPathFreeObject(result);
                    return (char*)peerid;
                }
            }

            xmlFree(name);
            xmlFree(peerid);
        }
        xmlXPathFreeObject(result);
    }

    printf("No similar names found :(\n");

    free(ans);
    free(fullname);
    return NULL;

}
コード例 #22
0
ファイル: tmx_xml.c プロジェクト: V0idExp/tmx
static int parse_data(xmlTextReaderPtr reader, int32_t **gidsadr, size_t gidscount) {
	char *value, *inner_xml;

	if (!(value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"encoding"))) { /* encoding */
		tmx_err(E_MISSEL, "xml parser: missing 'encoding' attribute in the 'data' element");
		return 0;
	}

	if (!(inner_xml = (char*)xmlTextReaderReadInnerXml(reader))) {
		tmx_err(E_XDATA, "xml parser: missing content in the 'data' element");
		tmx_free_func(value);
		return 0;
	}

	if (!strcmp(value, "base64")) {
		tmx_free_func(value);
		if (!(value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"compression"))) { /* compression */
			tmx_err(E_MISSEL, "xml parser: missing 'compression' attribute in the 'data' element");
			goto cleanup;
		}
		if (strcmp(value, "zlib") && strcmp(value, "gzip")) {
			tmx_err(E_ENCCMP, "xml parser: unsupported data compression: '%s'", value); /* unsupported compression */
			goto cleanup;
		}
		if (!data_decode(str_trim(inner_xml), B64Z, gidscount, gidsadr)) goto cleanup;

	} else if (!strcmp(value, "xml")) {
		tmx_err(E_ENCCMP, "xml parser: unimplemented data encoding: XML");
		goto cleanup;
	} else if (!strcmp(value, "csv")) {
		if (!data_decode(str_trim(inner_xml), CSV, gidscount, gidsadr)) goto cleanup;
	} else {
		tmx_err(E_ENCCMP, "xml parser: unknown data encoding: %s", value);
		goto cleanup;
	}
	tmx_free_func(value);
	tmx_free_func(inner_xml);
	return 1;

cleanup:
	tmx_free_func(value);
	tmx_free_func(inner_xml);
	return 0;
}
コード例 #23
0
ファイル: string.c プロジェクト: bandilab/bandicoot
static void test_trim()
{
    char s[64];
    str_cpy(s, " \r  \n \t  abc\t\t\t\r\r");
    char *res = str_trim(s);
    if (str_len(res) != 3)
        fail();

    if (str_cmp("abc", res) != 0)
        fail();
}
コード例 #24
0
ファイル: defines.c プロジェクト: Refandler/gentee
pstr  STDCALL os_tempdir( pstr name )
{
  #ifdef LINUX
   pstr stemp = os_gettemp();
   uint uLenTempStr  =  str_len(stemp);
   str_copy(name,stemp);
  #else
   str_setlen( name, GetTempPath( 1024, str_reserve( name, 1024 )->data ));
  #endif
  return str_trim( name, SLASH, TRIM_ONE | TRIM_RIGHT );
}
コード例 #25
0
ファイル: cnv_setup.cpp プロジェクト: siamect/proview
int CnvSetup::setup(char* filename)
{
  int sts;
  char line[400];
  char line_part[4][80];
  int nr;
  char line_cnt = 0;
  FILE* fp;

  fp = fopen(filename, "r");
  if (!fp)
    return 0;

  while (1) {
    sts = CnvCtx::read_line(line, sizeof(line), fp);
    if (!sts)
      break;
    else {
      line_cnt++;
      str_trim(line, line);
      if (streq(line, ""))
        continue;

      if (line[0] == '!' || line[0] == '#')
        continue;

      nr = dcli_parse(line, " 	=", "", (char*)line_part,
          sizeof(line_part) / sizeof(line_part[0]), sizeof(line_part[0]), 0);

      if (streq(CnvCtx::low(line_part[0]), "group")) {
        if (nr < 2) {
          printf("** Setup syntax error in file %s, line %d\n", filename,
              line_cnt);
          continue;
        }
        if (group_cnt >= (int)(sizeof(groups) / sizeof(groups[0]))) {
          printf("** Max number of groups exceeded in file %s, line %d\n",
              filename, line_cnt);
          continue;
        }
        strcpy(groups[group_cnt], line_part[1]);
        if (nr >= 3)
          strcpy(groups_startpage[group_cnt], line_part[2]);
        else
          strcpy(groups_startpage[group_cnt], "");
        group_cnt++;
      }
    }
  }
  fclose(fp);

  return 1;
}
コード例 #26
0
ファイル: lib_str.c プロジェクト: PichuChen/formosa
void str_unquote(volatile char *str)
{
	volatile char *ptr;

	str_trim(str);
	if (*str != '\"')
		return;

	for (ptr = str + 1 ; *ptr != '\0' && *ptr != '\"' ; ++ptr)
		*(ptr - 1) = *ptr;
	*(ptr - 1) = '\0';
}
コード例 #27
0
ファイル: tw2.c プロジェクト: kernel-bz/linux-kernel-struct
//교정(revision) 단어 B+트리에 입력
bool tw2_rev_word_insert (BTREE* rs, char akey[][ASIZE])
{
	char *pkey1, *pkey2, *mkey1, *mkey2;
	NODE5 *leaf;

	pkey1 = str_lower (akey[0]);	//소문자로 변환
	pkey1 = str_trim (pkey1);		//앞뒤 whitespace 잘라냄
	if (! *pkey1) return false;

	pkey2 = str_lower (akey[1]);	//소문자로 변환
	pkey2 = str_trim (pkey2);		//앞뒤 whitespace 잘라냄
	if (! *pkey2) return false;
	
	if (bpt_find_leaf_key (rs, pkey1, &leaf) < 0) {	
		//리프에 동일한 키가 없다면 메모리할당후 삽입
		mkey1 = malloc (str_len (pkey1) + 1);
		if (!mkey1) {
			printf ("## Failure to allocate memory.\n");
			return false;
		}
		str_copy (mkey1, pkey1);

		mkey2 = malloc (str_len (pkey2) + 1);
		if (!mkey2) {
			printf ("## Failure to allocate memory.\n");
			return false;
		}
		str_copy (mkey2, pkey2);
		//B+트리에 입력
		rs->root = bpt_insert (rs, leaf, mkey1, mkey2, FLAG_INSERT);
		//printf ("** Inserted.\n");
		return true;

	} else {
		printf ("** Exist same key.\n");
		return false;
	}
}
コード例 #28
0
ファイル: lib_mail.c プロジェクト: foxfair/formosa
static int mail_get_subject(char *buf, struct MailHeader *mh)
{
	char *subject = mh->subject;

	while (isspace(*(buf)))
		++buf;

	str_notab(buf);
	str_trim(buf);
	str_decode((unsigned char *)buf);
	str_ansi(subject, buf, SUBJECT_LEN);

	return 0;
}
コード例 #29
0
ファイル: magres.c プロジェクト: davedavemckay/magres-format
void magres_tokenize(MagresLine *line, char *str_line) {
  char *str_line_trimmed = str_trim(str_line);
  
  // First, work out how many columns there are
  line->num_cols = 0;

  bool whitespace = false;
  int line_length = strlen(str_line_trimmed);

  int i = 0;
  for(; i<line_length; ++i) {
    if(str_line_trimmed[i] == ' ' && !whitespace) {
      whitespace = true;
      line->num_cols++;
    } else if(str_line_trimmed[i] != ' ' && whitespace) {
      whitespace = false;
    }
  }

  if(strlen(str_line_trimmed) != 0) {
    line->num_cols += 1;
  }
  
  // Now copy all the tokens into the cols array
  line->cols = malloc(sizeof(char*) * line->num_cols);

  i = 0;
  int j = 0;
  int token_length = 0;
  int current_col = 0;

  for(; i<=line_length; ++i) {
    if((str_line_trimmed[i] == ' ' && !whitespace) || i == line_length) { // start of whitespace
      token_length = i - j;

      line->cols[current_col] = malloc(sizeof(char) * (token_length + 1));
      memcpy(line->cols[current_col], &str_line_trimmed[j], token_length);
      line->cols[current_col][token_length] = 0;
     
      if(token_length != 0) {
        current_col += 1;
      }

      whitespace = true;
    } else if(str_line_trimmed[i] != ' ' && whitespace) { // end of whitespace
      j = i;
      whitespace = false;
    }
  }
}
コード例 #30
0
ファイル: config.c プロジェクト: yzzyx/mimic
static void XMLCALL end(void *user_data, const char *el)
{
	SHORTCUT_SETTINGS *ss_ptr;

	depth --;

	if( sub_element == ELEMENT_TYPE ){
		ss_ptr = (((SETTINGS *)user_data)->shortcut_settings)->data;
		str_trim(ss_ptr->type_str);

		if( ss_ptr->type_str && strcasecmp(ss_ptr->type_str, "browser") == 0){
			ss_ptr->type = SHORTCUT_TYPE_BROWSER;
		}else if( ss_ptr->type_str && strcasecmp(ss_ptr->type_str, "exec") == 0){
			ss_ptr->type = SHORTCUT_TYPE_EXEC;
		}else if( ss_ptr->type_str && strcasecmp(ss_ptr->type_str, "exec_show") == 0){
			ss_ptr->type = SHORTCUT_TYPE_EXEC_SHOW;
		}else if( ss_ptr->type_str && strcasecmp(ss_ptr->type_str, "automount") == 0){
			ss_ptr->type = SHORTCUT_TYPE_DIRECTORY_LIST;
		}else{	/* dummy label */
			ss_ptr->type = SHORTCUT_TYPE_LABEL;
		}
	}else if( sub_element == ELEMENT_NAME ){
		ss_ptr = (((SETTINGS *)user_data)->shortcut_settings)->data;
		str_trim(ss_ptr->name);
	}else if( sub_element == ELEMENT_FILTER ){
		ss_ptr = (((SETTINGS *)user_data)->shortcut_settings)->data;
		str_trim(ss_ptr->filter);
	}else if( sub_element == ELEMENT_EXEC ){
		ss_ptr = (((SETTINGS *)user_data)->shortcut_settings)->data;
		str_trim(ss_ptr->exec);
	}else if( sub_element == ELEMENT_PATH ){
		ss_ptr = (((SETTINGS *)user_data)->shortcut_settings)->data;
		str_trim(ss_ptr->path);
	}

	sub_element = -1;
}