示例#1
0
文件: date.c 项目: BigEd/wp34s
void date_alphatime(enum nilop op) {
	char buf[16], *p;
	int h, m, s;
	const char *suffix;

	if (extract_time(&h, &m, &s, 100))
		return;
	xset(buf, '\0', sizeof(buf));
	if (UState.t12) {
		if (h >= 12) {
			h -= 12;
			suffix = " PM";
		} else
			suffix = " AM";
		if (h == 0)
			h = 12;
	} else
		suffix = "";
	p = num_arg(buf, h);
	*p++ = ':';
	p = num_arg_0(p, m, 2);
	*p++ = ':';
	p = num_arg_0(p, s, 2);
	scopy(p, suffix);
	add_string(buf);
}
示例#2
0
/*
 *Cette fonction vient lire chaque ligne et extrait time
 *et DeltaTCP pour chaque trame. Elle stocke cette info dans une QStringList.
 *Elle s'occupe aussi d'enregistrer les logs dans le fichier report.csv
 */
void Core::process_line(QString line){

    QStringList list =splitLine(line);
    double deltaTCP = extractDeltaTCP(list);
    _DeltaTcpList.append(deltaTCP);
    double time = extract_time(line);

    report(time,deltaTCP);


}
示例#3
0
void sheet_keyboard_ungrab (Sheet *sheet, GdkEvent *event)
{
	g_return_if_fail (sheet);
	g_return_if_fail (IS_SHEET (sheet));
#ifndef DEBUG_DISABLE_GRABBING
	if (sheet->priv->keyboard_grabbed) {
		sheet->priv->keyboard_grabbed = FALSE;
		goo_canvas_keyboard_ungrab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid),
		                            extract_time (event));
	}
#endif
}
示例#4
0
文件: date.c 项目: BigEd/wp34s
void date_settime(enum nilop op) {
	int h, m, s;
	if (extract_time(&h, &m, &s, 24))
		return;
#ifdef REALBUILD
	if (Xtal) {
		busy();
		RTC_SetTime((unsigned char) h, (unsigned char) m, (unsigned char) s);
	} else
		err(ERR_NO_CRYSTAL);
#else
	err(ERR_ILLEGAL);
#endif
}
示例#5
0
gboolean sheet_keyboard_grab (Sheet *sheet, GdkEvent *event)
{
	g_return_val_if_fail (sheet, FALSE);
	g_return_val_if_fail (IS_SHEET (sheet), FALSE);
#ifndef DEBUG_DISABLE_GRABBING
	if (sheet->priv->keyboard_grabbed == FALSE &&
	    goo_canvas_keyboard_grab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid),
	                              TRUE, /*do not reroute signals through sheet->grid*/
	                              extract_time (event)) == GDK_GRAB_SUCCESS) {
		sheet->priv->keyboard_grabbed = TRUE;
	}
	return (sheet->priv->keyboard_grabbed == TRUE);
#else
	return TRUE;
#endif
}
示例#6
0
gboolean sheet_pointer_grab (Sheet *sheet, GdkEvent *event)
{
	g_return_val_if_fail (sheet, FALSE);
	g_return_val_if_fail (IS_SHEET (sheet), FALSE);
#ifndef DEBUG_DISABLE_GRABBING
	if (sheet->priv->pointer_grabbed == 0 &&
	    goo_canvas_pointer_grab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid),
	                             GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
	                                 GDK_BUTTON_RELEASE_MASK,
	                             NULL, extract_time (event)) == GDK_GRAB_SUCCESS) {
		sheet->priv->pointer_grabbed = 1;
	}
	return (sheet->priv->pointer_grabbed == 1);
#else
	return TRUE;
