From owner-freebsd-questions@FreeBSD.ORG Mon Oct 19 17:06:40 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB9B3106566C for ; Mon, 19 Oct 2009 17:06:39 +0000 (UTC) (envelope-from kline@thought.org) Received: from aristotle.thought.org (ns1.thought.org [209.180.213.210]) by mx1.freebsd.org (Postfix) with ESMTP id 906218FC15 for ; Mon, 19 Oct 2009 17:06:39 +0000 (UTC) Received: from thought.org (tao.thought.org [10.47.0.250]) (authenticated bits=0) by aristotle.thought.org (8.14.2/8.14.2) with ESMTP id n9JH6TiY028361; Mon, 19 Oct 2009 10:06:29 -0700 (PDT) (envelope-from kline@thought.org) Received: by thought.org (nbSMTP-1.00) for uid 1002 kline@thought.org; Mon, 19 Oct 2009 10:06:34 -0700 (PDT) Date: Mon, 19 Oct 2009 10:06:34 -0700 From: Gary Kline To: Brad Mettee Message-ID: <20091019170634.GA12371@thought.org> References: <20091019013337.GA9522@thought.org> <4ADBFDBA.6040702@pchotshots.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4ADBFDBA.6040702@pchotshots.com> User-Agent: Mutt/1.4.2.3i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: With 23 years of service to the Unix community. X-Spam-Status: No, score=-4.4 required=3.6 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on aristotle.thought.org Cc: FreeBSD Mailing List Subject: Re: need C help, passing char buffer[] by-value.... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2009 17:06:40 -0000 On Mon, Oct 19, 2009 at 01:48:42AM -0400, Brad Mettee wrote: > Gary Kline wrote: > >Guys, > > > >maybe this can't be done reading in a file with fgets(buffer[128], fp), > >then calling skiptags(), conditionally, to while () past ',' and '>'. > > > >I know I need to calll skipTags with its address, skipTags(&buffer);, but > >then how to i > >handle the variable "s" in skipTags? Anybody? > > > > > > > > > >// redo, skip TAGS > >skipTags((char *)&s) > >{ > > if (*s == '<') > > { > > while (*s != '>') > > { > > s++; > > } > > s++; > > } > >} > > > Your function may not work exactly as you think it will. Your basic idea > runs on the assumption that the tag will never be broken during the file > read. It's possible that you'll read "some data read will have ">more data here", or some variation thereof. > If you know for a fact that the string you read in will always be > complete, then what's below should work fine: > > // where *s is the address of a string to be parsed > // maxlen represents the maximum number of chars potentially in the string > and is not zero based (ie: maxlen 256 = char positions 0-255) > // *curpos is the current position of the pointer (this prevents bounds > errors) > skipTags(char *s, long maxlen, long *curpos) > { > if (*s == '<') > { > while (*s != '>' && && *s && *curpos < maxlen) > { > s++; > (*curpos)++; > } > if (*curpos < maxlen) > { > s++; > (*curpos)++; > } > } > } > > When you read in the next line of the file, reset curpos to zero, set > maxlen to number of bytes read. As you process each char after the > function is called, you'll need to increment curpos as well. > > Depending on the size of the files you are reading, you may be able to > read the entire file into memory at once and avoid any possible TAG > splitting. > > If you explain exactly what you're trying to accomplish, we may be able > to come up with an easier/cleaner solution. > > (warning: none of the above code is tested, but in concept it should > work ok) > It didn't core dump, but neither work. Basically, I'm doing a read via fgets: "while(fgets(buf, sizeof buf, fp_in)) {" an HTML or other file with . Optionally, say, given the switch -N, the program would NOT progress any of the HTML tags; It would only touch other stuff in the file. Simply put, I have a fixed buffer, buf[1024], that I want to change --i think by-reference-----not certain-----by calling skiptags(*&buf); and skiptags() would read past the and return the buffer to the place after fgets() where skiptags(&buf) is called missing all markup . I'm better at by-refernce with ints that chars, so I don't know how far off I am here. That's why I;'m asking you guys. gary -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php