mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +02:00
Merge branch 'master' of github.com:brmlab/brmbar
Conflicts: Makefile brmbar.c
This commit is contained in:
commit
3d8cbd98b4
5 changed files with 92 additions and 26 deletions
4
Makefile
4
Makefile
|
@ -1,12 +1,12 @@
|
|||
CC=bcc
|
||||
CFLAGS=-Md -W
|
||||
|
||||
all: brmbar.c defines.h
|
||||
all: brmbar.c
|
||||
gcc -Wall brmbar.c -o brmbar
|
||||
bcc -Md -W brmbar.c -o brmbar.com
|
||||
|
||||
clean:
|
||||
rm -f brmbar.com brmbar
|
||||
rm -f brmbar.com
|
||||
|
||||
dos:
|
||||
dosbox brmbar.com
|
||||
|
|
93
brmbar.c
93
brmbar.c
|
@ -1,24 +1,74 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "defines.h"
|
||||
|
||||
#define EAN_MAXLEN 32
|
||||
#define NAME_MAXLEN 128
|
||||
#define PERSON_MAXLEN 16
|
||||
#define ITEMS_MAXCOUNT 128
|
||||
#define PEOPLE_MAXCOUNT 128
|
||||
#define BUFSIZE 128
|
||||
|
||||
struct item {
|
||||
char ean[EAN_MAXLEN];
|
||||
char name[NAME_MAXLEN];
|
||||
int price;
|
||||
} items[ITEM_MAXNUM];
|
||||
};
|
||||
|
||||
char *people[PERSON_MAXLEN];
|
||||
struct item items[ITEMS_MAXCOUNT];
|
||||
char people[PEOPLE_MAXCOUNT][PERSON_MAXLEN];
|
||||
|
||||
int items_count;
|
||||
int people_count;
|
||||
|
||||
char buf[BUFSIZE];
|
||||
|
||||
void fill_items()
|
||||
{
|
||||
char buf[128];
|
||||
FILE *f = fopen("items.txt", "r");
|
||||
while (fgets(buf, 128, f)) {
|
||||
printf("%s\n", buf);
|
||||
|
||||
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] == '\t') {
|
||||
buf[i] = 0;
|
||||
strcpy(items[items_count].ean, &buf[begin]);
|
||||
buf[i] = '\t';
|
||||
begin = i + 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//Read the item name
|
||||
i = begin;
|
||||
while (i < BUFSIZE) {
|
||||
if (buf[i] == '\t') {
|
||||
buf[i] = 0;
|
||||
strcpy(items[items_count].name, &buf[begin]);
|
||||
buf[i] = '\t';
|
||||
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);
|
||||
}
|
||||
|
@ -28,35 +78,42 @@ void fill_people()
|
|||
FILE *f = fopen("people.txt", "r");
|
||||
people_count = 0;
|
||||
while (fgets(people[people_count], PERSON_MAXLEN , f)) {
|
||||
char *c = strchr(people[people_count], '\n');
|
||||
if (c) *c = 0;
|
||||
people[people_count][PERSON_MAXLEN-1] = 0;
|
||||
++people_count;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
int read_item() {
|
||||
char buf[128];
|
||||
int i;
|
||||
for (;;) {
|
||||
printf("i> ");
|
||||
if (fgets(buf, 128, stdin)) {
|
||||
if (fgets(buf, BUFSIZE, stdin)) {
|
||||
for (i = 0; i < items_count; ++i) {
|
||||
if (!strncmp( buf, items[i].ean, strlen(items[i].ean) )) {
|
||||
if (items[i].price) {
|
||||
printf("Item: %s (%d Kc)\n\n", items[i].name, items[i].price);
|
||||
} else {
|
||||
printf("Item: %s\n\n", items[i].name);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
printf("Unknown item %s\n", buf);
|
||||
printf("Unknown item: %s\n", buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int read_person() {
|
||||
char buf[128];
|
||||
int i;
|
||||
for (;;) {
|
||||
printf("p> ");
|
||||
if (fgets(buf, 128, stdin)) {
|
||||
if (fgets(buf, BUFSIZE, stdin)) {
|
||||
for (i = 0; i < people_count; ++i) {
|
||||
if (!strncmp( buf, people[0], strlen(people[0]) )) {
|
||||
if (!strncmp( buf, people[i], strlen(people[i]) )) {
|
||||
printf("Person: %s\n\n", people[i]);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -65,13 +122,25 @@ int read_person() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void do_action(i, p) int i; int p; {
|
||||
// TODO: perform action - person P selected item I
|
||||
if (!strcmp("BACK", people[p])) {
|
||||
printf("Going back ...\n\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, p;
|
||||
fill_items();
|
||||
fill_people();
|
||||
for (;;) {
|
||||
i = read_item();
|
||||
p = read_person();
|
||||
do_action(i, p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
10
defines.h
10
defines.h
|
@ -1,10 +0,0 @@
|
|||
#ifndef _BRMBAR_DEFINES_H_
|
||||
#define _BRMBAR_DEFINES_H_
|
||||
|
||||
#define EAN_MAXLEN 32
|
||||
#define NAME_MAXLEN 128
|
||||
#define ITEM_MAXNUM 128
|
||||
#define PERSON_MAXLEN 16
|
||||
|
||||
#endif
|
||||
|
10
items.txt
10
items.txt
|
@ -1,2 +1,8 @@
|
|||
4029764001807 Club Mate 0.5L 35
|
||||
4029764001821 Club Mate 0.33L 25
|
||||
cred50 Credit 50
|
||||
cred100 Credit 100
|
||||
cred200 Credit 200
|
||||
cred500 Credit 500
|
||||
cred1000 Credit 1000
|
||||
status Status 0
|
||||
4029764001807 Club Mate 0.5L -35
|
||||
4029764001821 Club Mate 0.33L -25
|
||||
|
|
|
@ -3,3 +3,4 @@ czestmyr
|
|||
niekt0
|
||||
stick
|
||||
tomsuch
|
||||
BACK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue