Beispiel #1
0
Datei: struct.c Projekt: 4ker/8cc
void testmain() {
    print("struct");
    t1();
    t2();
    t3();
    t4();
    t5();
    t6();
    t7();
    t8();
    t9();
    t10();
    t11();
    t12();
    t13();
    t14();
    unnamed();
    assign();
    arrow();
    incomplete();
    bitfield_basic();
    bitfield_mix();
    bitfield_union();
    bitfield_unnamed();
    bitfield_initializer();
    test_offsetof();
    flexible_member();
    empty_struct();
}
Beispiel #2
0
Argv::Argv(const std::string& defaultdesc,bool helpopt,const std::string& helpdesc)
	:m_status(PARSE_INIT)
	,m_curidx(0)
{
#ifdef BOOST_PO
	std::shared_ptr<boost::program_options::options_description> unnamed(new boost::program_options::options_description(defaultdesc));
	m_options.push_back(std::make_pair(unnamed,true));
	if (helpopt)
	{
		addBoolOption("help,h",helpdesc);
	}
#endif
}
bool ColorPalette::save()
{
    QString filename = p->fileName;
    if ( filename.isEmpty() )
    {
        filename = unnamed(p->name)+".gpl";
    }

    QFile file(filename);
    if ( !file.open(QFile::Text|QFile::WriteOnly) )
        return false;

    QTextStream stream(&file);

    stream << "GIMP Palette\n";
    stream << "Name: " << unnamed(p->name) << '\n';
    if ( p->columns )
        stream << "Columns: " << p->columns << '\n';
    /// \todo Options to add comments
    stream << "#\n";

    for ( int i = 0; i < p->colors.size(); i++ )
    {
        stream << qSetFieldWidth(3) << p->colors[i].first.red() << qSetFieldWidth(0) << ' '
               << qSetFieldWidth(3) << p->colors[i].first.green() << qSetFieldWidth(0) << ' '
               << qSetFieldWidth(3) << p->colors[i].first.blue() << qSetFieldWidth(0) << '\t'
               << unnamed(p->colors[i].second) << '\n';
    }

    if ( !file.error() )
    {
        setDirty(false);
        return true;
    }

    return false;
}
void AstBegin::dump(ostream& str) {
    this->AstNode::dump(str);
    if (unnamed()) str<<" [UNNAMED]";
    if (generate()) str<<" [GEN]";
    if (genforp()) str<<" [GENFOR]";
}
		/**
		 * @brief parse - substruction context
		 * @param[in]    v : value string header pointer
		 * @param[in] conf : configuration
		 * @param[in] line : reading line
		 * @return ==0 : success
		 */
		inline
		int file_stream::unnamed(char *v,configuration *conf, int *line)
		{
			char value[512];
			int ret = 0;
			int sep = 0;
			char sep_token = 0;

			LogDebugf("Begin - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
			LogIndent();

			{ // ----> get value or nesting
				// get separater
				if((sep = find_separater(v)) >= 0){
					sep_token = v[sep];
					v[sep] = '\0';
				}

				// erase blank
				erase_blank(v);
				// check blank
				if(  *v  == '\0'){
					LogDebug("next line\n");
					LogUnindent();
					LogDebugf("End - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
					return 1;
				}
				else if(*v == TokenEndScope ){
					// no value
					LogDebug("end nesting\n");
					LogUnindent();
					LogDebugf("End - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
					return 0;
				}
				else if( *v == TokenEndValue){
					LogDebug("invalid token\n");
					LogUnindent();
					LogDebugf("Fail - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
					return -1;
				}
				else {// ---> get value
					get_ascii(value, v);
					erase_blank(v);

					if( *v  != '\0') return -1;
				}// <--- get value


				// get unnamed value
				if( *value != '\0'){
					conf->child_push_back(0, value);
					if( sep_token == TokenEndValue){
						ret = unnamed(v + sep + 1, conf, line);
					}
				}
			} // <---- get value or nesting

			LogUnindent();
			LogDebugf("End - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
			return ret;
		}
		/**
		 * @brief parse - substruction context
		 * @param[in]    fp : file stream
		 * @param[in]     n : name string header pointer
		 * @param[in]     v : value string header pointer
		 * @param[in]     s : configuration
		 * @param[in]  line : reading line
		 * @return ==0 : success
		 */
		inline
		int file_stream::substitution(FILE *fp, char *n, char *v, configuration *conf, int *line)
		{
			char name[512];
			char value[512];

			LogDebugf("Begin: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);

			{ // ---> get name
				// zero initialize
				::memset(name, 0, sizeof(name));

				get_ascii(name, n);
				erase_blank(n);
				if( *n != '\0'){
					LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
					return -1;
				}
				LogDebugf("     : name \"%s\"\n", name);
			} // <--- get name

			{ // ----> get value or nesting
				erase_blank(v);
				LogDebugf("     : value \"%s\"\n", v);
				if( v[0] != TokenBeginScope ){

					// check error
					if( *v == '\0' ){
						LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
						return -1;
					}

					{// ---> get value
						get_ascii(value, v);
						erase_blank(v);
						if( *value == '\0'){
							LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
							return -1;
						}
						if( *v != '\0'){
							LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
							return -1;
						}
						conf->child_push_back(name, value);
					}// <--- get value
				}
				// ---> nesting
				else {
					LogDebug("     : nesting\n");
					::memmove(v, v + 1, ::strlen(v) - 1);
					erase_blank(v);
					LogDebugf("     : nesting \"%s\"\n", v);
					if( *v == '\0' ){
						configuration *p;
						// todo modify to not need search
						conf->child_push_back(name, 0);
						p = conf->child_find(name, 0);
						_parse_(fp, p, line);
					}
					else {
						configuration *p;
						// todo modify to not need search
						conf->child_push_back(name, 0);
						p = conf->child_find(name, 0);
						if( unnamed(v, p, line) == 1) {
							// not end of nesting
							// read next line
							_parse_(fp, p, line);
						}
					}
				} // <--- nesting

			} // <---- get value or nesting


			LogDebugf("  End: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
			return 0;
		}
		/**
		 * @brief parse
		 * @param[in]    fp : file stream
		 * @param[out] conf : configuration
		 * @param[in]  line : reading line
		 * @retval ==0 : success
		 * @retval < 0 : failure
		 */
		inline
		int file_stream::_parse_(FILE *fp, configuration *conf, int *line)
		{
			char ws[512];
			int ret;

			LogDebugf("Begin - int FileStream::_parse_(%p, %p, %p)\n", fp, conf, line);
			LogIndent();

			// ---> file read loop
			while( !::feof(fp) ){
				// zero clear workspace
				::memset(ws, 0, sizeof(ws));
				// file read
				if( !::fgets(ws + ::strlen(ws), sizeof(ws) - ::strlen(ws), fp) )
					break;
				// count line number
				(*line)++;
				LogDebugf("line \'%d\'\n", *line);

				conf->show(0);
				// erase comment
				erase_comment(ws);

				if( (ret = find_separater(ws)) < 0){
					if( unnamed(ws, conf, line) < 0){
						LogUnindent();
						LogDebugf("Fail - int FileStream::_parse_(%p, %p, %p)", fp, conf, line);
						return -1;
					}
				}
				else {
					LogDebugf("get separater \'%c\'\n", ws[ret]);
					switch( ws[ret] ){
					// substruct
					case TokenSubst:
					{
						ws[ret] = '\0';
						if( substitution(fp, ws, ws + ret + 1, conf, line) < 0){
							LogUnindent();
							LogDebugf("Fail - int FileStream::_parse_(%p, %p, %p)", fp, conf, line);
							return -1;
						}
					}
					break;

					// nesting
					case TokenBeginScope:
						LogDebug("invalid nesting");
						break;
					case TokenEndScope:
						if( unnamed(ws, conf, line) < 0){
							LogDebugf("configure read error at line %d\n", *line);
							LogUnindent();
							LogDebugf(" Fail: int FileStream::_parse_(%p, %p, %p)", fp, conf, line);
							return -1;
						}
						return 0;

						// unnamed value
					case TokenComment:
					case TokenEndValue:
					case TokenEndLine:
						if( unnamed(ws, conf, line) < 0){
							LogDebugf("configure read error at line %d\n", *line);
							LogUnindent();
							LogDebugf(" Fail: int FileStream::_parse_(%p, %p, %p)", fp, conf, line);
							return -1;
						}
						break;
					} // <--- switch

				}
			}
			// <--- file read loop

			LogUnindent();
			LogDebugf("  End: int FileStream::_parse_(%p, %p, %p)\n", fp, conf, line);
			return 0;
		}
Beispiel #8
0
int main(int argc, char **argv)
{
  program_name = argv[0];
  int special_flag = 0;
  int skewchar = -1;
  int opt;
  const char *gf_file = 0;
  while ((opt = getopt(argc, argv, "svg:k:")) != EOF)
    switch (opt) {
    case 'g':
      gf_file = optarg;
      break;
    case 's':
      special_flag = 1;
      break;
    case 'k':
      {
	char *ptr;
	long n = strtol(optarg, &ptr, 0);
	if ((n == 0 && ptr == optarg)
	    || *ptr != '\0'
	    || n < 0
	    || n > UCHAR_MAX)
	  error("invalid skewchar");
	else
	  skewchar = (int)n;
	break;
      }
    case 'v':
      {
	extern const char *version_string;
	fprintf(stderr, "tfmtodit version %s\n", version_string);
	fflush(stderr);
	break;
      }
    case '?':
      usage();
      break;
    case EOF:
      assert(0);
    }
  if (argc - optind != 3)
    usage();
  gf g;
  if (gf_file) {
    if (!g.load(gf_file))
      return 1;
  }
  const char *tfm_file = argv[optind];
  const char *map_file = argv[optind + 1];
  const char *font_file = argv[optind + 2];
  tfm t;
  if (!t.load(tfm_file))
    return 1;
  char_list *table[256];
  if (!read_map(map_file, table))
    return 1;
  if (!freopen(font_file, "w", stdout)) {
    error("can't open `%1' for writing: %2", font_file, strerror(errno));
    return 1;
  }
  printf("name %s\n", font_file);
  if (special_flag)
    fputs("special\n", stdout);
  char *internal_name = strsave(argv[optind]);
  int len = strlen(internal_name);
  if (len > 4 && strcmp(internal_name + len - 4, ".tfm") == 0)
    internal_name[len - 4] = '\0';
  char *s = strrchr(internal_name, '/');
  printf("internalname %s\n", s ? s + 1 : internal_name);
  int n;
  if (t.get_param(2, &n)) {
    if (n > 0)
      printf("spacewidth %d\n", n*MULTIPLIER);
  }
  if (t.get_param(1, &n) && n != 0)
    printf("slant %f\n", atan2(n/double(1<<20), 1.0)*180.0/M_PI);
  int xheight;
  if (!t.get_param(5, &xheight))
    xheight = 0;
  int i;
  // Print the list of ligatures.
  // First find the indices of each character that can participate in
  // a ligature.
  for (i = 0; i < 256; i++)
    for (int j = 0; j < sizeof(lig_chars)/sizeof(lig_chars[0]); j++)
      for (char_list *p = table[i]; p; p = p->next)
	if (strcmp(lig_chars[j].ch, p->ch) == 0)
	  lig_chars[j].i = i;
  // For each possible ligature, if its participants all exist,
  // and it appears as a ligature in the tfm file, include in
  // the list of ligatures.
  int started = 0;
  for (i = 0; i < sizeof(lig_table)/sizeof(lig_table[0]); i++) {
    int i1 = lig_chars[lig_table[i].c1].i;
    int i2 = lig_chars[lig_table[i].c2].i;
    int r = lig_chars[lig_table[i].res].i;
    if (i1 >= 0 && i2 >= 0 && r >= 0) {
      unsigned char c;
      if (t.get_lig(i1, i2, &c) && c == r) {
	if (!started) {
	  started = 1;
	  fputs("ligatures", stdout);
	}
	printf(" %s", lig_table[i].ch);
      }
    }
  }
  if (started)
    fputs(" 0\n", stdout);
  printf("checksum %d\n", t.get_checksum());
  printf("designsize %d\n", t.get_design_size());
  // Now print out the kerning information.
  int had_kern = 0;
  kern_iterator iter(&t);
  unsigned char c1, c2;
  int k;
  while (iter.next(&c1, &c2, &k))
    if (c2 != skewchar) {
      k *= MULTIPLIER;
      char_list *q = table[c2];
      for (char_list *p1 = table[c1]; p1; p1 = p1->next)
	for (char_list *p2 = q; p2; p2 = p2->next) {
	  if (!had_kern) {
	    printf("kernpairs\n");
	    had_kern = 1;
	  }
	  printf("%s %s %d\n", p1->ch, p2->ch, k);
	}
    }
  printf("charset\n");
  char_list unnamed("---");
  for (i = 0; i < 256; i++) 
    if (t.contains(i)) {
      char_list *p = table[i] ? table[i] : &unnamed;
      int m[6];
      m[0] = t.get_width(i);
      m[1] = t.get_height(i);
      m[2] = t.get_depth(i);
      m[3] = t.get_italic(i);
      m[4] = g.get_left_adjustment(i);
      m[5] = g.get_right_adjustment(i);
      printf("%s\t%d", p->ch, m[0]*MULTIPLIER);
      for (int j = int(sizeof(m)/sizeof(m[0])) - 1; j > 0; j--)
	if (m[j] != 0)
	  break;
      for (int k = 1; k <= j; k++)
	printf(",%d", m[k]*MULTIPLIER);
      int type = 0;
      if (m[2] > 0)
	type = 1;
      if (m[1] > xheight)
	type += 2;
      printf("\t%d\t%04o\n", type, i);
      for (p = p->next; p; p = p->next)
	printf("%s\t\"\n", p->ch);
    }
  return 0;
}
Beispiel #9
0
void AstBegin::dump(ostream& str) {
    this->AstNode::dump(str);
    if (unnamed()) str<<" [UNNAMED]";
    if (hidden()) str<<" [HIDDEN]";
}