int main(int argc, char **argv){ struct stat buf; struct timeval tv; char *filename; FILE *fp; /* struct timezone tz; */ filename = argv[1]; gettimeofday(&tv, NULL); /* printf("time of day = %ld . %ld\n", tv.tv_sec, tv.tv_usec); */ printf("current time of day = %s\n", ctime(&tv.tv_sec)); if ( !stat(filename, &buf) ){ fp = fopen("book-list.txt", "a"); fprintf(fp,"%s %s\n", ctime(&buf.st_mtime), get_book_name(filename)); /* printf("ctime of file %s = %s\n", filename, ctime(&buf.st_mtime)); // get modify time of the file */ }else { perror("stat"); exit(-1); } /* printf("ctime = %ld, mtime = %ld, atime = %ld\n", buf.st_ctime, buf.st_mtime, buf.st_atime); */ /* return system("curl -s https://www.packtpub.com/packt/offers/free-learning > out.txt"); */ return 0; }
BookFile *km_book_open_file(gchar *filename) { BookFile *book; FILE *file; gchar *buffer,**lines,*tmp,tmpstr[1024],*tmp1; gint i,j,a; struct stat stats; if (lstat (filename, &stats) == -1) return NULL; if (!(file = fopen (filename, "r"))) return NULL; g_print("%s\n",filename); buffer = (gchar *) g_malloc (stats.st_size + 1); if (fread (buffer, 1, stats.st_size, file) != (guint) stats.st_size) { g_free (buffer); fclose (file); return NULL; } fclose (file); buffer[stats.st_size] = '\0'; book = (BookFile *)g_malloc0 (sizeof (BookFile)); book->bookfilename = g_strdup (filename); tmp=strrchr(filename,G_DIR_SEPARATOR); if (tmp) { book->name=g_strdup(get_book_name(tmp+1)); } else { book->name=g_strdup(get_book_name(filename)); } book->author=g_strdup("С֥Âé");; book->website=g_strdup("http://www.zhimajie.net"); book->email=g_strdup("*****@*****.**"); book->about=g_strdup("À´×Ô¡¶ÎÒÒ²°®±³µ¥´Ê¡·"); lines = g_strsplit (buffer, "\r\n", 0); g_free (buffer); a=0; while (lines[a]) { a++; } book->words.w=(gchar **)g_malloc((a+1)*sizeof(gchar *)); book->words.t=(gchar **)g_malloc((a+1)*sizeof(gchar *)); book->words.m=(gchar **)g_malloc((a+1)*sizeof(gchar *)); i=0; j=0; while (lines[i]) { //g_print("%d ",i); /*if (i>=1804) { g_print("%d %s",i,lines[i]); }*/ strcpy(tmpstr,lines[i]); tmp=strchr(tmpstr,'\t'); if (tmp) { *tmp='\0'; g_strstrip(tmpstr); book->words.w[j]=g_strdup(tmpstr); if (*(tmp+1)=='\t') { book->words.t[j]=NULL; tmp1=tmp; } else { tmp1=strchr(tmp+2,'/'); *tmp1='\0'; g_strstrip(tmp+2); book->words.t[j]=g_strdup(tmp+2); } tmp1=strchr(tmp1+1,'\t'); if (tmp1) { g_strstrip(tmp1+1); book->words.m[j]=g_strdup(tmp1+1); } else { book->words.m[j]=NULL; } j++; } i++; } book->words.w[j]=NULL; book->wordcount=j; g_strfreev (lines); return book; }