Annotation of OpenXM_contrib/gnuplot/win/geticon.c, Revision 1.1
1.1 ! maekawa 1: #ifndef lint
! 2: static char *RCSid = "$Id: geticon.c,v 1.2 1993/09/27 17:24:27 alex Exp $";
! 3: #endif
! 4:
! 5: /* geticon.c */
! 6: /* extract Borland ascii format icons from resource script */
! 7: /* and write as Microsoft binary format .ICO files */
! 8: /* Russell Lang 1992-12-20 */
! 9:
! 10: #include <stdio.h>
! 11: #include <stdlib.h>
! 12: #include <string.h>
! 13: #include <ctype.h>
! 14:
! 15: /* HBB 980809: naming a variable 'inline' is a bad idea, these days. Too
! 16: * many compilers use it as a keyword... Changed to 'inputline' */
! 17: #define MAXLINE 255
! 18: FILE *rcfile;
! 19: char inputline[MAXLINE+1];
! 20: char *tok1, *tok2, *tok3;
! 21: char *p;
! 22: char iconname[MAXLINE+1];
! 23: FILE *iconfile;
! 24: int line;
! 25:
! 26: int htoi(char ch)
! 27: {
! 28: ch = toupper(ch);
! 29: if (ch < '0')
! 30: return(0);
! 31: else if (ch <= '9')
! 32: return((int)(ch - '0'));
! 33: else if (ch < 'A')
! 34: return(0);
! 35: else if (ch <= 'F')
! 36: return((int)(ch - 'A' + 10));
! 37: return(0);
! 38: }
! 39:
! 40: void
! 41: geticon(void)
! 42: {
! 43: char ch;
! 44: fgets(inputline,MAXLINE,rcfile);
! 45: line++;
! 46: if (strncmp(inputline,"BEGIN",5)) {
! 47: fprintf(stderr,"Expecting BEGIN at line %d\n",line);
! 48: exit(3);
! 49: }
! 50: if ( (iconfile = fopen(iconname,"wb")) == (FILE *)NULL) {
! 51: fprintf(stderr,"Can't open ICON file %s\n",iconname);
! 52: exit(4);
! 53: }
! 54: fgets(inputline,MAXLINE,rcfile);
! 55: line++;
! 56: while (strncmp(inputline,"END",3) && !feof(rcfile)) {
! 57: for (p = inputline; *p && (*p==' ' || *p == '\t' || *p=='\''); p++);
! 58: while (isxdigit(*p)) {
! 59: ch = htoi(*p++)<<4;
! 60: ch += htoi(*p++);
! 61: fputc(ch, iconfile);
! 62: p++;
! 63: }
! 64: fgets(inputline,MAXLINE,rcfile);
! 65: line++;
! 66: }
! 67: fclose(iconfile);
! 68: }
! 69:
! 70: int
! 71: main(int argc, char *argv[])
! 72: {
! 73: if ((argc < 2) || (argc > 3)) {
! 74: fprintf(stderr,"Usage: geticon resource_file [icon_directory]\n");
! 75: return(1);
! 76: }
! 77: if ( (rcfile = fopen(argv[1],"r")) == (FILE *)NULL) {
! 78: fprintf(stderr,"Can't open RC file\n");
! 79: return(2);
! 80: }
! 81: line = 0;
! 82: while (fgets(inputline,MAXLINE,rcfile)) {
! 83: line++;
! 84: tok1 = strtok(inputline," \t\r\n");
! 85: tok2 = strtok(NULL," \t\r\n");
! 86: tok3 = strtok(NULL," \t\r\n");
! 87: if (tok2 && !strcmp(tok2,"ICON") && (tok3 == (char *)NULL)) {
! 88: iconname[0] = '\0';
! 89: if (argc == 3) {
! 90: strcpy(iconname,argv[2]);
! 91: strcat(iconname,"\\");
! 92: }
! 93: strcat(iconname,tok1);
! 94: strcat(iconname,".ico");
! 95: fprintf(stdout,"%s\n",iconname);
! 96: geticon();
! 97: }
! 98: }
! 99: return (0);
! 100: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>