X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fmisc.c;h=7ff3a94781e0ed66ab23597f99b5a19935c9484c;hb=bb33b871657d1af6beda881e33b536512815aa9b;hp=3b3f6a04212dcbde4775d8a54874d9bdf8a4c844;hpb=e6856beb007b3f09036a04290c6b162953ddfece;p=rocksndiamonds.git diff --git a/src/misc.c b/src/misc.c index 3b3f6a04..7ff3a947 100644 --- a/src/misc.c +++ b/src/misc.c @@ -235,12 +235,49 @@ char *getLoginName() { struct passwd *pwd; - if (!(pwd = getpwuid(getuid()))) - return "ANONYMOUS"; + if ((pwd = getpwuid(getuid())) == NULL) + return ANONYMOUS_NAME; else return pwd->pw_name; } +char *getRealName() +{ +#ifndef MSDOS + struct passwd *pwd; + + if ((pwd = getpwuid(getuid())) == NULL || strlen(pwd->pw_gecos) == 0) + return ANONYMOUS_NAME; + else + { + static char real_name[1024]; + char *from_ptr = pwd->pw_gecos, *to_ptr = real_name; + + if (strchr(pwd->pw_gecos, 'ß') == NULL) + return pwd->pw_gecos; + + /* the user's real name contains a 'ß' character (german sharp s), + which has no equivalent in upper case letters (which our fonts use) */ + while (*from_ptr != '\0' && (long)(to_ptr - real_name) < 1024 - 2) + { + if (*from_ptr != 'ß') + *to_ptr++ = *from_ptr++; + else + { + from_ptr++; + *to_ptr++ = 's'; + *to_ptr++ = 's'; + } + } + *to_ptr = '\0'; + + return real_name; + } +#else + return ANONYMOUS_NAME; +#endif +} + char *getHomeDir() { #ifndef MSDOS @@ -315,6 +352,25 @@ void MarkTileDirty(int x, int y) redraw_mask |= REDRAW_TILES; } +void SetBorderElement() +{ + int x, y; + + BorderElement = EL_LEERRAUM; + + for(y=0; y> 8) & 0xff, file); + fputc((value >> 0) & 0xff, file); + } + else /* BYTE_ORDER_LITTLE_ENDIAN */ + { + fputc((value >> 0) & 0xff, file); + fputc((value >> 8) & 0xff, file); + } +} + +int getFile32BitInteger(FILE *file, int byte_order) +{ + if (byte_order == BYTE_ORDER_BIG_ENDIAN) + return ((fgetc(file) << 24) | + (fgetc(file) << 16) | + (fgetc(file) << 8) | + (fgetc(file) << 0)); + else /* BYTE_ORDER_LITTLE_ENDIAN */ + return ((fgetc(file) << 0) | + (fgetc(file) << 8) | + (fgetc(file) << 16) | + (fgetc(file) << 24)); +} + +void putFile32BitInteger(FILE *file, int value, int byte_order) +{ + if (byte_order == BYTE_ORDER_BIG_ENDIAN) + { + fputc((value >> 24) & 0xff, file); + fputc((value >> 16) & 0xff, file); + fputc((value >> 8) & 0xff, file); + fputc((value >> 0) & 0xff, file); + } + else /* BYTE_ORDER_LITTLE_ENDIAN */ + { + fputc((value >> 0) & 0xff, file); + fputc((value >> 8) & 0xff, file); + fputc((value >> 16) & 0xff, file); + fputc((value >> 24) & 0xff, file); + } +} + +void getFileChunk(FILE *file, char *chunk_buffer, int *chunk_length, + int byte_order) +{ + const int chunk_identifier_length = 4; + + /* read chunk identifier */ + fgets(chunk_buffer, chunk_identifier_length + 1, file); + + /* read chunk length */ + *chunk_length = getFile32BitInteger(file, byte_order); +} + +void putFileChunk(FILE *file, char *chunk_name, int chunk_length, + int byte_order) +{ + /* write chunk identifier */ + fputs(chunk_name, file); + + /* write chunk length */ + putFile32BitInteger(file, chunk_length, byte_order); +} + #define TRANSLATE_KEYSYM_TO_KEYNAME 0 #define TRANSLATE_KEYSYM_TO_X11KEYNAME 1 #define TRANSLATE_X11KEYNAME_TO_KEYSYM 2 @@ -602,9 +739,9 @@ void translate_keyname(KeySym *keysym, char **x11name, char **name, int mode) { XK_slash, "XK_slash", "/" }, { XK_colon, "XK_colon", ":" }, { XK_semicolon, "XK_semicolon", ";" }, - { XK_less, "XK_less", "less" }, - { XK_equal, "XK_equal", "equal" }, - { XK_greater, "XK_greater", "greater" }, + { XK_less, "XK_less", "<" }, + { XK_equal, "XK_equal", "=" }, + { XK_greater, "XK_greater", ">" }, { XK_question, "XK_question", "?" }, { XK_at, "XK_at", "@" }, @@ -828,12 +965,8 @@ char getCharFromKeySym(KeySym keysym) letter = keyname[0]; else if (strcmp(keyname, "space") == 0) letter = ' '; - else if (strcmp(keyname, "less") == 0) - letter = '<'; - else if (strcmp(keyname, "equal") == 0) - letter = '='; - else if (strcmp(keyname, "greater") == 0) - letter = '>'; + else if (strcmp(keyname, "circumflex") == 0) + letter = '^'; return letter; }