void test_string_compare() {
  const char *test_type = "string", *test_content = "compare";
  bool ok = 1;

  String s1 = cstr2str("123456789");
  String s2 = cstr2str("987654321");
  String s3 = cstr2str("292");

  if (scompare(s1, s2) != -1 ||
      scompare(s2, s1) != 1  ||
      scompare(s1, s1) != 0  ||
      scompare(s1, s3) != 1  ||
      scompare(s3, s2) != -1
      ) {
    ok = 0;
  }

  if (!ok) {
    printf("%s test fails on %s.\n", test_type, test_content);
  }

  sdestro(&s1);
  sdestro(&s2);
  sdestro(&s3);
}
示例#2
0
void HSH_insert( SYM symbol)
{
/**************************************
 *
 *	H S H _ i n s e r t
 *
 **************************************
 *
 * Functional description
 *	Insert a symbol into the hash table.
 *
 **************************************/
	const USHORT h = hash(symbol->sym_string, symbol->sym_length);

	for (SYM old = hash_table[h]; old; old = old->sym_collision)
	{
		if (scompare(symbol->sym_string, symbol->sym_length,
					 old->sym_string, old->sym_length))
		{
			symbol->sym_homonym = old->sym_homonym;
			old->sym_homonym = symbol;
			return;
		}
	}

	symbol->sym_collision = hash_table[h];
	hash_table[h] = symbol;
}
示例#3
0
qli_symbol* HSH_lookup(const SCHAR* string, int length)
{
    /**************************************
     *
     *	H S H _ l o o k u p
     *
     **************************************
     *
     * Functional description
     *	Perform a string lookup against hash table.
     *
     **************************************/
    scompare_t scompare = scompare_ins;

    if (length > 1 && string[0] == '"')
    {
        // This logic differs from DSQL. See how LEX_token works.
        length -= 2;
        ++string;
        scompare = scompare_sens;
    }
    for (qli_symbol* symbol = hash_table[hash(string, length)]; symbol;
            symbol = symbol->sym_collision)
    {
        if (scompare(string, length, symbol->sym_string, symbol->sym_length))
            return symbol;
    }

    return NULL;
}
示例#4
0
void HSH_insert( qli_symbol* symbol, bool ignore_case)
{
    /**************************************
     *
     *	H S H _ i n s e r t
     *
     **************************************
     *
     * Functional description
     *	Insert a symbol into the hash table.
     *
     **************************************/
    const int h = hash(symbol->sym_string, symbol->sym_length);
    scompare_t scompare = ignore_case ? scompare_ins : scompare_sens;

    for (qli_symbol* old = hash_table[h]; old; old = old->sym_collision)
    {
        if (scompare(symbol->sym_string, symbol->sym_length, old->sym_string, old->sym_length))
        {
            symbol->sym_homonym = old->sym_homonym;
            old->sym_homonym = symbol;
            return;
        }
    }

    symbol->sym_collision = hash_table[h];
    hash_table[h] = symbol;
}
示例#5
0
/*   get string of style patameter   */
static int getparam(char *buff, const char *paraname, char *param)
{
	int cc;

	cc=scompare(buff,paraname);
	if (cc!=-1) {
		convline(buff,cc,param);
		return 1;
	}
	return 0;
}
示例#6
0
int
icompare(char *ax, char *bx, char frmt, char frml)
{
	register ANYTYPE	*a, *b;
	register int		length;
	ANYTYPE			atemp, btemp;

	length = frml & I1MASK;
	if (frmt == CHAR_CONST)
		return (scompare(ax, length, bx, length));
	a = &atemp;
	b = &btemp;
	bmove(ax, (char *) a, length);
	bmove(bx, (char *) b, length);
	if (bequal((char *) a, (char *) b, length))
		return (0);
	switch (frmt) {
	  case INT_CONST:
		switch (length) {
		  case 1:
			return (a->i1type - b->i1type);
		  case 2:
			return (a->i2type - b->i2type);
		  case 4:
			return (a->i4type > b->i4type ? 1 : -1);
		}
		break;

	  case FLOAT_CONST:
		if (frml == 4) {
			if ( a->f4type > b->f4type )
				return ( 1 );
			else
				return ( -1 );
		} else {
			if ( a->f8type > b->f8type )
				return ( 1 );
			else
				return ( -1 );
		}
		break;
	}
	syserr("compare: t=%d,l=%d", frmt, frml);
	/*NOTREACHED*/
	return(-1);
}
示例#7
0
SYM HSH_lookup(const SCHAR* string, USHORT length)
{
/**************************************
 *
 *	H S H _ l o o k u p
 *
 **************************************
 *
 * Functional description
 *	Perform a string lookup against hash table.
 *
 **************************************/
	for (SYM symbol = hash_table[hash(string, length)]; symbol; symbol = symbol->sym_collision)
	{
		if (scompare(string, length, symbol->sym_string, symbol->sym_length))
			return symbol;
	}

	return NULL;
}
示例#8
0
/*   get character of style parameter   */
static int getparachar(char *buff, const char *paraname, char *param)
{
	int j,cc;

	cc=scompare(buff,paraname);
	if (cc!=-1) {
		for (j=cc;j<strlen(buff);j++) {
			if (buff[j]=='\'') {
				(*param)=buff[j+1];
				break;
			}
			else if (buff[j]=='\n') {
				if (fgets(buff,4095,fp)==NULL) {
					break;
				}
				else j= -1;
			}
		}
		return 1;
	}
	return 0;
}
示例#9
0
/*   read style file   */
void styread(const char *filename)
{
	int i,cc;
	char buff[4096],tmp[4096];

	filename = KP_find_file(&kp_ist,filename);
	if(kpse_in_name_ok(filename))
		fp=fopen(filename,"rb");
	else
		fp=NULL;
	if (fp==NULL) {
		fprintf(stderr,"%s does not exist.\n",filename);
		exit(0);
	}

	for (i=0;;i++) {
		if (fgets(buff,4095,fp)==NULL) break;
		if (getparam(buff,"keyword",keyword)) continue;
		if (getparachar(buff,"arg_open",&arg_open)) continue;
		if (getparachar(buff,"arg_close",&arg_close)) continue;
		if (getparachar(buff,"range_open",&range_open)) continue;
		if (getparachar(buff,"range_close",&range_close)) continue;
		if (getparachar(buff,"level",&level)) continue;
		if (getparachar(buff,"actual",&actual)) continue;
		if (getparachar(buff,"encap",&encap)) continue;
		if (getparachar(buff,"quote",&quote)) continue;
		if (getparachar(buff,"escape",&escape)) continue;
		if (getparam(buff,"preamble",preamble)) continue;
		if (getparam(buff,"postamble",postamble)) continue;
		if (getparam(buff,"group_skip",group_skip)) continue;
		if (getparam(buff,"lethead_prefix",lethead_prefix)) continue;
		if (getparam(buff,"heading_prefix",lethead_prefix)) continue;
		if (getparam(buff,"lethead_suffix",lethead_suffix)) continue;
		if (getparam(buff,"heading_suffix",lethead_suffix)) continue;
		if (getparam(buff,"symhead_positive",symhead_positive)) continue;
		if (getparam(buff,"symhead_negative",symhead_negative)) continue;
		if (getparam(buff,"numhead_positive",numhead_positive)) continue;
		if (getparam(buff,"numhead_negative",numhead_negative)) continue;
		cc=scompare(buff,"lethead_flag");
		if (cc!= -1) {
			lethead_flag=atoi(&buff[cc]);
			continue;
		}
		cc=scompare(buff,"heading_flag");
		if (cc!= -1) {
			lethead_flag=atoi(&buff[cc]);
			continue;
		}
		cc=scompare(buff,"priority");
		if (cc!= -1) {
			priority=atoi(&buff[cc]);
			continue;
		}
		if (getparam(buff,"item_0",item_0)) continue;
		if (getparam(buff,"item_1",item_1)) continue;
		if (getparam(buff,"item_2",item_2)) continue;
		if (getparam(buff,"item_2",item_2)) continue;
		if (getparam(buff,"item_01",item_01)) continue;
		if (getparam(buff,"item_x1",item_x1)) continue;
		if (getparam(buff,"item_12",item_12)) continue;
		if (getparam(buff,"item_x2",item_x2)) continue;
		if (getparam(buff,"delim_0",delim_0)) continue;
		if (getparam(buff,"delim_1",delim_1)) continue;
		if (getparam(buff,"delim_2",delim_2)) continue;
		if (getparam(buff,"delim_n",delim_n)) continue;
		if (getparam(buff,"delim_r",delim_r)) continue;
		if (getparam(buff,"delim_t",delim_t)) continue;
		if (getparam(buff,"suffix_2p",suffix_2p)) continue;
		if (getparam(buff,"suffix_3p",suffix_3p)) continue;
		if (getparam(buff,"suffix_mp",suffix_mp)) continue;
		if (getparam(buff,"encap_prefix",encap_prefix)) continue;
		if (getparam(buff,"encap_infix",encap_infix)) continue;
		if (getparam(buff,"encap_suffix",encap_suffix)) continue;
		cc=scompare(buff,"line_max");
		if (cc!= -1) {
			line_max=atoi(&buff[cc]);
			continue;
		}
		if (getparam(buff,"indent_space",indent_space)) continue;
		cc=scompare(buff,"indent_length");
		if (cc!= -1) {
			indent_length=atoi(&buff[cc]);
			continue;
		}
		if (getparam(buff,"symbol",symbol)) continue;
		cc=scompare(buff,"symbol_flag");
		if (cc!= -1) {
			symbol_flag=atoi(&buff[cc]);
			continue;
		}
		cc=scompare(buff,"letter_head");
		if (cc!= -1) {
			letter_head=atoi(&buff[cc]);
			continue;
		}
		if (getparam(buff,"atama",tmp)) {
			multibyte_to_widechar(atama,STYBUFSIZE,tmp);
			continue;
		}
		if (getparam(buff,"tumunja",tmp)) {
			multibyte_to_widechar(tumunja,STYBUFSIZE,tmp);
			continue;
		}
		if (getparam(buff,"hanzi_head",tmp)) {
			multibyte_to_widechar(hanzi_head,STYBUFSIZE,tmp);
			continue;
		}
		if (getparam(buff,"page_compositor",page_compositor)) continue;
		if (getparam(buff,"page_precedence",page_precedence)) continue;
		if (getparam(buff,"character_order",character_order)) continue;
		if (getparam(buff,"icu_locale",     icu_locale     )) continue;
		cc=scompare(buff,"icu_rules");
		if (cc!= -1) {
			escape_mode=1;
			getparam(buff,"icu_rules",icu_rules);
			escape_mode=0;
			continue;
		}
		if (getparam(buff,"icu_attributes", icu_attr_str   )) continue;
	}
	fclose(fp);
}
示例#10
0
文件: wsh.c 项目: synthetixa/whirlios
int main() {
  char lstr[8][64];
  char buffer[80];
  char verb[80];
  char wd[512];
  int len;
  int prog;
  int selected_sbuffer = 0;

  while (1) {
    iwrites("wsh-");
    fgetwd(wd);
    iwrites(wd);
    iwrites("> ");
    ireads(buffer, 80);
    len = sfindc(buffer, ' ');
    if (len < 0)
      len = slength(buffer);
    scopy(verb, buffer, len);
    if (!scompare(verb, "help")) {
      iwrites("\ncat: print file contents\ncd: change directories\necho: print a string\nhelp: display this message\nls: list files\npwd: print current working directory\nloads: load a string to be used with all commands which act upon strings\nprintf: write to a pre-existing file\nprints: print the currently loaded string\nrms: unload the currently loaded string\ncons: concatenate a string to the end of the currently loaded string\nloadfs: load the contents of a file into the String Buffer\nchsf: switch to the next String Buffer\nchsb: switch to the previous String Buffer\npsb: print the currently selected String Buffer\nreboot: reboot the operating system\n\n");
    }
    else if (!scompare(verb, "ls")) {
      ls();
    }
    else if (!scompare(verb, "cd")) {
      cd(buffer + len + 1);
    }
    else if (!scompare(verb, "cat")) {
      /* Mrew? */
      cat(buffer + len + 1);
    }
    else if  (!scompare(verb, "echo")){
      echo(buffer + len + 1);
    }
    else if  (!scompare(verb, "pwd")){
      pwd();
    }
    else if (!scompare(verb, "reboot")) {
      ireboot();
    }
    else if (!scompare(verb, "printf")) {
      printf(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "loads")) {
      loads(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "prints")) {
      iwrites(lstr[selected_sbuffer]);
      iwrites("\n");
    }
    else if (!scompare(verb, "rms")) {
      scopy(lstr[selected_sbuffer], "\0", 1);
    }
    else if (!scompare(verb, "loadfs")) {
      loadfs(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "cons")) {
      cons(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "chsf")) {
      selected_sbuffer = chsf(selected_sbuffer);
    }
    else if (!scompare(verb, "psb")) {
      psb(selected_sbuffer);
    }
    else if (!scompare(verb, "chsb")) {
      selected_sbuffer = chsb(selected_sbuffer);
    }
    /*
    else if (!scompare(verb, "mk")) {
      mk(buffer + len + 1);
    }
    */
    else if (sfindc(verb, '/') == -1) {
      prog = fget("/bin/");
      if (!prog) {
        iwrites("Error: unable to locate bin directory\n");
        continue;
      }
      prog = ffind(prog, verb);
      if (!prog) {
        iwrites("Error: unrecognized command \"");
        iwrites(verb);
        iwrites("\"\n");
        continue;
      }
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else if (prog = fget(verb)) {
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else {
      iwrites("Error: executable not found\n");
      continue;
    }
  }
}