예제 #1
0
파일: main.c 프로젝트: dmpas/e1c83-form-gtk
static const xmlNode *
find_by_path(const xmlNode *root, const char *path)
{
    char *subs = malloc(strlen(path) + 1);
    const xmlNode *p = root;

    while (*path) {
        int l = strlen(path);
        char *k = strstr(path, "/");
        if (k == 0) {
            strcpy(subs, path);
            path = path + l;
        } else {
            l = k - path;
            strncpy(subs, path, l);
            subs[l] = 0;
            path = k + 1;
        }
        p = find_by_name(p->children, subs);
        if (!p)
            break;
    }
    free(subs);
    return p;
}
예제 #2
0
static int bslhid_resume(transport_t base)
{
	struct bslhid_transport *tr = (struct bslhid_transport *)base;
	struct usb_bus *bus;
	struct usb_device *dev;

	if (tr->handle)
		return 0;

	usb_init();
	usb_find_busses();
	usb_find_devices();

	bus = find_by_name(tr->bus_name);
	if (!bus) {
		printc_err("bslhid: can't find bus to resume from\n");
		return -1;
	}

	/* We can't portably distinguish physical locations, so this
	 * will have to do.
	 */
	dev = find_first_bsl(bus);
	if (!dev) {
		printc_err("bslhid: can't find a BSL HID on this bus\n");
		return -1;
	}

	if (open_device(tr, dev) < 0) {
		printc_err("bslhid: failed to resume BSL HID device\n");
		return -1;
	}

	return 0;
}
예제 #3
0
list_t hash_table_find_by_name(hash_table_t* table, char* value) {
	list_t toReturn = init_list();	
	if(table==NULL) { return false; }
 	for(unsigned long i = hash(value)%table->size; i < table->size*table->size; i += table->size) {
 		list_t toAppend = find_by_name(table->tab[i],value);
 		append(&toReturn, &toAppend);
 	}
	return toReturn;
};
예제 #4
0
GFont fonts_get_font_by_name(const char* name) {
  AppFont* font = find_by_name(name);
  if (NULL == font) {
    return NULL;
  }
  if (NULL == font->font) {
    load(font);
  }
  return font->font;
}
예제 #5
0
int
fdir_lookup (fbuf *the_fbuf, const VenusFid *dir,
	     const char *name, VenusFid *file)
{
     DirPage0 *page0;
     unsigned ind;

     page0 = (DirPage0 *)fbuf_buf(the_fbuf);
     assert (page0);
     ind = find_by_name (page0, name, file, dir);

     if (ind == 0)
	 return 0;
     else
	 return ENOENT;
}
예제 #6
0
void CShareManager::tryMountAutoShare(const QString &path)
{
#ifndef QT_TEST
	DEBUG_INFO_ONE(path);
#endif
	if(!path.startsWith(mounter_->mountPoint()))
		return;
	QString name = path.mid(mounter_->mountPoint().size());
	QMutexLocker l(&taskListmutex_);
	CShareSet::iterator it = std::find_if(prepared_.begin(), prepared_.end(), std::bind1st(find_by_name(), name));
	if(it == prepared_.end()) return;
	taskList_.push_back(qMakePair(MountAutoShare, *it));
	cond_.wakeOne();
}
예제 #7
0
파일: work10_2.c 프로젝트: windard/Learn-C
	int main (void)
	{
		struct STUDENT			stu[5]={
			{1416001,"yang",'m',"hubei",{100,98,95,98,100}},
			{1416002,"huang",'m',"gansu",{94,96,95,100,97}},
			{1416003,"guo",'w',"hebei",{99,98,100,94,98}},
			{1416004,"pan",'m',"shanxi",{100,98,95,100,93}},
			{1416005,"liu",'w',"shanxi",{100,98,100,98,100}}
			};
		float					ave;
		int						i;
		struct STUDENT			*p;
		char					name[20];
		struct STUDENT			*m;

		for(i=0;i<5;i++)
		{
			printf("No %d\n",i);
			print_string(&stu[i]);
		}

			printf("Press ENTER to continue\n");
		printf("\n");

		getche();

		for(i=0;i<5;i++)
		{
			ave=get_average(&stu[i]);
			printf("The ave of No.%d:\t%f\n",i,ave);
		}

		printf("\n");

		printf("Press ENTER to continue \n");

		getche();

		while(1)
		{
			printf("Please input your find name :\n");
			printf("Press N to stop\n");
			gets(name);

			if(strcmp(name,"N")==0)
				break;
			p=find_by_name(stu,name);
			print_string(p);
		}

		printf("\nPress ENTER to continue\n\n");

		getche();

		printf("Who is found has the highest score is :\n");
		m=find_max(stu);
		print_string(m);

		printf("Press ENTER to continue \n");

		getche();

		sort_by_score(stu);

			return 0;
	}
