static alignment utoalign(wchar_t *p) { if (!ustricmp(p, L"centre") || !ustricmp(p, L"center")) return CENTRE; if (!ustricmp(p, L"leftplus")) return LEFTPLUS; return LEFT; }
/* be_sys_find_resource: * This is the same of the unix resource finder; it looks into the * home directory and in /etc. */ int be_sys_find_resource(char *dest, AL_CONST char *resource, int size) { char buf[256], tmp[256], *last; char *home = getenv("HOME"); if (home) { /* look for ~/file */ append_filename(buf, uconvert_ascii(home, tmp), resource, sizeof(buf)); if (exists(buf)) { ustrzcpy(dest, size, buf); return 0; } /* if it is a .cfg, look for ~/.filerc */ if (ustricmp(get_extension(resource), uconvert_ascii("cfg", tmp)) == 0) { ustrzcpy(buf, sizeof(buf) - ucwidth(OTHER_PATH_SEPARATOR), uconvert_ascii(home, tmp)); put_backslash(buf); ustrzcat(buf, sizeof(buf), uconvert_ascii(".", tmp)); ustrzcpy(tmp, sizeof(tmp), resource); ustrzcat(buf, sizeof(buf), ustrtok_r(tmp, ".", &last)); ustrzcat(buf, sizeof(buf), uconvert_ascii("rc", tmp)); if (file_exists(buf, FA_ARCH | FA_RDONLY | FA_HIDDEN, NULL)) { ustrzcpy(dest, size, buf); return 0; } } } /* look for /etc/file */ append_filename(buf, uconvert_ascii("/etc/", tmp), resource, sizeof(buf)); if (exists(buf)) { ustrzcpy(dest, size, buf); return 0; } /* if it is a .cfg, look for /etc/filerc */ if (ustricmp(get_extension(resource), uconvert_ascii("cfg", tmp)) == 0) { ustrzcpy(buf, sizeof(buf), uconvert_ascii("/etc/", tmp)); ustrzcpy(tmp, sizeof(tmp), resource); ustrzcat(buf, sizeof(buf), ustrtok_r(tmp, ".", &last)); ustrzcat(buf, sizeof(buf), uconvert_ascii("rc", tmp)); if (exists(buf)) { ustrzcpy(dest, size, buf); return 0; } } return -1; }
static void apply_shortcut_to_menuitems_with_command(Menu* menu, Command *command, Params* params, JAccel accel) { JList children = menu->getChildren(); JLink link; JI_LIST_FOR_EACH(children, link) { Widget* child = (Widget*)link->data; if (child->getType() == JI_MENUITEM) { ASSERT(dynamic_cast<MenuItem2*>(child) != NULL); MenuItem2* menuitem = static_cast<MenuItem2*>(child); Command* mi_command = menuitem->getCommand(); Params* mi_params = menuitem->getParams(); if (mi_command && ustricmp(mi_command->short_name(), command->short_name()) == 0 && ((mi_params && *mi_params == *params) || (Params() == *params))) { // Set the accelerator to be shown in this menu-item menuitem->setAccel(jaccel_new_copy(accel)); } if (Menu* submenu = menuitem->getSubmenu()) apply_shortcut_to_menuitems_with_command(submenu, command, params, accel); } }
int eof_copy_file(const char * src, const char * dest) { PACKFILE * src_fp = NULL; PACKFILE * dest_fp = NULL; void *ptr = NULL; //Used to buffer memory unsigned long src_size = 0; unsigned long i; eof_log("eof_copy_file() entered", 1); if((src == NULL) || (dest == NULL)) return 0; if(!ustricmp(src,dest)) //Special case: The input and output file are the same return 0; //Return success without copying any files src_size = (unsigned long)file_size_ex(src); if(src_size > LONG_MAX) return 0; //Unable to validate I/O due to Allegro's usage of signed values src_fp = pack_fopen(src, "r"); if(!src_fp) { return 0; } dest_fp = pack_fopen(dest, "w"); if(!dest_fp) { (void) pack_fclose(src_fp); return 0; } //Attempt to buffer the input file into memory for faster read and write ptr = malloc((size_t)src_size); if(ptr != NULL) { //If a buffer large enough to store the input file was created long long_src_size = src_size; if((pack_fread(ptr, long_src_size, src_fp) != long_src_size) || (pack_fwrite(ptr, long_src_size, dest_fp) != long_src_size)) { //If there was an error reading from file or writing from memory free(ptr); //Release buffer return 0; //Return error } free(ptr); //Release buffer } else { //Otherwise copy the slow way (one byte at a time) for(i = 0; i < src_size; i++) { (void) pack_putc(pack_getc(src_fp), dest_fp); } } (void) pack_fclose(src_fp); (void) pack_fclose(dest_fp); return 1; }
Command* CommandsModule::getCommandByName(const char* name) { if (!name) return NULL; for (CommandsList::iterator it = m_commands.begin(); it != m_commands.end(); ++it) { if (ustricmp((*it)->short_name(), name) == 0) return *it; } return NULL; }
static void process_one_word(Accelerator* accel, char* word) { KeyModifiers modifiers = kKeyNoneModifier; KeyScancode scancode = kKeyNil; int ascii = 0; char* tok; // Special case: plus sign if (word[0] == '+' && word[1] == 0) { accel->addKey(kKeyNoneModifier, kKeyNil, '+'); return; } for (tok=ustrtok(word, "+"); tok; tok=ustrtok(NULL, "+")) { // Modifiers if (ustricmp(tok, "Shift") == 0) { modifiers = (KeyModifiers)((int)modifiers | (int)kKeyShiftModifier); } else if (ustricmp (tok, "Alt") == 0) { modifiers = (KeyModifiers)((int)modifiers | (int)kKeyAltModifier); } else if (ustricmp (tok, "Ctrl") == 0) { modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier); } // Scancode // word with one character else if (tok[1] == 0) { if (((*tok >= 'a') && (*tok <= 'z')) || ((*tok >= 'A') && (*tok <= 'Z'))) { ascii = tolower(*tok); } else { ascii = *tok; } if (((*tok >= 'a') && (*tok <= 'z')) || ((*tok >= 'A') && (*tok <= 'Z'))) scancode = (KeyScancode)((int)kKeyA + tolower(*tok) - 'a'); else if ((*tok >= '0') && (*tok <= '9')) scancode = (KeyScancode)((int)kKey0 + *tok - '0'); else { switch (*tok) { case '~': scancode = kKeyTilde; break; case '-': scancode = kKeyMinus; break; case '=': scancode = kKeyEquals; break; case '[': scancode = kKeyOpenbrace; break; case ']': scancode = kKeyClosebrace; break; case ';': scancode = kKeyColon; break; case '\'': scancode = kKeyQuote; break; case '\\': scancode = kKeyBackslash; break; case ',': scancode = kKeyComma; break; case '.': scancode = kKeyStop; break; case '/': scancode = kKeySlash; break; case '*': scancode = kKeyAsterisk; break; } } } /* other ones */ else { /* F1, F2, ..., F11, F12 */ if ((toupper (*tok) == 'F') && (ustrlen(tok) <= 3)) { int num = ustrtol(tok+1, NULL, 10); if ((num >= 1) && (num <= 12)) scancode = (KeyScancode)((int)kKeyF1 + num - 1); } else if ((ustricmp(tok, "Escape") == 0) || (ustricmp(tok, "Esc") == 0)) scancode = kKeyEsc; else if (ustricmp(tok, "Backspace") == 0) scancode = kKeyBackspace; else if (ustricmp(tok, "Tab") == 0) scancode = kKeyTab; else if (ustricmp(tok, "Enter") == 0) scancode = kKeyEnter; else if (ustricmp(tok, "Space") == 0) scancode = kKeySpace; else if ((ustricmp(tok, "Insert") == 0) || (ustricmp(tok, "Ins") == 0)) scancode = kKeyInsert; else if ((ustricmp(tok, "Delete") == 0) || (ustricmp(tok, "Del") == 0)) scancode = kKeyDel; else if (ustricmp(tok, "Home") == 0) scancode = kKeyHome; else if (ustricmp(tok, "End") == 0) scancode = kKeyEnd; else if ((ustricmp(tok, "Page Up") == 0) || (ustricmp(tok, "PgUp") == 0)) scancode = kKeyPageUp; else if ((ustricmp(tok, "Page Down") == 0) || (ustricmp(tok, "PgDn") == 0)) scancode = kKeyPageDown; else if (ustricmp(tok, "Left") == 0) scancode = kKeyLeft; else if (ustricmp(tok, "Right") == 0) scancode = kKeyRight; else if (ustricmp(tok, "Up") == 0) scancode = kKeyUp; else if (ustricmp(tok, "Down") == 0) scancode = kKeyDown; else if (ustricmp(tok, "0 Pad") == 0) scancode = kKey0Pad; else if (ustricmp(tok, "1 Pad") == 0) scancode = kKey1Pad; else if (ustricmp(tok, "2 Pad") == 0) scancode = kKey2Pad; else if (ustricmp(tok, "3 Pad") == 0) scancode = kKey3Pad; else if (ustricmp(tok, "4 Pad") == 0) scancode = kKey4Pad; else if (ustricmp(tok, "5 Pad") == 0) scancode = kKey5Pad; else if (ustricmp(tok, "6 Pad") == 0) scancode = kKey6Pad; else if (ustricmp(tok, "7 Pad") == 0) scancode = kKey7Pad; else if (ustricmp(tok, "8 Pad") == 0) scancode = kKey8Pad; else if (ustricmp(tok, "9 Pad") == 0) scancode = kKey9Pad; else if (ustricmp(tok, "Slash Pad") == 0) scancode = kKeySlashPad; else if (ustricmp(tok, "Asterisk") == 0) scancode = kKeyAsterisk; else if (ustricmp(tok, "Minus Pad") == 0) scancode = kKeyMinusPad; else if (ustricmp(tok, "Plus Pad") == 0) scancode = kKeyPlusPad; else if (ustricmp(tok, "Del Pad") == 0) scancode = kKeyDelPad; else if (ustricmp(tok, "Enter Pad") == 0) scancode = kKeyEnterPad; } } accel->addKey(modifiers, scancode, ascii); }
/* fs_flist_putter: * Callback routine for for_each_file() to fill the file selector listbox. */ static int fs_flist_putter(AL_CONST char *str, int attrib, void *check_attrib) { char *s, *ext, *name; int c, c2; s = get_filename(str); fix_filename_case(s); if(!(attrib & FA_DIREC)) { /* Check if file extension matches. */ if(fext_p) { ext = get_extension(s); for(c=0; c<fext_size; c++) { if(ustricmp(ext, fext_p[c]) == 0) goto Next; } return 0; } Next: /* Check if file attributes match. */ if(check_attrib) { for(c=0; c<ATTRB_MAX; c++) { if((attrb_state[c] == ATTRB_SET) && (!(attrib & attrb_flag[c]))) return 0; if((attrb_state[c] == ATTRB_UNSET) && (attrib & attrb_flag[c])) return 0; } } } if((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) { int size = ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0); name = (char *) zc_malloc(size); if(!name) return -1; ustrzcpy(name, size, s); if(attrib & FA_DIREC) put_backslash(name); /* Sort alphabetically with directories first. */ for(c=0; c<flist->size; c++) { if(ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) { if(attrib & FA_DIREC) if(ustrfilecmp(name, flist->name[c]) < 0) break; } else { if(attrib & FA_DIREC) break; if(ustrfilecmp(name, flist->name[c]) < 0) break; } } /* Shift in preparation for inserting the new entry. */ for(c2=flist->size; c2>c; c2--) flist->name[c2] = flist->name[c2-1]; /* Insert the new entry. */ flist->name[c] = name; flist->size++; } return 0; }
static textconfig text_configure(paragraph *source) { textconfig ret; paragraph *p; int n; /* * Non-negotiables. */ ret.bullet.next = NULL; ret.bullet.alt = NULL; ret.bullet.type = word_Normal; ret.atitle.just_numbers = FALSE; /* ignored */ ret.atitle.number_at_all = TRUE; /* ignored */ /* * Defaults. */ ret.indent = 7; ret.indent_code = 2; ret.listindentbefore = 1; ret.listindentafter = 3; ret.width = 68; ret.atitle.align = CENTRE; ret.atitle.underline = L"\x2550\0=\0\0"; ret.achapter.align = LEFT; ret.achapter.just_numbers = FALSE; ret.achapter.number_at_all = TRUE; ret.achapter.number_suffix = L": "; ret.achapter.underline = L"\x203E\0-\0\0"; ret.nasect = 1; ret.asect = snewn(ret.nasect, alignstruct); ret.asect[0].align = LEFTPLUS; ret.asect[0].just_numbers = TRUE; ret.asect[0].number_at_all = TRUE; ret.asect[0].number_suffix = L" "; ret.asect[0].underline = L"\0"; ret.include_version_id = TRUE; ret.indent_preambles = FALSE; ret.bullet.text = L"\x2022\0-\0\0"; ret.rule = L"\x2500\0-\0\0"; ret.filename = dupstr("output.txt"); ret.startemph = L"_\0_\0\0"; ret.endemph = uadv(ret.startemph); ret.startstrong = L"*\0*\0\0"; ret.endstrong = uadv(ret.startstrong); ret.listsuffix = L"."; ret.charset = CS_ASCII; /* * Default quote characters are Unicode matched single quotes, * falling back to the TeXlike `'. */ ret.lquote = L"\x2018\0\x2019\0`\0'\0\0"; ret.rquote = uadv(ret.lquote); /* * Two-pass configuration so that we can pick up global config * (e.g. `quotes') before having it overridden by specific * config (`text-quotes'), irrespective of the order in which * they occur. */ for (p = source; p; p = p->next) { if (p->type == para_Config) { if (!ustricmp(p->keyword, L"quotes")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } } } } for (p = source; p; p = p->next) { if (p->type == para_Config) { if (!ustricmp(p->keyword, L"text-indent")) { ret.indent = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-charset")) { ret.charset = charset_from_ustr(&p->fpos, uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-filename")) { sfree(ret.filename); ret.filename = dupstr(adv(p->origkeyword)); } else if (!ustricmp(p->keyword, L"text-indent-code")) { ret.indent_code = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-width")) { ret.width = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-list-indent")) { ret.listindentbefore = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-listitem-indent")) { ret.listindentafter = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-chapter-align")) { ret.achapter.align = utoalign(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-chapter-underline")) { ret.achapter.underline = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-chapter-numeric")) { ret.achapter.just_numbers = utob(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-chapter-shownumber")) { ret.achapter.number_at_all = utob(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-chapter-suffix")) { ret.achapter.number_suffix = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-section-align")) { wchar_t *q = uadv(p->keyword); int n = 0; if (uisdigit(*q)) { n = utoi(q); q = uadv(q); } if (n >= ret.nasect) { int i; ret.asect = sresize(ret.asect, n+1, alignstruct); for (i = ret.nasect; i <= n; i++) ret.asect[i] = ret.asect[ret.nasect-1]; ret.nasect = n+1; } ret.asect[n].align = utoalign(q); } else if (!ustricmp(p->keyword, L"text-section-underline")) { wchar_t *q = uadv(p->keyword); int n = 0; if (uisdigit(*q)) { n = utoi(q); q = uadv(q); } if (n >= ret.nasect) { int i; ret.asect = sresize(ret.asect, n+1, alignstruct); for (i = ret.nasect; i <= n; i++) ret.asect[i] = ret.asect[ret.nasect-1]; ret.nasect = n+1; } ret.asect[n].underline = q; } else if (!ustricmp(p->keyword, L"text-section-numeric")) { wchar_t *q = uadv(p->keyword); int n = 0; if (uisdigit(*q)) { n = utoi(q); q = uadv(q); } if (n >= ret.nasect) { int i; ret.asect = sresize(ret.asect, n+1, alignstruct); for (i = ret.nasect; i <= n; i++) ret.asect[i] = ret.asect[ret.nasect-1]; ret.nasect = n+1; } ret.asect[n].just_numbers = utob(q); } else if (!ustricmp(p->keyword, L"text-section-shownumber")) { wchar_t *q = uadv(p->keyword); int n = 0; if (uisdigit(*q)) { n = utoi(q); q = uadv(q); } if (n >= ret.nasect) { int i; ret.asect = sresize(ret.asect, n+1, alignstruct); for (i = ret.nasect; i <= n; i++) ret.asect[i] = ret.asect[ret.nasect-1]; ret.nasect = n+1; } ret.asect[n].number_at_all = utob(q); } else if (!ustricmp(p->keyword, L"text-section-suffix")) { wchar_t *q = uadv(p->keyword); int n = 0; if (uisdigit(*q)) { n = utoi(q); q = uadv(q); } if (n >= ret.nasect) { int i; ret.asect = sresize(ret.asect, n+1, alignstruct); for (i = ret.nasect; i <= n; i++) { ret.asect[i] = ret.asect[ret.nasect-1]; } ret.nasect = n+1; } ret.asect[n].number_suffix = q; } else if (!ustricmp(p->keyword, L"text-title-align")) { ret.atitle.align = utoalign(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-title-underline")) { ret.atitle.underline = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-versionid")) { ret.include_version_id = utob(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-indent-preamble")) { ret.indent_preambles = utob(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-bullet")) { ret.bullet.text = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-rule")) { ret.rule = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-list-suffix")) { ret.listsuffix = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-emphasis")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.startemph = uadv(p->keyword); ret.endemph = uadv(ret.startemph); } } else if (!ustricmp(p->keyword, L"text-strong")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.startstrong = uadv(p->keyword); ret.endstrong = uadv(ret.startstrong); } } else if (!ustricmp(p->keyword, L"text-quotes")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } } } } /* * Now process fallbacks on quote characters, underlines, the * rule character, the emphasis characters, and bullets. */ while (*uadv(ret.rquote) && *uadv(uadv(ret.rquote)) && (!cvt_ok(ret.charset, ret.lquote) || !cvt_ok(ret.charset, ret.rquote))) { ret.lquote = uadv(ret.rquote); ret.rquote = uadv(ret.lquote); } while (*uadv(ret.endemph) && *uadv(uadv(ret.endemph)) && (!cvt_ok(ret.charset, ret.startemph) || !cvt_ok(ret.charset, ret.endemph))) { ret.startemph = uadv(ret.endemph); ret.endemph = uadv(ret.startemph); } while (*uadv(ret.endstrong) && *uadv(uadv(ret.endstrong)) && (!cvt_ok(ret.charset, ret.startstrong) || !cvt_ok(ret.charset, ret.endstrong))) { ret.startstrong = uadv(ret.endstrong); ret.endstrong = uadv(ret.startstrong); } while (*ret.atitle.underline && *uadv(ret.atitle.underline) && !cvt_ok(ret.charset, ret.atitle.underline)) ret.atitle.underline = uadv(ret.atitle.underline); while (*ret.achapter.underline && *uadv(ret.achapter.underline) && !cvt_ok(ret.charset, ret.achapter.underline)) ret.achapter.underline = uadv(ret.achapter.underline); for (n = 0; n < ret.nasect; n++) { while (*ret.asect[n].underline && *uadv(ret.asect[n].underline) && !cvt_ok(ret.charset, ret.asect[n].underline)) ret.asect[n].underline = uadv(ret.asect[n].underline); } while (*ret.bullet.text && *uadv(ret.bullet.text) && !cvt_ok(ret.charset, ret.bullet.text)) ret.bullet.text = uadv(ret.bullet.text); while (*ret.rule && *uadv(ret.rule) && !cvt_ok(ret.charset, ret.rule)) ret.rule = uadv(ret.rule); return ret; }
/* fs_flist_putter: * Callback routine for for_each_file() to fill the file selector listbox. */ static void fs_flist_putter(AL_CONST char *str, int attrib, int param) { char ext_tokens[32]; char *s, *ext, *tok, *name; char tmp[512], tmp2[32]; int c, c2, i, k, sign; /* attribute flags (rhsda order) * 0 = not required, 1 = must be set, -1 = must be unset */ int attr_flag[5+5] = { 0, -1, -1, 0, 0, FA_RDONLY, FA_HIDDEN, FA_SYSTEM, FA_DIREC, FA_ARCH }; c = usetc(ext_tokens, ' '); c += usetc(ext_tokens+c, ','); c += usetc(ext_tokens+c, ';'); usetc(ext_tokens+c, 0); s = get_filename(str); fix_filename_case(s); if (fext) { ustrcpy(tmp, fext); ustrtok(tmp, ext_tokens); c = (ustrtok(NULL, ext_tokens) ? 1 : 0); if (!c) { if (!ustrchr(fext, '/')) c = 1; } if (c && (!(attrib & FA_DIREC))) { ustrcpy(tmp, fext); ext = get_extension(s); tok = ustrtok(tmp, ext_tokens); while (tok) { if (ustricmp(ext, tok) == 0) break; tok = ustrtok(NULL, ext_tokens); } if (!tok) return; } c = usetc(ext_tokens, ' '); c += usetc(ext_tokens+c, ','); c += usetc(ext_tokens+c, ';'); c += usetc(ext_tokens+c, '/'); usetc(ext_tokens+c, 0); ustrcpy(tmp, fext); tok = ustrchr(tmp, '/'); if (tok) tok = ustrtok(tok, ext_tokens); if (tok) { sign = 1; c = usetc(tmp2, 'r'); c += usetc(tmp2+c, 'h'); c += usetc(tmp2+c, 's'); c += usetc(tmp2+c, 'd'); c += usetc(tmp2+c, 'a'); c += usetc(tmp2+c, '+'); c += usetc(tmp2+c, '-'); usetc(tmp2+c, 0); /* scan the string */ i = 0; while ((c = utolower(ugetat(tok, i)))) { k = 0; while ((c2 = ugetat(tmp2, k))!=0) { if (c == c2) { if (k<5) { attr_flag[k] = sign; break; } else sign = (k==5) ? 1 : -1; } k++; } i++; } } } /* check if file attributes match */ if (!(attr_flag[3+5] & attrib)) { /* if not a directory, we check all attributes except FA_DIREC */ for (c=0; c<5; c++) { if (c == 3) continue; if ((attr_flag[c] == 1) && (!(attrib & attr_flag[c+5]))) return; if ((attr_flag[c] == -1) && (attrib & attr_flag[c+5])) return; } } else { /* if a directory, we check only FA_DIREC */ if (attr_flag[3] == -1) return; } if ((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) { name = malloc(ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0)); if (!name) return; for (c=0; c<flist->size; c++) { if (ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) { if (attrib & FA_DIREC) if (ustrfilecmp(s, flist->name[c]) < 0) break; } else { if (attrib & FA_DIREC) break; if (ustrfilecmp(s, flist->name[c]) < 0) break; } } for (c2=flist->size; c2>c; c2--) flist->name[c2] = flist->name[c2-1]; flist->name[c] = name; ustrcpy(flist->name[c], s); if (attrib & FA_DIREC) put_backslash(flist->name[c]); flist->size++; } }
static int compare_to_find_tag(void *av, void *bv) { wchar_t *a = (wchar_t *)av; indextag *b = (indextag *)bv; return ustricmp(a, b->name); }
static int compare_tags(void *av, void *bv) { indextag *a = (indextag *)av, *b = (indextag *)bv; return ustricmp(a->name, b->name); }
static infoconfig info_configure(paragraph *source) { infoconfig ret; paragraph *p; /* * Defaults. */ ret.filename = dupstr("output.info"); ret.maxfilesize = 64 << 10; ret.charset = CS_ASCII; ret.width = 70; ret.listindentbefore = 1; ret.listindentafter = 3; ret.indent_code = 2; ret.index_width = 40; ret.listsuffix = L"."; ret.bullet = L"\x2022\0-\0\0"; ret.rule = L"\x2500\0-\0\0"; ret.startemph = L"_\0_\0\0"; ret.endemph = uadv(ret.startemph); ret.lquote = L"\x2018\0\x2019\0`\0'\0\0"; ret.rquote = uadv(ret.lquote); ret.sectsuffix = L": "; ret.underline = L"\x203E\0-\0\0"; ret.index_text = L"Index"; /* * Two-pass configuration so that we can pick up global config * (e.g. `quotes') before having it overridden by specific * config (`info-quotes'), irrespective of the order in which * they occur. */ for (p = source; p; p = p->next) { if (p->type == para_Config) { if (!ustricmp(p->keyword, L"quotes")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } } else if (!ustricmp(p->keyword, L"index")) { ret.index_text = uadv(p->keyword); } } } for (p = source; p; p = p->next) { if (p->type == para_Config) { if (!ustricmp(p->keyword, L"info-filename")) { sfree(ret.filename); ret.filename = dupstr(adv(p->origkeyword)); } else if (!ustricmp(p->keyword, L"info-charset")) { ret.charset = charset_from_ustr(&p->fpos, uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"info-max-file-size")) { ret.maxfilesize = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"info-width")) { ret.width = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"info-indent-code")) { ret.indent_code = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"info-index-width")) { ret.index_width = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"info-list-indent")) { ret.listindentbefore = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"info-listitem-indent")) { ret.listindentafter = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"info-section-suffix")) { ret.sectsuffix = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"info-underline")) { ret.underline = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"info-bullet")) { ret.bullet = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"info-rule")) { ret.rule = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"info-list-suffix")) { ret.listsuffix = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"info-emphasis")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.startemph = uadv(p->keyword); ret.endemph = uadv(ret.startemph); } } else if (!ustricmp(p->keyword, L"info-quotes")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } } } } /* * Now process fallbacks on quote characters, underlines, the * rule character, the emphasis characters, and bullets. */ while (*uadv(ret.rquote) && *uadv(uadv(ret.rquote)) && (!cvt_ok(ret.charset, ret.lquote) || !cvt_ok(ret.charset, ret.rquote))) { ret.lquote = uadv(ret.rquote); ret.rquote = uadv(ret.lquote); } while (*uadv(ret.endemph) && *uadv(uadv(ret.endemph)) && (!cvt_ok(ret.charset, ret.startemph) || !cvt_ok(ret.charset, ret.endemph))) { ret.startemph = uadv(ret.endemph); ret.endemph = uadv(ret.startemph); } while (*ret.underline && *uadv(ret.underline) && !cvt_ok(ret.charset, ret.underline)) ret.underline = uadv(ret.underline); while (*ret.bullet && *uadv(ret.bullet) && !cvt_ok(ret.charset, ret.bullet)) ret.bullet = uadv(ret.bullet); while (*ret.rule && *uadv(ret.rule) && !cvt_ok(ret.charset, ret.rule)) ret.rule = uadv(ret.rule); return ret; }
void info_backend(paragraph *sourceform, keywordlist *keywords, indexdata *idx, void *unused) { paragraph *p; infoconfig conf; word *prefix, *body, *wp; word spaceword; wchar_t *prefixextra; int nesting, nestindent; int indentb, indenta; int filepos; int has_index; info_data intro_text = EMPTY_INFO_DATA; node *topnode, *currnode; word bullet; FILE *fp; IGNORE(unused); conf = info_configure(sourceform); /* * Go through and create a node for each section. */ topnode = info_node_new("Top", conf.charset); currnode = topnode; for (p = sourceform; p; p = p->next) switch (p->type) { /* * Chapter titles. */ case para_Chapter: case para_Appendix: case para_UnnumberedChapter: case para_Heading: case para_Subsect: { node *newnode, *upnode; char *nodename; nodename = info_node_name_for_para(p, &conf); newnode = info_node_new(nodename, conf.charset); sfree(nodename); p->private_data = newnode; if (p->parent) upnode = (node *)p->parent->private_data; else upnode = topnode; assert(upnode); newnode->up = upnode; currnode->next = newnode; newnode->prev = currnode; currnode->listnext = newnode; currnode = newnode; } break; default: p->private_data = NULL; break; } /* * Set up the display form of each index entry. */ { int i; indexentry *entry; for (i = 0; (entry = index234(idx->entries, i)) != NULL; i++) { info_idx *ii = snew(info_idx); info_data id = EMPTY_INFO_DATA; id.charset = conf.charset; ii->nnodes = ii->nodesize = 0; ii->nodes = NULL; ii->length = info_rdaddwc(&id, entry->text, NULL, FALSE, &conf); ii->text = id.output.text; entry->backend_data = ii; } } /* * An Info file begins with a piece of introductory text which * is apparently never shown anywhere. This seems to me to be a * good place to put the copyright notice and the version IDs. * Also, Info directory entries are expected to go here. */ intro_text.charset = conf.charset; info_rdaddsc(&intro_text, "This Info file generated by Halibut, "); info_rdaddsc(&intro_text, version); info_rdaddsc(&intro_text, "\n\n"); for (p = sourceform; p; p = p->next) if (p->type == para_Config && !ustricmp(p->keyword, L"info-dir-entry")) { wchar_t *section, *shortname, *longname, *kw; char *s; section = uadv(p->keyword); shortname = *section ? uadv(section) : L""; longname = *shortname ? uadv(shortname) : L""; kw = *longname ? uadv(longname) : L""; if (!*longname) { error(err_cfginsufarg, &p->fpos, p->origkeyword, 3); continue; } info_rdaddsc(&intro_text, "INFO-DIR-SECTION "); info_rdadds(&intro_text, section); info_rdaddsc(&intro_text, "\nSTART-INFO-DIR-ENTRY\n* "); info_rdadds(&intro_text, shortname); info_rdaddsc(&intro_text, ": ("); s = dupstr(conf.filename); if (strlen(s) > 5 && !strcmp(s+strlen(s)-5, ".info")) s[strlen(s)-5] = '\0'; info_rdaddsc(&intro_text, s); sfree(s); info_rdaddsc(&intro_text, ")"); if (*kw) { keyword *kwl = kw_lookup(keywords, kw); if (kwl && kwl->para->private_data) { node *n = (node *)kwl->para->private_data; info_rdaddsc(&intro_text, n->name); } } info_rdaddsc(&intro_text, ". "); info_rdadds(&intro_text, longname); info_rdaddsc(&intro_text, "\nEND-INFO-DIR-ENTRY\n\n"); } for (p = sourceform; p; p = p->next) if (p->type == para_Copyright) info_para(&intro_text, NULL, NULL, p->words, keywords, 0, 0, conf.width, &conf); for (p = sourceform; p; p = p->next) if (p->type == para_VersionID) info_versionid(&intro_text, p->words, &conf); if (intro_text.output.text[intro_text.output.pos-1] != '\n') info_rdaddc(&intro_text, '\n'); /* Do the title */ for (p = sourceform; p; p = p->next) if (p->type == para_Title) info_heading(&topnode->text, NULL, p->words, conf.width, &conf); nestindent = conf.listindentbefore + conf.listindentafter; nesting = 0; currnode = topnode; /* Do the main document */ for (p = sourceform; p; p = p->next) switch (p->type) { case para_QuotePush: nesting += 2; break; case para_QuotePop: nesting -= 2; assert(nesting >= 0); break; case para_LcontPush: nesting += nestindent; break; case para_LcontPop: nesting -= nestindent; assert(nesting >= 0); break; /* * Things we ignore because we've already processed them or * aren't going to touch them in this pass. */ case para_IM: case para_BR: case para_Biblio: /* only touch BiblioCited */ case para_VersionID: case para_NoCite: case para_Title: break; /* * Chapter titles. */ case para_Chapter: case para_Appendix: case para_UnnumberedChapter: case para_Heading: case para_Subsect: currnode = p->private_data; assert(currnode); assert(currnode->up); if (!currnode->up->started_menu) { info_rdaddsc(&currnode->up->text, "* Menu:\n\n"); currnode->up->started_menu = TRUE; } info_menu_item(&currnode->up->text, currnode, p, &conf); has_index |= info_check_index(p->words, currnode, idx); info_heading(&currnode->text, p->kwtext, p->words, conf.width, &conf); nesting = 0; break; case para_Rule: info_rule(&currnode->text, nesting, conf.width - nesting, &conf); break; case para_Normal: case para_Copyright: case para_DescribedThing: case para_Description: case para_BiblioCited: case para_Bullet: case para_NumberedList: has_index |= info_check_index(p->words, currnode, idx); if (p->type == para_Bullet) { bullet.next = NULL; bullet.alt = NULL; bullet.type = word_Normal; bullet.text = conf.bullet; prefix = • prefixextra = NULL; indentb = conf.listindentbefore; indenta = conf.listindentafter; } else if (p->type == para_NumberedList) { prefix = p->kwtext; prefixextra = conf.listsuffix; indentb = conf.listindentbefore; indenta = conf.listindentafter; } else if (p->type == para_Description) { prefix = NULL; prefixextra = NULL; indentb = conf.listindentbefore; indenta = conf.listindentafter; } else { prefix = NULL; prefixextra = NULL; indentb = indenta = 0; } if (p->type == para_BiblioCited) { body = dup_word_list(p->kwtext); for (wp = body; wp->next; wp = wp->next); wp->next = &spaceword; spaceword.next = p->words; spaceword.alt = NULL; spaceword.type = word_WhiteSpace; spaceword.text = NULL; } else { wp = NULL; body = p->words; } info_para(&currnode->text, prefix, prefixextra, body, keywords, nesting + indentb, indenta, conf.width - nesting - indentb - indenta, &conf); if (wp) { wp->next = NULL; free_word_list(body); } break; case para_Code: info_codepara(&currnode->text, p->words, nesting + conf.indent_code, conf.width - nesting - 2 * conf.indent_code); break; } /* * Create an index node if required. */ if (has_index) { node *newnode; int i, j, k; indexentry *entry; char *nodename; nodename = info_node_name_for_text(conf.index_text, &conf); newnode = info_node_new(nodename, conf.charset); sfree(nodename); newnode->up = topnode; currnode->next = newnode; newnode->prev = currnode; currnode->listnext = newnode; k = info_rdadds(&newnode->text, conf.index_text); info_rdaddsc(&newnode->text, "\n"); while (k > 0) { info_rdadds(&newnode->text, conf.underline); k -= ustrwid(conf.underline, conf.charset); } info_rdaddsc(&newnode->text, "\n\n"); info_menu_item(&topnode->text, newnode, NULL, &conf); for (i = 0; (entry = index234(idx->entries, i)) != NULL; i++) { info_idx *ii = (info_idx *)entry->backend_data; for (j = 0; j < ii->nnodes; j++) { /* * When we have multiple references for a single * index term, we only display the actual term on * the first line, to make it clear that the terms * really are the same. */ if (j == 0) info_rdaddsc(&newnode->text, ii->text); for (k = (j ? 0 : ii->length); k < conf.index_width-2; k++) info_rdaddc(&newnode->text, ' '); info_rdaddsc(&newnode->text, " *Note "); info_rdaddsc(&newnode->text, ii->nodes[j]->name); info_rdaddsc(&newnode->text, "::\n"); } } } /* * Finalise the text of each node, by adding the ^_ delimiter * and the node line at the top. */ for (currnode = topnode; currnode; currnode = currnode->listnext) { char *origtext = currnode->text.output.text; currnode->text = empty_info_data; currnode->text.charset = conf.charset; info_rdaddsc(&currnode->text, "\037\nFile: "); info_rdaddsc(&currnode->text, conf.filename); info_rdaddsc(&currnode->text, ", Node: "); info_rdaddsc(&currnode->text, currnode->name); if (currnode->prev) { info_rdaddsc(&currnode->text, ", Prev: "); info_rdaddsc(&currnode->text, currnode->prev->name); } info_rdaddsc(&currnode->text, ", Up: "); info_rdaddsc(&currnode->text, (currnode->up ? currnode->up->name : "(dir)")); if (currnode->next) { info_rdaddsc(&currnode->text, ", Next: "); info_rdaddsc(&currnode->text, currnode->next->name); } info_rdaddsc(&currnode->text, "\n\n"); info_rdaddsc(&currnode->text, origtext); /* * Just make _absolutely_ sure we end with a newline. */ if (currnode->text.output.text[currnode->text.output.pos-1] != '\n') info_rdaddc(&currnode->text, '\n'); sfree(origtext); } /* * Compute the offsets for the tag table. */ filepos = intro_text.output.pos; for (currnode = topnode; currnode; currnode = currnode->listnext) { currnode->pos = filepos; filepos += currnode->text.output.pos; } /* * Split into sub-files. */ if (conf.maxfilesize > 0) { int currfilesize = intro_text.output.pos, currfilenum = 1; for (currnode = topnode; currnode; currnode = currnode->listnext) { if (currfilesize > intro_text.output.pos && currfilesize + currnode->text.output.pos > conf.maxfilesize) { currfilenum++; currfilesize = intro_text.output.pos; } currnode->filenum = currfilenum; currfilesize += currnode->text.output.pos; } } /* * Write the primary output file. */ fp = fopen(conf.filename, "w"); if (!fp) { error(err_cantopenw, conf.filename); return; } fputs(intro_text.output.text, fp); if (conf.maxfilesize == 0) { for (currnode = topnode; currnode; currnode = currnode->listnext) fputs(currnode->text.output.text, fp); } else { int filenum = 0; fprintf(fp, "\037\nIndirect:\n"); for (currnode = topnode; currnode; currnode = currnode->listnext) if (filenum != currnode->filenum) { filenum = currnode->filenum; fprintf(fp, "%s-%d: %d\n", conf.filename, filenum, currnode->pos); } } fprintf(fp, "\037\nTag Table:\n"); if (conf.maxfilesize > 0) fprintf(fp, "(Indirect)\n"); for (currnode = topnode; currnode; currnode = currnode->listnext) fprintf(fp, "Node: %s\177%d\n", currnode->name, currnode->pos); fprintf(fp, "\037\nEnd Tag Table\n"); fclose(fp); /* * Write the subfiles. */ if (conf.maxfilesize > 0) { int filenum = 0; fp = NULL; for (currnode = topnode; currnode; currnode = currnode->listnext) { if (filenum != currnode->filenum) { char *fname; filenum = currnode->filenum; if (fp) fclose(fp); fname = snewn(strlen(conf.filename) + 40, char); sprintf(fname, "%s-%d", conf.filename, filenum); fp = fopen(fname, "w"); if (!fp) { error(err_cantopenw, fname); return; } sfree(fname); fputs(intro_text.output.text, fp); } fputs(currnode->text.output.text, fp); }
static manconfig man_configure(paragraph *source) { paragraph *p; manconfig ret; /* * Defaults. */ ret.th = NULL; ret.headnumbers = FALSE; ret.mindepth = 0; ret.filename = dupstr("output.1"); ret.charset = CS_ASCII; ret.bullet = L"\x2022\0o\0\0"; ret.rule = L"\x2500\0-\0\0"; ret.lquote = L"\x2018\0\x2019\0\"\0\"\0\0"; ret.rquote = uadv(ret.lquote); /* * Two-pass configuration so that we can pick up global config * (e.g. `quotes') before having it overridden by specific * config (`man-quotes'), irrespective of the order in which * they occur. */ for (p = source; p; p = p->next) { if (p->type == para_Config) { if (!ustricmp(p->keyword, L"quotes")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } } } } for (p = source; p; p = p->next) { if (p->type == para_Config) { if (!ustricmp(p->keyword, L"man-identity")) { wchar_t *wp, *ep; wp = uadv(p->keyword); ep = wp; while (*ep) ep = uadv(ep); sfree(ret.th); ret.th = snewn(ep - wp + 1, wchar_t); memcpy(ret.th, wp, (ep - wp + 1) * sizeof(wchar_t)); } else if (!ustricmp(p->keyword, L"man-charset")) { ret.charset = charset_from_ustr(&p->fpos, uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"man-headnumbers")) { ret.headnumbers = utob(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"man-mindepth")) { ret.mindepth = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"man-filename")) { sfree(ret.filename); ret.filename = dupstr(adv(p->origkeyword)); } else if (!ustricmp(p->keyword, L"man-bullet")) { ret.bullet = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"man-rule")) { ret.rule = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"man-quotes")) { if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } } }
int main(void) { int w,h,bpp; int windowed; int count; char **data; char *title; char *filename; int r,g,b; BITMAP *background; int display; RGB pal[256]; int x, y; /* you should always do this at the start of Allegro programs */ if (allegro_init() != 0) return 1; /* set up the keyboard handler */ install_keyboard(); /* save the current ini file, then set the program specific one */ push_config_state(); set_config_file("exconfig.ini"); /* the gfx mode is stored like this: * 640 480 16 * the get_config_argv() function returns a pointer to a char * array, and stores the size of the char array in an int */ data = get_config_argv("graphics", "mode", &count); if (count != 3) { /* We expect only 3 parameters */ allegro_message("Found %i parameters in graphics.mode instead of " "the 3 expected.\n", count); w = 320; h = 200; bpp = 8; } else { w = atoi(data[0]); h = atoi(data[1]); bpp = atoi(data[2]); } /* Should we use a windowed mode? * In the config file this is stored as either FALSE or TRUE. * So we need to read a string and see what it contains. * If the entry is not found, we use "FALSE" by default */ if (ustricmp(get_config_string("graphics", "windowed", "FALSE"), "FALSE") == 0) windowed = GFX_AUTODETECT_FULLSCREEN; else windowed = GFX_AUTODETECT_WINDOWED; /* the title string * The string returned is stored inside of the config system * and would be lost if we call pop_config_state(), so we create * a copy of it. */ title = ustrdup(get_config_string("content", "headline", "<no headline>")); /* the title color * once again this is stored as three ints in one line */ data = get_config_argv("content", "headercolor", &count); if (count != 3) { /* We expect only 3 parameters */ allegro_message("Found %i parameters in content.headercolor " "instead of the 3 expected.\n", count); r = g = b = 255; } else { r = atoi(data[0]); g = atoi(data[1]); b = atoi(data[2]); } /* The image file to read * The string returned is stored inside of the config system * and would be lost if we call pop_config_state(), so we create * a copy of it. */ filename = ustrdup(get_config_string("content", "image", "mysha.pcx")); /* and it's tiling mode */ display = get_config_int("content", "display", 0); if (display <0 || display > 2) { allegro_message("content.display must be within 0..2\n"); display = 0; } /* restore the old config file */ pop_config_state(); /* set the graphics mode */ set_color_depth(bpp); if (set_gfx_mode(windowed, w, h, 0, 0) != 0) { allegro_message("Unable to set mode %ix%i with %ibpp\n", w, h, bpp); free(filename); free(title); exit(-1); } /* Clear the screen */ clear_bitmap(screen); /* load the image */ background = load_bitmap(filename, pal); if (background != NULL) { set_palette(pal); switch (display) { case 0: /* stretch */ stretch_blit(background, screen, 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); break; case 1: /* center */ blit(background, screen, 0, 0, (SCREEN_W - background->w)/2, (SCREEN_H - background->h)/2, background->w, background->h); break; case 2: /* tile */ for (y = 0; y < SCREEN_H; y += background->h) for (x = 0; x < SCREEN_W; x += background->w) blit(background, screen, 0, 0, x, y, background->w, background->h); break; } } else { textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H/2, makecol(r,g,b), -1, "%s not found", filename); } textout_centre_ex(screen, font, title, SCREEN_W/2, 20, makecol(r,g,b), -1); readkey(); free(filename); free(title); return 0; }