Beispiel #1
0
void USB::dumpDevice(usbdesc_device *d) {
	iprintf("Device:\n");
	iprintf("\tUSB Version:  %d.%d\n", d->bcdUSB >> 8, (d->bcdUSB & 0xFF) >> 4);
	iprintf("\tClass:        0x%04X\n", d->bDeviceClass);
	iprintf("\tSubClass:     0x%04X\n", d->bDeviceSubClass);
	iprintf("\tProtocol:     0x%04X\n", d->bDeviceProtocol);
	iprintf("\tMax Packet:   %d\n", d->bMaxPacketSize);
	iprintf("\tVendor:       0x%04X\n", d->idVendor);
	iprintf("\tProduct:      0x%04X\n", d->idProduct);
	iprintf("\tManufacturer: "); dumpString(d->iManufacturer);
	iprintf("\tProduct:      "); dumpString(d->iProduct);
	iprintf("\tSerial:       "); dumpString(d->iSerialNumber);
	iprintf("\tNum Configs:  %d\n", d->bNumConfigurations);
}
Beispiel #2
0
void USB::dumpCDC(uint8_t *d) {
	switch(d[2]) {
		case USB_CDC_SUBTYPE_HEADER: {
			usbcdc_header *h = (usbcdc_header *) d;
            if (h)
            {
                iprintf("\t\t*CDC header\n");
                iprintf("\t\t\tbcdCDC:  0x%04X\n", h->bcdCDC);
            }
			break;
		}
		case USB_CDC_SUBTYPE_UNION: {
			usbcdc_union *u = (usbcdc_union *) d;
            if (u)
            {
                iprintf("\t\t*CDC union\n");
                iprintf("\t\t\tMaster:  %d\n", u->bMasterInterface);
                iprintf("\t\t\tSlave:   %d\n", u->bSlaveInterface0);
            }
			break;
		}
		case USB_CDC_SUBTYPE_CALL_MANAGEMENT: {
			usbcdc_callmgmt *m = (usbcdc_callmgmt *) d;
			iprintf("\t\t*CDC Call Management\n");
			iprintf("\t\t\tCapabilities:  0x%02X ", m->bmCapabilities);
			if (m->bmCapabilities & USB_CDC_CALLMGMT_CAP_CALLMGMT)
				iprintf("(CALLMGMT)");
			if (m->bmCapabilities & USB_CDC_CALLMGMT_CAP_DATAINTF)
				iprintf("(DATAINTF)");
			iprintf("\n");
			iprintf("\t\t\tData Interface: %d\n", m->bDataInterface);
			break;
		}
		case USB_CDC_SUBTYPE_ACM: {
			usbcdc_acm *a = (usbcdc_acm *) d;
			iprintf("\t\t*CDC ACM\n");
			iprintf("\t\t\tCapabilities: 0x%02X ", a->bmCapabilities);
			if (a->bmCapabilities & USB_CDC_ACM_CAP_COMM)
				iprintf("(COMM)");
			if (a->bmCapabilities & USB_CDC_ACM_CAP_LINE)
				iprintf("(LINE)");
			if (a->bmCapabilities & USB_CDC_ACM_CAP_BRK)
				iprintf("(BRK)");
			if (a->bmCapabilities & USB_CDC_ACM_CAP_NOTIFY)
				iprintf("(NOTIFY)");
			iprintf("\n");
			break;
		}
		case USB_CDC_SUBTYPE_ETHERNET: {
			usbcdc_ether *e = (usbcdc_ether *) d;
			iprintf("\t\t*CDC Ethernet\n");
			iprintf("\t\t\tMAC address: "); dumpString(e->iMacAddress);
			iprintf("\t\t\tStatistics: 0x%02lX\n", e->bmEthernetStatistics);
			iprintf("\t\t\tMax Segment Size: %d\n", e->wMaxSegmentSize);
			iprintf("\t\t\tMC Filters: %d\n", e->wNumberMCFilters);
			iprintf("\t\t\tPower Filters: %d\n", e->bNumberPowerFilters);
			break;
		}
	}
}
Beispiel #3
0
bool Trace::dump(TraceLevel level, const char* file, int line,
                 const char* buf, int buflen, const char* format, ...)
{
    if(m_enabled == false || level < LEVEL_ERROR || level > m_level)
        return false;

    std::va_list ap;
    va_start(ap, format);
    char msgbuf[8156];
    std::vsnprintf(msgbuf, sizeof (msgbuf), format, ap);
    va_end(ap);

    char srcbuf[256];
    std::snprintf(srcbuf, sizeof (srcbuf), " {%s:%d}", file, line);

    assert(level >= 0 && level < LVSTR.size());
    const auto msg = getCurrentTimeString() + LVSTR[level] +
        msgbuf + srcbuf + "\n" + dumpString(buf, buflen, 16) + "\n";

    std::size_t n{0};
    {
        std::lock_guard<std::mutex> lock{m_mutex};
        if(m_file != nullptr)
            n = std::fwrite(msg.c_str(), sizeof (char), msg.size(), m_file);
    }
    return (n >= msg.size());
}
/**
 * \brief True if one of the given literals overlaps with the suffix of
 * another, meaning that they could arrive at the same offset.
 */
