--- gforth/prim 1999/12/03 18:24:22 1.41 +++ gforth/prim 2000/05/31 14:37:40 1.46 @@ -488,6 +488,7 @@ the first string is smaller, @i{n} is -1 is 1. Currently this is based on the machine's character comparison. In the future, this may change to consider the current locale and its collation order."" +/* close ' to keep fontify happy */ n = memcmp(c_addr1, c_addr2, u10) n = 1; : - rot 2dup - >r min swap -text dup - IF rdrop - ELSE drop r@ 0> - IF rdrop -1 - ELSE r> 1 and - THEN - THEN ; + rot 2dup swap - >r min swap -text dup + IF rdrop ELSE drop r> sgn THEN ; +: sgn ( n -- -1/0/1 ) + dup 0= IF EXIT THEN 0< 2* 1+ ; -text c_addr1 u c_addr2 -- n new dash_text n = memcmp(c_addr1, c_addr2, u); @@ -514,8 +512,8 @@ else if (n>0) swap bounds ?DO dup c@ I c@ = WHILE 1+ LOOP drop 0 ELSE c@ I c@ - unloop THEN -text-flag ; -: -text-flag ( n -- -1/0/1 ) - dup 0< IF drop -1 ELSE 0> 1 and THEN ; +: sgn ( n -- -1/0/1 ) + dup 0= IF EXIT THEN 0< 2* 1+ ; toupper c1 -- c2 gforth ""If @i{c1} is a lower-case character (in the current locale), @i{c2} @@ -1487,6 +1485,7 @@ getenv c_addr1 u1 -- c_addr2 u2 gforth is the host operating system's expansion of that environment variable. If the environment variable does not exist, @i{c-addr2 u2} specifies a string 0 characters in length."" +/* close ' to keep fontify happy */ c_addr2 = getenv(cstr(c_addr1,u1,1)); u2 = (c_addr2 == NULL ? 0 : strlen(c_addr2)); @@ -1499,6 +1498,8 @@ wretval = pclose((FILE *)wfileid); wior = IOR(wretval==-1); time&date -- nsec nmin nhour nday nmonth nyear facility-ext time_and_date +""Report the current time of day. Seconds, minutes and hours are numbered from 0. +Months are numbered from 1."" struct timeval time1; struct timezone zone1; struct tm *ltime; @@ -1512,6 +1513,7 @@ nmin =ltime->tm_min; nsec =ltime->tm_sec; ms n -- facility-ext +""Wait at least @i{n} milli-second."" struct timeval timeout; timeout.tv_sec=n/1000; timeout.tv_usec=1000*(n%1000); @@ -1545,6 +1547,7 @@ I/O result code. If @i{a-addr1} is 0, Gf @code{resize} @code{allocate}s @i{u} address units."" /* the following check is not necessary on most OSs, but it is needed on SunOS 4.1.2. */ +/* close ' to keep fontify happy */ if (a_addr1==NULL) a_addr2 = (Cell *)malloc(u); else @@ -1636,21 +1639,26 @@ if (wior) clearerr((FILE *)wfileid); read-line c_addr u1 wfileid -- u2 flag wior file read_line -/* +#if 1 Cell c; flag=-1; for(u2=0; u20); switch(number[u]) { @@ -1884,7 +1899,7 @@ if((flag=FLAG(!(Cell)*endconv))) { IF_FTOS(fp[0] = FTOS); fp += -1; - FTOS = r; + FTOS = sign ? -r : r; } else if(*endconv=='d' || *endconv=='D') { @@ -1894,7 +1909,7 @@ else if(*endconv=='d' || *endconv=='D') { IF_FTOS(fp[0] = FTOS); fp += -1; - FTOS = r; + FTOS = sign ? -r : r; } } @@ -2142,6 +2157,7 @@ rret = (SYSCALL(Float(*)(argdlist($1)))u ') +\ close ' to keep fontify happy open-lib c_addr1 u1 -- u2 gforth open_lib #if defined(HAVE_LIBDL) || defined(HAVE_DLOPEN) @@ -2191,3 +2207,45 @@ fp=FP; IF_TOS(TOS=sp[0];) IF_FTOS(FTOS=fp[0]); +\+file + +open-dir c_addr u -- wdirid wior gforth open_dir +wdirid = (Cell)opendir(tilde_cstr(c_addr, u, 1)); +wior = IOR(wdirid == 0); + +read-dir c_addr u1 wdirid -- u2 flag wior gforth read_dir +struct dirent * dent; +dent = readdir((DIR *)wdirid); +wior = 0; +flag = -1; +if(dent == NULL) { + u2 = 0; + flag = 0; +} else { + u2 = strlen(dent->d_name); + if(u2 > u1) + u2 = u1; + memmove(c_addr, dent->d_name, u2); +} + +close-dir wdirid -- wior gforth close_dir +wior = IOR(closedir((DIR *)wdirid)); + +filename-match c_addr1 u1 c_addr2 u2 -- flag gforth match_file +char * string = cstr(c_addr1, u1, 1); +char * pattern = cstr(c_addr2, u2, 0); +flag = FLAG(!fnmatch(pattern, string, 0)); + +\+ + +newline -- c_addr u gforth +""String containing the newline sequence of the host OS"" +char newline[] = { +#ifdef unix +'\n' +#else +'\r','\n' +#endif +}; +c_addr=newline; +u=sizeof(newline);