23高级软工

高级软件工程学习总结和心得体会

参考资料《代码中的软件工程》https://gitee.com/mengning997/se

正则表达式

基本字符串搜索

/word 向光标下搜索“word”字符;?word 向光标上搜索“word”字符;
n 向下重复上次搜索指令;N向上重复上次搜索指令;

同时搜索多个字符串 用 | 连接 (或)

通配符

“.” hug huh hut hum 都可以用hu. 来匹配;
“+” hahhhhhh 可以用hah+来匹配;省略 >=1次的字符;
“*\” ha hahhhhhh 可以用通过ha*来匹配;省略表示>=0次的字符;
“? ” 可能存在的字符 比如color colour 用 colou?r来匹配;注意?是在后面的

字符集

[aiu] /b[aiu]g可以用来匹配bag big bug;
- 连接符表示集合元素范围 [0-9]表示数字0到数字9 [a-z]表示所有小写字母;
^ 表示否定 [^aeiou] 不匹配元音字母;

快捷方式 \w匹配[A-Za-z0-9_] \W匹配[^A-Za-z0-9_] \d匹配数字[0-9] \D匹配[^0-9]

贪婪匹配和懒惰匹配

贪婪匹配找最长;懒惰匹配找最短;默认是贪婪匹配;使用字符?改为懒惰匹配
titanic
t[a-z]*i 会匹配 titani;t[a-z]*?i 会匹配 ti

匹配开头和结尾

在集合外用 ^ 和 $ 来表示从开头还是从结尾匹配;^[Ricky] 而不是 [^Ricky]

vim

我也选择gg

menu代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "linktable.h"

int Help();
int Quit();

#define CMD_MAX_LEN 128
#define DESC_LEN    1024
#define CMD_NUM     10


/* data struct and its operations */

typedef struct DataNode
{
    tLinkTableNode head;
    char*   cmd;
    char*   desc;
    int     (*handler)();
} tDataNode;


int SearchCondition(tLinkTableNode * pLinkTableNode, void * args)
{
    char * cmd = (char*) args;
    tDataNode * pNode = (tDataNode *)pLinkTableNode;
    if(strcmp(pNode->cmd, cmd) == 0)
    {
        return  SUCCESS;  
    }
    return FAILURE;	       
}

/* find a cmd in the linklist and return the datanode pointer */
tDataNode* FindCmd(tLinkTable * head, char * cmd)
{
    return  (tDataNode*)SearchLinkTableNode(head, SearchCondition, (void*)cmd);
}

/* show all cmd in listlist */
int ShowAllCmd(tLinkTable * head)
{
    tDataNode * pNode = (tDataNode*)GetLinkTableHead(head);
    while(pNode != NULL)
    {
        printf("%s - %s\n", pNode->cmd, pNode->desc);
        pNode = (tDataNode*)GetNextLinkTableNode(head, (tLinkTableNode *)pNode);
    }
    return 0;
}

int InitMenuData(tLinkTable ** ppLinktable)
{
    *ppLinktable = CreateLinkTable();
    tDataNode* pNode = (tDataNode*)malloc(sizeof(tDataNode));
    pNode->cmd = "help";
    pNode->desc = "Menu List:";
    pNode->handler = Help;
    AddLinkTableNode(*ppLinktable, (tLinkTableNode *)pNode);
    pNode = (tDataNode*)malloc(sizeof(tDataNode));
    pNode->cmd = "version";
    pNode->desc = "Menu Program V1.0";
    pNode->handler = NULL; 
    AddLinkTableNode(*ppLinktable, (tLinkTableNode *)pNode);
    pNode = (tDataNode*)malloc(sizeof(tDataNode));
    pNode->cmd = "quit";
    pNode->desc = "Quit from Menu Program V1.0";
    pNode->handler = Quit; 
    AddLinkTableNode(*ppLinktable, (tLinkTableNode *)pNode);
 
    return 0; 
}

/* menu program */

tLinkTable * head = NULL;

int main()
{
    InitMenuData(&head); 
   /* 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();
        }
   
    }
}

int Help()
{
    ShowAllCmd(head);
    return 0; 
}

int Quit()
{
    exit(0);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值