c参数解析

复制代码
 
#include <iostream>
using namespace std;
#include <string.h>

#include <stdlib.h>

#define ARGS_BUF 1024
#define ARGS_MAX 10

struct args {
    char  buf[ARGS_BUF];
    int   argc;
    char* argv[ARGS_MAX];
};
static char*
_strchrskip(char* s, int c) {
    while (*s && *s == c) s++;
    return s;
}
static void
_parse(struct args* A, int max) {
    if (max <= 0)
        max = ARGS_MAX;
    else if (max > ARGS_MAX)
        max = ARGS_MAX;

    int n = 0;
    char* p = A->buf;
    char* next;
    while (*p) {
        p = _strchrskip(p, ' ');
        if (*p == '\0')
            break;
        
        A->argv[n] = p; 
        if (++n >= max)
            break;

        next = strchr(p, ' ');
        if (next == NULL)
            break;
        
        *next = '\0';
        p = next+1;
    }
    A->argc = n;
}
int
args_parsestr(struct args* A, int max, const char* str) {
    strncpy(A->buf, str, ARGS_BUF-1);
    _parse(A, max);
    return A->argc;
}
int
args_parsestrl(struct args* A, int max, const char* str, size_t l) {
    if (l == 0) {
        A->argc = 0;
        return 0;
    }
    if (l >= ARGS_BUF)
        l = ARGS_BUF - 1;
    memcpy(A->buf, str, l);
    A->buf[l] = '\0';
    _parse(A, max);
    return A->argc;
}

struct np_state {
    int cap; 
    void** ud; 
    int maxfd;
    fd_set rfds;
    fd_set wfds;
    fd_set rtmp;
    fd_set wtmp;
};

int main()
{
  
  cout << sizeof(ud) << endl;
  return 0;
}
复制代码

 

posted on   lydstory  阅读(59)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-02-17 openvas.t
2020-02-17 中易字体
2020-02-17 masm
2020-02-17 qmemcpy 存在吗?
2020-02-17 RTCS通信
2020-02-17 c++编码规范:变量加空格,if空行
2020-02-17 c++编码规范:在头文件里使用别的类,尽量使用类的声明,而不要include其他类的头文件。

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示