Exemplo n.º 1
0
int main(int argc, char **argv)
{
    if (argc < 3) {
        // ###### Note: please consider adding new tests to karchivetest (so that they can be automated)
        // rather than here (interactive)
        printf("\n"
               " Usage :\n"
               " ./kziptest list /path/to/existing_file.zip       tests listing an existing zip\n"
               " ./kziptest print-all file.zip                    prints contents of all files.\n"
               " ./kziptest print file.zip filename               prints contents of one file.\n"
               " ./kziptest update file.zip filename              update filename in file.zip.\n"
               " ./kziptest save file.zip                         save file.\n"
               " ./kziptest load file.zip                         load file.\n"
               " ./kziptest write file.bz2                        write compressed file.\n"
               " ./kziptest read file.bz2                         read uncompressed file.\n"
              );
        return 1;
    }
    QCoreApplication app(argc, argv);
    QString command = argv[1];
    if (command == QLatin1String("list")) {
        return doList(QFile::decodeName(argv[2]));
    } else if (command == QLatin1String("print-all")) {
        return doPrintAll(QFile::decodeName(argv[2]));
    } else if (command == QLatin1String("print")) {
        if (argc != 4) {
            printf("usage: kziptest print archivename filename");
            return 1;
        }
        return doPrint(QFile::decodeName(argv[2]), argv[3]);
    } else if (command == QLatin1String("save")) {
        return doSave(QFile::decodeName(argv[2]));
    } else if (command == QLatin1String("load")) {
        return doLoad(QFile::decodeName(argv[2]));
    } else if (command == QLatin1String("write")) {
        return doCompress(QFile::decodeName(argv[2]));
    } else if (command == QLatin1String("read")) {
        return doUncompress(QFile::decodeName(argv[2]));
    } else if (command == QLatin1String("update")) {
        if (argc != 4) {
            printf("usage: kziptest update archivename filename");
            return 1;
        }
        return doUpdate(QFile::decodeName(argv[2]), QFile::decodeName(argv[3]));
    } else if (command == QLatin1String("transfer")) {
        if (argc != 4) {
            printf("usage: kziptest transfer sourcefile destfile");
            return 1;
        }
        return doTransfer(QFile::decodeName(argv[2]), QFile::decodeName(argv[3]));
    } else {
        printf("Unknown command\n");
    }
}
Exemplo n.º 2
0
void doInput(student_t_ptr student_ptr[]){
    printf("How many student?\n>");
    scanf("%d",&numberofstudent);
    printf("Start to read data. eg: name 001 95 85 75 95 65 55\n");
    int i;
    for(i=0;i<numberofstudent;i++){
        *student_ptr[i] = doReadStudent();
    }
    printf("Read finished! Those data have been read.\n");
    doList(student_ptr);
}
Exemplo n.º 3
0
int main(int argc, const char * argv[])
{
	int count=0;
	RingList *theList = doList();
	doPrintList(theList);
	printf("\n");
	
	/*printf("List after swapping Node\n");
	doPrintList(swapNodeAtList(theList));
	
	doSortingValue(theList);
	printf("\n");
	printf("List after sorting Node\n");
	doPrintList(theList);
	*/
	theBubleSorting(theList, count);
	doPrintList(theList);
	system("pause");
}
Exemplo n.º 4
0
void buildFromFile(student_t_ptr student_ptr[],char name[]){
    FILE *fp = fopen(name,"r");
    if(fp == NULL){
        printf("Open file error!");
        return;
    }else{
        fscanf(fp,"%d",&numberofstudent);
        int i;
        for(i=0;i<numberofstudent;i++){
            fscanf(fp,"%s %d %d %d %d %d %d %d",
                   student_ptr[i]->name,&student_ptr[i]->ID,
                   &student_ptr[i]->score[0],&student_ptr[i]->score[1],
                   &student_ptr[i]->score[2],&student_ptr[i]->score[3],
                   &student_ptr[i]->score[4],&student_ptr[i]->score[5]);
        }
        printf("Read finished! Those data have been read.\n");
        doList(student_ptr);
    }
}
Exemplo n.º 5
0
//Funcion Protocolo
void start_protocol(const int clientSocket,const char baseDir[]) {

	char readBuffer[1024];
	int readBytes;
	char *cmdString;
	char *ptr;
	char *token;

	while(true) {
		cmdString = (char *) calloc(255,1);
		while((readBytes = read(clientSocket,readBuffer,1))>0) {
			cmdString = (char *) realloc(cmdString,strlen(cmdString)+readBytes+1);
			strncat(cmdString,readBuffer,readBytes);
			ptr = cmdString+(strlen(cmdString)-4);
			if(strcmp(ptr,"\r\n\r\n")==0) {
				*ptr = '\0';
				break;
			}
		}

		debug(4,"<- %s",cmdString);

		token = strtok(cmdString," \t\b");
		if(strcmp(token,"GET")==0) {
			token = strtok(NULL," \t\b");
			if(token == NULL) {
				sendLine(clientSocket, "ERROR ( Missing FileName )\r\n\r\n");
			} else {
				doGet(clientSocket,baseDir, token);
			}
		} else if(strcmp(token,"LIST")==0) {
			doList(clientSocket,baseDir);
		} else if(strcmp(token,"QUIT")==0) {
					break;
		} else {
			sendLine(clientSocket, "UNKOWN METHOD\r\n\r\n");
		}

		if(cmdString != NULL) free(cmdString);
	}

}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {
	int ret = EXIT_SUCCESS;                     /* return value */

	/* check parameter */
	if (argc < 2) {
		fprintf(stderr, "ERROR: You need to give some command.\n");
		showHelp();
		return (EXIT_FAILURE);
	}

	initSystem();
	if (gSystem == SYSTEM_ERROR) {
		fprintf(stderr, "ERROR: No package-system found (yum, apt).\n");
		exit(EXIT_FAILURE);
	}

	initCommand(argv[1]);
	initList(argc - 2, (char **)argv + 2);

	switch (gCommand) {
		case COMMAND_HELP:
			showHelp();
			break;
		case COMMAND_VERSION:
			showVersion();
			break;
		case COMMAND_INSTALL:
			if (gList == NULL) {
				fprintf(stderr, "Error: Need to pass a list of pkgs to install.\n");
				showHelp();
				ret = EXIT_FAILURE;
				break;
			}
			doInstall();
			break;
		case COMMAND_REMOVE:
			if (gList == NULL) {
				fprintf(stderr, "Error: Need to pass a list of pkgs to remove.\n");
				showHelp();
				ret = EXIT_FAILURE;
				break;
			}
			doRemove();
			break;
		case COMMAND_SEARCH:
			if (gList == NULL) {
				fprintf(stderr, "Error: Need to pass a list of pkgs to search.\n");
				showHelp();
				ret = EXIT_FAILURE;
				break;
			}
			doSearch();
			break;
		case COMMAND_LIST:
			if (gList == NULL) {
				fprintf(stderr, "Error: Need to pass a list of pkgs to lisst.\n");
				showHelp();
				ret = EXIT_FAILURE;
				break;
			}
			doList();
			break;
		case COMMAND_UPDATE:
			if (gList == NULL) {
				fprintf(stderr, "Error: Need to pass a list of pkgs to update.\n");
				showHelp();
				ret = EXIT_FAILURE;
				break;
			}
			doUpdate();
			break;
		default:
			fprintf(stderr, "ERROR: No such command '%s'. Please use '%s --help'.\n", argv[1], PRG_NAME);
			ret = EXIT_FAILURE;
	}

	destroy();

	return (ret);
}
Exemplo n.º 7
0
/*this is the main routine*/
void doshell()
{
	char line[80];

	/*run forever - the shell shouldn't end*/
	while(1==1)
	{
		/*read in a line*/
		printstring("SHELL>\0");
		readstring(line);

		/*match it against each possible command*/
		/*if the user presses return, ignore it*/
		if (line[0]==0xd)
			continue;
		else if (iscommand(line,"CLS\0")==1)
			doclear();
		else if (iscommand(line,"cls\0")==1)
			doclear();
		else if (iscommand(line,"COPY\0")==1)
			docopy();
		else if (iscommand(line,"copy\0")==1)
			docopy();
		else if (iscommand(line,"CREATE \0")==1)
			docreate(line);
		else if (iscommand(line,"create \0")==1)
			docreate(line);
		else if (iscommand(line,"DELETE \0")==1)
			dodelete(line);
		else if (iscommand(line,"delete \0")==1)
			dodelete(line);
		else if (iscommand(line,"DIR\0")==1)
			dodir();
		else if (iscommand(line,"dir\0")==1)
			dodir();
		else if (iscommand(line,"EXEC \0")==1)
			doexecute(line,1);
		else if (iscommand(line,"exec \0")==1)
			doexecute(line,1);
		else if (iscommand(line,"EXECBACK \0")==1)
			doexecute(line,0);
		else if (iscommand(line,"execback \0")==1)
			doexecute(line,0);
		else if (iscommand(line,"HELP\0")==1)
			dohelp();
		else if (iscommand(line,"help\0")==1)
			dohelp();
		else if (line[0]=='?')
			dohelp();
		else if (iscommand(line,"TYPE \0")==1)
			dotype(line);
		else if (iscommand(line,"type \0")==1)
			dotype(line);
		else if (iscommand(line,"KILL \0")==1)
			dokill(line);
		else if (iscommand(line,"kill \0")==1)
			dokill(line);
		else if (iscommand(line,"mkdir \0")==1)
			domkdir(line);
		else if (iscommand(line,"MKDIR\0")==1)
			domkdir(line);	
		else if (iscommand(line,"FORMAT\0")==1)
			doFormat();	
		else if (iscommand(line,"format\0")==1)
			doFormat();	
		else if (iscommand(line,"remove\0")==1)
			doRemove(line);	
		else if (iscommand(line,"REMOVE\0")==1)
			doRemove(line);	
		else if (iscommand(line,"list\0")==1)
			doList();	
		else if (iscommand(line,"LIST\0")==1)
			doList();	
		else if (iscommand(line,"count\0")==1)
			doCount(line);
		else if (iscommand(line,"WRITE\0")==1)
				doCreateFile(line);	
		else if (iscommand(line,"write\0")==1)
			doCreateFile(line);
		else if (iscommand(line,"READ\0")==1)
				doEcho(line);	
		else if (iscommand(line,"read\0")==1)
			doEcho(line);
		else
			printstring("Command not found\r\n\0");
		printstring("\r\n\0");
	}
}
Exemplo n.º 8
0
int main (int argc, char **argv)
{
 int dbug=0;
 char *input;
 int ch;
 list *l = lst_create();

 if(argc ==2){
   if(argv[1][0] == '-' && argv[1][1] == 'd'){
     dbug = 1;  // ./a.out -d
     printf("\nDebug mode activated\n");
   }
 }
 
 printf ("Starting Restaurant Wait List Program\n\n");
 printf ("Enter command: ");

 while ((ch = getNextNWSChar ()) != EOF)
   {
    /* check for the various commands */
    if ('q' == ch)
      {
       printf ("Quitting Program\n");
       return (0);
      }
    else if ('?' == ch)
      {
       printCommands();
      }
    else if('a' == ch)
      {
       doAdd(l,dbug);
      } 
    else if('c' == ch)
      {
       doCallAhead(l,dbug);
      } 
    else if('w' == ch)
      {
       doWaiting(l,dbug);
      } 
    else if('r' == ch)
      {
       doRetrieve(l,dbug);
      } 
    else if('l' == ch)
      {
       doList(l,dbug);
      } 
    else if('d' == ch)
      {
       doDisplay(l,dbug);
      } 
    else
      {
       printf ("%c - in not a valid command\n", ch);
       printf ("For a list of valid commands, type ?\n");
       clearToEoln();
      }

    printf ("\nEnter command: ");
   }

 printf ("Quiting Program - EOF reached\n");
 lst_free(l,dbug);
 return 1;
}