Compare commits

..

No commits in common. "cc33fd3e2c3c246bd9ba3a925a01bec3b6e93b5a" and "ecec3ea611a269341bf3d884ac9ff79094427c79" have entirely different histories.

5 changed files with 21 additions and 19 deletions

View File

@ -169,7 +169,7 @@ void remove_admin(char* role){
} }
char line[100]; char line[100];
while(fgets(line,100,fp) != NULL){ while(fgets(line,100,fp) != NULL){
if(unlikely(line[0] == '#')) { if(line[0] == '#') {
fprintf(fp2,"%s",line); fprintf(fp2,"%s",line);
continue; continue;
} }
@ -194,7 +194,7 @@ int basic_get_row_count(int end, FILE *fp){
while(!feof(fp)&&!ferror(fp)){ while(!feof(fp)&&!ferror(fp)){
char buffer[100]; char buffer[100];
fgets(buffer, sizeof(buffer),fp); fgets(buffer, sizeof(buffer),fp);
if(unlikely(buffer[0] == '#' || buffer[0] == '\0')){//catch comment line and ignore if(buffer[0] == '#' || buffer[0] == '\0'){//catch comment line and ignore
continue; continue;
} }
colmun_count++; colmun_count++;
@ -223,7 +223,7 @@ struct inventory read_db_invt(){//please open file in read mode
for(INVENTORY j=category;j<=ENDOFINVENTORY;j++){ for(INVENTORY j=category;j<=ENDOFINVENTORY;j++){
char buffer[100]; char buffer[100];
fgets(buffer, sizeof(buffer),fp); fgets(buffer, sizeof(buffer),fp);
if(unlikely(buffer[0] == '#')){//catch comment line and ignore if(buffer[0] == '#'){//catch comment line and ignore
j--;//decrement j to prevent skipping next column j--;//decrement j to prevent skipping next column
}else{ }else{
buffer[strlen(buffer)] = '\0'; buffer[strlen(buffer)] = '\0';
@ -265,6 +265,8 @@ struct inventory read_db_invt(){//please open file in read mode
fclose(fp); fclose(fp);
db.db.init_status = true; db.db.init_status = true;
return db; return db;
} }
struct transaction read_db_tran(){ struct transaction read_db_tran(){
FILE* fp = fopen(TRANSACTION_DB, "r"); FILE* fp = fopen(TRANSACTION_DB, "r");
@ -283,7 +285,7 @@ struct transaction read_db_tran(){
for(TRANSACTION j=date;j<=ENDOFTRANSACTION;j++){ for(TRANSACTION j=date;j<=ENDOFTRANSACTION;j++){
char buffer[100]; char buffer[100];
fgets(buffer, sizeof(buffer),fp); fgets(buffer, sizeof(buffer),fp);
if(unlikely(buffer[0] == '#')){//catch comment line and ignore if(buffer[0] == '#'){//catch comment line and ignore
j--;//decrement j to prevent skipping next column j--;//decrement j to prevent skipping next column
}else{ }else{
buffer[strlen(buffer)] = '\0'; buffer[strlen(buffer)] = '\0';
@ -342,7 +344,7 @@ struct user read_db_user(){
for(USER j=name;j<=ENDOFUSER;j++){ for(USER j=name;j<=ENDOFUSER;j++){
char buffer[100]; char buffer[100];
fgets(buffer, sizeof(buffer),fp); fgets(buffer, sizeof(buffer),fp);
if(unlikely(buffer[0] == '#')){//catch comment line and ignore if(buffer[0] == '#'){//catch comment line and ignore
j--;//decrement j to prevent skipping next column j--;//decrement j to prevent skipping next column
}else{ }else{
buffer[strlen(buffer)] = '\0';//prevent any garbage value buffer[strlen(buffer)] = '\0';//prevent any garbage value
@ -461,12 +463,15 @@ bool update_db_invt(struct inventory invt){
return false; return false;
} }
for(int i=0;i<invt.db.row_count;i++){ for(int i=0;i<invt.db.row_count;i++){
if(invt.row[i].barcode == -1024 || invt.row[i].isdeleted == true)//skip create new row if(invt.row[i].barcode == -1024)//skip create new row
continue; continue;
if(invt.row[i].isdeleted == true){
continue;
}
for(INVENTORY j=category;j<=ENDOFINVENTORY;j++){ for(INVENTORY j=category;j<=ENDOFINVENTORY;j++){
char buffer[100]; char buffer[100];
do{ do{
if(unlikely(feof(fpR))){ if(feof(fpR)){
break; break;
} }
fgets(buffer, sizeof(buffer),fpR); fgets(buffer, sizeof(buffer),fpR);
@ -522,7 +527,7 @@ bool update_db_tran(struct transaction tran){
for(TRANSACTION j=date;j<=ENDOFTRANSACTION;j++){ for(TRANSACTION j=date;j<=ENDOFTRANSACTION;j++){
char buffer[100]; char buffer[100];
do{ do{
if(unlikely(feof(fpR))){ if(feof(fpR)){
break; break;
} }
fgets(buffer, sizeof(buffer),fpR); fgets(buffer, sizeof(buffer),fpR);
@ -577,7 +582,7 @@ bool update_db_user(struct user user){
for(USER j=name;j<=ENDOFUSER;j++){ for(USER j=name;j<=ENDOFUSER;j++){
char buffer[100]; char buffer[100];
do{ do{
if(unlikely(feof(fpR))){ if(feof(fpR)){
break; break;
} }
fgets(buffer, sizeof(buffer),fpR); fgets(buffer, sizeof(buffer),fpR);

Binary file not shown.

View File

@ -133,7 +133,7 @@ void add_tran(){
free(row); free(row);
return; return;
} }
if(!row || !append_transaction_db(row)){ if(row == NULL || !append_transaction_db(row)){
printf("Failed to add item\n"); printf("Failed to add item\n");
}else{ }else{
printf("Item added\n"); printf("Item added\n");
@ -165,7 +165,7 @@ struct transaction update_tran(struct transaction db,int index){
item_inputer("ID",LONG,&db.row[index].id,true); item_inputer("ID",LONG,&db.row[index].id,true);
item_inputer("Barcode",LONG,&db.row[index].barcode,true); item_inputer("Barcode",LONG,&db.row[index].barcode,true);
if(unlikely(!update_db_tran(db))){ if(!update_db_tran(db)){
printf("Failed to update transaction\n"); printf("Failed to update transaction\n");
exit(1);//exit program to prevent errors exit(1);//exit program to prevent errors
}else{ }else{
@ -180,7 +180,7 @@ struct transaction update_tran(struct transaction db,int index){
struct transaction remove_tran(struct transaction db,int index){ struct transaction remove_tran(struct transaction db,int index){
db.row[index].isdeleted = true; db.row[index].isdeleted = true;
if(unlikely(!update_db_tran(db))){ if(!update_db_tran(db)){
printf("Failed to delete transaction\n"); printf("Failed to delete transaction\n");
exit(1);//exit program to prevent errors exit(1);//exit program to prevent errors
}else{ }else{

View File

@ -90,7 +90,7 @@ struct user add_user(struct user db){
return db; return db;
} }
if(unlikely(!append_user(temprow))){ if(!append_user(temprow)){
printf("Failed to add user\n"); printf("Failed to add user\n");
exit(1);//exit program to prevent errors exit(1);//exit program to prevent errors
}else{ }else{
@ -111,7 +111,7 @@ struct user edit_user(struct user db,int index){
item_inputer("id",LONG,&db.row[index].id,true); item_inputer("id",LONG,&db.row[index].id,true);
item_inputer("role",STRING,&db.row[index].role,true); item_inputer("role",STRING,&db.row[index].role,true);
if(unlikely(!update_db_user(db))){ if(!update_db_user(db)){
printf("Failed to update user\n"); printf("Failed to update user\n");
exit(1);//exit program to prevent errors exit(1);//exit program to prevent errors
}else{ }else{
@ -125,7 +125,7 @@ struct user edit_user(struct user db,int index){
} }
struct user delete_user(struct user db,int index){ struct user delete_user(struct user db,int index){
db.row[index].isdeleted = true; db.row[index].isdeleted = true;
if(unlikely(!update_db_user(db))){ if(!update_db_user(db)){
printf("Failed to delete user\n"); printf("Failed to delete user\n");
exit(1);//exit program to prevent errors exit(1);//exit program to prevent errors
}else{ }else{

View File

@ -14,10 +14,7 @@
#include <stdio_ext.h> #include <stdio_ext.h>
#endif #endif
#define SIZE_OF_PAGE 20 #define SIZE_OF_PAGE 20
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
void Cls(){ void Cls(){
#ifdef _WIN32 #ifdef _WIN32
system("cls"); system("cls");