View Single Post
Old 01-15-2018, 08:35 AM   #86
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 7,902
Default

If anybody wants a little training with the EEL string handling system (which in fact is very simple, but might be unusual, regarding the ways of other programming language, hire some example code for checking out:
Code:
@init

printf("init\n");

printf("----\n");

#st = "1234";
#su = "9876";
printf("%d: %s\n",#st,#st);
printf("%d: %s\n",#su,#su);
printf("%d: %s\n",st);
printf("%d: %s\n",su);
printf("----\n");

sn = 0;
strcpy(sn, "abcd");

sm = 1;
strcpy(sm, "ABCD");

so = #st;
sp = #su;
printf("%d: %s\n", sn, sn);
printf("%d: %s\n", sm, sm);
printf("%d: %s\n", so, so);
printf("%d: %s\n", sp, sp);
printf("%d: %s\n",  #,  #);
# = "hash";
h = #;
printf("%d: %s\n",  #,  #);
printf("%d: %s\n",  h,  h);
h = # = "hash";
printf("%d: %s\n",  #,  #);
printf("%d: %s\n",  h,  h);

printf("%d: %s\n",  #,  z=#="hash1");
printf("%d: %s\n",  #=#st,  #);
printf("%d: %s\n",  z,  z);

printf("\n-- sprintf --\n");
x = 777;
y = sprintf(x, "//%d//", 3);
printf("%d: %s   %d: %s\n", x, x, y, y);
y = sprintf(#, "//%d//", 3);
printf("%d: %s   %d: %s\n", #, #, y, y);
printf("%d: %s   %d: %s\n", x, x, y, y);
printf("%d: %s   %d: %s\n", #, #, y, y);
y = 3;
y = "three";
y1 = sprintf(y2=#, y3="//%s//", y4=y);
printf("%d: %s   %d: %s   %d: %s   %d: %s\n", y1, y1, y2, y2, y3, y3, y4, y4);


printf("\n-- += --\n");
#f = "f";
#g = "g";
#f += sn;
sm += #g;
printf("+=    %s,   %i,    %s,    %i\n", #f, #f, sm, sm);
#f = #f + sn;
#g = "123" + #f; //+"456";
printf("+     %s,   %s\n", #f, #g);

printf("\n-- Loop --\n");
strcpy(2, #st);
strcpy(3, #su);
i = 0;
loop(4,
  printf("%i: %s\n", i, i);
  i += 1;
);


printf("\n-- match --\n");

z = match ("x", "xyz");
printf ("%d\n", z);
z = match ("xyz", "xyz");
printf ("%d\n", z);

x = "x";
y = "abcdef";
z = match(x, y);
printf("%d: %s   %d: %s\n", x, x, y, y);
printf ("%d\n", z);

x = "cd";
z = match(x, y);
printf("%d: %s   %d: %s\n", x, x, y, y);
printf ("%d\n", z);
z = match(x, "%0s", y);
printf("%d: %s   %d: %s\n", x, x, y, y);
printf ("%d\n", z);


printf("\n-- file --\n");
f = fopen("c:/tmp/xxx.txt", "r");
printf("handle: %i\n", f);
  f ? (
    i = 0;
    x = 100;
    l = -1;
    while (l) (
      l = fgets(f, x);
      l ? (
        str_setlen(x, l-1);
        printf("%i: %i: %s\n", i, l, x);
      );  
      i += 1;
      x += 1;
    );  
    printf("----\n");
    x = 100;
    loop (i-1,
      l = strlen(x);
      printf("%i: %s\n", l, x);
      x += 1;
    )
  );
printf("----\n");
(I did not try the 3rd parameter of match, as I am not at all knowledgeable with RegEx, and hence the documentation is too sparse for me to comprehend.)
-Michael

Last edited by mschnell; 01-15-2018 at 10:19 PM.
mschnell is offline   Reply With Quote