I want to write a program that will look for a specified line in an .asm source file, and place my procedure calls from another file into it. I want it to work sort of like the #include preprocessor directive, but for assembly source. Here's the code I've been using:
Code:
#include <stdio.h>
int find(FILE *fp, char *find)
{
while ((fscanf(fp, "%c", *find) != 1)
{
if (ferror(fp))
{
fclose(fp);
return -1;
}
if (feof(fp))
{
fclose(fp));
return -2;
}
fscanf(fp, "%*[^\n]");
}
}
void filecopy(FILE *ipf, FILE *opf)
{
char c;
while ((c = getc(ipf)) != EOF)
{
putc(c, opf);
}
}
main (int argc, char *argv[])
{
FILE *fp, *fp2;
long int found, file_pos, file2_pos;
if (argc != 3)
{
printf("Usage: link filename filename2\n");
return 2;
}
if ((fp = fopen(argv[1], "a+")) == NULL)
{
printf("Error: %s cannot be opened.", argv[1]);
return 1;
}
if ((fp2 = fopen(argv[2], "a+")) == NULL)
{
printf("Error: %s cannot be opened.", argv[2]);
return 1;
}
found = find(fp, '&');
if (found == -1)
{
printf("File error!");
return 0;
}
if (found == -2)
{
printf("No call was made for include macro!");
return 0;
}
fgetpos(fp, &file_pos);
fgetpos(fp2, &file2_pos
fseek(fp, 7L, SEEK_CUR);
fseek(fp2, 0L, SEEK_END);
fprintf(fp2, "\n");
filecopy(fp, fp2);
fsetpos(fp, &file_pos);
fseek(fp2, 0L, SEEK_SET);
filecopy(fp2, fp);
fclose(fp);
fclose(fp2);
return 0;
}
If anyone could be so kind as to tell me what i'm doing wrong, I would be extremely pleased! Also, it compiles fine, but it never performs the file routines that i wrote into it.