[Github-comments] [geany/geany] [Feature request] Support different combinations of I/O in Custom Commands (#1037)
Andy Alt
notifications at xxxxx
Thu Oct 20 21:03:58 UTC 2016
```
/*
* This can be used with Geany's custom commands
* it will capitalize the first letter in a selection, and every following word that
* is preceded by a space.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define MAX_LENGTH 1024
int main(int argc, char **argv)
{
char *selection = malloc (sizeof (char* ) * MAX_LENGTH + 1);
if (fgets (selection, MAX_LENGTH + 1, stdin) != NULL)
{
if (strlen (selection) > MAX_LENGTH)
return 1;
int pos = 0;
while (selection[pos] != '\0')
{
if (selection[pos] == ' ' || pos == 0)
{
/* Use a loop here in case a space follows a space in the string
* otherwise the second ' ' would get capped, but not the letter
* that follows it
*
* NOTE: Most people would probably just want the extra space
* deleted but left as is for now)
*/
while (selection[pos] == ' ')
pos++;
selection[pos] = toupper (selection[pos]);
}
pos++;
}
fprintf (stdout, "%s", selection);
return 0;
}
return 1;
}
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/issues/1037#issuecomment-255227671
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20161020/7fc4616f/attachment.html>
More information about the Github-comments
mailing list