Jspice3
complete.c File Reference
#include "spice.h"
#include "cpdefs.h"
#include <sys/types.h>
#include "suffix.h"
Include dependency graph for complete.c:

Go to the source code of this file.

Data Structures

struct  ccom
 

Macros

#define CNTRL_D   '\004'
 
#define ESCAPE   '\033'
 
#define NCLASSES   32
 
#define NARGS   4
 

Functions

static struct ccom * getccom ()
 
static wordlist * ccfilec ()
 
static wordlist * ccmatch ()
 
static void printem ()
 
static wordlist * cctowl ()
 
static void throwaway ()
 
static struct ccom * clookup ()
 
static void cdelete ()
 
void cp_ccom (wordlist *wlist, char *buf, bool esc)
 
static wordlist * cctowl (struct ccom *cc, bool sib)
 
wordlist * cp_cctowl (char *stuff)
 
void cp_ccon (bool on)
 
bool cp_comlook (char *word)
 
void cp_addcomm (char *word, long bits0, long bits1, long bits2, long bits3)
 
void cp_remcomm (char *word)
 
void cp_addkword (int class, char *word)
 
void cp_remkword (class, char *word)
 
char * cp_kwswitch (int class, char *tree)
 
void cp_ccfreetrie (char *pntr)
 
void cp_ccrestart (bool kwords)
 
static void throwaway (struct ccom *dbase)
 
static struct ccom * clookup (char *word, struct ccom **dd, bool pref, bool create)
 
static void cdelete (struct ccom *node)
 

Variables

bool cp_nocc
 
static struct ccom * commands = NULL
 
static struct ccom * keywords [NCLASSES]
 

Macro Definition Documentation

#define CNTRL_D   '\004'

Definition at line 50 of file complete.c.

#define ESCAPE   '\033'

Definition at line 51 of file complete.c.

#define NARGS   4

Definition at line 53 of file complete.c.

#define NCLASSES   32

Definition at line 52 of file complete.c.

Function Documentation

static wordlist* ccfilec ( )
static
static wordlist* ccmatch ( )
static
static wordlist* cctowl ( )
static
static wordlist* cctowl ( struct ccom *  cc,
bool  sib 
)
static

Definition at line 376 of file complete.c.

380 {
381  wordlist *wl, *end;
382 
383  if (!cc)
384  return (NULL);
385  if (!cc->cc_invalid) {
386  wl = alloc(struct wordlist);
387  wl->wl_word = copy(cc->cc_name);
388  wl->wl_next = cctowl(cc->cc_child, true);
389  if (wl->wl_next)
390  wl->wl_next->wl_prev = wl;
391  }
392  else
393  wl = cctowl(cc->cc_child, true);
394  if (sib) {
395  if (wl) {
396  for (end = wl; end->wl_next; end = end->wl_next)
397  ;
398  end->wl_next = cctowl(cc->cc_sibling, true);
399  if (end->wl_next)
400  end->wl_next->wl_prev = wl;
401  }
402  else
403  wl = cctowl(cc->cc_sibling, true);
404  }
405  return (wl);
406 }
Definition: library.c:18
#define alloc(type)
Definition: cdmacs.h:21
char * copy()
char * cc_name
Definition: complete.c:85
struct ccom * cc_child
Definition: complete.c:88
struct wordlist * wl_prev
Definition: cpstd.h:24
char cc_invalid
Definition: complete.c:87
#define NULL
Definition: spdefs.h:121
static wordlist * cctowl()
Definition: cpstd.h:21
struct ccom * cc_sibling
Definition: complete.c:89
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
static void cdelete ( )
static
static void cdelete ( struct ccom *  node)
static

Definition at line 798 of file complete.c.

801 {
802  node->cc_invalid = 1;
803  return;
804 }
char cc_invalid
Definition: complete.c:87
static struct ccom* clookup ( )
static
static struct ccom* clookup ( char *  word,
struct ccom **  dd,
bool  pref,
bool  create 
)
static

Definition at line 686 of file complete.c.