#endif
}
示例#7
0
文件: os_ext.c 项目: mk-fg/fgc
static PyObject *
oe_lutimes(PyObject *self, PyObject *args) { // (str) filename, (tuple) (atime, mtime)
	char *path; PyObject *ftimes;
	if (!PyArg_ParseTuple( args, "etO:utime",
		Py_FileSystemDefaultEncoding, &path, &ftimes )) return NULL;

	struct timeval tv[2];

	if (PyTuple_Check(ftimes) && PyTuple_Size(ftimes) == 2) {
		int i;
		for (i=0; i<2; i++) {
			if ( extract_time(PyTuple_GET_ITEM(ftimes, i),
					&tv[i].tv_sec, &tv[i].tv_usec) == -1 ) {
				PyMem_Free(path);
				return NULL; } }

		Py_BEGIN_ALLOW_THREADS
		i = lutimes(path, tv);
		Py_END_ALLOW_THREADS

		if (i < 0) return posix_error_with_allocated_filename(path); }
示例#8
0
文件: anna.c 项目: Harenome/Anna-Lise
static inline int ping_v4(const char * hostname)
{
    int sockfd;
    struct sockaddr_in address;
    icmp4_packet packet;

    int success = get_ipv4(hostname, IPPROTO_ICMP, &address);
    printf("ping ");
    print_host_v4(&address);
    printf("\n");
    succeed_or_die(success, 0, create_raw_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP, &sockfd));
    succeed_or_die(success, 0, icmp4_packet_init(&packet, extract_ipv4(&address)));
    succeed_or_die(success, 0, icmp4_packet_set_length(&packet, sizeof packet));

    int sent = 0;
    int i = 0;
    int gotten = 0;
    struct timeval wait_time = { 1, 0 };
    long double min = 0.;
    long double max = 0.;
    long double sum = .0;
    struct timeval ping_start = { 0, 0 };
    struct timeval ping_end = { 0, 0 };
    gettimeofday(&ping_start, NULL);
    while (success == 0 && fin_des_temps == 1)
    {
        struct timeval start = { 0, 0 };
        struct timeval end = { 0, 0 };

        succeed_or_die(success, 0, icmp4_packet_set_echo_seq(&packet, i));
        gettimeofday(&start, NULL);
        if (sendto(sockfd, &packet, sizeof packet, 0, (struct sockaddr *) &address, sizeof address) == sizeof packet)
        {
            sent++;
            icmp4_packet received;
            memset(&received, 0, sizeof received);
            int before = gotten;
            if (receive_icmp_v4(sockfd, &address, &wait_time, &received) == 0)
            {
                if (received.icmp_header.type == ICMP_ECHOREPLY
                    && received.icmp_header.un.echo.sequence == i
                    && received.icmp_header.un.echo.id == packet.icmp_header.un.echo.id
                    )
                {
                    gotten++;
                    gettimeofday(&end, NULL);
                    struct timeval diff = diff_timeval(start, end);
                    long double rtt = extract_time(diff);
                    update_statistics(&min, &max, &sum, rtt, gotten, before);
                    print_received(&received, &address, rtt);

                    if (rtt > sum / gotten * 2 || rtt < sum / gotten / 2)
                        success = -1;
                }
            }
            if ((float) gotten / sent < 0.7)
                success = -1;
        }
        i++;
        sleep(1);
    }
    gettimeofday(&ping_end, NULL);
    struct timeval total = diff_timeval(ping_start, ping_end);
    print_ping_statistics(sent, gotten, min, max, sum, total, &address);

    return success;

}
示例#9
0
文件: anna.c 项目: Harenome/Anna-Lise
static inline void print_ping_statistics(int sent, int gotten, long double min, long double max, long double sum, struct timeval total, struct sockaddr_in * address)
{
    printf("--- ");
    print_host_v4(address);
    printf(" ping statistics ---\n");
    printf("%d packets transmitted, %d received, %.0f%% paquet loss, time %.0Lfms\n", sent, gotten, ((float) (sent - gotten) / sent) * 100, extract_time(total));
    printf("rtt min/avg/max = %.3Lf/%.3Lf/%.3Lf\n", min, sum / gotten, max);


}
示例#10
0
static void
csv_write_var__ (struct csv_writer *w, const struct csv_var *cv,
                 const union value *value)
{
  const char *label;

  label = val_labs_find (cv->val_labs, value);
  if (label != NULL)
    csv_output_string (w, label);
  else if (cv->width == 0 && value->f == SYSMIS)
    csv_output_buffer (w, " ", 1);
  else if (w->opts.use_print_formats)
    csv_output_format (w, cv, value);
  else
    {
      char s[MAX (DBL_STRLEN_BOUND, 128)];
      char *cp;

      switch (cv->format.type)
        {
        case FMT_F:
        case FMT_COMMA:
        case FMT_DOT:
        case FMT_DOLLAR:
        case FMT_PCT:
        case FMT_E:
        case FMT_CCA:
        case FMT_CCB:
        case FMT_CCC:
        case FMT_CCD:
        case FMT_CCE:
        case FMT_N:
        case FMT_Z:
        case FMT_P:
        case FMT_PK:
        case FMT_IB:
        case FMT_PIB:
        case FMT_PIBHEX:
        case FMT_RB:
        case FMT_RBHEX:
        case FMT_WKDAY:
        case FMT_MONTH:
          dtoastr (s, sizeof s, 0, 0, value->f);
          cp = strpbrk (s, ".,");
          if (cp != NULL)
            *cp = w->opts.decimal;
          break;

        case FMT_DATE:
        case FMT_ADATE:
        case FMT_EDATE:
        case FMT_JDATE:
        case FMT_SDATE:
        case FMT_QYR:
        case FMT_MOYR:
        case FMT_WKYR:
          if (value->f < 0)
            strcpy (s, " ");
          else
            {
              int y, m, d;

              extract_date (value->f, &y, &m, &d);
              snprintf (s, sizeof s, "%02d/%02d/%04d", m, d, y);
            }
          break;

        case FMT_DATETIME:
          if (value->f < 0)
            strcpy (s, " ");
          else
            {
              int y, m, d, M, S;
              double H;

              extract_time (extract_date (value->f, &y, &m, &d), &H, &M, &S);
              snprintf (s, sizeof s, "%02d/%02d/%04d %02.0f:%02d:%02d",
                        m, d, y, H, M, S);
            }
          break;

        case FMT_TIME:
        case FMT_DTIME:
          {
            double H;
            int M, S;

            extract_time (fabs (value->f), &H, &M, &S);
            snprintf (s, sizeof s, "%s%02.0f:%02d:%02d",
                      value->f < 0 ? "-" : "", H, M, S);
          }
          break;

        case FMT_A:
        case FMT_AHEX:
          csv_output_format (w, cv, value);
          return;

        case FMT_NUMBER_OF_FORMATS:
          NOT_REACHED ();
        }
      csv_output_string (w, s);
    }
}
示例#11
0
/**
 * Process a package file and store updates in the database
 */
