Mercurial > repo
diff daoyu.c @ 7624:c803b6d4eaee
<Kaynato> mv FZQ7RLm4 daoyu.c
author | HackBot |
---|---|
date | Fri, 29 Apr 2016 01:27:51 +0000 |
parents | 49eadf845bb9 |
children | 8f18f8a9c3ba |
line wrap: on
line diff
--- a/daoyu.c Fri Apr 29 01:27:29 2016 +0000 +++ b/daoyu.c Fri Apr 29 01:27:51 2016 +0000 @@ -10,7 +10,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License -* aint with this program. If not, see <http://www.gnu.org/licenses/>. +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* @@ -22,26 +22,23 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> -#define DEFAULT_INTERPRET_CELL_LENGTH 32 #define BITS_IN_BYTE 8 -#define BITS_IN_CELL (sizeof(unsigned int) * 8) -#define BYTE_MASK 0xff +#define BITS_IN_CELL (sizeof(unsigned long) * 8) #define INPUT_DELIMITER '@' typedef struct PATH { struct PATH* owner; /* OWNER PROGRAM */ struct PATH* child; /* CHILD PROGRAM */ - unsigned int* prg_data; /* DATA */ - unsigned int prg_allocbits; /* OPEN DATA BITS*/ - unsigned int prg_index; /* INSTRUCTION POINTER*/ + unsigned long* prg_data; /* DATA */ + unsigned long prg_allocbits; /* OPEN DATA BITS*/ + unsigned long prg_index; /* INSTRUCTION POINTER*/ unsigned char prg_level; /* OPERATING LEVEL */ - unsigned int sel_length; /* LENGTH OF SELECTION*/ - unsigned int sel_index; /* INDEX OF SELECTION*/ + unsigned long sel_length; /* LENGTH OF SELECTION*/ + unsigned long sel_index; /* INDEX OF SELECTION*/ unsigned int prg_floor; /* FLOOR OF PATH */ - unsigned int prg_start; /* START OF RUNNING */ + unsigned long prg_start; /* START OF RUNNING */ } Pathstrx; typedef Pathstrx* Path; @@ -54,15 +51,15 @@ char getInput(); char algn(Path); char getChar(unsigned char); -char* bin(unsigned int); +char* bin(unsigned long); char* str_dup(char *s); -char* l_to_str(unsigned int, unsigned char, unsigned char); +char* l_to_str(unsigned long, unsigned char, unsigned char); static void skip(); -static void write_by_bit_index(Path, unsigned int, unsigned int, unsigned int); +static void write_by_bit_index(Path, unsigned long, unsigned long, unsigned long); unsigned char getNybble(char); -unsigned int read_by_bit_index(Path, unsigned int, unsigned int); -unsigned int mask(int); -unsigned int ptwo_round(unsigned int); +unsigned long read_by_bit_index(Path, unsigned long, unsigned long); +unsigned long mask(int); +unsigned long ptwo_round(unsigned long); static unsigned char command = 0; static int doloop = 1; @@ -120,7 +117,7 @@ void interpret(char* input) { - unsigned int length = 0; /* How many bytes in input */ + unsigned long length = 0; /* How many bytes in input */ /* Initialize path */ struct PATH newpath = NEW_PATH; @@ -139,8 +136,8 @@ (dao->prg_allocbits) = length * 8; /* Prevent zero-sized allocation */ - if (length % sizeof(unsigned int) != 0) - length = sizeof(unsigned int); + if (length % sizeof(unsigned long) != 0) + length = sizeof(unsigned long); /* Allocate bytes for data array */ if (((dao->prg_data) = calloc(length, 1)) == NULL) @@ -167,10 +164,10 @@ } -unsigned int ptwo_round(unsigned int x) +unsigned long ptwo_round(unsigned long x) { - unsigned int rounded = x; /* Initialize bytes_alloc with the file_size value. */ - unsigned int shift = 0; /* Shift for first one of file size for rounding */ + unsigned long rounded = x; /* Initialize bytes_alloc with the file_size value. */ + unsigned long shift = 0; /* Shift for first one of file size for rounding */ while ((rounded >> 1) != 0) /* Determine leftmost '1' bit of file size. */ { /* */ @@ -217,7 +214,7 @@ return d; /*Return new memory */ } -char* bin(unsigned int val) { return l_to_str(val, 32, 2); } +char* bin(unsigned long val) { return l_to_str(val, 32, 2); } char getChar(unsigned char ch) { @@ -225,7 +222,7 @@ return symbols[ch]; } -char* l_to_str(unsigned int val, unsigned char len, unsigned char radix) +char* l_to_str(unsigned long val, unsigned char len, unsigned char radix) { static char buf[32] = { '0' }; int i = 33; @@ -262,12 +259,12 @@ static void swaps(Path path) { unsigned int i = 0; - unsigned int report = 0; + unsigned long report = 0; levlim(1) if (P_LEN == 1) return; if (P_LEN <= BITS_IN_CELL) { - unsigned int half_len = P_LEN / 2; + unsigned long half_len = P_LEN / 2; write_by_bit_index(path, P_IND, P_LEN, read_by_bit_index(path, P_IND, half_len) | (read_by_bit_index(path, P_IND + half_len, half_len) << half_len)); return; } @@ -281,8 +278,10 @@ static void later(Path path) { - if (algn(path) || (PR_LEV >= 4)) P_IND += P_LEN; - else merge(path); + if (algn(path) || (PR_LEV >= 4)) + P_IND += P_LEN; + else + merge(path); } static void merge(Path path) @@ -304,13 +303,14 @@ static void sifts(Path path) { - unsigned int write = P_IND; - unsigned int read = 0; + unsigned long write = P_IND; + unsigned long read = 0; levlim(5) while(write<P_ALC) { - while(!read_by_bit_index(path, write+read, 4)) - read += 4; + if (write+read<P_ALC) + while(!read_by_bit_index(path, write+read, 4)) + read += 4; if(read) write_by_bit_index(path, write, 4, (write+read<P_ALC)?read_by_bit_index(path, write+read, 4):0); write += 4; @@ -320,8 +320,7 @@ static void execs(Path path, Path caller) { - /***************************************************************EXECUTION LOOP***************************************************************/ - unsigned int tempNum1 = 0; /* Expedite calculation */ + unsigned long tempNum1 = 0; /* Expedite calculation */ levlim(8) /* Level operation checking */ P_RUNNING = path; /* Set running */ @@ -333,9 +332,9 @@ return; } memcpy(P_CHILD, &NEW_PATH, sizeof(struct PATH)); /* Copy over initialization data */ - (*(*path).child).owner = path; /* Set owner of this new Path */ - (*(*path).child).prg_floor = (path->prg_floor) + 1; /* Set floor of this new Path */ - (*(*path).child).prg_data = calloc(1, sizeof(unsigned int)); /* Set data of this new Path */ + path->child->owner = path; /* Set owner of this new Path */ + path->child->prg_floor = (path->prg_floor) + 1; /* Set floor of this new Path */ + path->child->prg_data = calloc(1, sizeof(unsigned long)); /* Set data of this new Path */ } P_WRITTEN = P_CHILD; /* Set this as written on */ @@ -345,7 +344,7 @@ for (; doloop && P_PIND < (P_ALC / 4) && path != NULL && P_WRITTEN != NULL ; P_PIND++) /* Execution Loop */ { tempNum1 = (P_RUNNING->prg_index); - command = ((P_RUNNING->prg_data)[(tempNum1 * 4) / 32] >> (32 - ((tempNum1 * 4) % 32) - 4)) & mask(4); /* Calculate command */ + command = ((P_RUNNING->prg_data)[(tempNum1 * 4) / BITS_IN_CELL] >> (BITS_IN_CELL - ((tempNum1 * 4) % BITS_IN_CELL) - 4)) & mask(4); /* Calculate command */ if (command == 5) execs(P_WRITTEN, path); @@ -404,7 +403,7 @@ static void reads(Path path) { - int pos = P_IND; + long pos = P_IND; levlim(6) if (P_LEN < 8) { @@ -424,7 +423,7 @@ int report = read_by_bit_index(path, 0, 1); if ((P_RUNNING->owner) != NULL) { - unsigned int ownind = ((P_RUNNING->owner)->prg_index); + unsigned long ownind = ((P_RUNNING->owner)->prg_index); write_by_bit_index(P_RUNNING->owner, (ownind) * 4, 4, report); } free(P_DATA); @@ -486,8 +485,8 @@ static void doalc(Path path) { - unsigned int new_cell_count = 0; - unsigned int* new_data_pointer = NULL; + unsigned long new_cell_count = 0; + unsigned long* new_data_pointer = NULL; levlim(1) P_ALC <<= 1; @@ -496,19 +495,19 @@ else new_cell_count = P_ALC / BITS_IN_BYTE; - new_cell_count /= sizeof(unsigned int); + new_cell_count /= sizeof(unsigned long); - if ((new_data_pointer = calloc(new_cell_count, sizeof(unsigned int))) == NULL) + if ((new_data_pointer = calloc(new_cell_count, sizeof(unsigned long))) == NULL) { - printf("Error allocating %d bytes: ", new_cell_count * sizeof(unsigned int)); + printf("Error allocating %d bytes: ", new_cell_count * sizeof(unsigned long)); perror(""); abort(); } if (new_cell_count > 1) - memcpy(new_data_pointer, P_DATA, new_cell_count * sizeof(unsigned int) / 2); + memcpy(new_data_pointer, P_DATA, new_cell_count * sizeof(unsigned long) / 2); else - memcpy(new_data_pointer, P_DATA, sizeof(unsigned int)); + memcpy(new_data_pointer, P_DATA, sizeof(unsigned long)); P_DATA = new_data_pointer; @@ -543,18 +542,18 @@ return P_IND % (P_LEN << 1) == 0; } -unsigned int mask(int length) +unsigned long mask(int length) { if (length < BITS_IN_CELL) return ((int)1 << length) - 1; else return 0xFFFFFFFF; } -unsigned int read_by_bit_index(Path path, unsigned int i, unsigned int len) +unsigned long read_by_bit_index(Path path, unsigned long i, unsigned long len) { return (P_DATA[i / BITS_IN_CELL] >> (BITS_IN_CELL - (i % BITS_IN_CELL) - len)) & mask(len); } -static void write_by_bit_index(Path path, unsigned int i, unsigned int len, unsigned int write) +static void write_by_bit_index(Path path, unsigned long i, unsigned long len, unsigned long write) { int shift = BITS_IN_CELL - (i % BITS_IN_CELL) - len; if (len > BITS_IN_CELL) abort();