bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #30328] Fast echo (with code proposal)


From: Olexiy Buyanskyy
Subject: [bug #30328] Fast echo (with code proposal)
Date: Mon, 19 Jul 2010 17:37:42 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.7) Gecko/20100701 Firefox/3.6.7 ( .NET CLR 3.5.30729)

Follow-up Comment #6, bug #30328 (project make):

what about to have some function $(file file_name,open_type,string)

where open_type can be the same as for fopen



static void replace_all(char* inputStr,const char* pattern,const char*
substr) {
   char * found = strstr(inputStr,pattern);
   int patternLen = strlen(pattern);
   int substrLen = strlen(substr);
   char * end = inputStr + strlen(inputStr);
   while (found != 0) {
      strncpy(found,substr,substrLen);
      memmove(found+substrLen,found+patternLen,end - (found + substrLen) +
1);
      found = strstr(found,pattern);
   }
}

/**
 * Output information to file.
 * argv - file name
 * argv + 1 - can be w,a, see fopen
 * argv + 2,... - message to output to file
*/
static char * func_file(char *o, char **argv, const char *funcname) {
   char **argvp;
   int len = 0;

   FILE * pFile = fopen(*argv,*(argv+1));
   if (pFile != 0) {
      for (argvp = argv+2; *argvp != 0; ++argvp) {
         char * param = *argvp;
         replace_all(param,"\n","n");
         replace_all(param,"\t","t");
         /* need to put more here */
         len += strlen(param) + 2;
         fputs(param,pFile);
      }
      fclose(pFile);
   } else {
      error(reading_file, _("Could not open file: `%s`"), *argv);
   }
   return o;
}



After that you can use to append


$(file file.out,a,some text with n to append to file)


if you need to write to file


$(file file.out,w,some text with n to create new file)



    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?30328>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]