~dax/drpc

1f210d8b2afac38c0bb558302e51452d13aeb679 — dax 11 months ago
initial commit
6 files changed, 288 insertions(+), 0 deletions(-)

A Makefile
A README.md
A config.mk
A drpc.1
A drpc.1.scd
A drpc.c
A  => Makefile +40 -0
@@ 1,40 @@
# drpc - doman reconstruction project calculator

include config.mk

NAME = drpc
DOCS = README.md
SRC = drpc.c 
OBJ = ${SRC:.c=.o}

all: options drpc

options:
	@echo ${NAME} build options:
	@echo "CFLAGS   = ${CFLAGS}"
	@echo "CC       = ${CC}"

.c.o:
	${CC} -c ${CFLAGS} $<

${OBJ}: config.mk

drpc: ${OBJ}
	${CC} -o $@ ${OBJ}

clean:
	rm -f drpc ${OBJ}

install: all
	mkdir -p ${DESTDIR}${BINDIR}
	cp -f drpc ${DESTDIR}${BINDIR}
	chmod 755 ${DESTDIR}${BINDIR}/drpc
	mkdir -p ${DESTDIR}${MANDIR}/man1
	cp -f drpc.1 ${DESTDIR}${MANDIR}/man1
	chmod 644 ${DESTDIR}${MANDIR}/man1/drpc.1

uninstall:
	rm -f ${DESTDIR}${BINDIR}/drpc
	rm -f ${DESTDIR}${MANDIR}/man1/drpc.1

.PHONY: all options clean install uninstall

A  => README.md +37 -0
@@ 1,37 @@
# drpc - doman reconstruction project calculator

drpc is a tool to ff14 players to calculate the number of allagan pieces to donate to the doman reconstruction project.


## Installation

Edit config.mk to match your local setup.

Enter the following command to build and install drpc:

	make install

By default, this will install files into /usr/local.


## Usage

`drpc [-r] [-p platinum] [-g gold] [-s silver] [-b bronze] [-t tin] cap rate`

`cap` is the weekly gil cap, e.g. `20000` for 20,000 gil

`rate` is the percentage bonus, e.g. `200` for 200%

`p`, `g`, `s`, `b`, and `t` are the available allagan pieces to donate

`s` reverses the priority to donate the cheap pieces first instead of the expensive pieces


## License

All drpc source code is distributed under the ISC license. See source files for verbatim license and copyright info.


## Contact

Send comments, bug reports, and patches to dev@dax.moe.

A  => config.mk +15 -0
@@ 1,15 @@
# Customize below to fit your system

# paths
PREFIX = /usr/local
BINDIR = ${PREFIX}/bin
DATAROOTDIR=${PREFIX}/share
DOCDIR = ${DATAROOTDIR}/doc
MANDIR = ${DATAROOTDIR}/man

# flags
CPPFLAGS = -D_XOPEN_SOURCE=700
CFLAGS   = -std=c99 -pedantic -Wall ${CPPFLAGS}

# compiler and linker
CC = cc

A  => drpc.1 +54 -0
@@ 1,54 @@
.\" Generated by scdoc 1.9.2
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.nh
.ad l
.\" Begin generated content:
.TH "drpc" "1" "2019-03-07"
.P
.SH NAME
.P
drpc - calculate donations for doman reconstruction project
.P
.SH SYNOPSIS
.P
\fBdrpc\fR [-r] [-p \fIplatinum\fR] [-g \fIgold\fR] [-s \fIsilver\fR] [-b \fIbronze\fR] [-t \fItin\fR] \fIcap\fR \fIrate\fR
.P
.SH DESCRIPTION
.P
\fBdrpc\fR is a tool to calculate the number of allagan pieces to donate to the doman reconstruction project.
.P
\fIcap\fR is the weekly gil cap.
.P
\fIrate\fR is the percentage buying rate.
.P
.SH OPTIONS
.P
\fB-p,g,s,b,t\fR
.RS 4
Number of allagan pieces available to donate:
Platinum, Gold, Silver, Bronze, and Tin
.P
.RE
\fB-r\fR
.RS 4
Reverse the priority of donation to lower-cost pieces instead of high-cost pieces
.P
.RE
.SH EXAMPLE
.P
Calculate how many pieces to donate with a 20,000 gil cap and a 200% rate, with 50 gold pieces and 20 bronze pieces:
.P
.RS 4
drpc -g 50 -b 20 20000 200
.P
.RE
Donate the cheaper pieces first:
.RS 4
.P
drpc -r -g 50 -b 20 20000 200
.P
.RE
.SH AUTHORS
.P
dax <dax@dax.moe>

