void protect_special_characters(const char *text,Encoding encoding_output,int bom_output,int mask_encoding_compatibility_input){ U_FILE *source; U_FILE *destination; //fprintf(stdout,"protect special character\n"); char temp_name_file[FILENAME_MAX]; char path[FILENAME_MAX]; get_path(text,path); sprintf(temp_name_file,"%stemp",path); source = u_fopen_existing_versatile_encoding(mask_encoding_compatibility_input, text,U_READ); if( source == NULL){ perror("u_fopen\n"); fprintf(stderr,"Cannot open file %s\n",text); exit(1); } destination = u_fopen_versatile_encoding(encoding_output,bom_output,mask_encoding_compatibility_input,temp_name_file,U_WRITE); if( destination == NULL){ perror("u_fopen\n"); fprintf(stderr,"Cannot open file %s\n",temp_name_file); exit(1); } int a; a = u_fgetc(source); while(a!=EOF){ u_fputc((unichar)a,destination); if(a=='{'){ //fprintf(stdout,"opening bracket found\n"); unichar *bracket_string = get_braced_string(source); unichar *protected_bracket_string = protect_braced_string(bracket_string); //u_fprints(protected_bracket_string,destination); u_fprintf(destination,"%S",protected_bracket_string); //u_printf("%S --- ",bracket_string); //u_printf("%S\n",protected_bracket_string); free(bracket_string); free(protected_bracket_string); } a = u_fgetc(source); } u_fclose(source); u_fclose(destination); copy_file(text,temp_name_file); // should delete the 'temp' file }
void parse_text(struct fst2txt_parameters* p) { fill_buffer(p->text_buffer,p->f_input); int debut=p->fst2->initial_states[1]; p->variables=new_Variables(p->fst2->input_variables); int n_blocks=0; u_printf("Block %d",n_blocks); int within_tag=0; while (p->current_origin<p->text_buffer->size) { if (!p->text_buffer->end_of_file && p->current_origin>(p->text_buffer->size-MINIMAL_SIZE_PRELOADED_TEXT)) { /* If must change of block, we update the absolute offset, and we fill the * buffer. */ p->absolute_offset=p->absolute_offset+p->current_origin; fill_buffer(p->text_buffer,p->current_origin,p->f_input); p->current_origin=0; n_blocks++; u_printf("\rBlock %d ",n_blocks); } p->output[0]='\0'; empty(p->stack); p->input_length=0; //memset(p->buffer,0,p->current_origin); if (p->buffer[p->current_origin]=='{') { within_tag=1; } else if (p->buffer[p->current_origin]=='}') { within_tag=0; } else if (!within_tag && (p->buffer[p->current_origin]!=' ' || p->space_policy==START_WITH_SPACE)) { // we don't start a match on a space unichar mot_token_buffer[MOT_BUFFER_TOKEN_SIZE]; scan_graph(0,debut,0,0,NULL,mot_token_buffer,p); } u_fprintf(p->f_output,"%S",p->output); if (p->input_length==0) { // if no input was read, we go on u_fputc(p->buffer[p->current_origin],p->f_output); (p->current_origin)++; } else { // we increase current_origin p->current_origin=p->current_origin+p->input_length; } } u_printf("\r \n"); free_Variables(p->variables); p->variables=NULL; }
void MweSplitApplicator::printSingleWindow(SingleWindow* window, std::ostream& output) { for (auto var : window->variables_output) { Tag* key = single_tags[var]; auto iter = window->variables_set.find(var); if (iter != window->variables_set.end()) { if (iter->second != grammar->tag_any) { Tag* value = single_tags[iter->second]; u_fprintf(output, "%S%S=%S>\n", stringbits[S_CMD_SETVAR].c_str(), key->tag.c_str(), value->tag.c_str()); } else { u_fprintf(output, "%S%S>\n", stringbits[S_CMD_SETVAR].c_str(), key->tag.c_str()); } } else { u_fprintf(output, "%S%S>\n", stringbits[S_CMD_REMVAR].c_str(), key->tag.c_str()); } } if (!window->text.empty()) { u_fprintf(output, "%S", window->text.c_str()); if (!ISNL(window->text[window->text.size() - 1])) { u_fputc('\n', output); } } uint32_t cs = (uint32_t)window->cohorts.size(); for (uint32_t c = 0; c < cs; c++) { Cohort* cohort = window->cohorts[c]; std::vector<Cohort*> cs = splitMwe(cohort); for (auto iter : cs) { printCohort(iter, output); } } u_fputc('\n', output); u_fflush(output); }
/** * Saves the given automaton into the given .fst2 file. */ void fst_file_write(Elag_fst_file_out* fstf,const Fst2Automaton* A) { Ustring* tag=new_Ustring(); void (*symbol_to_tag)(const symbol_t*,Ustring*)=NULL; switch (fstf->type) { case FST_TEXT: symbol_to_tag=symbol_to_text_label; break; case FST_GRAMMAR: symbol_to_tag=symbol_to_grammar_label; break; case FST_LOCATE: symbol_to_tag=symbol_to_locate_label; break; default: fatal_error("fst_file_write: invalid fstf->type: %d\n",fstf->type); } /* We save the graph number and name */ u_fprintf(fstf->f,"-%d %S\n",fstf->nb_automata+1,A->name); int index; unichar deflabel[]={'<','d','e','f','>',0}; for (int q=0;q<A->automaton->number_of_states;q++) { SingleGraphState state=A->automaton->states[q]; u_fprintf(fstf->f,"%C ",is_final_state(state)?'t':':'); for (Transition* t=state->outgoing_transitions;t!=NULL;t=t->next) { if (t->tag_number==-1) { /* If we are in the case of an "EMPTY" transition created because * the automaton was emptied as trim time */ u_strcpy(tag,"EMPTY"); } else { symbol_t* symbol=t->label; symbol_to_tag(symbol,tag); } if (fstf->type==FST_LOCATE) { /* If we are saving a Locate .fst2, we have to perform * some special things */ if (u_strcmp(tag->str, "<PNC>") == 0) { PNC_trans_write(fstf, t->state_number); } else if (u_strcmp(tag->str, "<CHFA>") == 0 || u_strcmp(tag->str, "<NB>") == 0) { CHFA_trans_write(fstf, t->state_number); } else if (u_strcmp(tag->str, "<.>") == 0) { LEXIC_trans_write(fstf, t->state_number); } else { goto normal_output; } } else { /* If we have a normal transition to print */ normal_output: index=get_value_index(tag->str,fstf->labels); u_fprintf(fstf->f,"%d %d ",index,t->state_number); } } if (state->default_state!=-1) { if (fstf->type!=FST_GRAMMAR) { error("Unexpected <def> label in text/locate automaton\n"); } index=get_value_index(deflabel,fstf->labels); u_fprintf(fstf->f,"%d %d ",index,state->default_state); } u_fputc('\n',fstf->f); } u_fprintf(fstf->f,"f \n"); free_Ustring(tag); fstf->nb_automata++; }
extern int main(int argc, char* argv[]) { const char *encoding = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = "."; int tostdout = 0; int prbom = 0; const char *pname; UResourceBundle *bundle = NULL; int32_t i = 0; const char* arg; /* Get the name of tool. */ pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (!pname) { pname = uprv_strrchr(*argv, U_FILE_ALT_SEP_CHAR); } #endif if (!pname) { pname = *argv; } else { ++pname; } /* error handling, printing usage message */ argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", pname, argv[-argc]); } if(argc<0 || options[0].doesOccur || options[1].doesOccur) { fprintf(argc < 0 ? stderr : stdout, "%csage: %s [ -h, -?, --help ] [ -V, --version ]\n" " [ -v, --verbose ] [ -e, --encoding encoding ] [ --bom ]\n" " [ -t, --truncate [ size ] ]\n" " [ -s, --sourcedir source ] [ -d, --destdir destination ]\n" " [ -i, --icudatadir directory ] [ -c, --to-stdout ]\n" " [ -A, --suppressAliases]\n" " bundle ...\n", argc < 0 ? 'u' : 'U', pname); return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[10].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", pname, DERB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); return U_ZERO_ERROR; } if(options[2].doesOccur) { encoding = options[2].value; } if (options[3].doesOccur) { if(options[2].doesOccur) { fprintf(stderr, "%s: Error: don't specify an encoding (-e) when writing to stdout (-c).\n", pname); return 3; } tostdout = 1; } if(options[4].doesOccur) { opt_truncate = TRUE; if(options[4].value != NULL) { truncsize = atoi(options[4].value); /* user defined printable size */ } else { truncsize = DERB_DEFAULT_TRUNC; /* we'll use default omitting size */ } } else { opt_truncate = FALSE; } if(options[5].doesOccur) { verbose = TRUE; } if (options[6].doesOccur) { outputDir = options[6].value; } if(options[7].doesOccur) { inputDir = options[7].value; /* we'll use users resources */ } if (options[8].doesOccur) { prbom = 1; } if (options[9].doesOccur) { u_setDataDirectory(options[9].value); } if (options[11].doesOccur) { suppressAliases = TRUE; } fflush(stderr); // use ustderr now. ustderr = u_finit(stderr, NULL, NULL); for (i = 1; i < argc; ++i) { static const UChar sp[] = { 0x0020 }; /* " " */ arg = getLongPathname(argv[i]); if (verbose) { u_fprintf(ustderr, "processing bundle \"%s\"\n", argv[i]); } icu::CharString locale; UErrorCode status = U_ZERO_ERROR; { const char *p = findBasename(arg); const char *q = uprv_strrchr(p, '.'); if (q == NULL) { locale.append(p, status); } else { locale.append(p, (int32_t)(q - p), status); } } if (U_FAILURE(status)) { return status; } icu::CharString infile; const char *thename = NULL; UBool fromICUData = !uprv_strcmp(inputDir, "-"); if (!fromICUData) { UBool absfilename = *arg == U_FILE_SEP_CHAR; #if U_PLATFORM_HAS_WIN32_API if (!absfilename) { absfilename = (uprv_strlen(arg) > 2 && isalpha(arg[0]) && arg[1] == ':' && arg[2] == U_FILE_SEP_CHAR); } #endif if (absfilename) { thename = arg; } else { const char *q = uprv_strrchr(arg, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (q == NULL) { q = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); } #endif infile.append(inputDir, status); if(q != NULL) { infile.appendPathPart(icu::StringPiece(arg, (int32_t)(q - arg)), status); } if (U_FAILURE(status)) { return status; } thename = infile.data(); } } if (thename) { bundle = ures_openDirect(thename, locale.data(), &status); } else { bundle = ures_open(fromICUData ? 0 : inputDir, locale.data(), &status); } if (U_SUCCESS(status)) { UFILE *out = NULL; const char *filename = 0; const char *ext = 0; if (locale.isEmpty() || !tostdout) { filename = findBasename(arg); ext = uprv_strrchr(filename, '.'); if (!ext) { ext = uprv_strchr(filename, 0); } } if (tostdout) { out = u_get_stdout(); } else { icu::CharString thefile; if (outputDir) { thefile.append(outputDir, status); } thefile.appendPathPart(filename, status); if (*ext) { thefile.truncate(thefile.length() - (int32_t)uprv_strlen(ext)); } thefile.append(".txt", status); if (U_FAILURE(status)) { return status; } out = u_fopen(thefile.data(), "w", NULL, encoding); if (!out) { u_fprintf(ustderr, "%s: couldn't create %s\n", pname, thefile.data()); u_fclose(ustderr); return 4; } } // now, set the callback. ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); if (U_FAILURE(status)) { u_fprintf(ustderr, "%s: couldn't configure converter for encoding\n", pname); u_fclose(ustderr); if(!tostdout) { u_fclose(out); } return 3; } if (prbom) { /* XXX: Should be done only for UTFs */ u_fputc(0xFEFF, out); } u_fprintf(out, "// -*- Coding: %s; -*-\n//\n", encoding ? encoding : getEncodingName(ucnv_getDefaultName())); u_fprintf(out, "// This file was dumped by derb(8) from "); if (thename) { u_fprintf(out, "%s", thename); } else if (fromICUData) { u_fprintf(out, "the ICU internal %s locale", locale.data()); } u_fprintf(out, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n"); if (!locale.isEmpty()) { u_fprintf(out, "%s", locale.data()); } else { u_fprintf(out, "%.*s%.*S", (int32_t)(ext - filename), filename, UPRV_LENGTHOF(sp), sp); } printOutBundle(out, bundle, 0, pname, &status); if (!tostdout) { u_fclose(out); } } else { reportError(pname, &status, "opening resource file"); } ures_close(bundle); } return 0; }
int xmlize(const VersatileEncodingConfig* vec,const char* fin,const char* fout,int ouput_style) { U_FILE* input = u_fopen(vec, fin, U_READ); if (input == NULL) { error("Input file '%s' not found!\n", fin); return DEFAULT_ERROR_CODE; } U_FILE* output = u_fopen(UTF8, fout, U_WRITE); if (output == NULL) { error("Cannot open output file '%s'!\n", fout); u_fclose(input); return DEFAULT_ERROR_CODE; } else // FIXME(johndoe) put breaks if(ouput_style==XML) { u_fprintf(output, xml_open); } else { u_fprintf(output, tei_open); } int sentence_count = 1; int sentence_count_relative = 1; int paragraph_count = 1; u_fprintf(output, "<p><s id=\"n%d\" xml:id=\"d1p%ds%d\">",sentence_count++,paragraph_count,sentence_count_relative++); int current_state = 0; unichar c; int i; while ((i = u_fgetc(input)) != EOF) { c = (unichar)i; switch (current_state) { case 0: { if ( c == '{') current_state = 1; else if(c == '&') u_fprintf(output, "&"); else if(c == '<') u_fprintf(output, "<"); else if(c == '>') u_fprintf(output, ">"); else u_fputc(c, output); break; } case 1: { if (c == 'S') current_state = 2; else { u_fputc('{', output); u_fputc(c, output); current_state = 0; } break; } case 2: { if (c == '}') current_state = 3; else { u_fputc('{', output); u_fputc('S', output); u_fputc(c, output); current_state = 0; } break; } case 3: { if (c == '{') current_state = 4; else if (c == '\n' || c == ' ' || c == '\t') { u_fputc(c, output); current_state = 3; } else { u_fprintf(output, "</s><s id=\"n%d\" xml:id=\"d1p%ds%d\">",sentence_count++,paragraph_count,sentence_count_relative++); u_fputc(c, output); current_state = 0; } break; } case 4: { if (c == 'S') current_state = 7; else if (c == 'P') current_state = 5; else { u_fputc('{', output); u_fputc(c, output); current_state = 0; } break; } case 5: { if (c == '}') { u_fprintf(output, "</s></p>\n"); paragraph_count++; sentence_count_relative=1; current_state = 6; } else { u_fputc('{', output); u_fputc('P', output); u_fputc(c, output); current_state = 0; } break; } case 6: { if (c == '\n' || c == ' ' || c == '\t') u_fputc(c, output); else { u_fprintf(output, "<p><s id=\"n%d\" xml:id=\"d1p%ds%d\">",sentence_count++,paragraph_count,sentence_count_relative++); u_fputc(c, output); current_state = 0; } break; } case 7: { if (c == '}') { current_state = 3; } else { u_fputc('{', output); u_fputc('S', output); u_fputc(c, output); current_state = 0; } break; } } } if (current_state == 3) { //... } else if (current_state == 6) { //... } else { u_fprintf(output, "</s></p>\n"); } if(ouput_style==XML) { u_fprintf(output, xml_close); } else { u_fprintf(output, tei_close); } u_fclose(input); u_fclose(output); u_printf("Done.\n"); return SUCCESS_RETURN_CODE; }
int tei2txt(char *fin, char *fout, const VersatileEncodingConfig* vec) { void* html_ctx = init_HTML_character_context(); if (html_ctx == NULL) { alloc_error("tei2txt"); return ALLOC_ERROR_CODE; } U_FILE* input = u_fopen(vec, fin, U_READ); if (input == NULL) { error("Input file '%s' not found!\n", fin); free_HTML_character_context(html_ctx); return DEFAULT_ERROR_CODE; } U_FILE* output = u_fopen(vec, fout, U_WRITE); if (output == NULL) { error("Cannot open output file '%s'!\n", fout); u_fclose(input); free_HTML_character_context(html_ctx); return DEFAULT_ERROR_CODE; } unichar buffer[5000]; int i, j, k; unichar c; if((i = u_fgetc(input)) != EOF) { c = (unichar)i; for (;;) { while(c != '<' && (i = u_fgetc(input)) != EOF) { c = (unichar)i; } j = 0; while((i = u_fgetc(input)) != EOF && (c = (unichar)i) != ' ' && (c = (unichar)i) != '\t' && (c = (unichar)i) != '\n' && (c = (unichar)i) != '>') { buffer[j++] = c; } buffer[j] = '\0'; if (c!='>') { /* We do this because we can find <body ...> */ while((i = u_fgetc(input)) != EOF && (c = (unichar)i) != '>') {} } //u_printf("Current tag : <%S>\n", buffer); if(!u_strcmp(buffer, body)) { break; } else { buffer[0] = '\0'; } } } else { error("Empty TEI file %s\n", fin); } char schars[11]; int first_sentence=1; int current_state = 0; int inside_sentence=0; while ((i = u_fgetc(input)) != EOF) { c = (unichar)i; switch (current_state) { case 0: { if(c == '<') { current_state = 1; inside_sentence=0; } else if(c == '&') { current_state = 3; } else if (inside_sentence) { u_fputc(c, output); } break; } case 1: { if(c == 's' || c == 'S') { current_state = 2; } else { while((i = u_fgetc(input)) != EOF) { c = (unichar)i; if(c == '>') { break; } } current_state = 0; } break; } case 2: { if(c == ' ' || c == '>') { current_state = 0; inside_sentence=1; if (!first_sentence) { /* We put a {STOP} tag in order to avoid matches that overlap 2 sentences */ u_fprintf(output,"\n{STOP}{S}"); } else { first_sentence=0; } } if(c != '>') { while((i = u_fgetc(input)) != EOF) { c = (unichar)i; if(c == '>') { break; } } } break; } case 3: { j = 0; while(c != ';' && (i = u_fgetc(input)) != EOF) { //u_printf("Current S-character: %C\n", c); schars[j++] = (char)c; c = (unichar)i; } schars[j] = '\0'; //u_printf("Current S-chain: %S\n", schars); k = get_HTML_character(html_ctx,schars, 1); switch (k) { case UNKNOWN_CHARACTER: { u_fputc('?', output); break; } case MALFORMED_HTML_CODE: { error("Malformed HTML character declaration &%s;\n", schars); u_fputc('?', output); break; } default: { c = (unichar)k; u_fputc(c, output); break; } } schars[0] = '\0'; current_state = 0; break; } } } u_fclose(output); u_fclose(input); free_HTML_character_context(html_ctx); u_printf("Done.\n"); return SUCCESS_RETURN_CODE; }
/* * main() This one function is all of the application code. */ int main(int argc, char **argv) { UBool displayUsage = FALSE; /* Set true if command line err or help */ /* option was requested. */ UBool verbose = FALSE; /* Set true if -v command line option. */ char *optionError = NULL; /* If command line contains an unrecognized */ /* option, this will point to it. */ char *locale=NULL; /* Locale name. Null for system default, */ /* otherwise set from command line. */ const char * programName = argv[0]; /* Program invocation name. */ UFILE *u_stdout; /* Unicode stdout file. */ UErrorCode err = U_ZERO_ERROR; /* Error return, used for most ICU */ /* functions. */ UResourceBundle *myResources; /* ICU Resource "handles" */ UResourceBundle *fortunes_r; int32_t numFortunes; /* Number of fortune strings available. */ int i; const UChar *resString; /* Points to strings fetched from Resources. */ int32_t len; /* Process command line options. * -l locale specify a locale * -v verbose mode. Display extra messages. * -? or --help display a usage line */ for (i=1; i<argc; i++) { if (strcmp(argv[i], "-l") ==0) { if (++i < argc) { locale = argv[i]; } continue; } if (strcmp(argv[i], "-v") == 0) { verbose = TRUE; continue;} if (strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "--help") == 0) { displayUsage = TRUE; continue;} optionError = argv[i]; displayUsage = TRUE; break; } /* ICU's icuio package provides a convenient way to write Unicode * data to stdout. The string data that we get from resources * will be UChar * strings, which icuio can handle nicely. */ u_stdout = u_finit(stdout, NULL /*locale*/, NULL /*codepage */); if (verbose) { u_fprintf(u_stdout, "%s: checking output via icuio.\n", programName); } #ifndef UFORTUNE_NOSETAPPDATA /* Tell ICU where our resource data is located in memory. * The data lives in the Fortune_Resources dll, and we just * pass the address of an exported symbol from that library * to ICU. */ udata_setAppData("fortune_resources", &fortune_resources_dat, &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: udata_setAppData failed with error \"%s\"\n", programName, u_errorName(err)); exit(-1); } #endif /* Open our resources. */ myResources = ures_open("fortune_resources", locale, &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: ures_open failed with error \"%s\"\n", programName, u_errorName(err)); exit(-1); } if (verbose) { u_fprintf(u_stdout, "status from ures_open(\"fortune_resources\", %s) is %s\n", locale? locale: " ", u_errorName(err)); } /* * Display any command line option usage errors and/or the * usage help message. These messages come from our resource bundle. */ if (optionError != NULL) { const UChar *msg = ures_getStringByKey(myResources, "optionMessage", &len, &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: ures_getStringByKey(\"optionMessage\") failed, %s\n", programName, u_errorName(err)); exit(-1); } u_file_write(msg, len, u_stdout); /* msg is UChar *, from resource */ u_fprintf(u_stdout, " %s\n", optionError); /* optionError is char *, from argv */ } if (displayUsage) { const UChar *usage; int returnValue=0; usage = ures_getStringByKey(myResources, "usage", &len, &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: ures_getStringByKey(\"usage\") failed, %s\n", programName, u_errorName(err)); exit(-1); } u_file_write(usage, len, u_stdout); if (optionError != NULL) {returnValue = -1;} return returnValue; } /* * Open the "fortunes" resources from within the already open resources */ fortunes_r = ures_getByKey(myResources, "fortunes", NULL, &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: ures_getByKey(\"fortunes\") failed, %s\n", programName, u_errorName(err)); exit(-1); } /* * Pick up and display a random fortune * */ numFortunes = ures_countArrayItems(myResources, "fortunes", &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: ures_countArrayItems(\"fortunes\") failed, %s\n", programName, u_errorName(err)); exit(-1); } if (numFortunes <= 0) { fprintf(stderr, "%s: no fortunes found.\n", programName); exit(-1); } i = (int)time(NULL) % numFortunes; /* Use time to pick a somewhat-random fortune. */ resString = ures_getStringByIndex(fortunes_r, i, &len, &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: ures_getStringByIndex(%d) failed, %s\n", programName, i, u_errorName(err)); exit(-1); } u_file_write(resString, len, u_stdout); /* Write out the message */ u_fputc(0x0a, u_stdout); /* and a trailing newline */ return 0; }
/** * Displays the letter keys of a given keyboard */ void print_Keyboard(Keyboard* keyboard,U_FILE* out) { if (keyboard==NULL) { fatal_error("Unexpected NULL keyboard error in print_Keyboard\n"); } u_fprintf(out," Keyboard name=%s\n\n",keyboard->name); u_fprintf(out," %s\n\n",keyboard->comment); /*----- First keyboard line -------*/ u_fputc(0x250C,out); for (int i=0;i<PC_KEYBOARD_UPPER_LINE_SIZE;i++) { u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x252C,out); } u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2510,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_UPPER_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->up0[i]!=NO_KEY_DEFINED)?keyboard->up0[i]:' ',out); u_fputc(' ',out); u_fputc(' ',out); u_fputc(0x2502,out); } u_fprintf(out," <"); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fprintf(out," "); u_fputc(0x2502,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_UPPER_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->low0[i]!=NO_KEY_DEFINED)?keyboard->low0[i]:' ',out); u_fputc(' ',out); u_fputc((keyboard->alt0[i]!=NO_KEY_DEFINED)?keyboard->alt0[i]:' ',out); u_fputc(0x2502,out); } u_fprintf(out," "); u_fputc(0x2502,out); u_fputc('\n',out); /*-------- Second keyboard line -----------*/ u_fputc(0x251C,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); for (int i=0;i<PC_KEYBOARD_LINE_SIZE;i++) { u_fputc(0x2500,out); u_fputc(0x252C,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); } u_fputc(0x2500,out); u_fputc(0x252C,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2524,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); u_fprintf(out," |<- "); u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->up1[i]!=NO_KEY_DEFINED)?keyboard->up1[i]:' ',out); u_fputc(' ',out); u_fputc(' ',out); u_fputc(0x2502,out); } u_fprintf(out," "); u_fputc(0x2502,out); u_fputc(' ',out); u_fputc(0x2502,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); u_fprintf(out," ->| "); u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->low1[i]!=NO_KEY_DEFINED)?keyboard->low1[i]:' ',out); u_fputc(' ',out); u_fputc((keyboard->alt1[i]!=NO_KEY_DEFINED)?keyboard->alt1[i]:' ',out); u_fputc(0x2502,out); } u_fprintf(out," <"); u_fputc(0x2500,out); u_fputc(0x2518,out); u_fputc(' ',out); u_fputc(0x2502,out); u_fputc('\n',out); /*-------- Third keyboard line --------*/ u_fputc(0x251C,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); for (int i=0;i<PC_KEYBOARD_LINE_SIZE;i++) { u_fputc(0x2500,out); u_fputc(0x252C,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); } u_fputc(0x2500,out); u_fputc(0x2510,out); u_fputc(' ',out); u_fputc(' ',out); u_fputc(' ',out); u_fputc(0x2502,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); u_fprintf(out," Caps "); u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->up2[i]!=NO_KEY_DEFINED)?keyboard->up2[i]:' ',out); u_fputc(' ',out); u_fputc(' ',out); u_fputc(0x2502,out); } u_fprintf(out," "); u_fputc(0x2502,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); u_fprintf(out," Lock "); u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->low2[i]!=NO_KEY_DEFINED)?keyboard->low2[i]:' ',out); u_fputc(' ',out); u_fputc((keyboard->alt2[i]!=NO_KEY_DEFINED)?keyboard->alt2[i]:' ',out); u_fputc(0x2502,out); } u_fprintf(out," "); u_fputc(0x2502,out); u_fputc('\n',out); /*-------- Fourth keyboard line ----------*/ u_fputc(0x251C,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x252C,out); u_fputc(0x2500,out); u_fputc(0x2534,out); for (int i=0;i<PC_KEYBOARD_LOWER_LINE_SIZE;i++) { u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x252C,out); u_fputc(0x2500,out); u_fputc(0x2534,out); } u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2524,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); u_fprintf(out," "); u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_LOWER_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->up3[i]!=NO_KEY_DEFINED)?keyboard->up3[i]:' ',out); u_fputc(' ',out); u_fputc(' ',out); u_fputc(0x2502,out); } u_fprintf(out," "); u_fputc(0x2502,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2502,out); u_fprintf(out," Shift"); u_fputc(0x2502,out); for (int i=0;i<PC_KEYBOARD_LOWER_LINE_SIZE;i++) { u_fputc(' ',out); u_fputc((keyboard->low3[i]!=NO_KEY_DEFINED)?keyboard->low3[i]:' ',out); u_fputc(' ',out); u_fputc((keyboard->alt3[i]!=NO_KEY_DEFINED)?keyboard->alt3[i]:' ',out); u_fputc(0x2502,out); } u_fprintf(out," Shift "); u_fputc(0x2502,out); u_fputc('\n',out); /*-----------------------------*/ u_fputc(0x2514,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); for (int i=0;i<PC_KEYBOARD_LOWER_LINE_SIZE-1;i++) { u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); } u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2534,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2500,out); u_fputc(0x2518,out); u_fputc('\n',out); }