Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor argument parser using cmdopt #10

Merged
merged 5 commits into from
Nov 1, 2023

Conversation

mohanson
Copy link
Collaborator

@mohanson mohanson commented Nov 1, 2023

Modified part of the source code of cmdopt, the diff results are as follows

2,5d1
<  * Copied from https://bellard.org/nncp/nncp-2023-10-21.tar.gz
<  */
< 
< /*
7c3
<  *
---
>  * 
29d24
< #include "my_stdlib.h"
31d25
< #include "my_stdio.h"
34,35c28,30
< #include "my_string.h"
< #include "my_assert.h"
---
> #include <assert.h>
> #include "cutils.h"
> 
57c52
< 
---
>     
71c66
< 
---
>     
110,111d104
< /* See the reason: https://reviews.llvm.org/D103009 */
< #pragma clang optimize off
121d113
< #pragma clang optimize on
140,141c132,133
<     arg_pos = 0;
<     for(optind = 0; optind < argc; ) {
---
>     arg_pos = 1;
>     for(optind = 1; optind < argc; ) {
217c209
< #endif
---
> #endif    
225c217
<     size_t len;
---
>     size_t len, i;
227c219
< 
---
>     
230d221
<         char l[256] = {0};
240c231
<                 strcat(l, " ");
---
>                 putchar(' ');
243c234
<             strcat(l, "-");
---
>             putchar('-');
245c236
<                 strcat(l, "-");
---
>                 putchar('-');
248c239,240
<             memcpy(&l[col+1], p, len);
---
>             for(i = 0; i < len; i++)
>                 putchar(p[i]);
250c242
< 
---
>             
255c247
< 
---
>         
257,264c249,252
<             if (d->arg_desc) {
<                 strcat(l, " ");
<                 strcat(l, d->arg_desc);
<                 col += 1 + strlen(d->arg_desc);
<             } else {
<                 strcat(l, " arg");
<                 col += 4;
<             }
---
>             if (d->arg_desc)
>                 col += printf(" %s", d->arg_desc);
>             else
>                 col += printf(" arg");
272c260
<             strcat(l, " ");
---
>             putchar(' ');
275,276c263
<         strcat(l, d->desc);
<         printf("%s", l);
---
>         printf("%s\n", d->desc);
302c289
< 
---
>     
332c319
< 
---
>     
348c335
< 
---
> 

@mohanson mohanson force-pushed the cmdopt branch 2 times, most recently from 5913b49 to ebab534 Compare November 1, 2023 01:24
quickjs/qjs.c Outdated Show resolved Hide resolved
quickjs/qjs.c Outdated Show resolved Hide resolved
quickjs/qjs.c Outdated Show resolved Hide resolved
quickjs/qjs.c Outdated Show resolved Hide resolved
quickjs/qjs.c Outdated Show resolved Hide resolved
@XuJiandong XuJiandong merged commit c8b2fae into nervosnetwork:main Nov 1, 2023
2 checks passed
@mohanson mohanson deleted the cmdopt branch December 13, 2024 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants