Esempio n. 1
0
main()
{    
    tLinkTable * head = NULL;
    InitMenuData(&head);
    printf("增加命令之前:\n");
    ShowAllCmd(head);
    FindCmd( head, "help");
    InsertCmd(head,"debug", "this is debug", NULL);
    printf("增加命令之后:\n");
    ShowAllCmd(head);
    while(1)
    {
        char cmd[CMD_MAX_LEN];
        printf("Input a cmd number > ");
        scanf("%s", cmd);
        tDataNode *p = FindCmd(head, cmd);
        if( p == NULL)
        {
            printf("This is a wrong cmd!\n ");
            continue;
        }
        printf("%s - %s\n", p->cmd, p->desc); 
        if(p->handler != NULL) 
        { 
            p->handler();
        }
   
    }
}
Esempio n. 2
0
/**
 * @brief find xx.rpm
 */
void testFindCmd4RpmFile()
{
  char *Filename = "../test-data/testdata4unpack/libgnomeui2-2.24.3-1pclos2010.src.rpm";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 17);
  Filename = "../test-data/testdata4unpack/fossology-1.2.0-1.el5.i386.rpm";
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 17);
}
Esempio n. 3
0
int main()
{
    tDataNode *p = NULL;
    /*cmd line begins*/
    p = head;	
    while(1)
    {
        char cmd[CMD_MAX_LEN];
        printf("Please input a cmd:\n");
 	scanf("%s",cmd);
 	p = head;
 	tDataNode *p = FindCmd(head,cmd);
 	if(p == NULL)
        {
 	    printf("This is a wrong cmd!\n");
 	    break;
 	}
 	while(p != NULL)
        {
 	    if(p->handler != NULL&&strcmp(p->cmd,cmd) == 0)
            {
 	        p->handler();
 		break;
 	    }
 	    else if(p->handler == NULL&&strcmp(p->cmd,cmd) == 0)
            {
 	        printf("%s - %s\n",p->cmd,p->desc);
 		break;
 	    }
 	    p = p->next;
 	}
    }
 	
}
Esempio n. 4
0
File: menu.c Progetto: peyfey/selabs
/* add commands into the head */
int AddCmd(tLinkTable *head, const char * cmd, const char * desc,int (*handler)(tLinkTable * handler), int * enable)
{
    if(head != NULL && cmd != NULL)
    {
        if(FindCmd(head, (char*)cmd)==NULL)
        {
            tDataNode * pNode = (tDataNode*)malloc(sizeof(tDataNode));
            pNode->pNext=NULL;
            pNode->cmd=cmd;
            pNode->desc=desc;
            pNode->handler=handler;
            pNode->enable=ENABLE;
            AddLinkTableNode(head,(tLinkTableNode *)pNode);
            return SUCCESS;
        }
        else
        {
            printf("command is exist!\n");
            return FAILURE;
        }
    }
    else
    {
        return FAILURE;
    }
}
Esempio n. 5
0
/**
 * @brief find xx.tar
 */
void testFindCmd4TarFile()
{
  char *Filename = "../test-data/testdata4unpack/rpm.tar";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 10);
}
Esempio n. 6
0
/*
 * run add cmd
 */
int Add(tLinkTable *pLinkTable)
{
    char AddCmd[CMD_MAX_LEN];
    char AddDesc[DESC_LEN];
    if(pLinkTable == NULL)
    {
        return FAILURE;
    }
    tDataNode * pAdd = (tDataNode *)malloc(sizeof(tDataNode));
    tDataNode * pTempNode;
    
    printf("Plase input AddCmd name > ");
    scanf("%s", AddCmd);
    pTempNode = FindCmd(pLinkTable, AddCmd);
    if(pTempNode != NULL)
    {
        printf("Cmd is existed!\n");
        return FAILURE;
    }
    strcpy(pAdd->cmd, AddCmd);
    printf("Plase input cmd desc >");
    getchar();
    scanf("%[^\n]", AddDesc);
    strcpy(pAdd->desc, AddDesc);
    pAdd->pNext = NULL;
    pAdd->hander = NULL;
    AddLinkTableNode(pLinkTable,(tLinkTableNode *)pAdd);
    return SUCCESS;
}
Esempio n. 7
0
/**
 * @brief find xx.udeb
 */
void testFindCmd4DebFile()
{
  char *Filename = "../test-data/testdata4unpack/libpango1.0-udeb_1.28.1-1_i386.udeb";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 19);  /* let ar handle udeb */
}
Esempio n. 8
0
/**
 * @brief find xx.rar
 */
void testFindCmd4RarFile()
{
  char *Filename = "../test-data/testdata4unpack/winscp376.rar";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 13);
}
Esempio n. 9
0
/**
 * @brief find xx.cpio
 */
