Update scanner.c
This commit is contained in:
parent
24ff911c78
commit
f7a2389e70
1 changed files with 100 additions and 102 deletions
202
scanner.c
202
scanner.c
|
|
@ -1,102 +1,100 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char* reverseStrchr(const char* str, int character) {
|
||||
char* result = NULL;
|
||||
// Iterate through the string
|
||||
while (*str != '\0') {
|
||||
// If the character is found, update the result pointer
|
||||
if (*str == character) {
|
||||
result = (char*)str;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void parse (char input[75]) {
|
||||
//Morphs input assuming it's a scan to batch code
|
||||
int lenny;
|
||||
if (strcmp(&input[0], "") == 0) {
|
||||
// pass
|
||||
}
|
||||
else if ('[' == input[0]) { // This handles OldSquare code
|
||||
//printf("A step is, %d \n", step);
|
||||
//printf("I got it!\n");
|
||||
char* entry = strchr(input, '$');
|
||||
//printf("Entry is: %p\n", entry);
|
||||
char* exit = reverseStrchr(input, '\x1D');
|
||||
//printf("Exit is: %p\n", exit);
|
||||
lenny = exit - entry - 1;
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char result[lenny+1];
|
||||
strncpy(result, (entry+1), lenny);
|
||||
result[lenny]='\0';
|
||||
//printf("%s\n", result);
|
||||
strcpy(input, result);
|
||||
}
|
||||
else if ('+' == input[0]) {
|
||||
//We could have Old top or Old Bot code here.
|
||||
if ('$' == input[1]) {
|
||||
//Old bot code
|
||||
//+$13KM083319L
|
||||
lenny = strlen(input);
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char result[lenny-4];
|
||||
strncpy(result, &input[2], lenny-4);
|
||||
result[lenny-4] = '\0';
|
||||
//printf("%s\n", result);
|
||||
strcpy(input, result);
|
||||
}
|
||||
else {
|
||||
printf("This Barcode does not contain a Batch code\n");
|
||||
}
|
||||
}
|
||||
else if ('0' == input[0]) {
|
||||
char result[10];
|
||||
lenny = strlen(input);
|
||||
strncpy(result, &input[26], lenny-26);
|
||||
//printf("%s\n", result);
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
strcpy(input, result);
|
||||
}
|
||||
else if (strchr(input, '|')) {
|
||||
//printf("I got it!\n");
|
||||
lenny = strlen(input);
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char* entry = strchr(input, '|');
|
||||
char holder[75];
|
||||
strncpy(holder, entry+1, lenny-(entry-&input[0]));
|
||||
//printf("Holder is: %s\n", holder);
|
||||
entry = strchr(holder, '|');
|
||||
lenny = entry - &holder[0];
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char result[lenny];
|
||||
strncpy(result, &holder[0], lenny);
|
||||
//printf("Result is: %s\n", result);
|
||||
result[lenny] = '\0';
|
||||
strcpy(input, result);
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
char input[75]; // 75 char limit
|
||||
printf("Begin scanning (type 'exit' to quit):\n");
|
||||
|
||||
while (1) {
|
||||
// Read user input
|
||||
fgets(input, sizeof(input), stdin);
|
||||
fputs("\033[A\033[2K",stdout);
|
||||
strtok(input, "\n");
|
||||
parse(input);
|
||||
|
||||
// Check if the user wants to exit
|
||||
if (strcmp(input, "exit") == 0) {
|
||||
printf("Exiting program. Goodbye!");
|
||||
break; // Exit the loop if the user types 'exit'
|
||||
}
|
||||
|
||||
// Print the input
|
||||
printf("%s\n", input);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char* reverseStrchr(const char* str, int character) {
|
||||
char* result = NULL;
|
||||
// Iterate through the string
|
||||
while (*str != '\0') {
|
||||
if (*str == character) {
|
||||
result = (char*)str;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void parse (char input[75]) {
|
||||
int lenny;
|
||||
if (strcmp(&input[0], "") == 0) {
|
||||
// pass
|
||||
}
|
||||
else if ('[' == input[0]) { // This handles OldSquare code
|
||||
//printf("A step is, %d \n", step);
|
||||
//printf("I got it!\n");
|
||||
char* entry = strchr(input, '$');
|
||||
//printf("Entry is: %p\n", entry);
|
||||
char* exit = reverseStrchr(input, '\x1D');
|
||||
//printf("Exit is: %p\n", exit);
|
||||
lenny = exit - entry - 1;
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char result[lenny+1];
|
||||
strncpy(result, (entry+1), lenny);
|
||||
result[lenny]='\0';
|
||||
//printf("%s\n", result);
|
||||
strcpy(input, result);
|
||||
}
|
||||
else if ('+' == input[0]) {
|
||||
//We could have Old top or Old Bot code here.
|
||||
if ('$' == input[1]) {
|
||||
//Old bot code
|
||||
//+$13KM083319L
|
||||
lenny = strlen(input);
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char result[lenny-4];
|
||||
strncpy(result, &input[2], lenny-4);
|
||||
result[lenny-4] = '\0';
|
||||
//printf("%s\n", result);
|
||||
strcpy(input, result);
|
||||
}
|
||||
else {
|
||||
printf("This Barcode does not contain a Batch code\n");
|
||||
}
|
||||
}
|
||||
else if ('0' == input[0]) {
|
||||
char result[10];
|
||||
lenny = strlen(input);
|
||||
strncpy(result, &input[26], lenny-26);
|
||||
//printf("%s\n", result);
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
strcpy(input, result);
|
||||
}
|
||||
else if (strchr(input, '|')) {
|
||||
//printf("I got it!\n");
|
||||
lenny = strlen(input);
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char* entry = strchr(input, '|');
|
||||
char holder[75];
|
||||
strncpy(holder, entry+1, lenny-(entry-&input[0]));
|
||||
//printf("Holder is: %s\n", holder);
|
||||
entry = strchr(holder, '|');
|
||||
lenny = entry - &holder[0];
|
||||
//printf("Lenny is: %d\n", lenny);
|
||||
char result[lenny];
|
||||
strncpy(result, &holder[0], lenny);
|
||||
//printf("Result is: %s\n", result);
|
||||
result[lenny] = '\0';
|
||||
strcpy(input, result);
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
char input[75]; // 75 char limit
|
||||
printf("Begin scanning (type 'exit' to quit):\n");
|
||||
|
||||
while (1) {
|
||||
// Read user input
|
||||
fgets(input, sizeof(input), stdin);
|
||||
fputs("\033[A\033[2K",stdout);
|
||||
strtok(input, "\n");
|
||||
parse(input);
|
||||
|
||||
// Check if the user wants to exit
|
||||
if (strcmp(input, "exit") == 0) {
|
||||
printf("Exiting program. Goodbye!");
|
||||
break; // Exit the loop if the user types 'exit'
|
||||
}
|
||||
|
||||
// Print the input
|
||||
printf("%s\n", input);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue