예제 #1
0
/* Given two chains of unicode tokens, return the union of them */
static int chain_merge(psf_unicode_dirent **dest, psf_unicode_dirent *src)
{
	char *str1, *str2, *tok2;
	psf_dword token;
	psf_unicode_dirent *ude, *ude2, *end;

	end = *dest;
	for (ude2 = *dest; ude2 != NULL; ude2 = ude2->psfu_next) end = ude2; 

	str1 = chain2str(*dest);
	str2 = chain2str(src);

	for (tok2 = strtok(str2, ";"); 
	     tok2 != NULL;
     	     tok2 = strtok(NULL, ";"))
	{
		if (strstr(str1, tok2)) 
		{
			continue;
		}
		if (strchr(tok2, '+'))
		{
			/* Add multiple token to end */	
			tok2++;
			/* Add sequence leadin */
			ude = newentry(0xFFFE);
			if (!ude) return PSF_E_NOMEM;
			end->psfu_next = ude;
			ude->psfu_next = NULL;
			end = ude;
			while (strlen(tok2) > 8)
			{
				sscanf(tok2, "%lx", &token);
				ude = newentry(token);
				if (!ude) return PSF_E_NOMEM;
				end->psfu_next = ude;
				ude->psfu_next = NULL;
				end = ude;
				tok2 += 9;	/* Skip hex & separator */
			}
		}
		else
		{
			sscanf(tok2 + 1, "%lx", &token);
			ude = newentry(token);
			if (!ude) return PSF_E_NOMEM;
/* Single token: Insert at front of chain */
			ude->psfu_next = *dest;
			*dest = ude;

		}
	}
	free(str1);
	free(str2);
	return 1;
}
예제 #2
0
void dataeditfrm::acceptdata()
{
    if(lblID->text()!="-")
		updateentry();
    else
		newentry();
	QSqlDatabase::database().commit();
    this->accept();
}
예제 #3
0
파일: db1.c 프로젝트: Hullberg/kod
  // Main loop