void testFindCmd4CpioFile()
{
  char *Filename = "../test-data/testdata4unpack/test.cpio";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 12);
}
Esempio n. 10
0
/**
 * @brief find xx.zip
 */
void testFindCmd4ZipFile()
{
  char *Filename = "../test-data/testdata4unpack/threezip.zip";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 9);
}
Esempio n. 11
0
/**
 * @brief find xx.iso
 */
void testFindCmd4IsoFile()
{
  char *Filename = "../test-data/testdata4unpack/imagefile.iso";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 20);  // let isoinfo handle the isos
}
Esempio n. 12
0
main()
{
    head = CreateLinkTable();
    AddLinkTableNode(head,(tLinkTableNode *)&data[0]);
    AddLinkTableNode(head,(tLinkTableNode *)&data[1]);
    
   /* cmd line begins */
    while(1)
    {
        char cmd[CMD_MAX_LEN];
        printf("Input a cmd number > ");
        scanf("%s", cmd);
        tDataNode *p = FindCmd(head, cmd);
        if( p == NULL)
        {
            printf("This is a wrong cmd!\n ");
            continue;
        }
        printf("%s - %s\n", p->cmd, p->desc); 
        if(p->handler != NULL) 
        { 
            p->handler();
        }
   
    }
}
Esempio n. 13
0
/**
 * @brief find xx.a
 */
void testFindCmd4ArchiveLibFile()
{
  char *Filename = "../test-data/testdata4unpack/libfossagent.a";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 18);
}
Esempio n. 14
0
/**
 * @brief find xx.Z
 */
void testFindCmd4ZFile()
{
  char *Filename = "../test-data/testdata4unpack/FileName.tar.Z";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 2);
}
Esempio n. 15
0
/**
 * @brief find xx.msi
 */
void testFindCmd4MsiFile()
{
  char *Filename = "../test-data/testdata4unpack/xunzai_Contacts.msi.msi";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 16);
}
Esempio n. 16
0
/**
 * @brief find xx.bz2
 */
void testFindCmd4Bz2File()
{
  char *Filename = "../test-data/testdata4unpack/test.tar.bz2";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 3);
}
Esempio n. 17
0
/**
 * @brief find .dsc
 */
void testFindCmd4DscFile()
{
  char *Filename = "../test-data/testdata4unpack/fcitx_3.6.2-1.dsc";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 27);
}
Esempio n. 18
0
/**
 * @brief find xx.cab
 */
void testFindCmd4CabFile()
{
  char *Filename = "../test-data/testdata4unpack/SKU011.CAB";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 16);
}
Esempio n. 19
0
/**
 * @brief find partition
 */
void testFindCmd4PartitionFile()
{
  char *Filename = "../test-data/testdata4unpack/vmlinuz-2.6.26-2-686";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 26);
}
Esempio n. 20
0
/**
 * @brief find ext2 fs
 */
void testFindCmd4Ext2File()
{
  char *Filename = "../test-data/testdata4unpack/ext2test-image";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 24);
}
Esempio n. 21
0
/**
 * @brief find ntfs fs
 */
void testFindCmd4NtfsFile()
{
  char *Filename = "../test-data/testdata4unpack/ntfstest-image";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 23);
}
Esempio n. 22
0
/**
 * @brief find xx.exe
 */
