Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: htop-dev/htop
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 595b1ee724b6be537fdaa1b014368065486e024f
Choose a base ref
..
head repository: htop-dev/htop
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2a3942956a6d3724d97e5063eaeeed0b873edb0e
Choose a head ref
Showing with 31 additions and 48 deletions.
  1. +27 −48 FlexMeter.c
  2. +4 −0 docs/FlexMeter/Template
75 changes: 27 additions & 48 deletions FlexMeter.c
Original file line number Diff line number Diff line change
@@ -5,17 +5,16 @@ Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

#include "config.h"
#include "FlexMeter.h"
#include <time.h>
#include <sys/time.h>
#include <dirent.h>
#include "CRT.h"
#include "Object.h"

#include <unistd.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <time.h>
#include <pwd.h>
#include "FlexMeter.h"
#include "Object.h"
#include "config.h"
#include "CRT.h"

#define FLEX_CFG_FOLDER ".config/htop/FlexMeter"

@@ -42,14 +41,6 @@ int check_for_meters(void);

static int parse_input(char * line)
{
for (int i = strlen(line);i>0;i--)
{
if ((line[i]=='\r') || (line[i]=='\n'))
{
line[i]='\0';
}
}

if (!strncmp(line,"name=",5))
{
meter_list[meters_count].uiName = xStrdup(line+5);
@@ -76,17 +67,24 @@ static int parse_input(char * line)

static int load_config(char * file)
{
int ret=0;
char buff[2048];
memset(buff,0,2048);
int ret = -1;
char *buff;
FILE *fp = fopen( file , "r");
while( NULL != fgets(buff, 2048, fp) )
{
parse_input(buff);
memset(buff,0,2048);

if (fp != NULL) {
while(1)
{
buff = String_readLine(fp);
if (buff!=NULL)
parse_input(buff);
else
break;
}

fclose(fp);
ret = 0;
}

fclose(fp);
return ret;
}

@@ -101,16 +99,17 @@ int check_for_meters(void)
// path to home folder 1 for zero 1 for slash
char * home = (char * ) xCalloc(1,(strlen(homedir) + strlen(FLEX_CFG_FOLDER) + 2));

sprintf(home,"%s/%s",homedir,FLEX_CFG_FOLDER);
xSnprintf(home,(strlen(homedir) + strlen(FLEX_CFG_FOLDER) + 2),"%s/%s",homedir,FLEX_CFG_FOLDER);

d = opendir(home);
if (d) {
while ((dir = readdir(d)) != NULL) {
if ( dir->d_name[0]!='.' && strcmp(".",dir->d_name) && strcmp("..",dir->d_name))
if ( dir->d_name[0]!='.')
{
// We are ignoring all files starting with . like ".Template" and "." ".." directories
meter_list[meters_count].name = xStrdup(dir->d_name);
memset(path,0,80);
sprintf(path,"%s/%s",home,dir->d_name);
xSnprintf(path,400,"%s/%s",home,dir->d_name);
if( 0 != load_config(path) )
{
break;
@@ -130,27 +129,7 @@ int check_for_meters(void)
}
else
{
if (0 == mkdir(home,0777))
{
char template [4][40] =
{
"name=template",
"command=echo \"`uptime`\"",
"type=TEXT_METERMODE",
"caption=\"UPTIME\""
};

char template_filename[500];
sprintf(template_filename,"%s/%s",home,".Template");
FILE * fp = fopen(template_filename,"w");
if (fp != NULL )
{
for (int i=0; i<4; i++)
{
fprintf(fp,"%s\n",template[i]);
}
}
}
mkdir(home,0700);
}

free(home);
4 changes: 4 additions & 0 deletions docs/FlexMeter/Template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name=template
command=echo "`uptime`"
type=TEXT_METERMODE
caption="UPTIME"