File: geticon.c

package info (click to toggle)
gnuplot 3.5beta6.347-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 5,032 kB
  • ctags: 4,235
  • sloc: ansic: 42,086; makefile: 561; asm: 539; sh: 386; objc: 379; csh: 297; pascal: 194; perl: 138; lisp: 88
file content (98 lines) | stat: -rw-r--r-- 2,306 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef lint
static char *RCSid = "$Id: geticon.c,v 1.2 1993/09/27 17:24:27 alex Exp $";
#endif

/* geticon.c */
/* extract Borland ascii format icons from resource script */
/* and write as Microsoft binary format .ICO files */
/* Russell Lang 1992-12-20 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAXLINE 255
FILE *rcfile;
char inline[MAXLINE+1];
char *tok1, *tok2, *tok3;
char *p;
char iconname[MAXLINE+1];
FILE *iconfile;
int line;

int htoi(char ch)
{
    ch = toupper(ch);
    if (ch < '0')
        return(0);
    else if (ch <= '9')
        return((int)(ch - '0'));
    else if (ch < 'A')
        return(0);
    else if (ch <= 'F')
        return((int)(ch - 'A' + 10));
    return(0);
}

void
geticon(void)
{
char ch;
    fgets(inline,MAXLINE,rcfile);
    line++;
    if (strncmp(inline,"BEGIN",5)) {
    	fprintf(stderr,"Expecting BEGIN at line %d\n",line);
    	exit(3);
    }
    if ( (iconfile = fopen(iconname,"wb")) == (FILE *)NULL) {
        fprintf(stderr,"Can't open ICON file %s\n",iconname);
        exit(4);
    }
    fgets(inline,MAXLINE,rcfile);
    line++;
    while (strncmp(inline,"END",3) && !feof(rcfile)) {
        for (p = inline; *p && (*p==' ' || *p == '\t' || *p=='\''); p++);
        while (isxdigit(*p)) {
            ch = htoi(*p++)<<4;
            ch += htoi(*p++);
            fputc(ch, iconfile);
            p++;
        }
        fgets(inline,MAXLINE,rcfile);
        line++;
    }
    fclose(iconfile);
}

int
main(int argc, char *argv[])
{
    if ((argc < 2) || (argc > 3)) {
	fprintf(stderr,"Usage:  geticon  resource_file [icon_directory]\n");
	return(1);
    }
    if ( (rcfile = fopen(argv[1],"r")) == (FILE *)NULL) {
	fprintf(stderr,"Can't open RC file\n");
	return(2);
    }
    line = 0;
    while (fgets(inline,MAXLINE,rcfile)) {
        line++;
	tok1 = strtok(inline," \t\r\n");
	tok2 = strtok(NULL," \t\r\n");
	tok3 = strtok(NULL," \t\r\n");
	if (tok2 && !strcmp(tok2,"ICON") && (tok3 == (char *)NULL)) {
            iconname[0] = '\0';
	    if (argc == 3) {
                strcpy(iconname,argv[2]);
                strcat(iconname,"\\");
            }
            strcat(iconname,tok1);
            strcat(iconname,".ico");
	    fprintf(stdout,"%s\n",iconname);
	    geticon();
	}
    }
    return (0);
}