reorganization

This commit is contained in:
Pavol Rusnak 2011-06-12 19:33:18 +02:00
parent bdd9f6ac92
commit fd6e33a390
11 changed files with 19 additions and 11 deletions

2
dos/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
brmbar
brmbar.com

12
dos/Makefile Normal file
View file

@ -0,0 +1,12 @@
CC=bcc
CFLAGS=-Md -W -O
all: brmbar.c
# gcc -Wall brmbar.c dataio.c -o brmbar
bcc $(CFLAGS) brmbar.c dataio.c gfx.c -o brmbar.com
clean:
rm -f brmbar.com brmbar barcodes.svg
dos:
dosbox brmbar.com

149
dos/brmbar.c Normal file
View file

@ -0,0 +1,149 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dataio.h"
#define EAN_MAXLEN 16
#define NAME_MAXLEN 64
#define PERSON_MAXLEN 16
#define ITEMS_MAXCOUNT 512
#define PEOPLE_MAXCOUNT 128
#define BUFSIZE 128
struct item {
char ean[EAN_MAXLEN];
char name[NAME_MAXLEN];
int price;
};
struct item items[ITEMS_MAXCOUNT];
char people[PEOPLE_MAXCOUNT][PERSON_MAXLEN];
int items_count;
int people_count;
int last_item = -1;
char buf[BUFSIZE];
void fill_items()
{
FILE *f = fopen("items.txt", "r");
items_count = 0;
while (fgets(buf, BUFSIZE, f)) {
int i = 0;
int begin = 0;
//Initialize the item
items[items_count].ean[0] = 0;
items[items_count].name[0] = 0;
items[items_count].price = 0;
//Read the item EAN
while (i < BUFSIZE) {
if (buf[i] == ';') {
buf[i] = 0;
strcpy(items[items_count].ean, &buf[begin]);
buf[i] = ';';
begin = i + 1;
break;
}
i++;
}
//Read the item name
i = begin;
while (i < BUFSIZE) {
if (buf[i] == ';') {
buf[i] = 0;
strcpy(items[items_count].name, &buf[begin]);
buf[i] = ';';
begin = i+1;
break;
}
i++;
}
//Use scanf to read the item price
i = begin;
if (i < BUFSIZE) {
sscanf(&buf[i], "%d", &items[items_count].price);
}
items_count++;
}
fclose(f);
}
void fill_people()
{
FILE *f = fopen("people.txt", "r");
people_count = 0;
while (fgets(people[people_count], PERSON_MAXLEN , f)) {
char *c = strpbrk(people[people_count], " \t\r\n");
if (c) *c = 0;
people[people_count][PERSON_MAXLEN-1] = 0;
++people_count;
}
fclose(f);
}
void read_input()
{
int i, balance;
printf("> ");
if (!fgets(buf, BUFSIZE, stdin)) return;
// scan items
for (i = 0; i < items_count; ++i) {
if (!strncmp(buf, items[i].ean, strlen(items[i].ean)) && strlen(items[i].ean)+1 == strlen(buf)) {
if (items[i].price == 30000) {
last_item = -2;
printf("\n%s\n\n", items[i].name);
} else
if (items[i].price == 0) {
last_item = -1;
printf("\n%s\n\n", items[i].name);
} else {
last_item = i;
printf("\n%s %d Kc\n\n", items[i].name, abs(items[i].price));
}
return;
}
}
// scan people
for (i = 0; i < people_count; ++i) {
if (!strncmp( buf, people[i], 3 )) {
printf("\nMember %s ", people[i]);
if (last_item == -1) {
balance = modify_credit(people[i], 0);
printf("has %d Kc.\n\n", balance);
} else
if (last_item == -2) {
balance = modify_credit(people[i], 0);
modify_credit(people[i], -balance);
printf("has credit set to 0 Kc.\n\n");
} else {
balance = modify_credit(people[i], items[last_item].price);
printf("has ordered %s for %d Kc and now has %d Kc.\n\n", items[last_item].name, abs(items[last_item].price), balance);
last_item = -1;
}
return;
}
}
// error
printf("\nUnknown code %s\n", buf);
}
int main()
{
fill_items();
fill_people();
for (;;) {
read_input();
}
return 0;
}

