/**
 * Determine if this is or is not a credit card number.
 * Return 1 if it is, 0 if it is not.
 * buf[-WINDOW_MARGIN] must be accessible.
 * buf[len+WINDOW_MARGIN] must be accessible
 */
bool valid_ccn(const char *buf,int buflen)
{
    /* Make the digits array */
    if(buflen>19) RETURN(0,"Too long");

    char digits[20];			// just the digits

    memset(digits,0,sizeof(digits));
    if(extract_digits_and_test(buf,buflen,digits)) RETURN(0,"failed nondigit count");
    if(prefix_test(digits))    RETURN(0,"failed prefix test");
    if(ccv1_test(digits))      RETURN(0,"failed ccv1 test");
    if(pattern_test(digits))   RETURN(0,"failed pattern test");
    if(histogram_test(digits)) RETURN(0,"failed histogram test");

    int before_window = 4;		// what we care about before
    int after_window = 4;		// what we care about before

    /* If the 4 characters before or after are hex digits but not decimal digits,
     * then this is probably not a credit card number.
     * We're probably instead in a sea of hex. So abort.
     */
    if(only_hex_digits(buf-before_window,before_window) && !only_dec_digits(buf-before_window,before_window)){
	RETURN(0,"failed before hex test");
    }
    if(only_hex_digits(buf+buflen,after_window) && !only_dec_digits(buf+buflen,after_window)){
	RETURN(0,"failed after hex test");
    }

    return 1;
}
static int validate_ccn_debug(const char *buf,int buflen)
{
    char digits[64];

    printf("running tests. 0 means passed, -1 means failed.\n\n");
    printf("nondigit_test(%s) = %d\n",buf,extract_digits_and_test(buf,buflen,digits));
    printf("prefix_test(%s) = %d \n",digits,prefix_test(digits));
    printf("ccv1_test(%s) = %d \n",digits,ccv1_test(digits));
    printf("histogram_test(%s) = %d \n",digits,histogram_test(digits));
    printf("pattern_test(%s) = %d \n",digits,pattern_test(digits));
    printf("only_hex_digits(%s) = %d\n",buf,only_hex_digits(buf,strlen(buf)));
    printf("only_dec_digits(%s) = %d\n",buf,only_dec_digits(buf,strlen(buf)));
    return validate_ccn(buf,buflen);
}
Example #3
0
int main(int argc, char *argv[])
{
    int found = UNKNOWN;
    int i;
    int id_start;
    int text_start;
    char *id_string;
    char *text_string;
    char *prefix_string;
    char *trail_string;
    char *text_string_orig;

    infile = fopen("../src/arch/amigaos/intl_text.c", "rb");
    if (infile == NULL) {
        close_all();
        return 1;
    }

    outfile = fopen("../src/arch/amigaos/temp_intl.h", "wb");
    if (outfile == NULL) {
        close_all();
        return 1;
    }

    fprintf(outfile, "/*\n");
    fprintf(outfile, " * intl_text.c - Translation texts to be included in intl.c\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " * Written by\n");
    fprintf(outfile, " *  Marco van den Heuvel <*****@*****.**>\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " * This file is part of VICE, the Versatile Commodore Emulator.\n");
    fprintf(outfile, " * See README for copyright notice.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " *  This program is free software; you can redistribute it and/or modify\n");
    fprintf(outfile, " *  it under the terms of the GNU General Public License as published by\n");
    fprintf(outfile, " *  the Free Software Foundation; either version 2 of the License, or\n");
    fprintf(outfile, " *  (at your option) any later version.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " *  This program is distributed in the hope that it will be useful,\n");
    fprintf(outfile, " *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
    fprintf(outfile, " *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
    fprintf(outfile, " *  GNU General Public License for more details.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " *  You should have received a copy of the GNU General Public License\n");
    fprintf(outfile, " *  along with this program; if not, write to the Free Software\n");
    fprintf(outfile, " *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\n");
    fprintf(outfile, " *  02111-1307  USA.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " */\n\n");
    fprintf(outfile, "intl_translate_t intl_string_table[] = {\n\n");

    while (found != FOUND_EMPTY_LINE) {
        found = genintl_getline(infile);
    }
    found = genintl_getline(infile);
    found = genintl_getline(infile);
    while (found != FOUND_END_OF_TABLE) {
        found = UNKNOWN;
        while (found != FOUND_EN && found != FOUND_END_OF_TABLE) {
            fwrite(line_buffer, 1, strlen(line_buffer), outfile);
            found = genintl_getline(infile);
        }
        if (found != FOUND_END_OF_TABLE) {
            i = 0;
            while (line_buffer[i] != '{') {
                i++;
            }
            id_start = i + 1;
            while (line_buffer[i] != ',') {
                i++;
            }
            line_buffer[i] = 0;
            while (line_buffer[i] != '"') {
                i++;
            }
            i++;
            text_start = i;
            while (!(line_buffer[i] == '"' && line_buffer[i + 1] == ' ' && line_buffer[i + 2] == '}' && line_buffer[i + 3] == ',')) {
                i++;
            }
            line_buffer[i] = 0;
            id_string = strdup(line_buffer + id_start);
            text_string = strdup(line_buffer + text_start);
            fprintf(outfile, "/* en */ {%s,    \"", line_buffer + id_start);
            write_converted_text(text_string, NULL, NULL);
            fprintf(outfile, "\" },\n/* da */ {%s_DA, \"", id_string);

            text_string_orig = strdup(text_string);

            prefix_string = prefix_test(text_string);
            trail_string = trailtest(text_string);

            for (i = 0; text[i].msgid != NULL; i++) {
                if (!strcmp(text[i].msgid, text_string)) {
                    break;
                }
                if (!strcmp(text[i].msgid, text_string_orig)) {
                    prefix_string = NULL;
                    trail_string = NULL;
                    break;
                }
            }
            if (strlen(text[i].msgstr_da) != 0) {
                write_converted_text(text[i].msgstr_da, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_da) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* de */ {%s_DE, \"", id_string);

            if (strlen(text[i].msgstr_de) != 0) {
                write_converted_text(text[i].msgstr_de, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_de) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* fr */ {%s_FR, \"", id_string);

            if (strlen(text[i].msgstr_fr) != 0) {
                write_converted_text(text[i].msgstr_fr, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_fr) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* hu */ {%s_HU, \"", id_string);

            if (strlen(text[i].msgstr_hu) != 0) {
                write_converted_text(text[i].msgstr_hu, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_hu) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* it */ {%s_IT, \"", id_string);

            if (strlen(text[i].msgstr_it) != 0) {
                write_converted_text(text[i].msgstr_it, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_it) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* ko */ {%s_KO, \"", id_string);

            if (strlen(text[i].msgstr_ko) != 0) {
                write_converted_text(text[i].msgstr_ko, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_ko) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* nl */ {%s_NL, \"", id_string);

            if (strlen(text[i].msgstr_nl) != 0) {
                write_converted_text(text[i].msgstr_nl, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_nl) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* ru */ {%s_RU, \"", id_string);

            if (strlen(text[i].msgstr_ru) != 0) {
                write_converted_text(text[i].msgstr_ru, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_ru) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* sv */ {%s_SV, \"", id_string);

            if (strlen(text[i].msgstr_sv) != 0) {
                write_converted_text(text[i].msgstr_sv, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_sv) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* tr */ {%s_TR, \"", id_string);

            if (strlen(text[i].msgstr_tr) != 0) {
                write_converted_text(text[i].msgstr_tr, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_tr) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n");
            while (found != FOUND_EMPTY_LINE) {
                found = genintl_getline(infile);
            }
            free(id_string);
            free(text_string);
            free(text_string_orig);
        }
    }
    fprintf(outfile, "};\n");
    close_all();
    return 0;
}
Example #4
0
int main(int argc, char *argv[])
{
    int found = UNKNOWN;
    int i = 0;
    int id;
    int failed = 0;
    char *text_string;
    char *prefix_string;
    char *trail_string;
    char *text_string_orig;

    if (argc != 2) {
        return 1;
    }

    infile = fopen(argv[1], "rb");
    if (infile == NULL) {
        close_all();
        return 1;
    }

    for (i = 0; files[i].filename != NULL; i++) {
        files[i].filehandle = fopen(files[i].filename, "wb");
        if (files[i].filehandle == NULL) {
            failed = 1;
        }
    }

    if (failed == 1) {
        close_all();
        return 1;
    }

    while (found != FOUND_STRINGTABLE && found != FOUND_EOF) {
        found = genrc_getline(infile);
        if (found != FOUND_EOF) {
            fwrite(line_buffer, 1, strlen(line_buffer), files[0].filehandle);
        }
    }
    if (found != FOUND_EOF) {
        for (i = 1; files[i].filename != NULL; i++) {
            fprintf(files[i].filehandle, "%s\n\n", files[i].title);
            if (files[i].pragma != NULL) {
                fprintf(files[i].filehandle, "#ifndef WINDRES_CP_IGNORE\n");
                fprintf(files[i].filehandle, "#pragma code_page(%s)\n", files[i].pragma);
                fprintf(files[i].filehandle, "#endif\n");
            }
            fprintf(files[i].filehandle, "STRINGTABLE\n");
            fprintf(files[i].filehandle, "LANGUAGE %s, %s\n", files[i].lang, files[i].sublang);
            fprintf(files[i].filehandle, "BEGIN\n");
        }
        while (found != FOUND_BEGIN) {
            found = genrc_getline(infile);
            fwrite(line_buffer, 1, strlen(line_buffer), files[0].filehandle);
        }
        found = genrc_getline(infile);
        while (found != FOUND_END) {
            if (found == FOUND_IFDEF || found == FOUND_ENDIF || found == FOUND_ELSE) {
                for (i = 0; files[i].filename != NULL; i++) {
                    fwrite(line_buffer, 1, strlen(line_buffer), files[i].filehandle);
                }
            } else {
                i = 0;
                while (line_buffer[i] != '"') {
                    i++;
                }
                line_buffer[i++] = 0;
                text_string = line_buffer + i;
                i += strlen(text_string);
                while (line_buffer[i] != '"') {
                    i--;
                }
                line_buffer[i] = 0;
                fprintf(files[0].filehandle, "%s\"", line_buffer);
                write_converted_text(text_string, files[0].filehandle, NULL, NULL);
                fprintf(files[0].filehandle, "\"\n");

                text_string_orig = strdup(text_string);

                prefix_string = prefix_test(text_string);
                trail_string = trailtest(text_string);

                for (id = 0; text[id].msgid != NULL; id++) {
                    if (!strcmp(text[id].msgid, text_string)) {
                        break;
                    }
                    if (!strcmp(text[id].msgid, text_string_orig)) {
                        prefix_string = NULL;
                        trail_string = NULL;
                        break;
                    }
                }
                for (i = 1; files[i].filename != NULL; i++) {
                    fprintf(files[i].filehandle, "%s\"", line_buffer);
                    switch (i) {
                        case 1:
                            if (strlen(text[id].msgstr_da) != 0) {
                                write_converted_text(text[id].msgstr_da, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 2:
                            if (strlen(text[id].msgstr_de) != 0) {
                                write_converted_text(text[id].msgstr_de, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 3:
                            if (strlen(text[id].msgstr_es) != 0) {
                                write_converted_text(text[id].msgstr_es, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 4:
                            if (strlen(text[id].msgstr_fr) != 0) {
                                write_converted_text(text[id].msgstr_fr, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 5:
                            if (strlen(text[id].msgstr_hu) != 0) {
                                write_converted_text(text[id].msgstr_hu, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 6:
                            if (strlen(text[id].msgstr_it) != 0) {
                                write_converted_text(text[id].msgstr_it, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 7:
                            if (strlen(text[id].msgstr_ko) != 0) {
                                write_converted_text(text[id].msgstr_ko, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 8:
                            if (strlen(text[id].msgstr_nl) != 0) {
                                write_converted_text(text[id].msgstr_nl, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 9:
                            if (strlen(text[id].msgstr_pl) != 0) {
                                write_converted_text(text[id].msgstr_pl, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 10:
                            if (strlen(text[id].msgstr_ru) != 0) {
                                write_converted_text(text[id].msgstr_ru, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 11:
                            if (strlen(text[id].msgstr_sv) != 0) {
                                write_converted_text(text[id].msgstr_sv, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 12:
                            if (strlen(text[id].msgstr_tr) != 0) {
                                write_converted_text(text[id].msgstr_tr, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                    }
                    fprintf(files[i].filehandle, "\"\n");
                }
                free(text_string_orig);
            }
            found = genrc_getline(infile);
        }
        for (i = 0; files[i].filename != NULL; i++) {
            fprintf(files[i].filehandle, "END\n");
            if (files[i].pragma != NULL) {
                fprintf(files[i].filehandle, "#ifndef WINDRES_CP_IGNORE\n");
                fprintf(files[i].filehandle, "#pragma code_page(28591)\n");
                fprintf(files[i].filehandle, "#endif\n");
            }
            fprintf(files[i].filehandle, "\n\n");
        }
    }
    close_all();
    return 0;
}