예제 #8
0
파일: rbt.c 프로젝트: nantoka/rb_tree
void insert(
    const char *name
) {
    debug("Insert node: %s", name);

    // Is name exceeding MAX_NAME_LENGTH chars?
    unsigned int len = strlen(name);
    // MAX_NAME_LENGTH is 59 bytes+'\0'
    check(len<MAX_NAME_LENGTH, "Insert: Name exceeds maximal length."); 

    // Allocate and initialize a new node
    Node *n = malloc(sizeof(Node));
    check_mem(n);
    n->parent = NULL; n->left = NIL; n->right = NIL; n->color = RED;
    strncpy(n->name, name, len);
    n->name[len] = '\0';
    
    if(root == NULL) {
		ins_count = 0;
		dbl_count = 0;
		del_count = 0;
        root = n;
    } else {
        // if already exsits skip
        if(find_by_name(n->name)) {
            debug("Insert node: %salready exists", n->name);
			dbl_count++;
            free(n);
            return;
        }
        // search for the proper place to include the node
        Node *current = root;
        while (1) {
    //        debug("Cmp %s with %s", n->name, current->name);
            int res = strcmp(n->name, current->name);
            if(res < 0) {
                if(current->left == NIL) {
                    current->left = n;
                    n->parent = current;
                    break;
                } else {
                    current = current->left;
                }
            } else if(res > 0) {
                if(current->right == NIL) {
                    current->right = n;
                    n->parent = current;
                    break;
                } else {
                    current = current->right;
                }
            }
        }	
    }


    // ensure red black tree properties
    fix_rb_tree(n);

	ins_count++;
	debug("Insert Counter: %d\n", ins_count);
    // check for properties
    check_requirements(root);

error:
    return;
}
예제 #9
0
파일: rbt.c 프로젝트: nantoka/rb_tree
	}
	if(n->right != NIL) {
		delete_all_rec(n->right);
	}
	free(n);
	del_count++;
}

//--------------------------------------------------------------------------------------------------
void delete(
    const char *name
) {
    debug("Delete: deleting %s", name);
    check(root, "Delete tree: root ==  NULL");
    
    Node *n = find_by_name(name);
    if(!n) {
        debug("Delete: Name not found");
        return;
    } else {
        debug("Delete: Name %s found", n->name);
        
    }

error:
    return;	
}