692 {
693  struct ccom *place = *dd, *tmpc;
694  int ind = 0, i;
695  char buf[BSIZE_SP];
696 
697  if (!word || !*word) return place;
698 
699  if (!place) {
700  /* This is the first time we were called. */
701  if (!create)
702  return (NULL);
703 
704  *dd = place = alloc(struct ccom);
705  buf[0] = *word;
706  buf[1] = '\0';
707  place->cc_name = copy(buf);
708  if (word[1])
709  place->cc_invalid = 1;
710 
711  }
712  while (word[ind]) {
713  /* Walk down the sibling list until we find a node that
714  * matches 'word' to 'ind' places.
715  */
716  while ((place->cc_name[ind] < word[ind]) && place->cc_sibling)
717  place = place->cc_sibling;
718  if (place->cc_name[ind] < word[ind]) {
719 
720  /* This line doesn't go out that far... */
721  if (!create)
722  return (NULL);
723 
724  place->cc_sibling = alloc(struct ccom);
725  place->cc_sibling->cc_ysibling = place;
726  place->cc_sibling->cc_parent = place->cc_parent;
727  place = place->cc_sibling;
728  place->cc_name = tmalloc(ind + 2);
729  for (i = 0; i < ind + 1; i++)
730  place->cc_name[i] = word[i];
731  place->cc_name[ind + 1] = '\0';
732  place->cc_invalid = 1;
733  }
734  else if (place->cc_name[ind] > word[ind]) {
735  if (!create)
736  return (NULL);
737 
738  /* Put this one between place and its pred. */
739  tmpc = alloc(struct ccom);
740  tmpc->cc_parent = place->cc_parent;
741  tmpc->cc_sibling = place;
742  tmpc->cc_ysibling = place->cc_ysibling;
743  place->cc_ysibling = tmpc;
744  place = tmpc;
745  if (tmpc->cc_ysibling)
746  tmpc->cc_ysibling->cc_sibling = tmpc;
747  else if (tmpc->cc_parent)
748  tmpc->cc_parent->cc_child = tmpc;
749  else
750  *dd = place;
751  place->cc_name = tmalloc(ind + 2);
752  for (i = 0; i < ind + 1; i++)
753  place->cc_name[i] = word[i];
754  place->cc_name[ind + 1] = '\0';
755  place->cc_invalid = 1;
756  }
757 
758  /* place now points to that node that matches the word for
759  * ind + 1 characters.
760  */
761 /* printf("place %s, word %s, ind %d\n", place->cc_name, word, ind); */
762  if (word[ind + 1]) { /* More to go... */
763  if (!place->cc_child) {
764 
765  /* No children, maybe make one and go on. */
766  if (!create)
767  return (NULL);
768 
769  tmpc = alloc(struct ccom);
770  tmpc->cc_parent = place;
771  place->cc_child = tmpc;
772  place = tmpc;
773  place->cc_name = tmalloc(ind + 3);
774  for (i = 0; i < ind + 2; i++)
775  place->cc_name[i] = word[i];
776  place->cc_name[ind + 2] = '\0';
777  if (word[ind + 2])
778  place->cc_invalid = 1;
779  }
780  else
781  place = place->cc_child;
782  ind++;
783  }
784  else
785  break;
786  }
787  if (!pref && !create && place->cc_invalid) {
788  /* This is no good, we want a real word. */
789  return (NULL);
790  }
791  return (place);
792 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
if(TDesc==NULL)
Definition: cd.c:1326
struct ccom * cc_parent
Definition: complete.c:91
Definition: complete.c:84
#define alloc(type)
Definition: cdmacs.h:21
char * copy()
char * cc_name
Definition: complete.c:85
char * tmalloc()
struct ccom * cc_child
Definition: complete.c:88
char cc_invalid
Definition: complete.c:87
#define NULL
Definition: spdefs.h:121
struct ccom * cc_sibling
Definition: complete.c:89
struct ccom * cc_ysibling
Definition: complete.c:90
void cp_addcomm ( char *  word,
long  bits0,
long  bits1,
long  bits2,
long  bits3 
)

Definition at line 520 of file complete.c.

524 {
525  struct ccom *cc;
526 
527  if (cp_nocc)
528  return;
529 
530  cc = clookup(word, &commands, false, true);
531  cc->cc_invalid = 0;
532  cc->cc_kwords[0] = bits0;
533  cc->cc_kwords[1] = bits1;
534  cc->cc_kwords[2] = bits2;
535  cc->cc_kwords[3] = bits3;
536  return;
537 }
Definition: subckt.c:18
Definition: complete.c:84
bool cp_nocc
Definition: complete.c:75
static struct ccom * clookup()
char cc_invalid
Definition: complete.c:87
static struct ccom * commands
Definition: complete.c:94
long cc_kwords[NARGS]
Definition: complete.c:86
void cp_addkword ( int  class,
char *  word 
)

Definition at line 559 of file complete.c.

563 {
564  struct ccom *cc;
565 
566  if (cp_nocc)
567  return;
568 
569  if ((class < 1) || (class >= NCLASSES)) {
570  fprintf(cp_err, "cp_addkword: Internal Error: bad class %d\n",
571  class);
572  return;
573  }
574  cc = clookup(word, &keywords[class], false, true);
575  cc->cc_invalid = 0;
576  return;
577 }
Definition: subckt.c:18
Definition: complete.c:84
bool cp_nocc
Definition: complete.c:75
#define NCLASSES
Definition: complete.c:52
FILE * cp_err
Definition: help.c:101
static struct ccom * clookup()
char cc_invalid
Definition: complete.c:87
static struct ccom * keywords[NCLASSES]
Definition: complete.c:95
void cp_ccfreetrie ( char *  pntr)

Definition at line 626 of file complete.c.

629 {
630  int i;
631  struct ccom *dbase = (struct ccom*)pntr;
632 
633  if (dbase == commands) commands = NULL;
634  for (i = 0; i < NCLASSES; i++)
635  if (dbase == keywords[i])
636  keywords[i] = NULL;
637 
638  throwaway(dbase);
639 }
static void throwaway()
Definition: complete.c:84
#define NCLASSES
Definition: complete.c:52
#define NULL
Definition: spdefs.h:121
static struct ccom * commands
Definition: complete.c:94
static struct ccom * keywords[NCLASSES]
Definition: complete.c:95
void cp_ccom ( wordlist *  wlist,
char *  buf,
bool  esc 
)

Definition at line 365 of file complete.c.

370 {
371  return;
372 }
void cp_ccon ( bool  on)

Definition at line 423 of file complete.c.

426 {
427 #ifdef TIOCSTI
428 
429 #ifdef HAVE_TERMIOS_H
430 
431 #define TERM_GET TCGETS
432 #define TERM_SET TCSETS
433  static struct termios sbuf;
434  static struct termios OS_Buf;
435 
436 #else
437 
438 #ifdef HAVE_TERMIO_H
439 
440 #define TERM_GET TCGETA
441 #define TERM_SET TCSETA
442  static struct termio sbuf;
443  static struct termio OS_Buf;
444 
445 #else
446 #ifdef HAVE_SGTTY_H
447  static bool ison = false;
448  struct tchars tbuf;
449  struct sgttyb sbuf;
450 
451  if (cp_nocc || !cp_interactive || (ison == on))
452  return;
453  ison = on;
454 
455  /* Set the terminal up -- make escape the break character, and
456  * make sure we aren't in raw or cbreak mode. Hope the (void) ioctl's
457  * won't fail.
458  */
459  (void) ioctl(fileno(cp_in), TIOCGETC, (char *) &tbuf);
460  if (on)
461  tbuf.t_brkc = ESCAPE;
462  else
463  tbuf.t_brkc = '\0';
464  (void) ioctl(fileno(cp_in), TIOCSETC, (char *) &tbuf);
465 
466  (void) ioctl(fileno(cp_in), TIOCGETP, (char *) &sbuf);
467  sbuf.sg_flags &= ~(RAW|CBREAK);
468  (void) ioctl(fileno(cp_in), TIOCSETP, (char *) &sbuf);
469 
470 #endif
471 #endif
472 
473 #ifdef TERM_GET
474  static bool ison = false;
475 
476  if (cp_nocc || !cp_interactive || (ison == on))
477  return;
478  ison = on;
479 
480  if (ison == true) {
481  (void) ioctl(fileno(cp_in), TERM_GET, (char *) &OS_Buf);
482  sbuf = OS_Buf;
483  sbuf.c_cc[VEOF] = 0;
484  sbuf.c_cc[VEOL] = ESCAPE;
485  sbuf.c_cc[VEOL2] = CNTRL_D;
486  (void) ioctl(fileno(cp_in), TERM_SET, (char *) &sbuf);
487  }
488  else {
489  (void) ioctl(fileno(cp_in), TERM_SET, (char *) &OS_Buf);
490  }
491 
492 #endif
493 #endif
494 
495 #endif
496 
497  return;
498 }
#define CNTRL_D
Definition: complete.c:50
bool cp_nocc
Definition: complete.c:75
static char * sbuf
Definition: parse.c:40
bool cp_interactive
Definition: help.c:100
#define ESCAPE
Definition: complete.c:51
FILE * cp_in
Definition: help.c:101
void cp_ccrestart ( bool  kwords)

Definition at line 645 of file complete.c.

648 {
649  int i;
650 
652  commands = NULL;
653 
654  if (kwords)
655  for (i = 0; i < NCLASSES; i++) {
656  throwaway(keywords[i]);
657  keywords[i] = NULL;
658  }
659  return;
660 }
static void throwaway()
#define NCLASSES
Definition: complete.c:52
#define NULL
Definition: spdefs.h:121
static struct ccom * commands
Definition: complete.c:94
static struct ccom * keywords[NCLASSES]
Definition: complete.c:95
wordlist* cp_cctowl ( char *  stuff)

Definition at line 412 of file complete.c.

415 {
416  return (cctowl((struct ccom *) stuff, true));
417 }
Definition: complete.c:84
static wordlist * cctowl()
bool cp_comlook ( char *  word)

Definition at line 506 of file complete.c.

509 {
510  if (word && *word && clookup(word, &commands, false, false))
511  return (true);
512  else
513  return (false);
514 }
static struct ccom * clookup()
static struct ccom * commands
Definition: complete.c:94
char* cp_kwswitch ( int  class,
char *  tree 
)

Definition at line 607 of file complete.c.

611 {
612  char *old;
613 
614  if ((class < 1) || (class >= NCLASSES)) {
615  fprintf(cp_err, "cp_addkword: Internal Error: bad class %d\n",
616  class);
617  return (NULL);
618  }
619  old = (char *) keywords[class];
620  keywords[class] = (struct ccom *) tree;
621  return (old);
622 }
Definition: complete.c:84
#define NCLASSES
Definition: complete.c:52
FILE * cp_err
Definition: help.c:101
#define NULL
Definition: spdefs.h:121
static struct ccom * keywords[NCLASSES]
Definition: complete.c:95
void cp_remcomm ( char *  word)

Definition at line 543 of file complete.c.

546 {
547  struct ccom *cc;
548 
549  cc = clookup(word, &commands, false, false);
550  if (cc)
551  cdelete(cc);
552  return;
553 }
Definition: subckt.c:18
Definition: complete.c:84
static struct ccom * clookup()
static void cdelete()
static struct ccom * commands
Definition: complete.c:94
void cp_remkword ( class  ,
char *  word 
)

Definition at line 583 of file complete.c.

586 {
587  struct ccom *cc;
588 
589  if ((class < 1) || (class >= NCLASSES)) {
590  fprintf(cp_err, "cp_addkword: Internal Error: bad class %d\n",
591  class);
592  return;
593  }
594  cc = clookup(word, &keywords[class], false, false);
595  if (cc)
596  cdelete(cc);
597  return;
598 }
Definition: subckt.c:18
Definition: complete.c:84
#define NCLASSES
Definition: complete.c:52
FILE * cp_err
Definition: help.c:101
static struct ccom * clookup()
static void cdelete()
static struct ccom * keywords[NCLASSES]
Definition: complete.c:95
static struct ccom* getccom ( )
static
static void printem ( )
static
static void throwaway ( )
static
static void throwaway ( struct ccom *  dbase)
static

Definition at line 664 of file complete.c.

667 {
668  if (dbase == NULL) return;
669  if (dbase->cc_child)
670  throwaway(dbase->cc_child);
671  if (dbase->cc_sibling)
672  throwaway(dbase->cc_sibling);
673  tfree(dbase->cc_name);
674  tfree(dbase);
675  return;
676 }
static void throwaway()
char * cc_name
Definition: complete.c:85
struct ccom * cc_child
Definition: complete.c:88
#define tfree(x)
Definition: cdmacs.h:22
#define NULL
Definition: spdefs.h:121
struct ccom * cc_sibling
Definition: complete.c:89

Variable Documentation

struct ccom* commands = NULL
static

Definition at line 94 of file complete.c.

bool cp_nocc

Definition at line 75 of file complete.c.

struct ccom* keywords[NCLASSES]
static

Definition at line 95 of file complete.c.