Michiel Van Der Kolk | fff0d92 | 2005-04-28 16:41:08 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 by Michiel van der Kolk |
| 11 | * |
| 12 | * All files in this archive are subject to the GNU General Public License. |
| 13 | * See the file COPYING in the source tree root for full license agreement. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | #include <stdlib.h> |
| 20 | #include <stdio.h> |
| 21 | #include "token.h" |
| 22 | |
Michiel Van Der Kolk | 238bea7 | 2005-04-28 18:49:23 +0000 | [diff] [blame] | 23 | |
| 24 | #ifdef LITTLE_ENDIAN |
| 25 | #define BE32(_x_) (((_x_ & 0xff000000) >> 24) | \ |
| 26 | ((_x_ & 0x00ff0000) >> 8) | \ |
| 27 | ((_x_ & 0x0000ff00) << 8) | \ |
| 28 | ((_x_ & 0x000000ff) << 24)) |
| 29 | #else |
| 30 | #define BE32(_x_) _x_ |
| 31 | #endif |
| 32 | |
| 33 | |
Michiel Van Der Kolk | fff0d92 | 2005-04-28 16:41:08 +0000 | [diff] [blame] | 34 | struct token token; |
| 35 | char buf[500]; |
| 36 | long num; |
| 37 | FILE *fp; |
| 38 | main() { |
| 39 | int done=0; |
| 40 | printf("Output filename? "); |
| 41 | fflush(stdout); |
Michiel Van Der Kolk | a43f90f | 2005-04-28 17:03:45 +0000 | [diff] [blame] | 42 | fgets(buf,254,stdin); |
Michiel Van Der Kolk | d98b6ae | 2005-04-28 17:07:44 +0000 | [diff] [blame] | 43 | buf[strlen(buf)-1]=0; |
Michiel Van Der Kolk | fff0d92 | 2005-04-28 16:41:08 +0000 | [diff] [blame] | 44 | fp=fopen(buf,"w"); |
| 45 | if(fp<0) { |
| 46 | printf("Error opening outputfile.\n"); |
| 47 | return -1; |
| 48 | } |
| 49 | do { |
| 50 | printf("EOF=0 NOT=1 AND=2 OR=3 GT=4 GTE=5 LT=6 LTE=7 EQ=8 NE=9\n"); |
| 51 | printf("(strings:) CONTAINS=10 EQUALS=11\n"); |
| 52 | printf("'('=12 ')'=13\n"); |
| 53 | printf("(arguments:) NUMBER=14 NUMBERFIELD=15 STRING=16 STRINGFIELD=17\n"); |
| 54 | printf("Token kind? "); |
| 55 | fflush(stdout); |
Michiel Van Der Kolk | a43f90f | 2005-04-28 17:03:45 +0000 | [diff] [blame] | 56 | fgets(buf,254,stdin); |
| 57 | token.kind=strtol(buf,0,10); |
Michiel Van Der Kolk | fff0d92 | 2005-04-28 16:41:08 +0000 | [diff] [blame] | 58 | memset(&token.spelling,0,256); |
| 59 | if(token.kind==TOKEN_STRING) { |
| 60 | printf("Token spelling? "); |
| 61 | fflush(stdout); |
Michiel Van Der Kolk | a43f90f | 2005-04-28 17:03:45 +0000 | [diff] [blame] | 62 | fgets(token.spelling,254,stdin); |
Michiel Van Der Kolk | a40a315 | 2005-04-28 17:41:39 +0000 | [diff] [blame] | 63 | token.spelling[strlen(token.spelling)-1]=0; |
Michiel Van Der Kolk | fff0d92 | 2005-04-28 16:41:08 +0000 | [diff] [blame] | 64 | } |
| 65 | if(token.kind==TOKEN_STRINGIDENTIFIER) |
| 66 | printf("TITLE=4 ARTIST=5 ALBUM=6 GENRE=7 FILENAME=8\n"); |
| 67 | else if(token.kind==TOKEN_NUMIDENTIFIER) |
| 68 | printf("YEAR=1 RATING=2 PLAYCOUNT=3\n"); |
| 69 | token.intvalue=0; |
| 70 | if(token.kind==TOKEN_STRINGIDENTIFIER || |
| 71 | token.kind==TOKEN_NUMIDENTIFIER || |
| 72 | token.kind==TOKEN_NUM) { |
| 73 | printf("Token intvalue? "); |
| 74 | fflush(stdout); |
Michiel Van Der Kolk | a43f90f | 2005-04-28 17:03:45 +0000 | [diff] [blame] | 75 | fgets(buf,254,stdin); |
Michiel Van Der Kolk | 238bea7 | 2005-04-28 18:49:23 +0000 | [diff] [blame] | 76 | token.intvalue=BE32(strtol(buf,0,10)); |
Michiel Van Der Kolk | fff0d92 | 2005-04-28 16:41:08 +0000 | [diff] [blame] | 77 | } |
| 78 | fwrite(&token,sizeof(struct token),1,fp); |
| 79 | done=token.kind==0; |
| 80 | } while(!done); |
| 81 | fclose(fp); |
| 82 | printf("Successfully wrote tokenfile\n"); |
| 83 | } |