diff --git a/a.out b/a.out deleted file mode 100755 index d782067..0000000 Binary files a/a.out and /dev/null differ diff --git a/attrib.c b/attrib.c deleted file mode 100644 index 4ea876e..0000000 --- a/attrib.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "string.h" -#include "stdlib.h" -#include "ctype.h" -#include "stdio.h" -#include "futil.h" - -char* g_attribs=(char*)0; -const char** g_attrib_index=(const char**)0; -int g_attribs_count=0; -int g_attribs_len=0; - -/* - * load and index an attributes file - */ -int load_attrib_file(const char* file) { - FILE* stream=fopen(file,"r"); - g_attribs_len=file_len(stream); - g_attribs_count=fcountc(stream,',')+1; - g_attribs=calloc(g_attribs_len,sizeof(char)+1); - g_attrib_index=calloc(sizeof(char*),g_attribs_count); - const char** ind_writer = g_attrib_index; - int n='\0'; - char* writer=g_attribs; - *ind_writer=writer; - ++ind_writer; - while((n=fgetc(stream))!=EOF) { - char c=(char)n; - printf("%c",c); - switch(c) { - case ',': - *writer='\0'; - if(isspace((char)fpeek(stream))) - *ind_writer=writer+2; - else - *ind_writer=writer+1; - ++ind_writer; - break; - case '\t': - case '\n': - *writer=' '; - break; - default: - *writer=c; - break; - } - ++writer; - } - *writer='\0'; - for(int i=0;i0) { - int roll = rolld(d); - total += roll; - if(i!=(void*)0) - *(i++) = roll; - } - return total; -} - -int process_dice_format(const char* format,int* num,int* die) { - int dummy; // dummy int for if either of the out adresses is 0 - if(num==(void*)0)num=&dummy; - if(die==(void*)0)die=&dummy; - char buf[10]; - memset(buf,0,10); // clear buffer - char* bufw=buf; - const char* next=format; - while(*next!='\0') { - if(*next=='d') { // argument is d in d format - if(next==format) // if there is no die count given, assume 1 - *num=1; - else - *num=atoi(buf); // store buffered string as number - memset(buf,0,10); // clear buffer - bufw=buf; // reset buffer walker - next++; // skip - } - *bufw=*next; // buffer next character - bufw++;next++; // increment walker and next character - } - *die=atoi(buf); - return 0; -} - -void roll_and_print(int n, int d) { - int* out_rolls=malloc(sizeof(int)*n); - int result=rollnd(n,d,out_rolls); - printf(" %d (%dd%d) ",result,n,d); - // only print inbetween steps if there are any - if(n>1) { - for(int i=0;i=g_argc)return 0; - const char* arg=g_argv[argind]; - char buf[10]; - memset(buf,0,10); - if(strcmp(arg,"-i")==0) { - f_interactive=1; - return process_arg(argind+1); - } else if(strcmp(arg, "-a")==0) { - load_attrib_file(g_argv[argind+1]); - return process_arg(argind+2); - } else if(isdigit(arg[0])||arg[0]=='d') { - process_dice_format(arg,&f_num,&f_die); - return process_arg(argind+1); - } - return 0; -} diff --git a/flags.h b/flags.h deleted file mode 100644 index eec8ade..0000000 --- a/flags.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _flags_h -#define _flags_h - -extern int f_interactive; -extern int f_num; -extern int f_die; -extern int g_argc; -extern const char** g_argv; - -extern int process_arg(int argind); - -#endif /* _flags_h */ diff --git a/futil.c b/futil.c deleted file mode 100644 index eb69e16..0000000 --- a/futil.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "stdlib.h" -#include "stdio.h" - -long file_len(FILE* file) { - fpos_t pos; - fgetpos(file,&pos); - fseek(file,0,SEEK_END); - long len=ftell(file); - fsetpos(file,&pos); - return len; -} - -long fcountc(FILE* file, char c) { - int i = 0; - long t = 0; - fpos_t strt; - fgetpos(file,&strt); - while((i=fgetc(file))!=EOF) { - if((char)i==c) - ++t; - } - fsetpos(file, &strt); - return t; -} - -int fpeek(FILE* file) { - fpos_t p; - fgetpos(file,&p); - int v = fgetc(file); - fsetpos(file,&p); - return v; -} diff --git a/futil.h b/futil.h deleted file mode 100644 index 5808993..0000000 --- a/futil.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _futils_h -#define _futils_h - -#include "stdio.h" - -/* - * return the length of a text file - */ -long file_len(FILE* file); - -/* - * count the number of occurences of c in file - * starting from the current stream position - */ -long fcountc(FILE* file, char c); - -/* - * peek the next value of file - */ -int fpeek(FILE* file); - -#endif /* _futils_h */ diff --git a/interactive.c b/interactive.c deleted file mode 100644 index 928cab4..0000000 --- a/interactive.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "stdio.h" -#include "dice.h" -#include "string.h" -#include "flags.h" - -int run_interactive() { - int running = 1; - char buf[24]; - while(running) { - printf("> "); - memset(buf,0,10); - scanf("%s",buf); - if(strcmp(buf,"quit")==0||strcmp(buf,"exit")==0||strcmp(buf,"q")==0) return 0; - process_dice_format(buf,&f_num,&f_die); - if(f_num!=0&&f_die!=0||buf[0]=='\0') - roll_and_print(f_num, f_die); - } - return 0; -} diff --git a/interactive.h b/interactive.h deleted file mode 100644 index 2badb87..0000000 --- a/interactive.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _interactive_h -#define _interactive_h - -extern int run_interactive(); - -#endif /* _interactive_h */ diff --git a/main.c b/main.c deleted file mode 100644 index 67a5d61..0000000 --- a/main.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "time.h" -#include "stdlib.h" -#include "dice.h" -#include "flags.h" -#include "interactive.h" - -int main(int argc,const char* argv[]) { - srand(time(NULL)); - g_argv=argv; - g_argc=argc; - process_arg(1); - // if there are valid dice to roll - if(f_die>0&&f_num>0) { - roll_and_print(f_num,f_die); - } - if(f_interactive==1||argc==1) { - return run_interactive(); - } -} diff --git a/pc.c b/pc.c deleted file mode 100644 index d9ca797..0000000 --- a/pc.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pc.h" -#include "memory.h" - -int new_character(pc_t* pc, const char* name) { - memset(pc,0,sizeof(pc_t)); - strncpy(pc->name,name,64); - return 0; -} diff --git a/pc.h b/pc.h deleted file mode 100644 index 69a9698..0000000 --- a/pc.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _pc_h -#define _pc_h - -typedef struct pc_t { - char name[64]; - int dexterity,strength,constitution,intelligence,wisdom; - const char* spells[64]; - const char* traits[64]; -} pc_t; - -int new_character(pc_t* pc, const char* name); - -#endif /* _pc_h */ diff --git a/test.csv b/test.csv deleted file mode 100644 index 00ad55d..0000000 --- a/test.csv +++ /dev/null @@ -1 +0,0 @@ -firebolt, fireball, mage hand, magic shield