Esempio n. 1
0
File: main.c Progetto: idmit/accomb
int main(int argc, const char * argv[])
{
    List *cmnds = NULL;
    char *string = NULL;
    int quit = 0;
    
    ErrorCode errorCode = ERRORCODE_NO_ERROR, endOfFile = ERRORCODE_NO_ERROR;
    
    CATCH_ERROR(InitInput(&string), errHandler); // allocating input string
    MEM(string, initialError); // checking if allocation was successful, otherwise quiting
    
    while (endOfFile == ERRORCODE_NO_ERROR && quit != 1) // ends on <quit> command
    {
        ReleaseList(&cmnds); // releasing list of tokens
        endOfFile = ReadStringFromStream(stdin, &string); // reading string of unknown length
        CATCH_ERROR(Tokenize(string, &cmnds), errHandler); // creating a list of tokens from input string
        CATCH_ERROR(Route(cmnds, &quit), errHandler); // trying to find a matching method
        
        errHandler:
            PrintErrorFeedback(errorCode); // on error printing feedback info and continuing main loop
    }
    
    ReleaseList(&cmnds); // after escaping while
    ReleaseInput(string);
    
    return 0;
    
    initialError:
        return 1;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
ParseArguments(argc, argv);//incorrect arguments? print help & exit. Also, fill in SourceDirectoryName and DestinationDirectoryName; process flags.
Vprintf("OddBackup, version %s.\nBackup '%s' to '%s'.\n", VERSION, SourceDirectoryName, DestinationDirectoryName);
switch (Suspicion)
	{
	case 1: Vprintf("All attempts of shell-injections will be eliminated!\n");break;
	case 0: Vprintf("You'll be asked about fixing suspicious filenames.\n");break;
	case -1: Vprintf("You won't be disturbed with suspicious filenames. Enjoy your day!\n");break;
	}
struct dirent * DirectoryEntryPointer;
DIR * ProcessingDirPointer;

PushDir(SourceDirectoryName);

while (ProcessingDirectoryName = PopDir())
	{
	if (DotsCheck(ProcessingDirectoryName))//eliminate "." and ".." entries
		{
		continue;
		}
	if (!TryDirectory(ProcessingDirectoryName))
		{
		printf("Can't backup %s.\n", ProcessingDirectoryName);
		continue;
		}
	Dprintf("Processing %s\n", ProcessingDirectoryName);
	Vprintf("Entering %s\n", ProcessingDirectoryName);
	ProcessingDirPointer = opendir(ProcessingDirectoryName);
	CATCH_ERROR("Can't open directory");
	while ((DirectoryEntryPointer = readdir(ProcessingDirPointer)) != NULL)
		{
		switch(DirectoryEntryPointer->d_type)
			{
			case DT_DIR :	PushDir(AbsoluteSourceName(DirectoryEntryPointer->d_name)); break;//it's a directory - will be processed too
			case DT_REG :	if (IsToBeBackuped(DirectoryEntryPointer->d_name))//it's a file
						{
						BackupAndGzip(DirectoryEntryPointer->d_name);
						};
					break;
			default : printf("%s is neither file nor directory - can't backup.\n", DirectoryEntryPointer->d_name);
			}
		}
	Vprintf("Leaving %s\n", ProcessingDirectoryName);
	closedir(ProcessingDirPointer);
	free(ProcessingDirectoryName);
	}

return 0;
}
Esempio n. 3
0
Client::~Client()
{
  // Close an open socket. Do not throw exceptions in the destructor.
  if (isConnected()) {
    CATCH_ERROR(close());
  }

#if defined(_WIN32)
  if (m_initialize) {
    if (0 == WSACleanup()) {
      m_initialize = false;
    }
  }
#endif  // _WIN32
}
Esempio n. 4
0
void GlobaliseInput()
{
char * CallersDirectoryName = get_current_dir_name();
CATCH_ERROR("Can't get calling directory's name");
if (!CallersDirectoryName)
	{
	exit(-1);
	}
Dprintf("GI: Caller's Directory: %s\n",CallersDirectoryName);
if (SourceDirectoryName[0] != '/')//not global path
	{
	char * GlobalSourceDirectoryName = (char*)malloc(sizeof(char)*(strlen(CallersDirectoryName)+strlen(SourceDirectoryName)+3));
	if (SourceDirectoryName[0] == '.')
		{
		sprintf(GlobalSourceDirectoryName, "%s%s", CallersDirectoryName, SourceDirectoryName + 1);
		}
	else
		{
		sprintf(GlobalSourceDirectoryName, "%s/%s", CallersDirectoryName, SourceDirectoryName);
		}
	SourceDirectoryName = GlobalSourceDirectoryName;
	}
Dprintf("GI: Source Directory: %s\n", SourceDirectoryName);
if (DestinationDirectoryName[0] != '/')//not global path
	{
	char * GlobalDestinationDirectoryName = (char*)malloc(sizeof(char)*(strlen(CallersDirectoryName)+strlen(DestinationDirectoryName)+3));
	if (DestinationDirectoryName[0] == '.')
		{
		sprintf(GlobalDestinationDirectoryName, "%s%s", CallersDirectoryName, DestinationDirectoryName + 1);
		}
	else
		{
		sprintf(GlobalDestinationDirectoryName, "%s/%s", CallersDirectoryName, DestinationDirectoryName);
		}
	DestinationDirectoryName = GlobalDestinationDirectoryName;
	}
Dprintf("GI: Destination Directory: %s\n", DestinationDirectoryName);
free(CallersDirectoryName);
}