static void read_case_file (Graph *graph, const char *filename) { /* open file for reading */ FILE *file = fopen (filename, "r"); size_t bufsize = 1024; char buf[bufsize]; while(fgets (buf, bufsize, file) != NULL){ char *ptr1 = &buf[0]; char *machine,*c1,*c2,*price; machine = nextnum (&ptr1); c1 = nextnum (&ptr1); c2 = nextnum (&ptr1); price = nextnum (&ptr1); GraphNode *node1 = graph_lookup_node (graph, c1); GraphNode *node2 = graph_lookup_node (graph, c2); unsigned int price_val = (unsigned int)strtoul (price, NULL, 10); unsigned int machine_num = (unsigned int)strtoul (machine, NULL, 10); graph_add_edge (node1, node2, machine_num, price_val); } fclose (file); }
int64_t parseIso8601Time(const char *str) { // Check to make sure that it has a valid format if (!checkString(str, "dddd-dd-ddTdd:dd:dd")) { return -1; } #define nextnum() (((*str - '0') * 10) + (*(str + 1) - '0')) // Convert it struct tm stm; memset(&stm, 0, sizeof(stm)); stm.tm_year = (nextnum() - 19) * 100; str += 2; stm.tm_year += nextnum(); str += 3; stm.tm_mon = nextnum() - 1; str += 3; stm.tm_mday = nextnum(); str += 3; stm.tm_hour = nextnum(); str += 3; stm.tm_min = nextnum(); str += 3; stm.tm_sec = nextnum(); str += 2; stm.tm_isdst = -1; int64_t ret = mktime(&stm); // Skip the millis if (*str == '.') { str++; while (isdigit(*str)) { str++; } } if (checkString(str, "-dd:dd") || checkString(str, "+dd:dd")) { int sign = (*str++ == '-') ? -1 : 1; int hours = nextnum(); str += 3; int minutes = nextnum(); ret += (-sign * (((hours * 60) + minutes) * 60)); } // Else it should be Z to be a conformant time string, but we just assume // that it is rather than enforcing that return ret; }
void do_frame() { pvr_vertex_t * vert; int x, y, z; int i, col; int seed = oldseed; pvr_dr_state_t dr_state; #define nextnum() seed = seed * 1164525 + 1013904223; #define getnum(mn) (seed & ((mn) - 1)) vid_border_color(0, 0, 0); pvr_wait_ready(); vid_border_color(255, 0, 0); pvr_scene_begin(); pvr_list_begin(PVR_LIST_OP_POLY); pvr_prim(&hdr, sizeof(hdr)); pvr_dr_init(dr_state); x = getnum(1024); nextnum(); y = getnum(512); nextnum(); z = getnum(128) + 1; nextnum(); col = getnum(256); nextnum(); vert = pvr_dr_target(dr_state); vert->flags = PVR_CMD_VERTEX; vert->x = x; vert->y = y; vert->z = z; vert->u = vert->v = 0.0f; vert->argb = col | (col << 8) | (col << 16) | 0xff000000; vert->oargb = 0; pvr_dr_commit(vert); for(i = 0; i < polycnt; i++) { x = (x + ((getnum(64)) - 32)) & 1023; nextnum(); y = (y + ((getnum(64)) - 32)) % 511; nextnum(); col = getnum(256); nextnum(); vert = pvr_dr_target(dr_state); vert->flags = PVR_CMD_VERTEX; vert->x = x; vert->y = y; vert->z = z; vert->u = vert->v = 0.0f; vert->argb = col | (col << 8) | (col << 16) | 0xff000000; vert->oargb = 0; if(i == (polycnt - 1)) vert->flags = PVR_CMD_VERTEX_EOL; pvr_dr_commit(vert); } pvr_list_finish(); pvr_scene_finish(); vid_border_color(0, 255, 0); oldseed = seed; }