From graphics!scraft@bobsbox.rent.com Wed Jan 20 19:32:56 1993 Received: from calvin.sfasu.edu by umaxc.weeg.uiowa.edu (5.61.jnf/920629) on Wed, 20 Jan 93 19:32:49 -0600 id AA13029 with SMTP Received: from rutgers.edu by calvin.sfasu.EDU with SMTP (5.59/25-eef) id AA12437; Wed, 20 Jan 93 19:18:51 CST Return-Path: Received: from bobsbox.rent.com by rutgers.edu (5.59/SMI4.0/RU1.5/3.08) with UUCP id AA23011; Wed, 20 Jan 93 17:40:15 EST Received: by bobsbox.rent.com (V1.16/Amiga) id AA0bg68; Wed, 20 Jan 93 13:50:16 EST Received: by graphics.rent.com (1.65/waf) via UUCP; Wed, 20 Jan 93 12:49:17 EST for hyperc-l@calvin.sfasu.edu Comments: New Brunswick, NJ Message-Id: <79RoXB12w165w@graphics.rent.com> Date: Wed, 20 Jan 93 12:39:53 EST Organization: The Graphics BBS (2D,3D,GIF,Animation) +1 908/469-0049 From: scraft@graphics.rent.com (Steve Craft) To: hyperc-l@calvin.sfasu.edu Subject: Help this guy Status: R Can you guys find the problems below? A guy I sent a Hyper-C development disk to asked me the below and I though I'd better put it to the heavyweights: _____________________________________________________ SALUTATIONS FROM THE HINTERLAND! Thanks for the speedy delivery of this very interesting Hyper-c programming system. I can tell you've done a lot of work cleaning and sorting all the details. Unfortunately I am modem-less and so unable to use your SJAUG BBS. But you seem to have had some experience solving problems in this system and I hope you can help me with two puzzling deadends. My first problem deals with making a scanf.o file to put in bin/libc. I referred to the e-mail from Eric McGillicuddy and Andy Werner and deleted the lnk and rm $1.o lines from my bin/cc file as below: ; ; batch file for compiling C programs... ; NOTE: Do NOT specify the ".c" ending the source filename! ; bin/ppf -i |hdrs/ -o $1.p $1.c bin/hyperc -o $1.s $1.p rm $1.p bin/asmcp -o $1.o $1.s rm $1.s Unfortunately, when I compiled using cclib source/scanf the program stopped with this error: source/scanf.c:#9';'expected When I exit to the text editor I cannot find a problem with the source code for scanf.c, here's my listing: /* scanf.c utility function Formatted input for HyperC */ /* #include */ #define BUFSIZ 100 #define TRUE 1 #define FALSE 0 INT scanf(fmt,args) <----This is where the problem supposedly is! EXT *fmt; INT *args; { TEXT buf[BUFSIZ], temp[BUFSIZ]; TEXT *str, *ptr; INT maxchars, nargs, i, **arv; BOOL ignore, space; CHAR fctl; LOCAL INT convert() { INT val; CHAR fctl; val=0; while (isdigit(*fmt)) val = 10*val + *fmt++ -'0'; if (!val) switch (fctl =*fmt) { case 'd': case 'D': val = 6; break; case 'i': case 'I': val = 8; break; case 'u': case 'U': val = 5; break; case 'o': case 'O': val = 6; break; case 'x': case 'X': val = 4; break; case 'h': case 'H': val = 3; break; case 'c': case 'C': val = 1; break; default: val = BUFSIZ - 2; break; } return ((val > BUFSIZ-2) ? BUFSIZ-2 : val); } LOCAL VOID strcopy (dest, src) CHAR *src, *dest; { while (*dest++ = *src++) ; } arv=&args; nargs=0; ignore = FALSE; space = FALSE; conRead (buf, BUFSIZ); str = buf; while (*fmt) { if (*fmt == ' ') space = TRUE; if (*fmt++ == '%') { if (*fmt == '*') { /* suppression character, useless but k&r use it*/ ignore = TRUE; ++fmt; } maxchars = convert(); ptr = temp; for (i =0; i < maxchars; i++) { if (isspace(*str) && space) { str++; break; } *ptr++ = *str++; } *ptr = '\0'; ptr = temp; if (!ignore) switch (fctl = *fmt++) { case 'd': case 'D': case 'i': case 'I': **arv = atoi (&ptr); break; case 'u': case 'U': if (*ptr =='-') *ptr=' '; **arv = atoi (&ptr); break; case 'o': case 'O': movel (ptr,ptr+1,8); ptr[0] = '0'; **arv = atoi (&ptr); break; case 'x': case 'X': movel (ptr,&ptr[2],6); *ptr = '0'; /* add '0x' prefix to string to make atoi work*/ ptr[1] = 'x'; **arv = atoi (&ptr); break; case 'h': case 'H': **arv = atoi (&ptr); break; case 'c': case 'C': **arv = *ptr; break; case 'n': case 'N': arv++; break; case 's': case 'S': strcopy (*arv, ptr); break; default: **arv = '\0'; break; } /*end switch */ arv++; ++nargs; fmt--; /* clean up control string pointer */ } /* end if '%' */ } /* end while */ return (nargs); } /*end scanf */ I hope you have better luck in figuring that one out than I did! I can see no problems with this code. The same is also true of my second problem. I decided to try something different and work on a program I have already started in BASIC. The first thing I tried involved making a menu: /* Main menu */ menuA () #include "hdrs/std.h" { page(); clrkbd(); /* Print menu */ cursor(5, 35); vidinv(); putstr(" MAIN MENU "); vidnorm(); } But when I compiled this code I got an error reading the hdrs/std.h file, again I got the same error: hdrs/std.h:#23";"expected So I went into the text editor and still was unable to find any problems with this code: /* * std.h -- standard defines for C */ #define VOID int #define BOOL char #define CHAR char #define BYTE char #define UBYTE unsigned char #define WORD short #define UWORD unsigned short #define INT int #define UINT unsigned int #define TEXT char #define BITSET bitset #define GLOBAL #define LOCAL static #define REG register #define EXTERN extern #define VAR var BITSET CHARSET {CHAR}; <---- This is supposedly the error! EXTERN CHARSET digitset; EXTERN CHARSET alphaset; EXTERN CHARSET alnumset; EXTERN CHARSET hexset; EXTERN CHARSET spaceset; #define NIL 0 #define YES 1 #define NO 0 #define OK 0 #define ERR 1 #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) < (b)) ? (b) : (a)) #define abs(x) (((x) < 0) ? -(x) : (x)) #define isodd(x) ((INT)(x) & 1) #define isnil(x) ((x) == NIL) #define notnil(x) (!isnil(x)) #define isdigit(ch) ((ch) in digitset) #define ishex(ch) ((ch) in hexset) #define isalpha(ch) ((ch) in alphaset) #define isalnum(ch) ((ch) in alnumset) #define isspace(ch) ((ch) in spaceset) #define clreos() putchr(0x0b) #define clreol() putchr(0x1d) #define page() putchr('\f') #define beep() putchr(0x07) #define vidnorm() putchr(0x0e) #define vidinv() putchr(0x0f) #define bs() putchr('\b') #define cr() putchr('\n') #define tab() putchr('\t') #define cursor(row, col) setcurs(((row) << 8) + (col)) /* * files.h -- header for file structures on Apple PRODOS */ #define BLKSIZ 512 /* size of block in bytes */ #define NAMSIZ 14 /* nbr of chars per filename */ #define FILE INT typedef INT FPOS[2]; #define SEEKMOD enum seekMode SEEKMOD (SEEKABS, SEEKREL, SEEKEOF); #define rewind(fp) seek(fp, 0, 0, SEEKABS) /* --- end of std.h --- */ "Steve Craft" MicrofoneBBS 908.494.8666 // Check out Hyper-C, the best user #9 SJAUG BBS 609.424.1382 // "C" language development scraft@graphics.rent.com // system for the Apple ][ From david@cs.uow.edu.au Wed Jan 20 20:07:03 1993 Received: from calvin.sfasu.edu by umaxc.weeg.uiowa.edu (5.61.jnf/920629) on Wed, 20 Jan 93 20:06:59 -0600 id AA02365 with SMTP Received: from wraith.cs.uow.edu.au by calvin.sfasu.EDU with SMTP (5.59/25-eef) id AA12450; Wed, 20 Jan 93 19:55:38 CST Return-Path: Received: from draci (draci.cs.uow.edu.au) by wraith.cs.uow.edu.au with SMTP (5.65c/IDA-1.4.4); id AA29527; Thu, 21 Jan 1993 12:54:14 +1100 (from david@cs.uow.edu.au for ) Received: by draci id AA00463 (5.65c/IDA-1.4.4); Thu, 21 Jan 1993 12:54:12 +1100 From: David E A Wilson Message-Id: <199301210154.AA00463@draci> Subject: Re: Help this guy To: scraft@graphics.rent.com (Steve Craft) Date: Thu, 21 Jan 1993 12:38:24 +1100 (EST) Cc: hyperC-l@calvin.sfasu.edu (Hyper C Mailing List) In-Reply-To: <79RoXB12w165w@graphics.rent.com> from "Steve Craft" at Jan 20, 93 12:39:53 pm Content-Type: text Content-Length: 2110 Status: R > /* scanf.c utility function Formatted input for HyperC */ > > /* #include */ > > #define BUFSIZ 100 > #define TRUE 1 > #define FALSE 0 > > INT scanf(fmt,args) <----This is where the problem supposedly is! > EXT *fmt; > INT *args; > > { > TEXT buf[BUFSIZ], temp[BUFSIZ]; > TEXT *str, *ptr; > INT maxchars, nargs, i, **arv; > BOOL ignore, space; > CHAR fctl; > There should be some code ending with a } here before you start defining another function... > LOCAL INT convert() > { > INT val; > CHAR fctl; > > val=0; > while (isdigit(*fmt)) > val = 10*val + *fmt++ -'0'; > if (!val) > switch (fctl =*fmt) { > case 'd': > case 'D': > val = 6; > break; Code deleted for brevity... > } > return ((val > BUFSIZ-2) ? BUFSIZ-2 : val); > } > > LOCAL VOID strcopy (dest, src) > CHAR *src, *dest; > { > while (*dest++ = *src++) > ; > } > Ahhh! And here it is. Remember, in C all functions are global unlike Pascal for instance where you define functions inside other functions. > arv=&args; > nargs=0; > ignore = FALSE; > space = FALSE; > conRead (buf, BUFSIZ); > str = buf; > while (*fmt) { Code deleted for brevity... > } /* end while */ > return (nargs); > } /*end scanf */ > I recommend that you move the functions strcopy & convert outside of scanf (in front of it would be best). > /* Main menu */ > > menuA () > #include "hdrs/std.h" > > { page(); > clrkbd(); > > /* Print menu */ > cursor(5, 35); > vidinv(); > putstr(" MAIN MENU "); > vidnorm(); > } > > But when I compiled this code I got an error reading the hdrs/std.h > file, again I got the same error: > > hdrs/std.h:#23";"expected Yes - you should not include a headr file in the middle of defining a function. Move menuA() AFTER #include "hdrs/std.h" and it should work much better. -- David Wilson +61 42 213802 voice, +61 42 213262 fax Dept Comp Sci, Uni of Wollongong david@cs.uow.edu.au