46
dos/dataio.c Normal file
View file

@ -0,0 +1,46 @@
#include <stdio.h>
#include <string.h>
#include "dataio.h"
int modify_credit(name, price)
const char* name;
int price;
{
char filename[20];
int i;
int credit;
FILE* person_data;
strcpy(filename, "DATA\\");
i = 5;
strncpy(&filename[i], name, 8);
if (strlen(name) > 8) {
i += 8;
} else {
i += strlen(name);
}
strcpy(&filename[i], ".txt");
person_data = fopen(filename, "r");
if (person_data == NULL) {
// printf("Warning: Filename %s does not exist!\n", filename);
credit = 0;
} else {
fscanf(person_data, "%i", &credit);
fclose(person_data);
}
// Write only if the price would change credit
if (price != 0) {
credit += price;
person_data = fopen(filename, "w");
if (person_data == NULL) {
// printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
} else {
fprintf(person_data, "%i", credit);
fclose(person_data);
}
}
return credit;
}

6
dos/dataio.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef _BRMBAR_DATAIO_H_
#define _BRMBAR_DATAIO_H_
extern int modify_credit(name, price);
#endif

35
dos/gfx.c Normal file
View file

@ -0,0 +1,35 @@
#include "gfx.h"
void init_graphics() {
#asm
mov al, #0x13
mov ah, #0x0
int 0x10
#endasm
}
void put_pixel(x, y, color)
int x;
int y;
char color;
{
x = x + y*320;
#asm
mov ax, #0xa000
mov es, ax
mov al, _put_pixel.color[bp]
mov di, _put_pixel.x[bp]
seg es
mov [di], al
#endasm
}
void deinit_graphics() {
#asm
mov al, #0x12
mov ah, #0x0
int 0x10
#endasm
}

14
dos/gfx.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef _BRMBAR_GRAPHIX_H_
#define _BRMBAR_GRAPHIX_H_
#define COL_WHITE 15
#define COL_BLACK 0
extern void init_graphics();
extern void put_pixel(x, y, color);
extern void deinit_graphics();
#endif

23
dos/items.txt Normal file
View file

@ -0,0 +1,23 @@
$02;Credit 20;20
$05;Credit 50;50
$10;Credit 100;100
$20;Credit 200;200
$50;Credit 500;500
$1k;Credit 1000;1000
SHW;SHOW credit;0
RST;RESET credit;30000
4029764001807;Club Mate 0.5L;-35
4029764001821;Club Mate 0.33L;-25
5018374350930;Tesco Baked Beans in Tomato Sauce;-20
7622300331436;Delissa mlecna;-10
7622300331498;Delissa oriskova;-10
8593868000555;Pivo Branik 10% svetle;-25
8594404000329;Pivo Gambrinus 10% svetle;-25
8594404001241;Pivo Radegast 10% svetle;-25
8594001021512;Matonni perliva 1,5L;-20
5449000000286;Coca-Cola 2L;-50
8801043263108;Shin Cup Noodle Soup;-25
8934646229308;Lucky Beef Flavor;-10
8594033171902;Big Shock tycinka;-15
85909311;Margot tycinka;-15
8584004041198;Tatranky;-8

32
dos/people.txt Normal file
View file

@ -0,0 +1,32 @@
abyssal
alexka
axtheb
aym
b00lean
biiter
blami
chido
czestmyr
fissie
harvie
jenda
joe
johny
kubicekh
kxt
lui
nephirus
niekt0
pasky
pborky
prusajr
rainbof
ruza
sargon
shady
stevko
stick
tma
tomsuch
tutchek
zombie