static
bool literalsCouldRace(const rose_literal_id &lit1,
                       const rose_literal_id &lit2) {
    DEBUG_PRINTF("compare %s (delay %u) and %s (delay %u)\n",
                 dumpString(lit1.s).c_str(), lit1.delay,
                 dumpString(lit2.s).c_str(), lit2.delay);

    // Add dots on the end of each literal for delay.
    const auto v1 = makePath(lit1);
    const auto v2 = makePath(lit2);

    // See if the smaller path is a suffix of the larger path.
    const auto *smaller = v1.size() < v2.size() ? &v1 : &v2;
    const auto *bigger = v1.size() < v2.size() ? &v2 : &v1;
    auto r = mismatch(smaller->rbegin(), smaller->rend(), bigger->rbegin(),
                      overlaps);
    return r.first == smaller->rend();
}
Beispiel #5
0
void USB::dumpConfiguration(usbdesc_configuration *c) {
	iprintf("Configuration:\n");
	iprintf("\tTotal Length:        %db\n", c->wTotalLength);
	iprintf("\tNum Interfaces:      %d\n", c->bNumInterfaces);
	iprintf("\tConfiguration Value: %d\n", c->bConfigurationValue);
	iprintf("\tConfiguration:       "); dumpString(c->iConfiguration);
	iprintf("\tAttributes:          %s\n", ((c->bmAttributes & 0x80)?"Bus Powered":"Self Powered"));
	iprintf("\tMax Power:           %dmA\n", c->bMaxPower * 2);
}
Beispiel #6
0
void USB::dumpString(int i) {
	if (i > 0) {
		uint8_t j = findStringIndex(i);
		if (j > 0) {
			iprintf("[%d] ", i);
			dumpString((usbdesc_string *) descriptors[j]);
			return;
		}
	}
	iprintf("-none-\n");
}
Beispiel #7
0
void USB::dumpInterface(usbdesc_interface *i) {
	iprintf("\t*Interface\n");
	iprintf("\t\tNumber:        %d\n", i->bInterfaceNumber);
	iprintf("\t\tAlternate:     %d\n", i->bAlternateSetting);
	iprintf("\t\tNum Endpoints: %d\n", i->bNumEndPoints);
	iprintf("\t\tClass:         0x%02X ", i->bInterfaceClass);
	switch(i->bInterfaceClass) {
		case UC_COMM:
			iprintf("(COMM)");
			break;
		case UC_MASS_STORAGE:
			iprintf("(MSC)");
			break;
		case UC_CDC_DATA:
			iprintf("(CDC DATA)");
			break;
	}
	iprintf("\n");
	iprintf("\t\tSubClass:      0x%02X ", i->bInterfaceSubClass);
	switch(i->bInterfaceClass) {
		case UC_COMM: {
			switch(i->bInterfaceSubClass) {
				case USB_CDC_SUBCLASS_ACM:
					iprintf("(ACM)");
					break;
				case USB_CDC_SUBCLASS_ETHERNET:
					iprintf("(ETHERNET)");
					break;
			}
			break;
		}
		case UC_MASS_STORAGE: {
			switch(i->bInterfaceSubClass) {
				case MSC_SUBCLASS_SCSI:
					iprintf("(SCSI)");
					break;
			}
			break;
		}
	}
	iprintf("\n");
	iprintf("\t\tProtocol:      0x%02X ", i->bInterfaceProtocol);
	iprintf("\n");
	iprintf("\t\tInterface:     "); dumpString(i->iInterface);
}
/** \brief True if the literal expression \a expr could be added to Rose. */
bool shortcutLiteral(NG &ng, const ParsedExpression &pe) {
    assert(pe.component);

    if (!ng.cc.grey.allowLiteral) {
        return false;
    }

    const auto &expr = pe.expr;

    // XXX: don't shortcut literals with extended params (yet)
    if (expr.min_offset || expr.max_offset != MAX_OFFSET || expr.min_length ||
        expr.edit_distance) {
        DEBUG_PRINTF("extended params not allowed\n");
        return false;
    }

    ConstructLiteralVisitor vis;
    try {
        assert(pe.component);
        pe.component->accept(vis);
        assert(vis.repeat_stack.empty());
    } catch (const ConstructLiteralVisitor::NotLiteral&) {
        DEBUG_PRINTF("not a literal\n");
        return false;
    }

    const ue2_literal &lit = vis.lit;

    if (lit.empty()) {
        DEBUG_PRINTF("empty literal\n");
        return false;
    }

    if (expr.highlander && lit.length() <= 1) {
        DEBUG_PRINTF("not shortcutting SEP literal\n");
        return false;
    }

    DEBUG_PRINTF("constructed literal %s\n", dumpString(lit).c_str());
    return ng.addLiteral(lit, expr.index, expr.report, expr.highlander,
                         expr.som);
}
Beispiel #9
0
void USB::dumpDescriptors() {
	uint8_t i;
	for (i = 0; i < N_DESCRIPTORS; i++) {
		if (descriptors[i] == (usbdesc_base *) 0) {
			iprintf("--- FIN at %d\n", i);
			return;
		}
		iprintf("[%d:+%d]", i, descriptors[i]->bLength);
		switch (descriptors[i]->bDescType) {
			case DT_DEVICE: {
				dumpDevice((usbdesc_device *) descriptors[i]);
				break;
			}
			case DT_CONFIGURATION: {
				dumpConfiguration((usbdesc_configuration *) descriptors[i]);
				break;
			}
			case DT_INTERFACE: {
				dumpInterface((usbdesc_interface *) descriptors[i]);
				break;
			}
			case DT_ENDPOINT: {
				dumpEndpoint((usbdesc_endpoint *) descriptors[i]);
				break;
			}
			case DT_STRING: {
				dumpString((usbdesc_string *) descriptors[i]);
				break;
			}
			case DT_CDC_DESCRIPTOR: {
				dumpCDC((uint8_t *) descriptors[i]);
				break;
			}
		}
	}
}
Beispiel #10
0
bool SmallWriteBuildImpl::determiniseLiterals() {
    DEBUG_PRINTF("handling literals\n");
    assert(!poisoned);
    assert(cand_literals.size() <= cc.grey.smallWriteMaxLiterals);

    if (cand_literals.empty()) {
        return true; /* nothing to do */
    }

    vector<unique_ptr<raw_dfa> > temp_dfas;

    for (const auto &cand : cand_literals) {
        NGHolder h;
        DEBUG_PRINTF("determinising %s\n", dumpString(cand.first).c_str());
        lit_to_graph(&h, cand.first, cand.second);
        temp_dfas.push_back(buildMcClellan(h, &rm, cc.grey));

        // If we couldn't build a McClellan DFA for this portion, then we
        // can't SmallWrite optimize the entire graph, so we can't
        // optimize any of it
        if (!temp_dfas.back()) {
            DEBUG_PRINTF("failed to determinise\n");
            poisoned = true;
            return false;
        }
    }

    if (!rdfa && temp_dfas.size() == 1) {
        /* no need to merge there is only one dfa */
        rdfa = move(temp_dfas[0]);
        return true;
    }

    /* do a merge of the new dfas */

    vector<const raw_dfa *> to_merge;

    if (rdfa) {/* also include the existing dfa */
        to_merge.push_back(rdfa.get());
    }

    for (const auto &d : temp_dfas) {
        to_merge.push_back(d.get());
    }

    assert(to_merge.size() > 1);

    while (to_merge.size() > LITERAL_MERGE_CHUNK_SIZE) {
        vector<const raw_dfa *> small_merge;
        small_merge.insert(small_merge.end(), to_merge.begin(),
                           to_merge.begin() + LITERAL_MERGE_CHUNK_SIZE);

        temp_dfas.push_back(
            mergeAllDfas(small_merge, DFA_MERGE_MAX_STATES, &rm, cc.grey));

        if (!temp_dfas.back()) {
            DEBUG_PRINTF("merge failed\n");
            poisoned = true;
            return false;
        }

        to_merge.erase(to_merge.begin(),
                       to_merge.begin() + LITERAL_MERGE_CHUNK_SIZE);
        to_merge.push_back(temp_dfas.back().get());
    }

    auto merged = mergeAllDfas(to_merge, DFA_MERGE_MAX_STATES, &rm, cc.grey);

    if (!merged) {
        DEBUG_PRINTF("merge failed\n");
        poisoned = true;
        return false;
    }

    DEBUG_PRINTF("merge succeeded, built %p\n", merged.get());

    // Replace our only DFA with the merged one
    rdfa = move(merged);

    return true;
}
Beispiel #11
0
int main(int argc, char **argv)
{
        FILE *dat, *inc;
        int rc;
        unsigned long size;
        string_count_t cnt;             /* current string number */
        string_size_t lsize;
        int makeLib = 0;

        *fDIR = '\0';
 
        if(argv[1] && stricmp(argv[1], "/lib") == 0) {
                --argc;
                ++argv;
                makeLib = 1;
        }

        // output directory
        if (argc > 1 && stricmp(argv[1], "/dir") == 0) {
          --argc;
          ++argv; 
          strcpy(fDIR, argv[1]);
          --argc;
          ++argv;
        }

        if (argc > 2) {
                puts("FIXSTRS - Generate STRINGS.DAT and STRINGS.H for a language\n"
                        "Useage: FIXSTRS [/lib] [language] [directory]\n"
                        "\tIf no language is specified, only the default strings are read.\n"
                        "\tThe <language>.LNG file must reside in the current directory.\n"
                        "Note: DEFAULT.LNG must be present in the current directory, too.");
                return 127;
        }

        in_file = 1;
        if((rc = loadFile(fTXT)) != 0)
                return rc;
        in_file = 2;
        if(argc > 1 && (rc = loadFile(argv[1])) != 0) {
          --argc;
          ++argv;      
          return rc;
        }

/* Now all the strings are cached into memory */

        if(maxCnt < 2) {
                fputs("No string definition found.\n", stderr);
                return 43;
        }

        /* Prepend a directory, if needed */
        if (*fDIR) {
          strcpy(temp1, fDIR);
          logfile = strcat(temp1, logfile);
        }
        /* Create the LOG file */
        if(argc > 1) {          /* Only if a local LNG file was specified */
                log = NULL;                     /* No LOG entry til this time */
                for(cnt = 0; cnt < maxCnt; ++cnt) {
                        switch(strg[cnt].flags & 3) {
                        case 0:         /* Er?? */
                                fputs("Internal error assigned string has no origin?!\n"
                                 , stderr);
                                return 99;
                        case 1:         /* DEFAULT.LNG only */
                                if(!log && (log = fopen(logfile, "wt")) == NULL) {
                                        fprintf(stderr, "Cannot create logfile: '%s'\n"
                                         , logfile);
                                        goto breakLogFile;
                                }
                                fprintf(log, "%s: Missing from local LNG file\n"
                                 , strg[cnt].name);
                                break;
                        case 2:         /* local.LNG only */
                                if(!log && (log = fopen(logfile, "wt")) == NULL) {
                                        fprintf(stderr, "Cannot create logfile: '%s'\n"
                                         , logfile);
                                        goto breakLogFile;
                                }
                                fprintf(log, "%s: No such string resource\n"
                                 , strg[cnt].name);
                                break;
                        case 3:         /* OK */
                                break;
                        }
                        if(strg[cnt].flags & VERSION_MISMATCH) {
                                if(!log && (log = fopen(logfile, "wt")) == NULL) {
                                        fprintf(stderr, "Cannot create logfile: '%s'\n"
                                         , logfile);
                                        goto breakLogFile;
                                }
                                fprintf(log, "%s: Version mismatch, current is: %u\n"
                                 , strg[cnt].name, strg[cnt].version);
                        }
                        if(strg[cnt].flags & VALIDATION_MISMATCH) {
                                if(!log && (log = fopen(logfile, "wt")) == NULL) {
                                        fprintf(stderr, "Cannot create logfile: '%s'\n"
                                         , logfile);
                                        goto breakLogFile;
                                }
                                fprintf(log, "%s: printf() format string mismatch, should be: %s\n"
                                 , strg[cnt].name, strg[cnt].vstring);
                        }
                }

                if(log)
                        fclose(log);
        }
breakLogFile:

        /* 1. Adjust the offset and generate the overall size */
        for(size = string[0].size, cnt = 1; cnt < maxCnt; ++cnt) {
                string[cnt].index = string[cnt-1].index + string[cnt-1].size;
                size += string[cnt].size;
        }

        if(size >= 0x10000ul - sizeof(string_index_t) * maxCnt) {
                fputs("Overall size of strings exceeds 64KB limit\n", stderr);
                return 44;
        }

        if (*fDIR) {
          strcpy(temp1, fDIR);
          fDAT = strcat(temp1, fDAT);
        }
        /* 2. Open STRINGS.DAT and STRINGS.H and dump control information */
        if ((dat = fopen(fDAT,"wb")) == NULL) {
                strcpy(temp2, "creating ");
                strcpy(temp2, fDAT);
                perror(temp2);
                return 36;
        }
        if (*fDIR) {
          strcpy(temp1, fDIR);
          fH = strcat(temp1, fH);
        }
        if ((inc = fopen(fH,"wt")) == NULL) {
                strcpy(temp2, "creating ");
                strcat(temp2, fH);
                perror(temp2);
                return 37;
        }

puts("FIXSTRS: building STRINGS resource");

        fputs("/*\n"
                " * This file was automatically generated by FIXSTRS.\n"
                " * Any modifications will be lost next time this tool\n"
                " * is invoked.\n"
                " */\n\n", inc);
        fprintf(inc,"#define  STRINGS_ID         \"%s%u\"\n"
         , id, STRING_RESOURCE_MINOR_ID);

        startResource(dat, RES_ID_STRINGS, STRING_RESOURCE_MINOR_ID);
                /* Preamble of STRINGS.DAT file */
        fprintf(dat, "%s%u", id, STRING_RESOURCE_MINOR_ID);
/*      fwrite(id, sizeof(id) - 1, 1, dat);             *//* file contents ID */
        fwrite("\r\n\x1a", 4, 1, dat);                  /* text file full stop */
        fputs("#define  STRINGS_ID_TRAILER 4\n", inc);  /* 4 additional bytes */
        fputs("\n\n", inc);                                             /* delimiter */

                /* parameters of strings */
        fwrite(&maxCnt, sizeof(maxCnt), 1, dat);        /* number of strings */
        lsize = (string_size_t)size;
        fwrite(&lsize, sizeof(lsize), 1, dat);          /* total size of string text */

                /* string control area */
        fwrite(string, sizeof(string[0]), maxCnt, dat);
        /* append the strings */
        for(cnt = 0; cnt < maxCnt; ++cnt) {
                fwrite(strg[cnt].text, string[cnt].size, 1, dat);
                if(makeLib)
                        fprintf(inc, "extern const char %s[];\n", strg[cnt].name);
                fprintf(inc, "#define  %-34s 0x%02x  /* @ 0x%04x */\n"
                 , strg[cnt].name, cnt, string[cnt].index);
        }
        fputs("\n/* END OF FILE */\n", inc);
        endResource(dat);

        fflush(dat);
        if(ferror(dat)) {
                strcpy(temp2, "Unspecific write error into ");
                strcat(temp2, fDAT);
                strcat(temp2, "\n");
                fputs(temp2, stderr);
                return 38;
        }
        fflush(inc);
        if(ferror(inc)) {
                strcpy(temp2, "Unspecific write error into ");
                strcat(temp2, fH);
                strcat(temp2, "\n");
                fputs(temp2, stderr);
                return 39;
        }

        fclose(dat);
        fclose(inc);

        if(makeLib) {
                mkdir(fDIR);
#define fdmake inc
#define ftc101 dat
                //cfilename[-1] = '\\';
                //strcpy(cfilename, fDMAKEFILE);
                if (*fDIR) {
                  strcpy(temp1, fDIR);
                  cfile = strcat(temp1, fDMAKEFILE);
                  cfilename = cfile + strlen(fDIR);
                }
                if((fdmake = fopen(cfile, "wt")) == NULL) {
                        pxerror("creating ", cfile);
                        return 100;
                }
                strcpy(cfilename, fTCMAKEFILE);
                if((ftc101 = fopen(cfile, "wt")) == NULL) {
                        pxerror("creating ", cfile);
                        return 101;
                }

puts("FIXSTRS: building STRINGS library source files");
                /********************** prologue */
                fputs("\
#\n\
# A Makefile for ATTRIB\n\
# (c) osFree project,\n\
# author, date\n\
#\n\
\n\
PROJ  = strings\n\
DESC  = Control file attributes\n\
#defines object file names in format objname.$(O)\n\
srcfiles = ", fdmake);

                /********************* individual files */
                for(cnt = 0; cnt < maxCnt; ++cnt) {
                        dumpString(cnt);
                        fprintf(fdmake, " &\n\t" objfmt1, cnt);
                }
                for(cnt = 0; cnt < maxCnt - 1; ++cnt)
                        fprintf(ftc101, "+" objfmt " \n", cnt);
                fprintf(ftc101, "+" objfmt " \n", cnt);
                /********************** epilogue */

                fputs("\n\n\
# defines additional options for C compiler\n\
ADD_COPT = -i=$(MYDIR)..$(SEP)include -i=$(MYDIR)..$(SEP)suppl\n\
\n\
!include $(%ROOT)/mk/libsdos.mk\n\
\n\
TARGETS  = $(PATH)$(PROJ).lib\n\
\n\
$(TARGETS): $(OBJS)\n\
 @$(MAKE) $(MAKEOPT) -f $(PATH)makefile.mk library=$(TARGETS) library install\n\
\n\
lib: $(TARGETS)\n\
\n", fdmake);

                fflush(ftc101);
                if(ferror(ftc101)) {
                        strcpy(temp2, "Unspecific error writing to ");
                        strcat(temp2, fTCMAKEFILE);
                        puts(temp2);
                        return 104;
                }
                fclose(ftc101);
                fflush(fdmake);
                if(ferror(fdmake)) {
                        strcpy(temp2, "Unspecific error writing to ");
                        strcat(temp2, fDMAKEFILE);
                        puts(temp2);
                        return 105;
                }
                fclose(fdmake);
        }

        return 0;
}
Beispiel #12
0
/* Dump top dictionary. */
static void dumpTopDict(abfDumpCtx h, abfTopDict *top)
	{
	char *OrigFontType;
	char *srcFontType;

	dumpString(h, "version", 		top->version.ptr);
	dumpString(h, "Notice", 		top->Notice.ptr);
	dumpString(h, "Copyright",		top->Copyright.ptr);
	dumpString(h, "FullName",		top->FullName.ptr);
	dumpString(h, "FamilyName", 	top->FamilyName.ptr);
	dumpString(h, "Weight", 		top->Weight.ptr);
    if (top->isFixedPitch           != cff_DFLT_isFixedPitch)
        fprintf(h->fp, "isFixedPitch        true\n");
    if (top->ItalicAngle            != cff_DFLT_ItalicAngle)
        fprintf(h->fp, "ItalicAngle         %g\n", top->ItalicAngle);
    if (top->UnderlinePosition      != cff_DFLT_UnderlinePosition)
        fprintf(h->fp, "UnderlinePosition   %g\n", top->UnderlinePosition);
    if (top->UnderlineThickness     != cff_DFLT_UnderlineThickness)
        fprintf(h->fp, "UnderlineThickness  %g\n", top->UnderlineThickness);
    if (top->UniqueID               != ABF_UNSET_INT)
        fprintf(h->fp, "UniqueID            %ld\n", top->UniqueID);
    if (top->FontBBox[0] != 0.0 || top->FontBBox[1] != 0.0 || 
        top->FontBBox[2] != 0.0 || top->FontBBox[3] != 0.0)
        fprintf(h->fp, "FontBBox            {%g,%g,%g,%g}\n", 
               top->FontBBox[0], top->FontBBox[1], 
               top->FontBBox[2], top->FontBBox[3]);
    if (top->StrokeWidth            != cff_DFLT_StrokeWidth)
        fprintf(h->fp, "StrokeWidth         %g\n", top->StrokeWidth);
    dumpIntArray(h, "XUID", top->XUID.cnt, top->XUID.array);

    /* CFF and Acrobat extensions */
	dumpString(h, "PostScript", 	top->PostScript.ptr);
	dumpString(h, "BaseFontName",	top->BaseFontName.ptr);
    dumpIntArray(h, "BaseFontBlend", 
                 top->BaseFontBlend.cnt, top->BaseFontBlend.array);
    if (top->FSType					!= ABF_UNSET_INT)
        fprintf(h->fp, "FSType              %ld\n", top->FSType);
	switch (top->OrigFontType)
		{
	case abfOrigFontTypeType1:
		OrigFontType = "Type1";
		break;
	case abfOrigFontTypeCID:
		OrigFontType = "CID";
		break;
	case abfOrigFontTypeTrueType:
		OrigFontType = "TrueType";
		break;
	case abfOrigFontTypeOCF:
		OrigFontType = "OCF";
		break;
	default:
		OrigFontType = NULL;
		break;
		}
	if (OrigFontType != NULL)
		fprintf(h->fp, "OrigFontType        %s\n", OrigFontType);
	if (top->WasEmbedded != 0)
		fprintf(h->fp, "WasEmbedded         true\n");

	/* Synthetic font */
	dumpString(h, "SynBaseFontName",top->SynBaseFontName.ptr);

    /* CID-keyed font extensions */
    dumpFontMatrix(h, "cid.FontMatrix",&top->cid.FontMatrix);
	dumpString(h, "cid.CIDFontName",top->cid.CIDFontName.ptr);
	dumpString(h, "cid.Registry", 	top->cid.Registry.ptr);
	dumpString(h, "cid.Ordering", 	top->cid.Ordering.ptr);
    if (top->cid.Supplement         != ABF_UNSET_INT)
        fprintf(h->fp, "cid.Supplement      %ld\n", top->cid.Supplement);
    if (top->cid.CIDFontVersion     != cff_DFLT_CIDFontVersion)
        fprintf(h->fp, "cid.CIDFontVersion  %.03f\n", top->cid.CIDFontVersion);
    if (top->cid.CIDFontRevision    != cff_DFLT_CIDFontRevision)
        fprintf(h->fp, "cid.CIDFontRevision %ld\n", top->cid.CIDFontRevision);
    if (top->cid.CIDCount           != cff_DFLT_CIDCount)
        fprintf(h->fp, "cid.CIDCount        %ld\n", top->cid.CIDCount);
    if (top->cid.UIDBase            != ABF_UNSET_INT)
        fprintf(h->fp, "cid.UIDBase         %ld\n", top->cid.UIDBase);

    /* Supplementary data */
    if (top->sup.flags              != 0)
		{
		char *sep = " (";
        fprintf(h->fp, "sup.flags           0x%08lx", top->sup.flags);
		if (top->sup.flags & ABF_SYN_FONT)
			{
			fprintf(h->fp, "%sABF_SYN_FONT", sep);
			sep = ",";
			}
		if (top->sup.flags & ABF_CID_FONT)
			{
			fprintf(h->fp, "%sABF_CID_FONT", sep);
			sep = ",";
			}
		if (sep[0] == ',')
			fprintf(h->fp, ")");
		fprintf(h->fp, "\n");
		}
	switch (top->sup.srcFontType)
		{
	case abfSrcFontTypeType1Name:
		srcFontType = "Type 1 (name-keyed)";
		break;
	case abfSrcFontTypeType1CID:
		srcFontType = "Type 1 (cid-keyed)";
		break;
    case abfSrcFontTypeCFFName:
        srcFontType = "CFF (name-keyed)";
        break;
    case abfSrcFontTypeCFFCID:
        srcFontType = "CFF (cid-keyed)";
        break;
    case abfSrcFontTypeSVGName:
        srcFontType = "SVG (name-keyed)";
        break;
    case abfSrcFontTypeUFOName:
        srcFontType = "UFO (name-keyed)";
        break;
	case abfSrcFontTypeTrueType:
		srcFontType = "TrueType";
		break;
	default:
		srcFontType = NULL;
		break;
		}
	if (srcFontType != NULL)
		fprintf(h->fp, "sup.srcFontType     %s\n", srcFontType);
    if (top->sup.UnitsPerEm         != 1000)
        fprintf(h->fp, "sup.UnitsPerEm      %ld\n", top->sup.UnitsPerEm);
    if (top->sup.nGlyphs            != ABF_UNSET_INT)
        fprintf(h->fp, "sup.nGlyphs         %ld\n", top->sup.nGlyphs);
    }
