Command Line Interface (CLI): your recommendations

R

Roman Mashak

Hello, Barry!
You wrote on Sun, 12 Feb 2006 11:08:48 -0800:

Thank you very much for useful tips.

[skip]
BS> But you are inconsistent. You actually copy the command but only
BS> store the argument addresses. What about the command is so special
BS> that you need to store the actual characters in cli->command rather
BS> than simply the address of the command in buf?


??>> while (1) {
??>> printf("%s", PROMPT);

BS> Use fflush here to force the output to your screen.

??>> if ( fgets(buf, BUFSIZ, stdin) ) {
??>> /* skip LF/CR/TAB/SP */
??>> if (buf[0] == '\n' || buf[0] == ' ' || buf[0] == '\r' ||
??>> buf[0] == '\t')

BS> Look up the isspace() function if you really want to do this. Are you
BS> sure you want to do this since the strtoken call in
BS> cliParseCommandLine() will very happily skip over leading white space
BS> for you?
Actually true, but my intention was to skip input consisting only of '\t',
'\n', ' ' and '\r'. That's isspace() is much better here.

With best regards, Roman Mashak. E-mail: (e-mail address removed)
 
N

Nick Keighley

Rod said:
Roman Mashak said:
Hello, Rod!
Sorry I made typo in first post, right definition of "cmdLineEntry_t" is:

/* define command line: <command> <param1> <param2> ... <paramN> */
typedef struct cmdLineEntry_s {
#define MAX_NAME 20
char command[MAX_NAME];
#define MAX_ARGS 10
char *params[MAX_ARGS];
unsigned int params_num;
handler_ptr_t cmd_handler;
} cmdLineEntry_t;

i.e. params is array of pointers to char.

Some suggestions:

the OP code was

/* skip LF/CR/TAB/SP */
if (buf[0] == '\n' || buf[0] == ' ' || buf[0] == '\r' ||
buf[0]
== '\t')


I would change this line, extra spaces deleted:

why remove the space, is that to reduce clarity or just for posting
purposes?
if (buf[0]=='\n'||buf[0]==' '||buf[0]=='\r'||buf[0]=='\t')

how is this different from the OP's code?
To this, to specifically catch an ASCII carriage return and newline:
if buf[0]==0x0A||buf[0]==0x0D||buf[0]==' '||buf[0]=='\t')

why? How do you know he's using ASCII? Your code is *less* clear
than the original! Why don't you replace ' ' and \t with hex values?
<rant> they were writing programming guides in '50's explaining why
this was a bad idea! <end rant>

ok, I exagerate... a little.
Or, to this:
if (strtok(buf,"\x0D\x0A\t ")==NULL)

or strchr()

<snip>

--
Nick Keighley

The Elements of Programming Style (Paperback)
by Brian W. Kernighan, P. J. Plauger

ok so it was 1978... only 30 years ago
 
R

Rod Pemberton

Nick Keighley said:
Rod said:
Some suggestions:

the OP code was

/* skip LF/CR/TAB/SP */
if (buf[0] == '\n' || buf[0] == ' ' || buf[0] == '\r' ||
buf[0]
== '\t')
I would change this line, extra spaces deleted:

why remove the space, is that to reduce clarity or just for posting
purposes?

I was just letting him know I had removed the spaces and he needed to locate
the same line in his program. Nothing more.
if (buf[0]=='\n'||buf[0]==' '||buf[0]=='\r'||buf[0]=='\t')

how is this different from the OP's code?

It isn't. It's his line. It's the line he needs to locate, with spaces, to
implement the following suggestion.
To this, to specifically catch an ASCII carriage return and newline:
if buf[0]==0x0A||buf[0]==0x0D||buf[0]==' '||buf[0]=='\t')

why?

Because '\r' and '\n' map to environment specific values. Those values may
not match his character set creating an unexpected result. '\n' can map to
many things. For Windows and DOS machines using ASCII, it usually maps to
0x0D 0x0A. For Linux, Unix, Posix using ASCII, it usually maps to 0x0A.
For Macintoshes using ASCII, it maps to 0x0D. For IBM mainframes using
EBCDIC, it maps to 0x15.
How do you know he's using ASCII?

I don't. But, to show him how to correctly code for the hexadecimal
sequences, I used ASCII as noted.
Your code is *less* clear
than the original!

Yes, but it corrects a common programming error: trapping C's value for '\r'
or '\n' instead of the character generated by the keyboard.
Why don't you replace ' ' and \t with hex values?

Because they don't cause problems as noted above.
<rant> they were writing programming guides in '50's explaining why
this was a bad idea! <end rant>

Does the code created by following the style guide work correctly for a
specific environment? Or, does it generate errors?
or strchr()

strchr() will only allow him to check for one char at a time. strtok() will
do all at once. He'll need to test to see if it's faster or slower than the
multiple if's.



Rod Pemberton
 
J

Jordan Abel

Nick Keighley said:
Rod said:
Hello, Rod!
Sorry I made typo in first post, right definition of "cmdLineEntry_t" is:

Some suggestions:

the OP code was

/* skip LF/CR/TAB/SP */
if (buf[0] == '\n' || buf[0] == ' ' || buf[0] == '\r' ||
buf[0]
== '\t')
I would change this line, extra spaces deleted:

why remove the space, is that to reduce clarity or just for posting
purposes?

I was just letting him know I had removed the spaces and he needed to locate
the same line in his program. Nothing more.
if (buf[0]=='\n'||buf[0]==' '||buf[0]=='\r'||buf[0]=='\t')

how is this different from the OP's code?

It isn't. It's his line. It's the line he needs to locate, with spaces, to
implement the following suggestion.
To this, to specifically catch an ASCII carriage return and newline:
if buf[0]==0x0A||buf[0]==0x0D||buf[0]==' '||buf[0]=='\t')