int mainloop(char *argv){
    FILE *database = fopen(argv, "r");
    char buffer[128];
    Node list = NULL;
    while(!(feof(database))){
      Node newNode = malloc(sizeof(struct node));
      readline(buffer, 128, database);
      newNode->key = malloc(strlen(buffer) + 1);
      strcpy(newNode->key, buffer);
      readline(buffer, 128, database);
      newNode->value = malloc(strlen(buffer) + 1);
      strcpy(newNode->value, buffer);
      newNode->next = list;
      list = newNode;
      }
  int choice = -1;
  while(choice != 0){
    puts("Please choose an operation");
    puts("1. Query a key");
    puts("2. Update an entry");
    puts("3. New entry");
    puts("4. Remove entry");
    puts("5. Print database");
    puts("0. Exit database");
    printf("? ");
    scanf("%d", &choice);
    while(getchar() != '\n'); // Clear stdin
    /*int found;
    Node cursor;*/
    switch(choice){
    case 1:
      querykey(list);
      break;
    case 2:
      updateentry(list);
      break;
    case 3:
      newentry(list);
      break;
      /*case 4:
      removeentry(list);
      break;
    case 5:
      printdb(list);
      break;*/
    case 0:
       // Exit
      puts("¡Adios señor!\n");
      break;
      default:
    puts("Could not parse choice! Please try again!\n");
      }
  }
  return 0;
}
예제 #4
0
파일: kob1.c 프로젝트: lecram/kibibeat
KNable *
newnable()
{
    KNable *knable;

    /* [Re]Initialize pseudo-random number generator. */
    srand(time(NULL));

    knable = (KNable *) malloc(sizeof(KNable));
    knable->level = 0;
    knable->header = newentry(SLHEIGHT - 1, "", NULL);
    return knable;
}
예제 #5
0
/* Copy a chain of unicode tokens from a PSF file into the unicodes[] array */
static psf_errno_t chain_copy(psf_unicode_dirent **dest, psf_unicode_dirent *src)
{
	psf_unicode_dirent *ude;
	while (src)
	{
		ude = newentry(src->psfu_token);
		if (!ude) return PSF_E_NOMEM;
		*dest = ude;
		dest = &ude->psfu_next;
		src = src->psfu_next;
	}
	return PSF_E_OK;
}
예제 #6
0
파일: root.c 프로젝트: anandab/akaros
static int createentry(int dir, char *name, int omode, int perm)
{
	int n = newentry(dir);
	strncpy(roottab[n].name, name, sizeof(roottab[n].name));
	roottab[n].length = 0;
	roottab[n].perm = perm;
	/* vers is already properly set. */
	mkqid(&roottab[n].qid, n, roottab[n].qid.vers,
	      perm & DMDIR ? QTDIR : QTFILE);
	rootdata[n].dotdot = roottab[dir].qid.path;
	rootdata[dir].ptr = &roottab[n];
	rootdata[n].size = 0;
	rootdata[n].sizep = &rootdata[n].size;
	return n;
}
예제 #7
0
파일: kob1.c 프로젝트: lecram/kibibeat
void
tset(KNable *knable, char *name, Kob *value)
{
    KEntry *kentry;
    KEntry *update[SLHEIGHT];
    int found, i;

    /* Seek name. */
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != NULL) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
        update[i] = kentry;
    }
    kentry = kentry->next[0];
    found = (kentry != NULL);
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        /* Set value. */
        delkob(&kentry->value);
        kentry->value = value;
    }
    else {
        /* Name not found. */
        /* New entry. */
        int level = trndlevel(knable);

        if (level > knable->level) {
            /* Assuming Dirty Hack, level == knable->level + 1. */
            knable->level++;
            update[level] = knable->header;
        }
        kentry = newentry(level, name, value);
        /* Place the entry in the skip list. */
        for (i = 0; i <= level; i++) {
            kentry->next[i] = update[i]->next[i];
            update[i]->next[i] = kentry;
        }
    }
}
예제 #8
0
void map_put(map_t *map, void *key, void *value)
{
    unsigned long hash = map->hashfunc(key);
    int b = hash % map->numbuckets;
    mapentry_t *e = map->buckets[b];

    while (e != NULL && map->cmpfunc(key, e->key) != 0)
    {
        e = e->next;
    }
    if (e == NULL)
    {
        map->buckets[b] = newentry(key, value, map->buckets[b]);
        map->size++;
        if (map->size >= map->numbuckets)
            growmap(map);
    }
    else
    {
        e->value = value;   
    }
}
예제 #9
0
int ordersfrm::init()
{
    int r = this->checkrights();
    if(r == 1)
		btnadd->setEnabled(FALSE);
    if(r==0)
		QMessageBox::information(0, tr("Authorization Required..."), tr("You are not authorized to open this modul\n\nPlease contact your Administrator")); 

	treeindex->header()->setResizeMode(0, QHeaderView::Stretch);
	treeindex->setColumnWidth(1, 50);
	treeindex->setColumnHidden(2, TRUE);
	
	treemain->setColumnWidth(0, 40);
	
    vars v;
    QStringList sgeo = v.loadgeo(this->objectName());
    if(sgeo.size() > 0	)
    {
        if(sgeo[0] == "1")
			this->setWindowState(this->windowState() ^ Qt::WindowMaximized);
	    this->setGeometry(sgeo[1].toInt(), sgeo[2].toInt(), sgeo[3].toInt(), sgeo[4].toInt());
   	}
    
   	lbluser->setText(username);
   	progbar->setMaximum(1);
   	progbar->setValue(1);
    this->countentries();

	connect(treeindex, SIGNAL(itemClicked ( QTreeWidgetItem*, int)), this, SLOT(loadentries()));
	connect(btnadd, SIGNAL(released()), this, SLOT(newentry()));
	connect(btnedit, SIGNAL(released()), this, SLOT(editentry()));
	connect(btndelete, SIGNAL(released()), this, SLOT(deleteentry()));
	connect(btncompleted, SIGNAL(released()), this, SLOT(complete()));
	connect(treemain, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contmenu()));
	connect(btnclose, SIGNAL(released()), this, SLOT(close()));

    return r;
}
예제 #10
0
startproc(Extsym *progname, int Class)
#endif
{
	register struct Entrypoint *p;

	p = ALLOC(Entrypoint);
	if(Class == CLMAIN) {
		puthead(CNULL, CLMAIN);
		if (progname)
		    strcpy (main_alias, progname->cextname);
	} else {
		if (progname) {
			/* Construct an empty subroutine with this name */
			/* in case the name is needed to force loading */
			/* of this block-data subprogram: the name can */
			/* appear elsewhere in an external statement. */
			entrypt(CLPROC, TYSUBR, (ftnint)0, progname, (chainp)0);
			endproc();
			newproc();
			}
		puthead(CNULL, CLBLOCK);
		}
	if(Class == CLMAIN)
		newentry( mkname(" MAIN"), 0 )->extinit = 1;
	p->entryname = progname;
	entries = p;

	procclass = Class;
	fprintf(diagfile, "   %s", (Class==CLMAIN ? "MAIN" : "BLOCK DATA") );
	if(progname) {
		fprintf(diagfile, " %s", progname->fextname);
		procname = progname->cextname;
		}
	fprintf(diagfile, ":\n");
	fflush(diagfile);
}
예제 #11
0
struct smackentry* opensmackentry(const char *username)
{
	FILE *fp;
	char   *line;
	size_t linelen;
	struct smackentry *entry = NULL;

