-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruntime.c
126 lines (108 loc) · 2.43 KB
/
runtime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "runtime.h"
double ABSF(double x) {
return (x > 0.0) ? x : -x;
}
int XABSF(int x) {
return (x > 0) ? x : -x;
}
double INTF(double x) {
return (double)(int) x;
}
int XINTF(double x) {
return (int) x;
}
double MODF(double x, double y){
return fmod(x, y);
}
int XMODF(int x,int y){
return x % y;
}
double MAX0F(int x,int y) {
return (double)(x > y? x : y);
}
double MAX1F(double x,double y) {
return (x > y? x : y);
}
int XMAX0F(int x,int y) {
return (x > y? x : y);
}
int XMAX1F(double x ,double y){
return (int)(x > y? x : y);
}
double MIN0F(int x,int y) {
return (double)(x < y? x : y);
}
double MIN1F(double x,double y) {
return (x < y? x : y);
}
int XMIN0F(int x,int y) {
return (x < y? x : y);
}
int XMIN1F(double x ,double y){
return (int)(x < y? x : y);
}
void next(format* f) {
f->i++;
if(f->front[f->i] == NULL) {
f->i = 0;
if(f->back != NULL) {
f->front = f->back;
f->back = NULL;
}
}
}
void out(format* f, double arg) {
while(1){
if(strstr(f->front[f->i], "%") == NULL)
printf(f->front[f->i]);
else if(strstr(f->front[f->i], "f") != NULL)
printf(f->front[f->i], arg);
else if(strstr(f->front[f->i], "d") != NULL)
printf(f->front[f->i], (int)arg);
if(strstr(f->front[f->i], "%")!= NULL) {
next(f);
break;
} else {
next(f);
}
}
}
void nullary_out(format* f) {
printf("%s", f->front[0]);
next(f);
}
void in(format* f, void** arg) {
int x;
int i = 0,j=0;
char* buf;
while(1){
if(strstr(f->front[f->i], "f") != NULL){
buf = strdup(f->front[f->i]);
for(; buf[i] != '\0'; i++) {
while(buf[i] == '.') {
i++;
while(buf[i] >= '0' && buf[i] <= '9') {
i++;
}
}
buf[j++] = buf[i];
}
buf[j] = '\0';
x = scanf(buf, (float*)arg);
free(buf);
}
else if(strstr(f->front[f->i], "d") != NULL) {
scanf(f->front[f->i], (int*)arg);
}
if(strstr(f->front[f->i], "%") != NULL) {
next(f);
break;
} else {
next(f);
}
}
}