Sunday, December 9, 2018

Having fun on the linux command bus

Thinking about strings I created a loadable that interfaces to the c string lib.  All interfaces the same, what, yes: argc,args.  So I just load the sharable with the consol loop, and sub system on the bus can use it, it is all linux command format.

The module has an entry point below. in the code. Very slow as frig, but exactly the same interface as just about anything. The interface never changes, c string utilities universally available.  That means, no matter who you are, or what kind of programming you do, if your codetravels on linux command bus, you are compatible.

#include <string.h>
int ItoA(int x, char* str);
int LenStr(int *argc,void * args[]) {
int i;
ItoA(strlen(char *) args[*argc + 1],args[0]);
*argc  +=2;
return(1);
}
int CatStr(int *argc,void * args[]) {
int i;
strcat(( char *) args[*argc + 1],(char *) args[*argc + 2]);
*argc  +=3;
return(1);
}

int Entry(int *argc, void * args[]) {
int argid=*argc;
else if(!strcmp(args[argid],"LenStr"))
          return(LenStr(argc,args));
else if(!strcmp(args[argid],"CatStr"))
           return(CatStr(argc,args));
return(0);
}
// putting ints to string args

#define Nums "0123456789"
int ItoA(int x, char* str) { 
char * n=Nums;
int i=0;
int k;
 while(x) {
for(k=i;k > 0;k--) str[k]=str[k-1];
k = x % 10;
str[0]= n[k];
x/=10;
i++;
}
str[i]=0;
return(k);
}

No comments: