/* --------------------------------------------------------------------------- * writes to pipe using the command defined by Settings.SaveCommand * %f are replaced by the passed filename */ static int WritePipe (char *Filename, bool thePcb) { FILE *fp; int result; char *p; static DynamicStringType command; int used_popen = 0; if (EMPTY_STRING_P (Settings.SaveCommand)) { fp = fopen (Filename, "w"); if (fp == 0) { Message ("Unable to write to file %s\n", Filename); return STATUS_ERROR; } } else { used_popen = 1; /* setup commandline */ DSClearString (&command); for (p = Settings.SaveCommand; *p; p++) { /* copy character if not special or add string to command */ if (!(*p == '%' && *(p + 1) == 'f')) DSAddCharacter (&command, *p); else { DSAddString (&command, Filename); /* skip the character */ p++; } } DSAddCharacter (&command, '\0'); printf ("write to pipe \"%s\"\n", command.Data); if ((fp = popen (command.Data, "w")) == NULL) { PopenErrorMessage (command.Data); return (STATUS_ERROR); } } if (thePcb) result = WritePCB (fp); else result = WriteBuffer (fp); if (used_popen) return (pclose (fp) ? STATUS_ERROR : result); return (fclose (fp) ? STATUS_ERROR : result); }
/* --------------------------------------------------------------------------- * writes PCB to file */ static int WritePCBFile (char *Filename) { FILE *fp; int result; if ((fp = fopen (Filename, "w")) == NULL) { OpenErrorMessage (Filename); return (STATUS_ERROR); } result = WritePCB (fp); fclose (fp); return (result); }