Beispiel #13
0
int main(int argc, char **argv)
{
	FILE *dat, *inc;
	int rc;
	unsigned long size;
	string_count_t cnt;		/* current string number */
	string_size_t lsize;
	int makeLib = 0;

	unlink(logfile);

	if(argv[1] && stricmp(argv[1], "/lib") == 0) {
		--argc;
		++argv;
		makeLib = 1;
	}

	if(argc > 2) {
		puts("FIXSTRS - Generate STRINGS.DAT and STRINGS.H for a language\n"
			"Useage: FIXSTRS [/lib] [language]\n"
			"\tIf no language is specified, only the default strings are read.\n"
			"\tThe <language>.LNG file must reside in the current directory.\n"
			"Note: DEFAULT.LNG must be present in the current directory, too.");
		return 127;
	}


	in_file = 1;
	if((rc = loadFile(fTXT)) != 0)
		return rc;
	in_file = 2;
	if(argc > 1 && (rc = loadFile(argv[1])) != 0)
		return rc;

/* Now all the strings are cached into memory */

	if(maxCnt < 2) {
		fputs("No string definition found.\n", stderr);
		return 43;
	}

	/* Create the LOG file */
	if(argc > 1) {		/* Only if a local LNG file was specified */
		log = NULL;			/* No LOG entry til this time */
		for(cnt = 0; cnt < maxCnt; ++cnt) {
			switch(strg[cnt].flags & 3) {
			case 0:		/* Er?? */
				fputs("Internal error assigned string has no origin?!\n"
				 , stderr);
				return 99;
			case 1:		/* DEFAULT.LNG only */
				if(!log && (log = fopen(logfile, "wt")) == NULL) {
					fprintf(stderr, "Cannot create logfile: '%s'\n"
					 , logfile);
					goto breakLogFile;
				}
				fprintf(log, "%s: Missing from local LNG file\n"
				 , strg[cnt].name);
				break;
			case 2:		/* local.LNG only */
				if(!log && (log = fopen(logfile, "wt")) == NULL) {
					fprintf(stderr, "Cannot create logfile: '%s'\n"
					 , logfile);
					goto breakLogFile;
				}
				fprintf(log, "%s: No such string resource\n"
				 , strg[cnt].name);
				break;
			case 3:		/* OK */
				break;
			}
			if(strg[cnt].flags & VERSION_MISMATCH) {
				if(!log && (log = fopen(logfile, "wt")) == NULL) {
					fprintf(stderr, "Cannot create logfile: '%s'\n"
					 , logfile);
					goto breakLogFile;
				}
				fprintf(log, "%s: Version mismatch, current is: %u\n"
				 , strg[cnt].name, strg[cnt].version);
			}
			if(strg[cnt].flags & VALIDATION_MISMATCH) {
				if(!log && (log = fopen(logfile, "wt")) == NULL) {
					fprintf(stderr, "Cannot create logfile: '%s'\n"
					 , logfile);
					goto breakLogFile;
				}
				fprintf(log, "%s: printf() format string mismatch, should be: %s\n"
				 , strg[cnt].name, strg[cnt].vstring);
			}
		}

		if(log)
			fclose(log);
	}
breakLogFile:

	/* 1. Adjust the offset and generate the overall size */
	for(size = string[0].size, cnt = 1; cnt < maxCnt; ++cnt) {
		string[cnt].index = string[cnt-1].index + string[cnt-1].size;
		size += string[cnt].size;
	}

	if(size >= 0x10000ul - sizeof(string_index_t) * maxCnt) {
		fputs("Overall size of strings exceeds 64KB limit\n", stderr);
		return 44;
	}

	/* 2. Open STRINGS.DAT and STRINGS.H and dump control information */
	if ((dat = fopen(fDAT,"wb")) == NULL) {
		perror("creating " fDAT);
		return 36;
	}
	if ((inc = fopen(fH,"wt")) == NULL) {
		perror("creating " fH);
		return 37;
	}

puts("FIXSTRS: building STRINGS resource");

	fputs("/*\n"
		" * This file was automatically generated by FIXSTRS.\n"
		" * Any modifications will be lost next time this tool\n"
		" * is invoked.\n"
		" */\n\n", inc);
	fprintf(inc,"#define  STRINGS_ID         \"%s%u\"\n"
	 , id, STRING_RESOURCE_MINOR_ID);

	startResource(dat, RES_ID_STRINGS, STRING_RESOURCE_MINOR_ID);
		/* Preamble of STRINGS.DAT file */
	fprintf(dat, "%s%u", id, STRING_RESOURCE_MINOR_ID);
/*	fwrite(id, sizeof(id) - 1, 1, dat);		*//* file contents ID */
	fwrite("\r\n\x1a", 4, 1, dat);			/* text file full stop */
	fputs("#define  STRINGS_ID_TRAILER 4\n", inc);	/* 4 additional bytes */
	fputs("\n\n", inc);						/* delimiter */

		/* parameters of strings */
	fwrite(&maxCnt, sizeof(maxCnt), 1, dat);	/* number of strings */
	lsize = (string_size_t)size;
	fwrite(&lsize, sizeof(lsize), 1, dat);		/* total size of string text */

		/* string control area */
	fwrite(string, sizeof(string[0]), maxCnt, dat);
	/* append the strings */
	for(cnt = 0; cnt < maxCnt; ++cnt) {
		fwrite(strg[cnt].text, string[cnt].size, 1, dat);
		if(makeLib)
			fprintf(inc, "extern const char %s[];\n", strg[cnt].name);
		fprintf(inc, "#define  %-34s 0x%02x  /* @ 0x%04x */\n"
		 , strg[cnt].name, cnt, string[cnt].index);
	}
	fputs("\n/* END OF FILE */\n", inc);
	endResource(dat);

	fflush(dat);
	if(ferror(dat)) {
		fputs("Unspecific write error into " fDAT "\n", stderr);
		return 38;
	}
	fflush(inc);
	if(ferror(inc)) {
		fputs("Unspecific write error into " fH "\n", stderr);
		return 39;
	}

	fclose(dat);
	fclose(inc);

	if(makeLib) {
		mkdir(stringdir);
#define fdmake inc
#define ftc101 dat
		cfilename[-1] = '\\';
		strcpy(cfilename, fDMAKEFILE);
		if((fdmake = fopen(cfile, "wt")) == NULL) {
			pxerror("creating ", cfile);
			return 100;
		}
		strcpy(cfilename, fTCMAKEFILE);
		if((ftc101 = fopen(cfile, "wt")) == NULL) {
			pxerror("creating ", cfile);
			return 101;
		}

puts("FIXSTRS: building STRINGS library source files");
		/********************** prologue */
		fputs("\
MAXLINELENGTH := 8192\n\
# Project specific C compiler flags\n\
MYCFLAGS_DBG = -UNDEBUG $(null,$(DEBUG) $(NULL) -DDEBUG=1)\n\
MYCFLAGS_NDBG = -DNDEBUG=1 -UDEBUG\n\
MYCFLAGS = $(null,$(NDEBUG) $(MYCFLAGS_DBG) $(MYCFLAGS_NDBG))\n\
\n\
#	Default target\n\
all: $(CFG) strings.lib\n\
\n\
strings.lib .LIBRARY : ", fdmake);

		/********************* individual files */
		for(cnt = 0; cnt < maxCnt; ++cnt) {
			dumpString(cnt);
			fprintf(fdmake, "\\\n\t" objfmt, cnt);
		}
		for(cnt = 0; cnt < maxCnt - 1; ++cnt)
#ifdef __TURBOC__
			fprintf(ftc101, "+" objfmt " &\n", cnt);
#else
			fprintf(ftc101, "+" objfmt "\n", cnt);
#endif
		fprintf(ftc101, "+" objfmt " \n", cnt);
		/********************** epilogue */

		fputs("\n\
\n\
.IF $(CFG) != $(NULL)\n\
\n\
CONFIGURATION = $(CONF_BASE)\n\
\n\
.IF $(_COMPTYPE) == BC\n\
CONF_BASE =	\\\n\
-f- \\\n\
-I$(INCDIR:s/;/ /:t\";\")	\\\n\
-L$(LIBDIR:s/;/ /:t\";\")	\\\n\
static void dumpValue(std::ostringstream& os, const JsonValue& o, int shiftWidth, const std::string& linefeed = "", int indent = 0) {
    switch (o.getTag()) {
    case JSON_NUMBER:
        char buffer[32];
        sprintf(buffer, "%f", o.toNumber());
        os << buffer;
        break;
    case JSON_TRUE:
        os << "true";
        break;        
    case JSON_FALSE:
        os << "false";
        break;
    case JSON_STRING:
        dumpString(os, o.toString());
        break;
    case JSON_ARRAY:
        // It is not necessary to use o.toNode() to check if an array or object
        // is empty before iterating over its members, we do it here to allow
        // nicer pretty printing.
        if (!o.toNode()) {
            os << "[]";
            break;
        }
        os << "[" << linefeed;
        for (auto i : o) {
            if (shiftWidth > 0)
                os << std::setw(indent + shiftWidth) << " " << std::setw(0);
            dumpValue(os, i->value, shiftWidth, linefeed, indent + shiftWidth);
            if (i->next)
                os << ",";
            os << linefeed;
        }
        if (indent > 0)
            os << std::setw(indent) << " " << std::setw(0);
        os.put(']');
        break;
    case JSON_OBJECT:
        if (!o.toNode()) {
            os << "{}";
            break;
        }
        os << "{" << linefeed;
        for (auto i : o) {
            if (shiftWidth > 0)
                os << std::setw(indent + shiftWidth) << " " << std::setw(0);
            dumpString(os, i->key);
            os << ":";
            dumpValue(os, i->value, shiftWidth, linefeed, indent + shiftWidth);
            if (i->next)
                os << ",";
            os << linefeed;
        }
        if (indent > 0)
            os << std::setw(indent) << " " << std::setw(0);
        os.put('}');
        break;
    case JSON_NULL:
        os << "null";
        break;
    }
}