LIB.TXT
上传用户:jnzhq888
上传日期:2007-01-18
资源大小:51694k
文件大小:1006k
- 15164
- 15165 STATIC CHAR NIL[] = "";
- 15166 STATIC CONST CHAR *Input = NIL;
- 15167 STATIC CHAR *Line;
- 15168 STATIC CONST char *Prompt;
- 15169 STATIC CHAR *Yanked;
- 15170 STATIC char *Screen;
- 15171 STATIC char NEWLINE[]= CRLF;
- 15172 STATIC HISTORY H;
- 15173 STATIC int Repeat;
- 15174 STATIC int End;
- 15175 STATIC int Mark;
- 15176 STATIC int OldPoint;
- 15177 STATIC int Point;
- 15178 STATIC int PushBack;
- 15179 STATIC int Pushed;
- 15180 STATIC int Signal;
- 15181 FORWARD KEYMAP Map[33];
- 15182 FORWARD KEYMAP MetaMap[17];
- 15183 STATIC SIZE_T Length;
- 15184 STATIC SIZE_T ScreenCount;
- 15185 STATIC SIZE_T ScreenSize;
- 15186 STATIC char *backspace;
- 15187 STATIC int TTYwidth;
- 15188 STATIC int TTYrows;
- 15189
- 15190 /* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */
- 15191 int rl_meta_chars = 0;
- 15192
- 15193 /*
- 15194 ** Declarations.
- 15195 */
- 15196 STATIC CHAR *editinput();
- 15197 extern int read();
- 15198 extern int write();
- 15199 #if defined(USE_TERMCAP)
- 15200 extern char *getenv();
- 15201 extern char *tgetstr();
- 15202 extern int tgetent();
- 15203 #endif /* defined(USE_TERMCAP) */
- 15204
- 15205 /*
- 15206 ** TTY input/output functions.
- 15207 */
- 15208
- 15209 STATIC void
- 15210 TTYflush()
- 15211 {
- 15212 if (ScreenCount) {
- 15213 (void)write(1, Screen, ScreenCount);
- 15214 ScreenCount = 0;
- 15215 }
- 15216 }
-
- 15218 STATIC void
- 15219 TTYput(c)
- 15220 CHAR c;
- 15221 {
- 15222 Screen[ScreenCount] = c;
- 15223 if (++ScreenCount >= ScreenSize - 1) {
- 15224 ScreenSize += SCREEN_INC;
- 15225 RENEW(Screen, char, ScreenSize);
- 15226 }
- 15227 }
-
- 15229 STATIC void
- 15230 TTYputs(p)
- 15231 CHAR *p;
- 15232 {
- 15233 while (*p)
- 15234 TTYput(*p++);
- 15235 }
-
- 15237 STATIC void
- 15238 TTYshow(c)
- 15239 CHAR c;
- 15240 {
- 15241 if (c == DEL) {
- 15242 TTYput('^');
- 15243 TTYput('?');
- 15244 }
- 15245 else if (ISCTL(c)) {
- 15246 TTYput('^');
- 15247 TTYput(UNCTL(c));
- 15248 }
- 15249 else if (rl_meta_chars && ISMETA(c)) {
- 15250 TTYput('M');
- 15251 TTYput('-');
- 15252 TTYput(UNMETA(c));
- 15253 }
- 15254 else
- 15255 TTYput(c);
- 15256 }
-
- 15258 STATIC void
- 15259 TTYstring(p)
- 15260 CHAR *p;
- 15261 {
- 15262 while (*p)
- 15263 TTYshow(*p++);
- 15264 }
-
- 15266 STATIC unsigned int
- 15267 TTYget()
- 15268 {
- 15269 CHAR c;
- 15270
- 15271 TTYflush();
- 15272 if (Pushed) {
- 15273 Pushed = 0;
- 15274 return PushBack;
- 15275 }
- 15276 if (*Input)
- 15277 return *Input++;
- 15278 return read(0, &c, (SIZE_T)1) == 1 ? c : EOF;
- 15279 }
-
- 15281 #define TTYback() (backspace ? TTYputs((CHAR *)backspace) : TTYput('b'))
- 15282
- 15283 STATIC void
- 15284 TTYbackn(n)
- 15285 int n;
- 15286 {
- 15287 while (--n >= 0)
- 15288 TTYback();
- 15289 }
-
- 15291 STATIC void
- 15292 TTYinfo()
- 15293 {
- 15294 static int init;
- 15295 #if defined(USE_TERMCAP)
- 15296 char *term;
- 15297 char buff[2048];
- 15298 char *bp;
- 15299 #endif /* defined(USE_TERMCAP) */
- 15300 #if defined(TIOCGWINSZ)
- 15301 struct winsize W;
- 15302 #endif /* defined(TIOCGWINSZ) */
- 15303
- 15304 if (init) {
- 15305 #if defined(TIOCGWINSZ)
- 15306 /* Perhaps we got resized. */
- 15307 if (ioctl(0, TIOCGWINSZ, &W) >= 0
- 15308 && W.ws_col > 0 && W.ws_row > 0) {
- 15309 TTYwidth = (int)W.ws_col;
- 15310 TTYrows = (int)W.ws_row;
- 15311 }
- 15312 #endif /* defined(TIOCGWINSZ) */
- 15313 return;
- 15314 }
- 15315 init++;
- 15316
- 15317 TTYwidth = TTYrows = 0;
- 15318 #if defined(USE_TERMCAP)
- 15319 bp = &buff[0];
- 15320 if ((term = getenv("TERM")) == NULL)
- 15321 term = "dumb";
- 15322 if (tgetent(buff, term) < 0) {
- 15323 TTYwidth = SCREEN_WIDTH;
- 15324 TTYrows = SCREEN_ROWS;
- 15325 return;
- 15326 }
- 15327 if ((backspace = tgetstr("le", &bp)) != NULL)
- 15328 backspace = strdup(backspace);
- 15329 TTYwidth = tgetnum("co");
- 15330 TTYrows = tgetnum("li");
- 15331 #endif /* defined(USE_TERMCAP) */
- 15332
- 15333 #if defined(TIOCGWINSZ)
- 15334 if (ioctl(0, TIOCGWINSZ, &W) >= 0) {
- 15335 TTYwidth = (int)W.ws_col;
- 15336 TTYrows = (int)W.ws_row;
- 15337 }
- 15338 #endif /* defined(TIOCGWINSZ) */
- 15339
- 15340 if (TTYwidth <= 0 || TTYrows <= 0) {
- 15341 TTYwidth = SCREEN_WIDTH;
- 15342 TTYrows = SCREEN_ROWS;
- 15343 }
- 15344 }
- 15345
- 15346
- 15347 /*
- 15348 ** Print an array of words in columns.
- 15349 */
- 15350 STATIC void
- 15351 columns(ac, av)
- 15352 int ac;
- 15353 CHAR **av;
- 15354 {
- 15355 CHAR *p;
- 15356 int i;
- 15357 int j;
- 15358 int k;
- 15359 int len;
- 15360 int skip;
- 15361 int longest;
- 15362 int cols;
- 15363
- 15364 /* Find longest name, determine column count from that. */
- 15365 for (longest = 0, i = 0; i < ac; i++)
- 15366 if ((j = strlen((char *)av[i])) > longest)
- 15367 longest = j;
- 15368 cols = TTYwidth / (longest + 3);
- 15369
- 15370 TTYputs((CHAR *)NEWLINE);
- 15371 for (skip = ac / cols + 1, i = 0; i < skip; i++) {
- 15372 for (j = i; j < ac; j += skip) {
- 15373 for (p = av[j], len = strlen((char *)p), k = len; --k >= 0; p++)
- 15374 TTYput(*p);
- 15375 if (j + skip < ac)
- 15376 while (++len < longest + 3)
- 15377 TTYput(' ');
- 15378 }
- 15379 TTYputs((CHAR *)NEWLINE);
- 15380 }
- 15381 }
-
- 15383 STATIC void
- 15384 reposition()
- 15385 {
- 15386 int i;
- 15387 CHAR *p;
- 15388
- 15389 TTYput('r');
- 15390 TTYputs((CONST CHAR *)Prompt);
- 15391 for (i = Point, p = Line; --i >= 0; p++)
- 15392 TTYshow(*p);
- 15393 }
-
- 15395 STATIC void
- 15396 left(Change)
- 15397 STATUS Change;
- 15398 {
- 15399 TTYback();
- 15400 if (Point) {
- 15401 if (ISCTL(Line[Point - 1]))
- 15402 TTYback();
- 15403 else if (rl_meta_chars && ISMETA(Line[Point - 1])) {
- 15404 TTYback();
- 15405 TTYback();
- 15406 }
- 15407 }
- 15408 if (Change == CSmove)
- 15409 Point--;
- 15410 }
-
- 15412 STATIC void
- 15413 right(Change)
- 15414 STATUS Change;
- 15415 {
- 15416 TTYshow(Line[Point]);
- 15417 if (Change == CSmove)
- 15418 Point++;
- 15419 }
-
- 15421 STATIC STATUS
- 15422 ring_bell()
- 15423 {
- 15424 TTYput(' 7');
- 15425 TTYflush();
- 15426 return CSstay;
- 15427 }
-
- 15429 STATIC STATUS
- 15430 do_macro(c)
- 15431 unsigned int c;
- 15432 {
- 15433 CHAR name[4];
- 15434
- 15435 name[0] = '_';
- 15436 name[1] = c;
- 15437 name[2] = '_';
- 15438 name[3] = ' ';
- 15439
- 15440 if ((Input = (CHAR *)getenv((char *)name)) == NULL) {
- 15441 Input = NIL;
- 15442 return ring_bell();
- 15443 }
- 15444 return CSstay;
- 15445 }
-
- 15447 STATIC STATUS
- 15448 do_forward(move)
- 15449 STATUS move;
- 15450 {
- 15451 int i;
- 15452 CHAR *p;
- 15453
- 15454 i = 0;
- 15455 do {
- 15456 p = &Line[Point];
- 15457 for ( ; Point < End && (*p == ' ' || !isalnum(*p)); Point++, p++)
- 15458 if (move == CSmove)
- 15459 right(CSstay);
- 15460
- 15461 for (; Point < End && isalnum(*p); Point++, p++)
- 15462 if (move == CSmove)
- 15463 right(CSstay);
- 15464
- 15465 if (Point == End)
- 15466 break;
- 15467 } while (++i < Repeat);
- 15468
- 15469 return CSstay;
- 15470 }
-
- 15472 STATIC STATUS
- 15473 do_case(type)
- 15474 CASE type;
- 15475 {
- 15476 int i;
- 15477 int end;
- 15478 int count;
- 15479 CHAR *p;
- 15480
- 15481 (void)do_forward(CSstay);
- 15482 if (OldPoint != Point) {
- 15483 if ((count = Point - OldPoint) < 0)
- 15484 count = -count;
- 15485 Point = OldPoint;
- 15486 if ((end = Point + count) > End)
- 15487 end = End;
- 15488 for (i = Point, p = &Line[i]; i < end; i++, p++) {
- 15489 if (type == TOupper) {
- 15490 if (islower(*p))
- 15491 *p = toupper(*p);
- 15492 }
- 15493 else if (isupper(*p))
- 15494 *p = tolower(*p);
- 15495 right(CSmove);
- 15496 }
- 15497 }
- 15498 return CSstay;
- 15499 }
-
- 15501 STATIC STATUS
- 15502 case_down_word()
- 15503 {
- 15504 return do_case(TOlower);
- 15505 }
-
- 15507 STATIC STATUS
- 15508 case_up_word()
- 15509 {
- 15510 return do_case(TOupper);
- 15511 }
-
- 15513 STATIC void
- 15514 ceol()
- 15515 {
- 15516 int extras;
- 15517 int i;
- 15518 CHAR *p;
- 15519
- 15520 for (extras = 0, i = Point, p = &Line[i]; i <= End; i++, p++) {
- 15521 TTYput(' ');
- 15522 if (ISCTL(*p)) {
- 15523 TTYput(' ');
- 15524 extras++;
- 15525 }
- 15526 else if (rl_meta_chars && ISMETA(*p)) {
- 15527 TTYput(' ');
- 15528 TTYput(' ');
- 15529 extras += 2;
- 15530 }
- 15531 }
- 15532
- 15533 for (i += extras; i > Point; i--)
- 15534 TTYback();
- 15535 }
-
- 15537 STATIC void
- 15538 clear_line()
- 15539 {
- 15540 Point = -strlen(Prompt);
- 15541 TTYput('r');
- 15542 ceol();
- 15543 Point = 0;
- 15544 End = 0;
- 15545 Line[0] = ' ';
- 15546 }
-
- 15548 STATIC STATUS
- 15549 insert_string(p)
- 15550 CHAR *p;
- 15551 {
- 15552 SIZE_T len;
- 15553 int i;
- 15554 CHAR *new;
- 15555 CHAR *q;
- 15556
- 15557 len = strlen((char *)p);
- 15558 if (End + len >= Length) {
- 15559 if ((new = NEW(CHAR, Length + len + MEM_INC)) == NULL)
- 15560 return CSstay;
- 15561 if (Length) {
- 15562 COPYFROMTO(new, Line, Length);
- 15563 DISPOSE(Line);
- 15564 }
- 15565 Line = new;
- 15566 Length += len + MEM_INC;
- 15567 }
- 15568
- 15569 for (q = &Line[Point], i = End - Point; --i >= 0; )
- 15570 q[len + i] = q[i];
- 15571 COPYFROMTO(&Line[Point], p, len);
- 15572 End += len;
- 15573 Line[End] = ' ';
- 15574 TTYstring(&Line[Point]);
- 15575 Point += len;
- 15576
- 15577 return Point == End ? CSstay : CSmove;
- 15578 }
-
- 15580 STATIC STATUS
- 15581 redisplay()
- 15582 {
- 15583 TTYputs((CONST CHAR *)NEWLINE);
- 15584 TTYputs((CONST CHAR *)Prompt);
- 15585 TTYstring(Line);
- 15586 return CSmove;
- 15587 }
-
- 15589 STATIC STATUS
- 15590 toggle_meta_mode()
- 15591 {
- 15592 rl_meta_chars = ! rl_meta_chars;
- 15593 return redisplay();
- 15594 }
- 15595
- 15596
- 15597 STATIC CHAR *
- 15598 next_hist()
- 15599 {
- 15600 return H.Pos >= H.Size - 1 ? NULL : H.Lines[++H.Pos];
- 15601 }
-
- 15603 STATIC CHAR *
- 15604 prev_hist()
- 15605 {
- 15606 return H.Pos == 0 ? NULL : H.Lines[--H.Pos];
- 15607 }
-
- 15609 STATIC STATUS
- 15610 do_insert_hist(p)
- 15611 CHAR *p;
- 15612 {
- 15613 if (p == NULL)
- 15614 return ring_bell();
- 15615 Point = 0;
- 15616 reposition();
- 15617 ceol();
- 15618 End = 0;
- 15619 return insert_string(p);
- 15620 }
-
- 15622 STATIC STATUS
- 15623 do_hist(move)
- 15624 CHAR *(*move)();
- 15625 {
- 15626 CHAR *p;
- 15627 int i;
- 15628
- 15629 i = 0;
- 15630 do {
- 15631 if ((p = (*move)()) == NULL)
- 15632 return ring_bell();
- 15633 } while (++i < Repeat);
- 15634 return do_insert_hist(p);
- 15635 }
-
- 15637 STATIC STATUS
- 15638 h_next()
- 15639 {
- 15640 return do_hist(next_hist);
- 15641 }
-
- 15643 STATIC STATUS
- 15644 h_prev()
- 15645 {
- 15646 return do_hist(prev_hist);
- 15647 }
-
- 15649 STATIC STATUS
- 15650 h_first()
- 15651 {
- 15652 return do_insert_hist(H.Lines[H.Pos = 0]);
- 15653 }
-
- 15655 STATIC STATUS
- 15656 h_last()
- 15657 {
- 15658 return do_insert_hist(H.Lines[H.Pos = H.Size - 1]);
- 15659 }
-
- 15661 /*
- 15662 ** Return zero if pat appears as a substring in text.
- 15663 */
- 15664 STATIC int
- 15665 substrcmp(text, pat, len)
- 15666 char *text;
- 15667 char *pat;
- 15668 int len;
- 15669 {
- 15670 char c;
- 15671
- 15672 if ((c = *pat) == ' ')
- 15673 return *text == ' ';
- 15674 for ( ; *text; text++)
- 15675 if (*text == c && strncmp(text, pat, len) == 0)
- 15676 return 0;
- 15677 return 1;
- 15678 }
-
- 15680 STATIC CHAR *
- 15681 search_hist(search, move)
- 15682 CHAR *search;
- 15683 CHAR *(*move)();
- 15684 {
- 15685 static CHAR *old_search;
- 15686 int len;
- 15687 int pos;
- 15688 int (*match)();
- 15689 char *pat;
- 15690
- 15691 /* Save or get remembered search pattern. */
- 15692 if (search && *search) {
- 15693 if (old_search)
- 15694 DISPOSE(old_search);
- 15695 old_search = (CHAR *)strdup((char *)search);
- 15696 }
- 15697 else {
- 15698 if (old_search == NULL || *old_search == ' ')
- 15699 return NULL;
- 15700 search = old_search;
- 15701 }
- 15702
- 15703 /* Set up pattern-finder. */
- 15704 if (*search == '^') {
- 15705 match = strncmp;
- 15706 pat = (char *)(search + 1);
- 15707 }
- 15708 else {
- 15709 match = substrcmp;
- 15710 pat = (char *)search;
- 15711 }
- 15712 len = strlen(pat);
- 15713
- 15714 for (pos = H.Pos; (*move)() != NULL; )
- 15715 if ((*match)((char *)H.Lines[H.Pos], pat, len) == 0)
- 15716 return H.Lines[H.Pos];
- 15717 H.Pos = pos;
- 15718 return NULL;
- 15719 }
-
- 15721 STATIC STATUS
- 15722 h_search()
- 15723 {
- 15724 static int Searching;
- 15725 CONST char *old_prompt;
- 15726 CHAR *(*move)();
- 15727 CHAR *p;
- 15728
- 15729 if (Searching)
- 15730 return ring_bell();
- 15731 Searching = 1;
- 15732
- 15733 clear_line();
- 15734 old_prompt = Prompt;
- 15735 Prompt = "Search: ";
- 15736 TTYputs((CONST CHAR *)Prompt);
- 15737 move = Repeat == NO_ARG ? prev_hist : next_hist;
- 15738 p = editinput();
- 15739 Prompt = old_prompt;
- 15740 Searching = 0;
- 15741 TTYputs((CONST CHAR *)Prompt);
- 15742 if (p == NULL && Signal > 0) {
- 15743 Signal = 0;
- 15744 clear_line();
- 15745 return redisplay();
- 15746 }
- 15747 p = search_hist(p, move);
- 15748 clear_line();
- 15749 if (p == NULL) {
- 15750 (void)ring_bell();
- 15751 return redisplay();
- 15752 }
- 15753 return do_insert_hist(p);
- 15754 }
-
- 15756 STATIC STATUS
- 15757 fd_char()
- 15758 {
- 15759 int i;
- 15760
- 15761 i = 0;
- 15762 do {
- 15763 if (Point >= End)
- 15764 break;
- 15765 right(CSmove);
- 15766 } while (++i < Repeat);
- 15767 return CSstay;
- 15768 }
-
- 15770 STATIC void
- 15771 save_yank(begin, i)
- 15772 int begin;
- 15773 int i;
- 15774 {
- 15775 if (Yanked) {
- 15776 DISPOSE(Yanked);
- 15777 Yanked = NULL;
- 15778 }
- 15779
- 15780 if (i < 1)
- 15781 return;
- 15782
- 15783 if ((Yanked = NEW(CHAR, (SIZE_T)i + 1)) != NULL) {
- 15784 COPYFROMTO(Yanked, &Line[begin], i);
- 15785 Yanked[i] = ' ';
- 15786 }
- 15787 }
-
- 15789 STATIC STATUS
- 15790 delete_string(count)
- 15791 int count;
- 15792 {
- 15793 int i;
- 15794 CHAR *p;
- 15795
- 15796 if (count <= 0 || End == Point)
- 15797 return ring_bell();
- 15798
- 15799 if (count == 1 && Point == End - 1) {
- 15800 /* Optimize common case of delete at end of line. */
- 15801 End--;
- 15802 p = &Line[Point];
- 15803 i = 1;
- 15804 TTYput(' ');
- 15805 if (ISCTL(*p)) {
- 15806 i = 2;
- 15807 TTYput(' ');
- 15808 }
- 15809 else if (rl_meta_chars && ISMETA(*p)) {
- 15810 i = 3;
- 15811 TTYput(' ');
- 15812 TTYput(' ');
- 15813 }
- 15814 TTYbackn(i);
- 15815 *p = ' ';
- 15816 return CSmove;
- 15817 }
- 15818 if (Point + count > End && (count = End - Point) <= 0)
- 15819 return CSstay;
- 15820
- 15821 if (count > 1)
- 15822 save_yank(Point, count);
- 15823
- 15824 for (p = &Line[Point], i = End - (Point + count) + 1; --i >= 0; p++)
- 15825 p[0] = p[count];
- 15826 ceol();
- 15827 End -= count;
- 15828 TTYstring(&Line[Point]);
- 15829 return CSmove;
- 15830 }
-
- 15832 STATIC STATUS
- 15833 bk_char()
- 15834 {
- 15835 int i;
- 15836
- 15837 i = 0;
- 15838 do {
- 15839 if (Point == 0)
- 15840 break;
- 15841 left(CSmove);
- 15842 } while (++i < Repeat);
- 15843
- 15844 return CSstay;
- 15845 }
-
- 15847 STATIC STATUS
- 15848 bk_del_char()
- 15849 {
- 15850 int i;
- 15851
- 15852 i = 0;
- 15853 do {
- 15854 if (Point == 0)
- 15855 break;
- 15856 left(CSmove);
- 15857 } while (++i < Repeat);
- 15858
- 15859 return delete_string(i);
- 15860 }
-
- 15862 STATIC STATUS
- 15863 kill_line()
- 15864 {
- 15865 int i;
- 15866
- 15867 if (Repeat != NO_ARG) {
- 15868 if (Repeat < Point) {
- 15869 i = Point;
- 15870 Point = Repeat;
- 15871 reposition();
- 15872 (void)delete_string(i - Point);
- 15873 }
- 15874 else if (Repeat > Point) {
- 15875 right(CSmove);
- 15876 (void)delete_string(Repeat - Point - 1);
- 15877 }
- 15878 return CSmove;
- 15879 }
- 15880
- 15881 save_yank(Point, End - Point);
- 15882 Line[Point] = ' ';
- 15883 ceol();
- 15884 End = Point;
- 15885 return CSstay;
- 15886 }
-
- 15888 STATIC STATUS
- 15889 insert_char(c)
- 15890 int c;
- 15891 {
- 15892 STATUS s;
- 15893 CHAR buff[2];
- 15894 CHAR *p;
- 15895 CHAR *q;
- 15896 int i;
- 15897
- 15898 if (Repeat == NO_ARG || Repeat < 2) {
- 15899 buff[0] = c;
- 15900 buff[1] = ' ';
- 15901 return insert_string(buff);
- 15902 }
- 15903
- 15904 if ((p = NEW(CHAR, Repeat + 1)) == NULL)
- 15905 return CSstay;
- 15906 for (i = Repeat, q = p; --i >= 0; )
- 15907 *q++ = c;
- 15908 *q = ' ';
- 15909 Repeat = 0;
- 15910 s = insert_string(p);
- 15911 DISPOSE(p);
- 15912 return s;
- 15913 }
-
- 15915 STATIC STATUS
- 15916 meta()
- 15917 {
- 15918 unsigned int c;
- 15919 KEYMAP *kp;
- 15920
- 15921 if ((c = TTYget()) == EOF)
- 15922 return CSeof;
- 15923 #if defined(ANSI_ARROWS)
- 15924 /* Also include VT-100 arrows. */
- 15925 if (c == '[' || c == 'O')
- 15926 switch (c = TTYget()) {
- 15927 default: return ring_bell();
- 15928 case EOF: return CSeof;
- 15929 case 'A': return h_prev();
- 15930 case 'B': return h_next();
- 15931 case 'C': return fd_char();
- 15932 case 'D': return bk_char();
- 15933 }
- 15934 #endif /* defined(ANSI_ARROWS) */
- 15935
- 15936 if (isdigit(c)) {
- 15937 for (Repeat = c - '0'; (c = TTYget()) != EOF && isdigit(c); )
- 15938 Repeat = Repeat * 10 + c - '0';
- 15939 Pushed = 1;
- 15940 PushBack = c;
- 15941 return CSstay;
- 15942 }
- 15943
- 15944 if (isupper(c))
- 15945 return do_macro(c);
- 15946 for (kp = MetaMap; kp->Function; kp++)
- 15947 if (kp->Key == c)
- 15948 return (*kp->Function)();
- 15949
- 15950 return ring_bell();
- 15951 }
-
- 15953 STATIC STATUS
- 15954 emacs(c)
- 15955 unsigned int c;
- 15956 {
- 15957 STATUS s;
- 15958 KEYMAP *kp;
- 15959
- 15960 OldPoint = Point;
- 15961 if (rl_meta_chars && ISMETA(c)) {
- 15962 Pushed = 1;
- 15963 PushBack = UNMETA(c);
- 15964 return meta();
- 15965 }
- 15966 for (kp = Map; kp->Function; kp++)
- 15967 if (kp->Key == c)
- 15968 break;
- 15969 s = kp->Function ? (*kp->Function)() : insert_char((int)c);
- 15970 if (!Pushed)
- 15971 /* No pushback means no repeat count; hacky, but true. */
- 15972 Repeat = NO_ARG;
- 15973 return s;
- 15974 }
-
- 15976 STATIC STATUS
- 15977 TTYspecial(c)
- 15978 unsigned int c;
- 15979 {
- 15980 if (ISMETA(c))
- 15981 return CSdispatch;
- 15982
- 15983 if (c == rl_erase || c == DEL)
- 15984 return bk_del_char();
- 15985 if (c == rl_kill) {
- 15986 if (Point != 0) {
- 15987 Point = 0;
- 15988 reposition();
- 15989 }
- 15990 Repeat = NO_ARG;
- 15991 return kill_line();
- 15992 }
- 15993 if (c == rl_eof && Point == 0 && End == 0)
- 15994 return CSeof;
- 15995 if (c == rl_intr) {
- 15996 Signal = SIGINT;
- 15997 return CSsignal;
- 15998 }
- 15999 if (c == rl_quit) {
- 16000 Signal = SIGQUIT;
- 16001 return CSeof;
- 16002 }
- 16003
- 16004 return CSdispatch;
- 16005 }
-
- 16007 STATIC CHAR *
- 16008 editinput()
- 16009 {
- 16010 unsigned int c;
- 16011
- 16012 Repeat = NO_ARG;
- 16013 OldPoint = Point = Mark = End = 0;
- 16014 Line[0] = ' ';
- 16015
- 16016 Signal = -1;
- 16017 while ((c = TTYget()) != EOF)
- 16018 switch (TTYspecial(c)) {
- 16019 case CSdone:
- 16020 return Line;
- 16021 case CSeof:
- 16022 return NULL;
- 16023 case CSsignal:
- 16024 return (CHAR *)"";
- 16025 case CSmove:
- 16026 reposition();
- 16027 break;
- 16028 case CSdispatch:
- 16029 switch (emacs(c)) {
- 16030 case CSdone:
- 16031 return Line;
- 16032 case CSeof:
- 16033 return NULL;
- 16034 case CSsignal:
- 16035 return (CHAR *)"";
- 16036 case CSmove:
- 16037 reposition();
- 16038 break;
- 16039 case CSdispatch:
- 16040 case CSstay:
- 16041 break;
- 16042 }
- 16043 break;
- 16044 case CSstay:
- 16045 break;
- 16046 }
- 16047 return NULL;
- 16048 }
-
- 16050 STATIC void
- 16051 hist_add(p)
- 16052 CHAR *p;
- 16053 {
- 16054 int i;
- 16055
- 16056 if ((p = (CHAR *)strdup((char *)p)) == NULL)
- 16057 return;
- 16058 if (H.Size < HIST_SIZE)
- 16059 H.Lines[H.Size++] = p;
- 16060 else {
- 16061 DISPOSE(H.Lines[0]);
- 16062 for (i = 0; i < HIST_SIZE - 1; i++)
- 16063 H.Lines[i] = H.Lines[i + 1];
- 16064 H.Lines[i] = p;
- 16065 }
- 16066 H.Pos = H.Size - 1;
- 16067 }
-
- 16069 /*
- 16070 ** For compatibility with FSF readline.
- 16071 */
- 16072 /* ARGSUSED0 */
- 16073 void
- 16074 rl_reset_terminal(p)
- 16075 char *p;
- 16076 {
- 16077 }
-
- 16079 void
- 16080 rl_initialize()
- 16081 {
- 16082 }
-
- 16084 char *
- 16085 readline(prompt)
- 16086 CONST char *prompt;
- 16087 {
- 16088 CHAR *line;
- 16089 int s;
- 16090
- 16091 if (Line == NULL) {
- 16092 Length = MEM_INC;
- 16093 if ((Line = NEW(CHAR, Length)) == NULL)
- 16094 return NULL;
- 16095 }
- 16096
- 16097 TTYinfo();
- 16098 rl_ttyset(0);
- 16099 hist_add(NIL);
- 16100 ScreenSize = SCREEN_INC;
- 16101 Screen = NEW(char, ScreenSize);
- 16102 Prompt = prompt ? prompt : (char *)NIL;
- 16103 TTYputs((CONST CHAR *)Prompt);
- 16104 if ((line = editinput()) != NULL) {
- 16105 line = (CHAR *)strdup((char *)line);
- 16106 TTYputs((CHAR *)NEWLINE);
- 16107 TTYflush();
- 16108 }
- 16109 rl_ttyset(1);
- 16110 DISPOSE(Screen);
- 16111 DISPOSE(H.Lines[--H.Size]);
- 16112 if (Signal > 0) {
- 16113 s = Signal;
- 16114 Signal = 0;
- 16115 (void)kill(getpid(), s);
- 16116 }
- 16117 return (char *)line;
- 16118 }
-
- 16120 void
- 16121 add_history(p)
- 16122 char *p;
- 16123 {
- 16124 if (p == NULL || *p == ' ')
- 16125 return;
- 16126
- 16127 #if defined(UNIQUE_HISTORY)
- 16128 if (H.Pos && strcmp(p, (char *) H.Lines[H.Pos - 1]) == 0)
- 16129 return;
- 16130 #endif /* defined(UNIQUE_HISTORY) */
- 16131 if (H.Size && strcmp(p, (char *) H.Lines[H.Size - 1]) == 0)
- 16132 return;
- 16133 hist_add((CHAR *)p);
- 16134 }
- 16135
- 16136
- 16137 STATIC STATUS
- 16138 beg_line()
- 16139 {
- 16140 if (Point) {
- 16141 Point = 0;
- 16142 return CSmove;
- 16143 }
- 16144 return CSstay;
- 16145 }
-
- 16147 STATIC STATUS
- 16148 del_char()
- 16149 {
- 16150 return delete_string(Repeat == NO_ARG ? 1 : Repeat);
- 16151 }
-
- 16153 STATIC STATUS
- 16154 end_line()
- 16155 {
- 16156 if (Point != End) {
- 16157 Point = End;
- 16158 return CSmove;
- 16159 }
- 16160 return CSstay;
- 16161 }
-
- 16163 /*
- 16164 ** Move back to the beginning of the current word and return an
- 16165 ** allocated copy of it.
- 16166 */
- 16167 STATIC CHAR *
- 16168 find_word()
- 16169 {
- 16170 static char SEPS[] = "#:;&|^$=`'{}()<>nt ";
- 16171 CHAR *p;
- 16172 CHAR *new;
- 16173 SIZE_T len;
- 16174
- 16175 for (p = &Line[Point]; p > Line && strchr(SEPS, (char)p[-1]) == NULL; p--)
- 16176 continue;
- 16177 len = Point - (p - Line) + 1;
- 16178 if ((new = NEW(CHAR, len)) == NULL)
- 16179 return NULL;
- 16180 COPYFROMTO(new, p, len);
- 16181 new[len - 1] = ' ';
- 16182 return new;
- 16183 }
-
- 16185 STATIC STATUS
- 16186 c_possible()
- 16187 {
- 16188 CHAR **av;
- 16189 CHAR *word;
- 16190 int ac;
- 16191
- 16192 word = find_word();
- 16193 ac = rl_list_possib((char *)word, (char ***)&av);
- 16194 if (word)
- 16195 DISPOSE(word);
- 16196 if (ac) {
- 16197 columns(ac, av);
- 16198 while (--ac >= 0)
- 16199 DISPOSE(av[ac]);
- 16200 DISPOSE(av);
- 16201 return CSmove;
- 16202 }
- 16203 return ring_bell();
- 16204 }
-
- 16206 STATIC STATUS
- 16207 c_complete()
- 16208 {
- 16209 CHAR *p;
- 16210 CHAR *word;
- 16211 int unique;
- 16212 STATUS s;
- 16213
- 16214 word = find_word();
- 16215 p = (CHAR *)rl_complete((char *)word, &unique);
- 16216 if (word)
- 16217 DISPOSE(word);
- 16218 if (p && *p) {
- 16219 s = insert_string(p);
- 16220 #if ANNOYING_NOISE
- 16221 if (!unique)
- 16222 (void)ring_bell();
- 16223 #endif
- 16224 DISPOSE(p);
- 16225 return s;
- 16226 }
- 16227 return c_possible();
- 16228 }
-
- 16230 STATIC STATUS
- 16231 accept_line()
- 16232 {
- 16233 Line[End] = ' ';
- 16234 return CSdone;
- 16235 }
-
- 16237 STATIC STATUS
- 16238 transpose()
- 16239 {
- 16240 CHAR c;
- 16241
- 16242 if (Point) {
- 16243 if (Point == End)
- 16244 left(CSmove);
- 16245 c = Line[Point - 1];
- 16246 left(CSstay);
- 16247 Line[Point - 1] = Line[Point];
- 16248 TTYshow(Line[Point - 1]);
- 16249 Line[Point++] = c;
- 16250 TTYshow(c);
- 16251 }
- 16252 return CSstay;
- 16253 }
-
- 16255 STATIC STATUS
- 16256 quote()
- 16257 {
- 16258 unsigned int c;
- 16259
- 16260 return (c = TTYget()) == EOF ? CSeof : insert_char((int)c);
- 16261 }
-
- 16263 STATIC STATUS
- 16264 wipe()
- 16265 {
- 16266 int i;
- 16267
- 16268 if (Mark > End)
- 16269 return ring_bell();
- 16270
- 16271 if (Point > Mark) {
- 16272 i = Point;
- 16273 Point = Mark;
- 16274 Mark = i;
- 16275 reposition();
- 16276 }
- 16277
- 16278 return delete_string(Mark - Point);
- 16279 }
-
- 16281 STATIC STATUS
- 16282 mk_set()
- 16283 {
- 16284 Mark = Point;
- 16285 return CSstay;
- 16286 }
-
- 16288 STATIC STATUS
- 16289 exchange()
- 16290 {
- 16291 unsigned int c;
- 16292
- 16293 if ((c = TTYget()) != CTL('X'))
- 16294 return c == EOF ? CSeof : ring_bell();
- 16295
- 16296 if ((c = Mark) <= End) {
- 16297 Mark = Point;
- 16298 Point = c;
- 16299 return CSmove;
- 16300 }
- 16301 return CSstay;
- 16302 }
-
- 16304 STATIC STATUS
- 16305 yank()
- 16306 {
- 16307 if (Yanked && *Yanked)
- 16308 return insert_string(Yanked);
- 16309 return CSstay;
- 16310 }
-
- 16312 STATIC STATUS
- 16313 copy_region()
- 16314 {
- 16315 if (Mark > End)
- 16316 return ring_bell();
- 16317
- 16318 if (Point > Mark)
- 16319 save_yank(Mark, Point - Mark);
- 16320 else
- 16321 save_yank(Point, Mark - Point);
- 16322
- 16323 return CSstay;
- 16324 }
-
- 16326 STATIC STATUS
- 16327 move_to_char()
- 16328 {
- 16329 unsigned int c;
- 16330 int i;
- 16331 CHAR *p;
- 16332
- 16333 if ((c = TTYget()) == EOF)
- 16334 return CSeof;
- 16335 for (i = Point + 1, p = &Line[i]; i < End; i++, p++)
- 16336 if (*p == c) {
- 16337 Point = i;
- 16338 return CSmove;
- 16339 }
- 16340 return CSstay;
- 16341 }
-
- 16343 STATIC STATUS
- 16344 fd_word()
- 16345 {
- 16346 return do_forward(CSmove);
- 16347 }
-
- 16349 STATIC STATUS
- 16350 fd_kill_word()
- 16351 {
- 16352 int i;
- 16353
- 16354 (void)do_forward(CSstay);
- 16355 if (OldPoint != Point) {
- 16356 i = Point - OldPoint;
- 16357 Point = OldPoint;
- 16358 return delete_string(i);
- 16359 }
- 16360 return CSstay;
- 16361 }
-
- 16363 STATIC STATUS
- 16364 bk_word()
- 16365 {
- 16366 int i;
- 16367 CHAR *p;
- 16368
- 16369 i = 0;
- 16370 do {
- 16371 for (p = &Line[Point]; p > Line && !isalnum(p[-1]); p--)
- 16372 left(CSmove);
- 16373
- 16374 for (; p > Line && p[-1] != ' ' && isalnum(p[-1]); p--)
- 16375 left(CSmove);
- 16376
- 16377 if (Point == 0)
- 16378 break;
- 16379 } while (++i < Repeat);
- 16380
- 16381 return CSstay;
- 16382 }
-
- 16384 STATIC STATUS
- 16385 bk_kill_word()
- 16386 {
- 16387 (void)bk_word();
- 16388 if (OldPoint != Point)
- 16389 return delete_string(OldPoint - Point);
- 16390 return CSstay;
- 16391 }
-
- 16393 STATIC int
- 16394 argify(line, avp)
- 16395 CHAR *line;
- 16396 CHAR ***avp;
- 16397 {
- 16398 CHAR *c;
- 16399 CHAR **p;
- 16400 CHAR **new;
- 16401 int ac;
- 16402 int i;
- 16403
- 16404 i = MEM_INC;
- 16405 if ((*avp = p = NEW(CHAR*, i))== NULL)
- 16406 return 0;
- 16407
- 16408 for (c = line; isspace(*c); c++)
- 16409 continue;
- 16410 if (*c == 'n' || *c == ' ')
- 16411 return 0;
- 16412
- 16413 for (ac = 0, p[ac++] = c; *c && *c != 'n'; ) {
- 16414 if (isspace(*c)) {
- 16415 *c++ = ' ';
- 16416 if (*c && *c != 'n') {
- 16417 if (ac + 1 == i) {
- 16418 new = NEW(CHAR*, i + MEM_INC);
- 16419 if (new == NULL) {
- 16420 p[ac] = NULL;
- 16421 return ac;
- 16422 }
- 16423 COPYFROMTO(new, p, i * sizeof (char **));
- 16424 i += MEM_INC;
- 16425 DISPOSE(p);
- 16426 *avp = p = new;
- 16427 }
- 16428 p[ac++] = c;
- 16429 }
- 16430 }
- 16431 else
- 16432 c++;
- 16433 }
- 16434 *c = ' ';
- 16435 p[ac] = NULL;
- 16436 return ac;
- 16437 }
-
- 16439 STATIC STATUS
- 16440 last_argument()
- 16441 {
- 16442 CHAR **av;
- 16443 CHAR *p;
- 16444 STATUS s;
- 16445 int ac;
- 16446
- 16447 if (H.Size == 1 || (p = H.Lines[H.Size - 2]) == NULL)
- 16448 return ring_bell();
- 16449
- 16450 if ((p = (CHAR *)strdup((char *)p)) == NULL)
- 16451 return CSstay;
- 16452 ac = argify(p, &av);
- 16453
- 16454 if (Repeat != NO_ARG)
- 16455 s = Repeat < ac ? insert_string(av[Repeat]) : ring_bell();
- 16456 else
- 16457 s = ac ? insert_string(av[ac - 1]) : CSstay;
- 16458
- 16459 if (ac)
- 16460 DISPOSE(av);
- 16461 DISPOSE(p);
- 16462 return s;
- 16463 }
-
- 16465 STATIC KEYMAP Map[33] = {
- 16466 { CTL('@'), mk_set },
- 16467 { CTL('A'), beg_line },
- 16468 { CTL('B'), bk_char },
- 16469 { CTL('D'), del_char },
- 16470 { CTL('E'), end_line },
- 16471 { CTL('F'), fd_char },
- 16472 { CTL('G'), ring_bell },
- 16473 { CTL('H'), bk_del_char },
- 16474 { CTL('I'), c_complete },
- 16475 { CTL('J'), accept_line },
- 16476 { CTL('K'), kill_line },
- 16477 { CTL('L'), redisplay },
- 16478 { CTL('M'), accept_line },
- 16479 { CTL('N'), h_next },
- 16480 { CTL('O'), ring_bell },
- 16481 { CTL('P'), h_prev },
- 16482 { CTL('Q'), ring_bell },
- 16483 { CTL('R'), h_search },
- 16484 { CTL('S'), ring_bell },
- 16485 { CTL('T'), transpose },
- 16486 { CTL('U'), ring_bell },
- 16487 { CTL('V'), quote },
- 16488 { CTL('W'), bk_kill_word },
- 16489 { CTL('X'), exchange },
- 16490 { CTL('Y'), yank },
- 16491 { CTL('Z'), end_line },
- 16492 { CTL('['), meta },
- 16493 { CTL(']'), move_to_char },
- 16494 { CTL('^'), ring_bell },
- 16495 { CTL('_'), ring_bell },
- 16496 { 0, NULL }
- 16497 };
- 16498
- 16499 STATIC KEYMAP MetaMap[17]= {
- 16500 { CTL('H'), wipe },
- 16501 { DEL, wipe },
- 16502 { ' ', mk_set },
- 16503 { '.', last_argument },
- 16504 { '<', h_first },
- 16505 { '>', h_last },
- 16506 { '?', c_possible },
- 16507 { 'b', bk_word },
- 16508 { 'd', fd_kill_word },
- 16509 { 'f', fd_word },
- 16510 { 'l', case_down_word },
- 16511 { 'm', toggle_meta_mode },
- 16512 { 'u', case_up_word },
- 16513 { 'y', yank },
- 16514 { 'w', copy_region },
- 16515 { 0, NULL }
- 16516 };
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/sysos9.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 16600 /* $Revision: 1.1 $
- 16601 **
- 16602 ** OS-9 system-dependant routines for editline library.
- 16603 */
- 16604 #include "editline.h"
- 16605 #include <sgstat.h>
- 16606 #include <modes.h>
- 16607
- 16608
- 16609 void
- 16610 rl_ttyset(Reset)
- 16611 int Reset;
- 16612 {
- 16613 static struct sgbuf old;
- 16614 struct sgbuf new;
- 16615
- 16616
- 16617 if (Reset == 0) {
- 16618 _gs_opt(0, &old);
- 16619 _gs_opt(0, &new);
- 16620 new.sg_backsp = 0; new.sg_delete = 0; new.sg_echo = 0;
- 16621 new.sg_alf = 0; new.sg_nulls = 0; new.sg_pause = 0;
- 16622 new.sg_page = 0; new.sg_bspch = 0; new.sg_dlnch = 0;
- 16623 new.sg_eorch = 0; new.sg_eofch = 0; new.sg_rlnch = 0;
- 16624 new.sg_dulnch = 0; new.sg_psch = 0; new.sg_kbich = 0;
- 16625 new.sg_kbach = 0; new.sg_bsech = 0; new.sg_bellch = 0;
- 16626 new.sg_xon = 0; new.sg_xoff = 0; new.sg_tabcr = 0;
- 16627 new.sg_tabsiz = 0;
- 16628 _ss_opt(0, &new);
- 16629 rl_erase = old.sg_bspch;
- 16630 rl_kill = old.sg_dlnch;
- 16631 rl_eof = old.sg_eofch;
- 16632 rl_intr = old.sg_kbich;
- 16633 rl_quit = -1;
- 16634 }
- 16635 else
- 16636 _ss_opt(0, &old);
- 16637 }
-
- 16639 void
- 16640 rl_add_slash(path, p)
- 16641 char *path;
- 16642 char *p;
- 16643 {
- 16644 (void)strcat(p, access(path, S_IREAD | S_IFDIR) ? " " : "/");
- 16645 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/sysunix.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 16700 /* $Revision: 1.2 $
- 16701 **
- 16702 ** Unix system-dependant routines for editline library.
- 16703 */
- 16704 #include "editline.h"
- 16705
- 16706 #if defined(HAVE_TCGETATTR)
- 16707 #include <termios.h>
- 16708
- 16709 void
- 16710 rl_ttyset(Reset)
- 16711 int Reset;
- 16712 {
- 16713 static struct termios old;
- 16714 struct termios new;
- 16715
- 16716 if (Reset == 0) {
- 16717 (void)tcgetattr(0, &old);
- 16718 rl_erase = old.c_cc[VERASE];
- 16719 rl_kill = old.c_cc[VKILL];
- 16720 rl_eof = old.c_cc[VEOF];
- 16721 rl_intr = old.c_cc[VINTR];
- 16722 rl_quit = old.c_cc[VQUIT];
- 16723
- 16724 new = old;
- 16725 new.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN);
- 16726 new.c_cc[VMIN] = 1;
- 16727 new.c_cc[VTIME] = 0;
- 16728 (void)tcsetattr(0, TCSADRAIN, &new);
- 16729 }
- 16730 else
- 16731 (void)tcsetattr(0, TCSADRAIN, &old);
- 16732 }
-
- 16734 #else
- 16735 #if defined(HAVE_TERMIO)
- 16736 #include <termio.h>
- 16737
- 16738 void
- 16739 rl_ttyset(Reset)
- 16740 int Reset;
- 16741 {
- 16742 static struct termio old;
- 16743 struct termio new;
- 16744
- 16745 if (Reset == 0) {
- 16746 (void)ioctl(0, TCGETA, &old);
- 16747 rl_erase = old.c_cc[VERASE];
- 16748 rl_kill = old.c_cc[VKILL];
- 16749 rl_eof = old.c_cc[VEOF];
- 16750 rl_intr = old.c_cc[VINTR];
- 16751 rl_quit = old.c_cc[VQUIT];
- 16752
- 16753 new = old;
- 16754 new.c_cc[VINTR] = -1;
- 16755 new.c_cc[VQUIT] = -1;
- 16756 new.c_lflag &= ~(ECHO | ICANON);
- 16757 new.c_cc[VMIN] = 1;
- 16758 new.c_cc[VTIME] = 0;
- 16759 (void)ioctl(0, TCSETAW, &new);
- 16760 }
- 16761 else
- 16762 (void)ioctl(0, TCSETAW, &old);
- 16763 }
-
- 16765 #else
- 16766 #include <sgtty.h>
- 16767
- 16768 void
- 16769 rl_ttyset(Reset)
- 16770 int Reset;
- 16771 {
- 16772 static struct sgttyb old_sgttyb;
- 16773 static struct tchars old_tchars;
- 16774 struct sgttyb new_sgttyb;
- 16775 struct tchars new_tchars;
- 16776
- 16777 if (Reset == 0) {
- 16778 (void)ioctl(0, TIOCGETP, &old_sgttyb);
- 16779 rl_erase = old_sgttyb.sg_erase;
- 16780 rl_kill = old_sgttyb.sg_kill;
- 16781
- 16782 (void)ioctl(0, TIOCGETC, &old_tchars);
- 16783 rl_eof = old_tchars.t_eofc;
- 16784 rl_intr = old_tchars.t_intrc;
- 16785 rl_quit = old_tchars.t_quitc;
- 16786
- 16787 new_sgttyb = old_sgttyb;
- 16788 new_sgttyb.sg_flags &= ~ECHO;
- 16789 new_sgttyb.sg_flags |= RAW;
- 16790 (void)ioctl(0, TIOCSETP, &new_sgttyb);
- 16791
- 16792 new_tchars = old_tchars;
- 16793 new_tchars.t_intrc = -1;
- 16794 new_tchars.t_quitc = -1;
- 16795 (void)ioctl(0, TIOCSETC, &new_tchars);
- 16796 }
- 16797 else {
- 16798 (void)ioctl(0, TIOCSETP, &old_sgttyb);
- 16799 (void)ioctl(0, TIOCSETC, &old_tchars);
- 16800 }
- 16801 }
- 16802 #endif /* defined(HAVE_TERMIO) */
- 16803 #endif /* defined(HAVE_TCGETATTR) */
- 16804
- 16805 void
- 16806 rl_add_slash(path, p)
- 16807 char *path;
- 16808 char *p;
- 16809 {
- 16810 struct stat Sb;
- 16811
- 16812 if (stat(path, &Sb) >= 0)
- 16813 (void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
- 16814 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/testit.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 16900 /* $Revision: 1.3 $
- 16901 **
- 16902 ** A "micro-shell" to test editline library.
- 16903 ** If given any arguments, commands aren't executed.
- 16904 */
- 16905 #include <stdio.h>
- 16906 #if defined(HAVE_STDLIB)
- 16907 #include <stdlib.h>
- 16908 #endif /* defined(HAVE_STDLIB) */
- 16909
- 16910 extern char *readline();
- 16911 extern void add_history();
- 16912
- 16913 #if !defined(HAVE_STDLIB)
- 16914 extern int chdir();
- 16915 extern int free();
- 16916 extern int strncmp();
- 16917 extern int system();
- 16918 extern void exit();
- 16919 extern char *getenv();
- 16920 #endif /* !defined(HAVE_STDLIB) */
- 16921
- 16922
- 16923 #if defined(NEED_PERROR)
- 16924 void
- 16925 perror(s)
- 16926 char *s;
- 16927 {
- 16928 extern int errno;
- 16929
- 16930 (voidf)printf(stderr, "%s: error %dn", s, errno);
- 16931 }
- 16932 #endif /* defined(NEED_PERROR) */
- 16933
- 16934
- 16935 /* ARGSUSED1 */
- 16936 int
- 16937 main(ac, av)
- 16938 int ac;
- 16939 char *av[];
- 16940 {
- 16941 char *prompt;
- 16942 char *p;
- 16943 int doit;
- 16944
- 16945 doit = ac == 1;
- 16946 if ((prompt = getenv("TESTPROMPT")) == NULL)
- 16947 prompt = "testit> ";
- 16948
- 16949 while ((p = readline(prompt)) != NULL) {
- 16950 (void)printf("ttt|%s|n", p);
- 16951 if (doit)
- 16952 if (strncmp(p, "cd ", 3) == 0) {
- 16953 if (chdir(&p[3]) < 0)
- 16954 perror(&p[3]);
- 16955 }
- 16956 else if (system(p) != 0)
- 16957 perror(p);
- 16958 add_history(p);
- 16959 free(p);
- 16960 }
- 16961 exit(0);
- 16962 /* NOTREACHED */
- 16963 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/end/edata.s
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17000 #
- 17001 .sect .text
- 17002 .sect .rom
- 17003 .sect .data
- 17004 .sect .bss
- 17005 .define _edata
- 17006 .sect .data
- 17007 .align _EM_WSIZE
- 17008 _edata:
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/end/em_end.s
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17100 #
- 17101 .sect .text
- 17102 .sect .rom
- 17103 .sect .data
- 17104 .sect .bss
- 17105 .define endtext,enddata,endbss,__end
- 17106 .sect .text
- 17107 .align _EM_WSIZE
- 17108 .sect .rom
- 17109 .align _EM_WSIZE
- 17110 .sect .data
- 17111 .align _EM_WSIZE
- 17112 .sect .bss
- 17113 .align _EM_WSIZE
- 17114 .sect .end ! only for declaration of _end, __end and endbss.
- 17115
- 17116 .sect .text
- 17117 endtext:
- 17118 .sect .rom
- 17119 endrom:
- 17120 .sect .data
- 17121 enddata:
- 17122 .sect .end
- 17123 __end:
- 17124 endbss:
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/end/end.s
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17200 .sect .text
- 17201 .sect .rom
- 17202 .sect .data
- 17203 .sect .bss
- 17204 .define _end
- 17205 .sect .end ! only for declaration of _end, __end and endbss.
- 17206 _end:
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/end/etext.s
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17300 #
- 17301 .sect .text
- 17302 .sect .rom
- 17303 .sect .data
- 17304 .sect .bss
- 17305 .define _etext
- 17306 .sect .text
- 17307 .align _EM_WSIZE
- 17308 .sect .text
- 17309 _etext:
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/FP_bias.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17400 /*
- 17401 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 17402 See the copyright notice in the ACK home directory, in the file "Copyright".
- 17403 */
- 17404
- 17405 /* $Header: FP_bias.h,v 1.4 89/07/25 14:16:55 ceriel Exp $ */
- 17406
- 17407 /*
- 17408 include file for floating point package
- 17409 */
- 17410
- 17411 /* FLOAT FORMAT EXPONENT BIAS */
- 17412
- 17413 #define SGL_BIAS 127 /* excess 128 notation used */
- 17414 #define DBL_BIAS 1023 /* excess 1024 notation used */
- 17415 #define EXT_BIAS 0 /* 2s-complement notation used */
- 17416 /* this is possible because the */
- 17417 /* sign is in a seperate word */
- 17418
- 17419 /* VARIOUS MAX AND MIN VALUES */
- 17420 /* 1) FOR THE DIFFERENT FORMATS */
- 17421
- 17422 #define SGL_MAX 254 /* standard definition */
- 17423 #define SGL_MIN 1 /* standard definition */
- 17424 #define DBL_MAX 2046 /* standard definition */
- 17425 #define DBL_MIN 1 /* standard definition */
- 17426 #define EXT_MAX 16383 /* standard minimum */
- 17427 #define EXT_MIN -16382 /* standard minimum */
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/FP_shift.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17500 /*
- 17501 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 17502 See the copyright notice in the ACK home directory, in the file "Copyright".
- 17503 */
- 17504
- 17505 /* $Header: FP_shift.h,v 1.3 89/07/25 14:17:04 ceriel Exp $ */
- 17506
- 17507 /*
- 17508 include file for floating point package
- 17509 */
- 17510
- 17511 # define CARRYBIT 0x80000000L
- 17512 # define NORMBIT 0x80000000L
- 17513 # define EXP_STORE 16
- 17514
- 17515
- 17516 /* parameters for Single Precision */
- 17517 #define SGL_EXPSHIFT 7
- 17518 #define SGL_M1LEFT 8
- 17519 #define SGL_ZERO 0xffffff80L
- 17520 #define SGL_EXACT 0xff
- 17521 #define SGL_RUNPACK SGL_M1LEFT
- 17522
- 17523 #define SGL_ROUNDUP 0x80
- 17524 #define SGL_CARRYOUT 0x01000000L
- 17525 #define SGL_MASK 0x007fffffL
- 17526
- 17527 /* parameters for Double Precision */
- 17528 /* used in extend.c */
- 17529
- 17530 #define DBL_EXPSHIFT 4
- 17531
- 17532 #define DBL_M1LEFT 11
- 17533
- 17534 #define DBL_RPACK (32-DBL_M1LEFT)
- 17535 #define DBL_LPACK DBL_M1LEFT
- 17536
- 17537 /* used in compact.c */
- 17538
- 17539 #define DBL_ZERO 0xfffffd00L
- 17540
- 17541 #define DBL_EXACT 0x7ff
- 17542
- 17543 #define DBL_RUNPACK DBL_M1LEFT
- 17544 #define DBL_LUNPACK (32-DBL_RUNPACK)
- 17545
- 17546 #define DBL_ROUNDUP 0x400
- 17547 #define DBL_CARRYOUT 0x00200000L
- 17548 #define DBL_MASK 0x000fffffL
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/FP_trap.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17600 /*
- 17601 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 17602 See the copyright notice in the ACK home directory, in the file "Copyright".
- 17603 */
- 17604
- 17605 /* $Header: FP_trap.h,v 1.2 88/04/07 11:33:06 ceriel Exp $ */
- 17606
- 17607 /*
- 17608 include file for floating point package
- 17609 */
- 17610
- 17611 /* EM TRAPS */
- 17612
- 17613 #define EIOVFL 3 /* Integer Overflow */
- 17614 #define EFOVFL 4 /* Floating Overflow */
- 17615 #define EFUNFL 5 /* Floating Underflow */
- 17616 #define EIDIVZ 6 /* Integer Divide by 0 */
- 17617 #define EFDIVZ 7 /* Floating Divide by 0.0 */
- 17618 #define EIUND 8 /* Integer Undefined Number */
- 17619 #define EFUND 9 /* Floating Undefined Number */
- 17620 #define ECONV 10 /* Conversion Error */
- 17621 # define trap(x) _fptrp(x)
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/FP_types.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17700 /*
- 17701 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 17702 See the copyright notice in the ACK home directory, in the file "Copyright".
- 17703 */
- 17704
- 17705 /* $Header: FP_types.h,v 1.4 93/01/05 12:03:05 ceriel Exp $ */
- 17706
- 17707 /********************************************************/
- 17708 /*
- 17709 Type definitions for C Floating Point Package
- 17710 include file for floating point package
- 17711 */
- 17712 /********************************************************/
- 17713 /*
- 17714 THESE STRUCTURES ARE USED TO ADDRESS THE INDIVIDUAL
- 17715 PARTS OF THE FLOATING POINT NUMBER REPRESENTATIONS.
- 17716
- 17717 THREE STRUCTURES ARE DEFINED:
- 17718 SINGLE: single precision floating format
- 17719 DOUBLE: double precision floating format
- 17720 EXTEND: double precision extended format
- 17721 */
- 17722 /********************************************************/
- 17723
- 17724 #ifndef __FPTYPES
- 17725 #define __FPTYPES
- 17726
- 17727 typedef struct {
- 17728 unsigned long h_32; /* higher 32 bits of 64 */
- 17729 unsigned long l_32; /* lower 32 bits of 64 */
- 17730 } B64;
- 17731
- 17732 typedef unsigned long SINGLE;
- 17733
- 17734 typedef struct {
- 17735 unsigned long d[2];
- 17736 } DOUBLE;
- 17737
- 17738 typedef struct { /* expanded float format */
- 17739 short sign;
- 17740 short exp;
- 17741 B64 mantissa;
- 17742 #define m1 mantissa.h_32
- 17743 #define m2 mantissa.l_32
- 17744 } EXTEND;
- 17745
- 17746 struct fef4_returns {
- 17747 int e;
- 17748 SINGLE f;
- 17749 };
- 17750
- 17751 struct fef8_returns {
- 17752 int e;
- 17753 DOUBLE f;
- 17754 };
- 17755
- 17756 struct fif4_returns {
- 17757 SINGLE ipart;
- 17758 SINGLE fpart;
- 17759 };
- 17760
- 17761 struct fif8_returns {
- 17762 DOUBLE ipart;
- 17763 DOUBLE fpart;
- 17764 };
- 17765
- 17766 #if __STDC__
- 17767 #define _PROTOTYPE(function, params) function params
- 17768 #else
- 17769 #define _PROTOTYPE(function, params) function()
- 17770 #endif
- 17771 _PROTOTYPE( void add_ext, (EXTEND *e1, EXTEND *e2));
- 17772 _PROTOTYPE( void mul_ext, (EXTEND *e1, EXTEND *e2));
- 17773 _PROTOTYPE( void div_ext, (EXTEND *e1, EXTEND *e2));
- 17774 _PROTOTYPE( void sub_ext, (EXTEND *e1, EXTEND *e2));
- 17775 _PROTOTYPE( void sft_ext, (EXTEND *e1, EXTEND *e2));
- 17776 _PROTOTYPE( void nrm_ext, (EXTEND *e1));
- 17777 _PROTOTYPE( void zrf_ext, (EXTEND *e1));
- 17778 _PROTOTYPE( void extend, (unsigned long *from, EXTEND *to, int size));
- 17779 _PROTOTYPE( void compact, (EXTEND *from, unsigned long *to, int size));
- 17780 _PROTOTYPE( void _fptrp, (int));
- 17781 _PROTOTYPE( void adf4, (SINGLE s2, SINGLE s1));
- 17782 _PROTOTYPE( void adf8, (DOUBLE s2, DOUBLE s1));
- 17783 _PROTOTYPE( void sbf4, (SINGLE s2, SINGLE s1));
- 17784 _PROTOTYPE( void sbf8, (DOUBLE s2, DOUBLE s1));
- 17785 _PROTOTYPE( void dvf4, (SINGLE s2, SINGLE s1));
- 17786 _PROTOTYPE( void dvf8, (DOUBLE s2, DOUBLE s1));
- 17787 _PROTOTYPE( void mlf4, (SINGLE s2, SINGLE s1));
- 17788 _PROTOTYPE( void mlf8, (DOUBLE s2, DOUBLE s1));
- 17789 _PROTOTYPE( void ngf4, (SINGLE f));
- 17790 _PROTOTYPE( void ngf8, (DOUBLE f));
- 17791 _PROTOTYPE( void zrf4, (SINGLE *l));
- 17792 _PROTOTYPE( void zrf8, (DOUBLE *z));
- 17793 _PROTOTYPE( void cff4, (DOUBLE src));
- 17794 _PROTOTYPE( void cff8, (SINGLE src));
- 17795 _PROTOTYPE( void cif4, (int ss, long src));
- 17796 _PROTOTYPE( void cif8, (int ss, long src));
- 17797 _PROTOTYPE( void cuf4, (int ss, long src));
- 17798 _PROTOTYPE( void cuf8, (int ss, long src));
- 17799 _PROTOTYPE( long cfu, (int ds, int ss, DOUBLE src));
- 17800 _PROTOTYPE( long cfi, (int ds, int ss, DOUBLE src));
- 17801 _PROTOTYPE( int cmf4, (SINGLE s2, SINGLE s1));
- 17802 _PROTOTYPE( int cmf8, (DOUBLE d1, DOUBLE d2));
- 17803 _PROTOTYPE( void fef4, (struct fef4_returns *r, SINGLE s1));
- 17804 _PROTOTYPE( void fef8, (struct fef8_returns *r, DOUBLE s1));
- 17805 _PROTOTYPE( void fif4, (struct fif4_returns *p, SINGLE x, SINGLE y));
- 17806 _PROTOTYPE( void fif8, (struct fif8_returns *p, DOUBLE x, DOUBLE y));
- 17807
- 17808 _PROTOTYPE( void b64_sft, (B64 *, int));
- 17809 _PROTOTYPE( void b64_lsft, (B64 *));
- 17810 _PROTOTYPE( void b64_rsft, (B64 *));
- 17811 _PROTOTYPE( int b64_add, (B64 *, B64 *));
- 17812 #endif
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/adder.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 17900 /*
- 17901 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 17902 See the copyright notice in the ACK home directory, in the file "Copyright".
- 17903 */
- 17904
- 17905 /* $Header: adder.h,v 1.2 92/02/20 18:20:25 philip Exp $ */
- 17906
- 17907 /*
- 17908 * include file for 32 & 64 bit addition
- 17909 */
- 17910
- 17911 typedef struct B64 {
- 17912 unsigned long h_32; /* higher 32 bits of 64 */
- 17913 unsigned long l_32; /* lower 32 bits of 64 */
- 17914 } B64;
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/byte_order.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18000 #define CHAR_UNSIGNED 0
- 18001 #define MSB_AT_LOW_ADDRESS 0
- 18002 #define MSW_AT_LOW_ADDRESS 0
- 18003 #define FL_MSB_AT_LOW_ADDRESS 0
- 18004 #define FL_MSW_AT_LOW_ADDRESS 0
- 18005 #define FL_MSL_AT_LOW_ADDRESS 0
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/get_put.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18100 /*
- 18101 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18102 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18103 */
- 18104
- 18105 /* $Header: get_put.h,v 1.3 89/10/25 17:15:01 ceriel Exp $ */
- 18106
- 18107 #include <byte_order.h>
- 18108
- 18109 #if CHAR_UNSIGNED
- 18110 #define Xchar(ch) (ch)
- 18111 #else
- 18112 #define Xchar(ch) ((ch) & 0377)
- 18113 #endif
- 18114
- 18115 #define BYTES_REVERSED (MSB_AT_LOW_ADDRESS != FL_MSB_AT_LOW_ADDRESS)
- 18116 #define WORDS_REVERSED (MSW_AT_LOW_ADDRESS != FL_MSW_AT_LOW_ADDRESS)
- 18117 #define LONGS_REVERSED (FL_MSL_AT_LOW_ADDRESS)
- 18118
- 18119 #if BYTES_REVERSED
- 18120 #define uget2(c) (Xchar((c)[1]) | ((unsigned) Xchar((c)[0]) << 8))
- 18121 #define Xput2(i, c) (((c)[1] = (i)), ((c)[0] = (i) >> 8))
- 18122 #define put2(i, c) { register int j = (i); Xput2(j, c); }
- 18123 #else
- 18124 #define uget2(c) (* ((unsigned short *) (c)))
- 18125 #define Xput2(i, c) (* ((short *) (c)) = (i))
- 18126 #define put2(i, c) Xput2(i, c)
- 18127 #endif
- 18128
- 18129 #define get2(c) ((short) uget2(c))
- 18130
- 18131 #if WORDS_REVERSED || BYTES_REVERSED
- 18132 #define get4(c) (uget2((c)+2) | ((long) uget2(c) << 16))
- 18133 #define put4(l, c) { register long x=(l);
- 18134 Xput2((int)x,(c)+2);
- 18135 Xput2((int)(x>>16),(c));
- 18136 }
- 18137 #else
- 18138 #define get4(c) (* ((long *) (c)))
- 18139 #define put4(l, c) (* ((long *) (c)) = (l))
- 18140 #endif
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/add_ext.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18200 /*
- 18201 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18202 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18203 */
- 18204
- 18205 /* $Header: add_ext.c,v 1.7 93/01/05 12:03:11 ceriel Exp $ */
- 18206
- 18207 /*
- 18208 ADD TWO EXTENDED FORMAT NUMBERS
- 18209 */
- 18210
- 18211 #include "FP_types.h"
- 18212
- 18213 void
- 18214 add_ext(e1,e2)
- 18215 register EXTEND *e1,*e2;
- 18216 {
- 18217 if ((e2->m1 | e2->m2) == 0L) {
- 18218 return;
- 18219 }
- 18220 if ((e1->m1 | e1->m2) == 0L) {
- 18221 *e1 = *e2;
- 18222 return;
- 18223 }
- 18224 sft_ext(e1, e2); /* adjust mantissas to equal powers */
- 18225 if (e1->sign != e2->sign) {
- 18226 /* e1 + e2 = e1 - (-e2) */
- 18227 if (e2->m1 > e1->m1 ||
- 18228 (e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
- 18229 /* abs(e2) > abs(e1) */
- 18230 EXTEND x;
- 18231
- 18232 x = *e1;
- 18233 *e1 = *e2;
- 18234 if (x.m2 > e1->m2) {
- 18235 e1->m1 -= 1; /* carry in */
- 18236 }
- 18237 e1->m1 -= x.m1;
- 18238 e1->m2 -= x.m2;
- 18239 }
- 18240 else {
- 18241 if (e2->m2 > e1->m2)
- 18242 e1->m1 -= 1; /* carry in */
- 18243 e1->m1 -= e2->m1;
- 18244 e1->m2 -= e2->m2;
- 18245 }
- 18246 }
- 18247 else {
- 18248 if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
- 18249 b64_rsft(&e1->mantissa); /* shift mantissa one bit RIGHT */
- 18250 e1->m1 |= 0x80000000L; /* set max bit */
- 18251 e1->exp++; /* increase the exponent */
- 18252 }
- 18253 }
- 18254 nrm_ext(e1);
- 18255 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/adder.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18300 /*
- 18301 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18302 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18303 */
- 18304
- 18305 /* $Header: adder.c,v 1.6 93/01/05 12:03:17 ceriel Exp $ */
- 18306
- 18307 /*
- 18308 * these are the routines the routines to do 32 and 64-bit addition
- 18309 */
- 18310
- 18311 # ifdef EXT_DEBUG
- 18312 # include <stdio.h>
- 18313 # endif
- 18314
- 18315 # include "FP_types.h"
- 18316 # define UNKNOWN -1
- 18317 # define TRUE 1
- 18318 # define FALSE 0
- 18319 # define MAXBIT 0x80000000L
- 18320
- 18321 /*
- 18322 * add 64 bits
- 18323 */
- 18324 int
- 18325 b64_add(e1,e2)
- 18326 /*
- 18327 * pointers to 64 bit 'registers'
- 18328 */
- 18329 register B64 *e1,*e2;
- 18330 {
- 18331 register int overflow;
- 18332 int carry;
- 18333
- 18334 /* add higher pair of 32 bits */
- 18335 overflow = ((unsigned long) 0xFFFFFFFF - e1->h_32 < e2->h_32);
- 18336 e1->h_32 += e2->h_32;
- 18337
- 18338 /* add lower pair of 32 bits */
- 18339 carry = ((unsigned long) 0xFFFFFFFF - e1->l_32 < e2->l_32);
- 18340 e1->l_32 += e2->l_32;
- 18341 # ifdef EXT_DEBUG
- 18342 printf("tttttb64_add: overflow (%d); internal carry(%d)n",
- 18343 overflow,carry);
- 18344 fflush(stdout);
- 18345 # endif
- 18346 if ((carry) && (++e1->h_32 == 0))
- 18347 return(TRUE); /* had a 64 bit overflow */
- 18348 return(overflow); /* return status from higher add */
- 18349 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/adf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18400 /*
- 18401 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18402 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18403 */
- 18404
- 18405 /* $Header: adf4.c,v 1.7 93/01/05 12:03:23 ceriel Exp $ */
- 18406
- 18407 /*
- 18408 ADD TWO FLOATS - SINGLE (ADF 4)
- 18409 */
- 18410
- 18411 #include "FP_types.h"
- 18412
- 18413 void
- 18414 adf4(s2,s1)
- 18415 SINGLE s1,s2;
- 18416 {
- 18417 EXTEND e1,e2;
- 18418 int swap = 0;
- 18419
- 18420 if (s1 == (SINGLE) 0) {
- 18421 s1 = s2;
- 18422 return;
- 18423 }
- 18424 if (s2 == (SINGLE) 0) {
- 18425 return;
- 18426 }
- 18427 extend(&s1,&e1,sizeof(SINGLE));
- 18428 extend(&s2,&e2,sizeof(SINGLE));
- 18429 add_ext(&e1,&e2);
- 18430 compact(&e1,&s1,sizeof(SINGLE));
- 18431 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/adf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18500 /*
- 18501 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18502 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18503 */
- 18504
- 18505 /* $Header: adf8.c,v 1.7 93/01/05 12:03:29 ceriel Exp $ */
- 18506
- 18507 /*
- 18508 ADD TWO FLOATS - DOUBLE (ADF 8)
- 18509 */
- 18510
- 18511 #include "FP_types.h"
- 18512
- 18513 void
- 18514 adf8(s2,s1)
- 18515 DOUBLE s1,s2;
- 18516 {
- 18517 EXTEND e1,e2;
- 18518
- 18519 if (s1.d[0] == 0 && s1.d[1] == 0) {
- 18520 s1 = s2;
- 18521 return;
- 18522 }
- 18523 if (s2.d[0] == 0 && s2.d[1] == 0) {
- 18524 return;
- 18525 }
- 18526
- 18527 extend(&s1.d[0],&e1,sizeof(DOUBLE));
- 18528 extend(&s2.d[0],&e2,sizeof(DOUBLE));
- 18529 add_ext(&e1,&e2);
- 18530 compact(&e1,&s1.d[0],sizeof(DOUBLE));
- 18531 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cff4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18600 /*
- 18601 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18602 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18603 */
- 18604
- 18605 /* $Header: cff4.c,v 1.5 93/01/05 12:03:36 ceriel Exp $ */
- 18606
- 18607 /*
- 18608 CONVERT DOUBLE TO SINGLE (CFF 8 4)
- 18609
- 18610 This routine works quite simply. A floating point
- 18611 of size 08 is converted to extended format.
- 18612 This extended variable is converted back to
- 18613 a floating point of size 04.
- 18614
- 18615 */
- 18616
- 18617 #include "FP_types.h"
- 18618
- 18619 void
- 18620 cff4(src)
- 18621 DOUBLE src; /* the source itself - THIS TIME it's DOUBLE */
- 18622 {
- 18623 EXTEND buf;
- 18624
- 18625 extend(&src.d[0],&buf,sizeof(DOUBLE)); /* no matter what */
- 18626 compact(&buf,&(src.d[1]),sizeof(SINGLE));
- 18627 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cff8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18700 /*
- 18701 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18702 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18703 */
- 18704
- 18705 /* $Header: cff8.c,v 1.5 93/01/05 12:03:41 ceriel Exp $ */
- 18706
- 18707 /*
- 18708 CONVERT SINGLE TO DOUBLE (CFF 4 8)
- 18709
- 18710 This routine works quite simply. A floating point
- 18711 of size 04 is converted to extended format.
- 18712 This extended variable is converted back to
- 18713 a floating point of size 08.
- 18714
- 18715 */
- 18716
- 18717 #include "FP_types.h"
- 18718
- 18719 void
- 18720 cff8(src)
- 18721 SINGLE src;
- 18722 {
- 18723 EXTEND buf;
- 18724
- 18725 extend(&src,&buf,sizeof(SINGLE)); /* no matter what */
- 18726 compact(&buf, &src,sizeof(DOUBLE));
- 18727 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cfi.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18800 /*
- 18801 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18802 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18803 */
- 18804
- 18805 /* $Header: cfi.c,v 1.5 93/01/05 12:03:48 ceriel Exp $ */
- 18806
- 18807 /*
- 18808 CONVERT FLOAT TO SIGNED (CFI m n)
- 18809
- 18810 N.B. The caller must know what it is getting.
- 18811 A LONG is always returned. If it is an
- 18812 integer the high byte is cleared first.
- 18813 */
- 18814
- 18815 #include "FP_trap.h"
- 18816 #include "FP_types.h"
- 18817 #include "FP_shift.h"
- 18818
- 18819 long
- 18820 cfi(ds,ss,src)
- 18821 int ds; /* destination size (2 or 4) */
- 18822 int ss; /* source size (4 or 8) */
- 18823 DOUBLE src; /* assume worst case */
- 18824 {
- 18825 EXTEND buf;
- 18826 long new;
- 18827 short max_exp;
- 18828
- 18829 extend(&src.d[0],&buf,ss); /* get extended format */
- 18830 if (buf.exp < 0) { /* no conversion needed */
- 18831 src.d[ss == 8] = 0L;
- 18832 return(0L);
- 18833 }
- 18834 max_exp = (ds << 3) - 2; /* signed numbers */
- 18835 /* have more limited max_exp */
- 18836 if (buf.exp > max_exp) {
- 18837 if (buf.exp == max_exp+1 && buf.sign && buf.m1 == NORMBIT &&
- 18838 buf.m2 == 0L) {
- 18839 }
- 18840 else {
- 18841 trap(EIOVFL); /* integer overflow */
- 18842 buf.exp %= max_exp; /* truncate */
- 18843 }
- 18844 }
- 18845 new = buf.m1 >> (31-buf.exp);
- 18846 if (buf.sign)
- 18847 new = -new;
- 18848 done:
- 18849 src.d[ss == 8] = new;
- 18850 return(new);
- 18851 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cfu.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 18900 /*
- 18901 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 18902 See the copyright notice in the ACK home directory, in the file "Copyright".
- 18903 */
- 18904
- 18905 /* $Header: cfu.c,v 1.5 93/01/05 12:03:55 ceriel Exp $ */
- 18906
- 18907 /*
- 18908 CONVERT FLOAT TO UNSIGNED (CFU m n)
- 18909
- 18910 N.B. The caller must know what it is getting.
- 18911 A LONG is always returned. If it is an
- 18912 integer the high byte is cleared first.
- 18913 */
- 18914
- 18915 #include "FP_trap.h"
- 18916 #include "FP_types.h"
- 18917
- 18918 long
- 18919 cfu(ds,ss,src)
- 18920 int ds; /* destination size (2 or 4) */
- 18921 int ss; /* source size (4 or 8) */
- 18922 DOUBLE src; /* assume worst case */
- 18923 {
- 18924 EXTEND buf;
- 18925 long new;
- 18926 short newint, max_exp;
- 18927
- 18928 extend(&src.d[0],&buf,ss); /* get extended format */
- 18929 if (buf.exp < 0) { /* no conversion needed */
- 18930 src.d[ss == 8] = 0L;
- 18931 return(0L);
- 18932 }
- 18933 max_exp = (ds << 3) - 1;
- 18934 if (buf.exp > max_exp) {
- 18935 trap(EIOVFL); /* integer overflow */
- 18936 buf.exp %= max_exp;
- 18937 }
- 18938 new = buf.m1 >> (31-buf.exp);
- 18939 done:
- 18940 src.d[ss == 8] = new;
- 18941 return(new);
- 18942 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cif4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19000 /*
- 19001 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19002 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19003 */
- 19004
- 19005 /* $Header: cif4.c,v 1.5 93/01/05 12:04:01 ceriel Exp $ */
- 19006
- 19007 /*
- 19008 CONVERT INTEGER TO SINGLE (CIF n 4)
- 19009
- 19010 THIS ROUTINE WORKS BY FILLING AN EXTENDED
- 19011 WITH THE INTEGER VALUE IN EXTENDED FORMAT
- 19012 AND USES COMPACT() TO PUT IT INTO THE PROPER
- 19013 FLOATING POINT PRECISION.
- 19014 */
- 19015
- 19016 #include "FP_types.h"
- 19017
- 19018 void
- 19019 cif4(ss,src)
- 19020 int ss; /* source size */
- 19021 long src; /* largest possible integer to convert */
- 19022 {
- 19023 EXTEND buf;
- 19024 short *ipt;
- 19025 long i_src;
- 19026 SINGLE *result;
- 19027
- 19028 zrf_ext(&buf);
- 19029 if (ss == sizeof(long)) {
- 19030 buf.exp = 31;
- 19031 i_src = src;
- 19032 result = (SINGLE *) &src;
- 19033 }
- 19034 else {
- 19035 ipt = (short *) &src;
- 19036 i_src = (long) *ipt;
- 19037 buf.exp = 15;
- 19038 result = (SINGLE *) &ss;
- 19039 }
- 19040 if (i_src == 0) {
- 19041 *result = (SINGLE) 0L;
- 19042 return;
- 19043 }
- 19044 /* ESTABLISHED THAT src != 0 */
- 19045 /* adjust exponent field */
- 19046 buf.sign = (i_src < 0) ? 0x8000 : 0;
- 19047 /* clear sign bit of integer */
- 19048 /* move to mantissa field */
- 19049 buf.m1 = (i_src < 0) ? -i_src : i_src;
- 19050 /* adjust mantissa field */
- 19051 if (ss != sizeof(long))
- 19052 buf.m1 <<= 16;
- 19053 nrm_ext(&buf); /* adjust mantissa field */
- 19054 compact(&buf, result,sizeof(SINGLE)); /* put on stack */
- 19055 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cif8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19100 /*
- 19101 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19102 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19103 */
- 19104
- 19105 /* $Header: cif8.c,v 1.5 93/01/05 12:04:07 ceriel Exp $ */
- 19106
- 19107 /*
- 19108 CONVERT INTEGER TO FLOAT (CIF n 8)
- 19109
- 19110 THIS ROUTINE WORKS BY FILLING AN EXTENDED
- 19111 WITH THE INTEGER VALUE IN EXTENDED FORMAT
- 19112 AND USES COMPACT() TO PUT IT INTO THE PROPER
- 19113 FLOATING POINT PRECISION.
- 19114 */
- 19115
- 19116 #include "FP_types.h"
- 19117
- 19118 void
- 19119 cif8(ss,src)
- 19120 int ss; /* source size */
- 19121 long src; /* largest possible integer to convert */
- 19122 {
- 19123 EXTEND buf;
- 19124 DOUBLE *result; /* for return value */
- 19125 short *ipt;
- 19126 long i_src;
- 19127
- 19128 result = (DOUBLE *) ((void *) &ss); /* always */
- 19129 zrf_ext(&buf);
- 19130 if (ss == sizeof(long)) {
- 19131 buf.exp = 31;
- 19132 i_src = src;
- 19133 }
- 19134 else {
- 19135 ipt = (short *) &src;
- 19136 i_src = (long) *ipt;
- 19137 buf.exp = 15;
- 19138 }
- 19139 if (i_src == 0) {
- 19140 zrf8(result);
- 19141 return;
- 19142 }
- 19143 /* ESTABLISHED THAT src != 0 */
- 19144 /* adjust exponent field */
- 19145 buf.sign = (i_src < 0) ? 0x8000 : 0;
- 19146 /* clear sign bit of integer */
- 19147 /* move to mantissa field */
- 19148 buf.m1 = (i_src < 0) ? -i_src : i_src;
- 19149 /* adjust mantissa field */
- 19150 if (ss != sizeof(long))
- 19151 buf.m1 <<= 16;
- 19152 nrm_ext(&buf);
- 19153 compact(&buf,&result->d[0],8);
- 19154 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cmf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19200 /*
- 19201 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19202 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19203 */
- 19204
- 19205 /* $Header: cmf4.c,v 1.6 93/01/05 12:04:14 ceriel Exp $ */
- 19206
- 19207 /*
- 19208 COMPARE SINGLES (CMF 4)
- 19209 */
- 19210
- 19211 #include "FP_types.h"
- 19212 #include "get_put.h"
- 19213
- 19214 int
- 19215 cmf4(f1,f2)
- 19216 SINGLE f1,f2;
- 19217 {
- 19218 /*
- 19219 * return ((f1 < f2) ? 1 : (f1 - f2))
- 19220 */
- 19221 #define SIGN(x) (((x) < 0) ? -1 : 1)
- 19222 int sign1,sign2;
- 19223 long l1,l2;
- 19224
- 19225 l1 = get4((char *) &f1);
- 19226 l2 = get4((char *) &f2);
- 19227
- 19228 if (l1 == l2) return 0;
- 19229
- 19230 sign1 = SIGN(l1);
- 19231 sign2 = SIGN(l2);
- 19232 if (sign1 != sign2) {
- 19233 if ((l1 & 0x7fffffff) == 0 &&
- 19234 (l2 & 0x7fffffff) == 0) return 0;
- 19235 return ((sign1 > 0) ? -1 : 1);
- 19236 }
- 19237
- 19238 return (sign1 * ((l1 < l2) ? 1 : -1));
- 19239 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cmf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19300 /*
- 19301 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19302 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19303 */
- 19304
- 19305 /* $Header: cmf8.c,v 1.9 93/01/05 12:04:22 ceriel Exp $ */
- 19306
- 19307 /*
- 19308 COMPARE DOUBLES (CMF 8)
- 19309 */
- 19310
- 19311 #include "FP_types.h"
- 19312 #include "get_put.h"
- 19313
- 19314 int
- 19315 cmf8(d1,d2)
- 19316 DOUBLE d1,d2;
- 19317 {
- 19318 #define SIGN(x) (((x) < 0) ? -1 : 1)
- 19319 /*
- 19320 * return ((d1 < d2) ? 1 : (d1 > d2) ? -1 : 0))
- 19321 */
- 19322 long l1,l2;
- 19323 int sign1,sign2;
- 19324 int rv;
- 19325
- 19326 #if FL_MSL_AT_LOW_ADDRESS
- 19327 l1 = get4((char *)&d1);
- 19328 l2 = get4((char *)&d2);
- 19329 #else
- 19330 l1 = get4(((char *)&d1+4));
- 19331 l2 = get4(((char *)&d2+4));
- 19332 #endif
- 19333 sign1 = SIGN(l1);
- 19334 sign2 = SIGN(l2);
- 19335 if (sign1 != sign2) {
- 19336 l1 &= 0x7fffffff;
- 19337 l2 &= 0x7fffffff;
- 19338 if (l1 != 0 || l2 != 0) {
- 19339 return ((sign1 > 0) ? -1 : 1);
- 19340 }
- 19341 }
- 19342 if (l1 != l2) { /* we can decide here */
- 19343 rv = l1 < l2 ? 1 : -1;
- 19344 }
- 19345 else { /* decide in 2nd half */
- 19346 unsigned long u1, u2;
- 19347 #if FL_MSL_AT_LOW_ADDRESS
- 19348 u1 = get4(((char *)&d1 + 4));
- 19349 u2 = get4(((char *)&d2 + 4));
- 19350 #else
- 19351 u1 = get4((char *)&d1);
- 19352 u2 = get4((char *)&d2);
- 19353 #endif
- 19354 if (u1 == u2)
- 19355 return(0);
- 19356 if (u1 < u2) rv = 1;
- 19357 else rv = -1;
- 19358 }
- 19359 return sign1 * rv;
- 19360 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/compact.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19400 /*
- 19401 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19402 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19403 */
- 19404
- 19405 /* $Header: compact.c,v 1.13 93/01/05 12:04:28 ceriel Exp $ */
- 19406
- 19407 /*
- 19408 COMPACT EXTEND FORMAT INTO FLOAT OF PROPER SIZE
- 19409 */
- 19410
- 19411 # include "FP_bias.h"
- 19412 # include "FP_shift.h"
- 19413 # include "FP_trap.h"
- 19414 # include "FP_types.h"
- 19415 # include "get_put.h"
- 19416
- 19417 void
- 19418 compact(f,to,size)
- 19419 EXTEND *f;
- 19420 unsigned long *to;
- 19421 int size;
- 19422 {
- 19423 int error = 0;
- 19424
- 19425 if (size == sizeof(DOUBLE)) {
- 19426 /*
- 19427 * COMPACT EXTENDED INTO DOUBLE
- 19428 */
- 19429 DOUBLE *DBL = (DOUBLE *) (void *) to;
- 19430
- 19431 if ((f->m1|(f->m2 & DBL_ZERO)) == 0L) {
- 19432 zrf8(DBL);
- 19433 return;
- 19434 }
- 19435 f->exp += DBL_BIAS; /* restore proper bias */
- 19436 if (f->exp > DBL_MAX) {
- 19437 dbl_over: trap(EFOVFL);
- 19438 f->exp = DBL_MAX+1;
- 19439 f->m1 = 0;
- 19440 f->m2 = 0;
- 19441 if (error++)
- 19442 return;
- 19443 }
- 19444 else if (f->exp < DBL_MIN) {
- 19445 b64_rsft(&(f->mantissa));
- 19446 if (f->exp < 0) {
- 19447 b64_sft(&(f->mantissa), -f->exp);
- 19448 f->exp = 0;
- 19449 }
- 19450 /* underflow ??? */
- 19451 }
- 19452
- 19453 /* local CAST conversion */
- 19454
- 19455 /* because of special format shift only 10 bits */
- 19456 /* bit shift mantissa 10 bits */
- 19457
- 19458 /* first align within words, then do store operation */
- 19459
- 19460 DBL->d[0] = f->m1 >> DBL_RUNPACK; /* plus 22 == 32 */
- 19461 DBL->d[1] = f->m2 >> DBL_RUNPACK; /* plus 22 == 32 */
- 19462 DBL->d[1] |= (f->m1 << DBL_LUNPACK); /* plus 10 == 32 */
- 19463
- 19464 /* if not exact then round to nearest */
- 19465 /* on a tie, round to even */
- 19466
- 19467 #ifdef EXCEPTION_INEXACT
- 19468 if ((f->m2 & DBL_EXACT) != 0) {
- 19469 INEXACT();
- 19470 #endif
- 19471 if (((f->m2 & DBL_EXACT) > DBL_ROUNDUP)
- 19472 || ((f->m2 & DBL_EXACT) == DBL_ROUNDUP
- 19473 && (f->m2 & (DBL_ROUNDUP << 1)))) {
- 19474 DBL->d[1]++; /* rounding up */
- 19475 if (DBL->d[1] == 0L) { /* carry out */
- 19476 DBL->d[0]++;
- 19477
- 19478 if (f->exp == 0 && (DBL->d[0] & ~DBL_MASK)) {
- 19479 f->exp++;
- 19480 }
- 19481 if (DBL->d[0] & DBL_CARRYOUT) { /* carry out */
- 19482 if (DBL->d[0] & 01)
- 19483 DBL->d[1] = CARRYBIT;
- 19484 DBL->d[0] >>= 1;
- 19485 f->exp++;
- 19486 }
- 19487 }
- 19488 /* check for overflow */
- 19489 if (f->exp > DBL_MAX)
- 19490 goto dbl_over;
- 19491 }
- 19492 #ifdef EXCEPTION_INEXACT
- 19493 }
- 19494 #endif
- 19495
- 19496 /*
- 19497 * STORE EXPONENT AND SIGN:
- 19498 *
- 19499 * 1) clear leading bits (B4-B15)
- 19500 * 2) shift and store exponent
- 19501 */
- 19502
- 19503 DBL->d[0] &= DBL_MASK;
- 19504 DBL->d[0] |=
- 19505 ((long) (f->exp << DBL_EXPSHIFT) << EXP_STORE);
- 19506 if (f->sign)
- 19507 DBL->d[0] |= CARRYBIT;
- 19508
- 19509 /*
- 19510 * STORE MANTISSA
- 19511 */
- 19512
- 19513 #if FL_MSL_AT_LOW_ADDRESS
- 19514 put4(DBL->d[0], (char *) &DBL->d[0]);
- 19515 put4(DBL->d[1], (char *) &DBL->d[1]);
- 19516 #else
- 19517 { unsigned long l;
- 19518 put4(DBL->d[1], (char *) &l);
- 19519 put4(DBL->d[0], (char *) &DBL->d[1]);
- 19520 DBL->d[0] = l;
- 19521 }
- 19522 #endif
- 19523 }
- 19524 else {
- 19525 /*
- 19526 * COMPACT EXTENDED INTO FLOAT
- 19527 */
- 19528 SINGLE *SGL;
- 19529
- 19530 /* local CAST conversion */
- 19531 SGL = (SINGLE *) (void *) to;
- 19532 if ((f->m1 & SGL_ZERO) == 0L) {
- 19533 *SGL = 0L;
- 19534 return;
- 19535 }
- 19536 f->exp += SGL_BIAS; /* restore bias */
- 19537 if (f->exp > SGL_MAX) {
- 19538 sgl_over: trap(EFOVFL);
- 19539 f->exp = SGL_MAX+1;
- 19540 f->m1 = 0L;
- 19541 f->m2 = 0L;
- 19542 if (error++)
- 19543 return;
- 19544 }
- 19545 else if (f->exp < SGL_MIN) {
- 19546 b64_rsft(&(f->mantissa));
- 19547 if (f->exp < 0) {
- 19548 b64_sft(&(f->mantissa), -f->exp);
- 19549 f->exp = 0;
- 19550 }
- 19551 /* underflow ??? */
- 19552 }
- 19553
- 19554 /* shift mantissa and store */
- 19555 *SGL = (f->m1 >> SGL_RUNPACK);
- 19556
- 19557 /* check for rounding to nearest */
- 19558 /* on a tie, round to even */
- 19559 #ifdef EXCEPTION_INEXACT
- 19560 if (f->m2 != 0 ||
- 19561 (f->m1 & SGL_EXACT) != 0L) {
- 19562 INEXACT();
- 19563 #endif
- 19564 if (((f->m1 & SGL_EXACT) > SGL_ROUNDUP)
- 19565 || ((f->m1 & SGL_EXACT) == SGL_ROUNDUP
- 19566 && (f->m1 & (SGL_ROUNDUP << 1)))) {
- 19567 (*SGL)++;
- 19568 if (f->exp == 0 && (*SGL & ~SGL_MASK)) {
- 19569 f->exp++;
- 19570 }
- 19571 /* check normal */
- 19572 if (*SGL & SGL_CARRYOUT) {
- 19573 *SGL >>= 1;
- 19574 f->exp++;
- 19575 }
- 19576 if (f->exp > SGL_MAX)
- 19577 goto sgl_over;
- 19578 }
- 19579 #ifdef EXCEPTION_INEXACT
- 19580 }
- 19581 #endif
- 19582
- 19583 /*
- 19584 * STORE EXPONENT AND SIGN:
- 19585 *
- 19586 * 1) clear leading bit of fraction
- 19587 * 2) shift and store exponent
- 19588 */
- 19589
- 19590 *SGL &= SGL_MASK; /* B23-B31 are 0 */
- 19591 *SGL |= ((long) (f->exp << SGL_EXPSHIFT) << EXP_STORE);
- 19592 if (f->sign)
- 19593 *SGL |= CARRYBIT;
- 19594
- 19595 /*
- 19596 * STORE MANTISSA
- 19597 */
- 19598
- 19599 put4(*SGL, (char *) &SGL);
- 19600 }
- 19601 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cuf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19700 /*
- 19701 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19702 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19703 */
- 19704
- 19705 /* $Header: cuf4.c,v 1.6 93/01/05 12:04:35 ceriel Exp $ */
- 19706
- 19707 /*
- 19708 CONVERT INTEGER TO SINGLE (CUF n 4)
- 19709
- 19710 THIS ROUTINE WORKS BY FILLING AN EXTENDED
- 19711 WITH THE INTEGER VALUE IN EXTENDED FORMAT
- 19712 AND USES COMPACT() TO PUT IT INTO THE PROPER
- 19713 FLOATING POINT PRECISION.
- 19714 */
- 19715
- 19716 #include "FP_types.h"
- 19717
- 19718 void
- 19719 cuf4(ss,src)
- 19720 int ss; /* source size */
- 19721 long src; /* largest possible integer to convert */
- 19722 {
- 19723 EXTEND buf;
- 19724 short *ipt;
- 19725 SINGLE *result;
- 19726 long i_src;
- 19727
- 19728 zrf_ext(&buf);
- 19729 if (ss == sizeof(long)) {
- 19730 buf.exp = 31;
- 19731 i_src = src;
- 19732 result = (SINGLE *) &src;
- 19733 }
- 19734 else {
- 19735 ipt = (short *) &src;
- 19736 i_src = (long) *ipt;
- 19737 buf.exp = 15;
- 19738 result = (SINGLE *) ((void *) &ss);
- 19739 }
- 19740 if (i_src == 0) {
- 19741 *result = (SINGLE) 0L;
- 19742 return;
- 19743 }
- 19744 /* ESTABLISHED THAT src != 0 */
- 19745
- 19746 /* adjust exponent field */
- 19747 if (ss != sizeof(long))
- 19748 i_src <<= 16;
- 19749
- 19750 /* move to mantissa field */
- 19751 buf.m1 = i_src;
- 19752
- 19753 /* adjust mantissa field */
- 19754 nrm_ext(&buf);
- 19755 compact(&buf,result,4);
- 19756 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/cuf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19800 /*
- 19801 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19802 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19803 */
- 19804
- 19805 /* $Header: cuf8.c,v 1.6 93/01/05 12:04:41 ceriel Exp $ */
- 19806
- 19807 /*
- 19808 CONVERT INTEGER TO FLOAT (CUF n 8)
- 19809
- 19810 THIS ROUTINE WORKS BY FILLING AN EXTENDED
- 19811 WITH THE INTEGER VALUE IN EXTENDED FORMAT
- 19812 AND USES COMPACT() TO PUT IT INTO THE PROPER
- 19813 FLOATING POINT PRECISION.
- 19814 */
- 19815
- 19816 #include "FP_types.h"
- 19817
- 19818 void
- 19819 cuf8(ss,src)
- 19820 int ss; /* source size */
- 19821 long src; /* largest possible integer to convert */
- 19822 {
- 19823 EXTEND buf;
- 19824 short *ipt;
- 19825 long i_src;
- 19826
- 19827 zrf_ext(&buf);
- 19828 if (ss == sizeof(long)) {
- 19829 buf.exp = 31;
- 19830 i_src = src;
- 19831 }
- 19832 else {
- 19833 ipt = (short *) &src;
- 19834 i_src = (long) *ipt;
- 19835 buf.exp = 15;
- 19836 }
- 19837 if (i_src == 0) {
- 19838 zrf8((DOUBLE *)((void *)&ss));
- 19839 return;
- 19840 }
- 19841 /* ESTABLISHED THAT src != 0 */
- 19842
- 19843 /* adjust exponent field */
- 19844 if (ss != sizeof(long))
- 19845 i_src <<= 16;
- 19846
- 19847 /* move to mantissa field */
- 19848 buf.m1 = i_src;
- 19849
- 19850 /* adjust mantissa field */
- 19851 nrm_ext(&buf);
- 19852 compact(&buf,(unsigned long *) (void *)&ss,8);
- 19853 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/div_ext.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 19900 /*
- 19901 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 19902 See the copyright notice in the ACK home directory, in the file "Copyright".
- 19903 */
- 19904
- 19905 /* $Header: div_ext.c,v 1.10 93/01/05 12:04:47 ceriel Exp $ */
- 19906
- 19907 /*
- 19908 DIVIDE EXTENDED FORMAT
- 19909 */
- 19910
- 19911 #include "FP_bias.h"
- 19912 #include "FP_trap.h"
- 19913 #include "FP_types.h"
- 19914
- 19915 /*
- 19916 November 15, 1984
- 19917
- 19918 This is a routine to do the work.
- 19919 There are two versions:
- 19920 One is based on the partial products method
- 19921 and makes no use possible machine instructions
- 19922 to divide (hardware dividers).
- 19923 The other is used when USE_DIVIDE is defined. It is much faster on
- 19924 machines with fast 4 byte operations.
- 19925 */
- 19926 /********************************************************/
- 19927
- 19928 void
- 19929 div_ext(e1,e2)
- 19930 EXTEND *e1,*e2;
- 19931 {
- 19932 short error = 0;
- 19933 B64 result;
- 19934 register unsigned long *lp;
- 19935 #ifndef USE_DIVIDE
- 19936 short count;
- 19937 #else
- 19938 unsigned short u[9], v[5];
- 19939 register int j;
- 19940 register unsigned short *u_p = u;
- 19941 int maxv = 4;
- 19942 #endif
- 19943
- 19944 if ((e2->m1 | e2->m2) == 0) {
- 19945 /*
- 19946 * Exception 8.2 - Divide by zero
- 19947 */
- 19948 trap(EFDIVZ);
- 19949 e1->m1 = e1->m2 = 0L;
- 19950 e1->exp = EXT_MAX;
- 19951 return;
- 19952 }
- 19953 if ((e1->m1 | e1->m2) == 0) { /* 0 / anything == 0 */
- 19954 e1->exp = 0; /* make sure */
- 19955 return;
- 19956 }
- 19957 #ifndef USE_DIVIDE
- 19958 /*
- 19959 * numbers are right shifted one bit to make sure
- 19960 * that m1 is quaranteed to be larger if its
- 19961 * maximum bit is set
- 19962 */
- 19963 b64_rsft(&e1->mantissa); /* 64 bit shift right */
- 19964 b64_rsft(&e2->mantissa); /* 64 bit shift right */
- 19965 e1->exp++;
- 19966 e2->exp++;
- 19967 #endif
- 19968 /* check for underflow, divide by zero, etc */
- 19969 e1->sign ^= e2->sign;
- 19970 e1->exp -= e2->exp;
- 19971
- 19972 #ifndef USE_DIVIDE
- 19973 /* do division of mantissas */
- 19974 /* uses partial product method */
- 19975 /* init control variables */
- 19976
- 19977 count = 64;
- 19978 result.h_32 = 0L;
- 19979 result.l_32 = 0L;
- 19980
- 19981 /* partial product division loop */
- 19982
- 19983 while (count--) {
- 19984 /* first left shift result 1 bit */
- 19985 /* this is ALWAYS done */
- 19986
- 19987 b64_lsft(&result);
- 19988
- 19989 /* compare dividend and divisor */
- 19990 /* if dividend >= divisor add a bit */
- 19991 /* and subtract divisior from dividend */
- 19992
- 19993 if ( (e1->m1 < e2->m1) ||
- 19994 ((e1->m1 == e2->m1) && (e1->m2 < e2->m2) ))
- 19995 ; /* null statement */
- 19996 /* i.e., don't add or subtract */
- 19997 else {
- 19998 result.l_32++; /* ADD */
- 19999 if (e2->m2 > e1->m2)
- 20000 e1->m1 -= 1; /* carry in */
- 20001 e1->m1 -= e2->m1; /* do SUBTRACTION */
- 20002 e1->m2 -= e2->m2; /* SUBTRACTION */
- 20003 }
- 20004
- 20005 /* shift dividend left one bit OR */
- 20006 /* IF it equals ZERO we can break out */
- 20007 /* of the loop, but still must shift */
- 20008 /* the quotient the remaining count bits */
- 20009 /* NB save the results of this test in error */
- 20010 /* if not zero, then the result is inexact. */
- 20011 /* this would be reported in IEEE standard */
- 20012
- 20013 /* lp points to dividend */
- 20014 lp = &e1->m1;
- 20015
- 20016 error = ((*lp | *(lp+1)) != 0L) ? 1 : 0;
- 20017 if (error) { /* more work */
- 20018 /* assume max bit == 0 (see above) */
- 20019 b64_lsft(&e1->mantissa);
- 20020 continue;
- 20021 }
- 20022 else
- 20023 break; /* leave loop */
- 20024 } /* end of divide by subtraction loop */
- 20025
- 20026 if (count > 0) {
- 20027 lp = &result.h_32;
- 20028 if (count > 31) { /* move to higher word */
- 20029 *lp = *(lp+1);
- 20030 count -= 32;
- 20031 *(lp+1) = 0L; /* clear low word */
- 20032 }
- 20033 if (*lp)
- 20034 *lp <<= count; /* shift rest of way */
- 20035 lp++; /* == &result.l_32 */
- 20036 if (*lp) {
- 20037 result.h_32 |= (*lp >> 32-count);
- 20038 *lp <<= count;
- 20039 }
- 20040 }
- 20041 #else /* USE_DIVIDE */
- 20042
- 20043 u[4] = (e1->m2 & 1) << 15;
- 20044 b64_rsft(&(e1->mantissa));
- 20045 u[0] = e1->m1 >> 16;
- 20046 u[1] = e1->m1;
- 20047 u[2] = e1->m2 >> 16;
- 20048 u[3] = e1->m2;
- 20049 u[5] = 0; u[6] = 0; u[7] = 0;
- 20050 v[1] = e2->m1 >> 16;
- 20051 v[2] = e2->m1;
- 20052 v[3] = e2->m2 >> 16;
- 20053 v[4] = e2->m2;
- 20054 while (! v[maxv]) maxv--;
- 20055 result.h_32 = 0;
- 20056 result.l_32 = 0;
- 20057 lp = &result.h_32;
- 20058
- 20059 /*
- 20060 * Use an algorithm of Knuth (The art of programming, Seminumerical
- 20061 * algorithms), to divide u by v. u and v are both seen as numbers
- 20062 * with base 65536.
- 20063 */
- 20064 for (j = 0; j <= 3; j++, u_p++) {
- 20065 unsigned long q_est, temp;
- 20066
- 20067 if (j == 2) lp++;
- 20068 if (u_p[0] == 0 && u_p[1] < v[1]) continue;
- 20069 temp = ((unsigned long)u_p[0] << 16) + u_p[1];
- 20070 if (u_p[0] >= v[1]) {
- 20071 q_est = 0x0000FFFFL;
- 20072 }
- 20073 else {
- 20074 q_est = temp / v[1];
- 20075 }
- 20076 temp -= q_est * v[1];
- 20077 while (temp < 0x10000 && v[2]*q_est > ((temp<<16)+u_p[2])) {
- 20078 q_est--;
- 20079 temp += v[1];
- 20080 }
- 20081 /* Now, according to Knuth, we have an estimate of the
- 20082 quotient, that is either correct or one too big, but
- 20083 almost always correct.
- 20084 */
- 20085 if (q_est != 0) {
- 20086 int i;
- 20087 unsigned long k = 0;
- 20088 int borrow = 0;
- 20089
- 20090 for (i = maxv; i > 0; i--) {
- 20091 unsigned long tmp = q_est * v[i] + k + borrow;
- 20092 unsigned short md = tmp;
- 20093
- 20094 borrow = (md > u_p[i]);
- 20095 u_p[i] -= md;
- 20096 k = tmp >> 16;
- 20097 }
- 20098 k += borrow;
- 20099 borrow = u_p[0] < k;
- 20100 u_p[0] -= k;
- 20101
- 20102 if (borrow) {
- 20103 /* So, this does not happen often; the estimate
- 20104 was one too big; correct this
- 20105 */
- 20106 *lp |= (j & 1) ? (q_est - 1) : ((q_est-1)<<16);
- 20107 borrow = 0;
- 20108 for (i = maxv; i > 0; i--) {
- 20109 unsigned long tmp
- 20110 = v[i]+(unsigned long)u_p[i]+borrow;
- 20111
- 20112 u_p[i] = tmp;
- 20113 borrow = tmp >> 16;
- 20114 }
- 20115 u_p[0] += borrow;
- 20116 }
- 20117 else *lp |= (j & 1) ? q_est : (q_est<<16);
- 20118 }
- 20119 }
- 20120 #ifdef EXCEPTION_INEXACT
- 20121 u_p = &u[0];
- 20122 for (j = 7; j >= 0; j--) {
- 20123 if (*u_p++) {
- 20124 error = 1;
- 20125 break;
- 20126 }
- 20127 }
- 20128 #endif
- 20129 #endif
- 20130
- 20131 #ifdef EXCEPTION_INEXACT
- 20132 if (error) {
- 20133 /*
- 20134 * report here exception 8.5 - Inexact
- 20135 * from Draft 8.0 of IEEE P754:
- 20136 * In the absence of an invalid operation exception,
- 20137 * if the rounded result of an operation is not exact or if
- 20138 * it overflows without a trap, then the inexact exception
- 20139 * shall be assigned. The rounded or overflowed result
- 20140 * shall be delivered to the destination.
- 20141 */
- 20142 INEXACT();
- 20143 #endif
- 20144 e1->mantissa = result;
- 20145
- 20146 nrm_ext(e1);
- 20147 if (e1->exp < EXT_MIN) {
- 20148 /*
- 20149 * Exception 8.4 - Underflow
- 20150 */
- 20151 trap(EFUNFL); /* underflow */
- 20152 e1->exp = EXT_MIN;
- 20153 e1->m1 = e1->m2 = 0L;
- 20154 return;
- 20155 }
- 20156 if (e1->exp >= EXT_MAX) {
- 20157 /*
- 20158 * Exception 8.3 - Overflow
- 20159 */
- 20160 trap(EFOVFL); /* overflow */
- 20161 e1->exp = EXT_MAX;
- 20162 e1->m1 = e1->m2 = 0L;
- 20163 return;
- 20164 }
- 20165 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/dvf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 20200 /*
- 20201 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 20202 See the copyright notice in the ACK home directory, in the file "Copyright".
- 20203 */
- 20204
- 20205 /* $Header: dvf4.c,v 1.5 93/01/05 12:04:53 ceriel Exp $ */
- 20206
- 20207 /*
- 20208 DIVIDE TWO SINGLES - SINGLE Precision (dvf 4)
- 20209 */
- 20210
- 20211 #include "FP_types.h"
- 20212
- 20213 void
- 20214 dvf4(s2,s1)
- 20215 SINGLE s1,s2;
- 20216 {
- 20217 EXTEND e1,e2;
- 20218
- 20219 extend(&s1,&e1,sizeof(SINGLE));
- 20220 extend(&s2,&e2,sizeof(SINGLE));
- 20221
- 20222 /* do a divide */
- 20223 div_ext(&e1,&e2);
- 20224 compact(&e1,&s1,sizeof(SINGLE));
- 20225 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/dvf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 20300 /*
- 20301 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 20302 See the copyright notice in the ACK home directory, in the file "Copyright".
- 20303 */
- 20304
- 20305 /* $Header: dvf8.c,v 1.5 93/01/05 12:04:59 ceriel Exp $ */
- 20306
- 20307 /*
- 20308 DIVIDE TWO FLOATS - DOUBLE Precision (DVF 8)
- 20309 */
- 20310
- 20311 #include "FP_types.h"
- 20312
- 20313 void
- 20314 dvf8(s2,s1)
- 20315 DOUBLE s1,s2;
- 20316 {
- 20317 EXTEND e1,e2;
- 20318
- 20319 extend(&s1.d[0],&e1,sizeof(DOUBLE));
- 20320 extend(&s2.d[0],&e2,sizeof(DOUBLE));
- 20321
- 20322 /* do a divide */
- 20323 div_ext(&e1,&e2);
- 20324 compact(&e1,&s1.d[0],sizeof(DOUBLE));
- 20325 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/extend.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 20400 /*
- 20401 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 20402 See the copyright notice in the ACK home directory, in the file "Copyright".
- 20403 */
- 20404
- 20405 /* $Header: extend.c,v 1.11 93/01/05 12:05:05 ceriel Exp $ */
- 20406
- 20407 /*
- 20408 CONVERTS FLOATING POINT TO EXTENDED FORMAT
- 20409
- 20410 Two sizes of FLOATING Point are known:
- 20411 SINGLE and DOUBLE
- 20412 */
- 20413 /********************************************************/
- 20414 /*
- 20415 It is not required to normalize in extended
- 20416 format, but it has been chosen to do so.
- 20417 Extended Format is as follows (at exit):
- 20418
- 20419 ->sign S000 0000 | 0000 0000 <SIGN>
- 20420 ->exp 0EEE EEEE | EEEE EEEE <EXPONENT>
- 20421 ->m1 LFFF FFFF | FFFF FFFF <L.Fraction>
- 20422 FFFF FFFF | FFFF FFFF <Fraction>
- 20423 ->m2 FFFF FFFF | FFFF FFFF <Fraction>
- 20424 FFFF F000 | 0000 0000 <Fraction>
- 20425 */
- 20426 /********************************************************/
- 20427
- 20428 #include "FP_bias.h"
- 20429 #include "FP_shift.h"
- 20430 #include "FP_types.h"
- 20431 #include "get_put.h"
- 20432 /********************************************************/
- 20433
- 20434 void
- 20435 extend(from,to,size)
- 20436 unsigned long *from;
- 20437 EXTEND *to;
- 20438 int size;
- 20439 {
- 20440 register char *cpt1;
- 20441 unsigned long tmp;
- 20442 int leadbit = 0;
- 20443
- 20444 cpt1 = (char *) from;
- 20445
- 20446 #if FL_MSL_AT_LOW_ADDRESS
- 20447 #if FL_MSW_AT_LOW_ADDRESS
- 20448 to->exp = uget2(cpt1);
- 20449 #else
- 20450 to->exp = uget2(cpt1+2);
- 20451 #endif
- 20452 #else
- 20453 #if FL_MSW_AT_LOW_ADDRESS
- 20454 to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 4 : 0));
- 20455 #else
- 20456 to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 6 : 2));
- 20457 #endif
- 20458 #endif
- 20459 to->sign = (to->exp & 0x8000); /* set sign bit */
- 20460 to->exp ^= to->sign;
- 20461 if (size == sizeof(DOUBLE))
- 20462 to->exp >>= DBL_EXPSHIFT;
- 20463 else
- 20464 to->exp >>= SGL_EXPSHIFT;
- 20465 if (to->exp > 0)
- 20466 leadbit++; /* will set Lead bit later */
- 20467 else to->exp++;
- 20468
- 20469 if (size == sizeof(DOUBLE)) {
- 20470 #if FL_MSL_AT_LOW_ADDRESS
- 20471 to->m1 = get4(cpt1);
- 20472 cpt1 += 4;
- 20473 tmp = get4(cpt1);
- 20474 #else
- 20475 tmp = get4(cpt1);
- 20476 cpt1 += 4;
- 20477 to->m1 = get4(cpt1);
- 20478 #endif
- 20479 if (to->exp == 1 && to->m1 == 0 && tmp == 0) {
- 20480 to->exp = 0;
- 20481 to->sign = 0;
- 20482 to->m1 = 0;
- 20483 to->m2 = 0;
- 20484 return;
- 20485 }
- 20486 to->m1 <<= DBL_M1LEFT; /* shift */
- 20487 to->exp -= DBL_BIAS; /* remove bias */
- 20488 to->m1 |= (tmp>>DBL_RPACK); /* plus 10 == 32 */
- 20489 to->m2 = (tmp<<DBL_LPACK); /* plus 22 == 32 */
- 20490 }
- 20491 else { /* size == sizeof(SINGLE) */
- 20492 to->m1 = get4(cpt1);
- 20493 to->m1 <<= SGL_M1LEFT; /* shift */
- 20494 if (to->exp == 1 && to->m1 == 0) {
- 20495 to->exp = 0;
- 20496 to->sign = 0;
- 20497 to->m1 = 0;
- 20498 to->m2 = 0;
- 20499 return;
- 20500 }
- 20501 to->exp -= SGL_BIAS; /* remove bias */
- 20502 to->m2 = 0L;
- 20503 }
- 20504
- 20505 to->m1 |= NORMBIT; /* set bit L */
- 20506 if (leadbit == 0) { /* set or clear Leading Bit */
- 20507 to->m1 &= ~NORMBIT; /* clear bit L */
- 20508 nrm_ext(to); /* and normalize */
- 20509 }
- 20510 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/fef4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 20600 /*
- 20601 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 20602 See the copyright notice in the ACK home directory, in the file "Copyright".
- 20603 */
- 20604
- 20605 /* $Header: fef4.c,v 1.7 93/01/05 12:05:12 ceriel Exp $ */
- 20606
- 20607 /*
- 20608 SEPERATE INTO EXPONENT AND FRACTION (FEF 4)
- 20609 */
- 20610
- 20611 #include "FP_types.h"
- 20612
- 20613 void
- 20614 fef4(r,s1)
- 20615 SINGLE s1;
- 20616 struct fef4_returns *r;
- 20617 {
- 20618 EXTEND buf;
- 20619 register struct fef4_returns *p = r; /* make copy; r might refer
- 20620 to itself (see table)
- 20621 */
- 20622
- 20623 extend(&s1,&buf,sizeof(SINGLE));
- 20624 if (buf.exp == 0 && buf.m1 == 0 && buf.m2 == 0) {
- 20625 p->e = 0;
- 20626 }
- 20627 else {
- 20628 p->e = buf.exp+1;
- 20629 buf.exp = -1;
- 20630 }
- 20631 compact(&buf,&p->f,sizeof(SINGLE));
- 20632 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/fef8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 20700 /*
- 20701 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 20702 See the copyright notice in the ACK home directory, in the file "Copyright".
- 20703 */
- 20704
- 20705 /* $Header: fef8.c,v 1.7 93/01/05 12:05:18 ceriel Exp $ */
- 20706
- 20707 /*
- 20708 SEPERATE DOUBLE INTO EXPONENT AND FRACTION (FEF 8)
- 20709 */
- 20710
- 20711 #include "FP_types.h"
- 20712
- 20713 void
- 20714 fef8(r, s1)
- 20715 DOUBLE s1;
- 20716 struct fef8_returns *r;
- 20717 {
- 20718 EXTEND buf;
- 20719 register struct fef8_returns *p = r; /* make copy, r might refer
- 20720 to itself (see table)
- 20721 */
- 20722
- 20723 extend(&s1.d[0],&buf,sizeof(DOUBLE));
- 20724 if (buf.exp == 0 && buf.m1 == 0 && buf.m2 == 0) {
- 20725 p->e = 0;
- 20726 }
- 20727 else {
- 20728 p->e = buf.exp + 1;
- 20729 buf.exp = -1;
- 20730 }
- 20731 compact(&buf,&p->f.d[0],sizeof(DOUBLE));
- 20732 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/fif4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 20800 /*
- 20801 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 20802 See the copyright notice in the ACK home directory, in the file "Copyright".
- 20803 */
- 20804
- 20805 /* $Header: fif4.c,v 1.7 93/01/05 12:05:24 ceriel Exp $ */
- 20806
- 20807 /*
- 20808 MULTIPLY AND DISMEMBER PARTS (FIF 4)
- 20809 */
- 20810
- 20811 #include "FP_types.h"
- 20812 #include "FP_shift.h"
- 20813
- 20814 void
- 20815 fif4(p,x,y)
- 20816 SINGLE x,y;
- 20817 struct fif4_returns *p;
- 20818 {
- 20819
- 20820 EXTEND e1,e2;
- 20821
- 20822 extend(&y,&e1,sizeof(SINGLE));
- 20823 extend(&x,&e2,sizeof(SINGLE));
- 20824 /* do a multiply */
- 20825 mul_ext(&e1,&e2);
- 20826 e2 = e1;
- 20827 compact(&e2,&y,sizeof(SINGLE));
- 20828 if (e1.exp < 0) {
- 20829 p->ipart = 0;
- 20830 p->fpart = y;
- 20831 return;
- 20832 }
- 20833 if (e1.exp > 30 - SGL_M1LEFT) {
- 20834 p->ipart = y;
- 20835 p->fpart = 0;
- 20836 return;
- 20837 }
- 20838 b64_sft(&e1.mantissa, 63 - e1.exp);
- 20839 b64_sft(&e1.mantissa, e1.exp - 63); /* "loose" low order bits */
- 20840 compact(&e1,&(p->ipart),sizeof(SINGLE));
- 20841 extend(&(p->ipart), &e2, sizeof(SINGLE));
- 20842 extend(&y, &e1, sizeof(SINGLE));
- 20843 sub_ext(&e1, &e2);
- 20844 compact(&e1, &(p->fpart), sizeof(SINGLE));
- 20845 }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/fif8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 20900 /*
- 20901 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 20902 See the copyright notice in the ACK home directory, in the file "Copyright".
- 20903 */
- 20904
- 20905 /* $Header: fif8.c,v 1.7 93/01/05 12:05:30 ceriel Exp $ */
- 20906
- 20907 /*
- 20908 MULTIPLY AND DISMEMBER PARTS (FIF 8)
- 20909 */
- 20910
- 20911 #include "FP_types.h"
- 20912 #include "FP_shift.h"
- 20913
- 20914 void
- 20915 fif8(p,x,y)
- 20916 DOUBLE x,y;
- 20917 struct fif8_returns *p;
- 20918 {
- 20919
- 20920 EXTEND e1,e2;
- 20921
- 20922 extend(&y.d[0],&e1,sizeof(DOUBLE));
- 20923 extend(&x.d[0],&e2,sizeof(DOUBLE));