rolldice_1.14.orig/0000755000175000017500000000000012565462616013642 5ustar thomasthomasrolldice_1.14.orig/rolldice.h0000644000175000017500000000336412064142415015600 0ustar thomasthomas/* * rolldice.h - v1.14 - 18 December 2012 * (c) Stevie Strickland, 1999-2012 * * This program has been placed under the GPL. Any bugfixes or enhancements * will be greatly appreciated :) * * Stevie Strickland - sstrickl@ccs.neu.edu */ /* Standard includes */ #include #include /* For GNU getopt */ #include /* For GNU readline */ #include /* For exit values */ #include /* For the time() function */ #include /* For the rand() and srand() functions */ #include /* For the strstr() function */ #include /* For some bounds */ #include /* The following #defines give the position of each important dice-related * number inside of the dice_nums array. The final #define gives us the * size of the dice_nums array, which should be the number of other * #defines below. */ #define NUM_ROLLS 0 #define NUM_DICE 1 #define NUM_SIDES 2 #define MULTIPLIER 3 #define MODIFIER 4 #define NUM_DROP 5 #define DICE_ARRAY_SIZE 6 /* The following #defines give the tokens for each part of the format * string. Perhaps eventually I'll change parse_string to use strtok() * instead of strstr() :) */ #define ROLL_IDENT "x" #define DICE_SIDES_IDENT "d" #define MULTI_IDENT "*" #define MOD_PLUS_IDENT "+" #define MOD_MINUS_IDENT "-" #define DROP_IDENT "s" // Defines values for true and false, just for testing stuff boolean-wise :) #define TRUE_VAL 1 #define FALSE_VAL 0 // Defines values for the random number file to use typedef enum {UNDEF, URANDOM, RANDOM} rand_type; // External function declarations for using rolldice() and kin. extern int *parse_string(char *dice_string); extern int rolldie(int num_sides); extern void init_random(rand_type rand_file); rolldice_1.14.orig/rolldice.6.src0000644000175000017500000000672012064142415016303 0ustar thomasthomas.\" Man file for rolldice(6) - v__VERSION__ - 18 Dec 2012 .\" (c) Stevie Strickland, 1999-2012 .\" .TH ROLLDICE 6 "18 Dec 2012" Linux .SH NAME rolldice \- rolls virtual dice .SH SYNOPSIS .B rolldice [ .I options .B ] .I [dice_string .I [dice_string .I ...]] .SH DESCRIPTION .B rolldice rolls virtual dice. The dice strings passed on the command line contain information on the dice to roll in a format comparable to the format used in most role playing games. .P If no dice strings are provided as command line arguments, .B rolldice uses stdin as input. .SH OPTIONS .RS .IP -h,--help returns the usage of diceroll .IP -v,--version returns the version of diceroll .IP -r,--random uses /dev/random for random number generating .IP -u,--urandom uses /dev/urandom for random number generating (default) .IP -s,--separate prints out the result of each individual die separately, as well as the operations and totals .RE .SH "DICE STRING FORMAT" The dice string uses the following format: .RS .IP {#x}{#}d[#|%]{*#}{+/-#}{s#} .RE .P The dice string doesn't have to be in the exact format outlined above, but this is the order I use. It will try to parse any different string containing the same sections in the best way it can, and will throw out anything that isn't one of the sections below. .P Now, to break this format down section by section: .RS .IP {#}d[#|%] The first number is the number of dice to roll, and the second number is the number of sides the dice have. The numbers rolled on each die are then added up and given as the result. Hence 3d6 means "roll three six-sided dice, add them together and return the result". If the first number is left out, then the number of dice defaults to 1. If the second number is not a number, but a percentage sign (%), then the number of sides becomes 100 (for a percentage roll). If this is not included in the dice string, then the default is 1d6. .IP {#x} This number describes how many times to roll. For example, if you want to roll 3 6-sided dice 6 times, you use the dice string 6x3d6. This returns six numbers, corresponding to the six different rolls. .IP {*#} This number describes how many times to multiply the result of each roll. 3d6*100 returns a number in the range of 300-1800, because 3-18 is the range for 3d6 and the result is then multipled by 100. .IP {+/-#} This number is the modifier to be added or subtracted, depending on the sign, from each roll. 1d4+1 results in a range from 2-5 (1-4 for the die, plus 1). This step is handled *after* the multiplication modifier. .IP {s#} This number describes how many lowest dice rolls to drop. This step is handled *before* the multiplication modifier. .RE .P Any combination of the optional parts of the string may be used, but only in the order show above. For an extreme example, "3x4d6*5+1s2" would roll four six-sided dice, drop the lowest two, multiply the result by 5, add 1 to that, and repeat the process two more times, for a total of three results. .SH DIAGNOSTICS The following error messages may appear on STDERR: Requested * is too large .RS Memory could not be allocated while parsing the string passed to the .B rolldice program .RE Problems with the malformed dice string .RS The dice string contains a syntax error (see upper section DICE STRING FORMAT) .RE Unknown option .RS An unknown command-line option was provided .RE The exit values returned by .B rolldice follow the BSD convention. .SH AUTHOR Stevie Strickland .SH VERSION __VERSION__ - 18 Dec 2012 rolldice_1.14.orig/CREDITS0000644000175000017500000000172512064142415014651 0ustar thomasthomasJohn Anderson - For making me write the program in the first place, after I told him I needed a project to work with C, and then complained about there not being any good free dice rolling programs... talein@whitestar.soark.net - For helping me see that my limits were wrong, and that MAXSHORT was the way (though now I'm using SHRT_MAX!) colin@nyx.net - For looking at my code and giving me suggestions for better random number generation (the only suggestion taken, so far, is the addition of /dev/(u)random... watch this space for news! Adam Northern - For aiding and abetting with the above "credit", now changed due to a change of heart on part of the upstream programmer (that is, me) mhess@email.unc.edu - For helping with the changelog entry for v1.2 which is, again, changed :) Stéphane Blondon - For improving error messages, the handling of version numbers and reading dice strings on standard input. rolldice_1.14.orig/Changelog0000644000175000017500000000466712064142415015453 0ustar thomasthomasv1.14 - 18 December 2012 - Stéphane changed the error handling from following stdlib conventions to BSD (sysexits.h) conventions. v1.13 - 05 August 2012 - Stéphane found a bug that caused dice strings with subtraction (e.g., "1d2-1") to be handled as addition (e.g., like "1d2+1"). v1.12 - 07 June 2012 - Stéphane Blondon has done some work in improving error messages, the handling of version numbers, and also reading dice strings on standard input. - A github repository is now available: https://github.com/sstrickl/rolldice v1.11 - 01 Feb 2010 - Only updating URLs/email addresses. No bugfixes in this revision, though I'll get around to soon. v1.10 - 25 Nov 2001 - Forgot to add a couple of entries to the changelogs, I see. Added them back in. - Truthfully, eventually I should rewrite this code completely, as I did originally write it before I really knew how one should write code like this. Perhaps over the winter break. - This version fixes the problem of urandom always being opened, thanks to initializing the (u)random file before reading in the command line options. Fixed that, plus replaced my option parsing code with a use of getopt_long(). v1.9 - 10 Mar 2001 - Never checked result of parse_string for unsuccessful parses. Fixed. v1.8 - 17 Oct 1999 - Segfaulted when one didn't specify how many dice to roll (should default to one). Fixed. v1.7 - 28 Mar 1999 - Changed dice string parser code, now more to my liking :) - Added ability to use multiple dice strings v1.6 - 27 Mar 1999 - Added ability to drop a number of lowest die rolls and made reading from /dev/urandom the default. In fact, there is no longer a method that uses the rand() function. If adding this feature back is needed, then just contact me and I'll work it back in. v1.5 - 10 Mar 1999 - Added ability to print out each individual die roll and added the long version of each of the options v1.4 - 12 Feb 1999 - Added ability to use "d#" type constructions and "d%" for percentages v1.3 - 27 Jan 1999 - Fixed documentation, both in getting rid of childish flames and in correcting the dates in the changelog (and anywhere else they might be wrong :) v1.2 - 27 Jan 1999 - added /dev/(u)random code v1.1 - 20 Jan 1999 - Fixed bug involving overflowing and underflowingi because of too large or negative dice attributes v1.0 - 19 Jan 1999 - Released rolldice rolldice_1.14.orig/rolldice.c0000644000175000017500000001616412064142415015575 0ustar thomasthomas/** * rolldice.c - v1.14 - 18 December 2012 * (c) Stevie Strickland, 1999-2012 * * This program has been placed under the GPL. Any bugfixes or enhancements * will be greatly appreciated :) * * Stevie Strickland - sstrickl@ccs.neu.edu */ #include "rolldice.h" // File pointer for random device static FILE* ran_dev; // Local functions int get_num_dice(int temp_int, int default_num); int *get_num_sides(char *dice_string, int temp_int, int *res_int); int *get_num_drop(char *dice_string, int temp_int, int *res_int); int *get_num_rolls(int temp_int, int *res_int); int *get_mutiplier(char *dice_string, int temp_int, int *res_int); int *get_plus_modifier(char *dice_string, int temp_int, int *res_int); int *get_minus_modifier(char *dice_string, int temp_int, int *res_int); int is_too_big(int num); void print_parse_error(const char * label, const int too_big_error); void init_random(rand_type rand_file) { if(rand_file == RANDOM) { if((ran_dev = fopen("/dev/random", "r")) == NULL) { fprintf(stderr, "Error in opening /dev/random!\n"); exit(EX_OSFILE); } } else if((ran_dev = fopen("/dev/urandom", "r")) == NULL) { fprintf(stderr, "Error in opening /dev/urandom!\n"); exit(EX_OSFILE); } } static int get_random(int sides) { unsigned int ret_value; if(!(fread(&ret_value, sizeof(unsigned int), 1, ran_dev) == 1)) { fprintf(stderr, "Error in reading random device!\n"); exit(EX_OSFILE); } return (int)(ret_value % sides); } /* rolldie() - Rolls a single die * * Parameters: int num_sides - number of sides of the die to roll * Returns: int - the result of the roll */ int rolldie ( int num_sides ) { return (1 + get_random(num_sides)); } /* parse_string() - Parses a string for dice rolling attributes * * Parameters: char *dice_string - string to parse * Returns: int * - array of nums describing the different aspects of the * dice to be rolled */ int *parse_string(char *dice_string) { int temp_int = -1, *dice_nums, *res_int; const int DEFAULT_NUM_DICE = 1; if((dice_nums = malloc ( DICE_ARRAY_SIZE * sizeof(int))) == NULL){ perror("rolldice"); exit(EX_OSERR); } dice_nums[NUM_ROLLS] = 1; dice_nums[NUM_DICE] = DEFAULT_NUM_DICE; dice_nums[NUM_SIDES] = 6; dice_nums[MULTIPLIER] = 1; dice_nums[MODIFIER] = 0; dice_nums[NUM_DROP] = 0; while(*dice_string != '\0') { if( isdigit(*dice_string) ) { sscanf(dice_string, "%d", &temp_int); while(isdigit(*(++dice_string))); } else { switch(*dice_string) { case 'd': dice_nums[NUM_DICE] = get_num_dice(temp_int, DEFAULT_NUM_DICE); dice_string++; res_int = get_num_sides(dice_string, temp_int, res_int); if (res_int == NULL){ free(dice_nums); return NULL; } else { dice_nums[NUM_SIDES] = *res_int; } break; case 's': dice_string++; res_int = get_num_drop(dice_string, temp_int, res_int); if (res_int == NULL){ free(dice_nums); return NULL; } else { dice_nums[NUM_DROP] = *res_int; } break; case 'x': dice_string++; res_int = get_num_rolls(temp_int, res_int); if (res_int == NULL){ free(dice_nums); return NULL; } else { dice_nums[NUM_ROLLS] = *res_int; } break; case '*': dice_string++; res_int = get_mutiplier(dice_string, temp_int, res_int); if (res_int == NULL){ free(dice_nums); return NULL; } else { dice_nums[MULTIPLIER] = *res_int; } break; case '+': dice_string++; res_int = get_plus_modifier(dice_string, temp_int, res_int); if (res_int == NULL){ free(dice_nums); return NULL; } else { dice_nums[MODIFIER] = *res_int; } break; case '-': dice_string++; res_int = get_minus_modifier(dice_string, temp_int, res_int); if (res_int == NULL){ free(dice_nums); return NULL; } else { dice_nums[MODIFIER] = *res_int; } break; default: dice_string++; break; } temp_int = 0; } } return dice_nums; } int get_num_dice(int temp_int, int default_num){ if( (temp_int <= 0 ) || is_too_big(temp_int) ) return default_num; else return temp_int; } int is_too_big(int num){ return num >= SHRT_MAX; } void print_parse_error(const char * label, const int too_big_error){ if (too_big_error){ fprintf(stderr, "rolldice: Requested %s is too large\n", label); } else{ fprintf(stderr, "rolldice: Problems with the malformed dice string (in %s), so quitting!\n", label); } } int *get_num_sides(char *dice_string, int temp_int, int *res_int){ const char *PERCENT = "%"; if(strncmp(dice_string, PERCENT, 1) == 0){ temp_int = 100; res_int = &temp_int; return res_int; } else if( (sscanf(dice_string, "%d", &temp_int) < 1 ) || (temp_int < 2) || is_too_big(temp_int) ) { print_parse_error("number of dice faces", is_too_big(temp_int)); return NULL; } else { res_int = &temp_int; return res_int; } } int *get_num_drop(char *dice_string, int temp_int, int *res_int){ if( (sscanf(dice_string, "%d", &temp_int) < 1) || (temp_int < 0) || is_too_big(temp_int) ) { print_parse_error("number of dropped dice", is_too_big(temp_int)); return NULL; } else { res_int = &temp_int; return res_int; } } int *get_num_rolls(int temp_int, int *res_int){ if( ( temp_int < 1 ) || is_too_big(temp_int) ) { print_parse_error("number of rolled dice", is_too_big(temp_int)); return NULL; } else { res_int = &temp_int; return res_int; } } int *get_mutiplier(char *dice_string, int temp_int, int *res_int){ if( (sscanf(dice_string, "%d", &temp_int) < 1) || (temp_int < 0) || is_too_big(temp_int) ) { print_parse_error("multiplier", is_too_big(temp_int)); return NULL; } else { res_int = &temp_int; return res_int; } } int *get_plus_modifier(char *dice_string, int temp_int, int *res_int){ if( (sscanf(dice_string, "%d", &temp_int) < 1) || (temp_int < 0) || is_too_big(temp_int) ) { print_parse_error("add modifier", is_too_big(temp_int)); return NULL; } else { res_int = &temp_int; return res_int; } } int *get_minus_modifier(char *dice_string, int temp_int, int *res_int){ if( (sscanf(dice_string, "%d", &temp_int) < 1) || (temp_int < 0) || is_too_big(temp_int) ) { print_parse_error("minus modifier", is_too_big(temp_int)); return NULL; } else { temp_int = - temp_int; res_int = &temp_int; return res_int; } } rolldice_1.14.orig/COPYING0000644000175000017500000004312712064142415014666 0ustar thomasthomas GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. rolldice_1.14.orig/tests/0000755000175000017500000000000012064142415014766 5ustar thomasthomasrolldice_1.14.orig/tests/rollfile0000644000175000017500000000001612064142415016516 0ustar thomasthomas1d2 1d3 2d2+2 rolldice_1.14.orig/tests/tests.sh0000755000175000017500000000415312064142415016472 0ustar thomasthomas#! /bin/bash # Released under GPL licence v2 or upper # # When executed ($ ./tests.sh), no errors should occur in the # two first sections. The third one should result in only error messages, # each one different. Segfault or default error messages must not appear. # # The following lines are the expected results: # Use argv #2 #3 #Roll #1: (2 ) = 2 #Roll #1: (1 ) = 1 #Roll #1: (1 ) = 1 #2 #2 # Use stdin #1 #1 #4 #Roll #1: (1 ) = 1 #Roll #1: (1 ) = 1 #Roll #1: (2 1 ) + 2 = 5 # Error messages handle numbers that are too large #rolldice: Requested number of dice faces is too large #rolldice: Requested number of dropped dice is too large #rolldice: Requested number of rolled dice is too large #rolldice: Requested multiplier is too large #rolldice: Requested add modifier is too large #rolldice: Requested minus modifier is too large function check_result { OUTPUT=`../rolldice $1` EXIT_VAL=$? TEST_SUCCESS=true if [[ $EXIT_VAL != 0 ]] then echo ${1}": ERROR (return value)" TEST_SUCCESS=false fi if echo ${OUTPUT} | grep -q -v $2 then echo ${1}": ERROR ("${OUTPUT}")" TEST_SUCCESS=false fi if $TEST_SUCCESS; then echo ${1}": OK" fi } function check_error { OUTPUT=`../rolldice $1` EXIT_VAL=$? # 65 == EX_DATAERR /* data format error */ if [[ $EXIT_VAL != 65 ]] then echo ${1}": ERROR ("$EXIT_VAL" instead of 65)" fi } echo -e "\tResult between right limits" check_result "1d2" "^[12]" check_result "1d2+1" "^[23]" check_result "1d2*2" "^[24]" check_result "1d2-1" "^[01]" echo -e "\tUse argv" ../rolldice 1d2 ../rolldice 1d2+1 ../rolldice -s 1d2 ../rolldice -s -u 1d2 ../rolldice -s -r 1d2 ../rolldice 1d2 1d3 ../rolldice 1d% ../rolldice 1d%+1 echo -e "\tUse stdin" cat rollfile | ../rolldice cat rollfile | ../rolldice -s echo -e "\tError messages handle numbers that are too large" check_error "1d123456789" check_error "2d3s123456789" check_error "123456789x2d2" check_error "2d2*123456789" check_error "2d2+123456789" check_error "2d2-123456789" rolldice_1.14.orig/README0000644000175000017500000000676512064142415014522 0ustar thomasthomasrolldice is just a simple program that rolls an amount of virtual dice of any size. Well, technically, all the attributes of the dice can't exceed SHRT_MAX, but I think it suffices for any normal FRPG. rolldice is a simple program, trying to uphold the UNIX philosophy of doing one thing, and doing that thing well. However, this is not a claim that rolldice cannot be improved, only that I am satisfied with it, as of right now... of course, any improvements will be accepted gladly! COMPILING Compiling rolldice requires the development files of the GNU readline library. HISTORY 1999.1.27 I've had a request to add /dev/(u)random as random number input, and so I've added the capability to use the random number devices as random input. The -u option gives you /dev/urandom, and the -r /dev/random. 1999.2.12 I know I've been a little late in adding some new features, and I apologize, but I'm sure you understand, college and all... anyway, there are two new features in this version of rolldice: A default for the number of dice to roll (so that strings like "d6" are possible now), and the ability to use "d%" as a percentage roll (rolls d100). You can also use strings like "#d%" to roll # percentage dice at once. 1999.3.10 New in this release is the ability to print out each separate die roll. When using this feature, you get the following output: [sstrickl@midkemia]:~$ rolldice -s 3d6 Roll #1: 2 4 2 = 8 [sstrickl@midkemia]:~$ rolldice -s 2x3d6 Roll #1: 5 2 6 = 13 Roll #2: 1 6 2 = 9 Easy? I thought so! :) 1999.3.27 I still haven't put in the option to allow multiple dice strings on the command line. However, I *have* added the ability to drop a number of lowest die rolls. This is for all those other methods of rolling characters under AD&D, and I'm sure other gaming systems use this sometimes ;) Also, /dev/urandom has been made the default random number generator, and the use of rand() has been dropped. If you wish this method to be added back to rolldice, just contact me and I'll do so. 1999.3.28 I made the parser code much cleaner... this won't really affect the use of the program, except now you can kinda shuffle sections around. They will still be resolved in the same order as before, however, so: [sstrickl@midkemia]:~$ rolldice -s 3d6-1*10 results in: Roll #1: (3 5 2) * 10 - 1 = 99 not: Roll #1: ((3 5 2) - 1) * 10 = 90 It's not quite that smart, sadly. And also, finally, at long last, I've added the ability to use multiple dice strings! Woohoo! So this means that unless I find or am asked to add a new method to the dice string itself, this might be the last release of diceroll, unless I actually do rewrite it to make it neater, find a cleaner parser implementation, or just get bored and decide to add something else... 2010.2.1 Changing the URL/email at the bottom of this file, both of which are outdated since I left Georgia Tech. 2012.5.4 Cleaning up this README a bit (or destroying history, however you want to look at it) to get it ready for posting at Github. Maybe one day I'll come back to it and clean it up as much as it needs, but I'm not optimistic. 2012.6.7 Thanks to Stéphane Blondon, there have been a few improvements in rolldice, including the ability to pipe input from standard input. Thanks for your contributions! 2012.8.5 Stéphane found a regression where subtraction was handled the same as plus, so that's fixed in this newest release. 2012.12.18 Stéphane changed the error handling from following stdlib conventions to BSD (sysexits.h) conventions. rolldice_1.14.orig/version.h0000644000175000017500000000037712064142415015471 0ustar thomasthomas/* * version.c - 18 December 2012 * * This program has been placed under the GPL. Any bugfixes or enhancements * will be greatly appreciated :) */ /* The version number :) */ static const int MAJOR_VERSION = 1; static const int MINOR_VERSION = 14; rolldice_1.14.orig/main.c0000644000175000017500000001143012064142415014713 0ustar thomasthomas/* * main.c - v1.14 - 18 December 2010 * (c) Stevie Strickland, 1999-2012 * * This program has been placed under the GPL. Any bugfixes or enhancements * will be greatly appreciated :) * * Stevie Strickland - sstrickl@ccs.neu.edu */ /* For the abs() function */ #include #include "rolldice.h" #include "version.h" /* The long options for this program in an struct option array */ struct option long_opts[] = {{"help", 0, NULL, 'h'}, {"version", 0, NULL, 'v'}, {"random", 0, NULL, 'r'}, {"urandom", 0, NULL, 'u'}, {"separate", 0, NULL, 's'}}; /* For getopt usage */ extern int optind; /* Stores the random number file to use */ rand_type rand_file = UNDEF; /* Should we print out the separate results of the dice rolls or not? */ static int print_separate; /* * print_usage() - Prints the usage for rolldice * * Parameters: Value with which to exit program * Returns: none */ static void print_usage(int exitval) { fprintf(stderr, "Usage: rolldice [options] \n"); fprintf(stderr, "For dice string format and options, "); fprintf(stderr, "see rolldice(6).\n"); exit(exitval); } /* * print_version() - Prints the version number * * Parameters: none * Returns: none */ static void print_version() { printf("rolldice, v%d.%d\n", MAJOR_VERSION, MINOR_VERSION); printf("Written by Stevie Strickland (sstrickl@ccs.neu.edu)\n"); exit(EX_OK); } /* print_rolls() - Prints the rolls, either just the totals or the * separate rolls, also. * * Parameters: Dice string with which to calculate dice rolls * Returns: None */ void print_rolls(int *dice_nums) { int i, j, k, temp_int, temp_index, temp_total; int* temp_roll; if((temp_roll = malloc(sizeof(*temp_roll) * dice_nums[NUM_DICE])) == NULL) { perror("rolldice"); exit(EX_OSERR); } for(i = 0; i < dice_nums[NUM_ROLLS]; i++) { temp_total = 0; if(print_separate) printf("Roll #%d: (", i+1); for(j = 0; j < dice_nums[NUM_DICE]; j++) { temp_roll[j] = rolldie(dice_nums[NUM_SIDES]); if(print_separate) printf("%d ", temp_roll[j]); temp_total += temp_roll[j]; } for(j = 0; j < dice_nums[NUM_DROP]; j++) { temp_int = SHRT_MAX; for(k = 0; k < dice_nums[NUM_DICE]; k++) if(temp_int > temp_roll[k]) { temp_int = temp_roll[k]; temp_index = k; } if(print_separate) printf("- %d ", temp_int); temp_total -= temp_int; temp_roll[temp_index] = SHRT_MAX; } if(print_separate) printf(") "); if(dice_nums[MULTIPLIER] != 1) { if(print_separate) printf("* %d ", dice_nums[MULTIPLIER]); temp_total *= dice_nums[MULTIPLIER]; } if(dice_nums[MODIFIER]) { if(print_separate){ if (dice_nums[MODIFIER] > 0) printf("+ %d ", dice_nums[MODIFIER]); else printf("- %d ", abs(dice_nums[MODIFIER])); } temp_total += dice_nums[MODIFIER]; } if(print_separate) printf("= "); printf("%d ", temp_total); if(print_separate) printf("\n"); } if(!print_separate) printf("\n"); } /* roll_from_stdin() - parse stdin, one roll by line * * Parameters: None * Returns: EX_OK or EXIT_DATAERR (if bad stdin) */ int roll_from_stdin(){ int *dice_nums = NULL; static char *line = (char *)NULL; line = readline(""); while(line){ dice_nums = parse_string( line ); if ( dice_nums == NULL ) { return EX_DATAERR; } free(line); print_rolls(dice_nums); free(dice_nums); line = (char *)NULL; line = readline(""); } return EX_OK; } /* roll_from_args() - parse command line args to roll dices * * Parameters: args passed to CLI * Returns: EX_OK or EXIT_DATAERR (if bad command line) */ int roll_from_args(char **argv){ int *dice_nums = NULL; int index; for(index = optind; argv[index] != NULL; index++) { dice_nums = parse_string( argv[index] ); if ( dice_nums == NULL ) { return EX_DATAERR; } print_rolls(dice_nums); free(dice_nums); } return EX_OK; } int main(int argc, char **argv) { int c; while((c = getopt_long(argc, argv, "hvrus", long_opts, NULL)) != -1) { switch(c) { case 'h': print_usage(EX_OK); break; case 'v': print_version(); break; case 'r': if(rand_file == URANDOM) { fprintf(stderr, "Choose either '-r' or '-u', please.\n"); return EX_USAGE; } rand_file = RANDOM; break; case 'u': if(rand_file == RANDOM) { fprintf(stderr, "Choose either '-r' or '-u', please.\n"); return EX_USAGE; } rand_file = URANDOM; break; case 's': print_separate = 1; break; } } init_random(rand_file); if ( optind == argc ) { return roll_from_stdin(); } else { return roll_from_args(argv); } } rolldice_1.14.orig/Makefile0000644000175000017500000000155312064142415015270 0ustar thomasthomas# Edited for Debian GNU/Linux DESTDIR = BIN = $(DESTDIR)/usr/games MAN = $(DESTDIR)/usr/share/man/man6 CC = gcc OBJFILES = main.o rolldice.o LIBS = -lm -lreadline INCLUDES = rolldice.h MAJOR_VERSION = $(shell grep MAJOR_VERSION version.h | cut -d" " -f6 | cut -f1 -d";") MINOR_VERSION = $(shell grep MINOR_VERSION version.h | cut -d" " -f6 | cut -d";" -f1) VERSION = $(MAJOR_VERSION).$(MINOR_VERSION) all: rolldice man rolldice: $(OBJFILES) $(CC) $(OBJFILES) -g -o rolldice $(LIBS) main.o: main.c $(INCLUDES) $(CC) -g -c main.c rolldice.o: rolldice.c $(INCLUDES) $(CC) -g -c rolldice.c install: $(EXECFILES) install -d $(BIN) $(MAN) install ./rolldice $(BIN) gzip -9 -c rolldice.6 > rolldice.6.gz install -m644 rolldice.6.gz $(MAN) man: sed s/__VERSION__/$(VERSION)/ rolldice.6.src > rolldice.6 clean: rm -f ./rolldice $(OBJFILES) rolldice.6 rolldice.6.gz