часть условий

feature-input-file
Numillyash 2022-10-20 12:25:45 +03:00
parent be382be864
commit 3f2b307e36
3 changed files with 88 additions and 6 deletions

View File

@ -36,7 +36,7 @@ int main()
char selects[7] = { 0, 5, 3, -1, -1, -1, -1 };
Condition a = { moreEqual, 2, 0, NULL, 0, NULL };
Condition* conditions[7] = { NULL, NULL, NULL, &a, NULL, NULL, NULL };
Condition* conditions[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
/*printf("\nselect:%d \n", selectFunc(selects, conditions));
printf("\nupdate:%d \n", updateFunc("TeStNaMe", NULL, -1, -1, NULL, NULL, NULL, conditions));
printf("\nselect:%d \n", selectFunc(selects, conditions));*/
@ -54,6 +54,9 @@ int main()
printDataBase();
parceLine("uniq first_nm");
printDataBase();
char line[] = "curse_id>=3";
parceCondition(line, conditions);
printf("\nselect:%d \n", selectFunc(selects, conditions));
parceLine("exit");

View File

@ -426,7 +426,7 @@ restartCycle:
char* formateTime(time_t time)
{
char* string = asctime(gmtime(time));
char* string = asctime(gmtime(&time));
char* symb = strchr(string, '\n');
*symb = '\0';
return string;

View File

@ -12,7 +12,7 @@ int workMode(char* y)
return -1;
}
void parceCondition();
int isField(char* str)
{
@ -81,7 +81,7 @@ int parceField(char* line, int* _field_num, char** _string, int* _int, time_t**
breakdown.tm_year = year - 1900; /* years since 1900 */
breakdown.tm_mon = month - 1;
breakdown.tm_mday = day;
breakdown.tm_hour = hour+3;
breakdown.tm_hour = hour + 3;
breakdown.tm_min = min;
breakdown.tm_sec = sec;
@ -110,6 +110,85 @@ int parceField(char* line, int* _field_num, char** _string, int* _int, time_t**
return -1;
}
int parceCondition(char* line, Condition* conditions[7])
{
int x = !strncmp(line, "result", 6);
if (x)
{
// îáðàáîòêà ðåñóëüòîâ
}
else
{
char buf[50], buf2[50];
strcpy(buf, line);
char* st1 = strtok(buf, "<>!=");
char* st2 = strtok(NULL, "<>!=");
strcpy(buf2, line);
char* usl = strtok(buf2, "qwertyuiop[]asdfghjkl;'zxcvbnm,./1234567890-+_");
Condition* a = (Condition*)malloc(sizeof(Condition));
x = isField(st1);
if (x == -1)
return -1;
conditions[x] = a;
int st1Len = strlen(st1), i= 0;
switch (x)
{
case 0:
case 1:
//
return 1;
case 2:
case 3:
i = atoi(st2);
a->compInt = i;
if (!strcmp(">=", usl))
a->condition = moreEqual;
else if (!strcmp(">", usl))
a->condition = more;
else if (!strcmp("<=", usl))
a->condition = lessEqual;
else if (!strcmp("<", usl))
a->condition = less;
else if (!strcmp("==", usl))
a->condition = equal;
else if (!strcmp("!=", usl))
a->condition = notEqual;
else
return -1;
return 1;
case 4:
case 5:
;
time_t result = 0;
int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
if (sscanf(st2, "%4d.%2d.%2d!%2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec) == 6) {
struct tm breakdown = { 0 };
breakdown.tm_year = year - 1900; /* years since 1900 */
breakdown.tm_mon = month - 1;
breakdown.tm_mday = day;
breakdown.tm_hour = hour + 3;
breakdown.tm_min = min;
breakdown.tm_sec = sec;
if ((result = mktime(&breakdown)) == (time_t)-1) {
return -1;
}
//puts(ctime(&result));
//printf("%s %d\n", formateTime(&result), result);
a->compTime = result;
return 1;
}
else {
return -1;
}
return 1;
default:
break;
}
}
}
int getWordsAndCount(char* line, char*** arr)
{
char buf[500], ** array;
@ -168,7 +247,7 @@ void parceLine(char* input)
int ints[2] = { 0,0 };
int f_num = -1;
int _int = -1;
time_t* tim = NULL, start = 0, end=0;
time_t* tim = NULL, start = 0, end = 0;
int stroks[99];
if (lixCount != 0) {
@ -179,7 +258,7 @@ void parceLine(char* input)
if (lixCount != 8) {
error(input); exit(100);
}
for (int i = 1; i < lixCount; i++)
{