Upload folder using huggingface_hub (part 79)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard007/C/0124233_tag.c +157 -0
- pool/shard007/C/0124242_mkfifo.c +47 -0
- pool/shard007/C/0124243_top9000.c +296 -0
- pool/shard007/C/0124245_reverse_singly_linked_list.c +69 -0
- pool/shard007/C/0124247_main.c +38 -0
- pool/shard007/C/0124248_vm.c +95 -0
- pool/shard007/C/0124252_cmain.c +167 -0
- pool/shard007/C/0124253_vector_realmonitor.c +22 -0
- pool/shard007/C/0124255_pth_cvsimple.c +78 -0
- pool/shard007/C/0124256_gauge_info.c +93 -0
- pool/shard007/C/0124257_Cancion.c +177 -0
- pool/shard007/C/0124266_watchdog.c +147 -0
- pool/shard007/C/0124267_finddomain.c +214 -0
- pool/shard007/C/0124268_dewarptest2.c +108 -0
- pool/shard007/C/0124269_pp_program.c +140 -0
- pool/shard007/C/0124270_duk_hthread_misc.c +49 -0
- pool/shard007/C/0124271_md5_test.c +100 -0
- pool/shard007/C/0124273_vl_ihashsum.c +240 -0
- pool/shard007/C/0124274_outputKeystroke.c +112 -0
- pool/shard007/C/0124275_parseiptables.c +212 -0
- pool/shard007/C/0124279_t-exp_taylor_sum.c +85 -0
- pool/shard007/C/0124280_list.c +191 -0
- pool/shard007/C/0124282_test_bos.c +244 -0
- pool/shard007/C/0124283_stm32f7xx_hal_timebase_rtc_wakeup_template.c +291 -0
- pool/shard007/C/0124284_asp.c +38 -0
- pool/shard007/C/0124287_nf_nat_tftp.c +56 -0
- pool/shard007/C/0124293_ping.c +145 -0
- pool/shard007/C/0124295_gpio.c +197 -0
- pool/shard007/C/0124297_vikexttool.c +209 -0
- pool/shard007/C/0124298_netbuf.c +245 -0
- pool/shard007/C/0124299_usbd_hid_dance_mouse.c +115 -0
- pool/shard007/C/0124301_test-column.c +180 -0
- pool/shard007/C/0124302_temp_to_file_voice.c +43 -0
- pool/shard007/C/0124304_vega20_baco.c +122 -0
- pool/shard007/C/0124305_pcm512x-spi.c +69 -0
- pool/shard007/C/0124306_pthread_getattr_np.c +179 -0
- pool/shard007/C/0124308_sysinit.c +124 -0
- pool/shard007/C/0124314_main.c +200 -0
- pool/shard007/C/0124319_csp_if_fifo_windows.c +225 -0
- pool/shard007/C/0124323_gpio.c +182 -0
- pool/shard007/C/0124325_md4_one.c +97 -0
- pool/shard007/C/0124326_soc-utils.c +178 -0
- pool/shard007/C/0124331_pvdpv.c +102 -0
- pool/shard007/C/0124332_metadata.c +65 -0
- pool/shard007/C/0124338_splitimage2pdf.c +129 -0
- pool/shard007/C/0124339_wb_next_pwent.c +201 -0
- pool/shard007/C/0124341_nspr_timer.c +91 -0
- pool/shard007/C/0124350_ext-toolchain-wrapper.c +172 -0
- pool/shard007/C/0124353_null_cipher.c +156 -0
- pool/shard007/C/0124355_bsmesh10.c +75 -0
pool/shard007/C/0124233_tag.c
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "cache.h"
|
| 2 |
+
#include "tag.h"
|
| 3 |
+
#include "commit.h"
|
| 4 |
+
#include "tree.h"
|
| 5 |
+
#include "blob.h"
|
| 6 |
+
|
| 7 |
+
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
|
| 8 |
+
#define PGP_MESSAGE "-----BEGIN PGP MESSAGE-----"
|
| 9 |
+
|
| 10 |
+
const char *tag_type = "tag";
|
| 11 |
+
|
| 12 |
+
struct object *deref_tag(struct object *o, const char *warn, int warnlen)
|
| 13 |
+
{
|
| 14 |
+
while (o && o->type == OBJ_TAG)
|
| 15 |
+
if (((struct tag *)o)->tagged)
|
| 16 |
+
o = parse_object(((struct tag *)o)->tagged->sha1);
|
| 17 |
+
else
|
| 18 |
+
o = NULL;
|
| 19 |
+
if (!o && warn) {
|
| 20 |
+
if (!warnlen)
|
| 21 |
+
warnlen = strlen(warn);
|
| 22 |
+
error("missing object referenced by '%.*s'", warnlen, warn);
|
| 23 |
+
}
|
| 24 |
+
return o;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
struct tag *lookup_tag(const unsigned char *sha1)
|
| 28 |
+
{
|
| 29 |
+
struct object *obj = lookup_object(sha1);
|
| 30 |
+
if (!obj)
|
| 31 |
+
return create_object(sha1, OBJ_TAG, alloc_tag_node());
|
| 32 |
+
if (!obj->type)
|
| 33 |
+
obj->type = OBJ_TAG;
|
| 34 |
+
if (obj->type != OBJ_TAG) {
|
| 35 |
+
error("Object %s is a %s, not a tag",
|
| 36 |
+
sha1_to_hex(sha1), typename(obj->type));
|
| 37 |
+
return NULL;
|
| 38 |
+
}
|
| 39 |
+
return (struct tag *) obj;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
static unsigned long parse_tag_date(const char *buf, const char *tail)
|
| 43 |
+
{
|
| 44 |
+
const char *dateptr;
|
| 45 |
+
|
| 46 |
+
while (buf < tail && *buf++ != '>')
|
| 47 |
+
/* nada */;
|
| 48 |
+
if (buf >= tail)
|
| 49 |
+
return 0;
|
| 50 |
+
dateptr = buf;
|
| 51 |
+
while (buf < tail && *buf++ != '\n')
|
| 52 |
+
/* nada */;
|
| 53 |
+
if (buf >= tail)
|
| 54 |
+
return 0;
|
| 55 |
+
/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
|
| 56 |
+
return strtoul(dateptr, NULL, 10);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
|
| 60 |
+
{
|
| 61 |
+
unsigned char sha1[HASH_OCTETS];
|
| 62 |
+
char type[HASH_OCTETS];
|
| 63 |
+
const char *bufptr = data;
|
| 64 |
+
const char *tail = bufptr + size;
|
| 65 |
+
const char *nl;
|
| 66 |
+
|
| 67 |
+
if (item->object.parsed)
|
| 68 |
+
return 0;
|
| 69 |
+
item->object.parsed = 1;
|
| 70 |
+
|
| 71 |
+
if (size < 64)
|
| 72 |
+
return -1;
|
| 73 |
+
if (memcmp("object ", bufptr, 7) || get_sha1_hex(bufptr + 7, sha1) || bufptr[47] != '\n')
|
| 74 |
+
return -1;
|
| 75 |
+
bufptr += 48; /* "object " + sha1 + "\n" */
|
| 76 |
+
|
| 77 |
+
if (prefixcmp(bufptr, "type "))
|
| 78 |
+
return -1;
|
| 79 |
+
bufptr += 5;
|
| 80 |
+
nl = memchr(bufptr, '\n', tail - bufptr);
|
| 81 |
+
if (!nl || sizeof(type) <= (nl - bufptr))
|
| 82 |
+
return -1;
|
| 83 |
+
strncpy(type, bufptr, nl - bufptr);
|
| 84 |
+
type[nl - bufptr] = '\0';
|
| 85 |
+
bufptr = nl + 1;
|
| 86 |
+
|
| 87 |
+
if (!strcmp(type, blob_type)) {
|
| 88 |
+
item->tagged = &lookup_blob(sha1)->object;
|
| 89 |
+
} else if (!strcmp(type, tree_type)) {
|
| 90 |
+
item->tagged = &lookup_tree(sha1)->object;
|
| 91 |
+
} else if (!strcmp(type, commit_type)) {
|
| 92 |
+
item->tagged = &lookup_commit(sha1)->object;
|
| 93 |
+
} else if (!strcmp(type, tag_type)) {
|
| 94 |
+
item->tagged = &lookup_tag(sha1)->object;
|
| 95 |
+
} else {
|
| 96 |
+
error("Unknown type %s", type);
|
| 97 |
+
item->tagged = NULL;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
if (bufptr + 4 < tail && !prefixcmp(bufptr, "tag "))
|
| 101 |
+
; /* good */
|
| 102 |
+
else
|
| 103 |
+
return -1;
|
| 104 |
+
bufptr += 4;
|
| 105 |
+
nl = memchr(bufptr, '\n', tail - bufptr);
|
| 106 |
+
if (!nl)
|
| 107 |
+
return -1;
|
| 108 |
+
item->tag = xmemdupz(bufptr, nl - bufptr);
|
| 109 |
+
bufptr = nl + 1;
|
| 110 |
+
|
| 111 |
+
if (bufptr + 7 < tail && !prefixcmp(bufptr, "tagger "))
|
| 112 |
+
item->date = parse_tag_date(bufptr, tail);
|
| 113 |
+
else
|
| 114 |
+
item->date = 0;
|
| 115 |
+
|
| 116 |
+
return 0;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
int parse_tag(struct tag *item)
|
| 120 |
+
{
|
| 121 |
+
enum object_type type;
|
| 122 |
+
void *data;
|
| 123 |
+
unsigned long size;
|
| 124 |
+
int ret;
|
| 125 |
+
|
| 126 |
+
if (item->object.parsed)
|
| 127 |
+
return 0;
|
| 128 |
+
data = read_sha1_file(item->object.sha1, &type, &size);
|
| 129 |
+
if (!data)
|
| 130 |
+
return error("Could not read %s",
|
| 131 |
+
sha1_to_hex(item->object.sha1));
|
| 132 |
+
if (type != OBJ_TAG) {
|
| 133 |
+
free(data);
|
| 134 |
+
return error("Object %s not a tag",
|
| 135 |
+
sha1_to_hex(item->object.sha1));
|
| 136 |
+
}
|
| 137 |
+
ret = parse_tag_buffer(item, data, size);
|
| 138 |
+
free(data);
|
| 139 |
+
return ret;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
/*
|
| 143 |
+
* Look at a signed tag object, and return the offset where
|
| 144 |
+
* the embedded detached signature begins, or the end of the
|
| 145 |
+
* data when there is no such signature.
|
| 146 |
+
*/
|
| 147 |
+
size_t parse_signature(const char *buf, unsigned long size)
|
| 148 |
+
{
|
| 149 |
+
char *eol;
|
| 150 |
+
size_t len = 0;
|
| 151 |
+
while (len < size && prefixcmp(buf + len, PGP_SIGNATURE) &&
|
| 152 |
+
prefixcmp(buf + len, PGP_MESSAGE)) {
|
| 153 |
+
eol = memchr(buf + len, '\n', size - len);
|
| 154 |
+
len += eol ? eol - (buf + len) + 1 : size - len;
|
| 155 |
+
}
|
| 156 |
+
return len;
|
| 157 |
+
}
|
pool/shard007/C/0124242_mkfifo.c
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* See LICENSE file for copyright and license details. */
|
| 2 |
+
#include <sys/stat.h>
|
| 3 |
+
|
| 4 |
+
#include <stdlib.h>
|
| 5 |
+
|
| 6 |
+
#include "util.h"
|
| 7 |
+
|
| 8 |
+
static void
|
| 9 |
+
usage(void)
|
| 10 |
+
{
|
| 11 |
+
eprintf("usage: %s [-m mode] name ...\n", argv0);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
int
|
| 15 |
+
main(int argc, char *argv[])
|
| 16 |
+
{
|
| 17 |
+
mode_t mode = 0, mask;
|
| 18 |
+
int mflag = 0, ret = 0;
|
| 19 |
+
|
| 20 |
+
ARGBEGIN {
|
| 21 |
+
case 'm':
|
| 22 |
+
mflag = 1;
|
| 23 |
+
mask = getumask();
|
| 24 |
+
mode = parsemode(EARGF(usage()), mode, mask);
|
| 25 |
+
break;
|
| 26 |
+
default:
|
| 27 |
+
usage();
|
| 28 |
+
} ARGEND
|
| 29 |
+
|
| 30 |
+
if (!argc)
|
| 31 |
+
usage();
|
| 32 |
+
|
| 33 |
+
for (; *argv; argc--, argv++) {
|
| 34 |
+
if (mkfifo(*argv, S_IRUSR | S_IWUSR | S_IRGRP |
|
| 35 |
+
S_IWGRP | S_IROTH | S_IWOTH) < 0) {
|
| 36 |
+
weprintf("mkfifo %s:", *argv);
|
| 37 |
+
ret = 1;
|
| 38 |
+
} else if (mflag) {
|
| 39 |
+
if (chmod(*argv, mode) < 0) {
|
| 40 |
+
weprintf("chmod %s:", *argv);
|
| 41 |
+
ret = 1;
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return ret;
|
| 47 |
+
}
|
pool/shard007/C/0124243_top9000.c
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* (C) Copyright 2007-2008
|
| 3 |
+
* Stelian Pop <stelian@popies.net>
|
| 4 |
+
* Lead Tech Design <www.leadtechdesign.com>
|
| 5 |
+
*
|
| 6 |
+
* (C) Copyright 2010
|
| 7 |
+
* Reinhard Meyer, EMK Elektronik, reinhard.meyer@emk-elektronik.de
|
| 8 |
+
*
|
| 9 |
+
* See file CREDITS for list of people who contributed to this
|
| 10 |
+
* project.
|
| 11 |
+
*
|
| 12 |
+
* This program is free software; you can redistribute it and/or
|
| 13 |
+
* modify it under the terms of the GNU General Public License as
|
| 14 |
+
* published by the Free Software Foundation; either version 2 of
|
| 15 |
+
* the License, or (at your option) any later version.
|
| 16 |
+
*
|
| 17 |
+
* This program is distributed in the hope that it will be useful,
|
| 18 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 20 |
+
* GNU General Public License for more details.
|
| 21 |
+
*
|
| 22 |
+
* You should have received a copy of the GNU General Public License
|
| 23 |
+
* along with this program; if not, write to the Free Software
|
| 24 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
| 25 |
+
* MA 02111-1307 USA
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
#include <common.h>
|
| 29 |
+
#include <net.h>
|
| 30 |
+
#include <netdev.h>
|
| 31 |
+
#include <mmc.h>
|
| 32 |
+
#include <i2c.h>
|
| 33 |
+
#include <spi.h>
|
| 34 |
+
#include <asm/io.h>
|
| 35 |
+
#include <asm/arch/hardware.h>
|
| 36 |
+
#include <asm/arch/at91sam9260_matrix.h>
|
| 37 |
+
#include <asm/arch/at91sam9_smc.h>
|
| 38 |
+
#include <asm/arch/at91_common.h>
|
| 39 |
+
#include <asm/arch/at91_pmc.h>
|
| 40 |
+
#include <asm/arch/at91_rstc.h>
|
| 41 |
+
#include <asm/arch/at91_shdwn.h>
|
| 42 |
+
#include <asm/arch/gpio.h>
|
| 43 |
+
|
| 44 |
+
DECLARE_GLOBAL_DATA_PTR;
|
| 45 |
+
|
| 46 |
+
#ifdef CONFIG_CMD_NAND
|
| 47 |
+
static void nand_hw_init(void)
|
| 48 |
+
{
|
| 49 |
+
struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
|
| 50 |
+
struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
|
| 51 |
+
unsigned long csa;
|
| 52 |
+
|
| 53 |
+
/* Assign CS3 to NAND/SmartMedia Interface */
|
| 54 |
+
csa = readl(&matrix->ebicsa);
|
| 55 |
+
csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
|
| 56 |
+
writel(csa, &matrix->ebicsa);
|
| 57 |
+
|
| 58 |
+
/* Configure SMC CS3 for NAND/SmartMedia */
|
| 59 |
+
writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
|
| 60 |
+
AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
|
| 61 |
+
&smc->cs[3].setup);
|
| 62 |
+
writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
|
| 63 |
+
AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
|
| 64 |
+
&smc->cs[3].pulse);
|
| 65 |
+
writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
|
| 66 |
+
&smc->cs[3].cycle);
|
| 67 |
+
writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
|
| 68 |
+
AT91_SMC_MODE_EXNW_DISABLE |
|
| 69 |
+
AT91_SMC_MODE_DBW_8 |
|
| 70 |
+
AT91_SMC_MODE_TDF_CYCLE(2),
|
| 71 |
+
&smc->cs[3].mode);
|
| 72 |
+
|
| 73 |
+
/* Configure RDY/BSY */
|
| 74 |
+
at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
|
| 75 |
+
|
| 76 |
+
/* Enable NandFlash */
|
| 77 |
+
at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
|
| 78 |
+
}
|
| 79 |
+
#endif
|
| 80 |
+
|
| 81 |
+
#ifdef CONFIG_MACB
|
| 82 |
+
static void macb_hw_init(void)
|
| 83 |
+
{
|
| 84 |
+
struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
|
| 85 |
+
|
| 86 |
+
/* Enable EMAC clock */
|
| 87 |
+
writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
|
| 88 |
+
|
| 89 |
+
/* Initialize EMAC=MACB hardware */
|
| 90 |
+
at91_macb_hw_init();
|
| 91 |
+
}
|
| 92 |
+
#endif
|
| 93 |
+
|
| 94 |
+
#ifdef CONFIG_GENERIC_ATMEL_MCI
|
| 95 |
+
/* this is a weak define that we are overriding */
|
| 96 |
+
int board_mmc_init(bd_t *bd)
|
| 97 |
+
{
|
| 98 |
+
struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
|
| 99 |
+
|
| 100 |
+
/* Enable MCI clock */
|
| 101 |
+
writel(1 << ATMEL_ID_MCI, &pmc->pcer);
|
| 102 |
+
|
| 103 |
+
/* Initialize MCI hardware */
|
| 104 |
+
at91_mci_hw_init();
|
| 105 |
+
|
| 106 |
+
/* This calls the atmel_mmc_init in gen_atmel_mci.c */
|
| 107 |
+
return atmel_mci_init((void *)ATMEL_BASE_MCI);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/* this is a weak define that we are overriding */
|
| 111 |
+
int board_mmc_getcd(u8 *cd, struct mmc *mmc)
|
| 112 |
+
{
|
| 113 |
+
/*
|
| 114 |
+
* the only currently existing use of this function
|
| 115 |
+
* (fsl_esdhc.c) suggests this function must return
|
| 116 |
+
* *cs = TRUE if a card is NOT detected -> in most
|
| 117 |
+
* cases the value of the pin when the detect switch
|
| 118 |
+
* closes to GND
|
| 119 |
+
*/
|
| 120 |
+
*cd = at91_get_gpio_value(CONFIG_SYS_MMC_CD_PIN) ? 1 : 0;
|
| 121 |
+
return 0;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
#endif
|
| 125 |
+
|
| 126 |
+
int board_early_init_f(void)
|
| 127 |
+
{
|
| 128 |
+
struct at91_shdwn *shdwn = (struct at91_shdwn *)ATMEL_BASE_SHDWN;
|
| 129 |
+
struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
|
| 130 |
+
|
| 131 |
+
/*
|
| 132 |
+
* make sure the board can be powered on by
|
| 133 |
+
* any transition on WKUP
|
| 134 |
+
*/
|
| 135 |
+
writel(AT91_SHDW_MR_WKMODE0H2L | AT91_SHDW_MR_WKMODE0L2H,
|
| 136 |
+
&shdwn->mr);
|
| 137 |
+
|
| 138 |
+
/* Enable clocks for all PIOs */
|
| 139 |
+
writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
|
| 140 |
+
(1 << ATMEL_ID_PIOC),
|
| 141 |
+
&pmc->pcer);
|
| 142 |
+
|
| 143 |
+
/* set SCL0 and SDA0 to open drain */
|
| 144 |
+
at91_set_pio_output(I2C0_PORT, SCL0_PIN, 1);
|
| 145 |
+
at91_set_pio_multi_drive(I2C0_PORT, SCL0_PIN, 1);
|
| 146 |
+
at91_set_pio_pullup(I2C0_PORT, SCL0_PIN, 1);
|
| 147 |
+
at91_set_pio_output(I2C0_PORT, SDA0_PIN, 1);
|
| 148 |
+
at91_set_pio_multi_drive(I2C0_PORT, SDA0_PIN, 1);
|
| 149 |
+
at91_set_pio_pullup(I2C0_PORT, SDA0_PIN, 1);
|
| 150 |
+
|
| 151 |
+
/* set SCL1 and SDA1 to open drain */
|
| 152 |
+
at91_set_pio_output(I2C1_PORT, SCL1_PIN, 1);
|
| 153 |
+
at91_set_pio_multi_drive(I2C1_PORT, SCL1_PIN, 1);
|
| 154 |
+
at91_set_pio_pullup(I2C1_PORT, SCL1_PIN, 1);
|
| 155 |
+
at91_set_pio_output(I2C1_PORT, SDA1_PIN, 1);
|
| 156 |
+
at91_set_pio_multi_drive(I2C1_PORT, SDA1_PIN, 1);
|
| 157 |
+
at91_set_pio_pullup(I2C1_PORT, SDA1_PIN, 1);
|
| 158 |
+
return 0;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
int board_init(void)
|
| 162 |
+
{
|
| 163 |
+
/* arch number of TOP9000 Board */
|
| 164 |
+
gd->bd->bi_arch_number = MACH_TYPE_TOP9000;
|
| 165 |
+
/* adress of boot parameters */
|
| 166 |
+
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
|
| 167 |
+
|
| 168 |
+
at91_seriald_hw_init();
|
| 169 |
+
#ifdef CONFIG_CMD_NAND
|
| 170 |
+
nand_hw_init();
|
| 171 |
+
#endif
|
| 172 |
+
#ifdef CONFIG_MACB
|
| 173 |
+
macb_hw_init();
|
| 174 |
+
#endif
|
| 175 |
+
#ifdef CONFIG_ATMEL_SPI0
|
| 176 |
+
/* (n+4) denotes to use nSPISEL(0) in GPIO mode! */
|
| 177 |
+
at91_spi0_hw_init(1 << (FRAM_CS_NUM + 4));
|
| 178 |
+
#endif
|
| 179 |
+
#ifdef CONFIG_ATMEL_SPI1
|
| 180 |
+
at91_spi1_hw_init(1 << (ENC_CS_NUM + 4));
|
| 181 |
+
#endif
|
| 182 |
+
return 0;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
#ifdef CONFIG_MISC_INIT_R
|
| 186 |
+
int misc_init_r(void)
|
| 187 |
+
{
|
| 188 |
+
/* read 'factory' part of EEPROM */
|
| 189 |
+
read_factory_r();
|
| 190 |
+
return 0;
|
| 191 |
+
}
|
| 192 |
+
#endif
|
| 193 |
+
|
| 194 |
+
int dram_init(void)
|
| 195 |
+
{
|
| 196 |
+
gd->ram_size = get_ram_size(
|
| 197 |
+
(void *)CONFIG_SYS_SDRAM_BASE,
|
| 198 |
+
CONFIG_SYS_SDRAM_SIZE);
|
| 199 |
+
return 0;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
#ifdef CONFIG_RESET_PHY_R
|
| 203 |
+
void reset_phy(void)
|
| 204 |
+
{
|
| 205 |
+
/*
|
| 206 |
+
* Initialize ethernet HW addresses prior to starting Linux,
|
| 207 |
+
* needed for nfsroot.
|
| 208 |
+
* TODO: We need to investigate if that is really necessary.
|
| 209 |
+
*/
|
| 210 |
+
eth_init(gd->bd);
|
| 211 |
+
}
|
| 212 |
+
#endif
|
| 213 |
+
|
| 214 |
+
int board_eth_init(bd_t *bis)
|
| 215 |
+
{
|
| 216 |
+
int rc = 0;
|
| 217 |
+
int num = 0;
|
| 218 |
+
#ifdef CONFIG_MACB
|
| 219 |
+
rc = macb_eth_initialize(0,
|
| 220 |
+
(void *)ATMEL_BASE_EMAC0,
|
| 221 |
+
CONFIG_SYS_PHY_ID);
|
| 222 |
+
if (!rc)
|
| 223 |
+
num++;
|
| 224 |
+
#endif
|
| 225 |
+
#ifdef CONFIG_ENC28J60
|
| 226 |
+
rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM,
|
| 227 |
+
ENC_SPI_CLOCK, SPI_MODE_0);
|
| 228 |
+
if (!rc)
|
| 229 |
+
num++;
|
| 230 |
+
# ifdef CONFIG_ENC28J60_2
|
| 231 |
+
rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+1,
|
| 232 |
+
ENC_SPI_CLOCK, SPI_MODE_0);
|
| 233 |
+
if (!rc)
|
| 234 |
+
num++;
|
| 235 |
+
# ifdef CONFIG_ENC28J60_3
|
| 236 |
+
rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+2,
|
| 237 |
+
ENC_SPI_CLOCK, SPI_MODE_0);
|
| 238 |
+
if (!rc)
|
| 239 |
+
num++;
|
| 240 |
+
# endif
|
| 241 |
+
# endif
|
| 242 |
+
#endif
|
| 243 |
+
return num;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/*
|
| 247 |
+
* I2C access functions
|
| 248 |
+
*
|
| 249 |
+
* Note:
|
| 250 |
+
* We need to access Bus 0 before relocation to access the
|
| 251 |
+
* environment settings.
|
| 252 |
+
* However i2c_get_bus_num() cannot be called before
|
| 253 |
+
* relocation.
|
| 254 |
+
*/
|
| 255 |
+
#ifdef CONFIG_SOFT_I2C
|
| 256 |
+
void iic_init(void)
|
| 257 |
+
{
|
| 258 |
+
/* ports are now initialized in board_early_init_f() */
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
int iic_read(void)
|
| 262 |
+
{
|
| 263 |
+
switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) {
|
| 264 |
+
case 0:
|
| 265 |
+
return at91_get_pio_value(I2C0_PORT, SDA0_PIN);
|
| 266 |
+
case 1:
|
| 267 |
+
return at91_get_pio_value(I2C1_PORT, SDA1_PIN);
|
| 268 |
+
}
|
| 269 |
+
return 1;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
void iic_sda(int bit)
|
| 273 |
+
{
|
| 274 |
+
switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) {
|
| 275 |
+
case 0:
|
| 276 |
+
at91_set_pio_value(I2C0_PORT, SDA0_PIN, bit);
|
| 277 |
+
break;
|
| 278 |
+
case 1:
|
| 279 |
+
at91_set_pio_value(I2C1_PORT, SDA1_PIN, bit);
|
| 280 |
+
break;
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
void iic_scl(int bit)
|
| 285 |
+
{
|
| 286 |
+
switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) {
|
| 287 |
+
case 0:
|
| 288 |
+
at91_set_pio_value(I2C0_PORT, SCL0_PIN, bit);
|
| 289 |
+
break;
|
| 290 |
+
case 1:
|
| 291 |
+
at91_set_pio_value(I2C1_PORT, SCL1_PIN, bit);
|
| 292 |
+
break;
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
#endif
|
pool/shard007/C/0124245_reverse_singly_linked_list.c
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdlib.h>
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
|
| 4 |
+
#define LEN 10
|
| 5 |
+
|
| 6 |
+
typedef int DataType;
|
| 7 |
+
typedef struct ListNode {
|
| 8 |
+
DataType val;
|
| 9 |
+
struct ListNode *next;
|
| 10 |
+
} ListNode, *ListNodePtr;
|
| 11 |
+
|
| 12 |
+
/* insert x in the start of the list */
|
| 13 |
+
void insert_list(ListNodePtr *head, DataType x)
|
| 14 |
+
{
|
| 15 |
+
ListNodePtr p;
|
| 16 |
+
p = malloc(sizeof(ListNode));
|
| 17 |
+
p->val = x;
|
| 18 |
+
p->next = *head;
|
| 19 |
+
*head = p;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* reverse the singly-linked list */
|
| 23 |
+
void reverse_singly_list(ListNodePtr *head)
|
| 24 |
+
{
|
| 25 |
+
ListNodePtr curr, np, prev;
|
| 26 |
+
if ( *head == NULL || head == NULL) {
|
| 27 |
+
return ;
|
| 28 |
+
}
|
| 29 |
+
curr = *head;
|
| 30 |
+
prev = NULL;
|
| 31 |
+
np = NULL;
|
| 32 |
+
while (curr != NULL) {
|
| 33 |
+
np = curr->next;
|
| 34 |
+
curr->next = prev;
|
| 35 |
+
prev = curr;
|
| 36 |
+
curr = np;
|
| 37 |
+
}
|
| 38 |
+
*head = prev;
|
| 39 |
+
return ;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* print the singly-linked list
|
| 43 |
+
* recursive printing */
|
| 44 |
+
void print_list(ListNodePtr head)
|
| 45 |
+
{
|
| 46 |
+
if (head != NULL)
|
| 47 |
+
{
|
| 48 |
+
printf("%d\t", head->val);
|
| 49 |
+
print_list(head->next);
|
| 50 |
+
}
|
| 51 |
+
else printf("\n");
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
int main(int argc, const char *argv[])
|
| 55 |
+
{
|
| 56 |
+
/* establish a list */
|
| 57 |
+
ListNodePtr listHead = NULL;
|
| 58 |
+
/* insert one item to the lsit */
|
| 59 |
+
insert_list(&listHead, 4);
|
| 60 |
+
insert_list(&listHead, 5);
|
| 61 |
+
insert_list(&listHead, 6);
|
| 62 |
+
/* print the original list */
|
| 63 |
+
print_list(listHead);
|
| 64 |
+
/* reverse the list */
|
| 65 |
+
reverse_singly_list(&listHead);
|
| 66 |
+
/* print reversed list */
|
| 67 |
+
print_list(listHead);
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
pool/shard007/C/0124247_main.c
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <gtk/gtk.h>
|
| 2 |
+
|
| 3 |
+
int main (int argc, char * argv[])
|
| 4 |
+
{
|
| 5 |
+
GtkWidget *ventana;
|
| 6 |
+
GtkWidget *boton;
|
| 7 |
+
GtkWidget *entrada;
|
| 8 |
+
GtkWidget *caja;
|
| 9 |
+
GtkWidget *combo;
|
| 10 |
+
|
| 11 |
+
GList *opciones;
|
| 12 |
+
|
| 13 |
+
gtk_init(&argc, &argv);
|
| 14 |
+
|
| 15 |
+
ventana = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
| 16 |
+
boton = gtk_button_new_with_label("Click me");
|
| 17 |
+
caja = gtk_vbox_new(TRUE,2);
|
| 18 |
+
entrada = gtk_entry_new();
|
| 19 |
+
combo = gtk_combo_new();
|
| 20 |
+
|
| 21 |
+
opciones = NULL;
|
| 22 |
+
opciones = g_list_append(opciones, "Opcion 1");
|
| 23 |
+
opciones = g_list_append(opciones, "Opcion 2");
|
| 24 |
+
opciones = g_list_append(opciones, "Opcion 3");
|
| 25 |
+
opciones = g_list_append(opciones, "Opcion 4");
|
| 26 |
+
|
| 27 |
+
gtk_combo_set_popdown_strings ((GtkCombo *) combo, opciones);
|
| 28 |
+
|
| 29 |
+
gtk_box_pack_start ((GtkBox *) caja, entrada, TRUE, TRUE, 2);
|
| 30 |
+
gtk_box_pack_start ((GtkBox *) caja, combo, TRUE, TRUE, 2);
|
| 31 |
+
gtk_box_pack_start ((GtkBox *) caja, boton, TRUE, TRUE, 2);
|
| 32 |
+
|
| 33 |
+
gtk_container_add((GtkContainer *) ventana, caja);
|
| 34 |
+
gtk_widget_show_all(ventana);
|
| 35 |
+
|
| 36 |
+
gtk_main();
|
| 37 |
+
return 0;
|
| 38 |
+
}
|
pool/shard007/C/0124248_vm.c
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
#include <stdio.h>
|
| 4 |
+
#include <stdlib.h>
|
| 5 |
+
#include <string.h>
|
| 6 |
+
|
| 7 |
+
#include "util/util.h"
|
| 8 |
+
#include "nametable.h"
|
| 9 |
+
#include "action.h"
|
| 10 |
+
#include "compiler.h"
|
| 11 |
+
#include "runtime.h"
|
| 12 |
+
#include "vm.h"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
int fus_vm_init(struct fus_vm_t *vm){
|
| 16 |
+
vm->nametable = fus_nametable_create();
|
| 17 |
+
if(vm->nametable == NULL)return 1;
|
| 18 |
+
|
| 19 |
+
vm->compiler = fus_compiler_create(vm->nametable);
|
| 20 |
+
if(vm->compiler == NULL)return 1;
|
| 21 |
+
|
| 22 |
+
vm->runtime = fus_runtime_create(vm->nametable);
|
| 23 |
+
if(vm->runtime == NULL)return 1;
|
| 24 |
+
|
| 25 |
+
vm->n_syscalls = 0;
|
| 26 |
+
vm->syscalls = NULL;
|
| 27 |
+
|
| 28 |
+
RET_IF_NZ(fus_compiler_push_frame(vm->compiler, FUS_COMPILER_FRAME_TYPE_GLOBAL));
|
| 29 |
+
RET_IF_NZ(fus_runtime_push_frame(vm->runtime, vm->compiler->frame->code));
|
| 30 |
+
|
| 31 |
+
return 0;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void fus_vm_cleanup(struct fus_vm_t *vm){
|
| 35 |
+
/* TODO: actually clean up */
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
struct fus_vm_t *fus_vm_create(){
|
| 39 |
+
struct fus_vm_t *vm = malloc(sizeof(*vm));
|
| 40 |
+
if(vm == NULL)return NULL;
|
| 41 |
+
|
| 42 |
+
if(fus_vm_init(vm) != 0)return NULL;
|
| 43 |
+
|
| 44 |
+
return vm;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
int fus_vm_reset(struct fus_vm_t *vm){
|
| 48 |
+
fus_vm_cleanup(vm);
|
| 49 |
+
return fus_vm_init(vm);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
int fus_vm_compile(struct fus_vm_t *vm, const char *line){
|
| 54 |
+
fus_compiler_load(vm->compiler, line);
|
| 55 |
+
while(!fus_compiler_is_empty(vm->compiler)){
|
| 56 |
+
RET_IF_NZ(fus_compiler_compile(vm->compiler));
|
| 57 |
+
}
|
| 58 |
+
return 0;
|
| 59 |
+
}
|
| 60 |
+
int fus_vm_run(struct fus_vm_t *vm){
|
| 61 |
+
while(fus_runtime_is_running(vm->runtime)){
|
| 62 |
+
RET_IF_NZ(fus_runtime_run(vm->runtime));
|
| 63 |
+
}
|
| 64 |
+
return 0;
|
| 65 |
+
}
|
| 66 |
+
int fus_vm_exec(struct fus_vm_t *vm, const char *line){
|
| 67 |
+
RET_IF_NZ(fus_vm_compile(vm, line));
|
| 68 |
+
RET_IF_NZ(fus_vm_run(vm));
|
| 69 |
+
return 0;
|
| 70 |
+
}
|
| 71 |
+
int fus_vm_exec_literal(struct fus_vm_t *vm, struct fus_value_t value){
|
| 72 |
+
RET_IF_NZ(fus_compiler_compile_literal(vm->compiler, value));
|
| 73 |
+
RET_IF_NZ(fus_vm_run(vm));
|
| 74 |
+
return 0;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
int fus_vm_push_syscall(struct fus_vm_t *vm, fus_syscall *syscall){
|
| 80 |
+
int new_n_syscalls = vm->n_syscalls + 1;
|
| 81 |
+
|
| 82 |
+
fus_syscall **new_syscalls = realloc(vm->syscalls, sizeof(*new_syscalls) * new_n_syscalls);
|
| 83 |
+
if(new_syscalls == NULL)return 1;
|
| 84 |
+
|
| 85 |
+
int new_syscall_i = new_n_syscalls - 1;
|
| 86 |
+
new_syscalls[new_syscall_i] = syscall;
|
| 87 |
+
|
| 88 |
+
vm->n_syscalls = new_n_syscalls;
|
| 89 |
+
vm->syscalls = new_syscalls;
|
| 90 |
+
|
| 91 |
+
/* Push the index of the new syscall onto the vm stack, so a registering library can access it in its initial fus code */
|
| 92 |
+
RET_IF_NZ(fus_vm_exec_literal(vm, fus_value_int(new_syscall_i)));
|
| 93 |
+
return 0;
|
| 94 |
+
}
|
| 95 |
+
|
pool/shard007/C/0124252_cmain.c
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* cmain.c - Startup code for the PowerPC. */
|
| 2 |
+
/*
|
| 3 |
+
* GRUB -- GRand Unified Bootloader
|
| 4 |
+
* Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
|
| 5 |
+
*
|
| 6 |
+
* GRUB is free software: you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* GRUB is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <alloca.h>
|
| 21 |
+
#include <stdint.h>
|
| 22 |
+
#include <grub/kernel.h>
|
| 23 |
+
#include <grub/misc.h>
|
| 24 |
+
#include <grub/types.h>
|
| 25 |
+
#include <grub/machine/kernel.h>
|
| 26 |
+
#include <grub/ieee1275/ieee1275.h>
|
| 27 |
+
|
| 28 |
+
int (*grub_ieee1275_entry_fn) (void *);
|
| 29 |
+
|
| 30 |
+
grub_ieee1275_phandle_t grub_ieee1275_chosen;
|
| 31 |
+
grub_ieee1275_ihandle_t grub_ieee1275_mmu;
|
| 32 |
+
|
| 33 |
+
static grub_uint32_t grub_ieee1275_flags;
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
int
|
| 38 |
+
grub_ieee1275_test_flag (enum grub_ieee1275_flag flag)
|
| 39 |
+
{
|
| 40 |
+
return (grub_ieee1275_flags & (1 << flag));
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void
|
| 44 |
+
grub_ieee1275_set_flag (enum grub_ieee1275_flag flag)
|
| 45 |
+
{
|
| 46 |
+
grub_ieee1275_flags |= (1 << flag);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#define SF "SmartFirmware(tm)"
|
| 50 |
+
#define OHW "PPC Open Hack'Ware"
|
| 51 |
+
|
| 52 |
+
static void
|
| 53 |
+
grub_ieee1275_find_options (void)
|
| 54 |
+
{
|
| 55 |
+
grub_ieee1275_phandle_t root;
|
| 56 |
+
grub_ieee1275_phandle_t options;
|
| 57 |
+
grub_ieee1275_phandle_t openprom;
|
| 58 |
+
grub_ieee1275_phandle_t bootrom;
|
| 59 |
+
int rc;
|
| 60 |
+
grub_uint32_t realmode = 0;
|
| 61 |
+
char tmp[32];
|
| 62 |
+
int is_smartfirmware = 0;
|
| 63 |
+
int is_olpc = 0;
|
| 64 |
+
|
| 65 |
+
grub_ieee1275_finddevice ("/", &root);
|
| 66 |
+
grub_ieee1275_finddevice ("/options", &options);
|
| 67 |
+
grub_ieee1275_finddevice ("/openprom", &openprom);
|
| 68 |
+
|
| 69 |
+
rc = grub_ieee1275_get_integer_property (options, "real-mode?", &realmode,
|
| 70 |
+
sizeof realmode, 0);
|
| 71 |
+
if (((rc >= 0) && realmode) || (grub_ieee1275_mmu == 0))
|
| 72 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE);
|
| 73 |
+
|
| 74 |
+
rc = grub_ieee1275_get_property (openprom, "CodeGen-copyright",
|
| 75 |
+
tmp, sizeof (tmp), 0);
|
| 76 |
+
if (rc >= 0 && !grub_strncmp (tmp, SF, sizeof (SF) - 1))
|
| 77 |
+
is_smartfirmware = 1;
|
| 78 |
+
|
| 79 |
+
rc = grub_ieee1275_get_property (root, "architecture",
|
| 80 |
+
tmp, sizeof (tmp), 0);
|
| 81 |
+
if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
|
| 82 |
+
is_olpc = 1;
|
| 83 |
+
|
| 84 |
+
if (is_smartfirmware)
|
| 85 |
+
{
|
| 86 |
+
/* Broken in all versions */
|
| 87 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
|
| 88 |
+
|
| 89 |
+
/* There are two incompatible ways of checking the version number. Try
|
| 90 |
+
both. */
|
| 91 |
+
rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version",
|
| 92 |
+
tmp, sizeof (tmp), 0);
|
| 93 |
+
if (rc < 0)
|
| 94 |
+
rc = grub_ieee1275_get_property (openprom, "firmware-version",
|
| 95 |
+
tmp, sizeof (tmp), 0);
|
| 96 |
+
if (rc >= 0)
|
| 97 |
+
{
|
| 98 |
+
/* It is tempting to implement a version parser to set the flags for
|
| 99 |
+
e.g. 1.3 and below. However, there's a special situation here.
|
| 100 |
+
3rd party updates which fix the partition bugs are common, and for
|
| 101 |
+
some reason their fixes aren't being merged into trunk. So for
|
| 102 |
+
example we know that 1.2 and 1.3 are broken, but there's 1.2.99
|
| 103 |
+
and 1.3.99 which are known good (and applying this workaround
|
| 104 |
+
would cause breakage). */
|
| 105 |
+
if (!grub_strcmp (tmp, "1.0")
|
| 106 |
+
|| !grub_strcmp (tmp, "1.1")
|
| 107 |
+
|| !grub_strcmp (tmp, "1.2")
|
| 108 |
+
|| !grub_strcmp (tmp, "1.3"))
|
| 109 |
+
{
|
| 110 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
|
| 111 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS);
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
if (is_olpc)
|
| 117 |
+
{
|
| 118 |
+
/* OLPC / XO laptops have three kinds of storage devices:
|
| 119 |
+
|
| 120 |
+
- NAND flash. These are accessible via OFW callbacks, but:
|
| 121 |
+
- Follow strange semantics, imposed by hardware constraints.
|
| 122 |
+
- Its ABI is undocumented, and not stable.
|
| 123 |
+
They lack "device_type" property, which conveniently makes GRUB
|
| 124 |
+
skip them.
|
| 125 |
+
|
| 126 |
+
- USB drives. Not accessible, because OFW shuts down the controller
|
| 127 |
+
in order to prevent collisions with applications accessing it
|
| 128 |
+
directly. Even worse, attempts to access it will NOT return
|
| 129 |
+
control to the caller, so we have to avoid probing them.
|
| 130 |
+
|
| 131 |
+
- SD cards. These work fine.
|
| 132 |
+
|
| 133 |
+
To avoid brekage, we only need to skip USB probing. However,
|
| 134 |
+
since detecting SD cards is more reliable, we do that instead.
|
| 135 |
+
*/
|
| 136 |
+
|
| 137 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom))
|
| 141 |
+
{
|
| 142 |
+
rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0);
|
| 143 |
+
if (rc >= 0 && !grub_strncmp (tmp, OHW, sizeof (OHW) - 1))
|
| 144 |
+
{
|
| 145 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
|
| 146 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS);
|
| 147 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET);
|
| 148 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM);
|
| 149 |
+
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_ANSI);
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
#undef SF
|
| 155 |
+
#undef OHW
|
| 156 |
+
|
| 157 |
+
void
|
| 158 |
+
grub_ieee1275_init (void)
|
| 159 |
+
{
|
| 160 |
+
grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
|
| 161 |
+
|
| 162 |
+
if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "mmu", &grub_ieee1275_mmu,
|
| 163 |
+
sizeof grub_ieee1275_mmu, 0) < 0)
|
| 164 |
+
grub_ieee1275_mmu = 0;
|
| 165 |
+
|
| 166 |
+
grub_ieee1275_find_options ();
|
| 167 |
+
}
|
pool/shard007/C/0124253_vector_realmonitor.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* mbed Microcontroller Library - RealMonitor
|
| 2 |
+
* Copyright (c) 2006-2009 ARM Limited. All rights reserved.
|
| 3 |
+
*/
|
| 4 |
+
#include "vector_defns.h"
|
| 5 |
+
|
| 6 |
+
extern void __mbed_dcc_irq(void);
|
| 7 |
+
|
| 8 |
+
/* Function: __mbed_init_realmonitor
|
| 9 |
+
* Setup the RealMonitor DCC Interrupt Handlers
|
| 10 |
+
*/
|
| 11 |
+
void __mbed_init_realmonitor(void) __attribute__((weak));
|
| 12 |
+
void __mbed_init_realmonitor() {
|
| 13 |
+
// Disable all interrupts
|
| 14 |
+
VICIntEnClr = 0xffffffff;
|
| 15 |
+
|
| 16 |
+
// Set DCC interrupt vector addresses
|
| 17 |
+
VICVectAddr2 = (unsigned)&__mbed_dcc_irq;
|
| 18 |
+
VICVectAddr3 = (unsigned)&__mbed_dcc_irq;
|
| 19 |
+
|
| 20 |
+
// Initialise RealMonitor
|
| 21 |
+
((void (*)(void))rm_init_entry)();
|
| 22 |
+
}
|
pool/shard007/C/0124255_pth_cvsimple.c
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <unistd.h>
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
#include <pthread.h>
|
| 4 |
+
|
| 5 |
+
#define NUM_THREADS 3
|
| 6 |
+
#define TCOUNT 10
|
| 7 |
+
#define COUNT_THRES 12
|
| 8 |
+
|
| 9 |
+
int condvar_was_hit = 0;
|
| 10 |
+
int count = 0;
|
| 11 |
+
int thread_ids[3] = {0,1,2};
|
| 12 |
+
pthread_mutex_t count_lock=PTHREAD_MUTEX_INITIALIZER;
|
| 13 |
+
pthread_cond_t count_hit_threshold=PTHREAD_COND_INITIALIZER;
|
| 14 |
+
|
| 15 |
+
void *inc_count(void *null)
|
| 16 |
+
{
|
| 17 |
+
int i=0;
|
| 18 |
+
|
| 19 |
+
for (i=0; i<TCOUNT; i++) {
|
| 20 |
+
pthread_mutex_lock(&count_lock);
|
| 21 |
+
count++;
|
| 22 |
+
printf("inc_counter(): count = %d, unlocking mutex\n", count);
|
| 23 |
+
if (count == COUNT_THRES) {
|
| 24 |
+
printf("hit threshold!\n");
|
| 25 |
+
pthread_cond_signal(&count_hit_threshold);
|
| 26 |
+
}
|
| 27 |
+
pthread_mutex_unlock(&count_lock);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
return(NULL);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void *watch_count(void *null)
|
| 34 |
+
{
|
| 35 |
+
pthread_mutex_lock(&count_lock);
|
| 36 |
+
|
| 37 |
+
while (count < COUNT_THRES) {
|
| 38 |
+
pthread_cond_wait(&count_hit_threshold, &count_lock);
|
| 39 |
+
condvar_was_hit = 1;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
pthread_mutex_unlock(&count_lock);
|
| 43 |
+
|
| 44 |
+
return(NULL);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
extern int
|
| 48 |
+
main(void)
|
| 49 |
+
{
|
| 50 |
+
int i;
|
| 51 |
+
pthread_t threads[3];
|
| 52 |
+
|
| 53 |
+
pthread_create(&threads[0], NULL, watch_count, NULL);
|
| 54 |
+
sleep(1);
|
| 55 |
+
pthread_create(&threads[1], NULL, inc_count, NULL);
|
| 56 |
+
pthread_create(&threads[2], NULL, inc_count, NULL);
|
| 57 |
+
|
| 58 |
+
for (i = 0; i < NUM_THREADS; i++) {
|
| 59 |
+
pthread_join(threads[i], NULL);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
if (condvar_was_hit == 1)
|
| 69 |
+
printf("condvar was hit!\n");
|
| 70 |
+
else if (condvar_was_hit > 1)
|
| 71 |
+
printf("condvar was multi-hit...\n");
|
| 72 |
+
else
|
| 73 |
+
printf("condvar was missed...\n");
|
| 74 |
+
|
| 75 |
+
return 0;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
pool/shard007/C/0124256_gauge_info.c
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// -----------------------------------------------------------------
|
| 2 |
+
// Application-dependent routine for writing gauge info file
|
| 3 |
+
// For MCRG-blocked measurements
|
| 4 |
+
|
| 5 |
+
// This file is an ASCII companion to the gauge configuration file
|
| 6 |
+
// and contains information about the action used to generate it.
|
| 7 |
+
// This information is consistently written in the pattern
|
| 8 |
+
// keyword value
|
| 9 |
+
// or
|
| 10 |
+
// keyword[n] value1 value2 ... valuen
|
| 11 |
+
// where n is an integer.
|
| 12 |
+
//
|
| 13 |
+
// Possible keywords are listed in io_lat.h
|
| 14 |
+
#include "block_includes.h"
|
| 15 |
+
// -----------------------------------------------------------------
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
// -----------------------------------------------------------------
|
| 20 |
+
// Write optional entries in the ASCII info file
|
| 21 |
+
// Call from one of the lattice output routines in io_lat4.c
|
| 22 |
+
// File has already been opened and the required magic number,
|
| 23 |
+
// time stamp and lattice dimensions have already been written
|
| 24 |
+
void write_appl_gauge_info(FILE *fp) {
|
| 25 |
+
write_gauge_info_item(fp, "action.description", "%s",
|
| 26 |
+
"\"Gauge plus fermion\"", 0, 0);
|
| 27 |
+
write_gauge_info_item(fp, "gauge.description", "%s",
|
| 28 |
+
"\"Fundamental--adjoint plaquette gauge action\"",
|
| 29 |
+
0, 0);
|
| 30 |
+
write_gauge_info_item(fp, "quark.description", "%s",
|
| 31 |
+
"\"nHYP KS fermions\"", 0, 0);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
#define INFOSTRING_MAX 2048
|
| 35 |
+
// Follow USQCD style for record XML
|
| 36 |
+
char *create_QCDML() {
|
| 37 |
+
size_t bytes = 0;
|
| 38 |
+
char *info = malloc(INFOSTRING_MAX * sizeof(*info));
|
| 39 |
+
size_t max = INFOSTRING_MAX;
|
| 40 |
+
char begin[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><usqcdInfo><version>1.0</version>";
|
| 41 |
+
char begin_info[] = "<info>";
|
| 42 |
+
char end_info[] = "</info>";
|
| 43 |
+
char end[] = "</usqcdInfo>";
|
| 44 |
+
Real myssplaq = g_ssplaq; // Precision conversion
|
| 45 |
+
Real mystplaq = g_stplaq; // Precision conversion
|
| 46 |
+
Real nersc_linktr = linktr.real / 3.0; // Convention and precision
|
| 47 |
+
char sums[20];
|
| 48 |
+
|
| 49 |
+
snprintf(info + bytes, max - bytes, "%s", begin);
|
| 50 |
+
bytes = strlen(info);
|
| 51 |
+
|
| 52 |
+
snprintf(info + bytes, max - bytes, "<plaq>%e</plaq>",
|
| 53 |
+
(myssplaq + mystplaq) / 6.0);
|
| 54 |
+
bytes = strlen(info);
|
| 55 |
+
|
| 56 |
+
snprintf(info + bytes, max - bytes, "<linktr>%e</linktr>", nersc_linktr);
|
| 57 |
+
bytes = strlen(info);
|
| 58 |
+
|
| 59 |
+
snprintf(info + bytes, max - bytes, "%s", begin_info);
|
| 60 |
+
bytes = strlen(info);
|
| 61 |
+
|
| 62 |
+
// The rest are optional
|
| 63 |
+
if (startlat_p != NULL) {
|
| 64 |
+
// Retain some info about the original (or previous) configuration
|
| 65 |
+
bytes = strlen(info);
|
| 66 |
+
sprint_gauge_info_item(info + bytes, max - bytes,
|
| 67 |
+
"gauge.previous.filename",
|
| 68 |
+
"%s", startlat_p->filename, 0, 0);
|
| 69 |
+
|
| 70 |
+
bytes = strlen(info);
|
| 71 |
+
sprint_gauge_info_item(info + bytes, max - bytes,
|
| 72 |
+
"gauge.previous.time_stamp",
|
| 73 |
+
"%s", startlat_p->header->time_stamp, 0, 0);
|
| 74 |
+
sprintf(sums, "%x %x", startlat_p->check.sum29, startlat_p->check.sum31);
|
| 75 |
+
|
| 76 |
+
bytes = strlen(info);
|
| 77 |
+
sprint_gauge_info_item(info + bytes, max - bytes,
|
| 78 |
+
"gauge.previous.checksums",
|
| 79 |
+
"%s", sums, 0, 0);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
snprintf(info + bytes, max - bytes, "%s", end_info);
|
| 83 |
+
bytes = strlen(info);
|
| 84 |
+
|
| 85 |
+
snprintf(info + bytes, max - bytes, "%s", end);
|
| 86 |
+
return info;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void free_QCDML(char *info) {
|
| 90 |
+
if (info != NULL)
|
| 91 |
+
free(info);
|
| 92 |
+
}
|
| 93 |
+
// -----------------------------------------------------------------
|
pool/shard007/C/0124257_Cancion.c
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "..\Musica\Cancion.h"
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
Cancion *CancionNew(char nombre[50],char URL[100],char Album[50],char Artista[50],char genero[50])
|
| 5 |
+
{
|
| 6 |
+
Cancion *C = NULL;
|
| 7 |
+
C = (Cancion*)malloc(sizeof(Cancion));
|
| 8 |
+
|
| 9 |
+
strcpy(C->Nombre,nombre);
|
| 10 |
+
strcpy(C->URL,URL);
|
| 11 |
+
strcpy(C->Album,Album);
|
| 12 |
+
strcpy(C->Artista,Artista);
|
| 13 |
+
strcpy(C->Genero,genero);
|
| 14 |
+
C->Ranking=0;
|
| 15 |
+
|
| 16 |
+
return C;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
void CancionPrint(Cancion *C)
|
| 20 |
+
{
|
| 21 |
+
printf("%s\t--\t%s\t--\t%s",C->Nombre,C->Album,C->Artista);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
List *LlenarLCanciones()
|
| 25 |
+
{
|
| 26 |
+
List *Lcanciones = NULL;
|
| 27 |
+
FILE *f = NULL;
|
| 28 |
+
NodeList *p = NULL;
|
| 29 |
+
Cancion *C = NULL;
|
| 30 |
+
char n[50], al[50], ar[50], ge[50], URL[100];
|
| 31 |
+
int x = 0;
|
| 32 |
+
|
| 33 |
+
f= fopen("Canciones.txt","r");
|
| 34 |
+
Lcanciones = listNew();
|
| 35 |
+
|
| 36 |
+
while (!feof(f))
|
| 37 |
+
{
|
| 38 |
+
x = fscanf(f,"%[^,],%[^,],%[^,],%[^,],%[^\n]\n",ar,al,n,ge,URL);
|
| 39 |
+
|
| 40 |
+
if(x>0)
|
| 41 |
+
listAddNode(Lcanciones,nodeListNew(CancionNew(n,URL,al,ar,ge)));
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
}
|
| 45 |
+
fclose(f);
|
| 46 |
+
|
| 47 |
+
return(Lcanciones);
|
| 48 |
+
|
| 49 |
+
}
|
| 50 |
+
int BuscarCancion(List *Al,char Nombre[50])
|
| 51 |
+
{
|
| 52 |
+
NodeList *p = NULL;
|
| 53 |
+
Cancion *C = NULL;
|
| 54 |
+
for (p = Al->header; p != NULL; p = p->next)
|
| 55 |
+
{
|
| 56 |
+
C = (Cancion*)nodeListGetCont(p);
|
| 57 |
+
|
| 58 |
+
if (strcmp(C->Nombre,Nombre) == 0)
|
| 59 |
+
return 1;
|
| 60 |
+
}
|
| 61 |
+
return 0;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
void OrdenarListasCanciones(List *L)
|
| 65 |
+
{
|
| 66 |
+
NodeList *i = NULL,*j = NULL;
|
| 67 |
+
Cancion *C1 = NULL, *C2 = NULL, *temp = NULL;
|
| 68 |
+
|
| 69 |
+
for (i = L->header; i != NULL; i = i->next)
|
| 70 |
+
{
|
| 71 |
+
C1 = (Cancion*)nodeListGetCont(i);
|
| 72 |
+
|
| 73 |
+
for (j = L->header; j != NULL; j = j->next)
|
| 74 |
+
{
|
| 75 |
+
C2 = (Cancion*)nodeListGetCont(j);
|
| 76 |
+
|
| 77 |
+
if(C1->Ranking > C2->Ranking)
|
| 78 |
+
{
|
| 79 |
+
temp = (Cancion*)j->cont;
|
| 80 |
+
j->cont = i->cont;
|
| 81 |
+
i->cont = temp;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
List *ListasCancionesTOP(List *L)
|
| 88 |
+
{
|
| 89 |
+
NodeList *i = NULL, *j = NULL;
|
| 90 |
+
Cancion *C1 = NULL, *C2 = NULL, *temp = NULL;
|
| 91 |
+
List *Lista = NULL;
|
| 92 |
+
int cont = 0;
|
| 93 |
+
|
| 94 |
+
Lista = listNew();
|
| 95 |
+
|
| 96 |
+
for (i = L->header; i != NULL && cont != 10; i = i->next)
|
| 97 |
+
{
|
| 98 |
+
cont ++;
|
| 99 |
+
C1 = (Cancion*)nodeListGetCont(i);
|
| 100 |
+
listAddNode(Lista, nodeListNew(C1));
|
| 101 |
+
}
|
| 102 |
+
return Lista;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
void ListPrintCanTOP(List *ListaCanciones)
|
| 106 |
+
{
|
| 107 |
+
NodeList *i = NULL;
|
| 108 |
+
Cancion *C = NULL;
|
| 109 |
+
int cont = 1;
|
| 110 |
+
|
| 111 |
+
printf("TOP 10 DE CANCIONES\nELECTRONICA\n");
|
| 112 |
+
|
| 113 |
+
for (i = ListaCanciones->header; i != NULL; i = i->next)
|
| 114 |
+
{
|
| 115 |
+
C=(Cancion*)nodeListGetCont(i);
|
| 116 |
+
|
| 117 |
+
if(strcmp(C->Genero,"Electronica") == 0 && C->Ranking > 0)
|
| 118 |
+
{
|
| 119 |
+
printf("%d %s %s\n",cont,C->Artista,C->Nombre);
|
| 120 |
+
cont ++;
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
cont=1;
|
| 124 |
+
|
| 125 |
+
printf("\nPOP\n");
|
| 126 |
+
|
| 127 |
+
for (i = ListaCanciones->header; i != NULL; i = i->next)
|
| 128 |
+
{
|
| 129 |
+
C = (Cancion*)nodeListGetCont(i);
|
| 130 |
+
|
| 131 |
+
if(strcmp(C->Genero,"Pop") == 0 && C->Ranking > 0)
|
| 132 |
+
{
|
| 133 |
+
printf("%d %s %s\n",cont,C->Artista,C->Nombre);
|
| 134 |
+
cont ++;
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
cont=1;
|
| 139 |
+
printf("\nREGGAETON\n");
|
| 140 |
+
|
| 141 |
+
for (i = ListaCanciones->header; i != NULL; i = i->next)
|
| 142 |
+
{
|
| 143 |
+
C = (Cancion*)nodeListGetCont(i);
|
| 144 |
+
if( strcmp(C->Genero,"Reggaeton") == 0 && C->Ranking>0 )
|
| 145 |
+
{
|
| 146 |
+
printf("%d %s %s\n",cont,C->Artista,C->Nombre);
|
| 147 |
+
cont ++;
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
cont=1;
|
| 152 |
+
|
| 153 |
+
printf("\nROCK\n");
|
| 154 |
+
|
| 155 |
+
for (i = ListaCanciones->header; i != NULL; i = i->next)
|
| 156 |
+
{
|
| 157 |
+
C = (Cancion*)nodeListGetCont(i);
|
| 158 |
+
if(strcmp(C->Genero,"Rock") == 0 && C->Ranking > 0)
|
| 159 |
+
{
|
| 160 |
+
printf("%d %s %s\n", cont, C->Artista, C->Nombre);
|
| 161 |
+
cont ++;
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
cont=1;
|
| 166 |
+
printf("\nSALSA\n");
|
| 167 |
+
|
| 168 |
+
for (i = ListaCanciones->header; i != NULL; i = i->next)
|
| 169 |
+
{
|
| 170 |
+
C = (Cancion*)nodeListGetCont(i);
|
| 171 |
+
if(strcmp(C->Genero,"Salsa") == 0 && C->Ranking>0)
|
| 172 |
+
{
|
| 173 |
+
printf("%d %s %s\n", cont, C->Artista, C->Nombre);
|
| 174 |
+
cont ++;
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
}
|
pool/shard007/C/0124266_watchdog.c
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Virtual hardware watchdog.
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2009 Red Hat Inc.
|
| 5 |
+
*
|
| 6 |
+
* This program is free software; you can redistribute it and/or
|
| 7 |
+
* modify it under the terms of the GNU General Public License
|
| 8 |
+
* as published by the Free Software Foundation; either version 2
|
| 9 |
+
* of the License, or (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*
|
| 19 |
+
* By Richard W.M. Jones (rjones@redhat.com).
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include "qemu-common.h"
|
| 23 |
+
#include "qemu-option.h"
|
| 24 |
+
#include "qemu-config.h"
|
| 25 |
+
#include "qemu-queue.h"
|
| 26 |
+
#include "qemu-objects.h"
|
| 27 |
+
#include "monitor.h"
|
| 28 |
+
#include "sysemu.h"
|
| 29 |
+
#include "hw/watchdog.h"
|
| 30 |
+
|
| 31 |
+
/* Possible values for action parameter. */
|
| 32 |
+
#define WDT_RESET 1 /* Hard reset. */
|
| 33 |
+
#define WDT_SHUTDOWN 2 /* Shutdown. */
|
| 34 |
+
#define WDT_POWEROFF 3 /* Quit. */
|
| 35 |
+
#define WDT_PAUSE 4 /* Pause. */
|
| 36 |
+
#define WDT_DEBUG 5 /* Prints a message and continues running. */
|
| 37 |
+
#define WDT_NONE 6 /* Do nothing. */
|
| 38 |
+
|
| 39 |
+
static int watchdog_action = WDT_RESET;
|
| 40 |
+
static QLIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
|
| 41 |
+
|
| 42 |
+
void watchdog_add_model(WatchdogTimerModel *model)
|
| 43 |
+
{
|
| 44 |
+
QLIST_INSERT_HEAD(&watchdog_list, model, entry);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* Returns:
|
| 48 |
+
* 0 = continue
|
| 49 |
+
* 1 = exit program with error
|
| 50 |
+
* 2 = exit program without error
|
| 51 |
+
*/
|
| 52 |
+
int select_watchdog(const char *p)
|
| 53 |
+
{
|
| 54 |
+
WatchdogTimerModel *model;
|
| 55 |
+
QemuOpts *opts;
|
| 56 |
+
|
| 57 |
+
/* -watchdog ? lists available devices and exits cleanly. */
|
| 58 |
+
if (strcmp(p, "?") == 0) {
|
| 59 |
+
QLIST_FOREACH(model, &watchdog_list, entry) {
|
| 60 |
+
fprintf(stderr, "\t%s\t%s\n",
|
| 61 |
+
model->wdt_name, model->wdt_description);
|
| 62 |
+
}
|
| 63 |
+
return 2;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
QLIST_FOREACH(model, &watchdog_list, entry) {
|
| 67 |
+
if (strcasecmp(model->wdt_name, p) == 0) {
|
| 68 |
+
/* add the device */
|
| 69 |
+
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
|
| 70 |
+
qemu_opt_set(opts, "driver", p);
|
| 71 |
+
return 0;
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
fprintf(stderr, "Unknown -watchdog device. Supported devices are:\n");
|
| 76 |
+
QLIST_FOREACH(model, &watchdog_list, entry) {
|
| 77 |
+
fprintf(stderr, "\t%s\t%s\n",
|
| 78 |
+
model->wdt_name, model->wdt_description);
|
| 79 |
+
}
|
| 80 |
+
return 1;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
int select_watchdog_action(const char *p)
|
| 84 |
+
{
|
| 85 |
+
if (strcasecmp(p, "reset") == 0)
|
| 86 |
+
watchdog_action = WDT_RESET;
|
| 87 |
+
else if (strcasecmp(p, "shutdown") == 0)
|
| 88 |
+
watchdog_action = WDT_SHUTDOWN;
|
| 89 |
+
else if (strcasecmp(p, "poweroff") == 0)
|
| 90 |
+
watchdog_action = WDT_POWEROFF;
|
| 91 |
+
else if (strcasecmp(p, "pause") == 0)
|
| 92 |
+
watchdog_action = WDT_PAUSE;
|
| 93 |
+
else if (strcasecmp(p, "debug") == 0)
|
| 94 |
+
watchdog_action = WDT_DEBUG;
|
| 95 |
+
else if (strcasecmp(p, "none") == 0)
|
| 96 |
+
watchdog_action = WDT_NONE;
|
| 97 |
+
else
|
| 98 |
+
return -1;
|
| 99 |
+
|
| 100 |
+
return 0;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
static void watchdog_mon_event(const char *action)
|
| 104 |
+
{
|
| 105 |
+
QObject *data;
|
| 106 |
+
|
| 107 |
+
data = qobject_from_jsonf("{ 'action': %s }", action);
|
| 108 |
+
monitor_protocol_event(QEVENT_WATCHDOG, data);
|
| 109 |
+
qobject_decref(data);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/* This actually performs the "action" once a watchdog has expired,
|
| 113 |
+
* ie. reboot, shutdown, exit, etc.
|
| 114 |
+
*/
|
| 115 |
+
void watchdog_perform_action(void)
|
| 116 |
+
{
|
| 117 |
+
switch(watchdog_action) {
|
| 118 |
+
case WDT_RESET: /* same as 'system_reset' in monitor */
|
| 119 |
+
watchdog_mon_event("reset");
|
| 120 |
+
qemu_system_reset_request();
|
| 121 |
+
break;
|
| 122 |
+
|
| 123 |
+
case WDT_SHUTDOWN: /* same as 'system_powerdown' in monitor */
|
| 124 |
+
watchdog_mon_event("shutdown");
|
| 125 |
+
qemu_system_powerdown_request();
|
| 126 |
+
break;
|
| 127 |
+
|
| 128 |
+
case WDT_POWEROFF: /* same as 'quit' command in monitor */
|
| 129 |
+
watchdog_mon_event("poweroff");
|
| 130 |
+
exit(0);
|
| 131 |
+
break;
|
| 132 |
+
|
| 133 |
+
case WDT_PAUSE: /* same as 'stop' command in monitor */
|
| 134 |
+
watchdog_mon_event("pause");
|
| 135 |
+
vm_stop(VMSTOP_WATCHDOG);
|
| 136 |
+
break;
|
| 137 |
+
|
| 138 |
+
case WDT_DEBUG:
|
| 139 |
+
watchdog_mon_event("debug");
|
| 140 |
+
fprintf(stderr, "watchdog: timer fired\n");
|
| 141 |
+
break;
|
| 142 |
+
|
| 143 |
+
case WDT_NONE:
|
| 144 |
+
watchdog_mon_event("none");
|
| 145 |
+
break;
|
| 146 |
+
}
|
| 147 |
+
}
|
pool/shard007/C/0124267_finddomain.c
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- buffer-read-only: t -*- vi: set ro: */
|
| 2 |
+
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
| 3 |
+
/* Handle list of needed message catalogs
|
| 4 |
+
Copyright (C) 1995-1999, 2000-2001, 2003-2007 Free Software Foundation, Inc.
|
| 5 |
+
Written by Ulrich Drepper <drepper@gnu.org>, 1995.
|
| 6 |
+
|
| 7 |
+
This program is free software; you can redistribute it and/or modify it
|
| 8 |
+
under the terms of the GNU Library General Public License as published
|
| 9 |
+
by the Free Software Foundation; either version 2, or (at your option)
|
| 10 |
+
any later version.
|
| 11 |
+
|
| 12 |
+
This program is distributed in the hope that it will be useful,
|
| 13 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 15 |
+
Library General Public License for more details.
|
| 16 |
+
|
| 17 |
+
You should have received a copy of the GNU Library General Public
|
| 18 |
+
License along with this program; if not, write to the Free Software
|
| 19 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
| 20 |
+
USA. */
|
| 21 |
+
|
| 22 |
+
#ifdef HAVE_CONFIG_H
|
| 23 |
+
# include <config.h>
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
#include <stdio.h>
|
| 27 |
+
#include <sys/types.h>
|
| 28 |
+
#include <stdlib.h>
|
| 29 |
+
#include <string.h>
|
| 30 |
+
|
| 31 |
+
#if defined HAVE_UNISTD_H || defined _LIBC
|
| 32 |
+
# include <unistd.h>
|
| 33 |
+
#endif
|
| 34 |
+
|
| 35 |
+
#include "gettextP.h"
|
| 36 |
+
#ifdef _LIBC
|
| 37 |
+
# include <libintl.h>
|
| 38 |
+
#else
|
| 39 |
+
# include "libgnuintl.h"
|
| 40 |
+
#endif
|
| 41 |
+
|
| 42 |
+
/* Handle multi-threaded applications. */
|
| 43 |
+
#ifdef _LIBC
|
| 44 |
+
# include <bits/libc-lock.h>
|
| 45 |
+
# define gl_rwlock_define_initialized __libc_rwlock_define_initialized
|
| 46 |
+
# define gl_rwlock_rdlock __libc_rwlock_rdlock
|
| 47 |
+
# define gl_rwlock_wrlock __libc_rwlock_wrlock
|
| 48 |
+
# define gl_rwlock_unlock __libc_rwlock_unlock
|
| 49 |
+
#else
|
| 50 |
+
# include "lock.h"
|
| 51 |
+
#endif
|
| 52 |
+
|
| 53 |
+
/* @@ end of prolog @@ */
|
| 54 |
+
/* List of already loaded domains. */
|
| 55 |
+
static struct loaded_l10nfile *_nl_loaded_domains;
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
/* Return a data structure describing the message catalog described by
|
| 59 |
+
the DOMAINNAME and CATEGORY parameters with respect to the currently
|
| 60 |
+
established bindings. */
|
| 61 |
+
struct loaded_l10nfile *
|
| 62 |
+
internal_function
|
| 63 |
+
_nl_find_domain (const char *dirname, char *locale,
|
| 64 |
+
const char *domainname, struct binding *domainbinding)
|
| 65 |
+
{
|
| 66 |
+
struct loaded_l10nfile *retval;
|
| 67 |
+
const char *language;
|
| 68 |
+
const char *modifier;
|
| 69 |
+
const char *territory;
|
| 70 |
+
const char *codeset;
|
| 71 |
+
const char *normalized_codeset;
|
| 72 |
+
const char *alias_value;
|
| 73 |
+
int mask;
|
| 74 |
+
|
| 75 |
+
/* LOCALE can consist of up to four recognized parts for the XPG syntax:
|
| 76 |
+
|
| 77 |
+
language[_territory][.codeset][@modifier]
|
| 78 |
+
|
| 79 |
+
Beside the first part all of them are allowed to be missing. If
|
| 80 |
+
the full specified locale is not found, the less specific one are
|
| 81 |
+
looked for. The various parts will be stripped off according to
|
| 82 |
+
the following order:
|
| 83 |
+
(1) codeset
|
| 84 |
+
(2) normalized codeset
|
| 85 |
+
(3) territory
|
| 86 |
+
(4) modifier
|
| 87 |
+
*/
|
| 88 |
+
|
| 89 |
+
/* We need to protect modifying the _NL_LOADED_DOMAINS data. */
|
| 90 |
+
gl_rwlock_define_initialized (static, lock);
|
| 91 |
+
gl_rwlock_rdlock (lock);
|
| 92 |
+
|
| 93 |
+
/* If we have already tested for this locale entry there has to
|
| 94 |
+
be one data set in the list of loaded domains. */
|
| 95 |
+
retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
|
| 96 |
+
strlen (dirname) + 1, 0, locale, NULL, NULL,
|
| 97 |
+
NULL, NULL, domainname, 0);
|
| 98 |
+
|
| 99 |
+
gl_rwlock_unlock (lock);
|
| 100 |
+
|
| 101 |
+
if (retval != NULL)
|
| 102 |
+
{
|
| 103 |
+
/* We know something about this locale. */
|
| 104 |
+
int cnt;
|
| 105 |
+
|
| 106 |
+
if (retval->decided <= 0)
|
| 107 |
+
_nl_load_domain (retval, domainbinding);
|
| 108 |
+
|
| 109 |
+
if (retval->data != NULL)
|
| 110 |
+
return retval;
|
| 111 |
+
|
| 112 |
+
for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
|
| 113 |
+
{
|
| 114 |
+
if (retval->successor[cnt]->decided <= 0)
|
| 115 |
+
_nl_load_domain (retval->successor[cnt], domainbinding);
|
| 116 |
+
|
| 117 |
+
if (retval->successor[cnt]->data != NULL)
|
| 118 |
+
break;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return retval;
|
| 122 |
+
/* NOTREACHED */
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/* See whether the locale value is an alias. If yes its value
|
| 126 |
+
*overwrites* the alias name. No test for the original value is
|
| 127 |
+
done. */
|
| 128 |
+
alias_value = _nl_expand_alias (locale);
|
| 129 |
+
if (alias_value != NULL)
|
| 130 |
+
{
|
| 131 |
+
#if defined _LIBC || defined HAVE_STRDUP
|
| 132 |
+
locale = strdup (alias_value);
|
| 133 |
+
if (locale == NULL)
|
| 134 |
+
return NULL;
|
| 135 |
+
#else
|
| 136 |
+
size_t len = strlen (alias_value) + 1;
|
| 137 |
+
locale = (char *) malloc (len);
|
| 138 |
+
if (locale == NULL)
|
| 139 |
+
return NULL;
|
| 140 |
+
|
| 141 |
+
memcpy (locale, alias_value, len);
|
| 142 |
+
#endif
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* Now we determine the single parts of the locale name. First
|
| 146 |
+
look for the language. Termination symbols are `_', '.', and `@'. */
|
| 147 |
+
mask = _nl_explode_name (locale, &language, &modifier, &territory,
|
| 148 |
+
&codeset, &normalized_codeset);
|
| 149 |
+
if (mask == -1)
|
| 150 |
+
/* This means we are out of core. */
|
| 151 |
+
return NULL;
|
| 152 |
+
|
| 153 |
+
/* We need to protect modifying the _NL_LOADED_DOMAINS data. */
|
| 154 |
+
gl_rwlock_wrlock (lock);
|
| 155 |
+
|
| 156 |
+
/* Create all possible locale entries which might be interested in
|
| 157 |
+
generalization. */
|
| 158 |
+
retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
|
| 159 |
+
strlen (dirname) + 1, mask, language, territory,
|
| 160 |
+
codeset, normalized_codeset, modifier,
|
| 161 |
+
domainname, 1);
|
| 162 |
+
|
| 163 |
+
gl_rwlock_unlock (lock);
|
| 164 |
+
|
| 165 |
+
if (retval == NULL)
|
| 166 |
+
/* This means we are out of core. */
|
| 167 |
+
goto out;
|
| 168 |
+
|
| 169 |
+
if (retval->decided <= 0)
|
| 170 |
+
_nl_load_domain (retval, domainbinding);
|
| 171 |
+
if (retval->data == NULL)
|
| 172 |
+
{
|
| 173 |
+
int cnt;
|
| 174 |
+
for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
|
| 175 |
+
{
|
| 176 |
+
if (retval->successor[cnt]->decided <= 0)
|
| 177 |
+
_nl_load_domain (retval->successor[cnt], domainbinding);
|
| 178 |
+
if (retval->successor[cnt]->data != NULL)
|
| 179 |
+
break;
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
/* The room for an alias was dynamically allocated. Free it now. */
|
| 184 |
+
if (alias_value != NULL)
|
| 185 |
+
free (locale);
|
| 186 |
+
|
| 187 |
+
out:
|
| 188 |
+
/* The space for normalized_codeset is dynamically allocated. Free it. */
|
| 189 |
+
if (mask & XPG_NORM_CODESET)
|
| 190 |
+
free ((void *) normalized_codeset);
|
| 191 |
+
|
| 192 |
+
return retval;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
#ifdef _LIBC
|
| 197 |
+
/* This is called from iconv/gconv_db.c's free_mem, as locales must
|
| 198 |
+
be freed before freeing gconv steps arrays. */
|
| 199 |
+
void __libc_freeres_fn_section
|
| 200 |
+
_nl_finddomain_subfreeres ()
|
| 201 |
+
{
|
| 202 |
+
struct loaded_l10nfile *runp = _nl_loaded_domains;
|
| 203 |
+
|
| 204 |
+
while (runp != NULL)
|
| 205 |
+
{
|
| 206 |
+
struct loaded_l10nfile *here = runp;
|
| 207 |
+
if (runp->data != NULL)
|
| 208 |
+
_nl_unload_domain ((struct loaded_domain *) runp->data);
|
| 209 |
+
runp = runp->next;
|
| 210 |
+
free ((char *) here->filename);
|
| 211 |
+
free (here);
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
#endif
|
pool/shard007/C/0124268_dewarptest2.c
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*====================================================================*
|
| 2 |
+
- Copyright (C) 2001 Leptonica. All rights reserved.
|
| 3 |
+
-
|
| 4 |
+
- Redistribution and use in source and binary forms, with or without
|
| 5 |
+
- modification, are permitted provided that the following conditions
|
| 6 |
+
- are met:
|
| 7 |
+
- 1. Redistributions of source code must retain the above copyright
|
| 8 |
+
- notice, this list of conditions and the following disclaimer.
|
| 9 |
+
- 2. Redistributions in binary form must reproduce the above
|
| 10 |
+
- copyright notice, this list of conditions and the following
|
| 11 |
+
- disclaimer in the documentation and/or other materials
|
| 12 |
+
- provided with the distribution.
|
| 13 |
+
-
|
| 14 |
+
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 15 |
+
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 16 |
+
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 17 |
+
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
|
| 18 |
+
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 19 |
+
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 20 |
+
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 21 |
+
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
| 22 |
+
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 23 |
+
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 24 |
+
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 25 |
+
*====================================================================*/
|
| 26 |
+
|
| 27 |
+
/*
|
| 28 |
+
* dewarptest2.c
|
| 29 |
+
*
|
| 30 |
+
* This runs the basic functions for a single page. It can be used
|
| 31 |
+
* to debug the disparity model-building.
|
| 32 |
+
*
|
| 33 |
+
* dewarptest2 method [image pageno]
|
| 34 |
+
*
|
| 35 |
+
* where: method = 1 (use single page dewarp function)
|
| 36 |
+
* 2 (break down into multiple steps)
|
| 37 |
+
*
|
| 38 |
+
* Default image is cat.035.jpg.
|
| 39 |
+
* Others are 1555.007.jpg, etc.
|
| 40 |
+
*/
|
| 41 |
+
|
| 42 |
+
#include "allheaders.h"
|
| 43 |
+
|
| 44 |
+
#define NORMALIZE 1
|
| 45 |
+
|
| 46 |
+
l_int32 main(int argc,
|
| 47 |
+
char **argv)
|
| 48 |
+
{
|
| 49 |
+
l_int32 method, pageno;
|
| 50 |
+
L_DEWARP *dew1;
|
| 51 |
+
L_DEWARPA *dewa;
|
| 52 |
+
PIX *pixs, *pixn, *pixg, *pixb, *pixd;
|
| 53 |
+
static char mainName[] = "dewarptest2";
|
| 54 |
+
|
| 55 |
+
if (argc != 2 && argc != 4)
|
| 56 |
+
return ERROR_INT("Syntax: dewarptest2 method [image pageno]",
|
| 57 |
+
mainName, 1);
|
| 58 |
+
|
| 59 |
+
if (argc == 2) {
|
| 60 |
+
pixs = pixRead("cat.035.jpg");
|
| 61 |
+
pageno = 35;
|
| 62 |
+
}
|
| 63 |
+
else {
|
| 64 |
+
pixs = pixRead(argv[2]);
|
| 65 |
+
pageno = atoi(argv[3]);
|
| 66 |
+
}
|
| 67 |
+
if (!pixs)
|
| 68 |
+
return ERROR_INT("image not read", mainName, 1);
|
| 69 |
+
method = atoi(argv[1]);
|
| 70 |
+
lept_mkdir("lept/dewarp");
|
| 71 |
+
|
| 72 |
+
if (method == 1) { /* Use single page dewarp function */
|
| 73 |
+
dewarpSinglePage(pixs, 0, 1, 1, &pixd, NULL, 1);
|
| 74 |
+
pixDisplay(pixd, 100, 100);
|
| 75 |
+
} else { /* Break down into multiple steps; require min of only 8 lines */
|
| 76 |
+
dewa = dewarpaCreate(40, 30, 1, 8, 50);
|
| 77 |
+
dewarpaUseBothArrays(dewa, 1);
|
| 78 |
+
|
| 79 |
+
#if NORMALIZE
|
| 80 |
+
/* Normalize for varying background and binarize */
|
| 81 |
+
pixn = pixBackgroundNormSimple(pixs, NULL, NULL);
|
| 82 |
+
pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2);
|
| 83 |
+
pixb = pixThresholdToBinary(pixg, 130);
|
| 84 |
+
pixDestroy(&pixn);
|
| 85 |
+
#else
|
| 86 |
+
/* Don't normalize; just threshold and clean edges */
|
| 87 |
+
pixg = pixConvertTo8(pixs, 0);
|
| 88 |
+
pixb = pixThresholdToBinary(pixg, 100);
|
| 89 |
+
pixSetOrClearBorder(pixb, 30, 30, 40, 40, PIX_CLR);
|
| 90 |
+
#endif
|
| 91 |
+
|
| 92 |
+
/* Run the basic functions */
|
| 93 |
+
dew1 = dewarpCreate(pixb, pageno);
|
| 94 |
+
dewarpaInsertDewarp(dewa, dew1);
|
| 95 |
+
dewarpBuildPageModel(dew1, "/tmp/lept/dewarp/test2_model.pdf");
|
| 96 |
+
dewarpaApplyDisparity(dewa, pageno, pixg, -1, 0, 0, &pixd,
|
| 97 |
+
"/tmp/lept/dewarp/test2_apply.pdf");
|
| 98 |
+
|
| 99 |
+
dewarpaInfo(stderr, dewa);
|
| 100 |
+
dewarpaDestroy(&dewa);
|
| 101 |
+
pixDestroy(&pixg);
|
| 102 |
+
pixDestroy(&pixb);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
pixDestroy(&pixs);
|
| 106 |
+
pixDestroy(&pixd);
|
| 107 |
+
return 0;
|
| 108 |
+
}
|
pool/shard007/C/0124269_pp_program.c
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**************************************************************************
|
| 2 |
+
*
|
| 3 |
+
* Copyright 2010 Jakob Bornecrantz
|
| 4 |
+
* Copyright 2011 Lauri Kasanen
|
| 5 |
+
* All Rights Reserved.
|
| 6 |
+
*
|
| 7 |
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
| 8 |
+
* copy of this software and associated documentation files (the
|
| 9 |
+
* "Software"), to deal in the Software without restriction, including
|
| 10 |
+
* without limitation the rights to use, copy, modify, merge, publish,
|
| 11 |
+
* distribute, sub license, and/or sell copies of the Software, and to
|
| 12 |
+
* permit persons to whom the Software is furnished to do so, subject to
|
| 13 |
+
* the following conditions:
|
| 14 |
+
*
|
| 15 |
+
* The above copyright notice and this permission notice (including the
|
| 16 |
+
* next paragraph) shall be included in all copies or substantial portions
|
| 17 |
+
* of the Software.
|
| 18 |
+
*
|
| 19 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| 20 |
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 21 |
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
| 22 |
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
| 23 |
+
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
| 24 |
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
| 25 |
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 26 |
+
*
|
| 27 |
+
**************************************************************************/
|
| 28 |
+
|
| 29 |
+
#include "postprocess/postprocess.h"
|
| 30 |
+
#include "cso_cache/cso_context.h"
|
| 31 |
+
#include "pipe/p_screen.h"
|
| 32 |
+
#include "pipe/p_context.h"
|
| 33 |
+
#include "pipe/p_state.h"
|
| 34 |
+
#include "pipe/p_shader_tokens.h"
|
| 35 |
+
#include "util/u_inlines.h"
|
| 36 |
+
#include "util/u_simple_shaders.h"
|
| 37 |
+
#include "util/u_memory.h"
|
| 38 |
+
|
| 39 |
+
/** Initialize the internal details */
|
| 40 |
+
struct program *
|
| 41 |
+
pp_init_prog(struct pp_queue_t *ppq, struct pipe_context *pipe,
|
| 42 |
+
struct cso_context *cso)
|
| 43 |
+
{
|
| 44 |
+
struct program *p;
|
| 45 |
+
|
| 46 |
+
pp_debug("Initializing program\n");
|
| 47 |
+
if (!pipe)
|
| 48 |
+
return NULL;
|
| 49 |
+
|
| 50 |
+
p = CALLOC(1, sizeof(struct program));
|
| 51 |
+
if (!p)
|
| 52 |
+
return NULL;
|
| 53 |
+
|
| 54 |
+
p->screen = pipe->screen;
|
| 55 |
+
p->pipe = pipe;
|
| 56 |
+
p->cso = cso;
|
| 57 |
+
|
| 58 |
+
{
|
| 59 |
+
static const float verts[4][2][4] = {
|
| 60 |
+
{
|
| 61 |
+
{1.0f, 1.0f, 0.0f, 1.0f},
|
| 62 |
+
{1.0f, 1.0f, 0.0f, 1.0f}
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
{-1.0f, 1.0f, 0.0f, 1.0f},
|
| 66 |
+
{0.0f, 1.0f, 0.0f, 1.0f}
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
{-1.0f, -1.0f, 0.0f, 1.0f},
|
| 70 |
+
{0.0f, 0.0f, 0.0f, 1.0f}
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
{1.0f, -1.0f, 0.0f, 1.0f},
|
| 74 |
+
{1.0f, 0.0f, 0.0f, 1.0f}
|
| 75 |
+
}
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
p->vbuf = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
|
| 79 |
+
PIPE_USAGE_STATIC, sizeof(verts));
|
| 80 |
+
pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(verts), verts);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
p->blend.rt[0].colormask = PIPE_MASK_RGBA;
|
| 84 |
+
p->blend.rt[0].rgb_src_factor = p->blend.rt[0].alpha_src_factor =
|
| 85 |
+
PIPE_BLENDFACTOR_SRC_ALPHA;
|
| 86 |
+
p->blend.rt[0].rgb_dst_factor = p->blend.rt[0].alpha_dst_factor =
|
| 87 |
+
PIPE_BLENDFACTOR_INV_SRC_ALPHA;
|
| 88 |
+
|
| 89 |
+
p->rasterizer.cull_face = PIPE_FACE_NONE;
|
| 90 |
+
p->rasterizer.half_pixel_center = 1;
|
| 91 |
+
p->rasterizer.bottom_edge_rule = 1;
|
| 92 |
+
p->rasterizer.depth_clip = 1;
|
| 93 |
+
|
| 94 |
+
p->sampler.wrap_s = p->sampler.wrap_t = p->sampler.wrap_r =
|
| 95 |
+
PIPE_TEX_WRAP_CLAMP_TO_EDGE;
|
| 96 |
+
|
| 97 |
+
p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
|
| 98 |
+
p->sampler.min_img_filter = p->sampler.mag_img_filter =
|
| 99 |
+
PIPE_TEX_FILTER_LINEAR;
|
| 100 |
+
p->sampler.normalized_coords = 1;
|
| 101 |
+
|
| 102 |
+
p->sampler_point.wrap_s = p->sampler_point.wrap_t =
|
| 103 |
+
p->sampler_point.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
|
| 104 |
+
p->sampler_point.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
|
| 105 |
+
p->sampler_point.min_img_filter = p->sampler_point.mag_img_filter =
|
| 106 |
+
PIPE_TEX_FILTER_NEAREST;
|
| 107 |
+
p->sampler_point.normalized_coords = 1;
|
| 108 |
+
|
| 109 |
+
p->velem[0].src_offset = 0;
|
| 110 |
+
p->velem[0].instance_divisor = 0;
|
| 111 |
+
p->velem[0].vertex_buffer_index = 0;
|
| 112 |
+
p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
|
| 113 |
+
p->velem[1].src_offset = 1 * 4 * sizeof(float);
|
| 114 |
+
p->velem[1].instance_divisor = 0;
|
| 115 |
+
p->velem[1].vertex_buffer_index = 0;
|
| 116 |
+
p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
|
| 117 |
+
|
| 118 |
+
if (!p->screen->is_format_supported(p->screen,
|
| 119 |
+
PIPE_FORMAT_R32G32B32A32_FLOAT,
|
| 120 |
+
PIPE_BUFFER, 1,
|
| 121 |
+
PIPE_BIND_VERTEX_BUFFER))
|
| 122 |
+
pp_debug("Vertex buf format fail\n");
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
{
|
| 126 |
+
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
|
| 127 |
+
TGSI_SEMANTIC_GENERIC
|
| 128 |
+
};
|
| 129 |
+
const uint semantic_indexes[] = { 0, 0 };
|
| 130 |
+
p->passvs = util_make_vertex_passthrough_shader(p->pipe, 2,
|
| 131 |
+
semantic_names,
|
| 132 |
+
semantic_indexes);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
p->framebuffer.nr_cbufs = 1;
|
| 136 |
+
|
| 137 |
+
p->surf.format = PIPE_FORMAT_B8G8R8A8_UNORM;
|
| 138 |
+
|
| 139 |
+
return p;
|
| 140 |
+
}
|
pool/shard007/C/0124270_duk_hthread_misc.c
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Thread support.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#include "duk_internal.h"
|
| 6 |
+
|
| 7 |
+
/* FIXME: separate "executor" thread and "target" thread for DECREF?
|
| 8 |
+
* This function is a bit dangerous because we free the built-ins and
|
| 9 |
+
* DECREF. If a built-in gets DECREF'd to zero and has a finalizer,
|
| 10 |
+
* we might have some problems in the finalizer.
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
void duk_hthread_terminate(duk_hthread *thr) {
|
| 14 |
+
int i;
|
| 15 |
+
|
| 16 |
+
DUK_ASSERT(thr != NULL);
|
| 17 |
+
|
| 18 |
+
duk_hthread_callstack_unwind(thr, 0); /* side effects, possibly errors */
|
| 19 |
+
|
| 20 |
+
duk_hthread_catchstack_unwind(thr, 0);
|
| 21 |
+
|
| 22 |
+
thr->valstack_bottom = thr->valstack;
|
| 23 |
+
duk_set_top((duk_context *) thr, 0); /* unwinds valstack, updating refcounts */
|
| 24 |
+
|
| 25 |
+
for (i = 0; i < DUK_NUM_BUILTINS; i++) {
|
| 26 |
+
#ifdef DUK_USE_REFERENCE_COUNTING
|
| 27 |
+
duk_hobject *h = thr->builtins[i];
|
| 28 |
+
#endif
|
| 29 |
+
thr->builtins[i] = NULL;
|
| 30 |
+
#ifdef DUK_USE_REFERENCE_COUNTING
|
| 31 |
+
DUK_HOBJECT_DECREF(thr, h);
|
| 32 |
+
#endif
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
thr->state = DUK_HTHREAD_STATE_TERMINATED;
|
| 36 |
+
|
| 37 |
+
/* FIXME: shrink to minimum size, but don't free stacks? */
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
duk_activation *duk_hthread_get_current_activation(duk_hthread *thr) {
|
| 41 |
+
DUK_ASSERT(thr != NULL);
|
| 42 |
+
|
| 43 |
+
if (thr->callstack_top > 0) {
|
| 44 |
+
return thr->callstack + thr->callstack_top - 1;
|
| 45 |
+
} else {
|
| 46 |
+
return NULL;
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
pool/shard007/C/0124271_md5_test.c
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or
|
| 5 |
+
* modify it under the terms of the GNU General Public License as
|
| 6 |
+
* published by the Free Software Foundation; either version 2 of the
|
| 7 |
+
* License, or any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful, but
|
| 10 |
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 12 |
+
* General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program; if not, write to the Free Software
|
| 16 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
| 17 |
+
* 02110-1301, USA.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
FILE_LICENCE ( GPL2_OR_LATER );
|
| 21 |
+
|
| 22 |
+
/** @file
|
| 23 |
+
*
|
| 24 |
+
* MD5 tests
|
| 25 |
+
*
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
#include <stdint.h>
|
| 29 |
+
#include <ipxe/md5.h>
|
| 30 |
+
#include <ipxe/test.h>
|
| 31 |
+
#include "digest_test.h"
|
| 32 |
+
|
| 33 |
+
/** An MD5 test vector */
|
| 34 |
+
struct md5_test_vector {
|
| 35 |
+
/** Test data */
|
| 36 |
+
void *data;
|
| 37 |
+
/** Test data length */
|
| 38 |
+
size_t len;
|
| 39 |
+
/** Expected digest */
|
| 40 |
+
uint8_t digest[MD5_DIGEST_SIZE];
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
/** MD5 test vectors */
|
| 44 |
+
static struct md5_test_vector md5_test_vectors[] = {
|
| 45 |
+
/* Test inputs borrowed from SHA-1 tests, with results
|
| 46 |
+
* calculated using md5sum.
|
| 47 |
+
*/
|
| 48 |
+
{ NULL, 0,
|
| 49 |
+
{ 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
|
| 50 |
+
0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } },
|
| 51 |
+
{ "abc", 3,
|
| 52 |
+
{ 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0,
|
| 53 |
+
0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } },
|
| 54 |
+
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
|
| 55 |
+
{ 0x82, 0x15, 0xef, 0x07, 0x96, 0xa2, 0x0b, 0xca,
|
| 56 |
+
0xaa, 0xe1, 0x16, 0xd3, 0x87, 0x6c, 0x66, 0x4a } },
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
/** MD5 test fragment lists */
|
| 60 |
+
static struct digest_test_fragments md5_test_fragments[] = {
|
| 61 |
+
{ { 0, -1UL, } },
|
| 62 |
+
{ { 1, 1, 1, 1, 1, 1, 1, 1 } },
|
| 63 |
+
{ { 2, 0, 23, 4, 6, 1, 0 } },
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Perform MD5 self-test
|
| 68 |
+
*
|
| 69 |
+
*/
|
| 70 |
+
static void md5_test_exec ( void ) {
|
| 71 |
+
struct digest_algorithm *digest = &md5_algorithm;
|
| 72 |
+
struct md5_test_vector *test;
|
| 73 |
+
unsigned long cost;
|
| 74 |
+
unsigned int i;
|
| 75 |
+
unsigned int j;
|
| 76 |
+
|
| 77 |
+
/* Correctness test */
|
| 78 |
+
for ( i = 0 ; i < ( sizeof ( md5_test_vectors ) /
|
| 79 |
+
sizeof ( md5_test_vectors[0] ) ) ; i++ ) {
|
| 80 |
+
test = &md5_test_vectors[i];
|
| 81 |
+
/* Test with a single pass */
|
| 82 |
+
digest_ok ( digest, NULL, test->data, test->len, test->digest );
|
| 83 |
+
/* Test with fragment lists */
|
| 84 |
+
for ( j = 0 ; j < ( sizeof ( md5_test_fragments ) /
|
| 85 |
+
sizeof ( md5_test_fragments[0] ) ) ; j++ ){
|
| 86 |
+
digest_ok ( digest, &md5_test_fragments[j],
|
| 87 |
+
test->data, test->len, test->digest );
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/* Speed test */
|
| 92 |
+
cost = digest_cost ( digest );
|
| 93 |
+
DBG ( "MD5 required %ld cycles per byte\n", cost );
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/** MD5 self-test */
|
| 97 |
+
struct self_test md5_test __self_test = {
|
| 98 |
+
.name = "md5",
|
| 99 |
+
.exec = md5_test_exec,
|
| 100 |
+
};
|
pool/shard007/C/0124273_vl_ihashsum.c
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @internal
|
| 2 |
+
** @file ihashsum.c
|
| 3 |
+
** @author Andrea Vedaldi
|
| 4 |
+
** @brief BINSUM - MEX
|
| 5 |
+
**/
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
|
| 9 |
+
All rights reserved.
|
| 10 |
+
|
| 11 |
+
This file is part of the VLFeat library and is made available under
|
| 12 |
+
the terms of the BSD license (see the COPYING file).
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
#include <mexutils.h>
|
| 16 |
+
#include <vl/generic.h>
|
| 17 |
+
|
| 18 |
+
#include <string.h>
|
| 19 |
+
|
| 20 |
+
/* hash function */
|
| 21 |
+
unsigned int fnv_hash (void const *key, int len)
|
| 22 |
+
{
|
| 23 |
+
unsigned char const *p = key;
|
| 24 |
+
unsigned int h = 2166136261U ;
|
| 25 |
+
int i;
|
| 26 |
+
|
| 27 |
+
for ( i = 0; i < len; i++ )
|
| 28 |
+
h = ( h * 16777619 ) ^ p[i];
|
| 29 |
+
|
| 30 |
+
return h;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
int
|
| 34 |
+
is_null (vl_uint8 const * x, int n)
|
| 35 |
+
{
|
| 36 |
+
int i ;
|
| 37 |
+
for (i = 0 ; i < n ; ++i) {
|
| 38 |
+
if (x[i]) return 0 ;
|
| 39 |
+
}
|
| 40 |
+
return 1 ;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
int
|
| 44 |
+
is_equal (vl_uint8 const * x, vl_uint8 const * y, int n)
|
| 45 |
+
{
|
| 46 |
+
int i ;
|
| 47 |
+
for (i = 0 ; i < n ; ++i) {
|
| 48 |
+
if (x[i] != y[i]) return 0 ;
|
| 49 |
+
}
|
| 50 |
+
return 1 ;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
void
|
| 54 |
+
cpy (vl_uint8 * x, vl_uint8 const * y, int n)
|
| 55 |
+
{
|
| 56 |
+
int i ;
|
| 57 |
+
for (i = 0 ; i < n ; ++i){
|
| 58 |
+
/* mexPrintf("cpy:%d %d\n",x[i],y[i]);*/
|
| 59 |
+
x[i] = y[i] ;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/** @brief Driver.
|
| 64 |
+
**
|
| 65 |
+
** @param nount number of output arguments.
|
| 66 |
+
** @param out output arguments.
|
| 67 |
+
** @param nin number of input arguments.
|
| 68 |
+
** @param in input arguments.
|
| 69 |
+
**/
|
| 70 |
+
void
|
| 71 |
+
mexFunction(int nout, mxArray *out[],
|
| 72 |
+
int nin, const mxArray *in[])
|
| 73 |
+
{
|
| 74 |
+
enum { IN_H, IN_ID, IN_NEXT, IN_K, IN_X } ;
|
| 75 |
+
enum { OUT_H, OUT_ID, OUT_NEXT} ;
|
| 76 |
+
|
| 77 |
+
mxArray *h_, *id_, *next_ ;
|
| 78 |
+
|
| 79 |
+
vl_uint32 * h ;
|
| 80 |
+
vl_uint32 * next ;
|
| 81 |
+
|
| 82 |
+
vl_uint8 * id ;
|
| 83 |
+
vl_uint8 const * x ;
|
| 84 |
+
|
| 85 |
+
unsigned int K, i, N, res, last, ndims ;
|
| 86 |
+
|
| 87 |
+
/* -----------------------------------------------------------------
|
| 88 |
+
* Check arguments
|
| 89 |
+
* -------------------------------------------------------------- */
|
| 90 |
+
|
| 91 |
+
if( nin != 5 ) {
|
| 92 |
+
mexErrMsgTxt("Five arguments required") ;
|
| 93 |
+
} else if (nout > 3) {
|
| 94 |
+
mexErrMsgTxt("At most three output argument.") ;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
if(! mxIsNumeric(in[IN_H]) || mxGetClassID(in[IN_H] )!= mxUINT32_CLASS ||
|
| 98 |
+
! mxIsNumeric(in[IN_NEXT])|| mxGetClassID(in[IN_NEXT])!= mxUINT32_CLASS) {
|
| 99 |
+
mexErrMsgTxt("H, NEXT must be UINT32.") ;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
if(! mxIsNumeric(in[IN_X]) || mxGetClassID(in[IN_X]) != mxUINT8_CLASS) {
|
| 103 |
+
mexErrMsgTxt("X must be UINT8") ;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
if (mxGetM(in[IN_H]) != 1 ||
|
| 107 |
+
mxGetM(in[IN_NEXT]) != 1) {
|
| 108 |
+
mexErrMsgTxt("H, NEXT must be row vectors") ;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
if(! mxIsNumeric(in[IN_ID]) || mxGetClassID(in[IN_ID])!= mxUINT8_CLASS) {
|
| 112 |
+
mexErrMsgTxt("ID must be UINT8.") ;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
ndims = mxGetM(in[IN_ID]) ;
|
| 116 |
+
res = mxGetN(in[IN_H]) ;
|
| 117 |
+
|
| 118 |
+
if(res != mxGetN(in[IN_ID]) ||
|
| 119 |
+
res != mxGetN(in[IN_NEXT])) {
|
| 120 |
+
mexErrMsgTxt("H, ID, NEXT must have the same number of columns") ;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
if(ndims != mxGetM(in[IN_X])) {
|
| 124 |
+
mexErrMsgTxt("ID and X must havethe same number of rows") ;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
if(! vlmxIsPlainScalar(in[IN_K])) {
|
| 128 |
+
mexErrMsgTxt("K must be a scalar") ;
|
| 129 |
+
}
|
| 130 |
+
K = (unsigned int) *mxGetPr(in[IN_K]) ;
|
| 131 |
+
|
| 132 |
+
h_ = mxDuplicateArray(in[IN_H]) ;
|
| 133 |
+
id_ = mxDuplicateArray(in[IN_ID]) ;
|
| 134 |
+
next_ = mxDuplicateArray(in[IN_NEXT]) ;
|
| 135 |
+
|
| 136 |
+
N = mxGetN(in[IN_X]) ;
|
| 137 |
+
|
| 138 |
+
h = mxGetData(h_ ) ;
|
| 139 |
+
id = mxGetData(id_ ) ;
|
| 140 |
+
next = mxGetData(next_) ;
|
| 141 |
+
x = mxGetData(in[IN_X]) ;
|
| 142 |
+
|
| 143 |
+
/*
|
| 144 |
+
Temporary remove mxArray pointers to these buffer as we will
|
| 145 |
+
mxRealloc them and if the user presses Ctrl-C matlab will attempt
|
| 146 |
+
to free unvalid memory
|
| 147 |
+
*/
|
| 148 |
+
|
| 149 |
+
mxSetData(h_, 0) ;
|
| 150 |
+
mxSetData(id_, 0) ;
|
| 151 |
+
mxSetData(next_, 0) ;
|
| 152 |
+
|
| 153 |
+
/* search for last occupied slot */
|
| 154 |
+
last = res ;
|
| 155 |
+
for (i = 0 ; i < res ; ++i) last = VL_MAX(last, next [i]) ;
|
| 156 |
+
|
| 157 |
+
/* REMARK: last and next are 1 based */
|
| 158 |
+
|
| 159 |
+
if (K > res) {
|
| 160 |
+
mexErrMsgTxt("K cannot be larger then the size of H") ;
|
| 161 |
+
}
|
| 162 |
+
if (last > res) {
|
| 163 |
+
mexErrMsgTxt("An element of NEXT is greater than the size of the table") ;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/* mexPrintf("last:%d\n",last) ;*/
|
| 167 |
+
|
| 168 |
+
/* -----------------------------------------------------------------
|
| 169 |
+
* Do job
|
| 170 |
+
* -------------------------------------------------------------- */
|
| 171 |
+
for (i = 0 ; i < N ; ++i) {
|
| 172 |
+
/* hash */
|
| 173 |
+
unsigned int h1, h2 ;
|
| 174 |
+
unsigned int j, p = 0 ;
|
| 175 |
+
|
| 176 |
+
/* cannot hash null labels */
|
| 177 |
+
if (is_null (x + i * ndims, ndims)) {
|
| 178 |
+
vlmxError(vlmxErrInvalidArgument, "The %d column of X is null.", i+1) ;
|
| 179 |
+
continue ;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
h1 = fnv_hash(x + i * ndims, ndims) % K ;
|
| 183 |
+
h2 = h1 | 0x1 ; /* this needs to be odd */
|
| 184 |
+
|
| 185 |
+
/* search first free or matching position */
|
| 186 |
+
p = h1 % K ;
|
| 187 |
+
for (j = 0 ; j < K ; ++j) {
|
| 188 |
+
if (is_null (id + p * ndims, ndims) ||
|
| 189 |
+
is_equal(id + p * ndims, x + i * ndims, ndims)) break ;
|
| 190 |
+
h1 += h2 ;
|
| 191 |
+
p = h1 % K ;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/* if after scanning the K elements in the hash table an empty/matching
|
| 195 |
+
bucket is still
|
| 196 |
+
not found, start using next to go into the overflow table */
|
| 197 |
+
while (! is_null (id + p * ndims, ndims) &&
|
| 198 |
+
! is_equal(id + p * ndims, x + i * ndims, ndims)) {
|
| 199 |
+
if (next [p] > res) {
|
| 200 |
+
mexErrMsgTxt("An element of NEXT is greater than the size of the table") ;
|
| 201 |
+
}
|
| 202 |
+
/* append */
|
| 203 |
+
if (next [p] == 0) {
|
| 204 |
+
if (last >= res) {
|
| 205 |
+
size_t res_ = res + VL_MAX(res / 2, 2) ;
|
| 206 |
+
h = mxRealloc(h, res_ * sizeof(vl_uint32) ) ;
|
| 207 |
+
next = mxRealloc(next, res_ * sizeof(vl_uint32) ) ;
|
| 208 |
+
id = mxRealloc(id, res_ * sizeof(vl_uint8) * ndims) ;
|
| 209 |
+
memset (h + res, 0, (res_ - res) * sizeof(vl_uint32) ) ;
|
| 210 |
+
memset (next + res, 0, (res_ - res) * sizeof(vl_uint32) ) ;
|
| 211 |
+
memset (id + res * ndims, 0, (res_ - res) * sizeof(vl_uint8) * ndims) ;
|
| 212 |
+
res = res_ ;
|
| 213 |
+
}
|
| 214 |
+
next [p] = ++ last ;
|
| 215 |
+
}
|
| 216 |
+
p = next [p] - 1 ;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/* accumulate */
|
| 220 |
+
h [p] += 1 ;
|
| 221 |
+
/* mexPrintf("p %d dims %d i %d N %d\n ", p, ndims, i, N) ;*/
|
| 222 |
+
cpy(id + p * ndims, x + i * ndims, ndims) ;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
mxSetData(h_, mxRealloc(h, last * sizeof(vl_uint32) )) ;
|
| 226 |
+
mxSetData(next_, mxRealloc(next, last * sizeof(vl_uint32) )) ;
|
| 227 |
+
mxSetData(id_, mxRealloc(id, last * sizeof(vl_uint8 ) * ndims)) ;
|
| 228 |
+
|
| 229 |
+
mxSetN(h_, last) ;
|
| 230 |
+
mxSetN(id_, last) ;
|
| 231 |
+
mxSetN(next_, last) ;
|
| 232 |
+
|
| 233 |
+
mxSetM(h_, 1) ;
|
| 234 |
+
mxSetM(next_, 1) ;
|
| 235 |
+
mxSetM(id_, ndims) ;
|
| 236 |
+
|
| 237 |
+
out[OUT_H] = h_ ;
|
| 238 |
+
out[OUT_ID] = id_ ;
|
| 239 |
+
out[OUT_NEXT] = next_ ;
|
| 240 |
+
}
|
pool/shard007/C/0124274_outputKeystroke.c
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
void printChar(int keycode[4])
|
| 2 |
+
{
|
| 3 |
+
Display *display;
|
| 4 |
+
int bksp,ctrl,shift,charU,caps;
|
| 5 |
+
|
| 6 |
+
display = XOpenDisplay(NULL);
|
| 7 |
+
|
| 8 |
+
bksp = XKeysymToKeycode(display, XK_BackSpace);
|
| 9 |
+
ctrl = XKeysymToKeycode(display, XK_Control_L);
|
| 10 |
+
shift = XKeysymToKeycode(display, XK_Shift_L);
|
| 11 |
+
charU = XKeysymToKeycode(display, XK_U);
|
| 12 |
+
caps = XKeysymToKeycode(display,XK_Caps_Lock);
|
| 13 |
+
|
| 14 |
+
XFlush( display );
|
| 15 |
+
|
| 16 |
+
printf("\nPrinting devanagari");
|
| 17 |
+
|
| 18 |
+
/*To turn off caps lock if ON */
|
| 19 |
+
if(xtest_get_capslock_state())
|
| 20 |
+
{
|
| 21 |
+
|
| 22 |
+
XTestFakeKeyEvent(display, caps, True, 0);
|
| 23 |
+
XTestFakeKeyEvent(display, caps, False, 0);
|
| 24 |
+
printf("\nCaps Lock OFF");
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
XTestFakeKeyEvent(display, bksp, True, 0);
|
| 28 |
+
XTestFakeKeyEvent(display, bksp, False,0);
|
| 29 |
+
|
| 30 |
+
XTestFakeKeyEvent(display, ctrl, True, 0);
|
| 31 |
+
XTestFakeKeyEvent(display, shift, True, 0);
|
| 32 |
+
|
| 33 |
+
XTestFakeKeyEvent(display, charU, True, 0);
|
| 34 |
+
XTestFakeKeyEvent(display, charU, False, 0);
|
| 35 |
+
|
| 36 |
+
XTestFakeKeyEvent(display, keycode[0], True, 0);
|
| 37 |
+
XTestFakeKeyEvent(display, keycode[0], False, 0);
|
| 38 |
+
|
| 39 |
+
XTestFakeKeyEvent(display, keycode[1], True, 0);
|
| 40 |
+
XTestFakeKeyEvent(display, keycode[1], False,0);
|
| 41 |
+
|
| 42 |
+
XTestFakeKeyEvent(display, keycode[2], True,0);
|
| 43 |
+
XTestFakeKeyEvent(display, keycode[2], False,0);
|
| 44 |
+
|
| 45 |
+
XTestFakeKeyEvent(display, keycode[3], True, 0);
|
| 46 |
+
XTestFakeKeyEvent(display, keycode[3], False, 0);
|
| 47 |
+
|
| 48 |
+
XTestFakeKeyEvent(display, shift, False, 0);
|
| 49 |
+
XTestFakeKeyEvent(display, ctrl, False,0);
|
| 50 |
+
|
| 51 |
+
XFlush( display );
|
| 52 |
+
XCloseDisplay( display );
|
| 53 |
+
/*if this option is not enabled then Maximum no. of clients reached error*/
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void printCharLong(char *arg,int bksp)
|
| 57 |
+
{
|
| 58 |
+
Display *display;
|
| 59 |
+
display = XOpenDisplay(NULL);
|
| 60 |
+
KeySym sym = XStringToKeysym(arg);
|
| 61 |
+
|
| 62 |
+
int min, max, numcodes;
|
| 63 |
+
XDisplayKeycodes(display,&min,&max);
|
| 64 |
+
KeySym *keysym;
|
| 65 |
+
|
| 66 |
+
keysym = XGetKeyboardMapping(display,min,max-min+1,&numcodes);
|
| 67 |
+
keysym[(max-min-1)*numcodes]=sym;
|
| 68 |
+
XChangeKeyboardMapping(display,min,numcodes,keysym,(max-min));
|
| 69 |
+
XFree(keysym);
|
| 70 |
+
XFlush( display );
|
| 71 |
+
|
| 72 |
+
KeyCode code = XKeysymToKeycode(display,sym);
|
| 73 |
+
|
| 74 |
+
if(bksp)
|
| 75 |
+
{
|
| 76 |
+
XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_BackSpace), True, 0);
|
| 77 |
+
XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_BackSpace), False, 0);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
XTestFakeKeyEvent(display, code, True, 0);
|
| 81 |
+
XTestFakeKeyEvent(display, code, False, 0);
|
| 82 |
+
|
| 83 |
+
XFlush( display );
|
| 84 |
+
XCloseDisplay( display );
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
void printExChar(char *whichKey,int count)
|
| 89 |
+
{
|
| 90 |
+
Display *display;
|
| 91 |
+
int bksp,ctrl,shift,charU,charV;
|
| 92 |
+
|
| 93 |
+
display = XOpenDisplay(NULL);
|
| 94 |
+
|
| 95 |
+
bksp = XKeysymToKeycode(display, XK_BackSpace);
|
| 96 |
+
|
| 97 |
+
while(count)
|
| 98 |
+
{
|
| 99 |
+
if(!strcmp(whichKey,"bksp"))
|
| 100 |
+
{
|
| 101 |
+
printf("\nPrint %d backspace(s)",count);
|
| 102 |
+
|
| 103 |
+
XTestFakeKeyEvent(display, bksp, True, 0);
|
| 104 |
+
XTestFakeKeyEvent(display, bksp, False,0);
|
| 105 |
+
|
| 106 |
+
XFlush( display );
|
| 107 |
+
XCloseDisplay( display );
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
count--;
|
| 111 |
+
}
|
| 112 |
+
}
|
pool/shard007/C/0124275_parseiptables.c
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Modified by: xChaos, 20131208 */
|
| 2 |
+
|
| 3 |
+
#include "cll1-0.6.2.h"
|
| 4 |
+
#include "ipstruct.h"
|
| 5 |
+
|
| 6 |
+
#define STRLEN 256
|
| 7 |
+
|
| 8 |
+
/* globals declared in prometheus.c */
|
| 9 |
+
extern struct IP *ips, *ip, *sharedip;
|
| 10 |
+
extern char *mark;
|
| 11 |
+
/* extern char *proxy_ip; */
|
| 12 |
+
extern int free_min;
|
| 13 |
+
extern int free_max;
|
| 14 |
+
extern int include_upload;
|
| 15 |
+
|
| 16 |
+
int traffic_detected = 0;
|
| 17 |
+
extern char *iptablesdump;
|
| 18 |
+
|
| 19 |
+
/* ===================== traffic analyser - uses iptables ================ */
|
| 20 |
+
|
| 21 |
+
void get_traffic_statistics(const char *whichiptables, int ipv6)
|
| 22 |
+
{
|
| 23 |
+
char *str,*cmd;
|
| 24 |
+
int downloadflag = 0;
|
| 25 |
+
FILE *f;
|
| 26 |
+
string(cmd,STRLEN);
|
| 27 |
+
|
| 28 |
+
sprintf(cmd, "%s -L -v -x -n -t mangle>%s", whichiptables, iptablesdump);
|
| 29 |
+
/*-----------------------------------------------------------------*/
|
| 30 |
+
printf("Running %s ...\n", cmd);
|
| 31 |
+
/*-----------------------------------------------------------------*/
|
| 32 |
+
system(cmd);
|
| 33 |
+
/*-----------------------------------------------------------------*/
|
| 34 |
+
printf("Processing %s ...\n", iptablesdump);
|
| 35 |
+
/*-----------------------------------------------------------------*/
|
| 36 |
+
f = fopen(iptablesdump,"r");
|
| 37 |
+
if(!f)
|
| 38 |
+
perror(iptablesdump);
|
| 39 |
+
|
| 40 |
+
while(!feof(f))
|
| 41 |
+
{
|
| 42 |
+
int col, accept = 0, /*proxyflag = 0, */valid = 1, setchainname = 0, commonflag = 0;
|
| 43 |
+
unsigned long long traffic = 0;
|
| 44 |
+
unsigned long pkts = 0;
|
| 45 |
+
char *ipaddr = NULL,*ptr;
|
| 46 |
+
|
| 47 |
+
string(str, STRLEN);
|
| 48 |
+
fgets(str, STRLEN, f);
|
| 49 |
+
valid_columns(ptr, str, ' ', col)
|
| 50 |
+
if(valid) switch(col)
|
| 51 |
+
{
|
| 52 |
+
case 1: if(eq(ptr,"Chain"))
|
| 53 |
+
{
|
| 54 |
+
setchainname = 1;
|
| 55 |
+
}
|
| 56 |
+
else if(eq(ptr,"pkts"))
|
| 57 |
+
{
|
| 58 |
+
valid = 0;
|
| 59 |
+
}
|
| 60 |
+
else
|
| 61 |
+
{
|
| 62 |
+
sscanf(ptr,"%lu",&pkts);
|
| 63 |
+
}
|
| 64 |
+
break;
|
| 65 |
+
case 2: if(setchainname)
|
| 66 |
+
{
|
| 67 |
+
if(!strncmp(ptr,"post_",5) || eq(ptr,"POSTROUTING"))
|
| 68 |
+
{
|
| 69 |
+
downloadflag = 1;
|
| 70 |
+
}
|
| 71 |
+
else
|
| 72 |
+
{
|
| 73 |
+
if(!strncmp(ptr,"forw_",5) || eq(ptr,"FORWARD"))
|
| 74 |
+
{
|
| 75 |
+
downloadflag = 0;
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
if(eq(ptr,"post_common") || eq(ptr,"forw_common"))
|
| 79 |
+
{
|
| 80 |
+
commonflag = 1;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
else
|
| 84 |
+
{
|
| 85 |
+
sscanf(ptr,"%Lu",&traffic);
|
| 86 |
+
traffic += (1<<19);
|
| 87 |
+
traffic >>= 20;
|
| 88 |
+
}
|
| 89 |
+
break;
|
| 90 |
+
case 3: if((strncmp(ptr,"post_",5) && strncmp(ptr,"forw_",5)) || commonflag)
|
| 91 |
+
{
|
| 92 |
+
accept = eq(ptr,mark);
|
| 93 |
+
}
|
| 94 |
+
break;
|
| 95 |
+
case 7: if(ipv6 && !downloadflag)
|
| 96 |
+
{
|
| 97 |
+
ipaddr = ptr;
|
| 98 |
+
}
|
| 99 |
+
break;
|
| 100 |
+
case 8: if(ipv6 && downloadflag)
|
| 101 |
+
{
|
| 102 |
+
ipaddr = ptr;
|
| 103 |
+
}
|
| 104 |
+
else if(!ipv6)
|
| 105 |
+
{
|
| 106 |
+
/* if(downloadflag)
|
| 107 |
+
{
|
| 108 |
+
if(strstr(proxy_ip,ptr))
|
| 109 |
+
{
|
| 110 |
+
proxyflag = 1;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
}
|
| 114 |
+
else
|
| 115 |
+
{ */
|
| 116 |
+
if(!downloadflag)
|
| 117 |
+
{
|
| 118 |
+
ipaddr = ptr;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
break;
|
| 122 |
+
case 9: if(!ipv6 && downloadflag)
|
| 123 |
+
{
|
| 124 |
+
ipaddr = ptr;
|
| 125 |
+
}
|
| 126 |
+
break;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if(accept && traffic>0 && ipaddr)
|
| 130 |
+
{
|
| 131 |
+
/* IPv6 subnet - /64 */
|
| 132 |
+
char *isipv6 = strstr(ipaddr,"/64");
|
| 133 |
+
if(ipv6 && isipv6)
|
| 134 |
+
{
|
| 135 |
+
*isipv6=0;
|
| 136 |
+
printf("(IPv6) ");
|
| 137 |
+
}
|
| 138 |
+
else
|
| 139 |
+
{
|
| 140 |
+
printf("(IPv4) ");
|
| 141 |
+
}
|
| 142 |
+
/*
|
| 143 |
+
if(proxyflag)
|
| 144 |
+
{
|
| 145 |
+
printf("(proxy) ");
|
| 146 |
+
}
|
| 147 |
+
else
|
| 148 |
+
*/
|
| 149 |
+
if(!downloadflag)
|
| 150 |
+
{
|
| 151 |
+
printf("(up) ");
|
| 152 |
+
}
|
| 153 |
+
else
|
| 154 |
+
{
|
| 155 |
+
printf("(down) ");
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
traffic_detected = 1;
|
| 159 |
+
printf("%s %Lu MB (%ld pkts)\n", ipaddr, traffic, pkts);
|
| 160 |
+
|
| 161 |
+
if_exists(ip, ips, eqi(ip->addr,ipaddr));
|
| 162 |
+
else
|
| 163 |
+
{
|
| 164 |
+
TheIP(ipaddr, FALSE);
|
| 165 |
+
if(eq(ip->addr,"0.0.0.0/0"))
|
| 166 |
+
{
|
| 167 |
+
ip->name = "(unregistered)";
|
| 168 |
+
ip->min = free_min;
|
| 169 |
+
ip->max = ip->desired=free_max;
|
| 170 |
+
}
|
| 171 |
+
else
|
| 172 |
+
{
|
| 173 |
+
ip->name = ipaddr;
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
if(downloadflag)
|
| 178 |
+
{
|
| 179 |
+
/*
|
| 180 |
+
if(proxyflag)
|
| 181 |
+
{
|
| 182 |
+
ip->proxy = traffic;
|
| 183 |
+
}
|
| 184 |
+
else
|
| 185 |
+
{*/
|
| 186 |
+
ip->traffic += traffic;
|
| 187 |
+
ip->traffic_down += traffic;
|
| 188 |
+
/* } */
|
| 189 |
+
ip->direct += traffic; /*-ip->proxy;*/
|
| 190 |
+
ip->pktsdown += pkts;
|
| 191 |
+
}
|
| 192 |
+
else
|
| 193 |
+
{
|
| 194 |
+
ip->upload += traffic;
|
| 195 |
+
ip->traffic_up += traffic;
|
| 196 |
+
ip->pktsup += pkts;
|
| 197 |
+
if(include_upload)
|
| 198 |
+
{
|
| 199 |
+
ip->traffic += traffic;
|
| 200 |
+
}
|
| 201 |
+
else
|
| 202 |
+
{
|
| 203 |
+
if(ip->upload > ip->traffic)
|
| 204 |
+
{
|
| 205 |
+
ip->traffic = ip->upload;
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
free(cmd);
|
| 212 |
+
}
|
pool/shard007/C/0124279_t-exp_taylor_sum.c
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2016 Fredrik Johansson
|
| 3 |
+
|
| 4 |
+
This file is part of Arb.
|
| 5 |
+
|
| 6 |
+
Arb is free software: you can redistribute it and/or modify it under
|
| 7 |
+
the terms of the GNU Lesser General Public License (LGPL) as published
|
| 8 |
+
by the Free Software Foundation; either version 2.1 of the License, or
|
| 9 |
+
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#include "arb_mat.h"
|
| 13 |
+
|
| 14 |
+
int main()
|
| 15 |
+
{
|
| 16 |
+
slong iter;
|
| 17 |
+
flint_rand_t state;
|
| 18 |
+
|
| 19 |
+
flint_printf("exp_sum_taylor....");
|
| 20 |
+
fflush(stdout);
|
| 21 |
+
|
| 22 |
+
flint_randinit(state);
|
| 23 |
+
|
| 24 |
+
for (iter = 0; iter < 500 * arb_test_multiplier(); iter++)
|
| 25 |
+
{
|
| 26 |
+
arb_mat_t A, S1, S2, S3;
|
| 27 |
+
fmpz_t f;
|
| 28 |
+
slong n, N, prec1, prec2;
|
| 29 |
+
|
| 30 |
+
n = n_randint(state, 5);
|
| 31 |
+
N = n_randint(state, 40);
|
| 32 |
+
prec1 = 2 + n_randint(state, 200);
|
| 33 |
+
prec2 = 2 + n_randint(state, 200);
|
| 34 |
+
|
| 35 |
+
arb_mat_init(A, n, n);
|
| 36 |
+
arb_mat_init(S1, n, n);
|
| 37 |
+
arb_mat_init(S2, n, n);
|
| 38 |
+
arb_mat_init(S3, n, n);
|
| 39 |
+
fmpz_init(f);
|
| 40 |
+
|
| 41 |
+
arb_mat_randtest(A, state, prec1, 10);
|
| 42 |
+
arb_mat_randtest(S1, state, prec1, 10);
|
| 43 |
+
arb_mat_randtest(S2, state, prec1, 10);
|
| 44 |
+
|
| 45 |
+
arb_mat_exp_taylor_sum(S1, A, N, prec1);
|
| 46 |
+
|
| 47 |
+
arb_mat_exp_taylor_sum(S2, A, N + 1, prec2);
|
| 48 |
+
|
| 49 |
+
arb_mat_pow_ui(S3, A, N, prec2);
|
| 50 |
+
fmpz_fac_ui(f, N);
|
| 51 |
+
arb_mat_scalar_div_fmpz(S3, S3, f, prec2);
|
| 52 |
+
arb_mat_add(S3, S3, S1, prec2);
|
| 53 |
+
|
| 54 |
+
if (!arb_mat_overlaps(S2, S3))
|
| 55 |
+
{
|
| 56 |
+
flint_printf("FAIL\n\n");
|
| 57 |
+
flint_printf("n = %wd, N = %wd\n", n, N);
|
| 58 |
+
flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
|
| 59 |
+
flint_printf("S1 = \n"); arb_mat_printd(S1, 15); flint_printf("\n\n");
|
| 60 |
+
flint_printf("S2 = \n"); arb_mat_printd(S2, 15); flint_printf("\n\n");
|
| 61 |
+
flint_printf("S3 = \n"); arb_mat_printd(S3, 15); flint_printf("\n\n");
|
| 62 |
+
flint_abort();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
arb_mat_exp_taylor_sum(A, A, N, prec1);
|
| 66 |
+
|
| 67 |
+
if (!arb_mat_overlaps(A, S1))
|
| 68 |
+
{
|
| 69 |
+
flint_printf("FAIL (aliasing)\n\n");
|
| 70 |
+
flint_abort();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
arb_mat_clear(A);
|
| 74 |
+
arb_mat_clear(S1);
|
| 75 |
+
arb_mat_clear(S2);
|
| 76 |
+
arb_mat_clear(S3);
|
| 77 |
+
fmpz_clear(f);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
flint_randclear(state);
|
| 81 |
+
flint_cleanup();
|
| 82 |
+
flint_printf("PASS\n");
|
| 83 |
+
return EXIT_SUCCESS;
|
| 84 |
+
}
|
| 85 |
+
|
pool/shard007/C/0124280_list.c
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2015 Poddubny Michael
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*/
|
| 22 |
+
#include "base/list.h"
|
| 23 |
+
|
| 24 |
+
#include <assert.h>
|
| 25 |
+
#include <stdlib.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
|
| 28 |
+
#ifdef USE_MEMTRACK
|
| 29 |
+
#include <memtrack.h>
|
| 30 |
+
#endif
|
| 31 |
+
|
| 32 |
+
struct SListNode {
|
| 33 |
+
struct SListNode *next;
|
| 34 |
+
void *element;
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
struct SList {
|
| 38 |
+
struct SListNode *head;
|
| 39 |
+
struct SListNode *tail;
|
| 40 |
+
|
| 41 |
+
size_t size;
|
| 42 |
+
size_t element_size;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
extern SLIST *
|
| 46 |
+
slist_alloc(size_t element_size) {
|
| 47 |
+
SLIST *list = malloc(sizeof(SLIST));
|
| 48 |
+
|
| 49 |
+
if (list == NULL)
|
| 50 |
+
return NULL;
|
| 51 |
+
|
| 52 |
+
list->element_size = element_size;
|
| 53 |
+
list->head = NULL;
|
| 54 |
+
list->tail = NULL;
|
| 55 |
+
|
| 56 |
+
return list;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
extern void
|
| 60 |
+
slist_free(SLIST *list) {
|
| 61 |
+
struct SListNode *node;
|
| 62 |
+
|
| 63 |
+
while (list->head != NULL) {
|
| 64 |
+
node = list->head;
|
| 65 |
+
list->head = node->next;
|
| 66 |
+
|
| 67 |
+
free(node->element);
|
| 68 |
+
node->element = NULL;
|
| 69 |
+
|
| 70 |
+
free(node);
|
| 71 |
+
node = NULL;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
free(list);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
extern int
|
| 78 |
+
slist_prepend(SLIST *list, void *element) {
|
| 79 |
+
struct SListNode *node = malloc(sizeof(struct SListNode));
|
| 80 |
+
|
| 81 |
+
if(node == NULL)
|
| 82 |
+
return 0;
|
| 83 |
+
|
| 84 |
+
node->element = malloc(list->element_size);
|
| 85 |
+
|
| 86 |
+
memcpy(node->element, element, list->element_size);
|
| 87 |
+
|
| 88 |
+
node->next = list->head;
|
| 89 |
+
list->head = node;
|
| 90 |
+
|
| 91 |
+
if (list->tail == NULL)
|
| 92 |
+
list->tail = list->head;
|
| 93 |
+
|
| 94 |
+
return list->size++;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern int
|
| 98 |
+
slist_append(SLIST *list, void *element) {
|
| 99 |
+
struct SListNode *node = malloc(sizeof(struct SListNode));
|
| 100 |
+
|
| 101 |
+
if (node == NULL)
|
| 102 |
+
return 0;
|
| 103 |
+
|
| 104 |
+
node->element = malloc(list->element_size);
|
| 105 |
+
node->next = NULL;
|
| 106 |
+
|
| 107 |
+
memcpy(node->element, element, list->element_size);
|
| 108 |
+
|
| 109 |
+
if (list->head == NULL)
|
| 110 |
+
list->head = list->tail = node;
|
| 111 |
+
else {
|
| 112 |
+
list->tail->next = node;
|
| 113 |
+
list->tail = node;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return list->size++;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
extern int
|
| 120 |
+
slist_remove(SLIST *list, void *element) {
|
| 121 |
+
(void)list;
|
| 122 |
+
(void)element;
|
| 123 |
+
|
| 124 |
+
/* NOT IMPLEMENTED */
|
| 125 |
+
|
| 126 |
+
return -1;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
extern SLIST_ITERATOR
|
| 130 |
+
slist_head(SLIST *list, void *element) {
|
| 131 |
+
struct SListNode *node = list->head;
|
| 132 |
+
|
| 133 |
+
if (element)
|
| 134 |
+
memcpy(element, node->element, list->element_size);
|
| 135 |
+
|
| 136 |
+
return list->head;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
extern SLIST_ITERATOR
|
| 140 |
+
slist_tail(SLIST *list, void *element) {
|
| 141 |
+
struct SListNode *node = list->tail;
|
| 142 |
+
|
| 143 |
+
if (element)
|
| 144 |
+
memcpy(element, node->element, list->element_size);
|
| 145 |
+
|
| 146 |
+
return list->tail;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
extern SLIST_ITERATOR
|
| 150 |
+
slist_next(SLIST_ITERATOR iterator) {
|
| 151 |
+
assert(iterator != NULL);
|
| 152 |
+
|
| 153 |
+
return iterator->next;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
extern SLIST_ITERATOR
|
| 157 |
+
slist_previous(SLIST *list, SLIST_ITERATOR iterator) {
|
| 158 |
+
assert(iterator != NULL);
|
| 159 |
+
|
| 160 |
+
struct SListNode *node = list->head;
|
| 161 |
+
struct SListNode *prev;
|
| 162 |
+
|
| 163 |
+
while (node != NULL) {
|
| 164 |
+
prev = node;
|
| 165 |
+
node = node->next;
|
| 166 |
+
|
| 167 |
+
if (node == iterator)
|
| 168 |
+
return prev;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
return NULL;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
extern void*
|
| 175 |
+
slist_get(SLIST_ITERATOR iterator) {
|
| 176 |
+
return iterator->element;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
extern void
|
| 180 |
+
slist_for_each(SLIST *list, LIST_ITERATOR_FUNC iterator_func) {
|
| 181 |
+
assert(iterator_func != NULL);
|
| 182 |
+
|
| 183 |
+
struct SListNode *node = list->head;
|
| 184 |
+
|
| 185 |
+
bool quit = false;
|
| 186 |
+
|
| 187 |
+
while((node != NULL) && !quit) {
|
| 188 |
+
quit = iterator_func(node->element);
|
| 189 |
+
node = node->next;
|
| 190 |
+
}
|
| 191 |
+
}
|
pool/shard007/C/0124282_test_bos.c
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2018 Intel Corporation
|
| 3 |
+
*
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
#include <ztest.h>
|
| 8 |
+
#include <tc_util.h>
|
| 9 |
+
|
| 10 |
+
#include <sys/byteorder.h>
|
| 11 |
+
#include <usb/usb_device.h>
|
| 12 |
+
|
| 13 |
+
#include <usb/bos.h>
|
| 14 |
+
|
| 15 |
+
#include <logging/log.h>
|
| 16 |
+
LOG_MODULE_REGISTER(test_main, LOG_LEVEL_DBG);
|
| 17 |
+
|
| 18 |
+
/*
|
| 19 |
+
* Compare old style USB BOS definition with section aligned
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
static const uint8_t dummy_descriptor[] = {
|
| 23 |
+
0x00, 0x01, 0x02
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
static struct webusb_bos_desc {
|
| 27 |
+
struct usb_bos_descriptor bos;
|
| 28 |
+
struct usb_bos_platform_descriptor platform_webusb;
|
| 29 |
+
struct usb_bos_capability_webusb capability_data_webusb;
|
| 30 |
+
struct usb_bos_platform_descriptor platform_msos;
|
| 31 |
+
struct usb_bos_capability_msos capability_data_msos;
|
| 32 |
+
} __packed webusb_bos_descriptor = {
|
| 33 |
+
.bos = {
|
| 34 |
+
.bLength = sizeof(struct usb_bos_descriptor),
|
| 35 |
+
.bDescriptorType = USB_DESC_BOS,
|
| 36 |
+
.wTotalLength = sizeof(struct webusb_bos_desc),
|
| 37 |
+
.bNumDeviceCaps = 2,
|
| 38 |
+
},
|
| 39 |
+
/* WebUSB Platform Capability Descriptor:
|
| 40 |
+
* https://wicg.github.io/webusb/#webusb-platform-capability-descriptor
|
| 41 |
+
*/
|
| 42 |
+
.platform_webusb = {
|
| 43 |
+
.bLength = sizeof(struct usb_bos_platform_descriptor)
|
| 44 |
+
+ sizeof(struct usb_bos_capability_webusb),
|
| 45 |
+
.bDescriptorType = USB_DESC_DEVICE_CAPABILITY,
|
| 46 |
+
.bDevCapabilityType = USB_BOS_CAPABILITY_PLATFORM,
|
| 47 |
+
.bReserved = 0,
|
| 48 |
+
/* WebUSB Platform Capability UUID
|
| 49 |
+
* 3408b638-09a9-47a0-8bfd-a0768815b665
|
| 50 |
+
*/
|
| 51 |
+
.PlatformCapabilityUUID = {
|
| 52 |
+
0x38, 0xB6, 0x08, 0x34,
|
| 53 |
+
0xA9, 0x09,
|
| 54 |
+
0xA0, 0x47,
|
| 55 |
+
0x8B, 0xFD,
|
| 56 |
+
0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65,
|
| 57 |
+
},
|
| 58 |
+
},
|
| 59 |
+
.capability_data_webusb = {
|
| 60 |
+
.bcdVersion = sys_cpu_to_le16(0x0100),
|
| 61 |
+
.bVendorCode = 0x01,
|
| 62 |
+
.iLandingPage = 0x01
|
| 63 |
+
},
|
| 64 |
+
/* Microsoft OS 2.0 Platform Capability Descriptor
|
| 65 |
+
* See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/
|
| 66 |
+
* microsoft-defined-usb-descriptors
|
| 67 |
+
* Adapted from the source:
|
| 68 |
+
* https://github.com/sowbug/weblight/blob/master/firmware/webusb.c
|
| 69 |
+
* (BSD-2) Thanks http://janaxelson.com/files/ms_os_20_descriptors.c
|
| 70 |
+
*/
|
| 71 |
+
.platform_msos = {
|
| 72 |
+
.bLength = sizeof(struct usb_bos_platform_descriptor)
|
| 73 |
+
+ sizeof(struct usb_bos_capability_msos),
|
| 74 |
+
.bDescriptorType = USB_DESC_DEVICE_CAPABILITY,
|
| 75 |
+
.bDevCapabilityType = USB_BOS_CAPABILITY_PLATFORM,
|
| 76 |
+
.bReserved = 0,
|
| 77 |
+
.PlatformCapabilityUUID = {
|
| 78 |
+
/**
|
| 79 |
+
* MS OS 2.0 Platform Capability ID
|
| 80 |
+
* D8DD60DF-4589-4CC7-9CD2-659D9E648A9F
|
| 81 |
+
*/
|
| 82 |
+
0xDF, 0x60, 0xDD, 0xD8,
|
| 83 |
+
0x89, 0x45,
|
| 84 |
+
0xC7, 0x4C,
|
| 85 |
+
0x9C, 0xD2,
|
| 86 |
+
0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,
|
| 87 |
+
},
|
| 88 |
+
},
|
| 89 |
+
.capability_data_msos = {
|
| 90 |
+
/* Windows version (8.1) (0x06030000) */
|
| 91 |
+
.dwWindowsVersion = sys_cpu_to_le32(0x06030000),
|
| 92 |
+
.wMSOSDescriptorSetTotalLength =
|
| 93 |
+
sys_cpu_to_le16(sizeof(dummy_descriptor)),
|
| 94 |
+
.bMS_VendorCode = 0x02,
|
| 95 |
+
.bAltEnumCode = 0x00
|
| 96 |
+
}
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
/* In a case linker places data in a different order */
|
| 100 |
+
static struct webusb_bos_desc_2 {
|
| 101 |
+
struct usb_bos_descriptor bos;
|
| 102 |
+
struct usb_bos_platform_descriptor platform_msos;
|
| 103 |
+
struct usb_bos_capability_msos capability_data_msos;
|
| 104 |
+
struct usb_bos_platform_descriptor platform_webusb;
|
| 105 |
+
struct usb_bos_capability_webusb capability_data_webusb;
|
| 106 |
+
} __packed webusb_bos_descriptor_2;
|
| 107 |
+
|
| 108 |
+
USB_DEVICE_BOS_DESC_DEFINE_CAP struct usb_bos_webusb {
|
| 109 |
+
struct usb_bos_platform_descriptor platform;
|
| 110 |
+
struct usb_bos_capability_webusb cap;
|
| 111 |
+
} __packed cap_webusb = {
|
| 112 |
+
.platform = {
|
| 113 |
+
.bLength = sizeof(struct usb_bos_platform_descriptor) +
|
| 114 |
+
sizeof(struct usb_bos_capability_webusb),
|
| 115 |
+
.bDescriptorType = USB_DESC_DEVICE_CAPABILITY,
|
| 116 |
+
.bDevCapabilityType = USB_BOS_CAPABILITY_PLATFORM,
|
| 117 |
+
.bReserved = 0,
|
| 118 |
+
/* WebUSB Platform Capability UUID
|
| 119 |
+
* 3408b638-09a9-47a0-8bfd-a0768815b665
|
| 120 |
+
*/
|
| 121 |
+
.PlatformCapabilityUUID = {
|
| 122 |
+
0x38, 0xB6, 0x08, 0x34,
|
| 123 |
+
0xA9, 0x09,
|
| 124 |
+
0xA0, 0x47,
|
| 125 |
+
0x8B, 0xFD,
|
| 126 |
+
0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65,
|
| 127 |
+
},
|
| 128 |
+
},
|
| 129 |
+
.cap = {
|
| 130 |
+
.bcdVersion = sys_cpu_to_le16(0x0100),
|
| 131 |
+
.bVendorCode = 0x01,
|
| 132 |
+
.iLandingPage = 0x01
|
| 133 |
+
},
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
USB_DEVICE_BOS_DESC_DEFINE_CAP struct usb_bos_msosv2 {
|
| 137 |
+
struct usb_bos_platform_descriptor platform;
|
| 138 |
+
struct usb_bos_capability_msos cap;
|
| 139 |
+
} __packed cap_msosv2 = {
|
| 140 |
+
.platform = {
|
| 141 |
+
.bLength = sizeof(struct usb_bos_platform_descriptor)
|
| 142 |
+
+ sizeof(struct usb_bos_capability_msos),
|
| 143 |
+
.bDescriptorType = USB_DESC_DEVICE_CAPABILITY,
|
| 144 |
+
.bDevCapabilityType = USB_BOS_CAPABILITY_PLATFORM,
|
| 145 |
+
.bReserved = 0,
|
| 146 |
+
.PlatformCapabilityUUID = {
|
| 147 |
+
/**
|
| 148 |
+
* MS OS 2.0 Platform Capability ID
|
| 149 |
+
* D8DD60DF-4589-4CC7-9CD2-659D9E648A9F
|
| 150 |
+
*/
|
| 151 |
+
0xDF, 0x60, 0xDD, 0xD8,
|
| 152 |
+
0x89, 0x45,
|
| 153 |
+
0xC7, 0x4C,
|
| 154 |
+
0x9C, 0xD2,
|
| 155 |
+
0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,
|
| 156 |
+
},
|
| 157 |
+
},
|
| 158 |
+
.cap = {
|
| 159 |
+
/* Windows version (8.1) (0x06030000) */
|
| 160 |
+
.dwWindowsVersion = sys_cpu_to_le32(0x06030000),
|
| 161 |
+
.wMSOSDescriptorSetTotalLength =
|
| 162 |
+
sys_cpu_to_le16(sizeof(dummy_descriptor)),
|
| 163 |
+
.bMS_VendorCode = 0x02,
|
| 164 |
+
.bAltEnumCode = 0x00,
|
| 165 |
+
},
|
| 166 |
+
};
|
| 167 |
+
|
| 168 |
+
static void test_usb_bos_macros(void)
|
| 169 |
+
{
|
| 170 |
+
const struct usb_bos_descriptor *hdr = usb_bos_get_header();
|
| 171 |
+
size_t len = usb_bos_get_length();
|
| 172 |
+
|
| 173 |
+
TC_PRINT("length %zu\n", len);
|
| 174 |
+
|
| 175 |
+
usb_bos_register_cap((void *)&cap_webusb);
|
| 176 |
+
usb_bos_register_cap((void *)&cap_msosv2);
|
| 177 |
+
|
| 178 |
+
/* usb_bos_fix_total_length(); corrected with register */
|
| 179 |
+
|
| 180 |
+
LOG_HEXDUMP_DBG((void *)hdr, len, "Header");
|
| 181 |
+
LOG_HEXDUMP_DBG((void *)&webusb_bos_descriptor, sizeof(cap_webusb),
|
| 182 |
+
"webusb cap");
|
| 183 |
+
LOG_HEXDUMP_DBG((void *)&webusb_bos_descriptor_2, sizeof(cap_msosv2),
|
| 184 |
+
"webusb cap msos v2");
|
| 185 |
+
|
| 186 |
+
zassert_true(len ==
|
| 187 |
+
sizeof(struct usb_bos_descriptor) +
|
| 188 |
+
sizeof(cap_webusb) +
|
| 189 |
+
sizeof(cap_msosv2),
|
| 190 |
+
"Incorrect calculated length");
|
| 191 |
+
zassert_true(!memcmp(hdr, &webusb_bos_descriptor, len) ||
|
| 192 |
+
!memcmp(hdr, &webusb_bos_descriptor_2, len),
|
| 193 |
+
"Wrong data");
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
static void test_usb_bos(void)
|
| 197 |
+
{
|
| 198 |
+
struct usb_setup_packet setup;
|
| 199 |
+
int32_t len = 0;
|
| 200 |
+
uint8_t *data = NULL;
|
| 201 |
+
int ret;
|
| 202 |
+
|
| 203 |
+
/* Already registered due to previous test */
|
| 204 |
+
|
| 205 |
+
setup.wValue = (USB_DESC_BOS & 0xFF) << 8;
|
| 206 |
+
|
| 207 |
+
ret = usb_handle_bos(&setup, &len, &data);
|
| 208 |
+
|
| 209 |
+
TC_PRINT("%s: ret %d len %u data %p\n", __func__, ret, len, data);
|
| 210 |
+
|
| 211 |
+
zassert_true(!ret, "Return code failed");
|
| 212 |
+
zassert_equal(len, sizeof(webusb_bos_descriptor), "Wrong length");
|
| 213 |
+
zassert_true(!memcmp(data, &webusb_bos_descriptor, len) ||
|
| 214 |
+
!memcmp(data, &webusb_bos_descriptor_2, len),
|
| 215 |
+
"Wrong data");
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
/* test case main entry */
|
| 219 |
+
void test_main(void)
|
| 220 |
+
{
|
| 221 |
+
/* Prepare webusb_bos_descriptor_2 */
|
| 222 |
+
memcpy(&webusb_bos_descriptor_2.bos,
|
| 223 |
+
&webusb_bos_descriptor.bos,
|
| 224 |
+
sizeof(struct usb_bos_descriptor));
|
| 225 |
+
|
| 226 |
+
memcpy(&webusb_bos_descriptor_2.platform_msos,
|
| 227 |
+
&webusb_bos_descriptor.platform_msos,
|
| 228 |
+
sizeof(struct usb_bos_platform_descriptor));
|
| 229 |
+
memcpy(&webusb_bos_descriptor_2.capability_data_msos,
|
| 230 |
+
&webusb_bos_descriptor.capability_data_msos,
|
| 231 |
+
sizeof(struct usb_bos_capability_msos));
|
| 232 |
+
|
| 233 |
+
memcpy(&webusb_bos_descriptor_2.platform_webusb,
|
| 234 |
+
&webusb_bos_descriptor.platform_webusb,
|
| 235 |
+
sizeof(struct usb_bos_platform_descriptor));
|
| 236 |
+
memcpy(&webusb_bos_descriptor_2.capability_data_webusb,
|
| 237 |
+
&webusb_bos_descriptor.capability_data_webusb,
|
| 238 |
+
sizeof(struct usb_bos_capability_webusb));
|
| 239 |
+
|
| 240 |
+
ztest_test_suite(test_osdesc,
|
| 241 |
+
ztest_unit_test(test_usb_bos_macros),
|
| 242 |
+
ztest_unit_test(test_usb_bos));
|
| 243 |
+
ztest_run_test_suite(test_osdesc);
|
| 244 |
+
}
|
pool/shard007/C/0124283_stm32f7xx_hal_timebase_rtc_wakeup_template.c
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
******************************************************************************
|
| 3 |
+
* @file stm32f7xx_hal_timebase_rtc_wakeup_template.c
|
| 4 |
+
* @author MCD Application Team
|
| 5 |
+
* @brief HAL time base based on the hardware RTC_WAKEUP Template.
|
| 6 |
+
*
|
| 7 |
+
* This file overrides the native HAL time base functions (defined as weak)
|
| 8 |
+
* to use the RTC WAKEUP for the time base generation:
|
| 9 |
+
* + Intializes the RTC peripheral and configures the wakeup timer to be
|
| 10 |
+
* incremented each 1ms
|
| 11 |
+
* + The wakeup feature is configured to assert an interrupt each 1ms
|
| 12 |
+
* + HAL_IncTick is called inside the HAL_RTCEx_WakeUpTimerEventCallback
|
| 13 |
+
* + HSE (default), LSE or LSI can be selected as RTC clock source
|
| 14 |
+
@verbatim
|
| 15 |
+
==============================================================================
|
| 16 |
+
##### How to use this driver #####
|
| 17 |
+
==============================================================================
|
| 18 |
+
[..]
|
| 19 |
+
This file must be copied to the application folder and modified as follows:
|
| 20 |
+
(#) Rename it to 'stm32f7xx_hal_timebase_rtc_wakeup.c'
|
| 21 |
+
(#) Add this file and the RTC HAL drivers to your project and uncomment
|
| 22 |
+
HAL_RTC_MODULE_ENABLED define in stm32f7xx_hal_conf.h
|
| 23 |
+
|
| 24 |
+
[..]
|
| 25 |
+
(@) HAL RTC alarm and HAL RTC wakeup drivers cant be used with low power modes:
|
| 26 |
+
The wake up capability of the RTC may be intrusive in case of prior low power mode
|
| 27 |
+
configuration requiring different wake up sources.
|
| 28 |
+
Application/Example behavior is no more guaranteed
|
| 29 |
+
(@) The stm32f7xx_hal_timebase_tim use is recommended for the Applications/Examples
|
| 30 |
+
requiring low power modes
|
| 31 |
+
|
| 32 |
+
@endverbatim
|
| 33 |
+
******************************************************************************
|
| 34 |
+
* @attention
|
| 35 |
+
*
|
| 36 |
+
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
| 37 |
+
*
|
| 38 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
| 39 |
+
* are permitted provided that the following conditions are met:
|
| 40 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
| 41 |
+
* this list of conditions and the following disclaimer.
|
| 42 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 43 |
+
* this list of conditions and the following disclaimer in the documentation
|
| 44 |
+
* and/or other materials provided with the distribution.
|
| 45 |
+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
| 46 |
+
* may be used to endorse or promote products derived from this software
|
| 47 |
+
* without specific prior written permission.
|
| 48 |
+
*
|
| 49 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 50 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 51 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 52 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 53 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 54 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 55 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 56 |
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 57 |
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 58 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 59 |
+
*
|
| 60 |
+
******************************************************************************
|
| 61 |
+
*/
|
| 62 |
+
|
| 63 |
+
/* Includes ------------------------------------------------------------------*/
|
| 64 |
+
#include "stm32f7xx_hal.h"
|
| 65 |
+
/** @addtogroup STM32F7xx_HAL_Driver
|
| 66 |
+
* @{
|
| 67 |
+
*/
|
| 68 |
+
|
| 69 |
+
/** @defgroup HAL_TimeBase_RTC_WakeUp_Template HAL TimeBase RTC WakeUp Template
|
| 70 |
+
* @{
|
| 71 |
+
*/
|
| 72 |
+
|
| 73 |
+
/* Private typedef -----------------------------------------------------------*/
|
| 74 |
+
/* Private define ------------------------------------------------------------*/
|
| 75 |
+
|
| 76 |
+
/* Uncomment the line below to select the appropriate RTC Clock source for your application:
|
| 77 |
+
+ RTC_CLOCK_SOURCE_HSE: can be selected for applications requiring timing precision.
|
| 78 |
+
+ RTC_CLOCK_SOURCE_LSE: can be selected for applications with low constraint on timing
|
| 79 |
+
precision.
|
| 80 |
+
+ RTC_CLOCK_SOURCE_LSI: can be selected for applications with low constraint on timing
|
| 81 |
+
precision.
|
| 82 |
+
*/
|
| 83 |
+
#define RTC_CLOCK_SOURCE_HSE
|
| 84 |
+
/* #define RTC_CLOCK_SOURCE_LSE */
|
| 85 |
+
/* #define RTC_CLOCK_SOURCE_LSI */
|
| 86 |
+
|
| 87 |
+
#ifdef RTC_CLOCK_SOURCE_HSE
|
| 88 |
+
#define RTC_ASYNCH_PREDIV 99U
|
| 89 |
+
#define RTC_SYNCH_PREDIV 9U
|
| 90 |
+
#define RCC_RTCCLKSOURCE_1MHZ ((uint32_t)((uint32_t)RCC_BDCR_RTCSEL | (uint32_t)((HSE_VALUE/1000000U) << 16U)))
|
| 91 |
+
#else /* RTC_CLOCK_SOURCE_LSE || RTC_CLOCK_SOURCE_LSI */
|
| 92 |
+
#define RTC_ASYNCH_PREDIV 0U
|
| 93 |
+
#define RTC_SYNCH_PREDIV 31U
|
| 94 |
+
#endif /* RTC_CLOCK_SOURCE_HSE */
|
| 95 |
+
|
| 96 |
+
/* Private macro -------------------------------------------------------------*/
|
| 97 |
+
/* Private variables ---------------------------------------------------------*/
|
| 98 |
+
RTC_HandleTypeDef hRTC_Handle;
|
| 99 |
+
|
| 100 |
+
/* Private function prototypes -----------------------------------------------*/
|
| 101 |
+
void RTC_WKUP_IRQHandler(void);
|
| 102 |
+
|
| 103 |
+
/* Private functions ---------------------------------------------------------*/
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* @brief This function configures the RTC_WKUP as a time base source.
|
| 107 |
+
* The time source is configured to have 1ms time base with a dedicated
|
| 108 |
+
* Tick interrupt priority.
|
| 109 |
+
* Wakeup Time base = ((RTC_ASYNCH_PREDIV + 1) * (RTC_SYNCH_PREDIV + 1)) / RTC_CLOCK
|
| 110 |
+
= 1ms
|
| 111 |
+
* Wakeup Time = WakeupTimebase * WakeUpCounter (0 + 1)
|
| 112 |
+
= 1 ms
|
| 113 |
+
* @note This function is called automatically at the beginning of program after
|
| 114 |
+
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
|
| 115 |
+
* @param TickPriority Tick interrupt priority.
|
| 116 |
+
* @retval HAL status
|
| 117 |
+
*/
|
| 118 |
+
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
|
| 119 |
+
{
|
| 120 |
+
__IO uint32_t counter = 0U;
|
| 121 |
+
|
| 122 |
+
RCC_OscInitTypeDef RCC_OscInitStruct;
|
| 123 |
+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
| 124 |
+
|
| 125 |
+
#ifdef RTC_CLOCK_SOURCE_LSE
|
| 126 |
+
/* Configue LSE as RTC clock soucre */
|
| 127 |
+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
| 128 |
+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
| 129 |
+
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
| 130 |
+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
| 131 |
+
#elif defined (RTC_CLOCK_SOURCE_LSI)
|
| 132 |
+
/* Configue LSI as RTC clock soucre */
|
| 133 |
+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
|
| 134 |
+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
| 135 |
+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
| 136 |
+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
|
| 137 |
+
#elif defined (RTC_CLOCK_SOURCE_HSE)
|
| 138 |
+
/* Configue HSE as RTC clock soucre */
|
| 139 |
+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
| 140 |
+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
| 141 |
+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
| 142 |
+
/* Ensure that RTC is clocked by 1MHz */
|
| 143 |
+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_1MHZ;
|
| 144 |
+
#else
|
| 145 |
+
#error Please select the RTC Clock source
|
| 146 |
+
#endif /* RTC_CLOCK_SOURCE_LSE */
|
| 147 |
+
|
| 148 |
+
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK)
|
| 149 |
+
{
|
| 150 |
+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
| 151 |
+
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) == HAL_OK)
|
| 152 |
+
{
|
| 153 |
+
/* Enable RTC Clock */
|
| 154 |
+
__HAL_RCC_RTC_ENABLE();
|
| 155 |
+
/* The time base should be 1ms
|
| 156 |
+
Time base = ((RTC_ASYNCH_PREDIV + 1) * (RTC_SYNCH_PREDIV + 1)) / RTC_CLOCK
|
| 157 |
+
HSE as RTC clock
|
| 158 |
+
Time base = ((99 + 1) * (9 + 1)) / 1Mhz
|
| 159 |
+
= 1ms
|
| 160 |
+
LSE as RTC clock
|
| 161 |
+
Time base = ((31 + 1) * (0 + 1)) / 32.768Khz
|
| 162 |
+
= ~1ms
|
| 163 |
+
LSI as RTC clock
|
| 164 |
+
Time base = ((31 + 1) * (0 + 1)) / 32Khz
|
| 165 |
+
= 1ms
|
| 166 |
+
*/
|
| 167 |
+
hRTC_Handle.Instance = RTC;
|
| 168 |
+
hRTC_Handle.Init.HourFormat = RTC_HOURFORMAT_24;
|
| 169 |
+
hRTC_Handle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
|
| 170 |
+
hRTC_Handle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
|
| 171 |
+
hRTC_Handle.Init.OutPut = RTC_OUTPUT_DISABLE;
|
| 172 |
+
hRTC_Handle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
| 173 |
+
hRTC_Handle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
| 174 |
+
HAL_RTC_Init(&hRTC_Handle);
|
| 175 |
+
|
| 176 |
+
/* Disable the write protection for RTC registers */
|
| 177 |
+
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
| 178 |
+
|
| 179 |
+
/* Disable the Wake-up Timer */
|
| 180 |
+
__HAL_RTC_WAKEUPTIMER_DISABLE(&hRTC_Handle);
|
| 181 |
+
|
| 182 |
+
/* In case of interrupt mode is used, the interrupt source must disabled */
|
| 183 |
+
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&hRTC_Handle,RTC_IT_WUT);
|
| 184 |
+
|
| 185 |
+
/* Wait till RTC WUTWF flag is set */
|
| 186 |
+
while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(&hRTC_Handle, RTC_FLAG_WUTWF) == RESET)
|
| 187 |
+
{
|
| 188 |
+
if(counter++ == (SystemCoreClock /48U))
|
| 189 |
+
{
|
| 190 |
+
return HAL_ERROR;
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/* Clear PWR wake up Flag */
|
| 195 |
+
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
|
| 196 |
+
|
| 197 |
+
/* Clear RTC Wake Up timer Flag */
|
| 198 |
+
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hRTC_Handle, RTC_FLAG_WUTF);
|
| 199 |
+
|
| 200 |
+
/* Configure the Wake-up Timer counter */
|
| 201 |
+
hRTC_Handle.Instance->WUTR = (uint32_t)0U;
|
| 202 |
+
|
| 203 |
+
/* Clear the Wake-up Timer clock source bits in CR register */
|
| 204 |
+
hRTC_Handle.Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
|
| 205 |
+
|
| 206 |
+
/* Configure the clock source */
|
| 207 |
+
hRTC_Handle.Instance->CR |= (uint32_t)RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
|
| 208 |
+
|
| 209 |
+
/* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
|
| 210 |
+
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
|
| 211 |
+
|
| 212 |
+
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
|
| 213 |
+
|
| 214 |
+
/* Configure the Interrupt in the RTC_CR register */
|
| 215 |
+
__HAL_RTC_WAKEUPTIMER_ENABLE_IT(&hRTC_Handle,RTC_IT_WUT);
|
| 216 |
+
|
| 217 |
+
/* Enable the Wake-up Timer */
|
| 218 |
+
__HAL_RTC_WAKEUPTIMER_ENABLE(&hRTC_Handle);
|
| 219 |
+
|
| 220 |
+
/* Enable the write protection for RTC registers */
|
| 221 |
+
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
| 222 |
+
|
| 223 |
+
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, TickPriority, 0U);
|
| 224 |
+
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
|
| 225 |
+
return HAL_OK;
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
return HAL_ERROR;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/**
|
| 232 |
+
* @brief Suspend Tick increment.
|
| 233 |
+
* @note Disable the tick increment by disabling RTC_WKUP interrupt.
|
| 234 |
+
* @retval None
|
| 235 |
+
*/
|
| 236 |
+
void HAL_SuspendTick(void)
|
| 237 |
+
{
|
| 238 |
+
/* Disable the write protection for RTC registers */
|
| 239 |
+
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
| 240 |
+
/* Disable WAKE UP TIMER Interrupt */
|
| 241 |
+
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&hRTC_Handle, RTC_IT_WUT);
|
| 242 |
+
/* Enable the write protection for RTC registers */
|
| 243 |
+
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/**
|
| 247 |
+
* @brief Resume Tick increment.
|
| 248 |
+
* @note Enable the tick increment by Enabling RTC_WKUP interrupt.
|
| 249 |
+
* @retval None
|
| 250 |
+
*/
|
| 251 |
+
void HAL_ResumeTick(void)
|
| 252 |
+
{
|
| 253 |
+
/* Disable the write protection for RTC registers */
|
| 254 |
+
__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
|
| 255 |
+
/* Enable WAKE UP TIMER interrupt */
|
| 256 |
+
__HAL_RTC_WAKEUPTIMER_ENABLE_IT(&hRTC_Handle, RTC_IT_WUT);
|
| 257 |
+
/* Enable the write protection for RTC registers */
|
| 258 |
+
__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
/**
|
| 262 |
+
* @brief Wake Up Timer Event Callback in non blocking mode
|
| 263 |
+
* @note This function is called when RTC_WKUP interrupt took place, inside
|
| 264 |
+
* RTC_WKUP_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
| 265 |
+
* a global variable "uwTick" used as application time base.
|
| 266 |
+
* @param hrtc RTC handle
|
| 267 |
+
* @retval None
|
| 268 |
+
*/
|
| 269 |
+
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
|
| 270 |
+
{
|
| 271 |
+
HAL_IncTick();
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* @brief This function handles WAKE UP TIMER interrupt request.
|
| 276 |
+
* @retval None
|
| 277 |
+
*/
|
| 278 |
+
void RTC_WKUP_IRQHandler(void)
|
| 279 |
+
{
|
| 280 |
+
HAL_RTCEx_WakeUpTimerIRQHandler(&hRTC_Handle);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/**
|
| 284 |
+
* @}
|
| 285 |
+
*/
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* @}
|
| 289 |
+
*/
|
| 290 |
+
|
| 291 |
+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
pool/shard007/C/0124284_asp.c
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
|
| 3 |
+
int main(void) {
|
| 4 |
+
int t;
|
| 5 |
+
scanf("%d", &t);
|
| 6 |
+
while (t--) {
|
| 7 |
+
int n;
|
| 8 |
+
scanf("%d", &n);
|
| 9 |
+
int a[n];
|
| 10 |
+
int i;
|
| 11 |
+
for (i = 0; i < n; i++) {
|
| 12 |
+
scanf("%d", a+i);
|
| 13 |
+
}
|
| 14 |
+
int flag = 0;
|
| 15 |
+
for (i = 1; i < n; i++) {
|
| 16 |
+
int d = i;
|
| 17 |
+
int c = 0;
|
| 18 |
+
while (d > 0 && a[d] < a[d-1]) {
|
| 19 |
+
int t = a[d];
|
| 20 |
+
a[d] = a[d-1];
|
| 21 |
+
a[d-1] = t;
|
| 22 |
+
d--;
|
| 23 |
+
c++;
|
| 24 |
+
if (c > 1) {
|
| 25 |
+
flag = 1;
|
| 26 |
+
break;
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
if (flag == 1)
|
| 30 |
+
break;
|
| 31 |
+
}
|
| 32 |
+
if (flag == 1)
|
| 33 |
+
printf("NO\n");
|
| 34 |
+
else
|
| 35 |
+
printf("YES\n");
|
| 36 |
+
}
|
| 37 |
+
return 0;
|
| 38 |
+
}
|
pool/shard007/C/0124287_nf_nat_tftp.c
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: GPL-2.0-only
|
| 2 |
+
/* (C) 2001-2002 Magnus Boden <mb@ozaba.mine.nu>
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#include <linux/module.h>
|
| 6 |
+
#include <linux/udp.h>
|
| 7 |
+
|
| 8 |
+
#include <net/netfilter/nf_conntrack_helper.h>
|
| 9 |
+
#include <net/netfilter/nf_conntrack_expect.h>
|
| 10 |
+
#include <net/netfilter/nf_nat_helper.h>
|
| 11 |
+
#include <linux/netfilter/nf_conntrack_tftp.h>
|
| 12 |
+
|
| 13 |
+
#define NAT_HELPER_NAME "tftp"
|
| 14 |
+
|
| 15 |
+
MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
|
| 16 |
+
MODULE_DESCRIPTION("TFTP NAT helper");
|
| 17 |
+
MODULE_LICENSE("GPL");
|
| 18 |
+
MODULE_ALIAS_NF_NAT_HELPER(NAT_HELPER_NAME);
|
| 19 |
+
|
| 20 |
+
static struct nf_conntrack_nat_helper nat_helper_tftp =
|
| 21 |
+
NF_CT_NAT_HELPER_INIT(NAT_HELPER_NAME);
|
| 22 |
+
|
| 23 |
+
static unsigned int help(struct sk_buff *skb,
|
| 24 |
+
enum ip_conntrack_info ctinfo,
|
| 25 |
+
struct nf_conntrack_expect *exp)
|
| 26 |
+
{
|
| 27 |
+
const struct nf_conn *ct = exp->master;
|
| 28 |
+
|
| 29 |
+
exp->saved_proto.udp.port
|
| 30 |
+
= ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.udp.port;
|
| 31 |
+
exp->dir = IP_CT_DIR_REPLY;
|
| 32 |
+
exp->expectfn = nf_nat_follow_master;
|
| 33 |
+
if (nf_ct_expect_related(exp) != 0) {
|
| 34 |
+
nf_ct_helper_log(skb, exp->master, "cannot add expectation");
|
| 35 |
+
return NF_DROP;
|
| 36 |
+
}
|
| 37 |
+
return NF_ACCEPT;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
static void __exit nf_nat_tftp_fini(void)
|
| 41 |
+
{
|
| 42 |
+
nf_nat_helper_unregister(&nat_helper_tftp);
|
| 43 |
+
RCU_INIT_POINTER(nf_nat_tftp_hook, NULL);
|
| 44 |
+
synchronize_rcu();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
static int __init nf_nat_tftp_init(void)
|
| 48 |
+
{
|
| 49 |
+
BUG_ON(nf_nat_tftp_hook != NULL);
|
| 50 |
+
nf_nat_helper_register(&nat_helper_tftp);
|
| 51 |
+
RCU_INIT_POINTER(nf_nat_tftp_hook, help);
|
| 52 |
+
return 0;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
module_init(nf_nat_tftp_init);
|
| 56 |
+
module_exit(nf_nat_tftp_fini);
|
pool/shard007/C/0124293_ping.c
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* ping.c
|
| 3 |
+
*
|
| 4 |
+
* Created on: 2016. 5. 16.
|
| 5 |
+
* Author: Ryu Woon Jung (Leon)
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
//
|
| 9 |
+
// ********* ping Example *********
|
| 10 |
+
//
|
| 11 |
+
//
|
| 12 |
+
// Available Dynamixel model on this example : All models using Protocol 2.0
|
| 13 |
+
// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL.
|
| 14 |
+
// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below "#define"d variables yourself.
|
| 15 |
+
// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M])
|
| 16 |
+
//
|
| 17 |
+
|
| 18 |
+
#ifdef __linux__
|
| 19 |
+
#include <unistd.h>
|
| 20 |
+
#include <fcntl.h>
|
| 21 |
+
#include <termios.h>
|
| 22 |
+
#elif defined(_WIN32) || defined(_WIN64)
|
| 23 |
+
#include <conio.h>
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
#include <stdio.h>
|
| 27 |
+
#include "dynamixel_sdk.h" // Uses Dynamixel SDK library
|
| 28 |
+
|
| 29 |
+
// Protocol version
|
| 30 |
+
#define PROTOCOL_VERSION 2.0 // See which protocol version is used in the Dynamixel
|
| 31 |
+
|
| 32 |
+
// Default setting
|
| 33 |
+
#define DXL_ID 1 // Dynamixel ID: 1
|
| 34 |
+
#define BAUDRATE 1000000
|
| 35 |
+
#define DEVICENAME "/dev/ttyUSB0" // Check which port is being used on your controller
|
| 36 |
+
// ex) Windows: "COM1" Linux: "/dev/ttyUSB0"
|
| 37 |
+
|
| 38 |
+
int getch()
|
| 39 |
+
{
|
| 40 |
+
#ifdef __linux__
|
| 41 |
+
struct termios oldt, newt;
|
| 42 |
+
int ch;
|
| 43 |
+
tcgetattr(STDIN_FILENO, &oldt);
|
| 44 |
+
newt = oldt;
|
| 45 |
+
newt.c_lflag &= ~(ICANON | ECHO);
|
| 46 |
+
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
| 47 |
+
ch = getchar();
|
| 48 |
+
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
| 49 |
+
return ch;
|
| 50 |
+
#elif defined(_WIN32) || defined(_WIN64)
|
| 51 |
+
return _getch();
|
| 52 |
+
#endif
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
int kbhit(void)
|
| 56 |
+
{
|
| 57 |
+
#ifdef __linux__
|
| 58 |
+
struct termios oldt, newt;
|
| 59 |
+
int ch;
|
| 60 |
+
int oldf;
|
| 61 |
+
|
| 62 |
+
tcgetattr(STDIN_FILENO, &oldt);
|
| 63 |
+
newt = oldt;
|
| 64 |
+
newt.c_lflag &= ~(ICANON | ECHO);
|
| 65 |
+
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
| 66 |
+
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
| 67 |
+
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
| 68 |
+
|
| 69 |
+
ch = getchar();
|
| 70 |
+
|
| 71 |
+
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
| 72 |
+
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
| 73 |
+
|
| 74 |
+
if (ch != EOF)
|
| 75 |
+
{
|
| 76 |
+
ungetc(ch, stdin);
|
| 77 |
+
return 1;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return 0;
|
| 81 |
+
#elif defined(_WIN32) || defined(_WIN64)
|
| 82 |
+
return _kbhit();
|
| 83 |
+
#endif
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
int main()
|
| 87 |
+
{
|
| 88 |
+
// Initialize PortHandler Structs
|
| 89 |
+
// Set the port path
|
| 90 |
+
// Get methods and members of PortHandlerLinux or PortHandlerWindows
|
| 91 |
+
int port_num = portHandler(DEVICENAME);
|
| 92 |
+
|
| 93 |
+
// Initialize PacketHandler Structs
|
| 94 |
+
packetHandler();
|
| 95 |
+
|
| 96 |
+
int dxl_comm_result = COMM_TX_FAIL; // Communication result
|
| 97 |
+
|
| 98 |
+
uint8_t dxl_error = 0; // Dynamixel error
|
| 99 |
+
uint16_t dxl_model_number; // Dynamixel model number
|
| 100 |
+
|
| 101 |
+
// Open port
|
| 102 |
+
if (openPort(port_num))
|
| 103 |
+
{
|
| 104 |
+
printf("Succeeded to open the port!\n");
|
| 105 |
+
}
|
| 106 |
+
else
|
| 107 |
+
{
|
| 108 |
+
printf("Failed to open the port!\n");
|
| 109 |
+
printf("Press any key to terminate...\n");
|
| 110 |
+
getch();
|
| 111 |
+
return 0;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// Set port baudrate
|
| 115 |
+
if (setBaudRate(port_num, BAUDRATE))
|
| 116 |
+
{
|
| 117 |
+
printf("Succeeded to change the baudrate!\n");
|
| 118 |
+
}
|
| 119 |
+
else
|
| 120 |
+
{
|
| 121 |
+
printf("Failed to change the baudrate!\n");
|
| 122 |
+
printf("Press any key to terminate...\n");
|
| 123 |
+
getch();
|
| 124 |
+
return 0;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
// Try to ping the Dynamixel
|
| 128 |
+
// Get Dynamixel model number
|
| 129 |
+
dxl_model_number = pingGetModelNum(port_num, PROTOCOL_VERSION, DXL_ID);
|
| 130 |
+
if ((dxl_comm_result = getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS)
|
| 131 |
+
{
|
| 132 |
+
printTxRxResult(PROTOCOL_VERSION, dxl_comm_result);
|
| 133 |
+
}
|
| 134 |
+
else if ((dxl_error = getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0)
|
| 135 |
+
{
|
| 136 |
+
printRxPacketError(PROTOCOL_VERSION, dxl_error);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
printf("[ID:%03d] ping Succeeded. Dynamixel model number : %d\n", DXL_ID, dxl_model_number);
|
| 140 |
+
|
| 141 |
+
// Close port
|
| 142 |
+
closePort(port_num);
|
| 143 |
+
|
| 144 |
+
return 0;
|
| 145 |
+
}
|
pool/shard007/C/0124295_gpio.c
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2006-2018, RT-Thread Development Team
|
| 3 |
+
*
|
| 4 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 5 |
+
*
|
| 6 |
+
* Change Logs:
|
| 7 |
+
* Date Author Notes
|
| 8 |
+
* 2016-08-29 Aubr.Cool the first version
|
| 9 |
+
*/
|
| 10 |
+
#include <rthw.h>
|
| 11 |
+
#include <rtdevice.h>
|
| 12 |
+
#include <board.h>
|
| 13 |
+
|
| 14 |
+
#ifdef RT_USING_PIN
|
| 15 |
+
|
| 16 |
+
#include "stm32l0xx.h"
|
| 17 |
+
|
| 18 |
+
#define __RCC_GPIO_CLK_ENABLE(BIT) do { \
|
| 19 |
+
__IO uint32_t tmpreg; \
|
| 20 |
+
SET_BIT(RCC->IOPENR, BIT);\
|
| 21 |
+
/* Delay after an RCC peripheral clock enabling */ \
|
| 22 |
+
tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN);\
|
| 23 |
+
UNUSED(tmpreg); \
|
| 24 |
+
} while(0)
|
| 25 |
+
#define __RCC_GPIO_CLK_DISABLE(BIT) CLEAR_BIT(RCC->IOPENR, BIT)
|
| 26 |
+
|
| 27 |
+
#define __STM32_PIN(index, gpio, gpio_index) \
|
| 28 |
+
{index, RCC_IOPENR_GPIO##gpio##EN, GPIO##gpio, GPIO_PIN_##gpio_index}
|
| 29 |
+
#define __STM32_PIN_DEFAULT {-1, 0, 0}
|
| 30 |
+
|
| 31 |
+
/* STM32 GPIO driver */
|
| 32 |
+
struct pin_index
|
| 33 |
+
{
|
| 34 |
+
int index;
|
| 35 |
+
unsigned int clk;
|
| 36 |
+
GPIO_TypeDef *gpio;
|
| 37 |
+
uint32_t pin;
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
static const struct pin_index pins[] =
|
| 41 |
+
{
|
| 42 |
+
#ifdef UFQFPN32
|
| 43 |
+
__STM32_PIN_DEFAULT,
|
| 44 |
+
__STM32_PIN(1, C, 14),
|
| 45 |
+
__STM32_PIN(2, C, 15),
|
| 46 |
+
__STM32_PIN_DEFAULT,
|
| 47 |
+
__STM32_PIN_DEFAULT,
|
| 48 |
+
__STM32_PIN_DEFAULT,
|
| 49 |
+
__STM32_PIN(6, A, 0),
|
| 50 |
+
__STM32_PIN(7, A, 1),
|
| 51 |
+
__STM32_PIN(8, A, 2),
|
| 52 |
+
__STM32_PIN(9, A, 3),
|
| 53 |
+
__STM32_PIN(10, A, 4),
|
| 54 |
+
__STM32_PIN(11, A, 5),
|
| 55 |
+
__STM32_PIN(12, A, 6),
|
| 56 |
+
__STM32_PIN(13, A, 7),
|
| 57 |
+
__STM32_PIN(14, B, 0),
|
| 58 |
+
__STM32_PIN(15, B, 1),
|
| 59 |
+
__STM32_PIN_DEFAULT,
|
| 60 |
+
__STM32_PIN_DEFAULT,
|
| 61 |
+
__STM32_PIN(18, A, 8),
|
| 62 |
+
__STM32_PIN(19, A, 9),
|
| 63 |
+
__STM32_PIN(20, A, 10),
|
| 64 |
+
__STM32_PIN(21, A, 11),
|
| 65 |
+
__STM32_PIN(22, A, 12),
|
| 66 |
+
__STM32_PIN(23, A, 13),
|
| 67 |
+
__STM32_PIN_DEFAULT,
|
| 68 |
+
__STM32_PIN(25, A, 14),
|
| 69 |
+
__STM32_PIN(26, B, 4),
|
| 70 |
+
__STM32_PIN(27, B, 5),
|
| 71 |
+
__STM32_PIN(28, B, 6),
|
| 72 |
+
__STM32_PIN(29, B, 7),
|
| 73 |
+
__STM32_PIN_DEFAULT,
|
| 74 |
+
__STM32_PIN_DEFAULT,
|
| 75 |
+
__STM32_PIN_DEFAULT,
|
| 76 |
+
#endif
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
#define ITEM_NUM(items) sizeof(items)/sizeof(items[0])
|
| 81 |
+
const struct pin_index *get_pin(uint8_t pin)
|
| 82 |
+
{
|
| 83 |
+
const struct pin_index *index;
|
| 84 |
+
|
| 85 |
+
if (pin < ITEM_NUM(pins))
|
| 86 |
+
{
|
| 87 |
+
index = &pins[pin];
|
| 88 |
+
if (index->index == -1)
|
| 89 |
+
index = RT_NULL;
|
| 90 |
+
}
|
| 91 |
+
else
|
| 92 |
+
{
|
| 93 |
+
index = RT_NULL;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
return index;
|
| 97 |
+
};
|
| 98 |
+
inline void stm32_pin_write_early(rt_base_t pin, rt_base_t value)
|
| 99 |
+
{
|
| 100 |
+
const struct pin_index *index;
|
| 101 |
+
|
| 102 |
+
index = get_pin(pin);
|
| 103 |
+
if (index == RT_NULL)
|
| 104 |
+
{
|
| 105 |
+
return;
|
| 106 |
+
}
|
| 107 |
+
HAL_GPIO_WritePin(index->gpio, index->pin, value);
|
| 108 |
+
}
|
| 109 |
+
void stm32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
|
| 110 |
+
{
|
| 111 |
+
stm32_pin_write_early(pin, value);
|
| 112 |
+
}
|
| 113 |
+
inline int stm32_pin_read_early(rt_base_t pin)
|
| 114 |
+
{
|
| 115 |
+
int value;
|
| 116 |
+
const struct pin_index *index;
|
| 117 |
+
|
| 118 |
+
value = PIN_LOW;
|
| 119 |
+
|
| 120 |
+
index = get_pin(pin);
|
| 121 |
+
if (index == RT_NULL)
|
| 122 |
+
{
|
| 123 |
+
return value;
|
| 124 |
+
}
|
| 125 |
+
value = HAL_GPIO_ReadPin(index->gpio, index->pin);
|
| 126 |
+
return value;
|
| 127 |
+
}
|
| 128 |
+
int stm32_pin_read(rt_device_t dev, rt_base_t pin)
|
| 129 |
+
{
|
| 130 |
+
return stm32_pin_read_early(pin);
|
| 131 |
+
}
|
| 132 |
+
void stm32_pin_mode_early(rt_base_t pin, rt_base_t mode)
|
| 133 |
+
{
|
| 134 |
+
const struct pin_index *index;
|
| 135 |
+
GPIO_InitTypeDef GPIO_InitStructure;
|
| 136 |
+
|
| 137 |
+
index = get_pin(pin);
|
| 138 |
+
if (index == RT_NULL)
|
| 139 |
+
{
|
| 140 |
+
return;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* Configure GPIO_InitStructure */
|
| 144 |
+
GPIO_InitStructure.Pin = index->pin;
|
| 145 |
+
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
| 146 |
+
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
| 147 |
+
__RCC_GPIO_CLK_ENABLE(index->clk);
|
| 148 |
+
if (mode == GPIO_MODE_OUTPUT_PP)
|
| 149 |
+
{
|
| 150 |
+
/* output setting */
|
| 151 |
+
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
| 152 |
+
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
| 153 |
+
} else if(mode == GPIO_MODE_OUTPUT_OD)
|
| 154 |
+
{
|
| 155 |
+
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_OD;
|
| 156 |
+
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
| 157 |
+
}
|
| 158 |
+
else if (mode == GPIO_MODE_INPUT)
|
| 159 |
+
{
|
| 160 |
+
/* input setting: not pull. */
|
| 161 |
+
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
| 162 |
+
GPIO_InitStructure.Pull = GPIO_PULLUP;
|
| 163 |
+
} else if(((mode & 0xFF) == GPIO_MODE_AF_PP) ||
|
| 164 |
+
((mode & 0xFF) == GPIO_MODE_AF_OD)
|
| 165 |
+
) {
|
| 166 |
+
GPIO_InitStructure.Mode = (mode & ~0xFF00);
|
| 167 |
+
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
| 168 |
+
GPIO_InitStructure.Alternate = (mode & 0xFF00) >> 8;
|
| 169 |
+
} else if(mode == GPIO_MODE_ANALOG){
|
| 170 |
+
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
|
| 171 |
+
} else {
|
| 172 |
+
/* input setting:default. */
|
| 173 |
+
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
| 174 |
+
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
| 175 |
+
}
|
| 176 |
+
HAL_GPIO_Init(index->gpio, &GPIO_InitStructure);
|
| 177 |
+
}
|
| 178 |
+
void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
|
| 179 |
+
{
|
| 180 |
+
stm32_pin_mode_early(pin, mode);
|
| 181 |
+
}
|
| 182 |
+
const static struct rt_pin_ops _stm32_pin_ops =
|
| 183 |
+
{
|
| 184 |
+
stm32_pin_mode,
|
| 185 |
+
stm32_pin_write,
|
| 186 |
+
stm32_pin_read,
|
| 187 |
+
};
|
| 188 |
+
int stm32_hw_pin_init(void)
|
| 189 |
+
{
|
| 190 |
+
int result;
|
| 191 |
+
|
| 192 |
+
result = rt_device_pin_register("pin", &_stm32_pin_ops, RT_NULL);
|
| 193 |
+
return result;
|
| 194 |
+
}
|
| 195 |
+
INIT_BOARD_EXPORT(stm32_hw_pin_init);
|
| 196 |
+
|
| 197 |
+
#endif
|
pool/shard007/C/0124297_vikexttool.c
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* viking -- GPS Data and Topo Analyzer, Explorer, and Manager
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
|
| 5 |
+
*
|
| 6 |
+
* This program is free software; you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program; if not, write to the Free Software
|
| 18 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 19 |
+
*
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#ifdef HAVE_CONFIG_H
|
| 23 |
+
#include "config.h"
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
#include "vikexttool.h"
|
| 27 |
+
|
| 28 |
+
#include <string.h>
|
| 29 |
+
|
| 30 |
+
#include <glib/gi18n.h>
|
| 31 |
+
|
| 32 |
+
static void ext_tool_class_init ( VikExtToolClass *klass );
|
| 33 |
+
static void ext_tool_init ( VikExtTool *vlp );
|
| 34 |
+
|
| 35 |
+
static GObjectClass *parent_class;
|
| 36 |
+
|
| 37 |
+
static void ext_tool_finalize ( GObject *gob );
|
| 38 |
+
static gchar *ext_tool_get_label ( VikExtTool *vw );
|
| 39 |
+
|
| 40 |
+
typedef struct _VikExtToolPrivate VikExtToolPrivate;
|
| 41 |
+
|
| 42 |
+
struct _VikExtToolPrivate
|
| 43 |
+
{
|
| 44 |
+
gint id;
|
| 45 |
+
gchar *label;
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
#define EXT_TOOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
|
| 49 |
+
VIK_EXT_TOOL_TYPE, \
|
| 50 |
+
VikExtToolPrivate))
|
| 51 |
+
|
| 52 |
+
GType vik_ext_tool_get_type()
|
| 53 |
+
{
|
| 54 |
+
static GType w_type = 0;
|
| 55 |
+
|
| 56 |
+
if (!w_type)
|
| 57 |
+
{
|
| 58 |
+
static const GTypeInfo w_info =
|
| 59 |
+
{
|
| 60 |
+
sizeof (VikExtToolClass),
|
| 61 |
+
NULL, /* base_init */
|
| 62 |
+
NULL, /* base_finalize */
|
| 63 |
+
(GClassInitFunc) ext_tool_class_init,
|
| 64 |
+
NULL, /* class_finalize */
|
| 65 |
+
NULL, /* class_data */
|
| 66 |
+
sizeof (VikExtTool),
|
| 67 |
+
0,
|
| 68 |
+
(GInstanceInitFunc) ext_tool_init,
|
| 69 |
+
};
|
| 70 |
+
w_type = g_type_register_static ( G_TYPE_OBJECT, "VikExtTool", &w_info, G_TYPE_FLAG_ABSTRACT );
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
return w_type;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
enum
|
| 77 |
+
{
|
| 78 |
+
PROP_0,
|
| 79 |
+
|
| 80 |
+
PROP_ID,
|
| 81 |
+
PROP_LABEL,
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
static void
|
| 85 |
+
ext_tool_set_property (GObject *object,
|
| 86 |
+
guint property_id,
|
| 87 |
+
const GValue *value,
|
| 88 |
+
GParamSpec *pspec)
|
| 89 |
+
{
|
| 90 |
+
VikExtTool *self = VIK_EXT_TOOL (object);
|
| 91 |
+
VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
|
| 92 |
+
|
| 93 |
+
switch (property_id)
|
| 94 |
+
{
|
| 95 |
+
case PROP_ID:
|
| 96 |
+
priv->id = g_value_get_uint (value);
|
| 97 |
+
g_debug ("VikExtTool.id: %d", priv->id);
|
| 98 |
+
break;
|
| 99 |
+
|
| 100 |
+
case PROP_LABEL:
|
| 101 |
+
g_free (priv->label);
|
| 102 |
+
priv->label = g_value_dup_string (value);
|
| 103 |
+
g_debug ("VikExtTool.label: %s", priv->label);
|
| 104 |
+
break;
|
| 105 |
+
|
| 106 |
+
default:
|
| 107 |
+
/* We don't have any other property... */
|
| 108 |
+
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
| 109 |
+
break;
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
static void
|
| 114 |
+
ext_tool_get_property (GObject *object,
|
| 115 |
+
guint property_id,
|
| 116 |
+
GValue *value,
|
| 117 |
+
GParamSpec *pspec)
|
| 118 |
+
{
|
| 119 |
+
VikExtTool *self = VIK_EXT_TOOL (object);
|
| 120 |
+
VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
|
| 121 |
+
|
| 122 |
+
switch (property_id)
|
| 123 |
+
{
|
| 124 |
+
case PROP_ID:
|
| 125 |
+
g_value_set_uint (value, priv->id);
|
| 126 |
+
break;
|
| 127 |
+
|
| 128 |
+
case PROP_LABEL:
|
| 129 |
+
g_value_set_string (value, priv->label);
|
| 130 |
+
break;
|
| 131 |
+
|
| 132 |
+
default:
|
| 133 |
+
/* We don't have any other property... */
|
| 134 |
+
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
| 135 |
+
break;
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
static void ext_tool_class_init ( VikExtToolClass *klass )
|
| 140 |
+
{
|
| 141 |
+
GObjectClass *gobject_class;
|
| 142 |
+
GParamSpec *pspec;
|
| 143 |
+
|
| 144 |
+
gobject_class = G_OBJECT_CLASS (klass);
|
| 145 |
+
gobject_class->finalize = ext_tool_finalize;
|
| 146 |
+
gobject_class->set_property = ext_tool_set_property;
|
| 147 |
+
gobject_class->get_property = ext_tool_get_property;
|
| 148 |
+
|
| 149 |
+
pspec = g_param_spec_string ("label",
|
| 150 |
+
"Label",
|
| 151 |
+
"Set the label",
|
| 152 |
+
"<no-set>" /* default value */,
|
| 153 |
+
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
|
| 154 |
+
g_object_class_install_property (gobject_class,
|
| 155 |
+
PROP_LABEL,
|
| 156 |
+
pspec);
|
| 157 |
+
|
| 158 |
+
pspec = g_param_spec_uint ("id",
|
| 159 |
+
"Id of the tool",
|
| 160 |
+
"Set the id",
|
| 161 |
+
0 /* minimum value */,
|
| 162 |
+
G_MAXUINT16 /* maximum value */,
|
| 163 |
+
0 /* default value */,
|
| 164 |
+
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
|
| 165 |
+
g_object_class_install_property (gobject_class,
|
| 166 |
+
PROP_ID,
|
| 167 |
+
pspec);
|
| 168 |
+
|
| 169 |
+
klass->get_label = ext_tool_get_label;
|
| 170 |
+
|
| 171 |
+
parent_class = g_type_class_peek_parent (klass);
|
| 172 |
+
|
| 173 |
+
g_type_class_add_private (klass, sizeof (VikExtToolPrivate));
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
VikExtTool *vik_ext_tool_new ()
|
| 177 |
+
{
|
| 178 |
+
return VIK_EXT_TOOL ( g_object_new ( VIK_EXT_TOOL_TYPE, NULL ) );
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
static void ext_tool_init ( VikExtTool *self )
|
| 182 |
+
{
|
| 183 |
+
VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
|
| 184 |
+
priv->label = NULL;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
static void ext_tool_finalize ( GObject *gob )
|
| 188 |
+
{
|
| 189 |
+
VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE ( gob );
|
| 190 |
+
g_free ( priv->label ); priv->label = NULL;
|
| 191 |
+
G_OBJECT_CLASS(parent_class)->finalize(gob);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
static gchar *ext_tool_get_label ( VikExtTool *self )
|
| 195 |
+
{
|
| 196 |
+
VikExtToolPrivate *priv = NULL;
|
| 197 |
+
priv = EXT_TOOL_GET_PRIVATE (self);
|
| 198 |
+
return g_strdup ( priv->label );
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
gchar *vik_ext_tool_get_label ( VikExtTool *w )
|
| 202 |
+
{
|
| 203 |
+
return VIK_EXT_TOOL_GET_CLASS( w )->get_label( w );
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
void vik_ext_tool_open ( VikExtTool *self, VikWindow *vwindow )
|
| 207 |
+
{
|
| 208 |
+
VIK_EXT_TOOL_GET_CLASS( self )->open( self, vwindow );
|
| 209 |
+
}
|
pool/shard007/C/0124298_netbuf.c
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @file
|
| 3 |
+
* Network buffer management
|
| 4 |
+
*
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
| 9 |
+
* All rights reserved.
|
| 10 |
+
*
|
| 11 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
| 12 |
+
* are permitted provided that the following conditions are met:
|
| 13 |
+
*
|
| 14 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
| 15 |
+
* this list of conditions and the following disclaimer.
|
| 16 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 17 |
+
* this list of conditions and the following disclaimer in the documentation
|
| 18 |
+
* and/or other materials provided with the distribution.
|
| 19 |
+
* 3. The name of the author may not be used to endorse or promote products
|
| 20 |
+
* derived from this software without specific prior written permission.
|
| 21 |
+
*
|
| 22 |
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
| 23 |
+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
| 24 |
+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
| 25 |
+
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 26 |
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
| 27 |
+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 28 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 29 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
| 30 |
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
| 31 |
+
* OF SUCH DAMAGE.
|
| 32 |
+
*
|
| 33 |
+
* This file is part of the lwIP TCP/IP stack.
|
| 34 |
+
*
|
| 35 |
+
* Author: Adam Dunkels <adam@sics.se>
|
| 36 |
+
*
|
| 37 |
+
*/
|
| 38 |
+
|
| 39 |
+
#include "lwip/opt.h"
|
| 40 |
+
|
| 41 |
+
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
|
| 42 |
+
|
| 43 |
+
#include "lwip/netbuf.h"
|
| 44 |
+
#include "lwip/memp.h"
|
| 45 |
+
|
| 46 |
+
#include "arch/sys_arch.h"
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Create (allocate) and initialize a new netbuf.
|
| 50 |
+
* The netbuf doesn't yet contain a packet buffer!
|
| 51 |
+
*
|
| 52 |
+
* @return a pointer to a new netbuf
|
| 53 |
+
* NULL on lack of memory
|
| 54 |
+
*/
|
| 55 |
+
struct
|
| 56 |
+
netbuf *netbuf_new(void)
|
| 57 |
+
{
|
| 58 |
+
struct netbuf *buf;
|
| 59 |
+
|
| 60 |
+
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
|
| 61 |
+
if (buf != NULL) {
|
| 62 |
+
buf->p = NULL;
|
| 63 |
+
buf->ptr = NULL;
|
| 64 |
+
ip_addr_set_any(&buf->addr);
|
| 65 |
+
buf->port = 0;
|
| 66 |
+
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
|
| 67 |
+
#if LWIP_CHECKSUM_ON_COPY
|
| 68 |
+
buf->flags = 0;
|
| 69 |
+
#endif /* LWIP_CHECKSUM_ON_COPY */
|
| 70 |
+
buf->toport_chksum = 0;
|
| 71 |
+
#if LWIP_NETBUF_RECVINFO
|
| 72 |
+
ip_addr_set_any(&buf->toaddr);
|
| 73 |
+
#endif /* LWIP_NETBUF_RECVINFO */
|
| 74 |
+
#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
|
| 75 |
+
return buf;
|
| 76 |
+
} else {
|
| 77 |
+
return NULL;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Deallocate a netbuf allocated by netbuf_new().
|
| 83 |
+
*
|
| 84 |
+
* @param buf pointer to a netbuf allocated by netbuf_new()
|
| 85 |
+
*/
|
| 86 |
+
void
|
| 87 |
+
netbuf_delete(struct netbuf *buf)
|
| 88 |
+
{
|
| 89 |
+
if (buf != NULL) {
|
| 90 |
+
if (buf->p != NULL) {
|
| 91 |
+
pbuf_free(buf->p);
|
| 92 |
+
buf->p = buf->ptr = NULL;
|
| 93 |
+
}
|
| 94 |
+
memp_free(MEMP_NETBUF, buf);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Allocate memory for a packet buffer for a given netbuf.
|
| 100 |
+
*
|
| 101 |
+
* @param buf the netbuf for which to allocate a packet buffer
|
| 102 |
+
* @param size the size of the packet buffer to allocate
|
| 103 |
+
* @return pointer to the allocated memory
|
| 104 |
+
* NULL if no memory could be allocated
|
| 105 |
+
*/
|
| 106 |
+
void *
|
| 107 |
+
netbuf_alloc(struct netbuf *buf, u16_t size)
|
| 108 |
+
{
|
| 109 |
+
LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
|
| 110 |
+
|
| 111 |
+
/* Deallocate any previously allocated memory. */
|
| 112 |
+
if (buf->p != NULL) {
|
| 113 |
+
pbuf_free(buf->p);
|
| 114 |
+
}
|
| 115 |
+
buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
|
| 116 |
+
if (buf->p == NULL) {
|
| 117 |
+
return NULL;
|
| 118 |
+
}
|
| 119 |
+
LWIP_ASSERT("check that first pbuf can hold size",
|
| 120 |
+
(buf->p->len >= size));
|
| 121 |
+
buf->ptr = buf->p;
|
| 122 |
+
return buf->p->payload;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Free the packet buffer included in a netbuf
|
| 127 |
+
*
|
| 128 |
+
* @param buf pointer to the netbuf which contains the packet buffer to free
|
| 129 |
+
*/
|
| 130 |
+
void
|
| 131 |
+
netbuf_free(struct netbuf *buf)
|
| 132 |
+
{
|
| 133 |
+
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
|
| 134 |
+
if (buf->p != NULL) {
|
| 135 |
+
pbuf_free(buf->p);
|
| 136 |
+
}
|
| 137 |
+
buf->p = buf->ptr = NULL;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Let a netbuf reference existing (non-volatile) data.
|
| 142 |
+
*
|
| 143 |
+
* @param buf netbuf which should reference the data
|
| 144 |
+
* @param dataptr pointer to the data to reference
|
| 145 |
+
* @param size size of the data
|
| 146 |
+
* @return ERR_OK if data is referenced
|
| 147 |
+
* ERR_MEM if data couldn't be referenced due to lack of memory
|
| 148 |
+
*/
|
| 149 |
+
err_t
|
| 150 |
+
netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
|
| 151 |
+
{
|
| 152 |
+
LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
|
| 153 |
+
if (buf->p != NULL) {
|
| 154 |
+
pbuf_free(buf->p);
|
| 155 |
+
}
|
| 156 |
+
buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
|
| 157 |
+
if (buf->p == NULL) {
|
| 158 |
+
buf->ptr = NULL;
|
| 159 |
+
return ERR_MEM;
|
| 160 |
+
}
|
| 161 |
+
buf->p->payload = (void*)dataptr;
|
| 162 |
+
buf->p->len = buf->p->tot_len = size;
|
| 163 |
+
buf->ptr = buf->p;
|
| 164 |
+
return ERR_OK;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* Chain one netbuf to another (@see pbuf_chain)
|
| 169 |
+
*
|
| 170 |
+
* @param head the first netbuf
|
| 171 |
+
* @param tail netbuf to chain after head, freed by this function, may not be reference after returning
|
| 172 |
+
*/
|
| 173 |
+
void
|
| 174 |
+
netbuf_chain(struct netbuf *head, struct netbuf *tail)
|
| 175 |
+
{
|
| 176 |
+
LWIP_ERROR("netbuf_ref: invalid head", (head != NULL), return;);
|
| 177 |
+
LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;);
|
| 178 |
+
pbuf_cat(head->p, tail->p);
|
| 179 |
+
head->ptr = head->p;
|
| 180 |
+
memp_free(MEMP_NETBUF, tail);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
/**
|
| 184 |
+
* Get the data pointer and length of the data inside a netbuf.
|
| 185 |
+
*
|
| 186 |
+
* @param buf netbuf to get the data from
|
| 187 |
+
* @param dataptr pointer to a void pointer where to store the data pointer
|
| 188 |
+
* @param len pointer to an u16_t where the length of the data is stored
|
| 189 |
+
* @return ERR_OK if the information was retreived,
|
| 190 |
+
* ERR_BUF on error.
|
| 191 |
+
*/
|
| 192 |
+
err_t
|
| 193 |
+
netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
|
| 194 |
+
{
|
| 195 |
+
LWIP_ERROR("netbuf_data: invalid buf", (buf != NULL), return ERR_ARG;);
|
| 196 |
+
LWIP_ERROR("netbuf_data: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
|
| 197 |
+
LWIP_ERROR("netbuf_data: invalid len", (len != NULL), return ERR_ARG;);
|
| 198 |
+
|
| 199 |
+
if (buf->ptr == NULL) {
|
| 200 |
+
return ERR_BUF;
|
| 201 |
+
}
|
| 202 |
+
*dataptr = buf->ptr->payload;
|
| 203 |
+
*len = buf->ptr->len;
|
| 204 |
+
return ERR_OK;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* Move the current data pointer of a packet buffer contained in a netbuf
|
| 209 |
+
* to the next part.
|
| 210 |
+
* The packet buffer itself is not modified.
|
| 211 |
+
*
|
| 212 |
+
* @param buf the netbuf to modify
|
| 213 |
+
* @return -1 if there is no next part
|
| 214 |
+
* 1 if moved to the next part but now there is no next part
|
| 215 |
+
* 0 if moved to the next part and there are still more parts
|
| 216 |
+
*/
|
| 217 |
+
s8_t
|
| 218 |
+
netbuf_next(struct netbuf *buf)
|
| 219 |
+
{
|
| 220 |
+
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return -1;);
|
| 221 |
+
if (buf->ptr->next == NULL) {
|
| 222 |
+
return -1;
|
| 223 |
+
}
|
| 224 |
+
buf->ptr = buf->ptr->next;
|
| 225 |
+
if (buf->ptr->next == NULL) {
|
| 226 |
+
return 1;
|
| 227 |
+
}
|
| 228 |
+
return 0;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/**
|
| 232 |
+
* Move the current data pointer of a packet buffer contained in a netbuf
|
| 233 |
+
* to the beginning of the packet.
|
| 234 |
+
* The packet buffer itself is not modified.
|
| 235 |
+
*
|
| 236 |
+
* @param buf the netbuf to modify
|
| 237 |
+
*/
|
| 238 |
+
void
|
| 239 |
+
netbuf_first(struct netbuf *buf)
|
| 240 |
+
{
|
| 241 |
+
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
|
| 242 |
+
buf->ptr = buf->p;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
#endif /* LWIP_NETCONN */
|
pool/shard007/C/0124299_usbd_hid_dance_mouse.c
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**************************************************************************//**
|
| 2 |
+
*
|
| 3 |
+
* @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 6 |
+
*
|
| 7 |
+
* Change Logs:
|
| 8 |
+
* Date Author Notes
|
| 9 |
+
* 2020-6-16 HPHuang First version
|
| 10 |
+
*
|
| 11 |
+
******************************************************************************/
|
| 12 |
+
|
| 13 |
+
#include <rtconfig.h>
|
| 14 |
+
|
| 15 |
+
#if defined(RT_USB_DEVICE_HID) && (defined(BSP_USING_USBD) || defined(BSP_USING_HSUSBD))
|
| 16 |
+
|
| 17 |
+
#include <rtthread.h>
|
| 18 |
+
#include <rtdevice.h>
|
| 19 |
+
|
| 20 |
+
#define DBG_SECTION_NAME "dancemouse"
|
| 21 |
+
#define DBG_LEVEL DBG_LOG
|
| 22 |
+
#include <rtdbg.h>
|
| 23 |
+
|
| 24 |
+
static struct rt_thread usb_thread;
|
| 25 |
+
ALIGN(RT_ALIGN_SIZE)
|
| 26 |
+
static char usb_thread_stack[1024];
|
| 27 |
+
static struct rt_semaphore tx_sem_complete;
|
| 28 |
+
|
| 29 |
+
static rt_err_t event_hid_in(rt_device_t dev, void *buffer)
|
| 30 |
+
{
|
| 31 |
+
return rt_sem_release(&tx_sem_complete);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
static void usb_thread_entry(void *parameter)
|
| 35 |
+
{
|
| 36 |
+
int8_t i8MouseTable[] = { -16, -16, -16, 0, 16, 16, 16, 0};
|
| 37 |
+
uint8_t u8MouseIdx = 0;
|
| 38 |
+
uint8_t u8MoveLen = 0, u8MouseMode = 1;
|
| 39 |
+
uint8_t pu8Buf[4];
|
| 40 |
+
rt_err_t result = RT_EOK;
|
| 41 |
+
|
| 42 |
+
rt_device_t device = (rt_device_t)parameter;
|
| 43 |
+
|
| 44 |
+
result = rt_sem_init(&tx_sem_complete, "tx_complete_sem_hid", 1, RT_IPC_FLAG_FIFO);
|
| 45 |
+
RT_ASSERT(result == RT_EOK);
|
| 46 |
+
|
| 47 |
+
result = rt_device_set_tx_complete(device, event_hid_in);
|
| 48 |
+
RT_ASSERT(result == RT_EOK);
|
| 49 |
+
|
| 50 |
+
LOG_I("Ready.\n");
|
| 51 |
+
|
| 52 |
+
while (1)
|
| 53 |
+
{
|
| 54 |
+
u8MouseMode ^= 1;
|
| 55 |
+
if (u8MouseMode)
|
| 56 |
+
{
|
| 57 |
+
if (u8MoveLen > 14)
|
| 58 |
+
{
|
| 59 |
+
/* Update new report data */
|
| 60 |
+
pu8Buf[0] = 0x00;
|
| 61 |
+
pu8Buf[1] = i8MouseTable[u8MouseIdx & 0x07];
|
| 62 |
+
pu8Buf[2] = i8MouseTable[(u8MouseIdx + 2) & 0x07];
|
| 63 |
+
pu8Buf[3] = 0x00;
|
| 64 |
+
u8MouseIdx++;
|
| 65 |
+
u8MoveLen = 0;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
else
|
| 69 |
+
{
|
| 70 |
+
pu8Buf[0] = pu8Buf[1] = pu8Buf[2] = pu8Buf[3] = 0;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
u8MoveLen++;
|
| 74 |
+
|
| 75 |
+
if (rt_device_write(device, HID_REPORT_ID_MOUSE, pu8Buf, 4) == 0)
|
| 76 |
+
{
|
| 77 |
+
/* Sleep 200 Milli-seconds */
|
| 78 |
+
rt_thread_mdelay(200);
|
| 79 |
+
}
|
| 80 |
+
else
|
| 81 |
+
{
|
| 82 |
+
/* Wait it done. */
|
| 83 |
+
result = rt_sem_take(&tx_sem_complete, RT_WAITING_FOREVER);
|
| 84 |
+
RT_ASSERT(result == RT_EOK);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
} // while(1)
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
static int dance_mouse_init(void)
|
| 91 |
+
{
|
| 92 |
+
rt_err_t ret = RT_EOK;
|
| 93 |
+
rt_device_t device = rt_device_find("hidd");
|
| 94 |
+
|
| 95 |
+
RT_ASSERT(device != RT_NULL);
|
| 96 |
+
|
| 97 |
+
ret = rt_device_open(device, RT_DEVICE_FLAG_WRONLY);
|
| 98 |
+
RT_ASSERT(ret == RT_EOK);
|
| 99 |
+
|
| 100 |
+
ret = rt_thread_init(&usb_thread,
|
| 101 |
+
"hidd",
|
| 102 |
+
usb_thread_entry, device,
|
| 103 |
+
usb_thread_stack, sizeof(usb_thread_stack),
|
| 104 |
+
10, 20);
|
| 105 |
+
RT_ASSERT(ret == RT_EOK);
|
| 106 |
+
|
| 107 |
+
ret = rt_thread_startup(&usb_thread);
|
| 108 |
+
RT_ASSERT(ret == RT_EOK);
|
| 109 |
+
|
| 110 |
+
return 0;
|
| 111 |
+
}
|
| 112 |
+
INIT_APP_EXPORT(dance_mouse_init);
|
| 113 |
+
|
| 114 |
+
#endif /* #if defined(RT_USB_DEVICE_HID) && (defined(BSP_USING_USBD) || defined(BSP_USING_HSUSBD)) */
|
| 115 |
+
|
pool/shard007/C/0124301_test-column.c
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- c-basic-offset: 2; coding: utf-8 -*- */
|
| 2 |
+
/*
|
| 3 |
+
Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
|
| 4 |
+
|
| 5 |
+
This library is free software; you can redistribute it and/or
|
| 6 |
+
modify it under the terms of the GNU Lesser General Public
|
| 7 |
+
License version 2.1 as published by the Free Software Foundation.
|
| 8 |
+
|
| 9 |
+
This library is distributed in the hope that it will be useful,
|
| 10 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 12 |
+
Lesser General Public License for more details.
|
| 13 |
+
|
| 14 |
+
You should have received a copy of the GNU Lesser General Public
|
| 15 |
+
License along with this library; if not, write to the Free Software
|
| 16 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
#include <groonga.h>
|
| 20 |
+
|
| 21 |
+
#include <gcutter.h>
|
| 22 |
+
#include <glib/gstdio.h>
|
| 23 |
+
|
| 24 |
+
#include "../lib/grn-assertions.h"
|
| 25 |
+
|
| 26 |
+
void test_fix_size_set_value_set(void);
|
| 27 |
+
void test_fix_size_set_value_increment(void);
|
| 28 |
+
void test_create_on_temporary_table(void);
|
| 29 |
+
|
| 30 |
+
static grn_logger_info *logger;
|
| 31 |
+
static grn_ctx *context;
|
| 32 |
+
static grn_obj *database;
|
| 33 |
+
static grn_obj *bookmarks;
|
| 34 |
+
static grn_obj *count_column;
|
| 35 |
+
static grn_id groonga_bookmark_id;
|
| 36 |
+
|
| 37 |
+
static void
|
| 38 |
+
create_bookmarks_table(void)
|
| 39 |
+
{
|
| 40 |
+
const gchar bookmarks_table_name[] = "bookmarks";
|
| 41 |
+
|
| 42 |
+
bookmarks = grn_table_create(context,
|
| 43 |
+
bookmarks_table_name,
|
| 44 |
+
strlen(bookmarks_table_name),
|
| 45 |
+
NULL,
|
| 46 |
+
GRN_OBJ_TABLE_HASH_KEY,
|
| 47 |
+
get_object("ShortText"),
|
| 48 |
+
NULL);
|
| 49 |
+
grn_test_assert_context(context);
|
| 50 |
+
cut_assert_not_null(
|
| 51 |
+
bookmarks,
|
| 52 |
+
cut_message("%s", grn_collect_logger_to_string(logger)));
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
static void
|
| 56 |
+
add_count_column_to_bookmarks_table (void)
|
| 57 |
+
{
|
| 58 |
+
const gchar count_column_name[] = "count";
|
| 59 |
+
|
| 60 |
+
count_column = grn_column_create(context,
|
| 61 |
+
bookmarks,
|
| 62 |
+
count_column_name,
|
| 63 |
+
strlen(count_column_name),
|
| 64 |
+
NULL, 0,
|
| 65 |
+
get_object("Int32"));
|
| 66 |
+
grn_test_assert_context(context);
|
| 67 |
+
cut_assert_not_null(
|
| 68 |
+
count_column,
|
| 69 |
+
cut_message("%s", grn_collect_logger_to_string(logger)));
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
static void
|
| 73 |
+
add_groonga_bookmark(void)
|
| 74 |
+
{
|
| 75 |
+
gchar key[] = "groonga";
|
| 76 |
+
groonga_bookmark_id = grn_table_add(context, bookmarks,
|
| 77 |
+
&key, strlen(key), NULL);
|
| 78 |
+
grn_test_assert_context(context);
|
| 79 |
+
grn_test_assert_not_nil(
|
| 80 |
+
groonga_bookmark_id,
|
| 81 |
+
cut_message("%s", grn_collect_logger_to_string(logger)));
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void
|
| 85 |
+
cut_setup(void)
|
| 86 |
+
{
|
| 87 |
+
logger = setup_grn_logger();
|
| 88 |
+
context = g_new0(grn_ctx, 1);
|
| 89 |
+
grn_ctx_init(context, 0);
|
| 90 |
+
database = grn_db_create(context, NULL, NULL);
|
| 91 |
+
|
| 92 |
+
create_bookmarks_table();
|
| 93 |
+
add_count_column_to_bookmarks_table();
|
| 94 |
+
add_groonga_bookmark();
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
void
|
| 98 |
+
cut_teardown(void)
|
| 99 |
+
{
|
| 100 |
+
grn_obj_close(context, database);
|
| 101 |
+
grn_ctx_fin(context);
|
| 102 |
+
g_free(context);
|
| 103 |
+
teardown_grn_logger(logger);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
void
|
| 107 |
+
test_fix_size_set_value_set(void)
|
| 108 |
+
{
|
| 109 |
+
gint32 count = 29;
|
| 110 |
+
gint32 retrieved_count;
|
| 111 |
+
grn_obj record_value;
|
| 112 |
+
grn_obj retrieved_record_value;
|
| 113 |
+
|
| 114 |
+
GRN_INT32_INIT(&record_value, 0);
|
| 115 |
+
GRN_INT32_SET(context, &record_value, count);
|
| 116 |
+
grn_test_assert(grn_obj_set_value(context, count_column, groonga_bookmark_id,
|
| 117 |
+
&record_value, GRN_OBJ_SET));
|
| 118 |
+
|
| 119 |
+
GRN_INT32_INIT(&retrieved_record_value, 0);
|
| 120 |
+
grn_obj_get_value(context, count_column, groonga_bookmark_id, &retrieved_record_value);
|
| 121 |
+
retrieved_count = GRN_INT32_VALUE(&retrieved_record_value);
|
| 122 |
+
cut_assert_equal_int(count, retrieved_count);
|
| 123 |
+
GRN_OBJ_FIN(context, &record_value);
|
| 124 |
+
GRN_OBJ_FIN(context, &retrieved_record_value);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
void
|
| 128 |
+
test_fix_size_set_value_increment(void)
|
| 129 |
+
{
|
| 130 |
+
gint32 count = 29;
|
| 131 |
+
gint32 increment_count = 5;
|
| 132 |
+
gint32 retrieved_count;
|
| 133 |
+
grn_obj *record_value;
|
| 134 |
+
grn_obj *retrieved_record_value;
|
| 135 |
+
|
| 136 |
+
record_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT32);
|
| 137 |
+
grn_bulk_write(context, record_value, (const char *)&count, sizeof(count));
|
| 138 |
+
grn_test_assert(grn_obj_set_value(context, count_column, groonga_bookmark_id,
|
| 139 |
+
record_value, GRN_OBJ_SET));
|
| 140 |
+
grn_obj_close(context, record_value);
|
| 141 |
+
|
| 142 |
+
record_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT32);
|
| 143 |
+
grn_bulk_write(context, record_value,
|
| 144 |
+
(const char *)&increment_count, sizeof(increment_count));
|
| 145 |
+
grn_test_assert(grn_obj_set_value(context, count_column, groonga_bookmark_id,
|
| 146 |
+
record_value, GRN_OBJ_INCR));
|
| 147 |
+
grn_obj_close(context, record_value);
|
| 148 |
+
|
| 149 |
+
retrieved_record_value = grn_obj_get_value(context, count_column,
|
| 150 |
+
groonga_bookmark_id, NULL);
|
| 151 |
+
memcpy(&retrieved_count,
|
| 152 |
+
GRN_BULK_HEAD(retrieved_record_value),
|
| 153 |
+
GRN_BULK_VSIZE(retrieved_record_value));
|
| 154 |
+
cut_assert_equal_int(count + increment_count, retrieved_count);
|
| 155 |
+
grn_obj_close(context, retrieved_record_value);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
void
|
| 159 |
+
test_create_on_temporary_table(void)
|
| 160 |
+
{
|
| 161 |
+
grn_obj *table;
|
| 162 |
+
grn_obj *column;
|
| 163 |
+
const gchar *column_name = "count";
|
| 164 |
+
|
| 165 |
+
table = grn_table_create(context, NULL, 0, NULL,
|
| 166 |
+
GRN_OBJ_TABLE_NO_KEY,
|
| 167 |
+
NULL,
|
| 168 |
+
NULL);
|
| 169 |
+
grn_test_assert_context(context);
|
| 170 |
+
column = grn_column_create(context,
|
| 171 |
+
table,
|
| 172 |
+
column_name,
|
| 173 |
+
strlen(column_name),
|
| 174 |
+
NULL, 0,
|
| 175 |
+
get_object("Int32"));
|
| 176 |
+
grn_test_assert_error(GRN_INVALID_ARGUMENT,
|
| 177 |
+
"[column][create] "
|
| 178 |
+
"temporary table doesn't support column: <count>",
|
| 179 |
+
context);
|
| 180 |
+
}
|
pool/shard007/C/0124302_temp_to_file_voice.c
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// CPU temperature writing in the text file
|
| 3 |
+
// The 6th of September 2018
|
| 4 |
+
|
| 5 |
+
// To compilate use: gcc <fileName.c> -o <result> -lrt
|
| 6 |
+
|
| 7 |
+
// Write temperature to the file
|
| 8 |
+
// Then read it with female voice
|
| 9 |
+
|
| 10 |
+
// By ALexander Noyanov
|
| 11 |
+
// Version:2.1
|
| 12 |
+
// Modified: Feb 23 2019
|
| 13 |
+
|
| 14 |
+
#include <stdio.h>
|
| 15 |
+
|
| 16 |
+
int main(){
|
| 17 |
+
|
| 18 |
+
float systemp, millideg;
|
| 19 |
+
FILE *thermal;
|
| 20 |
+
FILE *fout;
|
| 21 |
+
int n,deg;
|
| 22 |
+
|
| 23 |
+
thermal = fopen("/sys/class/thermal/thermal_zone0/temp","r"); // System temp file
|
| 24 |
+
fout = fopen("temp.txt","w"); // Output text file
|
| 25 |
+
|
| 26 |
+
n = fscanf(thermal,"%f",&millideg);
|
| 27 |
+
fclose(thermal);
|
| 28 |
+
systemp = millideg / 1000; // Temperature float
|
| 29 |
+
|
| 30 |
+
printf("CPU temperature is %f degrees C\n",systemp);
|
| 31 |
+
|
| 32 |
+
fprintf(fout,"%f \n",systemp); // Print in the file
|
| 33 |
+
|
| 34 |
+
fclose(fout); // Close file
|
| 35 |
+
|
| 36 |
+
system(""); // Read it from file with nice female voice!
|
| 37 |
+
system("flite -voice slt -t \"My processor temperature is\" "); // phrase
|
| 38 |
+
system("flite -voice slt -f \"temp.txt\" "); // CPU temperature from the file
|
| 39 |
+
system("flite -voice slt -t \" degrees Celsius\" ");
|
| 40 |
+
|
| 41 |
+
return 0;
|
| 42 |
+
|
| 43 |
+
}
|
pool/shard007/C/0124304_vega20_baco.c
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2018 Advanced Micro Devices, Inc.
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
| 5 |
+
* copy of this software and associated documentation files (the "Software"),
|
| 6 |
+
* to deal in the Software without restriction, including without limitation
|
| 7 |
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| 8 |
+
* and/or sell copies of the Software, and to permit persons to whom the
|
| 9 |
+
* Software is furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
| 17 |
+
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
| 18 |
+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
| 19 |
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 20 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
*/
|
| 23 |
+
#include "amdgpu.h"
|
| 24 |
+
#include "soc15.h"
|
| 25 |
+
#include "soc15_hw_ip.h"
|
| 26 |
+
#include "soc15_common.h"
|
| 27 |
+
#include "vega20_inc.h"
|
| 28 |
+
#include "vega20_ppsmc.h"
|
| 29 |
+
#include "vega20_baco.h"
|
| 30 |
+
#include "vega20_smumgr.h"
|
| 31 |
+
|
| 32 |
+
#include "amdgpu_ras.h"
|
| 33 |
+
|
| 34 |
+
static const struct soc15_baco_cmd_entry clean_baco_tbl[] =
|
| 35 |
+
{
|
| 36 |
+
{CMD_WRITE, SOC15_REG_ENTRY(NBIF, 0, mmBIOS_SCRATCH_6), 0, 0, 0, 0},
|
| 37 |
+
{CMD_WRITE, SOC15_REG_ENTRY(NBIF, 0, mmBIOS_SCRATCH_7), 0, 0, 0, 0},
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
int vega20_baco_get_capability(struct pp_hwmgr *hwmgr, bool *cap)
|
| 41 |
+
{
|
| 42 |
+
struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
|
| 43 |
+
uint32_t reg;
|
| 44 |
+
|
| 45 |
+
*cap = false;
|
| 46 |
+
if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_BACO))
|
| 47 |
+
return 0;
|
| 48 |
+
|
| 49 |
+
if (((RREG32(0x17569) & 0x20000000) >> 29) == 0x1) {
|
| 50 |
+
reg = RREG32_SOC15(NBIF, 0, mmRCC_BIF_STRAP0);
|
| 51 |
+
|
| 52 |
+
if (reg & RCC_BIF_STRAP0__STRAP_PX_CAPABLE_MASK)
|
| 53 |
+
*cap = true;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
return 0;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
int vega20_baco_get_state(struct pp_hwmgr *hwmgr, enum BACO_STATE *state)
|
| 60 |
+
{
|
| 61 |
+
struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
|
| 62 |
+
uint32_t reg;
|
| 63 |
+
|
| 64 |
+
reg = RREG32_SOC15(NBIF, 0, mmBACO_CNTL);
|
| 65 |
+
|
| 66 |
+
if (reg & BACO_CNTL__BACO_MODE_MASK)
|
| 67 |
+
/* gfx has already entered BACO state */
|
| 68 |
+
*state = BACO_STATE_IN;
|
| 69 |
+
else
|
| 70 |
+
*state = BACO_STATE_OUT;
|
| 71 |
+
return 0;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
int vega20_baco_set_state(struct pp_hwmgr *hwmgr, enum BACO_STATE state)
|
| 75 |
+
{
|
| 76 |
+
struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
|
| 77 |
+
struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
|
| 78 |
+
enum BACO_STATE cur_state;
|
| 79 |
+
uint32_t data;
|
| 80 |
+
|
| 81 |
+
vega20_baco_get_state(hwmgr, &cur_state);
|
| 82 |
+
|
| 83 |
+
if (cur_state == state)
|
| 84 |
+
/* aisc already in the target state */
|
| 85 |
+
return 0;
|
| 86 |
+
|
| 87 |
+
if (state == BACO_STATE_IN) {
|
| 88 |
+
if (!ras || !adev->ras_enabled) {
|
| 89 |
+
data = RREG32_SOC15(THM, 0, mmTHM_BACO_CNTL);
|
| 90 |
+
data |= 0x80000000;
|
| 91 |
+
WREG32_SOC15(THM, 0, mmTHM_BACO_CNTL, data);
|
| 92 |
+
|
| 93 |
+
if(smum_send_msg_to_smc_with_parameter(hwmgr,
|
| 94 |
+
PPSMC_MSG_EnterBaco, 0, NULL))
|
| 95 |
+
return -EINVAL;
|
| 96 |
+
} else {
|
| 97 |
+
if(smum_send_msg_to_smc_with_parameter(hwmgr,
|
| 98 |
+
PPSMC_MSG_EnterBaco, 1, NULL))
|
| 99 |
+
return -EINVAL;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
} else if (state == BACO_STATE_OUT) {
|
| 103 |
+
if (smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ExitBaco, NULL))
|
| 104 |
+
return -EINVAL;
|
| 105 |
+
if (!soc15_baco_program_registers(hwmgr, clean_baco_tbl,
|
| 106 |
+
ARRAY_SIZE(clean_baco_tbl)))
|
| 107 |
+
return -EINVAL;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
return 0;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
int vega20_baco_apply_vdci_flush_workaround(struct pp_hwmgr *hwmgr)
|
| 114 |
+
{
|
| 115 |
+
int ret = 0;
|
| 116 |
+
|
| 117 |
+
ret = vega20_set_pptable_driver_address(hwmgr);
|
| 118 |
+
if (ret)
|
| 119 |
+
return ret;
|
| 120 |
+
|
| 121 |
+
return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_BacoWorkAroundFlushVDCI, NULL);
|
| 122 |
+
}
|
pool/shard007/C/0124305_pcm512x-spi.c
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Driver for the PCM512x CODECs
|
| 3 |
+
*
|
| 4 |
+
* Author: Mark Brown <broonie@linaro.org>
|
| 5 |
+
* Copyright 2014 Linaro Ltd
|
| 6 |
+
*
|
| 7 |
+
* This program is free software; you can redistribute it and/or
|
| 8 |
+
* modify it under the terms of the GNU General Public License
|
| 9 |
+
* version 2 as published by the Free Software Foundation.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful, but
|
| 12 |
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
+
* General Public License for more details.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include <linux/init.h>
|
| 18 |
+
#include <linux/module.h>
|
| 19 |
+
#include <linux/spi/spi.h>
|
| 20 |
+
|
| 21 |
+
#include "pcm512x.h"
|
| 22 |
+
|
| 23 |
+
static int pcm512x_spi_probe(struct spi_device *spi)
|
| 24 |
+
{
|
| 25 |
+
struct regmap *regmap;
|
| 26 |
+
int ret;
|
| 27 |
+
|
| 28 |
+
regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
|
| 29 |
+
if (IS_ERR(regmap)) {
|
| 30 |
+
ret = PTR_ERR(regmap);
|
| 31 |
+
return ret;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
return pcm512x_probe(&spi->dev, regmap);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
static int pcm512x_spi_remove(struct spi_device *spi)
|
| 38 |
+
{
|
| 39 |
+
pcm512x_remove(&spi->dev);
|
| 40 |
+
return 0;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
static const struct spi_device_id pcm512x_spi_id[] = {
|
| 44 |
+
{ "pcm5121", },
|
| 45 |
+
{ "pcm5122", },
|
| 46 |
+
{ },
|
| 47 |
+
};
|
| 48 |
+
MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
|
| 49 |
+
|
| 50 |
+
static const struct of_device_id pcm512x_of_match[] = {
|
| 51 |
+
{ .compatible = "ti,pcm5121", },
|
| 52 |
+
{ .compatible = "ti,pcm5122", },
|
| 53 |
+
{ }
|
| 54 |
+
};
|
| 55 |
+
MODULE_DEVICE_TABLE(of, pcm512x_of_match);
|
| 56 |
+
|
| 57 |
+
static struct spi_driver pcm512x_spi_driver = {
|
| 58 |
+
.probe = pcm512x_spi_probe,
|
| 59 |
+
.remove = pcm512x_spi_remove,
|
| 60 |
+
.id_table = pcm512x_spi_id,
|
| 61 |
+
.driver = {
|
| 62 |
+
.name = "pcm512x",
|
| 63 |
+
.owner = THIS_MODULE,
|
| 64 |
+
.of_match_table = pcm512x_of_match,
|
| 65 |
+
.pm = &pcm512x_pm_ops,
|
| 66 |
+
},
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
module_spi_driver(pcm512x_spi_driver);
|
pool/shard007/C/0124306_pthread_getattr_np.c
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
|
| 2 |
+
This file is part of the GNU C Library.
|
| 3 |
+
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
| 4 |
+
|
| 5 |
+
The GNU C Library is free software; you can redistribute it and/or
|
| 6 |
+
modify it under the terms of the GNU Lesser General Public
|
| 7 |
+
License as published by the Free Software Foundation; either
|
| 8 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 9 |
+
|
| 10 |
+
The GNU C Library is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
Lesser General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
License along with the GNU C Library; if not, write to the Free
|
| 17 |
+
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
| 18 |
+
02111-1307 USA. */
|
| 19 |
+
|
| 20 |
+
#include <assert.h>
|
| 21 |
+
#include <errno.h>
|
| 22 |
+
#include <inttypes.h>
|
| 23 |
+
#include <stdio.h>
|
| 24 |
+
#include <stdio_ext.h>
|
| 25 |
+
#include <stdlib.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
#include <sys/resource.h>
|
| 28 |
+
#include "pthreadP.h"
|
| 29 |
+
#include <lowlevellock.h>
|
| 30 |
+
#include <ldsodefs.h>
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
int
|
| 34 |
+
pthread_getattr_np (
|
| 35 |
+
pthread_t thread_id,
|
| 36 |
+
pthread_attr_t *attr)
|
| 37 |
+
{
|
| 38 |
+
struct pthread *thread = (struct pthread *) thread_id;
|
| 39 |
+
struct pthread_attr *iattr = (struct pthread_attr *) attr;
|
| 40 |
+
int ret = 0;
|
| 41 |
+
|
| 42 |
+
lll_lock (thread->lock, LLL_PRIVATE);
|
| 43 |
+
|
| 44 |
+
/* The thread library is responsible for keeping the values in the
|
| 45 |
+
thread desriptor up-to-date in case the user changes them. */
|
| 46 |
+
memcpy (&iattr->schedparam, &thread->schedparam,
|
| 47 |
+
sizeof (struct sched_param));
|
| 48 |
+
iattr->schedpolicy = thread->schedpolicy;
|
| 49 |
+
|
| 50 |
+
/* Clear the flags work. */
|
| 51 |
+
iattr->flags = thread->flags;
|
| 52 |
+
|
| 53 |
+
/* The thread might be detached by now. */
|
| 54 |
+
if (IS_DETACHED (thread))
|
| 55 |
+
iattr->flags |= ATTR_FLAG_DETACHSTATE;
|
| 56 |
+
|
| 57 |
+
/* This is the guardsize after adjusting it. */
|
| 58 |
+
iattr->guardsize = thread->reported_guardsize;
|
| 59 |
+
|
| 60 |
+
/* The sizes are subject to alignment. */
|
| 61 |
+
if (__builtin_expect (thread->stackblock != NULL, 1))
|
| 62 |
+
{
|
| 63 |
+
iattr->stacksize = thread->stackblock_size;
|
| 64 |
+
iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
|
| 65 |
+
}
|
| 66 |
+
else
|
| 67 |
+
{
|
| 68 |
+
/* No stack information available. This must be for the initial
|
| 69 |
+
thread. Get the info in some magical way. */
|
| 70 |
+
assert (abs (thread->pid) == thread->tid);
|
| 71 |
+
|
| 72 |
+
/* Stack size limit. */
|
| 73 |
+
struct rlimit rl;
|
| 74 |
+
|
| 75 |
+
/* The safest way to get the top of the stack is to read
|
| 76 |
+
/proc/self/maps and locate the line into which
|
| 77 |
+
__libc_stack_end falls. */
|
| 78 |
+
FILE *fp = fopen ("/proc/self/maps", "rc");
|
| 79 |
+
if (fp == NULL)
|
| 80 |
+
ret = errno;
|
| 81 |
+
/* We need the limit of the stack in any case. */
|
| 82 |
+
else
|
| 83 |
+
{
|
| 84 |
+
if (getrlimit (RLIMIT_STACK, &rl) != 0)
|
| 85 |
+
ret = errno;
|
| 86 |
+
else
|
| 87 |
+
{
|
| 88 |
+
/* We need no locking. */
|
| 89 |
+
__fsetlocking (fp, FSETLOCKING_BYCALLER);
|
| 90 |
+
|
| 91 |
+
/* Until we found an entry (which should always be the case)
|
| 92 |
+
mark the result as a failure. */
|
| 93 |
+
ret = ENOENT;
|
| 94 |
+
|
| 95 |
+
char *line = NULL;
|
| 96 |
+
size_t linelen = 0;
|
| 97 |
+
uintptr_t last_to = 0;
|
| 98 |
+
|
| 99 |
+
while (! feof_unlocked (fp))
|
| 100 |
+
{
|
| 101 |
+
if (getdelim (&line, &linelen, '\n', fp) <= 0)
|
| 102 |
+
break;
|
| 103 |
+
|
| 104 |
+
uintptr_t from;
|
| 105 |
+
uintptr_t to;
|
| 106 |
+
if (sscanf (line, "%" SCNxPTR "-%" SCNxPTR, &from, &to) != 2)
|
| 107 |
+
continue;
|
| 108 |
+
if (from <= (uintptr_t) __libc_stack_end
|
| 109 |
+
&& (uintptr_t) __libc_stack_end < to)
|
| 110 |
+
{
|
| 111 |
+
/* Found the entry. Now we have the info we need. */
|
| 112 |
+
iattr->stacksize = rl.rlim_cur;
|
| 113 |
+
iattr->stackaddr = (void *) to;
|
| 114 |
+
|
| 115 |
+
/* The limit might be too high. */
|
| 116 |
+
if ((size_t) iattr->stacksize
|
| 117 |
+
> (size_t) iattr->stackaddr - last_to)
|
| 118 |
+
iattr->stacksize = (size_t) iattr->stackaddr - last_to;
|
| 119 |
+
|
| 120 |
+
/* We succeed and no need to look further. */
|
| 121 |
+
ret = 0;
|
| 122 |
+
break;
|
| 123 |
+
}
|
| 124 |
+
last_to = to;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
free (line);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
fclose (fp);
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
iattr->flags |= ATTR_FLAG_STACKADDR;
|
| 135 |
+
|
| 136 |
+
if (ret == 0)
|
| 137 |
+
{
|
| 138 |
+
size_t size = 16;
|
| 139 |
+
cpu_set_t *cpuset = NULL;
|
| 140 |
+
|
| 141 |
+
do
|
| 142 |
+
{
|
| 143 |
+
size <<= 1;
|
| 144 |
+
|
| 145 |
+
void *newp = realloc (cpuset, size);
|
| 146 |
+
if (newp == NULL)
|
| 147 |
+
{
|
| 148 |
+
ret = ENOMEM;
|
| 149 |
+
break;
|
| 150 |
+
}
|
| 151 |
+
cpuset = (cpu_set_t *) newp;
|
| 152 |
+
|
| 153 |
+
ret = __pthread_getaffinity_np (thread_id, size, cpuset);
|
| 154 |
+
}
|
| 155 |
+
/* Pick some ridiculous upper limit. Is 8 million CPUs enough? */
|
| 156 |
+
while (ret == EINVAL && size < 1024 * 1024);
|
| 157 |
+
|
| 158 |
+
if (ret == 0)
|
| 159 |
+
{
|
| 160 |
+
iattr->cpuset = cpuset;
|
| 161 |
+
iattr->cpusetsize = size;
|
| 162 |
+
}
|
| 163 |
+
else
|
| 164 |
+
{
|
| 165 |
+
free (cpuset);
|
| 166 |
+
if (ret == ENOSYS)
|
| 167 |
+
{
|
| 168 |
+
/* There is no such functionality. */
|
| 169 |
+
ret = 0;
|
| 170 |
+
iattr->cpuset = NULL;
|
| 171 |
+
iattr->cpusetsize = 0;
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
lll_unlock (thread->lock, LLL_PRIVATE);
|
| 177 |
+
|
| 178 |
+
return ret;
|
| 179 |
+
}
|
pool/shard007/C/0124308_sysinit.c
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* @brief provide system init routine/configuration for NV32Fxx.
|
| 3 |
+
*
|
| 4 |
+
*******************************************************************************/
|
| 5 |
+
|
| 6 |
+
#include "common.h"
|
| 7 |
+
#include "sysinit.h"
|
| 8 |
+
#include "sim.h"
|
| 9 |
+
#include "uart.h"
|
| 10 |
+
#include "ics.h"
|
| 11 |
+
|
| 12 |
+
/********************************************************************/
|
| 13 |
+
|
| 14 |
+
uint16_t global_pass_count = 0;
|
| 15 |
+
uint16_t global_fail_count = 0;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
void print_sys_log(void);
|
| 19 |
+
void UART_InitPrint(void);
|
| 20 |
+
|
| 21 |
+
/*****************************************************************************//*!
|
| 22 |
+
+FUNCTION----------------------------------------------------------------
|
| 23 |
+
* @function name: sysinit
|
| 24 |
+
*
|
| 25 |
+
* @brief initalize system including SIM, ICS, UART, etc
|
| 26 |
+
*
|
| 27 |
+
* @param none
|
| 28 |
+
*
|
| 29 |
+
* @return none
|
| 30 |
+
*
|
| 31 |
+
* @ Pass/ Fail criteria: none
|
| 32 |
+
*****************************************************************************/
|
| 33 |
+
void sysinit (void)
|
| 34 |
+
{
|
| 35 |
+
SIM_ConfigType sSIMConfig = {{0}, 0};
|
| 36 |
+
ICS_ConfigType sICSConfig = {0};
|
| 37 |
+
|
| 38 |
+
/* initialize the Pass/Fail counts to 0 */
|
| 39 |
+
global_pass_count = 0;
|
| 40 |
+
global_fail_count = 0;
|
| 41 |
+
|
| 42 |
+
EFMCR &= 0xFFFF0001; // set wait state 1
|
| 43 |
+
|
| 44 |
+
#if defined(TRIM_IRC)
|
| 45 |
+
/* if not trimmed, do trim first */
|
| 46 |
+
ICS_Trim(ICS_TRIM_VALUE);
|
| 47 |
+
#endif
|
| 48 |
+
/*
|
| 49 |
+
* Enable SWD pin, RESET pin
|
| 50 |
+
*/
|
| 51 |
+
/*
|
| 52 |
+
* NOTE: please make sure other register bits are also write-once and
|
| 53 |
+
* need add other bit mask here if needed.
|
| 54 |
+
*/
|
| 55 |
+
#if defined(SPI0_PINREMAP)
|
| 56 |
+
sSIMConfig.u32PinSel |= SIM_PINSEL_SPI0PS_MASK;
|
| 57 |
+
#endif
|
| 58 |
+
|
| 59 |
+
#if defined(OUTPUT_BUSCLK)
|
| 60 |
+
sSIMConfig.sBits.bEnableCLKOUT = 1; /* output bus clock if enabled */
|
| 61 |
+
#endif
|
| 62 |
+
|
| 63 |
+
#if defined(DISABLE_NMI)
|
| 64 |
+
sSIMConfig.sBits.bDisableNMI = 1;
|
| 65 |
+
#endif
|
| 66 |
+
|
| 67 |
+
#if !defined(CPU_NV32M3)
|
| 68 |
+
/* make sure clocks to peripheral modules are enabled */
|
| 69 |
+
sSIMConfig.u32SCGC |= SIM_SCGC_SWD_MASK | SIM_SCGC_FLASH_MASK |
|
| 70 |
+
SIM_SCGC_UART0_MASK | SIM_SCGC_UART1_MASK |
|
| 71 |
+
SIM_SCGC_UART2_MASK
|
| 72 |
+
;
|
| 73 |
+
#else
|
| 74 |
+
sSIMConfig.u32SCGC |= SIM_SCGC_SWD_MASK | SIM_SCGC_FLASH_MASK |
|
| 75 |
+
SIM_SCGC_UART0_MASK
|
| 76 |
+
;
|
| 77 |
+
#endif
|
| 78 |
+
|
| 79 |
+
#if !defined(CPU_NV32)
|
| 80 |
+
/* bus clock divided by 2 */
|
| 81 |
+
// sSIMConfig.u32BusDiv |= SIM_CLKDIV_OUTDIV2_MASK;
|
| 82 |
+
#endif
|
| 83 |
+
|
| 84 |
+
// sSIMConfig.sBits.bBusDiv |= SIM_BUSDIV_BUSDIV_MASK;
|
| 85 |
+
|
| 86 |
+
SIM_Init(&sSIMConfig); /* initialize SIM */
|
| 87 |
+
|
| 88 |
+
#if defined(XOSC_STOP_ENABLE)
|
| 89 |
+
sICSConfig.oscConfig.bStopEnable = 1; /* enabled in stop mode */
|
| 90 |
+
#endif
|
| 91 |
+
|
| 92 |
+
#if defined(CRYST_HIGH_GAIN)
|
| 93 |
+
sICSConfig.oscConfig.bGain = 1; /* high gain */
|
| 94 |
+
#endif
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
#if (EXT_CLK_FREQ_KHZ >=4000)
|
| 98 |
+
sICSConfig.oscConfig.bRange = 1; /* high range */
|
| 99 |
+
#endif
|
| 100 |
+
|
| 101 |
+
sICSConfig.oscConfig.bEnable = 1; /* enable OSC */
|
| 102 |
+
sICSConfig.u32ClkFreq = EXT_CLK_FREQ_KHZ;
|
| 103 |
+
|
| 104 |
+
#if defined(USE_FEE)
|
| 105 |
+
sICSConfig.u8ClkMode = ICS_CLK_MODE_FEE;
|
| 106 |
+
#elif defined(USE_FBE_OSC)
|
| 107 |
+
sICSConfig.u8ClkMode = ICS_CLK_MODE_FBE_OSC;
|
| 108 |
+
#elif defined(USE_FEE_OSC)
|
| 109 |
+
sICSConfig.u8ClkMode = ICS_CLK_MODE_FEE_OSC;
|
| 110 |
+
#elif defined(USE_FBILP)
|
| 111 |
+
sICSConfig.u8ClkMode = ICS_CLK_MODE_FBILP;
|
| 112 |
+
#elif defined(USE_FBELP)
|
| 113 |
+
sICSConfig.u8ClkMode = ICS_CLK_MODE_FBELP;
|
| 114 |
+
#endif
|
| 115 |
+
|
| 116 |
+
ICS_Init(&sICSConfig); /* initialize ICS */
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
void NMI_Handler(void)
|
| 122 |
+
{
|
| 123 |
+
while(1);
|
| 124 |
+
}
|
pool/shard007/C/0124314_main.c
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2012, Ben Noordhuis <info@bnoordhuis.nl>
|
| 3 |
+
*
|
| 4 |
+
* Permission to use, copy, modify, and/or distribute this software for any
|
| 5 |
+
* purpose with or without fee is hereby granted, provided that the above
|
| 6 |
+
* copyright notice and this permission notice appear in all copies.
|
| 7 |
+
*
|
| 8 |
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 9 |
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 10 |
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 11 |
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 12 |
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 13 |
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
| 14 |
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include "uv.h"
|
| 18 |
+
|
| 19 |
+
#include <stdio.h>
|
| 20 |
+
#include <stdarg.h>
|
| 21 |
+
#include <stddef.h>
|
| 22 |
+
#include <stdlib.h>
|
| 23 |
+
#include <string.h>
|
| 24 |
+
#include <assert.h>
|
| 25 |
+
|
| 26 |
+
#define SERVER_ADDR "0.0.0.0" // a.k.a. "all interfaces"
|
| 27 |
+
#define SERVER_PORT 8000
|
| 28 |
+
|
| 29 |
+
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
| 30 |
+
#define container_of ngx_queue_data
|
| 31 |
+
|
| 32 |
+
struct user
|
| 33 |
+
{
|
| 34 |
+
ngx_queue_t queue; // linked list
|
| 35 |
+
uv_tcp_t handle;
|
| 36 |
+
char id[32];
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
static void *xmalloc(size_t len);
|
| 40 |
+
static void fatal(const char *what);
|
| 41 |
+
static void unicast(struct user *user, const char *msg);
|
| 42 |
+
static void broadcast(const char *fmt, ...);
|
| 43 |
+
static void make_user_id(struct user *user);
|
| 44 |
+
static const char *addr_and_port(struct user *user);
|
| 45 |
+
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size);
|
| 46 |
+
static void on_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf);
|
| 47 |
+
static void on_write(uv_write_t *req, int status);
|
| 48 |
+
static void on_close(uv_handle_t* handle);
|
| 49 |
+
static void on_connection(uv_stream_t* server_handle, int status);
|
| 50 |
+
|
| 51 |
+
static ngx_queue_t users;
|
| 52 |
+
|
| 53 |
+
int main(void)
|
| 54 |
+
{
|
| 55 |
+
ngx_queue_init(&users);
|
| 56 |
+
|
| 57 |
+
uv_tcp_t server_handle;
|
| 58 |
+
uv_tcp_init(uv_default_loop(), &server_handle);
|
| 59 |
+
|
| 60 |
+
const struct sockaddr_in addr = uv_ip4_addr(SERVER_ADDR, SERVER_PORT);
|
| 61 |
+
if (uv_tcp_bind(&server_handle, addr))
|
| 62 |
+
fatal("uv_tcp_bind");
|
| 63 |
+
|
| 64 |
+
const int backlog = 128;
|
| 65 |
+
if (uv_listen((uv_stream_t*) &server_handle, backlog, on_connection))
|
| 66 |
+
fatal("uv_listen");
|
| 67 |
+
|
| 68 |
+
printf("Listening at %s:%d\n", SERVER_ADDR, SERVER_PORT);
|
| 69 |
+
uv_run(uv_default_loop());
|
| 70 |
+
|
| 71 |
+
return 0;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
static void on_connection(uv_stream_t* server_handle, int status)
|
| 75 |
+
{
|
| 76 |
+
assert(status == 0);
|
| 77 |
+
|
| 78 |
+
// hurray, a new user!
|
| 79 |
+
struct user *user = xmalloc(sizeof(*user));
|
| 80 |
+
uv_tcp_init(uv_default_loop(), &user->handle);
|
| 81 |
+
|
| 82 |
+
if (uv_accept(server_handle, (uv_stream_t*) &user->handle))
|
| 83 |
+
fatal("uv_accept");
|
| 84 |
+
|
| 85 |
+
// add him to the list of users
|
| 86 |
+
ngx_queue_insert_tail(&users, &user->queue);
|
| 87 |
+
make_user_id(user);
|
| 88 |
+
|
| 89 |
+
// now tell everyone
|
| 90 |
+
broadcast("* %s joined from %s\n", user->id, addr_and_port(user));
|
| 91 |
+
|
| 92 |
+
// start accepting messages from the user
|
| 93 |
+
uv_read_start((uv_stream_t*) &user->handle, on_alloc, on_read);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size)
|
| 97 |
+
{
|
| 98 |
+
// Return a buffer that wraps a static buffer.
|
| 99 |
+
// Safe because our on_read() allocations never overlap.
|
| 100 |
+
static char buf[512];
|
| 101 |
+
return uv_buf_init(buf, sizeof(buf));
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
static void on_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
|
| 105 |
+
{
|
| 106 |
+
struct user *user = container_of(handle, struct user, handle);
|
| 107 |
+
|
| 108 |
+
if (nread == -1) {
|
| 109 |
+
// user disconnected
|
| 110 |
+
ngx_queue_remove(&user->queue);
|
| 111 |
+
uv_close((uv_handle_t*) &user->handle, on_close);
|
| 112 |
+
broadcast("* %s has left the building\n", user->id);
|
| 113 |
+
return;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// broadcast message
|
| 117 |
+
broadcast("%s said: %.*s", user->id, (int) nread, buf.base);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
static void on_write(uv_write_t *req, int status)
|
| 121 |
+
{
|
| 122 |
+
free(req);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
static void on_close(uv_handle_t* handle)
|
| 126 |
+
{
|
| 127 |
+
struct user *user = container_of(handle, struct user, handle);
|
| 128 |
+
free(user);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
static void fatal(const char *what)
|
| 132 |
+
{
|
| 133 |
+
uv_err_t err = uv_last_error(uv_default_loop());
|
| 134 |
+
fprintf(stderr, "%s: %s\n", what, uv_strerror(err));
|
| 135 |
+
exit(1);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
static void broadcast(const char *fmt, ...)
|
| 139 |
+
{
|
| 140 |
+
ngx_queue_t *q;
|
| 141 |
+
char msg[512];
|
| 142 |
+
va_list ap;
|
| 143 |
+
|
| 144 |
+
va_start(ap, fmt);
|
| 145 |
+
vsnprintf(msg, sizeof(msg), fmt, ap);
|
| 146 |
+
va_end(ap);
|
| 147 |
+
|
| 148 |
+
ngx_queue_foreach(q, &users) {
|
| 149 |
+
struct user *user = container_of(q, struct user, queue);
|
| 150 |
+
unicast(user, msg);
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
static void unicast(struct user *user, const char *msg)
|
| 155 |
+
{
|
| 156 |
+
size_t len = strlen(msg);
|
| 157 |
+
uv_write_t *req = xmalloc(sizeof(*req) + len);
|
| 158 |
+
void *addr = req + 1;
|
| 159 |
+
memcpy(addr, msg, len);
|
| 160 |
+
uv_buf_t buf = uv_buf_init(addr, len);
|
| 161 |
+
uv_write(req, (uv_stream_t*) &user->handle, &buf, 1, on_write);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
static void make_user_id(struct user *user)
|
| 165 |
+
{
|
| 166 |
+
// most popular baby names in Alabama in 2011
|
| 167 |
+
static const char *names[] = {
|
| 168 |
+
"Mason", "Ava", "James", "Madison", "Jacob", "Olivia", "John", "Isabella",
|
| 169 |
+
"Noah", "Addison", "Jayden", "Chloe", "Elijah", "Elizabeth", "Jackson",
|
| 170 |
+
"Abigail"
|
| 171 |
+
};
|
| 172 |
+
static unsigned int index0 = 0;
|
| 173 |
+
static unsigned int index1 = 1;
|
| 174 |
+
|
| 175 |
+
snprintf(user->id, sizeof(user->id), "%s %s", names[index0], names[index1]);
|
| 176 |
+
index0 = (index0 + 3) % ARRAY_SIZE(names);
|
| 177 |
+
index1 = (index1 + 7) % ARRAY_SIZE(names);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
static const char *addr_and_port(struct user *user)
|
| 181 |
+
{
|
| 182 |
+
struct sockaddr_in name;
|
| 183 |
+
int namelen = sizeof(name);
|
| 184 |
+
if (uv_tcp_getpeername(&user->handle, (struct sockaddr*) &name, &namelen))
|
| 185 |
+
fatal("uv_tcp_getpeername");
|
| 186 |
+
|
| 187 |
+
char addr[16];
|
| 188 |
+
static char buf[32];
|
| 189 |
+
uv_inet_ntop(AF_INET, &name.sin_addr, addr, sizeof(addr));
|
| 190 |
+
snprintf(buf, sizeof(buf), "%s:%d", addr, ntohs(name.sin_port));
|
| 191 |
+
|
| 192 |
+
return buf;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
static void *xmalloc(size_t len)
|
| 196 |
+
{
|
| 197 |
+
void *ptr = malloc(len);
|
| 198 |
+
assert(ptr != NULL);
|
| 199 |
+
return ptr;
|
| 200 |
+
}
|
pool/shard007/C/0124319_csp_if_fifo_windows.c
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <Windows.h>
|
| 2 |
+
#include <process.h>
|
| 3 |
+
#include <stdio.h>
|
| 4 |
+
#include <ctype.h>
|
| 5 |
+
#include <stddef.h>
|
| 6 |
+
#undef interface
|
| 7 |
+
|
| 8 |
+
#include <csp/csp.h>
|
| 9 |
+
#include <csp/csp_interface.h>
|
| 10 |
+
|
| 11 |
+
#define PIPE_BUFSIZE 1024
|
| 12 |
+
|
| 13 |
+
#define TYPE_SERVER 1
|
| 14 |
+
#define TYPE_CLIENT 2
|
| 15 |
+
#define PORT 10
|
| 16 |
+
#define BUF_SIZE 250
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
static LPCTSTR pipeName = TEXT("\\\\.\\pipe\\CSP_Pipe");
|
| 20 |
+
|
| 21 |
+
static HANDLE pipe = INVALID_HANDLE_VALUE;
|
| 22 |
+
|
| 23 |
+
unsigned WINAPI fifo_rx(void *);
|
| 24 |
+
unsigned WINAPI pipe_listener(void *);
|
| 25 |
+
|
| 26 |
+
void printError(void);
|
| 27 |
+
|
| 28 |
+
int csp_fifo_tx(csp_packet_t *packet, uint32_t timeout);
|
| 29 |
+
|
| 30 |
+
csp_iface_t csp_if_fifo = {
|
| 31 |
+
.name = "fifo",
|
| 32 |
+
.nexthop = csp_fifo_tx,
|
| 33 |
+
.mtu = BUF_SIZE,
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
int csp_fifo_tx(csp_packet_t *packet, uint32_t timeout) {
|
| 37 |
+
printf("csp_fifo_tx tid: %lu\n", GetCurrentThreadId());
|
| 38 |
+
DWORD expectedSent = packet->length + sizeof(uint32_t) + sizeof(uint16_t);
|
| 39 |
+
DWORD actualSent;
|
| 40 |
+
/* Write packet to fifo */
|
| 41 |
+
if( !WriteFile(pipe, &packet->length, expectedSent, &actualSent, NULL)
|
| 42 |
+
|| actualSent != expectedSent ) {
|
| 43 |
+
printError();
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
csp_buffer_free(packet);
|
| 47 |
+
return CSP_ERR_NONE;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
int main(int argc, char *argv[]) {
|
| 52 |
+
int me, other, type;
|
| 53 |
+
char *message = "Testing CSP";
|
| 54 |
+
csp_socket_t *sock = NULL;
|
| 55 |
+
csp_conn_t *conn = NULL;
|
| 56 |
+
csp_packet_t *packet = NULL;
|
| 57 |
+
|
| 58 |
+
/* Run as either server or client */
|
| 59 |
+
if (argc != 2) {
|
| 60 |
+
printf("usage: server <server/client>\r\n");
|
| 61 |
+
return -1;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/* Set type */
|
| 65 |
+
if (strcmp(argv[1], "server") == 0) {
|
| 66 |
+
me = 1;
|
| 67 |
+
other = 2;
|
| 68 |
+
type = TYPE_SERVER;
|
| 69 |
+
} else if (strcmp(argv[1], "client") == 0) {
|
| 70 |
+
me = 2;
|
| 71 |
+
other = 1;
|
| 72 |
+
type = TYPE_CLIENT;
|
| 73 |
+
} else {
|
| 74 |
+
printf("Invalid type. Must be either 'server' or 'client'\r\n");
|
| 75 |
+
return -1;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/* Init CSP and CSP buffer system */
|
| 79 |
+
if (csp_init(me) != CSP_ERR_NONE || csp_buffer_init(10, 300) != CSP_ERR_NONE) {
|
| 80 |
+
printf("Failed to init CSP\r\n");
|
| 81 |
+
return -1;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if( type == TYPE_SERVER ) {
|
| 85 |
+
_beginthreadex(NULL, 0, pipe_listener, NULL, 0, 0);
|
| 86 |
+
} else {
|
| 87 |
+
pipe = CreateFile(
|
| 88 |
+
pipeName,
|
| 89 |
+
GENERIC_READ | GENERIC_WRITE,
|
| 90 |
+
0,
|
| 91 |
+
NULL,
|
| 92 |
+
OPEN_EXISTING,
|
| 93 |
+
0,
|
| 94 |
+
NULL);
|
| 95 |
+
if( pipe == INVALID_HANDLE_VALUE ) {
|
| 96 |
+
printError();
|
| 97 |
+
return -1;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/* Set default route and start router */
|
| 102 |
+
csp_route_set(CSP_DEFAULT_ROUTE, &csp_if_fifo, CSP_NODE_MAC);
|
| 103 |
+
csp_route_start_task(0, 0);
|
| 104 |
+
|
| 105 |
+
/* Create socket and listen for incoming connections */
|
| 106 |
+
if (type == TYPE_SERVER) {
|
| 107 |
+
sock = csp_socket(CSP_SO_NONE);
|
| 108 |
+
csp_bind(sock, PORT);
|
| 109 |
+
csp_listen(sock, 5);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/* Super loop */
|
| 113 |
+
while (1) {
|
| 114 |
+
if (type == TYPE_SERVER) {
|
| 115 |
+
/* Process incoming packet */
|
| 116 |
+
conn = csp_accept(sock, 1000);
|
| 117 |
+
if (conn) {
|
| 118 |
+
packet = csp_read(conn, 0);
|
| 119 |
+
if (packet)
|
| 120 |
+
printf("Received: %s\r\n", packet->data);
|
| 121 |
+
csp_buffer_free(packet);
|
| 122 |
+
csp_close(conn);
|
| 123 |
+
}
|
| 124 |
+
} else {
|
| 125 |
+
/* Send a new packet */
|
| 126 |
+
packet = csp_buffer_get(strlen(message));
|
| 127 |
+
if (packet) {
|
| 128 |
+
strcpy((char *) packet->data, message);
|
| 129 |
+
packet->length = strlen(message);
|
| 130 |
+
|
| 131 |
+
conn = csp_connect(CSP_PRIO_NORM, other, PORT, 1000, CSP_O_NONE);
|
| 132 |
+
printf("Sending: %s\r\n", message);
|
| 133 |
+
if (!conn || !csp_send(conn, packet, 1000))
|
| 134 |
+
return -1;
|
| 135 |
+
csp_close(conn);
|
| 136 |
+
Sleep(1000);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return 0;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
void printError(void) {
|
| 145 |
+
LPTSTR messageBuffer = NULL;
|
| 146 |
+
DWORD errorCode = GetLastError();
|
| 147 |
+
DWORD formatMessageRet;
|
| 148 |
+
formatMessageRet = FormatMessage(
|
| 149 |
+
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
| 150 |
+
FORMAT_MESSAGE_FROM_SYSTEM |
|
| 151 |
+
FORMAT_MESSAGE_IGNORE_INSERTS,
|
| 152 |
+
NULL,
|
| 153 |
+
errorCode,
|
| 154 |
+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
| 155 |
+
(LPTSTR)&messageBuffer,
|
| 156 |
+
0,
|
| 157 |
+
NULL);
|
| 158 |
+
|
| 159 |
+
if( !formatMessageRet ) {
|
| 160 |
+
wprintf(L"FormatMessage error, code: %lu\n", GetLastError());
|
| 161 |
+
return;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
printf("%s\n", messageBuffer);
|
| 165 |
+
LocalFree(messageBuffer);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
unsigned WINAPI pipe_listener(void *parameters) {
|
| 169 |
+
while(1) {
|
| 170 |
+
HANDLE pipe = CreateNamedPipe(
|
| 171 |
+
pipeName,
|
| 172 |
+
PIPE_ACCESS_DUPLEX,
|
| 173 |
+
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
|
| 174 |
+
PIPE_UNLIMITED_INSTANCES,
|
| 175 |
+
PIPE_BUFSIZE,
|
| 176 |
+
PIPE_BUFSIZE,
|
| 177 |
+
0,
|
| 178 |
+
NULL);
|
| 179 |
+
BOOL clientConnected;
|
| 180 |
+
if( pipe == INVALID_HANDLE_VALUE ) {
|
| 181 |
+
printf("Error creating named pipe. Code %lu\n", GetLastError());
|
| 182 |
+
return -1;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// True if client connects *after* server called ConnectNamedPipe
|
| 186 |
+
// or *between* CreateNamedPipe and ConnectNamedPipe
|
| 187 |
+
clientConnected =
|
| 188 |
+
ConnectNamedPipe(pipe, NULL) ? TRUE : GetLastError()==ERROR_PIPE_CONNECTED;
|
| 189 |
+
printf("Client connected!\n");
|
| 190 |
+
|
| 191 |
+
if( !clientConnected ) {
|
| 192 |
+
printf("Failure while listening for clients. Code %lu\n", GetLastError());
|
| 193 |
+
CloseHandle(pipe);
|
| 194 |
+
return -1;
|
| 195 |
+
}
|
| 196 |
+
printf("Create client thread\n");
|
| 197 |
+
_beginthreadex(NULL, 0, fifo_rx, (PVOID)pipe, 0, 0);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
return 0;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
unsigned WINAPI fifo_rx(void *handle) {
|
| 204 |
+
printf("fifo_rx tid: %lu\n", GetCurrentThreadId());
|
| 205 |
+
HANDLE pipe = (HANDLE) handle;
|
| 206 |
+
csp_packet_t *buf = csp_buffer_get(BUF_SIZE);
|
| 207 |
+
DWORD bytesRead;
|
| 208 |
+
BOOL readSuccess;
|
| 209 |
+
|
| 210 |
+
while(1) {
|
| 211 |
+
readSuccess =
|
| 212 |
+
ReadFile(pipe, &buf->length, BUF_SIZE, &bytesRead, NULL);
|
| 213 |
+
if( !readSuccess || bytesRead == 0 ) {
|
| 214 |
+
csp_buffer_free(buf);
|
| 215 |
+
printError();
|
| 216 |
+
break;
|
| 217 |
+
}
|
| 218 |
+
csp_new_packet(buf, &csp_if_fifo, NULL);
|
| 219 |
+
buf = csp_buffer_get(BUF_SIZE);
|
| 220 |
+
}
|
| 221 |
+
printf("Closing pipe to client\n");
|
| 222 |
+
CloseHandle(pipe);
|
| 223 |
+
|
| 224 |
+
return 0;
|
| 225 |
+
}
|
pool/shard007/C/0124323_gpio.c
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* This file is part of the Soletta Project
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2015 Intel Corporation. All rights reserved.
|
| 5 |
+
*
|
| 6 |
+
* Redistribution and use in source and binary forms, with or without
|
| 7 |
+
* modification, are permitted provided that the following conditions
|
| 8 |
+
* are met:
|
| 9 |
+
*
|
| 10 |
+
* * Redistributions of source code must retain the above copyright
|
| 11 |
+
* notice, this list of conditions and the following disclaimer.
|
| 12 |
+
* * Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
* notice, this list of conditions and the following disclaimer in
|
| 14 |
+
* the documentation and/or other materials provided with the
|
| 15 |
+
* distribution.
|
| 16 |
+
* * Neither the name of Intel Corporation nor the names of its
|
| 17 |
+
* contributors may be used to endorse or promote products derived
|
| 18 |
+
* from this software without specific prior written permission.
|
| 19 |
+
*
|
| 20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 21 |
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 22 |
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 23 |
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 24 |
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 25 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 26 |
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 27 |
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 28 |
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 29 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 30 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
#include "sol-flow/gpio.h"
|
| 34 |
+
#include "sol-flow-internal.h"
|
| 35 |
+
|
| 36 |
+
#include "sol-flow.h"
|
| 37 |
+
#include "sol-gpio.h"
|
| 38 |
+
#include "sol-util-internal.h"
|
| 39 |
+
|
| 40 |
+
#include <stdio.h>
|
| 41 |
+
#include <stdlib.h>
|
| 42 |
+
|
| 43 |
+
struct gpio_data {
|
| 44 |
+
struct sol_gpio *gpio;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
static void
|
| 48 |
+
gpio_close(struct sol_flow_node *node, void *data)
|
| 49 |
+
{
|
| 50 |
+
struct gpio_data *mdata = data;
|
| 51 |
+
|
| 52 |
+
sol_gpio_close(mdata->gpio);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* GPIO READER ********************************************************************/
|
| 56 |
+
static void
|
| 57 |
+
gpio_reader_event(void *data, struct sol_gpio *gpio, bool value)
|
| 58 |
+
{
|
| 59 |
+
struct sol_flow_node *node = data;
|
| 60 |
+
|
| 61 |
+
sol_flow_send_boolean_packet(node,
|
| 62 |
+
SOL_FLOW_NODE_TYPE_GPIO_READER__OUT__OUT, value);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
static int
|
| 66 |
+
gpio_reader_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
|
| 67 |
+
{
|
| 68 |
+
uint32_t pin;
|
| 69 |
+
struct gpio_data *mdata = data;
|
| 70 |
+
const struct sol_flow_node_type_gpio_reader_options *opts =
|
| 71 |
+
(const struct sol_flow_node_type_gpio_reader_options *)options;
|
| 72 |
+
struct sol_gpio_config gpio_conf = { 0 };
|
| 73 |
+
static const enum sol_gpio_edge mode_lut[] = {
|
| 74 |
+
[0 + 2 * 0] = SOL_GPIO_EDGE_NONE,
|
| 75 |
+
[1 + 2 * 0] = SOL_GPIO_EDGE_RISING,
|
| 76 |
+
[0 + 2 * 1] = SOL_GPIO_EDGE_FALLING,
|
| 77 |
+
[1 + 2 * 1] = SOL_GPIO_EDGE_BOTH
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options, SOL_FLOW_NODE_TYPE_GPIO_READER_OPTIONS_API_VERSION, -EINVAL);
|
| 81 |
+
|
| 82 |
+
SOL_SET_API_VERSION(gpio_conf.api_version = SOL_GPIO_CONFIG_API_VERSION; )
|
| 83 |
+
gpio_conf.dir = SOL_GPIO_DIR_IN;
|
| 84 |
+
gpio_conf.active_low = opts->active_low;
|
| 85 |
+
gpio_conf.in.trigger_mode = mode_lut[opts->edge_rising + 2 * opts->edge_falling];
|
| 86 |
+
gpio_conf.in.cb = gpio_reader_event;
|
| 87 |
+
gpio_conf.in.user_data = node;
|
| 88 |
+
gpio_conf.in.poll_timeout = opts->poll_timeout;
|
| 89 |
+
|
| 90 |
+
if (gpio_conf.in.trigger_mode == SOL_GPIO_EDGE_NONE) {
|
| 91 |
+
SOL_WRN("gpio reader #%s: either edge_rising or edge_falling need to be"
|
| 92 |
+
" set for the node to generate events.", opts->pin);
|
| 93 |
+
return -EINVAL;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
if (streq(opts->pull, "up"))
|
| 97 |
+
gpio_conf.drive_mode = SOL_GPIO_DRIVE_PULL_UP;
|
| 98 |
+
else if (streq(opts->pull, "down"))
|
| 99 |
+
gpio_conf.drive_mode = SOL_GPIO_DRIVE_PULL_DOWN;
|
| 100 |
+
|
| 101 |
+
mdata->gpio = NULL;
|
| 102 |
+
if (!opts->pin || *opts->pin == '\0') {
|
| 103 |
+
SOL_WRN("gpio: Option 'pin' cannot be neither 'null' nor empty.");
|
| 104 |
+
return -EINVAL;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
if (opts->raw) {
|
| 108 |
+
if (!sscanf(opts->pin, "%" SCNu32, &pin)) {
|
| 109 |
+
SOL_WRN("gpio (%s): 'raw' option was set, but 'pin' value=%s couldn't be parsed as "
|
| 110 |
+
"integer.", opts->pin, opts->pin);
|
| 111 |
+
} else {
|
| 112 |
+
mdata->gpio = sol_gpio_open(pin, &gpio_conf);
|
| 113 |
+
}
|
| 114 |
+
} else {
|
| 115 |
+
mdata->gpio = sol_gpio_open_by_label(opts->pin, &gpio_conf);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
if (!mdata->gpio) {
|
| 119 |
+
SOL_WRN("Could not open gpio #%s", opts->pin);
|
| 120 |
+
return -EIO;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
return 0;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/* GPIO WRITER *******************************************************************/
|
| 127 |
+
|
| 128 |
+
static int
|
| 129 |
+
gpio_writer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
|
| 130 |
+
{
|
| 131 |
+
bool value;
|
| 132 |
+
struct gpio_data *mdata = data;
|
| 133 |
+
int r = sol_flow_packet_get_boolean(packet, &value);
|
| 134 |
+
|
| 135 |
+
SOL_INT_CHECK(r, < 0, r);
|
| 136 |
+
if (!sol_gpio_write(mdata->gpio, value)) {
|
| 137 |
+
return -EIO;
|
| 138 |
+
}
|
| 139 |
+
return 0;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
static int
|
| 143 |
+
gpio_writer_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
|
| 144 |
+
{
|
| 145 |
+
uint32_t pin;
|
| 146 |
+
struct gpio_data *mdata = data;
|
| 147 |
+
const struct sol_flow_node_type_gpio_writer_options *opts =
|
| 148 |
+
(const struct sol_flow_node_type_gpio_writer_options *)options;
|
| 149 |
+
struct sol_gpio_config gpio_conf = { 0 };
|
| 150 |
+
|
| 151 |
+
SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options, SOL_FLOW_NODE_TYPE_GPIO_WRITER_OPTIONS_API_VERSION, -EINVAL);
|
| 152 |
+
|
| 153 |
+
SOL_SET_API_VERSION(gpio_conf.api_version = SOL_GPIO_CONFIG_API_VERSION; )
|
| 154 |
+
gpio_conf.dir = SOL_GPIO_DIR_OUT;
|
| 155 |
+
gpio_conf.active_low = opts->active_low;
|
| 156 |
+
|
| 157 |
+
mdata->gpio = NULL;
|
| 158 |
+
if (!opts->pin || *opts->pin == '\0') {
|
| 159 |
+
SOL_WRN("gpio: Option 'pin' cannot be neither 'null' nor empty.");
|
| 160 |
+
return -EINVAL;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
if (opts->raw) {
|
| 164 |
+
if (!sscanf(opts->pin, "%" SCNu32, &pin)) {
|
| 165 |
+
SOL_WRN("gpio (%s): 'raw' option was set, but 'pin' value=%s couldn't be parsed as "
|
| 166 |
+
"integer.", opts->pin, opts->pin);
|
| 167 |
+
} else {
|
| 168 |
+
mdata->gpio = sol_gpio_open(pin, &gpio_conf);
|
| 169 |
+
}
|
| 170 |
+
} else {
|
| 171 |
+
mdata->gpio = sol_gpio_open_by_label(opts->pin, &gpio_conf);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
if (!mdata->gpio) {
|
| 175 |
+
SOL_WRN("Could not open gpio #%s", opts->pin);
|
| 176 |
+
return -EIO;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
return 0;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
#include "gpio-gen.c"
|
pool/shard007/C/0124325_md4_one.c
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* crypto/md4/md4_one.c */
|
| 2 |
+
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This package is an SSL implementation written
|
| 6 |
+
* by Eric Young (eay@cryptsoft.com).
|
| 7 |
+
* The implementation was written so as to conform with Netscapes SSL.
|
| 8 |
+
*
|
| 9 |
+
* This library is free for commercial and non-commercial use as long as
|
| 10 |
+
* the following conditions are aheared to. The following conditions
|
| 11 |
+
* apply to all code found in this distribution, be it the RC4, RSA,
|
| 12 |
+
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
| 13 |
+
* included with this distribution is covered by the same copyright terms
|
| 14 |
+
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
| 15 |
+
*
|
| 16 |
+
* Copyright remains Eric Young's, and as such any Copyright notices in
|
| 17 |
+
* the code are not to be removed.
|
| 18 |
+
* If this package is used in a product, Eric Young should be given attribution
|
| 19 |
+
* as the author of the parts of the library used.
|
| 20 |
+
* This can be in the form of a textual message at program startup or
|
| 21 |
+
* in documentation (online or textual) provided with the package.
|
| 22 |
+
*
|
| 23 |
+
* Redistribution and use in source and binary forms, with or without
|
| 24 |
+
* modification, are permitted provided that the following conditions
|
| 25 |
+
* are met:
|
| 26 |
+
* 1. Redistributions of source code must retain the copyright
|
| 27 |
+
* notice, this list of conditions and the following disclaimer.
|
| 28 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 29 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 30 |
+
* documentation and/or other materials provided with the distribution.
|
| 31 |
+
* 3. All advertising materials mentioning features or use of this software
|
| 32 |
+
* must display the following acknowledgement:
|
| 33 |
+
* "This product includes cryptographic software written by
|
| 34 |
+
* Eric Young (eay@cryptsoft.com)"
|
| 35 |
+
* The word 'cryptographic' can be left out if the rouines from the library
|
| 36 |
+
* being used are not cryptographic related :-).
|
| 37 |
+
* 4. If you include any Windows specific code (or a derivative thereof) from
|
| 38 |
+
* the apps directory (application code) you must include an acknowledgement:
|
| 39 |
+
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
| 40 |
+
*
|
| 41 |
+
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
| 42 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 43 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 44 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
| 45 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 46 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 47 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 48 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 49 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 50 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 51 |
+
* SUCH DAMAGE.
|
| 52 |
+
*
|
| 53 |
+
* The licence and distribution terms for any publically available version or
|
| 54 |
+
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
| 55 |
+
* copied and put under another distribution licence
|
| 56 |
+
* [including the GNU Public Licence.]
|
| 57 |
+
*/
|
| 58 |
+
|
| 59 |
+
#include <stdio.h>
|
| 60 |
+
#include <string.h>
|
| 61 |
+
#include <openssl/md4.h>
|
| 62 |
+
#include <openssl/crypto.h>
|
| 63 |
+
|
| 64 |
+
#ifdef CHARSET_EBCDIC
|
| 65 |
+
#include <openssl/ebcdic.h>
|
| 66 |
+
#endif
|
| 67 |
+
|
| 68 |
+
unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md)
|
| 69 |
+
{
|
| 70 |
+
MD4_CTX c;
|
| 71 |
+
static unsigned char m[MD4_DIGEST_LENGTH];
|
| 72 |
+
|
| 73 |
+
if (md == NULL) md=m;
|
| 74 |
+
if (!MD4_Init(&c))
|
| 75 |
+
return NULL;
|
| 76 |
+
#ifndef CHARSET_EBCDIC
|
| 77 |
+
MD4_Update(&c,d,n);
|
| 78 |
+
#else
|
| 79 |
+
{
|
| 80 |
+
char temp[1024];
|
| 81 |
+
unsigned long chunk;
|
| 82 |
+
|
| 83 |
+
while (n > 0)
|
| 84 |
+
{
|
| 85 |
+
chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
|
| 86 |
+
ebcdic2ascii(temp, d, chunk);
|
| 87 |
+
MD4_Update(&c,temp,chunk);
|
| 88 |
+
n -= chunk;
|
| 89 |
+
d += chunk;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
#endif
|
| 93 |
+
MD4_Final(md,&c);
|
| 94 |
+
OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
|
| 95 |
+
return(md);
|
| 96 |
+
}
|
| 97 |
+
|
pool/shard007/C/0124326_soc-utils.c
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: GPL-2.0+
|
| 2 |
+
//
|
| 3 |
+
// soc-util.c -- ALSA SoC Audio Layer utility functions
|
| 4 |
+
//
|
| 5 |
+
// Copyright 2009 Wolfson Microelectronics PLC.
|
| 6 |
+
//
|
| 7 |
+
// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
| 8 |
+
// Liam Girdwood <lrg@slimlogic.co.uk>
|
| 9 |
+
|
| 10 |
+
#include <linux/platform_device.h>
|
| 11 |
+
#include <linux/export.h>
|
| 12 |
+
#include <sound/core.h>
|
| 13 |
+
#include <sound/pcm.h>
|
| 14 |
+
#include <sound/pcm_params.h>
|
| 15 |
+
#include <sound/soc.h>
|
| 16 |
+
|
| 17 |
+
int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
|
| 18 |
+
{
|
| 19 |
+
return sample_size * channels * tdm_slots;
|
| 20 |
+
}
|
| 21 |
+
EXPORT_SYMBOL_GPL(snd_soc_calc_frame_size);
|
| 22 |
+
|
| 23 |
+
int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params)
|
| 24 |
+
{
|
| 25 |
+
int sample_size;
|
| 26 |
+
|
| 27 |
+
sample_size = snd_pcm_format_width(params_format(params));
|
| 28 |
+
if (sample_size < 0)
|
| 29 |
+
return sample_size;
|
| 30 |
+
|
| 31 |
+
return snd_soc_calc_frame_size(sample_size, params_channels(params),
|
| 32 |
+
1);
|
| 33 |
+
}
|
| 34 |
+
EXPORT_SYMBOL_GPL(snd_soc_params_to_frame_size);
|
| 35 |
+
|
| 36 |
+
int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots)
|
| 37 |
+
{
|
| 38 |
+
return fs * snd_soc_calc_frame_size(sample_size, channels, tdm_slots);
|
| 39 |
+
}
|
| 40 |
+
EXPORT_SYMBOL_GPL(snd_soc_calc_bclk);
|
| 41 |
+
|
| 42 |
+
int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params)
|
| 43 |
+
{
|
| 44 |
+
int ret;
|
| 45 |
+
|
| 46 |
+
ret = snd_soc_params_to_frame_size(params);
|
| 47 |
+
|
| 48 |
+
if (ret > 0)
|
| 49 |
+
return ret * params_rate(params);
|
| 50 |
+
else
|
| 51 |
+
return ret;
|
| 52 |
+
}
|
| 53 |
+
EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk);
|
| 54 |
+
|
| 55 |
+
static const struct snd_pcm_hardware dummy_dma_hardware = {
|
| 56 |
+
/* Random values to keep userspace happy when checking constraints */
|
| 57 |
+
.info = SNDRV_PCM_INFO_INTERLEAVED |
|
| 58 |
+
SNDRV_PCM_INFO_BLOCK_TRANSFER,
|
| 59 |
+
.buffer_bytes_max = 128*1024,
|
| 60 |
+
.period_bytes_min = PAGE_SIZE,
|
| 61 |
+
.period_bytes_max = PAGE_SIZE*2,
|
| 62 |
+
.periods_min = 2,
|
| 63 |
+
.periods_max = 128,
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
static int dummy_dma_open(struct snd_soc_component *component,
|
| 67 |
+
struct snd_pcm_substream *substream)
|
| 68 |
+
{
|
| 69 |
+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
|
| 70 |
+
|
| 71 |
+
/* BE's dont need dummy params */
|
| 72 |
+
if (!rtd->dai_link->no_pcm)
|
| 73 |
+
snd_soc_set_runtime_hwparams(substream, &dummy_dma_hardware);
|
| 74 |
+
|
| 75 |
+
return 0;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
static const struct snd_soc_component_driver dummy_platform = {
|
| 79 |
+
.open = dummy_dma_open,
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
static const struct snd_soc_component_driver dummy_codec = {
|
| 83 |
+
.idle_bias_on = 1,
|
| 84 |
+
.use_pmdown_time = 1,
|
| 85 |
+
.endianness = 1,
|
| 86 |
+
.non_legacy_dai_naming = 1,
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
#define STUB_RATES SNDRV_PCM_RATE_8000_384000
|
| 90 |
+
#define STUB_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
|
| 91 |
+
SNDRV_PCM_FMTBIT_U8 | \
|
| 92 |
+
SNDRV_PCM_FMTBIT_S16_LE | \
|
| 93 |
+
SNDRV_PCM_FMTBIT_U16_LE | \
|
| 94 |
+
SNDRV_PCM_FMTBIT_S24_LE | \
|
| 95 |
+
SNDRV_PCM_FMTBIT_S24_3LE | \
|
| 96 |
+
SNDRV_PCM_FMTBIT_U24_LE | \
|
| 97 |
+
SNDRV_PCM_FMTBIT_S32_LE | \
|
| 98 |
+
SNDRV_PCM_FMTBIT_U32_LE | \
|
| 99 |
+
SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
|
| 100 |
+
/*
|
| 101 |
+
* The dummy CODEC is only meant to be used in situations where there is no
|
| 102 |
+
* actual hardware.
|
| 103 |
+
*
|
| 104 |
+
* If there is actual hardware even if it does not have a control bus
|
| 105 |
+
* the hardware will still have constraints like supported samplerates, etc.
|
| 106 |
+
* which should be modelled. And the data flow graph also should be modelled
|
| 107 |
+
* using DAPM.
|
| 108 |
+
*/
|
| 109 |
+
static struct snd_soc_dai_driver dummy_dai = {
|
| 110 |
+
.name = "snd-soc-dummy-dai",
|
| 111 |
+
.playback = {
|
| 112 |
+
.stream_name = "Playback",
|
| 113 |
+
.channels_min = 1,
|
| 114 |
+
.channels_max = 384,
|
| 115 |
+
.rates = STUB_RATES,
|
| 116 |
+
.formats = STUB_FORMATS,
|
| 117 |
+
},
|
| 118 |
+
.capture = {
|
| 119 |
+
.stream_name = "Capture",
|
| 120 |
+
.channels_min = 1,
|
| 121 |
+
.channels_max = 384,
|
| 122 |
+
.rates = STUB_RATES,
|
| 123 |
+
.formats = STUB_FORMATS,
|
| 124 |
+
},
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
int snd_soc_dai_is_dummy(struct snd_soc_dai *dai)
|
| 128 |
+
{
|
| 129 |
+
if (dai->driver == &dummy_dai)
|
| 130 |
+
return 1;
|
| 131 |
+
return 0;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
static int snd_soc_dummy_probe(struct platform_device *pdev)
|
| 135 |
+
{
|
| 136 |
+
int ret;
|
| 137 |
+
|
| 138 |
+
ret = devm_snd_soc_register_component(&pdev->dev,
|
| 139 |
+
&dummy_codec, &dummy_dai, 1);
|
| 140 |
+
if (ret < 0)
|
| 141 |
+
return ret;
|
| 142 |
+
|
| 143 |
+
ret = devm_snd_soc_register_component(&pdev->dev, &dummy_platform,
|
| 144 |
+
NULL, 0);
|
| 145 |
+
|
| 146 |
+
return ret;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
static struct platform_driver soc_dummy_driver = {
|
| 150 |
+
.driver = {
|
| 151 |
+
.name = "snd-soc-dummy",
|
| 152 |
+
},
|
| 153 |
+
.probe = snd_soc_dummy_probe,
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
+
static struct platform_device *soc_dummy_dev;
|
| 157 |
+
|
| 158 |
+
int __init snd_soc_util_init(void)
|
| 159 |
+
{
|
| 160 |
+
int ret;
|
| 161 |
+
|
| 162 |
+
soc_dummy_dev =
|
| 163 |
+
platform_device_register_simple("snd-soc-dummy", -1, NULL, 0);
|
| 164 |
+
if (IS_ERR(soc_dummy_dev))
|
| 165 |
+
return PTR_ERR(soc_dummy_dev);
|
| 166 |
+
|
| 167 |
+
ret = platform_driver_register(&soc_dummy_driver);
|
| 168 |
+
if (ret != 0)
|
| 169 |
+
platform_device_unregister(soc_dummy_dev);
|
| 170 |
+
|
| 171 |
+
return ret;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
void __exit snd_soc_util_exit(void)
|
| 175 |
+
{
|
| 176 |
+
platform_driver_unregister(&soc_dummy_driver);
|
| 177 |
+
platform_device_unregister(soc_dummy_dev);
|
| 178 |
+
}
|
pool/shard007/C/0124331_pvdpv.c
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "sofam.h"
|
| 2 |
+
|
| 3 |
+
void iauPvdpv(double a[2][3], double b[2][3], double adb[2])
|
| 4 |
+
/*
|
| 5 |
+
** - - - - - - - - -
|
| 6 |
+
** i a u P v d p v
|
| 7 |
+
** - - - - - - - - -
|
| 8 |
+
**
|
| 9 |
+
** Inner (=scalar=dot) product of two pv-vectors.
|
| 10 |
+
**
|
| 11 |
+
** Status: vector/matrix support function.
|
| 12 |
+
**
|
| 13 |
+
** Given:
|
| 14 |
+
** a double[2][3] first pv-vector
|
| 15 |
+
** b double[2][3] second pv-vector
|
| 16 |
+
**
|
| 17 |
+
** Returned:
|
| 18 |
+
** adb double[2] a . b (see note)
|
| 19 |
+
**
|
| 20 |
+
** Note:
|
| 21 |
+
**
|
| 22 |
+
** If the position and velocity components of the two pv-vectors are
|
| 23 |
+
** ( ap, av ) and ( bp, bv ), the result, a . b, is the pair of
|
| 24 |
+
** numbers ( ap . bp , ap . bv + av . bp ). The two numbers are the
|
| 25 |
+
** dot-product of the two p-vectors and its derivative.
|
| 26 |
+
**
|
| 27 |
+
** Called:
|
| 28 |
+
** iauPdp scalar product of two p-vectors
|
| 29 |
+
**
|
| 30 |
+
** This revision: 2008 May 22
|
| 31 |
+
**
|
| 32 |
+
** Original version 2012-03-01
|
| 33 |
+
**
|
| 34 |
+
** Copyright (C) 2013 Naoki Arita. See notes at end.
|
| 35 |
+
*/
|
| 36 |
+
{
|
| 37 |
+
double adbd, addb;
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
/* a . b = constant part of result. */
|
| 41 |
+
adb[0] = iauPdp(a[0], b[0]);
|
| 42 |
+
|
| 43 |
+
/* a . bdot */
|
| 44 |
+
adbd = iauPdp(a[0], b[1]);
|
| 45 |
+
|
| 46 |
+
/* adot . b */
|
| 47 |
+
addb = iauPdp(a[1], b[0]);
|
| 48 |
+
|
| 49 |
+
/* Velocity part of result. */
|
| 50 |
+
adb[1] = adbd + addb;
|
| 51 |
+
|
| 52 |
+
return;
|
| 53 |
+
|
| 54 |
+
/*----------------------------------------------------------------------
|
| 55 |
+
**
|
| 56 |
+
** Celes is a wrapper of the SOFA Library for Ruby.
|
| 57 |
+
**
|
| 58 |
+
** This file is redistributed and relicensed in accordance with
|
| 59 |
+
** the SOFA Software License (http://www.iausofa.org/tandc.html).
|
| 60 |
+
**
|
| 61 |
+
** The original library is available from IAU Standards of
|
| 62 |
+
** Fundamental Astronomy (http://www.iausofa.org/).
|
| 63 |
+
**
|
| 64 |
+
**
|
| 65 |
+
**
|
| 66 |
+
**
|
| 67 |
+
**
|
| 68 |
+
** Copyright (C) 2013, Naoki Arita
|
| 69 |
+
** All rights reserved.
|
| 70 |
+
**
|
| 71 |
+
** Redistribution and use in source and binary forms, with or without
|
| 72 |
+
** modification, are permitted provided that the following conditions
|
| 73 |
+
** are met:
|
| 74 |
+
**
|
| 75 |
+
** 1 Redistributions of source code must retain the above copyright
|
| 76 |
+
** notice, this list of conditions and the following disclaimer.
|
| 77 |
+
**
|
| 78 |
+
** 2 Redistributions in binary form must reproduce the above copyright
|
| 79 |
+
** notice, this list of conditions and the following disclaimer in
|
| 80 |
+
** the documentation and/or other materials provided with the
|
| 81 |
+
** distribution.
|
| 82 |
+
**
|
| 83 |
+
** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
|
| 84 |
+
** the International Astronomical Union nor the names of its
|
| 85 |
+
** contributors may be used to endorse or promote products derived
|
| 86 |
+
** from this software without specific prior written permission.
|
| 87 |
+
**
|
| 88 |
+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 89 |
+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 90 |
+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 91 |
+
** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 92 |
+
** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 93 |
+
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 94 |
+
** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 95 |
+
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 96 |
+
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 97 |
+
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 98 |
+
** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 99 |
+
** POSSIBILITY OF SUCH DAMAGE.
|
| 100 |
+
**
|
| 101 |
+
**--------------------------------------------------------------------*/
|
| 102 |
+
}
|
pool/shard007/C/0124332_metadata.c
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Multi2Sim
|
| 3 |
+
* Copyright (C) 2013 Rafael Ubal (ubal@ece.neu.edu)
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#include <arch/southern-islands/asm/arg.h>
|
| 22 |
+
#include <lib/mhandle/mhandle.h>
|
| 23 |
+
#include <lib/util/list.h>
|
| 24 |
+
|
| 25 |
+
#include "metadata.h"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
/*
|
| 29 |
+
* Metadata Object
|
| 30 |
+
*/
|
| 31 |
+
|
| 32 |
+
struct si2bin_metadata_t *si2bin_metadata_create(void)
|
| 33 |
+
{
|
| 34 |
+
struct si2bin_metadata_t *metadata;
|
| 35 |
+
|
| 36 |
+
metadata = xcalloc(1, sizeof(struct si2bin_metadata_t));
|
| 37 |
+
|
| 38 |
+
metadata->arg_list = list_create();
|
| 39 |
+
|
| 40 |
+
/* Return */
|
| 41 |
+
return metadata;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void si2bin_metadata_free(struct si2bin_metadata_t *metadata)
|
| 45 |
+
{
|
| 46 |
+
struct si_arg_t *arg;
|
| 47 |
+
int i;
|
| 48 |
+
|
| 49 |
+
LIST_FOR_EACH(metadata->arg_list, i)
|
| 50 |
+
{
|
| 51 |
+
arg = list_get(metadata->arg_list, i);
|
| 52 |
+
si_arg_free(arg);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
list_free(metadata->arg_list);
|
| 56 |
+
|
| 57 |
+
free(metadata);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
void si2bin_metadata_add_arg(struct si2bin_metadata_t *metadata, struct si_arg_t *arg)
|
| 61 |
+
{
|
| 62 |
+
list_add(metadata->arg_list, arg);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
pool/shard007/C/0124338_splitimage2pdf.c
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*====================================================================*
|
| 2 |
+
- Copyright (C) 2001 Leptonica. All rights reserved.
|
| 3 |
+
-
|
| 4 |
+
- Redistribution and use in source and binary forms, with or without
|
| 5 |
+
- modification, are permitted provided that the following conditions
|
| 6 |
+
- are met:
|
| 7 |
+
- 1. Redistributions of source code must retain the above copyright
|
| 8 |
+
- notice, this list of conditions and the following disclaimer.
|
| 9 |
+
- 2. Redistributions in binary form must reproduce the above
|
| 10 |
+
- copyright notice, this list of conditions and the following
|
| 11 |
+
- disclaimer in the documentation and/or other materials
|
| 12 |
+
- provided with the distribution.
|
| 13 |
+
-
|
| 14 |
+
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 15 |
+
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 16 |
+
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 17 |
+
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
|
| 18 |
+
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 19 |
+
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 20 |
+
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 21 |
+
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
| 22 |
+
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 23 |
+
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 24 |
+
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 25 |
+
*====================================================================*/
|
| 26 |
+
|
| 27 |
+
/*
|
| 28 |
+
* splitimage2pdf.c
|
| 29 |
+
*
|
| 30 |
+
* Syntax: splitimage2pdf filein nx ny fileout
|
| 31 |
+
*
|
| 32 |
+
* nx = number of horizontal tiles
|
| 33 |
+
* ny = number of vertical tiles
|
| 34 |
+
*
|
| 35 |
+
* Generates pdf of image tiles. Rotates the image before
|
| 36 |
+
* tiling if the tiles otherwise will have larger width than
|
| 37 |
+
* height.
|
| 38 |
+
*
|
| 39 |
+
* N.B. This requires ps2pdf. It should be rewritten to generate pdf
|
| 40 |
+
* directly, instead of PostScript
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
#include "allheaders.h"
|
| 44 |
+
|
| 45 |
+
/* fill factor on 8.5 x 11 inch output page */
|
| 46 |
+
static const l_float32 FILL_FACTOR = 0.95;
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
int main(int argc,
|
| 50 |
+
char **argv)
|
| 51 |
+
{
|
| 52 |
+
char *filein, *fileout, *fname;
|
| 53 |
+
char buffer[512];
|
| 54 |
+
const char *psfile = "/tmp/junk_split_image.ps";
|
| 55 |
+
l_int32 nx, ny, i, w, h, d, ws, hs, n, res, ignore;
|
| 56 |
+
l_float32 scale;
|
| 57 |
+
PIX *pixs, *pixt, *pixr;
|
| 58 |
+
PIXA *pixa;
|
| 59 |
+
static char mainName[] = "splitimage2pdf";
|
| 60 |
+
|
| 61 |
+
if (argc != 5)
|
| 62 |
+
return ERROR_INT(" Syntax: splitimage2pdf filein nx ny fileout",
|
| 63 |
+
mainName, 1);
|
| 64 |
+
|
| 65 |
+
filein = argv[1];
|
| 66 |
+
nx = atoi(argv[2]);
|
| 67 |
+
ny = atoi(argv[3]);
|
| 68 |
+
fileout = argv[4];
|
| 69 |
+
|
| 70 |
+
lept_rm(NULL, "junk_split_image.ps");
|
| 71 |
+
|
| 72 |
+
if ((pixs = pixRead(filein)) == NULL)
|
| 73 |
+
return ERROR_INT("pixs not made", mainName, 1);
|
| 74 |
+
d = pixGetDepth(pixs);
|
| 75 |
+
if (d == 1 )
|
| 76 |
+
lept_rm(NULL, "junk_split_image.tif");
|
| 77 |
+
else if (d == 8 || d == 32)
|
| 78 |
+
lept_rm(NULL, "junk_split_image.jpg");
|
| 79 |
+
else
|
| 80 |
+
return ERROR_INT("d not in {1,8,32} bpp", mainName, 1);
|
| 81 |
+
|
| 82 |
+
pixGetDimensions(pixs, &ws, &hs, NULL);
|
| 83 |
+
if (ny * ws > nx * hs)
|
| 84 |
+
pixr = pixRotate90(pixs, 1);
|
| 85 |
+
else
|
| 86 |
+
pixr = pixClone(pixs);
|
| 87 |
+
|
| 88 |
+
pixa = pixaSplitPix(pixr, nx, ny, 0, 0);
|
| 89 |
+
n = pixaGetCount(pixa);
|
| 90 |
+
res = 300;
|
| 91 |
+
for (i = 0; i < n; i++) {
|
| 92 |
+
pixt = pixaGetPix(pixa, i, L_CLONE);
|
| 93 |
+
pixGetDimensions(pixt, &w, &h, NULL);
|
| 94 |
+
scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
|
| 95 |
+
fname = NULL;
|
| 96 |
+
if (d == 1) {
|
| 97 |
+
fname = genPathname("/tmp", "junk_split_image.tif");
|
| 98 |
+
pixWrite(fname, pixt, IFF_TIFF_G4);
|
| 99 |
+
if (i == 0) {
|
| 100 |
+
convertG4ToPS(fname, psfile, "w", 0, 0, 300,
|
| 101 |
+
scale, 1, FALSE, TRUE);
|
| 102 |
+
} else {
|
| 103 |
+
convertG4ToPS(fname, psfile, "a", 0, 0, 300,
|
| 104 |
+
scale, 1, FALSE, TRUE);
|
| 105 |
+
}
|
| 106 |
+
} else {
|
| 107 |
+
fname = genPathname("/tmp", "junk_split_image.jpg");
|
| 108 |
+
pixWrite(fname, pixt, IFF_JFIF_JPEG);
|
| 109 |
+
if (i == 0) {
|
| 110 |
+
convertJpegToPS(fname, psfile, "w", 0, 0, 300,
|
| 111 |
+
scale, 1, TRUE);
|
| 112 |
+
} else {
|
| 113 |
+
convertJpegToPS(fname, psfile, "a", 0, 0, 300,
|
| 114 |
+
scale, 1, TRUE);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
lept_free(fname);
|
| 118 |
+
pixDestroy(&pixt);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
sprintf(buffer, "ps2pdf %s %s", psfile, fileout);
|
| 122 |
+
ignore = system(buffer); /* ps2pdf */
|
| 123 |
+
|
| 124 |
+
pixaDestroy(&pixa);
|
| 125 |
+
pixDestroy(&pixr);
|
| 126 |
+
pixDestroy(&pixs);
|
| 127 |
+
return 0;
|
| 128 |
+
}
|
| 129 |
+
|
pool/shard007/C/0124339_wb_next_pwent.c
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Unix SMB/CIFS implementation.
|
| 3 |
+
async next_pwent
|
| 4 |
+
Copyright (C) Volker Lendecke 2009
|
| 5 |
+
|
| 6 |
+
This program is free software; you can redistribute it and/or modify
|
| 7 |
+
it under the terms of the GNU General Public License as published by
|
| 8 |
+
the Free Software Foundation; either version 3 of the License, or
|
| 9 |
+
(at your option) any later version.
|
| 10 |
+
|
| 11 |
+
This program is distributed in the hope that it will be useful,
|
| 12 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
GNU General Public License for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU General Public License
|
| 17 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "includes.h"
|
| 21 |
+
#include "winbindd.h"
|
| 22 |
+
#include "librpc/gen_ndr/ndr_wbint_c.h"
|
| 23 |
+
#include "passdb/machine_sid.h"
|
| 24 |
+
|
| 25 |
+
struct wb_next_pwent_state {
|
| 26 |
+
struct tevent_context *ev;
|
| 27 |
+
struct getpwent_state *gstate;
|
| 28 |
+
struct winbindd_pw *pw;
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
static void wb_next_pwent_fetch_done(struct tevent_req *subreq);
|
| 32 |
+
static void wb_next_pwent_fill_done(struct tevent_req *subreq);
|
| 33 |
+
|
| 34 |
+
static struct winbindd_domain *wb_next_find_domain(struct winbindd_domain *domain)
|
| 35 |
+
{
|
| 36 |
+
if (domain == NULL) {
|
| 37 |
+
domain = domain_list();
|
| 38 |
+
} else {
|
| 39 |
+
domain = domain->next;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if ((domain != NULL)
|
| 43 |
+
&& sid_check_is_our_sam(&domain->sid)) {
|
| 44 |
+
domain = domain->next;
|
| 45 |
+
}
|
| 46 |
+
return domain;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
struct tevent_req *wb_next_pwent_send(TALLOC_CTX *mem_ctx,
|
| 50 |
+
struct tevent_context *ev,
|
| 51 |
+
struct getpwent_state *gstate,
|
| 52 |
+
struct winbindd_pw *pw)
|
| 53 |
+
{
|
| 54 |
+
struct tevent_req *req, *subreq;
|
| 55 |
+
struct wb_next_pwent_state *state;
|
| 56 |
+
|
| 57 |
+
req = tevent_req_create(mem_ctx, &state, struct wb_next_pwent_state);
|
| 58 |
+
if (req == NULL) {
|
| 59 |
+
return NULL;
|
| 60 |
+
}
|
| 61 |
+
state->ev = ev;
|
| 62 |
+
state->gstate = gstate;
|
| 63 |
+
state->pw = pw;
|
| 64 |
+
|
| 65 |
+
if (state->gstate->next_user >= state->gstate->num_users) {
|
| 66 |
+
TALLOC_FREE(state->gstate->users);
|
| 67 |
+
|
| 68 |
+
state->gstate->domain = wb_next_find_domain(state->gstate->domain);
|
| 69 |
+
if (state->gstate->domain == NULL) {
|
| 70 |
+
tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
|
| 71 |
+
return tevent_req_post(req, ev);
|
| 72 |
+
}
|
| 73 |
+
subreq = wb_query_user_list_send(state, state->ev,
|
| 74 |
+
state->gstate->domain);
|
| 75 |
+
if (tevent_req_nomem(subreq, req)) {
|
| 76 |
+
return tevent_req_post(req, ev);
|
| 77 |
+
}
|
| 78 |
+
tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
|
| 79 |
+
return req;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
subreq = wb_fill_pwent_send(
|
| 83 |
+
state, state->ev,
|
| 84 |
+
&state->gstate->users[state->gstate->next_user],
|
| 85 |
+
state->pw);
|
| 86 |
+
if (tevent_req_nomem(subreq, req)) {
|
| 87 |
+
return tevent_req_post(req, ev);
|
| 88 |
+
}
|
| 89 |
+
tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
|
| 90 |
+
return req;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
static void wb_next_pwent_fetch_done(struct tevent_req *subreq)
|
| 94 |
+
{
|
| 95 |
+
struct tevent_req *req = tevent_req_callback_data(
|
| 96 |
+
subreq, struct tevent_req);
|
| 97 |
+
struct wb_next_pwent_state *state = tevent_req_data(
|
| 98 |
+
req, struct wb_next_pwent_state);
|
| 99 |
+
NTSTATUS status;
|
| 100 |
+
|
| 101 |
+
status = wb_query_user_list_recv(subreq, state->gstate,
|
| 102 |
+
&state->gstate->num_users,
|
| 103 |
+
&state->gstate->users);
|
| 104 |
+
TALLOC_FREE(subreq);
|
| 105 |
+
if (!NT_STATUS_IS_OK(status)) {
|
| 106 |
+
/* Ignore errors here, just log it */
|
| 107 |
+
DEBUG(10, ("query_user_list for domain %s returned %s\n",
|
| 108 |
+
state->gstate->domain->name,
|
| 109 |
+
nt_errstr(status)));
|
| 110 |
+
state->gstate->num_users = 0;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
if (state->gstate->num_users == 0) {
|
| 114 |
+
state->gstate->domain = state->gstate->domain->next;
|
| 115 |
+
|
| 116 |
+
if ((state->gstate->domain != NULL)
|
| 117 |
+
&& sid_check_is_our_sam(&state->gstate->domain->sid)) {
|
| 118 |
+
state->gstate->domain = state->gstate->domain->next;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if (state->gstate->domain == NULL) {
|
| 122 |
+
tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
|
| 123 |
+
return;
|
| 124 |
+
}
|
| 125 |
+
subreq = wb_query_user_list_send(state, state->ev,
|
| 126 |
+
state->gstate->domain);
|
| 127 |
+
if (tevent_req_nomem(subreq, req)) {
|
| 128 |
+
return;
|
| 129 |
+
}
|
| 130 |
+
tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
|
| 131 |
+
return;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
state->gstate->next_user = 0;
|
| 135 |
+
|
| 136 |
+
subreq = wb_fill_pwent_send(
|
| 137 |
+
state, state->ev,
|
| 138 |
+
&state->gstate->users[state->gstate->next_user],
|
| 139 |
+
state->pw);
|
| 140 |
+
if (tevent_req_nomem(subreq, req)) {
|
| 141 |
+
return;
|
| 142 |
+
}
|
| 143 |
+
tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
static void wb_next_pwent_fill_done(struct tevent_req *subreq)
|
| 147 |
+
{
|
| 148 |
+
struct tevent_req *req = tevent_req_callback_data(
|
| 149 |
+
subreq, struct tevent_req);
|
| 150 |
+
struct wb_next_pwent_state *state = tevent_req_data(
|
| 151 |
+
req, struct wb_next_pwent_state);
|
| 152 |
+
NTSTATUS status;
|
| 153 |
+
|
| 154 |
+
status = wb_fill_pwent_recv(subreq);
|
| 155 |
+
TALLOC_FREE(subreq);
|
| 156 |
+
/*
|
| 157 |
+
* When you try to enumerate users with 'getent passwd' and the user
|
| 158 |
+
* doesn't have a uid set we should just move on.
|
| 159 |
+
*/
|
| 160 |
+
if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
|
| 161 |
+
state->gstate->next_user += 1;
|
| 162 |
+
|
| 163 |
+
if (state->gstate->next_user >= state->gstate->num_users) {
|
| 164 |
+
TALLOC_FREE(state->gstate->users);
|
| 165 |
+
|
| 166 |
+
state->gstate->domain = wb_next_find_domain(state->gstate->domain);
|
| 167 |
+
if (state->gstate->domain == NULL) {
|
| 168 |
+
tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
|
| 169 |
+
return;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
subreq = wb_query_user_list_send(state, state->ev,
|
| 173 |
+
state->gstate->domain);
|
| 174 |
+
if (tevent_req_nomem(subreq, req)) {
|
| 175 |
+
return;
|
| 176 |
+
}
|
| 177 |
+
tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
|
| 178 |
+
return;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
subreq = wb_fill_pwent_send(state,
|
| 182 |
+
state->ev,
|
| 183 |
+
&state->gstate->users[state->gstate->next_user],
|
| 184 |
+
state->pw);
|
| 185 |
+
if (tevent_req_nomem(subreq, req)) {
|
| 186 |
+
return;
|
| 187 |
+
}
|
| 188 |
+
tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
|
| 189 |
+
|
| 190 |
+
return;
|
| 191 |
+
} else if (tevent_req_nterror(req, status)) {
|
| 192 |
+
return;
|
| 193 |
+
}
|
| 194 |
+
state->gstate->next_user += 1;
|
| 195 |
+
tevent_req_done(req);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
NTSTATUS wb_next_pwent_recv(struct tevent_req *req)
|
| 199 |
+
{
|
| 200 |
+
return tevent_req_simple_recv_ntstatus(req);
|
| 201 |
+
}
|
pool/shard007/C/0124341_nspr_timer.c
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* nspr_timer.c
|
| 3 |
+
*/
|
| 4 |
+
#include <nspr_timer.h>
|
| 5 |
+
|
| 6 |
+
volatile unsigned long nspr_current_msec;
|
| 7 |
+
// we just support little size timers
|
| 8 |
+
static nspr_event_timer_t *timer_list[TIMERS_SIZE];
|
| 9 |
+
static int ntimers = 0;
|
| 10 |
+
|
| 11 |
+
void nspr_time_update(void)
|
| 12 |
+
{
|
| 13 |
+
unsigned long sec, msec;
|
| 14 |
+
struct timeval tv;
|
| 15 |
+
|
| 16 |
+
nspr_gettimeofday(&tv);
|
| 17 |
+
sec = tv.tv_sec;
|
| 18 |
+
msec = tv.tv_usec / 1000;
|
| 19 |
+
|
| 20 |
+
nspr_current_msec = (unsigned long) sec * 1000 + msec;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void nspr_event_expire_timers(void)
|
| 24 |
+
{
|
| 25 |
+
int i;
|
| 26 |
+
nspr_event_timer_t *timer;
|
| 27 |
+
unsigned long delta;
|
| 28 |
+
|
| 29 |
+
for (i = 0; i < ntimers; i++) {
|
| 30 |
+
timer = timer_list[i];
|
| 31 |
+
delta = nspr_current_msec - timer->delta;
|
| 32 |
+
if (delta > timer->timer) {
|
| 33 |
+
timer->handler(timer);
|
| 34 |
+
timer->delta = nspr_current_msec;
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
unsigned long nspr_event_find_timer(void)
|
| 40 |
+
{
|
| 41 |
+
int i, j;
|
| 42 |
+
unsigned long deltas[TIMERS_SIZE];
|
| 43 |
+
unsigned long delta;
|
| 44 |
+
nspr_event_timer_t *timer;
|
| 45 |
+
|
| 46 |
+
for (i = 0, j = 0; i < ntimers; i++) {
|
| 47 |
+
timer = timer_list[i];
|
| 48 |
+
delta = nspr_current_msec - timer->delta;
|
| 49 |
+
if (delta < timer->timer) {
|
| 50 |
+
deltas[j++] = delta;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// get the latest delta time
|
| 55 |
+
if (j > 0) {
|
| 56 |
+
delta = 0;
|
| 57 |
+
for (i = 0; i < j; i++) {
|
| 58 |
+
if (delta < deltas[i]) {
|
| 59 |
+
delta = deltas[i];
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
else {
|
| 64 |
+
delta = NSPR_TIMER_INFINITE;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
return delta;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void nspr_event_add_timer(nspr_event_timer_t *timer)
|
| 71 |
+
{
|
| 72 |
+
nspr_time_update();
|
| 73 |
+
timer->delta = nspr_current_msec;
|
| 74 |
+
timer_list[ntimers] = timer;
|
| 75 |
+
timer->index = ntimers;
|
| 76 |
+
ntimers++;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
void nspr_event_del_timer(nspr_event_timer_t *timer)
|
| 80 |
+
{
|
| 81 |
+
nspr_event_timer_t *t;
|
| 82 |
+
if (timer->index == NSPR_TIMER_INVALID_INDEX)
|
| 83 |
+
return;
|
| 84 |
+
|
| 85 |
+
if (timer->index < --ntimers) {
|
| 86 |
+
t = timer_list[ntimers];
|
| 87 |
+
timer_list[timer->index] = t;
|
| 88 |
+
t->index = timer->index;
|
| 89 |
+
}
|
| 90 |
+
timer->index = NSPR_TIMER_INVALID_INDEX;
|
| 91 |
+
}
|
pool/shard007/C/0124350_ext-toolchain-wrapper.c
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Buildroot wrapper for external toolchains. This simply executes the real
|
| 3 |
+
* toolchain with a number of arguments (sysroot/arch/..) hardcoded,
|
| 4 |
+
* to ensure the external toolchain uses the correct configuration.
|
| 5 |
+
* The hardcoded path arguments are defined relative to the actual location
|
| 6 |
+
* of the binary.
|
| 7 |
+
*
|
| 8 |
+
* (C) 2011 Peter Korsgaard <jacmet@sunsite.dk>
|
| 9 |
+
* (C) 2011 Daniel Nyström <daniel.nystrom@timeterminal.se>
|
| 10 |
+
* (C) 2012 Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
|
| 11 |
+
* (C) 2013 Spenser Gilliland <spenser@gillilanding.com>
|
| 12 |
+
*
|
| 13 |
+
* This file is licensed under the terms of the GNU General Public License
|
| 14 |
+
* version 2. This program is licensed "as is" without any warranty of any
|
| 15 |
+
* kind, whether express or implied.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include <stdio.h>
|
| 19 |
+
#include <string.h>
|
| 20 |
+
#include <limits.h>
|
| 21 |
+
#include <unistd.h>
|
| 22 |
+
#include <stdlib.h>
|
| 23 |
+
|
| 24 |
+
static char path[PATH_MAX];
|
| 25 |
+
static char sysroot[PATH_MAX];
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* GCC errors out with certain combinations of arguments (examples are
|
| 29 |
+
* -mabi-float={hard|soft} and -m{little|big}-endian), so we have to ensure
|
| 30 |
+
* that we only pass the predefined one to the real compiler if the inverse
|
| 31 |
+
* option isn't in the argument list.
|
| 32 |
+
* This specifies the worst case number of extra arguments we might pass
|
| 33 |
+
*/
|
| 34 |
+
#define EXCLUSIVE_ARGS 1
|
| 35 |
+
|
| 36 |
+
static char *predef_args[] = {
|
| 37 |
+
path,
|
| 38 |
+
"--sysroot", sysroot,
|
| 39 |
+
#ifdef BR_ARCH
|
| 40 |
+
"-march=" BR_ARCH,
|
| 41 |
+
#endif /* BR_ARCH */
|
| 42 |
+
#ifdef BR_TUNE
|
| 43 |
+
"-mtune=" BR_TUNE,
|
| 44 |
+
#endif /* BR_TUNE */
|
| 45 |
+
#ifdef BR_CPU
|
| 46 |
+
"-mcpu=" BR_CPU,
|
| 47 |
+
#endif
|
| 48 |
+
#ifdef BR_ABI
|
| 49 |
+
"-mabi=" BR_ABI,
|
| 50 |
+
#endif
|
| 51 |
+
#ifdef BR_FPU
|
| 52 |
+
"-mfpu=" BR_FPU,
|
| 53 |
+
#endif
|
| 54 |
+
#ifdef BR_SOFTFLOAT
|
| 55 |
+
"-msoft-float",
|
| 56 |
+
#endif /* BR_SOFTFLOAT */
|
| 57 |
+
#ifdef BR_MODE
|
| 58 |
+
"-m" BR_MODE,
|
| 59 |
+
#endif
|
| 60 |
+
#ifdef BR_64
|
| 61 |
+
"-m64",
|
| 62 |
+
#endif
|
| 63 |
+
#ifdef BR_ADDITIONAL_CFLAGS
|
| 64 |
+
BR_ADDITIONAL_CFLAGS
|
| 65 |
+
#endif
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
int main(int argc, char **argv)
|
| 69 |
+
{
|
| 70 |
+
char **args, **cur;
|
| 71 |
+
char *relbasedir, *absbasedir;
|
| 72 |
+
char *progpath = argv[0];
|
| 73 |
+
char *basename;
|
| 74 |
+
int ret, i, count = 0;
|
| 75 |
+
|
| 76 |
+
/* Calculate the relative paths */
|
| 77 |
+
basename = strrchr(progpath, '/');
|
| 78 |
+
if (basename) {
|
| 79 |
+
*basename = '\0';
|
| 80 |
+
basename++;
|
| 81 |
+
relbasedir = malloc(strlen(progpath) + 7);
|
| 82 |
+
if (relbasedir == NULL) {
|
| 83 |
+
perror(__FILE__ ": malloc");
|
| 84 |
+
return 2;
|
| 85 |
+
}
|
| 86 |
+
sprintf(relbasedir, "%s/../..", argv[0]);
|
| 87 |
+
absbasedir = realpath(relbasedir, NULL);
|
| 88 |
+
} else {
|
| 89 |
+
basename = progpath;
|
| 90 |
+
absbasedir = malloc(PATH_MAX + 1);
|
| 91 |
+
ret = readlink("/proc/self/exe", absbasedir, PATH_MAX);
|
| 92 |
+
if (ret < 0) {
|
| 93 |
+
perror(__FILE__ ": readlink");
|
| 94 |
+
return 2;
|
| 95 |
+
}
|
| 96 |
+
absbasedir[ret] = '\0';
|
| 97 |
+
for (i = ret; i > 0; i--) {
|
| 98 |
+
if (absbasedir[i] == '/') {
|
| 99 |
+
absbasedir[i] = '\0';
|
| 100 |
+
if (++count == 3)
|
| 101 |
+
break;
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
if (absbasedir == NULL) {
|
| 106 |
+
perror(__FILE__ ": realpath");
|
| 107 |
+
return 2;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/* Fill in the relative paths */
|
| 111 |
+
#ifdef BR_CROSS_PATH_REL
|
| 112 |
+
ret = snprintf(path, sizeof(path), "%s/" BR_CROSS_PATH_REL "/%s", absbasedir, basename);
|
| 113 |
+
#else /* BR_CROSS_PATH_ABS */
|
| 114 |
+
ret = snprintf(path, sizeof(path), BR_CROSS_PATH_ABS "/%s", basename);
|
| 115 |
+
#endif
|
| 116 |
+
if (ret >= sizeof(path)) {
|
| 117 |
+
perror(__FILE__ ": overflow");
|
| 118 |
+
return 3;
|
| 119 |
+
}
|
| 120 |
+
ret = snprintf(sysroot, sizeof(sysroot), "%s/" BR_SYSROOT, absbasedir);
|
| 121 |
+
if (ret >= sizeof(sysroot)) {
|
| 122 |
+
perror(__FILE__ ": overflow");
|
| 123 |
+
return 3;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
cur = args = malloc(sizeof(predef_args) +
|
| 127 |
+
(sizeof(char *) * (argc + EXCLUSIVE_ARGS)));
|
| 128 |
+
if (args == NULL) {
|
| 129 |
+
perror(__FILE__ ": malloc");
|
| 130 |
+
return 2;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/* start with predefined args */
|
| 134 |
+
memcpy(cur, predef_args, sizeof(predef_args));
|
| 135 |
+
cur += sizeof(predef_args) / sizeof(predef_args[0]);
|
| 136 |
+
|
| 137 |
+
#ifdef BR_FLOAT_ABI
|
| 138 |
+
/* add float abi if not overridden in args */
|
| 139 |
+
for (i = 1; i < argc; i++) {
|
| 140 |
+
if (!strncmp(argv[i], "-mfloat-abi=", strlen("-mfloat-abi=")) ||
|
| 141 |
+
!strcmp(argv[i], "-msoft-float") ||
|
| 142 |
+
!strcmp(argv[i], "-mhard-float"))
|
| 143 |
+
break;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if (i == argc)
|
| 147 |
+
*cur++ = "-mfloat-abi=" BR_FLOAT_ABI;
|
| 148 |
+
#endif
|
| 149 |
+
|
| 150 |
+
/* append forward args */
|
| 151 |
+
memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));
|
| 152 |
+
cur += argc - 1;
|
| 153 |
+
|
| 154 |
+
/* finish with NULL termination */
|
| 155 |
+
*cur = NULL;
|
| 156 |
+
|
| 157 |
+
if (getenv("BR_DEBUG_WRAPPER")) {
|
| 158 |
+
fprintf(stderr, "Executing");
|
| 159 |
+
|
| 160 |
+
for (i = 0; args[i]; i++)
|
| 161 |
+
fprintf(stderr, " %s", args[i]);
|
| 162 |
+
|
| 163 |
+
fprintf(stderr, "\n");
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
if (execv(path, args))
|
| 167 |
+
perror(path);
|
| 168 |
+
|
| 169 |
+
free(args);
|
| 170 |
+
|
| 171 |
+
return 2;
|
| 172 |
+
}
|
pool/shard007/C/0124353_null_cipher.c
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* null_cipher.c
|
| 3 |
+
*
|
| 4 |
+
* A null cipher implementation. This cipher leaves the plaintext
|
| 5 |
+
* unchanged.
|
| 6 |
+
*
|
| 7 |
+
* David A. McGrew
|
| 8 |
+
* Cisco Systems, Inc.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*
|
| 12 |
+
*
|
| 13 |
+
* Copyright (c) 2001-2006,2013 Cisco Systems, Inc.
|
| 14 |
+
* All rights reserved.
|
| 15 |
+
*
|
| 16 |
+
* Redistribution and use in source and binary forms, with or without
|
| 17 |
+
* modification, are permitted provided that the following conditions
|
| 18 |
+
* are met:
|
| 19 |
+
*
|
| 20 |
+
* Redistributions of source code must retain the above copyright
|
| 21 |
+
* notice, this list of conditions and the following disclaimer.
|
| 22 |
+
*
|
| 23 |
+
* Redistributions in binary form must reproduce the above
|
| 24 |
+
* copyright notice, this list of conditions and the following
|
| 25 |
+
* disclaimer in the documentation and/or other materials provided
|
| 26 |
+
* with the distribution.
|
| 27 |
+
*
|
| 28 |
+
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
| 29 |
+
* contributors may be used to endorse or promote products derived
|
| 30 |
+
* from this software without specific prior written permission.
|
| 31 |
+
*
|
| 32 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 33 |
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 34 |
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 35 |
+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 36 |
+
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
| 37 |
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 38 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 39 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 40 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
| 41 |
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 42 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
| 43 |
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 44 |
+
*
|
| 45 |
+
*/
|
| 46 |
+
|
| 47 |
+
#ifdef HAVE_CONFIG_H
|
| 48 |
+
#include <config.h>
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
#include "datatypes.h"
|
| 52 |
+
#include "null_cipher.h"
|
| 53 |
+
#include "err.h" /* for srtp_debug */
|
| 54 |
+
#include "alloc.h"
|
| 55 |
+
|
| 56 |
+
/* the null_cipher uses the cipher debug module */
|
| 57 |
+
|
| 58 |
+
extern srtp_debug_module_t srtp_mod_cipher;
|
| 59 |
+
|
| 60 |
+
static srtp_err_status_t srtp_null_cipher_alloc (srtp_cipher_t **c, int key_len, int tlen)
|
| 61 |
+
{
|
| 62 |
+
extern const srtp_cipher_type_t srtp_null_cipher;
|
| 63 |
+
|
| 64 |
+
debug_print(srtp_mod_cipher,
|
| 65 |
+
"allocating cipher with key length %d", key_len);
|
| 66 |
+
|
| 67 |
+
/* allocate memory a cipher of type null_cipher */
|
| 68 |
+
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
| 69 |
+
if (*c == NULL) {
|
| 70 |
+
return srtp_err_status_alloc_fail;
|
| 71 |
+
}
|
| 72 |
+
memset(*c, 0x0, sizeof(srtp_cipher_t));
|
| 73 |
+
|
| 74 |
+
/* set pointers */
|
| 75 |
+
(*c)->algorithm = SRTP_NULL_CIPHER;
|
| 76 |
+
(*c)->type = &srtp_null_cipher;
|
| 77 |
+
(*c)->state = (void *) 0x1; /* The null cipher does not maintain state */
|
| 78 |
+
|
| 79 |
+
/* set key size */
|
| 80 |
+
(*c)->key_len = key_len;
|
| 81 |
+
|
| 82 |
+
return srtp_err_status_ok;
|
| 83 |
+
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
static srtp_err_status_t srtp_null_cipher_dealloc (srtp_cipher_t *c)
|
| 87 |
+
{
|
| 88 |
+
extern const srtp_cipher_type_t srtp_null_cipher;
|
| 89 |
+
|
| 90 |
+
/* zeroize entire state*/
|
| 91 |
+
octet_string_set_to_zero((uint8_t*)c, sizeof(srtp_cipher_t));
|
| 92 |
+
|
| 93 |
+
/* free memory of type null_cipher */
|
| 94 |
+
srtp_crypto_free(c);
|
| 95 |
+
|
| 96 |
+
return srtp_err_status_ok;
|
| 97 |
+
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
static srtp_err_status_t srtp_null_cipher_init (void *cv, const uint8_t *key)
|
| 101 |
+
{
|
| 102 |
+
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
| 103 |
+
|
| 104 |
+
debug_print(srtp_mod_cipher, "initializing null cipher", NULL);
|
| 105 |
+
|
| 106 |
+
return srtp_err_status_ok;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
static srtp_err_status_t srtp_null_cipher_set_iv (void *cv, uint8_t *iv, srtp_cipher_direction_t dir)
|
| 110 |
+
{
|
| 111 |
+
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
| 112 |
+
return srtp_err_status_ok;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
static srtp_err_status_t srtp_null_cipher_encrypt (void *cv,
|
| 116 |
+
unsigned char *buf, unsigned int *bytes_to_encr)
|
| 117 |
+
{
|
| 118 |
+
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
| 119 |
+
return srtp_err_status_ok;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
static const char srtp_null_cipher_description[] = "null cipher";
|
| 123 |
+
|
| 124 |
+
static const srtp_cipher_test_case_t srtp_null_cipher_test_0 = {
|
| 125 |
+
0, /* octets in key */
|
| 126 |
+
NULL, /* key */
|
| 127 |
+
0, /* packet index */
|
| 128 |
+
0, /* octets in plaintext */
|
| 129 |
+
NULL, /* plaintext */
|
| 130 |
+
0, /* octets in plaintext */
|
| 131 |
+
NULL, /* ciphertext */
|
| 132 |
+
0,
|
| 133 |
+
NULL,
|
| 134 |
+
0,
|
| 135 |
+
NULL /* pointer to next testcase */
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
/*
|
| 140 |
+
* note: the decrypt function is idential to the encrypt function
|
| 141 |
+
*/
|
| 142 |
+
|
| 143 |
+
const srtp_cipher_type_t srtp_null_cipher = {
|
| 144 |
+
srtp_null_cipher_alloc,
|
| 145 |
+
srtp_null_cipher_dealloc,
|
| 146 |
+
srtp_null_cipher_init,
|
| 147 |
+
0, /* set_aad */
|
| 148 |
+
srtp_null_cipher_encrypt,
|
| 149 |
+
srtp_null_cipher_encrypt,
|
| 150 |
+
srtp_null_cipher_set_iv,
|
| 151 |
+
0, /* get_tag */
|
| 152 |
+
srtp_null_cipher_description,
|
| 153 |
+
&srtp_null_cipher_test_0,
|
| 154 |
+
SRTP_NULL_CIPHER
|
| 155 |
+
};
|
| 156 |
+
|
pool/shard007/C/0124355_bsmesh10.c
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/* ///////////////////////////////////////////////////////////////////////// */
|
| 3 |
+
/* This file is a part of the BSTools package */
|
| 4 |
+
/* written by Przemyslaw Kiciak */
|
| 5 |
+
/* ///////////////////////////////////////////////////////////////////////// */
|
| 6 |
+
/* (C) Copyright by Przemyslaw Kiciak, 2010, 2012 */
|
| 7 |
+
/* this package is distributed under the terms of the */
|
| 8 |
+
/* Lesser GNU Public License, see the file COPYING.LIB */
|
| 9 |
+
/* ///////////////////////////////////////////////////////////////////////// */
|
| 10 |
+
|
| 11 |
+
#include <stdio.h>
|
| 12 |
+
#include <stdlib.h>
|
| 13 |
+
#include <string.h>
|
| 14 |
+
|
| 15 |
+
#include "pkvaria.h"
|
| 16 |
+
#include "pknum.h"
|
| 17 |
+
#include "bsmesh.h"
|
| 18 |
+
#include "bsmprivate.h"
|
| 19 |
+
|
| 20 |
+
/* ////////////////////////////////////////////////////////////////////////// */
|
| 21 |
+
boolean bsm_RemoveFacetNum ( int inv, BSMvertex *imv, int *imvhei,
|
| 22 |
+
int inhe, BSMhalfedge *imhe,
|
| 23 |
+
int infac, BSMfacet *imfac, int *imfhei,
|
| 24 |
+
int nfr,
|
| 25 |
+
int *onv, int *onhe, int *onfac )
|
| 26 |
+
{
|
| 27 |
+
void *sp;
|
| 28 |
+
int ei, eb, vi, vb;
|
| 29 |
+
int d, fhe, i, k, en, v0, fve, v0d;
|
| 30 |
+
char *vtag, *ftag;
|
| 31 |
+
|
| 32 |
+
sp = pkv_GetScratchMemTop ();
|
| 33 |
+
/* compute the numbers of mesh vertices, halfedges and facets */
|
| 34 |
+
/* after facet removal */
|
| 35 |
+
if ( nfr < 0 || nfr >= infac ) { /* invalid facet number */
|
| 36 |
+
*onv = *onhe = *onfac = -1;
|
| 37 |
+
return false;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
vtag = pkv_GetScratchMem ( inv );
|
| 41 |
+
ftag = pkv_GetScratchMem ( infac );
|
| 42 |
+
if ( vtag && ftag ) {
|
| 43 |
+
bsm_TagMesh ( inv, imv, imvhei, inhe, imhe, infac, imfac, imfhei,
|
| 44 |
+
vtag, ftag, &vi, &vb, &ei, &eb );
|
| 45 |
+
/* the number of facets is decreased by one */
|
| 46 |
+
*onfac = infac - 1;
|
| 47 |
+
/* the number of halfedges is decreased by the number of facet edges */
|
| 48 |
+
d = imfac[nfr].degree;
|
| 49 |
+
*onhe = inhe - d;
|
| 50 |
+
/* the number of vertices is decreased by the number of facet */
|
| 51 |
+
/* vertices of degree 1 and increased by the number of vertices */
|
| 52 |
+
/* to be split */
|
| 53 |
+
fhe = imfac[nfr].firsthalfedge;
|
| 54 |
+
for ( i = k = 0; i < d; i++ ) {
|
| 55 |
+
en = imfhei[fhe+i];
|
| 56 |
+
v0 = imhe[en].v0;
|
| 57 |
+
if ( imv[v0].degree == 1 )
|
| 58 |
+
k ++;
|
| 59 |
+
else if ( vtag[v0] ) {
|
| 60 |
+
v0d = imv[v0].degree;
|
| 61 |
+
fve = imv[v0].firsthalfedge;
|
| 62 |
+
if ( en != imvhei[fve] && en != imvhei[fve+v0d-1] )
|
| 63 |
+
k --; /* the vertex has to be split */
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
*onv = inv - k;
|
| 67 |
+
pkv_SetScratchMemTop ( sp );
|
| 68 |
+
return true;
|
| 69 |
+
}
|
| 70 |
+
else {
|
| 71 |
+
pkv_SetScratchMemTop ( sp );
|
| 72 |
+
return false;
|
| 73 |
+
}
|
| 74 |
+
} /*bsm_RemoveFacetNum*/
|
| 75 |
+
|