int executeCMDs(char* cmds[], int numCommands) {
	//For each command
		//create array of char pointers to the arguments, pass to 
		//call execute CMD

	char* args[64] = {0};
	char* args2[64] = {0};
	char* token = (char*)malloc(sizeof(char) * 128);

	int i = 0,
		j = 0,
		a1 = 0,
		a2 = 0;

	token = strtok(cmds[i],  " ");
	j = 0;
	while(token != NULL) {
		args[j] = strdup(token);
		j++;
		a1++;
		token = strtok(NULL, " ");
	}
	if(numCommands == 2) {
		i++;
		token = strtok(cmds[i], " ");
		j = 0;
		while(token != NULL) {
			args2[j] = strdup(token);
			j++;
			a2++;
			token = strtok(NULL, " ");

		}
	}
	executeCMD(args, args2, a1, a2);

	/*for(; i < numCommands; i++) {
		printf("Command: %s\n", cmds[i]);
		token = strtok(cmds[i], " ");
		//args[0] = (char*)malloc(sizeof(char) * 128);
		//strcpy(args[0], token);
		//args[0] = token;
		j = 0; //the first command is the filename
		while(token != NULL) {
			args[j] = strdup(token);
			//args[j] = token;
			j++;
			a1++;
			
			token = strtok(NULL, " ");
		}
		args[j] = NULL;
		//executeCMD(args, args2j);
		memset(args, 0, 64);
	}*/
}
Beispiel #2
0
/************************************************************************
* Function: getRenameCount 
* * Parameters:
*       IN char *curcount: current renamecount value
*
* Description:
*       get the persist count number
*
* Returns:
*	0 if successful else appropriate error
***************************************************************************/
int getRenameCount(long *curcount)
{
    char tmp[1024] = { 0 };
    /* read the count num */
    if(!curcount)
	return -1;
    FILE *fp = NULL;
    if ((fp = fopen (RENAMECOUNTFILE, "r")) == NULL)
        goto newFile;
    if ((fgets (tmp, 1024, fp)) == NULL)
        {
            fclose (fp);
            goto newFile;
        }
    fclose (fp);
    long count;
    sscanf (tmp, "%ld", &count);
    *curcount=count;
    return 0;

  newFile:
    /* Not exists */
    /* Create new file and set default count to zero */
    sprintf (tmp, "touch %s", RENAMECOUNTFILE);
    ZInfo4 (DBG_MISC, "Will execute->%s", tmp);
    if (executeCMD (tmp) != 0)
        {
            ZError (DBG_MISC, "Execute failed->%s", tmp);
            return -1;
        }
    /* write zero to the file */
    sprintf (tmp, "echo 0 > %s", RENAMECOUNTFILE);
    ZInfo4 (DBG_MISC, "Will execute->%s", tmp);
    if (executeCMD (tmp) != 0)
        {
            ZError (DBG_MISC, "Execute failed->%s", tmp);
            return -1;
        }
    *curcount=0; 
    return 0;
}
void
EventsHandler::handleKeyPress(XEvent* event) {
	
	std::string cmd = mKeyBindings.getCommand(
		XLookupKeysym(&event->xkey, 0), 
		event->xkey.state
		);

	if(cmd == "kill_btwm")
		isRunning = false;
	else 
		if (cmd != "") 
			executeCMD(cmd);
}
Beispiel #4
0
/************************************************************************
* Function :    checkMoveFolder 
* * Parameters:
*
* * Description:
*       This function ensure moved folder exist.
*
* Returns:
*       0 if successful else appropriate error
***************************************************************************/
int checkMoveFolder()
{
	char cmd[1024];
        sprintf (cmd, "mkdir %s", MVOEDFOLDER );
	if(folderExists(MVOEDFOLDER)){
        	if (executeCMD (cmd) != 0)
        	{
              		ZError (DBG_MISC, "Create extracted folder failed->%s", cmd);
              		return -1;
        	}
		return 0;
	}
	else
       		return 0;

}
Beispiel #5
0
/************************************************************************
* Function: updateRenameCount 
* * Parameters:
*       IN long count: current renamecount value
*
* Description:
*       Store rename count value to file 
*
* Returns:
*       0 if successful else appropriate error
***************************************************************************/
int updateRenameCount( long count)
{
    char tmp[1024] = { 0 };
    FILE *fp = NULL;
    if ((fp = fopen (RENAMECOUNTFILE, "r")) == NULL)
        {
            ZError (DBG_MISC, "The count file doesn't exists->%s",
                    RENAMECOUNTFILE);
            return -1;
        }
    fclose (fp);
    /* exists */
    sprintf (tmp, "echo %ld > %s", count, RENAMECOUNTFILE);
    if (executeCMD (tmp) != 0){
            ZError (DBG_MISC, "Update count file failed->%s", tmp);
            return -1;
    }
    return 0;
}
Beispiel #6
0
void run(){
	int m;
	int intersize = sizeof(inter)/sizeof(char *);
	int in;
	in = 0;

		if(par[0] == NULL){
			printf("No command entered");
		}
	
		for(m = 0; m < intersize; m++){
			if(strcmp(par[0], inter[m]) == 0){
				in = 1;
				runInternal(m);
			}
		}
		if(in == 0) executeCMD();
		memset(par,0,sizeof(par));
		
}
Beispiel #7
0
/**********************************************************
 * function:PicasaDownLoadPhoto
 * description:download a photo by photoID
 *
 * IN char *objID:
 *
 * return:
 *      0 ok else error
 *                                                        *
 * ********************************************************/