	fp = fopen(SMACK_USERS, "r");
	if (!fp) {
		perror("opening " SMACK_USERS);
		errno = ENOSYS;
		return NULL;
	}

	line = malloc(32); // because it should suffice in theory
	linelen = 32;
	errno = ENOENT;
	while (getline(&line, &linelen, fp) != -1)
	{
		const char *userstart = NULL;
		const char *labelstart = NULL;

		char *inl = line;

		// skip initial whitespace
		while (isspace(*inl))
			++inl;

		if (!*inl)
			continue;

		// extract username:
		userstart = inl;
		// it may not be "standard" but nothing keeps me from using
		// _ or - in /etc/passwd
		while (isalpha(*inl) || *inl == '_' || *inl == '-')
			++inl;
		// insert a nulbyte to end the username
		*inl = '\0';
		++inl;

		// Check the username now
		if (strcmp(username, userstart))
			continue;

		while (isspace(*inl))
			++inl;

		if (!*inl)
			continue;

		// extract all labels:

		entry = newentry(username);
		do
		{
			labelstart = inl;
			while (*inl && !isspace(*inl))
				++inl;
			if (!*inl) {
				// end of line
				addentry(entry, labelstart);
				break;
			}
			// more following:
			*inl = '\0';
			addentry(entry, labelstart);
			++inl;
			while (isspace(*inl))
				++inl;
		} while(*inl);
		break;
	}

