repo_name
stringlengths
5
122
path
stringlengths
3
232
text
stringlengths
6
1.05M
thomas-sivilay/textstyle
TextStyle/Thot/Sources/Thot.h
<gh_stars>0 // // Thot.h // Thot // // Created by <NAME> on 8/16/17. // Copyright © 2017 <NAME>. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for Thot. FOUNDATION_EXPORT double ThotVersionNumber; //! Project version string for Thot. FOUNDATION_EXPORT const unsigned char ThotVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <Thot/PublicHeader.h>
SANDEEPREDDY56712/OELP_6thSem
btdriver.c
<gh_stars>0 #include "uart.h" #include "string.h" #include "pinmux.h" #include "gpio.h" #define HC05_UART uart_instance[1] #define STR_SIZE 15 int write_to_hc05(char *data) { while (*data != '\0') { write_uart_character(HC05_UART, *data); data++; } write_uart_character(HC05_UART,'\r'); write_uart_character(HC05_UART,'\n'); } int write_to_hc05_obd2(char *data) { while (*data != '\0') { write_uart_character(HC05_UART, *data); data++; } write_uart_character(HC05_UART,'\r'); } int write_enter_to_hc05(){ write_uart_character(HC05_UART,'\r'); write_uart_character(HC05_UART,'\n'); } int read_from_hc05_setup(char *data) { int ch; char *str = data; char *test = data; for(int i=0;i<198;i++) { read_uart_character(HC05_UART,&ch); *str = ch; str++; *str = '\0'; if(strstr(test,"OK") != NULL) { printf("read from hc05 %s\n",test); return 0; } if(strstr(test,"ERROR") != NULL) { printf("read from hc05 %s\n",test); return 0; } if(strstr(test,">") != NULL) { printf("read from hc05 %s\n",test); return 0; } if(strstr(test,"RECV") != NULL) { printf("read from hc05 %s\n",test); return 0; } if(strstr(test,"IP") != NULL) { printf("read from hc05 %s\n",test); return 0; } } *str = '\0'; return ; } int read_from_hc05(char *data) { int ch; char *str = data; char *test = data; for(int i=0;i<100;i++) { read_uart_character(HC05_UART,&ch); *str = ch; str++; *str = '\0'; if((char)ch == '\n' || *(str-1) == '>') { //printf("received str = %s\n", test); //printf("Read uart char \ n = %d\n", (char)ch); return 0; } } *str = '\0'; return ; } void setup_hc05(){ char data[200]; write_word(GPIO_DIRECTION_CNTRL_REG, 0x4); write_word(GPIO_DATA_REG, 0x4); printf(" Verifying AT status:\n"); write_to_hc05("AT"); delay(3); read_from_hc05_setup(data); printf(" Delete all autheticted devices AT RMAAD:\n"); write_to_hc05("AT+RMAAD"); delay(3); read_from_hc05_setup(data); printf(" Setting up AT ROLE\n"); write_to_hc05("AT+ROLE=1"); delay(3); read_from_hc05_setup(data); printf(" Checking AT ROLE\n"); write_to_hc05("AT+ROLE?"); delay(3); read_from_hc05_setup(data); printf(" Setting up AT CMODE\n"); write_to_hc05("AT+CMODE=0"); delay(3); read_from_hc05_setup(data); // printf(" setting AT PAIR\n"); // write_to_hc05("AT+PAIR=1111,22,344405, 9"); // delay(50); // read_from_hc05(data); printf(" sending AT BIND\n"); write_to_hc05("AT+BIND=DOE6,5D,CF1D71"); delay(5); read_from_hc05_setup(data); printf(" setting AT LINK\n"); write_to_hc05("AT+LINK=DOE6,5D,CF1D71"); delay(30); read_from_hc05_setup(data); // printf(" write AT+LINK\n"); // write_to_hc05("AT+LINK=BT_ADRS"); // delay(1); // read_from_hc05(data); write_word(GPIO_DATA_REG, 0x0); read_from_hc05(data); } void get_OBD_data(char* receiveData){ char data[10]; for (int i = 0; i < 100; i++){ // Getting engine RPM write_to_hc05("010C"); delay(2); read_from_hc05(receiveData + i*22 ); // Getting vehicle speed write_to_hc05("010D"); delay(2); read_from_hc05(receiveData + i*22 + 1*STR_SIZE); // Getting throttle position write_to_hc05("0111"); delay(2); read_from_hc05(receiveData + i*22 + 2*STR_SIZE); // Getting engine load write_to_hc05("0104"); delay(2); read_from_hc05(receiveData + i*22 + 3*STR_SIZE); // Getting coolant temp write_to_hc05("0105"); delay(2); read_from_hc05(receiveData + i*22 + 4*STR_SIZE); // Getting long term fuel trim bank 1 write_to_hc05("0107"); delay(2); read_from_hc05(receiveData + i*22 + 5*STR_SIZE); // Getting short term fuel trim bank 1 write_to_hc05("0106"); delay(2); read_from_hc05(receiveData + i*22 + 6*STR_SIZE); // Getting intake manifold pressure write_to_hc05("010B"); delay(2); read_from_hc05(receiveData + i*22 + 7*STR_SIZE); // Getting fuel tank level write_to_hc05("012F"); delay(2); read_from_hc05(receiveData + i*22 + 8*STR_SIZE); // Getting absolute throttle position write_to_hc05("0147"); delay(2); read_from_hc05(receiveData + i*22 + 9*STR_SIZE); // Getting pedal position D write_to_hc05("0149"); delay(2); read_from_hc05(receiveData + i*22 + 10*STR_SIZE); // Getting pedal position E write_to_hc05("014A"); delay(2); read_from_hc05(receiveData + i*22 + 11*STR_SIZE); // Getting commanded throttle actuator's value write_to_hc05("014C"); delay(2); read_from_hc05(receiveData + i*22 + 12*STR_SIZE); // Getting commanded fuel-air equi. ratio write_to_hc05("0144"); delay(2); read_from_hc05(receiveData + i*22 + 13*STR_SIZE); // Getting absolute barometric position write_to_hc05("0133"); delay(2); read_from_hc05(receiveData + i*22 + 14*STR_SIZE); // Getting relative throttle position write_to_hc05("0145"); delay(2); read_from_hc05(receiveData + i*22 + 15*STR_SIZE); // Getting intake air temperature write_to_hc05("010F"); delay(2); read_from_hc05(receiveData + i*22 + 16*STR_SIZE); // Getting timing advance write_to_hc05("010E"); delay(10); read_from_hc05(receiveData + i*22 + 17*STR_SIZE); // Getting Catalyst temperature from bank 1, sensor 1 write_to_hc05("013C"); delay(2); read_from_hc05(receiveData + i*22 + 18*STR_SIZE); // Getting Catalyst temperature from bank 1, sensor 2 write_to_hc05("013D"); delay(2); read_from_hc05(receiveData + i*22 + 19*STR_SIZE); // Getting Control module voltage write_to_hc05("0142"); delay(2); read_from_hc05(receiveData + i*22 + 20*STR_SIZE); // Getting Commanded evaporative purge write_to_hc05("012E"); delay(2); read_from_hc05(receiveData + i*22 + 21*STR_SIZE); // // Getting run-time with MIL on // write_to_hc05("014D"); // delay(2); // read_from_hc05(receiveData + i*22 + 22); // // Getting run-time after clearing trouble codes // write_to_hc05("014E"); // delay(2); // read_from_hc05(receiveData + i*22 + 23); // // Getting distance traveled with MIL on // write_to_hc05("0121"); // delay(2); // read_from_hc05(receiveData + i*22 + 24); // // Getting warm ups since trouble codes cleared // write_to_hc05("0130"); // delay(2); // read_from_hc05(receiveData + i*22 + 25); } // *(receiveData + (i+1)*22)='\0'; delay(10); } void main() { write_word(GPIO_DIRECTION_CNTRL_REG, 0x4); write_word(GPIO_DATA_REG, 0x4); int i=0; int baudrate = 9600; //int baudrate = 115200; int transmit_count = 0; printf("\n setting PIN MUX config to 2 .... \n"); *pinmux_config_reg = 0x5; printf("\n set PIN MUX config to 2 .... \n"); set_baud_rate(HC05_UART,baudrate); printf("\n Baud rate set to %d \n",baudrate); printf("\n Waiting to HC05 to initialize \n"); delay(3); setup_hc05(); delay(3); char receiveData[100][22][STR_SIZE]; get_OBD_data(*receiveData); for(int j=0; j<100; j++){ for(int k=0; k<22; k++){ printf("%s ", receiveData[j][k]); } printf("\n"); } int ch; printf("Entering while loop\n"); while(1){ char data_read[200]; // read_from_hc05(data_read); // printf("%s", data_read); write_to_hc05("Hello World !"); delay(10); } }
iIias/mcas
examples/personalities/cpp_pm_sort/src/cpp_pm_sort_plugin.h
/* * Description : PM sorting ADO * Authors : <NAME>, <NAME>, <NAME> * Authors email: <EMAIL>, <EMAIL>, <EMAIL> * License : Apache License, Version 2.0 * Done as part of the Workshop on Search Data Structures for High-Performance Databases * at Tel-Aviv University. */ #ifndef __CPP_PM_SORT_PLUGIN_H__ #define __CPP_PM_SORT_PLUGIN_H__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" #include <common/cycles.h> #include <api/ado_itf.h> #include <cpp_pm_sort_proto_generated.h> #include <libpmem.h> #include <string.h> #include <list> #include <common/utils.h> #define PM_SORT_CHUNK_SIZE MiB(128ULL) #define PM_SORT_RECORD_ARRAY_SIZE(chunk_level) (1280000ULL<<(chunk_level)) /**128 MB chunck, each record is 100 B*/ #define PM_SORT_NUMBER_OF_CHUNKS 512ULL /** * A logging record * first 10 bytes are the key for sorting purposes */ struct ADO_cpp_pm_sort_plugin_record { uint8_t timestamp[5]; uint8_t datacenter_id[2]; uint8_t operation_type[3]; uint8_t src_address[4]; uint8_t dst_address[4]; uint8_t private_data[82]; }; #define PM_SORT_RECORD_SIZE sizeof(ADO_cpp_pm_sort_plugin_record) enum pm_sorting_state_t { PM_SORT_IDLE, PM_SORT_CHUNK, PM_SORT_MERGE, PM_SORT_SPLIT_RESULT, }; /** * PM sort superblock */ struct ADO_cpp_pm_sort_plugin_superblock { bool valid; uint64_t timestamp; enum pm_sorting_state_t state; uint64_t last_modified_index; /* only relevant if in state PM_SORT_MERGE*/ uint64_t merge_phase; }; #define PM_SORT_SUPERBLOCK_SIZE (sizeof(struct ADO_cpp_pm_sort_plugin_superblock)) #define PM_SORT_NR_SUPERBLOCKS (2) #define PM_SORT_SUPERBLOCKS_SIZE (PM_SORT_NR_SUPERBLOCKS * PM_SORT_SUPERBLOCK_SIZE) #define POOL_SIZE 3*((PM_SORT_NUMBER_OF_CHUNKS+1) * PM_SORT_CHUNK_SIZE) + PM_SORT_SUPERBLOCKS_SIZE class ADO_cpp_pm_sort_plugin : public component::IADO_plugin { private: static constexpr bool option_DEBUG = true; /** * Updates the superblocks to the new state via the following steps: * Foreach superblock by order do: * 1. Toggle the valid flag for the superblock and persist the state. * 2. Update the metadata of the superblock and persist the state. * 3. Toggle back the valid flag for the superblock and persist that state. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param enum pm_sorting_state_t the new state to update to. * @param uint64_t the last chunk index modified by the algorithm, used for recovery. * @param uint64_t the last persistent merge phase, used for recovery. */ void update_superblock(ADO_cpp_pm_sort_plugin_superblock *sb, enum pm_sorting_state_t state, uint64_t last_modified_index, uint64_t merge_phase); /** * Swap portion of the quicksort, swaps two given records. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param ADO_cpp_pm_sort_plugin_record *points to the current chunk. * @param int index of the first record to swap. * @param int index of the second record to swap. */ void swap(ADO_cpp_pm_sort_plugin_superblock *sb, ADO_cpp_pm_sort_plugin_record *records, int i, int j); /** * Comapres two records by their key (first 10 bytes). * @param ADO_cpp_pm_sort_plugin_record *points to the first record. * @param ADO_cpp_pm_sort_plugin_record *points to the second record. * @return 1 if rec1's key is smaller, otherwise 0. */ int is_smaller(ADO_cpp_pm_sort_plugin_record *rec1, ADO_cpp_pm_sort_plugin_record *rec2); /** * Partition portion of the quicksort algorthim, the pivot element * in each Partition phase is chosen according to the median of three * strategy, i.e, The median between the first, middle, and last record * in the given range. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param ADO_cpp_pm_sort_plugin_record *points to the chunks (array of records). * @param int start of the range to partition. * @param int end of the range to partition. * @return index of the pivot after partitioning the range. */ int partition(ADO_cpp_pm_sort_plugin_superblock *sb, ADO_cpp_pm_sort_plugin_record *chunk, int start, int end); /** * Recursive portion of the quicksort algorthim and the begining of it, * runs until `start >= end`. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param ADO_cpp_pm_sort_plugin_record *points to the chunks (array of records). * @param int start of the range to sort. * @param int end of the range to sort. */ void quicksort(ADO_cpp_pm_sort_plugin_superblock *sb, ADO_cpp_pm_sort_plugin_record *chunk, int start, int end); /** * Given a chunk X, create a new XSorted chunk and update the superblock accordingly * for the given task. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param ADO_cpp_pm_sort_plugin_record *points to the chunks (array of records). * @param Aconst std::string& the name of the chunk (if name is X, new chunk shall be XSorted). * @param uint64_t MCAS ADO work_key. * @param int task type, affects how the superblock is updated and where the new chunk is written to. * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map from names to chunks, used only * in tasks that use the RAM (tasks 1 & 2). */ void create_sorted_chunk(ADO_cpp_pm_sort_plugin_superblock *sb, ADO_cpp_pm_sort_plugin_record *chunk, const std::string& chunk_name, uint64_t work_key, int task = 3, std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map = nullptr); /** * Runs though the final data and verifies that it's sorted. * @param uint64_t MCAS ADO work_key. * @return true if the result is sorted, otherwise false. */ bool verify(uint64_t work_key); /** * Calculates the final merge phase level. * @return the final merge phase level. */ uint64_t get_final_merge_phase(); /** * Merge two sorted chunks. * @param ADO_cpp_pm_sort_plugin_record *points to the destination chunk. * @param ADO_cpp_pm_sort_plugin_record *points to the first source chunk. * @param ADO_cpp_pm_sort_plugin_record *points to the second source chunk. * @param uint64_t current merge phase (determines expected chunk sizes). */ void chunk_merge(ADO_cpp_pm_sort_plugin_record *dst_chunk, ADO_cpp_pm_sort_plugin_record *src_chunk_1, ADO_cpp_pm_sort_plugin_record *src_chunk_2, uint64_t merge_phase); /** * Iterates of the superblocks and returns the valid state. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param uint64_t the first valid superblock, NULL if non was found (should never happen). */ ADO_cpp_pm_sort_plugin_superblock * get_updated_superblock(ADO_cpp_pm_sort_plugin_superblock *sb); /** * Handles the sorting phase of the ADO, allocates dest chunks according to the task and * persists the output if needed. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param uint64_t MCAS ADO work_key. * @param uint64_t Chunk index to begin sorting from. * @param int task type, affects how the superblock is updated and where the new chunk is written to. * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map from names to chunks, used only * in tasks that use the RAM (tasks 1 & 2). * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t sort_chunks(ADO_cpp_pm_sort_plugin_superblock *sb, const uint64_t work_key, uint64_t chunk_index, int task = 3, std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map = nullptr); /** * Handles the merging phase of the ADO, runs through all merge levels and * updates the superblocks between phases if needed. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param uint64_t MCAS ADO work_key. * @param uint64_t Chunk index to begin merging from. * @param uint64_t Merge level to begin merging from. * @param int task type, affects how the superblock is updated and where the new chunks are written to. * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map from names to chunks, used only * in tasks that use the RAM (tasks 1 & 2). * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t merge(ADO_cpp_pm_sort_plugin_superblock *sb, const uint64_t work_key, uint64_t chunk_index, uint64_t start_merge_phase, int task = 3, std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map = nullptr); /** * Splits the final result chunk into many L0 sized chunks (in the same order as they * appear in the final chunk). * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param uint64_t MCAS ADO work_key. * @param uint64_t Chunk index to begin splitting to (not 0 during recovery). * @param int task type, affects how the superblock is updated and where the new chunks are written to. * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map from names to chunks, used only * in tasks that use the RAM (tasks 1 & 2). * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t split_result(ADO_cpp_pm_sort_plugin_superblock *sb, const uint64_t work_key, uint64_t chunk_index, int task = 3, std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map = nullptr); /** * Inits the ADO, should be the first thing called. * Reads the superblock and checks if recovery should be triggered, if not clears * the pools and rewrites the unsorted data to the PM. * @param uint64_t MCAS ADO work_key. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t init(const uint64_t work_key); /** * Loads the unsorted gensort chunks from storage to the PM. * @param uint64_t MCAS ADO work_key. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t load_data(const uint64_t work_key, ADO_cpp_pm_sort_plugin_superblock *sb); /** * Clears the pool from old data. * @param uint64_t MCAS ADO work_key. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t clear_pool(const uint64_t work_key); /** * Retrieves the max between two records in a given chunk * @param ADO_cpp_pm_sort_plugin_record *points to the chunk. * @param int index of the first record. * @param int index of the second record record. * @param int index of the maximal record of the two. */ int max_record(ADO_cpp_pm_sort_plugin_record *chunk, int a, int b); /** * Retrieves the min between two records in a given chunk * @param ADO_cpp_pm_sort_plugin_record *points to the chunk. * @param int index of the first record. * @param int index of the second record record. * @param int index of the minimal record of the two. */ int min_record(ADO_cpp_pm_sort_plugin_record *chunk, int a, int b); /** * Calculates the pivot for quicksort according to the median of three * strategy, i.e, The median between the first, middle, and last record * in the given range. * @param ADO_cpp_pm_sort_plugin_record *points to the chunk. * @param int begining of the range. * @param int end of the range. * @param int index of the pivot element. */ int get_pivot(ADO_cpp_pm_sort_plugin_record *chunk, int start, int end); /** * Loads chunks from PM to RAM. * @param uint64_t MCAS ADO work_key. * @param int chunk level to load. * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map to store the chunks. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t load_from_PM(const uint64_t work_key, int level, std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map); /** * Frees the RAM data map (load_from_PM output). * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map to free. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t free_map(std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map); /** * Delete from PM old key-value pairs from past phases, should only be called * after current phase has been properly persisted. * also used in crash recovery to return PM to a stable state. * @param uint64_t MCAS ADO work_key. * @param int target chunk level (older levels will be deleted). * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t stabilize_PM(const uint64_t work_key, int level); /** * Copies all chunks from RAM map to PM * @param uint64_t MCAS ADO work_key. * @param int chunk level in map. * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map of chunks. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t backup_to_PM(const uint64_t work_key, uint64_t level, std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map); /** * Task 2 specific function, writes final result from map, starting from chunk_index, and updates superblock. * This allows task 2 recovery to continue from the persisted state. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param uint64_t MCAS ADO work_key. * @param int chunk index to start from. * @param std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *map of final chunks. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t backup_final_result(ADO_cpp_pm_sort_plugin_superblock *sb, const uint64_t work_key, uint64_t chunk_index, std::map<std::string, ADO_cpp_pm_sort_plugin_record*> *data_map); /** * Sort according to task 1 logic (RAM use only) * @param uint64_t MCAS ADO work_key. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t sort_task1(const uint64_t work_key); /** * Sort according to task 2 logic (RAM sorting & PM flushing) * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param uint64_t MCAS ADO work_key. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t sort_task2(ADO_cpp_pm_sort_plugin_superblock *sb, const uint64_t work_key); /** * Sort according to task 3 logic (PM use only), continues from superblock state. * @param ADO_cpp_pm_sort_plugin_superblock *points to the superblocks. * @param uint64_t MCAS ADO work_key. * @param status_t returns S_OK if no error, otherwise throws execptions. */ status_t sort_task3(ADO_cpp_pm_sort_plugin_superblock *sb, const uint64_t work_key); public: /** * Constructor * * @param block_device Block device interface * */ ADO_cpp_pm_sort_plugin() {} /** * Destructor * */ virtual ~ADO_cpp_pm_sort_plugin() {} /** * Component/interface management * */ DECLARE_VERSION(0.1f); DECLARE_COMPONENT_UUID(0x84307b41,0x84f1,0x496d,0xbfbf,0xb5,0xe4,0xcf,0x40,0x70,0xe3); void * query_interface(component::uuid_t& itf_uuid) override { if (itf_uuid == component::IADO_plugin::iid()) { return (void *) static_cast<component::IADO_plugin*>(this); } else return NULL; // we don't support this interface } void unload() override { delete this; } public: /* IADO_plugin */ status_t register_mapped_memory(void * shard_vaddr, void * local_vaddr, size_t len) override; status_t do_work(const uint64_t work_key, const char * key, size_t key_len, IADO_plugin::value_space_t& values, const void * in_work_request, /* don't use iovec because of non-const */ const size_t in_work_request_len, bool new_root, response_buffer_vector_t& response_buffers) override; status_t shutdown() override; }; #pragma GCC diagnostic pop #endif
iIias/mcas
examples/personalities/cpp_pm_sort/src/cpp_pm_sort_client.h
/* * Description : PM sorting ADO client * Authors : <NAME>, <NAME>, <NAME> * Authors email: <EMAIL>, <EMAIL>, <EMAIL> * License : Apache License, Version 2.0 * Done as part of the Workshop on Search Data Structures for High-Performance Databases * at Tel-Aviv University. */ #ifndef __EXAMPLE_FB_CLIENT_H__ #define __EXAMPLE_FB_CLIENT_H__ #include <string> #include <api/mcas_itf.h> #include "cpp_pm_sort_plugin.h" namespace cpp_pm_sort { using pool_t = component::IKVStore::pool_t; class Client { public: Client(const unsigned debug_level, unsigned patience, const std::string& addr_with_port, const std::string& nic_device); pool_t create_pool(const std::string& pool_name, const size_t size, const size_t expected_obj_count = 1000); pool_t open_pool(const std::string& pool_name, bool read_only = false); status_t close_pool(const pool_t pool); status_t delete_pool(const std::string& pool_name); status_t remove_chunk(const pool_t pool, const std::string& key); status_t sort(const pool_t pool, unsigned type); status_t init(const pool_t pool); status_t verify(const pool_t pool); private: component::IMCAS * _mcas; }; } #endif // __EXAMPLE_FB_CLIENT_H__
maxwellburson/42_ft_db
libft/lstr/lstr_finish.c
<filename>libft/lstr/lstr_finish.c<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* lststr_finish.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/12 22:11:38 by mburson #+# #+# */ /* Updated: 2017/01/16 20:23:04 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> #include <libft.h> #include <stdlib.h> static size_t total_length(t_lstr *link) { size_t size; size = 0; while (link) { size += ft_strlen(link->str); link = link->next; } return (size); } char *lstr_finish(t_lstr **start) { t_lstr *link; t_lstr *link_last; char *str; char *cur; if (*start == NULL) return (ft_strdup("")); if (!(str = (char*)malloc(sizeof(char) * (total_length(*start) + 1)))) return (NULL); cur = str; link = *start; *start = NULL; while (link) { cur = ft_strplace(cur, (link->str)); cur++; if (!(link->constant)) free(link->str); link_last = link; link = link->next; free(link_last); } *cur = '\0'; return (str); }
maxwellburson/42_ft_db
src/execute_command/filter.c
<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* filter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/03 15:03:52 by rle #+# #+# */ /* Updated: 2017/05/04 14:33:00 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> int filter(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) { t_vec new_entries; size_t i; uint8_t *entry; (void)(db); vec_init(&new_entries, entries->elmnt_size); i = 0; while (i < entries->elmnt_count) { entry = *(uint8_t**)vec_get(entries, i); if (0 == memcmp(entry + header->fields[cmd->field].offset, cmd->value, header->fields[cmd->field].value_size)) { vec_add(&new_entries, &entry); } i++; } vec_del(entries); *entries = new_entries; return (0); }
maxwellburson/42_ft_db
src/save_db.c
<filename>src/save_db.c<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* load_db.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/01 18:20:41 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> /* ** db format: ** header ** fields ** names ** db struct ** db data ** ** is casting ssize_t to size_t bad?? */ static int save_header(struct s_header *header, int fd) { ssize_t size; if (-1 == (size = write(fd, header, sizeof(*header)))) return (-1); if (size != sizeof(*header)) { g_error = "not everything got written\?\?"; return (-1); } return (0); } static int save_header_fields(struct s_header *header, int fd) { ssize_t size; size_t i; if (-1 == (size = write(fd, header->fields, sizeof(*header->fields) * header->field_count))) return (-1); if ((size_t)size != sizeof(*header->fields) * header->field_count) { g_error = "not everything got written\?\?"; return (-1); } i = 0; while (i < header->field_count) { size = write(fd, header->fields[i].name, header->fields[i].name_size); if (size == -1) return (-1); if ((size_t)size != header->fields[i].name_size) { g_error = "not everything got written\?\?"; return (-1); } i++; } return (0); } static int save_database(t_vec *db, int fd) { ssize_t size; if (-1 == (size = write(fd, db, sizeof(*db)))) return (-1); if (size != sizeof(*db)) { g_error = "not everything got written\?\?"; return (-1); } if (-1 == (size = write(fd, db->data, db->elmnt_count * db->elmnt_size))) return (-1); if ((size_t)size != db->elmnt_count * db->elmnt_size) { g_error = "not everything got written\?\?"; return (-1); } return (0); } int save_db(struct s_header *header, t_vec *db, int argc, char **argv) { int fd; char *file; if (argc == 1) file = DEFAULT_FILE; else if (argc == 2) file = argv[1]; else if (argc > 2) { g_error = "bad useage in save (how did this even happen\?\?)"; return (-1); } if (-1 == (fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666)) || -1 == save_header(header, fd) || -1 == save_header_fields(header, fd) || -1 == save_database(db, fd) || -1 == close(fd)) return (-1); return (0); }
maxwellburson/42_ft_db
libft/convert/ft_itoa_base.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_itoa_base.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/07 18:26:12 by mburson #+# #+# */ /* Updated: 2017/01/07 18:26:14 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> #include <stdlib.h> #include <libft.h> #include <stdint.h> /* ** converts a number into a representation in the given base */ static char rep_mask(int num, _Bool uppercase) { if (0 <= num && num <= 9) return (num + '0'); else if (uppercase) return (num - 10 + 'A'); else return (num - 10 + 'a'); } char *ft_itoa_base(uintmax_t n, uintmax_t base, _Bool uppercase) { char *str; int i; i = ft_numlen_un(n, base); if (!(str = (char*)malloc(sizeof(char) * (i + 1)))) return (NULL); str[i] = '\0'; while (i) { i--; str[i] = rep_mask(n % base, uppercase); n /= base; } return (str); }
maxwellburson/42_ft_db
src/vector/vec_init.c
<filename>src/vector/vec_init.c /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* corewar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: zsmith <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/04/05 13:46:56 by zsmith ### ########.fr */ /* */ /* ************************************************************************** */ #include <vector.h> #include <stdlib.h> #include <libft.h> #include <string.h> int vec_init(t_vec *vector, size_t elmnt_size) { if (NULL == (vector->data = malloc(elmnt_size * VECTOR_INITIAL_SIZE))) return (-1); vector->elmnt_size = elmnt_size; vector->elmnt_count = 0; vector->elmnt_max = VECTOR_INITIAL_SIZE; vector->data_end = vector->data; return (0); }
maxwellburson/42_ft_db
src/vector/vec_realloc.c
<reponame>maxwellburson/42_ft_db<filename>src/vector/vec_realloc.c /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* corewar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: zsmith <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/04/05 13:46:56 by zsmith ### ########.fr */ /* */ /* ************************************************************************** */ #include <vector.h> #include <stdlib.h> #include <libft.h> int vec_realloc(t_vec *vec, size_t new_size) { uint8_t *new_data; if (NULL == (new_data = malloc(vec->elmnt_size * new_size))) return (-1); memcpy(new_data, vec->data, vec->elmnt_size * vec->elmnt_count); free(vec->data); vec->elmnt_max = new_size; vec->data = new_data; vec->data_end = new_data + (vec->elmnt_size * vec->elmnt_count); return (0); }
maxwellburson/42_ft_db
libft/convert/ft_utf_32_8.c
<reponame>maxwellburson/42_ft_db<filename>libft/convert/ft_utf_32_8.c<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_utf_32_8.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/19 20:59:54 by mburson #+# #+# */ /* Updated: 2017/01/19 20:59:56 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <wchar.h> #include <libft.h> #include <string.h> #include <stdlib.h> static unsigned char format_trailing(unsigned char c) { return ((c & 0b00111111) | 0b10000000); } static unsigned char format_first(unsigned char c, int length) { return ((0b11110000 << (4 - length)) | c); } static char get_length(wint_t c) { if (!((0xFFFFFFFF << 7) & c)) return (1); if (!((0xFFFFFFFF << 11) & c)) return (2); if (!((0xFFFFFFFF << 16) & c)) return (3); if (!((0xFFFFFFFF << 21) & c)) return (4); return (0); } unsigned char *ft_utf_32_8(wint_t c) { unsigned char *res; int len; int i; if (!(len = get_length(c)) || !(res = (unsigned char*)malloc(sizeof(char) * (len + 1)))) return (NULL); res[len] = '\0'; if (len == 1) { res[0] = (unsigned char)c; return (res); } i = len; while (i) { i--; if ((res[i] = (unsigned char)c)) { res[i] = format_trailing(res[i]); c = c >> 6; } } res[i] = format_first(res[i], len); return (res); }
maxwellburson/42_ft_db
src/execute_command/add.c
<reponame>maxwellburson/42_ft_db /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* add.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/03 15:03:52 by rle #+# #+# */ /* Updated: 2017/05/05 22:39:59 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> static void repoint(t_vec *entries, t_vec *db, uint8_t *old_data) { uint8_t **entry; entry = (uint8_t**)entries->data; while (entry < (uint8_t**)entries->data_end) { *entry = vec_get(db, (*entry - old_data) / db->elmnt_size); entry++; } entries->data_end = (void*)entry; } int add(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) { uint8_t *entry; if (db->elmnt_count == db->elmnt_max) { entry = db->data; if (-1 == vec_realloc(db, db->elmnt_max * VECTOR_INCREASE_RATIO)) return (-1); repoint(entries, db, entry); } entry = vec_get(db, db->elmnt_count); db->elmnt_count++; db->data_end = (uint8_t*)db->data_end + db->elmnt_size; bzero(entry, header->entry_size); memcpy(entry + header->fields[cmd->field].offset, cmd->value, header->fields[cmd->field].value_size); if (-1 == vec_add(entries, &entry)) return (-1); return (0); }
maxwellburson/42_ft_db
include/ft_db.h
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_db.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/05 23:23:51 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_DB_H # define FT_DB_H # include <stdbool.h> # include <string.h> # include <unistd.h> # include <vector.h> # include <libft.h> # include <stdint.h> # include <stdlib.h> # include <stdio.h> # include <errno.h> # include <sys/types.h> # include <sys/stat.h> # include <fcntl.h> # define DEFAULT_FILE "default.db" # define INPUT_PROMPT "\e[33mft_db ->\e[39m " # define DEBUG 0 # define COMMAND_COUNT 9 enum e_ctype { NONE = 0, CLOSE = 1, GET = 2, SET = 3, ADD = 4, DELETE = 5, FILTER = 6, GETALL = 7, DROP = 8, CLEAR = 9 }; struct s_command { enum e_ctype type; uint64_t field; void *value; }; struct s_field { void *name; uint64_t name_size; uint64_t offset; uint64_t value_size; }; struct s_header { uint64_t entry_size; uint64_t field_count; struct s_field *fields; }; extern char *g_error; int print_entries(struct s_header *header, t_vec *entries); int get_next_line(char **next_line); int save_db(struct s_header *header, t_vec *db, int argc, char **argv); /* ** load_db/ */ int load_db(struct s_header *header, t_vec *db, int argc, char **argv); int new_db(struct s_header *header, t_vec *db); int open_db(struct s_header *header, t_vec *db, int fd); /* ** get_command/ */ int get_next_command(struct s_command *command, struct s_header *header); int get_command_type(char *line, struct s_command *command); int get_field(char *line, struct s_header *header, uint64_t *field_type); int get_value(char *line, struct s_command *command, struct s_header *header); uint64_t value_size(char *line); int compare_string(char *big, char *little); /* ** execute_command/ */ int execute_command(struct s_header *header, struct s_command *command, t_vec *entries, t_vec *db); int add(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db); int clear(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db); int delete(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db); int filter(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db); int get(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db); int getall(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db); int set(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db); int drop(struct s_header *header, struct s_command *command, t_vec *entries, t_vec *db); /* ** debug.c */ void debug_print(struct s_header *header, t_vec *db, struct s_command *command, t_vec *held_entries); void debug_entries(t_vec *db, t_vec *entries); void debug_command(struct s_command *command); void debug_db(t_vec *db); void debug_header(struct s_header *header); #endif
maxwellburson/42_ft_db
src/load_db/load_db.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* load_db.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/01 18:20:41 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> static char *pick_file(int argc, char **argv) { if (argc == 1) return (DEFAULT_FILE); else if (argc == 2) return (argv[1]); else { g_error = "Usage: ft_db: [DATABASE FILE]"; return (NULL); } } int load_db(struct s_header *header, t_vec *db, int argc, char **argv) { int fd; char *file; if (NULL == (file = pick_file(argc, argv))) return (-1); fd = open(file, O_RDONLY); if (-1 == fd) { if (errno == 2) { errno = 0; printf("\e[1mnew db:\e[0m %s\n\n", file); return (new_db(header, db)); } else return (-1); } else { printf("\e[1mopening:\e[0m %s\n\n", file); return (open_db(header, db, fd)); } }
maxwellburson/42_ft_db
libft/convert/ft_atoi.c
<reponame>maxwellburson/42_ft_db<filename>libft/convert/ft_atoi.c /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/31 16:59:01 by mburson #+# #+# */ /* Updated: 2016/10/31 16:59:03 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> /* ** converts a string to an int */ int ft_atoi(const char *str) { long result; size_t index; _Bool negative; result = 0; index = 0; negative = 0; while ((9 <= str[index] && str[index] <= 13) || str[index] == 32) index++; if (str[index] == '-') { index++; negative = 1; } else if (str[index] == '+') index++; while (47 < str[index] && str[index] < 58) { result = 10 * result + str[index] - 48; index++; } if (negative) result *= -1; return (result); }
maxwellburson/42_ft_db
src/vector/vec_rm.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* vec_rm.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/01 18:01:46 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <vector.h> #include <stdlib.h> #include <libft.h> int vec_rm(t_vec *vector, size_t index) { memcpy(vector->data + (index * vector->elmnt_size), vector->data + ((index + 1) * vector->elmnt_size), (vector->elmnt_count - (index + 1)) * vector->elmnt_size); vector->elmnt_count--; if (vector->elmnt_count * VECTOR_DECREASE_RATIO < vector->elmnt_max) { if (-1 == vec_realloc(vector, VECTOR_INCREASE_RATIO)) return (-1); } return (0); }
maxwellburson/42_ft_db
src/execute_command/delete.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* delete.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/03 15:03:52 by rle #+# #+# */ /* Updated: 2017/05/03 15:13:33 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> static _Bool swap(uint8_t **first, uint8_t **second) { uint8_t *swap; if (*first < *second) { swap = *first; *first = *second; *second = swap; return (true); } else return (false); } static void entries_reverse_sort(t_vec *entries) { size_t i; _Bool made_change; made_change = true; while (made_change) { made_change = false; i = 0; while (i + 1 < entries->elmnt_count) { made_change = made_change \ || swap(vec_get(entries, i), vec_get(entries, i + 1)); i++; } } } int delete(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) { size_t i; size_t j; uint8_t *entry; (void)(db); entries_reverse_sort(entries); i = 0; while (i < entries->elmnt_count) { entry = *(uint8_t**)vec_get(entries, i); j = (entry - db->data) / db->elmnt_size; memcpy(db->data + (j * db->elmnt_size), db->data + ((j + 1) * db->elmnt_size), (db->elmnt_count - (j + 1)) * db->elmnt_size); db->elmnt_count--; i++; } if (db->elmnt_count * VECTOR_DECREASE_RATIO < db->elmnt_max) { if (-1 == vec_realloc(db, VECTOR_INCREASE_RATIO)) return (-1); } clear(header, cmd, entries, db); return (0); }
maxwellburson/42_ft_db
src/execute_command/drop.c
<filename>src/execute_command/drop.c /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* drop.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/05 23:13:06 by rle #+# #+# */ /* Updated: 2017/05/05 23:26:47 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> int drop(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) { uint8_t *entry; size_t i; (void)db; i = 0; while (i < entries->elmnt_count) { entry = *(uint8_t**)vec_get(entries, i); if (0 == memcmp(entry + header->fields[cmd->field].offset, cmd->value, header->fields[cmd->field].value_size)) vec_rm(entries, i); else i++; } return (0); }
maxwellburson/42_ft_db
src/load_db/open_db.c
<filename>src/load_db/open_db.c<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* open_db.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/05 21:46:08 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> #define DB_OVERHEAD_PERCENT 0.2 static int load_header(struct s_header *header, int fd) { ssize_t size; if (-1 == (size = read(fd, header, sizeof(*header)))) return (-1); if (size != sizeof(*header)) { g_error = "BAD FILE"; return (-1); } return (0); } static int load_header_fields(struct s_header *header, int fd) { ssize_t size; header->fields = malloc(sizeof(*header->fields) * header->field_count); if (NULL == header->fields) return (-1); size = read(fd, header->fields, sizeof(*header->fields) * header->field_count); if (-1 == size) return (-1); if ((size_t)size != sizeof(*header->fields) * header->field_count) { g_error = "BAD FILE"; return (-1); } return (0); } static int load_field_names(struct s_header *header, int fd) { ssize_t size; size_t i; i = 0; while (i < header->field_count) { header->fields[i].name = malloc(header->fields[i].name_size); if (NULL == header->fields[i].name) return (-1); size = read(fd, header->fields[i].name, header->fields[i].name_size); if (size == -1) return (-1); if ((size_t)size != header->fields[i].name_size) { g_error = "not everything got written\?\?"; return (-1); } i++; } return (0); } static int load_database(t_vec *db, int fd) { ssize_t size; size = read(fd, db, sizeof(*db)); if (-1 == size) return (-1); if (size != sizeof(*db)) { g_error = "BAD FILE"; return (-1); } db->elmnt_max = db->elmnt_count * (1 + DB_OVERHEAD_PERCENT); if (NULL == (db->data = malloc(db->elmnt_size * db->elmnt_max))) return (-1); if (-1 == (size = read(fd, db->data, db->elmnt_size * db->elmnt_count))) return (-1); if ((size_t)size != db->elmnt_size * db->elmnt_count) { g_error = "BAD FILE"; return (-1); } db->data_end = db->data + (db->elmnt_count * db->elmnt_size); return (0); } /* ** does not verify if there is anything left in the file */ int open_db(struct s_header *header, t_vec *db, int fd) { if (-1 == load_header(header, fd) || -1 == load_header_fields(header, fd) || -1 == load_field_names(header, fd) || -1 == load_database(db, fd) || -1 == close(fd)) return (-1); return (0); }
maxwellburson/42_ft_db
src/get_command/get_value.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_value.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/05 22:03:03 by rle #+# #+# */ /* Updated: 2017/05/05 22:15:52 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> int get_value(char *line, struct s_command *command, struct s_header *header) { int i; int j; j = 0; i = 0; command->value = (char *)malloc(sizeof(char) * \ header->fields[command->field].value_size); ft_bzero(command->value, header->fields[command->field].value_size); while (line[i] && line[i] != ':') i++; if (!line[i++]) return (0); while (line[i]) { ((char *)command->value)[j] = line[i]; i++; j++; } return (1); } uint64_t value_size(char *line) { int i; int j; i = 0; j = 0; while (line[i] && line[i] != ':') i++; if (!line[i++]) return (-1); while (line[i]) { i++; j++; } return (j); }
maxwellburson/42_ft_db
src/ft_db.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_db.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/04 22:43:51 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> /* ** TODO: Let user know if db is loading or initializing ** ** BUG: right now the default db save will overwrite the last one, ** need to generage new name if deafult exists (db, db(1), db(2), ...) ** ** BUG: shit hits the fan when we delete */ char *g_error; static void print_error(void) { if (g_error) dprintf(STDERR_FILENO, "ERROR: %s\n", g_error); else perror("ERROR"); } static int manip_loop(struct s_header *header, t_vec *db, struct s_command *command, t_vec *held_entries) { while (true) { if (DEBUG) debug_print(header, db, command, held_entries); if ((-1 == get_next_command(command, header)) || -1 == execute_command(header, command, held_entries, db)) { return (1); } if (command->type == CLOSE) return (0); if (-1 == print_entries(header, held_entries)) { return (1); } ft_memdel(&command->value); } } static int manip_db(struct s_header *header, t_vec *db) { struct s_command command; t_vec held_entries; int ret; ret = 0; if (-1 == vec_init(&held_entries, sizeof(void*))) { print_error(); return (-1); } ret = manip_loop(header, db, &command, &held_entries); vec_del(&held_entries); free(command.value); return (ret); } void free_header(struct s_header *header) { size_t i; i = 0; while (i < header->field_count) { free(header->fields[i].name); i++; } free(header->fields); } int main(int argc, char **argv) { struct s_header header; t_vec db; int ret; g_error = NULL; ret = 0; if (-1 == load_db(&header, &db, argc, argv) || -1 == manip_db(&header, &db) || -1 == save_db(&header, &db, argc, argv)) { print_error(); ret = 1; } vec_del(&db); free_header(&header); return (ret); }
maxwellburson/42_ft_db
libft/lstr/lstr_add.c
<reponame>maxwellburson/42_ft_db /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* lstr_add.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/13 01:50:17 by mburson #+# #+# */ /* Updated: 2017/01/13 01:50:18 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <libft.h> #include <stdlib.h> #include <stdbool.h> _Bool lstr_add(t_lstr **start, char *str, _Bool constant) { t_lstr *link; if (!*start) { if (!(*start = lstr_new(str, constant))) return (false); return (true); } link = (*start); while (link->next) link = link->next; if (!(link->next = lstr_new(str, constant))) return (false); return (true); }
maxwellburson/42_ft_db
src/get_next_line.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_next_line.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/22 13:30:02 by rle #+# #+# */ /* Updated: 2017/04/30 16:51:34 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> #define BUFF_SIZE 64 static t_lstr *next_lstr(void) { t_lstr *line; char buff[BUFF_SIZE + 1]; ssize_t ret; line = NULL; while (true) { if (-1 == (ret = read(0, buff, BUFF_SIZE))) { if (errno == 4) { errno = 0; continue ; } free(lstr_finish(&line)); return (NULL); } buff[ret] = '\0'; lstr_add(&line, ft_strdup(buff), false); if (ret == 0 || ft_strchr(buff, '\n')) return (line); } } int get_next_line(char **next_line) { t_lstr *line; char *swap; char *c; ft_putstr(INPUT_PROMPT); line = next_lstr(); if (line == NULL) return (-1); if (NULL == (swap = lstr_finish(&line))) return (-1); if (NULL == (c = ft_strchr(swap, '\n'))) { *next_line = swap; } else { *next_line = ft_strndup(swap, ft_strchr(swap, '\n') - swap); free(swap); if (NULL == *next_line) return (-1); } return (0); }
maxwellburson/42_ft_db
libft/string/ft_strndup.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strndup.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 20:28:11 by mburson #+# #+# */ /* Updated: 2016/12/15 17:14:28 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> #include <stdlib.h> #include <errno.h> /* ** creates a new string from char *str of n length and null terminates it */ char *ft_strndup(const char *str, size_t n) { char *new_str; if (!(new_str = (char*)malloc(sizeof(char) * (n + 1)))) { errno = ENOMEM; return (NULL); } new_str[n] = '\0'; while (n) { n--; new_str[n] = str[n]; } return (new_str); }
maxwellburson/42_ft_db
src/execute_command/get.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/03 15:04:35 by rle #+# #+# */ /* Updated: 2017/05/03 15:13:35 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> static _Bool already_held(t_vec *held_entries, uint8_t *entry) { uint8_t **held; held = (uint8_t**)held_entries->data; while (held < (uint8_t**)held_entries->data_end) { if (*held == entry) return (true); held++; } return (false); } int get(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) { size_t i; uint8_t *entry; i = 0; while (i < db->elmnt_count) { entry = vec_get(db, i); if (0 == memcmp(entry + header->fields[cmd->field].offset, cmd->value, header->fields[cmd->field].value_size) && !already_held(entries, entry)) { if (-1 == vec_add(entries, &entry)) return (-1); } i++; } return (0); }
maxwellburson/42_ft_db
libft/list/lstsort.c
<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstnew.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/04 16:16:20 by mburson #+# #+# */ /* Updated: 2017/03/22 09:05:38 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdbool.h> #include <libft.h> void lstsort(t_list **dir_lst, _Bool (compare)(void*, void*)) { t_list *swap; t_list **link; _Bool sorted; sorted = false; while (sorted == false) { sorted = true; link = dir_lst; while (*link && (*link)->next) { if (compare((*link)->content, (*link)->next->content)) { sorted = false; swap = (*link)->next; (*link)->next = swap->next; swap->next = (*link); (*link) = swap; } link = &((*link)->next); } } }
maxwellburson/42_ft_db
include/vector.h
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* vector.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/01 17:38:39 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef VECTOR_H # define VECTOR_H # include <libft.h> # include <stdint.h> # define VECTOR_INITIAL_SIZE 4 # define VECTOR_INCREASE_RATIO 2 # define VECTOR_DECREASE_RATIO 6 typedef struct s_vector { size_t elmnt_size; size_t elmnt_count; size_t elmnt_max; uint8_t *data; uint8_t *data_end; } t_vec; int vec_add(t_vec *vector, void *element); void vec_set(t_vec *vector, size_t i, void *element); void vec_del(t_vec *vector); void *vec_get(t_vec *vector, size_t index); int vec_init(t_vec *vector, size_t elmnt_size); int vec_realloc(t_vec *vec, size_t new_size); int vec_rm(t_vec *vector, size_t index); #endif
maxwellburson/42_ft_db
src/execute_command/execute_command.c
<filename>src/execute_command/execute_command.c<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* execute_command.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/05 23:23:56 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> static int none(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) { (void)(header); (void)(cmd); (void)(entries); (void)(db); return (0); } static int (*const g_commands[])(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) = { &none, &none, &get, &set, &add, &delete, &filter, &getall, &drop, &clear }; int execute_command(struct s_header *header, struct s_command *command, t_vec *entries, t_vec *db) { if (command->type < COMMAND_COUNT) return (g_commands[command->type](header, command, entries, db)); else { g_error = "ERROR: bad command type\n"; return (-1); } }
maxwellburson/42_ft_db
src/execute_command/getall.c
<filename>src/execute_command/getall.c<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* show.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/03 15:03:52 by rle #+# #+# */ /* Updated: 2017/05/03 15:15:33 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> int getall(struct s_header *header, struct s_command *cmd, t_vec *entries, t_vec *db) { size_t i; uint8_t *entry; (void)(header); (void)(cmd); free(entries->data); entries->elmnt_count = db->elmnt_count; entries->elmnt_max = db->elmnt_max; entries->data = malloc(entries->elmnt_count * entries->elmnt_size); if (NULL == entries->data) return (-1); entries->data_end = (uint8_t*)entries->data + (entries->elmnt_count * entries->elmnt_size); i = 0; while (i < db->elmnt_count) { entry = vec_get(db, i); vec_set(entries, i, &entry); i++; } return (0); }
maxwellburson/42_ft_db
libft/string/ft_strsplit.c
<reponame>maxwellburson/42_ft_db<filename>libft/string/ft_strsplit.c /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strsplit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/02 19:30:30 by mburson #+# #+# */ /* Updated: 2016/12/02 19:30:32 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> #include <libft.h> #include <stdlib.h> static size_t plength(const char *str, char split) { size_t len; len = 0; while (str[len] && str[len] != split) len++; return (len); } char **ft_strsplit(char const *s, char c) { char **new; size_t i; size_t j; size_t len; if (!(new = (char**)malloc(sizeof(char*) * (ft_wrdcnt(s, c) + 1)))) return (NULL); i = 0; j = 0; while (s[i]) { if (s[i] != c) { len = plength(&(s[i]), c); if (!(new[j] = (char*)malloc(sizeof(char) * (len + 1)))) return (NULL); ft_strncpy(new[j], &(s[i]), len); new[j][len] = '\0'; i += len - 1; j++; } i++; } new[j] = NULL; return (new); }
maxwellburson/42_ft_db
src/load_db/new_db.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* new_db.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/05 23:03:35 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> #define VALUE_SIZE 100 static int get_head_count(struct s_header *header) { int n; char *line; write(1, "How many fields?\n", 17); get_next_line(&line); n = ft_atoi(line); free(line); while (n < 1) { write(1, "Fields must be greater than 0\n", 30); get_next_line(&line); n = ft_atoi(line); free(line); } header->field_count = n; if (NULL == (header->fields = malloc(sizeof(*header->fields) * n))) return (-1); return (0); } static int get_h_field(struct s_header *header, int max) { int i; char *line; i = 0; printf("Field %i?\n", max + 1); get_next_line(&line); while (i < max) { if (0 == ft_strcmp(header->fields[i].name, line)) { free(line); write(1, "Field already exists\n", 21); get_next_line(&line); i = 0; } i++; } header->fields[max].name = line; header->fields[max].name_size = ft_strlen(header->fields[max].name); return (1); } static int get_h_value(int *value_size) { char *line; puts("Value size?"); get_next_line(&line); *value_size = ft_atoi(line); free(line); while (*value_size < 0) { write(1, "Value size must be 0 or greater\n", 32); get_next_line(&line); *value_size = ft_atoi(line); free(line); } return (1); } int new_db(struct s_header *header, t_vec *db) { int i; int value_size; i = 0; if (-1 == get_head_count(header)) return (-1); header->entry_size = 0; while (i < (int)header->field_count) { get_h_field(header, i); get_h_value(&value_size); if (i == 0) header->fields[i].offset = 0; else header->fields[i].offset = \ header->fields[i - 1].offset + header->fields[i - 1].value_size; header->fields[i].value_size = value_size; header->entry_size += value_size; i++; } vec_init(db, header->entry_size); if (DEBUG) debug_header(header); return (0); }
maxwellburson/42_ft_db
src/debug.c
<reponame>maxwellburson/42_ft_db<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_db.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/04 22:39:55 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> void debug_header(struct s_header *header) { uint64_t i; puts("\e[32mheader debug:\e[39m"); printf("entry_size: %llu\n", header->entry_size); printf("field_count: %llu\n", header->field_count); ft_putchar('\n'); i = 0; while (i < header->field_count) { printf("\e[32mfield %llu\e[39m\n", i); puts("name:"); write(1, header->fields[i].name, header->fields[i].name_size); ft_putchar('\n'); printf("offset: %llu\n", header->fields[i].offset); printf("value_size: %llu\n", header->fields[i].value_size); ft_putchar('\n'); i++; } } void debug_db(t_vec *db) { (void)(db); } void debug_command(struct s_command *command) { (void)(command); } void debug_entries(t_vec *db, t_vec *entries) { size_t j; size_t i; uint8_t *entry; i = 0; while (i < entries->elmnt_count) { entry = *(uint8_t**)vec_get(entries, i); j = (entry - db->data) / db->elmnt_size; printf("entry: %zu\n", i); printf("entry offset: %ju\n", entry - db->data); printf("entry fixed offset: %ju\n", j); printf("db elmnt size: %ju\n", db->elmnt_size); putchar('\n'); i++; } } void debug_print(struct s_header *header, t_vec *db, struct s_command *command, t_vec *held_entries) { debug_db(db); debug_command(command); debug_entries(db, held_entries); }
maxwellburson/42_ft_db
src/get_command/get_type.c
<reponame>maxwellburson/42_ft_db /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_type.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/05 22:07:49 by rle #+# #+# */ /* Updated: 2017/05/05 23:09:36 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> int get_command_type(char *line, struct s_command *command) { if (compare_string(line, "CLOSE")) command->type = CLOSE; if (compare_string(line, "GET")) command->type = GET; if (compare_string(line, "SET")) command->type = SET; if (compare_string(line, "ADD")) command->type = ADD; if (compare_string(line, "CLEAR")) command->type = CLEAR; if (compare_string(line, "DELETE")) command->type = DELETE; if (compare_string(line, "FILTER")) command->type = FILTER; if (compare_string(line, "GETALL")) command->type = GETALL; if (compare_string(line, "DROP")) command->type = DROP; if (command->type == NONE) return (0); return (1); }
maxwellburson/42_ft_db
libft/libft.h
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* libft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 10:04:47 by mburson #+# #+# */ /* Updated: 2016/12/15 17:30:40 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIBFT_H # define LIBFT_H # include <string.h> # include <stdint.h> # include <wchar.h> typedef struct s_list { void *content; struct s_list *next; } t_list; /* ** for lstr_add and lstr_finish */ typedef struct s_lstr { char *str; _Bool constant; struct s_lstr *next; } t_lstr; /* ** ./bool/ */ int ft_isalnum(int c); int ft_isalpha(int c); int ft_isascii(int c); int ft_isdigit(int c); int ft_isprint(int c); /* ** ./convert/ */ uintmax_t ft_absolute(intmax_t n); int ft_atoi(const char *str); char *ft_itoa(int n); char *ft_itoa_base(uintmax_t n, uintmax_t base, \ _Bool uppercase); int ft_tolower(int c); int ft_toupper(int c); wint_t ft_utf_16_32(wchar_t **c); unsigned char *ft_utf_16_8(wchar_t **c); unsigned char *ft_utf_32_8(wint_t c); /* ** ./list/ */ void lstadd(t_list **alst, t_list *new); void lstpush(t_list **alst, t_list *new); void lstdel(t_list **alist, void (*del)(void *)); void lstdelone(t_list **alst, void (*del)(void *)); void lstiter(t_list *lst, void (*f)(t_list *elem)); t_list *lstmap(t_list *lst, t_list *(*f)(t_list *elem)); t_list *lstnew(void *content); void lstprint(t_list *link); void lstreverse(t_list **alst); void lstsort(t_list **dir_lst, _Bool (compare)(void*, void*)); /* ** ./lstr/ */ _Bool lstr_add(t_lstr **start, char *str, _Bool constant); char *lstr_finish(t_lstr **start); t_lstr *lstr_new(char *str, _Bool constant); void lstr_print(t_lstr *link); /* ** ./memory/ */ void *ft_bzero(void *s, size_t len); void *ft_memalloc(size_t size); void *ft_memccpy(void *dst, const void *src, \ int c, size_t n); void *ft_memchr(const void *s, int c, size_t n); int ft_memcmp(const void *s1, const void *s2, size_t n); void *ft_memcpy(void *dst, const void *src, size_t n); void ft_memdel(void **ap); void *ft_memdup(const void *item, size_t size); void *ft_memmove(void *dst, const void *src, size_t n); void *ft_memset(void *b, int c, size_t len); /* ** ./other/ */ int ft_numlen(long n, long base); int ft_numlen_un(uintmax_t n, uintmax_t base); /* ** ./put/ */ void ft_putchar(char c); void ft_putchar_fd(char c, int fd); void ft_putendl(const char *s); void ft_putendl_fd(const char *s, int fd); void ft_putnbr(int n); void ft_putnbr_fd(int n, int fd); void ft_putstr(const char *s); void ft_putstr_fd(const char *s, int fd); void ft_putstrw(const wchar_t *str); /* ** ./string/ */ char *ft_strplace(char *dst, const char *src); size_t ft_wrdcnt(const char *str, char split); int ft_strchri(const char *str, char c); char *ft_strnchr(const char *s, int c, size_t n); size_t ft_strlen(const char *s); size_t ft_strlenw(const wchar_t *str); char *ft_strcpy(char *dest, const char *src); char *ft_strncpy(char *dest, const char *src, size_t len); char *ft_strndup(const char *str, size_t n); char *ft_strcat(char *s1, const char *s2); char *ft_strncat(char *s1, const char *s2, size_t n); size_t ft_strlcat(char *s1, const char *s2, size_t size); char *ft_strchr(const char *s, int c); char *ft_strrchr(const char *s, int c); char *ft_strstr(const char *big, const char *little); char *ft_strnstr(const char *big, const char *little, \ size_t len); int ft_strcmp(char *s1, char *s2); int ft_strncmp(char *s1, char *s2, size_t n); char *ft_strnew(size_t size); void ft_strdel(char **s); char *ft_strdup(const char *str); void ft_strclr(char *s); void ft_striter(char *s, void (*f)(char *)); void ft_striteri(char *s, void (*f)(unsigned int, char *)); char *ft_strmap(char *s, char (*f)(char)); char *ft_strmapi(char *s, char (*f)(unsigned int, char)); char *ft_strsub(char const *s, unsigned int start, size_t len); char *ft_strjoin(char const *s1, char const *s2); char *ft_strtrim(char const *s); char **ft_strsplit(char const *s, char c); #endif
maxwellburson/42_ft_db
src/print_entries.c
<filename>src/print_entries.c /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* print_entries.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/05/05 14:03:48 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> static int print_entry(struct s_header *header, uint8_t *entry) { size_t i; i = 0; while (i < header->field_count) { write(1, header->fields[i].name, header->fields[i].name_size); write(1, ":", 1); write(1, entry + (i * header->fields[i].value_size), header->fields[i].value_size); write(1, " ", 2); i++; } write(1, "\n", 1); return (0); } int print_entries(struct s_header *header, t_vec *entries) { size_t i; write(1, "\n", 1); i = 0; while (i < entries->elmnt_count) { print_entry(header, *(uint8_t**)vec_get(entries, i)); i++; } if (i == 0) write(1, "(nothing held)\n", 15); write(1, "\n", 1); return (0); }
maxwellburson/42_ft_db
src/get_command/get_command.c
<reponame>maxwellburson/42_ft_db /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_command.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/04/28 14:04:53 by rle #+# #+# */ /* Updated: 2017/05/05 23:02:51 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_db.h" static int parse_commmand(char *line, struct s_command *command, struct s_header *header) { if (get_command_type(line, command)) { if (command->type == CLOSE || command->type == CLEAR \ || command->type == DELETE || command->type == GETALL) return (1); else if (-1 == get_field(line, header, &command->field)) { write(1, "Invalid field\n", 14); return (0); } else if (value_size(line) > header->fields[command->field].value_size) { write(1, "Value size is too large\n", 24); return (0); } else if (!get_value(line, command, header)) return (0); return (1); } return (0); } int get_next_command(struct s_command *command, struct s_header *header) { char *line; int ret; ret = 0; ft_bzero(command, sizeof(*command)); while (ret != 1) { if (-1 == get_next_line(&line)) break ; ret = parse_commmand(line, command, header); free(line); if (ret == -1) break ; } return (ret); }
maxwellburson/42_ft_db
src/get_command/get_field.c
<gh_stars>0 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_field.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rle <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/05 22:03:40 by rle #+# #+# */ /* Updated: 2017/05/05 22:17:57 by rle ### ########.fr */ /* */ /* ************************************************************************** */ #include <ft_db.h> int compare_string(char *big, char *little) { int i; i = 0; while (big[i] && little[i] && (big[i] == little[i])) i++; if (!little[i]) return (1); return (0); } static char *cpy_head_name(char *name, int size) { int i; char *tmp; tmp = (char *)malloc(sizeof(char) * size + 1); i = 0; while (i < size) { tmp[i] = name[i]; i++; } tmp[i] = '\0'; return (tmp); } static int get_name(struct s_header *header, uint64_t *field_type, char *field) { char *tmp; uint64_t i; i = -1; while (++i < header->field_count) { tmp = cpy_head_name(header->fields[i].name, \ header->fields[i].name_size); if (compare_string(tmp, field)) { *field_type = i; free(field); free(tmp); return (0); } free(tmp); } free(field); return (-1); } int get_field(char *line, struct s_header *header, uint64_t *field_type) { uint64_t i; int j; char *field; j = 0; i = 0; while (line[i] && line[i] != ' ') i++; if (!line[i++]) return (-1); while (line[i + j] && line[i + j] != ':') j++; if (!line[i + j]) return (-1); field = (char *)malloc(sizeof(char) * j + 1); j = 0; while (line[i] && line[i] != ':') field[j++] = line[i++]; field[j] = '\0'; i = -1; return (get_name(header, field_type, field)); }
maxwellburson/42_ft_db
src/vector/vec_add.c
<reponame>maxwellburson/42_ft_db /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* corewar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: zsmith <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 18:52:02 by mburson #+# #+# */ /* Updated: 2017/04/05 13:46:56 by zsmith ### ########.fr */ /* */ /* ************************************************************************** */ #include <vector.h> #include <stdlib.h> #include <libft.h> int vec_add(t_vec *vector, void *element) { if (vector->elmnt_count == vector->elmnt_max) { if (-1 == vec_realloc(vector, vector->elmnt_count * VECTOR_INCREASE_RATIO)) return (-1); } vector->elmnt_count++; memcpy(vector->data_end, element, vector->elmnt_size); vector->data_end = (uint8_t*)vector->data_end + vector->elmnt_size; return (0); }
maxwellburson/42_ft_db
libft/string/ft_strtrim.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strtrim.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <<EMAIL>> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/02 18:52:42 by mburson #+# #+# */ /* Updated: 2016/12/02 18:52:45 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdlib.h> #include <string.h> #include <libft.h> static _Bool is_whitespace(char c) { return (c == ' ' || c == '\n' || c == '\t'); } char *ft_strtrim(char const *s) { size_t start; size_t end; char *new; start = 0; end = ft_strlen(s) - 1; while (is_whitespace(s[start])) start++; while (is_whitespace(s[end]) && end > 0) end--; if (start >= end) return (ft_strdup("\0")); if (!(new = (char*)malloc(end - start + 2))) return (NULL); ft_strncpy(new, &(s[start]), end - start + 1); new[end - start + 1] = '\0'; return (new); }
HarrisLee/Utils
MySampleCode-master/CocoaPodsDemo/OtherLinkerFlag/OtherLinkerFlag/BSStaticLibraryOne.h
// // BSStaticLibraryOne.h // BSStaticLibraryOne // // Created by 张星宇 on 2017/1/7. // Copyright © 2017年 bestswifter. All rights reserved. // #import <Foundation/Foundation.h> @interface BSStaticLibraryOne : NSObject - (void)saySomething; @end
HarrisLee/Utils
MySampleCode-master/load/load/Child+load.h
// // Child+load.h // load // // Created by 张星宇 on 16/2/1. // Copyright © 2016年 zxy. All rights reserved. // #import "Child.h" @interface Child (load) @end
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/HashTest.h
<filename>MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/HashTest.h // // HashTest.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/25. // Copyright © 2016年 zxy. All rights reserved. // #import "EOCPerson.h" @interface HashTest : EOCPerson - (void)testMutableCollection; @end
HarrisLee/Utils
GetIpAddress(v4+v6)/GetIPAddress/GetIPAddress.h
// // GetIPAddress.h // GetIPAddress // // Created by <NAME> on 8/28/15. // Copyright (c) 2015 <NAME>. All rights reserved. // #import <Foundation/Foundation.h> @interface GetIPAddress : NSObject + (NSString *)getIPAddress:(BOOL)preferIPv4; + (NSDictionary *)getIPAddresses; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtMainTableViewDataSource.h
// // KtMainTableViewDataSource.h // KtTableView // // Created by bestswifter on 16/4/13. // Copyright © 2016年 zxy. All rights reserved. // #import "KtTableViewDataSource.h" @interface KtMainTableViewDataSource : KtTableViewDataSource @end
HarrisLee/Utils
UniversalApp-master/MiAiApp/Manager/UserManager/UserInfo.h
<gh_stars>0 // // UserInfo.h // MiAiApp // // Created by 徐阳 on 2017/5/23. // Copyright © 2017年 徐阳. All rights reserved. // #import <Foundation/Foundation.h> @interface UserInfo : NSObject PropertyLongLong(userId); @end
HarrisLee/Utils
UniversalApp-master/MiAiApp/Define/FontAndColorMacros.h
// // FontAndColorMacros.h // MiAiApp // // Created by 徐阳 on 2017/5/18. // Copyright © 2017年 徐阳. All rights reserved. // #ifndef FontAndColorMacros_h #define FontAndColorMacros_h #define CNavBgColor [UIColor colorWithHexString:@"00AE68"] #endif /* FontAndColorMacros_h */
HarrisLee/Utils
MySampleCode-master/runtime/runtime/NSString+MyImplementation.h
// // NSString+MyImplementation.h // runtime // // Created by 张星宇 on 16/1/2. // Copyright © 2016年 张星宇. All rights reserved. // #import <Foundation/Foundation.h> @interface NSString (MyImplementation) - (NSString *)myLowercaseString; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtBaseModel/KtBaseListModel/KtBaseListModel.h
// // KtBaseListModel.h // KtTableView // // Created by bestswifter on 16/5/18. // Copyright © 2016年 zxy. All rights reserved. // #import "KtBaseModel.h" #import "KtBaseListItem.h" @protocol KtBaseListModelProtocol <NSObject> @required - (void)refreshRequestDidSuccess; - (void)loadRequestDidSuccess; - (void)didLoadLastPage; - (void)handleAfterRequestFinish; // 请求结束后的操作,刷新tableview或关闭动画等。 @optional - (void)didLoadFirstPage; @end @interface KtBaseListModel : KtBaseModel @property (nonatomic, strong) KtBaseListItem *listItem; @property (nonatomic, weak) id<KtBaseListModelProtocol> delegate; @property (nonatomic, assign) BOOL isRefresh; // 如果为是,表示刷新,否则为加载。 - (void)loadPage:(int)pageNumber; - (void)loadNextPage; - (void)loadPreviousPage; @end
HarrisLee/Utils
ContainerWork/Libraries/Libraries/SNViewController.h
<reponame>HarrisLee/Utils // // SNViewController.h // Libraries // // Created by JianRongCao on 1/19/17. // Copyright © 2017 JianRongCao. All rights reserved. // #import <UIKit/UIKit.h> @interface SNViewController : UIViewController @end
HarrisLee/Utils
MySampleCode-master/CocoaPodsDemo/BSStaticLibraryOne/Pod/Pod.h
// // Pod.h // Pod // // Created by 张星宇 on 2017/1/8. // Copyright © 2017年 bestswifter. All rights reserved. // #import <Foundation/Foundation.h> @interface Pod : NSObject @end
HarrisLee/Utils
MySampleCode-master/CocoaPodsDemo/OtherLinkerFlag/OtherLinkerFlag/ViewController.h
<filename>MySampleCode-master/CocoaPodsDemo/OtherLinkerFlag/OtherLinkerFlag/ViewController.h // // ViewController.h // OtherLinkerFlag // // Created by 张星宇 on 2017/1/7. // Copyright © 2017年 bestswifter. All rights reserved. // #import <UIKit/UIKit.h> #import "BSStaticLibraryOne.h" #import "BSStaticLibraryOne+Extension.h" @interface ViewController : UIViewController @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/AppDelegate.h
<gh_stars>0 // // AppDelegate.h // KtTableView // // Created by bestswifter on 16/4/13. // Copyright © 2016年 zxy. All rights reserved. // #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
HarrisLee/Utils
MySampleCode-master/load/load/Child.h
// // Child.h // load // // Created by 张星宇 on 16/2/1. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> #import "Parent.h" @interface Child : Parent @end
HarrisLee/Utils
UniversalApp-master/MiAiApp/AppDelegate.h
// // AppDelegate.h // MiAiApp // // Created by 徐阳 on 2017/5/17. // Copyright © 2017年 徐阳. All rights reserved. // #import <UIKit/UIKit.h> #import "MainTabBarController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) MainTabBarController *mainTabBar; @end
HarrisLee/Utils
RMUtilsFramework/RMUtilsFramework/RMUtilsFramework.h
<gh_stars>0 // // RMUtilsFramework.h // RMUtilsFramework // // Created by JianRongCao on 15/12/14. // Copyright © 2015年 JianRongCao. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for RMUtilsFramework. FOUNDATION_EXPORT double RMUtilsFrameworkVersionNumber; //! Project version string for RMUtilsFramework. FOUNDATION_EXPORT const unsigned char RMUtilsFrameworkVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <RMUtilsFramework/PublicHeader.h> #import <RMUtilsFramework/RMUtils.h>
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/EOCErrors.h
<reponame>HarrisLee/Utils // // EOCErrors.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/27. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> @interface EOCErrors : NSObject extern NSString *const EOCErrorDomain; typedef NS_ENUM(NSUInteger, EOCError) { EOCErrorUnkonwn = -1, EOCErrorInternalInconsistency = 100, EOCErrorGeneralFault = 105, EOCErrorBadInput = 500, }; @end
HarrisLee/Utils
UniversalApp-master/MiAiApp/Utils/NetWork/HeaderModel.h
<gh_stars>0 // // HeaderModel.h // MiAiApp // // Created by 徐阳 on 2017/5/23. // Copyright © 2017年 徐阳. All rights reserved. // #import <Foundation/Foundation.h> #import "OpenUDID.h" /** header 参数model */ @interface HeaderModel : NSObject PropertyLongLong(userid);//用户ID PropertyString(imei);//设备号 PropertyNSInteger(os_type);//0未知,1安卓,2IOS PropertyString(version);//当前APP版本 PropertyString(channel);//来源渠道 苹果使用:@"App Store" PropertyString(clientId);//客户端唯一标示,后台用来判断是否更换设备 PropertyNSInteger(versioncode);//内部维护的应用版本 随版本递增 PropertyString(mobile_model);//手机型号 PropertyString(mobile_brand);//手机品牌 @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtBaseModel/KtBaseItem.h
// // KtBaseItem.h // KtTableView // // Created by bestswifter on 16/5/13. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> @interface KtBaseItem : NSObject - (id)initWithData:(NSDictionary *)data; // property中如有包含TBCBaseListItem对象的数组,需要设定此规则 - (void)addMappingRuleArrayProperty:(NSString*)propertyName class:(Class)cls; // 所有需要映射的property都需要设定此规则 - (void)addMappingRuleProperty:(NSString*)propertyName pathInJson:(NSString*)path; - (id)setData:(id)data; @end @interface KtClassHelper : NSObject + (KtClassHelper *)sharedInstance; @property (nonatomic, retain) NSMutableDictionary *propertyListCache; - (NSDictionary *)propertyList:(Class)cls; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtMainTableModel.h
<reponame>HarrisLee/Utils // // KtMainTableModel.h // KtTableView // // Created by bestswifter on 16/5/13. // Copyright © 2016年 zxy. All rights reserved. // #import "KtBaseListModel.h" #import "KtMainTableItem.h" @interface KtMainTableModel : KtBaseListModel @property (nonatomic, strong) KtMainTableItem *tableViewItem; @end
HarrisLee/Utils
RMUtilsFramework/RMUtilsFramework/RMUtils.h
// // RMUtils.h // RMUtilsFramework // // Created by JianRongCao on 15/12/14. // Copyright © 2015年 JianRongCao. All rights reserved. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface RMUtils : NSObject /*! Email地址合法性判断 非法:NO 合法:YES*/ + (BOOL)isValidateEmail:(NSString *)email; /*! 手机号码合法性判断 非法:NO 合法:YES*/ + (BOOL)isValidatPhone:(NSString*)phone; /*! 字符串是否是N位的纯数字和字母*/ + (BOOL)isValidateNumberSymbol:(NSString *)string length:(NSInteger)length; /*! 判断该对象是否是NSDictionary*/ + (BOOL)isValidDictionary:(id)object; /*! 判断该对象是否是NSArray*/ + (BOOL)isValidArray:(id)object; /*! 判断该对象是否是NSString*/ + (BOOL)isValidString:(NSString*)string; /*! 获取时间 格式如今天 12:11, 昨天:09:15等等*/ + (NSString *)commonTimeFormat:(NSString*)msgCreateTime; /*! 根据时间字符串获取时间*/ + (NSString *)getTime:(NSString *)time oldFormat:(NSString *)oldFormat format:(NSString *)format; /*! 根据时间戳获取时间*/ + (NSString *)getTime:(NSTimeInterval)time format:(NSString *)format; /*! 获取硬件型号,如iPhone 6S,iPad Pro等*/ + (NSString *)getPlatformVersion; /*! 返回运营商平台*/ + (NSString *)checkChinaMobile; /*! 将JSON字符串序列化成对象*/ + (id)serializationString:(NSString *)jsonString; /*! 将NSDictionary对象转换成NSString*/ + (NSString *)serializationObject:(id)object; /*! 获取Model的属性数组(getSuper YES:获取父类属性 NO:不获取父类属性)*/ + (NSArray *)getPropertyList:(Class)obj superClass:(BOOL)superCls; /*! 获取NSDictionary的值,将Model对应的key进行赋值,以model的key值为标准*/ + (void)setModelValue:(id)model fromDictionary:(NSDictionary *)param; /*! App内部某个文件的位置*/ + (NSString *)bundlePath:(NSString *)fileName; /*! App Documents文件夹下某个文件的位置*/ + (NSString *)documentsFilePath:(NSString *)fileName; /*! App Documents文件夹下某个文件夹的位置*/ + (NSString *)documentsDirectotyPath:(NSString *)direction; /*! App Libiries/Caches下某个文件的位置*/ + (NSString *)cacheFilePath:(NSString *)cacheName; /*! App Libiries/Caches下某个文件夹的位置*/ + (NSString *)cacheDirectionPath:(NSString *)direction; /*! 优先使用ContentOfFile的方式加载图片*/ + (UIImage *)imageNameWithString:(NSString *)imageName; NSString* ClassName(Class cls); @end
HarrisLee/Utils
MySampleCode-master/runtime/runtime/Replacement.h
// // Replacement.h // runtime // // Created by 张星宇 on 16/1/2. // Copyright © 2016年 张星宇. All rights reserved. // #import <Foundation/Foundation.h> @interface Replacement : NSObject @end
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/Literal.h
// // Literal.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/24. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> @interface Literal : NSObject @property (nonatomic, strong) NSArray *animals; @property (nonatomic, strong) NSDictionary *personData; @end
HarrisLee/Utils
DylibContainer/Pods/Libraries/Libraries/Utils.h
<reponame>HarrisLee/Utils<gh_stars>0 // // Utils.h // Libraries // // Created by JianRongCao on 1/16/17. // Copyright © 2017 JianRongCao. All rights reserved. // #import <Foundation/Foundation.h> @interface Utils : NSObject + (Utils *)shareInstance; - (void)showMessage:(NSString *)message; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtMainTableItem.h
// // KtMainTableItem.h // KtTableView // // Created by bestswifter on 16/5/13. // Copyright © 2016年 zxy. All rights reserved. // #import "KtBaseListItem.h" @interface KtMainTableItem : KtBaseListItem @property (strong, nonatomic) NSMutableArray *books; // 存放了每个 cell 的标题 @end @interface KtMainTableBookItem : KtBaseItem @property (copy, nonatomic) NSString *bookTitle; @property (copy, nonatomic) NSString *url; @property (copy, nonatomic) NSString *imageUrl; @end
HarrisLee/Utils
OpenSSLRSAWrapper/OpenSSLRSAWrapper/AppDelegate.h
// // AppDelegate.h // OpenSSLRSAWrapper // // Created by <EMAIL> on 9/29/12. // Copyright (c) 2012 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> #import "ViewController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
HarrisLee/Utils
UniversalApp-master/MiAiApp/Define/URLMacros.h
<reponame>HarrisLee/Utils<filename>UniversalApp-master/MiAiApp/Define/URLMacros.h<gh_stars>0 // // URLMacros.h // MiAiApp // // Created by 徐阳 on 2017/5/18. // Copyright © 2017年 徐阳. All rights reserved. // #ifndef URLMacros_h #define URLMacros_h /* 将项目中所有的接口写在这里,方便统一管理,降低耦合 这里通过宏定义来切换你当前的服务器类型, 将你要切换的服务器类型宏后面置为真(即>0即可),其余为假(置为0) 如下:现在的状态为测试服务器 这样做切换方便,不用来回每个网络请求修改请求域名,降低出错事件 */ #define DevelopSever 1 #define TestSever 0 #define ProductSever 0 #if DevelopSever /**开发服务器*/ #define URL_main @"http://192.168.20.31:20000" //#define URL_main @"http://192.168.11.122:8090" //展鹏 #elif TestSever /**测试服务器*/ #define URL_main @"http://192.168.20.31:20000" #elif ProductSever /**生产服务器*/ #define URL_main @"http://192.168.20.31:20000" #endif #pragma mark - 详细接口地址 //测试接口 //NSString *const URL_Test = @"api/recharge/price/list"; #define URL_Test @"/api/cast/home/start" #endif /* URLMacros_h */
HarrisLee/Utils
UniversalApp-master/MiAiApp/Manager/UserManager.h
<reponame>HarrisLee/Utils // // UserManager.h // MiAiApp // // Created by 徐阳 on 2017/5/22. // Copyright © 2017年 徐阳. All rights reserved. // #import <Foundation/Foundation.h> @interface UserManager : NSObject @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KTMainViewController.h
<filename>MySampleCode-master/KtTableView/KtTableView/KTMainViewController.h<gh_stars>0 // // ViewController.h // KtTableView // // Created by bestswifter on 16/4/13. // Copyright © 2016年 zxy. All rights reserved. // #import <UIKit/UIKit.h> #import "KtRefreshTableViewController.h" @interface KTMainViewController : KtRefreshTableViewController @end
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/EOCEmployeeDeveloper.h
<filename>MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/EOCEmployeeDeveloper.h // // EOCEmployeeDeveloper.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/25. // Copyright © 2016年 zxy. All rights reserved. // #import "EOCEmployee.h" @interface EOCEmployeeDeveloper : EOCEmployee @end
HarrisLee/Utils
UniversalApp-master/MiAiApp/AppDelegate+AppService.h
// // AppDelegate+AppService.h // MiAiApp // // Created by 徐阳 on 2017/5/19. // Copyright © 2017年 徐阳. All rights reserved. // #import "AppDelegate.h" @interface AppDelegate (AppService) + (AppDelegate *)shareAppDelegate; /** 当前顶层控制器 */ -(UIViewController*) getCurrentVC; -(UIViewController*) getCurrentUIVC; @end
HarrisLee/Utils
ContainerWork/Libraries/Libraries/Libraries.h
// // Libraries.h // Libraries // // Created by JianRongCao on 1/16/17. // Copyright © 2017 JianRongCao. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for Libraries. FOUNDATION_EXPORT double LibrariesVersionNumber; //! Project version string for Libraries. FOUNDATION_EXPORT const unsigned char LibrariesVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <Libraries/PublicHeader.h> #import <Libraries/Utils.h> #import <Libraries/SNViewController.h>
HarrisLee/Utils
UniversalApp-master/MiAiApp/Manager/UserManager/UserManager.h
<reponame>HarrisLee/Utils // // UserManager.h // MiAiApp // // Created by 徐阳 on 2017/5/22. // Copyright © 2017年 徐阳. All rights reserved. // #import <Foundation/Foundation.h> #import "UserInfo.h" typedef NS_ENUM(NSInteger, UserLoginStatus){ kUserLoginStatusThird = 0x01 << 0,//第三方登录 kUserLoginStatusPwd = 0x01 << 1,///账号登录,自己 }; #define isLogin [UserManager sharedUserManager].isLogined #define curUser [UserManager sharedUserManager].curUserInfo /** 包含用户相关服务 */ @interface UserManager : NSObject SINGLETON_FOR_HEADER(UserManager) //当前用户 @property (nonatomic, strong) UserInfo *curUserInfo; @property (nonatomic, assign) UserLoginStatus loginStatus; @property (nonatomic, assign) BOOL isLogined; @end
HarrisLee/Utils
MySampleCode-master/CocoaPodsDemo/OtherLinkerFlag/OtherLinkerFlag/BSStaticLibraryOne+Extension.h
// // BSStaticLibraryOne+Extension.h // BSStaticLibraryOne // // Created by 张星宇 on 2017/1/7. // Copyright © 2017年 bestswifter. All rights reserved. // #import "BSStaticLibraryOne.h" @interface BSStaticLibraryOne (Extension) - (void)sayOtherThing; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtExtension/NSDictionary+KtExtension.h
<gh_stars>0 // // NSDictionary+KtExtension.h // KtTableView // // Created by bestswifter on 16/5/15. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> @interface NSDictionary (KtExtension) /*! @brief 根据路径获取obj 例如path为test/xxx/vallue, 会从dict中找到key为test的dict, 在test的dict中找到key为xxx的dict 在xxx的dict中找到key为value的对象 @param path 给定的路径 eg. test/xxx/value @return 返回obj or nil */ - (NSObject *)objectAtPath:(NSString *)path; /*! @brief 根据路径获取obj 如果获取不到返回other @param path 给定的路径 @param other 默认值,当找不到给定的obj,返回other @return 返回obj or other */ - (NSObject *)objectAtPath:(NSString *)path otherwise:(NSObject *)other; /*! @brief 判断给定的key值是否为BOOL类型 @param path 给定的路径 @return YES or NO */ - (BOOL)boolAtPath:(NSString *)path; /*! @brief 判断给定的key值是否为BOOL类型,如果给定的路径中找不到key值,返回other @param path 给定的路径 @param other 默认值,当找不到给定的obj,返回other @return 判断结果 */ - (BOOL)boolAtPath:(NSString *)path otherwise:(BOOL)other; /*! @brief 获取给定的key值,返回类型为number @param path 给定的路径 @return key值 or nil */ - (NSNumber *)numberAtPath:(NSString *)path; /*! @brief 获取给定的key值,返回类型为number @param path 给定的路径 @param otherwise 默认值,当找不到给定的obj,返回other @return key值 or other */ - (NSNumber *)numberAtPath:(NSString *)path otherwise:(NSNumber *)other; /*! @brief 获取给定的key值,返回类型为String @param path 给定的路径 @return key值 or nil */ - (NSString *)stringAtPath:(NSString *)path; /*! @brief 获取给定的key值,返回类型为string @param path 给定的路径 @param otherwise 默认值,当找不到给定的obj,返回otherwise @return key值 or otherwise */ - (NSString *)stringAtPath:(NSString *)path otherwise:(NSString *)other; /*! @brief 获取给定的key值,返回类型为NSArray @param path:给定的路径 @return key值 or nil */ - (NSArray *)arrayAtPath:(NSString *)path; /*! @brief 获取给定的key值,返回类型为NSArray @param path 给定的路径 @param otherwise 默认值,当找不到给定的obj,返回otherwise @return key值 or otherwise */ - (NSArray *)arrayAtPath:(NSString *)path otherwise:(NSArray *)other; /*! @brief 获取给定的key值,返回类型为NSMutableArray @param path:给定的路径 @return key值 or nil */ - (NSMutableArray *)mutableArrayAtPath:(NSString *)path; /*! @brief 获取给定的key值,返回类型为NSMutableArray @param path:给定的路径 @param otherwise:默认值,当找不到给定的obj,返回otherwise @return key值 or otherwise */ - (NSMutableArray *)mutableArrayAtPath:(NSString *)path otherwise:(NSMutableArray *)other; //有类型检查的获取NSDictionary类型 否则返回other /*! @brief 通过给定的path获取NSDictionary @param path:给定的路径 @return key值 or nil */ - (NSDictionary *)dictAtPath:(NSString *)path; /*! @brief 通过给定的path获取NSDictionary @param path:给定的路径 @param otherwise:默认值,当找不到给定的obj,返回otherwise @return key值 or otherwise */ - (NSDictionary *)dictAtPath:(NSString *)path otherwise:(NSDictionary *)other; /*! @brief 通过给定的path获取NSMutableDictionary @param path:给定的路径 @return key值 or nil */ - (NSMutableDictionary *)mutableDictAtPath:(NSString *)path; /*! @brief 通过给定的path获取NSMutableDictionary @param path:给定的路径 @param otherwise:默认值,当找不到给定的obj,返回otherwise @return key值 or otherwise */ - (NSMutableDictionary *)mutableDictAtPath:(NSString *)path otherwise:(NSMutableDictionary *)other; /*! @brief 将当前数据转换为NSData,包含编码格式 @return NSData类型的数据 */ -(NSData*)data; @end #pragma mark NSMutableDictionary接口 ///NSMutableDictionary接口 @interface NSMutableDictionary (IDPExtension) /*! @brief 安全添加键值对 @param anObject: value @param forKey:key */ - (void)safeSetObject:(id)anObject forKey:(id<NSCopying>)aKey; /*! @brief 安全添加键值对 @param anObject: value @param forKey:key */ - (void)safeSetObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey; /*! @brief 安全移除key @param forKey:key */ - (void)safeRemoveObjectForKey:(id)aKey; @end
HarrisLee/Utils
MySampleCode-master/load/load/Parent.h
<filename>MySampleCode-master/load/load/Parent.h<gh_stars>0 // // Parent.h // load // // Created by 张星宇 on 16/2/1. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> @interface Parent : NSObject @end
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/EOCSmithPerson.h
// // EOCSmithPerson.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/24. // Copyright © 2016年 zxy. All rights reserved. // #import "EOCPerson.h" @interface EOCSmithPerson : EOCPerson @end
HarrisLee/Utils
UniversalApp-master/MiAiApp/Define/ThirdMacros.h
<gh_stars>0 // // ThirdMacros.h // MiAiApp // // Created by 徐阳 on 2017/5/18. // Copyright © 2017年 徐阳. All rights reserved. // #ifndef ThirdMacros_h #define ThirdMacros_h #endif /* ThirdMacros_h */
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtBaseModel/KtBaseModel.h
// // KtBaseModel.h // KtTableView // // Created by bestswifter on 16/5/13. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> #import "KtBaseServerAPI.h" #import "KtBaseItem.h" @class KtBaseModel; /*! @brief 用于KtBaseModel回调的block定义 */ typedef void(^KtModelBlock)(KtBaseModel *); @interface KtBaseModel : NSObject //自动解析的数据类型 可能在不同线程访问 因此设置为 atomic @property (assign,atomic) Class parseDataClassType; // 回调函数 @property (nonatomic, copy) KtModelBlock completionBlock; //网络请求 @property (nonatomic,retain) KtBaseServerAPI *serverApi; //网络请求参数 @property (nonatomic,retain) NSDictionary *params; //请求地址 需要在子类init中初始化 @property (nonatomic,copy) NSString *address; - (instancetype)initWithAddress:(NSString *)address; - (void)handleParsedData:(KtBaseItem *)parsedData; - (void)loadWithShortConnection; - (void)loadWithLongConnection; - (void)refresh; - (void)cancel; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtExtension/UIView+KtExtension.h
<gh_stars>0 // // UIView+KtExtension.h // KtTableView // // Created by bestswifter on 16/4/13. // Copyright © 2016年 zxy. All rights reserved. // #import <UIKit/UIKit.h> @interface UIView (KtExtension) //frame accessors /*! @brief 初始坐标 */ @property (nonatomic, assign) CGPoint origin; /*! @brief View大小 */ @property (nonatomic, assign) CGSize size; /*! @brief 顶部坐标值 */ @property (nonatomic, assign) CGFloat top; /*! @brief 左部坐标值 */ @property (nonatomic, assign) CGFloat left; /*! @brief 底部坐标值 */ @property (nonatomic, assign) CGFloat bottom; /*! @brief 右部坐标值 */ @property (nonatomic, assign) CGFloat right; /*! @brief 宽度值 */ @property (nonatomic, assign) CGFloat width; /*! @brief 高度值 */ @property (nonatomic, assign) CGFloat height; /*! @brief 中心点X坐标 */ @property (nonatomic, assign) CGFloat x; /*! @brief 中心点Y坐标 */ @property (nonatomic, assign) CGFloat y; //bounds accessors /*! @brief 边界大小 */ @property (nonatomic, assign) CGSize boundsSize; /*! @brief 边界宽度 */ @property (nonatomic, assign) CGFloat boundsWidth; /*! @brief 边界高度 */ @property (nonatomic, assign) CGFloat boundsHeight; //content getters /*! @brief 边界区域 */ @property (nonatomic, readonly) CGRect contentBounds; /*! @brief 边界中心点 */ @property (nonatomic, readonly) CGPoint contentCenter; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtBaseModel/KtBaseListModel/KtBaseListItem.h
<filename>MySampleCode-master/KtTableView/KtTableView/KtBaseModel/KtBaseListModel/KtBaseListItem.h // // KtBaseListItem.h // KtTableView // // Created by bestswifter on 16/5/18. // Copyright © 2016年 zxy. All rights reserved. // #import "KtBaseItem.h" @interface KtBaseListItem : KtBaseItem //@property (nonatomic, assign) int hasNext; //@property (nonatomic, assign) int hasPrev; @property (nonatomic, assign) int pageNumber; // 为了简化问题,我们让客户端直接传这个值,其实应该用上面两个。 @end
HarrisLee/Utils
MySampleCode-master/Enum/Enum/OCEnum.h
// // OCEnum.m // Enum // // Created by 张星宇 on 16/1/12. // Copyright © 2016年 张星宇. All rights reserved. // #import <Foundation/Foundation.h> typedef NS_ENUM(NSInteger, MyEnum) { //以下是枚举成员 ValueA = 1, // 如果不写值,默认为1,这是枚举的原始值 ValueB, // 默认是ValueA的值加1 ValueC, // 默认是ValueB的值加1,以此类推 ValueD };
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/Enum.h
// // Enum.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/24. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> @interface Enum : NSObject @end
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/EOCPerson.h
<reponame>HarrisLee/Utils // // EOCPerson.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/24. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> // 引入这行代码会导致两个头文件互相引用 //#import "EOCEmployer.h" @class EOCEmployee; // 不要在头文件中使用 static,否则会变成全局变量,放在实现文件里面即可 static const int ANIMATION_DURATION = 1; static int ANOTHER_DURATION = 2; static void * const EOCMyKey = @"EOCMyKey"; FOUNDATION_EXPORT NSString *const EOCStringConstant; @interface EOCPerson : NSObject<NSCopying> @property (nonatomic, copy) NSString *firstName; @property (nonatomic, copy) NSString *lastName; @property (nonatomic, strong) EOCEmployee *employee; @end
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/EOCEmployeeFinance.h
// // EOCEmployeeFinance.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/25. // Copyright © 2016年 zxy. All rights reserved. // #import "EOCEmployee.h" @interface EOCEmployeeFinance : EOCEmployee @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtBaseModel/KtBaseServerAPI.h
// // KtBaseServerAPI.h // KtTableView // // Created by bestswifter on 16/5/13. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> #import "AFNetworking.h" /*! @brief API访问的处理状态,IDPServerAPI.state */ typedef enum { KT_PROC_STAT_CREATED = 1, KT_PROC_STAT_LOADING, KT_PROC_STAT_SUCCEED, KT_PROC_STAT_FAILED, KT_PROC_STAT_CANCELLED } KtProcessStateEnum; /*! @brief Http请求方法 @discussion POST方法 @discussion GET方法ß */ typedef enum { KT_REQUEST_POST, // POST方法 KT_REQUEST_GET, // GET方法 } KtHttpRequestMethod; // ServerAPI 的回调 @class KtBaseServerAPI; typedef void(^KtServerAPICompletionBlock)(KtBaseServerAPI *); @interface KtBaseServerAPI : NSObject @property (nonatomic, strong) AFHTTPSessionManager *manager; // request @property (nonatomic, readonly) NSString *server; // 形如 www.address.of.api,可兼容前面带“http://”、以及后面带“/”的情况 @property (nonatomic, copy) NSString *api; // 形如 /some/api/to/access,可兼容前面不带“/”的情况 @property (nonatomic, readonly) NSDictionary *reqParams; // 请求参数 @property (nonatomic, readonly) NSDictionary *files; // 请求文件 @property (nonatomic, copy) KtServerAPICompletionBlock userBlock; // serverapi回调的block // response @property (nonatomic, retain) NSError *error; // code为IDPErrorEnum类型,服务器返回存放在userInfo的errno和errmsg里 @property (nonatomic, retain) NSDictionary *jsonData; // 解析出的JSON @property (nonatomic, retain) NSData *rawData; // 原始data,用于二进制结果 @property (nonatomic, readonly, copy) NSString *rawString; // 原始字符串,用于文本结果,lazyloading @property (nonatomic, retain) id protobufParserData; // 服务器返回的protobuf解析后的数据 // state @property (nonatomic, assign) KtProcessStateEnum state; // 性能信息 @property (nonatomic, readonly) CFTimeInterval startTime; // 请求发起时间 @property (nonatomic, readonly) CFTimeInterval netCost; // 网络耗时 - (id)initWithServer:(NSString *)server; /*! @brief 访问API,子类不需要重载 @discussion 本方法可重复调用,会自动中止当前请求(但并不调用用户回调) @discussion 回调调用时机:请求失败、请求被中止、请求成功 @discussion 回调一般是根据state访问error或者parsedData,并关掉菊花 @param api 形如 /some/api/to/access,可兼容前面不带“/”的情况 @param params 参数 @param files 文件 @param requestMethod KtHttpRequestMethod(GET/POST) @param block KtServerAPICompletionBlock 回调 */ - (void)accessAPI:(NSString *)api WithParams:(NSDictionary *)params files:(NSDictionary *)files requestMethod:(KtHttpRequestMethod)method completionBlock:(KtServerAPICompletionBlock)block; /*! @brief 访问API,子类不需要重载 (DEFAULT POST METHOD) @param api 形如 /some/api/to/access,可兼容前面不带“/”的情况 @param params 参数 @param files 文件 @param block KtServerAPICompletionBlock 回调 */ - (void)accessAPI:(NSString *)api WithParams:(NSDictionary *)params files:(NSDictionary *)files completionBlock:(KtServerAPICompletionBlock)block; /*! @brief 访问API, 省略files参数的版本 @param api 形如 /some/api/to/access,可兼容前面不带“/”的情况 @param params 参数 @param block KtServerAPICompletionBlock 回调 */ - (void)accessAPI:(NSString *)api WithParams:(NSDictionary *)params completionBlock:(KtServerAPICompletionBlock)block; - (void)cancel; - (void)refresh; @end
HarrisLee/Utils
MySampleCode-master/Effective OC/EffectiveObjectiveC/EffectiveObjectiveC/EOCEmployee.h
<reponame>HarrisLee/Utils // // EOCEmployee.h // EffectiveObjectiveC // // Created by 张星宇 on 16/3/24. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> #import "EOCPerson.h" typedef NS_ENUM(NSUInteger, EOCEmployeeType) { EOCEmployeeTypeDeveloper, EOCEmployeeTypeDesigner, EOCEmployeeTypeFinance, }; @interface EOCEmployee : NSObject <NSCopying> - (void) addEmployee:(EOCPerson *)person; - (void) doSomeWork; + (EOCEmployee *)employeeWithType:(EOCEmployeeType)type; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtBaseModel/KtBaseListModel/KtRefreshTableViewController.h
// // KtRefreshTableViewController.h // KtTableView // // Created by bestswifter on 16/5/20. // Copyright © 2016年 zxy. All rights reserved. // #import "KtTableViewController.h" #import "KtBaseListModel.h" @interface KtRefreshTableViewController : KtTableViewController<KtBaseListModelProtocol> @property (nonatomic, strong) KtBaseListModel *listModel; - (void)requestDidSuccess; // 子类请求完成后的处理方法。 @end
HarrisLee/Utils
MySampleCode-master/CocoaPodsDemo/BSStaticLibraryOne/BSStaticLibraryTwo/BSStaticLibraryTwo.h
// // BSStaticLibraryTwo.h // BSStaticLibraryTwo // // Created by 张星宇 on 2017/1/8. // Copyright © 2017年 bestswifter. All rights reserved. // #import <Foundation/Foundation.h> @interface BSStaticLibraryTwo : NSObject - (void)saySomething; @end
HarrisLee/Utils
MySampleCode-master/runtime/runtime/MethodForwardTest.h
<gh_stars>0 // // MyTest.h // runtime // // Created by 张星宇 on 16/1/2. // Copyright © 2016年 张星宇. All rights reserved. // #import <Foundation/Foundation.h> @interface MethodForwardTest : NSObject - (void)test; @end
HarrisLee/Utils
MySampleCode-master/KtTableView/KtTableView/KtMainTableViewCell.h
<filename>MySampleCode-master/KtTableView/KtTableView/KtMainTableViewCell.h // // KtMainTableViewCell.h // KtTableView // // Created by bestswifter on 16/4/13. // Copyright © 2016年 zxy. All rights reserved. // #import <UIKit/UIKit.h> #import "KtBaseTableViewCell.h" @interface KtMainTableViewCell : KtBaseTableViewCell @end
HarrisLee/Utils
MySampleCode-master/CornerRadius/CornerRadius/UIImage+ImageRoundedCorner.h
<filename>MySampleCode-master/CornerRadius/CornerRadius/UIImage+ImageRoundedCorner.h // // UIImage+ImageRoundedCorner.h // CornerRadius // // Created by 张星宇 on 16/3/3. // Copyright © 2016年 zxy. All rights reserved. // #import <UIKit/UIKit.h> @interface UIImage (ImageRoundedCorner) - (UIImage*)imageAddCornerWithRadius:(CGFloat)radius andSize:(CGSize)size; @end
HarrisLee/Utils
MySampleCode-master/load/load/Other.h
// // Normal.h // load // // Created by 张星宇 on 16/2/1. // Copyright © 2016年 zxy. All rights reserved. // #import <Foundation/Foundation.h> @interface Other : NSObject + (void)printName; - (void)originalFunc; @end
Paperized/ChonkyNumber
src/ChonkyNumber.h
<reponame>Paperized/ChonkyNumber #pragma once #include <string> #include <vector> constexpr const char* IRREGULAR_OPERATION = "NaN"; //Check if the two ChonkyNumbers are not a number, if yes set the output as irregular and return #define RETURN_IF_NAN_OPERANDS(num1, num2, output) if(!num1.m_IsNumber || !num2.m_IsNumber) \ { \ output->SetAsIrregular(); \ return; \ } //Check if it's not a number, if yes set the output as irregular and return #define RETURN_IF_NAN_OPERAND(num1, output) if(!num1.m_IsNumber) \ { \ output->SetAsIrregular(); \ return; \ } /* BigNumber class to compute Integer arbitrary-precision math */ class ChonkyNumber { public: //Instantiate a ChonkyNumber with default value 0 ChonkyNumber(); //Instantiate a ChonkyNumber with a string ChonkyNumber(std::string& number); //Instantiate a ChonkyNumber with a string ChonkyNumber(std::string&&); //Instantiate a ChonkyNumber with a char array ChonkyNumber(const char*); //Instantiate a ChonkyNumber with a long long int ChonkyNumber(long long int); //Instantiate a ChonkyNumber with a long int ChonkyNumber(long int); //Instantiate a ChonkyNumber with a int ChonkyNumber(int); ~ChonkyNumber(); //Change the current value with another ChonkyNumber void ChangeValue(ChonkyNumber&); //Change the current value with a str inline void ChangeValue(std::string& str) { if (ChonkyNumber::IsNumber(str)) ChangeValue(str, true); else { std::string n = IRREGULAR_OPERATION; ChangeValue(n, true); } } //Change the current value with a char array inline void ChangeValue(const char* c_arr) { std::string str = c_arr; ChangeValue(c_arr); } //Change the current value with a char array inline void ChangeValue(std::string&& str) { ChangeValue(str); } //Change the current value with a long long int inline void ChangeValue(long long int num) { std::string str = std::to_string(num); ChangeValue(str, true); } //Change the current value with a long int inline void ChangeValue(long int num) { std::string str = std::to_string(num); ChangeValue(str, true); } //Change the current value with an int inline void ChangeValue(int num) { std::string str = std::to_string(num); ChangeValue(str, true); } //Return true if number inline bool IsNaN () { return !m_IsNumber; } //Return true if even inline bool IsEven() { return m_IsNumber && ((m_Number[m_Number.size() - 1] - 48) % 2 == 0); } //Return true if odd inline bool IsOdd() { return m_IsNumber && ((m_Number[m_Number.size() - 1] - 48) % 2 != 1); } //Return true if prime bool IsPrime() const; //Set the current value as irregular or NaN, usefull when computing an irregular operation void SetAsIrregular(); //Stringify the current value std::string AsString() const; //Get the current value's digits size inline int DigitsSize() const { return m_Number.size(); } //Negate the current number and return a reference of it inline ChonkyNumber& Negate() { m_IsNegative = !m_IsNegative; return *this; } //Sum another ChonkyNumber and return a reference of the first ChonkyNumber& operator+=(const ChonkyNumber& num); //Subtract another ChonkyNumber and return a reference of the first ChonkyNumber& operator-=(const ChonkyNumber& num); //Multiply another ChonkyNumber and return a reference of the first ChonkyNumber& operator*=(const ChonkyNumber& num); //Divide another ChonkyNumber and return a reference of the first ChonkyNumber& operator/=(const ChonkyNumber& num); //Prefix increment, returns a reference of the number ChonkyNumber& operator++(); //Prefix decrement, returns a reference of the number ChonkyNumber& operator--(); //Postfix increment, returns a new value of the number ChonkyNumber operator++(int); //Postfix decrement, returns a new value of the number ChonkyNumber operator--(int); //Equal compare two ChonkyNumber friend inline bool operator==(const ChonkyNumber& num1, const ChonkyNumber& num2) { return num1.m_Number.compare(num2.m_Number) == 0 && num1.m_IsNegative == num2.m_IsNegative; } //Major compare two ChonkyNumber friend inline bool operator>(const ChonkyNumber& num1, const ChonkyNumber& num2) { return (num1.m_IsNegative <= num2.m_IsNegative) && ChonkyNumber::HasBiggerDigits(num1, num2); } //Less compare two ChonkyNumber friend inline bool operator<(const ChonkyNumber& num1, const ChonkyNumber& num2) { return (num1.m_IsNegative >= num2.m_IsNegative) && ChonkyNumber::HasBiggerDigits(num2, num1); } //Major or equals compare two ChonkyNumber friend inline bool operator>=(const ChonkyNumber& num1, const ChonkyNumber& num2) { return (num1.m_IsNegative <= num2.m_IsNegative) && ChonkyNumber::HasBiggerOrEqualDigits(num1, num2); } //Less or equals compare two ChonkyNumber friend inline bool operator<=(const ChonkyNumber& num1, const ChonkyNumber& num2) { return (num1.m_IsNegative >= num2.m_IsNegative) && ChonkyNumber::HasBiggerOrEqualDigits(num1, num2); } //Sum two ChonkyNumber and return a new value friend ChonkyNumber operator+(const ChonkyNumber&, const ChonkyNumber&); //Subtract two ChonkyNumber and return a new value friend ChonkyNumber operator-(const ChonkyNumber&, const ChonkyNumber&); //Multiply two ChonkyNumber and return a new value friend ChonkyNumber operator*(const ChonkyNumber&, const ChonkyNumber&); //Divide two ChonkyNumber and return a new value friend ChonkyNumber operator/(const ChonkyNumber&, const ChonkyNumber&); //Pow a ChonkyNumber with it's exponent and return a new value friend ChonkyNumber operator^(const ChonkyNumber&, int); //Module a ChonkyNumber with it's module and return a new value friend ChonkyNumber operator%(const ChonkyNumber&, int); friend inline std::ostream& operator<<(std::ostream& os, const ChonkyNumber& num) { os << num.AsString(); return os; } //Check if the number (sign ignored) of first ChonkyNumber it's bigger than the second inline static bool HasBiggerDigits(const ChonkyNumber& num1, const ChonkyNumber& num2) { return (num1.DigitsSize() > num2.DigitsSize()) || (num1.DigitsSize() == num2.DigitsSize() && num1.m_Number.compare(num2.m_Number) > 0); } //Check if the number (sign ignored) of first ChonkyNumber it's bigger or equals than the second inline static bool HasBiggerOrEqualDigits(const ChonkyNumber& num1, const ChonkyNumber& num2) { return (num1.DigitsSize() > num2.DigitsSize()) || (num1.DigitsSize() == num2.DigitsSize() && num1.m_Number.compare(num2.m_Number) >= 0); } //Add two ChonkyNumber and output the result to the pointer argument static void Add(ChonkyNumber&, ChonkyNumber&, ChonkyNumber*); //Add all ChonkyNumber inside a vector and output the result to the pointer argument static void AddAll(std::vector<ChonkyNumber>&, ChonkyNumber*); //Subtract two ChonkyNumber and output the result to the pointer argument static void Subtract(ChonkyNumber&, ChonkyNumber&, ChonkyNumber*); //Multiply two ChonkyNumber and output the result to the pointer argument static void Multiply(ChonkyNumber&, ChonkyNumber&, ChonkyNumber*); //Divide two ChonkyNumber and output the result to the pointer argument static void Divide(ChonkyNumber&, ChonkyNumber&, ChonkyNumber*); //Pow a ChonkyNumber by it's exponent and output the result to the pointer argument static void Pow(ChonkyNumber&, int, ChonkyNumber*); //Module a ChonkyNumber by it's module and output the result to the pointer argument static void Module(ChonkyNumber&, int, ChonkyNumber*); //Check if the string it's an actual integer number static bool IsNumber(std::string& str); private: //Assign the string value as the number of this ChonkyNumber, bool value ignores any sign change void ChangeValue(std::string&, bool); private: //String rappresentation of the number (without sign) std::string m_Number; //Sign of the number bool m_IsNegative; //Check if it's an actual number bool m_IsNumber; };
mcuhq/pic16f1829-bluetooth-example
mcc_generated_files/tmr4.h
/** TMR4 Generated Driver API Header File @Company Microchip Technology Inc. @File Name tmr4.h @Summary This is the generated header file for the TMR4 driver using MPLAB(c) Code Configurator @Description This header file provides APIs for TMR4. Generation Information : Product Revision : MPLAB(c) Code Configurator - v3.00 Device : PIC16F1829 Driver Version : 2.00 The generated drivers are tested against the following: Compiler : XC8 1.35 MPLAB : MPLAB X 3.20 */ /* Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved. Microchip licenses to you the right to use, modify, copy and distribute Software only when embedded on a Microchip microcontroller or digital signal controller that is integrated into your product or third party product (pursuant to the sublicense terms in the accompanying license agreement). You should refer to the license agreement accompanying this Software for additional information regarding your rights and obligations. SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. */ #ifndef _TMR4_H #define _TMR4_H /** Section: Included Files */ #include <stdint.h> #include <stdbool.h> #ifdef __cplusplus // Provide C++ Compatibility extern "C" { #endif /** Section: Macro Declarations */ #define TMR4_INTERRUPT_TICKER_FACTOR 10500 /** Section: TMR4 APIs */ /** @Summary Initializes the TMR4 module. @Description This function initializes the TMR4 Registers. This function must be called before any other TMR4 function is called. @Preconditions None @Param None @Returns None @Comment @Example <code> main() { // Initialize TMR4 module TMR4_Initialize(); // Do something else... } </code> */ void TMR4_Initialize(void); /** @Summary This function starts the TMR4. @Description This function starts the TMR4 operation. This function must be called after the initialization of TMR4. @Preconditions Initialize the TMR4 before calling this function. @Param None @Returns None @Example <code> // Initialize TMR4 module // Start TMR4 TMR4_StartTimer(); // Do something else... </code> */ void TMR4_StartTimer(void); /** @Summary This function stops the TMR4. @Description This function stops the TMR4 operation. This function must be called after the start of TMR4. @Preconditions Initialize the TMR4 before calling this function. @Param None @Returns None @Example <code> // Initialize TMR4 module // Start TMR4 TMR4_StartTimer(); // Do something else... // Stop TMR4; TMR4_StopTimer(); </code> */ void TMR4_StopTimer(void); /** @Summary Reads the TMR4 register. @Description This function reads the TMR4 register value and return it. @Preconditions Initialize the TMR4 before calling this function. @Param None @Returns This function returns the current value of TMR4 register. @Example <code> // Initialize TMR4 module // Start TMR4 TMR4_StartTimer(); // Read the current value of TMR4 if(0 == TMR4_ReadTimer()) { // Do something else... // Reload the TMR value TMR4_Reload(); } </code> */ uint8_t TMR4_ReadTimer(void); /** @Summary Writes the TMR4 register. @Description This function writes the TMR4 register. This function must be called after the initialization of TMR4. @Preconditions Initialize the TMR4 before calling this function. @Param timerVal - Value to write into TMR4 register. @Returns None @Example <code> #define PERIOD 0x80 #define ZERO 0x00 while(1) { // Read the TMR4 register if(ZERO == TMR4_ReadTimer()) { // Do something else... // Write the TMR4 register TMR4_WriteTimer(PERIOD); } // Do something else... } </code> */ void TMR4_WriteTimer(uint8_t timerVal); /** @Summary Load value to Period Register. @Description This function writes the value to PR4 register. This function must be called after the initialization of TMR4. @Preconditions Initialize the TMR4 before calling this function. @Param periodVal - Value to load into TMR4 register. @Returns None @Example <code> #define PERIOD1 0x80 #define PERIOD2 0x40 #define ZERO 0x00 while(1) { // Read the TMR4 register if(ZERO == TMR4_ReadTimer()) { // Do something else... if(flag) { flag = 0; // Load Period 1 value TMR4_LoadPeriodRegister(PERIOD1); } else { flag = 1; // Load Period 2 value TMR4_LoadPeriodRegister(PERIOD2); } } // Do something else... } </code> */ void TMR4_LoadPeriodRegister(uint8_t periodVal); /** @Summary Timer Interrupt Service Routine @Description Timer Interrupt Service Routine is called by the Interrupt Manager. @Preconditions Initialize the TMR4 module with interrupt before calling this isr. @Param None @Returns None */ void TMR4_ISR(void); /** @Summary CallBack function @Description This function is called from the timer ISR. User can write your code in this function. @Preconditions Initialize the TMR4 module with interrupt before calling this function. @Param None @Returns None */ void TMR4_CallBack(void); /** @Summary Set Timer Interrupt Handler @Description This sets the function to be called during the ISR @Preconditions Initialize the TMR4 module with interrupt before calling this. @Param Address of function to be set @Returns None */ void TMR4_SetInterruptHandler(void *InterruptHandler); /** @Summary Timer Interrupt Handler @Description This is a function pointer to the function that will be called during the ISR @Preconditions Initialize the TMR4 module with interrupt before calling this isr. @Param None @Returns None */ void (*TMR4_InterruptHandler)(void); /** @Summary Default Timer Interrupt Handler @Description This is the default Interrupt Handler function @Preconditions Initialize the TMR4 module with interrupt before calling this isr. @Param None @Returns None */ void TMR4_DefaultInterruptHandler(void); #ifdef __cplusplus // Provide C++ Compatibility } #endif #endif // _TMR4_H /** End of File */
mcuhq/pic16f1829-bluetooth-example
mcc_generated_files/tmr4.c
<reponame>mcuhq/pic16f1829-bluetooth-example /** TMR4 Generated Driver File @Company Microchip Technology Inc. @File Name tmr4.c @Summary This is the generated driver implementation file for the TMR4 driver using MPLAB(c) Code Configurator @Description This source file provides APIs for TMR4. Generation Information : Product Revision : MPLAB(c) Code Configurator - v3.00 Device : PIC16F1829 Driver Version : 2.00 The generated drivers are tested against the following: Compiler : XC8 1.35 MPLAB : MPLAB X 3.20 */ /* Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved. Microchip licenses to you the right to use, modify, copy and distribute Software only when embedded on a Microchip microcontroller or digital signal controller that is integrated into your product or third party product (pursuant to the sublicense terms in the accompanying license agreement). You should refer to the license agreement accompanying this Software for additional information regarding your rights and obligations. SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. */ /** Section: Included Files */ #include <xc.h> #include "tmr4.h" /** Section: TMR4 APIs */ void TMR4_Initialize(void) { // Set TMR4 to the options selected in the User Interface // T4CKPS 1:64; T4OUTPS 1:1; TMR4ON off; T4CON = 0x03; // PR4 5; PR4 = 0x05; // TMR4 0; TMR4 = 0x00; // Clearing IF flag before enabling the interrupt. PIR3bits.TMR4IF = 0; // Enabling TMR4 interrupt. PIE3bits.TMR4IE = 1; // Set Default Interrupt Handler TMR4_SetInterruptHandler(TMR4_DefaultInterruptHandler); // Start TMR4 TMR4_StartTimer(); } void TMR4_StartTimer(void) { // Start the Timer by writing to TMRxON bit T4CONbits.TMR4ON = 1; } void TMR4_StopTimer(void) { // Stop the Timer by writing to TMRxON bit T4CONbits.TMR4ON = 0; } uint8_t TMR4_ReadTimer(void) { uint8_t readVal; readVal = TMR4; return readVal; } void TMR4_WriteTimer(uint8_t timerVal) { // Write to the Timer4 register TMR4 = timerVal; } void TMR4_LoadPeriodRegister(uint8_t periodVal) { PR4 = periodVal; } void TMR4_ISR(void) { static volatile unsigned int CountCallBack = 0; // clear the TMR4 interrupt flag PIR3bits.TMR4IF = 0; // callback function - called every 10500th pass if (++CountCallBack >= TMR4_INTERRUPT_TICKER_FACTOR) { // ticker function call TMR4_CallBack(); // reset ticker counter CountCallBack = 0; } } void TMR4_CallBack(void) { // Add your custom callback code here // this code executes every TMR4_INTERRUPT_TICKER_FACTOR periods of TMR4 if(TMR4_InterruptHandler) { TMR4_InterruptHandler(); } } void TMR4_SetInterruptHandler(void* InterruptHandler){ TMR4_InterruptHandler = InterruptHandler; } void TMR4_DefaultInterruptHandler(void){ // add your TMR4 interrupt custom code // or set custom function using TMR4_SetInterruptHandler() } /** End of File */
mcuhq/pic16f1829-bluetooth-example
mcc_generated_files/eusart.h
<gh_stars>0 /** EUSART Generated Driver API Header File @Company Microchip Technology Inc. @File Name eusart.h @Summary This is the generated header file for the EUSART driver using MPLAB(c) Code Configurator @Description This header file provides APIs for driver for EUSART. Generation Information : Product Revision : MPLAB(c) Code Configurator - v3.00 Device : PIC16F1829 Driver Version : 2.00 The generated drivers are tested against the following: Compiler : XC8 1.35 MPLAB : MPLAB X 3.20 */ /* Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved. Microchip licenses to you the right to use, modify, copy and distribute Software only when embedded on a Microchip microcontroller or digital signal controller that is integrated into your product or third party product (pursuant to the sublicense terms in the accompanying license agreement). You should refer to the license agreement accompanying this Software for additional information regarding your rights and obligations. SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. */ #ifndef _EUSART_H #define _EUSART_H /** Section: Included Files */ #include <xc.h> #include <stdbool.h> #include <stdint.h> #ifdef __cplusplus // Provide C++ Compatibility extern "C" { #endif /** Section: Macro Declarations */ #define EUSART_DataReady (eusartRxCount) /** Section: Data Type Definitions */ /** Section: Global variables */ extern volatile uint8_t eusartTxBufferRemaining; extern volatile uint8_t eusartRxCount; /** Section: EUSART APIs */ /** @Summary Initialization routine that takes inputs from the EUSART GUI. @Description This routine initializes the EUSART driver. This routine must be called before any other EUSART routine is called. @Preconditions None @Param None @Returns None @Comment @Example */ void EUSART_Initialize(void); /** @Summary Read a byte of data from the EUSART. @Description This routine reads a byte of data from the EUSART. @Preconditions EUSART_Initialize() function should have been called before calling this function. The transfer status should be checked to see if the receiver is not empty before calling this function. EUSART_DataReady is a macro which checks if any byte is received. Call this macro before using this function. @Param None @Returns A data byte received by the driver. @Example <code> void main(void) { // initialize the device SYSTEM_Initialize(); uint8_t data; // Enable the Global Interrupts INTERRUPT_GlobalInterruptEnable(); // Enable the Peripheral Interrupts INTERRUPT_PeripheralInterruptEnable(); printf("\t\tTEST CODE\n\r"); //Enable redirect STDIO to USART before using printf statements printf("\t\t---- ----\n\r"); printf("\t\tECHO TEST\n\r"); printf("\t\t---- ----\n\n\r"); printf("Enter any string: "); do{ data = EUSART1_Read(); // Read data received EUSART_Write(data); // Echo back the data received }while(!EUSART1_DataReady); //check if any data is received } </code> */ uint8_t EUSART_Read(void); /** @Summary Writes a byte of data to the EUSART. @Description This routine writes a byte of data to the EUSART. @Preconditions EUSART_Initialize() function should have been called before calling this function. The transfer status should be checked to see if transmitter is not busy before calling this function. @Param txData - Data byte to write to the EUSART @Returns None @Example <code> Refer to EUSART_Read() for an example </code> */ void EUSART_Write(uint8_t txData); /** @Summary Maintains the driver's transmitter state machine and implements its ISR. @Description This routine is used to maintain the driver's internal transmitter state machine.This interrupt service routine is called when the state of the transmitter needs to be maintained in a non polled manner. @Preconditions EUSART_Initialize() function should have been called for the ISR to execute correctly. @Param None @Returns None */ void EUSART_Transmit_ISR(void); /** @Summary Maintains the driver's receiver state machine and implements its ISR @Description This routine is used to maintain the driver's internal receiver state machine.This interrupt service routine is called when the state of the receiver needs to be maintained in a non polled manner. @Preconditions EUSART_Initialize() function should have been called for the ISR to execute correctly. @Param None @Returns None */ void EUSART_Receive_ISR(void); #ifdef __cplusplus // Provide C++ Compatibility } #endif #endif // _EUSART_H /** End of File */
mcuhq/pic16f1829-bluetooth-example
main.c
<filename>main.c<gh_stars>0 /** Generated Main Source File Company: Microchip Technology Inc. File Name: main.c Summary: This is the main file generated using MPLAB(c) Code Configurator Description: This header file provides implementations for driver APIs for all modules selected in the GUI. Generation Information : Product Revision : MPLAB(c) Code Configurator - v3.00 Device : PIC16F1829 Driver Version : 2.00 The generated drivers are tested against the following: Compiler : XC8 1.35 MPLAB : MPLAB X 3.20 */ #include "mcc_generated_files/mcc.h" /* Main application */ //#include "stdio.h" #include <stdio.h> // used for printf #include <xc.h> // regsiter mappings void putch(char d); // the 'printf' function uses this for its printing. // we are going to override it so it prints to the UART static void uartWrite(char d); // function for printing one character at a time void timer4ISR(); // function callback from TMR4 interrupt routine static uint32_t tmp; // global temp variable that will be sent to void main(void) { // initialize the device SYSTEM_Initialize(); // Enable the Global Interrupts INTERRUPT_GlobalInterruptEnable(); // Enable the Peripheral Interrupts INTERRUPT_PeripheralInterruptEnable(); // Create a call-back to our own implementation of a timer4 interrupt TMR4_SetInterruptHandler(timer4ISR); // pin configuration for the two LEDs ANSELCbits.ANSC0 = 0; // digital pin ANSELCbits.ANSC3 = 0; // digital pin TRISCbits.TRISC0 = 0; // output TRISCbits.TRISC3 = 0; // output WPUCbits.WPUC0 = 0; // disable weak pull-up WPUCbits.WPUC3 = 0; // disable weak pull-up __delay_ms(2000); // delay for HC-06 initialization printf("AT+NAMEmc<EMAIL>"); __delay_ms(4000); // wait for setting to take effect while (1) { if(eusartRxCount != 0){ char rxChar = EUSART_Read(); // check to see if received anything on the UART printf("\nRX: %c\n", rxChar); // if yes, echo it back if(rxChar == 'c') // if we got a `c` character, toggle an LED LATCbits.LATC3 ^= 1; // toggle this } } } void putch(char d){ uartWrite(d); } static void uartWrite(char txData){ while(0 == PIR1bits.TXIF); // wait for current byte to finish sending TXREG = txData; // Write the data byte to the USART. } // Enter here on a Timer4 rollover interrupt void timer4ISR(){ printf("%d",tmp++); // constantly write this to connected device LATCbits.LATC0 ^= 1; } /** End of File */
mcuhq/pic16f1829-bluetooth-example
mcc_generated_files/eusart.c
/** EUSART Generated Driver File @Company Microchip Technology Inc. @File Name eusart.c @Summary This is the generated driver implementation file for the EUSART driver using MPLAB(c) Code Configurator @Description This header file provides implementations for driver APIs for EUSART. Generation Information : Product Revision : MPLAB(c) Code Configurator - v3.00 Device : PIC16F1829 Driver Version : 2.00 The generated drivers are tested against the following: Compiler : XC8 1.35 MPLAB : MPLAB X 3.20 */ /* Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved. Microchip licenses to you the right to use, modify, copy and distribute Software only when embedded on a Microchip microcontroller or digital signal controller that is integrated into your product or third party product (pursuant to the sublicense terms in the accompanying license agreement). You should refer to the license agreement accompanying this Software for additional information regarding your rights and obligations. SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. */ /** Section: Included Files */ #include "eusart.h" /** Section: Macro Declarations */ #define EUSART_TX_BUFFER_SIZE 8 #define EUSART_RX_BUFFER_SIZE 8 /** Section: Global Variables */ static uint8_t eusartTxHead = 0; static uint8_t eusartTxTail = 0; static uint8_t eusartTxBuffer[EUSART_TX_BUFFER_SIZE]; volatile uint8_t eusartTxBufferRemaining; static uint8_t eusartRxHead = 0; static uint8_t eusartRxTail = 0; static uint8_t eusartRxBuffer[EUSART_RX_BUFFER_SIZE]; volatile uint8_t eusartRxCount; /** Section: EUSART APIs */ void EUSART_Initialize(void) { // disable interrupts before changing states PIE1bits.RCIE = 0; PIE1bits.TXIE = 0; // Set the EUSART module to the options selected in the user interface. // ABDOVF no_overflow; SCKP Non-Inverted; BRG16 16bit_generator; WUE disabled; ABDEN disabled; BAUDCON = 0x08; // SPEN enabled; RX9 8-bit; CREN enabled; ADDEN disabled; SREN disabled; RCSTA = 0x90; // TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC slave; TXSTA = 0x24; // Baud Rate = 9600; SPBRGL 64; SPBRGL = 0x40; // Baud Rate = 9600; SPBRGH 3; SPBRGH = 0x03; // initializing the driver state eusartTxHead = 0; eusartTxTail = 0; eusartTxBufferRemaining = sizeof(eusartTxBuffer); eusartRxHead = 0; eusartRxTail = 0; eusartRxCount = 0; // enable receive interrupt PIE1bits.RCIE = 1; } uint8_t EUSART_Read(void) { uint8_t readValue = 0; while(0 == eusartRxCount) { } PIE1bits.RCIE = 0; readValue = eusartRxBuffer[eusartRxTail++]; if(sizeof(eusartRxBuffer) <= eusartRxTail) { eusartRxTail = 0; } eusartRxCount--; PIE1bits.RCIE = 1; return readValue; } void EUSART_Write(uint8_t txData) { while(0 == eusartTxBufferRemaining) { } if(0 == PIE1bits.TXIE) { TXREG = txData; } else { PIE1bits.TXIE = 0; eusartTxBuffer[eusartTxHead++] = txData; if(sizeof(eusartTxBuffer) <= eusartTxHead) { eusartTxHead = 0; } eusartTxBufferRemaining--; } PIE1bits.TXIE = 1; } void EUSART_Transmit_ISR(void) { // add your EUSART interrupt custom code if(sizeof(eusartTxBuffer) > eusartTxBufferRemaining) { TXREG = eusartTxBuffer[eusartTxTail++]; if(sizeof(eusartTxBuffer) <= eusartTxTail) { eusartTxTail = 0; } eusartTxBufferRemaining++; } else { PIE1bits.TXIE = 0; } } void EUSART_Receive_ISR(void) { if(1 == RCSTAbits.OERR) { // EUSART error - restart RCSTAbits.CREN = 0; RCSTAbits.CREN = 1; } // buffer overruns are ignored eusartRxBuffer[eusartRxHead++] = RCREG; if(sizeof(eusartRxBuffer) <= eusartRxHead) { eusartRxHead = 0; } eusartRxCount++; } /** End of File */
mcuhq/pic16f1829-bluetooth-example
mcc_generated_files/interrupt_manager.c
/** Generated Interrupt Manager Source File @Company: Microchip Technology Inc. @File Name: interrupt_manager.c @Summary: This is the Interrupt Manager file generated using MPLAB(c) Code Configurator @Description: This header file provides implementations for global interrupt handling. For individual peripheral handlers please see the peripheral driver for all modules selected in the GUI. Generation Information : Product Revision : MPLAB(c) Code Configurator - v3.00 Device : PIC16F1829 Driver Version : 1.02 The generated drivers are tested against the following: Compiler : XC8 1.35 MPLAB : MPLAB X 3.20 */ /* Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved. Microchip licenses to you the right to use, modify, copy and distribute Software only when embedded on a Microchip microcontroller or digital signal controller that is integrated into your product or third party product (pursuant to the sublicense terms in the accompanying license agreement). You should refer to the license agreement accompanying this Software for additional information regarding your rights and obligations. SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. */ #include "interrupt_manager.h" #include "mcc.h" void interrupt INTERRUPT_InterruptManager (void) { // interrupt handler if(PIE1bits.TXIE == 1 && PIR1bits.TXIF == 1) { EUSART_Transmit_ISR(); } else if(PIE1bits.RCIE == 1 && PIR1bits.RCIF == 1) { EUSART_Receive_ISR(); } else if(PIE3bits.TMR4IE == 1 && PIR3bits.TMR4IF == 1) { TMR4_ISR(); } else { //Unhandled Interrupt } } /** End of File */
frankleafy/Leafy-Lantern-source-code
Source/Server/webserver/leafy.h
<gh_stars>0 String loadHomePage(); String loadGauge(); void getQueryString(); void getSettings(); void setSettings(String, String); void startAccesPoint(); void clearSettings(); void connectToWifi(); String load404(ESP32WebServer); String loadDashboard(); void getAndSetTime(); void startTimer(); void rotateplants(); String getTimeString(); #define ANALOGLIGHTPIN1 1 // number of outgoing bytes to buffer for Serial1