/rusxmms/librcd

To get this branch, use:
bzr branch http://suren.me/webbzr/rusxmms/librcd

« back to all changes in this revision

Viewing changes to statgen/upper.c

  • Committer: Suren A. Chilingaryan
  • Date: 2005-06-16 23:19:27 UTC
  • Revision ID: Arch-1:ds@dside.dyndns.org--darksoft-2004%librcd--main--0.1--base-0
initial import

(automatically generated log message)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <unistd.h>
 
3
#include <ctype.h>
 
4
#include <locale.h>
 
5
#include <sys/types.h>
 
6
#include <sys/stat.h>
 
7
 
 
8
 
 
9
main(int argc, char *argv[]) {
 
10
    FILE *f;
 
11
    struct stat st;
 
12
    unsigned char *text;
 
13
    char locale[32];
 
14
    int i;
 
15
 
 
16
 
 
17
    if (argc!=3) {
 
18
        printf("Usage: %s <file name> <encoding>\n",argv[0]);
 
19
        exit(0);
 
20
    }
 
21
 
 
22
    if (strlen(argv[2])>12) {
 
23
        printf("Invalid encoding(%s) specified!\n",argv[2]);
 
24
        exit(1);
 
25
    }
 
26
    
 
27
    if ((!strcasecmp(argv[2],"koi"))||(!strcasecmp(argv[2],"koi8"))||(!strcasecmp(argv[2],"koi-8"))||(!strcasecmp(argv[2],"koi8-r")))
 
28
        sprintf(locale,"ru_RU.%s","KOI8-R");
 
29
    else if ((!strcasecmp(argv[2],"win"))||(!strcasecmp(argv[2],"cp1251"))||(!strcasecmp(argv[2],"cp-1251"))||(!strcasecmp(argv[2],"win1251"))||(!strcasecmp(argv[2],"win-1251")))
 
30
        sprintf(locale,"ru_RU.%s","CP1251");
 
31
    else
 
32
        sprintf(locale,"ru_RU.%s",argv[2]);
 
33
    if (!setlocale(LC_CTYPE,locale)) {
 
34
        printf("Can't set locale %s!\n",argv[2]);
 
35
        exit(1);
 
36
    }
 
37
    
 
38
    if (stat(argv[1],&st)) {
 
39
        printf("Specified file can't be stated!\n");
 
40
        exit(1);
 
41
    }
 
42
    
 
43
    if (!S_ISREG(st.st_mode)) {
 
44
        printf("Specified file isn't regular file!\n");
 
45
        exit(1);
 
46
    }
 
47
    
 
48
    text=(unsigned char*)malloc(st.st_size);
 
49
    if (!text) {
 
50
        printf("Can't allocate %lu bytes of memory!\n",st.st_size);
 
51
        exit(1);
 
52
    }
 
53
    
 
54
    f=fopen(argv[1],"r");
 
55
    if (!f) {
 
56
        printf("Failed to open specified file. Check permissions!\n");
 
57
        free(text);
 
58
        exit(1);
 
59
    }
 
60
    if (fread(text,1,st.st_size,f)!=st.st_size) {
 
61
        printf("Problem reading specified file!\n");
 
62
        free(text);
 
63
        fclose(f);
 
64
        exit(1);
 
65
    }
 
66
    fclose(f);
 
67
    
 
68
    for (i=0;i<st.st_size;i++) 
 
69
        text[i]=toupper(text[i]);
 
70
    
 
71
    f=fopen("UPPED.OUT","w");
 
72
    fwrite(text,1,st.st_size,f);
 
73
    fclose(f);
 
74
    free(text);
 
75
}