	free(line);
	fclose(fp);
	return entry;
}
예제 #12
0
void
register_hash(char *buf, struct sockaddr_in *from_addr)
{
	tracker_register_t	*req = (tracker_register_t *)buf;
	hash_info_t		*hashinfo;
	tracker_info_t		*reqinfo;
	uint16_t		numpeers;
	peer_t			dynamic_peers[1];
	peer_t			*peers;
	int			i, j, k;

	for (i = 0; i < req->numhashes; ++i) {
		reqinfo = &req->info[i];
#ifdef	LATER
		fprintf(stderr,
			"register_hash:enter:hash (0x%llx)\n", reqinfo->hash);
		fprintf(stderr, "register_hash:hash_table:before\n\n");
		print_hash_table();
#endif

		if (reqinfo->numpeers == 0) {
			/*
			 * no peer specified. dynamically determine
			 * the peer IP address from the host who
			 * sent us the message
			 */
			numpeers = 1;
			dynamic_peers[0].ip = from_addr->sin_addr.s_addr;
			peers = dynamic_peers;
		} else {
			numpeers = reqinfo->numpeers;
			peers = reqinfo->peers;
		}

#ifdef	DEBUG
		fprintf(stderr, "register_hash:numpeers:1 (0x%d)\n", numpeers);
#endif

		/*
		 * scan the list for this hash.
		 */
		if ((hashinfo = getpeers(reqinfo->hash, NULL)) != NULL) {
			/*
			 * this hash is already in the table, see if this peer
			 * is already in the list
			 */
			for (j = 0 ; j < numpeers ; ++j) {
				int	found = 0;
		
				for (k = 0 ; k < hashinfo->numpeers ; ++k) {
					if (peers[j].ip ==
							hashinfo->peers[k].ip) {
						found = 1;
						hashinfo->peers[k].state =
							READY;
						break;
					}
				}

				if (!found) {
					peers[j].state = READY;
#ifdef	DEBUG
					fprintf(stderr, "register_hash:calling addpeer:1\n");
#endif
					addpeer(hashinfo, &peers[j]);
				}
			}
		} else {
			/*
			 * if not, then add this hash to the end of the list
			 */
			if ((hashinfo = newentry()) == NULL) {
				fprintf(stderr,
					"register_hash:newentry:failed\n");
				abort();
			}

			hashinfo->hash = reqinfo->hash;
			hashinfo->numpeers = 0;

			for (j = 0 ; j < numpeers ; ++j) {
				peers[j].state = READY;
#ifdef	DEBUG
				fprintf(stderr,
					"register_hash:calling addpeer:2\n");
#endif
				addpeer(hashinfo, &peers[j]);
			}
		}
#ifdef	LATER
	fprintf(stderr, "register_hash:hash_table:after\n\n");
	print_hash_table();
#endif

#ifdef	DEBUG
	fprintf(stderr, "register_hash:exit:hash (0x%llx)\n", reqinfo->hash);
#endif
	}
}
예제 #13
0
void
dolookup(int sockfd, uint64_t hash, uint32_t seqno,
	struct sockaddr_in *from_addr)
{
	tracker_lookup_resp_t	*resp;
	tracker_info_t		*respinfo;
	hash_info_t		*hashinfo;
	hash_info_t		*predhashinfo;
	size_t			len;
	int			j;
	int			flags;
	int			index, next_index;
	char			found;
	char			buf[64*1024];

	resp = (tracker_lookup_resp_t *)buf;
	resp->header.op = LOOKUP;
	resp->header.seqno = seqno;

	/*
	 * keep a running count for the length of the data
	 */
	len = sizeof(tracker_lookup_resp_t);

	/*
	 * look up info for this hash
	 */
	respinfo = (tracker_info_t *)resp->info;
	respinfo->hash = hash;

	len += sizeof(tracker_info_t);

	/*
	 * always send back at least one hash, even if it is empty (i.e.,
	 * it has no peers.
	 */
	resp->numhashes = 1;

	found = 0;

	if ((hashinfo = getpeers(hash, &index)) != NULL) {
		/*
		 * shuffle the peers
		 */
		prep_peers(hashinfo, respinfo, from_addr, &found);

		if (respinfo->numpeers > 0) {
			avalanche_log(respinfo->peers[0].ip, from_addr->sin_addr.s_addr, hash);
		}

#ifdef	DEBUG
		fprintf(stderr,
			"resp info numpeers (%d)\n", respinfo->numpeers);
#endif

		len += (sizeof(respinfo->peers[0]) * respinfo->numpeers);

		respinfo = (tracker_info_t *)
			(&(respinfo->peers[respinfo->numpeers]));

		/*
		 * now get hash info for the "predicted" next file downloads
		 */
		next_index = index;
		for (j = 0 ; j < PREDICTIONS ; ++j) {
			if ((predhashinfo = getnextpeers(hash, &next_index))
					!= NULL) {

				if (index == next_index) {
					/*
					 * there are less than 'PREDICTIONS'
					 * number of valid hash entries and
					 * we've examined them all. break out
					 * of this loop.
					 */
					break;
				}

				prep_peers(predhashinfo, respinfo, from_addr,
					NULL);

				if (respinfo->numpeers > 0) {
					avalanche_log(respinfo->peers[0].ip,
						      from_addr->sin_addr.s_addr,
						      predhashinfo->hash);
				}
			} else {
				/*
				 * no more valid hashes
				 */
				break;
			}

			len += sizeof(tracker_info_t) +
				(sizeof(respinfo->peers[0]) *
					respinfo->numpeers);

			respinfo = (tracker_info_t *)
				(&(respinfo->peers[respinfo->numpeers]));

			++resp->numhashes;
		}

#ifdef	DEBUG
	fprintf(stderr, "len (%d)\n", (int)len);
#endif

	} else {
		/*
		 * this hash is not in the table, so let's add it.
		 */
		if ((hashinfo = newentry()) == NULL) {
			fprintf(stderr, "dolookup:newentry:failed\n");
			abort();
		}

		hashinfo->hash = hash;
		hashinfo->numpeers = 0;

		respinfo->numpeers = 0;

		avalanche_log(ntohl(INADDR_LOOPBACK), from_addr->sin_addr.s_addr, hash);
	}