static void process_packages(char *filename, char *product, bool update)
{
	char *uri, line[12288], *pos;
	int count = 0, errored = 0, vulnerable = 0, new_packages = 0;
	int new_versions = 0, updated_versions = 0, deleted_versions = 0;
	time_t gen_time;
	u_int32_t pid = 0;
	enumerator_t *e;
	database_t *db;
	FILE *file;

	/* opening package file */
	printf("loading\"%s\"\n", filename);
	file = fopen(filename, "r");
	if (!file)
	{
		fprintf(stderr, "could not open \"%s\"\n", filename);
		exit(EXIT_FAILURE);
	}

	/* connect package database */
	uri = lib->settings->get_str(lib->settings, "pacman.database", NULL);
	if (!uri)
	{
		fprintf(stderr, "database URI pacman.database not set\n");
		fclose(file);
		exit(EXIT_FAILURE);
	}
	db = lib->db->create(lib->db, uri);
	if (!db)
	{
		fprintf(stderr, "could not connect to database '%s'\n", uri);
		fclose(file);
		exit(EXIT_FAILURE);
	}

	/* check if product is already in database */
	e = db->query(db, "SELECT id FROM products WHERE name = ?",
				  DB_TEXT, product, DB_INT);
	if (e)
	{
		if (!e->enumerate(e, &pid))
		{
			pid = 0;
		}
		e->destroy(e);
	}
	if (!pid)
	{
		if (db->execute(db, &pid, "INSERT INTO products (name) VALUES (?)",
						DB_TEXT, product) != 1)
		{
			fprintf(stderr, "could not store product '%s' to database\n",
							 product);
			fclose(file);
			db->destroy(db);
			exit(EXIT_FAILURE);
		}
	}

	while (fgets(line, sizeof(line), file))
	{
		char *package, *version;
		char *cur_version, *version_update = NULL, *version_delete = NULL;
		bool security, add_version = TRUE;
		int cur_security, security_update = 0, security_delete = 0;
		u_int32_t gid = 0, vid = 0, vid_update = 0, vid_delete = 0;
		time_t cur_time;

		count++;
		if (count == 1)
		{
			printf("%s", line);
		}
		if (count == 3)
		{
			gen_time = extract_time(line);

			if (gen_time == UNDEFINED_TIME)
			{
				fprintf(stderr, "could not extract generation time\n");
				fclose(file);
				db->destroy(db);
				exit(EXIT_FAILURE);
			}
			printf("Generated: %T\n", &gen_time, TRUE);
		}
		if (count < 7)
		{
			continue;
		}

		/* look for the package name */
		pos = strchr(line, ' ');
		if (!pos)
		{
			fprintf(stderr, "could not extract package name from '%.*s'\n",
					(int)(strlen(line)-1), line);
			errored++;
			continue;
		}
		*pos++ = '\0';
		package = line;

		/* look for version string in parentheses */
		if (*pos == '(')
		{
			version = ++pos;
			pos = strchr(pos, ')');
			if (pos)
			{
				*pos++ = '\0';
			}
			else
			{
				fprintf(stderr, "could not extract package version from "
						"'%.*s'\n", (int)(strlen(line)-1), line);
				errored++;
				continue;
			}
		}
		else
		{
			/* no version information, skip entry */
			continue;
		}
		security = (strstr(pos, "[security]") != NULL);
		if (security)
		{
			vulnerable++;
		}

		/* handle non-security packages in update mode only */
		if (!update && !security)
		{
			continue;
		}

		/* check if package is already in database */
		e = db->query(db, "SELECT id FROM packages WHERE name = ?",
						  DB_TEXT, package, DB_INT);
		if (e)
		{
			if (!e->enumerate(e, &gid))
			{
				gid = 0;
			}
			e->destroy(e);
		}
		if (!gid && security)
		{
			if (db->execute(db, &gid, "INSERT INTO packages (name) VALUES (?)",
								DB_TEXT, package) != 1)
			{
				fprintf(stderr, "could not store package '%s' to database\n",
								 package);
				fclose(file);
				db->destroy(db);
				exit(EXIT_FAILURE);
			}
			new_packages++;
		}

		/* check for package versions already in database */
		e = db->query(db,
				"SELECT id, release, security, time FROM versions "
				"WHERE package = ? AND product = ?",
				DB_INT, gid, DB_INT, pid, DB_INT, DB_TEXT, DB_INT, DB_INT);
		if (!e)
		{
			break;
		}
		while (e->enumerate(e, &vid, &cur_version, &cur_security, &cur_time))
		{
			if (streq(version, cur_version))
			{
				/* already in data base */
				add_version = FALSE;
				break;
			}
			else if (gen_time > cur_time)
			{
				if (security)
				{
					if (cur_security)
					{
						vid_update = vid;
						version_update = strdup(cur_version);
						security_update = cur_security;
					}
					else
					{
						vid_delete = vid;
						version_delete = strdup(cur_version);
						security_delete = cur_security;
					}
				}
				else
				{
					if (!cur_security)
					{
						vid_update = vid;
						version_update = strdup(cur_version);
						security_update = cur_security;
					}
				}
			}
			else
			{
				if (security == cur_security)
				{
					add_version = FALSE;
				}
			}
		}
		e->destroy(e);

		if ((!vid && !security) || (vid && !add_version))
		{
			free(version_update);
			free(version_delete);
			continue;
		}

		if ((!vid && security) || (vid && !vid_update))
		{
			printf("%s (%s) %s\n", package, version, security ? "[s]" : "");

			if (db->execute(db, &vid,
				"INSERT INTO versions "
				"(package, product, release, security, time) "
				"VALUES (?, ?, ?, ?, ?)", DB_INT, gid, DB_INT, pid,
				DB_TEXT, version, DB_INT, security, DB_INT, gen_time) != 1)
			{
				fprintf(stderr, "could not store version '%s' to database\n",
								 version);
				free(version_update);
				free(version_delete);
				fclose(file);
				db->destroy(db);
				exit(EXIT_FAILURE);
			}
			new_versions++;
		}
		else
		{
			printf("%s (%s) %s updated by\n",
				   package, version_update, security_update ? "[s]" : "");
			printf("%s (%s) %s\n", package, version, security ? "[s]" : "");

			if (db->execute(db, NULL,
				"UPDATE versions SET release = ?, time = ? WHERE id = ?",
				DB_TEXT, version, DB_INT, gen_time, DB_INT, vid_update) <= 0)
			{
				fprintf(stderr, "could not update version '%s' to database\n",
								 version);
				free(version_update);
				free(version_delete);
				fclose(file);
				db->destroy(db);
				exit(EXIT_FAILURE);
			}
			updated_versions++;
		}

		if (vid_delete)
		{
			printf("%s (%s) %s deleted\n",
				   package, version_delete, security_delete ? "[s]" : "");

			if (db->execute(db, NULL,
				"DELETE FROM  versions WHERE id = ?",
				DB_INT, vid_delete) <= 0)
			{
				fprintf(stderr, "could not delete version '%s' from database\n",
								 version_delete);
				free(version_update);
				free(version_delete);
				fclose(file);
				db->destroy(db);
				exit(EXIT_FAILURE);
			}
			deleted_versions++;
		}
		free(version_update);
		free(version_delete);
	}
	fclose(file);
	db->destroy(db);

	printf("processed %d packages, %d security, %d new packages, "
		   "%d new versions, %d updated versions, %d deleted versions, "
		   "%d errored\n", count - 6, vulnerable, new_packages, new_versions,
		   updated_versions, deleted_versions, errored);
}