MUBLE v0.01
// ALL RIGHTS RESERVED TO DARIUS_II (c) 2005 | darius_ll@yahoo.com
// this is a SNAPSHOT of MUBLE v0.01
// ment to show how the things will work and look from the public side
// more as the operators of the program
// – missing the data type and libs implementation
// – and with this also the loading and saving of the data to files.
// – this features will be up in the v1.00 of MUBLE that is now in
// testing mode and will be made public next week.
#include
#include
#include
#include
// Maximum Code Length
#define MCL 8
// Maximum Rest Length
#define MRL 255
// Minimum Code Length
#define mcl 5
// minimul Rest Length
#define mrl 5
char ACTIVE[MCL]=””; //this will be a future pointer to a member of a list
//who’s info will be a user type data
//and this initialization will be NULL
void muble(int i) {
printf(„Welcome to MUBLE (Management of Users, Books and Lending Event)\n”);
if (i==0)
printf(„+ (M)enu || (E)xit + 2005 (c) Darius II ver. 0.01\n”);
}
void info(char *cod) {
printf(„info: %s\n”,cod);
// this function will print the info details of the given code
// it will work for any of user/book/lending data types
}
void menu(char *cod) {
printf(„menu: %s\n”,cod);
// this function will print specified menu for the data types
// meaning different menu for user/book/lend event
// ALSO IF THE CODE POINTS TO A REAL CODE OF BOOKS/USERS/LENDS
// WILL GIVE ACCESS AND PRINT EXTRA OPTIONS / COMMANDS.
}
void menu() {
printf(„+ +\n”);
printf(„ (M)main \n”);
printf(„ (U)user \n”);
printf(„ (B)ooks \n”);
printf(„ (L)end \n”);
printf(„ (E)xit \n”);
printf(„+ +\n”);
}
void lend(char *cod, char *rst) {
// this function will register a new lend event
// like lending on/off book(s)
// ALSO CALL INFO AND MENU if code will be a valid lend code
if (cod[0]==’u’) printf(„Lend: %s == %s\n”,cod,rst);
if (cod[0]==’l’) {info(cod);menu(cod);}
}
void user(char *cod, char *rst) {
// this function will register a new user event
// IF REST AVAILABLE will quickly lend the books from
// the RST line
// ALSO CALL INFO AND MENU if code will be a valid user code
if (strlen(cod)>1) {
info(cod);
if ((strlen(rst)>=mrl) && (strlen(cod)>=mcl)) lend(cod,rst);
else printf(„[COD: (%d>=%d) && RST: (%d>=%d)] invalid lend params.\n”,strlen(cod),mcl,strlen(rst),mrl);
strcpy(ACTIVE,cod);
}
menu(cod);
}
void book(char *cod, char *rst) {
// this function will register a new book event
// like adding, modify, lending on/off book(s)* – if user active
// ALSO CALL INFO AND MENU if code will be a valid book code
if (strlen(cod)>1) {
info(cod);
if (strlen(ACTIVE)>mcl) {
if (strlen(cod)>mcl) lend(ACTIVE,cod);
else printf(„[COD: (%d>=%d)] invalid lend params.\n”,strlen(cod),mcl);
if (strlen(rst)>mcl) lend(ACTIVE,rst);
else printf(„[RST: (%d>=%d)] invalid lend params.\n”,strlen(rst),mrl);
}
}
menu(cod);
}
void analize(char* line) {
// this function will determine how the command must be interpreted
clrscr();
if (strlen(line)<1) return;
char cod[MCL]=””;
char rst[MRL]=””;
//printf(„command: %s\n”,line);
if (strlen(line)>mcl) {
//strncat(cod,line,7);
char *p;
p=strtok(line,” „);
strcpy(cod,p);
printf(„cod: %s (%d)\n”,cod,strlen(cod));
p=strtok(NULL,NULL);
strcpy(rst,p);
printf(„rst: %s (%d)\n”,rst,strlen(rst));
}
char x=line[0];
tolower(x);
switch (x) {
case ‘m’:muble(1);printf(„Mainmenu:\n”);menu();break;
case ‘u’:printf(„Usermenu:\n”);user(cod,rst);break;
case ‘b’:printf(„Bookmenu:\n”);book(cod,rst);break;
case ‘l’:printf(„Lendmenu:\n”);lend(cod,rst);break;
case ‘e’:muble(1);printf(„Whatever.\n”);break;
default :muble(0);printf(„Wrong command. (%c #%d | %s)\n”,line[0],line[0],line);
}
}
void main(void) {
clrscr();
char cmdline[MRL];
muble(0);
do {
printf(„#”);
gets(cmdline);
if (strlen(cmdline)>0) analize(cmdline);
}
while (cmdline[0]!=’e’);
printf(„\n.d2.bye.\n”);
getch();
return;
}
Lasă un comentariu