int list_pop_back(t_list *list, void (*freedata)(void*)) { t_elm *rm; if (list == NULL || list->last == NULL) { errno = EINVAL; return (-1); } rm = list->last; list->nb_elm--; if (list->nb_elm == 0) { list->last = NULL; list->first = NULL; if (freedata != NULL) freedata(rm->data); free(rm); return (0); } list->last = rm->prev; list->last->next = list->first; list->first->prev = list->last; if (freedata != NULL) freedata(rm->data); free(rm); return (0); }
void RBT_destroy_node(struct RBT_NODE *node, void (*freedata)(void *)) { if ( node != NULL ) { freedata(node->data); node->left = NULL; node->right = NULL; node->parent = NULL; free(node); } }
void freeop(AMODE *ap) /* * release any temporary registers used in an addressing mode. */ { if( ap->mode == am_immed || ap->mode == am_direct ) return; /* no registers used */ if( ap->mode == am_dreg) freedata(ap->preg); else if( ap->mode == am_areg || ap->mode == am_ind || ap->mode == am_indx || ap->mode == am_adec || ap->mode == am_ainc) freeaddr(ap->preg); else if( ap->mode == am_freg && ap->preg < cf_freefloat && next_float>0) { fregs[ap->preg] = 0; --next_float; } else if (ap->mode == am_baseindxdata) { freeaddr(ap->preg); freedata(ap->sreg); } else if (ap->mode == am_baseindxaddr) { freeaddr(ap->preg); freeaddr(ap->sreg); } }
/* * Main loop */ void game_run(void) { U32 tm, tmx; loaddata(); /* load cached data */ game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD; tm = sys_gettime(); game_state = XRICK; /* main loop */ while (game_state != EXIT) { /* timer */ tmx = tm; tm = sys_gettime(); tmx = tm - tmx; if (tmx < game_period) sys_sleep(game_period - tmx); /* video */ /*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/ sysvid_update(game_rects); draw_STATUSRECT.next = NULL; /* FIXME freerects should handle this */ /* sound */ /*snd_mix();*/ /* events */ if (game_waitevt) sysevt_wait(); /* wait for an event */ else sysevt_poll(); /* process events (non-blocking) */ /* frame */ frame(); } freedata(); /* free cached data */ }
int list_erase(t_list *list, int pos, void (*freedata)(void*)) { t_elm *rm; if (list == NULL || pos >= list->nb_elm || pos < 0) { errno = EINVAL; return (-1); } if ((rm = list_get_elm(list, pos)) == NULL) return (-1); if (pos == 0) list->first = rm->next; else if (pos == list->nb_elm - 1) list->last = rm->prev; rm->next->prev = rm->prev; rm->prev->next = rm->next; if (freedata != NULL) freedata(rm->data); free(rm); list->nb_elm--; return (0); }
/* * Main loop */ void game_run(void) { U32 tm; #if 0 U32 tmx; #endif loaddata(); /* load cached data */ game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD; tm = sys_gettime(); game_state = XRICK; /* main loop */ while (game_state != EXIT) { #if 0 /* This code doesn't make any sense to me at all. It waits until the desired amount of time has passed and then takes the time at which it started waiting (which is not synchronous with anything) as the reference point for the next frame. This sort of works if your system takes very little time to compute the frame, but fails horribly otherwise, e.g. if you use blocking I/O (sound, vblank). */ tmx = tm; tm = sys_gettime(); tmx = tm - tmx; if (tmx < game_period) sys_sleep(game_period - tmx); #endif /* video */ /*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/ sysvid_update(game_rects); draw_STATUSRECT.next = NULL; /* FIXME freerects should handle this */ /* timer */ /* Reset the timing if it's way out of line, such as when the game thread has been paused. */ if (sys_gettime() - tm > game_period * 10) tm = sys_gettime() - game_period / 2; /* Update sound while waiting. */ do { syssnd_callback(); } while (sys_gettime() - tm < game_period / 2); /* Use the time at which the frame should have been complete as reference for the next frame. This makes it possible to "catch up" if a frame has taken longer for some reason. */ tm = tm + game_period / 2; /* sound */ /*snd_mix();*/ /* events */ if (game_waitevt) sysevt_wait(); /* wait for an event */ else sysevt_poll(); /* process events (non-blocking) */ /* frame */ frame(); } freedata(); /* free cached data */ }
int main(int argc, char *argv[]) { FILE *fp = stdin; static char *buf = NULL; static size_t size = 0; int label, workingtime = 0; const unsigned int procrastination = getlabelid("!*"); const unsigned int work = getlabelid("+"); unsigned int payed = getlabelid(""); ARGBEGIN { case 'c': columns = atoi(EARGF(usage())); if (columns > LENGTH(convert)) columns = LENGTH(convert); break; case 'e': options.efc = atoi(EARGF(usage())); break; case 'd': options.flags |= F_DAY_STAT; break; case 'm': options.flags |= F_MONTH_STAT; break; case 'M': options.mph = atoi(EARGF(usage())); break; case 't': options.flags |= F_PRINT_TASK; break; case 'w': options.flags |= F_WEEK_STAT; break; case 'W': payed = getlabelid(EARGF(usage())); break; default: usage(); } ARGEND; initdata(); while (getline(&buf, &size, fp) > 0) { char * time; struct interval interval; if ((time = istask(buf, &interval))) { const int timeint = interval.stop - interval.start; label = getlabelid(buf); char * tmp = strchr(time, ')'); if (!tmp) continue; tmp[0] = '\0'; if (options.flags & F_PRINT_TASK) { printf("%-2s(%s", buf, time); if (tmp[-1] == '-') printf("%s", sec2str(interval.stop)); printf(") %.2f:%s", (timeint) / 3600.0, tmp + 1); } set(timeint, label); set(timeint, 0); if (strchr(buf, '!')) set(timeint, procrastination); if (convert[label].mark == '+') set(timeint, work); if (label == payed) workingtime += timeint; continue; } int rd; if ((rd = getdayid(buf)) >= 0) { if (options.flags & F_DAY_STAT) printdaystat(); if (options.flags & F_PRINT_TASK) printf("%s", buf); memset(data.day, 0, LENGTH(convert) * sizeof(int)); continue; } if (strstr(buf, WEEK)) { if (options.flags & F_WEEK_STAT) printweekstat(); memset(data.week, 0, LENGTH(convert) * sizeof(int)); continue; } if (isnewmonth(buf)) { if (options.flags & F_MONTH_STAT) printmonthstat(); memset(data.month, 0, LENGTH(convert) * sizeof(int)); continue; } if (!strncmp(buf, PAY_MARK, strlen(PAY_MARK))) { printtopay(workingtime / 3600.0); workingtime = 0; } } printdaystat(); printf("\n"); printweekstat(); printf("\n"); printmonthstat(); printf("\n"); printyearstat(); printf("\n"); printtopay(workingtime / 3600.0); freedata(); free(buf); return EXIT_SUCCESS; }
/* * * * * * data management * * * * * */ static XDBlock* allocdata(XDStore *s, uint n) { int i, j; XDBlock *d, *d1; Dpage *p; /* find or create a bigger block */ i = dblog2(n+HdrSize); if(i < LogMindat) i = LogMindat; if(i > s->lgpagesz){ werrstr("block too big"); return nil; } for(j=i; s->free[j]==nil && j<s->lgpagesz; j++) ; DBG print("alloc %ud log %d j %d\n", n, i, j); if(s->free[j]==nil){ //print("A\n"); p = allocpage(s); if(p == nil) return nil; DBG print("new page %ud\n", p->addr); d = mkdata(s, p, p->a, s->ds.pagesize); if(d == nil){ p->nref--; return nil; } }else{ //print("B\n"); d = popfree(s, j); if(d == nil) print("popfree nil: %r\n"); p = d->p; assert(p != nil); } //print("have block %ud size %ud\n", d->db.addr, d->m); /* * we have to mark d as allocated (d->db.n != ~0) * otherwise freeing blocks next to d will reclaim d * out from under us. */ d->db.n = n; d->m = 1<<i; branddata(d); /* chop the block in half until it's just about right */ for(j--; j>=i; j--){ //print("chop off %d (lgpagesz=%d)\n", 1<<j, s->lgpagesz); d1 = mkdata(s, p, d->pa+(1<<j), 1<<j); if(d1 == nil){ d->m = 1<<(j+1); branddata(d); freedata(d); return nil; } branddata(d1); freedata(d1); } //print("allocdata addr %ud p->a %p a %p\n", d->db.addr, d->p->a, d->pa); //print("%.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux\n", // d->pa[0], d->pa[1], d->pa[2], d->pa[3], // d->pa[4], d->pa[5], d->pa[6], d->pa[7]); return d; }
int main(void) { int number = 0; /*表示する発言番号*/ int i; /*カウンタ*/ char fname[FNAME_LEN]; /*ファイル名作成*/ char *buffer; /*バッファ*/ char **file2Dim; /*発言ファイルを格納*/ char **name, **value; /*QUERY_STRINGのname=value*/ int count; /*name=valueの組数*/ char Title[BUFSIZE]; CF config; if(!getConfig( &config )) { fatal_error("■ 設定ファイルの読み込みに失敗しました。", body); return 1; } count = getForm(&name, &value); buffer = getValue( "number", name, value ); if( buffer == NULL ) { fatal_error("■ システムエラーです。このCGIの実行方法をお確かめください。", body); exit(1); } else { number = atoi( buffer ); if( number == 0 ) { fatal_error("■ システムエラーです。再度実行してください。", body); exit(1); } } sprintf( fname,"./file/%d", number ); file2Dim = readFile( fname ); if( file2Dim == NULL ) { fatal_error("■ システムエラーです。再度実行してください。", body); exit(1); } /*--- フォーム出力 ---*/ sprintf( Title, "#%d (%s)", number, config.aptitle ); printPageHeader(Title); puts(body); printf(" %05d %s <A HREF=\"mailto:%s\">%s</A> <B>%s</B>\n", number, *(file2Dim + 1), *(file2Dim + 3), *(file2Dim + 2), *(file2Dim + 5)); printf( "<HR>\n" "<BLOCKQUOTE>\n" "<PRE>%s" , font ); for( i = 15; *(file2Dim + i); i++ ) { if( **(file2Dim) == '>' ) /*引用行は斜体にする*/ printf( "<EM>%s</EM>", *(file2Dim + i) ); else fputs( *(file2Dim + i), stdout ); } printUrl( *(file2Dim + 11) ); printf( "</FONT>" "</PRE>\n" "</BLOCKQUOTE>\n" "<HR>\n" "</BODY>\n" "</HTML>\n" ); freeTwoDimArray( file2Dim ); if(count > 0) freedata(name, value); exit(0); }