why?

Because '\r' and '\n' map to environment specific values. Those values may
not match his character set creating an unexpected result. '\n' can map to
many things. For Windows and DOS machines using ASCII, it usually maps to
0x0D 0x0A.

Yes, on text file output. No, anywhere else. '\n' does not map to a pair
of two character values. It may be returned by getchar when getchar sees
those two values, but nowhere else.
For Linux, Unix, Posix using ASCII, it usually maps to 0x0A.
For Macintoshes using ASCII, it maps to 0x0D.

I doubt that [other than reading/writing to files opened in text mode as
noted above.]
For IBM mainframes using EBCDIC, it maps to 0x15.

Bullshit, as noted below.
I don't. But, to show him how to correctly code for the hexadecimal
sequences, I used ASCII as noted.


Yes, but it corrects a common programming error: trapping C's value for '\r'
or '\n' instead of the character generated by the keyboard.


Because they don't cause problems as noted above.

They do on "IBM mainframes using EBCDIC".
Does the code created by following the style guide work correctly for a
specific environment? Or, does it generate errors?


strchr() will only allow him to check for one char at a time. strtok() will
do all at once. He'll need to test to see if it's faster or slower than the
multiple if's.

strpbrk(), then. strtok is evil for other reasons.




note: on ANY ascii-based system, \r is 13 and \n is 10. NO MATTER HOW
the system represents linebreaks in text files or as a keyboard code.

Also - reading from stdin - whenever the user presses enter, that will
appear to getchar() or fgets() or whatever else is used to read it as
'\n', regardless of whether the enter key actually sends 0x0D or 42 or
396.
 
B

Barry Schwarz

Roman Mashak said:
Hello, Rod!
Sorry I made typo in first post, right definition of "cmdLineEntry_t" is:

/* define command line: <command> <param1> <param2> ... <paramN> */
typedef struct cmdLineEntry_s {
#define MAX_NAME 20
char command[MAX_NAME];
#define MAX_ARGS 10
char *params[MAX_ARGS];
unsigned int params_num;
handler_ptr_t cmd_handler;
} cmdLineEntry_t;

i.e. params is array of pointers to char.

Some suggestions:

I would change this line, extra spaces deleted:
if (buf[0]=='\n'||buf[0]==' '||buf[0]=='\r'||buf[0]=='\t')

To this, to specifically catch an ASCII carriage return and newline:
if buf[0]==0x0A||buf[0]==0x0D||buf[0]==' '||buf[0]=='\t')

Why be inconsistent? Use 0x20 for ' ' and 0x09 for '\t'

Why assume the program is executed on an ASCII system? \n and \r are
guaranteed to work on all systems.



Remove del for email
 
R

RSoIsCaIrLiIoA

; nasmw -f obj this_file.asm
; bcc32 file.c this.obj

section _DATA public align=4 class=DATA use32

extern _isspace
global _popola

; global _main

section _TEXT public align=1 class=CODE use32

; int popola(char** v, char* buf, int limit)
; s=0j, 4i, 8b, 12ra, 16@v, 20@buf, 24@limit
_popola:
push ebx
push esi
push edi
%define @v esp+16
%define @buf esp+20
%define @limit esp+24
xor edi, edi
cmp dword[@v], 0
je .fn
cmp dword[@buf], 0
je .fn
cmp dword[@limit], 0
jle .fn
mov esi, [@buf]
xor ebx, ebx
.a0:
mov bl, [esi]
push ebx
call _isspace
add esp, 4
cmp eax, 0
je .a1
inc esi
jmp short .a0
.a1:
cmp ebx, 0
je .fn
cmp edi, [@limit]
jne .a2
inc edi
jmp short .fn
.a2:
mov eax, [@v]
mov dword[eax+4*edi], esi
inc edi
.a3:
mov bl, [esi]
cmp ebx, 0
je .a4
push ebx
call _isspace
add esp, 4
cmp eax, 0
jne .a4
inc esi
jmp short .a3
.a4:
cmp ebx, 0
je .fn
mov byte[esi], 0
inc esi
jmp short .a0

.fn:
mov eax, edi
%undef @v
%undef @buf
%undef @limit
pop edi
pop esi
pop ebx
ret


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define UC unsigned char
#define U unsigned

static const char *pc = "CLI[\"vexit\" to end]> ";

struct you{
char* name;
char* pointer;
unsigned npar;
struct you* prev;
};

struct you *last=0;

int popola(char** v, char* buf, int limit);


int
inserisci(const char* name, char* pointer, U par)
{struct you *tm;
char *tmp;
unsigned sz;
///////////////////
if( name==0 || (sz=strlen(name))==0 )
return 0;
if( (tm =malloc(sizeof(struct you)))==0 )
return 0;
if( (tmp=malloc(sz+2))==0 )
{free(tm); return 0;}
tm->name=tmp; strcpy(tm->name, name);
tm->pointer= pointer; tm->npar=par;
tm->prev=last; last=tm;
return 1;
}

void free_list(void)
{struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
free(v->name); free(v);
}
last=0;
}


int show(void){puts("cliShow() stub");return 0;}
int version(void){puts("cliVersion() stub");return 0;}
int help(void){puts("cliHelp() stub");return 0;}
int port(void){puts("cliPort() stub"); return 0;}
void vexit(void)
{puts("cliExit() stub");
free_list();
exit(0);
}

void add(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1+aa2);
}

void sub(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1-aa2);
}


