Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • c12a31890bcff6c040fce9b975ec078bdf25bd34
  • master par défaut protégée
  • convert-to-dlang
  • clear-warnings
  • update-structs
  • unittests
  • bjarne-stroustrup
  • 5.67.0
8 résultats

utils.c

Blame
  • utils.c 1,62 Kio
    #include <p2c/p2c.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <p2c/strings.h>
    #include "log.h"
    #include "logglobals.h"
    #include "utils.h"
    
    /**
     * Reserved for future use.
     */
    void working()
    {
    }
    
    void getword(char *buf, char *wrd)
    {
    	char STR1[256];
    	char STR2[256];
    
    	strcpy(STR1, strltrim(strrtrim(strcpy(STR2, buf))));
    	strcpy(buf, STR1);
    	if (*buf == '"')
    		strwordx(buf, wrd);
    	else
    	{
    		strwordx(buf, wrd);
    		strupper(wrd, wrd);
    	}
    }
    
    /* char *strcpy_overlap(char *dst, char *src) */
    /* { */
    /*	size_t i = 0; */
    
    /*	do { */
    /*		dst[i] = src[i]; */
    /*		if (src[i++] == '\0') */
    /*			break; */
    /*	} while (1); */
    /*	return dst; */
    /* } */
    
    
    void stamp(long *i)
    {
    	gg.curstamp++;
    	*i = gg.curstamp;
    }
    
    void dounits(char *s, double *r)
    {
    	char ch;
    
    	if (*s == '\0')
    		return;
    	ch = s[0];
    	if (ch >= 'a')
    		ch -= 32;
    	if (ch == 'F')
    	{
    		*r *= 1e-15;
    		return;
    	}
    	if (ch == 'P')
    	{
    		*r *= 1e-12;
    		return;
    	}
    	if (ch == 'N')
    	{
    		*r *= 1e-9;
    		return;
    	}
    	if (ch == 'U')
    	{
    		*r *= 1e-6;
    		return;
    	}
    	if (ch == 'K')
    	{
    		*r *= 1e3;
    		return;
    	}
    	if (ch == 'G')
    	{
    		*r *= 1e9;
    		return;
    	}
    	if (ch == 'T')
    	{
    		*r *= 1e12;
    		return;
    	}
    	if (ch != 'M')
    		return;
    	if (strlen(s) >= 3 && (s[1] == 'E' || s[1] == 'e') &&
    			(s[2] == 'G' || s[2] == 'g'))
    		*r *= 1e6;
    	else
    		*r *= 1e-3;
    }
    
    
    void readreal(char s_[], double *r)
    {
    	char s[256];
    	long i;
    	char *STR1;
    	char STR2[256];
    
    	strcpy(s, s_);
    	if (!(*s != '\0' && (s[0] == '.' || s[0] == '+' || s[0] == '-' || isdigit(s[0]))))
    		return;
    	*r = strtod(s, &STR1);
    	i = STR1 - s + 1;
    	strcpy_overlap(s, s + i - 1);
    	strcpy(STR2, strltrim(s));
    	strcpy(s, STR2);
    	dounits(s, r);
    }