int tlog_save( char *filestr) { char cmd[100]; char filename[80]; int sts; char saved_filename[80]; char wild_filename[80]; char dev[80]; char dir[80]; char file[80]; char type[80]; int version; int first; char *s; unsigned long search_ctx; tlog_get_defaultfilename( filestr, wild_filename, ".tlog", "pwrp_tlog:"); first = 1; for(;;) { if ( first) { /* Get the first file */ search_ctx = 0; sts = dir_search_file( &search_ctx, wild_filename, filename); if (EVEN(sts)) return sts; first = 0; } else { /* Get the next file */ sts = dir_search_file( &search_ctx, wild_filename, filename); if (EVEN(sts)) break; } sts = dir_parse_filename( filename, dev, dir, file, type, &version); strcpy( saved_filename, "pwrp_stlog:"); strcat( saved_filename, file); strcat( saved_filename, type); if ( s = strrchr( filename, ';')) *s = 0; sprintf( cmd, "copy/log %s %s", filename, saved_filename); sts = system( cmd); if (EVEN(sts)) return sts; } dir_search_file_end( &search_ctx); return TLOG__SUCCESS; }
main() { int sts; long date2[2]; char wild_filename[80] = "t*.t"; char filename[80]; char dev[80]; char dir[80]; char file[80]; char type[80]; int version; sts = dir_search_file( wild_filename, filename, 1, 0); if (EVEN(sts)) printf("No files\n"); printf("%s\n", filename); sts = dir_parse_filename( filename, dev, dir, file, type, &version); while (ODD(sts)) { sts = dir_search_file( wild_filename, filename, 0, 0); if (ODD(sts)) printf("%s\n", filename); } }
pwr_tStatus tlog_diff( char *filestr, char *output, char *timestr, int parallell, int attribute, int text, int ttext, int noorder, int exact, char *since_str, char *before_str ) { char saved_filename[80]; char filename[80]; FILE *outfile; int sts; tlog_t_linelist *new_list; tlog_t_linelist *old_list; int new_list_count; int old_list_count; float time; int nr; diff_ctx ctx; char modulestr[80]; char cmd[100]; char new_filename[80]; char old_filename[80]; char wild_filename[80]; char dev[80]; char dir[80]; char file[80]; char type[80]; int version; int first; pwr_tTime file_time; int file_size; int file_version; pwr_tTime before_time; pwr_tTime since_time; int diff_count; unsigned long search_ctx; tlog_get_defaultfilename( filestr, wild_filename, ".tlog", "pwrp_tlog:"); diff_count = 0; first = 1; for(;;) { if ( first) { /* Get the first file */ search_ctx = 0; sts = dir_search_file( &search_ctx, wild_filename, filename); if (EVEN(sts)) return sts; /* At least one file is found */ if ( output != NULL) { /* Open the output file */ outfile = fopen( output, "w"); if ( !outfile ) return TLOG__FILEOPEN; } else outfile = 0; if ( timestr != NULL) { /* Convert to float */ nr = sscanf( timestr, "%f", &time); if ( nr != 1) return TLOG__TIMESYNTAX; } else time = 0.5; if ( before_str != NULL) { sts = tlog_qual_to_time( before_str, &before_time); if (EVEN(sts)) return TLOG__BEFOREQUAL; } if ( since_str != NULL) { sts = tlog_qual_to_time( since_str, &since_time); if (EVEN(sts)) return TLOG__SINCEQUAL; } first = 0; } else { /* Get the next file */ sts = dir_search_file( &search_ctx, wild_filename, filename); if (EVEN(sts)) break; /* fprintf( outfile, ""); */ } sts = dir_get_fileinfo( filename, (pwr_tTime *) &file_time, &file_size, &file_version, NULL); if (EVEN(sts)) return sts; if ( since_str != NULL) { if ( time_Acomp( &file_time, &since_time) < 0) continue; } if ( before_str != NULL) { if ( time_Acomp( &file_time, &before_time) > 0) continue; } sts = dir_parse_filename( filename, dev, dir, file, type, &version); strcpy( saved_filename, "pwrp_stlog:"); strcat( saved_filename, file); strcat( saved_filename, type); /* Read the new file */ new_list_count = 0; sts = tlog_insert_file( filename, &new_list, &new_list_count, new_filename); if ( EVEN(sts)) { if ( outfile) { fprintf( outfile, "\n\n\nNew file: %s\n", new_filename); fprintf( outfile, "%%TLOG-E-NEWOPEN, Unable to open new file\n"); } else { printf( "\n\n\nNew file: %s\n", new_filename); printf( "%%TLOG-E-NEWOPEN, Unable to open new file\n"); } continue; } if ( outfile) fprintf( outfile, "\n\n\nNew file: %s\n", new_filename); else printf( "\n\n\nNew file: %s\n", new_filename); /* Read the old file */ old_list_count = 0; sts = tlog_insert_file( saved_filename, &old_list, &old_list_count, old_filename); if ( EVEN(sts)) { if ( outfile) { fprintf( outfile, "Old file: %s\n", old_filename); fprintf( outfile, "%%TLOG-E-OLDOPEN, Unable to open old file\n"); } else { printf( "Old file: %s\n", old_filename); printf( "%%TLOG-E-OLDOPEN, Unable to open old file\n"); } free( new_list); continue; } if ( outfile) fprintf( outfile, "Old file: %s\n", old_filename); else printf( "Old file: %s\n", old_filename); ctx = calloc( 1, sizeof( *ctx)); ctx->max_difftime = time; ctx->new_list = new_list; ctx->old_list = old_list; ctx->old_list_count = old_list_count; ctx->new_list_count = new_list_count; ctx->outfile = outfile; ctx->parallell = parallell; ctx->attribute = attribute; ctx->text = text; ctx->ttext = ttext; ctx->noorder = noorder; ctx->exact = exact; strcpy( ctx->new_filename, new_filename); strcpy( ctx->old_filename, old_filename); sts = tlog_lists_cmp( ctx); if ( EVEN(sts)) return sts; diff_count++; free( new_list); free( old_list); free( ctx); } if ( outfile) fclose( outfile); sts = dir_search_file_end( &search_ctx); if ( diff_count == 0) if ( outfile) fprintf( outfile, "No files found\n"); else printf( "No files found\n"); return TLOG__SUCCESS; }