int main(void)
{char buf[BUFSIZ] = {0}, *a[32];
struct you *p;
int cv;
/////////////////////////////////
inserisci("show",(char*) show, 0);
inserisci("version", (char*) version, 0);
inserisci("help", (char*) help, 0);
inserisci("port", (char*) port, 0);
inserisci("vexit",(char*) vexit, 0);
inserisci("add",(char*) add, 2);
inserisci("sub",(char*) sub, 2);

la:;
while (1)
{printf("%s", pc); fflush(stdout);
if( fgets(buf, BUFSIZ, stdin)!=0 )
{cv=popola(a, buf, 7);
if(cv<=0) goto la;
else --cv;
for(p=last; p ;p=p->prev)
if(strcmp(p->name, a[0])==0)
{if(p->npar!=(U)cv) goto la;
switch(p->npar)
{case 0:
( (void (*)(void))(p->pointer) )( );
break;
case 1:
( (void (*)(char*))(p->pointer) )(a[1]);
break;
case 2:
( (void (*)(char*, char*))(p->pointer) )
(a[1], a[2]);
break;
case 3:
( (void (*)(char*, char*, char*))(p->pointer) )
(a[1], a[2], a[3]);
break;
case 4:
( (void (*)(char*, char*, char*, char*) )
(p->pointer) ) (a[1], a[2], a[3], a[4]);
break;
case 5:
( (void (*)(char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5]);
break;
case 6:
( (void (*)(char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6]);
break;
case 7:
( (void (*)(char*, char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
break;
default:
break;
}
}
}
}
return 0;
}
 
R

RSoIsCaIrLiIoA

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define UC unsigned char
#define U unsigned

static const char *pc = "CLI[\"vexit\" to end]> ";

struct you{
char* name;
char* pointer;
char* descrizione;
unsigned npar;
struct you* prev;
};

struct you *last=0;

int popola(char** v, char* buf, int limit);


int
inserisci(const char* name, char* pointer, U par, char*
descrizione)
{struct you *tm;
char *tmp;
unsigned sz;
///////////////////
if( name==0 || (sz=strlen(name))==0 )
return 0;
if( (tm =malloc(sizeof(struct you)))==0 )
return 0;
if( (tmp=malloc(sz+2))==0 )
{free(tm); return 0;}
tm->name=tmp; strcpy(tm->name, name);
tm->pointer= pointer; tm->npar=par;
tm->prev=last; last=tm;
tm->descrizione = descrizione;
return 1;
}

void free_list(void)
{struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
free(v->name); free(v);
}
last=0;
}


void show(void){puts("cliShow() stub"); }
void version(void){puts("cliVersion() stub");}
void help(void)
{U i;
struct you *p=last, *v;
puts("Comandi(parametri)");
while(1) {if(p==0) break;
v=p; p=p->prev;
printf("%s(%u): %s\n",
v->name, v->npar, v->descrizione);
}
}

void port(void){puts("cliPort() stub");}
void vexit(void)
{puts("cliExit() stub");
free_list();
exit(0);
}

void add(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1+aa2);
}

void sub(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1-aa2);
}


int main(void)
{char buf[BUFSIZ] = {0}, *a[32];
struct you *p;
int cv;
/////////////////////////////////
inserisci("show",(char*) show, 0, "mostra etc");
inserisci("version", (char*) version, 0, "mostra versione");
inserisci("help", (char*) help, 0, "help");
inserisci("h", (char*) help, 0, "help");
inserisci("-h", (char*) help, 0, "help");
inserisci("port", (char*) port, 0, "port");
inserisci("vexit",(char*) vexit, 0, "esce dal sistema");
inserisci("add",(char*) add, 2, "somma due numeri");
inserisci("sub",(char*) sub, 2, "fa differenza di due numeri");

la:;
while (1)
{printf("%s", pc); fflush(stdout);
if( fgets(buf, BUFSIZ, stdin)!=0 )
{cv=popola(a, buf, 7);
if(cv<=0) goto la;
else --cv;
for(p=last; p ;p=p->prev)
if(strcmp(p->name, a[0])==0)
{if(p->npar!=(U)cv) goto la;
switch(p->npar)
{case 0:
( (void (*)(void))(p->pointer) )( );
break;
case 1:
( (void (*)(char*))(p->pointer) )(a[1]);
break;
case 2:
( (void (*)(char*, char*))(p->pointer) )
(a[1], a[2]);
break;
case 3:
( (void (*)(char*, char*, char*))(p->pointer) )
(a[1], a[2], a[3]);
break;
case 4:
( (void (*)(char*, char*, char*, char*) )
(p->pointer) ) (a[1], a[2], a[3], a[4]);
break;
case 5:
( (void (*)(char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5]);
break;
case 6:
( (void (*)(char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6]);
break;
case 7:
( (void (*)(char*, char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
break;
default:
break;
}
}
}
}
return 0;
}
 
R

RSoIsCaIrLiIoA

you are so killfiled its not true.
Mark McIntyre

what does it means?
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

this above means do you see any error?
 
R

RSoIsCaIrLiIoA

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define UC unsigned char
#define U unsigned

static const char *pc = "CLI[\"vexit\" to end]> ";

struct you{
char* name;
char* pointer;
char* descrizione;
unsigned npar;
struct you* prev;
};

struct you *last=0;

/*limit sono i parametri + 1 (nome della funzione) */
int popola(char** v, char* buf, int limit);

void skip_line(FILE* pf)
{int c; while( (c=fgetc(pf))!='\n' && c!=EOF );}

int
inserisci(const char* name, char* pointer, U par, char*
descrizione)
{struct you *tm;
char *tmp;
unsigned sz;
///////////////////
if( name==0 || (sz=strlen(name))==0 )
return 0;
if( (tm =malloc(sizeof(struct you)))==0 )
return 0;
if( (tmp=malloc(sz+2))==0 )
{free(tm); return 0;}
tm->name=tmp; strcpy(tm->name, name);
tm->pointer= pointer; tm->npar=par;
tm->prev=last; last=tm;
tm->descrizione = descrizione;
return 1;
}

void free_list(void)
{struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
free(v->name); free(v);
}
last=0;
}


void
insert_f(char* name, char* pointer, char* par, char* descrizione)
{char *pn=0;
U paru=0;
int k;

k=sscanf(pointer, "%p", &pn);
if(k!=1) {printf("parametro \"pointer\" non accettato\n"); return;}
k=sscanf(par , "%u", &paru);
if(k!=1) {printf("parametro \"parametri\" non accettato\n"); return;}
k=inserisci(name, pn, paru, descrizione);
if(k!=1){printf("problemi di memoria\n"); return;}
}

void show(void){puts("cliShow() stub"); }
void version(void){puts("cliVersion() stub");}
void help(void)
{U i;
struct you *p=last, *v;
puts("Comandi(parametri)");
while(1) {if(p==0) break;
v=p; p=p->prev;
printf("%p %s(%u): %s\n",
(void*)(v->pointer), v->name, v->npar, v->descrizione);
}
}

void port(void){puts("cliPort() stub");}
void vexit(void)
{puts("cliExit() stub");
free_list();
exit(0);
}

void add(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1+aa2);
}

void sub(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1-aa2);
}


int main(void)
{char buf[BUFSIZ] = {0}, *a[32];
struct you *p;
int cv, led;
/////////////////////////////////
inserisci("show",(char*) show, 0, "mostra etc");
inserisci("version", (char*) version, 0, "mostra versione");
inserisci("help", (char*) help, 0, "help");
inserisci("h", (char*) help, 0, "help");
inserisci("-h", (char*) help, 0, "help");
inserisci("port", (char*) port, 0, "port");
inserisci("vexit",(char*) vexit, 0, "esce dal sistema");
inserisci("add",(char*) add, 2, "somma due numeri");
inserisci("sub",(char*) sub, 2, "fa differenza di due numeri");
inserisci("inserisci",(char*) insert_f, 4,
"inserisce una funzione:\ninserisci(name, pointer_to_fun,
parametri, descrizione)");

la:;
while (1)
{printf("%s", pc); fflush(stdout);
buf[BUFSIZ-2]=0; /* massimo BUFSIZ-2 chars */
if( fgets(buf, BUFSIZ, stdin )!=0 )
{if(buf[BUFSIZ-2]!=0)
{printf("Linea troppo lunga\n");
if(feof(stdin)) vexit();
skip_line(stdin);
if(feof(stdin)) vexit();
goto la;
}
cv=popola(a, buf, 8);
if(cv<=0 || cv>8) goto la1;
else --cv;
for(p=last, led=0; led==0 && p!=0 ;p=p->prev)
{if(strcmp(p->name, a[0])==0)
{if(p->npar!=(U)cv)
{la1:; printf("Parametri non corretti\n"); goto la;}
switch(p->npar)
{case 0:
( (void (*)(void))(p->pointer) )( );
led=1;
break;
case 1:
( (void (*)(char*))(p->pointer) )(a[1]);
led=1;
break;
case 2:
( (void (*)(char*, char*))(p->pointer) )
(a[1], a[2]);
led=1;
break;
case 3:
( (void (*)(char*, char*, char*))(p->pointer) )
(a[1], a[2], a[3]);
led=1;
break;
case 4:
( (void (*)(char*, char*, char*, char*) )
(p->pointer) ) (a[1], a[2], a[3], a[4]);
led=1;
break;
case 5:
( (void (*)(char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5]);
led=1;
break;
case 6:
( (void (*)(char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6]);
led=1;
break;
case 7:
( (void (*)(char*, char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
led=1;
break;
default:
break;
}//end switch
}//if
}//for
if(led!=1) printf("funzione non presente\n");
}// if fgets
if(feof(stdin)) vexit();
}//while
return 0;
}

----------------

; nasmw -f obj this_file.asm
; bcc32 this_file.obj

section _DATA public align=4 class=DATA use32

extern _isspace
global _popola

; global _main

section _TEXT public align=1 class=CODE use32

; int popola(char** v, char* buf, int limit)
; s=0j, 4i, 8b, 12ra, 16@v, 20@buf, 24@limit
_popola:
push ebx
push esi
push edi
%define @v esp+16
%define @buf esp+20
%define @limit esp+24
xor edi, edi
cmp dword[@v], 0
je .fn
cmp dword[@buf], 0
je .fn
cmp dword[@limit], 0
jle .fn
mov esi, [@buf]
xor ebx, ebx
..a0:
mov bl, [esi]
push ebx
call _isspace
add esp, 4
cmp eax, 0
je .a1
inc esi
jmp short .a0
..a1:
cmp ebx, 0
je .fn
cmp edi, [@limit]
jne .a2
mov edi, -1
jmp short .fn
..a2:
mov eax, [@v]
mov dword[eax+4*edi], esi
inc edi
..a3:
mov bl, [esi]
cmp ebx, 0
je .a4
push ebx
call _isspace
add esp, 4
cmp eax, 0
jne .a4
inc esi
jmp short .a3
..a4:
cmp ebx, 0
je .fn
mov byte[esi], 0
inc esi
jmp short .a0

..fn:
mov eax, edi
%undef @v
%undef @buf
%undef @limit
pop edi
pop esi
pop ebx
ret
 
R

RSoIsCaIrLiIoA

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>


#define UC unsigned char
#define U unsigned

#define BUFSIZ_ BUFSIZ

static const char *pc = "CLI[\"vexit\" to end]> ";

struct you{
char* name;
char* pointer;
char* descrizione;
unsigned npar;
struct you* prev;
};

struct you *last=0;

/*limit sono i parametri + 1 (nome della funzione) */
int popola(char** v, char* buf, int limit);

void skip_line(FILE* pf)
{int c; while( (c=fgetc(pf))!='\n' && c!=EOF );}

int cerca(const char* name, U par)
{U i;
struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
if( v->npar==par && strcmp(v->name, name)==0 )
return 1;
}
return 0;
}

int
inserisci(const char* name, char* pointer, U par, char*
descrizione)
{struct you *tm;
char *tmp;
unsigned sz;
///////////////////
if( name==0 || (sz=strlen(name))==0 )
return 0;
if( cerca(name, par)==1 )
return 0;
if( (tm =malloc(sizeof(struct you)))==0 )
return 0;
if( (tmp=malloc(sz+2))==0 )
{free(tm); return 0;}
tm->name=tmp; strcpy(tm->name, name);
tm->pointer= pointer; tm->npar=par;
tm->prev=last; last=tm;
tm->descrizione = descrizione;
return 1;
}

void free_list(void)
{struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
free(v->name); free(v);
}
last=0;
}


void
insert_f(char* name, char* pointer, char* par, char* descrizione)
{char *pn=0;
U paru=0;
int k;

k=sscanf(pointer, "%p", &pn);
if(k!=1) {printf("parametro \"pointer\" non accettato\n"); return;}
k=sscanf(par , "%u", &paru);
if(k!=1) {printf("parametro \"parametri\" non accettato\n"); return;}
k=inserisci(name, pn, paru, descrizione);
if(k!=1){printf("problemi di memoria o nome gia\' scelto\n");
return;
}
}

void show(void){puts("cliShow() stub"); }
void version(void){puts("cliVersion() stub");}
void help(void)
{U i;
struct you *p=last, *v;
puts("Comandi(parametri)");
while(1) {if(p==0) break;
v=p; p=p->prev;
printf("%p %s(%u): %s\n",
(void*)(v->pointer), v->name, v->npar, v->descrizione);
}
}

void port(void){puts("cliPort() stub");}
void vexit(void)
{puts("cliExit() stub");
free_list();
exit(0);
}

void add(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1+aa2);
}

void sub(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1-aa2);
}


int main(void)
{char buf[BUFSIZ_] = {0}, *a[32];
struct you *p;
int cv, led;
/////////////////////////////////
inserisci("show",(char*) show, 0, "mostra etc");
inserisci("version", (char*) version, 0, "mostra versione");
inserisci("help", (char*) help, 0, "help");
inserisci("h", (char*) help, 0, "help");
inserisci("-h", (char*) help, 0, "help");
inserisci("port", (char*) port, 0, "port");
inserisci("vexit",(char*) vexit, 0, "esce dal sistema");
inserisci("add",(char*) add, 2, "somma due numeri");
inserisci("sub",(char*) sub, 2, "fa differenza di due numeri");
inserisci("inserisci",(char*) insert_f, 4,
"inserisce una funzione:\ninserisci(name, pointer_to_fun,
parametri, descrizione)");

la:;
while (1)
{printf("%s", pc); fflush(stdout);
buf[BUFSIZ_-2]=0; /* massimo BUFSIZ_-1 chars */
if( fgets(buf, BUFSIZ_, stdin )!=0 )
{if(buf[BUFSIZ_-2]!=0 && buf[BUFSIZ_-2]!='\n')
{printf("Linea troppo lunga\n");
if(feof(stdin)) vexit();
skip_line(stdin);
if(feof(stdin)) vexit();
goto la;
}
cv=popola(a, buf, 8);
if(cv<=0 || cv>8) goto la1;
else --cv;
for(p=last, led=0; led==0 && p!=0 ;p=p->prev)
{if(strcmp(p->name, a[0])==0)
{if(p->npar!=(U)cv)
{la1:; printf("Parametri non corretti\n"); goto la;}
switch(p->npar)
{case 0:
( (void (*)(void))(p->pointer) )( );
led=1;
break;
case 1:
( (void (*)(char*))(p->pointer) )(a[1]);
led=1;
break;
case 2:
( (void (*)(char*, char*))(p->pointer) )
(a[1], a[2]);
led=1;
break;
case 3:
( (void (*)(char*, char*, char*))(p->pointer) )
(a[1], a[2], a[3]);
led=1;
break;
case 4:
( (void (*)(char*, char*, char*, char*) )
(p->pointer) ) (a[1], a[2], a[3], a[4]);
led=1;
break;
case 5:
( (void (*)(char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5]);
led=1;
break;
case 6:
( (void (*)(char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6]);
led=1;
break;
case 7:
( (void (*)(char*, char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
led=1;
break;
default:
break;
}//end switch
}//if
}//for
if(led!=1) printf("funzione non presente\n");
}// if fgets
if(feof(stdin)) vexit();
}//while
return 0;
}
 
D

Dave Thompson

To this, to specifically catch an ASCII carriage return and newline:
if buf[0]==0x0A||buf[0]==0x0D||buf[0]==' '||buf[0]=='\t')

why?

Because '\r' and '\n' map to environment specific values. Those values may
not match his character set creating an unexpected result. '\n' can map to
many things. For Windows and DOS machines using ASCII, it usually maps to
0x0D 0x0A. For Linux, Unix, Posix using ASCII, it usually maps to 0x0A.
For Macintoshes using ASCII, it maps to 0x0D. For IBM mainframes using
EBCDIC, it maps to 0x15.
Well, they certainly match the platform's character set (or more
precisely code), that's the purpose of the mapping. I think you're
saying his _data_ may not match his platform. Which is possible,
although it is possible in so many ways it's not clear to me that
fixing only this one is worth it.
Because they don't cause problems as noted above.
They are different and do cause this problem for EBCDIC vs ASCII,
whereas CR by coincidence is 0x0D in both and does not.
strchr() will only allow him to check for one char at a time. strtok() will
do all at once. He'll need to test to see if it's faster or slower than the
multiple if's.
And strspn() does it all at once without modifying the data, if that's
an issue, although in this (OP) case he definitely has a modifiable
buffer and AFAICS doesn't need the data afterwards.

Agree about testing, although in this case I very much doubt the
difference is even detectable much less significant.

- David.Thompson1 at worldnet.att.net
 
R

RSoIsCaIrLiIoA

do you like my CLI (Command Line Interface)? :))

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>


#define UC unsigned char
#define U unsigned

#define BUFSIZ_ BUFSIZ

static const char *pc_pro = "CLI[\"vexit\" to end]> ";

struct you{
char* name;
char* pointer;
char* descrizione;
unsigned npar;
struct you* prev;
};

struct you *last=0;

/*limit sono i parametri + 1 (nome della funzione) */
int popola(char** v, char* buf, int limit);

int skip_line(FILE* pf)
{int c; while( (c=fgetc(pf))!='\n' && c!=EOF ); return c;}

int cmp_from_now(char* a0, char* a1)
{int i;
for( i=0; a0!=0 && a0==a1 && !isspace(a0); ++i);
if( (isspace(a0)||a0==0) && (isspace(a1)||a1==0))
return 1;
else return 0;
}

int cerca(const char* name, U par)
{U i;
struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
if( v->npar==par && strcmp(v->name, name)==0 )
return 1;
}
return 0;
}

int
inserisci(const char* name, char* pointer, U par, char*
descrizione)
{struct you *tm;
char *tmp;
unsigned sz;
///////////////////
if( name==0 || (sz=strlen(name))==0 )
return 0;
if( cerca(name, par)==1 )
return 0;
if( (tm =malloc(sizeof(struct you)))==0 )
return 0;
if( (tmp=malloc(sz+2))==0 )
{free(tm); return 0;}
tm->name=tmp; strcpy(tm->name, name);
tm->pointer= pointer; tm->npar=par;
tm->prev=last; last=tm;
tm->descrizione = descrizione;
return 1;
}

void free_list(void)
{struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
free(v->name); free(v);
}
last=0;
}


void
insert_f(char* name, char* pointer, char* par, char* descrizione)
{char *pn=0;
U paru=0;
int k;

k=sscanf(pointer, "%p", &pn);
if(k!=1) {printf("parametro \"pointer\" non accettato\n"); return;}
k=sscanf(par , "%u", &paru);
if(k!=1) {printf("parametro \"parametri\" non accettato\n"); return;}
k=inserisci(name, pn, paru, descrizione);
if(k!=1){printf("problemi di memoria\n"); return;}
}


void sys(char* a1){if( system(a1)!=0 ) printf("\a"); }
void show(void){puts("cliShow() stub"); }
void version(void){puts("cliVersion() stub");}
void help(void)
{U i;
struct you *p=last, *v;
puts("Comandi(parametri)");
while(1) {if(p==0) break;
v=p; p=p->prev;
printf("%p %s(%u): %s\n",
(void*)(v->pointer), v->name, v->npar, v->descrizione);
}
}

void port(void){puts("cliPort() stub");}
void vexit(void)
{puts("cliExit() stub");
free_list();
exit(0);
}

void add(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1+aa2);
}

void sub(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1-aa2);
}


int main(void)
{char buf[BUFSIZ_] = {0}, *a[32], *pc;
struct you *p;
int cv, led;
/////////////////////////////////
inserisci("sys",(char*) sys, 1, "chiama sistema");
inserisci("show",(char*) show, 0, "mostra etc");
inserisci("version", (char*) version, 0, "mostra versione");
inserisci("help", (char*) help, 0, "help");
inserisci("h", (char*) help, 0, "help");
inserisci("-h", (char*) help, 0, "help");
inserisci("port", (char*) port, 0, "port");
inserisci("vexit",(char*) vexit, 0, "esce dal sistema");
inserisci("add",(char*) add, 2, "somma due numeri");
inserisci("sub",(char*) sub, 2, "fa differenza di due numeri");
inserisci("inserisci",(char*) insert_f, 4,
"inserisce una funzione:\ninserisci(name, pointer_to_fun,
parametri, descrizione)");

la:;
while (1)
{printf("%s", pc_pro); fflush(stdout);
buf[BUFSIZ_-2]=0; /* massimo BUFSIZ_-1 chars */
if( fgets(buf, BUFSIZ_, stdin )!=0 )
{if(buf[BUFSIZ_-2]!=0 && buf[BUFSIZ_-2]!='\n')
{printf("Linea troppo lunga\n");
if(feof(stdin)) vexit();
if( skip_line(stdin) == EOF );
vexit();
goto la;
}
for(pc=buf; isspace(*pc); ++pc);
if( cmp_from_now(pc, "sys")==1 )
{if(pc[3]==0) sys("\n");
else sys(pc+4);
goto la;
}
cv=popola(a, buf, 8);
if(cv<=0 || cv>8) goto la1;
else --cv;
for(p=last, led=0; led==0 && p!=0 ;p=p->prev)
{if(strcmp(p->name, a[0])==0)
{if(p->npar!=(U)cv)
{la1:; printf("Parametri non corretti\n"); goto la;}
switch(p->npar)
{case 0:
( (void (*)(void))(p->pointer) )( );
led=1;
break;
case 1:
( (void (*)(char*))(p->pointer) )(a[1]);
led=1;
break;
case 2:
( (void (*)(char*, char*))(p->pointer) )
(a[1], a[2]);
led=1;
break;
case 3:
( (void (*)(char*, char*, char*))(p->pointer) )
(a[1], a[2], a[3]);
led=1;
break;
case 4:
( (void (*)(char*, char*, char*, char*) )
(p->pointer) ) (a[1], a[2], a[3], a[4]);
led=1;
break;
case 5:
( (void (*)(char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5]);
led=1;
break;
case 6:
( (void (*)(char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6]);
led=1;
break;
case 7:
( (void (*)(char*, char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
led=1;
break;
default:
break;
}//end switch
}//if
}//for
if(led!=1) printf("funzione non presente\n");
}// if fgets
if(feof(stdin)) vexit();
}//while
return 0;
}
 
R

RSoIsCaIrLiIoA

do you like my CLI (Command Line Interface)? :))

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main(void)
{char buf[BUFSIZ_] = {0}, *a[32], *pc;
struct you *p;
int cv, led;
/////////////////////////////////
inserisci("sys",(char*) sys, 1, "chiama sistema");
inserisci("show",(char*) show, 0, "mostra etc");
inserisci("version", (char*) version, 0, "mostra versione");
inserisci("help", (char*) help, 0, "help");
inserisci("h", (char*) help, 0, "help");
inserisci("-h", (char*) help, 0, "help");
inserisci("port", (char*) port, 0, "port");
inserisci("vexit",(char*) vexit, 0, "esce dal sistema");
inserisci("add",(char*) add, 2, "somma due numeri");
inserisci("sub",(char*) sub, 2, "fa differenza di due numeri");
inserisci("inserisci",(char*) insert_f, 4,
"inserisce una funzione:\ninserisci(name, pointer_to_fun,
parametri, descrizione)");

la:;
while (1)
{printf("%s", pc_pro); fflush(stdout);
buf[BUFSIZ_-2]=0; /* massimo BUFSIZ_-1 chars */
if( fgets(buf, BUFSIZ_, stdin )!=0 )
{if(buf[BUFSIZ_-2]!=0 && buf[BUFSIZ_-2]!='\n')
{printf("Linea troppo lunga\n");
if(feof(stdin)) vexit();
if( skip_line(stdin) == EOF );
vexit();
goto la;
}
for(pc=buf; isspace(*pc); ++pc);
if( cmp_from_now(pc, "sys")==1 )
{if(pc[3]==0) sys("\n");
else sys(pc+4);

if(feof(stdin)) vexit();
goto la;
}
cv=popola(a, buf, 8);
if(cv<=0 || cv>8) goto la1;
else --cv;
for(p=last, led=0; led==0 && p!=0 ;p=p->prev)
{if(strcmp(p->name, a[0])==0)
{if(p->npar!=(U)cv)
{la1:; printf("Parametri non corretti\n"); goto la;}
switch(p->npar)
{case 0:
( (void (*)(void))(p->pointer) )( );
led=1;
break;
case 1:
( (void (*)(char*))(p->pointer) )(a[1]);
led=1;
break;
case 2:
( (void (*)(char*, char*))(p->pointer) )
(a[1], a[2]);
led=1;
break;
case 3:
( (void (*)(char*, char*, char*))(p->pointer) )
(a[1], a[2], a[3]);
led=1;
break;
case 4:
( (void (*)(char*, char*, char*, char*) )
(p->pointer) ) (a[1], a[2], a[3], a[4]);
led=1;
break;
case 5:
( (void (*)(char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5]);
led=1;
break;
case 6:
( (void (*)(char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6]);
led=1;
break;
case 7:
( (void (*)(char*, char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
led=1;
break;
default:
break;
}//end switch
}//if
}//for
if(led!=1) printf("funzione non presente\n");
}// if fgets
if(feof(stdin)) vexit();
}//while
return 0;
}
 
R

RSoIsCaIrLiIoA

Do you like my Command Line Interface?
your is better than this? Why?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define UC unsigned char
#define U unsigned

#define BUFSIZ_ BUFSIZ

static const char *pc_pro = "CLI[\"vexit\" to end]> ";

struct you{
char* name;
char* pointer;
char* descrizione;
unsigned npar;
struct you* prev;
};

struct you *last=0;

/*limit sono i parametri + 1 (nome della funzione) */
int popola(char** v, char* buf, int limit);

int skip_line(FILE* pf)
{int c; while( (c=fgetc(pf))!='\n' && c!=EOF ); return c;}

int cmp_from_now(char* a0, char* a1)
{int i;
for( i=0; a0!=0 && a0==a1 && !isspace(a0); ++i);
if( (isspace(a0)||a0==0) && (isspace(a1)||a1==0))
return 1;
else return 0;
}

int cerca(const char* name, U par)
{U i;
struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
if( v->npar==par && strcmp(v->name, name)==0 )
return 1;
}
return 0;
}

int
inserisci(const char* name, char* pointer, U par, char*
descrizione)
{struct you *tm;
char *tmp;
unsigned sz;
///////////////////
if( name==0 || (sz=strlen(name))==0 )
return 0;
if( cerca(name, par)==1 )
return 0;
if( (tm =malloc(sizeof(struct you)))==0 )
return 0;
if( (tmp=malloc(sz+2))==0 )
{free(tm); return 0;}
tm->name=tmp; strcpy(tm->name, name);
tm->pointer= pointer; tm->npar=par;
tm->prev=last; last=tm;
tm->descrizione = descrizione;
return 1;
}

void free_list(void)
{struct you *p=last, *v;
while(1) {if(p==0) break;
v=p; p=p->prev;
free(v->name); free(v);
}
last=0;
}


void
insert_f(char* name, char* pointer, char* par, char* descrizione)
{char *pn=0;
U paru=0;
int k;

k=sscanf(pointer, "%p", &pn);
if(k!=1) {printf("parametro \"pointer\" non accettato\n"); return;}
k=sscanf(par , "%u", &paru);
if(k!=1) {printf("parametro \"parametri\" non accettato\n"); return;}
k=inserisci(name, pn, paru, descrizione);
if(k!=1){printf("problemi di memoria\n"); return;}
}


void sys(char* a1){if( system(a1)!=0 ) printf("\a"); }
void show(void){puts("cliShow() stub"); }
void version(void){puts("cliVersion() stub");}
void help(void)
{U i;
struct you *p=last, *v;
puts("Comandi(parametri)");
while(1) {if(p==0) break;
v=p; p=p->prev;
printf("%p %s(%u): %s\n",
(void*)(v->pointer), v->name, v->npar, v->descrizione);
}
}

void port(void){puts("cliPort() stub");}
void vexit(void)
{puts("cliExit() stub");
free_list();
exit(0);
}

void add(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1+aa2);
}

void sub(char* a1, char* a2)
{int aa1=0, aa2=0;
sscanf(a1, "%d", &aa1);
sscanf(a2, "%d", &aa2);
printf("%d\n", aa1-aa2);
}


int main(void)
{char buf[BUFSIZ_] = {0}, *a[32], *pc;
struct you *p;
int cv, led;
/////////////////////////////////
inserisci("sys",(char*) sys, 1, "chiama sistema");
inserisci("show",(char*) show, 0, "mostra etc");
inserisci("version", (char*) version, 0, "mostra versione");
inserisci("help", (char*) help, 0, "help");
inserisci("h", (char*) help, 0, "help");
inserisci("-h", (char*) help, 0, "help");
inserisci("port", (char*) port, 0, "port");
inserisci("vexit",(char*) vexit, 0, "esce dal sistema");
inserisci("add",(char*) add, 2, "somma due numeri");
inserisci("sub",(char*) sub, 2, "fa differenza di due numeri");
inserisci("inserisci",(char*) insert_f, 4,
"inserisce una funzione:\ninserisci(name, pointer_to_fun,
parametri, descrizione)");

la0:;
while (1)
{printf("%s", pc_pro); fflush(stdout);
buf[BUFSIZ_-2]=0; /* massimo BUFSIZ_-1 chars */
if( fgets(buf, BUFSIZ_, stdin )!=0 )
{if(buf[BUFSIZ_-2]!=0 && buf[BUFSIZ_-2]!='\n')
{printf("Linea troppo lunga\n");
if(feof(stdin)) vexit();
if( skip_line(stdin) == EOF );
vexit();
goto la0;
}
for(pc=buf; isspace(*pc); ++pc);
if( cmp_from_now(pc, "sys")==1 )
{if(pc[3]==0) sys("\n");
else sys(pc+4);
goto la;
}
cv=popola(a, buf, 8);
if(cv<=0 || cv>8) goto la1;
else --cv;
for(p=last, led=0; led==0 && p!=0 ;p=p->prev)
{if(strcmp(p->name, a[0])==0)
{if(p->npar!=(U)cv)
{la1:;
printf("Parametri non corretti\n"); goto la;
}
switch(p->npar)
{case 0:
( (void (*)(void))(p->pointer) )( );
led=1;
break;
case 1:
( (void (*)(char*))(p->pointer) )(a[1]);
led=1;
break;
case 2:
( (void (*)(char*, char*))(p->pointer) )
(a[1], a[2]);
led=1;
break;
case 3:
( (void (*)(char*, char*, char*))(p->pointer) )
(a[1], a[2], a[3]);
led=1;
break;
case 4:
( (void (*)(char*, char*, char*, char*) )
(p->pointer) ) (a[1], a[2], a[3], a[4]);
led=1;
break;
case 5:
( (void (*)(char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5]);
led=1;
break;
case 6:
( (void (*)(char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6]);
led=1;
break;
case 7:
( (void (*)(char*, char*, char*, char*, char*, char*, char*))
(p->pointer) )( a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
led=1;
break;
default:
break;
}//end switch
}//if
}//for
if(led!=1) printf("funzione non presente\n");
}// if fgets
la:;
if(feof(stdin)) vexit();
}//while
return 0;
}

---------------------------

; nasmw -f obj this_file.asm
; bcc32 this_file.obj

section _DATA public align=4 class=DATA use32

extern _isspace
global _popola

; global _main

section _TEXT public align=1 class=CODE use32

; int popola(char** v, char* buf, int limit)
; s=0j, 4i, 8b, 12ra, 16@v, 20@buf, 24@limit
_popola:
push ebx
push esi
push edi
%define @v esp+16
%define @buf esp+20
%define @limit esp+24
xor edi, edi
cmp dword[@v], 0
je .fn
cmp dword[@buf], 0
je .fn
cmp dword[@limit], 0
jle .fn
mov esi, [@buf]
xor ebx, ebx
..a0:
mov bl, [esi]
push ebx
call _isspace
add esp, 4
cmp eax, 0
je .a1
inc esi
jmp short .a0
..a1:
cmp ebx, 0
je .fn
cmp edi, [@limit]
jne .a2
mov edi, -1
jmp short .fn
..a2:
mov eax, [@v]
mov dword[eax+4*edi], esi
inc edi
..a3:
mov bl, [esi]
cmp ebx, 0
je .a4
push ebx
call _isspace
add esp, 4
cmp eax, 0
jne .a4
inc esi
jmp short .a3
..a4:
cmp ebx, 0
je .fn
mov byte[esi], 0
inc esi
jmp short .a0

..fn:
mov eax, edi
%undef @v
%undef @buf
%undef @limit
pop edi
pop esi
pop ebx
ret
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top