int PicasaDownLoadPhoto(char *objID)
{
#if 0
	char		url[512] = {0};
	char		sessionID[512] = {0};
	struct MemoryStruct chunk;
	CURL		*curl;
	CURLcode	cret;
	long		httpRspCode = 0;
	struct curl_slist *slist = NULL;
	char		*retxml = NULL;
	char photoName[1024] = {0};
	char photoType[128]={0};
	char photoURL[1024] = {0};
	char fileFullPath[1024];
	char folderPath[1024]={0};
	char CMD[1024]={0};
	DIR *dir;
	struct dirent *ptr;
	char errxml[1024];
	char hostAddr[128] = {0};
	char title[128]={0};
	char usrname[128]={0};
	char sessionID[1024]={0};

	/*    get the download file's url and title by objID */
	if(getURLByID(objID,photoURL,title,sessionID)<0) {
		return -1;
	}
	ZError(DBG_MISC,"the photo URL is %s",photoURL);
	/*    get the usrname by objID*/
	GetPicasaUsrName(objID,usrname);

	strcpy(url, photoURL);

	sprintf(request, "GET /%s HTTP/1.0\r\nHost: %s:%d\r\nContent-Length: %d\r\nContent-Type: application/atom+xml\r\nAuthorization: GoogleLogin auth=%s\r\n\r\n", host_file, hostAddr, portnumber, 0, sessionID);

			sprintf(errxml,"<ret op=\"downLoadPhoto\"><error></error></ret>");

	/*get download file's name*/
	sprintf(photoName,"%s%s",title,photoType);

	/*    check the directory("/data/OnlineSync/Picasa") exist the folder*/
	if(folderExists("/data/OnlineSync/Picasa")<0)
	{
		//new a named usrname folder
		sprintf(CMD,"mkdir /data/OnlineSync/Picasa");
		if(executeCMD(CMD)<0)
			goto failed;
	}
	else 
		ZError(DBG_MISC,"Picasa folder exists!");

	/*    check the directory("/data/OnlineSync/Picasa/usrDir") exist the folder*/
	sprintf(folderPath,"/data/OnlineSync/Picasa/%s/",usrname);
	if(folderExists(folderPath)<0)
	{
		//new a named usrname folder
		sprintf(CMD,"mkdir %s",folderPath);
		if(executeCMD(CMD)<0)
			goto failed;
	}
	else 
		ZError(DBG_MISC,"user folder exists!");


	/* check the filename at the specify directory */ 
	dir =opendir(folderPath);
	while((ptr = readdir(dir))!=NULL)
	{
		if(!strcmp(ptr->d_name,photoName))
		{
			ZError(DBG_MISC,"Please rename the photo name!!.....\n");
			closedir(dir);
			goto failed;
		}
	}
	closedir(dir);

	/*     put the binary image into the specify file       */
	memset(fileFullPath,0,1024);
	sprintf(fileFullPath,"%s%s",folderPath,photoName);
	ZError(DBG_MISC,"fileFullPath-->%s",fileFullPath);
	ZError(DBG_MISC,"\nthe http.content-->%s",http.content);

	memset(CMD,0,1024);
	sprintf(CMD,"wget %s -O %s",photoURL,fileFullPath);

	if(executeCMD(CMD)<0)
		goto failed;

#endif
	return 0;

}
Beispiel #8
0
/* Implement for ImportSummaryDB interface */
int createImportSummaryDB ()
{
    ZInfo4 (DBG_MISC, "Creating ImportsummaryDB...");
    return executeCMD (IMPORT_SUMMARY_INIT);
}