I want to reproduce a string search and replace between to arrays that
I have done in perl using very little code. I am not sure how best do
this without overdoing it... I have the outline of the code written
below - I just need to know what is my next best steps to complete it
-- or a suggestion if what I have so far is not correct. Thanks, john
My perl script basically inserts some postscript code for a watermark
into another postscript file.
Here is basic idea in psuedo perl ocode:
@infile = read_file("c:\\my_drawing.ps");
@watermark_code = read_file("c:\\watermark.ps");
# This is the core filter code
foreach $line (@infile) {
if ($line =~ /showpage/i) { # find line with showpage
$line =~ s/showpage//i; # remove showpage from line
push @outfile,$line; # add line from infile
push @outfile,"@watermark"; #insert all lines of watermark
} else { # all other lines in infile
push @outfile,$line; # add line from infile
} # end if and else
} # end foreach
The help I need is just with the above loop. Here is my current C code
I have written to get ready to do this loop.
I left out the read_ps_file function to make this email smaller...
int merge_watermark (void)
{
int watermark_lines;
int current_ps_lines;
int line;
char **watermark_code;
char **current_ps_code;
char watermark_file[256] = "c:\\temp\\watermark.ps";
char current_ps_file[256] = "c:\\temp\\18.ps";
watermark_lines = read_ps_file(watermark_file,watermark_code);
current_ps_lines = read_ps_file(current_ps_file,current_ps_code);
for (line=0;line<=current_ps_lines;line++) {
// merge code here...
} // end
} 2 1451 jo*********@yahoo.com wrote: I want to reproduce a string search and replace between to arrays that I have done in perl using very little code. I am not sure how best do this without overdoing it... I have the outline of the code written below - I just need to know what is my next best steps to complete it -- or a suggestion if what I have so far is not correct. Thanks, john
My perl script basically inserts some postscript code for a watermark into another postscript file.
Here is basic idea in psuedo perl ocode:
@infile = read_file("c:\\my_drawing.ps"); @watermark_code = read_file("c:\\watermark.ps");
# This is the core filter code foreach $line (@infile) { if ($line =~ /showpage/i) { # find line with showpage $line =~ s/showpage//i; # remove showpage from line push @outfile,$line; # add line from infile push @outfile,"@watermark"; #insert all lines of watermark } else { # all other lines in infile push @outfile,$line; # add line from infile } # end if and else } # end foreach
The help I need is just with the above loop. Here is my current C code I have written to get ready to do this loop.
I left out the read_ps_file function to make this email smaller...
int merge_watermark (void) { int watermark_lines; int current_ps_lines; int line; char **watermark_code; char **current_ps_code; char watermark_file[256] = "c:\\temp\\watermark.ps"; char current_ps_file[256] = "c:\\temp\\18.ps";
watermark_lines = read_ps_file(watermark_file,watermark_code); current_ps_lines = read_ps_file(current_ps_file,current_ps_code);
for (line=0;line<=current_ps_lines;line++) { // merge code here...
char line_buffer[1024];
/* for each line */
if (fgets(line_buffer, sizeof(line_buffer), in_fp)) {
char *p = strstr(line_buffer, "showpage");
if (p) {
fwrite(line_buffer, 1, p - line_buffer, out_fp);
fputs(watermark_lines, out_fp);
fputs(p + sizeof("showpage") - 1, out_fp);
}
else
fputs(line_buffer, out_fp);
}
else {
EOF or error
}
This should work if:
1. There are no lines with containing 1023 characters or more
2. There are no output errors
3. There are no NULs embedded in the file
Robert } // end
}
Thanks.....
Is your solution just reading and writing directly to the file?
Just trying to figure out how you are doing this ....
I assume that you identify the location in the line where showpage
shows up by assigning its position in the line to the pointer p?
Is that the correct way to say what you are doing? Not sure about
terminology....
Are in_fp and out_fp file handles or char string arrays?
Thanks for any help in understanding what you are doing --- so I can do
this again next time :-)
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: R U B'n |
last post by:
Hi everyone,
I have to make a (case-insensitive) search from a form with only one
search string,
e.g. "Doe Peters english California",
which will search in several fields of my table for each...
|
by: pmatos |
last post by:
Hi all,
Sometimes I have a function which creates an object and returns it.
Some are sets, other vectors but that's not very important. In these
cases I do something like this:
vector<int> *...
|
by: Matt Kruse |
last post by:
http://www.JavascriptToolbox.com/bestpractices/
I started writing this up as a guide for some people who were looking for
general tips on how to do things the 'right way' with Javascript. Their...
|
by: Chad Myers |
last post by:
I've been perf testing an application of mine and I've noticed that there
are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String
instances being created.
I've done some...
|
by: zoro |
last post by:
Hi,
I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party
string handling library that includes some very useful string
functions, in particular I'm interested in BEFORE (return...
| |
by: Rob |
last post by:
Rather new to vb.net...
I am wondering if the following is possible and sounds reasonable...
Can connection objects and datasets be defined once (at program load) and be
available for the life...
|
by: Joel Hedlund |
last post by:
Hi all!
I use python for writing terminal applications and I have been bothered
by how hard it seems to be to determine the terminal size. What is the
best way of doing this?
At the end I've...
|
by: RWF |
last post by:
I have read that when using asynchronous IO it is best to keep all your
operations asynchronous. But why if there is nothing left do in the
AsyncCallback method other than to call an IO operation?...
|
by: Diego Martins |
last post by:
Since C++ (and STL) have many ways to do string concatenation, I want
to hear (read) from you how you do to concatenate strings with other
strings and other types. The approaches I know are:
--...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |