int sys_link() { char *old_path, *new_path; if(argptr(0, &old_path, 1) < 0 || argptr(1, &new_path, 1) < 0) return -1; return ilink(old_path, new_path); }
int loaddefs(int fromfile, char *fname, int mode) { nialptr ts; int repeatloop, keepreading, nolines, inremark, linecnt; FILE *f1 = NULL; /* initialized to avoid complaint */ int errorsfound; if (fromfile) { f1 = openfile(fname, 'r', 't'); if (f1 == OPENFAILED) return (false); pushsysfile(f1); } /* a loaddefs always affects the global environment. We reset current_env to relect this. The code to restore the environment is below. This must be saved on the stack, otherwise it can get thrown away since it may only be owned by a transient definition value. The following example failed before I protected this on the stack: retry is { host 'vi bug.ndf'; loaddefs"bug l } where this definition was in the file bug.ndf. */ apush(current_env); current_env = Null; ts = topstack; /* to monitor stack growth on each action */ errorsfound = 0; /* reset parse error counter */ repeatloop = true; linecnt = 0; /* loop to pick up groups of lines */ while (repeatloop) { /* continue as long as their are line groups */ /* test on each circuit if an interrupt signal has been posted */ #ifdef USER_BREAK_FLAG if (fromfile) checksignal(NC_CS_NORMAL); #endif inremark = false; nolines = 0; keepreading = true; /* loop to pick up lines until a whitespace line occurs */ while (keepreading) { if (fromfile) { /* reading a line from the file */ readfileline(f1, (mode ? 2 : 0)); /* mode==2 only in a loaddefs */ /* readfileline places result on the stack */ if (top == Eoffault) { apop(); /* to remove the end of file marker */ repeatloop = false; break; /* to end read loop */ } } else { /* select a line from array defsndf loadded from defstbl.h */ char *line; line = defsndf[linecnt++]; if (linecnt == NOLINES) { repeatloop = false; keepreading = false; /* to end read loop */ } mkstring(line); /* convert the line to a Nial string and push it */ } if (nolines == 0) { /* check first line of group for a remark */ char firstchar; int i = 0; /* loop to skip blanks */ while (i < tally(top) && fetch_char(top, i) <= BLANK) i++; /* note whether first char is "#" */ firstchar = fetch_char(top, i); if (tally(top)) inremark = firstchar == HASHSYMBOL; else inremark = false; } /* if the line is all while space then we are at the end of a group */ if (top == Null || allwhitespace(pfirstchar(top))) { keepreading = false; freeup(apop()); /* to get rid of the empty line */ } else /* count the line on the stack */ nolines++; } /* we have a group of lines to process */ if (nolines > 0) { mklist(nolines); /* create a list of lines and link them*/ ilink(); if (inremark) { freeup(apop()); /* remarks are ignored */ } else { /* carry out the actions of the main loop */ iscan(); parse(true); /* check whether parse produced an error */ if (kind(top) == faulttype) { if (top != Nullexpr) { errorsfound++; if (mode == 0) { /* show error message */ apush(top); ipicture(); show(apop()); } } } /* evaluate the parse tree, if it is a fault, it is the value returned */ ieval(); #ifdef DEBUG memchk(); #endif if (mode) { /* show the result */ if (top != Nullexpr) { ipicture(); show(apop()); } else apop(); /* the Nullexpr */ } else freeup(apop()); /* free because it might not be Nullexpr */ } if (mode) { /* now display empty line */ writechars(STDOUT, "", (nialint) 0, true); if (keeplog && f1 == STDIN) writelog("", 0, true); } } /* check that the stack hasn't grown */ if (ts != topstack) { while (ts != topstack) freeup(apop()); exit_cover(NC_STACK_GROWN_I); } } /* done reading groups of lines */ if (fromfile) { closefile(f1); popsysfile(); } /* restore the current_env */ current_env = apop(); if (errorsfound > 0) nprintf(OF_NORMAL_LOG, "errors found: %d\n", errorsfound); return (true); }