Exemplo n.º 1
0
inline bool xml_element::parse_head(string data) {
  data.qreplace("\t", " ");
  data.qreplace("\r", " ");
  data.qreplace("\n", " ");
  while(qstrpos(data, "  ")) data.qreplace("  ", " ");
  data.qreplace(" =", "=");
  data.qreplace("= ", "=");
  data.rtrim();

  lstring part;
  part.qsplit(" ", data);

  name = part[0];
  if(name == "") throw "...";

  for(unsigned i = 1; i < part.size(); i++) {
    lstring side;
    side.qsplit("=", part[i]);
    if(side.size() != 2) throw "...";

    xml_attribute attr;
    attr.name = side[0];
    attr.content = side[1];
    if(strbegin(attr.content, "\"") && strend(attr.content, "\"")) attr.content.trim_once("\"");
    else if(strbegin(attr.content, "'") && strend(attr.content, "'")) attr.content.trim_once("'");
    else throw "...";
    attribute.append(attr);
  }

  return true;
}
Exemplo n.º 2
0
void Application::initPaths(const char *basename) {
  char temp[PATH_MAX];

  if(realpath(basename, temp)) {
    //remove program name
    strtr(temp, "\\", "/");
    for(signed i = strlen(temp) - 1; i >= 0; i--) {
      if(temp[i] == '/') {
        temp[i] = 0;
        break;
      }
    }

    if(strend(temp, "/") == false) strcat(temp, "/");
    config().path.base = temp;
  } else {
    config().path.base = "";
  }

  if(userpath(temp)) {
    strtr(temp, "\\", "/");
    if(strend(temp, "/") == false) strcat(temp, "/");
    config().path.user = temp;
  } else {
    config().path.user = "";
  }

  char cwd[PATH_MAX];
  config().path.startup = getcwd(cwd);
}
Exemplo n.º 3
0
int main(void)
{
    char *s1 = "some really long string.";
    char *s2 = "ng.";
    char *s3 = "ng";

    if(strend(s1, s2))
    {
        printf("The string (%s) has (%s) at the end.\n", s1, s2);
    }
    else
    {
        printf("The string (%s) doesn't have (%s) at the end.\n", s1, s2);
    }
    if(strend(s1, s3))
    {
        printf("The string (%s) has (%s) at the end.\n", s1, s3);
    }
    else
    {
        printf("The string (%s) doesn't have (%s) at the end.\n", s1, s3);
    }

    return 0;
}
Exemplo n.º 4
0
void
scan_nfs_shared_directories(void)
{
    FILE *exports;
    gint count = 0;
    gchar buf[512];
    
    if (nfs_shares_list) {
        g_free(nfs_shares_list);
    }

    nfs_shares_list = g_strdup("");
    
    if ((exports = fopen("/etc/exports", "r"))) {
        while (fgets(buf, 512, exports)) {
            if (buf[0] != '/')
                continue;
            
            strend(buf, ' ');
            strend(buf, '\t');

            nfs_shares_list = h_strdup_cprintf("%s=\n", 
                                               buf, nfs_shares_list);
            count++;
        }

        fclose(exports);
    }

    if (!count) {
        g_free(nfs_shares_list);
        
        nfs_shares_list = g_strdup("No NFS exports=\n");
    }
}
Exemplo n.º 5
0
void
vUndo(void)
{

	/*
	 * Avoid UU which clobbers ability to do u.
	 */
	if (vundkind == VNONE || vundkind == VCAPU || vUNDdot != dot) {
		(void) beep();
		return;
	}
	CP(vutmp, linebuf);
	vUD1 = linebuf; vUD2 = strend(linebuf);
	putmk1(dot, vUNDsav);
	getDOT();
	vUA1 = linebuf; vUA2 = strend(linebuf);
	vundkind = VCAPU;
	if (state == ONEOPEN || state == HARDOPEN) {
		vjumpto(dot, vUNDcurs, 0);
		return;
	}
	vdirty(vcline, 1);
	if(MB_CUR_MAX > 1)
		rewrite = _ON;
	vsyncCL();
	if(MB_CUR_MAX > 1)
		rewrite = _OFF;
	cursor = linebuf;
	vfixcurs();
}
Exemplo n.º 6
0
static void SetEngineSettingsInfo(sreEngineSettingsInfo *info) {
    sprintf(scene_info_text_line[0], "SRE v0.4.4, %s, back-end: %s", opengl_str[info->opengl_version],
        sre_internal_backend->name);
    sprintf(scene_info_text_line[1], "");
    sprintf(scene_info_text_line[2], "Resolution: %dx%d", info->window_width, info->window_height);
    sprintf(scene_info_text_line[3],
        "Multi-pass rendering: %s (press 6 or 7 to change)", no_yes_str[info->multi_pass_rendering]);
    sprintf(scene_info_text_line[4], "Reflection model: %s (4 5)", info->reflection_model_description);
    sprintf(scene_info_text_line[5], "Shadows setting: %s (1 2 3)", info->shadows_description);
    if (info->shadows_method == SRE_SHADOWS_SHADOW_VOLUMES)
        sprintf(strend(scene_info_text_line[5]), ", Shadow cache: %s",
            disabled_enabled_str[(info->rendering_flags & SRE_RENDERING_FLAG_SHADOW_CACHE_ENABLED) != 0]);
    const char *scissors_cache_description;
    if (info->scissors_method == SRE_SCISSORS_GEOMETRY) {
        if (info->rendering_flags & SRE_RENDERING_FLAG_GEOMETRY_SCISSORS_CACHE_ENABLED)
            scissors_cache_description = " Scissors cache enabled";
        else
            scissors_cache_description = " Scissors cache disabled";
    }
    else
        scissors_cache_description = "";
    sprintf(scene_info_text_line[6], "Scissors optimization mode: %s (D S G)%s",
        info->scissors_description, scissors_cache_description);
    sprintf(scene_info_text_line[7], "");
    sprintf(scene_info_text_line[8], "Max texture filtering anisotropy level: %.1f", info->max_anisotropy);
    sprintf(scene_info_text_line[9], "");
    sprintf(scene_info_text_line[10], "HDR rendering: %s (F2 F3)", disabled_enabled_str[info->HDR_enabled]);
    if (info->HDR_enabled)
        sprintf(strend(scene_info_text_line[10]), ", Tone-mapping shader: %s (F4)",
            sreGetToneMappingShaderName(info->HDR_tone_mapping_shader));
    sprintf(scene_info_text_line[11], "");
    sprintf(scene_info_text_line[12], "");
    sprintf(scene_info_text_line[13], "");
}
Exemplo n.º 7
0
void symdirget(char *dir)
{
  char buff[FN_REFLEN];
  char *pos=strend(dir);
  if (dir[0] && pos[-1] != FN_DEVCHAR && access(dir, F_OK))
  {
    FILE *fp;
    char temp= *(--pos);            /* May be "/" or "\" */
    strmov(pos,".sym");
    fp = my_fopen(dir, O_RDONLY,MYF(0));
    *pos++=temp; *pos=0;	  /* Restore old filename */
    if (fp)
    {
      if (fgets(buff, sizeof(buff)-1, fp))
      {
	for (pos=strend(buff);
	     pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
	     pos --);

	/* Ensure that the symlink ends with the directory symbol */
	if (pos == buff || pos[-1] != FN_LIBCHAR)
	  *pos++=FN_LIBCHAR;

	strmake(dir,buff, (uint) (pos-buff));
      }
      my_fclose(fp,MYF(0));
    }
  }
}
Exemplo n.º 8
0
int main() {
    char *s = "abcdefg";
    char *t1 = "efgh";
    char *t2 = "fg";
    printf("%d\n", mystrlen(s));
    printf("%d\n", strend(s, t1));
    printf("%d\n", strend(s, t2));
}
Exemplo n.º 9
0
int main()
{
	char *s = "A dog is a pet";
	char *t1 = "pet";
	char *t2 = "Adsgpet";
	
	printf("%s\n%s\n", (strend(s, t1) ? "match" : "not match"), (strend(s, t2) ? "match" : "not match"));
	return 0;
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: nagahar/kr
main()
{
	int strend(char *, char *);
	char *s="TEST";
	char *t="EST";
	char *u="HOGE";
	char *v="FUGAFUGA";
	
	printf("%d\n",strend(s,t));
	printf("%d\n",strend(u,v));
}
Exemplo n.º 11
0
int main() {
	printf("Does 'the end' end with 'end'?\n");
	int end = strend("the end", "end");
	end ? printf("yes\n") : printf("no\n");

	printf("Does 'the ending' end with 'end'?\n");
	end = strend("the ending", "end");
	end ? printf("yes\n") : printf("no\n");

	printf("Does 'the end' end with 'an end'?\n");
	end = strend("the end", "an end");
	end ? printf("yes\n") : printf("no\n");
}
Exemplo n.º 12
0
Arquivo: morph.c Projeto: Arnukk/TDS
/* Try to find baseform (lemma) of individual word in POS */
char *morphword(char *word, int pos)
{
    int offset, cnt;
    int i;
    static char retval[WORDBUF];
    char *tmp, tmpbuf[WORDBUF], *end;
    
    sprintf(retval,"");
    sprintf(tmpbuf, "");
    end = "";
    
    if(word == NULL) 
	return(NULL);

    /* first look for word on exception list */
    
    if((tmp = exc_lookup(word, pos)) != NULL)
	return(tmp);		/* found it in exception list */

    if (pos == ADV) {		/* only use exception list for adverbs */
	return(NULL);
    }
    if (pos == NOUN) {
	if (strend(word, "ful")) {
	    cnt = strrchr(word, 'f') - word;
	    strncat(tmpbuf, word, cnt);
	    end = "ful";
	} else 
	    /* check for noun ending with 'ss' or short words */
	    if (strend(word, "ss") || (strlen(word) <= 2))
		return(NULL);
    }

/* If not in exception list, try applying rules from tables */

    if (tmpbuf[0] == '\0')
	strcpy(tmpbuf, word);

    offset = offsets[pos];
    cnt = cnts[pos];

    for(i = 0; i < cnt; i++){
	strcpy(retval, wordbase(tmpbuf, (i + offset)));
	if(strcmp(retval, tmpbuf) && is_defined(retval, pos)) {
	    strcat(retval, end);
	    return(retval);
	}
    }
    return(NULL);
}
Exemplo n.º 13
0
static void
group_handle_normal(GKeyFile * key_file, ShellModuleEntry * entry,
                    gchar * group, gchar ** keys)
{
    GtkTreeIter		 parent;
    GtkTreeStore	*store = GTK_TREE_STORE(shell->info->model);
    gchar 		*tmp   = g_strdup(group);
    gint                 i;

    gtk_tree_store_append(store, &parent, NULL);

    strend(tmp, '#');
    gtk_tree_store_set(store, &parent, INFO_TREE_COL_NAME, tmp, -1);
    g_free(tmp);

    for (i = 0; keys[i]; i++) {
        gchar *key = keys[i];
        gchar *value;
        GtkTreeIter child;

        value = g_key_file_get_value(key_file, group, key, NULL);

        if (g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) {
            gtk_tree_store_append(store, &child, &parent);
            gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, value, -1);

            strend(key, '#');

            if (*key == '$') {
                gchar **tmp;

                tmp = g_strsplit(++key, "$", 0);

                gtk_tree_store_set(store, &child, INFO_TREE_COL_NAME, tmp[1],
                                   INFO_TREE_COL_DATA, tmp[0], -1);

                g_strfreev(tmp);
            } else {
                gtk_tree_store_set(store, &child, INFO_TREE_COL_NAME, key,
                                   INFO_TREE_COL_DATA, NULL, -1);
            }

            g_hash_table_insert(update_tbl, g_strdup(key),
                                gtk_tree_iter_copy(&child));

        }

        g_free(value);
    }
}
Exemplo n.º 14
0
int winscp_regular_request(char *request)
{
	/*
	 * winscp uses one of two requests to terminate each command.
	 * we must determine which (if any) is terminating this request. fun!
	 */
	char *new_request=NULL;
	int retval=0;
	int retzero=1;
	new_request=strend(request, WINSCP_EOF_REQ_ZERO);
	if (NULL == new_request)
	{
		retzero=0;
		new_request=strend(request, WINSCP_EOF_REQ_STATUS);
		if (NULL == new_request)
		{
			new_request=strend(request, WINSCP_EOF_REQ_RETVAL);
			if (NULL == new_request)
			{
				printf ("command wasn't terminated with %s, %s or %s\n",
					WINSCP_EOF_REQ_RETVAL, WINSCP_EOF_REQ_ZERO, WINSCP_EOF_REQ_STATUS);
				return(-1);	/* bogus termination */
			}
		}
	}
	/*
	 *	here is where we fool winscp clients into believing we are a real shell
	 */
	if ((exact_match(new_request, "echo \"$status\"")) ||
		(exact_match(new_request, "echo \"$?\"")))
	{
		printf ("0\n");
		fflush(stdout);
	}
	/*
	 *  ignore unalias and unset commands
	 */
	else if ((NULL!=strbeg(new_request,"unset ")) ||
		(NULL!=strbeg(new_request,"unalias ")))
		retval=0;
	else
	{
		retval=process_ssh_request(new_request);
		if (retzero)		/* ignore actual retval if winscp wants us to */
			retval=0;
	}
	free(new_request);
	return(retval);
}
Exemplo n.º 15
0
int main(){
	char *s = "isch der Fisch";
	char *t = "isch";

	printf("%d\n", strend(s,t));
	return 0;
}
Exemplo n.º 16
0
void symdirget(char *dir)
{
  char buff[FN_REFLEN+1];
  char *pos=strend(dir);
  if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK))
  {
    File file;
    size_t length;
    char temp= *(--pos);            /* May be "/" or "\" */
    strmov(pos,".sym");
    file= my_open(dir, O_RDONLY, MYF(0));
    *pos++=temp; *pos=0;	  /* Restore old filename */
    if (file >= 0)
    {
      if ((length= my_read(file, buff, sizeof(buff) - 1, MYF(0))) > 0)
      {
	for (pos= buff + length ;
	     pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
	     pos --);

	/* Ensure that the symlink ends with the directory symbol */
	if (pos == buff || pos[-1] != FN_LIBCHAR)
	  *pos++=FN_LIBCHAR;

	strmake(dir,buff, (size_t) (pos-buff));
      }
      my_close(file, MYF(0));
    }
  }
}
Exemplo n.º 17
0
/******************************************************************************
 * Function:        void strcatc(char *str,char c)
 *
 * PreCondition:    None
 *
 * Input:           str - pointer to the zero terminated string
 *					c   - appendable character
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Append one character to a zero terminated string
 *
 * Note:            Using static variable for less code size
 *****************************************************************************/