void testFindCmd4ExeFile()
{
  char *Filename = "../test-data/testdata4unpack/PUTTY.EXE";
  int result = 0;
  result = FindCmd(Filename);
  FO_ASSERT_EQUAL(result, 16);  /* this can be unpacked by 7z */
}
Esempio n. 23
0
int main()
{
    /*if s=0,that means the Initialization of cmd[] is failed*/
    int s;
    s = 1;
    while(s)
    {
        tDataNode *p;
        char *cmd;
        cmd = (char *)malloc(sizeof(char*));
        tDataNode *head = NULL;
        head = GetCmdDef(head);
        if(head != NULL)
        {
            printf("Input a cmd number > ");
            scanf("%s",cmd);
            p = FindCmd(head,cmd);
            /* get the right command */
            if(p != NULL)
            {
                /* Show help list */
                if(strcmp(cmd,HELP_CMD) == 0)
                {
                    printf("******This is a help list******\n");
                    /* print out all cmd  */
                    for(p = head;p != NULL;p = p->next)
                    {
                        printf("%s - %s\n", p->cmd, p->desc);
                    }
                }
                else
                {
                    /* quit the program */
                    if(strcmp(cmd,QUIT_CMD) == 0)
                    {
                        exit(0);
                    }
                    else
                    {
                        printf("The command you input is %s,%s\n",p->cmd,p->desc);
                    }
                }
            }
            else
            {
                printf("This is a wrong command! Try again!\n");
            }
        }
        else
        {
            s = 0;
            printf("fail to open the \"menu.ini\" file in the path of the program,\n");
            printf("or the contents of \"menu.ini\" file have some mistakes.\n ");
            system("pause");
        }
    }
    return 0;
}
Esempio n. 24
0
static void ExecCmd (Collection* Args, const CmdEntry* Tab, unsigned Count)
/* Search for the command in slot 0 of the given collection. If found, check
 * the argument count, then execute it. If there are problems, output a
 * diagnostic.
 */
{
    /* Search for the command, check number of args, then execute it */
    const char* Cmd = CollAt (Args, 0);
    const CmdEntry* E = FindCmd (Cmd, Tab, Count);
    if (E == 0) {
        PrintLine ("No such command: %s", Cmd);
        return;
    }

    /* Check the number of arguments. Zero means that the function will check
     * itself. A negative count means that the function needs at least
     * abs(count) arguments. A positive count means that the function needs
     * exactly this number of arguments.
     * Note: The number includes the command itself.
     */
    if (E->ArgCount > 0 && (int)CollCount (Args) != E->ArgCount) {
        /* Argument number mismatch */
        switch (E->ArgCount) {

            case 1:
                PrintLine ("Command doesn't accept an argument");
                return;

            case 2:
                PrintLine ("Command requires an argument");
                return;

            default:
                PrintLine ("Command requires %d arguments", E->ArgCount-1);
                return;
        }
    } else if (E->ArgCount < 0 && (int)CollCount (Args) < -E->ArgCount) {
        /* Argument number mismatch */
        switch (E->ArgCount) {

            case -2:
                PrintLine ("Command requires at least one argument");
                return;

            default:
                PrintLine ("Command requires at least %d arguments", E->ArgCount-1);
                return;
        }
    } else {
        /* Remove the command from the argument list, then execute it */
        CollDelete (Args, 0);
        E->Func (Args);
    }
}
Esempio n. 25
0
/**
 * @brief find fat fs
 */
void testFindCmd4FatFile()
{
  char *Filename = "../test-data/testdata4unpack/fattest-image";
  int result = 0;
  result = FindCmd(Filename);
  //FO_ASSERT_EQUAL(result, 22);
  if (result == 16 || result == 22)
  {
    FO_PASS(result);
  }else{
    FO_FAIL(result);
  }
  
}
Esempio n. 26
0
/**
 * @brief find xx.7z
 */
void testFindCmdNormal()
{
  char *Filename = "../test-data/testdata4unpack.7z";
  int result = 0;
  result = FindCmd(Filename);
  //FO_ASSERT_EQUAL(result, 15);
  if (result == 15 || result == 16)
  {
    FO_PASS(result);
  
  }else
  {
    FO_FAIL(result);
  }
}
Esempio n. 27
0
File: menu.c Progetto: peyfey/selabs
/* turn on or turn off a command */
int OnOffCmd(tLinkTable *head, const char *cmd,int enable)
{
    tDataNode *p;
    p = FindCmd(head, (char*)cmd);
    if(p==NULL)
    {
        printf("command is not exist!\n");
        return FAILURE;
    }
    else
    {
        p->enable =enable;
        return SUCCESS;
    }
    return 0;
}
Esempio n. 28
0
main()
{   while(1)
    {char cmd[CMD_MAX_LENS]; 
     printf("please enter the cmd:\n");
     scanf("%s",cmd);
     tDataNode *P;
     tDataNode* p=FindCmd(menulist,cmd);
     if(p!=NULL)
    {
       printf("%s- %s\n",p->cmd,p->dsc);
       if(p->handler!=NULL)
           p->handler();
    }
    else printf("it is a wrong number\n");
    } 
}
Esempio n. 29
0
/* Delete Cmd from linklist */
int DelCmd(char *cmd)
{
    tDataNode *pNode = NULL;
    
    if(head == NULL || cmd == NULL)
    {
        return FAILURE;
    }
    
    pNode = FindCmd(cmd);
    /* Check if the cmd is existence */
    if(pNode == NULL)
    {
        return FAILURE;
    }

    return DelLinkTableNode(head, (tLinkTableNode *)pNode);
}
Esempio n. 30
0
File: menu.c Progetto: peyfey/selabs
/* delete commands from the head */
int DelCmd(tLinkTable *head, const char * cmd)
{
    tDataNode *p;
    p = FindCmd(head, (char*)cmd);
    if(p==NULL)
    {
         printf("command is not exist!\n");
         return FAILURE;
    }
    else
    {
        DelLinkTableNode(head,(tLinkTableNode *)p);
        free(p);
        p=NULL;
        return SUCCESS;
    }

}