//-------------------------------------------------------------------------------------------------
Node *find_by_name (
    const char *name
예제 #10
0
 // return true if a PerfData item with the name specified in the
 // argument exists, otherwise return false.
 bool contains(const char* name) { return find_by_name(name) != NULL; }
예제 #11
0
파일: main.c 프로젝트: dmpas/e1c83-form-gtk
static form_element_t *
read_83_form(const char *path)
{

    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;
    const xmlNode *el;

    doc = xmlReadFile(path, NULL, 0);
    root_element = xmlDocGetRootElement(doc);

    el = find_by_name(root_element->children, "Elements");

    int grouping = GROUPING_VERTICAL;

    {
        const xmlNode *p = find_by_path(el, "Properties/ChildrenGrouping")->children;

        if (xstrcmp(p->content, "Vertical") != 0)
            grouping = GROUPING_HORIZONTAL;
    }

    el = find_by_path(el, "ContainedItems");

    form_element_t *form = malloc(sizeof(*form));

    form->widget = grouping == GROUPING_HORIZONTAL
            ? gtk_hbox_new(false, 2)
            : gtk_vbox_new(false, 2)
    ;
    form->box = true;

    {
        const xmlNode *pre = find_by_name(root_element->children, "Elements");
        pre = find_by_path(pre, "PredefinedContainedItems");

        if (pre->children) {

            form_element_t vbox, pre_box;
            vbox.widget = gtk_vbox_new(false, 0);
            vbox.box = true;

            pre_box.widget = gtk_vbox_new(false, 0);
            pre_box.box = true;

            load_form_elements(pre->children, &pre_box);

            gtk_box_pack_start(GTK_BOX(vbox.widget), pre_box.widget, false, false, 0);
            gtk_box_pack_start(GTK_BOX(vbox.widget), form->widget, false, false, 0);

            form->widget = vbox.widget;
        }
    }

    load_form_elements(el->children, form);

    xmlFreeDoc(doc);

    xmlCleanupParser();

    return form;
}
예제 #12
0
파일: main.c 프로젝트: xudifsd/lab
struct data * search_by_name(struct name_hash_table *name_table) {
    char name[NAME_MAXLEN];
    printf("Please input name you want search:");
    scanf("%s", name);
    return find_by_name(name_table, name);
}
예제 #13
0
파일: structs.c 프로젝트: Shea690901/ldmud
/*-------------------------------------------------------------------------*/
struct_type_t *
struct_new_prototype ( string_t *name, string_t *prog_name )

/* Create a new prototype struct typeobject from the given data.
 * The references from the data are adopted, and the result is the
 * new typeobject with one reference.
 * When an error occurs, NULL is returned and the input data is freed.
 */

{
    struct_type_t * pSType;
    struct_name_t * pSName;
    hash32_t hash = hash2(name, prog_name);

    pSName = find_by_name(name, prog_name, hash);
    if (pSName == NULL)
    {
        /* No name yet, create one. */
        pSName = xalloc(STRUCT_NAME_MEMSIZE);
        if (pSName == NULL)
        {
            free_mstring(name);
            free_mstring(prog_name);
            return NULL;
        }
        size_struct_type += STRUCT_NAME_MEMSIZE;

        pSName->hash = hash;

        pSName->ref = 1;
        pSName->name = name;
        pSName->prog_name = prog_name;

        pSName->lpctype = NULL;
        pSName->current = NULL;

        if (!add_struct_name(pSName))
        {
            free_struct_name(pSName);
            return NULL;
        }
    }
    else
    {
        ref_struct_name(pSName);
        free_mstring(name);
        free_mstring(prog_name);
    }

    pSType = xalloc(STRUCT_TYPE_MEMSIZE);
    if (pSType != NULL)
    {
        pSType->ref = 1;
        pSType->name = pSName;
        pSType->unique_name = NULL;
        pSType->prog_id = 0;
        pSType->num_members = 0;
        pSType->member = NULL;
        pSType->base = NULL;

        num_struct_type++;
        size_struct_type += STRUCT_TYPE_MEMSIZE;
    }
    else
    {
        free_struct_name(pSName);
    }

    return pSType;
} /* struct_new_prototype() */
예제 #14
0
bool QHiMDWinDetection::winEvent(MSG * msg, long * result)
    {
        QString name, devID, path ;
        if(msg->message == WM_DEVICECHANGE)
        {
            PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR )msg->lParam;
            switch(msg->wParam)
            {
                case DBT_DEVICEARRIVAL :
                {
                    if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
                    {
                        PDEV_BROADCAST_VOLUME pHdrv = (PDEV_BROADCAST_VOLUME)pHdr;
                        path = FindPath(pHdrv->dbcv_unitmask);
                        devID = get_deviceID_from_driveletter(path.at(0).toLatin1());
                        if(!devID.isEmpty())
                        {
                            if(is_himddevice(devID, name))
                            {
                                qDebug() << "Message:DBT_DEVICEARRIVAL for drive " + path;
                                add_himddevice(path, name);
                            }
                        }
                    }
                    else if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
                        devID = QString::fromWCharArray(pDevInf->dbcc_name).toUpper();
                        /* only handle netmd devices, himd devices will be handled by DBT_DEVTYP_VOLUME */
                        if(identified(devID, name) && name.contains("NetMD)"))
                        {
                            qDebug() << name << " detected, rescanning netmd devices" << endl;
                            rescan_netmd_devices();
                        }
                    }
                    break;
                }
                case DBT_DEVICEREMOVECOMPLETE :
                {
                    if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
                    {
                        PDEV_BROADCAST_VOLUME pHdrv = (PDEV_BROADCAST_VOLUME)pHdr;
                        path = FindPath(pHdrv->dbcv_unitmask);
                        qDebug() << "Message:DBT_DEVICEREMOVECOMPLETE for drive " + path;
                        remove_himddevice(path);
                    }
                    else if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
                        devID = QString::fromWCharArray(pDevInf->dbcc_name).toUpper();
                        if(identified(devID, name) && name.contains("NetMD)"))
                        {
                            qDebug() << name << " removed, rescanning netmd devices" << endl;
                            rescan_netmd_devices();
                        }
                    }
                    break;
                }
                case DBT_DEVICEQUERYREMOVE :
                {
                    if(pHdr->dbch_devicetype & DBT_DEVTYP_HANDLE)
                    {
                        PDEV_BROADCAST_HANDLE pHdrh = (PDEV_BROADCAST_HANDLE)pHdr;
                        QMDDevice *dev = find_by_handle(pHdrh->dbch_handle);
                        if(!dev)
                        {
                            qDebug() << "Message:DBT_DEVICEQUERYREMOVE for unknown device " << pHdrh->dbch_handle;
                            break;
                        }
                        if(dev->isBusy())
                        {
                            *result = BROADCAST_QUERY_DENY;
                            qDebug() << "Message:DBT_DEVICEQUERYREMOVE for drive " + path + " denied: transfer in progress";
                            return true;
                        }
                        else
                        {
                            qDebug() << "Message:DBT_DEVICEQUERYREMOVE requested";
                            remove_himddevice(dev->path());
                        }
                    }
                    else if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
                        devID = QString::fromWCharArray(pDevInf->dbcc_name).toUpper();
                        if(identified(devID, name) && name.contains("NetMD)"))
                        {
                            QMDDevice * dev = find_by_name(name);
                            if(!dev)
                                break;
                            if(dev->isBusy())
                            {
                                *result = BROADCAST_QUERY_DENY;
                                return true;
                            }
                            dev->close();
                        }
                    }
                    break;
                }
                case my_DBT_CUSTOMEVENT :
                {
                    if(pHdr->dbch_devicetype & DBT_DEVTYP_HANDLE)
                    {
                        PDEV_BROADCAST_HANDLE pHdrh = (PDEV_BROADCAST_HANDLE)pHdr;
                        if (pHdrh->dbch_eventguid == my_GUID_IO_MEDIA_ARRIVAL)
                        {
                            qDebug() << "Message:DBT_CUSTOMEVENT - GUID_IO_MEDIA_ARRIVAL";
                            add_himd(pHdrh->dbch_handle);
                            break;
                        }
                        if (pHdrh->dbch_eventguid == my_GUID_IO_MEDIA_REMOVAL)
                        {
                            qDebug() << "Message:DBT_CUSTOMEVENT - GUID_IO_MEDIA_REMOVAL";
                            remove_himd(pHdrh->dbch_handle);
                            break;
                        }
                    }
                    break;
                }
                default: return false;  // skip unknown/unused messages
            }
            *result = TRUE;
            return true;
        }
        return false;
    }