void strcatc(char *str,char c)
{
	static char *s;
	s=strend(str);
	*s=c;
	s[1]=0;
}
Exemplo n.º 18
0
int my_redel(const char *org_name, const char *tmp_name, myf MyFlags)
{
  int error=1;
  DBUG_ENTER("my_redel");
  DBUG_PRINT("my",("org_name: '%s' tmp_name: '%s'  MyFlags: %d",
		   org_name,tmp_name,MyFlags));

  if (my_copystat(org_name,tmp_name,MyFlags) < 0)
    goto end;
  if (MyFlags & MY_REDEL_MAKE_BACKUP)
  {
    char name_buff[FN_REFLEN+20];    
    char ext[20];
    ext[0]='-';
    get_date(ext+1,2+4,(time_t) 0);
    strmov(strend(ext),REDEL_EXT);
    if (my_rename(org_name, fn_format(name_buff, org_name, "", ext, 2),
		  MyFlags))
      goto end;
  }
  else if (my_delete(org_name,MyFlags))
      goto end;
  if (my_rename(tmp_name,org_name,MyFlags))
    goto end;

  error=0;
end:
  DBUG_RETURN(error);
} /* my_redel */
Exemplo n.º 19
0
static const char *my_get_module_parent(char *buf, size_t size)
{
  char *last= NULL;
  char *end;
  if (!GetModuleFileName(NULL, buf, (DWORD) size))
    return NULL;
  end= strend(buf);

  /*
    Look for the second-to-last \ in the filename, but hang on
    to a pointer after the last \ in case we're in the root of
    a drive.
  */
  for ( ; end > buf; end--)
  {
    if (*end == FN_LIBCHAR)
    {
      if (last)
      {
        /* Keep the last '\' as this works both with D:\ and a directory */
        end[1]= 0;
        break;
      }
      last= end;
    }
  }

  return buf;
}
Exemplo n.º 20
0
int check_if_legal_filename(const char *path)
{
  const char *end;
  const char **reserved_name;
  DBUG_ENTER("check_if_legal_filename");

  path+= dirname_length(path);                  /* To start of filename */
  if (!(end= strchr(path, FN_EXTCHAR)))
    end= strend(path);
  if (path == end || (uint) (end - path) > MAX_RESERVED_NAME_LENGTH)
    DBUG_RETURN(0);                             /* Simplify inner loop */

  for (reserved_name= reserved_names; *reserved_name; reserved_name++)
  {
    const char *reserved= *reserved_name;       /* never empty */
    const char *name= path;
    
    do
    {
      if (*reserved != my_toupper(&my_charset_latin1, *name))
        break;
      if (++name == end && !reserved[1])
        DBUG_RETURN(1);                         /* Found wrong path */
    } while (*++reserved);
  }
  DBUG_RETURN(0);
}
Exemplo n.º 21
0
dmi_handle_list *dmidecode_match_value(const char *name, const char *value, const unsigned long *dmi_type) {
    dmi_handle_list *hl = NULL;
    gchar *full = NULL, *p = NULL, *next_nl = NULL;
    unsigned int ch = 0;
    int ln = 0, lnv = 0;

    if (!name) return NULL;
    ln = strlen(name);
    lnv = (value) ? strlen(value) : 0;

    full = dmidecode_read(dmi_type);
    if (full) {
        p = full;
        while(next_nl = strchr(p, '\n')) {
            strend(p, '\n');
            if (!(sscanf(p, "Handle 0x%X", &ch) > 0) ) {
                while(*p == '\t') p++;
                if (strncmp(p, name, ln) == 0) {
                    if (*(p + ln) == ':') {
                        p = p + ln + 1;
                        while(*p == ' ') p++;
                        if (!value || strncmp(p, value, lnv) == 0)
                            hl = dmi_handle_list_add(hl, ch);
                    }
                }
            }
            p = next_nl + 1;
        }
        free(full);
    }

    return hl;
}
Exemplo n.º 22
0
void
finduser(register struct packet *pkt)
{
    register char *p;
    char	*user;
    char groupid[6];
    int none;
    int ok_user;
    extern char saveid[];

    none = 1;
#if 0
    user = logname();
#else
    user = saveid;
#endif
    sprintf(groupid,"%lu",(unsigned long)getgid());
    while ((p = getline(pkt)) != NULL && *p != CTLCHAR) {
        none = 0;
        ok_user = 1;
        repl(p,'\n','\0');	/* this is done for equal test below */
        if(*p == '!') {
            ++p;
            ok_user = 0;
        }
        if (!pkt->p_user)
            if (equal(user,p) || equal(groupid,p))
                pkt->p_user = ok_user;
        *(strend(p)) = '\n';	/* repl \0 end of line w/ \n again */
    }
    if (none)
        pkt->p_user = 1;
    if (p == NULL || p[1] != EUSERNAM)
        fmterr(pkt);
}
Exemplo n.º 23
0
static void
moreinfo_handle_normal(GKeyFile * key_file, gchar * group, gchar ** keys)
{
    GtkTreeIter		 parent;
    GtkTreeStore	*store = GTK_TREE_STORE(shell->moreinfo->model);
    gint                 i;

    gtk_tree_store_append(store, &parent, NULL);
    gtk_tree_store_set(store, &parent, INFO_TREE_COL_NAME, group, -1);

    for (i = 0; keys[i]; i++) {
        gchar *key = keys[i];
        GtkTreeIter child;
        gchar *value;

        value = g_key_file_get_value(key_file, group, key, NULL);

        if (g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) {
            strend(key, '#');

            gtk_tree_store_append(store, &child, &parent);
            gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, value,
                               INFO_TREE_COL_NAME, key, -1);
        }

        g_free(value);
    }
}
Exemplo n.º 24
0
static usbd *usb_get_device_list_lsusb() {
    gboolean spawned;
    gchar *out, *err, *p, *next_nl;
    usbd *head = NULL, *nd;
    int bus, dev, vend, prod, ec;

    spawned = g_spawn_command_line_sync("lsusb",
            &out, &err, NULL, NULL);
    if (spawned) {
        p = out;
        while(next_nl = strchr(p, '\n')) {
            strend(p, '\n');
            ec = sscanf(p, "Bus %d Device %d: ID %x:%x", &bus, &dev, &vend, &prod);
            if (ec == 4) {
                nd = usb_get_device(bus, dev);
                if (head == NULL) {
                    head = nd;
                } else {
                    usbd_list_append(head, nd);
                }
            }
            p = next_nl + 1;
        }
        g_free(out);
        g_free(err);
    }
    return head;
}
Exemplo n.º 25
0
int main() {
	char *s = "abcdef";
	char *t = "def";

	printf("%d\n", strend(s, t));
	return 0;
}
Exemplo n.º 26
0
Arquivo: 5-4.c Projeto: dboychev/C
main()
{
	char s[] = "abcd efg hjkl";
	char t[] = "fg hjkl";

	printf("%d\n", strend(s, t));
}
int main()
{
	char x[] = "World Hello"; 
	char y[] = "ello"; 
	
	int result1 = strend(x, y); 
	printf("Should return 1:\n%d\n", result1); 
	
	char a[] = "Hello World"; 
	char b[] = "ello"; 
	
	int result2 = strend(a, b); 
	printf("Should return 0:\n%d\n", result2); 
	
	return 0; 
}
Exemplo n.º 28
0
char *sti64cpy(                 // CONCATENATE I64 NUMBER
    char *tgt,                  // - target location
    signed_64 value )           // - value to be concatenated
{
    sprintf( tgt, "%lld", VAL64( value ) );
    return strend( tgt );
}
Exemplo n.º 29
0
 inline lstring directory::files(const string &pathname, const string &pattern) {
   lstring list;
   string path = pathname;
   path.transform("/", "\\");
   if(!strend(path, "\\")) path.append("\\");
   path.append("*");
   HANDLE handle;
   WIN32_FIND_DATA data;
   handle = FindFirstFile(utf16_t(path), &data);
   if(handle != INVALID_HANDLE_VALUE) {
     if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
       string name = utf8_t(data.cFileName);
       if(wildcard(name, pattern)) list.append(name);
     }
     while(FindNextFile(handle, &data) != false) {
       if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
         string name = utf8_t(data.cFileName);
         if(wildcard(name, pattern)) list.append(name);
       }
     }
     FindClose(handle);
   }
   if(list.size() > 0) sort(&list[0], list.size());
   return list;
 }
Exemplo n.º 30
0
int main(void) {
	char string1[MAX_STRING], string2[MAX_STRING];
	int character, element;

	for (;;) {
		for (element = 0; element < MAX_STRING - 1 && (character = getchar()) != EOF && character != '\n'; ++element)
			string1[element] = character;
		string1[element] = '\0';
		if (character == EOF)
			break;

		for (element = 0; element < MAX_STRING - 1 && (character = getchar()) != EOF && character != '\n'; ++element)
			string2[element] = character;
		string2[element] = '\0';
		if (character == EOF)
			break;

		if (strend(string1, string2))
			printf("The second string occurs at the end of the first string!\n");
		else
			printf("The second string does not occur at the end of the first string...\n");
	}

	return 0;
}