printff: Normal printf with flush.
This commit is contained in:
@@ -293,32 +293,32 @@ FileNode *FileNode_Load(char *filePath) {
|
||||
}
|
||||
|
||||
void FileNode_PrintNode(FileNode *fileNode) {
|
||||
printf(FileNode_GetPath(fileNode, NULL ));
|
||||
printff(FileNode_GetPath(fileNode, NULL ));
|
||||
if (fileNode->flags & FileFlag_Normal) {
|
||||
printf(" File");
|
||||
printff(" File");
|
||||
} else {
|
||||
printf(" Dir");
|
||||
printff(" Dir");
|
||||
}
|
||||
printf(" %d", fileNode->estado);
|
||||
printff(" %d", fileNode->estado);
|
||||
if (fileNode->estado == FileStatus_New) {
|
||||
printf(" Nuevo");
|
||||
printff(" Nuevo");
|
||||
}
|
||||
if (fileNode->estado == FileStatus_Modified) {
|
||||
printf(" Modificado");
|
||||
printff(" Modificado");
|
||||
}
|
||||
if (fileNode->estado == FileStatus_Deleted) {
|
||||
printf(" Borrado!!!");
|
||||
printff(" Borrado!!!");
|
||||
}
|
||||
printf("\n");
|
||||
printff("\n");
|
||||
|
||||
if(fileNode->flags&FileFlag_HasSize){
|
||||
printf("\\-Tamanho: %lld\n",fileNode->size);
|
||||
printff("\\-Tamanho: %lld\n",fileNode->size);
|
||||
}
|
||||
if(fileNode->flags&FileFlag_HastTime){
|
||||
printf("\\-Fecha : ");FileTime_Print(fileNode->fileTime);printf("\n");
|
||||
printff("\\-Fecha : ");FileTime_Print(fileNode->fileTime);printff("\n");
|
||||
}
|
||||
if(fileNode->flags&FileFlag_HasCRC){
|
||||
printf("\\-CRC : [%08X]\n",fileNode->crc);
|
||||
printff("\\-CRC : [%08X]\n",fileNode->crc);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -339,7 +339,7 @@ void FileNode_Print(FileNode *fileNode) {
|
||||
while (fileNodeAux->next == NULL ) {
|
||||
fileNodeAux = fileNodeAux->parent;
|
||||
if (fileNodeAux == fileNode || fileNodeAux == NULL ) {
|
||||
printf("End\n");
|
||||
printff("End\n");
|
||||
end = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -551,37 +551,37 @@ void AccionFileNode_Print(AccionFileNode *actionFileNode) {
|
||||
|
||||
switch (actionFileNode->action) {
|
||||
case AccionFileCmp_Nothing:
|
||||
//printf("%s == %s\n",pathIzq,pathDer);
|
||||
//printff("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case AccionFileCmp_LeftToRight:
|
||||
printf(" => %s\n", showPath);
|
||||
printff(" => %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_RightToLeft:
|
||||
printf(" <= %s\n", showPath);
|
||||
printff(" <= %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DeleteLeft:
|
||||
printf(" *- %s\n", showPath);
|
||||
printff(" *- %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DeleteRight:
|
||||
printf(" -* %s\n", showPath);
|
||||
printff(" -* %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DateLeftToRight:
|
||||
printf(" -> %s\n", showPath);
|
||||
printff(" -> %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DateRightToLeft:
|
||||
printf(" <- %s\n", showPath);
|
||||
printff(" <- %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_MakeRightDirectory:
|
||||
printf(" -D %s\n", showPath);
|
||||
printff(" -D %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_MakeLeftDirectory:
|
||||
printf(" D- %s\n", showPath);
|
||||
printff(" D- %s\n", showPath);
|
||||
break;
|
||||
}
|
||||
|
||||
actionFileNode = actionFileNode->next;
|
||||
}
|
||||
printf("End\n");
|
||||
printff("End\n");
|
||||
}
|
||||
|
||||
void AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) {
|
||||
@@ -631,43 +631,43 @@ void AccionFileNode_RunList(AccionFileNode *actionFileNode, char *pathLeft,
|
||||
|
||||
switch (actionFileNode->action) {
|
||||
case AccionFileCmp_Nothing:
|
||||
//printf("%s == %s\n",pathIzq,pathDer);
|
||||
//printff("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case AccionFileCmp_LeftToRight:
|
||||
printf(" => %s\n", showPath);
|
||||
printff(" => %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_RightToLeft:
|
||||
printf(" <= %s\n", showPath);
|
||||
printff(" <= %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_DeleteLeft:
|
||||
printf(" *- %s\n", showPath);
|
||||
printff(" *- %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_DeleteRight:
|
||||
printf(" -* %s\n", showPath);
|
||||
printff(" -* %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_DateLeftToRight:
|
||||
printf(" -> %s\n", showPath);
|
||||
printff(" -> %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_DateRightToLeft:
|
||||
printf(" <- %s\n", showPath);
|
||||
printff(" <- %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_MakeRightDirectory:
|
||||
printf(" -D %s\n", showPath);
|
||||
printff(" -D %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_MakeLeftDirectory:
|
||||
printf(" D- %s\n", showPath);
|
||||
printff(" D- %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
}
|
||||
|
||||
actionFileNode = actionFileNode->next;
|
||||
}
|
||||
printf("End\n");
|
||||
printff("End\n");
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void FileTime_Print(FileTime fileTime) {
|
||||
struct tm *tms;
|
||||
|
||||
tms = localtime((time_t *) &fileTime);
|
||||
printf("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||
printff("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
||||
tms->tm_sec);
|
||||
}
|
||||
@@ -302,7 +302,7 @@ void File_IterateDir(char *path,
|
||||
&& strcmp(entidad_dir->d_name, "..")) {
|
||||
// A partir de aqui hay un fichero
|
||||
// (o directorio)
|
||||
snprintf(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||
snprintff(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||
fin = func(f_path, entidad_dir->d_name, data);
|
||||
}
|
||||
}
|
||||
|
||||
88
src/main.c
88
src/main.c
@@ -11,22 +11,22 @@
|
||||
void Help(char *exe) {
|
||||
char exeFilename[MaxPath];
|
||||
File_GetName(exe, exeFilename);
|
||||
printf("Usage:\n");
|
||||
printf(" %s info [file] {[file] {..}}\n", exeFilename);
|
||||
printf(" %s scan [dir] [tree] \n", exeFilename);
|
||||
printf(" %s rescan [dir] [tree] \n", exeFilename);
|
||||
printf(" %s read [file] [tree]\n", exeFilename);
|
||||
printf(" %s dir [dir]\n", exeFilename);
|
||||
printf("\n");
|
||||
printf(" %s sync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s resync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s synctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s resynctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf("\n");
|
||||
printf(" %s copy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s recopy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s copytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s recopytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff("Usage:\n");
|
||||
printff(" %s info [file] {[file] {..}}\n", exeFilename);
|
||||
printff(" %s scan [dir] [tree] \n", exeFilename);
|
||||
printff(" %s rescan [dir] [tree] \n", exeFilename);
|
||||
printff(" %s read [file] [tree]\n", exeFilename);
|
||||
printff(" %s dir [dir]\n", exeFilename);
|
||||
printff("\n");
|
||||
printff(" %s sync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff(" %s resync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff(" %s synctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff(" %s resynctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff("\n");
|
||||
printff(" %s copy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff(" %s recopy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff(" %s copytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printff(" %s recopytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
}
|
||||
|
||||
FileNode *CheckDir(char *path, int recheck);
|
||||
@@ -52,29 +52,29 @@ int main(int argc, char *argv[]) {
|
||||
// Scanear informacion de directorio y guardar arbol
|
||||
long long tScan=Time_GetTime();
|
||||
FileNode *fileNode;
|
||||
printf("Building FileNode..\n");
|
||||
printff("Building FileNode..\n");
|
||||
fileNode = FileNode_Build(argv[2]);
|
||||
tScan=Time_GetTime()-tScan;
|
||||
printf("tScan: %9lldus\n",tScan);
|
||||
printff("tScan: %9lldus\n",tScan);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
} else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||
// Scanear informacion de directorio y guardar arbol
|
||||
FileNode *fileNode;
|
||||
printf("Loading FileNode..\n");
|
||||
printff("Loading FileNode..\n");
|
||||
fileNode = FileNode_Load(argv[3]);
|
||||
if (fileNode) {
|
||||
printf("Rebuilding FileNode..\n");
|
||||
printff("Rebuilding FileNode..\n");
|
||||
long long tScan=Time_GetTime();
|
||||
fileNode = FileNode_Refresh(fileNode, argv[2]);
|
||||
tScan=Time_GetTime()-tScan;
|
||||
printf("tScan: %9lldus\n",tScan);
|
||||
printff("tScan: %9lldus\n",tScan);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
}else{
|
||||
printf("Building FileNode..\n");
|
||||
printff("Building FileNode..\n");
|
||||
long long tScan=Time_GetTime();
|
||||
fileNode = FileNode_Build(argv[2]);
|
||||
tScan=Time_GetTime()-tScan;
|
||||
printf("tScan: %9lldus\n",tScan);
|
||||
printff("tScan: %9lldus\n",tScan);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
}
|
||||
} else if (!strcmp(argv[1], "read") && argc == 3) {
|
||||
@@ -128,7 +128,7 @@ FileNode *CheckDir(char *path, int recheck) {
|
||||
// Comprobar directorio
|
||||
snprintf(dirNodesFile, MaxPath, "%s/"FileNode_Filename, path);
|
||||
if (recheck) {
|
||||
printf("Checking Directory.. %s\n", path);
|
||||
printff("Checking Directory.. %s\n", path);
|
||||
long long tScan=Time_GetTime();
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (fileNode) {
|
||||
@@ -137,13 +137,13 @@ FileNode *CheckDir(char *path, int recheck) {
|
||||
fileNode = FileNode_Build(path);
|
||||
}
|
||||
tScan=Time_GetTime()-tScan;
|
||||
printf("tScan: %9lldus\n",tScan);
|
||||
printff("tScan: %9lldus\n",tScan);
|
||||
FileNode_Save(fileNode, dirNodesFile);
|
||||
} else {
|
||||
printf("Loading Directory.. %s\n", path);
|
||||
printff("Loading Directory.. %s\n", path);
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (!fileNode) {
|
||||
printf("Error, no nodesFile.fs\n");
|
||||
printff("Error, no nodesFile.fs\n");
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
@@ -153,17 +153,17 @@ FileNode *CheckDir(char *path, int recheck) {
|
||||
void PrintStatistics(AccionFileNode *actionFileNode) {
|
||||
ActionQueueStatistics statistics;
|
||||
AccionFileNode_Statistics(actionFileNode, &statistics);
|
||||
printf("Statistics\n");
|
||||
printf(" % 12s % 12s % 12s\n", "Read", "Write", "Delete");
|
||||
printf("Left : % 12lld % 12lld % 12lld\n", statistics.readLeft,
|
||||
printff("Statistics\n");
|
||||
printff(" % 12s % 12s % 12s\n", "Read", "Write", "Delete");
|
||||
printff("Left : % 12lld % 12lld % 12lld\n", statistics.readLeft,
|
||||
statistics.writeLeft, statistics.deleteLeft);
|
||||
printf("Right: % 12lld % 12lld % 12lld\n", statistics.readRight,
|
||||
printff("Right: % 12lld % 12lld % 12lld\n", statistics.readRight,
|
||||
statistics.writeRight, statistics.deleteRight);
|
||||
printf("\n");
|
||||
printf("Copy count : % 10d\n", statistics.fullCopyCount);
|
||||
printf("Date copy count: % 10d\n", statistics.dateCopyCount);
|
||||
printf("Directory count: % 10d\n", statistics.directoryCount);
|
||||
printf("Delete count : % 10d\n", statistics.deleteCount);
|
||||
printff("\n");
|
||||
printff("Copy count : % 10d\n", statistics.fullCopyCount);
|
||||
printff("Date copy count: % 10d\n", statistics.dateCopyCount);
|
||||
printff("Directory count: % 10d\n", statistics.directoryCount);
|
||||
printff("Delete count : % 10d\n", statistics.deleteCount);
|
||||
}
|
||||
|
||||
int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun) {
|
||||
@@ -171,11 +171,11 @@ int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun) {
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
if (!File_ExistsPath(pathLeft) || !File_IsDirectory(pathLeft)) {
|
||||
printf("Error, directory does not exist: %s\n", pathLeft);
|
||||
printff("Error, directory does not exist: %s\n", pathLeft);
|
||||
return 0;
|
||||
}
|
||||
if (!File_ExistsPath(pathRight) || !File_IsDirectory(pathRight)) {
|
||||
printf("Error, directory does not exist: %s\n", pathRight);
|
||||
printff("Error, directory does not exist: %s\n", pathRight);
|
||||
return 0;
|
||||
}
|
||||
fileNodeLeft = CheckDir(pathLeft, recheck);
|
||||
@@ -189,11 +189,11 @@ int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun) {
|
||||
|
||||
// Construir acciones
|
||||
long long tBuild=Time_GetTime();
|
||||
printf("Building action list.. \n");
|
||||
printff("Building action list.. \n");
|
||||
AccionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = AccionFileNode_BuildSync(fileNodeLeft, fileNodeRight);
|
||||
tBuild=Time_GetTime()-tBuild;
|
||||
printf("tBuild: %9lldus\n",tBuild);
|
||||
printff("tBuild: %9lldus\n",tBuild);
|
||||
|
||||
if (dryRun) {
|
||||
// Mostrar lista de acciones
|
||||
@@ -212,11 +212,11 @@ int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
if (!File_ExistsPath(pathLeft) || !File_IsDirectory(pathLeft)) {
|
||||
printf("Error, directory does not exist: %s\n", pathLeft);
|
||||
printff("Error, directory does not exist: %s\n", pathLeft);
|
||||
return 0;
|
||||
}
|
||||
if (!File_ExistsPath(pathRight) || !File_IsDirectory(pathRight)) {
|
||||
printf("Error, directory does not exist: %s\n", pathRight);
|
||||
printff("Error, directory does not exist: %s\n", pathRight);
|
||||
return 0;
|
||||
}
|
||||
fileNodeLeft = CheckDir(pathLeft, reCheck);
|
||||
@@ -230,11 +230,11 @@ int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
||||
|
||||
// Construir acciones
|
||||
long long tBuild=Time_GetTime();
|
||||
printf("Building action list.. \n");
|
||||
printff("Building action list.. \n");
|
||||
AccionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = AccionFileNode_BuildCopy(fileNodeLeft, fileNodeRight);
|
||||
tBuild=Time_GetTime()-tBuild;
|
||||
printf("tBuild: %9lldus\n",tBuild);
|
||||
printff("tBuild: %9lldus\n",tBuild);
|
||||
|
||||
if (dryRun) {
|
||||
// Mostrar lista de acciones
|
||||
|
||||
17
src/util.c
17
src/util.c
@@ -65,4 +65,19 @@ void Time_Pause(int pausa){
|
||||
tv.tv_usec=(long long)pausa%1000000;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
}
|
||||
#endif // if WIN32
|
||||
#endif // if WIN32
|
||||
|
||||
|
||||
int printff(char *fmt, ...){
|
||||
va_list ap;
|
||||
int n;
|
||||
|
||||
// Print
|
||||
va_start(ap,fmt);
|
||||
n=vprintf(fmt,ap);
|
||||
va_end(ap);
|
||||
|
||||
// Flush
|
||||
fflush(stdout);
|
||||
return(n);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef _UTIL_
|
||||
#define _UTIL_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
char *String_Copy(char *str);
|
||||
|
||||
/////////////////////////////
|
||||
@@ -16,4 +19,6 @@ long long Time_GetTime();
|
||||
// Pauses the execution for t usecs.
|
||||
void Time_Pause(int pausa);
|
||||
|
||||
int printff(char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user