	if (!found) {
		peer_t	newpeer;

		/*
		 * the client has made a 'lookup' request which means the client
		 * will soon be downloading the file. let's add this peer to
		 * the hash and mark this peer as 'downloading'.
		 */
		newpeer.ip = from_addr->sin_addr.s_addr;
		newpeer.state = DOWNLOADING;
#ifdef	DEBUG
		fprintf(stderr, "dolookup:calling addpeer\n");
#endif

		addpeer(hashinfo, &newpeer);
	}

#ifdef	DEBUG
	fprintf(stderr, "dolookup:numhashes (%d)\n", resp->numhashes);
#endif

	resp->header.length = len;

#ifdef	DEBUG
	fprintf(stderr, "send buf: ");
	dumpbuf((char *)resp, len);
#endif

	flags = 0;
	sendto(sockfd, buf, len, flags, (struct sockaddr *)from_addr,
		sizeof(*from_addr));

#ifdef	DEBUG
	fprintf(stderr, "dolookup:exit:hash (0x%llx)\n", hash);
#endif

	return;
}
예제 #14
0
파일: newhelp.c 프로젝트: Aconex/pcp
int
main(int argc, char **argv)
{
    int		n;
    int		c;
    int		i;
    int		sts;
    char	*pmnsfile = PM_NS_DEFAULT;
    char	*fname = NULL;
    char	pathname[MAXPATHLEN];
    FILE	*inf;
    char	buf[MAXENTRY+MAXLINE];
    char	*endnum;
    char	*bp;
    char	*p;
    int		skip;
    help_idx_t	hdr;

    while ((c = pmgetopt_r(argc, argv, &opts)) != EOF) {
	switch (c) {

	case 'D':	/* debug flag */
	    if ((sts = __pmParseDebug(opts.optarg)) < 0) {
		pmprintf("%s: unrecognized debug flag specification (%s)\n",
		    pmProgname, opts.optarg);
		opts.errors++;
	    }
	    else
		pmDebug |= sts;
	    break;

	case 'n':	/* alternative namespace file */
	    pmnsfile = opts.optarg;
	    break;

	case 'o':	/* alternative output file name */
	    fname = opts.optarg;
	    break;

	case 'V':	/* more chit-chat */
	    verbose++;
	    break;

	case 'v':	/* version 2 only these days */
	    version = (int)strtol(opts.optarg, &endnum, 10);
	    if (*endnum != '\0') {
		pmprintf("%s: -v requires numeric argument\n", pmProgname);
		opts.errors++;
	    }
	    if (version != 2) {
		pmprintf("%s: deprecated option - only version 2 is supported\n",
			pmProgname);
		opts.errors++;
	    }
	    break;

	case '?':
	default:
	    opts.errors++;
	    break;
	}
    }

    if (opts.errors) {
	pmUsageMessage(&opts);
	exit(2);
    }

    if ((n = pmLoadNameSpace(pmnsfile)) < 0) {
	fprintf(stderr, "%s: pmLoadNameSpace: %s\n", pmProgname, pmErrStr(n));
	exit(2);
    }

    do {
	if (opts.optind < argc) {
	    filename = argv[opts.optind];
	    if ((inf = fopen(filename, "r")) == NULL) {
		perror(filename);
		exit(2);
	    }
	    if (fname == NULL)
		fname = filename;
	}
	else {
	    if (fname == NULL) {
		fprintf(stderr, 
			"%s: need either a -o option or a filename "
			"argument to name the output file\n", pmProgname);
		exit(2);
	    }
	    filename = "<stdin>";
	    inf = stdin;
	}

	if (version == 2 && f == NULL) {
	    sprintf(pathname, "%s.pag", fname);
	    if ((f = fopen(pathname, "w")) == NULL) {
		fprintf(stderr, "%s: fopen(\"%s\", ...) failed: %s\n",
		    pmProgname, pathname, osstrerror());
		exit(2);
	    }
	    /* header: 2 => pag cf 1 => dir */
	    fprintf(f, "PcPh2%c\n", '0' + version);
	}

	bp = buf;
	skip = 1;
	for ( ; ; ) {
	    if (fgets(bp, MAXLINE, inf) == NULL) {
		skip = -1;
		*bp = '@';
	    }
	    ln++;
	    if (bp[0] == '#')
		continue;
	    if (bp[0] == '@') {
		/* start of a new entry */
		if (bp > buf) {
		    /* really have a prior entry */
		    p = bp - 1;
		    while (p > buf && *p == '\n')
			p--;
		    *++p = '\n';
		    *++p = '\0';
		    newentry(buf);
		}
		if (skip == -1)
		    break;
		skip = 0;
		bp++;	/* skip '@' */
		while (*bp && isspace((int)*bp))
		    bp++;
		if (bp[0] == '\0') {
		    if (verbose)
			fprintf(stderr, "%s: [%s:%d] null entry?\n", 
				pmProgname, filename, ln);
		    skip = 1;
		    bp = buf;
		    if (!status) status = 1;
		}
		else {
		    for (p = bp; *p; p++)
			;
		    memmove(buf, bp, p - bp + 1);
		    for (bp = buf; *bp; bp++)
			;
		}
	    }
	    if (skip)
		continue;
	    for (p = bp; *p; p++)
		;
	    if (bp > buf && p[-1] != '\n') {
		*p++ = '\n';
		*p = '\0';
		fprintf(stderr, "%s: [%s:%d] long line split after ...\n%s",
			    pmProgname, filename, ln, buf);
		ln--;
		if (!status) status = 1;
	    }
	    bp = p;
	    if (bp > &buf[MAXENTRY]) {
		bp = &buf[MAXENTRY];
		bp[-1] = '\0';
		bp[-2] = '\n';
		fprintf(stderr, "%s: [%s:%d] entry truncated after ... %s",
			    pmProgname, filename, ln, &bp[-64]);
		skip = 1;
		if (!status) status = 1;
	    }
	}

	fclose(inf);
	opts.optind++;
    } while (opts.optind < argc);

    if (f != NULL) {
	fclose(f);

	/* do the directory index ... */
	sprintf(pathname, "%s.dir", fname);
	if ((f = fopen(pathname, "w")) == NULL) {
	    fprintf(stderr, "%s: fopen(\"%s\", ...) failed: %s\n",
		pmProgname, pathname, osstrerror());
	    exit(2);
	}

	/* index header */
	hdr.pmid = 0x50635068;		/* "PcPh" */
	/* "1" => dir, next char is version */
	hdr.off_oneline = 0x31000000 | (('0' + version) << 16);
	hdr.off_text = thisindex + 1;	/* # entries */
	if (fwrite(&hdr, sizeof(hdr), 1, f) != 1 || ferror(f)) {
	     fprintf(stderr, "%s: fwrite index failed: %s\n",
		     pmProgname, osstrerror());
	     exit(2);
	}

	/* sort and write index */
	qsort((void *)hindex, thisindex+1, sizeof(hindex[0]), idcomp);
	for (i = 0; i <= thisindex; i++) {
	    if (fwrite(&hindex[i], sizeof(hindex[0]), 1, f) != 1
		|| ferror(f)) {
		 fprintf(stderr, "%s: fwrite index failed: %s\n",
			 pmProgname, osstrerror());
		 exit(2);
	    }
	}
    }

    exit(status);
}