Trailer:
Iron Sky:
Danger 5:
Nazis on the moon or Nazis with Dinosaurs?
Diese Umfrage wurde am 19. Nov 2011 um 00:00 beendet.
Iron Sky (Nazis on the moon) | |
Danger 5 (Nazis with Dinosaurs) |
![]() mailto, against spam! Nazis on the moon or Nazis with Dinosaurs?Umfrage · 12. November 2011 00:16 · 2 Kommentare Trailer: Danger 5: Nazis on the moon or Nazis with Dinosaurs?
SSL-Client with gnutlsComputer · 10. November 2011 22:40 See also:
Compile: Memleaks:
Try this with openssl Tags: ansi c · client · gnutls · openssl · ssl · tls Simple Backup ToolSonstiges · 27. August 2011 18:07 I had the choice:
of course I chose option 2 it walks a directory tree and saves files (backup filename: sha1sum) as a lzma-archive; moreover it saves 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <sys/types.h> 5 #include <sys/stat.h> 6 #include <dirent.h> 7 #include <sys/stat.h> 8 #include <fcntl.h> 9 #include <unistd.h> 10 #include <libgen.h> 11 #include <time.h> 12 #include <magic.h> 13 #include <archive.h> 14 #include <archive_entry.h> 15 #include <sqlite3.h> 16 17 #include <openssl/sha.h> 18 #include <openssl/md5.h> 19 20 #error "complete BACKUP_BASE define" 21 #define BACKUP_BASE "/somewhere" 22 #define BACKUP_DIR BACKUP_BASE"/" 23 #define BACKUPDB_FILE BACKUP_BASE"/db" 24 25 #define USE_SHA1 26 #ifdef USE_SHA1 27 #define DIGEST_LEN SHA_DIGEST_LENGTH 28 #else 29 #define DIGEST_LEN MD5_DIGEST_LENGTH 30 #endif 31 32 33 #define CREATE_FILETABLE "CREATE TABLE IF NOT EXISTS files (id TEXT NOT 34 NULL PRIMARY 35 KEY, user 36 VARCHAR(20), 37 filepath TEXT 38 NOT NULL, type 39 TEXT NOT NULL, 40 hashsum TEXT 41 NOT NULL, 42 hostname 43 VARCHAR(256), 44 comment VARCHAR( 45 256), version 46 VARCHAR(256), 47 time BIGINT);" 48 #define INSERT_FILE "INSERT INTO files (id, user, filepath, type, hashsum, 49 hostname, comment, version, time) 50 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); 51 " 52 53 void save_file(int fd, char *filename, char *targetfilepath, struct stat 54 *st) 55 { 56 int len; 57 char buf[8192]; 58 struct archive *a; 59 struct archive_entry *entry; 60 struct stat tmp_st; 61 62 if (stat(targetfilepath, &tmp_st) == 0) 63 return; 64 65 66 a = archive_write_new(); 67 archive_write_set_compression_xz(a); 68 archive_write_set_format_pax_restricted(a); 69 archive_write_open_filename(a, targetfilepath); 70 entry = archive_entry_new(); 71 archive_entry_set_mtime(entry, time(NULL), 0); 72 archive_entry_set_pathname(entry, filename); 73 archive_entry_set_size(entry, st->st_size); 74 archive_entry_set_filetype(entry, AE_IFREG); 75 archive_entry_set_perm(entry, 0644); 76 archive_write_header(a, entry); 77 lseek(fd, 0, SEEK_SET); 78 while ((len = read(fd, buf, sizeof(buf))) > 0) 79 archive_write_data(a, buf, len); 80 81 archive_entry_free(entry); 82 archive_write_close(a); 83 archive_write_finish(a); 84 } 85 86 void save_fileinfo(sqlite3 *db, unsigned char *digest, char *filepath, char 87 *type, char *hostname, char *user, char *comment, char 88 *version, unsigned int backup_time) 89 { 90 int i, j; 91 char digest_id_char[SHA_DIGEST_LENGTH+SHA_DIGEST_LENGTH+1], digest_char[ 92 DIGEST_LEN+DIGEST_LEN+1]; 93 unsigned char digest_id[SHA_DIGEST_LENGTH]; 94 sqlite3_stmt *stmt; 95 SHA_CTX ctx; 96 97 98 SHA1_Init(&ctx); 99 100 SHA1_Update(&ctx, digest, DIGEST_LEN); 101 SHA1_Update(&ctx, hostname, strlen(hostname)); 102 SHA1_Update(&ctx, &backup_time, sizeof(backup_time)); 103 SHA1_Update(&ctx, user, strlen(user)); 104 SHA1_Update(&ctx, filepath, strlen(filepath)); 105 SHA1_Final(digest_id, &ctx); 106 107 for (i = 0, j = 0; i < SHA_DIGEST_LENGTH; i++, j+=2) 108 sprintf(digest_id_char+j, "%02x", digest_id[i]); 109 for (i = 0, j = 0; i < DIGEST_LEN; i++, j+=2) 110 sprintf(digest_char+j, "%02x", digest[i]); 111 112 sqlite3_prepare_v2(db, INSERT_FILE, -1, &stmt, 0); 113 sqlite3_bind_text(stmt, 1, digest_id_char, -1, SQLITE_STATIC); 114 sqlite3_bind_text(stmt, 2, user, -1, SQLITE_STATIC); 115 sqlite3_bind_text(stmt, 3, filepath, -1, SQLITE_STATIC); 116 sqlite3_bind_text(stmt, 4, type, -1, SQLITE_STATIC); 117 sqlite3_bind_text(stmt, 5, digest_char, -1, SQLITE_STATIC); 118 sqlite3_bind_text(stmt, 6, hostname, -1, SQLITE_STATIC); 119 sqlite3_bind_text(stmt, 7, comment, -1, SQLITE_STATIC); 120 sqlite3_bind_text(stmt, 8, version, -1, SQLITE_STATIC); 121 sqlite3_bind_int(stmt, 9, backup_time); 122 if (sqlite3_step(stmt) != SQLITE_DONE) 123 { 124 fprintf(stderr, "Can't insert: %s\n", sqlite3_errmsg(db)); 125 exit(1); 126 } 127 sqlite3_finalize(stmt); 128 129 } 130 131 void process_file(char *filepath, struct stat *st, sqlite3 *db, unsigned 132 int backup_time) 133 { 134 int i, j, len, fd; 135 char buf[8192]; 136 char type[20]; 137 magic_t m; 138 unsigned char digest[DIGEST_LEN]; 139 #ifdef USE_SHA1 140 SHA_CTX ctx; 141 SHA1_Init(&ctx); 142 #else 143 MD5_CTX ctx; 144 MD5_Init(&ctx); 145 #endif 146 char backup_file[strlen(BACKUP_DIR)+1+(2*sizeof(digest))+7+1]; 147 148 if (!strcmp(filepath, BACKUPDB_FILE)) 149 return; 150 fd = open(filepath, 0, O_RDONLY); 151 if (fd == -1) 152 return; 153 154 m = magic_open(MAGIC_MIME_TYPE); 155 magic_load(m, NULL); 156 magic_compile(m, NULL); 157 158 len=read(fd, buf, sizeof(buf)); 159 160 #ifdef USE_SHA1 161 SHA1_Update(&ctx, buf, len); 162 #else 163 MD5_Update(&ctx, buf, len); 164 #endif 165 snprintf(type, 19, "%s", magic_buffer(m, buf, len)); 166 printf("type: %s ", type); 167 168 while ((len=read(fd, buf, sizeof(buf))) > 0) 169 #ifdef USE_SHA1 170 SHA1_Update(&ctx, buf, len); 171 #else 172 MD5_Update(&ctx, buf, len); 173 #endif 174 175 magic_close(m); 176 177 #ifdef USE_SHA1 178 SHA1_Final(digest, &ctx); 179 #else 180 MD5_Final(digest, &ctx); 181 #endif 182 for (i = 0; i < sizeof(digest); i++) 183 printf("%02x", (unsigned char)digest[i]); 184 185 186 printf(" %s ", filepath); 187 188 if (S_ISREG(st->st_mode)) 189 printf("normal file\n"); 190 191 snprintf(backup_file, strlen(BACKUP_DIR)+2, "%s/", BACKUP_DIR); 192 for (i = 0, j = 0; i < sizeof(digest); i++, j+=2) 193 sprintf(backup_file+strlen(BACKUP_DIR)+1+j, "%02x", (unsigned char) 194 digest[i]); 195 196 sprintf(backup_file+strlen(BACKUP_DIR)+1+(2*sizeof(digest)), ".tar.xz"); 197 save_file(fd, basename(filepath), backup_file, st); 198 save_fileinfo(db, digest, filepath, type, "erebos", getenv("USER"), 199 "comment", "version", backup_time); 200 201 close(fd); 202 } 203 204 void walktree(char *base_dir, sqlite3 *db, unsigned int backup_time) 205 { 206 struct stat st; 207 struct dirent *entry; 208 DIR *d; 209 char *filepath = realpath(base_dir, NULL); 210 char *real_backuppath = realpath(BACKUP_DIR, NULL); 211 int filepath_len = strlen(filepath); 212 213 if (!strncmp(filepath, real_backuppath, strlen(real_backuppath))) 214 goto frees; 215 if (basename(filepath)[0] == '.') 216 goto frees; 217 d = opendir(filepath); 218 lstat(filepath, &st); 219 if (S_ISREG(st.st_mode)) 220 { 221 process_file(filepath, &st, db, backup_time); 222 goto ret; 223 } 224 else if (!S_ISDIR(st.st_mode)) 225 goto ret; 226 227 filepath = realloc(filepath, PATH_MAX); 228 229 while ((entry = readdir(d)) != NULL) 230 { 231 if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) 232 continue; 233 if (filepath_len + strlen(entry->d_name) >= PATH_MAX) 234 { 235 fprintf(stderr, "wrong filepath :(\n"); 236 exit(-1); 237 } 238 239 sprintf(filepath+filepath_len, "/%s", entry->d_name); 240 241 lstat(filepath, &st); 242 if (S_ISREG(st.st_mode)) 243 process_file(filepath, &st, db, backup_time); 244 else if (S_ISDIR(st.st_mode)) 245 walktree(filepath, db, backup_time); 246 247 } 248 249 250 ret: 251 closedir(d); 252 frees: 253 free(filepath); 254 free(real_backuppath); 255 } 256 257 sqlite3* init_db() 258 { 259 sqlite3 *db; 260 char *errmsg = 0; 261 262 sqlite3_open(BACKUPDB_FILE, &db); 263 264 if (sqlite3_exec(db, CREATE_FILETABLE, NULL, 0, &errmsg) != SQLITE_OK) 265 { 266 fprintf(stderr, "Can't create table: %s\n%s\n", sqlite3_errmsg(db), 267 CREATE_FILETABLE); 268 return NULL; 269 } 270 271 return db; 272 } 273 274 int main(int argc, char **argv) 275 { 276 sqlite3 *db; 277 278 if (argc != 2) 279 { 280 fprintf(stderr, "%s <dirpath>\n", argv[0]); 281 exit(-1); 282 } 283 284 db = init_db(); 285 if (db == NULL) 286 exit(-1); 287 walktree(argv[1], db, time(NULL)); 288 289 sqlite3_close(db); 290 return 0; 291 } Makefile: all: backup.c
gcc -std=gnu99 -lssl backup.c -lmagic -Wall -g -larchive -lsqlite3 -o backupRestore tool will be written as soon as I need it Very simple 2D Game (SDL)Computer · 06. August 2011 00:21 In case you wanna create a 2D SDL game: 1 #include <SDL/SDL.h> 2 #include <SDL/SDL_image.h> 3 #include <SDL/SDL_gfxPrimitives.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <unistd.h> 7 8 9 #define GAME_X 640 10 #define GAME_Y 400 11 12 #define MAP_MAX_X 10000 13 #define MAP_MAX_Y 10000 14 enum object_type 15 { 16 BACKGROUND, 17 PLAYER 18 }; 19 20 struct objects 21 { 22 enum object_type type; 23 uint16_t id; 24 25 uint32_t map_x; 26 uint32_t map_y; 27 28 int16_t speed_x; 29 int16_t speed_y; 30 }; 31 32 struct video_objects // 1st is background 33 { 34 struct objects o; 35 SDL_Surface *surface; 36 struct video_objects *next; 37 38 uint16_t x; 39 uint16_t y; 40 uint8_t w; 41 uint8_t h; 42 }; 43 44 struct 45 { 46 uint16_t x; 47 uint16_t y; 48 } map_quadrant; 49 50 SDL_Surface *background = NULL; 51 SDL_Surface *screen = NULL; 52 53 uint32_t now_ticks; 54 55 struct objects *player; 56 57 58 //------------------------------------------ 59 60 void motion(struct objects *o) 61 { 62 63 if ((int32_t)(o->map_x - o->speed_x) < 0) 64 { 65 o->map_x = 0; 66 o->speed_x = 1; 67 } 68 69 if ((int32_t)(o->map_y - o->speed_y) < 0) 70 { 71 o->map_y = 0; 72 o->speed_y = 1; 73 } 74 75 if ((int32_t)(o->map_y + o->speed_y) > MAP_MAX_Y) 76 { 77 o->map_y = MAP_MAX_Y; 78 o->speed_y = -1; 79 } 80 81 if ((int32_t)(o->map_x + o->speed_x) > MAP_MAX_X) 82 { 83 o->map_x = MAP_MAX_X; 84 o->speed_x = -1; 85 } 86 87 o->map_x += o->speed_x; 88 o->map_y += o->speed_y; 89 90 } 91 92 void player_position(int *x, int *y) // depends on map quadrant 93 { 94 *x = player->map_x % (GAME_X-20); 95 *y = player->map_y % (GAME_Y-20); 96 } 97 98 void draw_info() 99 { 100 char pos[50]; 101 102 boxRGBA(screen, GAME_X+2, GAME_Y-10, 1024, GAME_Y, 0, 40, 0, 255); 103 snprintf(pos, 50, "pos: %d/%d quadrant: %d/%d speed: %d/%d", player-> 104 map_x, player->map_y, map_quadrant.x, map_quadrant.y, player-> 105 speed_x, player->speed_y); 106 stringRGBA(screen, GAME_X+2, GAME_Y-9, pos, 255, 0, 0, 255); 107 } 108 109 void draw(struct video_objects *vo) 110 { 111 SDL_Rect r; 112 113 map_quadrant.x = player->map_x/GAME_X; 114 map_quadrant.y = player->map_y/GAME_Y; 115 do 116 { 117 switch (vo->o.type) 118 { 119 case BACKGROUND: 120 SDL_BlitSurface(vo->surface, NULL, screen, NULL); 121 break; 122 case PLAYER: 123 //r.x = vo->x; 124 //r.y = vo->y; 125 player_position(&r.x, &r.y); 126 r.w = 20; 127 r.h = 20; 128 SDL_BlitSurface(vo->surface, NULL, screen, &r); 129 draw_info(); 130 motion(&vo->o); 131 break; 132 } 133 134 vo = vo->next; 135 } 136 while (vo != NULL); 137 138 139 SDL_Flip(screen); 140 141 } 142 143 int events() 144 { 145 SDL_Event ev; 146 SDL_keysym keysym; 147 148 149 while (SDL_PollEvent(&ev) != 0) 150 { 151 keysym = ev.key.keysym; 152 switch (ev.type) 153 { 154 case SDL_KEYDOWN: 155 switch (keysym.sym) 156 { 157 case SDLK_q: 158 return -1; 159 160 case SDLK_UP: 161 case SDLK_k: 162 player->speed_y--; 163 break; 164 case SDLK_DOWN: 165 case SDLK_j: 166 player->speed_y++; 167 break; 168 case SDLK_RIGHT: 169 case SDLK_l: 170 player->speed_x++; 171 break; 172 case SDLK_LEFT: 173 case SDLK_h: 174 player->speed_x--; 175 break; 176 case SDLK_s: 177 player->speed_x = 0; 178 player->speed_y = 0; 179 break; 180 default: 181 break; 182 } 183 break; 184 } 185 } 186 187 return 0; 188 } 189 190 void wait() 191 { 192 uint32_t diff = SDL_GetTicks() - now_ticks; 193 uint32_t delay = 30-diff; 194 195 //printf("ticks: %u\n", diff); 196 197 if (delay < 1000) 198 SDL_Delay(delay); 199 now_ticks = SDL_GetTicks(); 200 } 201 202 struct video_objects *init_vos() 203 { 204 struct video_objects *vo = calloc(1, sizeof(struct video_objects)); 205 206 vo->next = NULL; 207 //vo->surface = IMG_Load("pics/galaxy.png"); 208 vo->surface = SDL_CreateRGBSurface(SDL_HWSURFACE, GAME_X, GAME_Y, 32, 0,0, 209 0,0); 210 boxRGBA(vo->surface, 0, 0, GAME_X, GAME_Y, 0, 0, 0, 255); 211 vo->o.type = BACKGROUND; 212 213 return vo; 214 } 215 216 void add_player(struct video_objects *vo, uint16_t id) 217 { 218 while (vo->next != NULL) 219 vo = vo->next; 220 221 vo->next = calloc(1, sizeof(struct video_objects)); 222 vo = vo->next; 223 vo->next = NULL; 224 vo->o.type = PLAYER; 225 vo->o.id = id; 226 vo->surface = IMG_Load("pics/player1.png"); 227 228 vo->y = GAME_Y/2; 229 vo->x = GAME_X/2; 230 vo->w = vo->surface->w; 231 vo->h = vo->surface->h; 232 233 vo->o.map_x = 10; 234 vo->o.map_y = 10; 235 vo->o.speed_y = 0; 236 vo->o.speed_x = 0; 237 238 player = &vo->o; 239 } 240 241 242 struct video_objects *init_objects() 243 { 244 struct video_objects *vo; 245 246 vo = init_vos(); 247 add_player(vo, 1); 248 vlineRGBA(screen, GAME_X+1, 0, GAME_Y, 255, 0, 0, 255); 249 250 return vo; 251 } 252 253 int main() 254 { 255 struct video_objects *vo; 256 257 SDL_Init(SDL_INIT_VIDEO); 258 259 atexit(SDL_Quit); 260 261 screen = SDL_SetVideoMode(1024, GAME_Y, 16, SDL_HWSURFACE | SDL_DOUBLEBUF) 262 ; 263 vo = init_objects(); 264 265 if (screen == NULL) 266 { 267 printf("%s\n", SDL_GetError()); 268 exit(-1); 269 } 270 271 while (1) 272 { 273 draw(vo); 274 if (events() == -1) 275 break; 276 wait(); 277 } 278 279 printf("bye\n"); 280 return 0; 281 } compile: gcc `sdl-config --libs --cflags` file.c -o file -lSDL_image -lSDL_gfx -g -Wall Tags: 2d · ansi c · game · sdl Give gif,png,jpg files right extensionComputer · 23. Juli 2011 20:31 · 2 Kommentare
1 #!/usr/bin/perl -w 2 3 use strict; 4 use File::Type; 5 use File::Find(); 6 7 my $ft = File::Type->new(); 8 9 sub analyze { 10 my $file = $File::Find::name; 11 my $newname = $file; 12 my $type = $ft->checktype_filename($file); 13 my $ext = ""; #extension 14 15 $ext="jpg" if ($type eq "image/jpeg"); 16 $ext="png" if ($type eq "image/x-png"); 17 $ext="gif" if ($type eq "image/gif"); 18 19 if (not "$ext" eq "") { 20 $newname = $newname.".".$ext; 21 print "file: $file type: $type new name: $newname\n"; 22 rename "$file", "$newname"; 23 } 24 } 25 26 #analyze $ARGV[0]; 27 28 File::Find::find({wanted => \&analyze}, "$ARGV[0]"); Update:
Tags: extenion · file · gif · jpg · perl · png CalltraceTechnologie / Wissenschaft · 18. Juli 2011 16:47 In your favourite debugger you often get only a stacktrace, but I often just wanna have a calltrace;
Example:
So handle_server called several other functions:
Tags: ansi c · calltrace · debug · valgrind |
Einträge anzeigen
Jahr 2012 (3) AbonnierenTags |