aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Celes <celes@tecgraf.puc-rio.br>1994-08-04 13:23:29 -0300
committerWaldemar Celes <celes@tecgraf.puc-rio.br>1994-08-04 13:23:29 -0300
commit5034be66359eca9d7aea7edc1c51c71bf42f29c3 (patch)
tree66801a87a6414df92ecfa42805221345df04d5ea
parentb1e9b37883ebc3f9926f6693350a73d6cbb94b6e (diff)
downloadlua-5034be66359eca9d7aea7edc1c51c71bf42f29c3.tar.gz
lua-5034be66359eca9d7aea7edc1c51c71bf42f29c3.tar.bz2
lua-5034be66359eca9d7aea7edc1c51c71bf42f29c3.zip
Alteracao na funcao 'write" para permitir acrescentar caracteres
de espacamento, tabs, newline, etc. nos formatos. Corrigiu tambem bug do formato 'F' maiusculo.
-rw-r--r--iolib.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/iolib.c b/iolib.c
index 10d06f8c..1f411ea1 100644
--- a/iolib.c
+++ b/iolib.c
@@ -3,7 +3,7 @@
3** Input/output library to LUA 3** Input/output library to LUA
4*/ 4*/
5 5
6char *rcs_iolib="$Id: iolib.c,v 1.3 1994/03/28 15:14:02 celes Exp celes $"; 6char *rcs_iolib="$Id: iolib.c,v 1.4 1994/04/25 20:11:23 celes Exp celes $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
@@ -344,9 +344,11 @@ static char *buildformat (char *e, lua_Object o)
344 static char buffer[512]; 344 static char buffer[512];
345 static char f[80]; 345 static char f[80];
346 char *string = &buffer[255]; 346 char *string = &buffer[255];
347 char *fstart=e, *fspace;
347 char t, j='r'; 348 char t, j='r';
348 int m=0, n=0, l; 349 int m=0, n=0, l;
349 while (isspace(*e)) e++; 350 while (isspace(*e)) e++;
351 fspace = e;
350 t = *e++; 352 t = *e++;
351 if (*e == '<' || *e == '|' || *e == '>') j = *e++; 353 if (*e == '<' || *e == '|' || *e == '>') j = *e++;
352 while (isdigit(*e)) 354 while (isdigit(*e))
@@ -359,16 +361,22 @@ static char *buildformat (char *e, lua_Object o)
359 if (j == '<' || j == '|') sprintf(strchr(f,0),"-"); 361 if (j == '<' || j == '|') sprintf(strchr(f,0),"-");
360 if (m != 0) sprintf(strchr(f,0),"%d", m); 362 if (m != 0) sprintf(strchr(f,0),"%d", m);
361 if (n != 0) sprintf(strchr(f,0),".%d", n); 363 if (n != 0) sprintf(strchr(f,0),".%d", n);
362 sprintf(strchr(f,0), "%c", t); 364 switch (t)
363 switch (tolower(t))
364 { 365 {
365 case 'i': t = 'i'; 366 case 'i': case 'I': t = 'd';
367 sprintf(strchr(f,0), "%c", t);
366 sprintf (string, f, (long int)lua_getnumber(o)); 368 sprintf (string, f, (long int)lua_getnumber(o));
367 break; 369 break;
368 case 'f': case 'g': case 'e': t = 'f'; 370 case 'f': case 'g': case 'e': case 'G': case 'E':
371 sprintf(strchr(f,0), "%c", t);
369 sprintf (string, f, (float)lua_getnumber(o)); 372 sprintf (string, f, (float)lua_getnumber(o));
370 break; 373 break;
371 case 's': t = 's'; 374 case 'F': t = 'f';
375 sprintf(strchr(f,0), "%c", t);
376 sprintf (string, f, (float)lua_getnumber(o));
377 break;
378 case 's': case 'S': t = 's';
379 sprintf(strchr(f,0), "%c", t);
372 sprintf (string, f, lua_getstring(o)); 380 sprintf (string, f, lua_getstring(o));
373 break; 381 break;
374 default: return ""; 382 default: return "";
@@ -383,13 +391,22 @@ static char *buildformat (char *e, lua_Object o)
383 } 391 }
384 else if (m!=0 && j=='|') 392 else if (m!=0 && j=='|')
385 { 393 {
394 int k;
386 int i=l-1; 395 int i=l-1;
387 while (isspace(string[i])) i--; 396 while (isspace(string[i]) || string[i]==0) i--;
388 string -= (m-i) / 2; 397 string -= (m-i)/2;
389 i=0; 398 for(k=0; k<(m-i)/2; k++)
390 while (string[i]==0) string[i++] = ' '; 399 string[k] = ' ';
391 string[l] = 0; 400 }
401 /* add space characteres */
402 while (fspace != fstart)
403 {
404 string--;
405 fspace--;
406 *string = *fspace;
392 } 407 }
408 while (isspace(*e)) string[l++] = *e++;
409 string[l] = 0;
393 return string; 410 return string;
394} 411}
395static void io_write (void) 412static void io_write (void)