#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; }