A  => drpc.1.scd +40 -0
@@ 1,40 @@
drpc(1)

# NAME

drpc - calculate donations for doman reconstruction project

# SYNOPSIS

*drpc* [-r] [-p _platinum_] [-g _gold_] [-s _silver_] [-b _bronze_] [-t _tin_] _cap_ _rate_

# DESCRIPTION

*drpc* is a tool to calculate the number of allagan pieces to donate to the doman reconstruction project.

_cap_ is the weekly gil cap.

_rate_ is the percentage buying rate.

# OPTIONS

*-p,g,s,b,t*
	Number of allagan pieces available to donate:
	Platinum, Gold, Silver, Bronze, and Tin

*-r*
	Reverse the priority of donation to lower-cost pieces instead of high-cost pieces

# EXAMPLE

Calculate how many pieces to donate with a 20,000 gil cap and a 200% rate, with 50 gold pieces and 20 bronze pieces:

	drpc -g 50 -b 20 20000 200

Donate the cheaper pieces first:
	
	drpc -r -g 50 -b 20 20000 200

# AUTHORS

dax <dax@dax.moe>

A  => drpc.c +102 -0
@@ 1,102 @@
/**
 * Copyright 2019 dax <dax@dax.moe>
 * 
 * Permission to use, copy, modify, and/or distribute this software for any 
 * purpose with or without fee is hereby granted, provided that the above 
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 **/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define MIN(a,b) ((a < b) ? a:b)

enum {
	PLAT,
	GOLD,
	SILVER,
	BRONZE,
	TIN,
};

int value[5] = {10000, 2500, 500, 100, 25};

int
main(int argc, char **argv)
{
	int pieces[5] = {0,0,0,0,0};
	int donate[5] = {0,0,0,0,0};
	int cap;
	double rate;
	int reverse;
	const char *usage = "usage: drpc [-r] [-p platinum] [-g gold] [-s silver] [-b bronze] [-t tin] cap rate";

	int opt;
	while ((opt = getopt(argc, argv, "hrp:g:s:b:t:")) >= 0) {
		switch (opt) {
		case 'r':
			reverse = 1;
			break;
		case 'p':
			pieces[PLAT] = atoi(optarg);
			break;
		case 'g':
			pieces[GOLD] = atoi(optarg);
			break;
		case 's':
			pieces[SILVER] = atoi(optarg);
			break;
		case 'b':
			pieces[BRONZE] = atoi(optarg);
			break;
		case 't':
			pieces[TIN] = atoi(optarg);
			break;
		case 'h':
		default:
			fprintf(stderr, "%s\n", usage);
			exit(EXIT_FAILURE);
		}
	}

	argc -= optind;
	if (argc < 2) {
		fprintf(stderr, "error: too few arguments\n");
		fprintf(stderr, "%s\n", usage);
		exit(EXIT_FAILURE);
	} else if (argc > 2) {
		fprintf(stderr, "error: too many arguments\n");
		fprintf(stderr, "%s\n", usage);
		exit(EXIT_FAILURE);
	}

	cap = atoi(argv[optind]);
	rate = atof(argv[++optind]);

	for (int i = 0; i < 5; i++) {
		int type = i;
		if (reverse) {
			type = 5 - i - 1;
		}
		value[type] = (int)(value[type] * (100/rate));
		donate[type] = MIN((int)(cap / value[type]), pieces[type]);
		cap -= value[type] * donate[type];
	}

	printf("%d platnum\n", donate[PLAT]);
	printf("%d gold\n", donate[GOLD]);
	printf("%d silver\n", donate[SILVER]);
	printf("%d bronze\n", donate[BRONZE]);
	printf("%d tin\n", donate[TIN]);
	printf("%d remaining\n", cap);
	exit(EXIT_SUCCESS); 
}